%PDF- %PDF-
Direktori : /www/loslex/production/app/Livewire/ |
Current File : /www/loslex/production/app/Livewire/UserList.php |
<?php namespace App\Livewire; use App\Models\User; use Livewire\Component; use Livewire\Attributes\On; use Livewire\WithPagination; use Livewire\WithoutUrlPagination; use Illuminate\Support\Facades\Log; use Illuminate\Contracts\Database\Query\Builder; class UserList extends Component { use WithPagination, WithoutUrlPagination; public bool $ufReferees = false; public bool $ufDeleted = false; public bool $ufEmailValidation = false; public bool $ufGuidAlias = false; public bool $ufLexHash = false; public bool $ufOrganizer = false; public bool $ufBanned = false; public $ufSearch; public function clearFilter() { $this->reset(); $this->resetPage(); } #[On('user-updated')] public function render() { $this->authorize('viewAny', User::class); $users = User::with(['organizer_groups', 'registrations']) ->orderBy('lastname') ->orderBy('firstname') ->orderBy('namesuffix') ->when($this->ufSearch, function (Builder $query, string $str) { $qArr = explode(' ', trim($str, ' ')); foreach ($qArr as $qry) { $query->whereAny(['firstname', 'lastname', 'namesuffix', 'username','email', 'licence_number'], 'LIKE', "%{$qry}%"); } }) ->when($this->ufEmailValidation, function (Builder $query) { $query->whereNull('email_verified_at'); }) ->when($this->ufGuidAlias, function (Builder $query) { $query->where('username', 'RLIKE', '^[A-Fa-f\d]{8}(-[A-Fa-f\d]{4}){3}-[A-Fa-f\d]{12}$'); }) ->when($this->ufLexHash, function (Builder $query) { $query->whereNotNull('lex_hash'); }) ->when($this->ufOrganizer, function (Builder $query) { $query->has('organizer_groups'); }) ->when($this->ufDeleted, function (Builder $query) { $query->onlyTrashed(); }) ->when($this->ufBanned, function (Builder $query) { $query->where('is_active', '0')->withTrashed(); }) ->paginate(18); return view('livewire.user-list', ['users' => $users]); } public function highlight($text) { if ($this->ufSearch) { $qArr = explode(' ', trim($this->ufSearch, ' ')); foreach ($qArr as $qry) { $word = $this->iast_normalize_regex($qry); $text = preg_replace("/($word)/i","<span class=\"search-highlight\">$1</span>", $text); } } return $text; } private function iast_normalize_regex($str) { $subst = [ 'a|á', 'c|č', 'd|ď', 'e|é|ě', 'i|í', 'n|ň', 'o|ó', 'r|ř', 's|š', 't|ť', 'u|ů|ú', 'y|ý', 'z|ž' ]; $subst_rex = []; foreach($subst as $variants) { $chars = explode('|', $variants); foreach($chars as $char) { $subst_rex[$char] = "({$variants})"; } } $str_chars = mb_str_split($str); $str_rex = ''; foreach($str_chars as $char) { $str_rex .= !isset($subst_rex[$char]) ? $char : $subst_rex[$char]; } return $str_rex; } }