function _changeCriterionType($criterion, $new_type) { $new_criterion = SJB_SearchCriterion::getCriterionByType($new_type); $new_criterion->setProperty($criterion->getProperty()); $new_criterion->setPropertyName($criterion->getPropertyName()); $new_criterion->setValue($criterion->getRawValue()); $new_criterion->setFieldValue($criterion->getFieldValue()); return $new_criterion; }
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); }
public static function extractCriteriaFromRequestData($request_data, $object = null) { $criteria = array('system' => array(), 'common' => array()); foreach ($request_data as $property_name => $criteria_data) { if (is_array($criteria_data)) { foreach ($criteria_data as $criterion_type => $criterion_value) { $criterion = SJB_SearchCriterion::getCriterionByType($criterion_type); if (!is_null($criterion)) { if (!empty($object)) { $object_details = $object->getDetails(); $object_properties = $object_details->getProperties(); } $property = isset($object_properties[$property_name]) ? $object_properties[$property_name] : null; if (empty($property) && !empty($object)) { foreach ($object_properties as $objectProperty) { if ($objectProperty->isComplex()) { $object_properties = $objectProperty->type->complex->getProperties(); $propertyNameWithoutParent = str_replace($objectProperty->getID() . ':', '', $property_name); if (isset($object_properties[$propertyNameWithoutParent])) { $property = $objectProperty; break; } } } } $property_is_system = SJB_ListingManager::propertyIsSystem($property_name) || !empty($property) && $property->isSystem(); //*** integer, float, date i18n transformation if (empty($property)) { $property = SJB_ListingManager::getPropertyByPropertyName($property_name); } if (!empty($property) && preg_match("/integer|float|date/i", $property->getType())) { $property->setValue($criterion_value); if ($property->isValid()) { $criterion_value = $property->getValue(); } } //*** ---------------------------------------- $criterion->setProperty($property); $criterion->setPropertyName($property_name); $criterion->setValue($criterion_value); if ($property_is_system) { $criteria['system'][$property_name][] = $criterion; } else { $criteria['common'][$property_name][] = $criterion; } } } } } return $criteria; }
function getSystemSQL($table = '') { if (!$this->isValid() || !is_array($this->value)) { return null; } $sql = array(); foreach ($this->value as $fieldName => $fieldValue) { foreach ($fieldValue as $criteriaType => $value) { $new_criterion = SJB_SearchCriterion::getCriterionByType($criteriaType); $new_criterion->setPropertyName($fieldName); $new_criterion->setValue($value); $sql[] = $new_criterion->getSystemSQL(); } } if ($sql) { return "(" . implode(' OR ', $sql) . ")"; } return null; }