Skip to content

Commit

Permalink
Merge pull request #1679 from NextDom/SonarViewControllerFix
Browse files Browse the repository at this point in the history
Fix viewController
  • Loading branch information
Sylvaner authored Feb 23, 2020
2 parents 19985cf + 8a23fdd commit 20cd0b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/Controller/Pages/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,38 @@ class ViewController extends BaseController
* @return string Content of view page
*
* @throws CoreException
* @throws \ReflectionException
*/
public static function get(&$pageData): string
{
$pageData['viewsList'] = ViewManager::all();
$allViews = ViewManager::all();
$viewId = Utils::init(AjaxParams::VIEW_ID);
$pageData['viewHideList'] = true;
$pageData['viewIsAdmin'] = AuthentificationHelper::isConnectedAsAdmin();
$pageData['viewDefault'] = UserManager::getStoredUser()->getOptions('displayViewByDefault');
$pageData['viewNoControl'] = Utils::init('noControl');
$pageData['viewsList'] = $allViews;

$currentView = null;
if (Utils::init(AjaxParams::VIEW_ID) == '') {

if (UserManager::getStoredUser()->getOptions('defaultDesktopView') != '') {
$currentView = ViewManager::byId(UserManager::getStoredUser()->getOptions('defaultDesktopView'));
if (empty($viewId)) {
$defaultDesktopView = UserManager::getStoredUser()->getOptions('defaultDesktopView');
if (!empty($defaultDesktopView)) {
$currentView = ViewManager::byId($defaultDesktopView);
}

if (!is_object($currentView) && is_array($pageData['viewsList']) && count($pageData['viewsList']) > 0) {
$currentView = $pageData['viewsList'][0];
if (!is_object($currentView) && is_array($allViews) && count($allViews) > 0) {
$currentView = $allViews[0];
}
} else {
$currentView = ViewManager::byId(Utils::init(AjaxParams::VIEW_ID));

$currentView = ViewManager::byId($viewId);
if (!is_object($currentView)) {
throw new CoreException('{{Vue inconnue. Vérifier l\'ID.}}');
throw new CoreException(__('Vue inconnue. Vérifier l\'ID.'));
}
}

if (!is_object($currentView)) {
throw new CoreException(__('Aucune vue n\'existe, cliquez <a href="index.php?v=d&p=view_edit">ici</a> pour en créer une.'));
}
$pageData['viewCurrent'] = $currentView;

if (UserManager::getStoredUser()->getOptions('displayViewByDefault') == 1 && Utils::init('report') != 1) {
if ($pageData['viewDefault'] == 1 && Utils::init('report') != 1) {
$pageData['viewHideList'] = false;
}
$pageData[ControllerData::JS_VARS][AjaxParams::VIEW_ID] = $currentView->getId();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit_tests/Ajax/CronAjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public function testStart()
sleep(10);
$jsonResult = json_decode($result, true);
$this->assertEquals('ok', $jsonResult['state']);
$this->assertStringContainsString('CRON ERROR', LogHelper::get('plugin4tests')[0]);
$this->assertStringContainsString('CRON ERROR', implode(LogHelper::get('plugin4tests')));
}
}

0 comments on commit 20cd0b5

Please sign in to comment.