DirectorView.php 44.6 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

Open Source Developer's avatar
changes  
Open Source Developer committed
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

44
            $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
Open Source Developer committed
45

46 47 48 49 50 51 52 53 54 55 56
            $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
57 58
            }

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

Open Source Developer's avatar
Open Source Developer committed
72

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

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

                                        $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);
Open Source Developer's avatar
Open Source Developer committed
145
                                           
146 147 148 149 150 151 152 153
                                        } 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);
                                        }


Open Source Developer's avatar
Open Source Developer committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
                                    $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,
                                    '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' => $checkstudentstatus -> directorconfirm ->value,
                                    'created' => date('d/m/Y H:i', $epalStudent -> created ->value),
Open Source Developer's avatar
bug  
Open Source Developer committed
181

Open Source Developer's avatar
Open Source Developer committed
182 183 184
                                    );
                                }
                                ++$i;
Open Source Developer's avatar
trans  
Open Source Developer committed
185
                }
Open Source Developer's avatar
Open Source Developer committed
186 187 188 189 190 191 192
                return $this->respondWithStatus(
                     $list, Response::HTTP_OK);
            }
            else
            {
               return $this->respondWithStatus([
                    'message' => t('Students not found!'),
Open Source Developer's avatar
trans  
Open Source Developer committed
193
                ], Response::HTTP_FORBIDDEN);
194
            }
Open Source Developer's avatar
Open Source Developer committed
195 196 197
        }
         else 
        {
198
            return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
199 200 201 202 203 204 205 206
                    'message' => t('User not found!'),
                ], Response::HTTP_FORBIDDEN);
        }
    }
    catch (\Exception $e)
    {
        $this->logger->warning($e->getMessage());
        return $this->respondWithStatus([
207 208
                'message' => t('Unexpected Error'),
            ], Response::HTTP_FORBIDDEN);
Open Source Developer's avatar
Open Source Developer committed
209
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
210
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
211

Open Source Developer's avatar
changes  
Open Source Developer committed
212 213 214



Open Source Developer's avatar
trans  
Open Source Developer committed
215 216 217
    public function ConfirmStudents(Request $request)
    {
        if (!$request->isMethod('POST')) {
218
            return $this->respondWithStatus([
219
                    'message' => t('Method Not Allowed'),
Open Source Developer's avatar
trans  
Open Source Developer committed
220 221 222 223
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

224
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
225 226 227 228 229 230 231
        $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
232
                }
233 234 235
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
236 237
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
238 239 240 241 242 243 244
            } elseif ($userRole === 'epal') {
                $postData = null;

                if ($content = $request->getContent()) {
                    $postData = json_decode($content);
                    $arr = $postData->students;
                    $type = $postData->type;
Open Source Developer's avatar
Open Source Developer committed
245 246
                    $valnew = intval($arr);
                    $typen = intval($type);
247 248 249
                        $studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('id' => $valnew));
                        $studentConfirm = reset($studentForConfirm);
                        if ($studentConfirm) {
Open Source Developer's avatar
Open Source Developer committed
250 251 252 253 254 255 256
                            if ($typen === 1) {
                                $studentConfirm->set('directorconfirm', 1);
                                $studentConfirm->save();
                                return $this->respondWithStatus([
                                 'message' => t('saved')
                            ,
                            ], Response::HTTP_OK);
257
                            }
Open Source Developer's avatar
Open Source Developer committed
258 259 260 261 262 263 264
                            elseif ($typen === 2) {
                                $studentConfirm->set('directorconfirm', 0);
                                $studentConfirm->save();
                                return $this->respondWithStatus([
                            'message' => t('saved')
                            ,
                            ], Response::HTTP_OK);
265
                            }
Open Source Developer's avatar
Open Source Developer committed
266
                            elseif ($typen === 3) {
267
                                unset($studentConfirm->{directorconfirm});
Open Source Developer's avatar
Open Source Developer committed
268 269 270 271 272 273 274 275 276 277 278
                                $studentConfirm->save();
                                return $this->respondWithStatus([
                            'message' => t('saved')
                            ,
                            ], Response::HTTP_OK);
                            }
                            else
                                 {
                            return $this->respondWithStatus([
                            'message' => t('Bad request'),
                            ], Response::HTTP_FORBIDDEN);
279
                            }
Open Source Developer's avatar
Open Source Developer committed
280 281

                            
282
                        }
Open Source Developer's avatar
Open Source Developer committed
283 284 285 286 287 288 289
                        else
                        {
                            return $this->respondWithStatus([
                            'message' => t('Student not found'),
                        ], Response::HTTP_FORBIDDEN);
                        }
                    
290

Open Source Developer's avatar
Open Source Developer committed
291
                    
Open Source Developer's avatar
trans  
Open Source Developer committed
292 293
                }
            } else {
294 295 296 297 298
                return $this->respondWithStatus([
                    'message' => t('post with no data'),
                ], Response::HTTP_BAD_REQUEST);
            }
        } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
299
            return $this->respondWithStatus([
300
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
trans  
Open Source Developer committed
301 302 303 304
                ], Response::HTTP_FORBIDDEN);
        }
    }

Open Source Developer's avatar
changes  
Open Source Developer committed
305 306


307
    public function SaveCapacity(Request $request, $taxi, $tomeas, $specialit)
Open Source Developer's avatar
Open Source Developer committed
308 309
    {
        if (!$request->isMethod('POST')) {
310
            return $this->respondWithStatus([
311
                    'message' => t('Method Not Allowed'),
Open Source Developer's avatar
Open Source Developer committed
312 313 314 315
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

316 317 318 319 320 321 322 323 324 325 326 327 328
        $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);
        }

329
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
        $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
349
                }
350 351 352
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
353 354
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
355 356
            } elseif ($userRole === 'epal') {
                $postData = null;
Open Source Developer's avatar
Open Source Developer committed
357

358 359 360 361 362 363
                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
364
                        ], Response::HTTP_BAD_REQUEST);
365
                    }
Open Source Developer's avatar
Open Source Developer committed
366

367 368 369 370 371 372
                    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
373
                        }
374
                    }
Open Source Developer's avatar
Open Source Developer committed
375

376 377 378 379 380 381
                    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
382
                        }
383
                    }
Open Source Developer's avatar
Open Source Developer committed
384

385 386 387 388 389 390
                    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
391
                        }
392
                    }
Open Source Developer's avatar
Open Source Developer committed
393

394 395 396 397 398 399 400 401
                    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
402

403 404
                    return $this->respondWithStatus([
                            'message' => t('saved'),
Open Source Developer's avatar
Open Source Developer committed
405
                        ], Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
406 407
                }
            } else {
408 409 410 411 412
                return $this->respondWithStatus([
                    'message' => t('post with no data'),
                ], Response::HTTP_BAD_REQUEST);
            }
        } else {
Open Source Developer's avatar
Open Source Developer committed
413
            return $this->respondWithStatus([
414
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
Open Source Developer committed
415 416 417 418
                ], Response::HTTP_FORBIDDEN);
        }
    }

Open Source Developer's avatar
changes  
Open Source Developer committed
419 420


421
    public function getSchools(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
422 423 424 425 426
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
427 428 429 430 431 432 433
        if ($user) {
            $selectionId = $user->init->value;
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if (($tmpRole === 'epal') || ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
                    $userRole = $tmpRole;
434
                }
435 436 437
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
438 439
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
440 441 442 443 444 445 446
            } 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
447

448 449 450 451 452 453
                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
454 455
                                    );

456
                    ++$i;
Open Source Developer's avatar
trans  
Open Source Developer committed
457 458
                }

459 460 461 462 463
                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
464 465
                        ], Response::HTTP_FORBIDDEN);
            }
466 467 468 469 470
        } else {
            return $this->respondWithStatus([
                            'message' => t('User not found!'),
                        ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
471 472
    }

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

Open Source Developer's avatar
trans  
Open Source Developer committed
474 475
    public function getCoursesPerSchool(Request $request, $schoolid)
    {
476
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
477 478 479

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
480 481 482 483 484 485 486
        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
487
                }
488 489 490
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
491 492
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
493 494 495 496 497
            } 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
498

499 500 501 502 503 504
            $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
505

506 507 508 509 510
            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
511
                }
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' => -1, 'currentclass' => 1));
513 514 515
                $list = array();
                foreach ($CourseA as $object) {
                    $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
516
                                    'id' => '1',
Open Source Developer's avatar
trans  
Open Source Developer committed
517
                                    'name' => 'Α Λυκείου',
Open Source Developer's avatar
trans  
Open Source Developer committed
518 519
                                    'size' => sizeof($studentPerSchool),
                                    'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
520 521
                                    'classes' => 1,
                                    'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
522
                                    );
523 524
                }
            }
525

526 527 528 529 530 531 532
            $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
533

534 535
                foreach ($CourseB as $object) {
                    $sectorid = $object->sector_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
536
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
537 538 539
                    $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
540 541
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
542 543
                            'classes' => 2,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
544 545 546

                          );
                }
547 548 549 550 551 552 553 554
            }
            $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
555

556 557
                foreach ($CourseC as $object) {
                    $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
558
                    $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
559

560 561 562
                    $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
563 564
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
565 566
                            'classes' => 3,
                            'limitdown' => $limit,
567

Open Source Developer's avatar
trans  
Open Source Developer committed
568 569
                          );
                }
570
            }
571 572 573 574 575 576
            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
577 578
                        ], Response::HTTP_FORBIDDEN);
            }
579 580 581 582 583
        } else {
            return $this->respondWithStatus([
                            'message' => t('User not found!'),
                        ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
584
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
585

586 587 588 589 590 591 592 593 594
    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
595

596 597 598 599 600 601
        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
602
            $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => -1, 'currentclass' => 1));
603

Open Source Developer's avatar
Open Source Developer committed
604
                    //foreach ($CourseA as $object) {
605 606
            if (sizeof($studentPerSchool) < $limit) {
                return false;
607
//                                exit;
608
            }
609 610 611 612 613 614 615 616 617
        }          //  }

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

619 620
            foreach ($CourseB as $object) {
                $sectorid = $object->sector_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
621
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
622 623 624
                if (sizeof($studentPerSchool) < $limit) {
                    return false;
                    exit;
Open Source Developer's avatar
Open Source Developer committed
625
                }
626 627 628 629 630 631 632 633 634
            }
        }
        $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
635

636 637
            foreach ($CourseC as $object) {
                $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
638
                $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
639

640 641 642
                if (sizeof($studentPerSchool) < $limit) {
                    return false;
                    exit;
Open Source Developer's avatar
Open Source Developer committed
643
                }
644 645
            }
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
646

647 648
        return true;
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
649

Open Source Developer's avatar
changes  
Open Source Developer committed
650 651
    
    public function FindCapacityPerSchool(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
652
    {
Open Source Developer's avatar
changes  
Open Source Developer committed
653
        $i = 0;
654
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
655 656

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
657 658 659 660 661 662 663 664 665 666 667 668 669 670
        $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
671
            $operation_shift = $school -> operation_shift -> value;
672 673 674 675 676
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
trans  
Open Source Developer committed
677
                }
678 679 680
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
681 682
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
683
            } elseif ($userRole === 'epal') {
Open Source Developer's avatar
changes  
Open Source Developer committed
684
                $categ = $school->metathesis_region->value;
685
                $list = array();
Open Source Developer's avatar
changes  
Open Source Developer committed
686 687
                $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
                $classcapacity = reset($CourseA);
Open Source Developer's avatar
trans  
Open Source Developer committed
688

Open Source Developer's avatar
changes  
Open Source Developer committed
689 690
                if ($classcapacity) {
                
Open Source Developer's avatar
trans  
Open Source Developer committed
691

Open Source Developer's avatar
changes  
Open Source Developer committed
692 693 694 695 696 697 698 699 700
                    $list[] = array(
                        'class' => 1,
                        'newsector' => 0,
                        'newspecialit' => 0,
                        'taxi' => 'Ά Λυκείου',
                        'capacity' => $classcapacity->capacity_class_a->value,
                        'globalindex' => $i,
                       
                       );
701
                }
Open Source Developer's avatar
changes  
Open Source Developer committed
702 703 704 705
                ++$i;
                $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid));
                if ($CourseB) {
                    
Open Source Developer's avatar
trans  
Open Source Developer committed
706

Open Source Developer's avatar
changes  
Open Source Developer committed
707 708 709 710 711 712 713 714 715 716 717
                    foreach ($CourseB as $object) {
                        $sectorid = $object->sector_id->entity->id();
                        
                        $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,
718
                                'capacity' => $classcapacity->capacity_class_sector->value,
Open Source Developer's avatar
changes  
Open Source Developer committed
719 720 721 722
                                'globalindex' => $i,
                                 );
                        }
                        ++$i;
723 724
                    }
                }
Open Source Developer's avatar
changes  
Open Source Developer committed
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
                $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid));
                if ($CourseC) {
                    
                        foreach ($CourseC as $object) {
                        
                        $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,
                                    
                            );
                        }
                        ++$i;
745 746
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
747

Open Source Developer's avatar
changes  
Open Source Developer committed
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
                if ($CourseC && $operation_shift != 'ΗΜΕΡΗΣΙΟ') {
                       
                    foreach ($CourseC as $object) {
                        
                        $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' => 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;
767 768
                    }
                }
Open Source Developer's avatar
Open Source Developer committed
769

770
                return $this->respondWithStatus(
Open Source Developer's avatar
changes  
Open Source Developer committed
771
                                     $list, Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
772
            }
773
        } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
774
            return $this->respondWithStatus([
775
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
trans  
Open Source Developer committed
776 777 778
                ], Response::HTTP_FORBIDDEN);
        }
    }
Open Source Developer's avatar
changes  
Open Source Developer committed
779
    
Open Source Developer's avatar
trans  
Open Source Developer committed
780

Open Source Developer's avatar
changes  
Open Source Developer committed
781
    public function FindCoursesPerSchool(Request $request)
Open Source Developer's avatar
Open Source Developer committed
782
    {
Open Source Developer's avatar
Open Source Developer committed
783
        $i = 0;
784
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
Open Source Developer committed
785 786

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
787 788 789 790 791 792 793 794 795 796 797 798 799 800
        $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
801
            $operation_shift = $school -> operation_shift -> value;
802 803 804 805 806
            $userRoles = $user->getRoles();
            $userRole = '';
            foreach ($userRoles as $tmpRole) {
                if ($tmpRole === 'epal') {
                    $userRole = $tmpRole;
Open Source Developer's avatar
Open Source Developer committed
807
                }
808 809 810
            }
            if ($userRole === '') {
                return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
811 812
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
813
            } elseif ($userRole === 'epal') {
Open Source Developer's avatar
Open Source Developer committed
814
                $categ = $school->metathesis_region->value;
815
                $list = array();
Open Source Developer's avatar
changes  
Open Source Developer committed
816 817 818
                $CourseA = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
               
                if ($CourseA) {
Open Source Developer's avatar
Open Source Developer committed
819 820 821 822 823
                $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
824
                $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
825

Open Source Developer's avatar
Open Source Developer committed
826 827
                    $list[] = array(
                        'class' => 1,
Open Source Developer's avatar
Open Source Developer committed
828 829
                        'newsector' => 0,
                        'newspecialit' => 0,
Open Source Developer's avatar
Open Source Developer committed
830
                        'taxi' => 'Ά Λυκείου',
831
                        'globalindex' => $i,
Open Source Developer's avatar
Open Source Developer committed
832 833
                        'limitdown' => $limit,
                        'size' => sizeof($studentPerSchool),
Open Source Developer's avatar
Open Source Developer committed
834
                       );
835 836 837 838
                }
                ++$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
839 840 841 842 843 844
                    $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;
                    }

845 846
                    foreach ($CourseB as $object) {
                        $sectorid = $object->sector_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
847
                        $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2));
Open Source Developer's avatar
changes  
Open Source Developer committed
848 849
                        
                       
850
                            $list[] = array(
Open Source Developer's avatar
Open Source Developer committed
851
                                'class' => 2,
852
                                'newsector' => $object->sector_id->entity->id(),
Open Source Developer's avatar
Open Source Developer committed
853
                                'newspecialit' => 0,
854 855
                                'taxi' => 'Β Λυκείου  '.$object->sector_id->entity->get('name')->value,
                                'globalindex' => $i,
Open Source Developer's avatar
Open Source Developer committed
856 857
                                'limitdown' => $limit,
                                'size' => sizeof($studentPerSchool),
Open Source Developer's avatar
Open Source Developer committed
858
                                );
Open Source Developer's avatar
changes  
Open Source Developer committed
859
                        
860
                        ++$i;
Open Source Developer's avatar
Open Source Developer committed
861
                    }
862 863 864
                }
                $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid));
                if ($CourseC) {
Open Source Developer's avatar
Open Source Developer committed
865 866 867 868 869 870 871
                    $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;
                        }
                        foreach ($CourseC as $object) {
                        
872
                        $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
873
                        $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3));
Open Source Developer's avatar
changes  
Open Source Developer committed
874
                        
875
                            $list[] = array(
Open Source Developer's avatar
Open Source Developer committed
876
                                'class' => 3,
Open Source Developer's avatar
Open Source Developer committed
877
                                    'newsector' => 0,
878 879 880
                                    '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
881 882
                                    'limitdown' => $limit,
                                    'size' => sizeof($studentPerSchool),
Open Source Developer's avatar
Open Source Developer committed
883
                            );
Open Source Developer's avatar
changes  
Open Source Developer committed
884
                      
885
                        ++$i;
Open Source Developer's avatar
Open Source Developer committed
886
                    }
887
                }
888

Open Source Developer's avatar
Open Source Developer committed
889 890 891 892 893 894
                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;
                        }
895
                    foreach ($CourseC as $object) {
Open Source Developer's avatar
Open Source Developer committed
896
                        
897
                        $specialityid = $object->specialty_id->entity->id();
Open Source Developer's avatar
bug  
Open Source Developer committed
898
                        $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 4));
Open Source Developer's avatar
changes  
Open Source Developer committed
899
                        
900
                            $list[] = array(
Open Source Developer's avatar
Open Source Developer committed
901
                                    'class' => 4,
Open Source Developer's avatar
Open Source Developer committed
902
                                    'newsector' => 0,
903 904 905
                                    '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
906 907
                                    'limitdown' => $limit,
                                    'size' => sizeof($studentPerSchool),
908

Open Source Developer's avatar
Open Source Developer committed
909
                                    );
Open Source Developer's avatar
changes  
Open Source Developer committed
910
                        
911 912 913
                        ++$i;
                    }
                }
Open Source Developer's avatar
Open Source Developer committed
914

915 916 917 918
                return $this->respondWithStatus(
                                     $list, Response::HTTP_OK);
            }
        } else {
Open Source Developer's avatar
Open Source Developer committed
919
            return $this->respondWithStatus([
920
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
Open Source Developer committed
921 922 923 924
                ], Response::HTTP_FORBIDDEN);
        }
    }

925 926
    private function respondWithStatus($arr, $s)
    {
Open Source Developer's avatar
transf  
Open Source Developer committed
927 928
        $res = new JsonResponse($arr);
        $res->setStatusCode($s);
929

Open Source Developer's avatar
transf  
Open Source Developer committed
930 931 932
        return $res;
    }
}