public function post() { //admin-navigation $admin_navigation = new AdminNavigation(); if ($admin_navigation->isNavigate()) { return $admin_navigation->goToN(); } //handle upload file if (Input::hasFile('file_to_upload')) { $file_patth = storage_path(); $file_upload_key = 'file_to_upload'; $csvUtil = new CsvUtil($file_patth, $file_upload_key); $data = $csvUtil->parse(); //now try import by csvUtil :) if (Input::has('model')) { $csvUtil->import(Input::get('model')); $this->messageController->send($csvUtil->getNotify(), $this::MESSAGE_KEY); return Redirect::to('admin/csv')->with('data', $data); } } if (Input::has('export-result')) { $contestants = Contestant::where('result', '>=', 0)->get(); $data = array(); foreach ($contestants as $contestant) { $data[] = array($contestant->id, $contestant->result, $contestant->email); } return CsvUtil::export($data); } //as a fallback return Redirect::to('admin/csv'); }
public function post() { //admin-navigation $admin_navigation = new AdminNavigation(); if ($admin_navigation->isNavigate()) { return $admin_navigation->goToN(); } return false; }
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() { //admin-navigation $admin_navigation = new AdminNavigation(); if ($admin_navigation->isNavigate()) { return $admin_navigation->goToN(); } //message-notification $messages = array(); //at this time, just one option in test-options, so $test_option = TestOption::first(); //'timer' if (Input::has($test_option->key)) { $test_option->value = Input::get($test_option->key); $test_option->save(); $messages[$test_option->key] = $test_option->key . ':saved'; $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); } return Redirect::to('result'); }
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(); }