Example #1
0
 public function post_write(Request $request)
 {
     $this->authorize('qna-write');
     $request->merge(['writer_id' => Auth::user()->id]);
     $a = Answer::create($request->all());
     return redirect("qs/{$a->q_id}#{$a->id}");
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request, $qId)
 {
     $answer = $request->all();
     $answer['question_id'] = $qId;
     $answer = Answer::create($answer);
     return redirect('admin/questions/' . $qId . '/answers/' . $answer->id);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = JWTAuth::parseToken()->authenticate();
     $user_id = $user->id;
     $question = Question::find($request['question_id']);
     if (!$question) {
         return response()->json(['success' => false, 'message' => "invalid question id."]);
     }
     $question_owner = $question->owner();
     //        dd($question_owner);
     if ($user->points == 0) {
         return response()->json(['success' => false, 'message' => "Please recharge"]);
     }
     //validate data
     $validator = Validator::make($request->all(), array('text' => 'required', 'question_id' => 'required'));
     if ($validator->fails()) {
         return $validator->errors()->all();
     } else {
         $previousAnswer = Answer::where('question_id', $request['question_id'])->where('user_id', $user_id)->get();
         if (count($previousAnswer) > 0) {
             return response()->json(['success' => false, 'message' => "You've already answered this question before.", 'answer' => $request['text']]);
         } else {
             $follower_user = $user->id . "_" . $question_owner->id;
             Answer::create(['text' => $request['text'], 'user_id' => $user_id, 'question_id' => $request['question_id'], 'follower_user' => $follower_user]);
             try {
                 $user->addFollowing($question_owner);
                 $user->points = $user->points - 1;
                 $user->save();
             } catch (Exception $e) {
             }
         }
         return response()->json(['success' => true, 'message' => "Answer Added Successfully", 'answer' => $request['text']]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('answers')->delete();
     $answers = array(['text' => 'answer1', 'user_id' => 3, 'question_id' => 1, 'follower_user' => '3_2'], ['text' => 'answer2', 'user_id' => 2, 'question_id' => 2, 'follower_user' => '8_2'], ['text' => 'answer3', 'user_id' => 1, 'question_id' => 2, 'follower_user' => '7_2'], ['text' => 'answer4', 'user_id' => 4, 'question_id' => 1, 'follower_user' => '6_2']);
     // Loop through each user above and create the record for them in the database
     foreach ($answers as $answer) {
         Answer::create($answer);
     }
 }
 public function storeAnswer($id, AnswerRequest $request)
 {
     if ($request->input('to_message') == $id) {
         Answer::create(['answer' => $request->input('answer'), 'user_id' => \Auth::id(), 'user_name' => \Auth::user()->name, 'to_message' => $request->input('to_message')]);
         flash()->success('Wiadomość prywatna została wysłana!');
         return redirect('/private/' . $request->input('to_message') . '');
     } else {
         return 'Oszust!';
     }
 }
Example #6
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Factory::create('fr_FR');
     $subjectsCount = Subject::all()->count();
     for ($qcms = 0; $qcms < 100; $qcms++) {
         $qcm = Qcm::create(['user_id' => 1, 'subject_id' => rand(1, $subjectsCount - 1), 'name' => $faker->sentence(6), 'description' => $faker->sentence(40)]);
         for ($questions = 0; $questions < rand(5, 10); $questions++) {
             $question = Question::create(['qcm_id' => $qcm->id, 'question' => $faker->sentence(20)]);
             for ($answers = 0; $answers < rand(2, 4); $answers++) {
                 Answer::create(['question_id' => $question->id, 'answer' => $faker->sentence(10), 'isValid' => $answers == 0]);
             }
         }
     }
 }
Example #7
0
 function answers()
 {
     $add = 1;
     $faker = Faker::create();
     $users = User::all();
     $questions = Question::lists('id');
     foreach ($users as $user) {
         foreach ($questions as $q) {
             $add++;
             $ts = \Carbon\Carbon::createFromDate(2015, 07, 22)->addMinutes($add)->toDateTimeString();
             Answer::create(['user_id' => $user->id, 'question_id' => $q, 'body' => $faker->paragraph, 'created_at' => $ts, 'updated_at' => $ts]);
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (!isset($request->qcode)) {
         return redirect('questionnaire')->with('error', 'Questionnaire code not set');
     }
     $guest = Guest::findByQcode($request->qcode);
     if (!isset($guest)) {
         return redirect('questionnaire')->with('error', 'Cannot find that questionnaire code');
     }
     // Check for changes to the guest
     $delta = $this->delta_check($guest, $request);
     $answer = Answer::create($request->all() + ['guest_id' => $guest->id, 'delta' => $delta]);
     Session::flash('message', 'Answer added for ' . $guest->full_name . '!');
     return redirect()->route('answers', ['guest' => $guest, '#view2016']);
 }
 public function store()
 {
     $data = Input::all();
     if (Input::get('comment_id') == '') {
         if (Comment::create($data)) {
             return Redirect::back()->withErrors(Null);
         } else {
             return Redirect::back()->withInput()->withErrors('comment publish fail!');
         }
     } else {
         if (Answer::create($data)) {
             return Redirect::back()->withErrors(Null);
         } else {
             return Redirect::back()->withInput()->withErrors('comment reply fail!');
         }
     }
 }
Example #10
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $rules = ['name' => 'required|min:5', 'class' => 'required', 'subject_id' => 'required', 'partition_id' => 'required'];
     $attrName = [0 => 'с първият отговор', 1 => 'с вторият отговор', 2 => 'с третият отговор', 3 => 'с четвъртият отговор', 4 => 'с петият отговор', 5 => 'с шестият отговор', 6 => 'с седмият отговор', 7 => 'с осмият отговор'];
     foreach ($request->get('answers') as $key => $value) {
         $rules['answers.' . $key] = 'required|min:5';
         $messages['answers.' . $key . '.required'] = 'Полето ' . $attrName[$key] . ' е задължително.';
         $messages['answers.' . $key . '.min'] = 'Полето ' . $attrName[$key] . ' трябва да бъде минимум :min знака.';
     }
     $validator = \Validator::make($request->all(), $rules, $messages);
     if ($validator->fails()) {
         return $validator->errors()->toJSON();
     }
     $user_id = \Auth::user()->id;
     $input = $request->all();
     $input['user_id'] = $user_id;
     $reqCorrect = $request->get('correct');
     if (sizeof($reqCorrect) > 1) {
         $input['type'] = 'multiple';
     } else {
         $input['type'] = 'one';
     }
     $question = Question::create($input);
     foreach ($request->get('answers') as $key => $value) {
         $correct = false;
         if (sizeof($reqCorrect) > 1) {
             foreach ($reqCorrect as $k => $v) {
                 if ($key == $reqCorrect[$k]) {
                     $correct = true;
                 }
             }
         } else {
             if ($key == $reqCorrect[0]) {
                 $correct = true;
             }
         }
         Answer::create(['name' => $value, 'question_id' => $question->id, 'correct' => $correct]);
     }
     \Session::flash('flash_message', 'Въпросът беше успешно добавен!');
     return ['type' => 'redirect', 'url' => url(route('admin.question.index'))];
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     // $this->call(ClassTableSeeder::class);
     //Optional just to clear table
     // DB::table('answers')->delete();
     // DB::table('questions')->delete();
     // DB::table('classes')->delete();
     // DB::table('users')->delete();
     $student1 = User::create(['name' => 'Scotty Gomez', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $student2 = User::create(['name' => 'Misha Dowd', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $lecturer = User::create(['name' => 'Dr. Andre Chen', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'lecturer']);
     $this->command->info('User Created!');
     $course = Course::create(['name' => 'Math', 'term' => 'Fall2020', 'lecturer_id' => $lecturer->id]);
     $this->command->info('Course Created!');
     $quiz = Quiz::create(['course_id' => $course->id, 'description' => 'A Quiz to Test Your Might!', 'quizTime' => '20', 'startDate' => '10.29.2015', 'endDate' => '10.30.2015']);
     $this->command->info('Quiz Created!');
     //Questions
     $q = Question::create(['prompt' => 'What is the sqare root of 4?', 'difficulty' => 'easy']);
     $q1 = Question::create(['prompt' => 'What is 2 X 3?', 'difficulty' => 'easy']);
     $this->command->info('2 Questions Created!');
     //Answers
     $a = Answer::create(['text' => '6', 'image' => NULL]);
     $a1 = Answer::create(['text' => '2', 'image' => NULL]);
     $a2 = Answer::create(['text' => '6', 'image' => NULL]);
     $a11 = Answer::create(['text' => '5', 'image' => NULL]);
     $this->command->info('All 4 Answers Created!');
     // Adding User to Course
     $course->users()->sync([$student1->id, $student2->id]);
     // Syncing Quiz to Questions
     $quiz->questions()->sync([$q->id, $q1->id]);
     // Syncing (Binding Qustion to Answer)
     $q->answers()->sync([$a->id, $a1->id]);
     $q1->answers()->sync([$a2->id, $a11->id]);
     $this->command->info('Everything Created and Linked!');
     Model::reguard();
 }
Example #12
0
 /**
  * Initially store the entry and send the user to Paypal for payment
  * @param Request $request
  */
 public function store(Request $request)
 {
     // Get the data from the request
     $data = $request->all();
     //dd($data);
     $user = Auth::user();
     //1. Insert each competition entry into the database with 'unpaid' status
     foreach ($data['competitions'] as $competition_id => $detail_id) {
         if ($detail_id != "noEntry") {
             $entryData = array();
             $entryData['user_id'] = $user->id;
             $entryData['event_id'] = $data['event_id'];
             $entryData['competition_id'] = $competition_id;
             $entryData['detail_id'] = $detail_id;
             $entryData['user_lastname'] = $user->lastname;
             $entryData['paymentStatus'] = 'unpaid';
             $entryData['discounts_applied'] = $data['discounts_applied'];
             //Now insert the data
             //dd($entryData);
             Entry::create($entryData);
         }
     }
     //2. Insert question answers in to answers table
     if (key_exists('questions', $data)) {
         foreach ($data['questions'] as $question_id => $question_answer) {
             $answerData = array();
             $answerData['question_id'] = $question_id;
             $answerData['competitor_id'] = $user->id;
             $answerData['event_id'] = $data['event_id'];
             if ($question_answer) {
                 $answerData['answer'] = $question_answer;
             }
             //if "" then default will be "No answer given" as per schema.
             //create the answer
             //dd($answerData);
             Answer::create($answerData);
         }
     }
     //3. Insert any extras that have been ordered into orders table
     //dd($data['extras']);
     if (key_exists('extras', $data)) {
         foreach ($data['extras'] as $extra_id => $extraOrder) {
             $orderData = array();
             $orderData['extra_id'] = $extra_id;
             $orderData['event_id'] = $data['event_id'];
             $orderData['user_id'] = $user->id;
             if ($extraOrder != "order") {
                 //This is an extra order with an array of info
                 if (array_key_exists('multiple', $extraOrder)) {
                     $orderData['multiple'] = $extraOrder['multiple'];
                 }
                 if (array_key_exists('infoRequired', $extraOrder)) {
                     $orderData['infoRequired'] = $extraOrder['infoRequired'];
                 }
             }
             //create the extra order
             ExtraOrder::create($orderData);
         }
     }
     //4. Send off the payment request to paypal (success=success, fail=delete above)
     //send over the event id, then later grab all the entries for this
     // user from the database and change the status or delete as appropriate after paypal payment.
     $event = Event::findOrFail($data['event_id']);
     try {
         $transactionDescription = "Entry fees for " . $event->name . ": £" . $data['total'];
         $transaction = $this->gateway->purchase(array('amount' => $data['total'], 'currency' => 'GBP', 'description' => $transactionDescription, 'returnUrl' => 'http://foresightentries.app/entry/paid/' . $event->id, 'cancelUrl' => 'http://foresightentries.app/entry/cancelled/' . $event->id));
         $transaction->setItems(array(array('name' => "Entry fees ({$event->name})", 'quantity' => '1', 'price' => $data['total'])));
         //SO THE BIG QUESTION HERE IS HOW DO I SEND THE PAYMENTS IN BITS TO ME AND
         //EVENT ORGANISER? Not right now. I'll do it manually at the closing date.
         $response = $transaction->send();
         if ($response->isRedirect()) {
             $response->redirect();
         } else {
             echo $response->getMessage();
             //do something here, presumably redirect to an error page.
         }
     } catch (\Exception $e) {
         echo "Exception caught while attempting authorize.\n";
         echo "Exception type == " . get_class($e) . "\n";
         echo "Message == " . $e->getMessage() . "\n";
     }
 }
Example #13
0
 /**
  * Post answer to correponding questions by an user.
  *	It's ajax function
  * @return Response
  */
 public function addAnswer(Request $request)
 {
     //print_r(json_encode(array("status"=>true)));
     $statusCode = 200;
     $response = ['status' => false, 'msg' => ""];
     //echo $request->input('questionid');exit;
     if ($request->input('questionid') != '') {
         $answerData = array("answer" => $request->input('answer'), "question_id" => $request->input('questionid'), "user_id" => Auth::user()->id);
         $addAnswer = Answer::create($answerData);
         if ($addAnswer) {
             $response = ['status' => true, 'msg' => "Added successfully"];
         } else {
             $response = ['status' => false, 'msg' => "Please try after some time"];
         }
     } else {
         $response = ['status' => false, 'msg' => "Question number is required"];
     }
     return response()->json($response, $statusCode);
 }
 public function postCreate(Request $request)
 {
     $this->validate($request, ['name' => 'required|string', 'description' => 'required|string', 'subject_id' => 'required|in:' . implode(',', array_keys(Subject::toList())), 'questions' => 'required|array', 'valids_answers' => 'required|array|size_array:questions|answer_exists:answers', 'answers' => 'required|array']);
     $qcm = DB::transaction(function () use($request) {
         $datas = $request->all();
         // Création du QCM wow!!§
         $qcm = Qcm::create(['user_id' => Auth::id(), 'subject_id' => $datas['subject_id'], 'name' => $datas['name'], 'description' => $datas['description']]);
         foreach ($datas['questions'] as $q => $question) {
             // Création des questions associées au QCM !!§
             $question = Question::create(['qcm_id' => $qcm->id, 'question' => $question]);
             foreach ($datas['answers'][$q] as $a => $answer) {
                 // Création des réponses associées aux questions !§§
                 $answer = Answer::create(['question_id' => $question->id, 'answer' => $answer, 'isValid' => (int) $datas['valids_answers'][$q] === $a]);
             }
         }
         return $qcm;
     });
     if ($qcm != null) {
         Session::push('messages', 'success|Votre QCM a bien été créé');
         return redirect()->route('qcm::mine');
     } else {
         Session::push('messages', "danger|Le QCM n'a pas été créé");
         return redirect(URL::previous());
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     Answer::create(['body' => $request->get('body'), 'created_at' => Carbon\Carbon::now(), 'updated_at' => Carbon\Carbon::now(), 'user_id' => Auth::user()->id, 'question_id' => $request->get('question_id')]);
     return redirect()->back()->with('status', 'Answer successfully posted');
 }
 public function postSaveQuestionResult($id, Request $req)
 {
     //save result
     $subject = Subject::find($id);
     $question = Question::find($req->get('question_id'));
     if ($req->get('option') != null) {
         //save the answer into table
         $duration = $subject->duration * 60;
         $time_taken = $req->get('time_taken' . $question->id);
         $time_per_question = $duration - $time_taken;
         //dd($time_taken);
         Answer::create(['user_id' => Auth::user()->id, 'question_id' => $req->get('question_id'), 'subject_id' => $id, 'user_answer' => $req->get('option'), 'question' => $question->question, 'option1' => $question->option1, 'option2' => $question->option2, 'option3' => $question->option3, 'option4' => $question->option4, 'right_answer' => $question->answer, 'time_taken' => $time_per_question]);
     }
     $next_question_id = $subject->questions()->where('id', '>', $req->get('question_id'))->min('id');
     if ($next_question_id != null) {
         return Response::json(['next_question_id' => $next_question_id]);
     }
     return redirect()->route('result', [$id]);
 }
 public function saveDraftAnswer()
 {
     $user_id = Auth::user()->id;
     Answer::create(['question_id' => $_GET['question'], 'user_id' => $user_id, 'answer' => $_GET['answer'], 'points' => $_GET['points']]);
 }