DirectorView.php 28.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 37 38



public function getSectorsPerSchool(Request $request, $epalId)
    {
39

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

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
         $user = reset($users);
         if ($user) {
//             $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('registry_no' => $user->mail->value, 'id' => intval($epalId)));
Open Source Developer's avatar
Open Source Developer committed
46
             $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => intval($epalId)));
47 48 49 50 51 52 53 54 55 56 57 58
             $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
transf  
Open Source Developer committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72
                $epalIdNew = intval($epalId);
                $sectorPerSchool = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id'=> $epalIdNew));
                $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++;
                }
73

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

Open Source Developer's avatar
transf  
Open Source Developer committed
84 85 86 87 88 89 90 91


        } else {

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

Open Source Developer's avatar
transf  
Open Source Developer committed
93 94
    }

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

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

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

Open Source Developer's avatar
trans  
Open Source Developer committed
134
                }
135

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

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

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

Open Source Developer's avatar
trans  
Open Source Developer committed
148 149 150 151 152 153
        } else {

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

Open Source Developer's avatar
trans  
Open Source Developer committed
155 156 157
    }


Open Source Developer's avatar
paging  
Open Source Developer committed
158
public function getStudentPerSchool(Request $request, $epalId , $selectId, $classId, $limitdown, $limitup)
Open Source Developer's avatar
trans  
Open Source Developer committed
159
    {
160

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

       $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user) {
//            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('registry_no' => $user->mail->value, 'id' => intval($epalId)));
Open Source Developer's avatar
Open Source Developer committed
167
            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array( 'id' => intval($epalId)));
168 169 170 171 172 173 174 175 176 177 178
            $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
trans  
Open Source Developer committed
179 180
                $epalIdNew = intval($epalId);
                $selectIdNew = intval($selectId);
Open Source Developer's avatar
trans  
Open Source Developer committed
181 182 183 184
                if ($classId == 1)
                {
                 $selectIdNew = -1;
                 $studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalIdNew, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
185

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

            if ($studentPerSchool) {
                 $list = array();
Open Source Developer's avatar
paging  
Open Source Developer committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
                 $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
212 213 214
                                    $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
215 216
                                   if ($i >= $limitdown && $i < $limitup)
                                   { 
Open Source Developer's avatar
trans  
Open Source Developer committed
217 218
                                    $newstatus = $checkstudentstatus -> directorconfirm-> getValue();
                                                                    
Open Source Developer's avatar
paging  
Open Source Developer committed
219 220 221 222 223 224 225 226 227
                                   $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
228
                                    'guardianfirstname' =>$epalUser -> name ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
229
                                    'guardiansurname' =>$epalUser -> surname ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
230 231 232 233 234 235
                                    '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
236
                                    'birthdate' =>$epalStudent -> birthdate ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
237 238
                                    'checkstatus' =>$newstatus[0][value],

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


255 256

        }
Open Source Developer's avatar
trans  
Open Source Developer committed
257 258 259 260 261 262
        else {

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

Open Source Developer's avatar
trans  
Open Source Developer committed
264
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
265 266 267



Open Source Developer's avatar
trans  
Open Source Developer committed
268 269 270 271
    public function ConfirmStudents(Request $request)
    {

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

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

Open Source Developer's avatar
trans  
Open Source Developer committed
283
            $postData = null;
Open Source Developer's avatar
trans  
Open Source Developer committed
284

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

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


public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit,$schoolid)
    {

Open Source Developer's avatar
trans  
Open Source Developer committed
331 332


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

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

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


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


Open Source Developer's avatar
trans  
Open Source Developer committed
382
                if (($tomeas != 0) && ($specialit != 0))
Open Source Developer's avatar
Open Source Developer committed
383 384 385 386 387 388
                {
                 $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();
389
                    }
Open Source Developer's avatar
Open Source Developer committed
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
                }






                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
trans  
Open Source Developer committed
417 418 419 420 421 422 423 424 425 426 427 428 429
    public function getSchoolsPerPerfetcure(Request $request, $perfectureId)
    {

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

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user)
            {
                $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
430

Open Source Developer's avatar
trans  
Open Source Developer committed
431
                    foreach ($schools as $object) {
Open Source Developer's avatar
Open Source Developer committed
432
                             $status = $this->returnstatus(147);  
Open Source Developer's avatar
trans  
Open Source Developer committed
433
                             $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
434 435
                                    'id' =>$object -> id(),
                                    'name' => $object -> name ->value,
Open Source Developer's avatar
Open Source Developer committed
436
                                    'status' => $status
Open Source Developer's avatar
trans  
Open Source Developer committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
                                    );

                                 $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
464 465 466



Open Source Developer's avatar
trans  
Open Source Developer committed
467 468 469 470 471 472 473 474 475 476
    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)
            {
               $list= array();

Open Source Developer's avatar
trans  
Open Source Developer committed
477 478 479 480 481 482 483
                $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
484 485
                if ($CourseA)        
                {
Open Source Developer's avatar
Open Source Developer committed
486 487 488 489 490 491
                    $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
492
                    $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
493 494 495
                    $list = array();
                    foreach ($CourseA as $object) {
                             $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
496
                                    'id' => '1',
Open Source Developer's avatar
trans  
Open Source Developer committed
497
                                    'name' => 'Α Λυκείου',
Open Source Developer's avatar
trans  
Open Source Developer committed
498 499
                                    'size' => sizeof($studentPerSchool),
                                    'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
500 501
                                    'classes' => 1,
                                    'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
502 503 504 505 506 507 508 509
                                    );
                                
                }            }

            
                $CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
                if ($CourseB)
                {
Open Source Developer's avatar
Open Source Developer committed
510 511 512 513 514 515 516
                    $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
517
                    foreach ($CourseB as $object) {
Open Source Developer's avatar
trans  
Open Source Developer committed
518 519
                    $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
520
                         $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
521
                            'id' => $object -> sector_id -> entity -> id(),
Open Source Developer's avatar
trans  
Open Source Developer committed
522
                            'name' => 'Β Λυκείου  '.$object -> sector_id -> entity-> get('name')->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
523 524
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
525 526
                            'classes' => 2,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
527 528 529 530 531 532 533

                          );
                    }
                }
              $CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
                if ($CourseC)
                {
Open Source Developer's avatar
Open Source Developer committed
534 535 536 537 538 539 540
                    $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
541
                    foreach ($CourseC as $object) {
Open Source Developer's avatar
trans  
Open Source Developer committed
542 543 544
                    $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
545
                         $list[] = array(
Open Source Developer's avatar
trans  
Open Source Developer committed
546
                            'id'=> $object -> specialty_id -> entity -> id(),
Open Source Developer's avatar
trans  
Open Source Developer committed
547
                            'name' => 'Γ Λυκείου  '.$object -> specialty_id -> entity-> get('name')->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
548 549
                            'size' => sizeof($studentPerSchool),
                            'categ' => $categ,
Open Source Developer's avatar
Open Source Developer committed
550 551
                            'classes' => 3,
                            'limitdown' => $limit,
Open Source Developer's avatar
trans  
Open Source Developer committed
552
                            
Open Source Developer's avatar
trans  
Open Source Developer committed
553 554 555
                          );
                    }
                }
Open Source Developer's avatar
trans  
Open Source Developer committed
556 557
                if ($CourseA || $CourseB || $CourseC)
                {
Open Source Developer's avatar
trans  
Open Source Developer committed
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
              
                            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
579

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

Open Source Developer's avatar
Open Source Developer committed
581 582 583 584 585 586 587
public function returnstatus($id)
{
    if ($id == 147)
       return true ;
    return false;
    
}
Open Source Developer's avatar
trans  
Open Source Developer committed
588 589


Open Source Developer's avatar
trans  
Open Source Developer committed
590 591 592 593 594 595


public function findCapacity(Request $request,$taxi,$tomeas,$specialit,$schoolid)
    {

    $tomeasnew = intval($tomeas);
Open Source Developer's avatar
trans  
Open Source Developer committed
596
    $specialitnew = intval($specialit) ;
Open Source Developer's avatar
trans  
Open Source Developer committed
597 598 599 600 601
       $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
trans  
Open Source Developer committed
602
           $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid));
Open Source Developer's avatar
trans  
Open Source Developer committed
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
             $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
trans  
Open Source Developer committed
627 628
                       'test' => "lalalala",
                       'school' => $schoolid
Open Source Developer's avatar
trans  
Open Source Developer committed
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
                        ); 
                    }
                }


                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
644
                        'sector' =>$tomeasnew."lala".$specialitnew
Open Source Developer's avatar
trans  
Open Source Developer committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
                        );
                    }
                }


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






                      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
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725

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
transf  
Open Source Developer committed
726 727 728 729 730 731 732 733 734 735 736
   private function respondWithStatus($arr, $s) {
        $res = new JsonResponse($arr);
        $res->setStatusCode($s);
        return $res;
    }





}