Ejemplo n.º 1
0
 public static function getFieldBySID($listing_field_sid)
 {
     $listing_field_info = SJB_ListingFieldDBManager::getListingFieldInfoBySID($listing_field_sid, 'listing_complex_fields');
     if (empty($listing_field_info)) {
         return null;
     } else {
         $listing_field = new SJB_ListingField($listing_field_info);
         $listing_field->setSID($listing_field_sid);
         return $listing_field;
     }
 }
Ejemplo n.º 2
0
 public static function getPropertyByParentID($parentID, $fieldID, $listing_type_sid = 0)
 {
     $parentSID = SJB_ListingFieldManager::getListingFieldSIDByID($parentID);
     $fields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($parentSID);
     $fieldSID = null;
     foreach ($fields as $field) {
         if ($field['id'] == $fieldID) {
             $fieldSID = $field['sid'];
         }
     }
     if ($fieldSID) {
         $property_info = SJB_ListingFieldDBManager::getListingFieldInfoBySID($fieldSID);
         $property_info['id'] = $parentID . "_" . $property_info['id'];
         $fieldID = $property_info['id'];
         return new SJB_ObjectProperty($property_info);
     }
     return null;
 }
Ejemplo n.º 3
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'list');
     $fieldSID = SJB_Request::getVar('field_sid', false);
     $parentSID = SJB_Request::getVar('sid', false);
     $errors = null;
     if ($fieldSID) {
         $tp->assign('field_sid', $fieldSID);
         $field_info = SJB_ListingFieldManager::getFieldInfoBySID($fieldSID);
         $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($field_info['listing_type_sid']);
         $tp->assign("field_info", $field_info);
         $tp->assign("type_info", $listing_type_info);
         $tp->assign("type_sid", isset($listing_type_info['sid']) ? $listing_type_info['sid'] : false);
         switch ($action) {
             case 'edit':
                 $form_submitted = SJB_Request::getVar('submit_form', false);
                 $sid = SJB_Request::getVar('sid', 0);
                 $listingFieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoBySID($sid);
                 $listingFieldInfo = array_merge($listingFieldInfo, $_REQUEST);
                 $listingField = new SJB_ListingField($listingFieldInfo);
                 $listingField->deleteProperty('type');
                 $listingField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($listingFieldInfo['hidden']) ? $listingFieldInfo['hidden'] : '', 'is_system' => true));
                 $profileField = SJB_Request::getVar('profile_field', false);
                 if ($form_submitted) {
                     if ($profileField) {
                         $listingFieldInfo['default_value'] = '';
                         $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id'];
                     } else {
                         $listingFieldInfo['profile_field_as_dv'] = '';
                     }
                 }
                 if (!empty($listingFieldInfo['default_value_setting'])) {
                     if ($listingFieldInfo['default_value_setting'] == 'default_country') {
                         $listingFieldInfo['default_value'] = $listingFieldInfo['default_value_setting'];
                         $listingFieldInfo['profile_field_as_dv'] = '';
                     } elseif ($listingFieldInfo['default_value_setting'] == 'profile_field') {
                         $listingFieldInfo['default_value'] = '';
                         $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id'];
                     }
                 }
                 $additionalParameters = array();
                 if ($listingFieldInfo['id'] == 'Country') {
                     $additionalParameters = array('list_values' => SJB_CountriesManager::getAllCountriesCodesAndNames());
                     $display_as = array('id' => 'display_as', 'caption' => 'Display Country as', 'type' => 'list', 'value' => isset($listingFieldInfo['display_as']) ? $listingFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'country_name', 'caption' => 'Country Name'), array('id' => 'country_code', 'caption' => 'Country Code')), 'is_system' => true, 'is_required' => true);
                 } elseif ($listingFieldInfo['id'] == 'State') {
                     $defaultCountry = SJB_ListingFieldManager::getDefaultCountryByParentSID($fieldSID);
                     $additionalParameters['list_values'] = array();
                     if (is_numeric($defaultCountry)) {
                         $additionalParameters['list_values'] = SJB_StatesManager::getStatesNamesByCountry($defaultCountry);
                     } elseif (!empty($defaultCountry)) {
                         $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id'];
                         $tp->assign('disableField', 1);
                     } else {
                         $additionalParameters['comment'] = 'Please select default country first to select default State';
                     }
                     $display_as = array('id' => 'display_as', 'caption' => 'Display State as', 'type' => 'list', 'value' => isset($listingFieldInfo['display_as']) ? $listingFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'state_name', 'caption' => 'State Name'), array('id' => 'state_code', 'caption' => 'State Code')), 'is_system' => true, 'is_required' => true);
                 }
                 $default_value = array('id' => 'default_value', 'sid' => isset($listingFieldInfo['sid']) ? $listingFieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['default_value']) ? $listingFieldInfo['default_value'] : '', 'type' => $listingField->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($listingFieldInfo['add_parameter']) ? $listingFieldInfo['add_parameter'] : '');
                 $default_value = array_merge($default_value, $additionalParameters);
                 $listingField->addProperty($default_value);
                 $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['profile_field_as_dv']) ? $listingFieldInfo['profile_field_as_dv'] : '', 'type' => 'list', 'length' => '', 'is_required' => false, 'is_system' => true);
                 $listingField->addProperty($profile_field_as_dv);
                 if (isset($display_as)) {
                     $listingField->addProperty($display_as);
                 }
                 if ($form_submitted) {
                     $listingField->addInfillInstructions(SJB_Request::getVar('instructions'));
                 } else {
                     $listingField->addInfillInstructions(isset($listingFieldInfo['instructions']) ? $listingFieldInfo['instructions'] : '');
                 }
                 $ListingFieldForm = new SJB_Form($listingField);
                 $ListingFieldForm->registerTags($tp);
                 $listingField->setSID($sid);
                 $addValidParam = array('field' => 'parent_sid', 'value' => $parentSID);
                 if ($form_submitted && $ListingFieldForm->isDataValid($errors, $addValidParam)) {
                     SJB_ListingFieldManager::saveListingField($listingField);
                     if ($listingFieldInfo['id'] == 'Country') {
                         $profileFieldAsDv = $listingField->getPropertyValue('profile_field_as_dv');
                         if ($profileFieldAsDv) {
                             $listingFieldsInfo = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($fieldSID);
                             foreach ($listingFieldsInfo as $fieldInfo) {
                                 if ($fieldInfo['id'] == 'State') {
                                     $listingField = new SJB_ListingField($fieldInfo);
                                     $listingField->setSID($fieldInfo['sid']);
                                     $default_value = array('id' => 'default_value', 'sid' => isset($fieldInfo['sid']) ? $fieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => '', 'type' => $listingField->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($fieldInfo['add_parameter']) ? $fieldInfo['add_parameter'] : '');
                                     $listingField->addProperty($default_value);
                                     $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => 'State', 'type' => 'list', 'length' => '', 'is_required' => false, 'is_system' => true);
                                     $listingField->addProperty($profile_field_as_dv);
                                     SJB_ListingFieldManager::saveListingField($listingField);
                                 }
                             }
                         }
                     }
                     if (SJB_Request::getVar('apply') == 'no' && empty($errors)) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-listing-field/edit-location-fields/?field_sid=" . $fieldSID);
                     }
                 }
                 $ListingFieldForm->makeDisabled('id');
                 $tp->assign('profileFieldAsDV', !empty($listingFieldInfo['profile_field_as_dv']));
                 $tp->assign('listingFieldInfo', $listingFieldInfo);
                 $tp->assign("field_type", $listingField->getFieldType());
                 $tp->assign("sid", $sid);
                 $tp->assign("form_fields", $ListingFieldForm->getFormFieldsInfo());
                 $tp->assign("errors", $errors);
                 $tp->display("edit_location_field.tpl");
                 break;
             case 'move_up':
                 SJB_ListingFieldManager::moveUpFieldBySID($fieldSID);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-location-fields/?field_sid=" . $parentSID);
                 break;
             case 'move_down':
                 SJB_ListingFieldManager::moveDownFieldBySID($fieldSID);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-location-fields/?field_sid=" . $parentSID);
                 break;
         }
         if ($action == 'list') {
             $listingFieldsInfo = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($fieldSID);
             $listingFields = array();
             $listingFieldSids = array();
             foreach ($listingFieldsInfo as $listingFieldInfo) {
                 $listingField = new SJB_ListingField($listingFieldInfo);
                 $listingField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($listingFieldInfo['hidden']) ? $listingFieldInfo['hidden'] : '', 'is_system' => true));
                 $listingField->setSID($listingFieldInfo['sid']);
                 $listingFields[] = $listingField;
                 $listingFieldSids[] = $listingFieldInfo['sid'];
             }
             $form_collection = new SJB_FormCollection($listingFields);
             $form_collection->registerTags($tp);
             $tp->assign("listing_field_sids", $listingFieldSids);
             $tp->display("listing_location_fields.tpl");
         }
     }
 }
Ejemplo n.º 4
0
 public static function getListingFieldsInfoByListingType($listing_type_sid, $pageID = 0)
 {
     $sids = SJB_ListingFieldDBManager::getListingFieldsValue($listing_type_sid, 'listing_type_sid', $pageID);
     $listing_fields_info = array();
     $i = 0;
     foreach ($sids as $sid) {
         $listing_fields_info[$i] = SJB_ListingFieldDBManager::getListingFieldInfoBySID($sid['sid']);
         $listing_fields_info[$i]['order'] = isset($sid['order']) ? $sid['order'] : $listing_fields_info[$i]['order'];
         $listing_fields_info[$i]['is_classifieds'] = 1;
         $i++;
     }
     return $listing_fields_info;
 }
Ejemplo n.º 5
0
 public static function getAllFieldsByPageSID($pageSID)
 {
     $fields = SJB_DB::query('SELECT * FROM `relations_listing_fields_posting_pages` WHERE `page_sid`=?n ORDER BY `order`', $pageSID);
     $listingFieldsInfo = array();
     foreach ($fields as $field) {
         $listingFieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoBySID($field['field_sid']);
         $listingFieldInfo['relationId'] = $field['sid'];
         $listingFieldsInfo[] = $listingFieldInfo;
     }
     return $listingFieldsInfo;
 }
Ejemplo n.º 6
0
 /**
  * @param $fieldName
  * @param $fieldID
  * @param SJB_SearchResultsTP $stp
  * @param $userField
  * @return mixed
  */
 public static function countListingsByFieldName($fieldName, $fieldID, $stp, $userField)
 {
     $refineSearchLimit = SJB_Settings::getSettingByName('refine_search_items_limit');
     $limit = $refineSearchLimit ? ' LIMIT 0, ' . $refineSearchLimit : '';
     $listing = new SJB_Listing(array(), $stp->listing_type_sid);
     $id_alias_info = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $listing->addFeaturedProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $listing_type_id_info = $listing->addListingTypeIDProperty();
     $listing->addCompanyNameProperty();
     $requestedCriteria = $stp->criteria_saver->getCriteria();
     if (isset($requestedCriteria['PostedWithin']) && $requestedCriteria['PostedWithin']['multi_like'][0] != '') {
         $within_period = $requestedCriteria['PostedWithin']['multi_like'][0];
         $i18n = SJB_I18N::getInstance();
         $requestedCriteria['activation_date']['not_less'] = $i18n->getDate(date('Y-m-d', strtotime("- {$within_period} days")));
         unset($requestedCriteria['PostedWithin']);
     }
     if (isset($requestedCriteria['CompanyName']['multi_like_and'][0])) {
         $userName = SJB_UserManager::getUserNameByCompanyName($requestedCriteria['CompanyName']['multi_like_and'][0]);
         unset($requestedCriteria['CompanyName']);
         if ($userName) {
             $requestedCriteria['username']['equal'] = $userName;
         }
     }
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($requestedCriteria, $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($listing_type_id_info);
     $aliases->changeAliasValuesInCriteria($criteria);
     $sqlTranslator = new SJB_SearchSqlTranslator('listings');
     $whereStatement = $sqlTranslator->_getWhereStatement($criteria);
     $objectSids = implode(',', $stp->found_listings_sids);
     if ($userField == 1) {
         $field = SJB_UserProfileFieldManager::getFieldInfoBySID($fieldID);
     } else {
         $field = SJB_ListingFieldDBManager::getListingFieldInfoBySID($fieldID);
     }
     $result = array();
     $cache = SJB_Cache::getInstance();
     if (!empty($field['parent_sid'])) {
         $parentInfo = SJB_ListingFieldManager::getFieldInfoBySID($field['parent_sid']);
         $fieldName = $parentInfo['id'] . "_" . $fieldName;
         $field['id'] = $fieldName;
         $field['parentID'] = $parentInfo['id'];
     }
     switch ($field['type']) {
         case 'list':
         case 'multilist':
             if ($userField == 1) {
                 $query = "SELECT up.`{$fieldName}` as caption, count(`listings`.`sid`) as count\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t INNER JOIN `users` `up` ON `listings`.`user_sid` = `up`.`sid`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t {$whereStatement}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND up.`{$fieldName}` != ''\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t GROUP BY `up`.`{$fieldName}` ORDER BY count DESC";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_USERS));
                 }
             } else {
                 $query = "SELECT `{$fieldName}` as caption, count(`{$fieldName}`) as count FROM `listings` {$whereStatement} AND `{$fieldName}` != '' GROUP BY `{$fieldName}` ORDER BY count DESC";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS));
                 }
             }
             self::breakMultiCategory($result);
             $newResult = array();
             $listItem = new SJB_ListingFieldListItemManager();
             foreach ($result as $key => $val) {
                 if (!empty($field['parent_sid'])) {
                     $caption = '';
                     if ($field['id'] == $field['parentID'] . '_State') {
                         $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $field['display_as']);
                     } else {
                         $listValues = $field['list_values'];
                     }
                     foreach ($listValues as $listValue) {
                         if ($listValue['id'] == $val['caption']) {
                             $caption = $listValue['caption'];
                             break;
                         }
                     }
                 } else {
                     $itemInfo = $listItem->getListItemBySID($val['caption']);
                     $caption = $itemInfo ? $itemInfo->getValue() : null;
                 }
                 if ($caption != null) {
                     $newResult[$key]['count'] = $val['count'];
                     $newResult[$key]['value'] = $caption;
                     $newResult[$key]['sid'] = $val['caption'];
                 }
             }
             arsort($newResult);
             $result = $newResult;
             if (count($result) > $refineSearchLimit) {
                 $result = array_slice($result, 0, $refineSearchLimit);
             }
             break;
         case 'tree':
             $query = "SELECT `lt`.`sid` as `sid`, `lt`.`caption` as `value`, count(`listings`.`sid`) as `count`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `listing_field_tree` `lt` ON `lt`.`field_sid` = {$field['sid']} AND find_in_set(`lt`.`sid`, `listings`.`{$fieldName}`)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$whereStatement} GROUP BY `lt`.`sid` having `lt`.`sid` IS NOT NULL ORDER BY `count` DESC {$limit}";
             if (!($propertyValue = $cache->load(md5($query)))) {
                 $propertyValue = SJB_DB::query($query);
                 $cache->save($propertyValue, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_FIELDS));
             }
             foreach ($propertyValue as $value) {
                 $result[$value['sid']] = $value;
             }
             break;
         default:
             if ($userField == 1) {
                 $companyColumn = "up.`{$fieldName}`";
                 $query = "SELECT {$companyColumn} as `value`, count(listings.`sid`) as `count`\n\t\t\t\t\t\t\t\t\t\t\t FROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t INNER JOIN `users` `up` ON `listings`.`user_sid` = `up`.`sid`\n\t\t\t\t\t\t\t\t\t\t\t {$whereStatement}\n\t\t\t\t\t\t\t\t\t\t\t GROUP BY {$companyColumn} ORDER BY `count` DESC {$limit}";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_USERS));
                 }
             } else {
                 if ($field['type'] == 'complex') {
                     $query = "SELECT `value`, count(`value`) as count FROM `listings_properties` WHERE `id`='{$fieldName}' AND `value` != '' AND `object_sid` in ({$objectSids}) GROUP BY `value` ORDER BY count DESC {$limit}";
                 } else {
                     $query = "SELECT `{$fieldName}` as value, count(`{$fieldName}`) as count FROM `listings` {$whereStatement} AND `{$fieldName}` != '' GROUP BY `{$fieldName}` ORDER BY count DESC {$limit}";
                 }
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS));
                 }
             }
             break;
     }
     $returnArr['caption'] = $field['caption'];
     $returnArr['values'] = $result;
     return $returnArr;
 }