Пример #1
0
 public function getEntries()
 {
     if (Auth::user()->isTeacher()) {
         $users = [];
         $archive = Archive::with('user', 'test', 'test.course', 'test.questions')->has('test')->has('user');
         foreach (Auth::user()->groups as $group) {
             foreach ($group->users as $user) {
                 $users[$user->id] = true;
             }
         }
         $archive->where(function ($query) use($users) {
             foreach (array_keys($users) as $key => $user_id) {
                 if ($key == 0) {
                     $query->where('user_id', $user_id);
                 } else {
                     $query->orWhere('user_id', $user_id);
                 }
             }
         });
         $archive = $archive->orderBy('created_at', 'ASC');
     } else {
         $archive = Archive::with('user', 'test', 'test.course', 'test.questions')->has('test')->has('user')->orderBy('created_at', 'ASC');
     }
     return $archive;
 }
Пример #2
0
 function store($id, Request $request, TestValidator $testvalidator)
 {
     $archive = Archive::with('user', 'test', 'test.questions', 'test.course')->has('user')->has('test')->findOrFail($id);
     $feedback = [];
     foreach ($request->get('feedback') as $key => $item) {
         $temp = htmlspecialchars(trim($item));
         if (strlen($temp) > 0) {
             $feedback[$key] = $temp;
         }
     }
     $reviewer = \Auth::user();
     if ($archive && count($feedback) > 0) {
         $archive->data = json_decode($archive->data, true);
         if ($archive->replied_to == 0) {
             $validation = $testvalidator->WithAnswers($archive->test, $archive->data['given_answers']);
             $mail_data = ['user' => $archive->user, 'test' => $archive->test, 'data' => $archive->data, 'reviewer' => $reviewer, 'feedback' => $feedback, 'validation' => $validation['validation']];
             // Email notification
             Mail::send('email.feedback_notification', $mail_data, function ($m) use($archive) {
                 $m->to($archive->user->email, $archive->user->name)->subject('Koepalautetta Media7 Raamattuopistolta');
             });
         }
         $data = $archive->data;
         $data['feedback'] = $feedback;
         $archive->data = json_encode($data);
         $archive->replied_to = 1;
         $archive->reviewed_by = $reviewer->id;
         $archive->discarded = 0;
         $archive->save();
         return ['success' => 1];
     } elseif (count($feedback) == 0) {
         $errors[] = "Anna edes jotain palautetta!";
     }
     return ['success' => 0, 'feedback' => $feedback, 'errors' => $errors];
 }
Пример #3
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $departmentId = null;
     if ($this->systemAdmin) {
         if (session('department_filter_id')) {
             $departmentId = session('department_filter_id');
         }
     } else {
         $departmentId = auth()->user()->department_id;
     }
     $archives = Archive::with(['papers', 'department.langs' => function ($query) {
         $query->lang();
     }]);
     if ($departmentId) {
         $archives->where('department_id', $departmentId);
     }
     $archives = $archives->get();
     return view('admin.archive.index', ['archives' => $archives, 'title' => trans('static.archive'), 'url' => action('Admin\\ArchiveController@create')]);
 }