Exemplo n.º 1
0
 /**
  * @Author: ANH DUNG Apr 07, 2014
  * <Edit By Jason>
  * @Todo: search at index page
  */
 public static function searchAtIndex()
 {
     $criteria = new CDbCriteria();
     self::AddConditionListingShow($criteria);
     if (isset($_GET['choosetype']) && $_GET['choosetype'] != ProPropertyType::SEARCH_ALL) {
         $criteria->compare('t.property_type_2', (int) $_GET['choosetype']);
     }
     if (isset($_GET['property_type_code']) && is_array($_GET['property_type_code'])) {
         $criteria->addInCondition('t.property_type_1', $_GET['property_type_code']);
     }
     if (isset($_GET['building']) && !empty($_GET['building'])) {
         $building = $_GET['building'];
         $criteria->addCondition("t.building_name LIKE :building");
         $criteria->params[':building'] = $building;
     }
     if (isset($_GET['minimum_price']) && !empty($_GET['minimum_price'])) {
         $criteria->addCondition("t.price >= " . (double) $_GET['minimum_price']);
     }
     if (isset($_GET['maximum_price']) && !empty($_GET['maximum_price'])) {
         $criteria->addCondition("t.price <= " . (double) $_GET['maximum_price']);
     }
     if (isset($_GET['minimum_bedroom']) && !empty($_GET['minimum_bedroom'])) {
         $criteria->addCondition("t.of_bedroom >= " . (double) $_GET['minimum_bedroom']);
     }
     if (isset($_GET['location']) && !empty($_GET['location'])) {
         $aListId = array();
         foreach ($_GET['location'] as $value) {
             $aListId[$value] = $value;
         }
         if (count($aListId)) {
             $criteria->addInCondition("t.location_id", $aListId);
         }
     }
     if (isset($_GET['furnishing_include']) && is_array($_GET['furnishing_include'])) {
         $aListId = ProListingFurnishingIncluded::getArrListingId($_GET['furnishing_include']);
         if (count($aListId)) {
             $criteria->addInCondition("t.id", $aListId);
         }
     }
     if (isset($_GET['maximum_bedroom']) && !empty($_GET['maximum_bedroom'])) {
         $criteria->addCondition("t.of_bedroom <= " . (double) $_GET['maximum_bedroom']);
     }
     if (isset($_GET['minimum_floor']) && !empty($_GET['minimum_floor'])) {
         $criteria->addCondition("t.floor_area_sqft >= " . (double) $_GET['minimum_floor']);
     }
     if (isset($_GET['maximum_floor']) && !empty($_GET['maximum_floor'])) {
         $criteria->addCondition("t.floor_area_sqft <= " . (double) $_GET['maximum_floor']);
     }
     //        if (isset($_GET['tenure']) && !empty($_GET['tenure'])) {
     //            // update soon
     //            $criteria->compare('t.tenure', ActiveRecord::safeField($_GET['tenure']), true);
     //        }
     if (isset($_GET['keywords']) && !empty($_GET['keywords'])) {
         $criteria->compare('t.keywordsearch', ActiveRecord::safeField($_GET['keywords']), true);
     }
     if (isset($_GET['LeaseTerm']) && !empty($_GET['LeaseTerm'])) {
         $criteria->compare('t.lease_term', ActiveRecord::safeField($_GET['LeaseTerm']));
     }
     if (isset($_GET['furnished']) && !empty($_GET['furnished'])) {
         $criteria->compare('t.furnished', ActiveRecord::safeField($_GET['furnished']));
     }
     if (isset($_GET['minimum_psf']) && !empty($_GET['minimum_psf'])) {
         $criteria->addCondition("t.search_psf >= " . (double) $_GET['minimum_psf']);
     }
     if (isset($_GET['maximum_psf']) && !empty($_GET['maximum_psf'])) {
         $criteria->addCondition("t.search_psf <= " . (double) $_GET['maximum_psf']);
     }
     //        if (isset($_GET['minimum_constructed']) && !empty($_GET['minimum_constructed'])) {
     //            $criteria->addCondition("t.constructed >= " . (double) $_GET['minimum_constructed']);
     //        }
     //        if (isset($_GET['maximum_constructed']) && !empty($_GET['maximum_constructed'])) {
     //            $criteria->addCondition("t.constructed <= " . (double) $_GET['maximum_constructed']);
     //        }
     if (isset($_GET['option']) && !empty($_GET['option'])) {
         foreach ($_GET['option'] as $key => $value) {
             if ($value == 1) {
                 //With photos only
                 //Listing
                 $aListingId = ProListingPhotos::getListListingId();
                 if (count($aListingId)) {
                     $criteria->addInCondition("t.id", $aListingId);
                 }
             } elseif ($value == 2) {
                 //With floor plan ( floor > 1)
                 $criteria->addCondition("t.floor_area > " . 1);
             }
         }
     }
     if (isset($_GET['listed_on']) && !empty($_GET['listed_on'])) {
         $currDate = date('Y-m-d');
         switch ($_GET['listed_on']) {
             case 1:
                 $currDate = date('Y-m-d', strtotime("{$currDate} -3 days")) . " 00:00:00";
                 $criteria->addCondition("t.date_listed > '{$currDate}'");
                 break;
             case 2:
                 $currDate = date('Y-m-d', strtotime("{$currDate} -7 days")) . " 00:00:00";
                 $criteria->addCondition("t.date_listed > '{$currDate}'");
                 break;
             case 3:
                 $currDate = date('Y-m-d', strtotime("{$currDate} -14 days")) . " 00:00:00";
                 $criteria->addCondition("t.date_listed > '{$currDate}'");
                 break;
             case 4:
                 $currDate = date('Y-m-d', strtotime("{$currDate} -30 days")) . " 00:00:00";
                 $criteria->addCondition("t.date_listed > '{$currDate}'");
                 break;
         }
     }
     if (isset($_GET['listing_type']) && $_GET['listing_type'] == 'sale' || isset($_GET['listing_for']) && $_GET['listing_for'] == 'for_sale') {
         $criteria->compare('t.listing_type', Listing::FOR_SALE);
     } else {
         $criteria->compare('t.listing_type', Listing::FOR_RENT);
     }
     // to get only company listing
     $criteria->addCondition('t.user_id IS NOT NULL AND t.user_id>0');
     $mListing = new Listing();
     /*         * * sort ** */
     $defaultSort = explode('.', Listing::DEFAULT_SORT_BY);
     $criteria->order = implode(' ', $defaultSort);
     /*         * * for sort at search form ** */
     if (isset($_GET['s_sort']) && !empty($_GET['s_sort'])) {
         // check valid $_GET['sort']
         $sSort = explode('.', $_GET['s_sort']);
         // $_GET['sort'] = name.desc
         if (count($sSort) == 2) {
             if ($mListing->hasAttribute($sSort[0]) && in_array($sSort[1], self::$aDirectionSort)) {
                 $criteria->order = implode(' ', $sSort);
             }
         }
     }
     /*         * * for sort at search form ** */
     if (isset($_GET['sort']) && !empty($_GET['sort'])) {
         // check valid $_GET['sort']
         $sSort = explode('.', $_GET['sort']);
         // $_GET['sort'] = name.desc
         if (count($sSort) == 2) {
             if ($mListing->hasAttribute($sSort[0]) && in_array($sSort[1], self::$aDirectionSort)) {
                 $criteria->order = implode(' ', $sSort);
             }
         }
     }
     /*         * * sort ** */
     /*         * * pageSize ** */
     $itemPerPage = Listing::DEFAULT_ITEM_PERPAGE;
     if (isset($_GET['pageSize'])) {
         $itemPerPage = (int) $_GET['pageSize'];
     }
     /*         * * pageSize ** */
     return new CActiveDataProvider('Listing', array('criteria' => $criteria, 'pagination' => array('pageSize' => $itemPerPage)));
 }