コード例 #1
0
 /**
  * @Route("/issue/edit/{id}/{project_id}", name="_editIssues")
  * @Template("TrackersBundle:Issues:edit.html.twig")
  */
 public function editAction($id, $project_id)
 {
     $issue = new Project_issues();
     $repositorys = $this->getDoctrine()->getRepository('TrackersBundle:Project_issues');
     if ($this->getRequest()->getMethod() == 'POST') {
         $requestData = $this->getRequest()->request;
         $form = $requestData->get('form');
         $assignedTo = $requestData->get('assigned_to');
         $date = $requestData->get('date');
         $time = $time = '0:0:0';
         // $requestData->get('time');
         $arr_date = explode('-', $date);
         $arr_time = explode(':', $time);
         $date_time = new \DateTime("now");
         $date_time->setDate($arr_date[0], $arr_date[1], $arr_date[2]);
         $date_time->setTime($arr_time[0], $arr_time[1], $arr_time[2]);
         $issue = $repositorys->find($id);
         $issue->setTitle($form['title']);
         $issue->setDescription($form['description']);
         $issue->setEndTime($date_time);
         $issue->setStatus($form['status']);
         $issue->setModified(new \DateTime("now"));
         $issue->setProjectId($project_id);
         $issue->setCreatedBy($this->getUser()->getId());
         $em = $this->getDoctrine()->getManager();
         $em->persist($issue);
         $em->flush();
         $repository_attachments = $this->getDoctrine()->getRepository('TrackersBundle:Project_issue_assignments');
         $attachments = $repository_attachments->findBy(array('issueId' => $issue->getId()));
         // delete user attachments
         if (!empty($attachments)) {
             foreach ($attachments as $attachment) {
                 $repository_attachments = $this->getDoctrine()->getRepository('TrackersBundle:Project_issue_assignments');
                 $em = $this->getDoctrine()->getManager();
                 $user_attachments = $repository_attachments->find($attachment->getId());
                 $em->remove($user_attachments);
                 $em->flush();
             }
         }
         $users_activity = new Users_activity();
         $users_activity->setUserId($this->getUser()->getId());
         $users_activity->setParentId($project_id);
         $users_activity->setItemId($issue->getId());
         $users_activity->setTypeId(5);
         $users_activity->setCreatedAt(new \DateTime("now"));
         $em->persist($users_activity);
         $em->flush();
         if (!empty($assignedTo)) {
             foreach ($assignedTo as $assigned) {
                 $project_issue_assignments = new Project_issue_assignments();
                 $project_issue_assignments->setUserId($assigned);
                 $project_issue_assignments->setIssueId($issue->getId());
                 $em->persist($project_issue_assignments);
                 $em->flush();
                 $repository = $this->getDoctrine()->getRepository('TrackersBundle:UserDetail');
                 $users = $repository->findBy(array('user_id' => $this->getUser()->getId()));
                 $user = $users[0];
                 $notifications = new Notifications();
                 $notifications->setUserId($assigned);
                 $notifications->setIssueId($issue->getId());
                 $notifications->setProjectId($project_id);
                 $notifications->setCreated(new \DateTime("now"));
                 $notifications->setIsRead(false);
                 $notifications->setText('You have reassign issue with title ' . $form['title'] . ' from ' . $user->getFirstname() . ' ' . $user->getLastname());
                 $em->persist($notifications);
                 $em->flush();
             }
         }
         $this->get('session')->getFlashBag()->add('notice', 'Issue is successfully edited!');
     }
     $em = $this->getDoctrine()->getEntityManager();
     $query = $em->createQuery("SELECT n.firstname , n.lastname ,n.user_id FROM TrackersBundle:UserDetail n, TrackersBundle:User_projects u WHERE  u.userId = n.user_id AND u.projectId = :project_id")->setParameter('project_id', $project_id);
     $entities = $query->getResult();
     $arr = array();
     $issues_id = $repositorys->find($id);
     // ---- load array mutil select
     $repository = $this->getDoctrine()->getRepository('TrackersBundle:Project_issue_assignments');
     $assignments = $repository->findBy(array('issueId' => $id));
     foreach ($entities as $post) {
         $is_select = false;
         foreach ($assignments as $assign) {
             if ($post['user_id'] == $assign->getUserId()) {
                 $is_select = true;
                 break;
             }
         }
         $arr[] = array('id' => $post['user_id'], 'fullName' => $post['firstname'] . " " . $post['lastname'], 'selected' => $is_select);
     }
     $assignedToOld = $issues_id->getassignedTo();
     // set form
     $issue->setTitle($issues_id->getTitle());
     $issue->setDescription($issues_id->getDescription());
     $issue->setStatus($issues_id->getStatus());
     $form = $this->createFormBuilder($issue)->add('title', 'text', array('label' => 'Tile', 'required' => true))->add('description', 'textarea', array('required' => false, 'label' => 'Description', 'attr' => array('class' => 'editor', 'id' => 'editor')))->add('status', 'choice', array('choices' => array('OPEN' => 'OPEN', 'HOLD' => 'HOLD', 'INPROGRESS' => 'INPROGRESS', 'CLOSED' => 'CLOSED', 'FINISHED' => 'FINISHED'), 'preferred_choices' => array($issues_id->getStatus()), 'label' => 'Status'))->getForm();
     return array('form' => $form->createView(), 'project_id' => $project_id, 'assignedTo' => $assignedToOld, 'assignedtos' => $arr, 'endtime' => $issues_id->getEndTime(), 'date' => $issues_id->getEndTime()->format('Y-m-d'), 'time' => $issues_id->getEndTime()->format('H:i:s'));
 }
コード例 #2
0
ファイル: TaskController.php プロジェクト: niceit/sf-tracker
 /**
  * @Route("/ajaxAddTask", name="_ajaxAddTask")
  */
 public function ajaxAddTaskAction()
 {
     $arr = array();
     if ($this->getRequest()->getMethod() == 'POST') {
         $requestData = $this->getRequest()->request;
         $title = $requestData->get('title');
         $id_category = $requestData->get('id_category');
         $project_id = $requestData->get('project_id');
         $user_asign = $requestData->get('user_asign');
         $file_id = $requestData->get('file');
         $due_date = $requestData->get('due_date');
         $Project_task = new Project_task();
         $Project_task->setTitle($title);
         $Project_task->setDescription('');
         $Project_task->setCategoryTaskId($id_category);
         $Project_task->setProjectId($project_id);
         $Project_task->setStatus('OPEN');
         $Project_task->setCreatedBy($this->getUser()->getId());
         $Project_task->setCreated(new \DateTime('now'));
         //$Project_task->setModified(new \DateTime('now'));
         if ($due_date == '') {
             $due_start = '';
         } else {
             // date due time
             $arr_due_date = explode('-', $due_date);
             $due_start = new \DateTime();
             $due_start->setDate($arr_due_date[0], $arr_due_date[1], $arr_due_date[2]);
             $Project_task->setDuetime($due_start);
         }
         $em = $this->getDoctrine()->getManager();
         $em->persist($Project_task);
         $em->flush();
         $repository_user = $this->getDoctrine()->getRepository('TrackersBundle:UserDetail');
         $users = $repository_user->findBy(array('user_id' => $this->getUser()));
         $user = $users[0];
         $text = $user->getFirstname() . ' ' . $user->getLastname() . " is task with content " . $title;
         if (!empty($user_asign)) {
             foreach ($user_asign as $user_id) {
                 $userTask = new UserTask();
                 $userTask->setUserId($user_id);
                 $userTask->setTaskId($Project_task->getId());
                 $userTask->setCreated(new \DateTime('now'));
                 $em = $this->getDoctrine()->getManager();
                 $em->persist($userTask);
                 $em->flush();
                 // notifiaction user attachment
                 $notifications = new Notifications();
                 $notifications->setUserId($user_id);
                 $notifications->setTaskId($Project_task->getId());
                 $notifications->setProjectId($project_id);
                 $notifications->setCreated(new \DateTime("now"));
                 $notifications->setIsRead(false);
                 $notifications->setText($text);
                 $em->persist($notifications);
                 $em->flush();
             }
         }
         if (!empty($file_id)) {
             foreach ($file_id as $file) {
                 $repository = $this->getDoctrine()->getRepository('TrackersBundle:Project_Task_Attachments');
                 $files = $repository->find($file);
                 $files->setTaskId($Project_task->getId());
                 $em->persist($files);
                 $em->flush();
             }
         }
         $full_name = '';
         $em = $this->getDoctrine()->getEntityManager();
         $query = $em->createQuery("SELECT n.firstname , n.lastname , n.user_id   FROM TrackersBundle:UserDetail n  WHERE  n.user_id IN (:string)  ")->setParameter('string', $user_asign);
         $i = 1;
         foreach ($query->getResult() as $row) {
             $full_name .= $row['firstname'] . " " . $row['lastname'] . " ";
             if (count($query->getResult()) != $i) {
                 $full_name .= " - ";
             }
             $i++;
         }
         $arr = array('id' => $Project_task->getId(), 'title' => $Project_task->getTitle(), 'duetime' => $Project_task->getDuetime(), 'full_name' => $full_name, 'url' => $this->generateUrl('_showTask', array('task_id' => $Project_task->getId())));
     } else {
         die('Error...');
     }
     echo json_encode($arr);
     die;
 }
コード例 #3
0
 /**
  * @Route("/savecomment", name="_savecomment")
  */
 public function saveCommentAction()
 {
     $requestData = $this->getRequest()->request;
     $comment = $requestData->get('comment');
     $issue_id = $requestData->get('issue_id');
     $project_id = $requestData->get('project_id');
     $file_id = $requestData->get('file_id');
     $projects_issues_comments = new Projects_issues_comments();
     $projects_issues_comments->setCreatedBy($this->getUser()->getId());
     $projects_issues_comments->setProjectId($project_id);
     $projects_issues_comments->setIssueId($issue_id);
     $projects_issues_comments->setComment($comment);
     $projects_issues_comments->setCreatedAt(new \DateTime("now"));
     $em = $this->getDoctrine()->getManager();
     $em->persist($projects_issues_comments);
     $em->flush();
     $users_activity = new Users_activity();
     $users_activity->setUserId($this->getUser()->getId());
     $users_activity->setParentId($project_id);
     $users_activity->setItemId($issue_id);
     $users_activity->setTypeId(2);
     $users_activity->setActionId($projects_issues_comments->getId());
     $users_activity->setCreatedAt(new \DateTime("now"));
     $em->persist($users_activity);
     $em->flush();
     if (!empty($file_id)) {
         foreach ($file_id as $file) {
             $repository = $this->getDoctrine()->getRepository('TrackersBundle:Projects_issues_attachments');
             $files = $repository->find($file);
             $files->setCommentId($projects_issues_comments->getId());
             $em->persist($files);
             $em->flush();
         }
     }
     $repository = $this->getDoctrine()->getRepository('TrackersBundle:UserDetail');
     $users = $repository->findBy(array('user_id' => $this->getUser()->getId()));
     $user = $users[0];
     $repository = $this->getDoctrine()->getRepository('TrackersBundle:Projects');
     $project = $repository->find($project_id);
     $repository = $this->getDoctrine()->getRepository('TrackersBundle:Project_issues');
     $issue = $repository->find($issue_id);
     // Get user detail
     $repository = $this->getDoctrine()->getRepository('TrackersBundle:UserDetail');
     $users = $repository->findBy(array('user_id' => $this->getUser()));
     $user = $users[0];
     $repository_attachments = $this->getDoctrine()->getRepository('TrackersBundle:Project_issue_assignments');
     $attachments = $repository_attachments->findBy(array('issueId' => $issue->getId()));
     // notifiaction user attachment
     $notifications = new Notifications();
     $text = $user->getFirstname() . ' ' . $user->getLastname() . " is comment issue with content " . $comment;
     // send user create project----
     if ($this->getUser()->getId() != $project->getOwnerId()) {
         $notifications = new Notifications();
         $notifications->setUserId($project->getOwnerId());
         $notifications->setIssueId($issue->getId());
         $notifications->setProjectId($project_id);
         $notifications->setCreated(new \DateTime("now"));
         $notifications->setIsRead(false);
         $notifications->setText($text);
         $em->persist($notifications);
         $em->flush();
     }
     // send user do issues----
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             if ($this->getUser()->getId() != $attachment->getUserId()) {
                 $notifications = new Notifications();
                 $notifications->setUserId($attachment->getUserId());
                 $notifications->setIssueId($issue->getId());
                 $notifications->setProjectId($project_id);
                 $notifications->setCreated(new \DateTime("now"));
                 $notifications->setIsRead(false);
                 $notifications->setText($text);
                 $em->persist($notifications);
                 $em->flush();
             }
         }
     }
     $repository = $this->getDoctrine()->getRepository('TrackersBundle:UserDetail');
     $users = $repository->findBy(array('user_id' => $this->getUser()->getId()));
     $user = $repository->find($users[0]->getId());
     $arr_comment = array('full_name' => $user->getFirstname() . " " . $user->getLastname(), 'created' => $projects_issues_comments->getCreatedAt(), 'comment' => $projects_issues_comments->getComment());
     echo json_encode($arr_comment);
     die;
 }