| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SleepingOwl\Admin\Display\Column\Filter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SleepingOwl\Admin\Traits\Assets; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Database\Eloquent\Builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use KodiComponents\Support\HtmlAttributes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Contracts\Support\Arrayable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Contracts\Support\Renderable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SleepingOwl\Admin\Traits\SqlQueryOperators; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SleepingOwl\Admin\Contracts\Display\ColumnMetaInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use SleepingOwl\Admin\Contracts\Display\NamedColumnInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use SleepingOwl\Admin\Contracts\Display\Extension\ColumnFilterInterface; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | abstract class BaseColumnFilter implements Renderable, ColumnFilterInterface, Arrayable | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     use SqlQueryOperators, HtmlAttributes, Assets, \SleepingOwl\Admin\Traits\Renderable; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * @var \Closure|null | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     protected $callback; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * @var string|null | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     protected $columnName; | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 62 |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 62 |  |         $this->initializePackage(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 | 62 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * Initialize column filter. | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 3 |  |     public function initialize() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 3 |  |         $this->includePackage(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 | 3 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * @return null|string | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 40 |  |     public function getColumnName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 40 |  |         return $this->columnName; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @param null|string $name | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @return $this | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function setColumnName($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->columnName = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         return $this; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      * @param mixed $value | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * @return mixed | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 40 |  |     public function parseValue($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 40 |  |         return $value; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |      * @deprecated | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      * @return \Closure|null | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 40 |  |     public function getCallback() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 40 |  |         return $this->callback; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |      * @param \Closure $callback | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |      * @deprecated | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |      * @return $this | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public function setCallback(\Closure $callback) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $this->callback = $callback; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         return $this; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * @param NamedColumnInterface $column | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      * @param Builder $query | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |      * @param string $queryString | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      * @param array|string $queryParams | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 40 |  |     public function apply(NamedColumnInterface $column, Builder $query, $queryString, $queryParams) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 40 |  |         $queryString = $this->parseValue($queryString); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 40 |  |         if (($metaInstance = $column->getMetaData()) instanceof ColumnMetaInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             if (method_exists($metaInstance, 'onFilterSearch')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 $metaInstance->onFilterSearch($column, $query, $queryString, $queryParams); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 40 |  |         if (is_callable($callback = $column->getFilterCallback())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             $callback($column, $query, $queryString, $queryParams); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 40 |  |         if (is_callable($callback = $this->getCallback())) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             $callback($column, $query, $queryString, $queryParams); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 40 |  |         if (empty($queryString)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 40 |  |         if (is_null($name = $this->getColumnName())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 40 |  |             $name = $column->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 40 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 40 |  |         if (strpos($name, '.') !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 20 |  |             $parts = explode('.', $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 20 |  |             $fieldName = array_pop($parts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 20 |  |             $relationName = implode('.', $parts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 | 20 |  |             $query->whereHas($relationName, function ($q) use ($queryString, $fieldName) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 20 |  |                 $this->buildQuery($q, $fieldName, $queryString); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 20 |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 20 |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 | 20 |  |             $this->buildQuery($query, $name, $queryString); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 144 | 40 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |      * Get the instance as an array. | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     public function toArray() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             'attributes'      => $this->htmlAttributesToString(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             'attributesArray' => $this->getHtmlAttributes(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 157 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 158 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 159 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.