public function getUserFilesById($id, \App\models\User $user) { $this->setWhere(array('id' => $id)); $data = $this->select(); if (empty($data)) { throw new \Exception('Файл не найден!'); } if ($user->roles_id != 1) { $tasksModel = new Tasks(); if ($data[0]['tasks_id'] > 0) { $tasksModel->getOneMyTask($user, $data[0]['tasks_id']); } elseif ($data[0]['projects_id'] > 0) { $projectsModel = new Projects(); $project = $projectsModel->getProjectsDataById($data[0]['projects_id']); if ($project['initiator_id'] != $user->id) { throw new \Exception('Доступ запрещен!'); } } else { throw new \Exception('Доступ запрещен!'); } } return $data[0]; }
public function saveAction() { if (!$this->isXmlHttpRequest()) { throw new \Exception('Неверный тип запроса!'); } $projectsModel = new Projects(); $data = $this->request->getPost(); if (!isset($data['id']) || !isset($data['action']) || !isset($data['name']) || !isset($data['description']) || !isset($data['date_deadline'])) { throw new \Exception('Неверный тип запроса!'); } $data['id'] = (int) $data['id']; $data['name'] = trim($data['name']); $data['description'] = trim($data['description']); $data['date_deadline'] = trim($data['date_deadline']); if ($data['name'] == '' || $data['date_deadline'] == '') { throw new \Exception('Вы заполнили не все необходимые поля!'); } unset($data['action']); $data['id'] = $projectsModel->save($data); $project = $projectsModel->getProjectsDataById($data['id']); $this->view->project = $project; $user = $this->session->getCurrentUser(); $this->view->user = $user; }