Ejemplo n.º 1
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.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));
 }
Ejemplo n.º 2
0
 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());
 }
Ejemplo n.º 3
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));
 }
Ejemplo n.º 4
0
 public function onPlainFilter_creator_name($filterName, $filterValue, $criteria)
 {
     $criteria->mergeWith(PeopleSearch::getCriteriaFindByName($filterValue, 'creator'));
 }