Source of file InstallerSamplecontent02Navigation.php

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

buildproject/core/module_navigation/installer/InstallerSamplecontent02Navigation.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
<?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                                 *
********************************************************************************************************/

namespace Kajona\Navigation\Installer;

use Kajona\Navigation\Admin\Elements\ElementNavigationAdmin;
use Kajona\Navigation\System\NavigationPoint;
use Kajona\Navigation\System\NavigationTree;
use Kajona\Pages\Admin\Elements\ElementPlaintextAdmin;
use Kajona\Pages\System\PagesElement;
use Kajona\Pages\System\PagesFolder;
use Kajona\Pages\System\PagesPage;
use Kajona\Pages\System\PagesPageelement;
use Kajona\Samplecontent\System\SamplecontentContentHelper;
use Kajona\System\System\Database;
use Kajona\System\System\SamplecontentInstallerInterface;

/**
 * Installer of the navigation samplecontent
 *
 */
class InstallerSamplecontent02Navigation implements SamplecontentInstallerInterface
{

    /**
     * @var Database
     */
    private $objDB;
    private $strContentLanguage;

    private $strMasterID = "";


    /**
     * @inheritDoc
     */
    public function isInstalled()
    {
        return NavigationTree::getObjectCountFiltered() > 0;
    }

    /**
     * Does the hard work: installs the module and registers needed constants
     *
     * @return string
     */
    public function install()
    {

        //search the master page
        $objMaster = PagesPage::getPageByName("master");
        if ($objMaster != null) {
            $this->strMasterID = $objMaster->getSystemid();
        }

        //fetch navifolder-id
        $strNaviFolderId = "";
        $arrFolder = PagesFolder::getFolderList();
        foreach ($arrFolder as $objOneFolder) {
            if ($objOneFolder->getStrName() == "mainnavigation") {
                $strNaviFolderId = $objOneFolder->getSystemid();
            }
        }


        $strReturn = "";
        $strReturn .= "Creating new mainnavigation-tree\n";
        $objNaviTree = new NavigationTree();
        $objNaviTree->setStrName("mainnavigation");
        $objNaviTree->setStrFolderId($strNaviFolderId);
        $objNaviTree->updateObjectToDb();
        $strTreeId = $objNaviTree->getSystemid();
        $strReturn .= "ID of new navigation-tree: ".$strTreeId."\n";


        $strReturn .= "Creating new portalnavigation-tree\n";
        $objNaviTree = new NavigationTree();
        $objNaviTree->setStrName("portalnavigation");
        $objNaviTree->updateObjectToDb();
        $strTreePortalId = $objNaviTree->getSystemid();
        $strReturn .= "ID of new navigation-tree: ".$strTreePortalId."\n";

        $strReturn .= "Creating navigation points\n";
        $objNaviPoint = new NavigationPoint();
        $objNaviPoint->setStrName("Home");
        $objNaviPoint->setStrPageI("index");
        $objNaviPoint->updateObjectToDb($strTreePortalId);


        if ($this->strMasterID != "") {
            $strReturn .= "Adding mainnavigation to master page\n";
            $strReturn .= "ID of master page: ".$this->strMasterID."\n";

            if (PagesElement::getElement("navigation") != null) {
                $objPagelement = new PagesPageelement();
                $objPagelement->setStrPlaceholder("mastermainnavi_navigation");
                $objPagelement->setStrName("mastermainnavi");
                $objPagelement->setStrElement("navigation");
                $objPagelement->updateObjectToDb($this->strMasterID);

                /** @var ElementNavigationAdmin $objElement */
                $objElement = $objPagelement->getConcreteAdminInstance();
                $objElement->setStrRepo($strTreeId);
                $objElement->setStrTemplate("mainnavi.tpl");
                $objElement->updateForeignElement();
            }

            $strReturn .= "Adding portalnavigation to master page\n";
            $strReturn .= "ID of master page: ".$this->strMasterID."\n";

            if (PagesElement::getElement("navigation") != null) {
                $objPagelement = new PagesPageelement();
                $objPagelement->setStrPlaceholder("masterportalnavi_navigation");
                $objPagelement->setStrName("masterportalnavi");
                $objPagelement->setStrElement("navigation");
                $objPagelement->updateObjectToDb($this->strMasterID);

                /** @var ElementNavigationAdmin $objElement */
                $objElement = $objPagelement->getConcreteAdminInstance();
                $objElement->setStrRepo($strTreePortalId);
                $objElement->setStrTemplate("portalnavi.tpl");
                $objElement->updateForeignElement();

            }

            $strReturn .= "Adding pathnavigation to master page\n";
            $strReturn .= "ID of master page: ".$this->strMasterID."\n";

            if (PagesElement::getElement("navigation") != null) {
                $objPagelement = new PagesPageelement();
                $objPagelement->setStrPlaceholder("masterpathnavi_navigation");
                $objPagelement->setStrName("masterpathnavi");
                $objPagelement->setStrElement("navigation");
                $objPagelement->updateObjectToDb($this->strMasterID);

                /** @var ElementNavigationAdmin $objElement */
                $objElement = $objPagelement->getConcreteAdminInstance();
                $objElement->setStrRepo($strTreeId);
                $objElement->setStrTemplate("breadcrumbnavi.tpl");
                $objElement->updateForeignElement();

            }
        }

        $strReturn .= "Creating simple sitemap...\n";

        $objHelper = new SamplecontentContentHelper();

        $objPage = $objHelper->createPage("sitemap", "Sitemap", PagesPage::getPageByName("index")->getSystemid());
        $strReturn .= "ID of new page: ".$objPage->getSystemid()."\n";

        $objBlocks = $objHelper->createBlocksElement("Headline", $objPage);
        $objBlock = $objHelper->createBlockElement("Headline", $objBlocks);

        $strReturn .= "Adding headline-element to new page\n";
        $objHeadline = $objHelper->createPageElement("headline_plaintext", $objBlock);
        /** @var ElementPlaintextAdmin $objHeadlineAdmin */
        $objHeadlineAdmin = $objHeadline->getConcreteAdminInstance();
        $objHeadlineAdmin->setStrText("Sitemap");
        $objHeadlineAdmin->updateForeignElement();


        $objBlocks = $objHelper->createBlocksElement("Special Content", $objPage);
        $objBlock = $objHelper->createBlockElement("Sitemap", $objBlocks);

        $objNavigation = $objHelper->createPageElement("sitemap_navigation", $objBlock);
        /** @var ElementNavigationAdmin $objElement */
        $objElement = $objNavigation->getConcreteAdminInstance();
        $objElement->setStrRepo($strTreeId);
        $objElement->setStrTemplate("sitemap.tpl");
        $objElement->updateForeignElement();


        $strReturn .= "Creating navigation points\n";
        $objNaviPoint = new NavigationPoint();
        $objNaviPoint->setStrName("Sitemap");
        $objNaviPoint->setStrPageI("sitemap");
        $objNaviPoint->updateObjectToDb($strTreePortalId);
        $strReturn .= "ID of new navigation point ".$objNaviPoint->getSystemid().".\n";

        $objNaviPoint = new NavigationPoint();
        if ($this->strContentLanguage == "de") {
            $objNaviPoint->setStrName("Impressum");
        }
        else {
            $objNaviPoint->setStrName("Imprint");
        }
        $objNaviPoint->setStrPageI("imprint");
        $objNaviPoint->updateObjectToDb($strTreePortalId);
        $strReturn .= "ID of new navigation point ".$objNaviPoint->getSystemid().".\n";


        return $strReturn;
    }

    public function setObjDb($objDb)
    {
        $this->objDB = $objDb;
    }

    public function setStrContentlanguage($strContentlanguage)
    {
        $this->strContentLanguage = $strContentlanguage;
    }

    public function getCorrespondingModule()
    {
        return "navigation";
    }
}