/** * 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(); } }
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(); } }
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'; } }