Esempio n. 1
0
 public function run()
 {
     $course = Course::firstOrCreate(['id' => '01234567891011121314151617181920', 'name' => "+2 Science"]);
     $subject = Subject::firstOrCreate(['id' => '23456789101112131415161718192001', 'name' => "Maths", 'ref_id' => $course->id]);
     $module = Module::firstOrCreate(['id' => '12345678910111213141516171819200', 'name' => "Calculas", 'ref_id' => $subject->id]);
     $chapter = Chapter::firstOrCreate(['id' => '45678910111213141516171819200123', 'name' => "Definite Integral", 'ref_id' => $module->id]);
     $topic = Topic::firstOrCreate(['id' => '67891011121314151617181920012345', 'name' => "Introduction", 'ref_id' => $chapter->id]);
     $question = Question::firstOrCreate(['id' => '89101112131415161718192001234567', 'topic_id' => $topic->id, 'question' => "What is the value of x? (x belongs to y) ", 'type' => 2, 'rating' => 3, 'level' => 4, 'source' => null, 'status' => 1, 'subject_id' => $subject->id, 'chapter_id' => $chapter->id, 'module_id' => $module->id]);
 }
 public function getdatas(Request $request)
 {
     $dateline = null;
     $data = null;
     $sort = Input::get("sort");
     $filters = [Input::get("subject") ? Input::get("subject") : null, Input::get("chapter") ? Input::get("chapter") : null, Input::get("topic") ? Input::get("topic") : null, Input::get("rating") ? Input::get("rating") : null, Input::get("level") ? Input::get("level") : null, Input::get("type") ? Input::get("type") : null];
     $activequestions = Question::where('type', '!=', 7)->active()->orderBy("created_at", "DESC");
     //filter subject,chapter,topic
     if ($filters[2]) {
         $activequestions = $activequestions->where('topic_id', $filters[2]);
     } else {
         if ($filters[1]) {
             $activequestions = $activequestions->where('chapter_id', $filters[1]);
         } else {
             if ($filters[0]) {
                 $activequestions = $activequestions->where('subject_id', $filters[0]);
             }
         }
     }
     //filter RATING if
     if ($filters[3]) {
         $activequestions = $activequestions->where('rating', $filters[3]);
     }
     //filter LEVEL if
     if ($filters[4]) {
         $activequestions = $activequestions->where('level', $filters[4]);
     }
     //filter TYPE if
     if ($filters[5]) {
         $activequestions = $activequestions->where('type', $filters[5]);
     }
     //get the query results
     $activequestions = $activequestions->get();
     //
     if ($sort == "authorwise") {
         $data = $this->convertToAuthorwise($activequestions);
         $dateline = $this->getDateLine($activequestions);
     } else {
         if ($sort == "datewise") {
             $data = $this->convertToDatewise($activequestions);
         } else {
             $data = $this->convertToOverall($activequestions);
             $dateline = $this->getDateLine($activequestions);
         }
     }
     return view('superadmin.analytics')->with('questions', $data)->with('datelines', $dateline)->with('sort', $sort)->with('filters', $filters)->with('qtypes', \App\QuestionType::all())->with('subjects', Subject::all())->with('path', $request->path());
 }
 public function asmctq()
 {
     $questions = \App\Models\Contents\Question::all();
     foreach ($questions as $key => $question) {
         $topic = \App\Models\Contents\Topic::find($question->topic_id);
         $chapter = $topic->chapter;
         $module = $chapter->module;
         $subject = $module->subject;
         if (!$question->chapter_id) {
             $question->chapter_id = $chapter->id;
         }
         if (!$question->module_id) {
             $question->module_id = $module->id;
         }
         if (!$question->subject_id) {
             $question->subject_id = $subject->id;
         }
         $question->save();
     }
     return view('superadmin.taskdone');
 }
 public function payuser($uid)
 {
     $questions = Question::where('type', '!=', 7)->where('author_id', $uid)->active()->get();
     foreach ($questions as $key => $question) {
         if ($question->credit) {
             $question->credit()->update(["status" => 1]);
         }
     }
     return redirect()->back();
 }
 public function getquestionshareurl($questionid)
 {
     $question = Question::findOrFail($questionid);
     $topic = $question->topic;
     $chapter = $topic->chapter;
     $subject = $chapter->module->subject;
     $course = $subject->course;
     $out = "/" . $course->name . "/" . $subject->name . "/" . $chapter->name . "/" . $topic->name . "/" . $questionid;
     return $out;
 }
 public function getUserCredit($id)
 {
     $questions = Question::where('status', 1)->where('type', '!=', 7)->where('author_id', $id)->get();
     $totalCredits = 0;
     $unpaid = 0;
     $paid = 0;
     foreach ($questions as $key => $question) {
         $credit = $question->credit;
         if ($credit) {
             //old questions dont have credit
             if ($credit->status == 0) {
                 $unpaid += $credit->credit;
             } else {
                 if ($credit->status == 1) {
                     $paid += $credit->credit;
                 }
             }
             $totalCredits += $credit->credit;
         }
     }
     return ["total" => $totalCredits, "paid" => $paid, "unpaid" => $unpaid];
 }
 public function generate(Request $req)
 {
     $date = $req->get("date");
     $options = $req->get('options');
     $totalnoq = 0;
     $questionResult = [];
     foreach ($options as $key => $option) {
         $allquestions = Question::active()->notsubquestion();
         $localQ = collect([]);
         $localNoq = $option["noq"];
         $totalnoq += $localNoq;
         $temp = null;
         if (isset($option["pureRandom"]) && $option["pureRandom"]) {
             $temp = $allquestions->get();
         } else {
             if (isset($option["topic"]) && $option["topic"]) {
                 $temp = $allquestions->where('topic_id', $option["topic"])->get();
             } else {
                 if (isset($option["chapter"]) && $option["chapter"]) {
                     $temp = $allquestions->where('chapter_id', $option["chapter"])->get();
                 } else {
                     if (isset($option["module"]) && $option["module"]) {
                         $temp = $allquestions->where('module_id', $option["module"])->get();
                     } else {
                         if (isset($option["subject"]) && $option["subject"]) {
                             $temp = $allquestions->where('subject_id', $option["subject"])->get();
                         } else {
                             $temp = $allquestions->get();
                         }
                     }
                 }
             }
         }
         // if($key+1==2){
         //  dd($option["subject"], $temp);
         // }
         //check for number of questions available
         if ($localNoq <= count($temp)) {
             //if has enough questions
             $localQ = $temp->random($localNoq)->toArray();
             if ($localNoq == 1) {
                 $localQ = [$localQ];
             }
             foreach ($localQ as $key => $question) {
                 if (in_array($question["id"], $questionResult)) {
                     //if question already there in result
                     //remove that question from data get
                     $temp = $temp->reject(function ($value, $key) {
                         return $value->id == $question->id;
                     });
                     //if more questions are there
                     //push one new random instead of current which is already there
                     if (count($temp) > 1) {
                         array_push($localQ, $temp->random(1)->toArray());
                     } else {
                         return \Response::json("Card no. " . ($key + 1) . " has not enough questions in database with the given options!", 500);
                     }
                 } else {
                     //if question no in result ; good to push
                     array_push($questionResult, $question["id"]);
                 }
             }
         } else {
             //not enough questions
             // dd($localNoq, $temp, $option);
             return \Response::json("Card no. " . ($key + 1) . " has not enough questions in database with the given options!", 500);
         }
     }
     $rq = new RandomQuestion();
     $rq->id = Uuid::generate();
     $rq->date = $date;
     $rq->noq = $totalnoq;
     $rq->created_by = \Auth::user()->id;
     $rq->save();
     foreach ($questionResult as $key => $value) {
         $lol = RandomQuestionList::create(["ref_id" => $rq->id, "question_id" => $value]);
     }
     return \Response::json(["id" => $rq->id . ""], 200);
 }