updated several Controllers in Drupal

parent 4221a15c
...@@ -46,10 +46,15 @@ function epal_mail($key, &$message, $params) { ...@@ -46,10 +46,15 @@ function epal_mail($key, &$message, $params) {
$message['subject'] = t('Σύστημα υποβολής αιτήσεων εγγραφής σε ΕΠΑΛ: Επιβεβαίωση e-mail', $options); $message['subject'] = t('Σύστημα υποβολής αιτήσεων εγγραφής σε ΕΠΑΛ: Επιβεβαίωση e-mail', $options);
$message['body'][] = $params['message']; $message['body'][] = $params['message'];
break; break;
case 'massive_mail': case 'massive_mail_unallocated':
$message['from'] = \Drupal::config('system.site')->get('mail'); $message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Μη ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options); $message['subject'] = t('Μη ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options);
$message['body'][] = $params['message']; $message['body'][] = $params['message'];
break; break;
case 'massive_mail_located':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options);
$message['body'][] = $params['message'];
break;
} }
} }
...@@ -73,7 +73,7 @@ epal.application_submit: ...@@ -73,7 +73,7 @@ epal.application_submit:
epal.allocation: epal.allocation:
path: '/epal/distribution' path: '/epal/distribution'
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
defaults: defaults:
_controller: '\Drupal\epal\Controller\Distribution::createDistribution' _controller: '\Drupal\epal\Controller\Distribution::createDistribution'
requirements: requirements:
...@@ -151,7 +151,7 @@ epal.ministry.report-completeness: ...@@ -151,7 +151,7 @@ epal.ministry.report-completeness:
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.report-all-stat: epal.ministry.report-all-stat:
path: '/ministry/report-all-stat/{regionId}/{adminId}/{schId}/{classId}/{sectorId}/{courseId}' path: '/ministry/report-all-stat/{regionId}/{adminId}/{schId}/{classId}/{sectorId}/{courseId}/{finalized}'
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
defaults: defaults:
...@@ -174,12 +174,20 @@ epal.ministry.retrieve-registry-id: ...@@ -174,12 +174,20 @@ epal.ministry.retrieve-registry-id:
_controller: '\Drupal\epal\Controller\ReportsCreator::retrieveUserRegistryNo' _controller: '\Drupal\epal\Controller\ReportsCreator::retrieveUserRegistryNo'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.massive_mail: epal.ministry.massive_mail_unallocated:
path: '/ministry/send-massive-mail' path: '/ministry/send-unallocated-massive-mail'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudents'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail_located:
path: '/ministry/send-located-massive-mail'
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
defaults: defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToStudents' _controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToLocatedStudents'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.retrievesettings: epal.ministry.retrievesettings:
...@@ -246,5 +254,3 @@ gettypeofschool: ...@@ -246,5 +254,3 @@ gettypeofschool:
_controller: '\Drupal\epal\Controller\DirectorView::gettypeofschool' _controller: '\Drupal\epal\Controller\DirectorView::gettypeofschool'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Contains \Drupal\query_example\Controller\QueryExampleController. * Contains \Drupal\query_example\Controller\QueryExampleController.
*/ */
namespace Drupal\epal\Controller; namespace Drupal\epal\Controller;
use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Entity\Query\QueryFactory;
...@@ -24,6 +25,12 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp; ...@@ -24,6 +25,12 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
define("SUCCESS", 0);
define("ERROR_DB", -1);
define("NO_CLASS_LIMIT_DOWN", -2);
define("SMALL_CLASS", 1);
define("NON_SMALL_CLASS", 2);
class Distribution extends ControllerBase { class Distribution extends ControllerBase {
protected $entity_query; protected $entity_query;
...@@ -68,9 +75,15 @@ class Distribution extends ControllerBase { ...@@ -68,9 +75,15 @@ class Distribution extends ControllerBase {
public function createDistribution(Request $request) { public function createDistribution(Request $request) {
//$this->findSmallClasses();
//return;
$numDistributions = 3; $numDistributions = 3;
$sizeOfBlock = 100000; $sizeOfBlock = 100000;
//POST method is checked //POST method is checked
if (!$request->isMethod('POST')) { if (!$request->isMethod('POST')) {
return $this->respondWithStatus([ return $this->respondWithStatus([
...@@ -101,6 +114,7 @@ class Distribution extends ControllerBase { ...@@ -101,6 +114,7 @@ class Distribution extends ControllerBase {
'message' => t("User Invalid Role"), 'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
//check where distribution can be done now ($capacityDisabled / $directorViewDisabled settings) //check where distribution can be done now ($capacityDisabled / $directorViewDisabled settings)
$capacityDisabled = false; $capacityDisabled = false;
...@@ -188,9 +202,7 @@ class Distribution extends ControllerBase { ...@@ -188,9 +202,7 @@ class Distribution extends ControllerBase {
//checkCapacityAndArrange (school_id, class_id, sectorORcourse_id, limitUp, schoolCapacity) //checkCapacityAndArrange (school_id, class_id, sectorORcourse_id, limitUp, schoolCapacity)
$sCon = $this->connection->select('eepal_school_field_data', 'eSchool') $sCon = $this->connection->select('eepal_school_field_data', 'eSchool')
->fields('eSchool', array('id', 'capacity_class_a')); ->fields('eSchool', array('id', 'capacity_class_a', 'operation_shift'));
//->condition('eSchool.id', 151, '>=')
//->condition('eSchool.id', 153, '<='); //προσαρμοσμένο για τα demo data --> να αλλάξει
$eepalSchools = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $eepalSchools = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSchools as $eepalSchool) { foreach ($eepalSchools as $eepalSchool) {
...@@ -212,7 +224,9 @@ class Distribution extends ControllerBase { ...@@ -212,7 +224,9 @@ class Distribution extends ControllerBase {
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) { foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
$this->checkCapacityAndArrange($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty); $this->checkCapacityAndArrange($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty);
//Δ' Λυκείου //Δ' Λυκείου
$this->checkCapacityAndArrange($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty); if ($eepalSchool->operation_shift === "ΕΣΠΕΡΙΝΟ") {
$this->checkCapacityAndArrange($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty);
}
} }
} //end for each school/department } //end for each school/department
...@@ -221,6 +235,7 @@ class Distribution extends ControllerBase { ...@@ -221,6 +235,7 @@ class Distribution extends ControllerBase {
} //end while } //end while
$this->findSmallClasses();
} //end try } //end try
...@@ -232,14 +247,6 @@ class Distribution extends ControllerBase { ...@@ -232,14 +247,6 @@ class Distribution extends ControllerBase {
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
} }
//return new RedirectResponse($this->redirectUrl . '?auth_token=' . $epalToken.'&auth_role=director', 302, []);
//return new RedirectResponse("../eepal/dist/#/minister/minister-view");
/*
return $this->respondWithStatus([
"message" => t("Distribution has made successfully")
], Response::HTTP_OK);
*/
$postData = null; $postData = null;
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$postData = json_decode($content); $postData = json_decode($content);
...@@ -305,7 +312,6 @@ class Distribution extends ControllerBase { ...@@ -305,7 +312,6 @@ class Distribution extends ControllerBase {
$specialization_id = -1; $specialization_id = -1;
//$currentTime = \Drupal\Core\TypedData\Plugin\DataType\TimeStamp::getDateTime();
$timestamp = strtotime(date("Y-m-d")); $timestamp = strtotime(date("Y-m-d"));
$this->connection->insert('epal_student_class')->fields( $this->connection->insert('epal_student_class')->fields(
array('id' => $this->globalCounterId++, array('id' => $this->globalCounterId++,
...@@ -319,6 +325,7 @@ class Distribution extends ControllerBase { ...@@ -319,6 +325,7 @@ class Distribution extends ControllerBase {
'specialization_id' => $specialization_id, 'specialization_id' => $specialization_id,
'points' => $epalStudent->points, 'points' => $epalStudent->points,
'distribution_id' => $choice_id, 'distribution_id' => $choice_id,
'finalized' => 1,
'status' => 1, 'status' => 1,
'created' => $timestamp, 'created' => $timestamp,
'changed' => $timestamp,) 'changed' => $timestamp,)
...@@ -367,7 +374,14 @@ class Distribution extends ControllerBase { ...@@ -367,7 +374,14 @@ class Distribution extends ControllerBase {
return $row->limit_up; return $row->limit_up;
} }
public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, $capacity) {
public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, $capacity) {
if (!isset($capacity)) {
//print_r("<br> ΜΠΗΚΑ!!! ");
//print_r("<br> ΣΧΟΛΕΙΟ: " . $epalId . " ΤΑΞΗ: " . $classId . " ΤΟΜΕΑΣ/ΕΙΔΙΚΟΤΗΤΑ: " . $secCourId . " ΧΩΡΗΤΙΚΟΤΗΤΑ: " . $capacity);
$capacity = 0;
}
$transaction = $this->connection->startTransaction(); $transaction = $this->connection->startTransaction();
...@@ -451,11 +465,10 @@ class Distribution extends ControllerBase { ...@@ -451,11 +465,10 @@ class Distribution extends ControllerBase {
//$this->pendingStudents = array_diff($this->pendingStudents, array($val)); //$this->pendingStudents = array_diff($this->pendingStudents, array($val));
} }
public function makeSelectionOfStudents(&$students, $limit) { public function makeSelectionOfStudents_VERSION_WITH_POINTS(&$students, $limit) {
//συνάρτηση επιλογής μαθητών σε περίπτωση υπερχείλισης //συνάρτηση επιλογής μαθητών σε περίπτωση υπερχείλισης
// (1) έχουν απόλυτη προτεραιότητα όσοι ήδη φοιτούσαν στο σχολείο (σε περίπτωση που φοιτούσαν περισσότεροι από την χωρητικότητα, τους δεχόμαστε όλους) // (1) έχουν απόλυτη προτεραιότητα όσοι ήδη φοιτούσαν στο σχολείο (σε περίπτωση που φοιτούσαν περισσότεροι από την χωρητικότητα, τους δεχόμαστε όλους)
// (2) αν απομένουν κενές θέσεις, επέλεξε από τους εναπομείναντες μαθητές αυτούς με τα περισσότερα μόρια. Σε περίπτωση ισοβαθμίας δεχόμαστε όλους όσους ισοβαθμούν. // (2) αν απομένουν κενές θέσεις, επέλεξε από τους εναπομείναντες μαθητές αυτούς με τα περισσότερα μόρια. Σε περίπτωση ισοβαθμίας δεχόμαστε όλους όσους ισοβαθμούν.
//αυτοδίκαια έχουν προτεραιότητα όσοι ήδη φοιτούσαν στο σχολείο
foreach($students as $student) { foreach($students as $student) {
$student->student_id; $student->student_id;
...@@ -525,6 +538,66 @@ class Distribution extends ControllerBase { ...@@ -525,6 +538,66 @@ class Distribution extends ControllerBase {
], Response::HTTP_OK); ], Response::HTTP_OK);
} }
public function makeSelectionOfStudents(&$students, $limit) {
//συνάρτηση επιλογής μαθητών σε περίπτωση υπερχείλισης
// (1) έχουν απόλυτη προτεραιότητα όσοι ήδη φοιτούσαν στο σχολείο (σε περίπτωση που φοιτούσαν περισσότεροι από την χωρητικότητα, τους δεχόμαστε όλους)
// (2) αν απομένουν κενές θέσεις,...τοποθέτησε και όλους τους άλλους!!.
//εύρεση αριθμού μαθητών που ήδη φοιτούσαν στο σχολείο
$cnt = 0;
foreach($students as $student) {
if ($student->currentepal === $student->epal_id) {
$cnt++;
if ($this->choice_id !== 1)
//διέγραψε τον μαθητή από τον πίνακα εκκρεμοτήτων (αν βρίσκεται εκεί)
//Κάτι τέτοιο δεν είναι δυνατό πια! (έκδοση χωρίς μόρια..)
$this->removeFromPendingStudents($student->student_id);
}
}
//print_r("<br>#ΕΓΓΡΑΦΩΝ ΠΟΥ ΟΙ ΜΑΘΗΤΕΣ ΦΟΙΤΟΥΣΑΝ ΗΔΗ:" . $cnt);
$newlimit = $limit - $cnt;
//print_r("<br>ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ:" . $limit);
$transaction = $this->connection->startTransaction();
//Αν δεν απέμειναν θέσεις (δηλαδή αν η χωρητικότητα είναι μικρότερη ή ίση από το πλήθος μαθητών που ήδη φοιτούν στο σχολείο)
//τότε διέγραψέ τους από τον προσωρινό πίνακα αποτελεσμάτων και βάλε τους στον στον πίνακα εκκρεμοτήτων
if ($newlimit <= 0) {
foreach($students as $student) {
if ($student->currentepal !== $student->epal_id) {
//print_r("<br>ΣΕ ΕΚΚΡΕΜΟΤΗΤΑ - ΔΙΑΓΡΑΦΗ: " . $student->student_id);
array_push($this->pendingStudents, $student->student_id);
try {
$this->connection->delete('epal_student_class')
->condition('student_id', $student->student_id)
->execute();
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("An unexpected problem occured during DELETE proccess in makeSelectionOfStudents Method of Distribution")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
} //end if currentepal
} //end foreach
} //endif newlimit
return $this->respondWithStatus([
"message" => t("makeSelectionOfStudents Method of Distribution has made successfully")
], Response::HTTP_OK);
} //end function
public function calculatePoints() { public function calculatePoints() {
return rand(0,20); return rand(0,20);
...@@ -537,7 +610,7 @@ class Distribution extends ControllerBase { ...@@ -537,7 +610,7 @@ class Distribution extends ControllerBase {
return $res; return $res;
} }
private function initializeResults() { private function initializeResults() {
//initialize/empty epal_student_class if there are already data in it! //initialize/empty epal_student_class if there are already data in it!
try { try {
...@@ -549,11 +622,169 @@ class Distribution extends ControllerBase { ...@@ -549,11 +622,169 @@ class Distribution extends ControllerBase {
"message" => t("An unexpected problem occured during initializeResults Method of Distribution") "message" => t("An unexpected problem occured during initializeResults Method of Distribution")
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
} }
}
private function findSmallClasses() {
//Για κάθε σχολείο βρες τα ολιγομελή τμήματα
$sCon = $this->connection->select('eepal_school_field_data', 'eSchool')
->fields('eSchool', array('id', 'metathesis_region','operation_shift'));
$eepalSchools = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSchools as $eepalSchool) {
//isSmallClass (school_id, class_id, sectorORcourse_id, school_category_metathesis)
// Α' τάξη
if ($this->isSmallClass($eepalSchool->id, "1", "-1", $eepalSchool->metathesis_region) === SMALL_CLASS) {
//print_r("<br> ΚΛΗΣΗ markStudentsInSmallClass: SCHOOL_ID: " . $eepalSchool->id . " CLASSID: " . "1 " . "SECTOR/COURSE ID: " . "-1 ");
if ($this->markStudentsInSmallClass($eepalSchool->id, "1", "-1") === ERROR_DB )
return ERROR_DB;
}
//print_r("<br>");
// Β' τάξη
$sCon = $this->connection->select('eepal_sectors_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'sector_id'))
->condition('eSchool.epal_id', $eepalSchool->id, '=');
$eepalSectorsInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSectorsInEpal as $eepalSecInEp) {
if ($this->isSmallClass($eepalSchool->id, "2", $eepalSecInEp->sector_id, $eepalSchool->metathesis_region) === SMALL_CLASS) {
//print_r("<br> ΚΛΗΣΗ markStudentsInSmallClass: SCHOOL_ID: " . $eepalSchool->id . " CLASSID: " . "2 " . "SECTOR/COURSE ID: " . $eepalSecInEp->sector_id);
if ($this->markStudentsInSmallClass($eepalSchool->id, "2", $eepalSecInEp->sector_id) === ERROR_DB )
return ERROR_DB;
}
//print_r("<br>");
}
// Γ' τάξη
$sCon = $this->connection->select('eepal_specialties_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'specialty_id'))
->condition('eSchool.epal_id', $eepalSchool->id, '=');
$eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
if ($this->isSmallClass($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id, $eepalSchool->metathesis_region) === SMALL_CLASS) {
//print_r("<br> ΚΛΗΣΗ markStudentsInSmallClass: SCHOOL_ID: " . $eepalSchool->id . " CLASSID: " . "3 " . "SECTOR/COURSE ID: " . $eepalSpecialInEp->specialty_id);
if ($this->markStudentsInSmallClass($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id) === ERROR_DB )
return ERROR_DB;
}
//print_r("<br>");
}
// Δ' τάξη
if ($eepalSchool->operation_shift === "ΕΣΠΕΡΙΝΟ") {
$sCon = $this->connection->select('eepal_specialties_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'specialty_id'))
->condition('eSchool.epal_id', $eepalSchool->id, '=');
$eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
if ($this->isSmallClass($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id, $eepalSchool->metathesis_region) === SMALL_CLASS) {
//print_r("<br> ΚΛΗΣΗ markStudentsInSmallClass: SCHOOL_ID: " . $eepalSchool->id . " CLASSID: " . "4 " . "SECTOR/COURSE ID: " . $eepalSpecialInEp->specialty_id);
if ($this->markStudentsInSmallClass($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id) === ERROR_DB )
return ERROR_DB;
}
//print_r("<br>");
}
} //end if ΕΣΠΕΡΙΝΟ
} //end for each school/department
} //end function
private function isSmallClass($schoolId, $classId, $sectorOrcourseId, $regionId) {
//print_r("<br> ΚΛΗΣΗ isSmallClass: SCHOOL_ID: " . $schoolId . " CLASSID: " . $classId . "SECTOR/COURSE ID: " . $sectorOrcourseId . "ΠΕΡΙΟΧΗ ΜΕΤΑΘΕΣΗΣ: " . $regionId);
$limitDown = $this->retrieveLimitDown($classId, $regionId);
//print_r("<br> ΚΑΤΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitDown);
if ($limitDown === NO_CLASS_LIMIT_DOWN)
return NO_CLASS_LIMIT_DOWN;
else if ($limitDown === ERROR_DB)
return ERROR_DB;
$numStudents = $this->countStudents($schoolId, $classId, $sectorOrcourseId);
//print_r("<br> ΑΡΙΘΜΟΣ ΜΑΘΗΤΩΝ: " . $numStudents);
if ($numStudents === ERROR_DB)
return ERROR_DB;
//Αν $numStudents == 0, γύρισε fasle, ώστε να μη γίνει περιττή κλήση στην markStudentsInSmallClass
if ( ($numStudents < $limitDown) && ($numStudents > 0) )
return SMALL_CLASS;
else
return NON_SMALL_CLASS;
}
private function retrieveLimitDown($classId, $regionId) {
try {
$sCon = $this->connection->select('epal_class_limits', 'eClassLimit')
->fields('eClassLimit', array('limit_down'))
->condition('eClassLimit.name', $classId, '=')
->condition('eClassLimit.category', $regionId, '=');
$classLimits = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if (sizeof($classLimits) === 1) {
$classLimit = reset($classLimits);
return $classLimit->limit_down;
}
else {
return NO_CLASS_LIMIT_DOWN;
}
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return ERROR_DB;
}
} //end function
private function countStudents($schoolId, $classId, $sectorOrcourseId) {
try {
$sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('id'))
->condition('eStudent.epal_id', $schoolId , '=')
->condition('eStudent.currentclass', $classId , '=')
->condition('eStudent.specialization_id', $sectorOrcourseId , '=');
return $sCon->countQuery()->execute()->fetchField();
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return ERROR_DB;
} }
}
private function markStudentsInSmallClass($schoolId, $classId, $sectorOrcourseId) {
try {
$query = $this->connection->update('epal_student_class');
$query->fields([
'finalized' => 0,
]);
$query->condition('epal_id', $schoolId);
$query->condition('currentclass', $classId);
if ($sectorOrcourseId !== "-1")
$query->condition('specialization_id', $sectorOrcourseId);
$query->execute();
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return ERROR_DB;
}
return SUCCESS;
}
......
...@@ -56,7 +56,7 @@ class InformUnlocatedStudents extends ControllerBase { ...@@ -56,7 +56,7 @@ class InformUnlocatedStudents extends ControllerBase {
} }
public function sendMailToStudents(Request $request) { public function sendMailToUnallocatedStudents(Request $request) {
try { try {
if (!$request->isMethod('GET')) { if (!$request->isMethod('GET')) {
...@@ -89,21 +89,26 @@ class InformUnlocatedStudents extends ControllerBase { ...@@ -89,21 +89,26 @@ class InformUnlocatedStudents extends ControllerBase {
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
$cnt_success = 0;
$cnt_fail = 0;
// εύρεση μαθητών που η αίτησή τους ΔΕΝ ικανοποιήθηκε // εύρεση μαθητών που η αίτησή τους ΔΕΝ ικανοποιήθηκε
$sCon = $this->connection->select('epal_student_class', 'eStudent') $sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('student_id')); ->fields('eStudent', array('student_id'));
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$studentIds = array(); $studentIds = array();
//array_push($studentIds,-1);
foreach ($epalStudents as $epalStudent) foreach ($epalStudents as $epalStudent)
array_push($studentIds, $epalStudent->student_id); array_push($studentIds, $epalStudent->student_id);
$sCon = $this->connection->select('epal_student', 'eStudent') $sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id', 'user_id', 'created')) ->fields('eStudent', array('id', 'user_id', 'created'))
->condition('eStudent.id', $studentIds, 'NOT IN'); ->condition('eStudent.id', $studentIds, 'NOT IN');
//$numNoAllocated = $sCon->countQuery()->execute()->fetchField(); //$numNoAllocated = $sCon->countQuery()->execute()->fetchField();
$epalNonLocatedStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $epalNonLocatedStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$cnt_success = 0;
$cnt_fail = 0;
foreach ($epalNonLocatedStudents as $epalNonLocatedStudent) { foreach ($epalNonLocatedStudents as $epalNonLocatedStudent) {
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('user_id' => $epalNonLocatedStudent->user_id)); $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('user_id' => $epalNonLocatedStudent->user_id));
$epalUser = reset($epalUsers); $epalUser = reset($epalUsers);
...@@ -114,7 +119,7 @@ class InformUnlocatedStudents extends ControllerBase { ...@@ -114,7 +119,7 @@ class InformUnlocatedStudents extends ControllerBase {
//$user = reset($users); //$user = reset($users);
if ($user) { if ($user) {
$langcode = $user->getPreferredLangcode(); $langcode = $user->getPreferredLangcode();
if ($this->sendEmail($user->getEmail(), $epalNonLocatedStudent->id, $epalNonLocatedStudent->created, $langcode)) if ($this->sendEmailToUnallocated($user->getEmail(), $epalNonLocatedStudent->id, $epalNonLocatedStudent->created, $langcode))
$cnt_success++; $cnt_success++;
} }
else { else {
...@@ -124,15 +129,10 @@ class InformUnlocatedStudents extends ControllerBase { ...@@ -124,15 +129,10 @@ class InformUnlocatedStudents extends ControllerBase {
} }
} else { } else {
/*
return $this->respondWithStatus([