diff --git a/drupal/modules/epal/src/Controller/DirectorView.php b/drupal/modules/epal/src/Controller/DirectorView.php index 11a5b9e7fd9266174be87289c976e1f73a98c6d9..7591a323b9965f99faee27699a1fb44708348350 100755 --- a/drupal/modules/epal/src/Controller/DirectorView.php +++ b/drupal/modules/epal/src/Controller/DirectorView.php @@ -369,15 +369,20 @@ class DirectorView extends ControllerBase $userRole = $tmpRole; } } - $this->logger->warning('userRole='.$userRole); if ($userRole === '') { return $this->respondWithStatus([ - 'error_code' => 4003, - ], Response::HTTP_FORBIDDEN); + 'error_code' => 4003, + ], Response::HTTP_FORBIDDEN); } elseif ($userRole === 'regioneduadmin') { - $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id' => $selectionId)); + $schools = $this->entityTypeManager + ->getStorage('eepal_school') + ->loadByProperties(array('region_edu_admin_id' => $selectionId)); } elseif ($userRole === 'eduadmin') { - $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('edu_admin_id' => $selectionId)); + $schools = $this->entityTypeManager + ->getStorage('eepal_school') + ->loadByProperties(array('edu_admin_id' => $selectionId)); + } else { + $schools = []; } if ($schools) { $list = array(); @@ -385,23 +390,22 @@ class DirectorView extends ControllerBase foreach ($schools as $object) { $status = $this->returnstatus($object->id()); $list[] = array( - 'id' => $object->id(), - 'name' => $object->name->value, - 'status' => $status, - ); + 'id' => $object->id(), + 'name' => $object->name->value, + 'status' => $status, + ); } - return $this->respondWithStatus( - $list, Response::HTTP_OK); + return $this->respondWithStatus($list, Response::HTTP_OK); } else { return $this->respondWithStatus([ - 'message' => t('Perfecture not found!'), - ], Response::HTTP_FORBIDDEN); + 'message' => t('No schools found!'), + ], Response::HTTP_FORBIDDEN); } } else { return $this->respondWithStatus([ - 'message' => t('User not found!'), - ], Response::HTTP_FORBIDDEN); + 'message' => t('User not found!'), + ], Response::HTTP_FORBIDDEN); } } @@ -422,122 +426,143 @@ class DirectorView extends ControllerBase } if ($userRole === '') { return $this->respondWithStatus([ - 'error_code' => 4003, - ], Response::HTTP_FORBIDDEN); + 'error_code' => 4003, + ], Response::HTTP_FORBIDDEN); } elseif ($userRole === 'regioneduadmin') { - $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid, 'region_edu_admin_id' => $newid)); + $SchoolCats = $this->entityTypeManager->getStorage('eepal_school') + ->loadByProperties(array('id' => $schoolid, 'region_edu_admin_id' => $newid)); } elseif ($userRole === 'eduadmin') { - $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid, 'edu_admin_id' => $newid)); + $SchoolCats = $this->entityTypeManager->getStorage('eepal_school') + ->loadByProperties(array('id' => $schoolid, 'edu_admin_id' => $newid)); } $SchoolCat = reset($SchoolCats); if ($SchoolCat) { - $list = array(); $categ = $SchoolCat->metathesis_region->value; - $operation_shift = $SchoolCat -> operation_shift -> value; + $operation_shift = $SchoolCat->operation_shift->value; + } else { + return $this->respondWithStatus([ + 'message' => t('No school located'), + ], Response::HTTP_FORBIDDEN); } - $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid)); + $list = array(); + $limit = -1; + $CourseA = $this->entityTypeManager->getStorage('eepal_school') + ->loadByProperties(array('id' => $schoolid)); if ($CourseA) { - $limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name' => 1, 'category' => $categ)); + $limit_down = $this->entityTypeManager->getStorage('epal_class_limits') + ->loadByProperties(array('name' => 1, 'category' => $categ)); $limitdown = reset($limit_down); if ($limitdown) { $limit = $limitdown->limit_down->value; + } else { + $limit = -1; } - $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1)); + $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class') + ->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1)); $list = array(); foreach ($CourseA as $object) { $list[] = array( - 'id' => '1', - 'name' => 'Α Λυκείου', - 'size' => sizeof($studentPerSchool), - 'categ' => $categ, - 'classes' => 1, - 'limitdown' => $limit, - ); + 'id' => '1', + 'name' => 'Α Λυκείου', + 'size' => sizeof($studentPerSchool), + 'categ' => $categ, + 'classes' => 1, + 'limitdown' => $limit, + ); } } - $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid)); + $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal') + ->loadByProperties(array('epal_id' => $schoolid)); if ($CourseB) { - $limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name' => 2, 'category' => $categ)); + $limit_down = $this->entityTypeManager->getStorage('epal_class_limits') + ->loadByProperties(array('name' => 2, 'category' => $categ)); $limitdown = reset($limit_down); if ($limitdown) { $limit = $limitdown->limit_down->value; + } else { + $limit = -1; } foreach ($CourseB as $object) { $sectorid = $object->sector_id->entity->id(); - $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2)); + $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class') + ->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2)); $list[] = array( - 'id' => $object->sector_id->entity->id(), - 'name' => 'Β Λυκείου '.$object->sector_id->entity->get('name')->value, - 'size' => sizeof($studentPerSchool), - 'categ' => $categ, - 'classes' => 2, - 'limitdown' => $limit, - - ); + 'id' => $object->sector_id->entity->id(), + 'name' => 'Β Λυκείου '.$object->sector_id->entity->get('name')->value, + 'size' => sizeof($studentPerSchool), + 'categ' => $categ, + 'classes' => 2, + 'limitdown' => $limit, + ); } } - $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid)); + $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal') + ->loadByProperties(array('epal_id' => $schoolid)); if ($CourseC) { - $limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name' => 3, 'category' => $categ)); + $limit_down = $this->entityTypeManager->getStorage('epal_class_limits') + ->loadByProperties(array('name' => 3, 'category' => $categ)); $limitdown = reset($limit_down); if ($limitdown) { $limit = $limitdown->limit_down->value; + } else { + $limit = -1; } foreach ($CourseC as $object) { $specialityid = $object->specialty_id->entity->id(); - $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3)); - + $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class') + ->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3)); $list[] = array( - 'id' => $object->specialty_id->entity->id(), - 'name' => 'Γ Λυκείου '.$object->specialty_id->entity->get('name')->value, - 'size' => sizeof($studentPerSchool), - 'categ' => $categ, - 'classes' => 3, - 'limitdown' => $limit, - - ); + 'id' => $object->specialty_id->entity->id(), + 'name' => 'Γ Λυκείου '.$object->specialty_id->entity->get('name')->value, + 'size' => sizeof($studentPerSchool), + 'categ' => $categ, + 'classes' => 3, + 'limitdown' => $limit, + ); } } if ($CourseC && $operation_shift != 'ΗΜΕΡΗΣΙΟ') { - $limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name' => 4, 'category' => $categ)); + $limit_down = $this->entityTypeManager->getStorage('epal_class_limits') + ->loadByProperties(array('name' => 4, 'category' => $categ)); $limitdown = reset($limit_down); if ($limitdown) { $limit = $limitdown->limit_down->value; + } else { + $limit = -1; } foreach ($CourseC as $object) { $specialityid = $object->specialty_id->entity->id(); - $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 4)); + $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class') + ->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 4)); $list[] = array( - 'id' => $object->specialty_id->entity->id(), - 'name' => 'Δ Λυκείου '.$object->specialty_id->entity->get('name')->value, - 'size' => sizeof($studentPerSchool), - 'categ' => $categ, - 'classes' => 4, - 'limitdown' => $limit, - - ); + 'id' => $object->specialty_id->entity->id(), + 'name' => 'Δ Λυκείου '.$object->specialty_id->entity->get('name')->value, + 'size' => sizeof($studentPerSchool), + 'categ' => $categ, + 'classes' => 4, + 'limitdown' => $limit, + ); } } if ($CourseA || $CourseB || $CourseC) { - return $this->respondWithStatus( - $list, Response::HTTP_OK); + return $this->respondWithStatus($list, Response::HTTP_OK); } else { return $this->respondWithStatus([ - 'message' => t('Perfecture not found!'), - ], Response::HTTP_FORBIDDEN); + 'message' => t('No courses found!'), + ], Response::HTTP_FORBIDDEN); } } else { return $this->respondWithStatus([ - 'message' => t('User not found!'), - ], Response::HTTP_FORBIDDEN); + 'message' => t('User not found!'), + ], Response::HTTP_FORBIDDEN); } } @@ -548,6 +573,8 @@ class DirectorView extends ControllerBase $SchoolCat = reset($SchoolCats); if ($SchoolCat) { $categ = $SchoolCat->metathesis_region->value; + } else { + $categ = '-'; } $CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $schoolid)); @@ -556,7 +583,10 @@ class DirectorView extends ControllerBase $limitdown = reset($limit_down); if ($limitdown) { $limit = $limitdown->limit_down->value; + } else { + $limit = -1; } + $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1)); if (sizeof($studentPerSchool) < $limit) { @@ -570,6 +600,8 @@ class DirectorView extends ControllerBase $limitdown = reset($limit_down); if ($limitdown) { $limit = $limitdown->limit_down->value; + } else { + $limit = -1; } foreach ($CourseB as $object) { @@ -587,6 +619,8 @@ class DirectorView extends ControllerBase $limitdown = reset($limit_down); if ($limitdown) { $limit = $limitdown->limit_down->value; + } else { + $limit = -1; } foreach ($CourseC as $object) { diff --git a/source/components/infoviews/eduadmin-view.ts b/source/components/infoviews/eduadmin-view.ts index 37b6c02af8b2230879b31780cb210568771045b6..e2a5693ee47cfbaf9cee817173a9fb2d5ae84c66 100644 --- a/source/components/infoviews/eduadmin-view.ts +++ b/source/components/infoviews/eduadmin-view.ts @@ -1,13 +1,13 @@ -import { Component, OnInit, OnDestroy, ElementRef, ViewChild, Injectable} from "@angular/core"; -import { AppSettings } from '../../app.settings'; -import { HelperDataService } from '../../services/helper-data-service'; -import {Observable} from "rxjs/Observable"; -import {Http, Headers, RequestOptions} from '@angular/http'; -import { NgRedux, select } from 'ng2-redux'; -import { IAppState } from '../../store/store'; -import {Router, ActivatedRoute, Params} from '@angular/router'; -import { BehaviorSubject, Subscription } from 'rxjs/Rx'; -import { ILoginInfo } from '../../store/logininfo/logininfo.types'; +import { Component, OnInit, OnDestroy, ElementRef, ViewChild, Injectable } from "@angular/core"; +import { AppSettings } from "../../app.settings"; +import { HelperDataService } from "../../services/helper-data-service"; +import { Observable } from "rxjs/Observable"; +import { Http, Headers, RequestOptions } from "@angular/http"; +import { NgRedux, select } from "ng2-redux"; +import { IAppState } from "../../store/store"; +import { Router, ActivatedRoute, Params } from "@angular/router"; +import { BehaviorSubject, Subscription } from "rxjs/Rx"; +import { ILoginInfo } from "../../store/logininfo/logininfo.types"; import { FormBuilder, @@ -15,34 +15,46 @@ import { FormControl, FormArray, Validators, -} from '@angular/forms'; +} from "@angular/forms"; @Component({ - selector: 'eduadmin-view', + selector: "eduadmin-view", template: `
+