コード例 #1
0
 public function create($data)
 {
     //error_reporting(E_ALL);
     //ini_set('display_errors', 1);
     //var_dump($data['laguageid']);exit;
     $projectid = $this->getRequest()->getQuery('projectid');
     $projectid = $this->getRequest()->getQuery('projectid');
     $iterm = new Itermnotm();
     if ($data['file']) {
         $file = $this->find('\\User\\Entity\\File', $data['file']['id']);
     }
     $project = $this->find('User\\Entity\\Project', $projectid);
     $taskList = $this->getEntityManager()->getRepository('User\\Entity\\Task')->findBy(array('project' => $project));
     $taskOrderArr = array();
     foreach ($taskList as $task) {
         $order = explode('-', $task->getTaskNumber());
         $order = $order[1];
         $taskOrderArr[] = (int) $order;
     }
     $max = max($taskOrderArr);
     $max++;
     $task_number = $project->getProjectNo() . '-' . $max;
     $iterm->setProject($project);
     $language = $this->find('User\\Entity\\Language', $data['languageid']);
     if ($data['task_id']) {
         $task = $this->find('User\\Entity\\Task', $data['task_id']);
         $iterm->setData(['name' => $data['name'], 'file' => $file ? $file : null, 'rate_freelancer' => $data['rate'], 'quantity' => $data['quantity'], 'total_freelancer' => $data['total'], 'language' => $language, 'task' => $task, 'of_freelancer' => $data['of_freelancer'] ? $data['of_freelancer'] : 0]);
     } else {
         $entityManager = $this->getEntityManager();
         $repository = $entityManager->getRepository('User\\Entity\\Task');
         $task = $repository->findBy(array('project' => $project, 'language' => $language, 'type' => 1));
         //var_dump($task);exit;
         if ($task) {
             if ($data['rate_client']) {
                 $iterm->setData(['name' => $data['name'], 'file' => $file ? $file : null, 'rate' => $data['rate_client'], 'quantity' => $data['quantity'], 'total' => $data['total'], 'language' => $language, 'task' => $task[0], 'of_freelancer' => $data['of_freelancer'] ? $data['of_freelancer'] : 0]);
             } else {
                 $iterm->setData(['name' => $data['name'], 'file' => $file ? $file : null, 'rate_freelancer' => $data['rate'], 'quantity' => $data['quantity'], 'total_freelancer' => $data['total'], 'language' => $language, 'task' => $task[0], 'of_freelancer' => $data['of_freelancer'] ? $data['of_freelancer'] : 0]);
             }
         } else {
             if ($data['rate_client']) {
                 $iterm->setData(['name' => $data['name'], 'file' => $file ? $file : null, 'rate' => $data['rate_client'], 'quantity' => $data['quantity'], 'total' => $data['total'], 'language' => $language, 'of_freelancer' => $data['of_freelancer'] ? $data['of_freelancer'] : 0]);
             } else {
                 $iterm->setData(['name' => $data['name'], 'file' => $file ? $file : null, 'rate_freelancer' => $data['rate'], 'quantity' => $data['quantity'], 'total_freelancer' => $data['total'], 'language' => $language, 'of_freelancer' => $data['of_freelancer'] ? $data['of_freelancer'] : 0]);
             }
         }
     }
     $iterm->save($this->getEntityManager());
     //add task if have not
     $entityManager = $this->getEntityManager();
     $repository = $entityManager->getRepository('User\\Entity\\Task');
     $task = $repository->findBy(array('project' => $project, 'language' => $language, 'type' => 1));
     if (!$task) {
         $task = new Task();
         $task->setData(['project' => $project, 'language' => $language, 'type' => 1, 'status' => 3, 'task_number' => $task_number]);
         $task->save($this->getEntityManager());
     }
     return new JsonModel(['iterm' => $iterm->getData()]);
 }