Retrieve values for use in filter options, that will be understood by DC_ filter
panels and frontend filter select boxes.
One can influence the amount of returned entries with the two parameters.
For the id list, the value "null" represents (as everywhere in MetaModels) all entries.
An empty array will return no entries at all.
The parameter "used only" determines, if only really attached values shall be returned.
This is only relevant, when using "null" as id list for attributes that have pre configured
values like select lists and tags i.e.
public getFilterOptions ( string[] | null $idList, boolean $usedOnly, array | null &$arrCount = null ) : array | ||
$idList | string[] | null | The ids of items that the values shall be fetched from (If empty or null, all items). |
$usedOnly | boolean | Determines if only "used" values shall be returned. |
$arrCount | array | null | Array for the counted values. |
리턴 | array | All options matching the given conditions as name => value. |
/** * Instantiate the field an set all values * * @param array $data * @param MetaModel $objMM */ public function __construct(array $data, MetaModel $objMM) { $this->mmAttribute = $objMM->getAttributeById($data['attr_id']); $this->colName = $this->mmAttribute->get('colname'); $dcaArray = $this->mmAttribute->getFieldDefinition($data); $this->eval = $dcaArray['eval']; unset($dcaArray['eval']); $this->data = $dcaArray; if ($data['tl_class']) { $this->addEval('class', $data['tl_class']); } /** * Check for inputType and convert if necessary */ switch ($this->get('inputType')) { case 'fileTree': $this->set('inputType', 'upload'); $this->fieldType = 'upload'; break; } if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Url\\Url')) { $this->set('inputType', 'beUrl'); $this->fieldType = 'complex'; } if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\IComplex')) { $this->fieldType = 'complex'; } /** * Check for RTE support on longtext fields */ if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Longtext\\Longtext')) { if (isset($data['rte']) && !empty($data['rte'])) { $this->rte = $data['rte']; $class = $this->getEval('class') . ' ' . $data['rte']; if (!$this->modifyEval('class', $class)) { $this->addEval('class', $class); } } } /** * Get option values from select attributes */ if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Select\\AbstractSelect')) { $this->set('options', $this->mmAttribute->getFilterOptions(null, false)); } /** * Add Save Handler */ switch ($this->fieldType) { case 'upload': $this->setSaveHandler(new UploadSaveHandler($this)); break; default: $this->setSaveHandler(new SaveHandler($this)); break; } }
/** * 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; }
/** * 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; }