Exemplo n.º 1
0
 /**
  *	Tasks Data for Dashboard Page
  */
 public function getTasks()
 {
     try {
         //Get the user id of the currently logged in user
         $userId = Sentry::getUser()->id;
         //Get all the task ids assigned to user
         $taskList = TaskUsers::where('user_id', $userId)->lists('task_id');
         if ($taskList != null) {
             //Total Tasks Assigned
             $totalTasks = count($taskList);
             //Total Number of Completed Tasks
             $completedTasks = Task::whereIn('id', $taskList)->where('status', 'completed')->count();
             //Total Number of pending Tasks
             $pendingTasks = $totalTasks - $completedTasks;
             //Percentage of Completed Tasks
             $percentage = (int) (($totalTasks - $pendingTasks) * 100) / $totalTasks;
             //Wrap up all data
             $tasks = array('totalTasks' => $totalTasks, 'completedTasks' => $completedTasks, 'pendingTasks' => $pendingTasks, 'percentage' => $percentage);
             return $tasks;
         } else {
             //Everything Zero
             $tasks = array('totalTasks' => 0, 'completedTasks' => 0, 'pendingTasks' => 0, 'percentage' => 0);
             return $tasks;
         }
     } catch (UserNotFoundException $e) {
         Log::error('Something Went Wrong - User Not found for getTasks in Dashboard');
         throw new \UserNotFoundException();
     } catch (Exception $e) {
         Log::error('Something Went Wrong - in getTasks in Dashboard');
         throw new \SomethingWentWrongException();
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
     }
 }
Exemplo n.º 3
0
 public function deleteTask($taskId, $userId)
 {
     try {
         $task = \Task::find($taskId);
         $task->deleted_by = $userId;
         $task->save();
         $task->delete();
         $taskcollabs = \Taskcollabs::where('task_id', $taskId)->delete();
         return 'success';
     } catch (\Exception $e) {
         \Log::error('Someting Went Wrong in Task Repository - deleteTask():' . $e->getMessage());
         return 'error';
     }
 }
Exemplo n.º 4
0
 public static function userTimeForTask($taskId)
 {
     try {
         $userTime = array();
         $userIdList = TaskUser::where('task_id', $taskId)->lists('user_id');
         foreach ($userIdList as $userId) {
             $userTimeTemp = array();
             $timeList = Timesheet::where('user_id', $userId)->where('task_id', $taskId)->lists('total_time_spent');
             $totalTime = 0;
             if (sizeof($timeList) != 0) {
                 foreach ($timeList as $time) {
                     $totalTime = $totalTime + $time;
                 }
             }
             $user = \User::find($userId);
             $userTimeTemp['userName'] = $user->first_name . $user->last_name;
             $userTimeTemp['totalTime'] = \DateAndTime::convertTime($totalTime);
             $userTime[] = $userTimeTemp;
         }
         return $userTime;
     } catch (\Exception $e) {
         \Log::error('Something Went Wrong in Report Repository - userTimeForTask():' . $e->getMessage());
         throw new SomeThingWentWrongException();
     }
 }
Exemplo n.º 5
0
 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();
     }
 }