Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
19.05% covered (danger)
19.05%
4 / 21
CRAP
17.74% covered (danger)
17.74%
11 / 62
ViewController
0.00% covered (danger)
0.00%
0 / 1
19.05% covered (danger)
19.05%
4 / 21
601.95
17.74% covered (danger)
17.74%
11 / 62
 __construct( \aae\ui\TemplateInterface $template, \aae\ui\Localizer $localizer = null )
0.00% covered (danger)
0.00%
0 / 1
3.79
55.56% covered (warning)
55.56%
5 / 9
 setErrorCode($errorCode)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setErrorMessage($errorMessage)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getErrorCode()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getErrorMessage()
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setError($errorMessage, $errorCode)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 __call($functionName, $args)
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 useTemplate($templateName)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 internalRedirect($actionName, $args = [])
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 7
 loadTemplate($templateName)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getHtml()
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getView()
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 localize($stringName, $language = null)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 localizeArrayElement(&$array, $arrayElmentName, $language = null)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 localizeAndDecorateArrayElement(&$array, $arrayElmentName, $decorationStringName, $language = null)
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 getActionEndings()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 cssClassToggle($selectorName, $n, $count)
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
 lastCall()
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 constructCall()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 _getControllerName()
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 10
 get_all_localized_stringsAction()
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
<?php
/**
 *
 */
namespace aae\ui {
    /**
     * @author Axel Ancona Esselmann
     * @package aae\ui
     */
    class ViewController implements \aae\ui\ViewControllerInterface {
        public $template;
        protected $_errorCode = 0;
        protected $_errorMessage;
        public function __construct(
            \aae\ui\TemplateInterface $template,
            \aae\ui\Localizer $localizer = null
        ) {
            $this->template = $template;
            $this->_localizer = $localizer;
            if (!is_null($this->_localizer)) {
                $this->_localizer->setI18nFileName($this->_getControllerName());
                $this->template->setLocalizer($localizer);
                if ($this->_localizer->hasDefaultLocalization()) $this->template["pageTitle"] = $this->localize("defaultPageTitle");
            }
            $this->constructCall();
        }
        public function setErrorCode($errorCode) {
            $this->_errorCode = $errorCode;
        }
        public function setErrorMessage($errorMessage) {
            $this->_errorMessage = $errorMessage;
        }
        public function getErrorCode() {
            return $this->_errorCode;
        }
        public function getErrorMessage() {
            return $this->_errorMessage;
        }
        public function setError($errorMessage, $errorCode) {
            $this->setErrorMessage($errorMessage);
            $this->setErrorCode($errorCode);
            return false;
        }
        public function __call($functionName, $args) {
            $actionName = $functionName."Action";
            if (!method_exists($this, $actionName)) throw new \Exception(get_class($this)." does not have the function $functionName", 1206140141);
            return call_user_func_array(array($this, $actionName), $args);
        }
        public function useTemplate($templateName) {
            $this->template->load($templateName);
        }
        public function internalRedirect($actionName, $args = []) {
            $argsString = "/".implode("/", $args);
            $controller = $this->_getControllerName();
            $action     = strstr($actionName, "Action", true);
            $location   = (strlen($action) > 0) ? "/$controller/".$action : $location = "/$controller";
            $locationWithArgs = $location.$argsString;
            header(header("Location: $locationWithArgs", 301));
        }
        public function loadTemplate($templateName) {
            $this->template->load($templateName);
        }
        public function getHtml() {
            return $this->template->__toString();
        }
        public function getView() {
            $this->lastCall();
            return $this->getHtml();
        }
        public function localize($stringName, $language = null) {
            $fileName = $this->_getControllerName();
            return $this->_localizer->localize($stringName, $fileName, $language);
        }
        public function localizeArrayElement(&$array, $arrayElmentName, $language = null) {
            $fileName = $this->_getControllerName();
            $this->_localizer->localizeArrayElement($array, $arrayElmentName, $fileName, $language);
        }
        public function localizeAndDecorateArrayElement(&$array, $arrayElmentName, $decorationStringName, $language = null) {
            $fileName = $this->_getControllerName();
            $this->_localizer->localizeAndDecorateArrayElement($array, $arrayElmentName, $decorationStringName, $fileName, $language);
        }
        public function getActionEndings() {
            return "Action";
        }
        /**
         * If html items have a template variable that is numbered cuntinuously, setMenuItem clears all but the $n
         * @param str $selectorName template variable (has to be numbered continuously)
         * @param int $n            the variable to be set as active
         * @param int $count        the number of template variables associated with $selectorName
         */
        public function cssClassToggle($selectorName, $n, $count) {
            for ($i=0; $i < $count; $i++) {
                if ($i !== $n) $this->template[$selectorName.$i] = "";
            }
            $this->template[$selectorName.$n] = " active";
        }
        public function lastCall() {
            # gets called before serializing of template. Overwrite to execute something on every action call
        }
        public function constructCall() {
            # gets called after the constructor is called. Overwrite to extend the constructor.
        }
        private function _getControllerName() {
            $class = get_class($this);
            $cn = strstr($class, "ViewController", true);
            if (strlen($cn) < 1) {
                $cn = strstr($class, "ApiController", true);
                if (strlen($cn) < 1) {
                    $cn = strstr($class, "TemplateController", true);
                    if (strlen($cn) < 1 && ($class != "ViewController" && $class != "TemplateController")) throw new \Exception("Controller ".$class." does not end in 'ViewController' or 'TemplateController'", 204151652);
                }
            }
            return strtolower($cn);
        }
        public function get_all_localized_stringsAction() {
            return $this->_localizer->localizeAll();
        }
    }
}