Source of file SystemtaskNavigationcheck.php

Size: 4,725 Bytes - Last Modified: 2016-05-18T03:08:26+02:00

buildproject/core/module_navigation/admin/systemtasks/SystemtaskNavigationcheck.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
<?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2016 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*   $Id$                        *
********************************************************************************************************/

namespace Kajona\Navigation\Admin\Systemtasks;

use Kajona\Navigation\System\NavigationPoint;
use Kajona\Navigation\System\NavigationTree;
use Kajona\Pages\System\PagesPage;
use Kajona\System\Admin\Systemtasks\AdminSystemtaskInterface;
use Kajona\System\Admin\Systemtasks\SystemtaskBase;
use Kajona\System\System\SystemModule;

/**
 * Checkes the existing navigation-points for valid internal links.
 *
 * @package module_navigation
 */
class SystemtaskNavigationcheck extends SystemtaskBase implements AdminSystemtaskInterface {


    /**
     * contructor to call the base constructor
     */
    public function __construct() {
        parent::__construct();
        //set the correct text-base
        $this->setStrTextBase("navigation");
    }

    /**
     * @inheritdoc
     */
    public function getGroupIdentifier() {
        return "";
    }

    /**
     * @inheritdoc
     */
    public function getStrInternalTaskName() {
        return "navigationcheck";
    }

    /**
     * @inheritdoc
     */
    public function getStrTaskName() {
        return $this->getLang("systemtask_navigationcheck_name");
    }

    /**
     * @inheritdoc
     */
    public function executeTask() {

        if(!SystemModule::getModuleByName("navigation")->rightEdit())
            return $this->getLang("commons_error_permissions");

        $strReturn = "";

        //load all navigation points, tree by tree
        $arrTrees = NavigationTree::getObjectListFiltered();
        foreach($arrTrees as $objOneTree) {
            $strReturn .= $this->getLang("systemtask_navigationcheck_treescan")." \"".$objOneTree->getStrName()."\"...<br />";
            if(validateSystemid($objOneTree->getStrFolderId()))
                $strReturn .= $this->getLang("systemtask_navigationcheck_autogenerated")."<br />";
            else
                $strReturn .= $this->processLevel($objOneTree->getSystemid(), 0)."<br />";
        }

        return $strReturn;
    }

    private function processLevel($intParentId, $intLevel) {
        $strReturn = "";
        $arrNaviPoints = NavigationPoint::getNaviLayer($intParentId);
        foreach($arrNaviPoints as $objOnePoint) {
            for($intI = 0; $intI<=$intLevel; $intI++)
                $strReturn .= "&nbsp; &nbsp;";

            $strReturn .= $this->processSinglePoint($objOnePoint);
            $strReturn .= $this->processLevel($objOnePoint->getSystemid(), $intLevel+1);
        }

        return $strReturn;
    }


    private function processSinglePoint(NavigationPoint $objPoint) {
        $strReturn = "";
        $bitError = false;

        $strReturn .= $objPoint->getStrName().": ";

        if($objPoint->getStrPageI() == "" && $objPoint->getStrPageE() == "") {
            $strReturn .= $this->getLang("systemtask_navigationcheck_invalidEmpty");
            $bitError = true;
        }
        else if($objPoint->getStrPageI() != "" && $objPoint->getStrPageE() != "") {
            $strReturn .= $this->getLang("systemtask_navigationcheck_invalidBoth");
            $bitError = true;
        }
        else if($objPoint->getStrPageI() != "" && $objPoint->getStrPageE() == "") {
            //try to load internal page and check if it exists
            $objPage = PagesPage::getPageByName($objPoint->getStrPageI());

            if($objPage == null) {
                $strReturn .= $this->getLang("systemtask_navigationcheck_invalidInternal")." ".$objPoint->getStrPageI().")";
                $bitError = true;
            } else {
                $strReturn .= $this->getLang("systemtask_navigationcheck_valid")." ".$objPoint->getStrPageI(). $objPoint->getStrPageE().")";
            }
        }
        else {
            $strReturn .= $this->getLang("systemtask_navigationcheck_valid")." ".$objPoint->getStrPageI(). $objPoint->getStrPageE().")";
        }

        if ($bitError) {
            $strReturn = "<b>".$strReturn."</b>";
        }

        return $strReturn."<br />";
    }

    /**
     * @inheritdoc
     */
    public function getAdminForm() {
        return "";
    }

}