SubmitedApplications.php 10.7 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
                $studentIdNew = intval($studentId) ;
                $epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'id'=> $studentIdNew));
                $i = 0;

                 if ($epalStudents) {
89
90


Open Source Developer's avatar
Open Source Developer committed
91
                 $list = array();
92

Open Source Developer's avatar
Open Source Developer committed
93
                foreach ($epalStudents as $object) {
94
95
96
97
98
99
100
101
102
103
104
105
106
107
                    $sectorName = '';
                    $courseName = '';
                    if ($object->currentclass->value === '2') {
                        $sectors = $this->entityTypeManager->getStorage('epal_student_sector_field')->loadByProperties(array('student_id' => $object->id()));
                        $sector = reset($sectors);
                        if ($sector)
                            $sectorName = $this->entityTypeManager->getStorage('eepal_sectors')->load($sector->sectorfield_id->target_id)->name->value;
                    }
                    else if ($object->currentclass->value === '3' || $object->currentclass->value === '4') {
                        $courses = $this->entityTypeManager->getStorage('epal_student_course_field')->loadByProperties(array('student_id' => $object->id()));
                        $course = reset($courses);
                        if ($course)
                            $courseName = $this->entityTypeManager->getStorage('eepal_specialty')->load($course->coursefield_id->target_id)->name->value;
                    }
Open Source Developer's avatar
Open Source Developer committed
108
                    $list[] = array(
109
                            'applicationId' => $object->id(),
Open Source Developer's avatar
Open Source Developer committed
110
                            'name' => $object -> name ->value,
Open Source Developer's avatar
Open Source Developer committed
111
112
                            'studentsurname' => $object -> studentsurname ->value,
                            'fatherfirstname' => $object -> fatherfirstname ->value,
Open Source Developer's avatar
styles    
Open Source Developer committed
113
                            'fathersurname' =>$object -> fathersurname ->value,
Open Source Developer's avatar
Open Source Developer committed
114
115
                            'motherfirstname' => $object -> motherfirstname ->value,
                            'mothersurname' =>$object -> mothersurname ->value,
116
117
118
119
120
121
                            'guardian_name' =>$object -> guardian_name ->value,
                            'guardian_surname' =>$object -> guardian_surname ->value,
                            'guardian_fathername' =>$object -> guardian_fathername ->value,
                            'guardian_mothername' =>$object -> guardian_mothername ->value,
                            'lastschool_schoolname' =>$object -> lastschool_schoolname ->value,
                            'lastschool_schoolyear' =>$object -> lastschool_schoolyear ->value,
122
123
124
125
                            'lastschool_class' =>$object -> lastschool_class ->value,
                            'currentclass' =>$object -> currentclass ->value,
                            'currentsector' =>$sectorName,
                            'currentcourse' =>$courseName,
Open Source Developer's avatar
trans    
Open Source Developer committed
126
127
128
129
                            'regionaddress' =>$object -> regionaddress ->value,
                            'regiontk' =>$object -> regiontk ->value,
                            'regionarea' =>$object -> regionarea ->value,
                            'certificatetype' =>$object -> certificatetype ->value,
130
                            'graduation_year' =>$object -> graduation_year ->value,
Open Source Developer's avatar
trans    
Open Source Developer committed
131
132
                            'telnum' =>$object -> telnum ->value,
                            'relationtostudent' =>$object -> relationtostudent ->value,
133
134
135
                            'birthdate' => substr($object->birthdate->value, 8, 2) . '/' . substr($object->birthdate->value, 6, 2) . '/' . substr($object->birthdate->value, 0, 4),
                            'created' => date('d/m/Y H:i', $object -> created ->value),

Open Source Developer's avatar
trans    
Open Source Developer committed
136
                        );
Open Source Developer's avatar
Open Source Developer committed
137

Open Source Developer's avatar
Open Source Developer committed
138
139
                    $i++;
                }
140

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

Open Source Developer's avatar
Open Source Developer committed
151

Open Source Developer's avatar
Open Source Developer committed
152

Open Source Developer's avatar
Open Source Developer committed
153
154
        } else {
            return $this->respondWithStatus([
Open Source Developer's avatar
trans    
Open Source Developer committed
155
                    'message' => t("User not found!!!!"),
Open Source Developer's avatar
Open Source Developer committed
156
157
                ], Response::HTTP_FORBIDDEN);
        }
158

Open Source Developer's avatar
Open Source Developer committed
159
160
161
162
163
    }


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

Open Source Developer's avatar
Open Source Developer committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
        $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++;
                }
184

Open Source Developer's avatar
Open Source Developer committed
185
186
187
188
189
190
191
192
193
                return $this->respondWithStatus(
                        $list
                    , Response::HTTP_OK);
                }
             else {
                       return $this->respondWithStatus([
                    'message' => t("EPAL chosen not found!!!"),
                ], Response::HTTP_FORBIDDEN);
                }
194

Open Source Developer's avatar
Open Source Developer committed
195
196


Open Source Developer's avatar
Open Source Developer committed
197
198
        } else {
            return $this->respondWithStatus([
Open Source Developer's avatar
Open Source Developer committed
199
                    'message' => t("User not found"),
Open Source Developer's avatar
Open Source Developer committed
200
201
                ], Response::HTTP_FORBIDDEN);
        }
202

Open Source Developer's avatar
trans    
Open Source Developer committed
203
204
205
    }


Open Source Developer's avatar
trans    
Open Source Developer committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    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 ));
223
                    $typeofcritiria = reset($critiriatype);
Open Source Developer's avatar
trans    
Open Source Developer committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
                    $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
267
268
269



Open Source Developer's avatar
Open Source Developer committed
270
271
272
273
274
   private function respondWithStatus($arr, $s) {
        $res = new JsonResponse($arr);
        $res->setStatusCode($s);
        return $res;
    }
Open Source Developer's avatar
Open Source Developer committed
275
276
277
278
279





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