Exemplo 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 questionsbyTopicName($coursename, $subject, $chapterName, $topicName)
 {
     $topics = Topic::where('name', $topicName)->get();
     $topicID = null;
     if (count($topics) == 1) {
         $topicID = $topics->first()->id;
     } else {
         $subjects = Course::where('name', $coursename)->first()->subjects()->where('name', $subject)->get();
         $questions = collect([]);
         foreach ($subjects as $subject) {
             foreach ($subject->modules as $module) {
                 foreach ($module->chapters as $chapter) {
                     if ($chapter->name === $chapterName) {
                         foreach ($chapter->topics as $topic) {
                             if ($topic->name === $topicName) {
                                 $topicID = $topic->id;
                                 break 4;
                             }
                         }
                     }
                 }
             }
         }
     }
     return Question::where('topic_id', $topicID);
 }
 public function add($typeid, $ref_uuid)
 {
     $uuid = Uuid::generate();
     switch ($typeid) {
         case 0:
             //Course
             $course = new Course();
             $course->name = Input::get('name');
             $course->id = $uuid->string;
             $course->save();
             return $course;
         case 1:
             //Subject
             $item = new Subject();
             break;
         case 2:
             //Module
             $item = new Module();
             break;
         case 3:
             //Cha[ter]
             $item = new Chapter();
             break;
         case 4:
             //Topic
             $item = new Topic();
             break;
         default:
             # code...
             break;
     }
     $item->name = Input::get('name');
     $item->id = $uuid->string;
     $item->ref_id = $ref_uuid;
     $item->save();
     return $item;
 }
 public function getcourses()
 {
     return Course::all();
 }