updated Distribution Controller with second Period distribution

parent ed27fc4c
...@@ -172,7 +172,8 @@ class Distribution extends ControllerBase { ...@@ -172,7 +172,8 @@ class Distribution extends ControllerBase {
//print_r("<br>FETCH: " . $j); //print_r("<br>FETCH: " . $j);
$sCon = $this->connection->select('epal_student', 'eStudent') $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', 1+ $sizeOfBlock*($j-1), '>=')
->condition('eStudent.id', $j*$sizeOfBlock, '<='); ->condition('eStudent.id', $j*$sizeOfBlock, '<=');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
...@@ -190,7 +191,8 @@ class Distribution extends ControllerBase { ...@@ -190,7 +191,8 @@ class Distribution extends ControllerBase {
if (sizeof($this->pendingStudents) != 0) { if (sizeof($this->pendingStudents) != 0) {
$sCon = $this->connection->select('epal_student', 'eStudent') $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'); ->condition('eStudent.id', $this->pendingStudents, 'IN');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
...@@ -361,6 +363,7 @@ class Distribution extends ControllerBase { ...@@ -361,6 +363,7 @@ class Distribution extends ControllerBase {
//'points' => $epalStudent->points, //'points' => $epalStudent->points,
'distribution_id' => $choice_id, 'distribution_id' => $choice_id,
'finalized' => 1, 'finalized' => 1,
'second_period' => $epalStudent->second_period,
'status' => 1, 'status' => 1,
'created' => $timestamp, 'created' => $timestamp,
'changed' => $timestamp,) 'changed' => $timestamp,)
...@@ -580,25 +583,12 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, ...@@ -580,25 +583,12 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup,
} }
} //endif new limit } //endif new limit
else { //$newlimit > 0 else { //$newlimit > 0
//NEW CODE LINES
if ($this->choice_id !== 1) if ($this->choice_id !== 1)
$this->removeFromPendingStudents($student->student_id); $this->removeFromPendingStudents($student->student_id);
} }
//END NEW CODE LINES
} //endif currentepal } //endif currentepal
} //end foreach } //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; return SUCCESS;
...@@ -702,8 +692,6 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, ...@@ -702,8 +692,6 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup,
} }
} //end if ΕΣΠΕΡΙΝΟ } //end if ΕΣΠΕΡΙΝΟ
} //end for each school/department } //end for each school/department
return SUCCESS; return SUCCESS;
...@@ -854,30 +842,48 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup, ...@@ -854,30 +842,48 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup,
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
try { 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') $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 , '='); ->condition('eStudent.second_period', 1 , '=');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
//$this->globalCounterId = 10000; //τοποθέτηση όλων των μαθητών Β' περιόδου στην πρώτη τους προτίμηση'
$this->globalCounterId = $this->retrieveLastStudentId() + 1; $this->globalCounterId = $this->retrieveLastStudentId() + 1;
if ($this->locateStudent(1, $epalStudents) === ERROR_DB) if ($this->locateStudent(1, $epalStudents) === ERROR_DB)
return $this->respondWithStatus([ 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); ], Response::HTTP_INTERNAL_SERVER_ERROR);
if ($this->findSmallClasses() === ERROR_DB)
//επαναϋπολογισμός όλων των ολιγομελών τμημάτων (Προσοχή: αφορά ΟΛΟΥΣ τους μαθητές - κανονικής και Β΄ περιόδου)
//αρχικοποίηση flag finalize σε 1 για όλους
if ($this->setFinalize() === ERROR_DB)
return $this->respondWithStatus([ 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); ], 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, ...@@ -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() { private function retrieveLastStudentId() {
$sCon = $this->connection->select('epal_student', 'eStudent') $sCon = $this->connection->select('epal_student', 'eStudent')
......
...@@ -95,19 +95,35 @@ class ReportsCreator extends ControllerBase { ...@@ -95,19 +95,35 @@ class ReportsCreator extends ControllerBase {
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
//υπολογισμός αριθμού δηλώσεων $list = array();
//υπολογισμός αριθμού αιτήσεων
$sCon = $this->connection->select('epal_student', 'eStudent') $sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id')); ->fields('eStudent', array('id'));
$numApplications = $sCon->countQuery()->execute()->fetchField(); $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') $sCon = $this->connection->select('epal_users', 'eUser')
->fields('eUser', array('id')); ->fields('eUser', array('id'));
$numUsers = $sCon->countQuery()->execute()->fetchField(); $numUsers = $sCon->countQuery()->execute()->fetchField();
array_push($list,(object) array('name' => "Αριθμός Εγγεγραμένων Χρηστών με ρόλο Αιτούντα", 'numStudents' => $numUsers));
$list = array();
array_push($list,(object) array('name' => "Αριθμός Αιτήσεων", 'numStudents' => $numApplications));
array_push($list,(object) array('name' => "Αριθμός Εγγεγραμένων Χρηστών", 'numStudents' => $numUsers));
return $this->respondWithStatus( return $this->respondWithStatus(
......
...@@ -20,6 +20,8 @@ import { API_ENDPOINT } from '../../app.settings'; ...@@ -20,6 +20,8 @@ import { API_ENDPOINT } from '../../app.settings';
class = "loading" *ngIf="successSending == -2" > class = "loading" *ngIf="successSending == -2" >
</div> </div>
<div style="min-height: 400px;">
<div id="emaiSentNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> <div id="emaiSentNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
<div class="modal-content"> <div class="modal-content">
...@@ -59,6 +61,8 @@ import { API_ENDPOINT } from '../../app.settings'; ...@@ -59,6 +61,8 @@ import { API_ENDPOINT } from '../../app.settings';
</button> </button>
</div> </div>
</div>
` `
}) })
......
...@@ -27,7 +27,9 @@ import { API_ENDPOINT } from '../../app.settings'; ...@@ -27,7 +27,9 @@ import { API_ENDPOINT } from '../../app.settings';
//encapsulation: ViewEncapsulation.None, //encapsulation: ViewEncapsulation.None,
template: ` template: `
<div>
<div style="min-height: 500px; ">
<h5> >Επιλογή Αναφοράς<br><br></h5> <h5> >Επιλογή Αναφοράς<br><br></h5>
......
...@@ -29,6 +29,7 @@ import { API_ENDPOINT } from '../../app.settings'; ...@@ -29,6 +29,7 @@ import { API_ENDPOINT } from '../../app.settings';
class = "loading" *ngIf=" distStatus === 'STARTED'" > class = "loading" *ngIf=" distStatus === 'STARTED'" >
</div> </div>
<div style="min-height: 400px;">
<div id="distributionNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> <div id="distributionNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
...@@ -78,7 +79,7 @@ import { API_ENDPOINT } from '../../app.settings'; ...@@ -78,7 +79,7 @@ import { API_ENDPOINT } from '../../app.settings';
<div class="col-md-6"> <div class="col-md-6">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="runDistribution()" [disabled] = "!capacityDisabled" > <button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="runDistribution()" [disabled] = "!capacityDisabled || secondPeriodEnabled" >
Εκτέλεση Κατανομής Μαθητών<span class="glyphicon glyphicon-menu-right"></span> Εκτέλεση Κατανομής Μαθητών<span class="glyphicon glyphicon-menu-right"></span>
</button> </button>
</div> </div>
...@@ -92,6 +93,8 @@ import { API_ENDPOINT } from '../../app.settings'; ...@@ -92,6 +93,8 @@ import { API_ENDPOINT } from '../../app.settings';
</div> </div>
</div>
` `
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment