Commit e0927eb6 authored by Open Source Developer's avatar Open Source Developer

Merge branch 'develop' of https://git.minedu.gov.gr/itminedu/e-epal into stylesandmenus

parents ff764cb9 df04a646
...@@ -43,3 +43,8 @@ entity.epal_class_limits.add_form: ...@@ -43,3 +43,8 @@ entity.epal_class_limits.add_form:
title: 'Add Epal class limits' title: 'Add Epal class limits'
appears_on: appears_on:
- entity.epal_class_limits.collection - entity.epal_class_limits.collection
entity.epal_config.add_form:
route_name: entity.epal_config.add_form
title: 'Add Epal config'
appears_on:
- entity.epal_config.collection
...@@ -124,3 +124,16 @@ epal_class_limits.admin.structure.settings: ...@@ -124,3 +124,16 @@ epal_class_limits.admin.structure.settings:
description: 'Configure Epal class limits entities' description: 'Configure Epal class limits entities'
route_name: epal_class_limits.settings route_name: epal_class_limits.settings
parent: system.admin_structure parent: system.admin_structure
# Epal config menu items definition
entity.epal_config.collection:
title: 'Epal config list'
route_name: entity.epal_config.collection
description: 'List Epal config entities'
parent: system.admin_structure
weight: 100
epal_config.admin.structure.settings:
title: Epal config settings
description: 'Configure Epal config entities'
route_name: epal_config.settings
parent: system.admin_structure
...@@ -196,3 +196,24 @@ entity.epal_class_limits.delete_form: ...@@ -196,3 +196,24 @@ entity.epal_class_limits.delete_form:
title: Delete title: Delete
weight: 10 weight: 10
# Epal config routing definition
epal_config.settings_tab:
route_name: epal_config.settings
title: 'Settings'
base_route: epal_config.settings
entity.epal_config.canonical:
route_name: entity.epal_config.canonical
base_route: entity.epal_config.canonical
title: 'View'
entity.epal_config.edit_form:
route_name: entity.epal_config.edit_form
base_route: entity.epal_config.canonical
title: Edit
entity.epal_config.delete_form:
route_name: entity.epal_config.delete_form
base_route: entity.epal_config.canonical
title: Delete
weight: 10
<?php <?php
/** /**
* @file * @file
...@@ -46,7 +46,6 @@ function epal_mail($key, &$message, $params) { ...@@ -46,7 +46,6 @@ function epal_mail($key, &$message, $params) {
$message['subject'] = t('Σύστημα υποβολής αιτήσεων εγγραφής σε ΕΠΑΛ: Επιβεβαίωση e-mail', $options); $message['subject'] = t('Σύστημα υποβολής αιτήσεων εγγραφής σε ΕΠΑΛ: Επιβεβαίωση e-mail', $options);
$message['body'][] = $params['message']; $message['body'][] = $params['message'];
break; break;
case 'massive_mail': case 'massive_mail':
$message['from'] = \Drupal::config('system.site')->get('mail'); $message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Μη ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options); $message['subject'] = t('Μη ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options);
......
...@@ -196,3 +196,22 @@ view published epal class limits entities: ...@@ -196,3 +196,22 @@ view published epal class limits entities:
view unpublished epal class limits entities: view unpublished epal class limits entities:
title: 'View unpublished Epal class limits entities' title: 'View unpublished Epal class limits entities'
add epal config entities:
title: 'Create new Epal config entities'
administer epal config entities:
title: 'Administer Epal config entities'
description: 'Allow to access the administration form to configure Epal config entities.'
restrict access: true
delete epal config entities:
title: 'Delete Epal config entities'
edit epal config entities:
title: 'Edit Epal config entities'
view published epal config entities:
title: 'View published Epal config entities'
view unpublished epal config entities:
title: 'View unpublished Epal config entities'
...@@ -182,6 +182,22 @@ epal.ministry.massive_mail: ...@@ -182,6 +182,22 @@ epal.ministry.massive_mail:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToStudents' _controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToStudents'
requirements: requirements:
_user_is_logged_in: 'TRUE' _user_is_logged_in: 'TRUE'
epal.ministry.retrievesettings:
path: '/ministry/retrieve-settings'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\MinisterSettings::retrieveSettings'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.storesettings:
path: '/ministry/store-settings/{capacityDisabled}/{directorViewDisabled}/{applicantsLoginDisabled}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\MinisterSettings::storeSettings'
requirements:
_user_is_logged_in: 'TRUE'
regionview: regionview:
path: '/epal/ScoolperPerf/{perfectureId}' path: '/epal/ScoolperPerf/{perfectureId}'
options: options:
......
<?php
/**
* @file
* Contains epal_config.page.inc.
*
* Page callback for Epal config entities.
*/
use Drupal\Core\Render\Element;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Prepares variables for Epal config templates.
*
* Default template: epal_config.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_epal_config(array &$variables) {
// Fetch EpalConfig Entity Object.
$epal_config = $variables['elements']['#epal_config'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
...@@ -83,6 +83,12 @@ class ApplicationSubmit extends ControllerBase { ...@@ -83,6 +83,12 @@ class ApplicationSubmit extends ControllerBase {
'certificatetype' => $applicationForm[0][certificatetype], 'certificatetype' => $applicationForm[0][certificatetype],
//'lastam' => $applicationForm[0][lastam], //'lastam' => $applicationForm[0][lastam],
'currentclass' => $applicationForm[0][currentclass], '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], //'currentepal' => $applicationForm[0][currentepal],
//'currentsector' => $applicationForm[0][currentsector], //'currentsector' => $applicationForm[0][currentsector],
'points' => $applicationForm[0][points], 'points' => $applicationForm[0][points],
......
...@@ -50,12 +50,30 @@ class CurrentUser extends ControllerBase ...@@ -50,12 +50,30 @@ class CurrentUser extends ControllerBase
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
$epalConfigs = $this->entityTypeManager->getStorage('epal_config')->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("Configuration not found"),
], Response::HTTP_FORBIDDEN);
}
$userRoles = $user->getRoles(); $userRoles = $user->getRoles();
foreach ($userRoles as $userRole) { foreach ($userRoles as $userRole) {
if (($userRole === 'epal') || ($userRole === 'regioneduadmin') || ($userRole === 'eduadmin')) { if (($userRole === 'epal') || ($userRole === 'regioneduadmin') || ($userRole === 'eduadmin')) {
return $this->respondWithStatus([ return $this->respondWithStatus([
'name' => $user->mail->value, 'cu_name' => $user->mail->value,
'title' => $user->init->value, 'cu_surname' => '',
'cu_fathername' => '',
'cu_mothername' => '',
'cu_email' => '',
'minedu_username' => '',
'minedu_userpassword' => '',
'lock_capacity' => $epalConfig->lock_school_capacity->value,
'lock_students' => $epalConfig->lock_school_students_view->value,
'lock_application' => $epalConfig->lock_application->value,
'disclaimer_checked' => "0",
'title' => $user->init->value
], Response::HTTP_OK); ], Response::HTTP_OK);
} else if ($userRole === 'applicant') { } else if ($userRole === 'applicant') {
break; break;
...@@ -66,8 +84,24 @@ class CurrentUser extends ControllerBase ...@@ -66,8 +84,24 @@ class CurrentUser extends ControllerBase
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken)); $epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers); $epalUser = reset($epalUsers);
if ($epalUser) { if ($epalUser) {
$userName = $epalUser->name->value;
$userSurname = $epalUser->surname->value;
$userFathername = $epalUser->fathername->value;
$userMothername = $epalUser->mothername->value;
$userEmail = $user->mail->value;
return $this->respondWithStatus([ return $this->respondWithStatus([
'name' => $epalUser->name->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_email' => mb_substr($user->mail->value,0,4,'UTF-8') !== "####" ? $user->mail->value : '',
'minedu_username' => '',
'minedu_userpassword' => '',
'lock_capacity' => $epalConfig->lock_school_capacity->value,
'lock_students' => $epalConfig->lock_school_students_view->value,
'lock_application' => $epalConfig->lock_application->value,
'disclaimer_checked' => "0",
'verificationCodeVerified' => $epalUser->verificationcodeverified->value,
], Response::HTTP_OK); ], Response::HTTP_OK);
} else { } else {
return $this->respondWithStatus([ return $this->respondWithStatus([
......
...@@ -102,6 +102,29 @@ class Distribution extends ControllerBase { ...@@ -102,6 +102,29 @@ class Distribution extends ControllerBase {
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
//check where distribution can be done now ($capacityDisabled / $directorViewDisabled settings)
$capacityDisabled = false;
$directorViewDisabled = false;
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
}
else {
$capacityDisabled = $epalConfig->lock_school_capacity->getString();
$directorViewDisabled = $epalConfig->lock_school_students_view->getString();
}
if ($capacityDisabled === "0" or $directorViewDisabled === "0") {
return $this->respondWithStatus([
'message' => t("capacityDisabled and / or directorViewDisabled settings are false"),
], Response::HTTP_FORBIDDEN);
}
$transaction = $this->connection->startTransaction(); $transaction = $this->connection->startTransaction();
......
<?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;
class MinisterSettings 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 retrieveSettings(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);
}
//minister settings retrieve
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
}
else {
$capacityDisabled = $epalConfig->lock_school_capacity->getString();
$directorViewDisabled = $epalConfig->lock_school_students_view->getString();
$applicantsLoginDisabled = $epalConfig->lock_application->getString();
}
$config_storage->resetCache();
return $this->respondWithStatus([
//'message' => t("post successful"),
'capacityDisabled' => $capacityDisabled,
'directorViewDisabled' => $directorViewDisabled,
'applicantsLoginDisabled' => $applicantsLoginDisabled,
], Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured during retrieveSettings Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
public function storeSettings(Request $request, $capacityDisabled, $directorViewDisabled, $applicantsLoginDisabled ) {
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);
}
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
}
else {
$epalConfig->set('lock_school_capacity', $capacityDisabled);
$epalConfig->set('lock_school_students_view', $directorViewDisabled);
$epalConfig->set('lock_application', $applicantsLoginDisabled);
$epalConfig->save();
}
$config_storage->resetCache();
return $this->respondWithStatus([
//'message' => t("post successful"),
'capacityDisabled' => $capacityDisabled,
'directorViewDisabled' => $directorViewDisabled,
'applicantsLoginDisabled' => $applicantsLoginDisabled,
], Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured during storeSettings Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
...@@ -514,7 +514,7 @@ class ReportsCreator extends ControllerBase { ...@@ -514,7 +514,7 @@ class ReportsCreator extends ControllerBase {
array_push($numClasses, $numClassCour); array_push($numClasses, $numClassCour);
array_push($numClasses, $numClassCour_D); array_push($numClasses, $numClassCour_D);
if ($sectorId === "0" && $courseId === 0) { if ($sectorId === "0" && $courseId === "0") {
$clidstart = 1; $clidstart = 1;
$clidend = 4; $clidend = 4;
......
<?php
namespace Drupal\epal\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\epal\EpalConfigInterface;
use Drupal\user\UserInterface;
/**
* Defines the Epal config entity.
*
* @ingroup epal
*
* @ContentEntityType(
* id = "epal_config",
* label = @Translation("Epal config"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\epal\EpalConfigListBuilder",
* "views_data" = "Drupal\epal\Entity\EpalConfigViewsData",
*
* "form" = {
* "default" = "Drupal\epal\Form\EpalConfigForm",
* "add" = "Drupal\epal\Form\EpalConfigForm",
* "edit" = "Drupal\epal\Form\EpalConfigForm",
* "delete" = "Drupal\epal\Form\EpalConfigDeleteForm",
* },
* "access" = "Drupal\epal\EpalConfigAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\epal\EpalConfigHtmlRouteProvider",
* },
* },
* base_table = "epal_config",
* admin_permission = "administer epal config entities",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* },
* links = {
* "canonical" = "/admin/structure/epal_config/{epal_config}",
* "add-form" = "/admin/structure/epal_config/add",
* "edit-form" = "/admin/structure/epal_config/{epal_config}/edit",
* "delete-form" = "/admin/structure/epal_config/{epal_config}/delete",
* "collection" = "/admin/structure/epal_config",
* },
* field_ui_base_route = "epal_config.settings"
* )
*/
class EpalConfig extends ContentEntityBase implements EpalConfigInterface {
use EntityChangedTrait;
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += array(
'user_id' => \Drupal::currentUser()->id(),
);
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getCreatedTime() {
return $this->get('created')->value;
}