DirectorView.php 31 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 46 47 48
                $epalId = $user ->  init -> value;

             $schools = $this->entityTypeManager->getStorage('eepal_school')->
             loadByProperties(array('id' => $epalId));
49 50 51 52 53 54 55 56 57 58 59 60
             $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;
             }


                $userid = $user -> id();
Open Source Developer's avatar
Open Source Developer committed
61 62
                //$epalIdNew = intval($epalId);
                $sectorPerSchool = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id'=> $epalId));
Open Source Developer's avatar
transf  
Open Source Developer committed
63 64 65 66 67 68 69 70 71 72 73 74
                $i = 0;

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

                   	 $i++;
                }
75

Open Source Developer's avatar
transf  
Open Source Developer committed
76 77 78 79 80 81 82
                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
                }
             else {
                       return $this->respondWithStatus([
                    'message' => t("School not found!!!"),
83
                ], Response::HTTP_OK);
Open Source Developer's avatar
transf  
Open Source Developer committed
84
                }
85

Open Source Developer's avatar
transf  
Open Source Developer committed
86 87 88 89 90 91 92 93


        } else {

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

Open Source Developer's avatar
transf  
Open Source Developer committed
95 96
    }

Open Source Developer's avatar
Open Source Developer committed
97
public function getSpecialPerSchool(Request $request , $sectorId)
Open Source Developer's avatar
trans  
Open Source Developer committed
98
    {
99

Open Source Developer's avatar
trans  
Open Source Developer committed
100
        $authToken = $request->headers->get('PHP_AUTH_USER');
101 102 103 104

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

            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array( 'id' => $epalId));
108 109 110 111 112 113 114 115 116 117
             $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;
             }
                $userid = $user -> id();
Open Source Developer's avatar
Open Source Developer committed
118 119
                //$epalIdNew = intval($epalId);
                $specialityPerSchool = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id'=> $epalId));
Open Source Developer's avatar
trans  
Open Source Developer committed
120 121 122 123 124 125 126 127 128 129
                $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);
130
                       if ($specialPerSec)
Open Source Developer's avatar
trans  
Open Source Developer committed
131 132 133 134 135
                        {       $list[] = array(
                                'specialty_id' => $object -> specialty_id ->entity->get('name')->value ,
                                'id' => $object -> specialty_id -> entity -> id()     );
                                $i++;
                        }
136

Open Source Developer's avatar
trans  
Open Source Developer committed
137
                }
138

Open Source Developer's avatar
trans  
Open Source Developer committed
139 140 141 142 143 144 145
                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
                }
             else {
                       return $this->respondWithStatus([
                    'message' => t("School not found!!!"),
146
                ], Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
147
                }
148

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

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

Open Source Developer's avatar
trans  
Open Source Developer committed
151 152 153 154 155 156
        } else {

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

Open Source Developer's avatar
trans  
Open Source Developer committed
158 159 160
    }


Open Source Developer's avatar
Open Source Developer committed
161
public function getStudentPerSchool(Request $request , $selectId, $classId, $limitdown, $limitup)
Open Source Developer's avatar
trans  
Open Source Developer committed
162
    {
163

Open Source Developer's avatar
trans  
Open Source Developer committed
164
        $authToken = $request->headers->get('PHP_AUTH_USER');
165 166 167 168

       $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user) {
Open Source Developer's avatar
Open Source Developer committed
169 170
            $epalId = $user ->  init -> value;
            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array( 'id' => $epalId));
171 172 173 174 175 176 177 178 179 180 181
            $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;
            }

                $userid = $user -> id();
Open Source Developer's avatar
Open Source Developer committed
182
                //$epalIdNew = intval($epalId);
Open Source Developer's avatar
trans  
Open Source Developer committed
183
                $selectIdNew = intval($selectId);
Open Source Developer's avatar
trans  
Open Source Developer committed
184 185 186
                if ($classId == 1)
                {
                 $selectIdNew = -1;
Open Source Developer's avatar
Open Source Developer committed
187
                 $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
188

Open Source Developer's avatar
trans  
Open Source Developer committed
189 190
                }
                else
191
                {
Open Source Developer's avatar
Open Source Developer committed
192
                $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
193
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
194 195 196 197
                $i = 0;

            if ($studentPerSchool) {
                 $list = array();
Open Source Developer's avatar
paging  
Open Source Developer committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
                 $i = 0;
                 if  ($limitdown==$limitup && $limitup == 0)
                     {
                            $list=array(
                                   'id' => sizeof($studentPerSchool)  
                                ); 
                     }

                  else   
                  {
                         foreach ($studentPerSchool as $object)
                                {
                                $studentId = $object -> id() ;
                                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
                                $epalStudent = reset($epalStudents);
                               
                                if ($epalStudents) {
Open Source Developer's avatar
trans  
Open Source Developer committed
215 216 217
                                    $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
218 219
                                   if ($i >= $limitdown && $i < $limitup)
                                   { 
Open Source Developer's avatar
trans  
Open Source Developer committed
220 221
                                    $newstatus = $checkstudentstatus -> directorconfirm-> getValue();
                                                                    
Open Source Developer's avatar
paging  
Open Source Developer committed
222 223 224 225 226 227 228 229 230
                                   $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
231
                                    'guardianfirstname' =>$epalUser -> name ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
232
                                    'guardiansurname' =>$epalUser -> surname ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
233 234 235 236 237 238
                                    '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
239
                                    'birthdate' =>$epalStudent -> birthdate ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
240 241
                                    'checkstatus' =>$newstatus[0][value],

Open Source Developer's avatar
paging  
Open Source Developer committed
242 243 244 245 246 247 248 249 250
                                    );
                                   }
                                   $i++;
                                }
                            }
                        }
                        return $this->respondWithStatus(
                                $list
                            , Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
251 252
                        }
             else {
253 254
                 $list = array();
                       return $this->respondWithStatus($list, Response::HTTP_OK);
Open Source Developer's avatar
trans  
Open Source Developer committed
255 256 257
                }


258 259

        }
Open Source Developer's avatar
trans  
Open Source Developer committed
260 261 262 263 264 265
        else {

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

Open Source Developer's avatar
trans  
Open Source Developer committed
267
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
268 269 270



Open Source Developer's avatar
trans  
Open Source Developer committed
271 272 273 274
    public function ConfirmStudents(Request $request)
    {

        if (!$request->isMethod('POST')) {
275
            return $this->respondWithStatus([
Open Source Developer's avatar
trans  
Open Source Developer committed
276 277 278 279 280
                    "message" => t("Method Not Allowed")
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

281 282 283
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
Open Source Developer's avatar
Open Source Developer committed
284
//             
285

Open Source Developer's avatar
trans  
Open Source Developer committed
286
            $postData = null;
Open Source Developer's avatar
trans  
Open Source Developer committed
287

Open Source Developer's avatar
trans  
Open Source Developer committed
288
            if ($content = $request->getContent())
Open Source Developer's avatar
trans  
Open Source Developer committed
289 290 291
            {
                 $postData = json_decode($content);
                 $arr = $postData->students;
Open Source Developer's avatar
trans  
Open Source Developer committed
292
                 $type = $postData ->type;
Open Source Developer's avatar
trans  
Open Source Developer committed
293 294

                foreach ($arr as $value) {
295
                    $valnew = intval($value);
Open Source Developer's avatar
trans  
Open Source Developer committed
296 297 298
                 $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
299
                    if ($type == 1)
Open Source Developer's avatar
trans  
Open Source Developer committed
300
                         $studentConfirm->set('directorconfirm', true);
Open Source Developer's avatar
trans  
Open Source Developer committed
301
                     if ($type == 2)
Open Source Developer's avatar
trans  
Open Source Developer committed
302
                        $studentConfirm->set('directorconfirm', false);
Open Source Developer's avatar
trans  
Open Source Developer committed
303 304
                    if ($type == 3)
                        unset($studentConfirm->{directorconfirm});
Open Source Developer's avatar
trans  
Open Source Developer committed
305
                         $studentConfirm->save();
306 307
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
                return $this->respondWithStatus([
                    'message' => t("saved"),
                ], Response::HTTP_OK);
            }
             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
329 330


Open Source Developer's avatar
Open Source Developer committed
331
public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
Open Source Developer's avatar
Open Source Developer committed
332 333
    {

Open Source Developer's avatar
trans  
Open Source Developer committed
334 335


Open Source Developer's avatar
Open Source Developer committed
336
        if (!$request->isMethod('POST')) {
337
            return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
338 339 340 341 342
                    "message" => t("Method Not Allowed")
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
        $authToken = $request->headers->get('PHP_AUTH_USER');

343 344 345
        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
Open Source Developer's avatar
Open Source Developer committed
346
             $schoolid = $user ->  init -> value;
Open Source Developer's avatar
trans  
Open Source Developer committed
347
             $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid));
348 349 350 351 352 353 354 355 356
             $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
357 358 359 360 361 362
            $postData = null;

            if ($content = $request->getContent())
            {
                 $postData = json_decode($content);
                 $cap = $postData->capacity;
Open Source Developer's avatar
trans  
Open Source Developer committed
363
                if (($tomeas == 0) && ($specialit == 0))
Open Source Developer's avatar
Open Source Developer committed
364 365 366 367 368 369
                {
                 $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid ));
                 $classcapacity = reset($CapacityPerClass);
                  if ($classcapacity) {
                         $classcapacity->set('capacity_class_a', $cap);
                         $classcapacity->save();
370
                    }
Open Source Developer's avatar
Open Source Developer committed
371 372 373
                }


Open Source Developer's avatar
trans  
Open Source Developer committed
374
                if (($tomeas != 0) && ($specialit == 0))
Open Source Developer's avatar
Open Source Developer committed
375 376 377 378 379 380
                {
                 $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();
381
                    }
Open Source Developer's avatar
Open Source Developer committed
382 383 384
                }


Open Source Developer's avatar
Open Source Developer committed
385
                if (($tomeas != 0) && ($specialit != 0) && ($taxi == 3))
Open Source Developer's avatar
Open Source Developer committed
386 387 388 389 390 391
                {
                 $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();
392
                    }
Open Source Developer's avatar
Open Source Developer committed
393 394 395
                }


Open Source Developer's avatar
Open Source Developer committed
396 397 398 399 400 401 402 403 404
                if (($tomeas != 0) && ($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
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427



                return $this->respondWithStatus([
                    'message' => t("saved"),
                ], Response::HTTP_OK);
            }
             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
428
    public function getSchoolsPerPerfetcure(Request $request)
Open Source Developer's avatar
trans  
Open Source Developer committed
429 430 431 432 433 434 435 436
    {

        $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
437
                $perfectureId = $user ->  init -> value;
Open Source Developer's avatar
trans  
Open Source Developer committed
438 439 440 441
                $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $perfectureId ));
                if ($schools)        
                {
                    $list = array();
Open Source Developer's avatar
Open Source Developer committed
442

Open Source Developer's avatar
trans  
Open Source Developer committed
443
                    foreach ($schools as $object) {
Open Source Developer's avatar
Open Source Developer committed
444
                             $status = $this->returnstatus(147);  
Open Source Developer's avatar
trans  
Open Source Developer committed
445
                             $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
446 447
                                    'id' =>$object -> id(),
                                    'name' => $object -> name ->value,
Open Source Developer's avatar
Open Source Developer committed
448
                                    'status' => $status
Open Source Developer's avatar
trans  
Open Source Developer committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
                                    );

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

                }
            }    
            else
            {

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

    }


Open Source Developer's avatar
Open Source Developer committed
476 477 478



Open Source Developer's avatar
trans  
Open Source Developer committed
479 480 481 482 483 484 485 486
    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
487

Open Source Developer's avatar
trans  
Open Source Developer committed
488 489
               $list= array();

Open Source Developer's avatar
trans  
Open Source Developer committed
490 491 492 493 494 495 496
                $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
497 498
                if ($CourseA)        
                {
Open Source Developer's avatar
Open Source Developer committed
499 500 501 502 503 504
                    $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
505
                    $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
506 507 508
                    $list = array();
                    foreach ($CourseA as $object) {
                             $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
509
                                    'id' => '1',
Open Source Developer's avatar
trans  
Open Source Developer committed
510
                                    'name' => 'Α Λυκείου',
Open Source Developer's avatar
trans  
Open Source Developer committed
511 512
                                    'size' => sizeof($studentPerSchool),
                                    'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
513 514
                                    'classes' => 1,
                                    'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
515 516 517 518 519 520 521 522
                                    );
                                
                }            }

            
                $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
                if ($CourseB)
                {
Open Source Developer's avatar
Open Source Developer committed
523 524 525 526 527 528 529
                    $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
530
                    foreach ($CourseB as $object) {
Open Source Developer's avatar
trans  
Open Source Developer committed
531 532
                    $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
533
                         $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
534
                            'id' => $object -> sector_id -> entity -> id(),
Open Source Developer's avatar
trans  
Open Source Developer committed
535
                            'name' => 'Β Λυκείου  '.$object -> sector_id -> entity-> get('name')->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
536 537
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
538 539
                            'classes' => 2,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
540 541 542 543 544 545 546

                          );
                    }
                }
              $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
                if ($CourseC)
                {
Open Source Developer's avatar
Open Source Developer committed
547 548 549 550 551 552 553
                    $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
554
                    foreach ($CourseC as $object) {
Open Source Developer's avatar
trans  
Open Source Developer committed
555 556 557
                    $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
558
                         $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
559
                            'id'=> $object -> specialty_id -> entity -> id(),
Open Source Developer's avatar
trans  
Open Source Developer committed
560
                            'name' => 'Γ Λυκείου  '.$object -> specialty_id -> entity-> get('name')->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
561 562
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
563 564
                            'classes' => 3,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
565
                            
Open Source Developer's avatar
trans  
Open Source Developer committed
566 567 568
                          );
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
569 570
                if ($CourseA || $CourseB || $CourseC)
                {
Open Source Developer's avatar
trans  
Open Source Developer committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
              
                            return $this->respondWithStatus(
                                     $list
                                   , Response::HTTP_OK);
                }
                else
                {
                       return $this->respondWithStatus([
                            'message' => t("Perfecture not found!"),
                        ], Response::HTTP_FORBIDDEN);

                }
            }    
            else
            {

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

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

Open Source Developer's avatar
Open Source Developer committed
594 595 596 597 598 599 600
public function returnstatus($id)
{
    if ($id == 147)
       return true ;
    return false;
    
}
Open Source Developer's avatar
trans  
Open Source Developer committed
601 602


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

Open Source Developer's avatar
Open Source Developer committed
604
public function findCapacity(Request $request,$taxi,$tomeas,$specialit)
Open Source Developer's avatar
trans  
Open Source Developer committed
605 606 607
    {

    $tomeasnew = intval($tomeas);
Open Source Developer's avatar
trans  
Open Source Developer committed
608
    $specialitnew = intval($specialit) ;
Open Source Developer's avatar
trans  
Open Source Developer committed
609 610 611 612 613
       $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
614
            $schoolid = $user ->  init -> value;
Open Source Developer's avatar
trans  
Open Source Developer committed
615
           $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid));
Open Source Developer's avatar
trans  
Open Source Developer committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
             $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;
             }
                     
              $list = array();

                if (($tomeasnew == 0) && ($specialitnew == 0))
                {
                 $CapacityPerClass = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid ));
                 $classcapacity = reset($CapacityPerClass);
                 
                
                  if ($classcapacity) {
                        
                       
                    $list[] = array(
                        'taxi' => $taxi,
                       'capacity' => $classcapacity -> capacity_class_a -> value ,
Open Source Developer's avatar
Open Source Developer committed
640
                       ); 
Open Source Developer's avatar
trans  
Open Source Developer committed
641 642 643 644 645 646 647 648 649 650 651 652 653 654
                    }
                }


                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 ,
Open Source Developer's avatar
trans  
Open Source Developer committed
655
                        'sector' =>$tomeasnew."lala".$specialitnew
Open Source Developer's avatar
trans  
Open Source Developer committed
656 657 658 659 660
                        );
                    }
                }


Open Source Developer's avatar
Open Source Developer committed
661
                if (($tomeasnew != 0) && ($specialitnew != 0) && ($taxi == 3))
Open Source Developer's avatar
trans  
Open Source Developer committed
662 663 664 665 666 667 668 669 670 671
                {
                 $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 ,
Open Source Developer's avatar
trans  
Open Source Developer committed
672
                        'specialty' =>"fromspeciality"
Open Source Developer's avatar
trans  
Open Source Developer committed
673 674 675 676
                        );
                    }
                }

Open Source Developer's avatar
Open Source Developer committed
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
                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"
                        );
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709





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

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


Open Source Developer's avatar
trans  
Open Source Developer committed
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744

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

                     $i++;
       

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


            } else {

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

    }



Open Source Developer's avatar
Open Source Developer committed
745 746
public function gettypeofschool(Request $request)
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
747

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

Open Source Developer's avatar
Open Source Developer committed
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
        $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;
                 }
                 else
                 {
                        $list = array();
                        $list[] = array(
                            'type' =>  $school ->  operation_shift  -> value,    
                            );
                        return $this->respondWithStatus(
                            $list
                        , Response::HTTP_OK);
     
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
776

Open Source Developer's avatar
Open Source Developer committed
777
            } else {
Open Source Developer's avatar
trans  
Open Source Developer committed
778

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

Open Source Developer's avatar
Open Source Developer committed
784
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
785 786


Open Source Developer's avatar
transf  
Open Source Developer committed
787 788 789 790 791 792 793 794 795 796 797
   private function respondWithStatus($arr, $s) {
        $res = new JsonResponse($arr);
        $res->setStatusCode($s);
        return $res;
    }





}