示例#1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     ini_set('max_execution_time', 0);
     $factorQuestions = Question::on('main')->where('id_question_type', QuestionType::TYPE_FACTOR)->get();
     $listIDAnswerFactor = [];
     foreach ($factorQuestions as $q) {
         $listIDAnswerFactor[] = QuestionAnswer::on('main')->where('id_question', $q->id)->lists('id_answer');
     }
     $listIDAnswerNormal = Question::on('main')->where('id_question_type', '!=', QuestionType::TYPE_FACTOR)->join('question_answer', 'question_answer.id_question', '=', 'questions.id')->distinct('id_answer')->orderBy('id_answer')->lists('id_answer');
     $keyGroup = [];
     foreach ($listIDAnswerFactor[0] as $fKey0) {
         foreach ($listIDAnswerFactor[1] as $fKey1) {
             foreach ($listIDAnswerFactor[2] as $fKey2) {
                 $arrTemp = [$fKey0, $fKey1, $fKey2];
                 sort($arrTemp);
                 $keyGroup[] = $arrTemp;
             }
         }
     }
     $insert = [];
     foreach ($keyGroup as $key) {
         $keyString = implode(',', $key);
         foreach ($listIDAnswerNormal as $idAnswer) {
             $answerRoot = DB::select("select * from option_ans where id='{$idAnswer}'");
             $idAttribute = $answerRoot[0]->attribute_id;
             $factor = DB::select("select * from factor where user_detail = '{$keyString}' and attribute_id='{$idAttribute}'");
             if (count($factor) > 0) {
                 $insert[] = ['key_group' => $keyString, 'id_answer' => $idAnswer, 'factor' => $factor[0]->factor];
             } else {
                 $insert[] = ['key_group' => $keyString, 'id_answer' => $idAnswer, 'factor' => rand(1, 3)];
             }
         }
     }
     Factor::insert($insert);
 }
示例#2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     ini_set('max_execution_time', 0);
     $data = DB::select('select * from question_option');
     $insert = [];
     foreach ($data as $d) {
         $insert[] = ['id_question' => $d->question_id, 'id_answer' => $d->option_ans_id];
     }
     QuestionAnswer::insert($insert);
 }
 function toggle_like()
 {
     Auth::checkLoggedIn();
     $answer = QuestionAnswer::fromId(Input::get('answerid'));
     if (!$answer->canView(Auth::getUser())) {
         throw new Exception('You are not allowed to like this answer.');
     }
     $answer->toggleLike(Auth::getUser());
     View::renderJson($answer->getContext(Auth::getUser()));
 }
示例#4
0
 /**
  * Determines whether or not a given user can edit the question.
  * @param User $user The user to check.
  * @return boolean
  */
 public function canEdit(User $user)
 {
     // See if they are a professor for the course
     $entry = Entry::fromId($this->getEntryId());
     if ($entry->canEdit($user)) {
         return true;
     }
     // See if they asked the question
     $firstAnswer = QuestionAnswer::fromId($this->getFirstAnswerId());
     if ($firstAnswer->getUserId() == $user->getUserId()) {
         return true;
     }
     // They cannot edit
     return false;
 }
 /**
  * Returns the static model of the specified AR class.
  * Please note that you should have this exact method in all your CActiveRecord descendants!
  * @param string $className active record class name.
  * @return WQuestionAnswer the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }