Ejemplo n.º 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');
 }