DirectorView.php 44 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 39


Open Source Developer's avatar
Open Source Developer committed
40
    public function getStudentPerSchool(Request $request, $classId, $sector, $specialit)
Open Source Developer's avatar
trans  
Open Source Developer committed
41
    {
42
        try {
43
            $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
Open Source Developer committed
44

45 46 47 48 49 50 51 52 53 54 55
            $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);
Open Source Developer's avatar
Open Source Developer committed
56 57
            }

58 59 60 61 62 63 64 65 66 67 68
            $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
69
                }
70

Open Source Developer's avatar
Open Source Developer committed
71

72 73 74 75 76 77
                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal') {
                        $userRole = $tmpRole;
                    }
78
                }
79 80
                if ($userRole === '') {
                    return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
81 82
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
83
                } elseif ($userRole === 'epal') {
Open Source Developer's avatar
Open Source Developer committed
84
                    $selectIdNew = $selectId;
85
                    if ($classId == 1) {
Open Source Developer's avatar
Open Source Developer committed
86
                        $selectIdNew = -1;
87
                    } elseif ($classId == 2) {
Open Source Developer's avatar
Open Source Developer committed
88
                        $selectIdNew = $sector;
89
                    } else {
Open Source Developer's avatar
Open Source Developer committed
90
                        $selectIdNew = $specialit;
91
                    }
Open Source Developer's avatar
bug  
Open Source Developer committed
92
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId));
93 94 95 96 97
                }
                $i = 0;
                if ($studentPerSchool) {
                    $list = array();
                    foreach ($studentPerSchool as $object) {
Open Source Developer's avatar
bug  
Open Source Developer committed
98
                            $studentId = intval($object->student_id ->getString());
Open Source Developer's avatar
Open Source Developer committed
99 100
                            $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id' => $studentId));
                            $epalStudent = reset($epalStudents);
101 102 103 104 105 106 107 108 109 110 111
                        if ($epalStudents) {
                            $studentIdNew = $epalStudent->id();
                            $checkstatus = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $studentIdNew));
                            $checkstudentstatus = reset($checkstatus);
                            $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;
Open Source Developer's avatar
Open Source Developer committed
112
                                }
113 114 115 116 117
                            } 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;
Open Source Developer's avatar
Open Source Developer committed
118
                                }
119 120 121 122 123 124 125 126 127 128 129 130
                            }


                                $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);
131
                                // $certificatetype_decoded = $crypt->decrypt($epalStudent->certificatetype->value); // obsolete
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
                                $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);
                            } 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(
                                'id' => $epalStudent->id(),
                                'name' => $name_decoded,
                                'studentsurname' => $studentsurname_decoded,
                                'fatherfirstname' => $fatherfirstname_decoded,
                                'motherfirstname' => $motherfirstname_decoded,
                                '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->lastschool_class->value,
                                'currentclass' =>$epalStudent -> currentclass ->value,
                                'currentsector' =>$sectorName,
                                'currentcourse' =>$courseName,
                                'regionaddress' => $regionaddress_decoded,
                                'regiontk' => $regiontk_decoded,
                                'regionarea' => $regionarea_decoded,
165
                                'certificatetype' => '', // $certificatetype_decoded, // obsolete
166 167 168 169 170 171 172 173 174 175
                                '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' => $checkstudentstatus -> directorconfirm ->value,
                                'created' => date('d/m/Y H:i', $epalStudent -> created ->value),

                            );
                        }
Open Source Developer's avatar
Open Source Developer committed
176
                                ++$i;
177 178
                    }
                    return $this->respondWithStatus(
Open Source Developer's avatar
Open Source Developer committed
179
                     $list, Response::HTTP_OK);
180 181
                } else {
                       return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
182
                    'message' => t('Students not found!'),
183 184 185 186 187
                        ], Response::HTTP_FORBIDDEN);
                }
            } else {
                return $this->respondWithStatus([
                'message' => t('User not found!'),
Open Source Developer's avatar
trans  
Open Source Developer committed
188
                ], Response::HTTP_FORBIDDEN);
189
            }
190 191
        } catch (\Exception $e) {
            $this->logger->warning($e->getMessage());
192
            return $this->respondWithStatus([
193
            'message' => t('Unexpected Error'),
194
            ], Response::HTTP_FORBIDDEN);
195
        }
Open Source Developer's avatar
Open Source Developer committed
196
    }
Open Source Developer's avatar
changes  
Open Source Developer committed
197

Open Source Developer's avatar
trans  
Open Source Developer committed
198 199 200
    public function ConfirmStudents(Request $request)
    {
        if (!$request->isMethod('POST')) {
201
            return $this->respondWithStatus(['message' => t('Method Not Allowed')], Response::HTTP_METHOD_NOT_ALLOWED);
Open Source Developer's avatar
trans  
Open Source Developer committed
202 203
        }

204
        $authToken = $request->headers->get('PHP_AUTH_USER');
205
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
206 207 208 209 210 211 212
        $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
213
                }
214
            }
215
            if ($userRole === 'epal') {
216 217 218 219
                if ($content = $request->getContent()) {
                    $postData = json_decode($content);
                    $arr = $postData->students;
                    $type = $postData->type;
Open Source Developer's avatar
Open Source Developer committed
220 221
                    $valnew = intval($arr);
                    $typen = intval($type);
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
                    $studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(['student_id' => $valnew]);
                    $studentConfirm = reset($studentForConfirm);
                    if ($studentConfirm) {
                        if ($typen === 1) {
                            $studentConfirm->set('directorconfirm', 1);
                            $studentConfirm->save();
                            return $this->respondWithStatus(['message' => t('saved')], Response::HTTP_OK);
                        } elseif ($typen === 2) {
                            $studentConfirm->set('directorconfirm', 0);
                            $studentConfirm->save();
                            return $this->respondWithStatus(['message' => t('saved')], Response::HTTP_OK);
                        } elseif ($typen === 3) {
                            unset($studentConfirm->{directorconfirm});
                            $studentConfirm->save();
                            return $this->respondWithStatus(['message' => t('saved')], Response::HTTP_OK);
                        } else {
                            return $this->respondWithStatus(['message' => t('Bad request')], Response::HTTP_FORBIDDEN);
Open Source Developer's avatar
Open Source Developer committed
239
                        }
240 241 242 243 244
                    } else {
                        return $this->respondWithStatus(['message' => t('Student not found')], Response::HTTP_FORBIDDEN);
                    }
                } else {
                    return $this->respondWithStatus(['message' => t('post with no data')], Response::HTTP_BAD_REQUEST);
Open Source Developer's avatar
trans  
Open Source Developer committed
245 246
                }
            } else {
247
                return $this->respondWithStatus(['error_code' => 4003], Response::HTTP_FORBIDDEN);
248 249
            }
        } else {
250
            return $this->respondWithStatus(['message' => t('EPAL user not found')], Response::HTTP_FORBIDDEN);
Open Source Developer's avatar
trans  
Open Source Developer committed
251 252 253
        }
    }

Open Source Developer's avatar
changes  
Open Source Developer committed
254 255


256
    public function SaveCapacity(Request $request, $taxi, $tomeas, $specialit)
Open Source Developer's avatar
Open Source Developer committed
257 258
    {
        if (!$request->isMethod('POST')) {
259
            return $this->respondWithStatus([
260
                    'message' => t('Method Not Allowed'),
Open Source Developer's avatar
Open Source Developer committed
261 262 263 264
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

265 266 267 268 269 270 271 272 273 274 275 276 277
        $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);
        }

278
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
        $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
298
                }
299 300 301
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
302 303
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
304 305
            } elseif ($userRole === 'epal') {
                $postData = null;
Open Source Developer's avatar
Open Source Developer committed
306

307 308 309 310 311 312
                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
313
                        ], Response::HTTP_BAD_REQUEST);
314
                    }
Open Source Developer's avatar
Open Source Developer committed
315

316 317 318 319 320 321
                    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
322
                        }
323
                    }
Open Source Developer's avatar
Open Source Developer committed
324

325 326 327 328 329 330
                    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
331
                        }
332
                    }
Open Source Developer's avatar
Open Source Developer committed
333

334 335 336 337 338 339
                    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
340
                        }
341
                    }
Open Source Developer's avatar
Open Source Developer committed
342

343 344 345 346 347 348 349 350
                    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
351

352 353
                    return $this->respondWithStatus([
                            'message' => t('saved'),
Open Source Developer's avatar
Open Source Developer committed
354
                        ], Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
355 356
                }
            } else {
357 358 359 360 361
                return $this->respondWithStatus([
                    'message' => t('post with no data'),
                ], Response::HTTP_BAD_REQUEST);
            }
        } else {
Open Source Developer's avatar
Open Source Developer committed
362
            return $this->respondWithStatus([
363
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
Open Source Developer committed
364 365 366 367
                ], Response::HTTP_FORBIDDEN);
        }
    }

Open Source Developer's avatar
changes  
Open Source Developer committed
368 369


370
    public function getSchools(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
371 372 373 374 375
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
376 377 378 379 380 381 382
        if ($user) {
            $selectionId = $user->init->value;
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if (($tmpRole === 'epal') || ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
                    $userRole = $tmpRole;
383
                }
384
            }
385
            $this->logger->warning('userRole='.$userRole);
386 387
            if ($userRole === '') {
                return $this->respondWithStatus([
388 389
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
390 391 392 393 394 395 396
            } 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
397

398 399 400 401 402 403
                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
404 405
                                    );

406
                    ++$i;
Open Source Developer's avatar
trans  
Open Source Developer committed
407 408
                }

409 410 411 412 413
                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
414 415
                        ], Response::HTTP_FORBIDDEN);
            }
416 417 418 419 420
        } else {
            return $this->respondWithStatus([
                            'message' => t('User not found!'),
                        ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
421 422
    }

Open Source Developer's avatar
changes  
Open Source Developer committed
423

Open Source Developer's avatar
trans  
Open Source Developer committed
424 425
    public function getCoursesPerSchool(Request $request, $schoolid)
    {
426
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
427 428 429

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
430 431 432 433 434 435 436
        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
437
                }
438 439 440
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
441 442
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
443 444 445 446 447
            } 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
448

Open Source Developer's avatar
trans  
Open Source Developer committed
449

450 451 452 453
            $SchoolCat = reset($SchoolCats);
            if ($SchoolCat) {
                $list = array();
                $categ = $SchoolCat->metathesis_region->value;
Open Source Developer's avatar
trans  
Open Source Developer committed
454
                $operation_shift = $SchoolCat -> operation_shift -> value;
455
            }
Open Source Developer's avatar
bugs  
Open Source Developer committed
456

Open Source Developer's avatar
Open Source Developer committed
457
            $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
Open Source Developer's avatar
trans  
Open Source Developer committed
458 459


460 461 462 463 464
            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
465
                }
Open Source Developer's avatar
bug  
Open Source Developer committed
466
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1));
467 468 469
                $list = array();
                foreach ($CourseA as $object) {
                    $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
470
                                    'id' => '1',
Open Source Developer's avatar
trans  
Open Source Developer committed
471
                                    'name' => 'Α Λυκείου',
Open Source Developer's avatar
trans  
Open Source Developer committed
472 473
                                    'size' => sizeof($studentPerSchool),
                                    'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
474 475
                                    'classes' => 1,
                                    'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
476
                                    );
477 478
                }
            }
479

480 481 482 483 484 485 486
            $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
487

488 489
                foreach ($CourseB as $object) {
                    $sectorid = $object->sector_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
490
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
491 492 493
                    $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
494 495
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
496 497
                            'classes' => 2,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
498 499 500

                          );
                }
501 502 503 504 505 506 507 508
            }
            $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
509

510 511
                foreach ($CourseC as $object) {
                    $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
512
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3));
Open Source Developer's avatar
trans  
Open Source Developer committed
513

514 515 516
                    $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
517 518
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
519 520
                            'classes' => 3,
                            'limitdown' => $limit,
521

Open Source Developer's avatar
trans  
Open Source Developer committed
522 523
                          );
                }
524
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
            if ($CourseC && $operation_shift != 'ΗΜΕΡΗΣΙΟ' ) {
                $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;
                }

                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));

                    $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,

                          );
                }
            }

548 549 550 551 552 553
            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
554 555
                        ], Response::HTTP_FORBIDDEN);
            }
556 557 558 559 560
        } else {
            return $this->respondWithStatus([
                            'message' => t('User not found!'),
                        ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
561
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
562

563 564 565 566 567 568 569 570 571
    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
572

573 574 575 576 577 578
        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
bug  
Open Source Developer committed
579
            $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1));
580

Open Source Developer's avatar
Open Source Developer committed
581
                    //foreach ($CourseA as $object) {
582 583
            if (sizeof($studentPerSchool) < $limit) {
                return false;
584
//                                exit;
585
            }
586 587 588 589 590 591 592 593 594
        }          //  }

                $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;
            }
595

596 597
            foreach ($CourseB as $object) {
                $sectorid = $object->sector_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
598
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
599 600 601
                if (sizeof($studentPerSchool) < $limit) {
                    return false;
                    exit;
Open Source Developer's avatar
Open Source Developer committed
602
                }
603 604 605 606 607 608 609 610 611
            }
        }
        $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
612

613 614
            foreach ($CourseC as $object) {
                $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
615
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3));
Open Source Developer's avatar
Open Source Developer committed
616

617 618 619
                if (sizeof($studentPerSchool) < $limit) {
                    return false;
                    exit;
Open Source Developer's avatar
Open Source Developer committed
620
                }
621 622
            }
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
623

624 625
        return true;
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
626

627

Open Source Developer's avatar
changes  
Open Source Developer committed
628
    public function FindCapacityPerSchool(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
629
    {
Open Source Developer's avatar
changes  
Open Source Developer committed
630
        $i = 0;
631
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
632 633

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
634 635 636 637 638 639 640 641 642 643 644 645 646 647
        $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;
            }
Open Source Developer's avatar
changes  
Open Source Developer committed
648
            $operation_shift = $school -> operation_shift -> value;
649 650 651 652 653
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
trans  
Open Source Developer committed
654
                }
655 656 657
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
658 659
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
660
            } elseif ($userRole === 'epal') {
Open Source Developer's avatar
changes  
Open Source Developer committed
661
                $categ = $school->metathesis_region->value;
662
                $list = array();
Open Source Developer's avatar
changes  
Open Source Developer committed
663 664
                $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
                $classcapacity = reset($CourseA);
Open Source Developer's avatar
trans  
Open Source Developer committed
665

Open Source Developer's avatar
changes  
Open Source Developer committed
666 667 668 669 670 671 672 673
                if ($classcapacity) {
                    $list[] = array(
                        'class' => 1,
                        'newsector' => 0,
                        'newspecialit' => 0,
                        'taxi' => 'Ά Λυκείου',
                        'capacity' => $classcapacity->capacity_class_a->value,
                        'globalindex' => $i,
674

Open Source Developer's avatar
changes  
Open Source Developer committed
675
                       );
676
                }
Open Source Developer's avatar
changes  
Open Source Developer committed
677 678 679 680 681
                ++$i;
                $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid));
                if ($CourseB) {
                    foreach ($CourseB as $object) {
                        $sectorid = $object->sector_id->entity->id();
682

Open Source Developer's avatar
changes  
Open Source Developer committed
683 684 685 686 687 688 689 690
                        $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'sector_id' => $sectorid));
                        $classcapacity = reset($CapacityPerClass);
                        if ($classcapacity) {
                            $list[] = array(
                                'class' => 2,
                                'newsector' => $object->sector_id->entity->id(),
                                'newspecialit' => 0,
                                'taxi' => 'Β Λυκείου  '.$object->sector_id->entity->get('name')->value,
691
                                'capacity' => $classcapacity->capacity_class_sector->value,
Open Source Developer's avatar
changes  
Open Source Developer committed
692 693 694 695
                                'globalindex' => $i,
                                 );
                        }
                        ++$i;
696 697
                    }
                }
Open Source Developer's avatar
changes  
Open Source Developer committed
698 699
                $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid));
                if ($CourseC) {
700
                    foreach ($CourseC as $object) {
Open Source Developer's avatar
changes  
Open Source Developer committed
701 702 703 704 705 706 707 708 709 710 711
                        $specialityid = $object->specialty_id->entity->id();
                        $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialityid));
                        $classcapacity = reset($CapacityPerClass);
                        if ($classcapacity) {
                            $list[] = array(
                                'class' => 3,
                                    'newsector' => 0,
                                    'newspecialit' => $object->specialty_id->entity->id(),
                                    'taxi' => 'Γ Λυκείου  '.$object->specialty_id->entity->get('name')->value,
                                    'capacity' => $classcapacity->capacity_class_specialty->value,
                                    'globalindex' => $i,
712

Open Source Developer's avatar
changes  
Open Source Developer committed
713 714 715
                            );
                        }
                        ++$i;
716 717
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
718

Open Source Developer's avatar
changes  
Open Source Developer committed
719 720 721
                if ($CourseC && $operation_shift != 'ΗΜΕΡΗΣΙΟ') {
                    foreach ($CourseC as $object) {
                        $specialityid = $object->specialty_id->entity->id();
722

Open Source Developer's avatar
changes  
Open Source Developer committed
723 724 725 726 727 728 729 730 731 732 733 734 735
                        $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialityid));
                        $classcapacity = reset($CapacityPerClass);
                        if ($classcapacity) {
                            $list[] = array(
                                    'class' => 4,
                                    'newsector' => 0,
                                    'newspecialit' => $object->specialty_id->entity->id(),
                                    'taxi' => 'Δ Λυκείου  '.$object->specialty_id->entity->get('name')->value,
                                    'capacity' => $classcapacity->capacity_class_specialty_d->value,
                                    'globalindex' => $i,
                                  );
                        }
                        ++$i;
736 737
                    }
                }
Open Source Developer's avatar
Open Source Developer committed
738

739
                return $this->respondWithStatus(
Open Source Developer's avatar
changes  
Open Source Developer committed
740
                                     $list, Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
741
            }
742
        } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
743
            return $this->respondWithStatus([
744
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
trans  
Open Source Developer committed
745 746 747
                ], Response::HTTP_FORBIDDEN);
        }
    }
748

Open Source Developer's avatar
trans  
Open Source Developer committed
749

Open Source Developer's avatar
changes  
Open Source Developer committed
750
    public function FindCoursesPerSchool(Request $request)
Open Source Developer's avatar
Open Source Developer committed
751
    {
Open Source Developer's avatar
Open Source Developer committed
752
        $i = 0;
753
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
Open Source Developer committed
754 755

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
756 757 758 759 760 761 762 763 764 765 766 767 768 769
        $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;
            }
Open Source Developer's avatar
Open Source Developer committed
770
            $operation_shift = $school -> operation_shift -> value;
771 772 773 774 775
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
776
                }
777 778 779
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
780 781
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
782
            } elseif ($userRole === 'epal') {
Open Source Developer's avatar
Open Source Developer committed
783
                $categ = $school->metathesis_region->value;
784
                $list = array();
Open Source Developer's avatar
changes  
Open Source Developer committed
785
                $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
786

Open Source Developer's avatar
changes  
Open Source Developer committed
787
                if ($CourseA) {
788 789 790 791 792 793
                    $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('epal_id' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1));
Open Source Developer's avatar
Open Source Developer committed
794

Open Source Developer's avatar
Open Source Developer committed
795 796
                    $list[] = array(
                        'class' => 1,
Open Source Developer's avatar
Open Source Developer committed
797 798
                        'newsector' => 0,
                        'newspecialit' => 0,
Open Source Developer's avatar
Open Source Developer committed
799
                        'taxi' => 'Ά Λυκείου',
800
                        'globalindex' => $i,
Open Source Developer's avatar
Open Source Developer committed
801 802
                        'limitdown' => $limit,
                        'size' => sizeof($studentPerSchool),
Open Source Developer's avatar
Open Source Developer committed
803
                       );
804 805 806 807
                }
                ++$i;
                $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid));
                if ($CourseB) {
Open Source Developer's avatar
Open Source Developer committed
808 809 810 811 812 813
                    $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;
                    }

814 815
                    foreach ($CourseB as $object) {
                        $sectorid = $object->sector_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
816
                        $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
817 818


819
                            $list[] = array(
Open Source Developer's avatar
Open Source Developer committed
820
                                'class' => 2,
821
                                'newsector' => $object->sector_id->entity->id(),
Open Source Developer's avatar
Open Source Developer committed
822
                                'newspecialit' => 0,
823 824
                                'taxi' => 'Β Λυκείου  '.$object->sector_id->entity->get('name')->value,
                                'globalindex' => $i,
Open Source Developer's avatar
Open Source Developer committed
825 826
                                'limitdown' => $limit,
                                'size' => sizeof($studentPerSchool),
Open Source Developer's avatar
Open Source Developer committed
827
                                );
828

829
                        ++$i;
Open Source Developer's avatar
Open Source Developer committed
830
                    }
831 832 833
                }
                $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid));
                if ($CourseC) {
Open Source Developer's avatar
Open Source Developer committed
834 835
                    $limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name' => 3, 'category' => $categ));
                        $limitdown = reset($limit_down);
836 837 838 839
                    if ($limitdown) {
                        $limit = $limitdown->limit_down->value;
                    }
                    foreach ($CourseC as $object) {
840
                        $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
841
                        $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3));
842

843 844 845 846 847 848 849 850 851
                        $list[] = array(
                        'class' => 3,
                            'newsector' => 0,
                            'newspecialit' => $object->specialty_id->entity->id(),
                            'taxi' => 'Γ Λυκείου  '.$object->specialty_id->entity->get('name')->value,
                            'globalindex' => $i,
                            'limitdown' => $limit,
                            'size' => sizeof($studentPerSchool),
                        );
852

853
                        ++$i;
Open Source Developer's avatar
Open Source Developer committed
854
                    }
855
                }
856

Open Source Developer's avatar
Open Source Developer committed
857 858 859
                if ($CourseC && $operation_shift != 'ΗΜΕΡΗΣΙΟ') {
                        $limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name' => 4, 'category' => $categ));
                        $limitdown = reset($limit_down);
860 861 862
                    if ($limitdown) {
                        $limit = $limitdown->limit_down->value;
                    }
863 864
                    foreach ($CourseC as $object) {
                        $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
865
                        $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 4));
866

867
                            $list[] = array(
Open Source Developer's avatar
Open Source Developer committed
868
                                    'class' => 4,
Open Source Developer's avatar
Open Source Developer committed
869
                                    'newsector' => 0,
870 871 872
                                    'newspecialit' => $object->specialty_id->entity->id(),
                                    'taxi' => 'Δ Λυκείου  '.$object->specialty_id->entity->get('name')->value,
                                    'globalindex' => $i,
Open Source Developer's avatar
Open Source Developer committed
873 874
                                    'limitdown' => $limit,
                                    'size' => sizeof($studentPerSchool),
875

Open Source Developer's avatar
Open Source Developer committed
876
                                    );
877

878 879 880
                        ++$i;
                    }
                }
Open Source Developer's avatar
Open Source Developer committed
881

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

892 893
    private function respondWithStatus($arr, $s)
    {
Open Source Developer's avatar
transf  
Open Source Developer committed
894 895
        $res = new JsonResponse($arr);
        $res->setStatusCode($s);
896

Open Source Developer's avatar
transf  
Open Source Developer committed
897 898 899
        return $res;
    }
}