Beispiel #1
0
 public function actionSearch()
 {
     Yii::beginProfile('search_property_and_people');
     // Initiate the entities.
     $properties = null;
     $users = null;
     $projects = null;
     $data = null;
     $data_user = null;
     $data_project = null;
     $data_user['user_type'] = 'agent';
     $amenities = null;
     $pages = null;
     $pagesAgent = null;
     $pagesBuilder = null;
     $pagesSpecialists = null;
     $pagesProject = null;
     $criteria = PropertyApi::getCriteriaObject($data);
     $totalProp = Property::model()->count();
     $pages = new CPagination($totalProp);
     $pages->pageSize = Yii::app()->params['resultsPerPage'];
     $pages->applyLimit($criteria);
     $properties = PropertyApi::searchPropertyWithCriteria($criteria);
     $propertiesCount = $totalProp;
     $totalUser = 0;
     $criteria = UserApi::getCriteriaObject($data_user);
     $users = UserApi::searchUser($data_user);
     if ($users) {
         $totalUser = count($users);
     }
     $pagesUser = new CPagination($totalUser);
     $pagesUser->pageSize = Yii::app()->params['resultsPerPage'];
     $pagesUser->applyLimit($criteria);
     $users = UserApi::searchUserWithCriteria($criteria);
     //$users = UserApi::searchUser($data_user);
     $projects = ProjectApi::searchProject($data_project);
     /* Property Model */
     $modelProperty = new Property();
     $modelState = new GeoState();
     $modelCity = new GeoCity();
     $propertyAmenities = new PropertyAmenities();
     // echo '<pre>';var_dump($pages);die();
     /* People Models */
     $modelUser = new UserCredentials();
     $modelProfile = new UserProfiles();
     $modelSpecialistType = new UserSpecialistType();
     /* Project Model */
     $modelProject = new Projects();
     $projectAmenities = new ProjectAmenities();
     if (isset($_POST['search']) && isset($_POST['mode'])) {
         if ($_POST['mode'] == "property") {
             $modelProperty->attributes = $_POST['Property'];
             //$modelProperty['i_want_to'] = isset($_POST['Property']['i_want_to'])?$_POST['Property']['i_want_to'] : null;
             $data = $_POST['Property'];
             $data['keyword'] = isset($_POST['keyword']) ? $_POST['keyword'] : null;
             $data['city'] = $_POST['GeoCity']['city'];
             $data['budget_min'] = $_POST['budget_min'];
             $data['budget_max'] = $_POST['budget_max'];
             $data['without_budget'] = isset($_POST['without_budget']) ? $_POST['without_budget'] : 0;
             $data['PropertyAmenities'] = isset($_POST['amenity_id']) ? $_POST['amenity_id'] : null;
             $data['posted_by_all'] = isset($_POST['posted_by_all']) ? $_POST['posted_by_all'] : 0;
             $data['posted_by'] = isset($_POST['posted_by']) ? $_POST['posted_by'] : null;
             $criteria = PropertyApi::getCriteriaObject($data);
             $totalProp = Property::model()->count();
             $pages = new CPagination($totalProp);
             $pages->pageSize = Yii::app()->params['resultsPerPage'];
             $pages->applyLimit($criteria);
             $properties = PropertyApi::searchPropertyWithCriteria($criteria);
             $propertiesCount = $totalProp;
             //$properties = PropertyApi::searchProperty($data);
         } elseif ($_POST['mode'] == "people") {
             $modelProfile->attributes = $_POST['UserProfiles'];
             $data_user = null;
             $data_user = $_POST['UserProfiles'];
             $data_user['user_type'] = $_POST['user_type'];
             $data_user['property_type_id'] = isset($_POST['property_type_id']) ? $_POST['property_type_id'] : null;
             $data_user['keyword'] = isset($_POST['keyword']) ? $_POST['keyword'] : null;
             $data_user['specialist_type_id'] = isset($_POST['specialist_type_id']) ? $_POST['specialist_type_id'] : null;
             //$users = UserApi::searchUser($data_user);
             if ($_POST['user_type'] == "agent") {
                 $totalAgent = '0';
                 $criteria = AgentProfileApi::getCriteriaObject($data_user);
                 $users = AgentProfileApi::searchAgents($data_user);
                 if ($users) {
                     $totalAgent = count($users);
                 }
                 $pagesAgent = new CPagination($totalAgent);
                 $pagesAgent->pageSize = Yii::app()->params['resultsPerPage'];
                 $pagesAgent->applyLimit($criteria);
                 $users = AgentProfileApi::searchAgentWithCriteria($criteria);
                 //	$users = AgentProfileApi::searchAgents($data_user);
             }
             if ($_POST['user_type'] == "builder") {
                 $totalBuilder = '0';
                 $criteria = BuilderProfileApi::getCriteriaObject($data_user);
                 $users = BuilderProfileApi::searchBuilderWithCriteria($criteria);
                 if ($users) {
                     $totalBuilder = count($users);
                 }
                 $pagesBuilder = new CPagination($totalBuilder);
                 $pagesBuilder->pageSize = Yii::app()->params['resultsPerPage'];
                 $pagesBuilder->applyLimit($criteria);
                 $users = BuilderProfileApi::searchBuilderWithCriteria($criteria);
             }
             if ($_POST['user_type'] == "specialist") {
                 $totalSpecialists = '0';
                 $criteria = SpecialistProfileApi::getCriteriaObject($data_user);
                 $users = SpecialistProfileApi::searchSpecialistsWithCriteria($criteria);
                 if ($users) {
                     $totalSpecialists = count($users);
                 }
                 $pagesSpecialists = new CPagination($totalSpecialists);
                 $pagesSpecialists->pageSize = Yii::app()->params['resultsPerPage'];
                 $pagesSpecialists->applyLimit($criteria);
                 $users = SpecialistProfileApi::searchSpecialistsWithCriteria($criteria);
             }
         } elseif ($_POST['mode'] == "project") {
             $modelProject->attributes = $_POST['Projects'];
             $amenities = isset($_POST['ProjectAmenities']['amenity_id']) ? $_POST['ProjectAmenities']['amenity_id'] : null;
             if ($amenities) {
                 $amenity_data = null;
                 foreach ($amenities as $i => $amenity) {
                     if ($i != 0) {
                         $amenity_data .= ',';
                     }
                     $amenity_data .= $amenity;
                 }
                 $amenities = $amenity_data;
             }
             $data = $_POST['Projects'];
             $data['keyword'] = isset($_POST['keyword']) ? $_POST['keyword'] : null;
             $data['city'] = $_POST['GeoCity']['city'];
             $data['budget_min'] = $_POST['budget_min'];
             $data['budget_max'] = $_POST['budget_max'];
             $data['ProjectAmenities'] = isset($_POST['ProjectAmenities']['amenity_id']) ? $_POST['ProjectAmenities']['amenity_id'] : null;
             $data['posted_by_all'] = isset($_POST['posted_by_all']) ? $_POST['posted_by_all'] : 0;
             $data['posted_by'] = isset($_POST['posted_by']) ? $_POST['posted_by'] : null;
             $totalProject = '0';
             $criteria = ProjectApi::getCriteriaObject($data);
             $users = ProjectApi::searchProjectWithCriteria($criteria);
             if ($users) {
                 $totalProject = count($users);
             }
             $pagesProject = new CPagination($totalProject);
             $pagesProject->pageSize = Yii::app()->params['resultsPerPage'];
             $pagesProject->applyLimit($criteria);
             $projects = ProjectApi::searchProjectWithCriteria($criteria);
         }
     }
     // echo '<br><pre>';var_dump($pages);die();
     $this->render('search', array('pages' => $pages, 'modelState' => $modelState, 'modelProperty' => $modelProperty, 'modelCity' => $modelCity, 'propertyAmenities' => $propertyAmenities, 'modelUser' => $modelUser, 'modelProfile' => $modelProfile, 'modelSpecialistType' => $modelSpecialistType, 'properties' => $properties, 'amenities' => $amenities, 'users' => $users, 'modelProject' => $modelProject, 'projectAmenities' => $projectAmenities, 'projects' => $projects, 'pagesAgent' => $pagesAgent, 'pagesUser' => $pagesUser, 'pagesBuilder' => $pagesBuilder, 'pagesSpecialists' => $pagesSpecialists, 'pagesProject' => $pagesProject, 'propertiesCount' => $propertiesCount));
     $this->render('search', array('pages' => $pages, 'modelProperty' => $modelProperty, 'modelCity' => $modelCity, 'propertyAmenities' => $propertyAmenities, 'modelUser' => $modelUser, 'modelProfile' => $modelProfile, 'modelSpecialistType' => $modelSpecialistType, 'properties' => $properties, 'amenities' => $amenities, 'users' => $users, 'modelProject' => $modelProject, 'projectAmenities' => $projectAmenities, 'projects' => $projects, 'pagesAgent' => $pagesAgent, 'pagesUser' => $pagesUser, 'pagesBuilder' => $pagesBuilder, 'pagesSpecialists' => $pagesSpecialists, 'pagesProject' => $pagesProject, 'propertiesCount' => $propertiesCount));
     $this->render('search', array('pages' => $pages, 'modelProperty' => $modelProperty, 'modelCity' => $modelCity, 'propertyAmenities' => $propertyAmenities, 'modelUser' => $modelUser, 'modelProfile' => $modelProfile, 'modelSpecialistType' => $modelSpecialistType, 'properties' => $properties, 'amenities' => $amenities, 'users' => $users, 'modelProject' => $modelProject, 'projectAmenities' => $projectAmenities, 'projects' => $projects, 'pagesAgent' => $pagesAgent, 'pagesUser' => $pagesUser, 'pagesBuilder' => $pagesBuilder, 'pagesSpecialists' => $pagesSpecialists, 'pagesProject' => $pagesProject, 'propertiesCount' => $propertiesCount));
     Yii::endProfile('search_property_and_people');
 }
Beispiel #2
0
 public function actionPeople()
 {
     Yii::beginProfile('search_people');
     $session = new CHttpSession();
     $session->open();
     //$session->destroy();
     // Initiate the entities.
     $users = null;
     $data = null;
     $modelUser = new UserCredentials();
     $modelProfile = new UserProfiles();
     $modelSpecialistType = new UserSpecialistType();
     $modelState = new GeoState();
     $modelCity = new GeoCity();
     $modelLocality = new GeoLocality();
     if (isset($_POST['GeoCity'])) {
         $modelCity->attributes = $_POST['GeoCity'];
     }
     if (isset($_POST['user_type'])) {
         //$data = $_POST['UserProfiles'];
         $data['user_type'] = $_POST['user_type'];
         $data['property_type_id'] = isset($_POST['property_type_id']) ? $_POST['property_type_id'] : null;
         $data['state_id'] = isset($_POST['GeoState']['state']) ? $_POST['GeoState']['state'] : null;
         $data['city_id'] = isset($_POST['GeoCity']['city']) ? $_POST['GeoCity']['city'] : null;
         $data['keyword'] = isset($_POST['keyword']) ? $_POST['keyword'] : null;
         $data['specialist_type_id'] = isset($_POST['specialist_type_id']) ? $_POST['specialist_type_id'] : null;
         $data['locality_id'] = isset($_POST['GeoLocality']['locality']) ? $_POST['GeoLocality']['locality'] : '';
         if ($data['specialist_type_id'][0] == '') {
             $data['specialist_type_id'] = null;
         }
         if ($data['locality_id'] != '') {
             $locality = GeoLocality::model()->find('locality=:locality', array(':locality' => $data['locality_id']));
             if ($locality) {
                 $data['locality_id'] = $locality->id;
             }
         }
         $totalResults = 0;
         if ($_POST['user_type'] == "agent") {
             $criteria = AgentProfileApi::getCriteriaObject($data);
             $totalResults = UserCredentials::model()->count($criteria);
             $pages = new CPagination($totalResults);
             $pages->pageSize = Yii::app()->params['resultsPerPage'];
             $pages->applyLimit($criteria);
             $users = AgentProfileApi::searchAgentWithCriteria($criteria);
             if (isset($_SERVER['HTTP_REFERER'])) {
                 unset($session['search-criteria-user-type']);
             }
             $session['search-criteria-user-type'] = 'agent';
         }
         if ($_POST['user_type'] == "builder") {
             $criteria = BuilderProfileApi::getCriteriaObject($data);
             $totalResults = UserCredentials::model()->count($criteria);
             $pages = new CPagination($totalResults);
             $pages->pageSize = Yii::app()->params['resultsPerPage'];
             $pages->applyLimit($criteria);
             $users = BuilderProfileApi::searchBuilderWithCriteria($criteria);
             if (isset($_SERVER['HTTP_REFERER'])) {
                 unset($session['search-criteria-user-type']);
             }
             $session['search-criteria-user-type'] = 'builder';
         }
         if ($_POST['user_type'] == "specialist") {
             $criteria = SpecialistProfileApi::getCriteriaObject($data);
             $totalResults = UserCredentials::model()->count($criteria);
             $pages = new CPagination($totalResults);
             $pages->pageSize = Yii::app()->params['resultsPerPage'];
             $pages->applyLimit($criteria);
             $users = SpecialistProfileApi::searchSpecialistsWithCriteria($criteria);
             if (isset($_SERVER['HTTP_REFERER'])) {
                 unset($session['search-criteria-user-type']);
             }
             $session['search-criteria-user-type'] = 'specialist';
         }
         $session['search-criteria-user'] = $criteria;
         $session['results-page'] = $totalResults;
     } else {
         if (isset($_SERVER['HTTP_REFERER'])) {
             unset($session['search-criteria-user-type']);
             unset($session['search-criteria-user']);
         }
         if (isset($session['search-criteria-user']) && isset($session['search-criteria-user-type'])) {
             $criteria = $session['search-criteria-user'];
             $userType = $session['search-criteria-user-type'];
             if ($userType == "agent") {
                 $data['user_type'] = 'agent';
                 $totalResults = UserCredentials::model()->count($criteria);
                 $pages = new CPagination($totalResults);
                 $pages->pageSize = Yii::app()->params['resultsPerPage'];
                 $pages->applyLimit($criteria);
                 $users = AgentProfileApi::searchAgentWithCriteria($criteria);
             } elseif ($userType == "builder") {
                 $data['user_type'] = 'builder';
                 $totalResults = UserCredentials::model()->count($criteria);
                 $pages = new CPagination($totalResults);
                 $pages->pageSize = Yii::app()->params['resultsPerPage'];
                 $pages->applyLimit($criteria);
                 $users = BuilderProfileApi::searchBuilderWithCriteria($criteria);
             } else {
                 $data['user_type'] = 'specialist';
                 $totalResults = UserCredentials::model()->count($criteria);
                 $pages = new CPagination($totalResults);
                 $pages->pageSize = Yii::app()->params['resultsPerPage'];
                 $pages->applyLimit($criteria);
                 $users = SpecialistProfileApi::searchSpecialistsWithCriteria($criteria);
             }
         } else {
             $data['user_type'] = 'agent';
             $criteria = AgentProfileApi::getCriteriaObject($data);
             $totalResults = UserCredentials::model()->count($criteria);
             $pages = new CPagination($totalResults);
             $pages->pageSize = Yii::app()->params['resultsPerPage'];
             $pages->applyLimit($criteria);
             $users = AgentProfileApi::searchAgentWithCriteria($criteria);
         }
     }
     $this->render('people', array('pages' => $pages, 'modelState' => $modelState, 'modelUser' => $modelUser, 'modelProfile' => $modelProfile, 'modelCity' => $modelCity, 'modelLocality' => $modelLocality, 'modelSpecialistType' => $modelSpecialistType, 'users' => $users, 'totalResults' => $totalResults, 'userType' => $data['user_type']));
     Yii::endProfile('search_people');
 }