MetaModels\Attribute\IAttribute::getFilterOptions PHP Method

getFilterOptions() public method

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.
return array All options matching the given conditions as name => value.
    public function getFilterOptions($idList, $usedOnly, &$arrCount = null);

Usage Example

 /**
  * 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;
     }
 }
All Usage Examples Of MetaModels\Attribute\IAttribute::getFilterOptions