/** * @param SJB_Object $object * @return SJB_Object */ public static function fillRegistrationDataWithUser(SJB_Object $object) { if (self::$oSocialPlugin instanceof GooglePlusSocialPlugin && ($oProfile = self::getProfileObject())) { /** @var $oProperty SJB_ObjectProperty */ foreach ($object->getProperties() as $oProperty) { $value = ''; switch ($oProperty->getID()) { case 'email': if (!empty($oProfile['email']) && empty($_POST['email'])) { $value = array('original' => $oProfile['email'], 'confirmed' => $oProfile['email']); } break; case 'FirstName': if (!empty($oProfile['name']['givenName'])) { $value = $oProfile['name']['givenName']; } break; case 'LastName': if (!empty($oProfile['name']['familyName'])) { $value = $oProfile['name']['familyName']; } break; case 'ContactName': if (!empty($oProfile['name']['formatted'])) { $value = $oProfile['name']['formatted']; } break; case 'CompanyName': if (!empty($oProfile['organizations']) && !empty($oProfile['organizations'][0]['name'])) { $value = $oProfile['organizations'][0]['name']; } elseif (!empty($oProfile['nickname'])) { $value = $oProfile['nickname']; } elseif (!empty($oProfile['displayName'])) { $value = $oProfile['displayName']; } 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()); } break; } if (!empty($value)) { $reqVal = SJB_Request::getVar($oProperty->getID(), false); if (empty($reqVal)) { $object->setPropertyValue($oProperty->getID(), $value); } } } } return $object; }
/** * @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; }
/** * @param $db_table_name * @param SJB_Object $object * @param bool $sid * @param array $listingSidsForCopy * @return bool */ public static function saveObject($db_table_name, SJB_Object $object, $sid = false, $listingSidsForCopy = array()) { $object_sid = $object->getSID(); if (is_null($object_sid)) { if ($sid) { if (!SJB_DB::query("INSERT INTO ?w (sid) VALUES({$sid})", $db_table_name)) { return false; } else { $object_sid = $sid; } } elseif (!$sid && !($object_sid = SJB_DB::query("INSERT INTO ?w() VALUES()", $db_table_name))) { return false; } $object->setSID($object_sid); } if (!empty($listingSidsForCopy)) { SJB_ListingManager::copyFilesAndPicturesFromListing($listingSidsForCopy['filesFrom'], $object_sid, $listingSidsForCopy['picturesFrom']); } $object_details = $object->getDetails(); $object_properties = $object_details->getProperties(); $complexFields = array(); foreach ($object_properties as $object_property) { if (!$object_property->saveIntoBD()) { continue; } if ($object_property->isComplex()) { $complexProperties = $object_property->type->complex->getProperties(); $propertyId = $object_property->getID(); $complexFields[$propertyId] = array(); if ($complexProperties) { foreach ($complexProperties as $complexProperty) { $complexProperty->setObjectSID($object_property->object_sid); $fieldValues = $complexProperty->getValue(); if (!empty($fieldValues) && is_array($fieldValues)) { foreach ($fieldValues as $complexEnum => $value) { $complexProperty->setValue($value); $complexProperty->setComplexEnum($complexEnum); $complexProperty->setComplexParent($propertyId); $propertySqlValue = $complexProperty->getSQLValue(); $complexPropertyID = $complexProperty->getID(); $complexParameter = $complexProperty->getAddParameter(); if ($complexParameter == '') { $complexFields[$propertyId][$complexPropertyID][$complexEnum] = $propertySqlValue == 'NULL' ? NULL : $propertySqlValue; } else { $complexFields[$propertyId][$complexPropertyID][$complexEnum] = array('add_parameter' => $complexParameter, 'value' => $propertySqlValue == 'NULL' ? NULL : $propertySqlValue); } } $complexProperty->setValue($fieldValues); } } } } elseif ($object_property->isParent()) { $childProperties = $object_property->type->child->getProperties(); $parentID = $object_property->getID(); $keywords = ''; if ($childProperties) { foreach ($childProperties as $childProperty) { $childProperty->setObjectSID($object_property->object_sid); $property_id = $parentID . "_" . $childProperty->getID(); $property_sql_value = $childProperty->getSQLValue(); if ($childProperty->getID() == 'State') { $displayAS = $childProperty->display_as; $displayAS = $displayAS ? $displayAS : 'state_name'; $childProperty->type->list_values = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS); } $keywords .= $childProperty->getKeywordValue() . ' '; if (empty($property_sql_value) && in_array($childProperty->getType(), array('boolean', 'integer', 'float'))) { $property_sql_value = 0; } SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); } } $origValue = $object_property->getValue(); $object_property->setValue($keywords); $property_id = $object_property->getID(); $property_sql_value = $object_property->getSQLValue(); $object_property->setValue($origValue); SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); } else { $property_id = $object_property->getID(); $property_sql_value = $object_property->getSQLValue(); $property_sql_add_parameter = $object_property->getAddParameter(); if ($object_property->isSystem()) { if (empty($property_sql_value) && in_array($object_property->getType(), array('boolean', 'integer', 'float'))) { $property_sql_value = 0; } SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); if (!empty($property_sql_add_parameter)) { if ($object_property->getType() == 'monetary' && $object->getObjectType() != 'field') { SJB_DB::query("UPDATE `?w` SET `?w` = ?w WHERE sid = ?n", $db_table_name, $property_id . '_parameter', $property_sql_add_parameter, $object_sid); } else { SJB_DB::query("UPDATE `?w` SET `add_parameter` = ?w WHERE sid = ?n", $db_table_name, $property_sql_add_parameter, $object_sid); } } } else { if (SJB_DB::table_exists($db_table_name . "_properties")) { $property_exists = SJB_DB::queryValue("SELECT COUNT(*) FROM ?w WHERE object_sid = ?n AND id = ?s", $db_table_name . "_properties", $object_sid, $property_id); if ($property_exists) { SJB_DB::query("UPDATE ?w SET value = ?s, add_parameter = ?s WHERE object_sid = ?n AND id = ?s", $db_table_name . "_properties", $property_sql_value, $property_sql_add_parameter, $object_sid, $property_id); } else { SJB_DB::query("INSERT INTO ?w(object_sid, id , value, add_parameter) VALUES(?n, ?s, ?s, ?s)", $db_table_name . "_properties", $object_sid, $property_id, $property_sql_value, $property_sql_add_parameter); } } } } } if (!empty($complexFields)) { SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, 'complex', serialize($complexFields), $object_sid); } }
function assignTemplateVariables($params) { global $variables_to_assign; $variables_to_assign = array(); if ($this->objectHasProperty($params['property'])) { $object_property = $this->getObjectProperty($params['property']); $variables_to_assign = $object_property->getPropertyVariablesToAssign(); } if (!empty($params['complexParent'])) { $complexParent = $params['complexParent']; $object = $this->object_properties[$complexParent]->type->complex; $object_properties = $object->getProperties(); if (isset($object_properties[$params['property']])) { $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); } if (isset($params['complexStep']) && !empty($this->object_properties[$complexParent]->value)) { if (is_string($this->object_properties[$complexParent]->value)) { $complexValue = unserialize($this->object_properties[$complexParent]->value); } else { $complexValue = $this->object_properties[$complexParent]->value; } //exception for monetary type if (!isset($variables_to_assign['list_currency'])) { $variables_to_assign['value'] = ''; } if (isset($complexValue[$params['property']]) && isset($complexValue[$params['property']][$params['complexStep']])) { if ($object_properties[$params['property']]->getType() === 'date' && $object_properties[$params['property']]->type->getConvertToDBDate()) { $field = $object_properties[$params['property']]; $field->type->property_info['value'] = $complexValue[$params['property']][$params['complexStep']]; if ($field->isValid() !== true) { $complexValue[$params['property']][$params['complexStep']] = ''; } $variables_to_assign['value'] = SJB_I18N::getInstance()->getInput('date', $complexValue[$params['property']][$params['complexStep']]); } elseif ($object_properties[$params['property']]->getType() == 'monetary') { if (isset($complexValue[$params['property']][$params['complexStep']]['value'])) { $variables_to_assign['value']['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']]['value'], ENT_QUOTES, "UTF-8"); } else { $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8"); } } elseif ($object_properties[$params['property']]->getType() == 'multilist') { $value = $complexValue[$params['property']][$params['complexStep']]; if (!is_array($value) && strpos($value, ',')) { $variables_to_assign['value'] = explode(',', $value); } else { $variables_to_assign['value'] = $value; } } elseif ($object_properties[$params['property']]->getType() !== 'text') { $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8"); } else { $variables_to_assign['value'] = $complexValue[$params['property']][$params['complexStep']]; } } } } if (!empty($params['parent'])) { $parent = $params['parent']; $object = $this->object_properties[$parent]->type->child; $object_properties = $object->getProperties(); if (isset($object_properties[$params['property']])) { $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); } elseif (strpos($params['property'], '.Code')) { $params['property'] = str_replace('.Code', '', $params['property']); if (!isset($object_properties[$params['property']])) { return false; } $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); if ($params['property'] == 'State') { $country = !empty($params['country']) ? $params['country'] : false; $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_code'); } $variables_to_assign['displayAS'] = 'Code'; } else { $params['property'] = str_replace('.Name', '', $params['property']); if (!isset($object_properties[$params['property']])) { return false; } $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); if ($params['property'] == 'State') { $country = !empty($params['country']) ? $params['country'] : false; $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_name'); } $variables_to_assign['displayAS'] = 'Name'; } } if (isset($params['fields'])) { $fields = $params['fields']; $object_property = $this->getObjectProperty($params['property']); $fieldProperties = $object_property->type->child->getProperties(); foreach ($fieldProperties as $key => $property) { if (!array_key_exists($property->getSID(), $fields)) { $object_property->type->child->deleteProperty($key); } } foreach ($fields as $key => $field) { $object_property->type->child->addProperty($field); } $variables_to_assign = $object_property->getPropertyVariablesToAssign(); } if (isset($params['complexStep'])) { $variables_to_assign['complexStep'] = $params['complexStep']; } if (isset($params['parameters'])) { $variables_to_assign = array_merge($variables_to_assign, array('parameters' => $params['parameters'])); } // made for FormBuilders Complex Fields. so admin could define custom html code if (isset($params['customHtml']) && !empty($params['customHtml'])) { $variables_to_assign['customHtml'] = trim($params['customHtml']); } $variables_to_assign = array_merge($variables_to_assign, $this->getVariablesToAssign($params)); $varToAssignValueIsEmpty = $this->isEmptyVariablesToAssignValue($variables_to_assign); if (($this->useDefaultValues || !$this->object->getSID()) && $varToAssignValueIsEmpty && $this->errors === false) { if ($variables_to_assign['default_value'] != '') { if (is_array($variables_to_assign['default_value'])) { $variables_to_assign['default_value']['currency'] = $variables_to_assign['default_value']['add_parameter']; } $variables_to_assign['value'] = $variables_to_assign['default_value']; } else { if ($variables_to_assign['profile_field_as_dv'] != '') { $variables_to_assign['value'] = htmlentities($variables_to_assign['profile_field_as_dv'], ENT_QUOTES, 'UTF-8'); } } } // заглушка для email - когда в value попадает массив из одного элемента [original] if ($variables_to_assign['id'] == 'email') { if (is_array($variables_to_assign['value'])) { $variables_to_assign['value'] = array_pop($variables_to_assign['value']); } } $variables_to_assign['defaultCountry'] = SJB_Settings::getSettingByName('default_country'); if (isset($params['searchWithin'])) { $variables_to_assign['searchWithin'] = $params['searchWithin']; } if (!isset($variables_to_assign['displayAS'])) { $variables_to_assign['displayAS'] = false; } if ($variables_to_assign['id'] == 'default_value' && in_array($this->object->getProperty('default_value')->getType(), array('list', 'multilist'))) { $variables_to_assign['sort_by_alphabet'] = $this->object->getPropertyValue('sort_by_alphabet'); } foreach ($variables_to_assign as $variable_name => $variable_value) { $this->template_processor->assign($variable_name, $variable_value); } return true; }
/** * @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; }