CRM-15779 remove duplicate code block
[civicrm-core.git] / CRM / Contact / Form / Task / Label.php
index c920aa6bda32f665ad6f62fc2baec80e5ec8a4b4..8924401ad9fbbd85b4c446dfe8edb057fd185899 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
 
   /**
-   * build all the data structures needed to build the form
+   * Build all the data structures needed to build the form
    *
    * @return void
-   * @access public
    */
-  function preProcess() {
+  public function preProcess() {
     $this->set('contactIds', $this->_contactIds);
     parent::preProcess();
   }
 
   /**
-   * Build the form
+   * Build the form object
    *
-   * @access public
    *
    * @return void
    */
-  function buildQuickForm() {
+  public function buildQuickForm() {
     CRM_Utils_System::setTitle(ts('Make Mailing Labels'));
 
     //add select for label
@@ -92,14 +90,13 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
   }
 
   /**
-   * This function sets the default values for the form.
+   * Set default values for the form.
    *
    * @param null
    *
    * @return array   array of default values
-   * @access public
    */
-  function setDefaultValues() {
+  public function setDefaultValues() {
     $defaults = array();
     $format = CRM_Core_BAO_LabelFormat::getDefaultValues();
     $defaults['label_name'] = CRM_Utils_Array::value('name', $format);
@@ -109,9 +106,8 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
   }
 
   /**
-   * process the form after the input has been submitted and validated
+   * Process the form after the input has been submitted and validated
    *
-   * @access public
    *
    * @return void
    */
@@ -142,7 +138,7 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
 
     $mailingFormatProperties = array();
     if ($mailingFormat) {
-      $mailingFormatProperties = self::getReturnProperties($mailingFormat);
+      $mailingFormatProperties = CRM_Utils_Token::getReturnProperties($mailingFormat);
       $returnProperties = array_merge($returnProperties, $mailingFormatProperties);
     }
     //we should not consider addressee for data exists, CRM-6025
@@ -266,6 +262,7 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
           continue;
         }
 
+        $contact = array_merge($contact, $contact[$locName]);
         unset($contact[$locName]);
 
         if (!empty($contact['county_id'])) {
@@ -365,7 +362,7 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
    *
    * @return bool
    */
-  function tokenIsFound($contact, $mailingFormatProperties, $tokenFields) {
+  public function tokenIsFound($contact, $mailingFormatProperties, $tokenFields) {
     foreach (array_merge($mailingFormatProperties, array_fill_keys($tokenFields, 1)) as $key => $dontCare) {
       if (!empty($contact[$key])) {
         return TRUE;
@@ -374,16 +371,15 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
     return FALSE;
   }
   /**
-   * function to create labels (pdf)
+   * Create labels (pdf)
    *
    * @param   array    $contactRows   assciated array of contact data
    * @param   string   $format   format in which labels needs to be printed
    * @param   string   $fileName    The name of the file to save the label in
    *
    * @return  null
-   * @access  public
    */
-  function createLabel(&$contactRows, &$format, $fileName = 'MailingLabels_CiviCRM.pdf') {
+  public function createLabel(&$contactRows, &$format, $fileName = 'MailingLabels_CiviCRM.pdf') {
     $pdf = new CRM_Utils_PDF_Label($format, 'mm');
     $pdf->Open();
     $pdf->AddPage();
@@ -401,38 +397,10 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
     $pdf->Output($fileName, 'D');
   }
 
-  /**
-   * function to create the array of returnProperties
-   *
-   * @param   string   $format   format for which return properties build
-   *
-   * @return array of returnProperties
-   * @access  public
-   */
-  function getReturnProperties(&$format) {
-    $returnProperties = array();
-    $matches = array();
-    preg_match_all('/(?<!\{|\\\\)\{(\w+\.\w+)\}(?!\})/',
-      $format,
-      $matches,
-      PREG_PATTERN_ORDER
-    );
-    if ($matches[1]) {
-      foreach ($matches[1] as $token) {
-        list($type, $name) = preg_split('/\./', $token, 2);
-        if ($name) {
-          $returnProperties["{$name}"] = 1;
-        }
-      }
-    }
-
-    return $returnProperties;
-  }
-
   /**
    * @param $rows
    */
-  function mergeSameAddress(&$rows) {
+  public function mergeSameAddress(&$rows) {
     $uniqueAddress = array();
     foreach (array_keys($rows) as $rowID) {
       // load complete address as array key
@@ -497,4 +465,3 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
     }
   }
 }
-