From 698e4e7b4422eb9a6be506a0e35a4472796f209d Mon Sep 17 00:00:00 2001 From: Nikos Date: Thu, 15 Jun 2017 20:03:55 +0300 Subject: [PATCH] updated Distribution Controller with second Period distribution --- .../epal/src/Controller/Distribution.php | 91 ++++++++++++++----- .../epal/src/Controller/ReportsCreator.php | 26 +++++- .../minister/minister-informstudents.ts | 4 + .../components/minister/minister-reports.ts | 4 +- source/components/minister/minister-view.ts | 5 +- 5 files changed, 98 insertions(+), 32 deletions(-) diff --git a/drupal/modules/epal/src/Controller/Distribution.php b/drupal/modules/epal/src/Controller/Distribution.php index aab9c3b..ad8476f 100755 --- a/drupal/modules/epal/src/Controller/Distribution.php +++ b/drupal/modules/epal/src/Controller/Distribution.php @@ -172,7 +172,8 @@ class Distribution extends ControllerBase { //print_r("
FETCH: " . $j); $sCon = $this->connection->select('epal_student', 'eStudent') - ->fields('eStudent', array('id', 'name', 'currentclass', 'currentepal', 'points')) + //->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); @@ -190,7 +191,8 @@ class Distribution extends ControllerBase { if (sizeof($this->pendingStudents) != 0) { $sCon = $this->connection->select('epal_student', 'eStudent') - ->fields('eStudent', array('id', 'name', 'currentclass', 'currentepal', 'points')) + //->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); @@ -361,6 +363,7 @@ class Distribution extends ControllerBase { //'points' => $epalStudent->points, 'distribution_id' => $choice_id, 'finalized' => 1, + 'second_period' => $epalStudent->second_period, 'status' => 1, 'created' => $timestamp, 'changed' => $timestamp,) @@ -580,25 +583,12 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, } } //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; @@ -702,8 +692,6 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, } } //end if ΕΣΠΕΡΙΝΟ - - } //end for each school/department return SUCCESS; @@ -854,30 +842,48 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, ], Response::HTTP_FORBIDDEN); } - try { + if ( $this->initializeResultsInSecondPeriod() === ERROR_DB) + return $this->respondWithStatus([ + "message" => t("Unexpected Error in initializeResultsInSecondPeriod function") + ], Response::HTTP_INTERNAL_SERVER_ERROR); + $sCon = $this->connection->select('epal_student', 'eStudent') - ->fields('eStudent', array('id', 'currentclass', 'currentepal')) + ->fields('eStudent', array('id', 'currentclass', 'currentepal', 'second_period')) ->condition('eStudent.second_period', 1 , '='); $epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); - //$this->globalCounterId = 10000; + //τοποθέτηση όλων των μαθητών Β' περιόδου στην πρώτη τους προτίμηση' $this->globalCounterId = $this->retrieveLastStudentId() + 1; - if ($this->locateStudent(1, $epalStudents) === ERROR_DB) return $this->respondWithStatus([ - "message" => t("Unexpected Error in locateStudent function") + "message" => t("Unexpected Error in locateStudent function after calling locateSecondPeriodStudents method"), + "numOfDeletions" => $num ], Response::HTTP_INTERNAL_SERVER_ERROR); - if ($this->findSmallClasses() === ERROR_DB) + + //επαναϋπολογισμός όλων των ολιγομελών τμημάτων (Προσοχή: αφορά ΟΛΟΥΣ τους μαθητές - κανονικής και Β΄ περιόδου) + + //αρχικοποίηση flag finalize σε 1 για όλους + if ($this->setFinalize() === ERROR_DB) return $this->respondWithStatus([ - "message" => t("Unexpected Error in findSmallClasses function AFTER locateSecondPeriodStudents!") + "message" => t("Unexpected Error in setFinalize function AFTER locateSecondPeriodStudents!") ], Response::HTTP_INTERNAL_SERVER_ERROR); - //αν αποτύχει, δεν γίνεται rollback. --> Λύση: διαγρα΄φή των όποιων αποτελεσμάτων ;; + //εύρεση ολιγομελών και καταχώρηση μαθητών σε αυτά με κατάλληλη ένδειξη (finalize=0) + if ($this->findSmallClasses() === ERROR_DB) { + //αν αποτύχει, δεν γίνεται rollback. --> Λύση: διαγρα΄φή των όποιων αποτελεσμάτων + if ($this->initializeResultsInSecondPeriod() === ERROR_DB) + return $this->respondWithStatus([ + "message" => t("Unexpected Error in initializeResults function AFTER findSmallClasses call Function") + ], Response::HTTP_INTERNAL_SERVER_ERROR); + return $this->respondWithStatus([ + "message" => t("Unexpected Error in findSmallClasses function AFTER locateSecondPeriodStudents!") + ], Response::HTTP_INTERNAL_SERVER_ERROR); + } } @@ -902,10 +908,45 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, } + } + + private function setFinalize() { + + try { + $query = $this->connection->update('epal_student_class'); + $query->fields([ + 'finalized' => 1, + ]); + $query->execute(); + } + catch (\Exception $e) { + $this->logger->warning($e->getMessage()); + return ERROR_DB; + } + return SUCCESS; } + + private function initializeResultsInSecondPeriod() { + + //initialize/empty epal_student_class if there are already data in it! + try { + //$this->connection->delete('epal_student_class')->execute(); + + $con = $this->connection->prepare("delete from epal_student_class where second_period = 1 "); + $con->execute(); + //$num = $con->rowCount(); + + } + catch (\Exception $e) { + $this->logger->warning($e->getMessage()); + return ERROR_DB; + } + return SUCCESS; + } + private function retrieveLastStudentId() { $sCon = $this->connection->select('epal_student', 'eStudent') diff --git a/drupal/modules/epal/src/Controller/ReportsCreator.php b/drupal/modules/epal/src/Controller/ReportsCreator.php index 1fd7531..467a0be 100644 --- a/drupal/modules/epal/src/Controller/ReportsCreator.php +++ b/drupal/modules/epal/src/Controller/ReportsCreator.php @@ -95,19 +95,35 @@ class ReportsCreator extends ControllerBase { ], Response::HTTP_FORBIDDEN); } - //υπολογισμός αριθμού δηλώσεων + $list = array(); + + //υπολογισμός αριθμού αιτήσεων $sCon = $this->connection->select('epal_student', 'eStudent') ->fields('eStudent', array('id')); $numApplications = $sCon->countQuery()->execute()->fetchField(); + array_push($list,(object) array('name' => "Αριθμός Αιτήσεων (συνολικά)", 'numStudents' => $numApplications)); + + //υπολογισμός αριθμού αιτήσεων ανά τάξη + for ($i = 1; $i <= 4; $i++) { + $sCon = $this->connection->select('epal_student', 'eStudent') + ->fields('eStudent', array('id')) + ->condition('eStudent.currentclass', strval($i) , '='); + $numApplications = $sCon->countQuery()->execute()->fetchField(); + array_push($list,(object) array('name' => "Αριθμός Αιτήσεων για " . $i . "η Τάξη", 'numStudents' => $numApplications)); + } + + //υπολογισμός αριθμού αιτήσεων για δεύτερη περίοδο + $sCon = $this->connection->select('epal_student', 'eStudent') + ->fields('eStudent', array('id')) + ->condition('eStudent.second_period', 1 , '='); + $numApplications = $sCon->countQuery()->execute()->fetchField(); + array_push($list,(object) array('name' => "Αριθμός Αιτήσεων B' περιόδου", 'numStudents' => $numApplications)); //υπολογισμός αριθμού χρηστών $sCon = $this->connection->select('epal_users', 'eUser') ->fields('eUser', array('id')); $numUsers = $sCon->countQuery()->execute()->fetchField(); - - $list = array(); - array_push($list,(object) array('name' => "Αριθμός Αιτήσεων", 'numStudents' => $numApplications)); - array_push($list,(object) array('name' => "Αριθμός Εγγεγραμένων Χρηστών", 'numStudents' => $numUsers)); + array_push($list,(object) array('name' => "Αριθμός Εγγεγραμένων Χρηστών με ρόλο Αιτούντα", 'numStudents' => $numUsers)); return $this->respondWithStatus( diff --git a/source/components/minister/minister-informstudents.ts b/source/components/minister/minister-informstudents.ts index 23826c8..6e9a17b 100644 --- a/source/components/minister/minister-informstudents.ts +++ b/source/components/minister/minister-informstudents.ts @@ -20,6 +20,8 @@ import { API_ENDPOINT } from '../../app.settings'; class = "loading" *ngIf="successSending == -2" > +
+