Example #1
0
 public function uploadTaskRequirementFileAction()
 {
     $taskId = $this->getRequest()->getPost('taskId');
     if (!$taskId) {
         return $this->getJsonModel()->setVariables(array('code' => 0, 'messages' => ['Dữ liệu không hợp lệ']));
     }
     $task = new \Work\Model\Task();
     $task->setId($taskId);
     $taskMapper = $this->getServiceLocator()->get('\\Work\\Model\\TaskMapper');
     if (!$taskMapper->get($task)) {
         return $this->getJsonModel()->setVariables(array('code' => 0, 'messages' => ['Dữ liệu không hợp lệ']));
     }
     $form = new \Home\Form\Media\TaskFile($this->getServiceLocator(), ['id' => $task->getId()]);
     $dataPopulate = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getQuery()->toArray(), $this->getRequest()->getFiles()->toArray());
     $dataPopulate['fileUpload']['name'] = Format::removeSigns($dataPopulate['fileUpload']['name']);
     $form->setData($dataPopulate);
     if ($form->isValid()) {
         $formData = $form->getData();
         $file = new \Work\Model\TaskFile();
         $file->setFileName($formData['fileUpload']['name']);
         $file->setFileSize($formData['fileUpload']['size']);
         $file->setTaskId($task->getId());
         $file->setCreatedById($this->user()->getIdentity());
         $file->setCreatedDateTime(DateBase::getCurrentDateTime());
         $fileMapper = $this->getServiceLocator()->get('\\Work\\Model\\TaskFileMapper');
         $fileMapper->save($file);
         return $this->getJsonModel()->setVariables(array('code' => 1, 'messages' => $formData));
     } else {
         return $this->getJsonModel()->setVariables(array('code' => 0, 'messages' => $form->getErrorMessagesList()));
     }
 }