Conditions | 4 |
Paths | 3 |
Total Lines | 43 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
30 | public function search() |
||
31 | { |
||
32 | // create model object |
||
33 | $model = new FormUserSearch(); |
||
34 | $model->setSubmitMethod('GET'); |
||
35 | |||
36 | // get app configs |
||
37 | $cfgs = $this->getConfigs(); |
||
38 | |||
39 | $records = null; |
||
40 | $pagination = null; |
||
41 | // check if request is sended |
||
42 | if ($model->send() && $model->validate()) { |
||
43 | // get records from db |
||
44 | $records = ProfileRecords::where('nick', 'like', '%' . $model->query . '%'); |
||
45 | $page = (int)$this->request->query->get('page'); |
||
46 | $userPerPage = (int)$cfgs['usersOnPage']; |
||
47 | if ($userPerPage < 1) { |
||
48 | $userPerPage = 1; |
||
49 | } |
||
50 | |||
51 | $offset = $page * $userPerPage; |
||
52 | // build pagination |
||
53 | $pagination = new SimplePagination([ |
||
54 | 'url' => ['profile/search', null, null, [$model->getFormName().'[query]' => $model->query, $model->getFormName().'[submit]' => true]], |
||
55 | 'page' => $page, |
||
56 | 'step' => $userPerPage, |
||
57 | 'total' => $records->count() |
||
58 | ]); |
||
59 | // make query finally |
||
60 | $records = $records->skip($offset) |
||
61 | ->take($userPerPage) |
||
62 | ->get(); |
||
63 | } |
||
64 | |||
65 | // display response |
||
66 | return $this->view->render('search', [ |
||
67 | 'model' => $model, |
||
68 | 'records' => $records, |
||
69 | 'pagination' => $pagination, |
||
70 | 'ratingOn' => (int)$cfgs['rating'] |
||
71 | ]); |
||
72 | } |
||
73 | } |