コード例 #1
0
 /**
  * @param SJB_Object $object
  * @return SJB_Object
  */
 public static function fillRegistrationDataWithUser(SJB_Object $object)
 {
     if ($oProfile = self::getProfileObject()) {
         /** @var $oProperty SJB_ObjectProperty */
         foreach ($object->getProperties() as $oProperty) {
             $value = false;
             switch ($oProperty->getID()) {
                 case 'Country':
                 case 'CurrentCountry':
                 case 'City':
                 case 'CurrentCity':
                     if (!empty($oProfile->location) && !empty($oProfile->location['name'])) {
                         $location = explode(', ', $oProfile->location['name']);
                         if ('Country' == $oProperty->getID() || 'CurrentCountry' == $oProperty->getID()) {
                             $value = count($location) > 2 ? !empty($location[2]) ? $location[2] : '' : (!empty($location[1]) ? $location[1] : '');
                         } elseif ('City' == $oProperty->getID() || 'CurrentCity' == $oProperty->getID()) {
                             $value = !empty($location[0]) ? $location[0] : '';
                         }
                     }
                     break;
                 case 'Location':
                     $country = '';
                     $city = '';
                     if (!empty($oProfile->location) && !empty($oProfile->location['name'])) {
                         $location = explode(', ', $oProfile->location['name']);
                         $country = count($location) > 2 ? !empty($location[2]) ? $location[2] : '' : (!empty($location[1]) ? $location[1] : '');
                         $country = $country ? SJB_CountriesManager::getCountrySIDByCountryName($country) : '';
                         $city = !empty($location[0]) ? $location[0] : '';
                     }
                     $reqVal = SJB_Request::getVar($oProperty->getID(), false);
                     if (empty($reqVal)) {
                         $location = $object->getChild('Location');
                         $propertyInfo = $location->getPropertyInfo('Country');
                         if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) {
                             $location->setPropertyValue('Country', $country);
                         }
                         $propertyInfo = $location->getPropertyInfo('City');
                         if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) {
                             $location->setPropertyValue('City', $city);
                         }
                     }
                     break;
                 case 'WorkExperience':
                     if (!empty($oProfile->work)) {
                         $aWork = array();
                         foreach ($oProfile->work as $position) {
                             $work = '';
                             if (!empty($position['employer'])) {
                                 $work .= $position['employer']['name'] . "\r\n";
                             }
                             if (!empty($position['location'])) {
                                 $work .= $position['location']['name'] . "\r\n";
                             }
                             if (!empty($position['start_date'])) {
                                 $work .= $position['start_date'] . "\r\n";
                             }
                             if (!empty($position['end_date'])) {
                                 $work .= $position['end_date'] . "\r\n";
                             }
                             if (!empty($work)) {
                                 $aWork[] = $work;
                             }
                         }
                         $value = implode("\r\n", $aWork);
                     }
                     break;
                 case 'Education':
                     if (!empty($oProfile->education)) {
                         $aEducation = array();
                         foreach ($oProfile->education as $education) {
                             $sEducation = '';
                             if (!empty($education['school'])) {
                                 $sEducation = $education['school']['name'];
                             }
                             if (!empty($education['year'])) {
                                 $sEducation .= '(' . $education['year']['name'] . '):<br/>';
                             }
                             if (!empty($education['type'])) {
                                 $sEducation .= $education['type'] . "\r\n";
                             }
                             if (!empty($education['concentration'])) {
                                 foreach ($education['concentration'] as $concentration) {
                                     $sEducation .= '<br/>' . $concentration['name'] . "\r\n";
                                 }
                             }
                             if (!empty($education['classes'])) {
                                 foreach ($education['classes'] as $classes) {
                                     $sEducation .= '<br/>' . $classes['name'] . ' : ' . $classes['description'] . "\r\n";
                                 }
                             }
                             if (!empty($sEducation)) {
                                 array_push($aEducation, $sEducation);
                             }
                         }
                         $value = implode("\r\n", $aEducation);
                     }
                     break;
                 case 'Title':
                 case 'TITLE':
                     $value = 'My Resume';
                     break;
                 case 'FirstName':
                     if (!empty($oProfile->first_name)) {
                         $value = $oProfile->first_name;
                     }
                     break;
                 case 'LastName':
                     if (!empty($oProfile->last_name)) {
                         $value = $oProfile->last_name;
                     }
                     break;
                 case 'ContactName':
                     if (!empty($oProfile->name)) {
                         $value = $oProfile->name;
                     }
                     break;
                 case 'WebSite':
                     if (!empty($oProfile->website)) {
                         $value = $oProfile->website;
                     }
                     break;
                 case 'CompanyName':
                     if (!empty($oProfile->work) && !empty($oProfile->work[0]['employer']['name'])) {
                         $value = $oProfile->work[0]['employer']['name'];
                     }
                     break;
                 case 'CompanyDescription':
                     if (!empty($oProfile->summary)) {
                         $value = $oProfile->summary;
                     }
                     break;
                 case 'email':
                     if (!empty($oProfile->email) && !SJB_Request::getVar('email', null)) {
                         $value = array('original' => $oProfile->email, 'confirmed' => $oProfile->email);
                     }
                     break;
                 case 'sendmail':
                     $value = false;
                     break;
                 case 'username':
                 case 'password':
                     continue 2;
                     break;
                 default:
                     $propertyCanBeDeleted = !in_array($oProperty->getID(), self::$aUserFields) && !in_array($oProperty->getID(), self::$aListingFields) && !$oProperty->isRequired();
                     if ($propertyCanBeDeleted) {
                         $object->deleteProperty($oProperty->getID());
                         continue 2;
                     }
                     break;
             }
             if (!empty($value)) {
                 $reqVal = SJB_Request::getVar($oProperty->getID(), false);
                 if (empty($reqVal)) {
                     // if user did not modified his data in form
                     $object->setPropertyValue($oProperty->getID(), $value);
                 }
             }
         }
     }
     return $object;
 }
コード例 #2
0
 /**
  * @param SJB_Object $object
  * @return SJB_Object
  */
 public static function fillRegistrationDataWithUser(SJB_Object $object)
 {
     if (self::$oSocialPlugin instanceof LinkedinSocialPlugin && ($oProfile = self::getProfileObject())) {
         /** @var $oProperty SJB_ObjectProperty */
         foreach ($object->getProperties() as $oProperty) {
             $value = '';
             switch ($oProperty->getID()) {
                 case 'Country':
                     if (!empty($oProfile->location->country->code)) {
                         $value = SJB_Countries::getCountryNameByISO2((string) $oProfile->location->country->code);
                     }
                     break;
                 case 'Location':
                     $country = '';
                     $city = '';
                     $address = '';
                     if (!empty($oProfile->location->country->code)) {
                         $country = SJB_Countries::getCountryNameByISO2((string) $oProfile->location->country->code);
                         $country = $country ? SJB_CountriesManager::getCountrySIDByCountryName($country) : '';
                     }
                     if (!empty($oProfile->location->name)) {
                         $city = $oProfile->location->name;
                     }
                     if (!empty($oProfile->{'main-address'})) {
                         $address = $oProfile->{'main-address'};
                     }
                     $location = $object->getChild('Location');
                     $propertyInfo = $location->getPropertyInfo('Country');
                     if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) {
                         $location->setPropertyValue('Country', $country);
                     }
                     $propertyInfo = $location->getPropertyInfo('City');
                     if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) {
                         $location->setPropertyValue('City', $city);
                     }
                     $propertyInfo = $location->getPropertyInfo('Address');
                     if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) {
                         $location->setPropertyValue('Address', $address);
                     }
                     break;
                 case 'DateOfBirth':
                     if (!empty($oProfile->{'date-of-birth'})) {
                         $year = !empty($oProfile->{'date-of-birth'}->year) ? (string) $oProfile->{'date-of-birth'}->year : '0000';
                         $month = !empty($oProfile->{'date-of-birth'}->month) ? (string) $oProfile->{'date-of-birth'}->month : '00';
                         $day = !empty($oProfile->{'date-of-birth'}->day) ? (string) $oProfile->{'date-of-birth'}->day : '00';
                         $value = SJB_I18N::getInstance()->getDate($day . '-' . $month . '-' . $year);
                     }
                     break;
                 case 'FirstName':
                     if (!empty($oProfile->{'first-name'})) {
                         $value = $oProfile->{'first-name'};
                     }
                     break;
                 case 'LastName':
                     if (!empty($oProfile->{'last-name'})) {
                         $value = $oProfile->{'last-name'};
                     }
                     break;
                 case 'ContactName':
                     if (!empty($oProfile->{'last-name'})) {
                         $value = $oProfile->{'first-name'} . ' ' . $oProfile->{'last-name'};
                     }
                     break;
                 case 'WebSite':
                     // WebSite
                     if (!empty($oProfile->website)) {
                         $value = $oProfile->website;
                     }
                     break;
                 case 'Title':
                 case 'TITLE':
                     if (!empty($oProfile->positions->position->title)) {
                         $value = $oProfile->positions->position->title;
                     }
                     break;
                 case 'CompanyName':
                     if (!empty($oProfile->positions->position->company->name)) {
                         $value = $oProfile->positions->position->company->name;
                     }
                     break;
                 case 'CompanyDescription':
                     if (!empty($oProfile->summary)) {
                         $value = $oProfile->summary;
                     }
                     break;
                 case 'City':
                     if (!empty($oProfile->location->name)) {
                         $value = $oProfile->location->name;
                     }
                     break;
                 case 'PhoneNumber':
                     if (!empty($oProfile->{'phone-numbers'})) {
                         $aPhoneNumbers = array();
                         foreach (self::$oProfile->{'phone-numbers'}->{'phone-number'} as $phone) {
                             array_push($aPhoneNumbers, $phone->{'phone-number'} . ' (' . $phone->{'phone-type'} . ')');
                         }
                         $value = implode(', ', $aPhoneNumbers);
                     }
                     break;
                 case 'jsTwitter':
                     if (!empty($oProfile->{'twitter-accounts'})) {
                         $aTwitters = array();
                         foreach (self::$oProfile->{'twitter-accounts'}->{'twitter-account'} as $twitter) {
                             array_push($aTwitters, $twitter->{'provider-account-name'});
                         }
                         $value = implode(', ', $aTwitters);
                     }
                     break;
                 case 'Address':
                     if (!empty($oProfile->{'main-address'})) {
                         $value = $oProfile->{'main-address'};
                     }
                     break;
                 case 'sendmail':
                     $value = false;
                     break;
                 case 'email':
                     if (!empty($oProfile->{'email-address'}) && !SJB_Request::getVar('email', null)) {
                         $value = array('original' => $oProfile->{'email-address'}, 'confirmed' => $oProfile->{'email-address'});
                     }
                     break;
                 case 'username':
                 case 'password':
                     continue 2;
                     break;
                 default:
                     $propertyCanBeDeleted = !in_array($oProperty->getID(), self::$aUserFields) && !in_array($oProperty->getID(), self::$aListingFields) && !$oProperty->isRequired();
                     if ($propertyCanBeDeleted) {
                         $object->deleteProperty($oProperty->getID());
                     }
                     break;
             }
             if (!empty($value)) {
                 $reqVal = SJB_Request::getVar($oProperty->getID(), false);
                 if (empty($reqVal)) {
                     // if user did not modified his data in form
                     $object->setPropertyValue($oProperty->getID(), $value);
                 }
             }
         }
     }
     return $object;
 }