private function filterResults($results)
 {
     $params = $this->getState('params');
     $filters = null;
     if (!empty($params['filters'])) {
         $filters = $params['filters'];
     }
     if ($filters == null) {
         //provo a recuperarli dalla sessione...
         $filters = BFCHelper::getFilterSearchParamsSession();
     }
     if ($filters == null) {
         return $results;
     }
     BFCHelper::setFilterSearchParamsSession($filters);
     // zone filtering
     if (!empty($filters['locationzones']) && is_array($results)) {
         $locationzones = $filters['locationzones'];
         $locationzones = explode(",", $locationzones);
         if (is_array($locationzones) || $locationzones != "0") {
             $results = array_filter($results, function ($result) use($locationzones) {
                 return is_array($locationzones) && (in_array($result->MrcZoneId, $locationzones) || in_array($result->ResZoneId, $locationzones)) || ($result->MrcZoneId == $locationzones || $result->ResZoneId == $locationzones);
             });
         }
     }
     // merchantgroups filtering
     if (!empty($filters['merchantgroups']) && is_array($results)) {
         $merchantgroups = $filters['merchantgroups'];
         $merchantgroups = explode(",", $merchantgroups);
         if (is_array($merchantgroups)) {
             //if ($stars > 0) {
             $results = array_filter($results, function ($result) use($merchantgroups) {
                 $hasTags = false;
                 $val = preg_replace('/\\s+/', '', $result->MrcTagsIdList);
                 $merchantGroupIdList = explode(",", $val);
                 if (is_array($merchantGroupIdList)) {
                     $arrayresult = array_intersect($merchantgroups, $merchantGroupIdList);
                     $hasTags = count($arrayresult) > 0;
                 } else {
                     $hasTags = is_array($merchantgroups) && in_array($merchantGroupIdList, $merchantgroups) || $merchantGroupIdList == $merchantgroups;
                 }
                 $val = preg_replace('/\\s+/', '', $result->TagsIdList);
                 $merchantGroupIdList = explode(",", $val);
                 if (is_array($merchantGroupIdList)) {
                     $arrayresult = array_intersect($merchantgroups, $merchantGroupIdList);
                     $hasTags = $hasTags || count($arrayresult) > 0;
                 } else {
                     $hasTags = $hasTags || (is_array($merchantgroups) && in_array($merchantGroupIdList, $merchantgroups) || $merchantGroupIdList == $merchantgroups);
                 }
                 return $hasTags;
             });
         }
     }
     //		// services filtering
     //		if (!empty($filters['services']) && is_array($results)) {
     //			$services = $filters['services'];
     //			$services = explode(",", $services);
     //			if (is_array($services)){
     //				$results = array_filter($results, function($result) use ($services) {
     //					$merchantServiceIdList = explode(",",$result->MrcServiceIdList);
     //					$resourceServiceIdList = explode(",",$result->ResServiceIdList);
     //					$serviceIdList = array_merge($merchantServiceIdList,$resourceServiceIdList);
     //					if (is_array($serviceIdList)) {
     //						$arrayresult = array_intersect($services, $serviceIdList);
     //						return (count($arrayresult)==count($services));
     //
     //					}else{
     //						return ((is_array($services) && in_array( $serviceIdList, $services )) || $serviceIdList == $services  );
     //					}
     //				});
     //			}
     //		}
     // services filtering resource
     if (!empty($filters['services']) && is_array($results)) {
         $services = $filters['services'];
         $services = explode(",", $services);
         if (is_array($services)) {
             $results = array_filter($results, function ($result) use($services) {
                 $serviceIdList = explode(",", $result->ResServiceIdList);
                 if (is_array($serviceIdList)) {
                     $arrayresult = array_intersect($services, $serviceIdList);
                     return count($arrayresult) == count($services);
                 } else {
                     return is_array($services) && in_array($serviceIdList, $services) || $serviceIdList == $services;
                 }
             });
         }
     }
     // services filtering merchants
     if (!empty($filters['servicesmerchants']) && is_array($results)) {
         $services = $filters['servicesmerchants'];
         $services = explode(",", $services);
         if (is_array($services)) {
             $results = array_filter($results, function ($result) use($services) {
                 $serviceIdList = explode(",", $result->MrcServiceIdList);
                 if (is_array($serviceIdList)) {
                     $arrayresult = array_intersect($services, $serviceIdList);
                     return count($arrayresult) == count($services);
                 } else {
                     return is_array($services) && in_array($serviceIdList, $services) || $serviceIdList == $services;
                 }
             });
         }
     }
     // mastertypologies filtering
     if (!empty($filters['mastertypologies']) && is_array($results)) {
         $mastertypologies = $filters['mastertypologies'];
         $mastertypologies = explode(",", $mastertypologies);
         if (is_array($mastertypologies)) {
             //if ($stars > 0) {
             $results = array_filter($results, function ($result) use($mastertypologies) {
                 return is_array($mastertypologies) && in_array($result->MasterTypologyId, $mastertypologies) || $result->MasterTypologyId == $mastertypologies;
             });
         }
     }
     // rooms filtering checkbox
     //		if (!empty($filters['rooms']) && is_array($results)) {
     //			$rooms = $filters['rooms'];
     //			$rooms = explode(",", $rooms);
     //			if (is_array($rooms)){
     //			//if ($stars > 0) {
     //				$results = array_filter($results, function($result) use ($rooms) {
     //					return ((is_array($rooms) && in_array( $result->Rooms, $rooms )) || $result->Rooms == $rooms  );
     //				});
     //			}
     //		}
     // rooms filtering radiobutton
     if (!empty($filters['rooms']) && is_array($results)) {
         $rooms = $filters['rooms'];
         if ($rooms > 0) {
             $results = array_filter($results, function ($result) use($rooms) {
                 return $result->Rooms >= $rooms;
             });
         }
     }
     // RateplanName filtering
     if (!empty($filters['rateplanname']) && is_array($results)) {
         $rateplanname = $filters['rateplanname'];
         $rateplanname = explode(",", $rateplanname);
         if (is_array($rateplanname)) {
             //if ($stars > 0) {
             $results = array_filter($results, function ($result) use($rateplanname) {
                 return is_array($rateplanname) && in_array($result->RateplanName, $rateplanname) || $result->RateplanName == $rateplanname;
             });
         }
     }
     // stars filtering
     if (!empty($filters['stars']) && is_array($results)) {
         $stars = $filters['stars'];
         $stars = explode(",", $stars);
         if (is_array($stars) || $stars != "0") {
             $results = array_filter($results, function ($result) use($stars) {
                 return is_array($stars) && (in_array($result->MrcRating, $stars) || $result->MrcRating == $stars || in_array($result->ResRating, $stars)) || $result->ResRating == $stars;
             });
         }
     }
     // bookingTypes filtering
     if (!empty($filters['bookingtypes']) && is_array($results)) {
         $bookingTypes = $filters['bookingtypes'];
         $bookingTypes = explode(",", $bookingTypes);
         if (is_array($bookingTypes) || $bookingTypes != "0") {
             $results = array_filter($results, function ($result) use($bookingTypes) {
                 //					return ((is_array($bookingTypes) && (in_array( $result->BookingType, $bookingTypes)) || $result->BookingType == $bookingTypes));
                 return is_array($bookingTypes) && in_array($result->IsBookable, $bookingTypes) || $result->IsBookable == $bookingTypes;
             });
         }
     }
     // offers filtering
     if (!empty($filters['offers']) && is_array($results)) {
         $offers = $filters['offers'];
         $offers = explode(",", $offers);
         if (is_array($offers) || $offers != "0") {
             $results = array_filter($results, function ($result) use($offers) {
                 //					return ((is_array($offers) && (in_array( $result->TotalPrice>$result->Price, $offers)) || $result->TotalPrice>$result->Price == $offers));
                 //return ((is_array($offers) && (in_array( !empty($result->DiscountId), $offers)) || !empty($result->DiscountId) == $offers));
                 return (is_array($offers) && in_array($result->IsOffer, $offers) || $result->IsOffer == $offers) && $result->TotalPrice > $result->Price;
             });
         }
     }
     // price min filtering
     if (!empty($filters['pricemin']) && is_array($results)) {
         $pricemin = $filters['pricemin'];
         if ($pricemin > 0) {
             $results = array_filter($results, function ($result) use($pricemin) {
                 return $result->Price >= $pricemin;
             });
         }
     }
     // price min filtering
     if (!empty($filters['pricemax']) && is_array($results)) {
         $pricemax = $filters['pricemax'];
         if ($pricemax > 0) {
             $results = array_filter($results, function ($result) use($pricemax) {
                 return $result->Price <= $pricemax;
             });
         }
     }
     return $results;
 }
示例#2
0
 private function filterResults($results)
 {
     $params = $this->getState('params');
     $filters = null;
     if (!empty($params['filters'])) {
         $filters = $params['filters'];
     }
     if ($filters == null) {
         //provo a recuperarli dalla sessione...
         $filters = BFCHelper::getFilterSearchParamsSession();
     }
     if ($filters == null) {
         return $results;
     }
     BFCHelper::setFilterSearchParamsSession($filters);
     // zone filtering
     if (!empty($filters['locationzones']) && is_array($results)) {
         $locationzones = $filters['locationzones'];
         $locationzones = explode(",", $locationzones);
         if (is_array($locationzones) || $locationzones != "0") {
             $results = array_filter($results, function ($result) use($locationzones) {
                 return is_array($locationzones) && (in_array($result->MrcZoneId, $locationzones) || in_array($result->ResZoneId, $locationzones)) || ($result->MrcZoneId == $locationzones || $result->ResZoneId == $locationzones);
             });
         }
     }
     // merchantgroups filtering
     if (!empty($filters['merchantgroups']) && is_array($results)) {
         $merchantgroups = $filters['merchantgroups'];
         //			echo "<pre>";
         //			echo print_r($mastertypologies);
         //			echo "</pre>";
         $merchantgroups = explode(",", $merchantgroups);
         if (is_array($merchantgroups)) {
             //if ($stars > 0) {
             $results = array_filter($results, function ($result) use($merchantgroups) {
                 $val = preg_replace('/\\s+/', '', $result->MrcGroupIdList);
                 $merchantGroupIdList = explode(",", $val);
                 if (is_array($merchantGroupIdList)) {
                     $arrayresult = array_intersect($merchantgroups, $merchantGroupIdList);
                     return count($arrayresult) > 0;
                 } else {
                     return is_array($merchantgroups) && in_array($merchantGroupIdList, $merchantgroups) || $merchantGroupIdList == $merchantgroups;
                 }
             });
         }
     }
     // services filtering
     if (!empty($filters['services']) && is_array($results)) {
         $services = $filters['services'];
         //			echo "<pre>";
         //			echo print_r($services);
         //			echo "</pre>";
         $services = explode(",", $services);
         if (is_array($services)) {
             $results = array_filter($results, function ($result) use($services) {
                 $merchantServiceIdList = explode(",", $result->MrcServiceIdList);
                 $resourceServiceIdList = explode(",", $result->ResServiceIdList);
                 $serviceIdList = array_merge($merchantServiceIdList, $resourceServiceIdList);
                 if (is_array($serviceIdList)) {
                     $arrayresult = array_intersect($services, $serviceIdList);
                     //return (count($arrayresult)>0);
                     //21/11/2014
                     /// modifica per ritornare solo quelli che hanno TUTTI i servizi selezionati
                     return count($arrayresult) == count($services);
                 } else {
                     return is_array($services) && in_array($serviceIdList, $services) || $serviceIdList == $services;
                 }
             });
         }
     }
     // mastertypologies filtering
     if (!empty($filters['mastertypologies']) && is_array($results)) {
         $mastertypologies = $filters['mastertypologies'];
         $mastertypologies = explode(",", $mastertypologies);
         if (is_array($mastertypologies)) {
             //if ($stars > 0) {
             $results = array_filter($results, function ($result) use($mastertypologies) {
                 return is_array($mastertypologies) && in_array($result->MasterTypologyId, $mastertypologies) || $result->MasterTypologyId == $mastertypologies;
             });
         }
     }
     // stars filtering
     if (!empty($filters['stars']) && is_array($results)) {
         $stars = $filters['stars'];
         $stars = explode(",", $stars);
         if (is_array($stars) || $stars != "0") {
             $results = array_filter($results, function ($result) use($stars) {
                 return is_array($stars) && (in_array($result->MrcRating, $stars) || $result->MrcRating == $stars || in_array($result->ResRating, $stars)) || $result->ResRating == $stars;
             });
         }
     }
     // bookingTypes filtering
     if (!empty($filters['bookingtypes']) && is_array($results)) {
         $bookingTypes = $filters['bookingtypes'];
         $stars = explode(",", $bookingTypes);
         if (is_array($bookingTypes) || $bookingTypes != "0") {
             $results = array_filter($results, function ($result) use($bookingTypes) {
                 return is_array($bookingTypes) && in_array($result->BookingType, $bookingTypes) || $result->BookingType == $bookingTypes;
             });
         }
     }
     // offers filtering
     if (!empty($filters['offers']) && is_array($results)) {
         $offers = $filters['offers'];
         $stars = explode(",", $offers);
         if (is_array($offers) || $offers != "0") {
             $results = array_filter($results, function ($result) use($offers) {
                 //					return ((is_array($offers) && (in_array( $result->TotalPrice>$result->Price, $offers)) || $result->TotalPrice>$result->Price == $offers));
                 //return ((is_array($offers) && (in_array( !empty($result->DiscountId), $offers)) || !empty($result->DiscountId) == $offers));
                 return is_array($offers) && in_array($result->IsOffer, $offers) || $result->IsOffer == $offers;
             });
         }
     }
     // price min filtering
     if (!empty($filters['pricemin']) && is_array($results)) {
         $pricemin = $filters['pricemin'];
         if ($pricemin > 0) {
             $results = array_filter($results, function ($result) use($pricemin) {
                 return $result->Price >= $pricemin;
             });
         }
     }
     // price min filtering
     if (!empty($filters['pricemax']) && is_array($results)) {
         $pricemax = $filters['pricemax'];
         if ($pricemax > 0) {
             $results = array_filter($results, function ($result) use($pricemax) {
                 return $result->Price <= $pricemax;
             });
         }
     }
     return $results;
 }