1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Front\Profile; |
4
|
|
|
|
5
|
|
|
use Apps\Model\Front\Profile\FormUserSearch; |
6
|
|
|
use Extend\Core\Arch\FrontAppController; |
7
|
|
|
use Ffcms\Core\App; |
8
|
|
|
use Ffcms\Core\Arch\View; |
9
|
|
|
use Apps\ActiveRecord\Profile as ProfileRecords; |
10
|
|
|
use Ffcms\Core\Helper\HTML\SimplePagination; |
11
|
|
|
use Ffcms\Core\Network\Response; |
12
|
|
|
use Ffcms\Core\Network\Request; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Trait ActionSearch |
17
|
|
|
* @package Apps\Controller\Front\Profile |
18
|
|
|
* @property View $view |
19
|
|
|
* @property Request $request |
20
|
|
|
* @property Response $response |
21
|
|
|
* @method array getConfigs() |
22
|
|
|
*/ |
23
|
|
|
trait ActionSearch |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Search users |
27
|
|
|
* @return string |
28
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
29
|
|
|
*/ |
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
|
|
|
} |