several updates

parent 245bf2d6
......@@ -78,6 +78,14 @@ epal.allocation:
_controller: '\Drupal\epal\Controller\Distribution::createDistribution'
requirements:
_user_is_logged_in: 'TRUE'
epal.allocation_second:
path: '/epal/distribution-secondperiod'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\Distribution::locateSecondPeriodStudents'
requirements:
_user_is_logged_in: 'TRUE'
epal.sectorperschool:
path: '/epal/sectorperschool'
options:
......
......@@ -101,7 +101,7 @@ class ApplicationSubmit extends ControllerBase
$regionaddress_encoded = $crypt->encrypt($applicationForm[0]['regionaddress']);
$regiontk_encoded = $crypt->encrypt($applicationForm[0]['regiontk']);
$regionarea_encoded = $crypt->encrypt($applicationForm[0]['regionarea']);
$certificatetype_encoded = $crypt->encrypt($applicationForm[0]['certificatetype']);
//$certificatetype_encoded = $crypt->encrypt($applicationForm[0]['certificatetype']);
$relationtostudent_encoded = $crypt->encrypt($applicationForm[0]['relationtostudent']);
$telnum_encoded = $crypt->encrypt($applicationForm[0]['telnum']);
$guardian_name_encoded = $crypt->encrypt($applicationForm[0]['cu_name']);
......@@ -157,8 +157,8 @@ class ApplicationSubmit extends ControllerBase
'regionaddress' => $regionaddress_encoded,
'regionarea' => $regionarea_encoded,
'regiontk' => $regiontk_encoded,
'certificatetype' => $certificatetype_encoded,
'graduation_year' => $applicationForm[0]['graduation_year'],
//'certificatetype' => $certificatetype_encoded,
//'graduation_year' => $applicationForm[0]['graduation_year'],
'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'],
'lastschool_unittypeid' => $applicationForm[0]['lastschool_unittypeid'],
'lastschool_schoolname' => $applicationForm[0]['lastschool_schoolname'],
......@@ -298,6 +298,8 @@ class ApplicationSubmit extends ControllerBase
(checkdate($date_parts[1], $date_parts[2], $date_parts[0]) !== true)) {
return 1003;
}
if (intval($date_parts[0]) >= 2003)
return 1003;
$birthdate = "{$date_parts[2]}-{$date_parts[1]}-{$date_parts[0]}";
if (!$student["name"]) {
......@@ -321,12 +323,14 @@ class ApplicationSubmit extends ControllerBase
if (!$student["regionarea"]) {
return 1010;
}
/*
if (!$student["certificatetype"]) {
return 1011;
}
if (!$student["graduation_year"]) {
return 1012;
}
*/
if (!$student["currentclass"] || ($student["currentclass"] !== "1" && $student["currentclass"] !== "2" && $student["currentclass"] !== "3" && $student["currentclass"] !== "4") ) {
return 1013;
}
......
......@@ -276,7 +276,7 @@ class Distribution extends ControllerBase {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return $this->respondWithStatus([
"message" => t("An unexpected problem occured")
"message" => t("An unexpected problem occured in createDistribution Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
......@@ -346,6 +346,8 @@ class Distribution extends ControllerBase {
$timestamp = strtotime(date("Y-m-d"));
$this->connection->insert('epal_student_class')->fields(
array('id' => $this->globalCounterId++,
'uuid' => \Drupal::service('uuid')->generate(),
......@@ -356,7 +358,7 @@ class Distribution extends ControllerBase {
'currentclass' => $epalStudent->currentclass,
'currentepal' => $epalStudent->currentepal,
'specialization_id' => $specialization_id,
'points' => $epalStudent->points,
//'points' => $epalStudent->points,
'distribution_id' => $choice_id,
'finalized' => 1,
'status' => 1,
......@@ -364,6 +366,7 @@ class Distribution extends ControllerBase {
'changed' => $timestamp,)
)->execute();
} //end if
} //foreach
......@@ -797,5 +800,127 @@ public function checkCapacityAndArrange($epalId, $classId, $secCourId, $limitup,
public function locateSecondPeriodStudents(Request $request) {
//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
$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);
}
//check where distribution can be done now
$secondPeriodEnabled = "0";
$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 {
$secondPeriodEnabled = $epalConfig->activate_second_period->getString();
}
if ($secondPeriodEnabled === "0" ) {
return $this->respondWithStatus([
'message' => t("secondPeriodEnabled setting is false"),
], Response::HTTP_FORBIDDEN);
}
try {
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id', 'currentclass', 'currentepal'))
->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")
], Response::HTTP_INTERNAL_SERVER_ERROR);
if ($this->findSmallClasses() === ERROR_DB)
return $this->respondWithStatus([
"message" => t("Unexpected Error in findSmallClasses function AFTER locateSecondPeriodStudents!")
], Response::HTTP_INTERNAL_SERVER_ERROR);
//αν αποτύχει, δεν γίνεται rollback. --> Λύση: διαγρα΄φή των όποιων αποτελεσμάτων ;;
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured in locateSecondPeriodStudents Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$postData = null;
if ($content = $request->getContent()) {
$postData = json_decode($content);
return $this->respondWithStatus([
'message' => "locateSecondPeriodStudents has made successfully",
], Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("post with no data"),
], Response::HTTP_BAD_REQUEST);
}
}
private function retrieveLastStudentId() {
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id'));
$sCon->orderBy('eStudent.id','desc');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if ($epalStudents) {
$epalStrudent = reset($epalStudents);
return $epalStrudent->id;
}
return 0;
}
}
......@@ -88,7 +88,8 @@ class PDFCreator extends ControllerBase {
], Response::HTTP_FORBIDDEN);
*/
//New epal-user validation
//Epal-user validation
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
......@@ -101,7 +102,6 @@ class PDFCreator extends ControllerBase {
], Response::HTTP_FORBIDDEN);
}
}
//end New User validation
//user role validation
......@@ -297,7 +297,7 @@ class PDFCreator extends ControllerBase {
$studentsurname_decoded = $this->crypt->decrypt($student->studentsurname->value);
$fatherfirstname_decoded = $this->crypt->decrypt($student->fatherfirstname->value);
$motherfirstname_decoded = $this->crypt->decrypt($student->motherfirstname->value);
$certificatetype_decoded = $this->crypt->decrypt($student->certificatetype->value);
//$certificatetype_decoded = $this->crypt->decrypt($student->certificatetype->value);
$relationtostudent_decoded = $this->crypt->decrypt($student->relationtostudent->value);
$telnum_decoded = $this->crypt->decrypt($student->telnum->value);
}
......@@ -375,18 +375,21 @@ class PDFCreator extends ControllerBase {
$this->pdf->Ln();
/*
$this->pdf->SetFont($this->fontLight, '', $this->fontSizeRegular);
$this->pdf->Cell($width+15, $height, $this->prepareString('Τύπος απολυτηρίου:'), 0, 'L');
$this->pdf->SetFont($this->fontBold, '', $this->fontSizeRegular);
//$this->pdf->Cell($width, $height, $this->prepareString($student->certificatetype->value), 0, 'L');
$this->pdf->Cell($width, $height, $this->prepareString($certificatetype_decoded), 0, 'L');
$this->pdf->Ln();
*/
/*
$this->pdf->SetFont($this->fontLight, '', $this->fontSizeRegular);
$this->pdf->Cell($width+15, $height, $this->prepareString('Έτος κτήσης απολυτηρίου:'), 0, 'L');
$this->pdf->SetFont($this->fontBold, '', $this->fontSizeRegular);
$this->pdf->Cell($width, $height, $this->prepareString($student->graduation_year->value), 0, 'L');
$this->pdf->Ln();
*/
$this->pdf->SetFont($this->fontLight, '', $this->fontSizeRegular);
$this->pdf->Cell($width+15, $height, $this->prepareString('Σχολείο τελευταίας φοίτησης:'), 0, 'L');
......
......@@ -416,6 +416,26 @@ class EpalStudentClass extends ContentEntityBase implements EpalStudentClassInte
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['second_period'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Δεύτερη περίοδος αιτήσεων'))
->setDescription(t('Δεύτερη περίοδος αιτήσεων.'))
->setSettings(array(
'text_processing' => 0,
))
->setRequired(false)
->setDefaultValue(false)
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'boolean',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'boolean',
'weight' => -4,
))
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the EPAL Student Class is published.'))
......
......@@ -82,6 +82,13 @@ import { API_ENDPOINT } from '../../app.settings';
Εκτέλεση Κατανομής Μαθητών<span class="glyphicon glyphicon-menu-right"></span>
</button>
</div>
<br>
<div class="col-md-6">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="runDistributionSecondPeriod()" [disabled] = "!secondPeriodEnabled" >
Τοποθέτηση Μαθητών Β' Περιόδου<span class="glyphicon glyphicon-menu-right"></span>
</button>
</div>
</div>
......@@ -106,6 +113,7 @@ import { API_ENDPOINT } from '../../app.settings';
private capacityDisabled: boolean;
private directorViewDisabled: boolean;
private applicantsResultsDisabled: boolean;
private secondPeriodEnabled: boolean;
constructor(/*private fb: FormBuilder,*/
// private _ata: LoginInfoActions,
......@@ -225,6 +233,33 @@ import { API_ENDPOINT } from '../../app.settings';
});
}
runDistributionSecondPeriod() {
this.distStatus = "STARTED";
this.showModal("#distributionWaitingNotice");
this._hds.makeDistributionSecondPeriod(this.minedu_userName, this.minedu_userPassword)
.then(msg => {
this.modalTitle.next("Τοποθέτηση Μαθητών 2ης Περιόδου Αιτήσεων");
this.modalText.next("Η τοποθέτηση μαθητών της δεύτερης περιόδου αιτήσεων ολοκληρώθηκε με επιτυχία!");
this.modalHeader.next("modal-header-success");
this.showModal("#distributionNotice");
if (this.distStatus !== "ERROR")
this.distStatus = "FINISHED";
})
.catch(err => {console.log(err);
this.distStatus = "ERROR";
this.modalTitle.next("Τοποθέτηση Μαθητών 2ης Περιόδου Αιτήσεων");
this.modalText.next("Αποτυχία τοποθέτησης. Προσπαθήστε ξανά. Σε περίπτωση που το πρόβλημα παραμένει, παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
this.modalHeader.next("modal-header-danger");
this.showModal("#distributionNotice");
});
}
retrieveSettings() {
......@@ -245,8 +280,10 @@ import { API_ENDPOINT } from '../../app.settings';
this.directorViewDisabled = Boolean(Number(this.settings$.value['directorViewDisabled']));
this.applicantsResultsDisabled = Boolean(Number(this.settings$.value['applicantsResultsDisabled']));
console.log("Debugging..");
console.log(this.capacityDisabled);
this.secondPeriodEnabled = Boolean(Number(this.settings$.value['secondPeriodEnabled']));
console.log("Nikos");
console.log( this.secondPeriodEnabled);
if (this.capacityDisabled == false) {
this.modalTitle.next("Κατανομή Μαθητών");
......
......@@ -632,6 +632,29 @@ export class HelperDataService implements OnInit, OnDestroy {
}
makeDistributionSecondPeriod(username, userpassword) {
let headers = new Headers({
"Content-Type": "application/json",
});
this.createMinistryAuthorizationHeader(headers, username, userpassword);
let options = new RequestOptions({ headers: headers });
return new Promise((resolve, reject) => {
this.http.post(`${AppSettings.API_ENDPOINT}/epal/distribution-secondperiod`, { username: username, userpassword: userpassword }, options)
.map(response => response.json())
.subscribe(data => {
resolve(data);
},
error => {
reject("Error POST in makeDistributionSecondPeriod");
},
() => console.log(""));
});
}
makeReport(username, userpassword, routepath, regionsel, adminsel, schsel, clsel, secsel, coursel, distribfinal) {
......
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