示例#1
0
 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));
 }
示例#2
0
 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);
 }
示例#3
0
 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());
 }