public static function saveListingField($listing_field, $pages = array(), $recursive = false) { $fieldID = false; $sid = $listing_field->getSID(); if ($sid) { $fieldInfo = parent::getObjectInfo('listing_fields', $sid); if (!empty($fieldInfo['id'])) { $fieldID = $fieldInfo['id']; } } parent::saveObject('listing_fields', $listing_field); $listingFieldType = $listing_field->getPropertyValue('type'); if ($listingFieldType == 'location') { if (!$sid) { $listingTypeSid = $listing_field->getPropertyValue('listing_type_sid'); $parentSid = $listing_field->getSID(); self::createFieldForLocation('Country', array('id' => 'Country', 'caption' => 'Country', 'type' => 'list'), $listingTypeSid, $parentSid); self::createFieldForLocation('State', array('id' => 'State', 'caption' => 'State', 'type' => 'list'), $listingTypeSid, $parentSid); self::createFieldForLocation('City', array('id' => 'City', 'caption' => 'City', 'type' => 'string'), $listingTypeSid, $parentSid); self::createFieldForLocation('ZipCode', array('id' => 'ZipCode', 'caption' => 'ZipCode', 'type' => 'geo'), $listingTypeSid, $parentSid); } parent::saveLocationField('listings', 'listing_fields', $listing_field, $fieldID); } else { if (!$recursive) { parent::saveField('listings', 'listing_fields', $listing_field, $fieldID); } } if ($listing_field->getOrder()) { return true; } $max_order = SJB_DB::queryValue('SELECT MAX(`order`) FROM `listing_fields` WHERE `listing_type_sid` = ?n', $listing_field->getListingTypeSID()); $max_order = empty($max_order) ? 0 : $max_order; foreach ($pages as $page) { SJB_PostingPagesManager::addListingFieldOnPage($listing_field->getSID(), $page['sid'], $page['listing_type_sid']); } return SJB_DB::query('UPDATE `listing_fields` SET `listing_type_sid` = ?n, `order` = ?n WHERE `sid` = ?n', $listing_field->getListingTypeSID(), ++$max_order, $listing_field->getSID()); }
public static function saveUserProfileField($user_profile_field, $recursive = false) { $user_group_sid = $user_profile_field->getUserGroupSID(); if ($user_group_sid) { $fieldID = false; $sid = $user_profile_field->getSID(); if ($sid) { $fieldInfo = parent::getObjectInfo('user_profile_fields', $sid); if (!empty($fieldInfo['id'])) { $fieldID = $fieldInfo['id']; } } parent::saveObject("user_profile_fields", $user_profile_field); $userFieldType = $user_profile_field->getPropertyValue('type'); if ($userFieldType == 'location') { if (!$sid) { $userProfileFeld = new SJB_UserProfileField(array('id' => 'Country', 'caption' => 'Country', 'type' => 'list')); $userProfileFeld->setUserGroupSID($user_group_sid); $userProfileFeld->addParentSID($user_profile_field->getSID()); self::saveUserProfileField($userProfileFeld, true); $userProfileFeld = new SJB_UserProfileField(array('id' => 'State', 'caption' => 'State', 'type' => 'list')); $userProfileFeld->setUserGroupSID($user_group_sid); $userProfileFeld->addParentSID($user_profile_field->getSID()); self::saveUserProfileField($userProfileFeld, true); $userProfileFeld = new SJB_UserProfileField(array('id' => 'City', 'caption' => 'City', 'type' => 'string')); $userProfileFeld->setUserGroupSID($user_group_sid); $userProfileFeld->addParentSID($user_profile_field->getSID()); self::saveUserProfileField($userProfileFeld, true); $userProfileFeld = new SJB_UserProfileField(array('id' => 'ZipCode', 'caption' => 'ZipCode', 'type' => 'geo')); $userProfileFeld->setUserGroupSID($user_group_sid); $userProfileFeld->addParentSID($user_profile_field->getSID()); self::saveUserProfileField($userProfileFeld, true); $userProfileFeld = new SJB_UserProfileField(array('id' => 'Address', 'caption' => 'Address', 'type' => 'string')); $userProfileFeld->setUserGroupSID($user_group_sid); $userProfileFeld->addParentSID($user_profile_field->getSID()); self::saveUserProfileField($userProfileFeld, true); } parent::saveLocationField("users", "user_profile_fields", $user_profile_field, $fieldID); } else { if (!$recursive) { parent::saveField("users", "user_profile_fields", $user_profile_field, $fieldID); } } if ($user_profile_field->getOrder()) { return true; } $max_order = SJB_DB::queryValue("SELECT MAX(`order`) FROM user_profile_fields WHERE user_group_sid = ?n", $user_group_sid); $next_order = $max_order + 1; return SJB_DB::query("UPDATE user_profile_fields SET user_group_sid = ?n, `order` = ?n WHERE sid = ?n", $user_group_sid, $next_order, $user_profile_field->getSID()); } return false; }