Source of file ElementLanguageswitchPortal.php

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

buildproject/core/module_languageswitch/portal/elements/ElementLanguageswitchPortal.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
<?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\Languageswitch\Portal\Elements;

use Kajona\Pages\Portal\ElementPortal;
use Kajona\Pages\Portal\PortalElementInterface;
use Kajona\Pages\System\PagesPage;
use Kajona\System\System\LanguagesLanguage;
use Kajona\System\System\LanguagesLanguageset;
use Kajona\System\System\Link;
use Kajona\System\System\Objectfactory;


/**
 * Portal-Class of the picture element
 *
 * @author sidler@mulchprod.de
 *
 * @targetTable element_universal.content_id
 */
class ElementLanguageswitchPortal extends ElementPortal implements PortalElementInterface
{

    /**
     * Returns the ready switch-htmlcode
     *
     * @return string
     */
    public function loadData()
    {

        //fallback for old elements not yet using the template
        if (!isset($this->arrElementData["char1"]) || $this->arrElementData["char1"] == "") {
            $this->arrElementData["char1"] = "languageswitch.tpl";
        }

        $arrObjLanguages = LanguagesLanguage::getObjectListFiltered(null, true);

        //load the languageset in order to generate more specific switches
        $objLanguageset = LanguagesLanguageset::getLanguagesetForSystemid($this->getParam("systemid"));


        $objLanguage = new LanguagesLanguage();
        $strCurLang = $objLanguage->getPortalLanguage();
        

        //Iterate over all languages
        $strRows = "";
        foreach ($arrObjLanguages as $objOneLanguage) {
            //Check, if the current page has elements
            $objPage = PagesPage::getPageByName($this->getPagename());
            $objPage->setStrLanguage($objOneLanguage->getStrName());
            if ($objPage === null) {
                continue;
            }

            if ((int)$objPage->getNumberOfElementsOnPage(true) == 0) {
                continue;
            }


            $strTargetSystemid = null;
            if ($objLanguageset != null) {
                $strTargetSystemid = $objLanguageset->getSystemidForLanguageid($objOneLanguage->getSystemid());
            }

            //the languageswitch is content aware. check if the target id is a news-entry
            $strSeoAddon = "";
            if (validateSystemid($strTargetSystemid)) {
                $objRecord = Objectfactory::getInstance()->getObject($strTargetSystemid);
                $strSeoAddon = $objRecord->getStrDisplayName();
            }

            //and the link
            $arrTemplate = array();
            if ($strTargetSystemid === null) {
                $arrTemplate["href"] = Link::getLinkPortalHref($objPage->getStrName(), "", "", "", "", $objOneLanguage->getStrName(), $strSeoAddon);
            }
            else {
                $arrTemplate["href"] = Link::getLinkPortalHref($objPage->getStrName(), "", $this->getAction(), "", $strTargetSystemid, $objOneLanguage->getStrName(), $strSeoAddon);
            }

            $arrTemplate["langname_short"] = $objOneLanguage->getStrName();
            $arrTemplate["langname_long"] = $this->getLang("lang_".$objOneLanguage->getStrName());

            if ($objOneLanguage->getStrName() == $this->getStrPortalLanguage()) {
                $strRows .= $this->objTemplate->fillTemplateFile($arrTemplate, "/module_languageswitch/".$this->arrElementData["char1"], "languageswitch_entry_active");
            }
            else {
                $strRows .= $this->objTemplate->fillTemplateFile($arrTemplate, "/module_languageswitch/".$this->arrElementData["char1"], "languageswitch_entry");
            }

        }

        $objPage = PagesPage::getPageByName($this->getPagename());
        $objPage->setStrLanguage($strCurLang);
        $objPage = PagesPage::getPageByName($this->getPagename());

        return $this->objTemplate->fillTemplateFile(array("languageswitch_entries" => $strRows), "/module_languageswitch/".$this->arrElementData["char1"], "languageswitch_wrapper");
    }

}