public function loadsolution($questionid) { $solution = Solution::where('question_id', $questionid)->first(); $out = ['solution' => []]; //=$solution->question; if (!$solution) { $question = Question::find($questionid); if ($question->type == 5) { foreach ($question->paragraphQuestions as $qqq) { array_push($out['solution'], $this->loadsolution($qqq->id)); } } } else { $out = ['solution' => $solution]; } return $out; }
public function accept($id = '') { $questionid = Input::get('id'); $credit = Input::get('credit'); $qq = QuestionRejected::where('question_id', $questionid)->first(); if ($qq) { $qq->delete(); } $qr = QuestionCredit::where('question_id', $questionid)->first(); if (!$qr) { $qr = new QuestionCredit(); } $qr->creditor_id = \Auth::user()->id; $qr->question_id = $questionid; $qr->credit = $credit; $qr->save(); $q = Question::find($questionid); $q->status = 1; $q->save(); return back(); }
public function createQuestion($uuid, $topicuuid, $questions, $level, $rating, $sources, $type, $edit) { $topic = Topic::find($topicuuid); $chapter = $topic->chapter; $module = $chapter->module; $subject = $module->subject; // dd($chapter,$module,$subject); // dd($topic->name, $chapter->name,$subject->name); if (!$edit) { return Question::create(["id" => $uuid, "topic_id" => $topicuuid, "question" => $questions, "level" => $level, "rating" => $rating, "source" => $sources, "type" => $type, "chapter_id" => $chapter->id, "subject_id" => $subject->id, "module_id" => $module->id, 'author_id' => \Auth::user()->id]); } else { // $question = new \stdClass(); Question::where('id', $uuid)->first()->update(['topic_id' => $topicuuid, 'question' => $questions, 'level' => $level, 'rating' => $rating, 'source' => $sources, 'type' => $type, "chapter_id" => $chapter->id, "subject_id" => $subject->id, "module_id" => $module->id, "status" => 3]); // $asd=$question; $question = Question::find($uuid); if ($question->type == 5) { //delete sub paragraphQuestions if there if ($question) { foreach ($question->paragraphQuestions as $key => $question) { $question->delete(); } } } return $question; } }