public function __construct($uploadTmpPath, LabServiceInterface $labService, $attachmentSize) { $id = new Input('id'); $id->setRequired(false)->getValidatorChain()->attach(new Validator\Digits()); $name = new Input('name'); $name->setRequired(true)->getFilterChain()->attach(new Filter\StringTrim()); $name->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\StringLength(['min' => 3])); $labTypeId = new Input('labtype_id'); $labTypeId->setRequired(true); $labTypeId->getValidatorChain()->attach(new Validator\NotEmpty()); $isNew = new Input('is_new'); $isNew->setRequired(false)->getFilterChain()->attach(new Filter\ToInt()); $responsibleId = new Input('responsible_id'); $responsibleId->setRequired(false)->getValidatorChain()->attach(new Validator\Digits()); $area = new Input('area'); $area->setRequired(true)->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\Digits()); $lessons = new Input('lessons'); $lessons->setRequired(false); $lessons->getValidatorChain()->attach(new Validator\NotEmpty()); $attachment = new FileInput('attachment'); $attachment->setRequired(false)->getFilterChain()->attach(new Filter\File\RenameUpload(['target' => $uploadTmpPath, 'randomize' => true])); $attachment->getValidatorChain()->attach(new Validator\File\UploadFile())->attach(new Validator\File\MimeType(['application/zip', 'application/x-rar-compressed', 'application/octet-stream', 'application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff', 'image/svg+xml', 'image/svg+xml', 'image/vnd.adobe.photoshop']))->attach(new Validator\File\Size(['max' => $attachmentSize])); $use_ext_program = new Input('use_ext_program'); $use_ext_program->setRequired(false); $use_in_program = new Input('use_in_program'); $use_in_program->setRequired(false); $has_network = new Input('has_network'); $has_network->setRequired(false); $has_network->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\InArray(['haystack' => $labService->getHasNetworkValues()])); $has_server = new Input('has_server'); $has_server->setRequired(false); $has_server->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\InArray(['haystack' => $labService->getHasServerValues()])); $this->inputFilter = new InputFilter(); $this->inputFilter->add($id)->add($name)->add($labTypeId)->add($isNew)->add($responsibleId)->add($area)->add($lessons)->add($attachment)->add($use_in_program)->add($use_ext_program)->add($has_server)->add($has_network); }
public function __invoke(Request $req, Response $res, array $args = []) { $school = $req->getAttribute('school', false); if (!$school) { return $res->withStatus(403, 'No school'); } $labs = $this->labService->getLabsBySchoolId($school->id); return $this->view->render($res, 'schools/labs.twig', ['school' => $school, 'labs' => $labs, 'staff' => array_map(function ($teacher) { return ['value' => $teacher['id'], 'label' => $teacher['fullname']]; }, $this->staffService->getTeachersBySchoolId($school->id)), 'network_options' => array_map(function ($option) { return ['value' => $option, 'label' => $option]; }, $this->labService->getHasNetworkValues()), 'server_options' => array_map(function ($option) { return ['value' => $option, 'label' => $option]; }, $this->labService->getHasServerValues()), 'lab_types' => array_map(function ($type) { return ['value' => $type['id'], 'label' => $type['name']]; }, $this->labService->getLabTypes()), 'lessons_options' => array_map(function ($lesson) { return ['value' => $lesson['id'], 'label' => $lesson['name']]; }, $this->labService->getLessons())]); }