]> _ Git - cubist_cms-back.git/commitdiff
wip #4977 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 Dec 2021 08:14:58 +0000 (09:14 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 Dec 2021 08:14:58 +0000 (09:14 +0100)
src/app/Magic/Fields/SelectFromModel.php

index 466d7976ab9862bf0ddbbf27c19ba1b3d2c92058..2d44b72514d645b25b1a65a724f507de3872bbe5 100644 (file)
@@ -20,9 +20,27 @@ class SelectFromModel extends Model
     protected $_order = false;
     protected $_allows_null = false;
 
+
     public function getDefaultAttributes()
     {
-        return array_merge(parent::getDefaultAttributes(), ['order' => $this->_order, 'allows_null' => $this->_allows_null]);
+        $field = $this;
+
+        return array_merge(parent::getDefaultAttributes(), [
+                'order' => $this->_order,
+                'allows_null' => $this->_allows_null,
+                'searchLogic' => function ($query, $column, $searchTerm) use ($field) {
+                    $pluckAttr = $field->getAttribute('column_attribute', $field->getAttribute('attribute'));
+                    $list = $field->pluck($pluckAttr);
+                    $findIds = [];
+                    foreach ($list as $id => $value) {
+                        if (stristr($value, $searchTerm)) {
+                            $findIds[] = $id;
+                        }
+                    }
+                    $query->orWhereIn($field->getName(), $findIds);
+                },
+            ]
+        );
     }
 
     protected function _preGetDefinition()