/** * Class constructor. */ public function __construct(ProjectService $projectService) { parent::__construct(); $this->setAttribute('method', 'post'); $this->setAttribute('class', 'form-horizontal'); $this->setAttribute('id', 'create-report'); /* * Create an array with possible periods. This will trigger a date but display a period (semester) */ $semesterOptions = []; foreach ($projectService->parseYearRange() as $year) { /* * Use the Report object to parse the data */ $report = new Report(); $report->setDatePeriod(\DateTime::createFromFormat('Y-m-d', $year . '-03-01')); $semesterOptions[$year . '-1'] = $report->parseName(); $report->setDatePeriod(\DateTime::createFromFormat('Y-m-d', $year . '-09-01')); $semesterOptions[$year . '-2'] = $report->parseName(); } $this->add(['type' => 'Zend\\Form\\Element\\Select', 'name' => 'period', 'options' => ['label' => _("txt-report-period"), 'help-block' => _("txt-report-period-explanation"), 'value_options' => $semesterOptions], 'attributes' => ['class' => "form-control", 'id' => "period"]]); $this->add(['type' => 'Zend\\Form\\Element\\Text', 'name' => 'item', 'options' => ['label' => _("txt-document-name"), 'help-block' => _("txt-document-name-explanation")], 'attributes' => ['placeholder' => _("txt-please-give-a-document-name")]]); $this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'options' => ["label" => "txt-file", "help-block" => _("txt-file-requirements")]]); $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-create")]]); $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'cancel', 'attributes' => ['class' => "btn btn-warning", 'value' => _("txt-cancel")]]); }
/** * @return Report */ public function getReport() { if (is_null($this->report)) { $this->report = new Report(); $this->report->setDatePeriod(new \DateTime()); if (!is_null($this->project)) { $this->report->setProject($this->project); } } return $this->report; }
/** * {@inheritDoc} */ public function setUp() { $this->serviceManager = Bootstrap::getServiceManager(); $this->report = new Report(); $this->report->setId(1); $this->report->setDatePeriod(new \DateTime()); $project = new Project(); $project->setId(1); $project->setNumber('1234'); $project->setProject('This is the number'); $this->report->setProject($project); $authorizeServiceMock = $this->getMockBuilder('BjyAuthorize\\View\\Helper\\IsAllowed')->disableOriginalConstructor()->getMock(); $authorizeServiceMock->expects($this->any())->method('__invoke')->will($this->returnValue(true)); $viewHelperManager = $this->serviceManager->get('viewhelpermanager'); $viewHelperManager->setService('isAllowed', $authorizeServiceMock); $urlViewHelperMock = $this->getMockBuilder(Url::class)->disableOriginalConstructor()->getMock(); $urlViewHelperMock->expects($this->any())->method('__invoke')->will($this->returnValue(true)); $viewHelperManager->setService('url', $urlViewHelperMock); $this->reportLink = $viewHelperManager->get('reportLink'); }
/** * @return bool */ public function isEmpty() { return is_null($this->report) || is_null($this->report->getId()); }
/** * Create a new project. * * @return ViewModel */ public function createAction() { $projectService = $this->getProjectService()->setProjectId($this->getEvent()->getRouteMatch()->getParam('project')); $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); $today = new \DateTime(); $currentPeriod = $this->getReportService()->getPeriod($today); $data['period'] = sprintf("%s-%s", $today->format("Y"), $currentPeriod->semester); $form = new CreateReport($projectService); $form->setInputFilter(new FilterCreateReport()); $form->setData($data); if ($this->getRequest()->isPost() && $form->isValid()) { $formData = $form->getData(); /* * Create the period */ $period = $this->getReportService()->getDateFromPeriod($formData['period']); /* * Check first if we have already a report for this project and period */ $report = $this->getReportService()->findReportByProjectAndPeriod($projectService->getProject(), $period); /* * Create a new report if no report is found */ if (is_null($report)) { $report = new Report(); $report->setDatePeriod($period); $report->setContact($this->zfcUserAuthentication()->getIdentity()); $report->setProject($projectService->getProject()); } /* * Create the item * when no name is given, take the name of the uploaded file */ $item = new Item(); if (empty($formData['item'])) { $item->setItem($formData['file']['name']); } else { $item->setItem($formData['item']); } $item->setReport($report); $item->setContact($this->zfcUserAuthentication()->getIdentity()); $fileSizeValidator = new FilesSize(PHP_INT_MAX); $fileSizeValidator->isValid($formData['file']); $item->setSize($fileSizeValidator->size); $item->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($formData['file']['type'])); /* * Save the object */ $reportItemObject = new ItemObject(); $reportItemObject->setObject(file_get_contents($formData['file']['tmp_name'])); $reportItemObject->setItem($item); $this->getReportService()->newEntity($reportItemObject); /* * Send the email tot he consortium */ $email = $this->getEmailService()->create(); $this->getEmailService()->setTemplate("/project/report-item/submit:mail"); $email->addSelection($this->getContactService()->findEntityById('selection', 219), $this->getContactService()); $email->setDocumentName($item); $email->setProject($report->getProject()); $email->setSubmitter($report->getContact()); $email->setContentType($item->getContentType()->getDescription()); $this->getEmailService()->send($email); $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-report-%s-for-project-%s-has-successfully-been-created"), $report->parseName(), $projectService->parseFullName())); return $this->redirect()->toRoute('community/project/report/report', ['id' => $reportItemObject->getItem()->getReport()->getId()]); } return new ViewModel(['projectService' => $projectService, 'form' => $form]); }