Example #1
0
 public static function answers($id)
 {
     $answers = PollAnswerLangModel::join(PollAnswerModel::getTableName(), PollAnswerModel::getField('id'), '=', PollAnswerLangModel::getField('answer_id'))->select(PollAnswerLangModel::getField('*'))->where(PollAnswerLangModel::getField('lang_id'), \WebAPL\Language::getId())->where(PollAnswerModel::getField('poll_id'), $id)->orderBy(PollAnswerModel::getField('ord'), 'asc')->get();
     foreach ($answers as &$answer) {
         $answer['count'] = PollVotesModel::where(array('poll_id' => $id, 'answer_id' => $answer->answer_id))->count();
     }
     return $answers;
 }
Example #2
0
 /**
  * Get list of answers jqgrid
  * @param int $poll_id
  * @param int $lang_id
  * @return json
  */
 public function getlist_answer($poll_lang_id)
 {
     User::onlyHas('poll-view');
     $jqgrid = new jQgrid('apl_poll_answer');
     return $jqgrid->populate(function ($start, $limit) use($poll_lang_id) {
         $answers = PollAnswerModel::select(PollAnswerModel::getField('id'), PollAnswerModel::getField('poll_id'), PollAnswerModel::getField('ord'), PollAnswerLangModel::getField('title'))->join(\PollAnswerLangModel::getTableName(), PollAnswerModel::getField('id'), '=', \PollAnswerLangModel::getField('answer_id'))->where(array(\PollAnswerLangModel::getField('lang_id') => \WebAPL\Language::getId()))->skip($start)->take($limit)->where(array('poll_id' => $poll_lang_id))->orderBy('ord', 'asc')->get();
         $list = [];
         foreach ($answers as $answer) {
             $list[] = array('id' => $answer->id, 'title' => $answer->title, 'count' => PollVotesModel::where(array('poll_id' => $answer->poll_id, 'answer_id' => $answer->id))->count(), 'ord' => $answer->ord);
         }
         return $list;
     });
 }