/**
  * 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 == ?';
     }
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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>';
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function buildJumpToUrlFor(IItem $item)
 {
     $information = $this->determineJumpToInformation();
     if (empty($information['pageDetails'])) {
         return array();
     }
     $result = $information;
     $parameters = '';
     $parameterList = array();
     if (!empty($information['filterSetting'])) {
         /** @var \MetaModels\Filter\Setting\ICollection $filterSetting */
         $filterSetting = $information['filterSetting'];
         $parameterList = $filterSetting->generateFilterUrlFrom($item, $this);
         foreach ($parameterList as $strKey => $strValue) {
             if ($strKey == 'auto_item') {
                 $parameters = '/' . $strValue . $parameters;
             } else {
                 $parameters .= sprintf('/%s/%s', $strKey, $strValue);
             }
         }
     }
     $result['params'] = $parameterList;
     $result['deep'] = strlen($parameters) > 0;
     $event = new GenerateFrontendUrlEvent($information['pageDetails'], $parameters, $information['language']);
     $this->metaModel->getServiceContainer()->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $event);
     $result['url'] = $event->getUrl();
     return $result;
 }
Exemplo n.º 6
0
 /**
  * Mock an attribute.
  *
  * @param IMetaModel $metaModel The metamodel.
  *
  * @param array      $values    The test values.
  *
  * @return \MetaModels\Attribute\ISimple
  */
 protected function mockAttribute($metaModel, $values = array())
 {
     $attributeData = array('id' => 1, 'colname' => 'testAttribute', 'name' => 'Test Attribute');
     $attribute = $this->getMock('\\MetaModels\\Attribute\\BaseSimple', array('filterGreaterThan', 'filterLessThan', 'get'), array($metaModel, $attributeData));
     $attribute->expects($this->any())->method('getColName')->will($this->returnValue($attributeData['colname']));
     $attribute->expects($this->any())->method('filterGreaterThan')->will($this->returnCallback(function ($testValue, $inclusive = false) use($values) {
         $ids = array();
         foreach ($values as $itemId => $value) {
             if ($inclusive) {
                 if ($value >= $testValue) {
                     $ids[] = $itemId;
                 }
             } elseif ($value > $testValue) {
                 $ids[] = $itemId;
             }
         }
         return $ids;
     }));
     $attribute->expects($this->any())->method('filterLessThan')->will($this->returnCallback(function ($testValue, $inclusive = false) use($values) {
         $ids = array();
         foreach ($values as $itemId => $value) {
             if ($inclusive) {
                 if ($value <= $testValue) {
                     $ids[] = $itemId;
                 }
             } elseif ($value < $testValue) {
                 $ids[] = $itemId;
             }
         }
         return $ids;
     }));
     /** @var \MetaModels\Attribute\ISimple $attribute */
     $metaModel->addAttribute($attribute);
     return $attribute;
 }
 /**
  * {@inheritdoc}
  */
 public function prepare(MetaModel $metaModel, Items $items, DefinitionMapper $mapper, Filter $filter = null, $deferred = false)
 {
     if ($deferred != $this->model->deferred) {
         return;
     }
     $values = array();
     $this->loadFallbackIcon($mapper);
     if ($this->model->iconAttribute) {
         $attribute = $metaModel->getAttributeById($this->model->iconAttribute);
         if (!$attribute) {
             return;
         }
         /** @var Item $item */
         foreach ($items as $item) {
             $value = $item->get($attribute->getColName());
             if ($value) {
                 $values[$item->get('id')] = is_array($value) ? $value['id'] : $value;
             }
         }
         $this->preLoadIcons($values, $mapper);
     }
 }
 /**
  * @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);
 }
Exemplo n.º 9
0
 /**
  * Generate the form.
  *
  * @return array
  */
 private function generateForm()
 {
     $fields = array();
     // Loop over all attributes now.
     foreach ($this->metaModel->getAttributes() as $attribute) {
         $attrId = $attribute->get('id');
         if (!$this->accepts($attribute)) {
             continue;
         }
         if ($this->knowsAttribute($attribute)) {
             if ($this->input->hasValue('attribute_' . $attrId)) {
                 $fields[] = array('checkbox' => false, 'text' => $this->translator->translate('addAll_addsuccess', static::$table, array($attribute->getName())), 'class' => 'tl_confirm', 'attr_id' => $attrId);
                 continue;
             }
             $fields[] = array('checkbox' => false, 'text' => $this->translator->translate('addAll_alreadycontained', static::$table, array($attribute->getName())), 'class' => 'tl_info', 'attr_id' => $attrId);
             continue;
         }
         $fields[] = array('checkbox' => true, 'text' => $this->translator->translate('addAll_willadd', static::$table, array($attribute->getName())), 'class' => 'tl_new', 'attr_id' => $attrId);
         $this->template->hasCheckbox = true;
     }
     return $fields;
 }
Exemplo n.º 10
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();
     }
 }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
0
 /**
  * Get all MetaModel items.
  *
  * @param MetaModel  $metaModel The MetaModel.
  * @param LayerModel $model     The layer model.
  * @param Filter     $filter    Optional request filter.
  *
  * @return Items
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 private function getItems(MetaModel $metaModel, LayerModel $model, Filter $filter = null)
 {
     $metaModelFilter = $metaModel->getEmptyFilter();
     $filterSetting = FilterSettingFactory::byId($model->metamodel_filtering);
     $filterSetting->addRules($metaModelFilter, array_merge(deserialize($model->metamodel_filteraprams, true), $this->getFilterParameters($filterSetting)));
     return $metaModel->findByFilter($metaModelFilter, $model->metamodel_sortby, 0, $model->metamodel_use_limit ? $model->metamodel_limit ?: 0 : 0, $model->metamodel_sortby_direction);
 }
Exemplo n.º 13
0
 /**
  * Prepare the rendering.
  *
  * @return ItemList
  */
 public function prepare()
 {
     if ($this->objItems) {
         return $this;
     }
     // Create an empty filter object if not done before.
     if (!$this->objFilter) {
         $this->objFilter = $this->objMetaModel->getEmptyFilter();
     }
     if ($this->objFilterSettings) {
         $this->objFilterSettings->addRules($this->objFilter, $this->arrParam);
     }
     $this->modifyFilter();
     $intTotal = $this->objMetaModel->getCount($this->objFilter);
     $calculator = $this->paginationLimitCalculator;
     $calculator->setTotalAmount($intTotal);
     $curPage = (int) \Input::get('page');
     if ($curPage > 1) {
         $calculator->setCurrentPage($curPage);
     }
     $this->objTemplate->total = $intTotal;
     $this->objItems = $this->objMetaModel->findByFilter($this->objFilter, $this->strSortBy, $calculator->getCalculatedOffset(), $calculator->getCalculatedLimit(), $this->strSortDirection, $this->getAttributeNames());
     return $this;
 }
Exemplo n.º 14
0
 /**
  * Perform the action.
  *
  * @param IMetaModel $metaModel       The MetaModel.
  *
  * @param array      $knownAttributes The list of known attributes.
  *
  * @param int        $startSort       The first sort index.
  *
  * @param int        $pid             The pid.
  *
  * @param array      $messages        The messages array.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function perform(IMetaModel $metaModel, $knownAttributes, $startSort, $pid, &$messages)
 {
     $database = $this->getDatabase();
     // Loop over all attributes now.
     foreach ($metaModel->getAttributes() as $attribute) {
         if (!array_key_exists($attribute->get('id'), $knownAttributes)) {
             $arrData = array('pid' => $pid, 'sorting' => $startSort, 'tstamp' => time(), 'dcatype' => 'attribute', 'attr_id' => $attribute->get('id'), 'tl_class' => '');
             $startSort += 128;
             $database->prepare('INSERT INTO tl_metamodel_dcasetting %s')->set($arrData)->execute();
             $messages[] = array('severity' => 'confirm', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addAll_addsuccess'], $attribute->getName()));
         }
     }
 }
Exemplo n.º 15
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'];
 }
Exemplo n.º 17
0
 /**
  * Get the list of jumpTos based on the items.
  *
  * @param array                                  $availableLanguages List of languages to be used.
  *
  * @param IMetaModel                             $metaModels         The MetaModels to be used.
  *
  * @param IFilter                                $filter             The filter to be used.
  *
  * @param \MetaModels\Render\Setting\ICollection $view               The view to be used.
  *
  * @param string|null                            $rootPage           The root page id or null if there is no root
  *                                                                   page.
  *
  * @return array A list of urls for the jumpTos
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function getJumpTosFor($availableLanguages, $metaModels, $filter, $view, $rootPage = null)
 {
     $entries = array();
     foreach ($availableLanguages as $language) {
         // Set the language.
         $GLOBALS['TL_LANGUAGE'] = $language;
         // Get the object.
         $items = $metaModels->findByFilter($filter);
         /** @var Item $item */
         foreach ($items as $item) {
             $jumpTo = $item->buildJumpToLink($view);
             $event = new GetPageDetailsEvent($jumpTo['page']);
             $this->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_GET_PAGE_DETAILS, $event);
             $pageDetails = $event->getPageDetails();
             // If there is a root page check the context.
             if ($rootPage !== null && $pageDetails['rootId'] != $rootPage) {
                 continue;
             }
             // Build the url.
             $url = $this->getBaseUrl($pageDetails, $jumpTo['url']);
             $entries[] = $url->getUrl();
         }
     }
     return $entries;
 }
 /**
  * Prepare used values.
  *
  * @param MetaModel $metaModel The meta model.
  * @param Items     $items     The meta model items list.
  * @param Attribute $reference The reference attribute.
  * @param array     $values    The reference values.
  * @param array     $icons     The used icons.
  * @param array     $styles    The used styles.
  *
  * @return void
  */
 protected function prepareValues(MetaModel $metaModel, Items $items, Attribute $reference, &$values, &$icons, &$styles)
 {
     $icon = $metaModel->getAttributeById($this->model->iconAttribute);
     $style = $metaModel->getAttributeById($this->model->styleAttribute);
     foreach ($items as $item) {
         $value = $item->get($reference->getColName());
         $itemId = $item->get('id');
         if ($value) {
             $values[$itemId] = $this->getAttributeValue($value);
         }
         if ($icon) {
             $value = $item->get($icon->getColName());
             if ($value) {
                 $icons[$itemId] = $this->getAttributeValue($value);
             }
         }
         if ($style) {
             $value = $item->get($style->getColName());
             if ($value) {
                 $styles[$itemId] = $this->getAttributeValue($value);
             }
         }
     }
 }
Exemplo n.º 19
0
 /**
  * Translate a property.
  *
  * @param array      $property  The property information to transform.
  *
  * @param IMetaModel $metaModel The MetaModel the property belongs to.
  *
  * @param string     $legend    The legend the property belongs to.
  *
  * @return bool
  */
 protected function translateProperty($property, $metaModel, $legend)
 {
     $attribute = $metaModel->getAttributeById($property['attr_id']);
     // Dead meat.
     if (!$attribute) {
         return false;
     }
     $propName = $attribute->getColName();
     $this->legends[$legend]['properties'][] = $propName;
     $this->properties[$propName] = array('info' => $attribute->getFieldDefinition($property));
     return true;
 }
Exemplo n.º 20
0
 /**
  * Create a widget for naming contexts. Use the language and translation information from the MetaModel.
  *
  * @param EnvironmentInterface $environment   The environment.
  *
  * @param PropertyInterface    $property      The property.
  *
  * @param IMetaModel           $metaModel     The MetaModel.
  *
  * @param string               $languageLabel The label to use for the language indicator.
  *
  * @param string               $valueLabel    The label to use for the input field.
  *
  * @param bool                 $isTextArea    If true, the widget will become a textarea, false otherwise.
  *
  * @param array                $arrValues     The values for the widget, needed to highlight the fallback language.
  *
  * @return void
  */
 public static function prepareLanguageAwareWidget(EnvironmentInterface $environment, PropertyInterface $property, IMetaModel $metaModel, $languageLabel, $valueLabel, $isTextArea, $arrValues)
 {
     if (!$metaModel->isTranslated()) {
         $extra = $property->getExtra();
         $extra['tl_class'] .= 'w50';
         $property->setWidgetType('text')->setExtra($extra);
         return;
     }
     $fallback = $metaModel->getFallbackLanguage();
     $languages = self::buildLanguageArray($metaModel, $environment->getTranslator());
     $neededKeys = array_keys($languages);
     // Ensure we have values for all languages present.
     if (array_diff_key(array_keys($arrValues), $neededKeys)) {
         foreach ($neededKeys as $langCode) {
             $arrValues[$langCode] = '';
         }
     }
     $rowClasses = array();
     foreach (array_keys($arrValues) as $langCode) {
         $rowClasses[] = $langCode == $fallback ? 'fallback_language' : 'normal_language';
     }
     $extra = $property->getExtra();
     $extra['minCount'] = $extra['maxCount'] = count($languages);
     $extra['disableSorting'] = true;
     $extra['tl_class'] = 'clr';
     $extra['columnFields'] = array('langcode' => array('label' => $languageLabel, 'exclude' => true, 'inputType' => 'justtextoption', 'options' => $languages, 'eval' => array('rowClasses' => $rowClasses, 'valign' => 'center', 'style' => 'min-width:75px;display:block;')), 'value' => array('label' => $valueLabel, 'exclude' => true, 'inputType' => $isTextArea ? 'textarea' : 'text', 'eval' => array('rowClasses' => $rowClasses, 'style' => 'width:400px;', 'rows' => 3)));
     $property->setWidgetType('multiColumnWizard')->setExtra($extra);
 }
Exemplo n.º 21
0
 /**
  * Perform the action.
  *
  * @param IMetaModel $metaModel       The MetaModel.
  *
  * @param array      $knownAttributes The list of known attributes.
  *
  * @param int        $startSort       The first sort index.
  *
  * @param int        $pid             The pid.
  *
  * @param array      $messages        The output messages.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function perform(IMetaModel $metaModel, $knownAttributes, $startSort, $pid, &$messages)
 {
     $database = $this->getDatabase();
     // Loop over all attributes now.
     foreach ($metaModel->getAttributes() as $attribute) {
         if (!array_key_exists($attribute->get('id'), $knownAttributes)) {
             $arrData = array();
             $objRenderSetting = $attribute->getDefaultRenderSettings();
             foreach ($objRenderSetting->getKeys() as $key) {
                 $arrData[$key] = $objRenderSetting->get($key);
             }
             $arrData = array_replace_recursive($arrData, array('pid' => $pid, 'sorting' => $startSort, 'tstamp' => time(), 'attr_id' => $attribute->get('id')));
             $startSort += 128;
             $database->prepare('INSERT INTO tl_metamodel_rendersetting %s')->set($arrData)->execute();
             $messages[] = array('severity' => 'confirm', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['addAll_addsuccess'], $attribute->getName()));
         }
     }
 }
Exemplo n.º 22
0
 /**
  * Check if the item is published.
  *
  * @param IMetaModel $objMetaModel Current metamodels.
  * @param int        $intItemId    Id of the item.
  *
  * @return boolean True => Published | False => Not published
  */
 protected function isPublishedItem($objMetaModel, $intItemId)
 {
     // Check publish state of an item.
     $objAttrCheckPublish = $this->getServiceContainer()->getDatabase()->prepare('SELECT colname FROM tl_metamodel_attribute WHERE pid=? AND check_publish=1')->limit(1)->execute($objMetaModel->get('id'));
     if ($objAttrCheckPublish->numRows > 0) {
         $objItem = $objMetaModel->findById($intItemId);
         if (!$objItem->get($objAttrCheckPublish->colname)) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 23
0
 /**
  * Destroy the filter settings for a MetaModel.
  *
  * @param IMetaModel $metaModel The MetaModel to destroy.
  *
  * @return void
  */
 protected function destroyFilterSettings(IMetaModel $metaModel)
 {
     $database = $this->getDatabase();
     // Delete everything from filter settings.
     $arrIds = $database->prepare('SELECT id FROM tl_metamodel_filter WHERE pid=?')->execute($metaModel->get('id'))->fetchEach('id');
     if ($arrIds) {
         $database->prepare(sprintf('DELETE FROM tl_metamodel_filtersetting WHERE pid IN (%s)', implode(',', $arrIds)))->execute();
     }
     $database->prepare('DELETE FROM tl_metamodel_filter WHERE pid=?')->execute($metaModel->get('id'));
 }
Exemplo n.º 24
0
 /**
  * Get available langauges.
  *
  * @param IMetaModel $objMetaModel The metamodel.
  *
  * @return array|null|\string[]
  */
 private function getAvailableLanguages(IMetaModel $objMetaModel)
 {
     return $objMetaModel->isTranslated() && $this->get('all_langs') ? $objMetaModel->getAvailableLanguages() : array($objMetaModel->getActiveLanguage());
 }