Exemple #1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo();
     $countListings = array();
     foreach ($listing_types as $type) {
         $requested_data = array();
         $requested_data['action'] = 'search';
         $requested_data['active']['equal'] = '1';
         $requested_data['listing_type']['equal'] = $type['id'];
         $requireApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($type['sid']);
         if ($requireApprove) {
             $requested_data['status']['equal'] = 'approved';
         }
         $listing = new SJB_Listing(array(), $type['sid']);
         $id_alias_info = $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $username_alias_info = $listing->addUsernameProperty();
         $listing_type_id_info = $listing->addListingTypeIDProperty();
         $listing->addCompanyNameProperty();
         if ($type['id'] == 'Resume') {
             $requested_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
         }
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($requested_data, $listing);
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($id_alias_info);
         $aliases->addAlias($username_alias_info);
         $aliases->addAlias($listing_type_id_info);
         $searcher = new SJB_ListingSearcher();
         $countListings[$type['id']] = $searcher->countRowsByCriteria($criteria, $aliases);
     }
     $tp->assign('listings_types', $countListings);
     $tp->display('count_listings.tpl');
 }
 private function getListingSidCollectionFromRequest($requested_data, $listing_type_sid, $criteria_saver)
 {
     $listing = new SJB_Listing(array(), $listing_type_sid);
     $id_alias_info = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $listing_type_id_info = $listing->addListingTypeIDProperty();
     $listing->addCompanyNameProperty();
     // select only accessible listings by user sid
     // see SearchCriterion.php, AccessibleCriterion class
     $requested_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
     $criteria = $criteria_saver->getCriteria();
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($criteria, $requested_data), $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($listing_type_id_info);
     $sortingFields = array();
     $orderInfo = $criteria_saver->getOrderInfo();
     $property = $listing->getProperty($orderInfo['sorting_field']);
     if (!empty($property) && $property->isSystem()) {
         $sortingFields = array('priority' => 'desc', $orderInfo['sorting_field'] => $orderInfo['sorting_order']);
     }
     $searcher = new SJB_ListingSearcher();
     return $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields);
 }
Exemple #3
0
 public static function createListing($listing_type_id)
 {
     $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
     $listing = new SJB_Listing(array(), $listing_type_sid);
     $listing->addUsernameProperty();
     $listing->addListingTypeIDProperty();
     $listing->addActivationDateProperty();
     $listing->addExpirationDateProperty();
     return $listing;
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $listingTypeSID = 0;
     if (isset($_REQUEST['passed_parameters_via_uri'])) {
         $params = SJB_FixedUrlParamProvider::getParams($_REQUEST);
         if ($params) {
             $listingTypeID = array_pop($params);
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
         }
     }
     if (!$listingTypeSID) {
         $errors['WRONG_LISTING_TYPE_ID_SPECIFIED'] = true;
     } else {
         $listing = new SJB_Listing(array(), $listingTypeSID);
         $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $listing->addUsernameProperty();
         $listing->addKeywordsProperty();
         $listing->addPicturesProperty();
         $listing->addListingTypeIDProperty();
         $listing->addPostedWithinProperty();
         $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid);
         $display_form = new SJB_Form($listing);
         $display_form->registerTags($tp);
         $form_fields = $display_form->getFormFieldsInfo();
         $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $tp->assign('form_fields', $form_fields);
         $tp->filterThenAssign('listing', $listing_structure);
         $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_DISPLAY, $listingTypeID);
         $formBuilder->setChargedTemplateProcessor($tp);
         $tp->assign('listingTypeInfo', SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID));
         $tp->assign('currentTheme', SJB_TemplateSupplier::getUserCurrentTheme());
     }
     $tp->assign('errors', $errors);
     $tp->display('bf_displaylisting.tpl');
 }
Exemple #5
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (isset($_REQUEST['listing_type_id'])) {
         $listing_type_id = $_REQUEST['listing_type_id'];
         SJB_Session::setValue('listing_type_id', $listing_type_id);
     } elseif (isset($_REQUEST['restore'])) {
         $listing_type_id = SJB_Session::getValue('listing_type_id');
     } else {
         SJB_Session::setValue('listing_type_id', null);
     }
     $listing_type_sid = 0;
     if (!empty($listing_type_id)) {
         $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
     }
     if (!isset($_REQUEST['listing_type']['equal']) && isset($listing_type_id)) {
         $_REQUEST['listing_type']['equal'] = $listing_type_id;
     }
     if (isset($_REQUEST['searchId'])) {
         $criteria_saver = new SJB_ListingCriteriaSaver($_REQUEST['searchId']);
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
     }
     $empty_listing = new SJB_Listing(array(), $listing_type_sid);
     $empty_listing->addIDProperty();
     $empty_listing->addActivationDateProperty();
     $empty_listing->addUsernameProperty();
     $empty_listing->addKeywordsProperty();
     $empty_listing->addPicturesProperty();
     $empty_listing->addListingTypeIDProperty();
     $empty_listing->addPostedWithinProperty();
     $search_form_builder = new SJB_SearchFormBuilder($empty_listing);
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
     $properties = $empty_listing->getProperties();
     foreach ($properties as $propertyName => $property) {
         if ($property->getType() == 'location') {
             $propertyInfo = $property->type->property_info;
             if ($propertyInfo['enable_search_by_radius'] == 1) {
                 if (!isset($criteria['system'][$propertyName])) {
                     $value = array('value' => '', 'radius' => '10');
                     $criterion = SJB_SearchCriterion::getCriterionByType('location');
                     $criterion->setProperty($property);
                     $criterion->setPropertyName($propertyName);
                     $criterion->setValue($value);
                     $criteria['system'][$propertyName][] = $criterion;
                 }
             }
         }
     }
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $form_fields = $search_form_builder->getFormFieldsInfo();
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $template = SJB_Request::getVar('form_template', 'search_form.tpl');
     $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_SEARCH, $listing_type_id);
     $formBuilder->setChargedTemplateProcessor($tp);
     if ($template == 'quick_search.tpl') {
         $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('Location');
         if ($fieldSID) {
             $fields = SJB_ListingFieldManager::getFieldInfoBySID($fieldSID);
             if (!empty($fields['fields'])) {
                 foreach ($fields['fields'] as $field) {
                     $form_fields[$fields['id'] . '_' . $field['id']] = $field;
                 }
             }
             $tp->assign('locationFields', array($fields));
         }
     }
     $tp->assign('form_fields', $form_fields);
     $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
     $tp->display($template);
 }
Exemple #6
0
 /**
  * Returns sortable properties by listing
  * @return array
  */
 private function getSortableProperties()
 {
     $emptyListing = new SJB_Listing(array(), $this->listingTypeSID);
     $emptyListing->addPicturesProperty();
     $emptyListing->addIDProperty();
     $emptyListing->addListingTypeIDProperty();
     $emptyListing->addActivationDateProperty();
     $emptyListing->addNumberOfViewsProperty();
     $emptyListing->addApplicationsProperty();
     $emptyListing->addSubuserProperty();
     $emptyListing->addActiveProperty();
     $emptyListing->addExpirationDateProperty(null);
     $sortableProperties = array();
     $propertyList = $emptyListing->getPropertyList();
     foreach ($propertyList as $property) {
         $sortableProperties[$property]['is_sortable'] = true;
     }
     return $sortableProperties;
 }
Exemple #7
0
 function _getEmptyListing()
 {
     $listing = new SJB_Listing(array(), $this->listing_type_sid);
     $listing->addPicturesProperty();
     $listing->addIDProperty();
     $listing->addListingTypeIDProperty();
     $listing->addActivationDateProperty();
     $listing->addUsernameProperty();
     $listing->addCompanyNameProperty();
     $listing->addFeaturedProperty();
     $listing->addFeaturedLastShowedProperty();
     return $listing;
 }
Exemple #8
0
 private function sendSearchedNotifications()
 {
     $savedSearches = SJB_SavedSearches::getAutoNotifySavedSearches();
     $listing = new SJB_Listing();
     $this->notifiedSavedSearchesSID = array();
     $notificationsLimit = (int) SJB_Settings::getSettingByName('num_of_listings_sent_in_email_alerts');
     foreach ($savedSearches as $savedSearch) {
         $searcher = new SJB_ListingSearcher();
         $listing->addActivationDateProperty();
         $dataSearch = unserialize($savedSearch['data']);
         $dataSearch['active']['equal'] = 1;
         $dateArray = explode('-', $savedSearch['last_send']);
         $savedSearch['last_send'] = strftime($this->lang['date_format'], mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]));
         $dataSearch['activation_date']['not_less'] = $savedSearch['last_send'];
         $dataSearch['activation_date']['not_more'] = $this->currentDate;
         $listingTypeSID = 0;
         if ($dataSearch['listing_type']['equal']) {
             $listingTypeID = $dataSearch['listing_type']['equal'];
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
             if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listingTypeSID)) {
                 $dataSearch['status']['equal'] = 'approved';
             }
         }
         $idAliasInfo = $listing->addIDProperty();
         $usernameAliasInfo = $listing->addUsernameProperty();
         $listingTypeIDInfo = $listing->addListingTypeIDProperty();
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($idAliasInfo);
         $aliases->addAlias($usernameAliasInfo);
         $aliases->addAlias($listingTypeIDInfo);
         $dataSearch['access_type'] = array('accessible' => $savedSearch['user_sid']);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($dataSearch, $listing);
         $searcher->found_object_sids = array();
         $searcher->setLimit($notificationsLimit);
         $foundListingsIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases);
         if (count($foundListingsIDs)) {
             $savedSearch['activation_date'] = $savedSearch['last_send'];
             if (SJB_Notifications::sendUserNewListingsFoundLetter($foundListingsIDs, $savedSearch['user_sid'], $savedSearch, $listingTypeSID)) {
                 SJB_Statistics::addStatistics('sentAlert', $listingTypeSID, $savedSearch['sid']);
                 SJB_DB::query('UPDATE `saved_searches` SET `last_send` = CURDATE() WHERE `sid` = ?n', $savedSearch['sid']);
             }
             $this->notifiedSavedSearchesSID[] = $savedSearch['sid'];
         }
     }
 }
Exemple #9
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $current_user = SJB_UserManager::getCurrentUser();
         if ($current_user->isSubuser()) {
             // У саб-юзера должны быть свои алерты
             $current_user = $current_user->getSubuserInfo();
         } else {
             $current_user = SJB_UserManager::getCurrentUserInfo();
         }
         $listing_type_id = '';
         /************************************************************/
         $tp = SJB_System::getTemplateProcessor();
         $tp->assign('action', 'list');
         $errors = array();
         $redirectUri = '/saved-searches/';
         if (isset($_REQUEST['is_alert'])) {
             if (isset($_REQUEST['listing_type_id'])) {
                 $listing_type_id = $_REQUEST['listing_type_id'];
                 SJB_Session::setValue('listing_type_id', $listing_type_id);
             } elseif (isset($_REQUEST['restore'])) {
                 $listing_type_id = SJB_Session::getValue('listing_type_id');
             } else {
                 SJB_Session::setValue('listing_type_id', null);
             }
             if (!SJB_Acl::getInstance()->isAllowed("use_{$listing_type_id}_alerts")) {
                 $errors = array('NOT_SUBSCRIBE' => true);
                 $tp->assign('ERRORS', $errors);
                 $tp->display('error.tpl');
                 return;
             } else {
                 $redirectUri = '/' . strtolower($listing_type_id) . '-alerts/';
             }
         } else {
             if (isset($_REQUEST['listing_type_id'])) {
                 $listing_type_id = $_REQUEST['listing_type_id'];
             }
             if (!SJB_Acl::getInstance()->isAllowed('save_searches')) {
                 $errors = array('NOT_SUBSCRIBE' => true);
                 $tp->assign('ERRORS', $errors);
                 $tp->display('error.tpl');
                 return;
             }
         }
         $isSubmittedForm = SJB_Request::getVar('submit', false);
         $listing_type_sid = !empty($listing_type_id) ? SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id) : 0;
         if (!isset($_REQUEST['listing_type']['equal']) && isset($listing_type_id)) {
             $_REQUEST['listing_type']['equal'] = $listing_type_id;
         }
         $action = SJB_Request::getVar('action', 'list');
         switch ($action) {
             case 'save':
                 if ($isSubmittedForm) {
                     $search_name = SJB_Request::getVar('name');
                     $emailFrequency = SJB_Request::getVar('email_frequency');
                     if (empty($search_name['equal'])) {
                         $errors['EMPTY_VALUE'] = 1;
                         $tp->assign('action', 'save');
                     } else {
                         unset($_REQUEST['name']);
                         unset($_REQUEST['email_frequency']);
                         if ($emailFrequency) {
                             $emailFrequency = array_pop($emailFrequency);
                             $emailFrequency = '&email_frequency=' . array_pop($emailFrequency);
                         } else {
                             $emailFrequency = '';
                         }
                         $search_name = $search_name['equal'];
                         $searchResultsTP = new SJB_SearchResultsTP($_REQUEST, $listing_type_id);
                         $tp = $searchResultsTP->getChargedTemplateProcessor();
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/save-search/?alert=true&url=' . $redirectUri . '&action=save&search_name=' . $search_name . '&searchId=' . $searchResultsTP->searchId . $emailFrequency);
                     }
                 } else {
                     $tp->assign('action', 'save');
                 }
                 break;
             case 'edit':
                 if (isset($_REQUEST['id_saved'])) {
                     if ($isSubmittedForm) {
                         $id_saved = $_REQUEST['id_saved'];
                         $name = $_REQUEST['name'];
                         $search_name = SJB_Request::getVar('name');
                         $emailFrequency = SJB_Request::getVar('email_frequency');
                         if (empty($search_name['equal'])) {
                             $errors['EMPTY_VALUE'] = 1;
                         } else {
                             unset($_REQUEST['name']);
                             unset($_REQUEST['email_frequency']);
                             if ($emailFrequency) {
                                 $emailFrequency = array_pop($emailFrequency);
                                 $emailFrequency = array_pop($emailFrequency);
                             } else {
                                 $emailFrequency = 'daily';
                             }
                             $searchResultsTP = new SJB_SearchResultsTP($_REQUEST, $listing_type_id);
                             $tp = $searchResultsTP->getChargedTemplateProcessor();
                             $criteria_saver = new SJB_ListingCriteriaSaver($searchResultsTP->searchId);
                             $requested_data = $criteria_saver->getCriteria();
                             SJB_SavedSearches::updateSearchOnDB($requested_data, $id_saved, $current_user['sid'], $name['equal'], $emailFrequency);
                         }
                         if (!empty($errors)) {
                             $tp->assign('action', 'edit');
                             $tp->assign('id_saved', $_REQUEST['id_saved']);
                         } else {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . $redirectUri . '?alert=is_update');
                         }
                     } else {
                         $tp->assign('action', 'edit');
                         $tp->assign('id_saved', $_REQUEST['id_saved']);
                     }
                 }
                 break;
             case 'edit_alert':
                 $tp->assign('action', 'edit');
                 $tp->assign('id_saved', $_REQUEST['id_saved']);
                 break;
             case 'edit_search':
                 $tp->assign('action', 'edit');
                 $tp->assign('id_saved', $_REQUEST['id_saved']);
                 $_REQUEST['form_template'] = SJB_Request::getVar('formTemplateNem');
                 break;
             case 'new':
                 $tp->assign('action', 'save');
                 break;
             case 'delete':
                 if (isset($_REQUEST['search_id'])) {
                     $search_id = $_REQUEST['search_id'];
                     SJB_SavedSearches::deleteSearchFromDBBySID($search_id);
                 }
                 break;
             case 'disable_notify':
                 if (isset($_REQUEST['search_id'])) {
                     SJB_SavedSearches::disableSearchAutoNotify($current_user['sid'], $_REQUEST['search_id']);
                 }
                 break;
             case 'enable_notify':
                 if (isset($_REQUEST['search_id'])) {
                     SJB_SavedSearches::enableSearchAutoNotify($current_user['sid'], $_REQUEST['search_id']);
                 }
                 break;
         }
         if ($action != 'new' && $action != 'edit_alert') {
             $saved_searches = SJB_SavedSearches::getSavedSearchesFromDB($current_user['sid']);
             if (isset($_REQUEST['is_alert'])) {
                 $saved_searches = SJB_SavedSearches::getSavedJobAlertFromDB($current_user['sid']);
             }
             foreach ($saved_searches as $key => $saved_search) {
                 $saved_searches[$key]['data'] = SJB_SavedSearches::buildCriteriaFields($saved_search['data']);
                 if (isset($saved_search['data']['listing_type']['equal'])) {
                     $saved_searches[$key]['listing_type'] = $saved_search['data']['listing_type']['equal'];
                 }
             }
             $tp->assign('saved_searches', $saved_searches);
         }
         $listing = new SJB_Listing(array(), $listing_type_sid);
         $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $listing->addUsernameProperty();
         $listing->addKeywordsProperty();
         $listing->addPicturesProperty();
         $listing->addEmailFrequencyProperty();
         $listing->addListingTypeIDProperty();
         $listing->addPostedWithinProperty();
         $search_form_builder = new SJB_SearchFormBuilder($listing);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
         $search_form_builder->setCriteria($criteria);
         $search_form_builder->registerTags($tp);
         $form_fields = $search_form_builder->getFormFieldsInfo();
         $tp->assign('form_fields', $form_fields);
         if (!empty($_REQUEST['name'])) {
             $tp->assign('search_name', $_REQUEST['name']);
         }
         if (!empty($_REQUEST['email_frequency'])) {
             $tp->assign('email_frequency', $_REQUEST['email_frequency']);
         }
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $form_template = SJB_Request::getVar('form_template', 'search_form.tpl');
         switch (SJB_Request::getVar('alert')) {
             case 'added':
                 $tp->assign('alert_added', 'added');
                 break;
             case 'is_update':
                 $tp->assign('alert_update', 'update');
                 break;
         }
         if (!$listing_type_id && isset($saved_search['data']['listing_type']['equal'])) {
             $listing_type_id = $saved_search['data']['listing_type']['equal'];
         }
         $tp->assign('errors', $errors);
         $tp->assign('user_logged_in', true);
         $tp->assign('listing_type_id', $listing_type_id);
         $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_SEARCH, $listing_type_id);
         $formBuilder->setChargedTemplateProcessor($tp);
         $tp->display($form_template);
     } else {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
 }
Exemple #10
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;
 }