DirectorView.php 55.5 KB
Newer Older
Open Source Developer's avatar
transf  
Open Source Developer committed
1 2 3 4 5 6 7 8 9 10
<?php

namespace Drupal\epal\Controller;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Open Source Developer's avatar
trans  
Open Source Developer committed
11
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
Open Source Developer's avatar
transf  
Open Source Developer committed
12

13 14
use Drupal\epal\Crypt;

Open Source Developer's avatar
transf  
Open Source Developer committed
15 16 17
class DirectorView extends ControllerBase
{
    protected $entityTypeManager;
18
    protected $logger;
Open Source Developer's avatar
trans  
Open Source Developer committed
19
  //  protected $testSchoolId='0640050';
Open Source Developer's avatar
transf  
Open Source Developer committed
20

21 22 23 24
    public function __construct(
        EntityTypeManagerInterface $entityTypeManager,
        LoggerChannelFactoryInterface $loggerChannel
    ) {
25

Open Source Developer's avatar
transf  
Open Source Developer committed
26
        $this->entityTypeManager = $entityTypeManager;
27
        $this->logger = $loggerChannel->get('epal-school');
Open Source Developer's avatar
transf  
Open Source Developer committed
28 29 30 31 32
    }

    public static function create(ContainerInterface $container)
    {
        return new static(
33 34
            $container->get('entity_type.manager'),
            $container->get('logger.factory')
Open Source Developer's avatar
transf  
Open Source Developer committed
35
        );
36
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
37

38
    public function getSectorsPerSchool(Request $request)
Open Source Developer's avatar
transf  
Open Source Developer committed
39 40
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');
41 42

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
43 44 45 46
        $user = reset($users);
        if ($user) {
            $epalId = $user->init->value;
            $schools = $this->entityTypeManager->getStorage('eepal_school')->
Open Source Developer's avatar
Open Source Developer committed
47
                     loadByProperties(array('id' => $epalId));
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
            $school = reset($schools);
            if (!$school) {
                $this->logger->warning('no access to this school='.$user->id());
                $response = new Response();
                $response->setContent('No access to this school');
                $response->setStatusCode(Response::HTTP_FORBIDDEN);
                $response->headers->set('Content-Type', 'application/json');

                return $response;
            }
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
63
                }
64 65 66
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
67 68
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
69 70 71 72 73 74 75 76
            } elseif ($userRole === 'epal') {
                $sectorPerSchool = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $epalId));
                if ($sectorPerSchool) {
                    $list = array();
                    foreach ($sectorPerSchool as $object) {
                        $list[] = array(
                                    'sector_id' => $object->sector_id->entity->get('name')->value,
                                    'id' => $object->sector_id->entity->id(),
Open Source Developer's avatar
Open Source Developer committed
77
                                    );
78
                    }
Open Source Developer's avatar
Open Source Developer committed
79

80 81
                    return $this->respondWithStatus(
                        $list, Response::HTTP_OK);
Open Source Developer's avatar
transf  
Open Source Developer committed
82
                }
83 84 85
            } else {
                return $this->respondWithStatus([
                    'message' => t('School not found!!!'),
86
                ], Response::HTTP_OK);
87
            }
Open Source Developer's avatar
transf  
Open Source Developer committed
88 89
        } else {
            return $this->respondWithStatus([
90
                    'message' => t('User not found!'),
Open Source Developer's avatar
transf  
Open Source Developer committed
91 92 93 94
                ], Response::HTTP_FORBIDDEN);
        }
    }

95
    public function getSpecialPerSchool(Request $request, $sectorId)
Open Source Developer's avatar
trans  
Open Source Developer committed
96 97
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');
98 99

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
100 101 102
        $user = reset($users);
        if ($user) {
            $epalId = $user->init->value;
Open Source Developer's avatar
Open Source Developer committed
103

104 105 106 107 108 109 110 111
            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $epalId));
            $school = reset($schools);
            if (!$school) {
                $this->logger->warning('no access to this school='.$user->id());
                $response = new Response();
                $response->setContent('No access to this school');
                $response->setStatusCode(Response::HTTP_FORBIDDEN);
                $response->headers->set('Content-Type', 'application/json');
Open Source Developer's avatar
Open Source Developer committed
112

113 114
                return $response;
            }
115

116 117 118 119 120
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
121
                }
122 123 124
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
125 126
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
127 128
            } elseif ($userRole === 'epal') {
                $specialityPerSchool = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $epalId));
Open Source Developer's avatar
trans  
Open Source Developer committed
129 130
                $i = 0;

131 132 133 134 135
                if ($specialityPerSchool) {
                    $list = array();
                    $SectorIdNew = intval($sectorId);
                    foreach ($specialityPerSchool as $object) {
                        $idSpecial = $object->specialty_id->entity->id();
136

137 138 139 140 141 142 143
                        $specialityPerSector = $this->entityTypeManager->getStorage('eepal_specialty')->loadByProperties(array('id' => $idSpecial, 'sector_id' => $SectorIdNew));
                        $specialPerSec = reset($specialityPerSector);
                        if ($specialPerSec) {
                            $list[] = array(
                                'specialty_id' => $object->specialty_id->entity->get('name')->value,
                                'id' => $object->specialty_id->entity->id(),     );
                            ++$i;
Open Source Developer's avatar
trans  
Open Source Developer committed
144
                        }
145
                    }
146

147 148
                    return $this->respondWithStatus(
                        $list, Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
149
                }
150 151 152
            } else {
                return $this->respondWithStatus([
                    'message' => t('School not found!!!'),
153
                ], Response::HTTP_OK);
154
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
155 156
        } else {
            return $this->respondWithStatus([
157
                    'message' => t('User not found!'),
Open Source Developer's avatar
trans  
Open Source Developer committed
158 159 160 161
                ], Response::HTTP_FORBIDDEN);
        }
    }

162
    public function getStudentPerSchool(Request $request, $selectId, $classId, $limitdown, $limitup)
Open Source Developer's avatar
trans  
Open Source Developer committed
163
    {
164
        try {
165 166
            $authToken = $request->headers->get('PHP_AUTH_USER');

167 168 169 170 171 172 173 174 175 176 177 178 179
            $epalConfigs = $this->entityTypeManager->getStorage('epal_config')->loadByProperties(array('name' => 'epal_config'));
            $epalConfig = reset($epalConfigs);
            if (!$epalConfig) {
                return $this->respondWithStatus([
                        "error_code" => 3001
                    ], Response::HTTP_FORBIDDEN);
            }
            if ($epalConfig->lock_students->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }

180 181 182 183 184 185 186 187 188 189 190
            $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
            $user = reset($users);
            if ($user) {
                $epalId = $user->init->value;
                $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $epalId));
                $school = reset($schools);
                if (!$school) {
                    $this->logger->warning('no access to this school='.$user->id());
                    return $this->respondWithStatus([
                        "message" => "No access to this school"
                    ], Response::HTTP_FORBIDDEN);
Open Source Developer's avatar
Open Source Developer committed
191
                }
192

193 194 195 196 197 198
                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal') {
                        $userRole = $tmpRole;
                    }
199
                }
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
                if ($userRole === '') {
                    return $this->respondWithStatus([
                        'error_code' => 4003,
                    ], Response::HTTP_FORBIDDEN);
                } elseif ($userRole === 'epal') {
                    if ($classId == 1) {
                        $selectId = -1;
                    }
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectId, 'currentclass' => $classId));

                    if ($studentPerSchool) {
                        $list = array();
                        if ($limitdown == $limitup && $limitup == 0) {
                            $list = array(
                                'id' => sizeof($studentPerSchool),
                                'up' => $limitup,
                                'down' => $limitdown,
                            );
                        } else {
                            $i = 0;
                            foreach ($studentPerSchool as $object) {
                                $studentId = $object->id();
                                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $studentId));
                                $epalStudent = reset($epalStudents);

                                if ($epalStudent) {
                                    $studentIdNew = $epalStudent->id();
                                    $checkstatus = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $studentIdNew));
                                    $checkstudentstatus = reset($checkstatus);
                                    if ($i >= $limitdown && $i < $limitup) {
                                        $sectorName = '';
                                        $courseName = '';
                                        if ($epalStudent->currentclass->value === '2') {
                                            $sectors = $this->entityTypeManager->getStorage('epal_student_sector_field')->loadByProperties(array('student_id' => $studentIdNew));
                                            $sector = reset($sectors);
                                            if ($sector) {
                                                $sectorName = $this->entityTypeManager->getStorage('eepal_sectors')->load($sector->sectorfield_id->target_id)->name->value;
                                            }
                                        } elseif ($epalStudent->currentclass->value === '3' || $epalStudent->currentclass->value === '4') {
                                            $courses = $this->entityTypeManager->getStorage('epal_student_course_field')->loadByProperties(array('student_id' => $studentIdNew));
                                            $course = reset($courses);
                                            if ($course) {
                                                $courseName = $this->entityTypeManager->getStorage('eepal_specialty')->load($course->coursefield_id->target_id)->name->value;
                                            }
                                        }
                                        $newstatus = $checkstudentstatus->directorconfirm->value;

                                        $crypt = new Crypt();
                                        try {
                                            $name_decoded = $crypt->decrypt($epalStudent->name->value);
                                            $studentsurname_decoded = $crypt->decrypt($epalStudent->studentsurname->value);
                                            $fatherfirstname_decoded = $crypt->decrypt($epalStudent->fatherfirstname->value);
                                            $motherfirstname_decoded = $crypt->decrypt($epalStudent->motherfirstname->value);
                                            $regionaddress_decoded = $crypt->decrypt($epalStudent->regionaddress->value);
                                            $regiontk_decoded = $crypt->decrypt($epalStudent->regiontk->value);
                                            $regionarea_decoded = $crypt->decrypt($epalStudent->regionarea->value);
                                            $certificatetype_decoded = $crypt->decrypt($epalStudent->certificatetype->value);
                                            $relationtostudent_decoded = $crypt->decrypt($epalStudent->relationtostudent->value);
                                            $telnum_decoded = $crypt->decrypt($epalStudent->telnum->value);
                                            $guardian_name_decoded = $crypt->decrypt($epalStudent->guardian_name->value);
                                            $guardian_surname_decoded = $crypt->decrypt($epalStudent->guardian_surname->value);
                                            $guardian_fathername_decoded = $crypt->decrypt($epalStudent->guardian_fathername->value);
                                            $guardian_mothername_decoded = $crypt->decrypt($epalStudent->guardian_mothername->value);
                                            // $name_decoded = $epalStudent->name->value;
                                            // $studentsurname_decoded = $epalStudent->studentsurname->value;
                                            // $fatherfirstname_decoded = $epalStudent->fatherfirstname->value;
                                            // $motherfirstname_decoded = $epalStudent->motherfirstname->value;
                                            // $regionaddress_decoded = $epalStudent->regionaddress->value;
                                            // $regiontk_decoded = $epalStudent->regiontk->value;
                                            // $regionarea_decoded = $epalStudent->regionarea->value;
                                            // $certificatetype_decoded = $epalStudent->certificatetype->value;
                                            // $relationtostudent_decoded = $epalStudent->relationtostudent->value;
                                            // $telnum_decoded = $epalStudent->telnum->value;
                                            // $guardian_name_decoded = $epalStudent->guardian_name->value;
                                            // $guardian_surname_decoded = $epalStudent->guardian_surname->value;
                                            // $guardian_fathername_decoded = $epalStudent->guardian_fathername->value;
                                            // $guardian_mothername_decoded = $epalStudent->guardian_mothername->value;
                                        } catch (\Exception $e) {
                                            $this->logger->warning(__METHOD__ . ' Decrypt error: ' . $e->getMessage());
                                            return $this->respondWithStatus([
                                                "message" => t("An unexpected error occured during DECODING data in getStudentPerSchool Method ")
                                            ], Response::HTTP_INTERNAL_SERVER_ERROR);
                                        }

                                        $list[] = array(
                                            'i' => $i,
                                            'id' => $epalStudent->id(),
                                            'name' => $name_decoded,
                                            'studentsurname' => $studentsurname_decoded,
                                            'fatherfirstname' => $fatherfirstname_decoded,
                                            'fathersurname' => $epalStudent->fathersurname->value,
                                            'motherfirstname' => $motherfirstname_decoded,
                                            'mothersurname' => $epalStudent->mothersurname->value,
                                            'guardian_name' => $guardian_name_decoded,
                                            'guardian_surname' => $guardian_surname_decoded,
                                            'guardian_fathername' => $guardian_fathername_decoded,
                                            'guardian_mothername' => $guardian_mothername_decoded,
                                            'lastschool_schoolname' => $epalStudent->lastschool_schoolname->value,
                                            'lastschool_schoolyear' => $epalStudent->lastschool_schoolyear->value,
                                            'lastschool_class' => $epalStudent->currentclass->value,
                                            'currentclass' => $epalStudent->currentclass->value,
                                            'currentsector' => $sectorName,
                                            'currentcourse' => $courseName,
                                            'regionaddress' => $regionaddress_decoded,
                                            'regiontk' => $regiontk_decoded,
                                            'regionarea' => $regionarea_decoded,
                                            'certificatetype' => $certificatetype_decoded,
                                            'graduation_year' => $epalStudent->graduation_year->value,
                                            'telnum' => $telnum_decoded,
                                            'relationtostudent' => $relationtostudent_decoded,
                                            //'birthdate' => substr($epalStudent->birthdate->value, 8, 10) . '/' . substr($epalStudent->birthdate->value, 6, 8) . '/' . substr($epalStudent->birthdate->value, 0, 4),
                                            'birthdate' => date("d-m-Y", strtotime($epalStudent->birthdate->value)),
                                            'checkstatus' => $newstatus[0][value],
                                            'created' => date('d/m/Y H:i', $epalStudent->created->value)
                                        );
315
                                    }
316
                                    ++$i;
Open Source Developer's avatar
paging  
Open Source Developer committed
317 318 319
                                }
                            }
                        }
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344

                        return $this->respondWithStatus(
                            $list, Response::HTTP_OK);
                    } else {
                        if ($limitdown == $limitup && $limitup == 0) {
                            $list = [
                                'id' => sizeof($studentPerSchool),
                                'up' => $limitup,
                                'down' => $limitdown,
                            ];
                        } else {
                            $list = [];
                        }

                        return $this->respondWithStatus($list, Response::HTTP_OK);
                    }
                } else {
                    if ($limitdown == $limitup && $limitup == 0) {
                        $list = [
                            'id' => sizeof($studentPerSchool),
                            'up' => $limitup,
                            'down' => $limitdown,
                        ];
                    } else {
                        $list = [];
Open Source Developer's avatar
Open Source Developer committed
345
                    }
346

347
                    return $this->respondWithStatus($list, Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
348
                }
349
            } else {
350
                return $this->respondWithStatus([
351
                    'message' => t('User not found!'),
Open Source Developer's avatar
trans  
Open Source Developer committed
352
                ], Response::HTTP_FORBIDDEN);
353 354 355 356
            }
        } catch (\Exception $e) {
            $this->logger->warning($e->getMessage());
            return $this->respondWithStatus([
357 358
                'message' => t('Unexpected Error'),
            ], Response::HTTP_FORBIDDEN);
359
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
360
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
361

Open Source Developer's avatar
trans  
Open Source Developer committed
362 363 364
    public function ConfirmStudents(Request $request)
    {
        if (!$request->isMethod('POST')) {
365
            return $this->respondWithStatus([
366
                    'message' => t('Method Not Allowed'),
Open Source Developer's avatar
trans  
Open Source Developer committed
367 368 369 370
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

371
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
372 373 374 375 376 377 378
        $user = reset($users);
        if ($user) {
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
379
                }
380 381 382
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
383 384
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
            } elseif ($userRole === 'epal') {
                $postData = null;

                if ($content = $request->getContent()) {
                    $postData = json_decode($content);
                    $arr = $postData->students;
                    $type = $postData->type;

                    foreach ($arr as $value) {
                        $valnew = intval($value);
                        $studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('id' => $valnew));
                        $studentConfirm = reset($studentForConfirm);
                        if ($studentConfirm) {
                            if ($type == 1) {
                                $studentConfirm->set('directorconfirm', true);
                            }
                            if ($type == 2) {
                                $studentConfirm->set('directorconfirm', false);
                            }
                            if ($type == 3) {
                                unset($studentConfirm->{directorconfirm});
                            }
                            $studentConfirm->save();
                        }
409
                    }
410 411 412

                    return $this->respondWithStatus([
                    'message' => t('saved'),
413
                    ], Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
414 415
                }
            } else {
416 417 418 419 420
                return $this->respondWithStatus([
                    'message' => t('post with no data'),
                ], Response::HTTP_BAD_REQUEST);
            }
        } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
421
            return $this->respondWithStatus([
422
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
trans  
Open Source Developer committed
423 424 425 426
                ], Response::HTTP_FORBIDDEN);
        }
    }

427
    public function SaveCapacity(Request $request, $taxi, $tomeas, $specialit)
Open Source Developer's avatar
Open Source Developer committed
428 429
    {
        if (!$request->isMethod('POST')) {
430
            return $this->respondWithStatus([
431
                    'message' => t('Method Not Allowed'),
Open Source Developer's avatar
Open Source Developer committed
432 433 434 435
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

436 437 438 439 440 441 442 443 444 445 446 447 448
        $epalConfigs = $this->entityTypeManager->getStorage('epal_config')->loadByProperties(array('name' => 'epal_config'));
        $epalConfig = reset($epalConfigs);
        if (!$epalConfig) {
            return $this->respondWithStatus([
                    "error_code" => 3001
                ], Response::HTTP_FORBIDDEN);
        }
        if ($epalConfig->lock_capacity->value) {
            return $this->respondWithStatus([
                    "error_code" => 3002
                ], Response::HTTP_FORBIDDEN);
        }

449
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
        $user = reset($users);
        if ($user) {
            $schoolid = $user->init->value;
            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
            $school = reset($schools);
            if (!$school) {
                $this->logger->warning('no access to this school='.$user->id());
                $response = new Response();
                $response->setContent('No access to this school');
                $response->setStatusCode(Response::HTTP_FORBIDDEN);
                $response->headers->set('Content-Type', 'application/json');

                return $response;
            }
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
469
                }
470 471 472
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
473 474
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
475 476
            } elseif ($userRole === 'epal') {
                $postData = null;
Open Source Developer's avatar
Open Source Developer committed
477

478 479 480 481 482 483
                if ($content = $request->getContent()) {
                    $postData = json_decode($content);
                    $cap = $postData->capacity;
                    if ($cap <= 0 || $cap > 99) {
                        return $this->respondWithStatus([
                            'message' => t('Number out of limits!'),
Open Source Developer's avatar
Open Source Developer committed
484
                        ], Response::HTTP_BAD_REQUEST);
485
                    }
Open Source Developer's avatar
Open Source Developer committed
486

487 488 489 490 491 492
                    if (($tomeas == 0) && ($specialit == 0)) {
                        $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
                        $classcapacity = reset($CapacityPerClass);
                        if ($classcapacity) {
                            $classcapacity->set('capacity_class_a', $cap);
                            $classcapacity->save();
Open Source Developer's avatar
Open Source Developer committed
493
                        }
494
                    }
Open Source Developer's avatar
Open Source Developer committed
495

496 497 498 499 500 501
                    if (($tomeas != 0) && ($specialit == 0)) {
                        $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'sector_id' => $tomeas));
                        $classcapacity = reset($CapacityPerClass);
                        if ($classcapacity) {
                            $classcapacity->set('capacity_class_sector', $cap);
                            $classcapacity->save();
Open Source Developer's avatar
Open Source Developer committed
502
                        }
503
                    }
Open Source Developer's avatar
Open Source Developer committed
504

505 506 507 508 509 510
                    if (($specialit != 0) && ($taxi == 3)) {
                        $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialit));
                        $classcapacity = reset($CapacityPerClass);
                        if ($classcapacity) {
                            $classcapacity->set('capacity_class_specialty', $cap);
                            $classcapacity->save();
Open Source Developer's avatar
Open Source Developer committed
511
                        }
512
                    }
Open Source Developer's avatar
Open Source Developer committed
513

514 515 516 517 518 519 520 521
                    if (($specialit != 0) && ($taxi == 4)) {
                        $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialit));
                        $classcapacity = reset($CapacityPerClass);
                        if ($classcapacity) {
                            $classcapacity->set('capacity_class_specialty_d', $cap);
                            $classcapacity->save();
                        }
                    }
Open Source Developer's avatar
Open Source Developer committed
522

523 524
                    return $this->respondWithStatus([
                            'message' => t('saved'),
Open Source Developer's avatar
Open Source Developer committed
525
                        ], Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
526 527
                }
            } else {
528 529 530 531 532
                return $this->respondWithStatus([
                    'message' => t('post with no data'),
                ], Response::HTTP_BAD_REQUEST);
            }
        } else {
Open Source Developer's avatar
Open Source Developer committed
533
            return $this->respondWithStatus([
534
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
Open Source Developer committed
535 536 537 538
                ], Response::HTTP_FORBIDDEN);
        }
    }

539
    public function getSchools(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
540 541 542 543 544
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
545 546 547 548 549 550 551
        if ($user) {
            $selectionId = $user->init->value;
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if (($tmpRole === 'epal') || ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
                    $userRole = $tmpRole;
552
                }
553 554 555
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
556 557
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
558 559 560 561 562 563 564
            } elseif ($userRole === 'regioneduadmin') {
                $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));
            }
            if ($schools) {
                $list = array();
Open Source Developer's avatar
Open Source Developer committed
565

566 567 568 569 570 571
                foreach ($schools as $object) {
                    $status = $this->returnstatus($object->id());
                    $list[] = array(
                                    'id' => $object->id(),
                                    'name' => $object->name->value,
                                    'status' => $status,
Open Source Developer's avatar
trans  
Open Source Developer committed
572 573
                                    );

574
                    ++$i;
Open Source Developer's avatar
trans  
Open Source Developer committed
575 576
                }

577 578 579 580 581
                return $this->respondWithStatus(
                                     $list, Response::HTTP_OK);
            } else {
                return $this->respondWithStatus([
                            'message' => t('Perfecture not found!'),
Open Source Developer's avatar
trans  
Open Source Developer committed
582 583
                        ], Response::HTTP_FORBIDDEN);
            }
584 585 586 587 588
        } else {
            return $this->respondWithStatus([
                            'message' => t('User not found!'),
                        ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
589 590
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
591 592
    public function getCoursesPerSchool(Request $request, $schoolid)
    {
593
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
594 595 596

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
597 598 599 600 601 602 603
        if ($user) {
            $newid = $user->init->value;
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if (($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
604
                }
605 606 607
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
608 609
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
610 611 612 613 614
            } elseif ($userRole === 'regioneduadmin') {
                $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));
            }
Open Source Developer's avatar
Open Source Developer committed
615

616 617 618 619 620 621
            $SchoolCat = reset($SchoolCats);
            if ($SchoolCat) {
                $list = array();
                $categ = $SchoolCat->metathesis_region->value;
            }
            $CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $schoolid));
Open Source Developer's avatar
trans  
Open Source Developer committed
622

623 624 625 626 627
            if ($CourseA) {
                $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;
Open Source Developer's avatar
trans  
Open Source Developer committed
628
                }
629 630 631 632
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1));
                $list = array();
                foreach ($CourseA as $object) {
                    $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
633
                                    'id' => '1',
Open Source Developer's avatar
trans  
Open Source Developer committed
634
                                    'name' => 'Α Λυκείου',
Open Source Developer's avatar
trans  
Open Source Developer committed
635 636
                                    'size' => sizeof($studentPerSchool),
                                    'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
637 638
                                    'classes' => 1,
                                    'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
639
                                    );
640 641
                }
            }
642

643 644 645 646 647 648 649
            $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));
                $limitdown = reset($limit_down);
                if ($limitdown) {
                    $limit = $limitdown->limit_down->value;
                }
Open Source Developer's avatar
Open Source Developer committed
650

651 652 653 654 655 656
                foreach ($CourseB as $object) {
                    $sectorid = $object->sector_id->entity->id();
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
                    $list[] = array(
                            'id' => $object->sector_id->entity->id(),
                            'name' => 'Β Λυκείου  '.$object->sector_id->entity->get('name')->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
657 658
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
659 660
                            'classes' => 2,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
661 662 663

                          );
                }
664 665 666 667 668 669 670 671
            }
            $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));
                $limitdown = reset($limit_down);
                if ($limitdown) {
                    $limit = $limitdown->limit_down->value;
                }
Open Source Developer's avatar
Open Source Developer committed
672

673 674 675
                foreach ($CourseC as $object) {
                    $specialityid = $object->specialty_id->entity->id();
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3));
Open Source Developer's avatar
trans  
Open Source Developer committed
676

677 678 679
                    $list[] = array(
                            'id' => $object->specialty_id->entity->id(),
                            'name' => 'Γ Λυκείου  '.$object->specialty_id->entity->get('name')->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
680 681
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
682 683
                            'classes' => 3,
                            'limitdown' => $limit,
684

Open Source Developer's avatar
trans  
Open Source Developer committed
685 686
                          );
                }
687
            }
688 689 690 691 692 693
            if ($CourseA || $CourseB || $CourseC) {
                return $this->respondWithStatus(
                                     $list, Response::HTTP_OK);
            } else {
                return $this->respondWithStatus([
                            'message' => t('Perfecture not found!'),
Open Source Developer's avatar
trans  
Open Source Developer committed
694 695
                        ], Response::HTTP_FORBIDDEN);
            }
696 697 698 699 700
        } else {
            return $this->respondWithStatus([
                            'message' => t('User not found!'),
                        ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
701
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
702

703 704 705 706 707 708 709 710 711
    public function returnstatus($id)
    {
        $schoolid = $id;
        $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
        $SchoolCat = reset($SchoolCats);
        if ($SchoolCat) {
            $categ = $SchoolCat->metathesis_region->value;
        }
        $CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $schoolid));
Open Source Developer's avatar
trans  
Open Source Developer committed
712

713 714 715 716 717 718 719
        if ($CourseA) {
            $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;
            }
            $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1));
720

Open Source Developer's avatar
Open Source Developer committed
721
                    //foreach ($CourseA as $object) {
722 723
            if (sizeof($studentPerSchool) < $limit) {
                return false;
724
//                                exit;
725
            }
726 727 728 729 730 731 732 733 734
        }          //  }

                $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));
            $limitdown = reset($limit_down);
            if ($limitdown) {
                $limit = $limitdown->limit_down->value;
            }
735

736 737 738 739 740 741
            foreach ($CourseB as $object) {
                $sectorid = $object->sector_id->entity->id();
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
                if (sizeof($studentPerSchool) < $limit) {
                    return false;
                    exit;
Open Source Developer's avatar
Open Source Developer committed
742
                }
743 744 745 746 747 748 749 750 751
            }
        }
        $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));
            $limitdown = reset($limit_down);
            if ($limitdown) {
                $limit = $limitdown->limit_down->value;
            }
Open Source Developer's avatar
Open Source Developer committed
752

753 754 755
            foreach ($CourseC as $object) {
                $specialityid = $object->specialty_id->entity->id();
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3));
Open Source Developer's avatar
Open Source Developer committed
756

757 758 759
                if (sizeof($studentPerSchool) < $limit) {
                    return false;
                    exit;
Open Source Developer's avatar
Open Source Developer committed
760
                }
761 762
            }
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
763

764 765 766
        return true;
//                exit;
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
767

768
    public function findCapacity(Request $request, $taxi, $tomeas, $specialit)
Open Source Developer's avatar
trans  
Open Source Developer committed
769
    {
770 771 772
        $tomeasnew = intval($tomeas);
        $specialitnew = intval($specialit);
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
773 774

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
        $user = reset($users);
        if ($user) {
            $schoolid = $user->init->value;
            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
            $school = reset($schools);
            if (!$school) {
                $this->logger->warning('no access to this school='.$user->id());
                $response = new Response();
                $response->setContent('No access to this school');
                $response->setStatusCode(Response::HTTP_FORBIDDEN);
                $response->headers->set('Content-Type', 'application/json');

                return $response;
            }
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
trans  
Open Source Developer committed
794
                }
795 796 797
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
798 799
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
800 801
            } elseif ($userRole === 'epal') {
                $list = array();
Open Source Developer's avatar
trans  
Open Source Developer committed
802

803 804 805
                if (($tomeasnew == 0) && ($specialitnew == 0)) {
                    $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
                    $classcapacity = reset($CapacityPerClass);
Open Source Developer's avatar
trans  
Open Source Developer committed
806

807 808
                    if ($classcapacity) {
                        $list[] = array(
Open Source Developer's avatar
Open Source Developer committed
809
                                'taxi' => $taxi,
810
                               'capacity' => $classcapacity->capacity_class_a->value,
Open Source Developer's avatar
Open Source Developer committed
811
                               );
812 813
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
814

815 816 817 818 819
                if (($tomeasnew != 0) && ($specialitnew == 0)) {
                    $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'sector_id' => $tomeasnew));
                    $classcapacity = reset($CapacityPerClass);
                    if ($classcapacity) {
                        $list[] = array(
Open Source Developer's avatar
Open Source Developer committed
820 821
                                'taxi' => $taxi,
                                'tomeas' => $tomeasnew,
822 823 824
                                'special' => $specialitnew,
                                'capacity' => $classcapacity->capacity_class_sector->value,
                                'sector' => $tomeasnew.'lala'.$specialitnew,
Open Source Developer's avatar
Open Source Developer committed
825
                                );
826 827
                    }
                }
828

829 830 831 832 833 834
                if (($tomeasnew != 0) && ($specialitnew != 0) && ($taxi == 3)) {
                    $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialitnew));
                    $classcapacity = reset($CapacityPerClass);
                    if ($classcapacity) {
                        $list[] = array(
                                'taxi' => $taxi,
Open Source Developer's avatar
Open Source Developer committed
835
                                'tomeas' => $tomeasnew,
836 837 838 839
                                'special' => $specialitnew,
                                'tomeas' => $classcapacity->specialty_id->value,
                                'capacity' => $classcapacity->capacity_class_specialty->value,
                                'specialty' => 'fromspeciality',
Open Source Developer's avatar
Open Source Developer committed
840
                                );
841 842
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
843

844 845 846 847 848 849
                if (($tomeasnew != 0) && ($specialitnew != 0) && ($taxi == 4)) {
                    $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialitnew));
                    $classcapacity = reset($CapacityPerClass);
                    if ($classcapacity) {
                        $list[] = array(
                                'taxi' => $taxi,
Open Source Developer's avatar
Open Source Developer committed
850
                                'tomeas' => $tomeasnew,
851 852 853 854
                                'special' => $specialitnew,
                                'tomeas' => $classcapacity->specialty_id->value,
                                'capacity' => $classcapacity->capacity_class_specialty_d->value,
                                'specialty' => 'fromspecialityd',
Open Source Developer's avatar
Open Source Developer committed
855
                                );
856 857
                    }
                }
Open Source Developer's avatar
Open Source Developer committed
858

859 860
                return $this->respondWithStatus(
                                             $list, Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
861
            }
862
        } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
863
            return $this->respondWithStatus([
864
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
trans  
Open Source Developer committed
865 866 867 868
                ], Response::HTTP_FORBIDDEN);
        }
    }

869
    public function getSchoolID(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
870 871 872 873
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
874 875 876 877 878 879
        $user = reset($users);
        if ($user) {
            $schid = intval($user->init->value);
            $list = array();
            $list[] = array(
                             'id' => $schid,
Open Source Developer's avatar
trans  
Open Source Developer committed
880 881
                        );

882 883 884
            return $this->respondWithStatus(
                        $list, Response::HTTP_OK);
        } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
885
            return $this->respondWithStatus([
886
                    'message' => t('User not found!'),
Open Source Developer's avatar
trans  
Open Source Developer committed
887 888 889 890
                ], Response::HTTP_FORBIDDEN);
        }
    }

891
    public function gettypeofschool(Request $request)
Open Source Developer's avatar
Open Source Developer committed
892 893
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
894

Open Source Developer's avatar
Open Source Developer committed
895
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
896 897 898 899
        $user = reset($users);
        if ($user) {
            $schid = intval($user->init->value);
            $schools = $this->entityTypeManager->getStorage('eepal_school')->
Open Source Developer's avatar
Open Source Developer committed
900
                 loadByProperties(array('id' => $schid));
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
            $school = reset($schools);
            if (!$school) {
                $this->logger->warning('no access to this school='.$user->id());
                $response = new Response();
                $response->setContent('No access to this school');
                $response->setStatusCode(Response::HTTP_FORBIDDEN);
                $response->headers->set('Content-Type', 'application/json');

                return $response;
            }
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
916
                }
917 918 919
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
920 921
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
922 923 924 925
            } elseif ($userRole === 'epal') {
                $list = array();
                $list[] = array(
                            'type' => $school->operation_shift->value,
Open Source Developer's avatar
Open Source Developer committed
926
                            );
Open Source Developer's avatar
trans  
Open Source Developer committed
927

928 929 930 931
                return $this->respondWithStatus(
                            $list, Response::HTTP_OK);
            }
        } else {
Open Source Developer's avatar
Open Source Developer committed
932
            return $this->respondWithStatus([
933
                    'message' => t('User not found!'),
Open Source Developer's avatar
Open Source Developer committed
934 935 936
                ], Response::HTTP_FORBIDDEN);
        }
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
937

938 939
    public function getlimitsperCourse(Request $request, $classid)
    {
940
        $authToken = $request->headers->get('PHP_AUTH_USER');
941 942 943

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
944 945 946 947 948 949 950
        if ($user) {
            $schoolid = $user->init->value;

            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
            $school = reset($schools);
            if (!$school) {
                $this->logger->warning('no access to this school='.$user->id());
951 952 953
                return $this->respondWithStatus([
                    'message' => "No access to this school"
                ], Response::HTTP_FORBIDDEN);
954 955 956 957 958 959
            }
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
960
                }
961 962 963
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
964 965
                    'error_code' => 4003,
                ], Response::HTTP_FORBIDDEN);
966 967
            } elseif ($userRole === 'epal') {
                $list = array();
Open Source Developer's avatar
Open Source Developer committed
968