/** * Add the parent filtering to the given data config if any defined. * * @param ConfigInterface $config The data config. * * @return void */ protected function addParentFilter($config) { $environment = $this->getEnvironment(); $definition = $environment->getDataDefinition(); $basicDefinition = $definition->getBasicDefinition(); $relationships = $definition->getModelRelationshipDefinition(); if (!$basicDefinition->getParentDataProvider()) { return; } // Apply parent filtering, do this only for root elements. if ($objParentCondition = $relationships->getChildCondition($basicDefinition->getParentDataProvider(), $basicDefinition->getRootDataProvider())) { $arrBaseFilter = $config->getFilter(); $arrFilter = $objParentCondition->getFilter($this->loadParentModel()); if ($arrBaseFilter) { $arrFilter = array_merge($arrBaseFilter, $arrFilter); } $config->setFilter($arrFilter); } }
/** * Add the filter for the item with the given id from the parent data provider to the given config. * * @param ModelIdInterface $idParent The id of the parent item. * * @param ConfigInterface $config The config to add the filter to. * * @return ConfigInterface * * @throws DcGeneralRuntimeException When the parent item is not found. */ private function addParentFilter($idParent, $config) { $environment = $this->getEnvironment(); $definition = $environment->getDataDefinition(); $providerName = $definition->getBasicDefinition()->getDataProvider(); $parentProviderName = $idParent->getDataProviderName(); $parentProvider = $environment->getDataProvider($parentProviderName); if ($definition->getBasicDefinition()->getParentDataProvider() !== $parentProviderName) { throw new DcGeneralRuntimeException('Unexpected parent provider ' . $parentProviderName . ' (expected ' . $definition->getBasicDefinition()->getParentDataProvider() . ')'); } if ($parentProvider) { $objParent = $parentProvider->fetch($parentProvider->getEmptyConfig()->setId($idParent->getId())); if (!$objParent) { throw new DcGeneralRuntimeException('Parent item ' . $idParent->getSerialized() . ' not found in ' . $parentProviderName); } $condition = $definition->getModelRelationshipDefinition()->getChildCondition($parentProviderName, $providerName); if ($condition) { $arrBaseFilter = $config->getFilter(); $arrFilter = $condition->getFilter($objParent); if ($arrBaseFilter) { $arrFilter = array_merge($arrBaseFilter, $arrFilter); } $config->setFilter(array(array('operation' => 'AND', 'children' => $arrFilter))); } } return $config; }
/** * Add the parent filtering to the given data config if any defined. * * @param ConfigInterface $config The data config. * * @param ModelInterface $parentModel The parent model. * * @return void * * @throws \RuntimeException When the parent provider does not match. */ private function addParentFilter(ConfigInterface $config, ModelInterface $parentModel) { $environment = $this->getEnvironment(); $definition = $environment->getDataDefinition(); $basicDefinition = $definition->getBasicDefinition(); $relationships = $definition->getModelRelationshipDefinition(); if ($basicDefinition->getParentDataProvider() !== $parentModel->getProviderName()) { throw new \RuntimeException(sprintf('Parent provider mismatch: %s vs. %s', $basicDefinition->getParentDataProvider(), $parentModel->getProviderName())); } if (!$basicDefinition->getParentDataProvider()) { return; } // Apply parent filtering, do this only for root elements. if ($parentCondition = $relationships->getChildCondition($basicDefinition->getParentDataProvider(), $basicDefinition->getRootDataProvider())) { $baseFilter = $config->getFilter(); $filter = $parentCondition->getFilter($parentModel); if ($baseFilter) { $filter = array_merge($baseFilter, $filter); } $config->setFilter($filter); } }
/** * {@inheritDoc} */ public function initialize(ConfigInterface $objConfig, PanelElementInterface $objElement = null) { $input = $this->getInputProvider(); $value = null; $field = null; if ($this->getPanel()->getContainer()->updateValues() && $input->hasValue('tl_field')) { $field = $input->getValue('tl_field'); $value = $input->getValue('tl_value'); $this->setPersistent($field, $value); } elseif ($input->hasPersistentValue('search')) { $persistent = $this->getPersistent(); if ($persistent) { $field = $persistent['field']; $value = $persistent['value']; } } $this->setSelectedProperty($field); $this->setValue($value); if (!($this->getSelectedProperty() && $this->getValue())) { return; } $arrCurrent = $objConfig->getFilter(); if (!is_array($arrCurrent)) { $arrCurrent = array(); } $objConfig->setFilter(array_merge_recursive($arrCurrent, array(array('operation' => 'AND', 'children' => array(array('operation' => 'LIKE', 'property' => $this->getSelectedProperty(), 'value' => sprintf('*%s*', $this->getValue()))))))); }
/** * {@inheritDoc} */ public function initialize(ConfigInterface $objConfig, PanelElementInterface $objElement = null) { $this->updateValue(); if ($this->getPropertyName() && $this->getValue() && $objElement !== $this) { $arrCurrent = $objConfig->getFilter(); if (!is_array($arrCurrent)) { $arrCurrent = array(); } $objConfig->setFilter(FilterBuilder::fromArray($arrCurrent)->getFilter()->andPropertyEquals($this->getPropertyName(), $this->getValue())->getAllAsArray()); } // Finally load the filter options. if ($objElement === null) { $this->loadFilterOptions(); } }
/** * {@inheritdoc} */ public function prepare(Config $config) { $config->setFilter($this->conditions); return $this; }
/** * {@inheritDoc} */ public function initialize(ConfigInterface $objConfig, PanelElementInterface $objElement = null) { $input = $this->getInputProvider(); $value = null; if ($this->getPanel()->getContainer()->updateValues() && $input->hasValue($this->getPropertyName())) { $value = $input->getValue($this->getPropertyName()); $this->setPersistent($value); } if ($input->hasPersistentValue('filter')) { $persistent = $this->getPersistent(); $value = $persistent; } if (!is_null($value)) { $this->setValue($value); } if ($this->getPropertyName() && $this->getValue() && $objElement !== $this) { $arrCurrent = $objConfig->getFilter(); if (!is_array($arrCurrent)) { $arrCurrent = array(); } $objConfig->setFilter(array_merge_recursive($arrCurrent, array(array('operation' => 'AND', 'children' => array(array('operation' => '=', 'property' => $this->getPropertyName(), 'value' => $this->getValue())))))); } // Finally load the filter options. if (is_null($objElement)) { $objTempConfig = $this->getOtherConfig(); $objTempConfig->setFields(array($this->getPropertyName())); $objFilterOptions = $this->getEnvironment()->getDataProvider()->getFilterOptions($objTempConfig); $arrOptions = array(); /** @var ModelInterface $objOption */ foreach ($objFilterOptions as $filterKey => $filterValue) { $arrOptions[(string) $filterKey] = $filterValue; } $this->arrfilterOptions = $arrOptions; } }