public function doRestList() { $model = $this->getModel(); if (empty($this->plainFilter['election_id'])) { throw new Exception('Election id filter property missed'); } $election = Election::model()->findByPk($this->plainFilter['election_id']); if (!$election) { throw new Exception('Election was not found'); } $criteria = new CDbCriteria(array('condition' => 't.election_id = ' . $election->id)); $peopleSearch = new PeopleSearch(); if ($name = $this->plainFilter['name']) { $peopleSearch->name = $name; } if ($ageFrom = $this->plainFilter['ageFrom']) { $peopleSearch->ageFrom = $ageFrom; } if ($ageTo = $this->plainFilter['ageTo']) { $peopleSearch->ageTo = $ageTo; } if ($birth_place = $this->plainFilter['birth_place']) { $peopleSearch->birth_place = $birth_place; } if ($gender = $this->plainFilter['gender']) { $peopleSearch->gender = $gender; } $arProvCriteria = $peopleSearch->search('')->criteria; if ($arProvCriteria) { $criteria->mergeWith($arProvCriteria); } $results = $model->with($this->nestedRelations)->filter($this->restFilter)->orderBy($this->restSort)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $forCount = $this->getModel()->filter($this->restFilter); $this->outputHelper('Records Retrieved Successfully', $results, $forCount->with($this->nestedRelations)->count($criteria)); }
public function actionIndex() { $model = new PeopleSearch('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['PeopleSearch'])) { $model->attributes = $_GET['PeopleSearch']; } $this->render('index', array('model' => $model)); }
public function doRestList() { if (empty($this->plainFilter['election_id'])) { throw new Exception('Election id filter property missed'); } $election = Election::model()->findByPk($this->plainFilter['election_id']); if (!$election) { throw new Exception('Election was not found'); } $criteria = new CDbCriteria(array('condition' => 't.election_id = ' . $election->id)); if (isset($this->plainFilter['user_id'])) { $criteria->mergeWith(array('condition' => 't.user_id = ' . (int) $this->plainFilter['user_id'])); } if (isset($this->plainFilter['candidate_id'])) { $criteria->mergeWith(array('condition' => 't.candidate_id = ' . (int) $this->plainFilter['candidate_id'])); } if (isset($this->plainFilter['accepted_only']) && $this->plainFilter['accepted_only']) { $criteria->addCondition('t.status = ' . Vote::STATUS_PASSED); } $peopleSearch = new PeopleSearch(); if ($name = $this->plainFilter['name']) { $peopleSearch->name = $name; } if ($ageFrom = $this->plainFilter['ageFrom']) { $peopleSearch->ageFrom = $ageFrom; } if ($ageTo = $this->plainFilter['ageTo']) { $peopleSearch->ageTo = $ageTo; } if ($birth_place = $this->plainFilter['birth_place']) { $peopleSearch->birth_place = $birth_place; } if ($gender = $this->plainFilter['gender']) { $peopleSearch->gender = $gender; } $arProvCriteria = $peopleSearch->search('profile')->criteria; if ($arProvCriteria) { $originalCriteria = clone $criteria; $criteria->mergeWith($arProvCriteria); } $results = $this->getModel()->with($this->nestedRelations)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $totalCount = $this->getModel()->with($this->nestedRelations)->count($criteria); $extraData = $totalCount; if (isset($this->plainFilter['candidate_id'])) { if (isset($originalCriteria)) { $criteria = $originalCriteria; } $acceptedCountCritetia = clone $criteria; $acceptedCount = $this->getModel()->with($this->nestedRelations)->count($acceptedCountCritetia->addCondition('t.status = ' . Vote::STATUS_PASSED)); $extraData = array('totalCount' => $totalCount, 'acceptedCount' => $acceptedCount); } $this->outputHelper('Records Retrieved Successfully', $results, $extraData); }
public function doRestList() { $model = $this->getModel(); $peopleSearch = new PeopleSearch(); if ($name = $this->plainFilter['name']) { $peopleSearch->name = $name; } if ($ageFrom = $this->plainFilter['ageFrom']) { $peopleSearch->ageFrom = $ageFrom; } if ($ageTo = $this->plainFilter['ageTo']) { $peopleSearch->ageTo = $ageTo; } if ($birth_place = $this->plainFilter['birth_place']) { $peopleSearch->birth_place = $birth_place; } if ($gender = $this->plainFilter['gender']) { $peopleSearch->gender = $gender; } if ($scopes = $this->plainFilter['applyScopes']) { $scopes = CJSON::decode($scopes); if (array_key_exists('elector', $scopes)) { $condition = 'elector.election_id = ' . $scopes['elector']['election_id']; if (isset($scopes['elector']['status'])) { $condition .= ' AND elector.status = ' . $scopes['elector']['status']; } $this->nestedModels['elector'] = array('joinType' => 'INNER JOIN', 'condition' => $condition); unset($scopes['elector']); } if (array_key_exists($scope = 'withElectorRegistrationRequest', $scopes)) { $condition = 'electorRegistrationRequest.election_id = ' . $scopes[$scope]['election_id'] . ' AND electorRegistrationRequest.status = ' . $scopes[$scope]['status']; $this->nestedModels['electorRegistrationRequest'] = array('joinType' => 'INNER JOIN', 'condition' => $condition); unset($scopes[$scope]); } if (array_key_exists('inVoterGroup', $scopes)) { $this->nestedModels['voterGroupMember'] = array('joinType' => 'INNER JOIN', 'condition' => 'voterGroupMember.voter_group_id = ' . $scopes['inVoterGroup']['voter_group_id']); } $peopleSearch->applyScopes = $scopes; } $this->flushRestFilter('applyScopes', 'ageFrom', 'ageTo', 'name'); $arProvCriteria = $peopleSearch->search()->criteria; $model->getDbCriteria()->mergeWith($arProvCriteria); $results = $model->with($this->nestedRelations)->filter($this->restFilter)->orderBy($this->restSort)->limit($this->restLimit)->offset($this->restOffset)->findAll(); $forCount = $this->getModel(); $forCount->getDbCriteria()->mergeWith($arProvCriteria); $this->outputHelper('Records Retrieved Successfully', $results, $forCount->filter($this->restFilter)->with($this->nestedRelations)->count()); }
public function doRestList() { if (empty($this->plainFilter['election_id'])) { throw new Exception('Election id filter property missed'); } $election = Election::model()->findByPk($this->plainFilter['election_id']); if (!$election) { throw new Exception('Election was not found'); } $criteria = new CDbCriteria(array('condition' => 't.object_id = ' . $election->id)); if (!empty($this->plainFilter['name'])) { $criteria->mergeWith(PeopleSearch::getCriteriaFindByName($this->plainFilter['name'], 'profile')); } $results = $this->getModel()->with($this->nestedRelations)->criteriaWithRole('election_administration')->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $this->outputHelper('Records Retrieved Successfully', $results, $this->getModel()->with($this->nestedRelations)->criteriaWithRole('election_administration')->count($criteria)); }
public function doRestList() { $userId = Yii::app()->user->id; if (!empty($this->plainFilter['participants'])) { //Find conversation by certain participants $participants = $this->plainFilter['participants']; if (!in_array($userId, $participants)) { throw new CHttpException(403, 'You are able to see conversations where you are participating only.'); } } else { $participants = array($userId); } $criteria = $this->getModel()->criteriaWithParticipants($participants)->with($this->nestedRelations); $conversation = new Conversation(); $this->_attachBehaviors($conversation); $countCriteria = $conversation->criteriaWithParticipants($participants)->with($this->nestedRelations); if (empty($this->plainFilter['participants'])) { $since = null; if (!empty($this->plainFilter['since'])) { $ts = substr($this->plainFilter['since'], 0, 10); $since = date('Y-m-d H:i:s', $ts); } $criteria->criteriaHasMessages($since)->criteriaOrderUnviewedFirst($userId); $countCriteria->criteriaHasMessages($since); if (!empty($this->plainFilter['participantName'])) { //Filtration by participant name $participantNameFilter = PeopleSearch::getCriteriaFindByName($this->plainFilter['participantName'], 'profile'); $participantNameFilter->join = 'LEFT JOIN conversation_participant cp ON cp.conversation_id = t.id ' . 'LEFT JOIN user_profile profile ON profile.user_id = cp.user_id'; $criteria->getDbCriteria()->mergeWith($participantNameFilter); $countCriteria->getDbCriteria()->mergeWith($participantNameFilter); } } $conversations = $criteria->limit($this->restLimit)->offset($this->restOffset)->findAll(array('group' => 't.id')); foreach ($conversations as $conversation) { $params = array('order' => 'created_ts DESC', 'limit' => 1); if ($since) { $params['condition'] = 'created_ts > "' . $since . '"'; unset($params['limit']); } $conversation->messages = $conversation->messages($params); } $this->outputHelper('Records Retrieved Successfully', $conversations, $countCriteria->count()); }
public function doRestList() { if (empty($this->plainFilter['election_id'])) { throw new Exception('Election id filter property missed'); } $election = Election::model()->findByPk($this->plainFilter['election_id']); if (!$election) { throw new Exception('Election was not found'); } $criteria = new CDbCriteria(array('condition' => 't.election_id = ' . $election->id)); if (!empty($this->plainFilter['name'])) { $criteria->mergeWith(PeopleSearch::getCriteriaFindByName($this->plainFilter['name'], 'profile')); } if (!empty($this->plainFilter['status'])) { $criteria->mergeWith(Candidate::getCriteriaWithStatusOnly($this->plainFilter['status'])); } if (in_array($election->status, array(Election::STATUS_ELECTION, Election::STATUS_FINISHED))) { $criteria->mergeWith(array('with' => 'acceptedVotesCount')); } $results = $this->getModel()->with($this->nestedRelations)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria); $this->outputHelper('Records Retrieved Successfully', $results, $this->getModel()->with($this->nestedRelations)->count($criteria)); }
public function onPlainFilter_creator_name($filterName, $filterValue, $criteria) { $criteria->mergeWith(PeopleSearch::getCriteriaFindByName($filterValue, 'creator')); }
public static function useDefault($search_data = null, &$errors, $defaults = null) { $search = new PeopleSearch($defaults); // Search by First Name $search->addSearchField('firstname', 'firstname', 'contains'); // Search by Surname $search->addSearchField('surname', 'surname', 'begins'); // Search by Comapny name $search->addSearchField('company', 'company_name', 'begins'); // Search by Assigned to Me $search->addSearchField('assigned_to', 'assigned_to_me', 'hide', false, 'advanced'); $search->setOnValue('assigned_to', EGS_USERNAME); // Search by Phone Number $search->addSearchField('phone', 'phone_number', 'begins', '', 'advanced'); // Search by Mobile Phone Number $search->addSearchField('mobile', 'mobile', 'begins', '', 'advanced'); // Search by Email Address $search->addSearchField('email', 'email', 'contains', '', 'advanced'); // Search by Town $search->addSearchField('town', 'town', 'contains', '', 'advanced'); // Search by Post Code $search->addSearchField('postcode', 'postcode', 'contains', '', 'advanced'); $search->setSearchData($search_data, $errors); return $search; }