/** * Delete project */ public function deleteProject($projectId, $userId) { //Get the task Ids of the project $tasks = \Task::where('project_id', $projectId)->lists('id'); if ($tasks == null) { //No Tasks. Delete data and users from the database $projectUsers = ProjectUsers::where('project_id', $projectId)->delete(); $project = Project::find($projectId); $project->deleted_by = $userId; $project->save(); $project->delete(); return true; } else { //Delete all users and data for all tasks of the project. Also delete all the users and data for the project $projectUsers = ProjectUsers::where('project_id', $projectId)->delete(); $taskUsers = TaskUser::whereIn('task_id', $tasks)->delete(); //$tasks = Task::where('project_id',$projectId)->delete(); foreach ($tasks as $taskId) { $task = \Task::find($taskId); $task->deleted_by = $userId; $task->save(); $task->delete(); } $project = Project::find($projectId); $project->deleted_by = $userId; $project->save(); $project->delete(); return true; } }
/** * Get all the userslist collaborated to the project */ public function getProjectUsersList($id) { $userList = ProjectUsers::where('project_id', $id)->lists('user_id'); $users = User::whereIn('id', $userList)->get(array('first_name', 'last_name', 'email', 'id'))->toJson(); return $users; }
public function checkPermission($taskId, $userId) { try { $createdUserId = \Task::where('id', '=', $taskId)->pluck('updated_by'); if ($createdUserId == $userId) { return 'success'; } $userCollab = \Taskcollabs::where('task_id', '=', $taskId)->where('user_id', '=', $userId)->get(); if (sizeof($userCollab) != 0) { return 'success'; } elseif (sizeof($userCollab) == 0) { $projectId = \Task::where('id', '=', $taskId)->pluck('project_id'); if ($projectId == null) { return 'error'; } else { $tempuser = \Sentry::getUserProvider()->findById($userId); $admin = \Sentry::getGroupProvider()->findByName('admin'); $manager = \Sentry::getGroupProvider()->findByName('manager'); $leader = \Sentry::getGroupProvider()->findByName('leader'); if ($tempuser->inGroup($admin) or $tempuser->inGroup($manager) or $tempuser->inGroup($leader)) { $projectCollabs = \Projectcollabs::where('project_id', '=', $projectId)->where('user_id', '=', $userId)->get(); if (sizeof($projectCollabs) != 0) { return 'success'; } else { return 'error'; } } else { return 'error'; } } } } catch (Exception $e) { \Log::error('Something Went Wrong - Task Repository - checkPermission():' . $e->getMessage()); return 'error'; } }
public static function userTimeForProject($projectId) { try { $users; $userIdList = \Projectcollabs::where('project_id', $projectId)->lists('user_id'); $taskIdList = \Task::where('project_id', $projectId)->lists('id'); foreach ($userIdList as $userId) { $tempUserData; $timeList = \Timesheet::whereIn('task_id', $taskIdList)->where('user_id', $userId)->lists('total_time_spent'); $totalTime = 0; foreach ($timeList as $time) { $totalTime = $totalTime + $time; } $user = \User::find($userId); $tempUserData['userName'] = $user->first_name . $user->last_name; $tempUserData['userId'] = $userId; $tempUserData['totalTime'] = \DateAndTime::convertTime($totalTime); $users[] = $tempUserData; } return $users; } catch (\Exception $e) { \Log::error('Something Went Wrong in Report Repository - userTimeForProject():' . $e->getMessage()); throw new SomeThingWentWrongException(); } }
/** * View for Task Editing * @param TaskId * @return View */ public function getEditTask($taskId) { try { $task = Task::findOrFail($taskId); } catch (ModelNotFoundException $e) { throw new \TaskNotFoundException(); } //Get the user id of the currently logged in user $userId = Sentry::getUser()->id; //Check permission $result = $this->tasks->checkPermission($taskId, $userId); if ($result == 'success') { //Authorized, Get the tasks $data = $this->tasks->viewTask($taskId); //Get the Subtasks $subTasks = $this->tasks->subTasks($taskId); //List of projects of the user $projectslist = ProjectUsers::where('user_id', $userId)->lists('project_id'); if (sizeof($projectslist) != 0) { $projects = Project::whereIn('id', $projectslist)->orderBy('project_name')->get(array('id', 'project_name'))->toArray(); } else { $projects = null; } //Exisiting Users $emaillist = null; foreach ($data[0]['users'] as $user) { if ($emaillist == null) { $emaillist = $user['email']; } else { $emaillist = $emaillist . ',' . $user['email']; } } //Return View return \View::make('dashboard.tasks.edit')->with('task', $data[0])->with('projects', $projects)->with('emailList', $emaillist)->with('subTasks', $subTasks); } else { //Not Authorized throw new \NotAuthorizedForTaskException(); } }