/** * Create a ICollection instance from the id. * * @param IMetaModel $metaModel The MetaModel for which to retrieve the render setting. * * @param string $settingId The id of the ICollection. * * @return ICollection The instance or null if not found. */ protected function internalCreateRenderSetting(IMetaModel $metaModel, $settingId) { $row = $this->serviceContainer->getDatabase()->prepare('SELECT * FROM tl_metamodel_rendersettings WHERE pid=? AND (id=? OR isdefault=1) ORDER BY isdefault ASC')->limit(1)->execute($metaModel->get('id'), $settingId ?: 0); /** @noinspection PhpUndefinedFieldInspection */ if (!$row->numRows) { $row = null; } $renderSetting = new Collection($metaModel, $row ? $row->row() : array()); if ($renderSetting->get('id')) { $this->collectAttributeSettings($metaModel, $renderSetting); } return $renderSetting; }
/** * {@inheritdoc} * * @throws \RuntimeException When the MetaModel could not be retrieved. */ public function createCollection($settingId) { // TODO: we should provide a collector like for attributes. $information = $this->serviceContainer->getDatabase()->prepare('SELECT * FROM tl_metamodel_filter WHERE id=?')->execute($settingId)->row(); if (!empty($information)) { $modelFactory = $this->serviceContainer->getFactory(); $metaModel = $modelFactory->getMetaModel($modelFactory->translateIdToMetaModelName($information['pid'])); $collection = new Collection($information); if ($metaModel === null) { throw new \RuntimeException('Could not retrieve MetaModel ' . $information['pid']); } $collection->setMetaModel($metaModel); $this->collectRules($collection); return $collection; } return new Collection(array()); }
/** * Create a new instance. * * @param IMetaModelsServiceContainer $serviceContainer The MetaModel service container. */ public function __construct(IMetaModelsServiceContainer $serviceContainer) { $this->serviceContainer = $serviceContainer; $this->dispatcher = $serviceContainer->getEventDispatcher(); $this->database = $serviceContainer->getDatabase(); }
/** * Retrieve the Contao database singleton instance. * * @return \Database */ protected function getDatabase() { return $this->container->getDatabase(); }