<?php
 namespace ModStart\Admin\Repository; use Illuminate\Support\Collection; use ModStart\Grid\Model; use ModStart\Module\ModuleManager; use ModStart\Module\ModuleStatus; use ModStart\Repository\Repository; use ModStart\Repository\RepositoryUtil; class ModuleRepository extends Repository { protected $keyName = 'name'; public function get(Model $model) { $query = []; foreach ($model->filter()->getConditions() as $condition) { if (!empty($condition['where'][2])) { $query[$condition['where'][0]] = $condition['where'][2]; } } $items = RepositoryUtil::itemsFromArray(ModuleManager::listLocalModules()); return $items->filter(function ($item) use ($query) { if (empty($query)) { return true; } foreach ($query as $k => $v) { switch ($k) { case 'type': if ($item->type != $v) { return false; } break; case 'status': switch ($v) { case ModuleStatus::INSTALLED: return ModuleManager::isModuleInstalled($item->name); case ModuleStatus::NOT_INSTALLED: return !ModuleManager::isModuleInstalled($item->name); } break; case 'keywords': $v = strtolower(trim($v, '%')); if (!str_contains(strtolower($item->name), $v) && !str_contains(strtolower($item->title), $v)) { return false; } break; } } return true; }); } }