public function __construct(LabServiceInterface $labService, AssetServiceInterface $assetsService) { $id = new Input('id'); $id->setRequired(false)->getValidatorChain()->attach(new Validator\Digits()); $itemCategoryId = new Input('itemcategory_id'); $itemCategoryId->setRequired(true)->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\Callback(['callback' => function ($value) use($assetsService) { try { $itemCategory = $assetsService->getItemCategoryById($value); return isset($itemCategory['id']) && $itemCategory['id'] == $value; } catch (Exception $ex) { return false; } }, 'message' => 'Ο τύπος δεν βρέθηκε'])); $labId = new Input('lab_id'); $labId->setRequired(true)->getFilterChain()->attach(new Filter\ToInt()); $labId->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\Callback(['callback' => function ($value) use($labService) { try { $lab = $labService->getLabById($value); return isset($lab['id']) && $lab['id'] == $value; } catch (Exception $ex) { return false; } }, 'message' => 'Το εργαστήριο δεν βρέθηκε'])); $qty = new Input('qty'); $qty->setRequired(true)->getFilterChain()->attach(new Filter\Digits())->attach(new Filter\ToInt()); $qty->getValidatorChain()->attach(new Validator\NotEmpty())->attach(new Validator\GreaterThan(['min' => 0])); $acquisitionYear = new Input('acquisition_year'); $acquisitionYear->setRequired(false)->getFilterChain()->attach(new Filter\Digits()); $acquisitionYear->getValidatorChain()->attach(new Validator\Date(['format' => 'Y']))->attach(new Validator\LessThan(['max' => date('Y'), 'inclusive' => true])); $comments = new Input('comments'); $comments->setRequired(false)->getFilterChain()->attach(new Filter\StripTags())->attach(new Filter\StringTrim()); $this->inputFilter = new InputFilter(); $this->inputFilter->add($id)->add($labId)->add($itemCategoryId)->add($qty)->add($acquisitionYear)->add($comments); }
private function getLabTypes() { return array_reduce($this->labService->getLabTypes(), function ($map, $type) { $map[trim($type['name'])] = $type['id']; return $map; }, []); }
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) { $school = $req->getAttribute('school'); if ($req->isPost()) { $this->appFormInputFilter->setData(array_merge($req->getParams(), ['school_id' => $school->id, 'submitted_by' => $this->authService->getIdentity()->mail])); $isValid = $this->appFormInputFilter->isValid(); if ($isValid) { $data = $this->appFormInputFilter->getValues(); $appForm = $this->appFormService->submit($data); $_SESSION['applicationForm']['appForm'] = $appForm; $res = $res->withRedirect($this->successUrl); return $res; } $this->view['form'] = ['is_valid' => $isValid, 'values' => $this->appFormInputFilter->getValues(), 'raw_values' => $this->appFormInputFilter->getRawValues(), 'messages' => $this->appFormInputFilter->getMessages()]; } $loadForm = (bool) $req->getParam('load', false); $this->view['choose'] = !$loadForm && !$req->isPost(); if (!$req->isPost() && $loadForm) { if (null !== ($appForm = $this->appFormService->findSchoolApplicationForm($school->id))) { $this->view['form'] = ['values' => $appForm]; } } $labs = $this->labService->getLabsBySchoolId($school->id); $res = $this->view->render($res, 'application_form/form.twig', ['lab_choices' => array_map(function ($lab) { return ['value' => $lab['id'], 'label' => $lab['name']]; }, $labs), 'type_choices' => array_map(function ($category) { return ['value' => $category['id'], 'label' => $category['name']]; }, $this->assetsService->getAllItemCategories())]); return $res; }
public function __invoke(Request $req, Response $res, array $args = []) { $school = $req->getAttribute('school', false); if (!$school) { return $res->withStatus(403, 'No school'); } $assets = $this->schoolAssetsService->getAssetsForSchool($school->id); $itemCategories = $this->assetsService->getAllItemCategories(); $labs = $this->labService->getLabsBySchoolId($school->id); return $this->view->render($res, 'schools/assets.twig', ['school' => $school, 'assets' => $assets, 'item_categories' => array_map(function ($category) { return ['value' => $category['id'], 'label' => $category['name']]; }, $itemCategories), 'labs' => array_map(function ($lab) { return ['value' => $lab['id'], 'label' => $lab['name']]; }, array_filter($labs, function ($lab) { return $lab['is_new'] !== "1"; }))]); }
public function __invoke(Request $req, Response $res, callable $next) { $res = $next($req, $res); $identity = $this->authService->getIdentity(); if (null === $identity) { return $res; } $user = R::load('user', $identity->id); if (!$user->school_id) { return $res; } $school_id = $user->school_id; if (0 < count($this->labService->getLabsBySchoolId($school_id))) { return $res; } $sync = $this->syncFromInventory; $sync($school_id); return $res; }
public function __invoke(Request $req, Response $res, array $args = []) { $school = $req->getAttribute('school'); return $this->view->render($res, 'schools/index.twig', ['school' => $school, 'staff' => array_reduce($this->staffService->getTeachersBySchoolId($school->id), function ($aggr, $teacher) { $name = sprintf('%s %s (%s)', $teacher['name'], $teacher['surname'], $teacher['branch']); if ($teacher['is_principle']) { $aggr['principle'] = $name; } else { $aggr['teachers'][] = $name; } return $aggr; }, []), 'labs' => $this->labService->getLabsBySchoolId($school->id), 'assets' => array_reduce($this->assetService->getAssetsForSchool($school->id), function ($aggr, $asset) { $assetType = $asset['itemcategory_id']; if (!isset($aggr[$assetType])) { $aggr[$assetType] = ['category' => $asset['itemcategory'], 'count' => 0]; } $aggr[$assetType]['count'] += $asset['qty']; return $aggr; }, [])]); }
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())]); }
public function __invoke(Request $req, Response $res) { $school = $req->getAttribute('school'); if ($req->isPost()) { $reqParams = $req->getParams(); array_splice($reqParams['items'], 0, 0); $this->appFormInputFilter->setData(array_merge($reqParams, ['school_id' => $school->id, 'submitted_by' => $this->authService->getIdentity()->mail])); $isValid = $this->appFormInputFilter->isValid(); if ($isValid) { $data = $this->appFormInputFilter->getValues(); $appForm = $this->appFormService->submit($data); $_SESSION['applicationForm']['appForm'] = $appForm; $res = $res->withRedirect($this->successUrl); return $res; } $this->view['form'] = ['is_valid' => $isValid, 'values' => $this->appFormInputFilter->getValues(), 'raw_values' => $this->appFormInputFilter->getRawValues(), 'messages' => $this->appFormInputFilter->getMessages()]; } $loadForm = (bool) $req->getParam('load', false); $this->view['choose'] = !$loadForm && !$req->isPost(); if (!$req->isPost() && $loadForm) { // take care of new options in applications and migrate existing ones if (null !== ($appForm = $this->appFormService->findSchoolApplicationForm($school->id))) { /** * Do mapping of old items to new only if items do exist (old form) * and the map is available at the app settings. * TODO: Only one version migrations are supported. If the old items are * two or more versions older, they will not be handled. */ // get the existing (db) application form version $items_version = $this->version; if (isset($appForm['items']) && \count($appForm['items']) > 0) { $items_version = array_values($appForm['items'])[0]['version']; } if ($this->version != $items_version && isset($appForm['items']) && isset($this->container['settings']['application_form']['itemcategory']['map']) && $this->container['settings']['application_form']['itemcategory']['map']['fromversion'] == $items_version && $this->container['settings']['application_form']['itemcategory']['map']['toversion'] == $this->version && isset($this->container['settings']['application_form']['itemcategory']['map']['items'])) { // if map exists for this version, use it $items_map = $this->container['settings']['application_form']['itemcategory']['map']['items']; $appForm['items'] = array_map(function ($item) use($items_map) { $migrate_values = []; if (isset($items_map[$item['itemcategory_id']]) && intval($items_map[$item['itemcategory_id']]) > 0) { $migrate_values = ['itemcategory_prev' => $item['itemcategory_id'], 'itemcategory_id_prev' => $item['itemcategory_id'], 'itemcategory_id' => intval($items_map[$item['itemcategory_id']])]; } else { $migrate_values = ['itemcategory_prev' => '', 'itemcategory_id_prev' => -1]; } $migrate_values['prev_form_load'] = true; return array_merge($item, $migrate_values); }, $appForm['items']); } elseif ($this->version != $items_version && isset($appForm['items']) && isset($this->container['settings']['application_form']['itemcategory']['map']) && ($this->container['settings']['application_form']['itemcategory']['map']['fromversion'] != $items_version || $this->container['settings']['application_form']['itemcategory']['map']['toversion'] != $this->version)) { // if map does not exist for this version, notify user $items_map = $this->container['settings']['application_form']['itemcategory']['map']['items']; $appForm['items'] = array_map(function ($item) use($items_map) { $migrate_values = ['itemcategory_prev' => '', 'itemcategory_id_prev' => -2, 'prev_form_load' => true]; return array_merge($item, $migrate_values); }, $appForm['items']); } $this->view['form'] = ['values' => $appForm]; } } $labs = $this->labService->getLabsBySchoolId($school->id); $res = $this->view->render($res, 'application_form/form.twig', ['lab_choices' => array_map(function ($lab) { return ['value' => $lab['id'], 'label' => $lab['name']]; }, $labs), 'type_choices' => array_map(function ($category) { return ['value' => $category['id'], 'label' => $category['name']]; }, $this->assetsService->getAllItemCategories($this->version))]); return $res; }