/** * Go over the required document types. */ public function checkDocumentTypes() { /* * Documents */ $documentsTypesNotFound = []; foreach ($this->versionType->getDocumentType() as $requiredDocumentType) { $documentTypeFound = false; foreach ($this->getProjectService()->getProject()->getDocument() as $document) { if ($document->getType()->getId() === $requiredDocumentType->getId()) { $documentTypeFound = true; } } if (!$documentTypeFound) { $documentsTypesNotFound[] = $requiredDocumentType->getType(); } } switch (true) { case sizeof($documentsTypesNotFound) === 1: $this->errors[self::CHECKLIST_DOCUMENTS] = sprintf('The required document of type ‘%s’ is missing in your %s', implode(', ', $documentsTypesNotFound), $this->getProjectLink('management', 'proposal documents section')); break; case sizeof($documentsTypesNotFound) > 1: $this->errors[self::CHECKLIST_DOCUMENTS] = sprintf('The required documents of types ‘%s’ is missing in your %s', implode(', ', $documentsTypesNotFound), $this->getProjectLink('management', 'proposal documents section')); break; } }
/** * @param ProjectService $projectService * @param Type $type */ public function __construct(ProjectService $projectService, Type $type) { parent::__construct(); $this->setAttribute('method', 'post'); $this->setAttribute('class', 'form-horizontal'); $this->type = $type; $this->projectService = $projectService; /* * Create an array of required documents */ $versionDocuments = []; if (sizeof($type->getDocumentType()) > 0 && sizeof($projectService->getProject()->getDocument()) > 0) { foreach ($type->getDocumentType() as $requiredDocumentType) { foreach ($projectService->getProject()->getDocument() as $document) { if ($document->getType()->getId() === $requiredDocumentType->getId()) { $versionDocuments[$document->getId()] = sprintf(_("Document: %s (%s)"), $document->getDocument(), $document->getType()); } } } } $this->add(['type' => 'Zend\\Form\\Element\\MultiCheckbox', 'name' => 'versionDocuments', 'options' => ['label' => _("txt-version-documents"), 'help-block' => _("txt-select-version-documents"), 'value_options' => $versionDocuments]]); $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'create', 'attributes' => ['class' => "btn btn-primary", 'value' => sprintf(_("Submit %s"), $type)]]); }