/** * Update the project */ public function updateProject($data, $userId) { //Find the project and update the fileds $project = Project::find($data['projectid']); $project->project_name = $data['project_name']; $project->description = $data['description']; $project->status = $data['status']; $tempStartDate = \DateTime::createFromFormat('j F, Y', $data['startdate']); $tempEndDate = \DateTime::createFromFormat('j F, Y', $data['enddate']); $project->start_date = $tempStartDate->format('Y-m-d'); $project->end_date = $tempEndDate->format('Y-m-d'); $project->project_client = $data['project_client']; $project->note = $data['note']; //If the project is marked completed fill the respective fields of database if ($data['status'] == 'completed') { $project->completed_on = date_create(); $project->mark_completed_by = $userId; $project->updated_by = $userId; $project->save(); } else { $project->updated_by = $userId; $project->save(); } //Remove all the Collaborators of the project $prjtUsrs = ProjectUsers::where('project_id', $data['projectid'])->forceDelete(); //New list of emails of collaborators $email = $data['tagsinput']; $emails = preg_split("/[\\s,]+/", $email); //Get the user Ids of the new collaborators $userIdList = \User::whereIn('email', $emails)->lists('id'); //Add collaborators foreach ($userIdList as $usrId) { $projectcollabs = new \Projectcollabs(); $projectcollabs->user_id = $usrId; $projectcollabs->project_id = $data['projectid']; $projectcollabs->save(); } //Get the project name and Id for the next view $projectName = $data['project_name']; $projectId = $data['projectid']; $files; $filesId = FileReference::where('parent_id', $projectId)->where('parent_type', 'project')->lists('attachment_id'); if ($filesId == null) { $files = null; } else { $files = Files::whereIn('id', $filesId)->get(array('file_name', 'id', 'key', 'size', 'uploaded_date', 'uploaded_by'))->toArray(); } //Wrap up data $returnData['projectName'] = $projectName; $returnData['projectId'] = $projectId; $returnData['files'] = $files; //Shoot back return $returnData; }
public function getFiles($taskId) { try { $files; $filesId = \Fileref::where('parent_id', $taskId)->where('parent_type', 'task')->lists('attachment_id'); if ($filesId == null) { $files = null; } else { $files = \Files::whereIn('id', $filesId)->get(array('file_name', 'id', 'key', 'size', 'uploaded_date', 'uploaded_by'))->toArray(); //$files = $filesJson; } return $files; } catch (Exception $e) { \Log::error('Someting Went Wrong in Task Reposiroty - getFiles():' . $e->getMessage()); } }
public function generateProjectReport($projectId, $userId) { try { $tasks; //Get Project $project = Project::find($projectId)->toArray(); //Get Task List $total_task_list = Task::where('project_id', $projectId)->lists('id'); if ($total_task_list == null) { //No Tasks, everything zero $project['total_tasks'] = 0; $project['uncompl_tasks'] = 0; $project['percentage'] = 0; $project['compl_tasks'] = 0; $project['active_tasks'] = 0; $project['delay_tasks'] = 0; } else { //List out the Id's of active / delayed tasks $total_uncompl_task_list = Task::whereNested(function ($query) use($projectId) { $query->where('project_id', $projectId); $query->where('status', 'active'); })->orWhere(function ($query) use($projectId) { $query->where('project_id', $projectId); $query->where('status', 'delayed'); })->lists('id'); //Calculation $percentage = (count($total_task_list) - count($total_uncompl_task_list)) * 100 / count($total_task_list); $project['total_tasks'] = count($total_task_list); $project['uncompl_tasks'] = count($total_uncompl_task_list); $project['percentage'] = $percentage; $project['compl_tasks'] = count($total_task_list) - count($total_uncompl_task_list); $project['delay_tasks'] = Task::whereIn('id', $total_task_list)->where('status', 'delayed')->count(); $project['active_tasks'] = Task::whereIn('id', $total_task_list)->where('status', 'active')->count(); $tasksList = Task::whereIn('id', $total_task_list)->get(array('name', 'status'))->toArray(); $project['taskList'] = $tasksList; //Check if User is admin, manager or leader. $user = \Sentry::getUserProvider()->findById($userId); $adminGroup = \Sentry::getGroupProvider()->findByName('admin'); $managerGroup = \Sentry::getGroupProvider()->findByName('manager'); $leaderGroup = \Sentry::getGroupProvider()->findByName('leader'); if ($user->inGroup($adminGroup) or $user->inGroup($managerGroup) or $user->inGroup($leaderGroup)) { //If the user is admin, manager or leader show all the tasks of the project $taskInterface = \App::make('TaskInterface'); foreach ($total_task_list as $taskId) { $tempTaskArray = array(); $tempTaskArray['task'] = $taskInterface->viewTask($taskId); $tempTaskArray['userTime'] = static::userTimeForTask($taskId); $tempTaskArray['subtasks'] = $taskInterface->subTasks($taskId); $tasks[] = $tempTaskArray; } $project['tasks'] = $tasks; $project['users'] = static::userTimeForProject($projectId); } else { //Else show only those tasks in which user is asignee $taskList = TaskUser::where('user_id', $userId)->whereIn('task_id', $total_task_list)->lists('task_id'); if (sizeof($taskList) != 0) { $taskInterface = \App::make('TaskInterface'); foreach ($taskList as $taskId) { $tempTaskArray = array(); $tempTaskArray['task'] = $taskInterface->viewTask($taskId); $tempTaskArray['subtasks'] = $taskInterface->subTasks($taskId); $tasks[] = $tempTaskArray; } $project['tasks'] = $tasks; } else { $project['tasks'] = null; } } } //Get all the files $filesId = FileReference::where('parent_id', $projectId)->where('parent_type', 'project')->lists('attachment_id'); if ($filesId == null) { $files = null; } else { $filesJson = \Files::whereIn('id', $filesId)->get(array('file_name', 'file_sys_ref', 'key', 'size', 'uploaded_date', 'uploaded_by'))->toArray(); $files = $filesJson; } $project['files'] = $files; //Retrun everything in array return $project; } catch (\Exception $e) { \Log::error('Something Went Wrong in Report Repository - generateProjectReport():' . $e->getMessage()); throw new SomeThingWentWrongException(); } }
/** * Delete Entity * @param int, string * @return boolean */ public static function deleteEntity($id, $type) { try { $dir; $entity; if ($type == 'task') { //Find Task $entity = \Task::withTrashed()->find($id); //Get the path of folder for uploads $dir = public_path() . '/uploads/tasks/' . $entity->folder; } elseif ($type == 'project') { //Get Project $entity = \Project::withTrashed()->find($id); //Get the path of folder for uploads $dir = public_path() . '/uploads/projects/' . $entity->folder; } if (is_dir($dir)) { //If Uploads directory exists, get list of files $files = array_diff(scandir($dir), array('.', '..')); //Delete Each file foreach ($files as $file) { unlink($dir . '/' . $file); } //Delete folder $deleteFolder = \File::deleteDirectory($dir); //Get the file attachment Ids $fileIds = \Fileref::where('parent_id', $id)->where('parent_type', $type)->lists('attachment_id'); if (sizeof($fileIds) != 0) { //Delete each file attachment entry from database foreach ($fileIds as $fieldId) { $deletefile = \Files::find($fieldId); $deletefile->forceDelete(); } } //Delete the entity $entity->forceDelete(); } else { //Folder doesn't exists, delete the entity $entity->forceDelete(); } return true; } catch (\Exception $e) { \Log::error('Something Went Wrong in Admin Data Controller - deleteEntity():' . $e->getMessage()); throw new \SomethingWentWrongException(); } }