| Total Complexity | 7 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class Dictionary extends Model |
||
| 16 | { |
||
| 17 | public $type = null; |
||
| 18 | public $name = null; |
||
| 19 | |||
| 20 | public function rules() |
||
| 21 | { |
||
| 22 | return [ |
||
| 23 | [['type', 'name'], 'safe'], |
||
| 24 | ]; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function attributes() |
||
| 32 | ]; |
||
| 33 | } |
||
| 34 | |||
| 35 | public static function primaryKey() { |
||
| 37 | } |
||
| 38 | |||
| 39 | public function search() { |
||
| 40 | $types = SettingsSheet::getDictionaries(); |
||
| 41 | $type = explode('.', $this->type)[0]; |
||
| 42 | /** |
||
| 43 | * @var ActiveQuery $query |
||
| 44 | */ |
||
| 45 | if (isset($types[$type])) { |
||
| 46 | $query = $types[$type]; |
||
| 47 | } else { |
||
| 48 | $query = current($types); |
||
| 49 | $query->where('0=1'); |
||
| 50 | } |
||
| 51 | |||
| 52 | if ($this->name) { |
||
| 53 | $query->andWhere([ |
||
| 54 | 'ILIKE', |
||
| 55 | 'name', |
||
| 56 | $this->name |
||
| 57 | ]); |
||
| 58 | } |
||
| 59 | |||
| 60 | $dp = new ActiveDataProvider([ |
||
| 61 | 'query' => $query, |
||
| 62 | ]); |
||
| 63 | |||
| 64 | return $dp; |
||
| 65 | } |
||
| 66 | |||
| 67 | public function formName() |
||
| 70 | } |
||
| 71 | } |