Exemple #1
0
 /**
  * deal with the klp data before export
  * @param $member,object
  * @param $headerKey,array
  */
 public static function preProcessKlpMemberData($member, $headerKeys)
 {
     $row = [];
     foreach ($member['properties'] as $property) {
         foreach ($headerKeys as &$headerKey) {
             //set the default value for County and Country
             $row['county'] = $row['country'] = '台灣';
             //change the value for gender
             if ($property['name'] == self::DEFAULT_PROPERTIES_GENDER) {
                 if ($property['value'] == 'male') {
                     $property['value'] = '先生';
                 } else {
                     $property['value'] = '小姐';
                 }
             }
             //modify the name,divide the name,and the result is firstName and surname
             if ($property['name'] == self::DEFAULT_PROPERTIES_NAME) {
                 list($lastName, $firstName) = StringUtil::splitName($property['value']);
                 $row['firstName'] = $firstName;
                 $row['lastName'] = $lastName;
             }
             //set the value for tel_1 and tel_2,becuse their value is equal with tel
             if ($property['name'] == self::DEFAULT_PROPERTIES_MOBILE) {
                 $row['tel_1'] = $row['tel_2'] = $property['value'];
             }
             if ($property['name'] == $headerKey) {
                 if (is_array($property['value'])) {
                     $row[$headerKey] = implode(',', $property['value']);
                 } else {
                     $row[$headerKey] = $property['value'];
                 }
             }
             //set ''
             if ($headerKey == 'tel' || $headerKey == '密碼') {
                 $row[$headerKey] = '';
             }
             //set default value;if the key value is not set,we must set the default value
             if (!isset($row[$headerKey])) {
                 $row[$headerKey] = '';
             }
         }
     }
     unset($member, $headerKeys);
     return $row;
 }