added InformUnallocatedStudents Controller, added reports in ReportCreator...

added InformUnallocatedStudents Controller, added reports in ReportCreator Controller, updated CreateDemoData Controller Utility
parent 21f6547a
...@@ -7,7 +7,7 @@ epal.user.send_verification_code: ...@@ -7,7 +7,7 @@ epal.user.send_verification_code:
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.user.verify_verification_code: epal.user.verify_verification_code:
path: '/epal/user/verifyvercode' path: '/epal/user/verifyvercode'
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
defaults: defaults:
...@@ -148,7 +148,7 @@ epal.ministry.general_report: ...@@ -148,7 +148,7 @@ epal.ministry.general_report:
_controller: '\Drupal\epal\Controller\ReportsCreator::makegGeneralReport' _controller: '\Drupal\epal\Controller\ReportsCreator::makegGeneralReport'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.report1: epal.ministry.report-completeness:
path: '/ministry/report-completeness' path: '/ministry/report-completeness'
options: options:
_auth: [ 'basic_auth' ] _auth: [ 'basic_auth' ]
...@@ -156,6 +156,22 @@ epal.ministry.report1: ...@@ -156,6 +156,22 @@ epal.ministry.report1:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportCompleteness' _controller: '\Drupal\epal\Controller\ReportsCreator::makeReportCompleteness'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.report-all-stat:
path: '/ministry/report-all-stat'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportAllStat'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail:
path: '/ministry/send-massive-mail'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToStudents'
requirements:
_user_is_logged_in: 'TRUE'
regionview: regionview:
path: '/epal/ScoolperPerf/{perfectureId}' path: '/epal/ScoolperPerf/{perfectureId}'
options: options:
...@@ -171,4 +187,4 @@ coursesperschools: ...@@ -171,4 +187,4 @@ coursesperschools:
defaults: defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getCoursesPerSchool' _controller: '\Drupal\epal\Controller\DirectorView::getCoursesPerSchool'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
\ No newline at end of file
...@@ -36,7 +36,7 @@ class CreateDemoData extends ControllerBase { ...@@ -36,7 +36,7 @@ class CreateDemoData extends ControllerBase {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query; $this->entity_query = $entity_query;
$this->connection = $connection; $this->connection = $connection;
//$this->logger = $loggerChannel->get('oauthost'); $this->logger = $loggerChannel->get('epal');
} }
public static function create(ContainerInterface $container) public static function create(ContainerInterface $container)
...@@ -64,19 +64,20 @@ class CreateDemoData extends ControllerBase { ...@@ -64,19 +64,20 @@ class CreateDemoData extends ControllerBase {
public function createData() { public function createData() {
$transaction = $this->connection->startTransaction(); $transaction = $this->connection->startTransaction();
try { try {
//insert demo records in entity: epal_student //insert demo records in entity: epal_student
$entity_manager = \Drupal::entityTypeManager(); $entity_manager = \Drupal::entityTypeManager();
$epaluserid = \Drupal::currentUser()->id(); $epaluserid = \Drupal::currentUser()->id();
for ($i = 1; $i <= 10000; $i++) { for ($i = 1; $i <= 500; $i++) {
//srand($this->make_seed()); //srand($this->make_seed());
//$curclass = rand(1,3); $curclass = rand(1,3);
$curclass = 1; //$curclass = 2;
$currentepal = rand(147,156); $currentepal = rand(137,165);
$student = array( $student = array(
//'epaluser_id' => $aitisi[0][epaluser_id], //'epaluser_id' => $aitisi[0][epaluser_id],
...@@ -84,22 +85,33 @@ class CreateDemoData extends ControllerBase { ...@@ -84,22 +85,33 @@ class CreateDemoData extends ControllerBase {
'name' => "firstname" . $i, 'name' => "firstname" . $i,
'studentsurname' => "surname" . $i, 'studentsurname' => "surname" . $i,
//'birthdate' => $aitisi[0][birthdate], //'birthdate' => $aitisi[0][birthdate],
'birthdate' => '01/01/1970',
//'fatherfirstname' => $aitisi[0][fatherfirstname], //'fatherfirstname' => $aitisi[0][fatherfirstname],
'fatherfirstname' => "fatherfirstname" . $i,
//'fathersurname' => $aitisi[0][fathersurname], //'fathersurname' => $aitisi[0][fathersurname],
'fathersurname' => "fathersurname" . $i,
//'motherfirstname' => $aitisi[0][motherfirstname], //'motherfirstname' => $aitisi[0][motherfirstname],
'motherfirstname' => "motherfirstname" . $i,
//'mothersurname' => $aitisi[0][mothersurname], //'mothersurname' => $aitisi[0][mothersurname],
'mothersurname' => "mothersurname" . $i,
//'studentamka' => $aitisi[0][studentamka], //'studentamka' => $aitisi[0][studentamka],
//'regionaddress' => $aitisi[0][regionaddress], //'regionaddress' => $aitisi[0][regionaddress],
'regionaddress' => "regionaddress" . $i,
//'regionarea' => $aitisi[0][regionarea], //'regionarea' => $aitisi[0][regionarea],
'regionarea' => "regionarea" . $i,
//'regiontk' => $aitisi[0][regiontk], //'regiontk' => $aitisi[0][regiontk],
'regiontk' => "tk" . $i,
//'certificatetype' => $aitisi[0][certificatetype], //'certificatetype' => $aitisi[0][certificatetype],
'certificatetype' => 'Απολυτήριο Γυμνασίου',
//'lastam' => $aitisi[0][lastam], //'lastam' => $aitisi[0][lastam],
'currentclass' => $curclass, 'currentclass' => $curclass,
'currentepal' => $currentepal 'currentepal' => $currentepal,
//'currentsector' => $aitisi[0][currentsector], //'currentsector' => $aitisi[0][currentsector],
//'relationtostudent' => $aitisi[0][relationtostudent], //'relationtostudent' => $aitisi[0][relationtostudent],
'relationtostudent' => 'Μαθητής',
//'telnum' => $aitisi[0][telnum], //'telnum' => $aitisi[0][telnum],
//'moria' => rand(0,10) 'telnum' => '6944123456',
'points' => rand(0,20)
); );
$entity_storage_student = $entity_manager->getStorage('epal_student'); $entity_storage_student = $entity_manager->getStorage('epal_student');
...@@ -109,85 +121,141 @@ class CreateDemoData extends ControllerBase { ...@@ -109,85 +121,141 @@ class CreateDemoData extends ControllerBase {
$created_student_id = $entity_object->id(); $created_student_id = $entity_object->id();
//insert demo records in entity: epal_student_epal_chosen
//$epal_id = rand(147,149); //TO BE REMOVED //insert records in entity: epal_student_course_field (αφορά μαθητές Γ' Λυκείου)
// or: epal_student_sector_field (αφορά μαθητές Β' Λυκείου)
$availableSchools = array();
$numEpalsChosen = rand(1,3); if ($curclass === 3) {
$epal_id = $this->UniqueRandNum(147,156,$numEpalsChosen);
//for ($j = 1; $j <= $numEpalsChosen ; $j++) { do {
if ($curclass === 2 || $curclass === 3) { $coursefield_id = rand(1,54);
//33% των μαθητών της Β' και Γ' Λυκείου δηλώνουν προτίμηση στο σχολείο που ήδη φοιτούν $course = array(
if (rand(1,3) === 1) { 'student_id' => $created_student_id,
'coursefield_id' => $coursefield_id
$epal_id[0] = $currentepal; );
//$epal_id = array($currentepal ,$currentepal, $currentepal);
$entity_storage_course = $entity_manager->getStorage('epal_student_course_field');
$entity_object = $entity_storage_course->create($course);
//$entity_storage_course->save($entity_object);
//εύρεση ΕΠΑΛ που διαθέτουν την αντίστοιχη ειδικότητα
print_r("<br> EIDIKOTHTA: " . $coursefield_id);
$eepalSpecialtiesInEpal_storage = $this->entityTypeManager->getStorage('eepal_specialties_in_epal');
//$eepalSpecialtiesInEpal = $eepalSpecialtiesInEpal_storage->loadByProperties(array('specialty_id' => $coursefield_id) );
$ids = $eepalSpecialtiesInEpal_storage->getQuery()
->condition('specialty_id', $coursefield_id, "=")
->condition('epal_id', 137, ">=")
->condition('epal_id', 165, "<=")
->execute();
$eepalSpecialtiesInEpal = $eepalSpecialtiesInEpal_storage->loadMultiple($ids);
print_r("<br> NUM_SCHOOLS: " . sizeof($eepalSpecialtiesInEpal));
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
array_push($availableSchools, $eepalSpecialInEp->epal_id->getString());
} }
else {
//$epal_id = rand(147,149);
if (sizeof($availableSchools) != 0)
$entity_storage_course->save($entity_object);
} //end do
while (sizeof($availableSchools) == 0);
$entity_storage_course->resetCache();
$eepalSpecialtiesInEpal_storage->resetCache();
}
else if ($curclass === 2) {
do {
$sectorfield_id = rand(1,9);
$sector = array(
'student_id' => $created_student_id,
'sectorfield_id' => $sectorfield_id
);
//print_r("<br>". $epal_id[0] . $epal_id[1] . $epal_id[2]); $entity_storage_sector = $entity_manager->getStorage('epal_student_sector_field');
$entity_object = $entity_storage_sector->create($sector);
//$entity_storage_sector->save($entity_object);
//εύρεση ΕΠΑΛ που διαθέτουν τον αντίστοιχο τομέα
print_r("<br> TOMEAS: " . $sectorfield_id);
$eepalSectorsInEpal_storage = $this->entityTypeManager->getStorage('eepal_sectors_in_epal');
$ids = $eepalSectorsInEpal_storage->getQuery()
->condition('sector_id', $sectorfield_id, "=")
->condition('epal_id', 137, ">=")
->condition('epal_id', 165, "<=")
->execute();
$eepalSectorsInEpal = $eepalSectorsInEpal_storage->loadMultiple($ids);
print_r("<br> NUM_SCHOOLS: " . sizeof($eepalSectorsInEpal));
foreach ($eepalSectorsInEpal as $eepalSecInEp) {
array_push($availableSchools, $eepalSecInEp->epal_id->getString());
} }
} if (sizeof($availableSchools) != 0)
$entity_storage_sector->save($entity_object);
} //end do
while (sizeof($availableSchools) == 0);
$entity_storage_sector->resetCache();
$eepalSectorsInEpal_storage->resetCache();
}
else if ($curclass === 1) {
print_r("<br> CLASS A: ");
$school_id_start = 137;
for ($l=0; $l < 29; $l++)
array_push($availableSchools, $school_id_start + $l);
}
$numEpalsChosen = rand(1,3);
if ($numEpalsChosen > sizeof($availableSchools))
$numEpalsChosen = sizeof($availableSchools);
print_r("<br> NUM_EPAL_CHOSEN " . $numEpalsChosen);
$epal_id_index = $this->UniqueRandNum(0,sizeof($availableSchools)-1,$numEpalsChosen);
for ($j=0; $j < $numEpalsChosen; $j++) {
print_r("<br> EPAL_CHOSEN_ID: " . $epal_id_index[$j]);
print_r("<br> EPAL_CHOSEN_REAL_ID: " . $availableSchools[$epal_id_index[$j]]);
}
for ($j = 0; $j < $numEpalsChosen ; $j++) { for ($j = 0; $j < $numEpalsChosen ; $j++) {
// print_r("<br>Data: Student" . $created_student_id . "EPAL" . $epal_id . "CHOICE" . $j );
$epalchosen = array( $epalchosen = array(
'student_id' => $created_student_id, 'student_id' => $created_student_id,
'epal_id' => $epal_id[$j], 'epal_id' => $availableSchools[$epal_id_index[$j]],
'choice_no' => $j+1 'choice_no' => $j+1
); );
//print_r("<br>Test1");
$entity_storage_epalchosen = $entity_manager->getStorage('epal_student_epal_chosen'); $entity_storage_epalchosen = $entity_manager->getStorage('epal_student_epal_chosen');
//print_r("<br>Test2");
$entity_object = $entity_storage_epalchosen->create($epalchosen); $entity_object = $entity_storage_epalchosen->create($epalchosen);
//print_r("<br>Test3");
$entity_storage_epalchosen->save($entity_object); $entity_storage_epalchosen->save($entity_object);
//print_r("<br>Test4");
} }
$entity_storage_epalchosen->resetCache();
$entity_storage_student->resetCache();
//insert records in entity: epal_student_course_field (αφορά μαθητές Γ' Λυκείου)
// or: epal_student_sector_field (αφορά μαθητές Β' Λυκείου)
if ($curclass === 3) {
$course = array(
//'name' => $aitisi[3][name],
//'student_id' => $aitis[3][student_i],
'student_id' => $created_student_id,
'coursefield_id' => rand(1,54)
);
$entity_storage_course = $entity_manager->getStorage('epal_student_course_field');
$entity_object = $entity_storage_course->create($course);
$entity_storage_course->save($entity_object);
}
else if ($curclass === 2) { /*
$sector = array( //TO BE CONSIDERED
//'name' => $aitisi[3][name], if ($curclass === 2 || $curclass === 3) {
'student_id' => $created_student_id, //33% των μαθητών της Β' και Γ' Λυκείου δηλώνουν προτίμηση στο σχολείο που ήδη φοιτούν
//'student_id' => $aitis[3][student_i], if (rand(1,3) === 1) {
'sectorfield_id' => rand(1,9) $epal_id[0] = $currentepal;
); }
$entity_storage_sector = $entity_manager->getStorage('epal_student_sector_field');
$entity_object = $entity_storage_sector->create($sector);
$entity_storage_sector->save($entity_object);
} }
*/
} }
} }
catch (\Exception $e) { catch (\Exception $e) {
//$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$returnmsg = "Αποτυχία καταχώρησης demo data!"; $returnmsg = "Αποτυχία καταχώρησης demo data!";
$response = new JsonResponse([$returnmsg]); $response = new JsonResponse([$returnmsg]);
$transaction->rollback(); // $transaction->rollback();
return $response; return $response;
} }
......
...@@ -24,8 +24,6 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp; ...@@ -24,8 +24,6 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
class Distribution extends ControllerBase { class Distribution extends ControllerBase {
protected $entity_query; protected $entity_query;
...@@ -112,7 +110,8 @@ class Distribution extends ControllerBase { ...@@ -112,7 +110,8 @@ class Distribution extends ControllerBase {
//initialize/empty epal_student_class if there are already data in it! //initialize/empty epal_student_class if there are already data in it!
$this->connection->delete('epal_student_class')->execute(); $this->connection->delete('epal_student_class')->execute();
$limitUp_class = $this->retrieveCapacityLimitUp("Α"); //$limitUp_class = $this->retrieveCapacityLimitUp("Α");
$limitUp_class = $this->retrieveCapacityLimitUp("1");
//print_r("<br> ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitUp_class); //print_r("<br> ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitUp_class);
while ($this->choice_id <= $numDistributions) { while ($this->choice_id <= $numDistributions) {
...@@ -575,6 +574,7 @@ class Distribution extends ControllerBase { ...@@ -575,6 +574,7 @@ class Distribution extends ControllerBase {
->condition('eStudent.id', $studentIds, 'NOT IN'); ->condition('eStudent.id', $studentIds, 'NOT IN');
$numNoAllocated = $sCon->countQuery()->execute()->fetchField(); $numNoAllocated = $sCon->countQuery()->execute()->fetchField();
/*
$list[] = array( $list[] = array(
'num_applications' => $numTotal, 'num_applications' => $numTotal,
'numchoice1' => $numData[0], 'numchoice1' => $numData[0],
...@@ -582,6 +582,26 @@ class Distribution extends ControllerBase { ...@@ -582,6 +582,26 @@ class Distribution extends ControllerBase {
'numchoice3' => $numData[2], 'numchoice3' => $numData[2],
'num_noallocated' => $numNoAllocated, 'num_noallocated' => $numNoAllocated,
); );
*/
$list = array();
//$record = new generalReportSchema;
//$record->name = "nikos";
//$record->numStudents = 20;
array_push($list,(object) array('name' => "Αριθμός Αιτήσεων", 'numStudents' => $numTotal));
// $record = (object) array('name' => "Αριθμός Αιτήσεων:", 'numStudents' => $numTotal);
array_push($list,(object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην πρώτη τους προτίμηση", 'numStudents' => $numData[0]));
//$record = (object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην πρώτη τους προτίμηση:", 'numStudents' => $numData[0]);
array_push($list,(object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην δεύτερή τους προτίμηση", 'numStudents' => $numData[1]));
//$record = (object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην δεύτερή τους προτίμηση:", 'numStudents' => $numData[1]);
array_push($list,(object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην τρίτη τους προτίμηση", 'numStudents' => $numData[2]));
//$record = (object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην τρίτη τους προτίμηση:", 'numStudents' => $numData[2]);
array_push($list,(object) array('name' => "Αριθμός μαθητών που δεν τοποθετήθηκαν σε καμμία τους προτίμηση", 'numStudents' => $numNoAllocated));
//$record = (object) array('name' => "Αριθμός μαθητών που δεν τοποθετήθηκαν σε καμμία τους προτίμηση:", 'numStudents' => $numNoAllocated);
return $this->respondWithStatus( return $this->respondWithStatus(
$list $list
...@@ -599,5 +619,72 @@ class Distribution extends ControllerBase { ...@@ -599,5 +619,72 @@ class Distribution extends ControllerBase {
/*
public function makeReport1(Request $request) {
try {
if (!$request->isMethod('GET')) {
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);
}
$list = array();
$sCon = $this->connection->select('eepal_school_field_data', 'eSchool')
->fields('eSchool', array('id', 'name'));
$epalSchools = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
//$schoolIds = array();
foreach ($epalSchools as $epalSchool) {
//array_push($schoolIds, $schoolId->id);
$sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('id', 'epal_id'))
->condition('eStudent.epal_id', $epalSchool->id , '=');
$num = $sCon->countQuery()->execute()->fetchField();
if ($num !== "0")
array_push($list,(object) array('schoolName' => $epalSchool->name, 'numStudents' => $num));
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured in makeReport1 Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
*/
} }
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
//use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface;
class InformUnlocatedStudents extends ControllerBase {
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
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;
$this->logger = $loggerChannel->get('epal');
}
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 sendMailToStudents(Request $request) {
try {
if (!$request->isMethod('GET')) {
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;