Student application submit validation changes

parent ed27fc4c
...@@ -29,6 +29,15 @@ class ApplicationSubmit extends ControllerBase ...@@ -29,6 +29,15 @@ class ApplicationSubmit extends ControllerBase
const CERT_GYM = 'Απολυτήριο Γυμνασίου'; const CERT_GYM = 'Απολυτήριο Γυμνασίου';
const CERT_LYK = 'Απολυτήριο Λυκείου'; const CERT_LYK = 'Απολυτήριο Λυκείου';
const VALID_NAMES_PATTERN = '/^[A-Za-zΑ-ΩΆΈΉΊΙΎΌΏα-ωάέήίΐύόώ \-]*$/mu';
const VALID_UCASE_NAMES_PATTERN = '/^[A-ZΑ-Ω]{3,}[A-ZΑ-Ω \-]*$/mu';
const VALID_ADDRESS_PATTERN = '/^[0-9A-Za-zΑ-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ\/\. \-]*$/mu';
const VALID_ADDRESSTK_PATTERN = '/^[0-9]{5}$/';
const VALID_DIGITS_PATTERN = '/^[0-9]*$/';
const VALID_TELEPHONE_PATTERN = '/^2[0-9]{9}$/';
const VALID_YEAR_PATTERN = '/^(19[6789][0-9]|20[0-1][0-9])$/';
const VALID_CAPACITY_PATTERN = '/[0-9]*$/';
protected $entityTypeManager; protected $entityTypeManager;
protected $logger; protected $logger;
protected $connection; protected $connection;
...@@ -60,7 +69,8 @@ class ApplicationSubmit extends ControllerBase ...@@ -60,7 +69,8 @@ class ApplicationSubmit extends ControllerBase
); );
} }
public function appSubmit(Request $request) { public function appSubmit(Request $request)
{
if (!$request->isMethod('POST')) { if (!$request->isMethod('POST')) {
return $this->respondWithStatus([ return $this->respondWithStatus([
"error_code" => 2001 "error_code" => 2001
...@@ -69,11 +79,9 @@ class ApplicationSubmit extends ControllerBase ...@@ -69,11 +79,9 @@ class ApplicationSubmit extends ControllerBase
$applicationForm = array(); $applicationForm = array();
$content = $request->getContent(); $content = $request->getContent();
if (!empty($content)) { if (!empty($content)) {
$applicationForm = json_decode($content, TRUE); $applicationForm = json_decode($content, true);
} } else {
else {
return $this->respondWithStatus([ return $this->respondWithStatus([
"error_code" => 5002 "error_code" => 5002
], Response::HTTP_BAD_REQUEST); ], Response::HTTP_BAD_REQUEST);
...@@ -101,17 +109,15 @@ class ApplicationSubmit extends ControllerBase ...@@ -101,17 +109,15 @@ class ApplicationSubmit extends ControllerBase
$regionaddress_encoded = $crypt->encrypt($applicationForm[0]['regionaddress']); $regionaddress_encoded = $crypt->encrypt($applicationForm[0]['regionaddress']);
$regiontk_encoded = $crypt->encrypt($applicationForm[0]['regiontk']); $regiontk_encoded = $crypt->encrypt($applicationForm[0]['regiontk']);
$regionarea_encoded = $crypt->encrypt($applicationForm[0]['regionarea']); $regionarea_encoded = $crypt->encrypt($applicationForm[0]['regionarea']);
//$certificatetype_encoded = $crypt->encrypt($applicationForm[0]['certificatetype']); // $certificatetype_encoded = $crypt->encrypt($applicationForm[0]['certificatetype']);
$relationtostudent_encoded = $crypt->encrypt($applicationForm[0]['relationtostudent']); $relationtostudent_encoded = $crypt->encrypt($applicationForm[0]['relationtostudent']);
$telnum_encoded = $crypt->encrypt($applicationForm[0]['telnum']); $telnum_encoded = $crypt->encrypt($applicationForm[0]['telnum']);
$guardian_name_encoded = $crypt->encrypt($applicationForm[0]['cu_name']); $guardian_name_encoded = $crypt->encrypt($applicationForm[0]['cu_name']);
$guardian_surname_encoded = $crypt->encrypt($applicationForm[0]['cu_surname']); $guardian_surname_encoded = $crypt->encrypt($applicationForm[0]['cu_surname']);
$guardian_fathername_encoded = $crypt->encrypt($applicationForm[0]['cu_fathername']); $guardian_fathername_encoded = $crypt->encrypt($applicationForm[0]['cu_fathername']);
$guardian_mothername_encoded = $crypt->encrypt($applicationForm[0]['cu_mothername']); $guardian_mothername_encoded = $crypt->encrypt($applicationForm[0]['cu_mothername']);
} } catch (\Exception $e) {
catch (\Exception $e) {
print_r($e->getMessage()); print_r($e->getMessage());
unset($crypt);
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
return $this->respondWithStatus([ return $this->respondWithStatus([
"error_code" => 5001 "error_code" => 5001
...@@ -125,7 +131,7 @@ class ApplicationSubmit extends ControllerBase ...@@ -125,7 +131,7 @@ class ApplicationSubmit extends ControllerBase
$authToken = $request->headers->get('PHP_AUTH_USER'); $authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken)); $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers); $epalUser = reset($epalUsers);
if (!$epalUser){ if (!$epalUser) {
return $this->respondWithStatus([ return $this->respondWithStatus([
"error_code" => 4003 "error_code" => 4003
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
...@@ -148,7 +154,6 @@ class ApplicationSubmit extends ControllerBase ...@@ -148,7 +154,6 @@ class ApplicationSubmit extends ControllerBase
'points' => 0, 'points' => 0,
'user_id' => $epalUser->user_id->target_id, 'user_id' => $epalUser->user_id->target_id,
'epaluser_id' => $epalUser->id(), 'epaluser_id' => $epalUser->id(),
'name' => $name_encoded, 'name' => $name_encoded,
'studentsurname' => $studentsurname_encoded, 'studentsurname' => $studentsurname_encoded,
'birthdate' => $applicationForm[0]['studentbirthdate'], 'birthdate' => $applicationForm[0]['studentbirthdate'],
...@@ -157,8 +162,8 @@ class ApplicationSubmit extends ControllerBase ...@@ -157,8 +162,8 @@ class ApplicationSubmit extends ControllerBase
'regionaddress' => $regionaddress_encoded, 'regionaddress' => $regionaddress_encoded,
'regionarea' => $regionarea_encoded, 'regionarea' => $regionarea_encoded,
'regiontk' => $regiontk_encoded, 'regiontk' => $regiontk_encoded,
//'certificatetype' => $certificatetype_encoded, // 'certificatetype' => $certificatetype_encoded,
//'graduation_year' => $applicationForm[0]['graduation_year'], // 'graduation_year' => $applicationForm[0]['graduation_year'],
'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'], 'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'],
'lastschool_unittypeid' => $applicationForm[0]['lastschool_unittypeid'], 'lastschool_unittypeid' => $applicationForm[0]['lastschool_unittypeid'],
'lastschool_schoolname' => $applicationForm[0]['lastschool_schoolname'], 'lastschool_schoolname' => $applicationForm[0]['lastschool_schoolname'],
...@@ -172,11 +177,25 @@ class ApplicationSubmit extends ControllerBase ...@@ -172,11 +177,25 @@ class ApplicationSubmit extends ControllerBase
'agreement' => $applicationForm[0]['disclaimer_checked'], 'agreement' => $applicationForm[0]['disclaimer_checked'],
'relationtostudent' => $relationtostudent_encoded, 'relationtostudent' => $relationtostudent_encoded,
'telnum' => $telnum_encoded, 'telnum' => $telnum_encoded,
'second_period' => $second_period, 'second_period' => $second_period,
); );
if (($errorCode = $this->validateStudent($student)) > 0) { if (($errorCode = $this->validateStudent(array_merge(
$student, [
'name' => $applicationForm[0]['name'],
'studentsurname' => $applicationForm[0]['studentsurname'],
'fatherfirstname' => $applicationForm[0]['fatherfirstname'],
'motherfirstname' => $applicationForm[0]['motherfirstname'],
'regionaddress' => $applicationForm[0]['regionaddress'],
'regiontk' => $applicationForm[0]['regiontk'],
'regionarea' => $applicationForm[0]['regionarea'],
'relationtostudent' => $applicationForm[0]['relationtostudent'],
'telnum' => $applicationForm[0]['telnum'],
'guardian_name' => $applicationForm[0]['cu_name'],
'guardian_surname' => $applicationForm[0]['cu_surname'],
'guardian_fathername' => $applicationForm[0]['cu_fathername'],
'guardian_mothername' => $applicationForm[0]['cu_mothername']
]))) > 0) {
return $this->respondWithStatus([ return $this->respondWithStatus([
"error_code" => $errorCode "error_code" => $errorCode
], Response::HTTP_OK); ], Response::HTTP_OK);
...@@ -218,7 +237,6 @@ class ApplicationSubmit extends ControllerBase ...@@ -218,7 +237,6 @@ class ApplicationSubmit extends ControllerBase
$entity_storage_epalchosen->save($entity_object); $entity_storage_epalchosen->save($entity_object);
} }
if ($applicationForm[0]['currentclass'] === "3" || $applicationForm[0]['currentclass'] === "4") { if ($applicationForm[0]['currentclass'] === "3" || $applicationForm[0]['currentclass'] === "4") {
$course = array( $course = array(
'student_id' => $created_student_id, 'student_id' => $created_student_id,
...@@ -256,19 +274,17 @@ class ApplicationSubmit extends ControllerBase ...@@ -256,19 +274,17 @@ class ApplicationSubmit extends ControllerBase
return $res; return $res;
} }
private function retrievePeriod()
private function retrievePeriod() { {
$config_storage = $this->entityTypeManager->getStorage('epal_config'); $config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config')); $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs); $epalConfig = reset($epalConfigs);
if (!$epalConfig) if (!$epalConfig) {
return 0; $secondPeriodEnabled = 0;
else } else {
$secondPeriodEnabled = $epalConfig->activate_second_period->getString(); $secondPeriodEnabled = $epalConfig->activate_second_period->getString();
}
return $secondPeriodEnabled; return $secondPeriodEnabled;
} }
/** /**
...@@ -299,58 +315,51 @@ class ApplicationSubmit extends ControllerBase ...@@ -299,58 +315,51 @@ class ApplicationSubmit extends ControllerBase
(checkdate($date_parts[1], $date_parts[2], $date_parts[0]) !== true)) { (checkdate($date_parts[1], $date_parts[2], $date_parts[0]) !== true)) {
return 1003; return 1003;
} }
if (intval($date_parts[0]) >= 2003) if (intval($date_parts[0]) >= 2003) {
return 1003; return 1003;
}
$birthdate = "{$date_parts[2]}-{$date_parts[1]}-{$date_parts[0]}"; $birthdate = "{$date_parts[2]}-{$date_parts[1]}-{$date_parts[0]}";
if (!$student["name"]) { if (preg_match(self::VALID_UCASE_NAMES_PATTERN, $student["name"]) !== 1) {
return 1004; return 1004;
} }
if (!$student["studentsurname"]) { if (preg_match(self::VALID_UCASE_NAMES_PATTERN, $student["studentsurname"]) !== 1) {
return 1005; return 1005;
} }
if (!$student["fatherfirstname"]) { if (preg_match(self::VALID_UCASE_NAMES_PATTERN, $student["fatherfirstname"]) !== 1) {
return 1006; return 1006;
} }
if (!$student["motherfirstname"]) { if (preg_match(self::VALID_UCASE_NAMES_PATTERN, $student["motherfirstname"]) !== 1) {
return 1007; return 1007;
} }
if (!$student["regionaddress"]) { if (preg_match(self::VALID_ADDRESS_PATTERN, $student["regionaddress"]) !== 1) {
return 1008; return 1008;
} }
if (!$student["regiontk"]) { if (preg_match(self::VALID_ADDRESSTK_PATTERN, $student["regiontk"]) !== 1) {
return 1009; return 1009;
} }
if (!$student["regionarea"]) { if (preg_match(self::VALID_NAMES_PATTERN, $student["regionarea"]) !== 1) {
return 1010; return 1010;
} }
/* if (!$student["currentclass"] || ($student["currentclass"] !== "1" && $student["currentclass"] !== "2" && $student["currentclass"] !== "3" && $student["currentclass"] !== "4")) {
if (!$student["certificatetype"]) {
return 1011;
}
if (!$student["graduation_year"]) {
return 1012;
}
*/
if (!$student["currentclass"] || ($student["currentclass"] !== "1" && $student["currentclass"] !== "2" && $student["currentclass"] !== "3" && $student["currentclass"] !== "4") ) {
return 1013; return 1013;
} }
if (!$student["relationtostudent"]) { if (!$student["relationtostudent"]) {
return 1014; return 1014;
} }
if (!$student["telnum"]) { if (preg_match(self::VALID_TELEPHONE_PATTERN, $student["telnum"]) !== 1) {
return 1015; return 1015;
} }
if (!$student["guardian_name"]) { if (preg_match(self::VALID_NAMES_PATTERN, $student["guardian_name"]) !== 1) {
return 1016; return 1016;
} }
if (!$student["guardian_surname"]) { if (preg_match(self::VALID_NAMES_PATTERN, $student["guardian_surname"]) !== 1) {
return 1017; return 1017;
} }
if (!$student["guardian_fathername"]) { if (preg_match(self::VALID_NAMES_PATTERN, $student["guardian_fathername"]) !== 1) {
return 1018; return 1018;
} }
if (!$student["guardian_mothername"]) { if (preg_match(self::VALID_NAMES_PATTERN, $student["guardian_mothername"]) !== 1) {
return 1019; return 1019;
} }
if (!$student["lastschool_registrynumber"]) { if (!$student["lastschool_registrynumber"]) {
......
...@@ -16,13 +16,11 @@ class DirectorView extends ControllerBase ...@@ -16,13 +16,11 @@ class DirectorView extends ControllerBase
{ {
protected $entityTypeManager; protected $entityTypeManager;
protected $logger; protected $logger;
// protected $testSchoolId='0640050';
public function __construct( public function __construct(
EntityTypeManagerInterface $entityTypeManager, EntityTypeManagerInterface $entityTypeManager,
LoggerChannelFactoryInterface $loggerChannel LoggerChannelFactoryInterface $loggerChannel
) { ) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal-school'); $this->logger = $loggerChannel->get('epal-school');
} }
...@@ -35,8 +33,6 @@ class DirectorView extends ControllerBase ...@@ -35,8 +33,6 @@ class DirectorView extends ControllerBase
); );
} }
public function getStudentPerSchool(Request $request, $classId, $sector, $specialit) public function getStudentPerSchool(Request $request, $classId, $sector, $specialit)
{ {
try { try {
...@@ -68,7 +64,6 @@ class DirectorView extends ControllerBase ...@@ -68,7 +64,6 @@ class DirectorView extends ControllerBase
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
$userRoles = $user->getRoles(); $userRoles = $user->getRoles();
$userRole = ''; $userRole = '';
foreach ($userRoles as $tmpRole) { foreach ($userRoles as $tmpRole) {
...@@ -91,11 +86,10 @@ class DirectorView extends ControllerBase ...@@ -91,11 +86,10 @@ class DirectorView extends ControllerBase
} }
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId)); $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId));
} }
$i = 0;
if ($studentPerSchool) { if ($studentPerSchool) {
$list = array(); $list = array();
foreach ($studentPerSchool as $object) { foreach ($studentPerSchool as $object) {
$studentId = intval($object->student_id ->getString()); $studentId = intval($object->student_id->getString());
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $studentId)); $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $studentId));
$epalStudent = reset($epalStudents); $epalStudent = reset($epalStudents);
if ($epalStudents) { if ($epalStudents) {
...@@ -118,7 +112,6 @@ class DirectorView extends ControllerBase ...@@ -118,7 +112,6 @@ class DirectorView extends ControllerBase
} }
} }
$crypt = new Crypt(); $crypt = new Crypt();
try { try {
$name_decoded = $crypt->decrypt($epalStudent->name->value); $name_decoded = $crypt->decrypt($epalStudent->name->value);
...@@ -142,7 +135,6 @@ class DirectorView extends ControllerBase ...@@ -142,7 +135,6 @@ class DirectorView extends ControllerBase
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
} }
$list[] = array( $list[] = array(
'id' => $epalStudent->id(), 'id' => $epalStudent->id(),
'name' => $name_decoded, 'name' => $name_decoded,
...@@ -173,7 +165,6 @@ class DirectorView extends ControllerBase ...@@ -173,7 +165,6 @@ class DirectorView extends ControllerBase
); );
} }
++$i;
} }
return $this->respondWithStatus( return $this->respondWithStatus(
$list, Response::HTTP_OK); $list, Response::HTTP_OK);
...@@ -251,8 +242,6 @@ class DirectorView extends ControllerBase ...@@ -251,8 +242,6 @@ class DirectorView extends ControllerBase
} }
} }
public function SaveCapacity(Request $request, $taxi, $tomeas, $specialit) public function SaveCapacity(Request $request, $taxi, $tomeas, $specialit)
{ {
if (!$request->isMethod('POST')) { if (!$request->isMethod('POST')) {
...@@ -365,8 +354,6 @@ class DirectorView extends ControllerBase ...@@ -365,8 +354,6 @@ class DirectorView extends ControllerBase
} }
} }
public function getSchools(Request $request) public function getSchools(Request $request)
{ {
$authToken = $request->headers->get('PHP_AUTH_USER'); $authToken = $request->headers->get('PHP_AUTH_USER');
...@@ -402,8 +389,6 @@ class DirectorView extends ControllerBase ...@@ -402,8 +389,6 @@ class DirectorView extends ControllerBase
'name' => $object->name->value, 'name' => $object->name->value,
'status' => $status, 'status' => $status,
); );
++$i;
} }
return $this->respondWithStatus( return $this->respondWithStatus(
...@@ -420,7 +405,6 @@ class DirectorView extends ControllerBase ...@@ -420,7 +405,6 @@ class DirectorView extends ControllerBase
} }
} }
public function getCoursesPerSchool(Request $request, $schoolid) public function getCoursesPerSchool(Request $request, $schoolid)
{ {
$authToken = $request->headers->get('PHP_AUTH_USER'); $authToken = $request->headers->get('PHP_AUTH_USER');
...@@ -446,7 +430,6 @@ class DirectorView extends ControllerBase ...@@ -446,7 +430,6 @@ class DirectorView extends ControllerBase
$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); $SchoolCat = reset($SchoolCats);
if ($SchoolCat) { if ($SchoolCat) {
$list = array(); $list = array();
...@@ -455,8 +438,6 @@ class DirectorView extends ControllerBase ...@@ -455,8 +438,6 @@ class DirectorView extends ControllerBase
} }
$CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid)); $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
if ($CourseA) { 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); $limitdown = reset($limit_down);
...@@ -522,7 +503,7 @@ class DirectorView extends ControllerBase ...@@ -522,7 +503,7 @@ class DirectorView extends ControllerBase
); );
} }
} }
if ($CourseC && $operation_shift != 'ΗΜΕΡΗΣΙΟ' ) { 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); $limitdown = reset($limit_down);
if ($limitdown) { if ($limitdown) {
...@@ -568,8 +549,8 @@ class DirectorView extends ControllerBase ...@@ -568,8 +549,8 @@ class DirectorView extends ControllerBase
if ($SchoolCat) { if ($SchoolCat) {
$categ = $SchoolCat->metathesis_region->value; $categ = $SchoolCat->metathesis_region->value;
} }
$CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $schoolid));
$CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $schoolid));
if ($CourseA) { 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); $limitdown = reset($limit_down);
...@@ -578,12 +559,10 @@ class DirectorView extends ControllerBase ...@@ -578,12 +559,10 @@ class DirectorView extends ControllerBase
} }
$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));
//foreach ($CourseA as $object) {
if (sizeof($studentPerSchool) < $limit) { if (sizeof($studentPerSchool) < $limit) {
return false; return false;
// exit;
} }
} // } }
$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) { if ($CourseB) {
...@@ -598,10 +577,10 @@ class DirectorView extends ControllerBase ...@@ -598,10 +577,10 @@ class DirectorView extends ControllerBase
$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));
if (sizeof($studentPerSchool) < $limit) { if (sizeof($studentPerSchool) < $limit) {
return false; return false;
exit;
} }
} }
} }
$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) { 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));
...@@ -616,7 +595,6 @@ class DirectorView extends ControllerBase ...@@ -616,7 +595,6 @@ class DirectorView extends ControllerBase
if (sizeof($studentPerSchool) < $limit) { if (sizeof($studentPerSchool) < $limit) {
return false; return false;
exit;
} }
} }
} }
...@@ -638,14 +616,10 @@ class DirectorView extends ControllerBase ...@@ -638,14 +616,10 @@ class DirectorView extends ControllerBase
$school = reset($schools); $school = reset($schools);
if (!$school) { if (!$school) {
$this->logger->warning('no access to this school='.$user->id()); $this->logger->warning('no access to this school='.$user->id());
$response = new Response(); return $this->respondWithStatus(['message' => 'No access to this school'], Response::HTTP_FORBIDDEN);
$response->setContent('No access to this school');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
} }
$operation_shift = $school -> operation_shift -> value;
$operation_shift = $school->operation_shift->value;
$userRoles = $user->getRoles(); $userRoles = $user->getRoles();
$userRole = ''; $userRole = '';
foreach ($userRoles as $tmpRole) { foreach ($userRoles as $tmpRole) {
...@@ -654,15 +628,13 @@ class DirectorView extends ControllerBase ...@@ -654,15 +628,13 @@ class DirectorView extends ControllerBase
} }
} }
if ($userRole === '') { if ($userRole === '') {
return $this->respondWithStatus([ return $this->respondWithStatus(['error_code' => 4003], Response::HTTP_FORBIDDEN);
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
} elseif ($userRole === 'epal') { } elseif ($userRole === 'epal') {
$categ = $school->metathesis_region->value; $categ = $school->metathesis_region->value;
$list = array(); $list = array();
$CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid)); $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
$classcapacity = reset($CourseA); $classcapacity = reset($CourseA);
if ($classcapacity) { if ($classcapacity) {
$list[] = array( $list[] = array(
'class' => 1, 'class' => 1,
...@@ -671,10 +643,10 @@ class DirectorView extends ControllerBase ...@@ -671,10 +643,10 @@ class DirectorView extends ControllerBase
'taxi' => 'Ά Λυκείου', 'taxi' => 'Ά Λυκείου',
'capacity' => $classcapacity->capacity_class_a->value, 'capacity' => $classcapacity->capacity_class_a->value,
'globalindex' => $i, 'globalindex' => $i,
); );
} }
++$i; ++$i;
$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) { if ($CourseB) {
foreach ($CourseB as $object) { foreach ($CourseB as $object) {
...@@ -695,6 +667,7 @@ class DirectorView extends ControllerBase ...@@ -695,6 +667,7 @@ class DirectorView extends ControllerBase
++$i; ++$i;
} }
} }
$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) { if ($CourseC) {
foreach ($CourseC as $object) { foreach ($CourseC as $object) {
...@@ -709,7 +682,6 @@ class DirectorView extends ControllerBase ...@@ -709,7 +682,6 @@ class DirectorView extends ControllerBase
'taxi' => 'Γ Λυκείου '.$object->specialty_id->entity->get('name')->value, 'taxi' => 'Γ Λυκείου '.$object->specialty_id->entity->get('name')->value,
'capacity' => $classcapacity->capacity_class_specialty->value, 'capacity' => $classcapacity->capacity_class_specialty->value,
'globalindex' => $i, 'globalindex' => $i,
); );
} }
++$i; ++$i;
...@@ -736,17 +708,13 @@ class DirectorView extends ControllerBase ...@@ -736,17 +708,13 @@ class DirectorView extends ControllerBase
} }
} }
return $this->respondWithStatus( return $this->respondWithStatus($list, Response::HTTP_OK);
$list, Response::HTTP_OK);
} }
} else { } else {
return $this->respondWithStatus([ return $this->respondWithStatus(['message' => t('EPAL user not found')], Response::HTTP_FORBIDDEN);
'message' => t('EPAL user not found'),
], Response::HTTP_FORBIDDEN);
} }
} }
public function FindCoursesPerSchool(Request $request) public function FindCoursesPerSchool(Request $request)
{ {
$i = 0; $i = 0;
...@@ -782,8 +750,8 @@ class DirectorView extends ControllerBase ...@@ -782,8 +750,8 @@ class DirectorView extends ControllerBase
} elseif ($userRole === 'epal') { } elseif ($userRole === 'epal') {