/**
  * Build the wizard string.
  *
  * @param ManipulateWidgetEvent $event The event.
  *
  * @return void
  */
 public function getWizard(ManipulateWidgetEvent $event)
 {
     if ($event->getModel()->getProviderName() !== $this->metaModel->getTableName() || $event->getProperty()->getName() !== $this->propertyName) {
         return;
     }
     $propName = $event->getProperty()->getName();
     $model = $event->getModel();
     $inputId = $propName;
     $translator = $event->getEnvironment()->getTranslator();
     $this->addStylesheet('metamodelsattribute_pageid', 'system/modules/metamodelsattribute_pageid/html/style.css');
     if (version_compare(VERSION, '3.1', '>=')) {
         $currentField = $model->getProperty($propName);
         /** @var GenerateHtmlEvent $imageEvent */
         $imageEvent = $event->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pickpage.gif', $translator->translate('pagepicker', 'MSC'), 'style="vertical-align:top;cursor:pointer"'));
         $event->getWidget()->wizard = ' <a href="contao/page.php?do=' . \Input::get('do') . '&amp;table=' . $this->metaModel->getTableName() . '&amp;field=' . $inputId . '&amp;value=' . $currentField . '" title="' . specialchars($translator->translate('pagepicker', 'MSC')) . '" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':765,\'title\':\'' . specialchars(str_replace("'", "\\'", $translator->translate('page.0', 'MOD'))) . '\',\'url\':this.href,\'id\':\'' . $inputId . '\',\'tag\':\'ctrl_' . $inputId . '\',\'insTagStr\':\'\',\'self\':this});' . 'return false">' . $imageEvent->getHtml() . '</a>';
         //get the page model to get the current title and alias to set it to the category
         // $pageModel = \PageModel::findById($currentField);
         // $model->setProperty('name',$pageModel->title);
         // $model->setProperty('alias',$pageModel->alias);
         // $model->getItem()->save();
         // var_dump(get_class_methods($event));
         return;
     } else {
         throw new Exception("This Attribut requires Contao >= 3.1", 1);
     }
 }
 /**
  * Return a string that describe the condition in a human readable way.
  *
  * @return string
  */
 public function describe()
 {
     if ($this->metaModel) {
         return 'metamodel.table == ' . $this->metaModel->getTableName();
     } else {
         return 'metamodel.table == ?';
     }
 }
 /**
  * Build the wizard string.
  *
  * @param ManipulateWidgetEvent $event The event.
  *
  * @return void
  */
 public function getWizard(ManipulateWidgetEvent $event)
 {
     if ($event->getModel()->getProviderName() !== $this->metaModel->getTableName() || $event->getProperty()->getName() !== $this->propertyName) {
         return;
     }
     $propName = $event->getProperty()->getName();
     $model = $event->getModel();
     $inputId = $propName . (!$this->metaModel->getAttribute($this->propertyName)->get('trim_title') ? '_1' : '');
     $translator = $event->getEnvironment()->getTranslator();
     $this->addStylesheet('metamodelsattribute_url', 'system/modules/metamodelsattribute_url/html/style.css');
     $currentField = deserialize($model->getProperty($propName), true);
     /** @var GenerateHtmlEvent $imageEvent */
     $imageEvent = $event->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('pickpage.gif', $translator->translate('pagepicker', 'MSC'), 'style="vertical-align:top;cursor:pointer"'));
     $event->getWidget()->wizard = ' <a href="contao/page.php?do=' . \Input::get('do') . '&amp;table=' . $this->metaModel->getTableName() . '&amp;field=' . $inputId . '&amp;value=' . str_replace(array('{{link_url::', '}}'), '', $currentField[1]) . '" title="' . specialchars($translator->translate('pagepicker', 'MSC')) . '" onclick="Backend.getScrollOffset();' . 'Backend.openModalSelector({\'width\':765,\'title\':\'' . specialchars(str_replace("'", "\\'", $translator->translate('page.0', 'MOD'))) . '\',\'url\':this.href,\'id\':\'' . $inputId . '\',\'tag\':\'ctrl_' . $inputId . '\',\'self\':this});' . 'return false">' . $imageEvent->getHtml() . '</a>';
 }
 /**
  * Extract the attribute instance from the MetaModel.
  *
  * @param IMetaModel $metaModel   The MetaModel instance.
  *
  * @param string     $attributeId The attribute id.
  *
  * @return IAttribute
  *
  * @throws \RuntimeException When the attribute could not be retrieved.
  */
 private function getAttributeFromMetaModel(IMetaModel $metaModel, $attributeId)
 {
     $attribute = $metaModel->getAttributeById($attributeId);
     if (!$attribute) {
         throw new \RuntimeException(sprintf('Could not retrieve attribute %s from MetaModel %s.', $attributeId, $metaModel->getTableName()));
     }
     return $attribute;
 }
Exemple #5
0
 /**
  * Retrieve the jump to label.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 private function getJumpToLabel()
 {
     $tableName = $this->metaModel->getTableName();
     if (isset($GLOBALS['TL_LANG']['MSC'][$tableName][$this->get('id')]['details'])) {
         return $GLOBALS['TL_LANG']['MSC'][$tableName][$this->get('id')]['details'];
     } elseif (isset($GLOBALS['TL_LANG']['MSC'][$tableName]['details'])) {
         return $GLOBALS['TL_LANG']['MSC'][$tableName]['details'];
     }
     return $GLOBALS['TL_LANG']['MSC']['details'];
 }
 /**
  * @param $name
  * @return IItem|null
  */
 protected function loadModel($name)
 {
     list($table, $id, $providerId) = explode('::', $name, 3);
     if ($providerId != $this->providerId) {
         // prevent that item for which this provider is not responsible will handle the model
         return null;
     }
     if (isset(static::$cache[$name])) {
         return static::$cache[$name];
     }
     if ($table != $this->metaModel->getTableName()) {
         return null;
     }
     return $this->metaModel->findById($id);
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 public function createCollection(IMetaModel $metaModel, $settingId = '')
 {
     $tableName = $metaModel->getTableName();
     if (!isset($this->renderSettings[$tableName])) {
         $this->renderSettings[$tableName] = array();
     }
     if (!isset($this->renderSettings[$tableName][$settingId])) {
         $this->renderSettings[$tableName][$settingId] = $this->internalCreateRenderSetting($metaModel, $settingId);
     }
     return $this->renderSettings[$tableName][$settingId];
 }
 /**
  * Retrieve the caption text for the "Show details" link.
  *
  * Stolen from MetaModels\ItemList::getDetailsCaption
  *
  * In order to achieve the correct caption text, the function tries several translation strings sequentially.
  * The first language key that is set will win, even if it is to be considered empty.
  *
  * This message is looked up in the following order:
  * 1. $GLOBALS['TL_LANG']['MSC'][<mm tablename>][<render settings id>]['details']
  * 2. $GLOBALS['TL_LANG']['MSC'][<mm tablename>]['details']
  * 3. $GLOBALS['TL_LANG']['MSC']['details']
  *
  * @param MetaModel $metaModel The MetaModel.
  *
  * @return string
  * @see    MetaModels\ItemList::getDetailsCaption
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function getDetailsCaption(MetaModel $metaModel)
 {
     $tableName = $metaModel->getTableName();
     if (isset($this->objView) && isset($GLOBALS['TL_LANG']['MSC'][$tableName][$this->objView->get('id')]['details'])) {
         return $GLOBALS['TL_LANG']['MSC'][$tableName][$this->objView->get('id')]['details'];
     } elseif (isset($GLOBALS['TL_LANG']['MSC'][$tableName]['details'])) {
         return $GLOBALS['TL_LANG']['MSC'][$tableName]['details'];
     }
     return $GLOBALS['TL_LANG']['MSC']['details'];
 }
Exemple #9
0
 /**
  * Create a new filter instance.
  *
  * @param IMetaModel $objMetaModel The MetaModel this filter shall apply to.
  */
 public function __construct(IMetaModel $objMetaModel)
 {
     if ($objMetaModel) {
         $this->strMetaModel = $objMetaModel->getTableName();
     }
 }
Exemple #10
0
 /**
  * Obtain the values of a property within a dc-general instance.
  *
  * @param IMetaModel           $metaModel   The metamodel instance to obtain the values from.
  *
  * @param EnvironmentInterface $environment The environment used in the input screen table dc-general.
  *
  * @param IAttribute           $attribute   The attribute to obtain the values for.
  *
  * @return array
  */
 private function getOptionsViaDcGeneral($metaModel, $environment, $attribute)
 {
     $factory = new DcGeneralFactory();
     $dcGeneral = $factory->setContainerName($metaModel->getTableName())->setEventDispatcher($environment->getEventDispatcher())->setTranslator($environment->getTranslator())->createDcGeneral();
     $subEnv = $dcGeneral->getEnvironment();
     $optEv = new GetPropertyOptionsEvent($subEnv, $subEnv->getDataProvider()->getEmptyModel());
     $optEv->setPropertyName($attribute->getColName());
     $subEnv->getEventDispatcher()->dispatch(GetPropertyOptionsEvent::NAME, $optEv);
     $options = $optEv->getOptions();
     return $options;
 }