SubmitedApplications.php 50.6 KB
Newer Older
Open Source Developer's avatar
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;
11
use Drupal\Core\Database\Connection;
12 13 14
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Crypt;

Open Source Developer's avatar
Open Source Developer committed
15
class SubmitedApplications extends ControllerBase
Open Source Developer's avatar
Open Source Developer committed
16 17
{
    protected $entityTypeManager;
18
    protected $logger;
19
    protected $connection;
20 21

    public function __construct(
22 23 24 25 26 27 28 29
        EntityTypeManagerInterface $entityTypeManager,
        Connection $connection,
        LoggerChannelFactoryInterface $loggerChannel)
    {
        $this->entityTypeManager = $entityTypeManager;
        $this->connection = $connection;
        $this->logger = $loggerChannel->get('epal');
    }
Open Source Developer's avatar
Open Source Developer committed
30 31 32 33

    public static function create(ContainerInterface $container)
    {
        return new static(
34
            $container->get('entity_type.manager'),
35
            $container->get('database'),
36
            $container->get('logger.factory')
Open Source Developer's avatar
Open Source Developer committed
37
        );
38
    }
Open Source Developer's avatar
Open Source Developer committed
39

40
    public function deleteApplication_HARDDELETE(Request $request)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    {
        if (!$request->isMethod('POST')) {
            return $this->respondWithStatus([
                    "error_code" => 2001
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }

        $content = $request->getContent();

        $applicationId = 0;
        if (!empty($content)) {
            $postArr = json_decode($content, TRUE);
            $applicationId = $postArr['applicationId'];
        }
        else {
            return $this->respondWithStatus([
                    "error_code" => 5002
                ], Response::HTTP_BAD_REQUEST);
        }

61 62

        $authToken = $request->headers->get('PHP_AUTH_USER');
63 64
        $transaction = $this->connection->startTransaction();
        try {
65 66 67 68 69 70 71 72 73 74 75 76 77 78
            //ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_results
            $config_storage = $this->entityTypeManager->getStorage('epal_config');
            $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
            $epalConfig = reset($epalConfigs);
            if (!$epalConfig) {
               return $this->respondWithStatus([
                       'message' => t("EpalConfig Enity not found"),
                   ], Response::HTTP_FORBIDDEN);
            }
            else if ($epalConfig->lock_application->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }
79
            $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
80 81 82
            $epalUser = reset($epalUsers);
            if ($epalUser) {
                $userid = $epalUser->id();
83

84 85 86 87
                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'id' => $applicationId));
                $epalStudent = reset($epalStudents);

                if ($epalStudent) {
88 89 90 91 92
                    if (!$epalStudent->second_period->value && $epalConfig->activate_second_period->value) {
                        return $this->respondWithStatus([
                                "error_code" => 3002
                            ], Response::HTTP_FORBIDDEN);
                    }
93 94 95 96 97 98 99
                    $epalStudentClasses = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $applicationId));
                    $epalStudentClass = reset($epalStudentClasses);
                    if ($epalStudentClass) {
                        return $this->respondWithStatus([
                                "error_code" => 3002
                            ], Response::HTTP_FORBIDDEN);
                    }
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
                    $delQuery = $this->connection->delete('epal_student_epal_chosen');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $delQuery = $this->connection->delete('epal_student_sector_field');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $delQuery = $this->connection->delete('epal_student_course_field');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $delQuery = $this->connection->delete('epal_student_class');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $epalStudent->delete();
                    return $this->respondWithStatus([
                      'error_code' => 0,
                  ], Response::HTTP_OK);

                } else {
                    return $this->respondWithStatus([
                    'message' => t('EPAL student not found'),
                ], Response::HTTP_FORBIDDEN);
                }
123 124
            } else {
                return $this->respondWithStatus([
125
                'message' => t('EPAL user not found'),
126 127
                ], Response::HTTP_FORBIDDEN);
            }
128 129 130
        } catch (\Exception $e) {
            $this->logger->warning($e->getMessage());
            $transaction->rollback();
131

132 133 134 135
            return $this->respondWithStatus([
                'error_code' => 5001,
            ], Response::HTTP_INTERNAL_SERVER_ERROR);
        }
136 137
    }

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
    //λογική διαγραφή αίτησης μαθητή
    public function deleteApplication(Request $request)
    {
        if (!$request->isMethod('POST')) {
            return $this->respondWithStatus([
                    "error_code" => 2001
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }

        $content = $request->getContent();

        $applicationId = 0;
        if (!empty($content)) {
            $postArr = json_decode($content, TRUE);
            $applicationId = $postArr['applicationId'];
        }
        else {
            return $this->respondWithStatus([
                    "error_code" => 5002
                ], Response::HTTP_BAD_REQUEST);
        }


        $authToken = $request->headers->get('PHP_AUTH_USER');
        $transaction = $this->connection->startTransaction();
        try {
            //ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_results
            $config_storage = $this->entityTypeManager->getStorage('epal_config');
            $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
            $epalConfig = reset($epalConfigs);
            if (!$epalConfig) {
               return $this->respondWithStatus([
                       'message' => t("EpalConfig Enity not found"),
                   ], Response::HTTP_FORBIDDEN);
            }
            /*
            //μη διαγραφή αν δεν είναι ενεργή η περίοδος υποβολής αιτήσεων
            else if ($epalConfig->lock_application->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }
            */
181
            $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
            $epalUser = reset($epalUsers);
            if ($epalUser) {
                $userid = $epalUser->id();

                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'id' => $applicationId));
                $epalStudent = reset($epalStudents);

                if ($epalStudent) {
                    /*
                    //άρνηση διαγραφής αν είμαστε στη δεύτερη περίοδο και η αίτηση είναι α' περιόδου
                    if (!$epalStudent->second_period->value && $epalConfig->activate_second_period->value) {
                        return $this->respondWithStatus([
                                "error_code" => 3002
                            ], Response::HTTP_FORBIDDEN);
                    }
                    */
                    $epalStudent->set('delapp', 1);
                    $timestamp = strtotime(date("Y-m-d"));
                    $epalStudent->set('delapp_changed', $timestamp);
                    $epalStudent->set('delapp_role', 'student');
202
                    $epalStudent->set('delapp_studentid',   $userid);
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
                    $epalStudent->save();

                    return $this->respondWithStatus([
                      'error_code' => 0,
                  ], Response::HTTP_OK);

                } else {
                    return $this->respondWithStatus([
                    'message' => t('EPAL student not found'),
                ], Response::HTTP_FORBIDDEN);
                }
            } else {
                return $this->respondWithStatus([
                'message' => t('EPAL user not found'),
                ], Response::HTTP_FORBIDDEN);
            }
        } catch (\Exception $e) {
            $this->logger->warning($e->getMessage());
            $transaction->rollback();

            return $this->respondWithStatus([
                'error_code' => 5001,
            ], Response::HTTP_INTERNAL_SERVER_ERROR);
        }
    }

Open Source Developer's avatar
Open Source Developer committed
229 230
    public function getSubmittedApplications(Request $request)
    {
Open Source Developer's avatar
Open Source Developer committed
231
        $authToken = $request->headers->get('PHP_AUTH_USER');
232
        $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
Open Source Developer's avatar
Open Source Developer committed
233 234
        $epalUser = reset($epalUsers);
        if ($epalUser) {
235
            $userid = $epalUser->id();
236

237
            $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'delapp' => 0));
Open Source Developer's avatar
Open Source Developer committed
238
            $i = 0;
239
            $list = array();
Open Source Developer's avatar
Open Source Developer committed
240
            if ($epalStudents) {
241 242
                $crypt = new Crypt();

243

244 245
                foreach ($epalStudents as $object) {
                    $canDelete = 0;
246 247 248 249 250 251 252 253 254 255 256 257 258 259

                    //ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_delete
                    $config_storage = $this->entityTypeManager->getStorage('epal_config');
                    $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
                    $epalConfig = reset($epalConfigs);
                    if (!$epalConfig) {
                       return $this->respondWithStatus([
                               'message' => t("EpalConfig Enity not found"),
                           ], Response::HTTP_FORBIDDEN);
                    }
                    else {
                       $applicantsAppDelDisabled = $epalConfig->lock_delete->value;
                    }

260 261
                    $epalStudentClasses = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $object->id()));
                    $epalStudentClass = reset($epalStudentClasses);
262 263
                    if (!$epalStudentClass && !$applicantsAppDelDisabled) {
                        $canDelete = 1;
264 265
                    }
                    else {
266
                        $canDelete = 0;
267
                    }
268 269 270 271
                    try {
                        $name_decoded = $crypt->decrypt($object->name->value);
                        $studentsurname_decoded = $crypt->decrypt($object->studentsurname->value);
                    } catch (\Exception $e) {
272 273
                        unset($crypt);
                        $this->logger->warning($e->getMessage());
274

275
                        return $this->respondWithStatus([
276
                          'message' => t('An unexpected error occured during DECODING data in getSubmittedApplications Method '),
277 278 279
                        ], Response::HTTP_INTERNAL_SERVER_ERROR);
                    }

Open Source Developer's avatar
Open Source Developer committed
280
                    $list[] = array(
281
                            'id' => $object->id(),
282 283 284
                            //'name' => $object -> name ->value,
                            'name' => $name_decoded,
                            //'studentsurname' => $object -> studentsurname ->value);
285 286
                            'studentsurname' => $studentsurname_decoded,
                            'candelete' => $canDelete, );
287
                    ++$i;
Open Source Developer's avatar
Open Source Developer committed
288
                }
289

290 291
                unset($crypt);

Open Source Developer's avatar
Open Source Developer committed
292
                return $this->respondWithStatus(
293 294
                        $list, Response::HTTP_OK);
            } else {
295 296
                return $this->respondWithStatus(
                        $list, Response::HTTP_OK);
297
            }
Open Source Developer's avatar
Open Source Developer committed
298 299
        } else {
            return $this->respondWithStatus([
300
                    'message' => t('User not found'),
Open Source Developer's avatar
Open Source Developer committed
301 302 303 304
                ], Response::HTTP_FORBIDDEN);
        }
    }

305
    public function getStudentApplications(Request $request, $studentId)
Open Source Developer's avatar
Open Source Developer committed
306 307
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');
308
        $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
Open Source Developer's avatar
Open Source Developer committed
309 310
        $epalUser = reset($epalUsers);
        if ($epalUser) {
311 312
            $userid = $epalUser->id();
            $studentIdNew = intval($studentId);
313
            $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'id' => $studentIdNew, 'delapp' => 0));
314
            $i = 0;
315

316 317
            if ($epalStudents) {
                $list = array();
318

Open Source Developer's avatar
Open Source Developer committed
319
                foreach ($epalStudents as $object) {
320 321 322 323 324
                    $sectorName = '';
                    $courseName = '';
                    if ($object->currentclass->value === '2') {
                        $sectors = $this->entityTypeManager->getStorage('epal_student_sector_field')->loadByProperties(array('student_id' => $object->id()));
                        $sector = reset($sectors);
325
                        if ($sector) {
326
                            $sectorName = $this->entityTypeManager->getStorage('eepal_sectors')->load($sector->sectorfield_id->target_id)->name->value;
327 328
                        }
                    } elseif ($object->currentclass->value === '3' || $object->currentclass->value === '4') {
329 330
                        $courses = $this->entityTypeManager->getStorage('epal_student_course_field')->loadByProperties(array('student_id' => $object->id()));
                        $course = reset($courses);
331
                        if ($course) {
332
                            $courseName = $this->entityTypeManager->getStorage('eepal_specialty')->load($course->coursefield_id->target_id)->name->value;
333
                        }
334
                    }
335 336

                    $crypt = new Crypt();
337 338 339 340 341 342 343 344
                    try {
                        $name_decoded = $crypt->decrypt($object->name->value);
                        $studentsurname_decoded = $crypt->decrypt($object->studentsurname->value);
                        $fatherfirstname_decoded = $crypt->decrypt($object->fatherfirstname->value);
                        $motherfirstname_decoded = $crypt->decrypt($object->motherfirstname->value);
                        $regionaddress_decoded = $crypt->decrypt($object->regionaddress->value);
                        $regiontk_decoded = $crypt->decrypt($object->regiontk->value);
                        $regionarea_decoded = $crypt->decrypt($object->regionarea->value);
345
                        //$relationtostudent_decoded = $crypt->decrypt($object->relationtostudent->value);
346 347 348 349 350 351
                        $telnum_decoded = $crypt->decrypt($object->telnum->value);
                        $guardian_name_decoded = $crypt->decrypt($object->guardian_name->value);
                        $guardian_surname_decoded = $crypt->decrypt($object->guardian_surname->value);
                        $guardian_fathername_decoded = $crypt->decrypt($object->guardian_fathername->value);
                        $guardian_mothername_decoded = $crypt->decrypt($object->guardian_mothername->value);
                    } catch (\Exception $e) {
352 353
                        //print_r($e->getMessage());
                        unset($crypt);
354 355 356 357 358
                        $this->logger->warning($e->getMessage());

                        return $this->respondWithStatus([
                            'message' => t('An unexpected error occured during DECODING data in getStudentApplications Method '),
                                   ], Response::HTTP_INTERNAL_SERVER_ERROR);
359 360 361
                    }
                    unset($crypt);

Open Source Developer's avatar
Open Source Developer committed
362
                    $list[] = array(
363
                            'applicationId' => $object->id(),
364 365 366 367
                            'name' => $name_decoded,
                            'studentsurname' => $studentsurname_decoded,
                            'fatherfirstname' => $fatherfirstname_decoded,
                            'motherfirstname' => $motherfirstname_decoded,
368
                            'guardian_name' => $guardian_name_decoded,
369
                            'guardian_surname' => $guardian_surname_decoded,
370 371 372 373 374 375 376 377 378 379 380 381
                            'guardian_fathername' => $guardian_fathername_decoded,
                            'guardian_mothername' => $guardian_mothername_decoded,
                            'lastschool_schoolname' => $object->lastschool_schoolname->value,
                            'lastschool_schoolyear' => $object->lastschool_schoolyear->value,
                            'lastschool_class' => $object->lastschool_class->value,
                            'currentclass' => $object->currentclass->value,
                            'currentsector' => $sectorName,
                            'currentcourse' => $courseName,
                            'regionaddress' => $regionaddress_decoded,
                            'regiontk' => $regiontk_decoded,
                            'regionarea' => $regionarea_decoded,
                            'telnum' => $telnum_decoded,
382
                            'relationtostudent' => $object->relationtostudent->value,
383 384
                            'birthdate' => substr($object->birthdate->value, 8, 2).'/'.substr($object->birthdate->value, 5, 2).'/'.substr($object->birthdate->value, 0, 4),
                            'created' => date('d/m/Y H:i', $object->created->value),
Open Source Developer's avatar
Open Source Developer committed
385
                        );
Open Source Developer's avatar
Open Source Developer committed
386

387
                    ++$i;
Open Source Developer's avatar
Open Source Developer committed
388
                }
389

Open Source Developer's avatar
Open Source Developer committed
390
                return $this->respondWithStatus(
391 392 393 394
                        $list, Response::HTTP_OK);
            } else {
                return $this->respondWithStatus([
                    'message' => t('EPAL user not found'),
Open Source Developer's avatar
Open Source Developer committed
395
                ], Response::HTTP_FORBIDDEN);
396
            }
Open Source Developer's avatar
Open Source Developer committed
397 398
        } else {
            return $this->respondWithStatus([
399
                    'message' => t('User not found!!!!'),
Open Source Developer's avatar
Open Source Developer committed
400 401 402 403
                ], Response::HTTP_FORBIDDEN);
        }
    }

404 405 406 407

    public function getApplicationDetails(Request $request, $studentId)
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');
408
        $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
409 410 411 412 413 414 415 416 417 418 419 420 421
        $epalUser = reset($epalUsers);
        if ($epalUser) {

            $config_storage = $this->entityTypeManager->getStorage('epal_config');
            $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
            $epalConfig = reset($epalConfigs);
            if (!$epalConfig) {
               return $this->respondWithStatus([
                       'message' => t("EpalConfig Enity not found"),
                   ], Response::HTTP_FORBIDDEN);
            }
            else {
               $applicantsResultsDisabled = $epalConfig->lock_results->value;
422
               $applicantsAppModifyDisabled = $epalConfig->lock_modify->value;
423
               //$secondPeriodEnabled = $epalConfig->activate_second_period->value;
424
               $dateStartInt = strtotime($epalConfig->date_start_b_period->value);
425 426
            }

427
            $status = "-1";
428 429 430 431
            $schoolName = '';
            $schoolAddress = '';
            $schoolTel = '';

432 433 434 435 436 437 438 439 440 441
            /*
            $studInDistr = false;
            $resQuery = $this->connection->select('epal_student_class', 'res')
                                    ->fields('res', array('student_id'));
            $resQuery->condition('res.student_id', intval($studentId), '=');
            $epalStudentClass = $resQuery->execute()->fetchAll(\PDO::FETCH_OBJ);
            if ($epalStudentClass && sizeof($epalStudentClass) > 0)
              $studInDistr = true;
            */

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
            $esQuery = $this->connection->select('epal_student', 'es')
                                    ->fields('es',
                                    array('name',
                                            'studentsurname',
                                            'fatherfirstname',
                                            'motherfirstname',
                                            'regionaddress',
                                            'regiontk',
                                            'regionarea',
                                            'relationtostudent',
                                            'telnum',
                                            'guardian_name',
                                            'guardian_surname',
                                            'guardian_fathername',
                                            'guardian_mothername',
                                            'id',
                                            'lastschool_schoolname',
459 460
                                            'lastschool_registrynumber',
                                            'lastschool_unittypeid',
461 462 463 464 465
                                            'lastschool_schoolyear',
                                            'lastschool_class',
                                            'currentclass',
                                            'birthdate',
                                            'created',
466
                                            'changed',
467
                                            'second_period',
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
                                        ))
                                    ->fields('esec',
                                    array('choice_no'
                                    ))
                                    ->fields('eesch',
                                    array('name'
                                    ))
                                    ->fields('eese',
                                    array('name',
                                    ))
                                    ->fields('eesp',
                                    array('name',
                                    ))
                                    ->fields('esc',
                                    array('finalized',
                                    ))
                                    ->fields('eeschfin',
                                    array('id',
                                            'name',
                                            'street_address',
                                            'phone_number'
                                    ));

            $esQuery->addJoin('left outer', 'epal_student_epal_chosen', 'esec', 'es.id=esec.student_id');
            $esQuery->addJoin('left outer', 'eepal_school_field_data', 'eesch', 'esec.epal_id=eesch.id');
            $esQuery->addJoin('left outer', 'epal_student_sector_field', 'essf', 'es.id=essf.student_id');
            $esQuery->addJoin('left outer', 'eepal_sectors_field_data', 'eese', 'essf.sectorfield_id=eese.id');
            $esQuery->addJoin('left outer', 'epal_student_course_field', 'escf', 'es.id=escf.student_id');
            $esQuery->addJoin('left outer', 'eepal_specialty_field_data', 'eesp', 'escf.coursefield_id=eesp.id');
            $esQuery->addJoin('left outer', 'epal_student_class', 'esc', 'es.id=esc.student_id');
            $esQuery->addJoin('left outer', 'eepal_school_field_data', 'eeschfin', 'esc.epal_id=eeschfin.id');
            $esQuery->condition('es.id', intval($studentId), '=');
            $esQuery->condition('es.epaluser_id', $epalUser->id(), '=');
            $esQuery->orderBy('esec.choice_no');

            $epalStudents = $esQuery->execute()->fetchAll(\PDO::FETCH_OBJ);

            if ($epalStudents && sizeof($epalStudents) > 0) {
                $epalSchoolsChosen = array();
                foreach ($epalStudents as $es) {
                    array_push($epalSchoolsChosen, array(
                        'epal_id' => $es->eesch_name,
                        'choice_no' => $es->choice_no,
                      ));
                }

                $epalStudent = reset($epalStudents);
                $list = array();

                    $crypt = new Crypt();
                    try {
                        $name_decoded = $crypt->decrypt($epalStudent->name);
                        $studentsurname_decoded = $crypt->decrypt($epalStudent->studentsurname);
                        $fatherfirstname_decoded = $crypt->decrypt($epalStudent->fatherfirstname);
                        $motherfirstname_decoded = $crypt->decrypt($epalStudent->motherfirstname);
                        $regionaddress_decoded = $crypt->decrypt($epalStudent->regionaddress);
                        $regiontk_decoded = $crypt->decrypt($epalStudent->regiontk);
                        $regionarea_decoded = $crypt->decrypt($epalStudent->regionarea);
526
                        //$relationtostudent_decoded = $crypt->decrypt($epalStudent->relationtostudent);
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
                        $telnum_decoded = $crypt->decrypt($epalStudent->telnum);
                        $guardian_name_decoded = $crypt->decrypt($epalStudent->guardian_name);
                        $guardian_surname_decoded = $crypt->decrypt($epalStudent->guardian_surname);
                        $guardian_fathername_decoded = $crypt->decrypt($epalStudent->guardian_fathername);
                        $guardian_mothername_decoded = $crypt->decrypt($epalStudent->guardian_mothername);
                    } catch (\Exception $e) {
                        unset($crypt);
                        $this->logger->warning($e->getMessage());

                        return $this->respondWithStatus([
                            'message' => t('An unexpected error occured during DECODING data in getStudentApplications Method '),
                                   ], Response::HTTP_INTERNAL_SERVER_ERROR);
                    }
                    unset($crypt);

542 543 544 545 546 547 548 549 550 551 552
                    //if ($epalStudent->finalized === null)  {
                    //    $status = "0";
                    //}

                    if ($applicantsResultsDisabled === "0") {
                      //To $epalStudent->finalized === null υποωοεί ότι δεν είναι κατανεμημένος αυτός ο μαθητής <-- ΝΑ ΕΛΕΓΧΘΕΙ
                      if ($epalStudent->finalized === "1")
                          $status = "1";
                      else if ($epalStudent->finalized === "0")
                          $status = "2";
                      else if (   ($epalStudent->second_period === "0" && /*$studInDistr === false*/ $epalStudent->finalized === null)   ||
553
                                  ($epalStudent->second_period === "1" && $epalStudent->changed < $dateStartInt)  )
554 555
                          $status = "3";
                      else if ($epalStudent->second_period === "1" &&
556
                               $epalStudent->changed >= $dateStartInt)
557
                          $status = "4";
558
                    }
559 560 561
                    else
                        $status = "0";

562 563 564 565 566 567 568 569 570 571 572
                    $list[] = array(
                            'applicationId' => $epalStudent->id,
                            'name' => $name_decoded,
                            'studentsurname' => $studentsurname_decoded,
                            'fatherfirstname' => $fatherfirstname_decoded,
                            'motherfirstname' => $motherfirstname_decoded,
                            'guardian_name' => $guardian_name_decoded,
                            'guardian_surname' => $guardian_surname_decoded,
                            'guardian_fathername' => $guardian_fathername_decoded,
                            'guardian_mothername' => $guardian_mothername_decoded,
                            'lastschool_schoolname' => $epalStudent->lastschool_schoolname,
573 574
                            'lastschool_registrynumber' => $epalStudent->lastschool_registrynumber,
                            'lastschool_unittypeid' => $epalStudent->lastschool_unittypeid,
575 576 577
                            'lastschool_schoolyear' => $epalStudent->lastschool_schoolyear,
                            'lastschool_class' => $epalStudent->lastschool_class,
                            'currentclass' => $epalStudent->currentclass,
578 579
                            //'currentsector' => $epalStudent->eese_name,
                            //'currentcourse' => $epalStudent->eesp_name,
580 581 582 583
                            'regionaddress' => $regionaddress_decoded,
                            'regiontk' => $regiontk_decoded,
                            'regionarea' => $regionarea_decoded,
                            'telnum' => $telnum_decoded,
584
                            'relationtostudent' => $epalStudent->relationtostudent,
585
                            'birthdate' => substr($epalStudent->birthdate, 8, 2).'/'.substr($epalStudent->birthdate, 5, 2).'/'.substr($epalStudent->birthdate, 0, 4),
586 587
                            //'created' => date('d/m/Y H:i', $epalStudent->created),
                            'changed' => date('d/m/Y H:i', $epalStudent->changed),
588 589
                            'epalSchoolsChosen' => $epalSchoolsChosen,
                            'applicantsResultsDisabled' => $applicantsResultsDisabled,
590
                            'applicantsAppModifyDisabled' => $applicantsAppModifyDisabled,
591 592 593 594
                            'status' => $status,
                            'schoolName' => $epalStudent->eeschfin_name,
                            'schoolAddress' => $epalStudent->street_address,
                            'schoolTel' => $epalStudent->phone_number,
595 596
                            'secondPeriod' => $epalStudent->second_period,
                            //'secondPeriodSettingEnabled' => $secondPeriodEnabled,
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
                        );

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

613
    public function getEpalChosen(Request $request, $studentId)
Open Source Developer's avatar
Open Source Developer committed
614 615
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');
616
        $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
Open Source Developer's avatar
Open Source Developer committed
617 618
        $epalUser = reset($epalUsers);
        if ($epalUser) {
619 620 621 622 623 624 625 626 627 628 629
            $userid = $epalUser->user_id->entity->id();
            $studentIdNew = intval($studentId);
            $ecQuery = $this->connection->select('epal_student_epal_chosen', 'ec')
                                                                    ->fields('ec', array('choice_no'))
                                                                    ->fields('es', array('name'));
            $ecQuery->addJoin('inner', 'eepal_school_field_data', 'es', 'ec.epal_id=es.id');
            $ecQuery->condition('ec.user_id', $userid, '=');
            $ecQuery->condition('ec.student_id', $studentIdNew, '=');
            $ecQuery->orderBy('ec.choice_no');
            $epalChosen = $ecQuery->execute()->fetchAll(\PDO::FETCH_OBJ);
            $i = 0;
Open Source Developer's avatar
Open Source Developer committed
630

631 632
            if ($epalChosen && sizeof($epalChosen) > 0) {
                $list = array();
Open Source Developer's avatar
Open Source Developer committed
633 634
                foreach ($epalChosen as $object) {
                    $list[] = array(
635 636 637 638
                            'epal_id' => $object->name,
                            'choice_no' => $object->choice_no,
                        );
                    ++$i;
Open Source Developer's avatar
Open Source Developer committed
639
                }
640

Open Source Developer's avatar
Open Source Developer committed
641
                return $this->respondWithStatus(
642 643 644 645
                        $list, Response::HTTP_OK);
            } else {
                return $this->respondWithStatus([
                    'message' => t('EPAL chosen not found!!!'),
Open Source Developer's avatar
Open Source Developer committed
646
                ], Response::HTTP_FORBIDDEN);
647
            }
Open Source Developer's avatar
Open Source Developer committed
648 649
        } else {
            return $this->respondWithStatus([
650
                    'message' => t('User not found'),
Open Source Developer's avatar
Open Source Developer committed
651 652
                ], Response::HTTP_FORBIDDEN);
        }
Open Source Developer's avatar
Open Source Developer committed
653 654
    }

Open Source Developer's avatar
Open Source Developer committed
655 656 657
    public function getCritiria(Request $request, $studentId, $type)
    {
        $authToken = $request->headers->get('PHP_AUTH_USER');
658
        $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
Open Source Developer's avatar
Open Source Developer committed
659 660
        $epalUser = reset($epalUsers);
        if ($epalUser) {
661 662 663 664
            $userid = $epalUser->user_id->entity->id();
            $studentIdNew = intval($studentId);
            $critiriaChosen = $this->entityTypeManager->getStorage('epal_student_moria')->loadByProperties(array('user_id' => $userid, 'student_id' => $studentIdNew));
            $i = 0;
Open Source Developer's avatar
Open Source Developer committed
665 666

            if ($critiriaChosen) {
667
                $list = array();
Open Source Developer's avatar
Open Source Developer committed
668
                foreach ($critiriaChosen as $object) {
669 670
                    $critirio_id = $object->criterio_id->entity->id();
                    $critiriatype = $this->entityTypeManager->getStorage('epal_criteria')->loadByProperties(array('id' => $critirio_id));
671
                    $typeofcritiria = reset($critiriatype);
672 673
                    $typecrit = $typeofcritiria->category->value;
                    if ($typecrit == 'Κοινωνικό' && $type == 1) {
Open Source Developer's avatar
Open Source Developer committed
674
                        $list[] = array(
675 676
                            'critirio' => $object->criterio_id->entity->get('name')->value,
                            'critirio_id' => $critirio_id,
Open Source Developer's avatar
Open Source Developer committed
677 678
                            );

679
                        ++$i;
Open Source Developer's avatar
Open Source Developer committed
680
                    }
681
                    if ($typecrit == 'Εισοδηματικό' && $type == 2) {
Open Source Developer's avatar
Open Source Developer committed
682
                        $list[] = array(
683 684
                            'critirio' => $object->criterio_id->entity->get('name')->value,
                            'critirio_id' => $critirio_id,
Open Source Developer's avatar
Open Source Developer committed
685 686
                            );

687
                        ++$i;
Open Source Developer's avatar
Open Source Developer committed
688 689 690 691
                    }
                }

                return $this->respondWithStatus(
692 693 694 695
                        $list, Response::HTTP_OK);
            } else {
                return $this->respondWithStatus([
                    'message' => t('EPAL chosen not found!!!'),
Open Source Developer's avatar
Open Source Developer committed
696
                ], Response::HTTP_FORBIDDEN);
697
            }
Open Source Developer's avatar
Open Source Developer committed
698 699
        } else {
            return $this->respondWithStatus([
700
                    'message' => t('User not found'),
Open Source Developer's avatar
Open Source Developer committed
701 702 703 704
                ], Response::HTTP_FORBIDDEN);
        }
    }

705

706
    //δεν τη χρησιμοποιούμε πια!
707 708 709 710
    public function getResults(Request $request, $studentId) {

      //έλεγχος πρόσβασης
      $authToken = $request->headers->get('PHP_AUTH_USER');
711
      $epalUsers = $this->entityTypeManager->getStorage('applicant_users')->loadByProperties(array('authtoken' => $authToken));
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
      $epalUser = reset($epalUsers);
      if ($epalUser) {
          $userid = $epalUser->id();
          $studentIdNew = intval($studentId);
          $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'id' => $studentIdNew));
          $i = 0;
          if ($epalStudents) {
              $list = array();

              //ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_results
              $config_storage = $this->entityTypeManager->getStorage('epal_config');
              $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
              $epalConfig = reset($epalConfigs);
              if (!$epalConfig) {
                 return $this->respondWithStatus([
                         'message' => t("EpalConfig Enity not found"),
                     ], Response::HTTP_FORBIDDEN);
              }
              else {
                 $applicantsResultsDisabled = $epalConfig->lock_results->getString();
732
                 //$applicantsAppModifyDisabled = $epalConfig->lock_modify->getString();
733
                 //$secondPeriodEnabled = $epalConfig->activate_second_period->getString();
734 735
              }

736
              $status = "0";
737 738 739
              // $status : 0 --> δεν υπάρχει στον πίνακα αποτελεσμάτων (είτε δεν έγινε ακόμα κατανομή, είτε έγινε κατανομή, αλλά..δεν κατανεμήθηκε! <-- ΠΡΟΣΟΧΗ!!)
              // $status : 1 --> κατανεμήθηκε και είναι "οριστικοποιημένος" (finalized = 1)
              // $status : 2 --> κατανεμήθηκε και είναι "μη οριστικοποιημένος" (finalized = 0), δηλαδή κατανεμήθηκε σε ολιγομελές τμήμα
740 741 742
              $schoolName = '';
              $schoolAddress = '';
              $schoolTel = '';
743
              $secondPeriod = "0";
744

745 746 747 748 749
              //ανάκτηση αποτελέσματος
              // εύρεση τοποθέτησης (περίπτωση μαθητή που τοποθετήθηκε "οριστικά")

              if ($applicantsResultsDisabled === "0")   {

750 751
                        $escQuery = $this->connection->select('epal_student_class', 'esc')
                                                ->fields('esc', array('student_id', 'epal_id', 'finalized'))
752 753 754
                                                ->fields('esch', array('id', 'name', 'street_address','phone_number'));
                        $escQuery->addJoin('inner', 'eepal_school_field_data', 'esch', 'esc.epal_id=esch.id');
                        $escQuery->condition('esc.student_id', intval($studentId), '=');
755 756
                        //$escQuery->condition('esc.second_period', intval($secondPeriodEnabled), '=');

757
                        $epalStudentClasses = $escQuery->execute()->fetchAll(\PDO::FETCH_OBJ);
758 759 760 761
                if  (sizeof($epalStudentClasses) === 1) {
                  $epalStudentClass = reset($epalStudentClasses);

                    if ($epalStudentClass->finalized === "1")  {
762
                      $status = "1";
763 764 765
                      $schoolName = $epalStudentClass->name;
                      $schoolAddress = $epalStudentClass->street_address;
                      $schoolTel = $epalStudentClass->phone_number;
766 767
                      //$secondPeriod = $epalStudentClass->second_period;
                      //$secondPeriodEnabled = $secondPeriodEnabled;
768 769 770
                    }
                    else  {
                        $status = "2";
771 772
                        //$secondPeriod = $epalStudentClass->second_period;
                        //$secondPeriodEnabled = $secondPeriodEnabled;
773 774 775 776
                    }
                }
                else  {
                    $status = "0";
777 778
                    //$secondPeriod = $epalStudentClass->second_period;
                    //$secondPeriodEnabled = $secondPeriodEnabled;
779 780 781 782 783 784
                }

            } //endif $applicantsResultsDisabled === "0"

            $list[] = array(
                      'applicantsResultsDisabled' => $applicantsResultsDisabled,
785
                      //'applicantsAppModifyDisabled' => $applicantsAppModifyDisabled,
786 787 788 789
                      'status' => $status,
                      'schoolName' => $schoolName,
                      'schoolAddress' => $schoolAddress,
                      'schoolTel' => $schoolTel,
790 791
                      //'secondPeriod' => $secondPeriod,
                      //'secondPeriodSettingEnabled' => $secondPeriodEnabled,
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
              );

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

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

    }

807

808
    public function deleteApplicationFromDirector_HARDDELETE(Request $request)
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
    {
        if (!$request->isMethod('POST')) {
            return $this->respondWithStatus([
                    "error_code" => 2001
                ], Response::HTTP_METHOD_NOT_ALLOWED);
        }
            $authToken = $request->headers->get('PHP_AUTH_USER');

            $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
            $user = reset($users);
            if ($user) {
                $epalId = $user->init->value;
                $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $epalId));
                $school = reset($schools);
                if (!$school) {
                    $this->logger->warning('no access to this school='.$user->id());
                    return $this->respondWithStatus([
                        "message" => "No access to this school"
                    ], Response::HTTP_FORBIDDEN);
                }

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



        $content = $request->getContent();

        $applicationId = 0;
        if (!empty($content)) {
            $postArr = json_decode($content, TRUE);
            $applicationId = $postArr['applicationId'];
        }
        else {
            return $this->respondWithStatus([
                    "error_code" => 5002
                ], Response::HTTP_BAD_REQUEST);
        }


859

860 861
        $transaction = $this->connection->startTransaction();
        try {
862
            //ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_school_students_view, lock_application
863 864 865 866 867 868 869 870 871

            $config_storage = $this->entityTypeManager->getStorage('epal_config');
            $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
            $epalConfig = reset($epalConfigs);
            if (!$epalConfig) {
               return $this->respondWithStatus([
                       'message' => t("EpalConfig Enity not found"),
                   ], Response::HTTP_FORBIDDEN);
            }
872
            /*
873 874 875 876 877
            else if ($epalConfig->lock_school_students_view->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }
878 879 880 881 882
            else if ($epalConfig->lock_application->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }
883 884 885 886 887 888 889
            */
            else if ($epalConfig->lock_delete->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }

890 891 892 893 894 895 896 897 898 899 900



                //$userid = $epalUser->id();

                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array( 'id' => $applicationId));
                $epalStudent = reset($epalStudents);

                if ($epalStudent) {
                    $epalStudentClasses = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $applicationId));
                    $epalStudentClass = reset($epalStudentClasses);
901

902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
                    if ($epalStudentClass)  {
                      if ($epalStudentClass->directorconfirm->value === "1")  {
                        return $this->respondWithStatus([
                                "error_code" => -1
                            ], Response::HTTP_FORBIDDEN);
                      }
                    }

                    $delQuery = $this->connection->delete('epal_student_epal_chosen');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $delQuery = $this->connection->delete('epal_student_sector_field');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $delQuery = $this->connection->delete('epal_student_course_field');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $delQuery = $this->connection->delete('epal_student_class');
                    $delQuery->condition('student_id', $applicationId);
                    $delQuery->execute();
                    $epalStudent->delete();
                    return $this->respondWithStatus([
                      'error_code' => 0,
                  ], Response::HTTP_OK);

                } else {
                    return $this->respondWithStatus([
                    'message' => t('EPAL student not found'),
                ], Response::HTTP_FORBIDDEN);
                }
        } catch (\Exception $e) {
            $this->logger->warning($e->getMessage());
            $transaction->rollback();

936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
            return $this->respondWithStatus([
                'error_code' => 5001,
            ], Response::HTTP_INTERNAL_SERVER_ERROR);
            }
        }
    }

}


//λογική διαγραφή αίτησης μαθητή από Διευθυντή
public function deleteApplicationFromDirector(Request $request)
{
    if (!$request->isMethod('POST')) {
        return $this->respondWithStatus([
                "error_code" => 2001
            ], Response::HTTP_METHOD_NOT_ALLOWED);
    }
        $authToken = $request->headers->get('PHP_AUTH_USER');

        $users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
        $user = reset($users);
        if ($user) {
            $epalId = $user->init->value;
960
            //$epalCode = $user->cu_name->value;
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 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 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
            $schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $epalId));
            $school = reset($schools);
            if (!$school) {
                $this->logger->warning('no access to this school='.$user->id());
                return $this->respondWithStatus([
                    "message" => "No access to this school"
                ], Response::HTTP_FORBIDDEN);
            }

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

            $content = $request->getContent();

            $applicationId = 0;
            if (!empty($content)) {
                $postArr = json_decode($content, TRUE);
                $applicationId = $postArr['applicationId'];
            }
            else {
                return $this->respondWithStatus([
                        "error_code" => 5002
                    ], Response::HTTP_BAD_REQUEST);
            }


        $transaction = $this->connection->startTransaction();
        try {
            //ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_delete
            $config_storage = $this->entityTypeManager->getStorage('epal_config');
            $epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
            $epalConfig = reset($epalConfigs);
            if (!$epalConfig) {
               return $this->respondWithStatus([
                       'message' => t("EpalConfig Enity not found"),
                   ], Response::HTTP_FORBIDDEN);
            }
            /*
            else if ($epalConfig->lock_school_students_view->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }
            //μη διαγραφή αν δεν είναι ενεργή η περίοδος υποβολής αιτήσεων
            else if ($epalConfig->lock_application->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }
            */
            else if ($epalConfig->lock_delete->value) {
                return $this->respondWithStatus([
                        "error_code" => 3002
                    ], Response::HTTP_FORBIDDEN);
            }


            $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array( 'id' => $applicationId));
            $epalStudent = reset($epalStudents);

            if ($epalStudent) {
                $epalStudentClasses = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $applicationId));
                $epalStudentClass = reset($epalStudentClasses);

                if ($epalStudentClass)  {
                  if ($epalStudentClass->directorconfirm->value === "1")  {
                    return $this->respondWithStatus([
                            "error_code" => -1
                        ], Response::HTTP_FORBIDDEN);
                  }
                }

                $epalStudent->set('delapp', 1);
                $timestamp = strtotime(date("Y-m-d"));
                $epalStudent->set('delapp_changed', $timestamp);
1046 1047
                $epalStudent->set('delapp_role', 'director');
                $epalStudent->set('delapp_epalid', $epalId);
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
                $epalStudent->save();

                $delQuery = $this->connection->delete('epal_student_class');
                $delQuery->condition('student_id', $applicationId);
                $delQuery->execute();

                return $this->respondWithStatus([
                  'error_code' => 0,
              ], Response::HTTP_OK);

            } else {
                return $this->respondWithStatus([
                'message' => t('EPAL student not found'),
            ], Response::HTTP_FORBIDDEN);
            }
        } catch (\Exception $e) {
            $this->logger->warning($e->getMessage());
            $transaction->rollback();

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
            return $this->respondWithStatus([
                'error_code' => 5001,
            ], Response::HTTP_INTERNAL_SERVER_ERROR);
            }
        }
    }
}



1077
private function respondWithStatus($arr, $s)
1078
    {
Open Source Developer's avatar
Open Source Developer committed
1079 1080
        $res = new JsonResponse($arr);
        $res->setStatusCode($s);
1081

Open Source Developer's avatar
Open Source Developer committed
1082 1083
        return $res;
    }
1084

1085
}