Example #1
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";
     }))]);
 }
Example #2
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;
     }, [])]);
 }