Ejemplo n.º 1
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $errors = array();
     $ListingFieldListItemManager = new SJB_ListingFieldListItemManager();
     if (!isset($_REQUEST['field_sid'], $_REQUEST['item_sid'])) {
         echo 'The system cannot proceed as some key paramaters are missed';
     } else {
         if (is_null($list_item = $ListingFieldListItemManager->getListItemBySID($_REQUEST['item_sid']))) {
             echo 'Wrong parameters are specified';
         } else {
             $list_item_info['value'] = $list_item->getValue();
             $template_processor->assign("list_item_info", $list_item_info);
             $form_submitted = SJB_Request::getVar('action', '');
             if ($form_submitted) {
                 if (empty($_REQUEST['list_item_value'])) {
                     $errors = array('Value' => 'EMPTY_VALUE');
                 } else {
                     $list_item->setValue(trim($_REQUEST['list_item_value']));
                     $ListingFieldListItemManager->saveListItem($list_item);
                     if ($form_submitted == 'save') {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-list/?field_sid=" . $_REQUEST['field_sid']);
                     }
                 }
             }
             $listing_field = SJB_ListingFieldManager::getFieldBySID($_REQUEST['field_sid']);
             $listing_field_info = SJB_ListingFieldManager::getFieldInfoBySID($_REQUEST['field_sid']);
             $template_processor->assign("listing_field_info", $listing_field_info);
             $template_processor->assign("listing_type_sid", $listing_field->getListingTypeSID());
             $template_processor->assign("field_sid", $_REQUEST['field_sid']);
             $template_processor->assign("item_sid", $_REQUEST['item_sid']);
             $template_processor->assign("list_item_value", htmlspecialchars($list_item->getValue()));
             $template_processor->assign("errors", $errors);
             $template_processor->assign("listing_type_info", SJB_ListingTypeManager::getListingTypeInfoBySID($listing_field->getListingTypeSID()));
             $template_processor->display("listing_list_item_editing.tpl");
         }
     }
 }
Ejemplo n.º 2
0
 private function UpdateListValues($listing)
 {
     $list_properties = array();
     $details = $listing->getDetails();
     $properties = $details->getProperties();
     foreach ($properties as $property) {
         if ($property->getType() == 'list') {
             $list_properties[$property->getID()] = $property;
         }
     }
     $listingFieldListItemManager = new SJB_ListingFieldListItemManager();
     foreach ($list_properties as $property) {
         $property_sid = $property->getSID();
         $property_value = $property->getValue();
         if (!empty($property_value)) {
             $list_item = $listingFieldListItemManager->getListItemByValue($property->getSID(), $property->getValue());
             if (empty($list_item)) {
                 $list_item = new SJB_ListItem();
                 $list_item->setFieldSID($property_sid);
                 $list_item->setValue($property_value);
                 $listingFieldListItemManager->saveListItem($list_item);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public static function getListValuesBySID($listing_field_sid)
 {
     $ListingFieldListItemManager = new SJB_ListingFieldListItemManager();
     $values = $ListingFieldListItemManager->getHashedListItemsByFieldSID($listing_field_sid);
     $field_values = array();
     foreach ($values as $key => $value) {
         $field_values[] = array('id' => $key, 'caption' => $value);
     }
     return $field_values;
 }
Ejemplo n.º 4
0
 public static function getCurrentSearchByCriteria($criteria)
 {
     $returnArray = array();
     $locationFields = SJB_ListingFieldManager::getFieldsInfoByType('location');
     foreach ($criteria as $fieldName => $field) {
         if (!in_array($fieldName, array('listing_type', 'active', 'username', 'status', 'CompanyName', 'keywords', 'PostedWithin', 'anonymous'))) {
             $result = array();
             $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldName);
             if (!$fieldInfo) {
                 foreach ($locationFields as $locationField) {
                     $locationSubFields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($locationField['sid']);
                     foreach ($locationSubFields as $locationSubField) {
                         if ($fieldName == $locationField['id'] . "_" . $locationSubField['id']) {
                             $fieldInfo = $locationSubField;
                             $fieldInfo['id'] = $locationField['id'] . "_" . $locationSubField['id'];
                         }
                     }
                 }
             }
             foreach ($field as $fieldType => $fieldValue) {
                 switch ($fieldType) {
                     case 'geo':
                         if ($fieldValue['location'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['location']] = $fieldValue['location'];
                         }
                         break;
                     case 'location':
                         if (!empty($fieldValue['value'])) {
                             $result[$fieldName][$fieldType][$fieldValue['value']] = $fieldValue['value'];
                         }
                         break;
                     case 'monetary':
                         if (!empty($fieldValue['not_less']) && $fieldValue['not_less'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['not_less']] = $fieldValue['not_less'];
                         }
                         if (!empty($fieldValue['not_more']) && $fieldValue['not_more'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['not_more']] = $fieldValue['not_more'];
                         }
                         break;
                     case 'multi_like':
                         $listItem = new SJB_ListingFieldListItemManager();
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     if ($fieldInfo['type'] == 'tree') {
                                         $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                         $name = $name ? $name : '';
                                         $result[$fieldName][$fieldType][$value] = $name;
                                     } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') {
                                         if (!empty($fieldInfo['parent_sid'])) {
                                             if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') {
                                                 $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']);
                                             } else {
                                                 $listValues = $fieldInfo['list_values'];
                                             }
                                             foreach ($listValues as $listValue) {
                                                 if ($listValue['id'] == $value) {
                                                     $result[$fieldName][$fieldType][$value] = $listValue['caption'];
                                                     break;
                                                 }
                                             }
                                         } else {
                                             $itemInfo = $listItem->getListItemBySID($value);
                                             $caption = $itemInfo ? $itemInfo->getValue() : $value;
                                             $result[$fieldName][$fieldType][$value] = $caption;
                                         }
                                     } else {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $itemInfo = $listItem->getListItemBySID($fieldValue);
                             $caption = $itemInfo ? $itemInfo->getValue() : $fieldValue;
                             $result[$fieldName][$fieldType][$fieldValue] = $caption;
                         }
                         break;
                     case 'tree':
                         $fieldValue = $fieldValue ? explode(',', $fieldValue) : "";
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                     $name = $name ? $name : '';
                                     $result[$fieldName][$fieldType][$value] = $name;
                                 }
                             }
                         }
                         break;
                     case 'multi_like_and':
                         if (is_array($fieldValue)) {
                             $listItem = new SJB_ListingFieldListItemManager();
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     if ($fieldInfo['type'] == 'tree') {
                                         $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                         $name = $name ? $name : '';
                                         $result[$fieldName][$fieldType][$value] = $name;
                                     } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') {
                                         if (!empty($fieldInfo['parent_sid'])) {
                                             if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') {
                                                 $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']);
                                             } else {
                                                 $listValues = $fieldInfo['list_values'];
                                             }
                                             foreach ($listValues as $listValue) {
                                                 if ($listValue['id'] == $value) {
                                                     $result[$fieldName][$fieldType][$value] = $listValue['caption'];
                                                     break;
                                                 }
                                             }
                                         } else {
                                             $itemInfo = $listItem->getListItemBySID($value);
                                             $caption = $itemInfo ? $itemInfo->getValue() : $value;
                                             $result[$fieldName][$fieldType][$value] = $caption;
                                         }
                                     } else {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                         }
                         break;
                     default:
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     $result[$fieldName][$fieldType][$value] = $value;
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                         }
                         break;
                 }
             }
             if ($result && !empty($fieldInfo)) {
                 $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption'];
                 $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']];
             }
         } elseif ($fieldName == 'CompanyName') {
             $result = array();
             $userFieldSID = SJB_DB::queryValue("SELECT `sid` FROM `user_profile_fields` WHERE `id` = 'CompanyName'");
             if ($userFieldSID) {
                 $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($userFieldSID);
                 foreach ($field as $fieldType => $fieldValue) {
                     switch ($fieldType) {
                         case 'multi_like_and':
                             if (is_array($fieldValue)) {
                                 foreach ($fieldValue as $value) {
                                     if ($value !== '') {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             } elseif ($fieldValue !== '') {
                                 $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                             }
                             break;
                     }
                 }
             }
             if ($result && !empty($fieldInfo)) {
                 $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption'];
                 $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']];
             }
         } elseif ($fieldName == 'keywords') {
             foreach ($field as $key => $val) {
                 if ($val) {
                     $returnArray['keywords']['field'][$key][$val] = $val;
                 }
             }
             if (isset($returnArray['keywords'])) {
                 $returnArray['keywords']['name'] = 'Keywords';
             }
         }
     }
     return $returnArray;
 }