Ejemplo n.º 1
0
 public function doRestList()
 {
     $criteria = new CDbCriteria(array('condition' => 't.user_id = ' . $this->plainFilter['user_id']));
     if (!empty($this->plainFilter['name'])) {
         $criteria->mergeWith(array('condition' => 'election.name LIKE :electionName', 'params' => array(':electionName' => '%' . $this->plainFilter['name'] . '%')));
     }
     if (!empty($this->plainFilter['status'])) {
         $criteria->mergeWith(Candidate::getCriteriaWithStatusOnly($this->plainFilter['status']));
     }
     $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));
 }
Ejemplo n.º 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 (!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));
 }