Exemple #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $users = User::all();
     $book_count = Book::all()->count();
     $chapter_count = Chapter::all()->count();
     return View::make('admin.admin_panel', array('pageTitle' => 'Admin Panel', 'users' => $users, 'book_count' => $book_count, 'chapter_count' => $chapter_count));
 }
 public function get()
 {
     $messages = $this->messageController->getMessages($this::MESSAGE_KEY);
     //contestant take test only one time, so
     //if !admin && has-result >>> redirect to 'result'
     //(admin not blocked, need to review test-page)
     $contestant = Auth::user();
     if ($contestant->id != 1 && $contestant->result != "") {
         return Redirect::to('result');
     }
     //load random-question from database
     $chapters = Chapter::all();
     $random_questions = array();
     foreach ($chapters as $chapter) {
         //each chapter, load random-questions by chapter-rate
         //then store in $random_questions
         //            if($chapter->rate != 0){//make sure chapter has question
         //                $random_questions[] = $chapter->getQuestions->random($chapter->rate);
         //            }
         if (count($chapter->getQuestions) > $chapter->rate) {
             $random_questions[] = $chapter->getQuestions->random($chapter->rate);
         }
     }
     //get timer from test option
     $test_options = TestOption::all();
     $timer = $test_options[0];
     return View::make('test-bootstrap', array('random_questions' => $random_questions, 'timer' => $timer, 'messages' => $messages));
 }
 public function post()
 {
     //page-navigation
     $admin_navigation = new AdminNavigation();
     if ($admin_navigation->isNavigate()) {
         return $admin_navigation->goToN();
     }
     //message-notification
     $messages = array();
     if (Input::has('chapter_rate')) {
         $chapters = Chapter::all();
         //get chapter-data, create chapter-rules for validation
         $chapter_rate_data = array();
         $chapter_rate_rules = array();
         foreach ($chapters as $chapter) {
             $max_rate = $chapter->getQuestions->count();
             $chapter_rate_data[$chapter->id] = Input::get($chapter->id);
             $chapter_rate_rules[$chapter->id] = 'integer|max:' . $max_rate;
         }
         //validate if chapter-rate <= max_rate
         $validator = Validator::make($chapter_rate_data, $chapter_rate_rules);
         if ($validator->fails()) {
             $validate_messages = $validator->messages()->toArray();
             $this->messageController->send($validate_messages, $this::MESSAGE_KEY);
             return Redirect::back();
         }
         //save chapter-rate to database
         $i = -1;
         foreach ($chapters as $chapter) {
             $chapter->rate = Input::get($chapter->id);
             $chapter->save();
             $messages['chapter_rate[' . ++$i . ']'] = 'chapter-' . $chapter->id . '-chapter_rate:saved';
         }
         //return back, show confirm from database
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //as a fallback
     $this->messageController->send($messages, $this::MESSAGE_KEY);
     return Redirect::to('admin/chapter-rate');
 }
 public function post()
 {
     //message-notification
     $messages = array();
     //handle navigation
     $admin_navigation = new AdminNavigation();
     if ($admin_navigation->isNavigate()) {
         return $admin_navigation->goToN();
     }
     //chapters-change
     //delete-chapter
     if (Input::has('delete_chapter')) {
         $chapter = Chapter::find(Input::get('chapter_id'));
         $questions = $chapter->getQuestions;
         if (count($questions) > 0) {
             $messages['delete_chapter'] = 'chapter-' . $chapter->id . ':has questions';
         } else {
             $chapter->delete();
             $messages['delete_chapter'] = 'chapter-' . $chapter->id . ':deleted';
         }
     }
     //new-chapter
     if (Input::has('new_chapter')) {
         $chapter = new Chapter();
         //delete +  auto_increment >>> modidify chapter-id not continuous
         //manually change chapter-id
         $last_chapter = Chapter::all()->last();
         $chapter->id = $last_chapter->id + 1;
         $chapter->text = Input::get('chapter_text');
         $chapter->rate = 0;
         $chapter->save();
         //messages-notification
         $messages['new_chapter'] = 'chapter-' . $chapter->id . '-' . $chapter->text . ':saved';
     }
     $this->messageController->send($messages, $this::MESSAGE_KEY);
     return Redirect::back();
 }