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;
 }
Exemple #2
0
 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";
     }))]);
 }
Exemple #3
0
 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;
 }
Exemple #4
0
 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())]);
 }
Exemple #5
0
 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($school_id)
 {
     $school = $this->schoolService->getSchool($school_id);
     try {
         $equipment = $this->inventoryService->getUnitEquipment($school['registry_no']);
     } catch (Exception $e) {
         $this->logger->error(sprintf('Problem retrieving assets from inventory for school %s', $school_id));
         $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
         return false;
     }
     $labTypes = $this->getLabTypes();
     $assetTypes = $this->getAssetTypes();
     try {
         $locations = $this->getLocations($school_id, $equipment, $labTypes, $assetTypes);
         R::storeAll($locations);
         $this->logger->info(sprintf('Add assets from inventory for school %s', $school_id));
         return $this->labService->getLabsBySchoolId($school_id);
     } catch (Exception $e) {
         $this->logger->error(sprintf('Problem inserting assets for school %s in database', $school_id));
         $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
         return false;
     }
 }
 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;
 }