added php encoding/decoding methods in appropriate Drupal Controllers

parent efb927c5
......@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Crypt;
class ApplicationSubmit extends ControllerBase {
protected $entityTypeManager;
......@@ -56,7 +58,37 @@ class ApplicationSubmit extends ControllerBase {
"error_code" => 5002
], Response::HTTP_BAD_REQUEST);
}
$transaction = $this->connection->startTransaction();
$crypt = new Crypt();
try {
$name_encoded = $crypt->encrypt($applicationForm[0]['name']);
$studentsurname_encoded = $crypt->encrypt($applicationForm[0]['studentsurname']);
$fatherfirstname_encoded = $crypt->encrypt($applicationForm[0]['fatherfirstname']);
$motherfirstname_encoded = $crypt->encrypt($applicationForm[0]['motherfirstname']);
$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']);
$relationtostudent_encoded = $crypt->encrypt($applicationForm[0]['relationtostudent']);
$telnum_encoded = $crypt->encrypt($applicationForm[0]['telnum']);
$guardian_name_encoded = $crypt->encrypt($applicationForm[0]['cu_name']);
$guardian_surname_encoded = $crypt->encrypt($applicationForm[0]['cu_surname']);
$guardian_fathername_encoded = $crypt->encrypt($applicationForm[0]['cu_fathername']);
$guardian_mothername_encoded = $crypt->encrypt($applicationForm[0]['cu_mothername']);
}
catch (\Exception $e) {
print_r($e->getMessage());
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"error_code" => 5001
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
unset($crypt);
$transaction = $this->connection->startTransaction();
try {
//insert records in entity: epal_student
$authToken = $request->headers->get('PHP_AUTH_USER');
......@@ -84,29 +116,43 @@ class ApplicationSubmit extends ControllerBase {
'points' => 0,
'user_id' => $epalUser->user_id->target_id,
'epaluser_id' => $epalUser->id(),
'name' => $applicationForm[0]['name'],
'studentsurname' => $applicationForm[0]['studentsurname'],
//'name' => $applicationForm[0]['name'],
'name' => $name_encoded,
//'studentsurname' => $applicationForm[0]['studentsurname'],
'studentsurname' => $studentsurname_encoded,
'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'],
//'fatherfirstname' => $applicationForm[0]['fatherfirstname'],
'fatherfirstname' => $fatherfirstname_encoded,
//'motherfirstname' => $applicationForm[0]['motherfirstname'],
'motherfirstname' => $motherfirstname_encoded,
//'regionaddress' => $applicationForm[0]['regionaddress'],
'regionaddress' => $regionaddress_encoded,
//'regionarea' => $applicationForm[0]['regionarea'],
'regionarea' => $regionarea_encoded,
//'regiontk' => $applicationForm[0]['regiontk'],
'regiontk' => $regiontk_encoded,
//'certificatetype' => $applicationForm[0]['certificatetype'],
'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'],
'lastschool_schoolyear' => $applicationForm[0]['lastschool_schoolyear'],
'lastschool_class' => $applicationForm[0]['lastschool_class'],
'lastschool_registrynumber' => $applicationForm[0]['lastschool_registrynumber'],
'lastschool_unittypeid' => $applicationForm[0]['lastschool_unittypeid'],
'lastschool_schoolname' => $applicationForm[0]['lastschool_schoolname'],
'lastschool_schoolyear' => $applicationForm[0]['lastschool_schoolyear'],
'lastschool_class' => $applicationForm[0]['lastschool_class'],
'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']
//'guardian_name' => $applicationForm[0]['cu_name'],
'guardian_name' => $guardian_name_encoded,
//'guardian_surname' => $applicationForm[0]['cu_surname'],
'guardian_surname' => $guardian_surname_encoded,
//'guardian_fathername' => $applicationForm[0]['cu_fathername'],
'guardian_fathername' => $guardian_fathername_encoded,
//'guardian_mothername' => $applicationForm[0]['cu_mothername'],
'guardian_mothername' => $guardian_mothername_encoded,
'agreement' => $applicationForm[0]['disclaimer_checked'],
//'relationtostudent' => $applicationForm[0]['relationtostudent'],
'relationtostudent' => $relationtostudent_encoded,
//'telnum' => $applicationForm[0]['telnum']
'telnum' => $telnum_encoded
);
if (($errorCode = $this->validateStudent($student)) > 0) {
......
......@@ -24,10 +24,10 @@ use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface;
define("ERROR_DB", -1);
define("NO_CLASS_LIMIT_DOWN", -2);
define("SMALL_CLASS", 1);
define("NON_SMALL_CLASS", 2);
define("ERR_DB", -1);
define("NO_CLASS_LIM_DOWN", -2);
define("SMALL_CLS", 1);
define("NON_SMALL_CLS", 2);
class ReportsCreator extends ControllerBase {
......@@ -603,8 +603,8 @@ class ReportsCreator extends ControllerBase {
for ($j = 0; $j < sizeof($schoolNameColumn); $j++) {
//αν έγινε αίτημα για εμφάνιση ολιγομελών και είναι το τρέχον τμήμα ολιγομελές
if ( ($finalized === "1") || ($finalized === "0" && $smallClass[$j] === SMALL_CLASS
&& $schoolSectionColumn[$j] !== "Β τάξη" && $schoolSectionColumn[$j] !== "Γ τάξη" && $schoolSectionColumn[$j] !== "Δ τάξη" ) )
if ( ($finalized === "1") || ($finalized === "0" && $smallClass[$j] === SMALL_CLS
&& $schoolSectionColumn[$j] !== "Β τάξη" && $schoolSectionColumn[$j] !== "Γ τάξη" && $schoolSectionColumn[$j] !== "Δ τάξη" ) )
array_push($list,(object) array(
'name' => $schoolNameColumn[$j],
......@@ -644,16 +644,16 @@ class ReportsCreator extends ControllerBase {
$limitDown = $this->retrieveLimitDown($classId, $regionId);
if ($limitDown === NO_CLASS_LIMIT_DOWN)
return NO_CLASS_LIMIT_DOWN;
else if ($limitDown === ERROR_DB)
return ERROR_DB;
if ($limitDown === NO_CLASS_LIM_DOWN)
return NO_CLASS_LIM_DOWN;
else if ($limitDown === ERR_DB)
return ERR_DB;
$numStudents = (int) $numStud;
if ( ($numStudents < $limitDown) /*&& ($numStudents > 0)*/ )
return SMALL_CLASS;
return SMALL_CLS;
else
return NON_SMALL_CLASS;
return NON_SMALL_CLS;
}
......@@ -671,12 +671,12 @@ class ReportsCreator extends ControllerBase {
return $classLimit->limit_down;
}
else {
return NO_CLASS_LIMIT_DOWN;
return NO_CLASS_LIM_DOWN;
}
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return ERROR_DB;
return ERR_DB;
}
} //end function
......
......@@ -9,19 +9,36 @@ use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\epal\Crypt;
class SubmitedApplications extends ControllerBase
{
protected $entityTypeManager;
protected $logger;
/*
public function __construct(EntityTypeManagerInterface $entityTypeManager)
{
$this->entityTypeManager = $entityTypeManager;
}
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal');
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager')
$container->get('entity_type.manager'),
$container->get('logger.factory')
);
}
......@@ -38,17 +55,37 @@ class SubmitedApplications extends ControllerBase
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid));
$i = 0;
if ($epalStudents) {
$list = array();
$crypt = new Crypt();
$list = array();
foreach ($epalStudents as $object) {
$indexid = intval($object -> id())-1;
try {
$name_decoded = $crypt->decrypt($object->name->value);
$studentsurname_decoded = $crypt->decrypt($object->studentsurname->value);
}
catch (\Exception $e) {
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected error occured during DECODING data in getSubmittedApplications Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
$list[] = array(
'id' => $indexid,
'name' => $object -> name ->value,
'studentsurname' => $object -> studentsurname ->value);
//'name' => $object -> name ->value,
'name' => $name_decoded,
//'studentsurname' => $object -> studentsurname ->value);
'studentsurname' => $studentsurname_decoded );
$i++;
}
unset($crypt);
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
......@@ -105,31 +142,74 @@ class SubmitedApplications extends ControllerBase
if ($course)
$courseName = $this->entityTypeManager->getStorage('eepal_specialty')->load($course->coursefield_id->target_id)->name->value;
}
$crypt = new Crypt();
try {
$name_decoded = $crypt->decrypt($object->name->value);
$studentsurname_decoded = $crypt->decrypt($object->studentsurname->value);
$fatherfirstname_decoded = $crypt->decrypt($object->fatherfirstname->value);
$motherfirstname_decoded = $crypt->decrypt($object->motherfirstname->value);
$regionaddress_decoded = $crypt->decrypt($object->regionaddress->value);
$regiontk_decoded = $crypt->decrypt($object->regiontk->value);
$regionarea_decoded = $crypt->decrypt($object->regionarea->value);
$certificatetype_decoded = $crypt->decrypt($object->certificatetype->value);
$relationtostudent_decoded = $crypt->decrypt($object->relationtostudent->value);
$telnum_decoded = $crypt->decrypt($object->telnum->value);
$guardian_name_decoded = $crypt->decrypt($object->guardian_name->value);
$guardian_surname_decoded = $crypt->decrypt($object->guardian_surname->value);
$guardian_fathername_decoded = $crypt->decrypt($object->guardian_fathername->value);
$guardian_mothername_decoded = $crypt->decrypt($object->guardian_mothername->value);
}
catch (\Exception $e) {
//print_r($e->getMessage());
unset($crypt);
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected error occured during DECODING data in getStudentApplications Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
unset($crypt);
$list[] = array(
'applicationId' => $object->id(),
'name' => $object -> name ->value,
'studentsurname' => $object -> studentsurname ->value,
'fatherfirstname' => $object -> fatherfirstname ->value,
//'name' => $object -> name ->value,
'name' => $name_decoded,
//'studentsurname' => $object -> studentsurname ->value,
'studentsurname' => $studentsurname_decoded,
//'fatherfirstname' => $object -> fatherfirstname ->value,
'fatherfirstname' => $fatherfirstname_decoded,
'fathersurname' =>$object -> fathersurname ->value,
'motherfirstname' => $object -> motherfirstname ->value,
//'motherfirstname' => $object -> motherfirstname ->value,
'motherfirstname' => $motherfirstname_decoded,
'mothersurname' =>$object -> mothersurname ->value,
'guardian_name' =>$object -> guardian_name ->value,
'guardian_surname' =>$object -> guardian_surname ->value,
'guardian_fathername' =>$object -> guardian_fathername ->value,
'guardian_mothername' =>$object -> guardian_mothername ->value,
//'guardian_name' =>$object -> guardian_name ->value,
'guardian_name' =>$guardian_name_decoded,
//'guardian_surname' =>$object -> guardian_surname ->value,
'guardian_surname' => $guardian_surname_decoded,
//'guardian_fathername' =>$object -> guardian_fathername ->value,
'guardian_fathername' =>$guardian_fathername_decoded,
//'guardian_mothername' =>$object -> guardian_mothername ->value,
'guardian_mothername' =>$guardian_mothername_decoded,
'lastschool_schoolname' =>$object -> lastschool_schoolname ->value,
'lastschool_schoolyear' =>$object -> lastschool_schoolyear ->value,
'lastschool_class' =>$object -> lastschool_class ->value,
'currentclass' =>$object -> currentclass ->value,
'currentsector' =>$sectorName,
'currentcourse' =>$courseName,
'regionaddress' =>$object -> regionaddress ->value,
'regiontk' =>$object -> regiontk ->value,
'regionarea' =>$object -> regionarea ->value,
'certificatetype' =>$object -> certificatetype ->value,
//'regionaddress' =>$object -> regionaddress ->value,
'regionaddress' =>$regionaddress_decoded,
//'regiontk' =>$object -> regiontk ->value,
'regiontk' =>$regiontk_decoded,
//'regionarea' =>$object -> regionarea ->value,
'regionarea' =>$regionarea_decoded,
//'certificatetype' =>$object -> certificatetype ->value,
'certificatetype' => $certificatetype_decoded,
'graduation_year' =>$object -> graduation_year ->value,
'telnum' =>$object -> telnum ->value,
'relationtostudent' =>$object -> relationtostudent ->value,
//'telnum' =>$object -> telnum ->value,
'telnum' =>$telnum_decoded,
//'relationtostudent' =>$object -> relationtostudent ->value,
'relationtostudent' => $relationtostudent_decoded,
'birthdate' => substr($object->birthdate->value, 8, 2) . '/' . substr($object->birthdate->value, 6, 2) . '/' . substr($object->birthdate->value, 0, 4),
'created' => date('d/m/Y H:i', $object -> created ->value),
......
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