Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sonar #1742

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/class/history.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ public static function getTemporalAvg($_cmd_id, $_startTime, $_endTime){
return HistoryManager::getTemporalAvg($_cmd_id, $_startTime, $_endTime);
}

}
}
45 changes: 22 additions & 23 deletions src/Ajax/CmdAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use NextDom\Enums\ActionRight;
use NextDom\Enums\AjaxParams;
use NextDom\Enums\CmdConfigKey;
use NextDom\Enums\CmdType;
use NextDom\Enums\CmdViewType;
use NextDom\Enums\Common;
Expand Down Expand Up @@ -57,7 +58,6 @@ class CmdAjax extends BaseAjax
* Get one or more command(s) HTML render
*
* @throws CoreException
* @throws \ReflectionException
*/
public function toHtml()
{
Expand All @@ -71,18 +71,18 @@ public function toHtml()
}
$result[$cmd->getId()] = [
'html' => $cmd->toHtml($value[Common::VERSION]),
'id' => $cmd->getId(),
AjaxParams::ID => $cmd->getId(),
];
}
$this->ajax->success($result);
} else {
// Render one command
$cmd = CmdManager::byId(Utils::init(AjaxParams::ID));
if (!is_object($cmd)) {
throw new CoreException(__('Commande inconnue - Vérifiez l\'id'));
throw new CoreException(__('Commande inconnue - Vérifiez l\'ID'));
}
$result = [];
$result['id'] = $cmd->getId();
$result[AjaxParams::ID] = $cmd->getId();
$result['html'] = $cmd->toHtml(Utils::init(AjaxParams::VERSION), Utils::init(AjaxParams::OPTION), Utils::init('cmdColor', null));
$this->ajax->success($result);
}
Expand All @@ -92,7 +92,6 @@ public function toHtml()
* Execute a command
*
* @throws CoreException
* @throws \ReflectionException
*/
public function execCmd()
{
Expand Down Expand Up @@ -306,7 +305,7 @@ public function save()
{
AuthentificationHelper::isConnectedAsAdminOrFail();
$cmdAjaxData = NextDomHelper::fromHumanReadable(json_decode(Utils::init(NextDomObj::CMD), true));
$cmd = CmdManager::byId($cmdAjaxData['id']);
$cmd = CmdManager::byId($cmdAjaxData[AjaxParams::ID]);
if (!is_object($cmd)) {
$cmd = new Cmd();
}
Expand All @@ -326,7 +325,7 @@ public function multiSave()
AuthentificationHelper::isConnectedAsAdminOrFail();
$cmds = json_decode(Utils::init(NextDomObj::CMD), true);
foreach ($cmds as $cmdAjaxData) {
$cmd = CmdManager::byId($cmdAjaxData['id']);
$cmd = CmdManager::byId($cmdAjaxData[AjaxParams::ID]);
if (!is_object($cmd)) {
continue;
}
Expand Down Expand Up @@ -419,8 +418,8 @@ public function getHistory()
if ($dateStart !== '') {
$dateStart = Utils::init(AjaxParams::DATE_START, date(DateFormat::FULL_DAY, strtotime(ConfigManager::byKey('history::defautShowPeriod') . ' ' . date(DateFormat::FULL_DAY))));
}
$result['maxValue'] = '';
$result['minValue'] = '';
$result[CmdConfigKey::MAX_VALUE] = '';
$result[CmdConfigKey::MIN_VALUE] = '';
if ($dateStart === null) {
$result['dateStart'] = '';
} else {
Expand Down Expand Up @@ -482,11 +481,11 @@ public function getHistory()
}
$infoHistory[] = $value;
if (!$NEXTDOM_INTERNAL_CONFIG[NextDomObj::CMD][Common::TYPE][Common::INFO][Common::SUBTYPE][$cmd->getSubType()][Common::IS_HISTORIZED][Common::TIMELINE_ONLY]) {
if (($value !== null && $value > $result['maxValue']) || $result['maxValue'] == '') {
$result['maxValue'] = round($value, 1);
if (($value !== null && $value > $result[CmdConfigKey::MAX_VALUE]) || $result[CmdConfigKey::MAX_VALUE] == '') {
$result[CmdConfigKey::MAX_VALUE] = round($value, 1);
}
if (($value !== null && $value < $result['minValue']) || $result['minValue'] == '') {
$result['minValue'] = round($value, 1);
if (($value !== null && $value < $result[CmdConfigKey::MIN_VALUE]) || $result[CmdConfigKey::MIN_VALUE] == '') {
$result[CmdConfigKey::MIN_VALUE] = round($value, 1);
}
}
$data[] = $infoHistory;
Expand All @@ -498,18 +497,18 @@ public function getHistory()
$infoHistory = [];
$infoHistory[] = floatval($datetime) * 1000;
$infoHistory[] = ($value === null) ? null : floatval($value);
if ($value > $result['maxValue'] || $result['maxValue'] == '') {
$result['maxValue'] = round($value, 1);
if ($value > $result[CmdConfigKey::MAX_VALUE] || $result[CmdConfigKey::MAX_VALUE] == '') {
$result[CmdConfigKey::MAX_VALUE] = round($value, 1);
}
if ($value < $result['minValue'] || $result['minValue'] == '') {
$result['minValue'] = round($value, 1);
if ($value < $result[CmdConfigKey::MIN_VALUE] || $result[CmdConfigKey::MIN_VALUE] == '') {
$result[CmdConfigKey::MIN_VALUE] = round($value, 1);
}
$data[] = $infoHistory;
}
}
$result['cmd_name'] = $cmdId;
$result['history_name'] = $cmdId;
$result['unite'] = Utils::init('unite');
$result[Common::UNITE] = Utils::init(Common::UNITE);
}
$result['data'] = $data;
$this->ajax->success($result);
Expand Down Expand Up @@ -544,27 +543,27 @@ public function setOrder()
$cmds = json_decode(Utils::init('cmds'), true);
$eqLogics = [];
foreach ($cmds as $cmdJsonData) {
if (!isset($cmdJsonData['id']) || trim($cmdJsonData['id']) == '') {
if (!isset($cmdJsonData[AjaxParams::ID]) || trim($cmdJsonData[AjaxParams::ID]) == '') {
continue;
}
$cmd = CmdManager::byId($cmdJsonData['id']);
$cmd = CmdManager::byId($cmdJsonData[AjaxParams::ID]);
if (!is_object($cmd)) {
continue;
}
if ($cmd->getOrder() != $cmdJsonData['order']) {
$cmd->setOrder($cmdJsonData['order']);
$cmd->save();
}
if (isset($cmdJsonData['line']) && isset($cmdJsonData['column'])) {
if (isset($cmdJsonData['line']) && isset($cmdJsonData[Common::COLUMN])) {
$renderVersion = Utils::init(AjaxParams::VERSION, CmdViewType::DASHBOARD);
if (!isset($eqLogics[$cmd->getEqLogic_id()])) {
$eqLogics[$cmd->getEqLogic_id()] = [NextDomObj::EQLOGIC => $cmd->getEqLogic(), Common::CHANGED => false];
}
$layoutDisplay = 'layout::' . $renderVersion . '::table::cmd::' . $cmd->getId();
if ($eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::line') != $cmdJsonData['line']
|| $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::column') != $cmdJsonData['column']) {
|| $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::column') != $cmdJsonData[Common::COLUMN]) {
$eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::line', $cmdJsonData['line']);
$eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::column', $cmdJsonData['column']);
$eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::column', $cmdJsonData[Common::COLUMN]);
$eqLogics[$cmd->getEqLogic_id()][Common::CHANGED] = true;
}
}
Expand Down
38 changes: 20 additions & 18 deletions src/Ajax/EqLogicAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
use NextDom\Helpers\AuthentificationHelper;
use NextDom\Helpers\NextDomHelper;
use NextDom\Helpers\Utils;
use NextDom\Managers\CmdManager;
use NextDom\Managers\EqLogicManager;
use NextDom\Managers\JeeObjectManager;
use NextDom\Model\Entity\Cmd;
use NextDom\Model\Entity\EqLogic;

/**
* Class EqLogicAjax
Expand All @@ -52,7 +54,7 @@ public function getEqLogicObject()
foreach ($linkedObject->getEqLogic() as $eqLogic) {
if ($eqLogic->isVisible()) {
$info_eqLogic = [];
$info_eqLogic[Common::ID] = $eqLogic->getId();
$info_eqLogic[AjaxParams::ID] = $eqLogic->getId();
$info_eqLogic[Common::TYPE] = $eqLogic->getEqType_name();
$info_eqLogic[Common::OBJECT_ID] = $eqLogic->getObject_id();
$info_eqLogic[Common::HTML] = $eqLogic->toHtml(Utils::init(AjaxParams::VERSION));
Expand Down Expand Up @@ -84,7 +86,7 @@ public function toHtml()
throw new CoreException(__('Pas de version indiqué pour le rendu HTML'));
}
$result[$eqLogic->getId()] = [
Common::ID => $eqLogic->getId(),
AjaxParams::ID => $eqLogic->getId(),
Common::TYPE => $eqLogic->getEqType_name(),
Common::OBJECT_ID => $eqLogic->getObject_id(),
Common::HTML => $eqLogic->toHtml($eqLogicData[AjaxParams::VERSION]),
Expand All @@ -97,7 +99,7 @@ public function toHtml()
throw new CoreException(__('Eqlogic inconnu. Vérifiez l\'ID'));
}
$eqLogicInfo = [];
$eqLogicInfo[Common::ID] = $eqLogic->getId();
$eqLogicInfo[AjaxParams::ID] = $eqLogic->getId();
$eqLogicInfo[Common::TYPE] = $eqLogic->getEqType_name();
$eqLogicInfo[Common::OBJECT_ID] = $eqLogic->getObject_id();
$eqLogicInfo[Common::HTML] = $eqLogic->toHtml(Utils::init(AjaxParams::VERSION));
Expand All @@ -114,7 +116,7 @@ public function htmlAlert()
}
$result[$eqLogic->getId()] = [
Common::HTML => $eqLogic->toHtml(Utils::init(AjaxParams::VERSION)),
Common::ID => $eqLogic->getId(),
AjaxParams::ID => $eqLogic->getId(),
Common::TYPE => $eqLogic->getEqType_name(),
Common::OBJECT_ID => $eqLogic->getObject_id(),
];
Expand Down Expand Up @@ -145,7 +147,7 @@ public function htmlBattery()
foreach ($list as $eqLogic) {
$result[] = [
Common::HTML => $eqLogic->batteryWidget(Utils::init(AjaxParams::VERSION)),
Common::ID => $eqLogic->getId(),
AjaxParams::ID => $eqLogic->getId(),
Common::TYPE => $eqLogic->getEqType_name(),
Common::OBJECT_ID => $eqLogic->getObject_id(),
];
Expand Down Expand Up @@ -197,7 +199,7 @@ public function listByTypeAndCmdType()
$eqLogicList = EqLogicManager::listByTypeAndCmdType(Utils::init(AjaxParams::TYPE), Utils::init(AjaxParams::TYPE_CMD), Utils::init(AjaxParams::SUB_TYPE_CMD));
$result = [];
foreach ($eqLogicList as $eqLogic) {
$eqLogic = EqLogicManager::byId($eqLogic[Common::ID]);
$eqLogic = EqLogicManager::byId($eqLogic[AjaxParams::ID]);
$info[NextDomObj::EQLOGIC] = Utils::o2a($eqLogic);
$info[NextDomObj::OBJECT] = ['name' => 'Aucun'];
if (is_object($eqLogic)) {
Expand Down Expand Up @@ -230,10 +232,10 @@ public function setOrder()
{
$eqLogics = json_decode(Utils::init('eqLogics'), true);
foreach ($eqLogics as $eqLogic_json) {
if (!isset($eqLogic_json[Common::ID]) || trim($eqLogic_json[Common::ID]) == '') {
if (!isset($eqLogic_json[AjaxParams::ID]) || trim($eqLogic_json[AjaxParams::ID]) == '') {
continue;
}
$eqLogic = EqLogicManager::byId($eqLogic_json[Common::ID]);
$eqLogic = EqLogicManager::byId($eqLogic_json[AjaxParams::ID]);
if (!is_object($eqLogic)) {
continue;
}
Expand Down Expand Up @@ -297,9 +299,9 @@ public function simpleSave()
{
AuthentificationHelper::isConnectedAsAdminOrFail();
$eqLogicSave = json_decode(Utils::init(NextDomObj::EQLOGIC), true);
$eqLogic = EqLogicManager::byId($eqLogicSave[Common::ID]);
$eqLogic = EqLogicManager::byId($eqLogicSave[AjaxParams::ID]);
if (!is_object($eqLogic)) {
throw new CoreException(__('EqLogic inconnu. Vérifiez l\'ID ') . $eqLogicSave[Common::ID]);
throw new CoreException(__('EqLogic inconnu. Vérifiez l\'ID ') . $eqLogicSave[AjaxParams::ID]);
}

if (!$eqLogic->hasRight(ActionRight::WRITE)) {
Expand Down Expand Up @@ -355,22 +357,22 @@ public function get()
public function save()
{
AuthentificationHelper::isConnectedAsAdminOrFail();

$eqLogicsSave = json_decode(Utils::init(NextDomObj::EQLOGIC), true);

foreach ($eqLogicsSave as $eqLogicSave) {
try {
if (!is_array($eqLogicSave)) {
throw new CoreException(__('Informations reçues incorrectes'));
}
$typeEqLogic = Utils::init(AjaxParams::TYPE);
$typeEqLogic = Utils::initStr(AjaxParams::TYPE);
$typeCmd = $typeEqLogic . NextDomObj::CMD;
if ($typeEqLogic == '' || !class_exists($typeEqLogic) || !class_exists($typeCmd)) {
throw new CoreException(__('Type incorrect, (classe commande inexistante)') . $typeCmd);
}
/** @var EqLogic $eqLogic */
$eqLogic = null;
if (isset($eqLogicSave[Common::ID])) {
$eqLogic = $typeEqLogic::byId($eqLogicSave[Common::ID]);
if (isset($eqLogicSave[AjaxParams::ID])) {
$eqLogic = $typeEqLogic::byId($eqLogicSave[AjaxParams::ID]);
}
if (!is_object($eqLogic)) {
$eqLogic = new $typeEqLogic();
Expand All @@ -385,16 +387,16 @@ public function save()
}
$eqLogicSave = NextDomHelper::fromHumanReadable($eqLogicSave);
Utils::a2o($eqLogic, $eqLogicSave);
$dbList = $typeCmd::byEqLogicId($eqLogic->getId());
$dbList = CmdManager::byEqLogicId($eqLogic->getId());
$eqLogic->save();
$enableList = [];

if (isset($eqLogicSave[NextDomObj::CMD])) {
$cmd_order = 0;
foreach ($eqLogicSave[NextDomObj::CMD] as $cmd_info) {
$cmd = null;
if (isset($cmd_info[Common::ID])) {
$cmd = $typeCmd::byId($cmd_info[Common::ID]);
if (isset($cmd_info[AjaxParams::ID])) {
$cmd = CmdManager::byId($cmd_info[AjaxParams::ID]);
}
if (!is_object($cmd)) {
$cmd = new $typeCmd();
Expand All @@ -415,6 +417,7 @@ public function save()
if (method_exists($eqLogic, 'postAjax')) {
$eqLogic->postAjax();
}
$this->ajax->success(Utils::o2a($eqLogic));
} catch (\Exception $e) {
if (strpos($e->getMessage(), '[MySQL] Error code : 23000') !== false) {
if ($e->getTrace()[2]['class'] == NextDomObj::EQLOGIC) {
Expand All @@ -426,7 +429,6 @@ public function save()
throw new CoreException($e->getMessage());
}
}
$this->ajax->success(Utils::o2a($eqLogic));
}
$this->ajax->success(null);
}
Expand Down
24 changes: 13 additions & 11 deletions src/Ajax/InteractAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
namespace NextDom\Ajax;

use NextDom\Enums\AjaxParams;
use NextDom\Enums\Common;
use NextDom\Enums\SQLField;
use NextDom\Enums\UserRight;
use NextDom\Exceptions\CoreException;
use NextDom\Helpers\NextDomHelper;
Expand All @@ -42,18 +44,18 @@ public function all()
$results = Utils::o2a(InteractDefManager::all());
foreach ($results as &$result) {
// @TODO TOus sélectionnés dans tous les cas
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
if ($result['link_type'] == 'cmd' && $result['link_id'] != '') {
$link_id = '';
foreach (explode('&&', $result['link_id']) as $cmd_id) {
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
if ($result[SQLField::LINK_TYPE] == 'cmd' && $result[SQLField::LINK_ID] != '') {
$linkId = '';
foreach (explode('&&', $result[SQLField::LINK_ID]) as $cmd_id) {
$cmd = CmdManager::byId($cmd_id);
if (is_object($cmd)) {
$link_id .= CmdManager::cmdToHumanReadable('#' . $cmd->getId() . '# && ');
$linkId .= CmdManager::cmdToHumanReadable('#' . $cmd->getId() . '# && ');
}

}
$result['link_id'] = trim(trim($link_id), '&&');
$result[SQLField::LINK_ID] = trim(trim($linkId), '&&');
}
}
$this->ajax->success($results);
Expand All @@ -62,16 +64,16 @@ public function all()
public function byId()
{
$result = Utils::o2a(InteractDefManager::byId(Utils::init(AjaxParams::ID)));
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
$this->ajax->success(NextDomHelper::toHumanReadable($result));
}

public function save()
{
$interact_json = NextDomHelper::fromHumanReadable(json_decode(Utils::init('interact'), true));
if (isset($interact_json['id'])) {
$interact = InteractDefManager::byId($interact_json['id']);
if (isset($interact_json[AjaxParams::ID])) {
$interact = InteractDefManager::byId($interact_json[AjaxParams::ID]);
}
if (!isset($interact) || !is_object($interact)) {
$interact = new InteractDef();
Expand Down
9 changes: 5 additions & 4 deletions src/Ajax/ListenerAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace NextDom\Ajax;

use NextDom\Enums\AjaxParams;
use NextDom\Enums\Common;
use NextDom\Enums\UserRight;
use NextDom\Exceptions\CoreException;
use NextDom\Helpers\NextDomHelper;
Expand Down Expand Up @@ -54,11 +55,11 @@ public function all()
{
$listeners = Utils::o2a(ListenerManager::all());
foreach ($listeners as &$listener) {
$listener['event_str'] = '';
foreach ($listener['event'] as $event) {
$listener['event_str'] .= $event . ',';
$listener[AjaxParams::EVENT_STR] = '';
foreach ($listener[Common::EVENT] as $event) {
$listener[AjaxParams::EVENT_STR] .= $event . ',';
}
$listener['event_str'] = NextDomHelper::toHumanReadable(trim($listener['event_str'], ','));
$listener[AjaxParams::EVENT_STR] = NextDomHelper::toHumanReadable(trim($listener[AjaxParams::EVENT_STR], ','));
}
$this->ajax->success($listeners);
}
Expand Down
Loading