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');
     }
     $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())]);
 }
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;
     }, [])]);
 }
Example #3
0
 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;
     }
     $teacher = $this->staffService->getTeacherById($id);
     if ($teacher['school_id'] != $school->id) {
         $res = $res->withStatus(403, 'Schools not match');
         return $res;
     }
     try {
         $this->staffService->removeTeacher($id);
         $res = $res->withStatus(204);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }
Example #4
0
 public function __invoke(Request $req, Response $res, array $args = [])
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $params = $req->getParams();
     $params['school_id'] = $school->id;
     $id = $params['id'];
     unset($params['id']);
     try {
         if ($id) {
             $teacher = $this->staffService->updateTeacher($params, $id);
             $res = $res->withStatus(200);
         } else {
             $teacher = $this->staffService->createTeacher($params);
             $res = $res->withStatus(201);
         }
         $res = $res->withJson($teacher);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }