/** * @param $taskName * @param $taskDesc * @param $taskDueDate * @param $taskStatus * @param null $userId * @param null $projectId * @return bool * @throws \Exception */ public function createTask($taskName, $taskDesc, $taskDueDate, $taskStatus, $userId = null, $projectId = null) { $task = new Task(); $task->setTitle($taskName); $task->setDescription($taskDesc); $task->setDueDate(new \DateTime($taskDueDate)); $task->setStatus($taskStatus); if ($projectId) { $project = $this->em->getRepository('AppBundle:Project'); $task->setProject($project->find($project_id)); } if ($userId) { $user = $this->em->getRepository('AppBundle:User'); $task->setUser($user->find($useId)); } try { $this->em->persist($task); $this->em->flush(); return true; } catch (\Exception $e) { throw $e; } }
/** * Send task over RPC to worker * Mark task as in progress nad worker as busy * @param Task $task * @param Worker $worker * @return void * @author Andraz <*****@*****.**> */ public function sendTaskToWorker(Task $task, Worker $worker) { $client = $this->newRpcClient($worker->getHost(), $worker->getport()); $parameters = [$worker->getId(), $task->getId(), $task->getParameters()]; $task->setStatus('in_progress'); $this->storage->saveTask($task); $worker->setStatus('busy'); $this->storage->saveWorker($worker); $success = $client->notify('run', $parameters); if ($success) { } return $success; }
public function executeAddTask() { $project = ProjectPeer::retrieveByUuid($this->getRequestParameter('slug')); // TODO: make sure user is a member of project $this->forward404Unless($project, 'Project not found, or user is not member, unable to add task'); $this->forward404Unless($user = sfGuardUserProfilePeer::retrieveByUuid($this->getRequestParameter('task_user'), 'Unable to retrieve user')); // TODO: add validation for task input $task = new Task(); $task->setProjectId($project->getId()); $task->setOwnerId($this->getUser()->getProfile()->getUserID()); $task->setName($this->getRequestParameter('name', 'Task Name')); $task->setDescription($this->getRequestParameter('description', 'Task Description')); if ($this->getRequestParameter('begin')) { list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('begin'), $this->getUser()->getCulture()); $task->setBegin("{$y}-{$m}-{$d}"); } if ($this->getRequestParameter('finish')) { list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('finish'), $this->getUser()->getCulture()); $task->setFinish("{$y}-{$m}-{$d}"); } $task->setStatus(sfConfig::get('app_task_status_open')); $task->setPriority($this->getRequestParameter('priority')); $task->save(); //if ($user != null) $task->addUser($user->getUserId()); $task->addUser($user->getUserId()); $this->redirect('@show_project_tasks?tab=tasks&project=' . $project->getSlug()); }
if ($description != $task->getDescription()) { // save changes $oldDescription = $task->getDescription(); $task->setDescription($description); $task->save(); // log it $logEvent = new Event(array('event_type_id' => 'edit_task_description', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID(), 'item_1_id' => $task->getID(), 'data_1' => $oldDescription, 'data_2' => $description)); $logEvent->save(); // set flag $modified = true; } // is status modified? if ($status != $task->getStatus()) { // save changes $oldStatus = $task->getStatus(); $task->setStatus($status); $task->save(); // log it $logEvent = new Event(array('event_type_id' => 'edit_task_status', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID(), 'item_1_id' => $task->getID(), 'data_1' => $oldStatus, 'data_2' => $status)); $logEvent->save(); // set flag $modified = true; } // is num needed modified? if ($numNeeded != $task->getNumNeeded()) { // save changes $oldNumNeeded = $task->getNumNeeded(); $task->setNumNeeded($numNeeded); $task->save(); // log it $logEvent = new Event(array('event_type_id' => 'edit_task_num_needed', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID(), 'item_1_id' => $task->getID(), 'data_1' => $oldNumNeeded, 'data_2' => $numNeeded));
/** * Get task by id * @param int $id * @return Task null */ public function getTask($id) { $result = $this->db->query("SELECT * FROM tasks WHERE id = {$id} LIMIT 1"); foreach ($result as $key => $row) { $task = new Task(); $task->setId($row['id']); $task->setName($row['name']); $task->setParameters($row['parameters']); $task->setStatus($row['status']); return $task; } return null; }