/** * {@inheritdoc} */ public function getMatchingIds() { if ($this->objAttribute instanceof ITranslated) { return $this->objAttribute->searchForInLanguages($this->strValue, $this->arrValidLanguages); } return $this->objAttribute->searchFor($this->strValue); }
/** * Test if the passed attribute is acceptable. * * @param IAttribute $attribute The attribute to check. * * @return bool */ protected function accepts($attribute) { if (!$attribute->get('id')) { return false; } return true; }
/** * Internal helper function for descendant classes to retrieve the options. * * @param IAttribute $objAttribute The attribute to search. * * @param string[]|null $arrIds The Id list of items for which to retrieve the options. * * @param array $arrCount If non null, the amount of matches will get returned. * * @return array */ protected function getParameterFilterOptions($objAttribute, $arrIds, &$arrCount = null, $forceToUseArrIds = false) { $arrOptions = $objAttribute->getFilterOptions($this->get('onlypossible') || $forceToUseArrIds ? $arrIds : null, (bool) $this->get('onlyused'), $arrCount); // Remove empty values. foreach ($arrOptions as $mixOptionKey => $mixOptions) { // Remove html/php tags. $mixOptions = strip_tags($mixOptions); $mixOptions = trim($mixOptions); if ($mixOptions === '' || $mixOptions === null) { unset($arrOptions[$mixOptionKey]); } } return $arrOptions; }
/** * Generate the toggle command information. * * @param CommandCollectionInterface $commands The already existing commands. * * @param IAttribute $attribute The attribute. * * @param string $commandName The name of the new command. * * @param string $class The name of the CSS class for the command. * * @param string $language The language name. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ protected function generateToggleCommand($commands, $attribute, $commandName, $class, $language) { if (!$commands->hasCommandNamed($commandName)) { $toggle = new TranslatedToggleCommand(); $toggle->setLanguage($language)->setToggleProperty($attribute->getColName())->setName($commandName)->setLabel($GLOBALS['TL_LANG']['MSC']['metamodelattribute_translatedcheckbox']['toggle'][0])->setDescription(sprintf($GLOBALS['TL_LANG']['MSC']['metamodelattribute_translatedcheckbox']['toggle'][1], $attribute->getName(), $language)); $extra = $toggle->getExtra(); $extra['icon'] = 'visible.gif'; $extra['class'] = $class; if ($commands->hasCommandNamed('show')) { $info = $commands->getCommandNamed('show'); } else { $info = null; } $commands->addCommand($toggle, $info); } }
/** * {@inheritDoc} */ public function getMatchingIds() { if ($this->mode == self::MODE_SINGLE) { return $this->runSimpleQuery('item_id', 'tl_metamodel_geolocation', 'latitude', 'longitude', array('att_id=?' => $this->singleAttribute->get('id'))); } else { return $this->runSimpleQuery('id', $this->getMetaModelTableName(), $this->latitudeAttribute->getColName(), $this->longitudeAttribute->getColName(), null); } }
/** * Run the search for the complex attribute geolocation. * * @param Container $container The container with all information. * * @param array $idList The list with the current ID's. * * @param IAttribute $latAttribute The attribute to filter on. * * @param IAttribute $longAttribute The attribute to filter on. * * @return array A list with all sorted id's. */ protected function doSearchForTwoSimpleAtt($container, $idList, $latAttribute, $longAttribute) { // Get location. $lat = $container->getLatitude(); $lng = $container->getLongitude(); $intDist = $container->getDistance(); $subSQL = sprintf('SELECT id, round ( sqrt ( power ( 2 * pi() / 360 * (%1$s - CAST(%3$s AS DECIMAL(10,6)) ) * 6371,2) + power(2 * pi() / 360 * (%2$s - CAST(%4$s AS DECIMAL(10,6))) * 6371 * COS(2 * pi() / 360 * (%1$s + CAST(%3$s AS DECIMAL(10,6))) * 0.5),2 ) ) ) AS item_dist FROM %6$s WHERE id IN(%5$s) ORDER BY item_dist', $lat, $lng, $latAttribute->getColName(), $longAttribute->getColName(), implode(', ', $idList), $this->getMetaModel()->getTableName()); $objResult = \Database::getInstance()->prepare($subSQL)->execute($intDist); $newIdList = array(); foreach ($objResult->fetchAllAssoc() as $item) { $id = $item['id']; $distance = $item['item_dist']; $newIdList[] = $id; self::$data[$id] = $distance; } $diff = array_diff($idList, $newIdList); return array_merge($newIdList, $diff); }
/** * 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); } } } }
/** * Fetch the ids for all items that hold a value that is greater than the passed value. * * If no entries have been found, the result is an empty array. * * @return string[]|null */ public function getMatchingIds() { return $this->objAttribute->filterGreaterThan($this->varValue, $this->blnInclusive); }
/** * Build parameter filter widgets. * * @param array $arrJumpTo The jumpTo page. * @param FrontendFilterOptions $objFrontendFilterOptions Frontendfilter options. * @param IAttribute $objAttribute MetaModel Attribute. * @param string $strParamName Param name. * @param array $arrOptions Options. * @param array $arrCount Count configuration. * @param array|null $arrParamValue Parameter value. * @param array $arrMyFilterUrl Filter url of the current filter. * * @return array * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ private function buildParameterFilterWidgets($arrJumpTo, FrontendFilterOptions $objFrontendFilterOptions, $objAttribute, $strParamName, $arrOptions, $arrCount, $arrParamValue, $arrMyFilterUrl) { return array($this->getParamName() => $this->prepareFrontendFilterWidget(array('label' => array($this->get('label') ? $this->get('label') : $objAttribute->getName(), 'GET: ' . $strParamName), 'inputType' => 'tags', 'options' => $arrOptions, 'count' => $arrCount, 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'eval' => array('includeBlankOption' => $this->get('blankoption') && !$objFrontendFilterOptions->isHideClearFilter(), 'blankOptionLabel' => &$GLOBALS['TL_LANG']['metamodels_frontendfilter']['do_not_filter'], 'multiple' => true, 'colname' => $objAttribute->getColname(), 'urlparam' => $strParamName, 'onlyused' => $this->get('onlyused'), 'onlypossible' => $this->get('onlypossible'), 'template' => $this->get('template')), 'urlvalue' => !empty($arrParamValue) ? implode(',', $arrParamValue) : ''), $arrMyFilterUrl, $arrJumpTo, $objFrontendFilterOptions)); }
/** * 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; }
/** * Prepare the label depending on yes no mode. * * @param IAttribute $objAttribute The metamodel attribute. * * @return array * * @SuppressWarnings(PHPMD.Superglobals) */ private function prepareLabel(IAttribute $objAttribute) { return $this->get('ynmode') == 'radio' || $this->get('ynfield') ? array($this->get('label') ?: $objAttribute->getName(), $this->get('ynmode') == 'yes' ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no']) : array($this->get('label') ?: $objAttribute->getName(), $this->get('ynmode') == 'no' ? sprintf($GLOBALS['TL_LANG']['MSC']['extended_no'], $this->get('label') ?: $objAttribute->getName()) : ($this->get('label') ?: $objAttribute->getName())); }
/** * Prepare options for the widget. * * @param array $arrIds List of ids. * @param IAttribute $objAttribute The metamodel attribute. * * @return array */ protected function prepareWidgetOptions($arrIds, $objAttribute) { $arrOptions = $objAttribute->getFilterOptions($this->get('onlypossible') ? $arrIds : null, (bool) $this->get('onlyused')); // Remove empty values from list. foreach ($arrOptions as $mixKeyOption => $mixOption) { // Remove html/php tags. $mixOption = strip_tags($mixOption); $mixOption = trim($mixOption); if ($mixOption === '' || $mixOption === null) { unset($arrOptions[$mixKeyOption]); } } return $arrOptions; }
/** * Generate the filter options for the parameters. * * @param IAttribute $objAttribute The attribute to fetch the values from. * * @param array $arrIds The id list to limit the results to. * * @param null|array $arrCount The array to use for storing the count. * * @return array */ protected function getParameterFilterOptions($objAttribute, $arrIds, &$arrCount = null) { $arrOptions = $objAttribute->getFilterOptions($this->get('onlypossible') ? $arrIds : null, (bool) $this->get('onlyused'), $arrCount); // Remove empty values. foreach ($arrOptions as $mixOptionKey => $mixOptions) { // Remove html/php tags. $mixOptions = strip_tags($mixOptions); $mixOptions = trim($mixOptions); if ($mixOptions === '' || $mixOptions === null) { unset($arrOptions[$mixOptionKey]); } } $arrNewOptions = array(); $arrNewCount = array(); // Sort the values, first char uppercase. foreach ($arrOptions as $strOptionsKey => $strOptionValue) { if ($strOptionsKey == '-') { continue; } $strFirstChar = mb_substr($strOptionValue, 0, 1); $charUpperFist = ucfirst($strFirstChar); $charLowerFirst = lcfirst($strFirstChar); $arrNewOptions[$charLowerFirst] = $charUpperFist; $arrNewCount[$charLowerFirst] = $arrNewCount[$charLowerFirst] + $arrCount[$strOptionsKey]; } $arrOptions = $arrNewOptions; $arrCount = $arrNewCount; return $arrOptions; }
/** * {@inheritdoc} */ public function addAttribute(IAttribute $objAttribute) { if (!$this->hasAttribute($objAttribute->getColName())) { $this->arrAttributes[$objAttribute->getColName()] = $objAttribute; } return $this; }
/** * Set the default value of the Attribute * * @param mixed $value */ public function setDefaultValue($value) { $value = $this->mmAttribute->valueToWidget($value); $this->set('value', $value); }
/** * Fetch the ids for all items that hold a value that is not equal to the passed value. * * If no entries have been found, the result is an empty array. * * @return string[]|null */ public function getMatchingIds() { return $this->objAttribute->filterNotEqual($this->varValue); }
/** * Helper function for {@see MetaModelItem::parseValue()} and {@see MetaModelItem::parseAttribute()}. * * @param IAttribute $objAttribute The attribute to parse. * * @param string $strOutputFormat The desired output format. * * @param ICollection|null $objSettings The settings object to be applied. * * @return array The parsed information for the given attribute. */ public function internalParseAttribute($objAttribute, $strOutputFormat, $objSettings) { $arrResult = array(); if ($objAttribute) { // Extract view settings for this attribute. if ($objSettings) { $objAttributeSettings = $objSettings->getSetting($objAttribute->getColName()); } else { $objAttributeSettings = null; } foreach ($objAttribute->parseValue($this->arrData, $strOutputFormat, $objAttributeSettings) as $strKey => $varValue) { $arrResult[$strKey] = $varValue; } } // If "hideEmptyValues" is true and the raw is empty remove text and output format. if ($objSettings instanceof ICollection && $objSettings->get('hideEmptyValues') && $this->isEmptyValue($arrResult['raw'])) { unset($arrResult[$strOutputFormat]); unset($arrResult['text']); } return $arrResult; }
/** * Fetch all options for a given model class. * * @param string $modelClass The model class. * @param IAttribute $attribute The MetaModel attribute which contains the select definitions. * * @return \Model\Collection|null */ protected function fetchOptionsCollection($modelClass, IAttribute $attribute) { if ($attribute->get('select_where')) { $collection = $modelClass::findBy(array($attribute->get('select_where')), array(), array('order' => $attribute->get('select_sorting'))); return $collection; } else { $collection = $modelClass::findAll(array('order' => $attribute->get('select_sorting'))); return $collection; } }
/** * Check if an attribute is already present. * * @param IAttribute $attribute The attribute to check. * * @return bool */ private function knowsAttribute($attribute) { return array_key_exists($attribute->get('id'), $this->knownAttributes); }
/** * Run the search for the complex attribute geolocation. * * @param Container $container The container with all information. * * @param IFilter $filter The filter container. * * @param IAttribute $latAttribute The attribute to filter on. * * @param IAttribute $longAttribute The attribute to filter on. * * @return void */ protected function doSearchForTwoSimpleAtt($container, $filter, $latAttribute, $longAttribute) { // Get location. $lat = $container->getLatitude(); $lng = $container->getLongitude(); $intDist = $container->getDistance(); $distance = sprintf('round(sqrt(' . 'power(2 * pi() / 360 * (%1$s - %3$s) * 6371,2)' . '+ power(2 * pi() / 360 * (%2$s - %4$s) * 6371 * COS( 2 * pi() / 360 * (%1$s + %3$s) * 0.5), 2)' . '))', $lat, $lng, $latAttribute->getColName(), $longAttribute->getColName()); $objResult = \Database::getInstance()->prepare(sprintf('SELECT id FROM %1$s WHERE %2$s<=? ORDER BY %2$s', $this->getMetaModel()->getTableName(), $distance))->execute($intDist); if ($objResult->numRows == 0) { $filter->addFilterRule(new StaticIdList(array())); } else { $filter->addFilterRule(new StaticIdList($objResult->fetchEach('id'))); } }