コード例 #1
0
ファイル: ListAssets.php プロジェクト: kanellov/gredu_labs
 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";
     }))]);
 }
コード例 #2
0
ファイル: DeleteAsset.php プロジェクト: eellak/gredu_labs
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school->id) {
         return $res->withStatus(403, 'No school');
     }
     $id = $req->getParam('id', false);
     if (!$id) {
         $res = $res->withStatus(404);
         return $res;
     }
     try {
         $this->schoolAssetsService->removeAssetFromSchool($school->id, $id);
         $res = $res->withStatus(204);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }
コード例 #3
0
ファイル: Index.php プロジェクト: eellak/gredu_labs
 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;
     }, [])]);
 }