/** * Execute the console command. * * @return void */ public function fire() { // $tutorials = objectToArray(DB::select(DB::raw('select id from tutorials'))); $tutorials = array_dot($tutorials); $students = array_dot(objectToArray(DB::select(DB::raw('SELECT `user_id` as `id` from `students`')))); $teachers = array_dot(objectToArray(DB::select(DB::raw('SELECT `user_id` as `id` from `teachers`')))); $subjects = array_dot(objectToArray(DB::select(DB::raw('SELECT id from subjects')))); $minimum = $this->option('minimum'); $assessmenttitle = "This is a {title|heading|header} for Assessment."; $assessmentdesc = "This is a sample {data|words|description} for Assessment."; for ($i = 1; $i <= $minimum; $i++) { $assessment = new Assessments(); $assessment->title = self::spintax($assessmenttitle); $assessment->description = self::spintax($assessmentdesc); $assessment->assessmenttype = "presentation"; $assessment->tutorialid = rand(1, 100); $assessment->teacherid = array_rand($teachers); $assessment->subjectid = rand(1, 55); $assessment->studentid = array_rand($students); $assessment->marks = rand(75, 100); $assessment->created_at = self::randDate('10th January 2013', date('jS F o')); $assessment->save(); } }
public function submit() { $userid = Sentry::getUser()->id; $user = Sentry::getUser(); $student = Student::findOrFail($user->id); $ssubjects = $student->extra; $subjects = unserialize($ssubjects); $truth = self::subjectValidator($user->id, $subjects, Input::get('subject')); if ($truth == 0) { return Redirect::to(URL::previous()); } $messages = array('title.required' => 'The :attribute is Required.', 'related_tutorial.unique' => 'You have already submitted a Assessment for this tutorial. Please Update it.You can only submit a Assessment Per Tutorial', 'required' => 'The :attribute is Required'); $validator = Validator::make(Input::all(), array('id' => 'required', 'title' => 'required|max:128|min:5', 'description' => 'max:1024', 'related_tutorial' => "required|unique:assessments,tutorialid,NULL,id,studentid," . $userid, 'submitted_to' => 'required', 'subject' => 'required', 'assessment_type' => 'required'), $messages); if ($validator->fails()) { Input::flash(); return Redirect::to('/assessment/submit')->withErrors($validator); } $assessment = new Assessments(); $assessment->title = Input::get('title'); $assessment->description = Input::get('description'); $assessment->assessmenttype = Input::get('assessment_type'); $assessment->tutorialid = Input::get('related_tutorial'); $assessment->teacherid = Input::get('submitted_to'); $assessment->subjectid = Input::get('subject'); $assessment->studentid = Sentry::getUser()->id; $assessment->save(); $newassessment = DB::table('assessments')->orderby('id', 'desc')->first(); $assessment = Assessments::find($newassessment->id); if (Input::hasFile('attachments')) { $files = Input::file('attachments'); foreach ($files as $file) { if ($file) { $name = $file->getClientOriginalName(); File::makeDirectory(app_path() . '/attachments/assessment-' . $newassessment->id . '/', 777); $file->move(app_path() . '/attachments/assessment-' . $newassessment->id . '/', $name); } } } $data = array(); $data['fname'] = User::find($assessment->studentid)->first_name; $data['lname'] = User::find($assessment->studentid)->last_name; $data['tutorial'] = Tutorials::find($assessment->tutorialid)->name; $data['submittedby'] = User::find($assessment->studentid)->first_name . ' ' . User::find($assessment->studentid)->last_name; $data['submittedon'] = $assessment->created_at; Mail::send('emails.assessmentsubmit', $data, function ($message) use($assessment) { $userid = $assessment->teacherid; $user = Sentry::findUserById($userid); $tutorial = Tutorials::find($assessment->tutorialid); $submittedby = User::find($assessment->studentid); $fullname = $user->first_name . ' ' . $user->last_name; $message->to($user->getLogin(), $fullname)->subject('New Assessment Submitted by ' . $submittedby->first_name . ' ' . $submittedby->last_name . ' on Tutorial ' . $tutorial->name); }); // Input::file('attachment1')->move(app_path().'/attachments/assessment-'.$assessment->id.'/',$name); $theme = Theme::uses('site')->layout('default'); $view = ['id' => $newassessment->id]; $theme->asset()->container('datatables')->writeScript('inline-script', '$(document).ready(function(){ $(\'#attachment\').dataTable({ "sDom": "<\'row\'<\'col-xs-5 col-sm-5 col-md-5\'l><\'col-xs-5 col-sm-5 col-md-5\'f>r>t<\'row\'<\'col-xs-5 col-sm-5 col-md-5\'i><\'col-xs-5 col-sm-5 col-md-5\'p>>", "oLanguage": { "sLengthMenu": "_MENU_ ' . ' Attachments per page" }, "sPagination":"bootstrap" }); });'); return $theme->scope('assessment.update', $view)->render(); }
public function doExam($tid, $eid, $hash) { $userid = Sentry::getUser()->id; $decryptedhash = Crypt::decrypt($hash); if ($decryptedhash == 'tutorial-' . $tid) { Session::put('halt_tutorial_except', 0); Session::put('examid', 0); $validator = Validator::make(Input::all(), ['related_tutorial' => "required|unique:assessments,tutorialid,NULL,id,studentid," . $userid, 'submitted_to' => 'required|exists:users,id', 'subject' => 'required|exists:subjects,id']); if ($validator->fails()) { return "EXAM PAPER HAS BEEN MODIFIED or SUBMITTED AGAIN.Click here to go to <a href='" . Setting::get('app.url') . "'>HOME PAGE</a>. ANSWERS ARE NOT ACCEPTED."; } $tutorial = Tutorials::findOrFail($tid); $exam = Exams::find($eid); $data = array(); $assessment = new Assessments(); $assessment->title = $tutorial->name . ' Exam For ' . $exam->title; $assessment->description = $exam->title . ' exam done for ' . $tutorial->name . ' by ' . Sentry::getUser()->first_name . ' ' . Sentry::getUser()->last_name; $assessment->assessmenttype = "exam"; $assessment->tutorialid = $tid; $assessment->studentid = Sentry::getUser()->id; $assessment->teacherid = $tutorial->createdby; $assessment->subjectid = $tutorial->subjectid; $assessment->save(); $questions = $exam->totalquestions; $input = Input::all(); for ($qc = 1; $qc <= $questions;) { Session::put('checkboxcount', 1); $data['answers'][$qc][1] = ''; $data['answers'][$qc][2] = ''; $data['answers'][$qc][3] = ''; $data['answers'][$qc][4] = ''; if (!isset($input['checkbox_' . $qc])) { $qc++; continue; } foreach ($input['checkbox_' . $qc] as $answer) { // var_dump($answer); $qu = Session::get('checkboxcount', 0); $data['answers'][$qc][$qu] = $answer; Session::put('checkboxcount', ++$qu); } $qc++; } $answerdata = json_encode($data); $nassessment = DB::table('assessments')->orderby('id', 'desc')->first(); $encryptedpath = 'questiondata'; // var_dump(app_path().'/files/assessment/'.$nassessment->id.'/exam-'.$tid.'/'); File::makeDirectory(app_path() . '/files/assessment/' . $nassessment->id . '/exam-' . $eid, 0777, true); file_put_contents(app_path() . '/files/assessment/' . $nassessment->id . '/exam-' . $exam->id . '/' . $encryptedpath . '.json', $answerdata); $failedquestions = []; file_put_contents(app_path() . '/files/assessment/' . $assessment->id . '/exam-' . $exam->id . '/questionfailed.json', $failedquestions); return Redirect::to('/'); // var_dump($decryptedhash); } else { return Redirect::to(URL::previous()); } }