public function indexWithQuiz(Request $request, $lecture_id, $subject_id, $assignment_id) { $assignment = Assignment::find($assignment_id); $questionsAll = new Collection(); foreach ($assignment->knowledgeunits()->get() as $knowledgeunit) { //Log::info('111 $knowledgeunit: '.$knowledgeunit->title); $questionsAll = $questionsAll->merge($knowledgeunit->questions()->get()); } $data = array('assignment' => $assignment, 'questionsAll' => $questionsAll); if (isset($subject_id)) { $subject = Subject::find($subject_id); $data["subject"] = $subject; } return view('assignment.quiz', $data); }
/** * Update the specified assignment with request info. * * @param Request $request * @return Response */ public function update_assignment(Request $request, $assignment_id) { if (!Auth::user()->hasRole('admin')) { return view('access_denied'); } $assignment = Assignment::find($request->assignment_id); //check whether professor matches the course $correctProfessorCheck = DB::select('select * from current_professors where user_id = ? and course_id = ?', [$request->professor, $request->course]); if ($correctProfessorCheck == null) { $errors['badProf'] = 'This professor is not currently teaching this course!'; session()->put('error', $errors['badProf']); } //check whether tutor matches the course $correctTutorCheck = DB::select('select * from available_tutors where user_id = ? and course_id = ?', [$request->tutor, $request->course]); if ($correctTutorCheck == null) { $errors['badTutor'] = 'This tutor is not currently tutoring this course!'; session()->put('error', $errors['badTutor']); } //handles errors by setting $errors array and displaying the value in blade if (!empty($errors)) { $data = array('errors' => $errors, 'old' => $request, 'assignment' => $assignment, 'courses' => Course::all(), 'tutors' => UserController::getTutors(), 'students' => UserController::getStudents(), 'professors' => UserController::getProfessors()); return view('assignment_edit', $data); } $assignment->tutor_id = $request->tutor; $assignment->student_id = $request->student; $assignment->course_id = $request->course; $assignment->professor_id = $request->professor; $assignment->save(); session()->put('success', 'Tutor assignment successfully updated!'); return redirect('/assignment/' . $assignment->id); }
public function ajaxChangeStatus() { /// first is for change userassignment in paymentlist page if (Request::input('userAssignment')) { $val = Request::input('val'); $assignID = Request::input('assignID'); $a = UserAssignment::find($assignID); $a->status = $val; $a->save(); } elseif (Request::input('complete_all_assignment')) { $user_id = Request::input('data'); foreach ($user_id as $u) { UserAssignment::where('user_id', $u)->update(array('status' => 5)); } } else { /// for assignment page $val = Request::input('val'); $assignID = Request::input('assignID'); $a = Assignment::find($assignID); $a->status = $val; $a->save(); } }
/** * @param $id * @return mixed */ public function getParameters($id) { $assignments = $this->assignment->find($id); return $assignments; }
public function getGroupsUnAssigned($groupId, $assigmentId) { $assigment = $this->assignment->find($assigmentId); return $assigment->groups()->where('id', '<>', $groupId)->get(); }
public function validate_user_assignment_link() { $link = Request::input('data'); /// user report link $id = Request::input('user_assignment_id'); $ua = UserAssignment::find($id); // user assignment /// used for (maybe) when user reached of max time to repost, then remove and return not exist to move if (!$ua) { return array('statusCode' => 500, 'content' => 'not_exist'); } $current_allow = Setting::where('name', 'time_to_repost')->first()->value; /// reached of allow time to repost if ($ua->time_to_repost == 1) { //// remove current user assignment - return to available /// message to user this assignment is Canceled $ua->delete(); return array('statusCode' => 500, 'content' => 'You have tried <strong>' . $current_allow . '</strong> times to repost but ' . $link . ' is not enough of quality. Your assignment is Canceled', 'overtime' => 'yes'); } $ua->time_to_repost = $ua->time_to_repost - 1; $ua->save(); /////********************************* $true_apply = UserAssignment::where('user_id', Auth::user()->id)->where('id', $id)->first(); if (!$true_apply) { return array('statusCode' => 500, 'content' => 'not_exist'); } $domain = strtolower($link); $domain = parse_url($domain, PHP_URL_HOST); $domain = preg_replace('/(?:https?:\\/\\/)?(?:www\\.)?(.*)\\/?$/i', '$1', $domain); $domain = preg_replace('/\\//i', '$1', $domain); /* * * BEGIN TO VALIDATE AND MINUS TIME TO TRY AND PLUS MORE TIME IF FAILED * If plus more time (minute_to_repost_time) , just get from Setting then plus with: created_at of this UA **/ //// check link domain same with user blog domain if ($domain != Auth::user()->userblog->domain) { $this->plus_time_repost($ua); return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is not match with your blog domain you have registered. You have <strong>' . $ua->time_to_repost . '</strong> times to try again'); } /************************************************/ /// ALL OK $assignment = Assignment::find($ua->assignment_id); $required_link = json_decode($assignment->img_link); $required_keyword = explode(',', $assignment->keyword); $wordcount = $assignment->minimum_wordcount; $curl = curl_init($link); curl_setopt($curl, CURLOPT_NOBODY, true); $result = curl_exec($curl); $headerStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($headerStatusCode == '404') { $this->plus_time_repost($ua); return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> does not exist. You have <strong>' . $ua->time_to_repost . '</strong> times to try again'); } elseif ($headerStatusCode == '301') { return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is redirected, please use direct link. You have <strong>' . $ua->time_to_repost . '</strong> times to try again'); } elseif ($headerStatusCode == '200') { $result_complete_validate = $this->complete_validate_blog($required_link, $link, $required_keyword, $wordcount); if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough') { /// not enough link $this->plus_time_repost($ua); $list_notfollow = ''; if (count($result_complete_validate['list_notfollow'])) { $list_notfollow .= '<ul>'; foreach ($result_complete_validate['list_notfollow'] as $ln) { $list_notfollow .= ' <li><strong> ' . $ln . '</strong> rel="nofollow" is not allowed</li> '; } $list_notfollow .= '</ul>'; } return array('statusCode' => 500, 'content' => 'Number of links required: <strong>' . $result_complete_validate['num'] . '</strong><br>' . $list_notfollow . ' . You have <strong>' . $ua->time_to_repost . '</strong> times to try again'); } if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough-keyword') { $this->plus_time_repost($ua); $list_notOK_keyword = ''; if (count($result_complete_validate['list_notOK_keyword'])) { $list_notOK_keyword .= '<ul>'; foreach ($result_complete_validate['list_notOK_keyword'] as $ln) { $list_notOK_keyword .= ' <li>Keyword: <strong> ' . $ln . '</strong> not found</li> '; } $list_notOK_keyword .= '</ul>'; } return array('statusCode' => 500, 'content' => 'Number of keyword required: <strong>' . $result_complete_validate['num'] . '</strong><br>' . $list_notOK_keyword . '. You have <strong>' . $ua->time_to_repost . '</strong> times to try again'); } if (isset($result_complete_validate['error']) && $result_complete_validate['error'] == 'not-enough-wordcount') { $this->plus_time_repost($ua); return array('statusCode' => 500, 'content' => 'Number of words required: <strong>' . $result_complete_validate['num'] . '</strong>. You have <strong>' . $ua->time_to_repost . '</strong> times to try again'); } /// ALl OKKKKKKKKKKKKKKK. Count user_assignment by assignment_id, if full with status 3, close this assignment UserAssignment::where('user_id', Auth::user()->id)->where('id', $id)->update(array('status' => 3, 'link' => $link, 'approved_at' => date('Y-m-d H:i:s', time()))); /// 2 is Written $total = UserAssignment::where('assignment_id', $ua->assignment_id)->where('status', 3)->count(); if ($total == $assignment->max_blogger) { $assignment->status = 0; $assignment->save(); } return array('statusCode' => 200); } else { $this->plus_time_repost($ua); return array('statusCode' => 500, 'content' => '<strong>' . $link . '</strong> is not valid. You have <strong>' . $ua->time_to_repost . '</strong> times to try again'); } }
public function assignment($id) { $assignment = Assignment::find($id); return view('pages.assignment', compact('assignment')); }