Example #1
0
 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;
 }