public function getTopicList()
 {
     $currentchapterid = Session::get('chapterid');
     $currentchapter = Chapter::find($currentchapterid);
     $subjectid = $currentchapter->getSubjectID();
     $subject = Subject::find($subjectid);
     return Response::json($subject->getTopics());
 }
 public function saveBook()
 {
     $book = Input::get('book');
     $chapters = Input::get('chapters');
     $bookMdl = Book::find($book['id']);
     $bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']);
     $bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']));
     $bookMdl->save();
     foreach ($chapters as $key => $chapter) {
         if ($chapter['id']) {
             $chapMdl = Chapter::find($chapter['id']);
         } else {
             $chapMdl = new Chapter();
         }
         if ($chapter['id'] && $chapter['isDeleted']) {
             $chapMdl->delete();
         } else {
             $chapMdl->book_id = $chapter['book_id'];
             $chapMdl->title = $chapter['title'];
             $chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null;
             $chapMdl->order = $chapter['order'];
             $chapMdl->save();
             if (count($chapter['elements'])) {
                 foreach ($chapter['elements'] as $key => $element) {
                     if ($element['id']) {
                         $elementMdl = Element::find($element['id']);
                     } else {
                         $elementMdl = new Element();
                     }
                     if ($element['id'] && $element['isDeleted']) {
                         $elementMdl->delete();
                     } else {
                         $elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id'];
                         $elementMdl->order = $element['order'];
                         $elementMdl->type = $element['type'];
                         if ($element['type'] == 4 || $element['type'] == 5) {
                             $elementMdl->content = json_encode($element['content']);
                         } else {
                             $elementMdl->content = $element['content'];
                         }
                         $elementMdl->note = $element['note'];
                         $elementMdl->save();
                     }
                 }
             }
         }
     }
     echo json_encode(['ok']);
 }
 public function getPrev($chid)
 {
     $_action = 'show';
     $chapter = Chapter::find($chid);
     $book = Book::find($chapter->book_id);
     $firstTextElement = Element::where('chapter_id', '=', $chid)->where('type', '!=', '2')->first();
     $firstImage = Element::where('chapter_id', '=', $chid)->where('type', '=', '2')->first();
     $tmpELement = ['id' => $firstTextElement['id'], 'chapter_id' => $firstTextElement['chapter_id'], 'order' => $firstTextElement['order'], 'type' => $firstTextElement['type'], 'content' => $firstTextElement['content'], 'note' => $firstTextElement['note']];
     if ($firstTextElement['type'] == 4 || $firstTextElement['type'] == 5) {
         $tmpELement['content'] = json_decode($firstTextElement['content'], true);
         //dd($element['content']);
     }
     $prevInfo = ['chapter' => $chapter, 'book' => $book, 'info' => $tmpELement ?: null, 'img' => $firstImage ?: null];
     echo json_encode($prevInfo, JSON_NUMERIC_CHECK);
 }
 public function postQuestionChange()
 {
     //message-notification
     $messages = array();
     //handle navigation
     $admin_navigation = new AdminNavigation();
     if ($admin_navigation->isNavigate()) {
         return $admin_navigation->goToN();
     }
     //handle chapter-text change
     //redirect after changed
     if (Input::has('chapter_change')) {
         $chapter = Chapter::find(Input::get('chapter_change'));
         $chapter->text = Input::get('chapter_text');
         $chapter->save();
         $messages['chapter_change_text'] = 'chapter-' . $chapter->id . ':saved';
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //handle delete-question
     //redirect after deleted, no need to modify other inputs
     if (Input::has('delete_question')) {
         $question = Question::find(Input::get('delete_question'));
         $store_question_id = $question->id;
         $question->delete();
         $messages['delete_question'] = 'question-' . $store_question_id . ':deleted';
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //handle change on a question (both this one, and it's options)
     //redirect after all-changes saved
     if (Input::has('question_change')) {
         $question = Question::find(Input::get('question_change'));
         //question-change, change question-text
         if (Input::has('question_text')) {
             $question->text = Input::get('question_text');
             $question->save();
             $messages['question_change_text'] = 'question-' . $question->id . ':saved';
         }
         //question-change, change question-chapter_id
         if (Input::has('chapter_id')) {
             $question->chapter_id = Input::get('chapter_id');
             $question->save();
             $new_chapter = $question->getChapter;
             $messages['question_change_chapter_id'] = 'question-' . $question->id . ':now belongs to chapter-' . $new_chapter->id;
         }
         //options-change
         if (Input::has('options')) {
             $options = Input::get('options');
             //save options-change
             $i = -1;
             foreach ($options as $option_id => $option_text) {
                 $option = Option::find($option_id);
                 $option->text = $option_text;
                 //reset all option-is_right = 0
                 //is_right set again with input-is_right checked
                 $option->is_right = 0;
                 $option->save();
                 $messages['options_change[' . ++$i . ']'] = 'option-' . $option->id . ':saved';
             }
             //modify option-is_right
             if (Input::has('is_right')) {
                 $option = Option::find(Input::get('is_right'));
                 //this option set is_right = 1
                 $option->is_right = 1;
                 $option->save();
                 $messages['options_change_is_right'] = 'option-' . $option->id . '-is_right:saved';
             }
         }
         //send message-notification
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //new-question
     //redirect after create new-one
     if (Input::has('new_question')) {
         //save new question
         $question = new Question();
         //delete + auto_increment >>> modify question-id not continuous
         //manually change question-id
         $last_question = Question::all()->last();
         $question->id = $last_question->id + 1;
         $question->text = Input::get('question_text');
         $question->chapter_id = Input::get('chapter_id');
         $question->save();
         $question_id = $question->id;
         $messages['new_question'] = 'question-' . $question->id . ':saved';
         //save new options
         $options_text = Input::get('options');
         $created_options = array();
         for ($i = 0; $i < 4; $i++) {
             $option = new Option();
             $option->text = $options_text[$i];
             $option->question_id = $question_id;
             $option->is_right = 0;
             $option->save();
             //store in array new-option in $created_options, to add is_right on which
             $created_options[$i] = $option;
             $messages['option[' . $i . ']'] = 'option-' . $option->id . ':saved';
         }
         if (Input::has('is_right')) {
             $right_option = Input::get('is_right');
             //get option from store-$created_options, which selected is_right
             $option = $created_options[$right_option];
             $option->is_right = 1;
             $option->save();
             $messages['option_is_right'] = 'option-' . $option->id . '-is_right:saved';
         }
         //send message-notification
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //as a fallback
     //send message-notification
     $this->messageController->send($messages, $this::MESSAGE_KEY);
     return Redirect::back();
 }
Exemple #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroyChapter($id)
 {
     $chapter_destroy = Chapter::find($id);
     if (Sentry::getUser()->id === $chapter_destroy->author_id) {
         $chapter_destroy->delete();
         return Redirect::to('/dashboard')->with('global_success', 'Your chapter was deleted, but you can start new one with forms on your right.');
     } else {
         return Redirect::to('/dashboard')->with('global_error', 'Come on! Why would you delete not your chapter? See "Edit corner" below to browse your own resources.');
     }
 }
Exemple #6
0
 public function unfavourite($id)
 {
     $user = Auth::User();
     $fav_check = DB::table('favourite_ch')->where('user_id', '=', $user->id)->where('favourite_id', '=', $id)->first();
     if ($fav_check == false) {
         return Redirect::to(URL::to('/chapter/' . Chapter::find($id)->slug))->with('global_error', 'This chapter doesn\'t exists in your favourites.');
     } else {
         $user->favouriteCh()->detach(Chapter::find($id));
         return Redirect::to(URL::previous())->with('global_success', 'Chapter has been removed from favourites.');
     }
 }