Newer
Older

Damien
committed
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*/
/**
* @brief Core Controller

Damien
committed
* @author dev@maarch.org
*/

Damien
committed
use SrcCore\models\ValidatorModel;

Damien
committed
class CoreController
{
public function initialize(Request $request, Response $response)

Damien
committed
{
$aInit = [];
$aInit['coreUrl'] = str_replace('rest/', '', UrlController::getCoreUrl());
$aInit['applicationName'] = CoreConfigModel::getApplicationName();
$aInit['applicationVersion'] = CoreConfigModel::getApplicationVersion();
$aInit['lang'] = CoreConfigModel::getLanguage();
if (!empty($GLOBALS['userId'])) {
$aInit['user'] = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id', 'user_id', 'firstname', 'lastname']]);
}
$aInit['customLanguage'] = CoreConfigModel::getCustomLanguage(['lang' => $aInit['lang']]);
$scriptsToInject = [];
$scripts = scandir('dist');
foreach ($scripts as $value) {
if (strstr($value, 'runtime.') !== false || strstr($value, 'main.') !== false || strstr($value, 'vendor.') !== false || strstr($value, 'scripts.') !== false) {
if (strstr($value, '.js.map') === false) {
$scriptName = explode(".", $value);
$modificationDate = filemtime(realpath("dist/" . $value));
$idArrayTime = $scriptName[0] . "." . pathinfo($value, PATHINFO_EXTENSION);
if (!isset($aInit['scriptsInjected'][$idArrayTime]) || $modificationDate > $aInit['scriptsInjected'][$idArrayTime][0]) {
if (isset($aInit['scriptsInjected'][$idArrayTime])) {
array_pop($scriptsToInject);
}
$aInit['scriptsInjected'][$idArrayTime][0] = filemtime(realpath("dist/" . $value));
$aInit['scriptsInjected'][$idArrayTime][1] = $value;
$scriptsToInject[] = $value;
}
$nbScriptsToInject = count($scriptsToInject);
for ($i = 0; $i < $nbScriptsToInject; $i++) {
foreach ($scriptsToInject as $value) {
if ($i == 0 && strstr($value, 'scripts.') !== false) {
$aInit['scriptsToinject'][] = $value;
} elseif ($i == 1 && strstr($value, 'main.') !== false) {
$aInit['scriptsToinject'][] = $value;
} elseif ($i == 2 && strstr($value, 'runtime.') !== false) {
$aInit['scriptsToinject'][] = $value;
} elseif ($i == 3 && strstr($value, 'vendor.') !== false) {
$aInit['scriptsToinject'][] = $value;
}
}

Damien
committed
return $response->withJson($aInit);
}
public function getHeader(Request $request, Response $response)
{
$user = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id', 'user_id', 'firstname', 'lastname']]);
$user['groups'] = UserModel::getGroupsByLogin(['login' => $GLOBALS['userId']]);
$user['entities'] = UserModel::getEntitiesByLogin(['login' => $GLOBALS['userId']]);
return $response->withJson([
public static function setGlobals(array $args)
{
ValidatorModel::notEmpty($args, ['login']);
ValidatorModel::stringType($args, ['login']);
$user = UserModel::getByLogin(['login' => $args['login'], 'select' => ['id']]);
$GLOBALS['userId'] = $args['login'];
$GLOBALS['id'] = $user['id'];
}
public function externalConnectionsEnabled(Request $request, Response $response)
{
$connections = [];
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/visa/xml/remoteSignatoryBooks.xml']);
if (!empty($loadedXml->signatoryBookEnabled)) {
$connections[(string)$loadedXml->signatoryBookEnabled] = true;
}
$mailevaConfig = CoreConfigModel::getMailevaConfiguration();
if ($mailevaConfig['enabled']) {
$connections['maileva'] = true;
}
return $response->withJson(['connection' => $connections]);
}