Completed
Push — master ( 5c55d7...79e99a )
by Fèvre
28s queued 15s
created

Users   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRowsQueryProperty() 0 10 1
A getRowsProperty() 0 4 1
A render() 0 4 1
1
<?php
2
3
namespace Xetaravel\Http\Livewire\Admin;
4
5
use Illuminate\Contracts\Database\Query\Builder;
6
use Illuminate\Contracts\View\View;
7
use Illuminate\Pagination\LengthAwarePaginator;
8
use Livewire\Component;
9
use Livewire\WithPagination;
10
use Xetaravel\Http\Livewire\Traits\WithCachedRows;
11
use Xetaravel\Http\Livewire\Traits\WithSorting;
12
use Xetaravel\Http\Livewire\Traits\WithPerPagePagination;
13
use Xetaravel\Models\User;
14
15
class Users extends Component
16
{
17
    use WithPagination;
0 ignored issues
show
Bug introduced by
The trait Livewire\WithPagination requires the property $paginationTheme which is not provided by Xetaravel\Http\Livewire\Admin\Users.
Loading history...
18
    use WithSorting;
19
    use WithCachedRows;
20
    use WithPerPagePagination;
0 ignored issues
show
Bug introduced by
The trait Xetaravel\Http\Livewire\...s\WithPerPagePagination requires the property $paginationTheme which is not provided by Xetaravel\Http\Livewire\Admin\Users.
Loading history...
21
22
    /**
23
     * The string to search.
24
     *
25
     * @var string
26
     */
27
    public string $search = '';
28
29
    /**
30
     * Used to update in URL the query string.
31
     *
32
     * @var string[]
33
     */
34
    protected $queryString = [
35
        'sortField' => ['as' => 'f'],
36
        'sortDirection' => ['as' => 'd'],
37
        'search' => ['except' => '', 'as' => 's']
38
    ];
39
40
    /**
41
     * Used to show the delete modal.
42
     *
43
     * @var bool
44
     */
45
    public bool $showDeleteModal = false;
46
47
    /**
48
     * Number of rows displayed on a page.
49
     * @var int
50
     */
51
    public int $perPage = 15;
52
53
    /**
54
     * Function to render the component.
55
     *
56
     * @return View
57
     */
58
    public function render()
59
    {
60
        return view('livewire.admin.users', [
61
            'users' => $this->rows
0 ignored issues
show
Bug Best Practice introduced by
The property rows does not exist on Xetaravel\Http\Livewire\Admin\Users. Since you implemented __get, consider adding a @property annotation.
Loading history...
62
        ]);
63
    }
64
65
    /**
66
     * Create and return the query for the items.
67
     *
68
     * @return Builder
69
     */
70
    public function getRowsQueryProperty(): Builder
71
    {
72
        $search = $this->search;
73
        $query = User::query()
74
            ->where('username', 'LIKE', '%' . $search . '%')
75
            ->orWhere('email', 'LIKE', '%' . $search . '%')
76
            ->orWhere('register_ip', 'LIKE', '%' . $search . '%')
77
            ->orWhere('last_login_ip', 'LIKE', '%' . $search . '%');
78
79
        return $this->applySorting($query);
80
    }
81
82
    /**
83
     * Build the query or get it from the cache and paginate it.
84
     *
85
     * @return LengthAwarePaginator
86
     */
87
    public function getRowsProperty(): LengthAwarePaginator
88
    {
89
        return $this->cache(function () {
90
            return $this->applyPagination($this->rowsQuery);
0 ignored issues
show
Bug Best Practice introduced by
The property rowsQuery does not exist on Xetaravel\Http\Livewire\Admin\Users. Since you implemented __get, consider adding a @property annotation.
Loading history...
91
        });
92
    }
93
}
94