DirectorView.php 51.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 12
use Drupal\Core\Database\Connection;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
Open Source Developer's avatar
transf  
Open Source Developer committed
13 14 15 16

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

20 21
    public function __construct(EntityTypeManagerInterface $entityTypeManager,
        LoggerChannelFactoryInterface $loggerChannel)
Open Source Developer's avatar
transf  
Open Source Developer committed
22 23
    {
        $this->entityTypeManager = $entityTypeManager;
24
        $this->logger = $loggerChannel->get('epal-school');
Open Source Developer's avatar
transf  
Open Source Developer committed
25 26 27 28 29
    }

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



Open Source Developer's avatar
Open Source Developer committed
37
public function getSectorsPerSchool(Request $request)
Open Source Developer's avatar
transf  
Open Source Developer committed
38
    {
39

Open Source Developer's avatar
transf  
Open Source Developer committed
40
        $authToken = $request->headers->get('PHP_AUTH_USER');
41 42 43 44

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
Open Source Developer's avatar
Open Source Developer committed
45
                $epalId = $user ->  init -> value;
Open Source Developer's avatar
Open Source Developer committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
                $schools = $this->entityTypeManager->getStorage('eepal_school')->
                     loadByProperties(array('id' => $epalId));
                     $school = reset($schools);
                     if (!$school) {
                         $this->logger->warning("no access to this school=" . $user->id());
                         $response = new Response();
                         $response->setContent('No access to this school');
                         $response->setStatusCode(Response::HTTP_FORBIDDEN);
                         $response->headers->set('Content-Type', 'application/json');
                         return $response;
                     }
                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal')  {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
Open Source Developer's avatar
transf  
Open Source Developer committed
68
                }
69

Open Source Developer's avatar
Open Source Developer committed
70 71 72 73 74 75 76 77 78 79 80 81
                else if ($userRole === 'epal')
                 {
                       $sectorPerSchool = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id'=> $epalId));
                        if ($sectorPerSchool) {
                         $list = array();
                        foreach ($sectorPerSchool as $object) {
                            $list[] = array(
                                    'sector_id' => $object -> sector_id ->entity->get('name')->value ,
                                    'id' => $object -> sector_id -> entity -> id()
                                    );
                        }

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

Open Source Developer's avatar
transf  
Open Source Developer committed
93 94 95 96 97 98 99 100


        } else {

            return $this->respondWithStatus([
                    'message' => t("User not found!"),
                ], Response::HTTP_FORBIDDEN);
        }
101

Open Source Developer's avatar
transf  
Open Source Developer committed
102 103
    }

Open Source Developer's avatar
Open Source Developer committed
104
public function getSpecialPerSchool(Request $request , $sectorId)
Open Source Developer's avatar
trans  
Open Source Developer committed
105
    {
106

Open Source Developer's avatar
trans  
Open Source Developer committed
107
        $authToken = $request->headers->get('PHP_AUTH_USER');
108 109 110 111

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

            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array( 'id' => $epalId));
115 116 117 118 119 120 121 122 123
             $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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal')  {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }

                else if ($userRole === 'epal')
                 {

              
Open Source Developer's avatar
Open Source Developer committed
142
                $specialityPerSchool = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id'=> $epalId));
Open Source Developer's avatar
trans  
Open Source Developer committed
143 144 145 146 147 148 149 150 151 152
                $i = 0;

            if ($specialityPerSchool) {
                 $list = array();
                 $SectorIdNew = intval($sectorId);
                foreach ($specialityPerSchool as $object) {
                       $idSpecial =  $object -> specialty_id -> entity -> id() ;

                       $specialityPerSector = $this->entityTypeManager->getStorage('eepal_specialty')->loadByProperties(array('id'=> $idSpecial,'sector_id' => $SectorIdNew ));
                       $specialPerSec = reset($specialityPerSector);
153
                       if ($specialPerSec)
Open Source Developer's avatar
trans  
Open Source Developer committed
154 155 156 157 158
                        {       $list[] = array(
                                'specialty_id' => $object -> specialty_id ->entity->get('name')->value ,
                                'id' => $object -> specialty_id -> entity -> id()     );
                                $i++;
                        }
159

Open Source Developer's avatar
trans  
Open Source Developer committed
160
                }
161

Open Source Developer's avatar
trans  
Open Source Developer committed
162 163 164 165
                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
                }
Open Source Developer's avatar
Open Source Developer committed
166
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
167 168 169
             else {
                       return $this->respondWithStatus([
                    'message' => t("School not found!!!"),
170
                ], Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
171
                }
172

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

Open Source Developer's avatar
transf  
Open Source Developer committed
174

Open Source Developer's avatar
trans  
Open Source Developer committed
175 176 177 178 179 180
        } else {

            return $this->respondWithStatus([
                    'message' => t("User not found!"),
                ], Response::HTTP_FORBIDDEN);
        }
181

Open Source Developer's avatar
trans  
Open Source Developer committed
182 183 184
    }


Open Source Developer's avatar
Open Source Developer committed
185
public function getStudentPerSchool(Request $request , $selectId, $classId, $limitdown, $limitup)
Open Source Developer's avatar
trans  
Open Source Developer committed
186
    {
187

Open Source Developer's avatar
trans  
Open Source Developer committed
188
        $authToken = $request->headers->get('PHP_AUTH_USER');
189 190 191 192

       $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user) {
Open Source Developer's avatar
Open Source Developer committed
193 194
            $epalId = $user ->  init -> value;
            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array( 'id' => $epalId));
195 196 197 198 199 200 201 202 203 204
            $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
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223

                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal')  {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }

                else if ($userRole === 'epal')
                 {
                
              
                $selectIdNew = $epalId;
Open Source Developer's avatar
trans  
Open Source Developer committed
224 225 226
                if ($classId == 1)
                {
                 $selectIdNew = -1;
Open Source Developer's avatar
Open Source Developer committed
227
                 $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
228

Open Source Developer's avatar
trans  
Open Source Developer committed
229 230
                }
                else
231
                {
Open Source Developer's avatar
Open Source Developer committed
232
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
233
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
234 235 236 237
                $i = 0;

            if ($studentPerSchool) {
                 $list = array();
Open Source Developer's avatar
paging  
Open Source Developer committed
238 239 240 241
                 $i = 0;
                 if  ($limitdown==$limitup && $limitup == 0)
                     {
                            $list=array(
Open Source Developer's avatar
Open Source Developer committed
242
                                   'id' => sizeof($studentPerSchool),
243
                                   'up' => $limitup,
Open Source Developer's avatar
Open Source Developer committed
244
                                   'down' => $limitdown
245
                                );
Open Source Developer's avatar
paging  
Open Source Developer committed
246 247
                     }

248
                  else
Open Source Developer's avatar
paging  
Open Source Developer committed
249 250 251 252 253 254
                  {
                         foreach ($studentPerSchool as $object)
                                {
                                $studentId = $object -> id() ;
                                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
                                $epalStudent = reset($epalStudents);
255

Open Source Developer's avatar
paging  
Open Source Developer committed
256
                                if ($epalStudents) {
Open Source Developer's avatar
trans  
Open Source Developer committed
257 258 259
                                    $studentIdNew = $epalStudent -> id();
                                    $checkstatus = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array( 'student_id'=> $studentIdNew));
                                    $checkstudentstatus = reset($checkstatus);
Open Source Developer's avatar
paging  
Open Source Developer committed
260
                                   if ($i >= $limitdown && $i < $limitup)
261
                                   {
Open Source Developer's avatar
trans  
Open Source Developer committed
262
                                    $newstatus = $checkstudentstatus -> directorconfirm-> getValue();
263

Open Source Developer's avatar
paging  
Open Source Developer committed
264 265 266 267 268 269 270 271 272
                                   $list[] = array(
                                    'i' => $i,
                                    'id' => $epalStudent -> id(),
                                    'name' => $epalStudent -> name ->value,
                                    'studentsurname' => $epalStudent -> studentsurname ->value,
                                    'fatherfirstname' => $epalStudent -> fatherfirstname ->value,
                                    'fathersurname' =>$epalStudent -> fathersurname ->value,
                                    'motherfirstname' => $epalStudent -> motherfirstname ->value,
                                    'mothersurname' =>$epalStudent -> mothersurname ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
273
                                    'guardianfirstname' =>$epalUser -> name ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
274
                                    'guardiansurname' =>$epalUser -> surname ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
275 276 277 278 279 280
                                    'regionaddress' =>$epalStudent -> regionaddress ->value,
                                    'regiontk' =>$epalStudent -> regiontk ->value,
                                    'regionarea' =>$epalStudent -> regionarea ->value,
                                    'certificatetype' =>$epalStudent -> certificatetype ->value,
                                    'telnum' =>$epalStudent -> telnum ->value,
                                    'relationtostudent' =>$epalStudent -> relationtostudent ->value,
Open Source Developer's avatar
paging  
Open Source Developer committed
281
                                    'birthdate' =>$epalStudent -> birthdate ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
282 283
                                    'checkstatus' =>$newstatus[0][value],

Open Source Developer's avatar
paging  
Open Source Developer committed
284 285 286 287 288 289 290 291 292
                                    );
                                   }
                                   $i++;
                                }
                            }
                        }
                        return $this->respondWithStatus(
                                $list
                            , Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
293
                        }
Open Source Developer's avatar
Open Source Developer committed
294 295
                    }
                    
Open Source Developer's avatar
trans  
Open Source Developer committed
296
             else {
297 298
                 $list = array();
                       return $this->respondWithStatus($list, Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
299 300
                }

Open Source Developer's avatar
Open Source Developer committed
301
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
302

Open Source Developer's avatar
Open Source Developer committed
303
        
Open Source Developer's avatar
trans  
Open Source Developer committed
304 305 306 307 308 309
        else {

            return $this->respondWithStatus([
                    'message' => t("User not found!"),
                ], Response::HTTP_FORBIDDEN);
        }
310

Open Source Developer's avatar
trans  
Open Source Developer committed
311
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
312 313 314



Open Source Developer's avatar
trans  
Open Source Developer committed
315 316 317 318
    public function ConfirmStudents(Request $request)
    {

        if (!$request->isMethod('POST')) {
319
            return $this->respondWithStatus([
Open Source Developer's avatar
trans  
Open Source Developer committed
320 321 322 323 324
                    "message" => t("Method Not Allowed")
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

325 326 327
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
328
//
Open Source Developer's avatar
Open Source Developer committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
                 $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal')  {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }

                else if ($userRole === 'epal')
                 {
344

Open Source Developer's avatar
trans  
Open Source Developer committed
345
            $postData = null;
Open Source Developer's avatar
trans  
Open Source Developer committed
346

Open Source Developer's avatar
trans  
Open Source Developer committed
347
            if ($content = $request->getContent())
Open Source Developer's avatar
trans  
Open Source Developer committed
348 349 350
            {
                 $postData = json_decode($content);
                 $arr = $postData->students;
Open Source Developer's avatar
trans  
Open Source Developer committed
351
                 $type = $postData ->type;
Open Source Developer's avatar
trans  
Open Source Developer committed
352 353

                foreach ($arr as $value) {
354
                    $valnew = intval($value);
Open Source Developer's avatar
trans  
Open Source Developer committed
355 356 357
                 $studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('id' => $valnew ));
                    $studentConfirm = reset($studentForConfirm);
                  if ($studentConfirm) {
Open Source Developer's avatar
trans  
Open Source Developer committed
358
                    if ($type == 1)
Open Source Developer's avatar
trans  
Open Source Developer committed
359
                         $studentConfirm->set('directorconfirm', true);
Open Source Developer's avatar
trans  
Open Source Developer committed
360
                     if ($type == 2)
Open Source Developer's avatar
trans  
Open Source Developer committed
361
                        $studentConfirm->set('directorconfirm', false);
Open Source Developer's avatar
trans  
Open Source Developer committed
362 363
                    if ($type == 3)
                        unset($studentConfirm->{directorconfirm});
Open Source Developer's avatar
trans  
Open Source Developer committed
364
                         $studentConfirm->save();
365 366
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
367 368 369
                return $this->respondWithStatus([
                    'message' => t("saved"),
                ], Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
370
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
            }
             else
              {
                  return $this->respondWithStatus([
                    'message' => t("post with no data"),
                ], Response::HTTP_BAD_REQUEST);
                }

            } else {
            return $this->respondWithStatus([
                    'message' => t("EPAL user not found"),
                ], Response::HTTP_FORBIDDEN);
        }
    }




Open Source Developer's avatar
Open Source Developer committed
389 390


Open Source Developer's avatar
Open Source Developer committed
391
public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
Open Source Developer's avatar
Open Source Developer committed
392 393
    {

Open Source Developer's avatar
trans  
Open Source Developer committed
394 395


Open Source Developer's avatar
Open Source Developer committed
396
        if (!$request->isMethod('POST')) {
397
            return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
398 399 400 401 402
                    "message" => t("Method Not Allowed")
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

403 404 405
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
Open Source Developer's avatar
Open Source Developer committed
406
             $schoolid = $user ->  init -> value;
Open Source Developer's avatar
trans  
Open Source Developer committed
407
             $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid));
408 409 410 411 412 413 414 415 416
             $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
417 418 419 420 421 422 423 424 425 426 427 428
                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal')  {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }
Open Source Developer's avatar
Open Source Developer committed
429

Open Source Developer's avatar
Open Source Developer committed
430
                else if ($userRole === 'epal')
Open Source Developer's avatar
Open Source Developer committed
431 432
                 {

Open Source Developer's avatar
Open Source Developer committed
433

Open Source Developer's avatar
Open Source Developer committed
434
                    $postData = null;
Open Source Developer's avatar
Open Source Developer committed
435

Open Source Developer's avatar
Open Source Developer committed
436 437 438 439 440 441 442 443 444 445
                    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!"),
                        ], Response::HTTP_BAD_REQUEST);
                         }
Open Source Developer's avatar
Open Source Developer committed
446

Open Source Developer's avatar
Open Source Developer committed
447 448 449 450 451 452 453 454 455
                        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
456 457


Open Source Developer's avatar
Open Source Developer committed
458 459 460 461 462 463 464 465 466
                        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
467 468


Open Source Developer's avatar
Open Source Developer committed
469 470 471 472 473 474 475 476 477
                        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
478 479


Open Source Developer's avatar
Open Source Developer committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
                        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();
                            }
                        }



                        return $this->respondWithStatus([
                            'message' => t("saved"),
                        ], Response::HTTP_OK);
                        }
Open Source Developer's avatar
Open Source Developer committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
            }
             else
              {
                  return $this->respondWithStatus([
                    'message' => t("post with no data"),
                ], Response::HTTP_BAD_REQUEST);
                }

            } else {
            return $this->respondWithStatus([
                    'message' => t("EPAL user not found"),
                ], Response::HTTP_FORBIDDEN);
        }
    }


512
    public function getSchools(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
513 514 515 516 517 518 519 520
    {

        $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user)
            {
Open Source Developer's avatar
Open Source Developer committed
521
                $selectionId = $user ->  init -> value;
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if (($tmpRole === 'epal') || ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }

                else if ($userRole === 'regioneduadmin') {
                    $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $selectionId ));
                }
                else if ($userRole === 'eduadmin') {
Open Source Developer's avatar
Open Source Developer committed
539
                    $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('edu_admin_id'=> $selectionId ));
540
                }
541
                if ($schools)
Open Source Developer's avatar
trans  
Open Source Developer committed
542 543
                {
                    $list = array();
Open Source Developer's avatar
Open Source Developer committed
544

Open Source Developer's avatar
trans  
Open Source Developer committed
545
                    foreach ($schools as $object) {
546
                             $status = $this->returnstatus($object -> id());
Open Source Developer's avatar
trans  
Open Source Developer committed
547
                             $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
548 549
                                    'id' =>$object -> id(),
                                    'name' => $object -> name ->value,
Open Source Developer's avatar
Open Source Developer committed
550
                                    'status' => $status
Open Source Developer's avatar
trans  
Open Source Developer committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
                                    );

                                 $i++;
                            }
                            return $this->respondWithStatus(
                                     $list
                                   , Response::HTTP_OK);
                }
                else
                {
                       return $this->respondWithStatus([
                            'message' => t("Perfecture not found!"),
                        ], Response::HTTP_FORBIDDEN);

                }
566
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
567 568 569 570 571 572 573 574 575 576 577
            else
            {

                   return $this->respondWithStatus([
                            'message' => t("User not found!"),
                        ], Response::HTTP_FORBIDDEN);
            }

    }


Open Source Developer's avatar
trans  
Open Source Developer committed
578 579 580 581 582 583 584
    public function getCoursesPerSchool(Request $request, $schoolid)
    {
      $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user)
Open Source Developer's avatar
Open Source Developer committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598
            {   
                $newid = $user ->  init -> value;
                $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if (($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }
Open Source Developer's avatar
Open Source Developer committed
599

Open Source Developer's avatar
Open Source Developer committed
600 601 602 603 604 605
                else if ($userRole === 'regioneduadmin') {
                    $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid, 'region_edu_admin_id' => $newid));
                }
                else if ($userRole === 'eduadmin') {
                    $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid , 'edu_admin_id' => $newid));
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
606

Open Source Developer's avatar
trans  
Open Source Developer committed
607 608
                $SchoolCat = reset($SchoolCats);
                if ($SchoolCat){
Open Source Developer's avatar
Open Source Developer committed
609
                $list= array();
Open Source Developer's avatar
trans  
Open Source Developer committed
610 611 612
                $categ = $SchoolCat-> metathesis_region -> value;
                }
                $CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $schoolid ));
613 614

                if ($CourseA)
Open Source Developer's avatar
trans  
Open Source Developer committed
615
                {
Open Source Developer's avatar
Open Source Developer committed
616 617 618 619 620 621
                    $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
622
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => -1, 'currentclass' => 1 ));
Open Source Developer's avatar
trans  
Open Source Developer committed
623 624 625
                    $list = array();
                    foreach ($CourseA as $object) {
                             $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
626
                                    'id' => '1',
Open Source Developer's avatar
trans  
Open Source Developer committed
627
                                    'name' => 'Α Λυκείου',
Open Source Developer's avatar
trans  
Open Source Developer committed
628 629
                                    'size' => sizeof($studentPerSchool),
                                    'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
630 631
                                    'classes' => 1,
                                    'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
632
                                    );
633

Open Source Developer's avatar
trans  
Open Source Developer committed
634 635
                }            }

636

Open Source Developer's avatar
trans  
Open Source Developer committed
637 638 639
                $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
                if ($CourseB)
                {
Open Source Developer's avatar
Open Source Developer committed
640 641 642 643 644 645 646
                    $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
trans  
Open Source Developer committed
647
                    foreach ($CourseB as $object) {
Open Source Developer's avatar
trans  
Open Source Developer committed
648 649
                    $sectorid = $object -> sector_id -> entity -> id();
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2 ));
Open Source Developer's avatar
trans  
Open Source Developer committed
650
                         $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
651
                            'id' => $object -> sector_id -> entity -> id(),
Open Source Developer's avatar
trans  
Open Source Developer committed
652
                            'name' => 'Β Λυκείου  '.$object -> sector_id -> entity-> get('name')->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
653 654
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
655 656
                            'classes' => 2,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
657 658 659 660 661 662 663

                          );
                    }
                }
              $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
                if ($CourseC)
                {
Open Source Developer's avatar
Open Source Developer committed
664 665 666 667 668 669 670
                    $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
trans  
Open Source Developer committed
671
                    foreach ($CourseC as $object) {
Open Source Developer's avatar
trans  
Open Source Developer committed
672 673 674
                    $specialityid = $object -> specialty_id -> entity -> id() ;
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3 ));

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

Open Source Developer's avatar
trans  
Open Source Developer committed
683 684 685
                          );
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
686 687
                if ($CourseA || $CourseB || $CourseC)
                {
688

Open Source Developer's avatar
trans  
Open Source Developer committed
689 690 691 692 693 694 695 696 697 698 699
                            return $this->respondWithStatus(
                                     $list
                                   , Response::HTTP_OK);
                }
                else
                {
                       return $this->respondWithStatus([
                            'message' => t("Perfecture not found!"),
                        ], Response::HTTP_FORBIDDEN);

                }
700
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
701 702 703 704 705 706 707 708
            else
            {

                   return $this->respondWithStatus([
                            'message' => t("User not found!"),
                        ], Response::HTTP_FORBIDDEN);
            }
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
709

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

Open Source Developer's avatar
Open Source Developer committed
711 712
public function returnstatus($id)
{
Open Source Developer's avatar
Open Source Developer committed
713
                $schoolid = $id;
714
                $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
Open Source Developer's avatar
Open Source Developer committed
715 716 717 718 719
                $SchoolCat = reset($SchoolCats);
                if ($SchoolCat){
                $categ = $SchoolCat-> metathesis_region -> value;
                }
                $CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $schoolid ));
720

721
                if ($CourseA)
Open Source Developer's avatar
Open Source Developer committed
722 723 724 725 726 727 728 729
                {
                    $limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 1, 'category' => $categ ));
                    $limitdown = reset($limit_down);
                    if ($limitdown)
                    {
                        $limit = $limitdown -> limit_down -> value;
                    }
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => -1, 'currentclass' => 1 ));
730

Open Source Developer's avatar
Open Source Developer committed
731 732
                    //foreach ($CourseA as $object) {
                            if (sizeof($studentPerSchool) < $limit){
733 734
                                return false;
//                                exit;
Open Source Developer's avatar
Open Source Developer committed
735
                            }
736

Open Source Developer's avatar
Open Source Developer committed
737 738
                }          //  }

739

Open Source Developer's avatar
Open Source Developer committed
740 741 742 743 744 745 746 747 748 749 750 751 752 753
                $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;
                    }

                    foreach ($CourseB as $object) {
                    $sectorid = $object -> sector_id -> entity -> id();
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2 ));
                         if (sizeof($studentPerSchool) < $limit){
754 755
                                return false;
                                exit;
Open Source Developer's avatar
Open Source Developer committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
                            }
                    }
                }
                $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;
                    }

                    foreach ($CourseC as $object) {
                    $specialityid = $object -> specialty_id -> entity -> id() ;
                    $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3 ));

                         if (sizeof($studentPerSchool) < $limit){
                                return false;
775 776
                                exit;
                                }
Open Source Developer's avatar
Open Source Developer committed
777 778 779
                    }
                }
                return true;
780
//                exit;
Open Source Developer's avatar
Open Source Developer committed
781
}
Open Source Developer's avatar
trans  
Open Source Developer committed
782 783


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

Open Source Developer's avatar
Open Source Developer committed
785
public function findCapacity(Request $request,$taxi,$tomeas,$specialit)
Open Source Developer's avatar
trans  
Open Source Developer committed
786 787 788
    {

    $tomeasnew = intval($tomeas);
Open Source Developer's avatar
trans  
Open Source Developer committed
789
    $specialitnew = intval($specialit) ;
Open Source Developer's avatar
trans  
Open Source Developer committed
790 791 792 793 794
       $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
Open Source Developer's avatar
Open Source Developer committed
795
            $schoolid = $user ->  init -> value;
Open Source Developer's avatar
trans  
Open Source Developer committed
796
           $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid));
Open Source Developer's avatar
trans  
Open Source Developer committed
797 798 799 800 801 802 803 804 805
             $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
806 807 808 809 810
              $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal')  {
                        $userRole = $tmpRole;
Open Source Developer's avatar
trans  
Open Source Developer committed
811 812
                    }
                }
Open Source Developer's avatar
Open Source Developer committed
813 814 815 816 817
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
818

Open Source Developer's avatar
Open Source Developer committed
819 820
                else if ($userRole === 'epal')
                 {
Open Source Developer's avatar
trans  
Open Source Developer committed
821

Open Source Developer's avatar
Open Source Developer committed
822
                      $list = array();
Open Source Developer's avatar
trans  
Open Source Developer committed
823

Open Source Developer's avatar
Open Source Developer committed
824 825 826 827
                        if (($tomeasnew == 0) && ($specialitnew == 0))
                        {
                         $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid ));
                         $classcapacity = reset($CapacityPerClass);
Open Source Developer's avatar
trans  
Open Source Developer committed
828 829


Open Source Developer's avatar
Open Source Developer committed
830
                          if ($classcapacity) {
Open Source Developer's avatar
trans  
Open Source Developer committed
831 832


Open Source Developer's avatar
Open Source Developer committed
833 834 835 836 837 838
                            $list[] = array(
                                'taxi' => $taxi,
                               'capacity' => $classcapacity -> capacity_class_a -> value ,
                               );
                            }
                        }
Open Source Developer's avatar
trans  
Open Source Developer committed
839 840


Open Source Developer's avatar
Open Source Developer committed
841 842 843 844 845 846 847 848 849 850 851 852 853 854
                        if (($tomeasnew != 0) && ($specialitnew == 0))
                        {
                         $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'sector_id' => $tomeasnew ));
                         $classcapacity = reset($CapacityPerClass);
                          if ($classcapacity) {
                            $list[] = array(
                                'taxi' => $taxi,
                                'tomeas' => $tomeasnew,
                                'special' =>$specialitnew,
                                'capacity' => $classcapacity -> capacity_class_sector -> value ,
                                'sector' =>$tomeasnew."lala".$specialitnew
                                );
                            }
                        }
Open Source Developer's avatar
trans  
Open Source Developer committed
855

856

Open Source Developer's avatar
Open Source Developer committed
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
                        if (($tomeasnew != 0) && ($specialitnew != 0) && ($taxi == 3))
                        {
                         $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialitnew));
                         $classcapacity = reset($CapacityPerClass);
                          if ($classcapacity) {
                            $list[] = array(
                                'taxi' =>$taxi,
                                'tomeas' => $tomeasnew,
                                'special' =>$specialitnew,
                                'tomeas' =>  $classcapacity ->  specialty_id -> value,
                                'capacity' => $classcapacity -> capacity_class_specialty -> value ,
                                'specialty' =>"fromspeciality"
                                );
                            }
                        }
Open Source Developer's avatar
trans  
Open Source Developer committed
872

Open Source Developer's avatar
Open Source Developer committed
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
                        if (($tomeasnew != 0) && ($specialitnew != 0) && ($taxi == 4))
                        {
                         $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid, 'specialty_id' => $specialitnew));
                         $classcapacity = reset($CapacityPerClass);
                          if ($classcapacity) {
                            $list[] = array(
                                'taxi' =>$taxi,
                                'tomeas' => $tomeasnew,
                                'special' =>$specialitnew,
                                'tomeas' =>  $classcapacity ->  specialty_id -> value,
                                'capacity' => $classcapacity -> capacity_class_specialty_d -> value ,
                                'specialty' =>"fromspecialityd"
                                );
                            }
                        }

                             return $this->respondWithStatus(
                                             $list
                                           , Response::HTTP_OK);

                            }
            }
             else {
Open Source Developer's avatar
trans  
Open Source Developer committed
896 897 898 899 900 901 902
            return $this->respondWithStatus([
                    'message' => t("EPAL user not found"),
                ], Response::HTTP_FORBIDDEN);
        }
    }


Open Source Developer's avatar
trans  
Open Source Developer committed
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921

public function getSchoolID(Request $request)
    {

        $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
                    $schid = intval($user ->  init -> value );
                    $list = array();
                    $list[] = array(
                             'id' =>  $schid
                        );


                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
922

Open Source Developer's avatar
trans  
Open Source Developer committed
923 924 925 926 927 928 929 930 931 932 933 934 935


            } else {

            return $this->respondWithStatus([
                    'message' => t("User not found!"),
                ], Response::HTTP_FORBIDDEN);
        }

    }



Open Source Developer's avatar
Open Source Developer committed
936 937
public function gettypeofschool(Request $request)
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
938

Open Source Developer's avatar
Open Source Developer committed
939
        $authToken = $request->headers->get('PHP_AUTH_USER');
Open Source Developer's avatar
trans  
Open Source Developer committed
940

Open Source Developer's avatar
Open Source Developer committed
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
                $schid = intval($user ->  init -> value );
                $schools = $this->entityTypeManager->getStorage('eepal_school')->
                 loadByProperties(array('id' => $schid));
                 $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
956 957 958 959 960 961 962 963 964 965 966 967 968 969
                  $userRoles = $user->getRoles();
                $userRole = '';
                foreach ($userRoles as $tmpRole) {
                    if ($tmpRole === 'epal')  {
                        $userRole = $tmpRole;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }

                else if ($userRole === 'epal')
Open Source Developer's avatar
Open Source Developer committed
970
                 {
Open Source Developer's avatar
Open Source Developer committed
971
                 
Open Source Developer's avatar
Open Source Developer committed
972 973
                        $list = array();
                        $list[] = array(
974
                            'type' =>  $school ->  operation_shift  -> value,
Open Source Developer's avatar
Open Source Developer committed
975 976 977 978
                            );
                        return $this->respondWithStatus(
                            $list
                        , Response::HTTP_OK);
979

Open Source Developer's avatar
Open Source Developer committed
980
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
981

Open Source Developer's avatar
Open Source Developer committed
982
            } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
983

Open Source Developer's avatar
Open Source Developer committed
984 985 986 987
            return $this->respondWithStatus([
                    'message' => t("User not found!"),
                ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
trans  
Open Source Developer committed
988

Open Source Developer's avatar
Open Source Developer committed
989
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
990 991


992 993 994 995 996 997 998 999 1000 1001 1002


    public function getlimitsperCourse(Request $request, $classid)
    {
      $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user)
            {
              $schoolid = $user ->  init -> value;
Open Source Developer's avatar
Open Source Developer committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

              $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;
                    }
                }
                if ($userRole === '') {
                    return $this->respondWithStatus([
                             'error_code' => 4003,
                         ], Response::HTTP_FORBIDDEN);
                }

                else if ($userRole === 'epal')
                 {

                 $list= array();
1031

1032
                $SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
1033 1034 1035
                $SchoolCat = reset($SchoolCats);
                if ($SchoolCat){
                $categ = $SchoolCat-> metathesis_region -> value;
1036

1037