Merge branch 'lock_actions' into 'develop'

Restructuring application views. Checking if account allowed(WIP)

See merge request !140
parents 71c37c05 d26c7f51
......@@ -173,7 +173,7 @@ class CASLogin extends ControllerBase
};
$umdobject = $filterAttribute("umdobject");
$physicaldeliveryofficename = $filterAttribute("physicaldeliveryofficename");
// $physicaldeliveryofficename = $filterAttribute("physicaldeliveryofficename");
/****** the following is for production : Χρήση μόνο από ΕΠΙΣΗΜΟΥΣ ΛΟΓΑΡΙΑΣΜΟΥΣ ***************************/
......@@ -186,12 +186,27 @@ class CASLogin extends ControllerBase
}
*/
phpCAS::trace($umdobject);
phpCAS::trace($physicaldeliveryofficename);
$gsnunitcodedn = $filterAttribute('edupersonorgunitdn:gsnunitcode:extended');
$gsnunitcode = substr($gsnunitcodedn, strpos($gsnunitcodedn, ";") + 1);
phpCAS::trace($gsnunitcode);
/* check if myschool account */
if (!$umdobject || $umdobject !== "ISaccount") {
return $this->redirectForbidden($configRowName, '5002');
}
if (!$gsnunitcode || $gsnunitcode !== $CASUser) {
return $this->redirectForbidden($configRowName, '5003');
}
/* end of checking myschool account */
$userAssigned = $this->assignRoleToUser($gsnunitcode);
if (sizeof($userAssigned) === 0) {
return $this->redirectForbidden($configRowName, '5004');
}
......
......@@ -8,7 +8,6 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Database\Connection;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
class DirectorView extends ControllerBase
......@@ -32,597 +31,525 @@ class DirectorView extends ControllerBase
);
}
public function getSectorsPerSchool(Request $request)
public function getSectorsPerSchool(Request $request)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
$epalId = $user -> init -> value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->
$user = reset($users);
if ($user) {
$epalId = $user->init->value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->
loadByProperties(array('id' => $epalId));
$school = reset($schools);
if (!$school) {
$this->logger->warning("no access to this school=" . $user->id());
$response = new Response();
$response->setContent('No access to this school');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
$school = reset($schools);
if (!$school) {
$this->logger->warning('no access to this school='.$user->id());
$response = new Response();
$response->setContent('No access to this school');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
if ($userRole === '') {
return $this->respondWithStatus([
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
}
else if ($userRole === 'epal')
{
$sectorPerSchool = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id'=> $epalId));
if ($sectorPerSchool) {
$list = array();
foreach ($sectorPerSchool as $object) {
$list[] = array(
'sector_id' => $object -> sector_id ->entity->get('name')->value ,
'id' => $object -> sector_id -> entity -> id()
} elseif ($userRole === 'epal') {
$sectorPerSchool = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $epalId));
if ($sectorPerSchool) {
$list = array();
foreach ($sectorPerSchool as $object) {
$list[] = array(
'sector_id' => $object->sector_id->entity->get('name')->value,
'id' => $object->sector_id->entity->id(),
);
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
return $this->respondWithStatus(
$list, Response::HTTP_OK);
}
}
else {
return $this->respondWithStatus([
'message' => t("School not found!!!"),
} else {
return $this->respondWithStatus([
'message' => t('School not found!!!'),
], Response::HTTP_OK);
}
}
} else {
return $this->respondWithStatus([
'message' => t("User not found!"),
'message' => t('User not found!'),
], Response::HTTP_FORBIDDEN);
}
}
public function getSpecialPerSchool(Request $request , $sectorId)
public function getSpecialPerSchool(Request $request, $sectorId)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
$epalId = $user -> init -> value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array( 'id' => $epalId));
$school = reset($schools);
if (!$school) {
$this->logger->warning("no access to this school=" . $user->id());
$response = new Response();
$response->setContent('No access to this school');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
$user = reset($users);
if ($user) {
$epalId = $user->init->value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $epalId));
$school = reset($schools);
if (!$school) {
$this->logger->warning('no access to this school='.$user->id());
$response = new Response();
$response->setContent('No access to this school');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
if ($userRole === '') {
return $this->respondWithStatus([
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
}
else if ($userRole === 'epal')
{
$specialityPerSchool = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id'=> $epalId));
} elseif ($userRole === 'epal') {
$specialityPerSchool = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $epalId));
$i = 0;
if ($specialityPerSchool) {
$list = array();
$SectorIdNew = intval($sectorId);
foreach ($specialityPerSchool as $object) {
$idSpecial = $object -> specialty_id -> entity -> id() ;
$specialityPerSector = $this->entityTypeManager->getStorage('eepal_specialty')->loadByProperties(array('id'=> $idSpecial,'sector_id' => $SectorIdNew ));
$specialPerSec = reset($specialityPerSector);
if ($specialPerSec)
{ $list[] = array(
'specialty_id' => $object -> specialty_id ->entity->get('name')->value ,
'id' => $object -> specialty_id -> entity -> id() );
$i++;
}
if ($specialityPerSchool) {
$list = array();
$SectorIdNew = intval($sectorId);
foreach ($specialityPerSchool as $object) {
$idSpecial = $object->specialty_id->entity->id();
}
$specialityPerSector = $this->entityTypeManager->getStorage('eepal_specialty')->loadByProperties(array('id' => $idSpecial, 'sector_id' => $SectorIdNew));
$specialPerSec = reset($specialityPerSector);
if ($specialPerSec) {
$list[] = array(
'specialty_id' => $object->specialty_id->entity->get('name')->value,
'id' => $object->specialty_id->entity->id(), );
++$i;
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
return $this->respondWithStatus(
$list, Response::HTTP_OK);
}
}
else {
return $this->respondWithStatus([
'message' => t("School not found!!!"),
} else {
return $this->respondWithStatus([
'message' => t('School not found!!!'),
], Response::HTTP_OK);
}
}
} else {
return $this->respondWithStatus([
'message' => t("User not found!"),
'message' => t('User not found!'),
], Response::HTTP_FORBIDDEN);
}
}
public function getStudentPerSchool(Request $request , $selectId, $classId, $limitdown, $limitup)
public function getStudentPerSchool(Request $request, $selectId, $classId, $limitdown, $limitup)
{
try {
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
$epalId = $user -> init -> value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array( 'id' => $epalId));
$epalId = $user->init->value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $epalId));
$school = reset($schools);
if (!$school) {
$this->logger->warning("no access to this school=" . $user->id());
$this->logger->warning('no access to this school='.$user->id());
$response = new Response();
$response->setContent('No access to this school');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
if ($userRole === '') {
return $this->respondWithStatus([
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
}
else if ($userRole === 'epal')
{
} elseif ($userRole === 'epal') {
$selectIdNew = $epalId;
if ($classId == 1)
{
$selectIdNew = -1;
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
}
else
{
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id'=> $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId ));
if ($classId == 1) {
$selectIdNew = -1;
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId));
} else {
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId));
}
$i = 0;
if ($studentPerSchool) {
$list = array();
$i = 0;
if ($limitdown==$limitup && $limitup == 0)
{
$list=array(
if ($studentPerSchool) {
$list = array();
$i = 0;
if ($limitdown == $limitup && $limitup == 0) {
$list = array(
'id' => sizeof($studentPerSchool),
'up' => $limitup,
'down' => $limitdown
'down' => $limitdown,
);
}
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(
} 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) {
$sectorName = '';
$courseName = '';
if ($epalStudent->currentclass->value === '2') {
$sectors = $this->entityTypeManager->getStorage('epal_student_sector_field')->loadByProperties(array('student_id' => $studentIdNew));
$sector = reset($sectors);
if ($sector)
$sectorName = $this->entityTypeManager->getStorage('eepal_sectors')->load($sector->sectorfield_id->target_id)->name->value;
}
else if ($epalStudent->currentclass->value === '3' || $epalStudent->currentclass->value === '4') {
$courses = $this->entityTypeManager->getStorage('epal_student_course_field')->loadByProperties(array('student_id' => $studentIdNew));
$course = reset($courses);
if ($course)
$courseName = $this->entityTypeManager->getStorage('eepal_specialty')->load($course->coursefield_id->target_id)->name->value;
}
$newstatus = $checkstudentstatus->directorconfirm->value;
$list[] = array(
'i' => $i,
'id' => $epalStudent -> id(),
'name' => $epalStudent -> name ->value,
'studentsurname' => $epalStudent -> studentsurname ->value,
'fatherfirstname' => $epalStudent -> fatherfirstname ->value,
'fathersurname' =>$epalStudent -> fathersurname ->value,
'motherfirstname' => $epalStudent -> motherfirstname ->value,
'mothersurname' =>$epalStudent -> mothersurname ->value,
'guardianfirstname' =>$epalUser -> name ->value,
'guardiansurname' =>$epalUser -> surname ->value,
'regionaddress' =>$epalStudent -> regionaddress ->value,
'regiontk' =>$epalStudent -> regiontk ->value,
'regionarea' =>$epalStudent -> regionarea ->value,
'certificatetype' =>$epalStudent -> certificatetype ->value,
'telnum' =>$epalStudent -> telnum ->value,
'relationtostudent' =>$epalStudent -> relationtostudent ->value,
'birthdate' =>$epalStudent -> birthdate ->value,
'checkstatus' =>$newstatus[0][value],
'id' => $epalStudent->id(),
'name' => $epalStudent->name->value,
'studentsurname' => $epalStudent->studentsurname->value,
'fatherfirstname' => $epalStudent->fatherfirstname->value,
'fathersurname' => $epalStudent->fathersurname->value,
'motherfirstname' => $epalStudent->motherfirstname->value,
'mothersurname' => $epalStudent->mothersurname->value,
'guardian_name' => $epalStudent->guardian_name->value,
'guardian_surname' => $epalStudent->guardian_surname->value,
'guardian_fathername' => $epalStudent->guardian_fathername->value,
'guardian_mothername' => $epalStudent->guardian_mothername->value,
'lastschool_schoolname' => $epalStudent->lastschool_schoolname->value,
'lastschool_schoolyear' => $epalStudent->lastschool_schoolyear->value,
'lastschool_class' => $epalStudent->currentclass->value,
'currentclass' =>$epalStudent -> currentclass ->value,
'currentsector' =>$sectorName,
'currentcourse' =>$courseName,
'regionaddress' => $epalStudent->regionaddress->value,
'regiontk' => $epalStudent->regiontk->value,
'regionarea' => $epalStudent->regionarea->value,
'certificatetype' => $epalStudent->certificatetype->value,
'graduation_year' => $epalStudent->graduation_year->value,
'telnum' => $epalStudent->telnum->value,
'relationtostudent' => $epalStudent->relationtostudent->value,
'birthdate' => substr($epalStudent->birthdate->value, 8, 10) . '/' . substr($epalStudent->birthdate->value, 6, 8) . '/' . substr($epalStudent->birthdate->value, 0, 4),
'checkstatus' => $newstatus[0][value],
'created' => date('d/m/Y H:i', $epalStudent -> created ->value),
);
}
$i++;
}
++$i;
}
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
}
else {
$list = array();
return $this->respondWithStatus($list, Response::HTTP_OK);
return $this->respondWithStatus(
$list, Response::HTTP_OK);
}
} else {
$list = array();
return $this->respondWithStatus($list, Response::HTTP_OK);
}
else {
} else {
return $this->respondWithStatus([
'message' => t("User not found!"),
'message' => t('User not found!'),
], Response::HTTP_FORBIDDEN);
}
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
'message' => t('Unexpected Error'),
], Response::HTTP_FORBIDDEN);
}
}
public function ConfirmStudents(Request $request)
{
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
'message' => t('Method Not Allowed'),
], Response::HTTP_METHOD_NOT_ALLOWED);
}
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
//
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
$user = reset($users);
if ($user) {
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
if ($userRole === '') {
return $this->respondWithStatus([
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
}
else if ($userRole === 'epal')
{
$postData = null;
if ($content = $request->getContent())
{
$postData = json_decode($content);
$arr = $postData->students;
$type = $postData ->type;
foreach ($arr as $value) {
$valnew = intval($value);
$studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('id' => $valnew ));
$studentConfirm = reset($studentForConfirm);
if ($studentConfirm) {
if ($type == 1)
$studentConfirm->set('directorconfirm', true);
if ($type == 2)
$studentConfirm->set('directorconfirm', false);
if ($type == 3)
unset($studentConfirm->{directorconfirm});
$studentConfirm->save();
} elseif ($userRole === 'epal') {
$postData = null;
if ($content = $request->getContent()) {
$postData = json_decode($content);
$arr = $postData->students;
$type = $postData->type;
foreach ($arr as $value) {
$valnew = intval($value);
$studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('id' => $valnew));
$studentConfirm = reset($studentForConfirm);
if ($studentConfirm) {
if ($type == 1) {
$studentConfirm->set('directorconfirm', true);
}
if ($type == 2) {
$studentConfirm->set('directorconfirm', false);
}
if ($type == 3) {
unset($studentConfirm->{directorconfirm});
}
$studentConfirm->save();
}
}
}
return $this->respondWithStatus([
'message' => t("saved"),
return $this->respondWithStatus([
'message' => t('saved'),
], Response::HTTP_OK);
}
}
else
{
return $this->respondWithStatus([
'message' => t("post with no data"),
], Response::HTTP_BAD_REQUEST);
}
} else {
return $this->respondWithStatus([
'message' => t('post with no data'),
], Response::HTTP_BAD_REQUEST);
}
} else {
return $this->respondWithStatus([
'message' => t("EPAL user not found"),
'message' => t('EPAL user not found'),
], Response::HTTP_FORBIDDEN);
}
}
public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
public function SaveCapacity(Request $request, $taxi, $tomeas, $specialit)
{
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
'message' => t('Method Not Allowed'),
], Response::HTTP_METHOD_NOT_ALLOWED);
}
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
$schoolid = $user -> init -> value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid));
$school = reset($schools);
if (!$school) {
$this->logger->warning("no access to this school=" . $user->id());
$response = new Response();
$response->setContent('No access to this school');
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
$user = reset($users);
if ($user) {
$schoolid = $user->init->value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $schoolid));
$school = reset($schools);
if (!$school) {
$this->logger->warning('no access to this school='.$user->id());