Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Χάρης Παπαδόπουλος
e-epal
Commits
a52ded3b
Commit
a52ded3b
authored
Jun 08, 2017
by
Open Source Developer
Browse files
Capacity cahsnges
parents
26cd365b
efb927c5
Changes
27
Expand all
Hide whitespace changes
Inline
Side-by-side
drupal/modules/casost/src/Controller/CASLogin.php
View file @
a52ded3b
...
...
@@ -173,7 +173,7 @@ class CASLogin extends ControllerBase
};
$umdobject
=
$filterAttribute
(
"umdobject"
);
$physicaldeliveryofficename
=
$filterAttribute
(
"physicaldeliveryofficename"
);
//
$physicaldeliveryofficename = $filterAttribute("physicaldeliveryofficename");
/****** the following is for production : Χρήση μόνο από ΕΠΙΣΗΜΟΥΣ ΛΟΓΑΡΙΑΣΜΟΥΣ ***************************/
...
...
@@ -186,12 +186,27 @@ class CASLogin extends ControllerBase
}
*/
phpCAS
::
trace
(
$umdobject
);
phpCAS
::
trace
(
$physicaldeliveryofficename
);
$gsnunitcodedn
=
$filterAttribute
(
'edupersonorgunitdn:gsnunitcode:extended'
);
$gsnunitcode
=
substr
(
$gsnunitcodedn
,
strpos
(
$gsnunitcodedn
,
";"
)
+
1
);
phpCAS
::
trace
(
$gsnunitcode
);
/* check if myschool account */
if
(
!
$umdobject
||
$umdobject
!==
"ISaccount"
)
{
return
$this
->
redirectForbidden
(
$configRowName
,
'5002'
);
}
if
(
!
$gsnunitcode
||
$gsnunitcode
!==
$CASUser
)
{
return
$this
->
redirectForbidden
(
$configRowName
,
'5003'
);
}
/* end of checking myschool account */
$userAssigned
=
$this
->
assignRoleToUser
(
$gsnunitcode
);
if
(
sizeof
(
$userAssigned
)
===
0
)
{
return
$this
->
redirectForbidden
(
$configRowName
,
'5004'
);
}
...
...
drupal/modules/epal/config/install/epal.settings.yml
0 → 100644
View file @
a52ded3b
ws_endpoint
:
'
https://the.url'
ws_username
:
'
username'
ws_password
:
'
password'
verbose
:
true
NO_SAFE_CURL
:
false
drupal/modules/epal/epal.routing.yml
View file @
a52ded3b
...
...
@@ -182,6 +182,14 @@ epal.ministry.massive_mail_unallocated:
_controller
:
'
\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudents'
requirements
:
_user_is_logged_in
:
'
TRUE'
epal.ministry.massive_mail_unallocated_smallclass
:
path
:
'
/ministry/send-unallocated-sc-massive-mail'
options
:
_auth
:
[
'
basic_auth'
]
defaults
:
_controller
:
'
\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudentsSC'
requirements
:
_user_is_logged_in
:
'
TRUE'
epal.ministry.massive_mail_located
:
path
:
'
/ministry/send-located-massive-mail'
options
:
...
...
@@ -278,3 +286,27 @@ epal.applicant.creationpdf:
_controller
:
'
\Drupal\epal\Controller\PdfCreator::createApplicantPDF'
requirements
:
_user_is_logged_in
:
'
TRUE'
epal.svc.getdidacticyears
:
path
:
'
/epal/get-didactic-years'
options
:
_auth
:
[
'
basic_auth'
]
defaults
:
_controller
:
'
\Drupal\epal\Controller\WSConsumer::getAllDidactiYear'
requirements
:
_user_is_logged_in
:
'
TRUE'
epal.svc.getstudentpromotion
:
path
:
'
/epal/get-student-promotion/{didactic_year_id}/{lastname}/{firstname}/{father_firstname}/{mother_firstname}/{birthdate}/{registry_no}/{level_name}'
options
:
_auth
:
[
'
basic_auth'
]
defaults
:
_controller
:
'
\Drupal\epal\Controller\WSConsumer::getStudentEpalPromotion'
requirements
:
_user_is_logged_in
:
'
TRUE'
epal.svc.getstudentcertification
:
path
:
'
/epal/get-student-certification/{didactic_year_id}/{lastname}/{firstname}/{father_firstname}/{mother_firstname}/{birthdate}/{registry_no}/{level_name}'
options
:
_auth
:
[
'
basic_auth'
]
defaults
:
_controller
:
'
\Drupal\epal\Controller\WSConsumer::getStudentEpalCertification'
requirements
:
_user_is_logged_in
:
'
TRUE'
drupal/modules/epal/src/Client.php
0 → 100644
View file @
a52ded3b
<?php
namespace
Drupal\epal
;
use
Symfony\Component\HttpFoundation\Response
;
use
Exception
;
/**
* Description of Client
*
*/
class
Client
{
private
$_settings
=
[
'verbose'
=>
false
,
'ws_endpoint'
=>
''
,
'ws_username'
=>
''
,
'ws_password'
=>
''
,
'NO_SAFE_CURL'
=>
false
];
private
$logger
;
// if this is set and settings sets verbose mode, it will be used for logging
private
$_token
=
null
;
// cache JWT
private
$_tokenExpirationTS
=
null
;
// try to calculate token expiration time
public
function
__construct
(
$settings
=
[],
$logger
=
null
)
{
$this
->
logger
=
$logger
;
$this
->
_settings
=
array_merge
(
$this
->
_settings
,
$settings
);
$this
->
_settings
[
'ws_endpoint_token'
]
=
"
{
$this
->
_settings
[
'ws_endpoint'
]
}
/oauth2/token"
;
$this
->
_settings
[
'ws_endpoint_token_granttype'
]
=
'password'
;
$this
->
_settings
[
'ws_endpoint_studentepalinfo'
]
=
"
{
$this
->
_settings
[
'ws_endpoint'
]
}
/api/epal/GetStudentEpalInfo"
;
$this
->
_settings
[
'ws_endpoint_studentepalcertification'
]
=
"
{
$this
->
_settings
[
'ws_endpoint'
]
}
/api/epal/GetStudentEpalCertification"
;
$this
->
_settings
[
'ws_endpoint_studentepalpromotion'
]
=
"
{
$this
->
_settings
[
'ws_endpoint'
]
}
/api/epal/GetStudentEpalPromotion"
;
$this
->
_settings
[
'ws_endpoint_alldidactiyear'
]
=
"
{
$this
->
_settings
[
'ws_endpoint'
]
}
/api/general/GetAllDidactiYear"
;
}
/**
* Επιστρέφει πίνακα με κλειδιά τα property names των πεδίων που επιστρέφει η GetStudentEpalInfo
* και τιμές λεκτικά - ετικέτες τους.
*
* @return array
*/
public
function
getStudentInfoFields
()
{
return
$this
->
studentInfoFields
;
}
/**
* Λαμβάνει το authentication token
*
* @return string To authentication header (Bearer <token>) έτοιμο για να μπει στο authorization
* @throws \Exception
*/
public
function
getTokenBearer
()
{
if
(
$this
->
_token
!==
null
&&
$this
->
_tokenExpirationTS
!==
null
&&
intval
(
$this
->
_tokenExpirationTS
)
>=
time
())
{
$this
->
log
(
__METHOD__
.
" reusing token"
);
return
$this
->
_token
;
}
$this
->
_token
=
null
;
$this
->
_tokenExpirationTS
=
null
;
$this
->
log
(
__METHOD__
.
" new token"
);
$headers
=
[
'Accept: application/json'
,
'Accept-Language: en-gb'
,
'Audience: Any'
,
// 'Content-Type: application/x-www-form-urlencoded' // should be set by post
'User-Agent: OSTEAM Client/v1.1 osteam'
];
$payload
=
http_build_query
([
'username'
=>
$this
->
_settings
[
'ws_username'
],
'password'
=>
$this
->
_settings
[
'ws_password'
],
'grant_type'
=>
$this
->
_settings
[
'ws_endpoint_token_granttype'
]
]);
$result
=
$this
->
post
(
$this
->
_settings
[
'ws_endpoint_token'
],
$payload
,
$headers
);
if
(
$result
[
'success'
]
===
false
)
{
$this
->
log
(
__METHOD__
.
" Error while calling ws. Diagnostic:
{
$result
[
'response'
]
}
. Response code:
{
$result
[
'http_status'
]
}
"
,
"error"
);
throw
new
Exception
(
"Προέκυψε λάθος κατά την άντληση των στοιχείων."
);
}
if
((
$response
=
json_decode
(
$result
[
'response'
],
true
))
!==
null
)
{
$this
->
_tokenExpirationTS
=
time
()
+
intval
(
$response
[
'expires_in'
])
-
15
;
// skip 15 seconds... just in case
$this
->
_token
=
ucfirst
(
$response
[
'token_type'
])
.
"
{
$response
[
'access_token'
]
}
"
;
return
$this
->
_token
;
}
else
{
$this
->
log
(
__METHOD__
.
" Error while getting token from response
{
$result
[
'response'
]
}
."
,
"error"
);
throw
new
Exception
(
"Προέκυψε λάθος κατά την λήψη του token. Αδυναμία άντλησης του token από το response."
);
}
}
/**
* Επιστρέφει λίστα των διδακτικών ετών με κλειδί το id και τιμή το λεκτικό.
*
* @return array Associative array με κλειδί το id και τιμή το λεκτικό. Π.χ.
* Array (
* [1] => 2008 - 2009
* [2] => 2011 - 2012
* [18] => 2013 - 2014
* [24] => 2016 - 2017
* )
*
* @throws \Exception Σε περίπτωση οποιουδήποτε λάθους
*/
public
function
getAllDidactiYear
()
{
$this
->
log
(
__METHOD__
);
$headers
=
[
'Accept: application/json'
,
'Accept-Language: en-gb'
,
'Audience: Any'
,
'Authorization: '
.
$this
->
getTokenBearer
(),
'User-Agent: OSTEAM Client/v1.1 osteam'
];
$result
=
$this
->
get
(
$this
->
_settings
[
'ws_endpoint_alldidactiyear'
],
[],
$headers
);
// data as path params...
if
(
$result
[
'success'
]
===
false
)
{
$this
->
log
(
__METHOD__
.
" Error while calling ws. Diagnostic:
{
$result
[
'response'
]
}
. Response code:
{
$result
[
'http_status'
]
}
"
,
"error"
);
throw
new
Exception
(
"Προέκυψε λάθος κατά την άντληση των στοιχείων."
);
}
if
((
$response
=
json_decode
(
$result
[
'response'
],
true
))
!==
null
)
{
return
$response
;
}
else
{
$this
->
log
(
__METHOD__
.
" Error while getting data from response
{
$result
[
'response'
]
}
."
,
"error"
);
throw
new
Exception
(
"Προέκυψε λάθος κατά την λήψη των στοιχείων. Αδυναμία άντλησης στοιχείων από την απάντηση."
);
}
}
/**
*
* @param string $endpoint_base_url web service url
* @param int $didactic_year_id {@see getAllDidactiYear()}
* @param string $lastname μόνο χαρακτήρες, κενά και μεσαίες παύλες
* @param string $firstname μόνο χαρακτήρες, κενά και μεσαίες παύλες
* @param string $father_firstname μόνο χαρακτήρες, κενά και μεσαίες παύλες
* @param string $mother_firstname μόνο χαρακτήρες, κενά και μεσαίες παύλες
* @param string $birthdate ημερομηνίες στη μορφή 4-1-1997 (d-M-yyyy)
*
* @return boolean|null
* @throws \Exception Σε περίπτωση οποιουδήποτε λάθους
*/
public
function
getStudentEpalPromotionOrCertification
(
$endpoint_base_url
,
$didactic_year_id
,
$lastname
,
$firstname
,
$father_firstname
,
$mother_firstname
,
$birthdate
,
$registry_no
,
$level_name
)
{
$parts
=
explode
(
'-'
,
$birthdate
,
3
);
if
((
$parts
===
false
)
||
count
(
$parts
)
!=
3
||
checkdate
(
intval
(
$parts
[
1
]),
intval
(
$parts
[
0
]),
intval
(
$parts
[
2
]))
===
false
)
{
$this
->
log
(
__METHOD__
.
" Mallformed birthdate"
,
"error"
);
throw
new
Exception
(
'Η ημερομηνία γέννησης πρέπει να είναι της μορφής Η/Μ/Ε'
,
Response
::
HTTP_BAD_REQUEST
);
}
if
(
mb_strlen
(
$lastname
)
==
0
||
mb_strlen
(
$firstname
)
==
0
||
mb_strlen
(
$father_firstname
)
==
0
||
mb_strlen
(
$mother_firstname
)
==
0
)
{
$this
->
log
(
__METHOD__
.
" Missing parameters"
,
"error"
);
throw
new
Exception
(
'Όλες οι παράμετροι είναι υποχρεωτικοί'
,
Response
::
HTTP_BAD_REQUEST
);
}
$data
=
[
'DidacticYearId'
=>
intval
(
$didactic_year_id
),
'LastName'
=>
$lastname
,
'FirstName'
=>
$firstname
,
'FatherFirstName'
=>
$father_firstname
,
'MotherFirstname'
=>
$mother_firstname
,
'BirthDate'
=>
$birthdate
,
'RegistryNo'
=>
$registry_no
,
'LevelName'
=>
$level_name
];
$headers
=
[
'Accept: application/json'
,
// 'Accept-Language: en-gb',
'Accept-Language: {"Accept-Language":"en-gb"}'
,
// as per spec provided...
'Audience: Any'
,
'Authorization: '
.
$this
->
getTokenBearer
(),
'User-Agent: OSTEAM Client/v1.1 osteam'
];
$endpoint
=
$endpoint_base_url
.
array_reduce
(
$data
,
function
(
$c
,
$v
)
{
$c
.
=
"/"
.
urlencode
(
$v
);
return
$c
;
},
''
);
$result
=
$this
->
get
(
$endpoint
,
[],
$headers
);
// data as path params...
if
(
$result
[
'success'
]
===
false
)
{
$this
->
log
(
__METHOD__
.
" Error while calling ws. Diagnostic:
{
$result
[
'response'
]
}
. Response code:
{
$result
[
'http_status'
]
}
"
,
"error"
);
throw
new
Exception
(
"Προέκυψε λάθος κατά την άντληση των στοιχείων."
);
}
// now return true/false/null ?
return
$result
[
'response'
];
// if (($response = json_decode($result['response'], true)) !== null) {
// return $response;
// } else {
// throw new Exception("Προέκυψε λάθος κατά την λήψη των στοιχείων. Αδυναμία άντλησης στοιχείων από το response {$result['response']}");
// }
}
public
function
getStudentEpalPromotion
(
$didactic_year_id
,
$lastname
,
$firstname
,
$father_firstname
,
$mother_firstname
,
$birthdate
,
$registry_no
,
$level_name
)
{
$this
->
log
(
__METHOD__
);
// " $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name");
return
$this
->
getStudentEpalPromotionOrCertification
(
$this
->
_settings
[
'ws_endpoint_studentepalpromotion'
],
$didactic_year_id
,
$lastname
,
$firstname
,
$father_firstname
,
$mother_firstname
,
$birthdate
,
$registry_no
,
$level_name
);
}
public
function
getStudentEpalCertification
(
$didactic_year_id
,
$lastname
,
$firstname
,
$father_firstname
,
$mother_firstname
,
$birthdate
,
$registry_no
,
$level_name
)
{
$this
->
log
(
__METHOD__
);
// " $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name");
return
$this
->
getStudentEpalPromotionOrCertification
(
$this
->
_settings
[
'ws_endpoint_studentepalcertification'
],
$didactic_year_id
,
$lastname
,
$firstname
,
$father_firstname
,
$mother_firstname
,
$birthdate
,
$registry_no
,
$level_name
);
}
protected
function
setCommonCurlOptions
(
$ch
,
$uri
,
$headers
)
{
curl_setopt
(
$ch
,
CURLOPT_URL
,
$uri
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$headers
);
curl_setopt
(
$ch
,
CURLOPT_USERAGENT
,
"OSTEAM Client/v1.1 osteam"
);
if
(
isset
(
$this
->
_settings
[
'NO_SAFE_CURL'
])
&&
$this
->
_settings
[
'NO_SAFE_CURL'
]
===
true
)
{
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYHOST
,
false
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
false
);
}
curl_setopt
(
$ch
,
CURLOPT_FOLLOWLOCATION
,
true
);
curl_setopt
(
$ch
,
CURLOPT_MAXREDIRS
,
3
);
curl_setopt
(
$ch
,
CURLOPT_CONNECTTIMEOUT
,
5
);
if
(
$this
->
_settings
[
'verbose'
])
{
curl_setopt
(
$ch
,
CURLOPT_VERBOSE
,
true
);
}
}
public
function
post
(
$uri
,
$payload
,
$headers
=
[])
{
$ch
=
curl_init
();
$this
->
setCommonCurlOptions
(
$ch
,
$uri
,
$headers
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
true
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$payload
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
$result
=
curl_exec
(
$ch
);
if
(
curl_errno
(
$ch
))
{
$this
->
log
(
__METHOD__
.
" Error calling
{
$uri
}
. Curl error: "
.
curl_error
(
$ch
)
.
" Curl info: "
.
var_export
(
curl_getinfo
(
$ch
),
true
),
"error"
);
throw
new
Exception
(
"Λάθος κατά την κλήση της υπηρεσίας."
);
}
if
(
intval
((
$http_code
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
))
/
100
)
!=
2
)
{
return
[
'success'
=>
false
,
'http_status'
=>
$http_code
,
'response'
=>
$result
];
}
curl_close
(
$ch
);
return
[
'success'
=>
true
,
'http_status'
=>
$http_code
,
'response'
=>
$result
];
}
public
function
get
(
$uri
,
$params
=
[],
$headers
=
[])
{
$ch
=
curl_init
();
if
(
is_array
(
$params
)
&&
count
(
$params
)
>
0
)
{
$qs
=
'?'
.
http_build_query
(
$params
);
}
else
{
$qs
=
''
;
}
$this
->
setCommonCurlOptions
(
$ch
,
"
{
$uri
}{
$qs
}
"
,
$headers
);
// curl_setopt($ch, CURLOPT_HTTPGET, true); // default
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
$result
=
curl_exec
(
$ch
);
if
(
curl_errno
(
$ch
))
{
$this
->
log
(
__METHOD__
.
" Error calling
{
$uri
}
. Curl error: "
.
curl_error
(
$ch
)
.
" Curl info: "
.
var_export
(
curl_getinfo
(
$ch
),
true
),
"error"
);
throw
new
Exception
(
"Λάθος κατά την κλήση της υπηρεσίας."
);
}
if
(
intval
((
$http_code
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
))
/
100
)
!=
2
)
{
return
[
'success'
=>
false
,
'http_status'
=>
$http_code
,
'response'
=>
$result
];
}
curl_close
(
$ch
);
return
[
'success'
=>
true
,
'http_status'
=>
$http_code
,
'response'
=>
$result
];
}
protected
function
log
(
$msg
,
$level
=
'info'
)
{
if
(
$this
->
logger
!==
null
&&
$this
->
_settings
[
'verbose'
])
{
switch
(
$level
)
{
case
'info'
:
case
'warning'
:
case
'error'
:
$this
->
logger
->
$level
(
$msg
);
break
;
default
:
$this
->
logger
->
error
(
$msg
);
break
;
}
}
return
;
}
}
drupal/modules/epal/src/Controller/DirectorView.php
View file @
a52ded3b
This diff is collapsed.
Click to expand it.
drupal/modules/epal/src/Controller/Distribution.php
View file @
a52ded3b
...
...
@@ -559,9 +559,10 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup,
//Αν δεν απέμειναν θέσεις (δηλαδή αν η χωρητικότητα είναι μικρότερη ή ίση από το πλήθος μαθητών που ήδη φοιτούν στο σχολείο)
//τότε διέγραψέ τους από τον προσωρινό πίνακα αποτελεσμάτων και βάλε τους στον στον πίνακα εκκρεμοτήτων
if
(
$newlimit
<=
0
)
{
foreach
(
$students
as
$student
)
{
foreach
(
$students
as
$student
)
{
if
(
$student
->
currentepal
!==
$student
->
epal_id
)
{
if
(
$newlimit
<=
0
)
{
//print_r("<br>ΣΕ ΕΚΚΡΕΜΟΤΗΤΑ - ΔΙΑΓΡΑΦΗ: " . $student->student_id);
array_push
(
$this
->
pendingStudents
,
$student
->
student_id
);
try
{
...
...
@@ -574,9 +575,27 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup,
$transaction
->
rollback
();
return
ERROR_DB
;
}
}
//end if currentepal
}
//end foreach
}
//endif newlimit
}
//endif new limit
else
{
//$newlimit > 0
//NEW CODE LINES
if
(
$this
->
choice_id
!==
1
)
$this
->
removeFromPendingStudents
(
$student
->
student_id
);
}
//END NEW CODE LINES
}
//endif currentepal
}
//end foreach
//NEW CODE LINES
/*
else {
foreach($students as $student)
if ($student->currentepal !== $student->epal_id)
if ($this->choice_id !== 1)
$this->removeFromPendingStudents($student->student_id);
}
*/
//END NEW CODE LINES
return
SUCCESS
;
...
...
drupal/modules/epal/src/Controller/InformUnlocatedStudents.php
View file @
a52ded3b
...
...
@@ -92,14 +92,15 @@ class InformUnlocatedStudents extends ControllerBase {
$cnt_success
=
0
;
$cnt_fail
=
0
;
// εύρεση μαθητών που η αίτησή τους ΔΕΝ ικανοποιήθηκε
// εύρεση μαθητών που η αίτησή τους ΔΕΝ ικανοποιήθηκε,
//(δεν κατανεμήθηκαν πουθενά)
$sCon
=
$this
->
connection
->
select
(
'epal_student_class'
,
'eStudent'
)
->
fields
(
'eStudent'
,
array
(
'student_id'
))
->
condition
(
'eStudent.finalized'
,
0
,
'='
);
->
fields
(
'eStudent'
,
array
(
'student_id'
))
;
//
->condition('eStudent.finalized', 0 , '=');
$epalStudents
=
$sCon
->
execute
()
->
fetchAll
(
\
PDO
::
FETCH_OBJ
);
$studentIds
=
array
();
//
array_push($studentIds,-1);
array_push
(
$studentIds
,
-
1
);
foreach
(
$epalStudents
as
$epalStudent
)
array_push
(
$studentIds
,
$epalStudent
->
student_id
);
...
...
@@ -107,7 +108,6 @@ class InformUnlocatedStudents extends ControllerBase {
$sCon
=
$this
->
connection
->
select
(
'epal_student'
,
'eStudent'
)
->
fields
(
'eStudent'
,
array
(
'id'
,
'user_id'
,
'created'
))
->
condition
(
'eStudent.id'
,
$studentIds
,
'NOT IN'
);
//$numNoAllocated = $sCon->countQuery()->execute()->fetchField();
$epalNonLocatedStudents
=
$sCon
->
execute
()
->
fetchAll
(
\
PDO
::
FETCH_OBJ
);
foreach
(
$epalNonLocatedStudents
as
$epalNonLocatedStudent
)
{
...
...
@@ -155,6 +155,106 @@ class InformUnlocatedStudents extends ControllerBase {
}
public
function
sendMailToUnallocatedStudentsSC
(
Request
$request
)
{
try
{
if
(
!
$request
->
isMethod
(
'GET'
))
{
return
$this
->
respondWithStatus
([
"message"
=>
t
(
"Method Not Allowed"
)
],
Response
::
HTTP_METHOD_NOT_ALLOWED
);
}
//user validation
$authToken
=
$request
->
headers
->
get
(
'PHP_AUTH_USER'
);
$users
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
loadByProperties
(
array
(
'name'
=>
$authToken
));
$user
=
reset
(
$users
);
if
(
!
$user
)
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"User not found"
),
],
Response
::
HTTP_FORBIDDEN
);
}
//user role validation
$roles
=
$user
->
getRoles
();
$validRole
=
false
;
foreach
(
$roles
as
$role
)
if
(
$role
===
"ministry"
)
{
$validRole
=
true
;
break
;
}
if
(
!
$validRole
)
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"User Invalid Role"
),
],
Response
::
HTTP_FORBIDDEN
);
}
$cnt_success
=
0
;
$cnt_fail
=
0
;
// εύρεση μαθητών που η αίτησή τους ΔΕΝ ικανοποιήθηκε,
//(δεν κατανεμήθηκαν πουθενά)
$sCon
=
$this
->
connection
->
select
(
'epal_student_class'
,
'eStudent'
)
->
fields
(
'eStudent'
,
array
(
'student_id'
))
->
condition
(
'eStudent.finalized'
,
0
,
'='
);
$epalStudents
=
$sCon
->
execute
()
->
fetchAll
(
\
PDO
::
FETCH_OBJ
);
$studentIds
=
array
();
array_push
(
$studentIds
,
-
1
);
foreach
(
$epalStudents
as
$epalStudent
)
array_push
(
$studentIds
,
$epalStudent
->
student_id
);
$sCon
=
$this
->
connection
->
select
(
'epal_student'
,
'eStudent'
)
->
fields
(
'eStudent'
,
array
(
'id'
,
'user_id'
,
'created'
))
->
condition
(
'eStudent.id'
,
$studentIds
,
'IN'
);
$epalNonLocatedStudents
=
$sCon
->
execute
()
->
fetchAll
(
\
PDO
::
FETCH_OBJ
);
foreach
(
$epalNonLocatedStudents
as
$epalNonLocatedStudent
)
{
$epalUsers
=
$this
->
entityTypeManager
->
getStorage
(
'epal_users'
)
->
loadByProperties
(
array
(
'user_id'
=>
$epalNonLocatedStudent
->
user_id
));
$epalUser
=
reset
(
$epalUsers
);
if
(
$epalUser
)
{
$user
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
load
(
$epalUser
->
user_id
->
target_id
);
//$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('uid' => $epalUser->user_id));
//$user = reset($users);
if
(
$user
)
{
$langcode
=
$user
->
getPreferredLangcode
();
if
(
$this
->
sendEmailToUnallocated
(
$user
->
getEmail
(),
$epalNonLocatedStudent
->
id
,
$epalNonLocatedStudent
->
created
,
$langcode
))
$cnt_success
++
;
}
else
{
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"user not found"
),
],
Response
::
HTTP_INTERNAL_SERVER_ERROR
);
}
}
else
{
$cnt_fail
++
;
}
}
//end foreach
return
$this
->
respondWithStatus
([
'message'
=>
t
(
"post successful"
),
'num_success_mail'
=>
$cnt_success
,
'num_fail_mail'
=>
$cnt_fail
,
//'test' => $test,
],
Response
::
HTTP_OK
);
}
//end try
catch
(
\
Exception
$e
)
{
$this
->
logger
->
warning
(
$e
->
getMessage
());
return
$this
->
respondWithStatus
([
"message"
=>
t
(
"An unexpected problem occured during sendMailToStudents Method "
)
],
Response
::
HTTP_INTERNAL_SERVER_ERROR
);
}
}
//sendEmail(e-mail address, A/A, application Date, lang)
private
function
sendEmailToUnallocated
(
$email
,
$appId
,
$appDate
,
$langcode
)
{
$mailManager
=
\
Drupal
::
service
(
'plugin.manager.mail'
);
...
...
@@ -163,9 +263,10 @@ class InformUnlocatedStudents extends ControllerBase {
$key
=
'massive_mail_unallocated'
;
//to be checked..
$to
=
$email
;
$params
[
'message'
]
=
"Σας ενημερώνουμε ότι η αίτησή σας με Α/Α: "
.
$appId
.
" - "
.
date
(
'd-m-y H:i:s'
,
$appDate
)
.
" δεν ικανοποιήθηκε. Παρακαλώ επικοινωνήστε άμεσα τηλεφωνικά με τη Διεύθυνση Δευτεροβάθμιας Εκπαίδευσης / Τμήμα Επαγγελματικής Εκπαίδευσης,"
.
"
\r\n
Τεστ1
\n
Τεστ2"
;
//e-mail body
$params
[
'message'
]
=
"Σας ενημερώνουμε ότι η αίτησή σας με Α/Α: "
.
$appId
.
" / "
.
date
(
'd-m-y H:i:s'
,
$appDate
)
.
" δεν ικανοποιήθηκε. Παρακαλώ επικοινωνήστε άμεσα τηλεφωνικά με τη Διεύθυνση Δευτεροβάθμιας Εκπαίδευσης / Τμήμα Επαγγελματικής Εκπαίδευσης."
.
"
\r\n\r\n
Ομάδα Διαχείρισης της εφαρμογής e-epal."
.
"
\r\n
Προσοχή: το μήνυμα που διαβάζετε είναι αυτοματοποιημένο. Παρακαλώ μην απαντάτε σε αυτό το μήνυμα.."
;
//e-mail body" ;//e-mail body