Commit c21dbc19 authored by Χάρης Παπαδόπουλος's avatar Χάρης Παπαδόπουλος
Browse files

Merge branch 'lock_actions' into 'develop'

restructured application form. Added new fields in backend(WIP). Conflicts resolution. Role checking in DirectorView controller

See merge request !117
parents cc188496 7ab03641
......@@ -38,7 +38,7 @@ epal.current_user:
_controller: '\Drupal\epal\Controller\CurrentUser::getLoginInfo'
requirements:
_user_is_logged_in: 'TRUE'
submitedapplications:
epal.submitedapplications:
path: '/epal/subapplic'
options:
_auth: [ 'basic_auth' ]
......@@ -46,7 +46,7 @@ submitedapplications:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getSubmittedApplications'
requirements:
_user_is_logged_in: 'TRUE'
studentapplication:
epal.studentapplication:
path: '/epal/student/{studentId}'
options:
_auth: [ 'basic_auth' ]
......@@ -54,7 +54,7 @@ studentapplication:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getStudentApplications'
requirements:
_user_is_logged_in: 'TRUE'
epalchosen:
epal.epalchosen:
path: '/epal/epalchosen/{studentId}'
options:
_auth: [ 'basic_auth' ]
......@@ -78,7 +78,7 @@ epal.allocation:
_controller: '\Drupal\epal\Controller\Distribution::createDistribution'
requirements:
_user_is_logged_in: 'TRUE'
sectorperschool:
epal.sectorperschool:
path: '/epal/sectorperSchool'
options:
_auth: [ 'basic_auth' ]
......@@ -86,7 +86,7 @@ sectorperschool:
_controller: '\Drupal\epal\Controller\DirectorView::getSectorsPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
specialityperschool:
epal.specialityperschool:
path: '/epal/specialityperSchool/{sectorId}'
options:
_auth: [ 'basic_auth' ]
......@@ -94,7 +94,7 @@ specialityperschool:
_controller: '\Drupal\epal\Controller\DirectorView::getSpecialPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
confirmstudents:
epal.confirmstudents:
path: '/epal/confirmstudent'
options:
_auth: [ 'basic_auth' ]
......@@ -102,7 +102,7 @@ confirmstudents:
_controller: '\Drupal\epal\Controller\DirectorView::ConfirmStudents'
requirements:
_user_is_logged_in: 'TRUE'
studentperschool:
epal.studentperschool:
path: '/epal/studentperSchool/{selectId}/{classId}/{limitdown}/{limitup}'
options:
_auth: [ 'basic_auth' ]
......@@ -110,7 +110,7 @@ studentperschool:
_controller: '\Drupal\epal\Controller\DirectorView::getStudentPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
savecapacity:
epal.savecapacity:
path: '/epal/savecapacity/{taxi}/{tomeas}/{specialit}'
options:
_auth: [ 'basic_auth' ]
......@@ -125,7 +125,7 @@ epal.ministry.log_in_go:
defaults:
_controller: '\Drupal\epal\Controller\MinistryLogin::loginGo'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.log_out_go:
path: '/ministry/logout'
options:
......@@ -133,7 +133,7 @@ epal.ministry.log_out_go:
defaults:
_controller: '\Drupal\epal\Controller\MinistryLogin::logoutGo'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.general_report:
path: '/ministry/general-report'
options:
......@@ -141,7 +141,7 @@ epal.ministry.general_report:
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::makegGeneralReport'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.report-completeness:
path: '/ministry/report-completeness/{regionId}/{adminId}/{schId}'
options:
......@@ -149,7 +149,7 @@ epal.ministry.report-completeness:
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportCompleteness'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.report-all-stat:
path: '/ministry/report-all-stat/{regionId}/{adminId}/{schId}/{classId}/{sectorId}/{courseId}/{finalized}'
options:
......@@ -157,7 +157,7 @@ epal.ministry.report-all-stat:
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportAllStat'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.report-no-capacity:
path: '/ministry/report-no-capacity/{capacityEnabled}'
options:
......@@ -165,7 +165,7 @@ epal.ministry.report-no-capacity:
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportNoCapacity'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.retrieve-registry-id:
path: '/ministry/retrieve-registry-id'
options:
......@@ -173,7 +173,7 @@ epal.ministry.retrieve-registry-id:
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::retrieveUserRegistryNo'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail_unallocated:
path: '/ministry/send-unallocated-massive-mail'
options:
......@@ -181,7 +181,7 @@ epal.ministry.massive_mail_unallocated:
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudents'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail_located:
path: '/ministry/send-located-massive-mail'
options:
......@@ -189,7 +189,7 @@ epal.ministry.massive_mail_located:
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToLocatedStudents'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.retrievesettings:
path: '/ministry/retrieve-settings'
options:
......@@ -197,7 +197,7 @@ epal.ministry.retrievesettings:
defaults:
_controller: '\Drupal\epal\Controller\MinisterSettings::retrieveSettings'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.ministry.storesettings:
path: '/ministry/store-settings/{capacityDisabled}/{directorViewDisabled}/{applicantsLoginDisabled}'
options:
......@@ -205,16 +205,16 @@ epal.ministry.storesettings:
defaults:
_controller: '\Drupal\epal\Controller\MinisterSettings::storeSettings'
requirements:
_user_is_logged_in: 'TRUE'
regionview:
path: '/epal/ScoolperPerf/{check_status}'
_user_is_logged_in: 'TRUE'
epal.perfectureschools:
path: '/epal/schools-per-perf'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getSchoolsPerPerfetcure'
_controller: '\Drupal\epal\Controller\DirectorView::getSchools'
requirements:
_user_is_logged_in: 'TRUE'
coursesperschools:
epal.coursesperschools:
path: '/epal/CoursesperSch/{schoolid}'
options:
_auth: [ 'basic_auth' ]
......@@ -222,7 +222,7 @@ coursesperschools:
_controller: '\Drupal\epal\Controller\DirectorView::getCoursesPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
critirioschosen:
epal.critirioschosen:
path: '/epal/critiriachosen/{studentId}/{type}'
options:
_auth: [ 'basic_auth' ]
......@@ -230,7 +230,7 @@ critirioschosen:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getCritiria'
requirements:
_user_is_logged_in: 'TRUE'
findcapacity:
epal.findcapacity:
path: '/epal/findCapacity/{taxi}/{tomeas}/{specialit}'
options:
_auth: [ 'basic_auth' ]
......@@ -238,7 +238,7 @@ findcapacity:
_controller: '\Drupal\epal\Controller\DirectorView::findCapacity'
requirements:
_user_is_logged_in: 'TRUE'
findschoolid:
epal.findschoolid:
path: '/epal/getschool'
options:
_auth: [ 'basic_auth' ]
......@@ -246,7 +246,7 @@ findschoolid:
_controller: '\Drupal\epal\Controller\DirectorView::getSchoolID'
requirements:
_user_is_logged_in: 'TRUE'
gettypeofschool:
epal.gettypeofschool:
path: '/epal/gettypeofschool'
options:
_auth: [ 'basic_auth' ]
......
......@@ -39,13 +39,11 @@ class ApplicationSubmit extends ControllerBase {
}
public function appSubmit(Request $request) {
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"error_code" => 2001
], Response::HTTP_METHOD_NOT_ALLOWED);
}
$applicationForm = array();
$content = $request->getContent();
......@@ -58,96 +56,83 @@ class ApplicationSubmit extends ControllerBase {
"error_code" => 5002
], Response::HTTP_BAD_REQUEST);
}
$transaction = $this->connection->startTransaction();
try {
//insert records in entity: epal_student
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if (!$epalUser){
return $this->respondWithStatus([
"error_code" => 4003
], Response::HTTP_FORBIDDEN);
}
$student = array(
'epaluser_id' => $epalUser->id(),
'name' => $applicationForm[0][name],
'studentsurname' => $applicationForm[0][studentsurname],
'birthdate' => $applicationForm[0][studentbirthdate],
'fatherfirstname' => $applicationForm[0][fatherfirstname],
'fathersurname' => $applicationForm[0][fathersurname],
'motherfirstname' => $applicationForm[0][motherfirstname],
'mothersurname' => $applicationForm[0][mothersurname],
'studentamka' => $applicationForm[0][studentamka],
'regionaddress' => $applicationForm[0][regionaddress],
'regionarea' => $applicationForm[0][regionarea],
'regiontk' => $applicationForm[0][regiontk],
'certificatetype' => $applicationForm[0][certificatetype],
//'lastam' => $applicationForm[0][lastam],
'currentclass' => $applicationForm[0][currentclass],
'guardian_name' => $applicationForm[0][cu_name],
'guardian_surname' => $applicationForm[0][cu_surname],
'guardian_fathername' => $applicationForm[0][cu_fathername],
'guardian_mothername' => $applicationForm[0][cu_mothername],
'agreement' => $applicationForm[0][disclaimer_checked],
//'currentepal' => $applicationForm[0][currentepal],
//'currentsector' => $applicationForm[0][currentsector],
'points' => $applicationForm[0][points],
'relationtostudent' => $applicationForm[0][relationtostudent],
'telnum' => $applicationForm[0][telnum]
'langcode' => 'el',
'student_record_id' => 0,
'sex' => 0,
'fathersurname' => '',
'mothersurname' => '',
'studentamka' => '',
'lastam' => '',
'graduate_school' => 0,
'apolytirio_id' => '',
'currentsector' => '',
'currentcourse' => '',
'points' => 0,
'user_id' => $epalUser->user_id->target_id,
'epaluser_id' => $epalUser->id(),
'name' => $applicationForm[0]['name'],
'studentsurname' => $applicationForm[0]['studentsurname'],
'birthdate' => $applicationForm[0]['studentbirthdate'],
'fatherfirstname' => $applicationForm[0]['fatherfirstname'],
'motherfirstname' => $applicationForm[0]['motherfirstname'],
'regionaddress' => $applicationForm[0]['regionaddress'],
'regionarea' => $applicationForm[0]['regionarea'],
'regiontk' => $applicationForm[0]['regiontk'],
'certificatetype' => $applicationForm[0]['certificatetype'],
'graduation_year' => $applicationForm[0]['graduation_year'],
'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'],
'lastschool_schoolyear' => $applicationForm[0]['lastschool_schoolyear'],
'lastschool_class' => $applicationForm[0]['lastschool_class'],
'currentepal' => $applicationForm[0]['currentepal'],
'currentclass' => $applicationForm[0]['currentclass'],
'guardian_name' => $applicationForm[0]['cu_name'],
'guardian_surname' => $applicationForm[0]['cu_surname'],
'guardian_fathername' => $applicationForm[0]['cu_fathername'],
'guardian_mothername' => $applicationForm[0]['cu_mothername'],
'agreement' => $applicationForm[0]['disclaimer_checked'],
'relationtostudent' => $applicationForm[0]['relationtostudent'],
'telnum' => $applicationForm[0]['telnum']
);
if (($errorCode = $this->validateStudent($student)) > 0) {
return $this->respondWithStatus([
"error_code" => $errorCode ], Response::HTTP_OK);
}
$entity_storage_student = $this->entityTypeManager->getStorage('epal_student');
$entity_object = $entity_storage_student->create($student);
$entity_storage_student->save($entity_object);
$created_student_id = $entity_object->id();
//insert records in entity: epal_student_epal_chosen
for ($i = 0; $i < sizeof($applicationForm[1]); $i++) {
$epalchosen = array(
//'name' => $applicationForm[1][$i][name],
'student_id' => $created_student_id,
'epal_id' => $applicationForm[1][$i][epal_id],
'choice_no' => $applicationForm[1][$i][choice_no]
//'points_for_order' => $applicationForm[1][$i][points_for_order],
//'distance_from_epal' => $applicationForm[1][$i][distance_from_epal],
//'points_for_distance' => $applicationForm[1][$i][points_for_distance],
'epal_id' => $applicationForm[1][$i]['epal_id'],
'choice_no' => $applicationForm[1][$i]['choice_no']
);
$entity_storage_epalchosen = $this->entityTypeManager->getStorage('epal_student_epal_chosen');
$entity_object = $entity_storage_epalchosen->create($epalchosen);
$entity_storage_epalchosen->save($entity_object);
}
//insert records in entity: epal_student_moria
for ($i = 0; $i < sizeof($applicationForm[2]); $i++) {
$criteria = array(
//'name' => $applicationForm[2][$i][name],
'student_id' => $created_student_id,
'income' => $applicationForm[2][$i][income],
'criterio_id' => $applicationForm[2][$i][criterio_id],
//'moria' => $applicationForm[2][$i][moria],
);
$entity_storage_criteria = $this->entityTypeManager->getStorage('epal_student_moria');
$entity_object = $entity_storage_criteria->create($criteria);
$entity_storage_criteria->save($entity_object);
}
//insert records in entity: epal_student_course_field (αφορά μαθητές Γ' Λυκείου)
// or: epal_student_sector_field (αφορά μαθητές Β' Λυκείου)
//if ($applicationForm[0][currentclass] === "Γ' Λυκείου") {
if ($applicationForm[0][currentclass] === "3" || $applicationForm[0][currentclass] === "4" ) {
//$course = array('name
if ($applicationForm[0]['currentclass'] === "3" || $applicationForm[0]['currentclass'] === "4" ) {
$course = array(
//'name' => $aitisi[3][name],
//'student_id' => $aitis[3][student_i],
'student_id' => $created_student_id,
'coursefield_id' => $applicationForm[3][coursefield_id]
'coursefield_id' => $applicationForm[3]['coursefield_id']
);
$entity_storage_course = $this->entityTypeManager->getStorage('epal_student_course_field');
......@@ -155,13 +140,10 @@ class ApplicationSubmit extends ControllerBase {
$entity_storage_course->save($entity_object);
}
//else if ($applicationForm[0][currentclass] === "Β' Λυκείου") {
else if ($applicationForm[0][currentclass] === "2") {
else if ($applicationForm[0]['currentclass'] === "2") {
$sector = array(
//'name' => $applicationForm[3][name],
'student_id' => $created_student_id,
//'student_id' => $aitis[3][student_i],
'sectorfield_id' => $applicationForm[3][sectorfield_id]
'sectorfield_id' => $applicationForm[3]['sectorfield_id']
);
$entity_storage_sector = $this->entityTypeManager->getStorage('epal_student_sector_field');
......@@ -174,7 +156,9 @@ class ApplicationSubmit extends ControllerBase {
}
catch (\Exception $e) {
print_r($e->getMessage());
$this->logger->warning($e->getMessage());
$transaction->rollback();
return $this->respondWithStatus([
"error_code" => 5001
......
......@@ -200,27 +200,27 @@ public function getStudentPerSchool(Request $request , $selectId, $classId, $lim
{
$list=array(
'id' => sizeof($studentPerSchool),
'up' => $limitup,
'up' => $limitup,
'down' => $limitdown
);
);
}
else
else
{
foreach ($studentPerSchool as $object)
{
$studentId = $object -> id() ;
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $studentId));
$epalStudent = reset($epalStudents);
if ($epalStudents) {
$studentIdNew = $epalStudent -> id();
$checkstatus = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array( 'student_id'=> $studentIdNew));
$checkstudentstatus = reset($checkstatus);
if ($i >= $limitdown && $i < $limitup)
{
{
$newstatus = $checkstudentstatus -> directorconfirm-> getValue();
$list[] = array(
'i' => $i,
'id' => $epalStudent -> id(),
......@@ -283,7 +283,7 @@ public function getStudentPerSchool(Request $request , $selectId, $classId, $lim
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
//
//
$postData = null;
......@@ -426,8 +426,7 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
}
public function getSchoolsPerPerfetcure(Request $request, $check_status)
public function getSchools(Request $request)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
......@@ -437,19 +436,31 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
if ($user)
{
$selectionId = $user -> init -> value;
if ($check_status == 1){
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $selectionId ));
}
else
{
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if (($tmpRole === 'epal') || ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
$userRole = $tmpRole;
}
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
}
else if ($userRole === 'regioneduadmin') {
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $selectionId ));
}
else if ($userRole === 'eduadmin') {
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('edu_admin_id'=> $selectionId ));
}
if ($schools)
}
if ($schools)
{
$list = array();
foreach ($schools as $object) {
$status = $this->returnstatus($object -> id());
$status = $this->returnstatus($object -> id());
$list[] = array(
'id' =>$object -> id(),
'name' => $object -> name ->value,
......@@ -469,7 +480,7 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
], Response::HTTP_FORBIDDEN);
}
}
}
else
{
......@@ -495,14 +506,14 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
$list= array();
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCat = reset($SchoolCats);
if ($SchoolCat){
$categ = $SchoolCat-> metathesis_region -> value;
}
$CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $schoolid ));
if ($CourseA)
if ($CourseA)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 1, 'category' => $categ ));
$limitdown = reset($limit_down);
......@@ -521,10 +532,10 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
'classes' => 1,
'limitdown' => $limit,
);
} }
$CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
if ($CourseB)
{
......@@ -570,13 +581,13 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
'categ' => $categ,
'classes' => 3,
'limitdown' => $limit,
);
}
}
if ($CourseA || $CourseB || $CourseC)
{
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
......@@ -588,7 +599,7 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
], Response::HTTP_FORBIDDEN);
}
}
}
else
{
......@@ -602,14 +613,14 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
public function returnstatus($id)
{
$schoolid = $id;
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCat = reset($SchoolCats);
if ($SchoolCat){
$categ = $SchoolCat-> metathesis_region -> value;
}
$CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $schoolid ));
if ($CourseA)
if ($CourseA)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 1, 'category' => $categ ));
$limitdown = reset($limit_down);
......@@ -618,16 +629,16 @@ public function returnstatus($id)
$limit = $limitdown -> limit_down -> value;
}
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => -1, 'currentclass' => 1 ));
//foreach ($CourseA as $object) {
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
return false;
// exit;
}
} // }
$CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
if ($CourseB)
{
......@@ -642,8 +653,8 @@ public function returnstatus($id)
$sectorid = $object -> sector_id -> entity -> id();
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2 ));
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
return false;
exit;
}
}
}
......@@ -663,12 +674,12 @@ public function returnstatus($id)
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
}
exit;
}
}
}
return true;
exit;
// exit;
}
......