SubmitedApplications.php 8.66 KB
Newer Older
Open Source Developer's avatar
trans  
Open Source Developer committed
1 2 3 4 5 6 7 8 9 10 11
<?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
Open Source Developer committed
12
class SubmitedApplications extends ControllerBase
Open Source Developer's avatar
trans  
Open Source Developer committed
13 14 15 16 17 18 19 20 21 22 23 24 25
{
    protected $entityTypeManager;

    public function __construct(EntityTypeManagerInterface $entityTypeManager)
    {
        $this->entityTypeManager = $entityTypeManager;
    }

    public static function create(ContainerInterface $container)
    {
        return new static(
            $container->get('entity_type.manager')
        );
26
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
27 28 29 30


    public function getSubmittedApplications(Request $request)
    {
31

Open Source Developer's avatar
Open Source Developer committed
32 33 34 35
        $authToken = $request->headers->get('PHP_AUTH_USER');
        $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
        $epalUser = reset($epalUsers);
        if ($epalUser) {
Open Source Developer's avatar
tranfer  
Open Source Developer committed
36
            $userid = $epalUser -> id();
37

Open Source Developer's avatar
tranfer  
Open Source Developer committed
38 39 40 41 42
            $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid));
            $i = 0;
            if ($epalStudents) {
                 $list = array();
                foreach ($epalStudents as $object) {
43

Open Source Developer's avatar
styles  
Open Source Developer committed
44
                    $indexid = intval($object -> id())-1;
Open Source Developer's avatar
Open Source Developer committed
45
                    $list[] = array(
Open Source Developer's avatar
styles  
Open Source Developer committed
46
                            'id' => $indexid,
Open Source Developer's avatar
Open Source Developer committed
47
                            'name' => $object -> name ->value,
Open Source Developer's avatar
tranfer  
Open Source Developer committed
48 49 50
                            'studentsurname' => $object -> studentsurname ->value);
                    $i++;
                }
51

Open Source Developer's avatar
tranfer  
Open Source Developer committed
52 53 54
                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
Open Source Developer's avatar
Open Source Developer committed
55 56 57
                }
            else {
                       return $this->respondWithStatus([
Open Source Developer's avatar
tranfer  
Open Source Developer committed
58
                    'message' => t("EPAL user not found"),
Open Source Developer's avatar
Open Source Developer committed
59 60
                ], Response::HTTP_FORBIDDEN);
                }
61 62


Open Source Developer's avatar
Open Source Developer committed
63 64 65 66 67 68 69


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

Open Source Developer's avatar
Open Source Developer committed
71 72 73
    }


74

Open Source Developer's avatar
Open Source Developer committed
75 76 77

 public function getStudentApplications(Request $request, $studentId)
    {
78

Open Source Developer's avatar
Open Source Developer committed
79 80 81 82 83
        $authToken = $request->headers->get('PHP_AUTH_USER');
        $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
        $epalUser = reset($epalUsers);
        if ($epalUser) {
            $userid = $epalUser -> id();
Open Source Developer's avatar
Open Source Developer committed
84 85 86 87 88 89 90 91 92
                $studentIdNew = intval($studentId) ;
                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'id'=> $studentIdNew));
                $i = 0;

                 if ($epalStudents) {
                 $list = array();
                foreach ($epalStudents as $object) {
                    $list[] = array(
                            'name' => $object -> name ->value,
Open Source Developer's avatar
Open Source Developer committed
93 94
                            'studentsurname' => $object -> studentsurname ->value,
                            'fatherfirstname' => $object -> fatherfirstname ->value,
Open Source Developer's avatar
styles  
Open Source Developer committed
95
                            'fathersurname' =>$object -> fathersurname ->value,
Open Source Developer's avatar
Open Source Developer committed
96 97
                            'motherfirstname' => $object -> motherfirstname ->value,
                            'mothersurname' =>$object -> mothersurname ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
98 99 100 101 102 103 104 105
                            'guardianfirstname' =>$epalUser -> name ->value,
                            'guardiansurname' =>$epalUser -> surname ->value,                            
                            'regionaddress' =>$object -> regionaddress ->value,
                            'regiontk' =>$object -> regiontk ->value,
                            'regionarea' =>$object -> regionarea ->value,
                            'certificatetype' =>$object -> certificatetype ->value,
                            'telnum' =>$object -> telnum ->value,
                            'relationtostudent' =>$object -> relationtostudent ->value,
Open Source Developer's avatar
Open Source Developer committed
106
                            'birthdate' =>$object -> birthdate ->value,
Open Source Developer's avatar
trans  
Open Source Developer committed
107
                        );
Open Source Developer's avatar
Open Source Developer committed
108

Open Source Developer's avatar
Open Source Developer committed
109 110
                    $i++;
                }
111

Open Source Developer's avatar
Open Source Developer committed
112 113 114 115 116 117 118 119 120
                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
                }
             else {
                       return $this->respondWithStatus([
                    'message' => t("EPAL user not found"),
                ], Response::HTTP_FORBIDDEN);
                }
121

Open Source Developer's avatar
Open Source Developer committed
122

Open Source Developer's avatar
Open Source Developer committed
123

Open Source Developer's avatar
Open Source Developer committed
124 125
        } else {
            return $this->respondWithStatus([
Open Source Developer's avatar
trans  
Open Source Developer committed
126
                    'message' => t("User not found!!!!"),
Open Source Developer's avatar
Open Source Developer committed
127 128
                ], Response::HTTP_FORBIDDEN);
        }
129

Open Source Developer's avatar
Open Source Developer committed
130 131 132 133 134
    }


public function getEpalChosen(Request $request, $studentId)
    {
135

Open Source Developer's avatar
Open Source Developer committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
        $authToken = $request->headers->get('PHP_AUTH_USER');
        $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
        $epalUser = reset($epalUsers);
        if ($epalUser) {
                $userid = $epalUser -> user_id -> entity -> id();
                $studentIdNew = intval($studentId) ;
                 $epalChosen = $this->entityTypeManager->getStorage('epal_student_epal_chosen')->loadByProperties(array( 'user_id'=>$userid,'student_id'=> $studentIdNew));
                $i = 0;

            if ($epalChosen) {
                 $list = array();
                foreach ($epalChosen as $object) {
                    $list[] = array(
                            'epal_id' => $object -> epal_id ->entity->get('name')->value ,
                            'choice_no' => $object -> choice_no ->value,
);

                    $i++;
                }
155

Open Source Developer's avatar
Open Source Developer committed
156 157 158 159 160 161 162 163 164
                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
                }
             else {
                       return $this->respondWithStatus([
                    'message' => t("EPAL chosen not found!!!"),
                ], Response::HTTP_FORBIDDEN);
                }
165

Open Source Developer's avatar
Open Source Developer committed
166 167


Open Source Developer's avatar
Open Source Developer committed
168 169
        } else {
            return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
170
                    'message' => t("User not found"),
Open Source Developer's avatar
Open Source Developer committed
171 172
                ], Response::HTTP_FORBIDDEN);
        }
173

Open Source Developer's avatar
trans  
Open Source Developer committed
174 175 176
    }


Open Source Developer's avatar
trans  
Open Source Developer committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 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 229 230 231 232 233 234 235 236 237
    public function getCritiria(Request $request, $studentId, $type)
    {

        $authToken = $request->headers->get('PHP_AUTH_USER');
        $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
        $epalUser = reset($epalUsers);
        if ($epalUser) {
                $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;

            if ($critiriaChosen) {
                 $list = array();
                foreach ($critiriaChosen as $object) {
                    $critirio_id = $object -> criterio_id ->entity -> id();
                    $critiriatype = $this->entityTypeManager->getStorage('epal_criteria')->loadByProperties(array( 'id'=>$critirio_id ));
                    $typeofcritiria = reset($critiriatype);    
                    $typecrit = $typeofcritiria -> category -> value;
                    if ($typecrit == "Κοινωνικό" && $type == 1){
                        $list[] = array(
                            'critirio' => $object -> criterio_id ->entity->get('name')->value ,
                            'critirio_id' => $critirio_id ,
                            );

                        $i++;
                    }
                    if ($typecrit == "Εισοδηματικό" && $type == 2){
                        $list[] = array(
                            'critirio' => $object -> criterio_id ->entity->get('name')->value ,
                            'critirio_id' => $critirio_id ,
                            );

                        $i++;
                    }


                }

                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
                }
             else {
                       return $this->respondWithStatus([
                    'message' => t("EPAL chosen 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
238 239 240



Open Source Developer's avatar
Open Source Developer committed
241 242 243 244 245
   private function respondWithStatus($arr, $s) {
        $res = new JsonResponse($arr);
        $res->setStatusCode($s);
        return $res;
    }
Open Source Developer's avatar
Open Source Developer committed
246 247 248 249 250





Open Source Developer's avatar
trans  
Open Source Developer committed
251
}