Commit 49681e06 authored by Open Source Developer's avatar Open Source Developer

bugs

parents 695e19e1 9e92e774
......@@ -188,9 +188,11 @@ class CASLogin extends ControllerBase
phpCAS::trace($umdobject);
phpCAS::trace($physicaldeliveryofficename);
$gsnunitcodedn = $filterAttribute('edupersonorgunitdn:gsnunitcode:extended');
// phpCAS::trace($physicaldeliveryofficename);
// $gsnunitcodedn = $filterAttribute('edupersonorgunitdn:gsnunitcode:extended');
$gsnunitcode = substr($gsnunitcodedn, strpos($gsnunitcodedn, ";") + 1);
$gsnunitcode = $filterAttribute('edupersonorgunitdn:gsnunitcode');
phpCAS::trace("$gsnunitcode=");
phpCAS::trace($gsnunitcode);
/* check if myschool account */
......@@ -274,6 +276,7 @@ class CASLogin extends ControllerBase
if ($user) {
$user->setPassword($epalToken);
$user->setUsername($epalToken);
$user->set('init', $userAssigned["id"]);
$user->save();
}
......
......@@ -46,6 +46,14 @@ epal.submitedapplications:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getSubmittedApplications'
requirements:
_user_is_logged_in: 'TRUE'
epal.application_delete:
path: '/epal/application/delete'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\SubmitedApplications::deleteApplication'
requirements:
_user_is_logged_in: 'TRUE'
epal.studentapplication:
path: '/epal/student/{studentId}'
options:
......@@ -78,6 +86,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.confirmstudents:
path: '/epal/confirmstudent'
options:
......@@ -221,7 +237,7 @@ epal.coursesperschools:
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getCoursesPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
_user_is_logged_in: 'TRUE'
epal.critirioschosen:
path: '/epal/critiriachosen/{studentId}/{type}'
options:
......@@ -278,6 +294,3 @@ epal.findcoursesperschool:
_controller: '\Drupal\epal\Controller\DirectorView::FindCoursesPerSchool'
requirements:
_user_is_logged_in: 'TRUE'
......@@ -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'],
......@@ -285,6 +285,7 @@ class ApplicationSubmit extends ControllerBase
*/
private function validateStudent($student)
{
$error_code = 0;
if (!$student["agreement"]) {
return 1001;
}
......@@ -298,6 +299,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 +324,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;
}
......
......@@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Database\Connection;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Crypt;
class CurrentUser extends ControllerBase
{
......@@ -84,16 +85,45 @@ class CurrentUser extends ControllerBase
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$crypt = new Crypt();
try {
$name_decoded = $crypt->decrypt($epalUser->name->value);
$surname_decoded = $crypt->decrypt($epalUser->surname->value);
$fathername_decoded = $crypt->decrypt($epalUser->fathername->value);
$mothername_decoded = $crypt->decrypt($epalUser->mothername->value);
}
catch (\Exception $e) {
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"error_code" => 5001
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
unset($crypt);
/*
$userName = $epalUser->name->value;
$userSurname = $epalUser->surname->value;
$userFathername = $epalUser->fathername->value;
$userMothername = $epalUser->mothername->value;
*/
$userName = $name_decoded;
$userSurname = $surname_decoded ;
$userFathername = $fathername_decoded;
$userMothername =$mothername_decoded;
$userEmail = $user->mail->value;
return $this->respondWithStatus([
'cu_name' => mb_substr($epalUser->name->value,0,4,'UTF-8') !== "####" ? $epalUser->name->value : '',
'cu_surname' => mb_substr($epalUser->surname->value,0,4,'UTF-8') !== "####" ? $epalUser->surname->value : '',
'cu_fathername' => mb_substr($epalUser->fathername->value,0,4,'UTF-8') !== "####" ? $epalUser->fathername->value : '',
'cu_mothername' => mb_substr($epalUser->mothername->value,0,4,'UTF-8') !== "####" ? $epalUser->mothername->value : '',
//'cu_name' => mb_substr($epalUser->name->value,0,4,'UTF-8') !== "####" ? $epalUser->name->value : '',
//'cu_surname' => mb_substr($epalUser->surname->value,0,4,'UTF-8') !== "####" ? $epalUser->surname->value : '',
//'cu_fathername' => mb_substr($epalUser->fathername->value,0,4,'UTF-8') !== "####" ? $epalUser->fathername->value : '',
//'cu_mothername' => mb_substr($epalUser->mothername->value,0,4,'UTF-8') !== "####" ? $epalUser->mothername->value : '',
'cu_name' => mb_substr($userName,0,4,'UTF-8') !== "####" ? $userName : '',
'cu_surname' => mb_substr($userSurname,0,4,'UTF-8') !== "####" ? $userSurname : '',
'cu_fathername' => mb_substr($userFathername,0,4,'UTF-8') !== "####" ? $userFathername : '',
'cu_mothername' => mb_substr($userMothername,0,4,'UTF-8') !== "####" ? $userMothername : '',
'cu_email' => mb_substr($user->mail->value,0,4,'UTF-8') !== "####" ? $user->mail->value : '',
'minedu_username' => '',
'minedu_userpassword' => '',
......@@ -119,16 +149,39 @@ class CurrentUser extends ControllerBase
if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) {
$userName = $epalUser->name->value;
$userSurname = $epalUser->surname->value;
$userFathername = $epalUser->fathername->value;
$userMothername = $epalUser->mothername->value;
$crypt = new Crypt();
try {
$userName = $crypt->decrypt($epalUser->name->value);
$userSurname = $crypt->decrypt($epalUser->surname->value);
$userFathername = $crypt->decrypt($epalUser->fathername->value);
$userMothername = $crypt->decrypt($epalUser->mothername->value);
}
catch (\Exception $e) {
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"error_code" => 5001
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
unset($crypt);
//$userName = $epalUser->name->value;
//$userSurname = $epalUser->surname->value;
//$userFathername = $epalUser->fathername->value;
//$userMothername = $epalUser->mothername->value;
$userEmail = $user->mail->value;
return $this->respondWithStatus([
'userName' => mb_substr($epalUser->name->value,0,4,'UTF-8') !== "####" ? $epalUser->name->value : '',
'userSurname' => mb_substr($epalUser->surname->value,0,4,'UTF-8') !== "####" ? $epalUser->surname->value : '',
'userFathername' => mb_substr($epalUser->fathername->value,0,4,'UTF-8') !== "####" ? $epalUser->fathername->value : '',
'userMothername' => mb_substr($epalUser->mothername->value,0,4,'UTF-8') !== "####" ? $epalUser->mothername->value : '',
//'userName' => mb_substr($epalUser->name->value,0,4,'UTF-8') !== "####" ? $epalUser->name->value : '',
//'userSurname' => mb_substr($epalUser->surname->value,0,4,'UTF-8') !== "####" ? $epalUser->surname->value : '',
//'userFathername' => mb_substr($epalUser->fathername->value,0,4,'UTF-8') !== "####" ? $epalUser->fathername->value : '',
//'userMothername' => mb_substr($epalUser->mothername->value,0,4,'UTF-8') !== "####" ? $epalUser->mothername->value : '',
'userName' => mb_substr($userName,0,4,'UTF-8') !== "####" ? $userName : '',
'userSurname' => mb_substr($userSurname,0,4,'UTF-8') !== "####" ? $userSurname : '',
'userFathername' => mb_substr($userFathername,0,4,'UTF-8') !== "####" ? $userFathername : '',
'userMothername' => mb_substr($userMothername,0,4,'UTF-8') !== "####" ? $userMothername : '',
'userEmail' => mb_substr($user->mail->value,0,4,'UTF-8') !== "####" ? $user->mail->value : '',
'verificationCodeVerified' => $epalUser->verificationcodeverified->value,
], Response::HTTP_OK);
......@@ -286,23 +339,56 @@ class CurrentUser extends ControllerBase
$postData = null;
if ($content = $request->getContent()) {
$postData = json_decode($content);
$crypt = new Crypt();
try {
$name_encoded = $crypt->encrypt($postData->userProfile->userName);
$surname_encoded = $crypt->encrypt($postData->userProfile->userSurname);
$fathername_encoded = $crypt->encrypt($postData->userProfile->userMothername);
$mothername_encoded = $crypt->encrypt($postData->userProfile->userFathername);
}
catch (\Exception $e) {
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"error_code" => 5001
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
unset($crypt);
/*
$epalUser->set('name', $postData->userProfile->userName);
$epalUser->set('surname', $postData->userProfile->userSurname);
$epalUser->set('mothername', $postData->userProfile->userMothername);
$epalUser->set('fathername', $postData->userProfile->userFathername);
*/
$epalUser->set('name', $name_encoded);
$epalUser->set('surname', $surname_encoded);
$epalUser->set('mothername', $fathername_encoded);
$epalUser->set('fathername', $mothername_encoded);
$epalUser->save();
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) {
$user->set('mail', $postData->userProfile->userEmail);
$user->save();
} else {
return $this->respondWithStatus([
'error_code' => '1001',
], Response::HTTP_FORBIDDEN);
}
return $this->respondWithStatus([
'message' => t("profile saved"),
'error_code' => '0',
], Response::HTTP_OK);
} else {
return $this->respondWithStatus([
'message' => t("post with no data"),
'error_code' => '1002',
], Response::HTTP_BAD_REQUEST);
}
} else {
return $this->respondWithStatus([
'message' => t("EPAL user not found"),
'error_code' => '1003',
], Response::HTTP_FORBIDDEN);
}
}
......
......@@ -35,12 +35,11 @@ class DirectorView extends ControllerBase
);
}
public function getStudentPerSchool(Request $request, $classId, $sector, $specialit)
{
try {
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalConfigs = $this->entityTypeManager->getStorage('epal_config')->loadByProperties(array('name' => 'epal_config'));
......@@ -70,157 +69,139 @@ class DirectorView extends ControllerBase
}
$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);
}
elseif ($userRole === 'epal')
{
} elseif ($userRole === 'epal') {
$selectIdNew = $selectId;
if ($classId == 1)
if ($classId == 1) {
$selectIdNew = -1;
elseif ($classId == 2)
} elseif ($classId == 2) {
$selectIdNew = $sector;
else
} else {
$selectIdNew = $specialit;
}
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('epal_id' => $epalId, 'specialization_id' => $selectIdNew, 'currentclass' => $classId));
}
$i = 0;
if ($studentPerSchool)
{
$list = array();
foreach ($studentPerSchool as $object)
{
}
$i = 0;
if ($studentPerSchool) {
$list = array();
foreach ($studentPerSchool as $object) {
$studentId = intval($object->student_id ->getString());
$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);
$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;
}
$crypt = new Crypt();
try {
$name_decoded = $crypt->decrypt($epalStudent->name->value);
$studentsurname_decoded = $crypt->decrypt($epalStudent->studentsurname->value);
$fatherfirstname_decoded = $crypt->decrypt($epalStudent->fatherfirstname->value);
$motherfirstname_decoded = $crypt->decrypt($epalStudent->motherfirstname->value);
$regionaddress_decoded = $crypt->decrypt($epalStudent->regionaddress->value);
$regiontk_decoded = $crypt->decrypt($epalStudent->regiontk->value);
$regionarea_decoded = $crypt->decrypt($epalStudent->regionarea->value);
$certificatetype_decoded = $crypt->decrypt($epalStudent->certificatetype->value);
$relationtostudent_decoded = $crypt->decrypt($epalStudent->relationtostudent->value);
$telnum_decoded = $crypt->decrypt($epalStudent->telnum->value);
$guardian_name_decoded = $crypt->decrypt($epalStudent->guardian_name->value);
$guardian_surname_decoded = $crypt->decrypt($epalStudent->guardian_surname->value);
$guardian_fathername_decoded = $crypt->decrypt($epalStudent->guardian_fathername->value);
$guardian_mothername_decoded = $crypt->decrypt($epalStudent->guardian_mothername->value);
} catch (\Exception $e) {
$this->logger->warning(__METHOD__ . ' Decrypt error: ' . $e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected error occured during DECODING data in getStudentPerSchool Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$list[] = array(
'id' => $epalStudent->id(),
'name' => $name_decoded,
'studentsurname' => $studentsurname_decoded,
'fatherfirstname' => $fatherfirstname_decoded,
'motherfirstname' => $motherfirstname_decoded,
'guardian_name' => $guardian_name_decoded,
'guardian_surname' => $guardian_surname_decoded,
'guardian_fathername' => $guardian_fathername_decoded,
'guardian_mothername' => $guardian_mothername_decoded,
'lastschool_schoolname' => $epalStudent->lastschool_schoolname->value,
'lastschool_schoolyear' => $epalStudent->lastschool_schoolyear->value,
'lastschool_class' => $epalStudent->lastschool_class->value,
'currentclass' =>$epalStudent -> currentclass ->value,
'currentsector' =>$sectorName,
'currentcourse' =>$courseName,
'regionaddress' => $regionaddress_decoded,
'regiontk' => $regiontk_decoded,
'regionarea' => $regionarea_decoded,
'certificatetype' => $certificatetype_decoded,
'graduation_year' => $epalStudent->graduation_year->value,
'telnum' => $telnum_decoded,
'relationtostudent' => $relationtostudent_decoded,
//'birthdate' => substr($epalStudent->birthdate->value, 8, 10) . '/' . substr($epalStudent->birthdate->value, 6, 8) . '/' . substr($epalStudent->birthdate->value, 0, 4),
'birthdate' => date("d-m-Y", strtotime($epalStudent->birthdate->value)),
'checkstatus' => $checkstudentstatus -> directorconfirm ->value,
'created' => date('d/m/Y H:i', $epalStudent -> created ->value),
);
if ($epalStudents) {
$studentIdNew = $epalStudent->id();
$checkstatus = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $studentIdNew));
$checkstudentstatus = reset($checkstatus);
$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;
}
} elseif ($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;
}
}
$crypt = new Crypt();
try {
$name_decoded = $crypt->decrypt($epalStudent->name->value);
$studentsurname_decoded = $crypt->decrypt($epalStudent->studentsurname->value);
$fatherfirstname_decoded = $crypt->decrypt($epalStudent->fatherfirstname->value);
$motherfirstname_decoded = $crypt->decrypt($epalStudent->motherfirstname->value);
$regionaddress_decoded = $crypt->decrypt($epalStudent->regionaddress->value);
$regiontk_decoded = $crypt->decrypt($epalStudent->regiontk->value);
$regionarea_decoded = $crypt->decrypt($epalStudent->regionarea->value);
$certificatetype_decoded = $crypt->decrypt($epalStudent->certificatetype->value);
$relationtostudent_decoded = $crypt->decrypt($epalStudent->relationtostudent->value);
$telnum_decoded = $crypt->decrypt($epalStudent->telnum->value);
$guardian_name_decoded = $crypt->decrypt($epalStudent->guardian_name->value);
$guardian_surname_decoded = $crypt->decrypt($epalStudent->guardian_surname->value);
$guardian_fathername_decoded = $crypt->decrypt($epalStudent->guardian_fathername->value);
$guardian_mothername_decoded = $crypt->decrypt($epalStudent->guardian_mothername->value);
} catch (\Exception $e) {
$this->logger->warning(__METHOD__ . ' Decrypt error: ' . $e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected error occured during DECODING data in getStudentPerSchool Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$list[] = array(
'id' => $epalStudent->id(),
'name' => $name_decoded,
'studentsurname' => $studentsurname_decoded,
'fatherfirstname' => $fatherfirstname_decoded,
'motherfirstname' => $motherfirstname_decoded,
'guardian_name' => $guardian_name_decoded,
'guardian_surname' => $guardian_surname_decoded,
'guardian_fathername' => $guardian_fathername_decoded,
'guardian_mothername' => $guardian_mothername_decoded,
'lastschool_schoolname' => $epalStudent->lastschool_schoolname->value,
'lastschool_schoolyear' => $epalStudent->lastschool_schoolyear->value,
'lastschool_class' => $epalStudent->lastschool_class->value,
'currentclass' =>$epalStudent -> currentclass ->value,
'currentsector' =>$sectorName,
'currentcourse' =>$courseName,
'regionaddress' => $regionaddress_decoded,
'regiontk' => $regiontk_decoded,
'regionarea' => $regionarea_decoded,
'certificatetype' => $certificatetype_decoded,
'graduation_year' => $epalStudent->graduation_year->value,
'telnum' => $telnum_decoded,
'relationtostudent' => $relationtostudent_decoded,
//'birthdate' => substr($epalStudent->birthdate->value, 8, 10) . '/' . substr($epalStudent->birthdate->value, 6, 8) . '/' . substr($epalStudent->birthdate->value, 0, 4),
'birthdate' => date("d-m-Y", strtotime($epalStudent->birthdate->value)),
'checkstatus' => $checkstudentstatus -> directorconfirm ->value,
'created' => date('d/m/Y H:i', $epalStudent -> created ->value),
);
}
++$i;
}
return $this->respondWithStatus(
}
return $this->respondWithStatus(
$list, Response::HTTP_OK);
}
else
{
return $this->respondWithStatus([
} else {
return $this->respondWithStatus([
'message' => t('Students not found!'),
], Response::HTTP_FORBIDDEN);
}
} else {
return $this->respondWithStatus([
'message' => t('User not found!'),
], Response::HTTP_FORBIDDEN);
}
}
else
{
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
'message' => t('User not found!'),
], Response::HTTP_FORBIDDEN);
}
}
catch (\Exception $e)
{
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
'message' => t('Unexpected Error'),
'message' => t('Unexpected Error'),
], Response::HTTP_FORBIDDEN);
}
}
}
public function ConfirmStudents(Request $request)
{
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
'message' => t('Method Not Allowed'),
], Response::HTTP_METHOD_NOT_ALLOWED);
return $this->respondWithStatus(['message' => t('Method Not Allowed')], Response::HTTP_METHOD_NOT_ALLOWED);
}
$authToken = $request->headers->get('PHP_AUTH_USER');
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
......@@ -231,74 +212,42 @@ class DirectorView extends ControllerBase
$userRole = $tmpRole;
}
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
} elseif ($userRole === 'epal') {
$postData = null;
if ($userRole === 'epal') {
if ($content = $request->getContent()) {
$postData = json_decode($content);
$arr = $postData->students;
$type = $postData->type;
$valnew = intval($arr);
$typen = intval($type);
$studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('id' => $valnew));
$studentConfirm = reset($studentForConfirm);
if ($studentConfirm) {
if ($typen === 1) {
$studentConfirm->set('directorconfirm', 1);
$studentConfirm->save();
return $this->respondWithStatus([
'message' => t('saved')
,
], Response::HTTP_OK);
}
elseif ($typen === 2) {
$studentConfirm->set('directorconfirm', 0);
$studentConfirm->save();
return $this->respondWithStatus([
'message' => t('saved')
,
], Response::HTTP_OK);
}
elseif ($typen === 3) {
unset($studentConfirm->{directorconfirm});
$studentConfirm->save();
return $this->respondWithStatus([
'message' => t('saved')
,
], Response::HTTP_OK);
}
else
{
return $this->respondWithStatus([
'message' => t('Bad request'),
], Response::HTTP_FORBIDDEN);
}
}
else
{
return $this->respondWithStatus([
'message' => t('Student not found'),
], Response::HTTP_FORBIDDEN);
$studentForConfirm = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(['student_id' => $valnew]);
$studentConfirm = reset($studentForConfirm);
if ($studentConfirm) {
if ($typen === 1) {
$studentConfirm->set('directorconfirm', 1);
$studentConfirm->save();
return $this->respondWithStatus(['message' => t('saved')], Response::HTTP_OK);
} elseif ($typen === 2) {
$studentConfirm->set('directorconfirm', 0);
$studentConfirm->save();
return $this->respondWithStatus(['message' => t('saved')], Response::HTTP_OK);
} elseif ($typen === 3) {
unset($studentConfirm->{directorconfirm});
$studentConfirm->save();
return $this->respondWithStatus(['message' => t('saved')], Response::HTTP_OK);
} else {
return $this->respondWithStatus(['message' => t('Bad request')], Response::HTTP_FORBIDDEN);
}
} else {
return $this->respondWithStatus(['message' => t('Student not found')], Response::HTTP_FORBIDDEN);
}
} 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);
return $this->respondWithStatus(['error_code' => 4003], Response::HTTP_FORBIDDEN);