/** * 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 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(); } }
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'; } }
/** * 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(); } }
public function restoreSingleEntity() { try { //Get the entity type and Id $entityType = \Input::get('restoreentitytype'); $entityId = \Input::get('restoreentityid'); if ($entityType == 'tasks') { //Find the task $restoreTask = \Task::withTrashed()->find($entityId); //Get the project Id associated with task $projectId = $restoreTask->project_id; if ($projectId != null) { $project = \Project::withTrashed()->find($projectId); //Check if project is deleted or not if (!$project->trashed()) { //Project is not deleted, restore task $restoreTask->restore(); \Taskcollabs::withTrashed()->where('task_id', $entityId)->restore(); } } else { //No project is associtated, restore task $restoreTask->restore(); \Taskcollabs::withTrashed()->where('task_id', $entityId)->restore(); } $tasks = \Task::onlyTrashed()->get()->toArray(); $data; if (sizeof($tasks) != 0) { foreach ($tasks as $task) { $tempData; $tempData['id'] = $task['id']; $tempData['name'] = $task['name']; $tempData['created_at'] = $task['created_at']; $tempData['deleted_at'] = $task['deleted_at']; $tempData['updated_at'] = $task['updated_at']; $data[] = $tempData; } //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Task Restored'); return \View::make('dashboard.admin.data')->with('data', $data)->with('type', 'Tasks'); } else { //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Task Restored'); return \View::make('dashboard.admin.data')->with('data', null)->with('type', 'Tasks'); } } elseif ($entityType == 'projects') { //List all Task Ids of the project $taskIds = \Task::withTrashed()->where('project_id', $entityId)->lists('id'); if (sizeof($taskIds) != 0) { foreach ($taskIds as $taskId) { $task = \Task::withTrashed()->find($taskId); //Check if task if trashed or not if ($task->trashed()) { //Restore Task $task->restore(); \Taskcollabs::withTrashed()->where('task_id', $taskId)->restore(); } } } //Find Project and restore $project = \Project::withTrashed()->find($entityId); $project->restore(); $projectCollabs = \Projectcollabs::withTrashed()->where('project_id', $entityId)->restore(); $projects = \Project::onlyTrashed()->get()->toArray(); $data; if (sizeof($projects) != 0) { foreach ($projects as $project) { $tempData; $tempData['id'] = $project['id']; $tempData['name'] = $project['project_name']; $tempData['created_at'] = $project['created_at']; $tempData['deleted_at'] = $project['deleted_at']; $tempData['updated_at'] = $project['updated_at']; $data[] = $tempData; } //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Project Restored'); return \View::make('dashboard.admin.data')->with('data', $data)->with('type', 'Projects'); } else { //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Project Restored'); return \View::make('dashboard.admin.data')->with('data', null)->with('type', 'Projects'); } } elseif ($entityType == 'events') { //Find Event and restore it $restoreEvent = \Events::withTrashed()->find($entityId); $restoreEvent->restore(); $restoreEventCollabs = \EventUser::withTrashed()->where('events_id', $entityId)->restore(); $events = \Events::onlyTrashed()->get()->toArray(); $data; if (sizeof($events) != 0) { foreach ($events as $event) { $tempData; $tempData['id'] = $event['id']; $tempData['name'] = $event['title']; $tempData['date'] = $event['date']; $tempData['created_at'] = $event['created_at']; $tempData['deleted_at'] = $event['deleted_at']; $tempData['updated_at'] = $event['updated_at']; $data[] = $tempData; } //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Event Restored'); return \View::make('dashboard.admin.data')->with('data', $data)->with('type', 'Events'); } else { //For Notifications \Session::put('status', 'success'); \Session::put('message', 'Event Restored'); return \View::make('dashboard.admin.data')->with('data', null)->with('type', 'Events'); } } } catch (\Exception $e) { \Log::error('Something Went Wrong in Admin Data Controller - restoreSingleEntity():' . $e->getMessage()); throw new \SomethingWentWrongException(); } }