Example #1
0
 /**
  * @return Collection
  */
 function getListQuestion()
 {
     $details = $this->details;
     $listIDQuestion = $details->lists('id_question');
     $listIDQuestion = array_unique($listIDQuestion);
     $questions = Question::whereIn('id', $listIDQuestion)->get();
     return $questions;
 }
Example #2
0
        $sets = Set::valid()->get();
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($sets);
    });
    $app->get('/:id', function ($id) use($app) {
        //      $set = Set::find($id);
        $ids = explode(';', $id);
        $set = Set::whereIn('id', $ids)->get();
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($set);
    });
    $app->get('/:id/questions', function ($id) use($app) {
        $ids = explode(';', $id);
        $questions = Question::whereIn('set_id', $ids)->get();
        $questions->load('answers');
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($questions);
    });
});
$app->group('/question(s)', function () use($app) {
    $app->get('/', function () use($app) {
        $questions = Question::with('answers')->get();
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($questions);
    });
    $app->get('/:id', function ($id) use($app) {
        $question = Question::with('answers')->find($id);
    public function emergencyUse()
    {
        //for($i=0;$i<10;$i++)
        //{
        ini_set('max_execution_time', 1000);
        $start = microtime(true);
        $userIds = array();
        $users = DB::select(DB::raw("select * from users where role!='admin_dd' and role!='sales_dd' and batchUpdate=2 Limit 10"));
        // $users = User::where('role','!=','admin_dd')->orWhere('role','!=','sales_dd')->orderby('name')->get();
        $userQuestion = array();
        $count = 1;
        foreach ($users as $user) {
            $userEvent_tmp[] = $user->event;
            $userIds[] = $user->id;
        }
        if (count($userIds) < 1) {
            dd("No User to be updated");
        }
        $userEvent = array_unique($userEvent_tmp);
        $questions_tmp = Question::whereIn('event', $userEvent)->get();
        $answerpair = Answer::whereIn('user_id', $userIds)->get();
        foreach ($questions_tmp as $question) {
            $userQuestionx[$question->event][] = $question;
        }
        foreach ($answerpair as $answer) {
            $userAnswers[$answer->question_id][] = $answer->user_id;
        }
        // $result = DB::select(DB::raw("select user_id,question_id from answers where  "));
        foreach ($users as $user) {
            foreach ($userQuestionx[$user->event] as $question) {
                // foreach($users as $user)
                $userQuestion[] = array($question->id, $user->id);
            }
        }
        $updated = false;
        foreach ($userQuestion as $pairval) {
            $answerx = new Answer();
            ?>
<div style="margin-bottom:30px;background:pink"><?php 
            if (!array_key_exists($pairval[0], $userAnswers)) {
                echo "<div style='background:yellow'>The Question answer is updated</div><br/>";
                $answerx->question_id = $pairval[0];
                $answerx->user_id = $pairval[1];
                $answerx->answer_text = '';
                //$answerx->save;
                //DB::select(DB::raw("insert into updatedanswertable (`questionid`,`userid`) values ('$pairval[0]','$pairval[1]') "));
                DB::select(DB::raw("insert into answers (`question_id`,`user_id`,`answer_text`) values ('{$pairval['0']}','{$pairval['1']}','') "));
                echo $pairval[0] . ",";
                echo $pairval[1] . "<br/>";
                $updated = true;
            } else {
                echo "The Question answer pair is already there<br/>";
                echo $pairval[0] . ",";
                echo $pairval[1] . "<br/>";
                $updated = true;
            }
            ?>
</div><?php 
            if ($updated == true) {
                DB::select(DB::raw("update users set batchUpdate=12 where id='{$pairval['1']}' "));
            }
        }
        $total = microtime(true) - $start;
        echo "Time to execute :" . $total;
        //sleep(10 * 60);
        //}
    }
Example #4
0
 public function main()
 {
     $defaultQuestions = Question::whereIn('id', [1, 2, 3, 4])->get();
     return View::make('home.main', compact('defaultQuestions'));
 }
Example #5
0
 function view($id, $idQuestion = null)
 {
     if ($idQuestion == null) {
         $adviceDetails = AdviceDetail::where('id_advice', $id)->get();
         $listHistory = Question::whereIn('id', array_diff($adviceDetails->lists('id_question'), Question::$_rootQuestionID))->get();
         if (array_unique($adviceDetails->lists('id_question')) == Question::count()) {
             return View::make('advice.view', ['select' => 'next', 'question' => null, 'listHistory' => $listHistory, 'id' => $id, 'tours' => []]);
         }
         if ($adviceDetails->count() == 0) {
             return Redirect::route('advice.view', ['id' => $id, 'idQuestion' => 'root']);
         } else {
             $adviceDetails = AdviceDetail::where('id_advice', $id)->get();
             //=============
             $questionAnswerLoc = AdviceDetail::where('id_advice', $id)->where('id_question', 1)->first();
             $location = Location::join(Answer::getTableName(), Answer::getTableName() . '.name', '=', Location::getTableName() . '.code')->where(Answer::getTableName() . '.id', $questionAnswerLoc->id_answer)->select(Location::getTableName() . '.*')->first();
             $tours = Tour::where('start_loc', $location->id)->get();
             $listAnsOfNotFactor = $adviceDetails->filter(function ($row) {
                 return !in_array($row->id_question, Question::$_rootQuestionID);
             });
             if ($listAnsOfNotFactor->count() > 0) {
                 $arrAnsPoint = $this->scoreAnswer($listAnsOfNotFactor->lists('id_answer'));
                 $arrAnsPoint = $this->interaction($arrAnsPoint);
                 $idAttrForNext = $this->getAttributeForNext($arrAnsPoint);
                 if ($idAttrForNext) {
                     $listIDQuestionHistory = $adviceDetails->lists('id_question');
                     $strAvoid = implode(',', $listIDQuestionHistory);
                     $questionForNext = DB::select("\n                            SELECT `questions`.*\n                            FROM `questions`\n                            INNER JOIN `question_answer`\n                            ON `questions`.`id` = `question_answer`.`id_question`\n                            INNER JOIN `answers`\n                            ON `question_answer`.`id_answer` = `answers`.`id`\n                            WHERE `answers`.`id_attribute` = {$idAttrForNext}\n                            AND `questions`.`id` NOT IN ({$strAvoid})\n                            GROUP BY `question_answer`.`id_question`\n                            ORDER BY COUNT(DISTINCT `question_answer`.`id_answer`) DESC\n                        ")[0];
                     $question = new Question((array) $questionForNext);
                 }
             } else {
                 $question = Question::find(5);
             }
             return View::make('advice.view', ['select' => 'next', 'question' => $question, 'listHistory' => $listHistory, 'id' => $id, 'tours' => $tours]);
         }
     } else {
         if ($idQuestion == 'root') {
             $questions = Question::whereIn('id', Question::$_rootQuestionID)->get();
             $listHistory = new Collection();
             return View::make('advice.view', ['select' => 'root', 'questions' => $questions, 'listHistory' => $listHistory, 'id' => $id]);
         } else {
             $question = Question::find($idQuestion);
             $adviceDetails = AdviceDetail::where('id_advice', $id)->get();
             $listHistory = Question::whereIn('id', array_diff($adviceDetails->lists('id_question'), array_merge(Question::$_rootQuestionID, [$idQuestion])))->get();
             return View::make('advice.view', ['select' => 'history', 'question' => $question, 'listHistory' => $listHistory, 'id' => $id]);
         }
     }
 }