Get a catalogue

@throws	UnexpectedValueException	If the catalogue doesn't implement the TranslatorCatalogueInterface
@return KTranslatorCatalogueInterface The translator catalogue.
962701
public function getCatalogue()
    {
        if (!$this->_catalogue instanceof KTranslatorCatalogueInterface)
        {
            if(!($this->_catalogue instanceof KObjectIdentifier)) {
                $this->setCatalogue($this->_catalogue);
            }

            $this->_catalogue = $this->getObject($this->_catalogue);
        }

        if(!$this->_catalogue instanceof KTranslatorCatalogueInterface)
        {
            throw new UnexpectedValueException(
                'Catalogue: '.get_class($this->_catalogue).' does not implement TranslatorCatalogueInterface'
            );
        }

        return $this->_catalogue;
    }
1053394
public function asObjectDescriptor(): Primitive\ObjectDescriptor
    {
        if (!$this->_element instanceof Primitive\ObjectDescriptor) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(
                    Element::TYPE_OBJECT_DESCRIPTOR));
        }
        return $this->_element;
    }
358289
public function getTable()
    {
        if (!($this->_table instanceof KDatabaseTableInterface))
        {
            //Make sure we have a table identifier
            if (!($this->_table instanceof KObjectIdentifier)) {
                $this->setTable($this->_table);
            }

            $this->_table = $this->getObject($this->_table);

            if (!($this->_table instanceof KDatabaseTableInterface))
            {
                throw new UnexpectedValueException(
                    'Table: ' . get_class($this->_table) . ' does not implement KDatabaseTableInterface'
                );
            }
        }

        return $this->_table;
    }
166133
public function getDatatypes() {
        if (empty($this->data)) {
            $this->data = $this->parse_string();
        }
        if (!is_array($this->data)) {
            throw new \UnexpectedValueException('No data set yet.');
        }

        $result = [];
        foreach ($this->titles as $cName) {
            $column = array_column($this->data, $cName);
            $cDatatypes = array_map(DatatypeEnum::class . '::getValidTypeFromSample', $column);

            $result[$cName] = $this->getMostFrequentDatatypeForColumn($cDatatypes);
        }

        $this->data_types = $result;

        return !empty($this->data_types) ? $this->data_types : [];
    }
1326787
public function getRequest()
    {
        if(!$this->_request instanceof KDispatcherRequestInterface)
        {
            $this->_request = $this->getObject($this->_request);

            if(!$this->_request instanceof KDispatcherRequestInterface)
            {
                throw new UnexpectedValueException(
                    'Request: '.get_class($this->_request).' does not implement KDispatcherRequestInterface'
                );
            }
        }

        return $this->_request;
    }
1234585
public function getController()
    {
        if(!($this->_controller instanceof KControllerInterface))
        {
            //Make sure we have a controller identifier
            if(!($this->_controller instanceof KObjectIdentifier)) {
                $this->setController($this->_controller);
            }

            $config = array(
                'request'    => $this->getRequest(),
                'response'   => $this->getResponse(),
                'user'       => $this->getUser(),
                'dispatched' => $this
            );

            $this->_controller = $this->getObject($this->_controller, $config);

            //Make sure the controller implements KControllerInterface
            if(!$this->_controller instanceof KControllerInterface)
            {
                throw new UnexpectedValueException(
                    'Controller: '.get_class($this->_controller).' does not implement KControllerInterface'
                );
            }
        }

        return $this->_controller;
    }
612150
public function transform($string)
    {
        $string = $this->transliterator->transliterate($string);
        if ($string === false) {
            throw new UnexpectedValueException($this->transliterator->getErrorMessage(), $this->transliterator->getErrorCode());
        }
        return $string;
    }
305821
public function transform($value): array
    {
        if (null === $value) {
            return [];
        }

        if (!$value instanceof ProductVariantInterface) {
            throw new UnexpectedTypeException($value, ProductVariantInterface::class);
        }

        return array_combine(
            array_map(function (ProductOptionValueInterface $productOptionValue) {
                return $productOptionValue->getOptionCode();
            }, $value->getOptionValues()->toArray()),
            $value->getOptionValues()->toArray()
        );
    }
1367008
public function getTranslator() {
        if (!$this->_translator) {
            if ($this->translator) {
                $class = $this->translator;
                $this->_translator = $class::get();
                if (!is_a($this->_translator, '\\mpf\\interfaces\\TranslatorInterface')) {
                    $this->_translator = null;
                    $this->translator = '';
                    throw new Exception("Invalid translator $class!  Must implement \\mpf\\interfaces\\TranslatorInterface!");
                }
            }
        }
        return $this->_translator;
    }
150610
public function getCatalog()
    {
        if ($this->idcat < 0) return false;
        try {
            return Catalog::getById($this->idcat);
        } catch (\Exception $e) {
            return false;
        }
    }
1107385
protected function getValueFromRelationQuery($query)
    {
        // Query must be a relation in this case, since we need the related model
        if ( ! ($query instanceof BelongsToMany)) {
            throw new UnexpectedValueException("Query must be BelongsToMany Relation instance for " . get_class($this));
        }

        /** @var BelongsToMany $query */

        $relatedModel = $query->getRelated();
        $keyName      = $relatedModel->getKeyName();
        $table        = $relatedModel->getTable();
        $pivotTable   = $query->getTable();
        $orderColumn  = $this->getPivotOrderColumn();

        $query = $this->prepareRelationQuery(
            $query
                ->withPivot([ $orderColumn ])
                ->orderBy($pivotTable . '.' . $orderColumn)
        );

        // Get only the relevant columns: key and pivot
        return $query->pluck($pivotTable . '.' . $orderColumn, $table . '.' . $keyName);
    }
1016264
public function getResponse()
    {
        if(!$this->_response instanceof KDispatcherResponseInterface)
        {
            $this->_response = $this->getObject($this->_response, array(
                'request' => $this->getRequest(),
                'user'    => $this->getUser(),
            ));

            if(!$this->_response instanceof KDispatcherResponseInterface)
            {
                throw new UnexpectedValueException(
                    'Response: '.get_class($this->_response).' does not implement KDispatcherResponseInterface'
                );
            }
        }

        return $this->_response;
    }
748790
public function getState()
    {
        if(!$this->__state instanceof KModelStateInterface)
        {
            $this->__state = $this->getObject($this->__state, array('model' => $this));

            if(!$this->__state instanceof KModelStateInterface)
            {
                throw new UnexpectedValueException(
                    'State: '.get_class($this->__state).' does not implement KModelStateInterface'
                );
            }
        }

        return $this->__state;
    }
811434
public function isRegistered($identifier)
    {
        if(strpos($identifier, '.') !== false )
        {
            $identifier = $this->getIdentifier($identifier);
            $class      = $this->getObject('manager')->getClass($identifier);

            if(!$class || !array_key_exists('KTranslatorLocatorInterface', class_implements($class)))
            {
                throw new UnexpectedValueException(
                    'Locator: '.$identifier.' does not implement KTranslatorLocatorInterface'
                );
            }

            $name = $class::getName();
        }
        else $name = $identifier;

        $result = in_array($name, $this->getLocators());
        return $result;
    }
702953
public function getView()
    {
        if(!$this->_view instanceof KViewInterface)
        {
            //Make sure we have a view identifier
            if(!($this->_view instanceof KObjectIdentifier)) {
                $this->setView($this->_view);
            }

            //Create the view
            $config = array(
                'url'        => $this->getObject('request')->getUrl(),
                'layout'     => $this->getRequest()->getQuery()->get('layout', 'identifier'),
                'auto_fetch' => $this instanceof KControllerModellable
            );

            $this->_view = $this->getObject($this->_view, $config);

            //Make sure the view implements KViewInterface
            if(!$this->_view instanceof KViewInterface)
            {
                throw new UnexpectedValueException(
                    'View: '.get_class($this->_view).' does not implement KViewInterface'
                );
            }
        }

        return $this->_view;
    }
1154860
public function getHeader()
	{
		if (!$this->getOption('key'))
		{
			throw new UnexpectedValueException('A Google Maps API key is required.');
		}

		$zoom = $this->getZoom();
		$center = $this->getCenter();
		$maptype = $this->getMapType();
		$id = $this->getMapID();
		$scheme = $this->isSecure() ? 'https' : 'http';
		$key = $this->getKey();
		$sensor = $this->hasSensor() ? 'true' : 'false';

		$setup = 'var mapOptions = {';
		$setup .= "zoom: {$zoom},";
		$setup .= "center: new google.maps.LatLng({$center[0]},{$center[1]}),";
		$setup .= "mapTypeId: google.maps.MapTypeId.{$maptype},";
		$setup .= substr(json_encode($this->getAdditionalMapOptions()), 1, -1);
		$setup .= '};';
		$setup .= "var map = new google.maps.Map(document.getElementById('{$id}'), mapOptions);";

		foreach ($this->listMarkers() as $marker)
		{
			$loc = $marker['loc'];
			$title = $marker['title'];
			$options = $marker['options'];

			$setup .= 'new google.maps.Marker({';
			$setup .= "position: new google.maps.LatLng({$loc[0]},{$loc[1]}),";
			$setup .= 'map: map,';
			$setup .= "title:'{$title}',";
			$setup .= substr(json_encode($options), 1, -1);
			$setup .= '});';
		}

		$setup .= $this->getAdditionalJavascript();

		if ($this->isAsync())
		{
			$asynccallback = $this->getAsyncCallback();

			$output = '<script type="text/javascript">';
			$output .= "function {$asynccallback}() {";
			$output .= $setup;
			$output .= '}';

			$onload = "function() {";
			$onload .= 'var script = document.createElement("script");';
			$onload .= 'script.type = "text/javascript";';
			$onload .= "script.src = '{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}&callback={$asynccallback}';";
			$onload .= 'document.body.appendChild(script);';
			$onload .= '}';
		}
		else
		{
			$output = "<script type='text/javascript' src='{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}'>";
			$output .= '</script>';
			$output .= '<script type="text/javascript">';

			$onload = "function() {";
			$onload .= $setup;
			$onload .= '}';
		}

		switch ($this->getAutoload())
		{
			case 'onload':
				$output .= "window.onload={$onload};";
				break;

			case 'jquery':
				$output .= "$(document).ready({$onload});";
				break;

			case 'mootools':
				$output .= "window.addEvent('domready',{$onload});";
				break;
		}

		$output .= '</script>';

		return $output;
	}
35702
public function getModel()
    {
        if(!$this->_model instanceof KModelInterface)
        {
            //Make sure we have a model identifier
            if(!($this->_model instanceof KObjectIdentifier)) {
                $this->setModel($this->_model);
            }

            $this->_model = $this->getObject($this->_model);

            if(!$this->_model instanceof KModelInterface)
            {
                throw new UnexpectedValueException(
                    'Model: '.get_class($this->_model).' does not implement KModelInterface'
                );
            }

            //Inject the request into the model state
            $this->_model->setState($this->getRequest()->query->toArray());
        }

        return $this->_model;
    }