public function addText() { $this->_methodName = 'addText'; $this->resolveParams(); $this->checkAuth(); $arNeed = ['userTaskId' => 'required|numeric', 'text' => 'required']; $this->checkAttr($arNeed); $task_user = \App\UserTask::where('id', $this->_request_params['userTaskId'])->where('id_user', Auth::user()->id)->first(); if (is_null($task_user)) { throw new \App\Exceptions\ExceptionApiContactnotfound($this->_request_params, $this->_typeName, $this->_methodName); } $infoTask = \App\InfoTask::where('id_taskUser', $task_user->id)->first(); if (is_null($infoTask)) { $infoTask = new \App\InfoTask(); $infoTask->id_taskUser = $task_user->id; } $infoTask->text = $this->_request_params['text']; $infoTask->save(); return $this; }
public function show() { $user_main = \App\Users::find($this->_idUser); if (is_null($user_main)) { return redirect('/users'); } $users = DB::table('UserTask')->join('task', 'UserTask.id_task', '=', 'task.id')->where('UserTask.id_user', $this->_idUser)->select(DB::raw('UserTask.id as id_userTask, status, UserTask.id_user, task.name as name, task.id as id_task, point, UserTask.updated_at'))->get(); $rows = ['done' => '', 'timeout' => '', 'available' => '', 'cancel' => '', 'active' => '']; foreach ($users as $user) { $status = ['avaliable' => '', 'done' => '', 'active' => '', 'cancel' => '', 'timeout' => '']; $status[$user->status] = 'selected'; $filesUser = \App\Files::where('id_taskUser', $user->id_userTask)->get(); $files = ""; if (!is_null($filesUser)) { foreach ($filesUser as $value) { $files .= $value->file . ';'; } } $infoUser = \App\InfoTask::where('id_taskUser', $user->id_userTask)->first(); if (is_null($infoUser)) { $lat = ""; $lng = ""; $text = ""; } else { $lat = $infoUser->lat; $lng = $infoUser->lng; $text = $infoUser->text; } $str = '<tr class="gradeC userRow fade in" data-id="' . $user->id_userTask . '" data-idtask="' . $user->id_task . '" data-files="' . $files . '" data-lat="' . $lat . '" data-lng="' . $lng . '" data-text="' . $text . '"> <td class="userEmail"> ' . $user->name . ' </td> <td class="center"> <div class="form-group"><select class="form-control select" id="select" autocomplete="off"> <option ' . $status['avaliable'] . ' value="avaliable">Available</option> <option ' . $status['done'] . ' value="done">Performed</option> <option ' . $status['active'] . ' value="active">Active</option> <option ' . $status['cancel'] . ' value="cancel">Declined</option> <option ' . $status['timeout'] . ' value="timeout">Overdued</option> </select></div> </td> '; switch ($user->status) { case 'done': $rows['done'] .= $str . ' <td> <button type="button" class="btn btn-success" >Read more</button> </td> </tr>'; break; case 'timeout': $rows['timeout'] .= $str . '</tr>'; break; case 'available': $rows['available'] .= $str . '</tr>'; break; case 'cancel': $rows['cancel'] .= $str . '</tr>'; break; case 'active': $rows['active'] .= $str . ' <td> ' . $user->updated_at . ' </td> </tr>'; break; default: break; } } $count = DB::table('UserTask')->join('task', 'UserTask.id_task', '=', 'task.id')->where('UserTask.id_user', $user_main->id)->where('UserTask.status', 'done')->groupBy('id_user')->select(DB::raw('sum(point) as point'))->get(); if (count($count) > 0) { $user_main->bonusPoint += $count[0]->point; } return View::make('view.userInfo')->withRows($rows)->withUser($user_main); }