Remove unnecessary payload

parent 184b525f
......@@ -24,944 +24,903 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface;
class Distribution extends ControllerBase {
const SUCCESS = 0;
const ERROR_DB = -1;
const NO_CLASS_LIMIT_DOWN = -2;
const SMALL_CLASS = 1;
const NON_SMALL_CLASS = 2;
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
protected $language;
protected $currentuser;
protected $pendingStudents = array();
protected $choice_id = 1;
protected $globalCounterId = 1;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
$connection = Database::getConnection();
$this->connection = $connection;
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$this->language = $language;
$currentuser = \Drupal::currentUser()->id();
$this->currentuser = $currentuser;
$this->logger = $loggerChannel->get('epal');
class Distribution extends ControllerBase
{
const SUCCESS = 0;
const ERROR_DB = -1;
const NO_CLASS_LIMIT_DOWN = -2;
const SMALL_CLASS = 1;
const NON_SMALL_CLASS = 2;
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
protected $language;
protected $currentuser;
protected $pendingStudents = array();
protected $choice_id = 1;
protected $globalCounterId = 1;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel
) {
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
$connection = Database::getConnection();
$this->connection = $connection;
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$this->language = $language;
$currentuser = \Drupal::currentUser()->id();
$this->currentuser = $currentuser;
$this->logger = $loggerChannel->get('epal');
}
public static function create(ContainerInterface $container)
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager'),
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
);
}
public function createDistribution(Request $request)
{
public function createDistribution(Request $request) {
$numDistributions = 3;
$sizeOfBlock = 1000000;
// POST method is checked
if (!$request->isMethod('POST')) {
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);
}
$numDistributions = 3;
$sizeOfBlock = 1000000;
// POST method is checked
if (!$request->isMethod('POST')) {
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
if (false === in_array('ministry', $user->getRoles())) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
// check where distribution can be done now ($capacityDisabled / $directorViewDisabled settings)
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
} else {
$capacityDisabled = $epalConfig->lock_school_capacity->getString();
$directorViewDisabled = $epalConfig->lock_school_students_view->getString();
$applicantsResultsDisabled = $epalConfig->lock_results->getString();
if ($capacityDisabled !== "1" || $directorViewDisabled !== "1" || $applicantsResultsDisabled !== "1") {
return $this->respondWithStatus([
'message' => t("capacityDisabled and / or directorViewDisabled settings are false"),
], Response::HTTP_FORBIDDEN);
}
}
$transaction = $this->connection->startTransaction();
try {
// initialize/empty epal_student_class if there are already data in it!
if ($this->initializeResults() === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in initializeResults function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
if (($limitUp_class = $this->retrieveCapacityLimitUp("1")) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in retrieveCapacityLimitUp function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
// print_r("<br> ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitUp_class);
while ($this->choice_id <= $numDistributions) {
if ($this->choice_id === 1) {
// υπολογισμός πλήθους non-finalized δηλώσεων για να καθοριστεί ο αριθμός των fetches που θα κάνουμε με συγκεκριμένο sizeOfBlock
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id'));
$numData = $sCon->countQuery()->execute()->fetchField();
//print_r("<br>numData: " . $numData);
// user role validation
if (false === in_array('ministry', $user->getRoles())) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
// check where distribution can be done now ($capacityDisabled / $directorViewDisabled settings)
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
} else {
$capacityDisabled = $epalConfig->lock_school_capacity->getString();
$directorViewDisabled = $epalConfig->lock_school_students_view->getString();
$applicantsResultsDisabled = $epalConfig->lock_results->getString();
if ($capacityDisabled === "0" || $directorViewDisabled === "0" || $applicantsResultsDisabled === "0") {
$num = 1;
$j = 1;
while ($num <= $numData) {
//print_r("<br>FETCH: " . $j);
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id', 'currentclass', 'currentepal', 'second_period'))
->condition('eStudent.id', 1 + $sizeOfBlock * ($j-1), '>=')
->condition('eStudent.id', $j * $sizeOfBlock, '<=');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if ($this->locateStudent($this->choice_id, $epalStudents) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in locateStudent function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$num = $num + sizeof($epalStudents);
$j = $j + 1;
}
}
else { // $this->choice_id !== 1
if (sizeof($this->pendingStudents) != 0) {
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id', 'currentclass', 'currentepal', 'second_period'))
->condition('eStudent.id', $this->pendingStudents, 'IN');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if ($this->locateStudent($this->choice_id, $epalStudents) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in locateStudent function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
} else { // αν δεν υπάρχουν εκκρεμότητες, μην συνεχίζεις με άλλο πέρασμα
break;
}
}
// Για κάθε σχολείο βρες τα τμήματα
// Για κάθε τμήμα βρες αν χωράνε και διευθέτησε (checkCapacityAndArrange)
// checkCapacityAndArrange (school_id, class_id, sectorORcourse_id, limitUp, schoolCapacity)
$sCon = $this->connection->select('eepal_school_field_data', 'eSchool')
->fields('eSchool', array('id', 'capacity_class_a', 'operation_shift'));
$eepalSchools = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSchools as $eepalSchool) {
if ($this->checkCapacityAndArrange($eepalSchool->id, "1", "-1", $limitUp_class, $eepalSchool->capacity_class_a) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$sCon = $this->connection->select('eepal_sectors_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'sector_id', 'capacity_class_sector'))
->condition('eSchool.epal_id', $eepalSchool->id, '=');
$eepalSectorsInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSectorsInEpal as $eepalSecInEp) {
if ($this->checkCapacityAndArrange($eepalSchool->id, "2", $eepalSecInEp->sector_id, $limitUp_class, $eepalSecInEp->capacity_class_sector) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
$sCon = $this->connection->select('eepal_specialties_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'specialty_id', 'capacity_class_specialty'))
->condition('eSchool.epal_id', $eepalSchool->id, '=');
$eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
//Γ' Λυκείου
if ($this->checkCapacityAndArrange($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
//Δ' Λυκείου
if ($eepalSchool->operation_shift === "ΕΣΠΕΡΙΝΟ") {
if ($this->checkCapacityAndArrange($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}
} //end for each school/department
$this->choice_id++;
} //end while
if ($this->findSmallClasses() === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([
'message' => t("capacityDisabled and / or directorViewDisabled settings are false"),
], Response::HTTP_FORBIDDEN);
}
}
"message" => t("Unexpected Error in findSmallClasses function AFTER initial Distribution!")
], Response::HTTP_INTERNAL_SERVER_ERROR);
// αν αποτύχει, δεν γίνεται rollback. --> Λύση: διαγραφή των όποιων αποτελεσμάτων
// if ($this->initializeResults() === self::ERROR_DB) {
// return $this->respondWithStatus([
// "message" => t("Unexpected Error in initializeResults function AFTER findSmallClasses call Function")
// ], Response::HTTP_INTERNAL_SERVER_ERROR);
// }
}
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("An unexpected problem occured in createDistribution Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$transaction = $this->connection->startTransaction();
return $this->respondWithStatus([
'message' => "Distribution has made successfully",
], Response::HTTP_OK);
}
try {
// initialize/empty epal_student_class if there are already data in it!
if ($this->initializeResults() === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in initializeResults function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
if (($limitUp_class = $this->retrieveCapacityLimitUp("1")) === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in retrieveCapacityLimitUp function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
// print_r("<br> ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitUp_class);
public function locateStudent($choice_id, &$epalStudents)
{
$numData = 0;
while ($this->choice_id <= $numDistributions) {
$epal_dist_id = -1;
$specialization_id = -1;
$transaction = $this->connection->startTransaction(); // TODO CHECK
try {
foreach ($epalStudents as $epalStudent) {
//print_r("<br>ΚΑΤΑΝΟΜΗ ΜΑΘΗΤΩΝ ΝΟ: " . $choice_id);
//print_r("<br>ΜΑΘΗΤΗΣ: " . $epalStudent->id);
$clCon = $this->connection->select('epal_student_epal_chosen', 'epals')
->fields('epals', array('student_id', 'epal_id', 'choice_no'))
->condition('epals.student_id', $epalStudent->id, '=')
->condition('epals.choice_no', $choice_id, '=');
$epalSchoolsChosen = $clCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if (sizeof($epalSchoolsChosen) !== 0) {
$epalSchoolChos = reset($epalSchoolsChosen);
//print_r(" SCHOOL_ID:" . $epalSchoolChos->epal_id . " STUDENT_ID " . $epalStudent->id);
$epal_dist_id = $epalSchoolChos->epal_id;
if ($epalStudent->currentclass === "2") {
$clCon = $this->connection->select('epal_student_sector_field', 'sectors')
->fields('sectors', array('student_id', 'sectorfield_id'))
->condition('sectors.student_id', $epalStudent->id, '=');
$epalSectorChosen = $clCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$epalSecChos = reset($epalSectorChosen);
} //Δ'Λυκείου - Γ' Λυκείου
elseif ($epalStudent->currentclass === "3" || $epalStudent->currentclass === "4") {
$clCon = $this->connection->select('epal_student_course_field', 'courses')
->fields('courses', array('student_id', 'coursefield_id'))
->condition('courses.student_id', $epalStudent->id, '=');
$epalCourseChosen = $clCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$epalCourChos = reset($epalCourseChosen);
}
if ($epalStudent->currentclass === "2") {
$specialization_id = $epalSecChos->sectorfield_id;
} //Δ'Λυκείου - Γ' Λυκείου
elseif ($epalStudent->currentclass === "3" || $epalStudent->currentclass === "4") {
$specialization_id = $epalCourChos->coursefield_id;
} else {
$specialization_id = -1;
}
$timestamp = strtotime(date("Y-m-d"));
$this->connection->insert('epal_student_class')->fields(
array('id' => $this->globalCounterId++,
'uuid' => \Drupal::service('uuid')->generate(),
'langcode' => $this->language,
'user_id' => $this->currentuser,
'student_id'=> $epalStudent->id,
'epal_id'=> $epal_dist_id,
'currentclass' => $epalStudent->currentclass,
'currentepal' => $epalStudent->currentepal,
'specialization_id' => $specialization_id,
//'points' => $epalStudent->points,
'distribution_id' => $choice_id,
'finalized' => 1,
'second_period' => $epalStudent->second_period,
'status' => 1,
'created' => $timestamp,
'changed' => $timestamp,)
)->execute();
} //end if
} //foreach
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB;
}
return self::SUCCESS;
}
// υπολογισμός πλήθους non-finalized δηλώσεων για να καθοριστεί ο αριθμός των fetches που θα κάνουμε με συγκεκριμένο sizeOfBlock
if ($this->choice_id === 1) {
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id'));
$numData = $sCon->countQuery()->execute()->fetchField();
//print_r("<br>numData: " . $numData);
}
$j = 1;
$num = 1;
if ($this->choice_id === 1) {
while ($num <= $numData) {
//print_r("<br>FETCH: " . $j);
$sCon = $this->connection->select('epal_student', 'eStudent')
//->fields('eStudent', array('id', 'name', 'currentclass', 'currentepal', 'points'))
->fields('eStudent', array('id', 'currentclass', 'currentepal', 'second_period'))
->condition('eStudent.id', 1 + $sizeOfBlock * ($j-1), '>=')
->condition('eStudent.id', $j * $sizeOfBlock, '<=');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if ($this->locateStudent($this->choice_id, $epalStudents) === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in locateStudent function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$num = $num + sizeof($epalStudents);
$j = $j + 1;
}
} else { // $this->choice_id !== 1
if (sizeof($this->pendingStudents) != 0) {
$sCon = $this->connection->select('epal_student', 'eStudent')
//->fields('eStudent', array('id', 'name', 'currentclass', 'currentepal', 'points'))
->fields('eStudent', array('id', 'currentclass', 'currentepal', 'second_period'))
->condition('eStudent.id', $this->pendingStudents, 'IN');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if ($this->locateStudent($this->choice_id, $epalStudents) === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in locateStudent function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
} else { // αν δεν υπάρχουν εκκρεμότητες, μην συνεχίζεις με άλλο πέρασμα
break;
}
}
// Για κάθε σχολείο βρες τα τμήματα
// Για κάθε τμήμα βρες αν χωράνε και διευθέτησε (checkCapacityAndArrange)
// checkCapacityAndArrange (school_id, class_id, sectorORcourse_id, limitUp, schoolCapacity)
$sCon = $this->connection->select('eepal_school_field_data', 'eSchool')
->fields('eSchool', array('id', 'capacity_class_a', 'operation_shift'));
$eepalSchools = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSchools as $eepalSchool) {
if ($this->checkCapacityAndArrange($eepalSchool->id, "1", "-1", $limitUp_class, $eepalSchool->capacity_class_a) === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$sCon = $this->connection->select('eepal_sectors_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'sector_id', 'capacity_class_sector'))
->condition('eSchool.epal_id', $eepalSchool->id, '=');
$eepalSectorsInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSectorsInEpal as $eepalSecInEp) {
if ($this->checkCapacityAndArrange($eepalSchool->id, "2", $eepalSecInEp->sector_id, $limitUp_class, $eepalSecInEp->capacity_class_sector) === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
$sCon = $this->connection->select('eepal_specialties_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'specialty_id', 'capacity_class_specialty'))
->condition('eSchool.epal_id', $eepalSchool->id, '=');
$eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
//Γ' Λυκείου
if ($this->checkCapacityAndArrange($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty) === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
//Δ' Λυκείου
if ($eepalSchool->operation_shift === "ΕΣΠΕΡΙΝΟ") {
if ($this->checkCapacityAndArrange($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id, $limitUp_class, $eepalSpecialInEp->capacity_class_specialty) === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in checkCapacityAndArrange function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}
} //end for each school/department
$this->choice_id++;
} //end while
if ($this->findSmallClasses() === self::ERROR_DB) {
return $this->respondWithStatus([
"message" => t("Unexpected Error in findSmallClasses function AFTER initial Distribution!")
], Response::HTTP_INTERNAL_SERVER_ERROR);
//αν αποτύχει, δεν γίνεται rollback. --> Λύση: διαγρα΄φή των όποιων αποτελεσμάτων
if ($this->initializeResults() === self::ERROR_DB)
return $this->respondWithStatus([
"message" => t("Unexpected Error in initializeResults function AFTER findSmallClasses call Function")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
public function retrieveCapacityLimitUp($className)
{
$transaction = $this->connection->startTransaction();
try {
$clCon = $this->connection->select('epal_class_limits', 'classLimits')
->fields('classLimits', array('limit_up'))
->condition('classLimits.name', $className, '=');
$results = $clCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$row = reset($results);
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB;
}
return $row->limit_up;
}
} //end try
public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, $capacity)
{
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("An unexpected problem occured in createDistribution Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
if (!isset($capacity)) {
//print_r("<br> ΜΠΗΚΑ!!! ");
//print_r("<br> ΣΧΟΛΕΙΟ: " . $epalId . " ΤΑΞΗ: " . $classId . " ΤΟΜΕΑΣ/ΕΙΔΙΚΟΤΗΤΑ: " . $secCourId . " ΧΩΡΗΤΙΚΟΤΗΤΑ: " . $capacity);
$capacity = 0;
}
$transaction = $this->connection->startTransaction();
try {
$clCon = $this->connection->select('epal_student_class', 'studentClass')
->fields('studentClass', array('epal_id', 'student_id', 'points', 'currentepal', 'currentclass', 'specialization_id'))
->condition('studentClass.epal_id', $epalId, '=')
->condition('studentClass.currentclass', $classId, '=')
->condition('studentClass.specialization_id', $secCourId, '=');
$epalStudentClass = $clCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$limit = $limitup * $capacity;
if (sizeof($epalStudentClass) > $limit) {
//print_r("<br>ΥΠΕΡΧΕΙΛΙΣΗ!");
//foreach ($epalStudentClass as $epalStudCl) {
//Υπολογισμός μορίων του μαθητή και (πιθανή) αποθήκευσή τους
//ΣΗΜΕΙΩΣΗ: Ο υπoλογισμός γίνεται στο front-end
//}
$this->makeSelectionOfStudents($epalStudentClass, $limit);
} else { //αφαίρεσε όσους μαθητές βρίσκονται στον πίνακα εκκρεμοτήτων
foreach ($epalStudentClass as $epalStudCl) {
if ($this->choice_id !== 1) {
////διέγραψε τον μαθητή από τον πίνακα εκκρεμοτήτων (αν βρίσκεται εκεί)
$this->removeFromPendingStudents($epalStudCl->student_id);
}
}
}
} // end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB;
}
return self::SUCCESS;
}
$postData = null;
if ($content = $request->getContent()) {
$postData = json_decode($content);
return $this->respondWithStatus([
'message' => "Distribution has made successfully",
], Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("post with no data"),
], Response::HTTP_BAD_REQUEST);
}
}
public function removeFromPendingStudents($val)
{
if (($key = array_search($val, $this->pendingStudents)) !== false) {
unset($this->pendingStudents[$key]);
}
//$this->pendingStudents = array_diff($this->pendingStudents, array($val));