1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Front\Content; |
4
|
|
|
|
5
|
|
|
use Apps\Model\Front\Content\EntityCategoryList; |
6
|
|
|
use Ffcms\Core\App; |
7
|
|
|
use Ffcms\Core\Arch\View; |
8
|
|
|
use Ffcms\Core\Helper\HTML\SimplePagination; |
9
|
|
|
use Ffcms\Core\Helper\Type\Arr; |
10
|
|
|
use Ffcms\Core\Network\Request; |
11
|
|
|
use Ffcms\Core\Network\Response; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Trait ActionList |
15
|
|
|
* @package Apps\Controller\Front\Content |
16
|
|
|
* @property View $view |
17
|
|
|
* @property Request $request |
18
|
|
|
* @property Response $response |
19
|
|
|
* @method array getConfigs |
20
|
|
|
*/ |
21
|
|
|
trait ActionList |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* List category content |
25
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
public function listing() |
29
|
|
|
{ |
30
|
|
|
$path = $this->request->getPathWithoutControllerAction(); |
31
|
|
|
$configs = $this->getConfigs(); |
|
|
|
|
32
|
|
|
$page = (int)$this->request->query->get('page', 0); |
33
|
|
|
$sort = (string)$this->request->query->get('sort', 'newest'); |
34
|
|
|
$itemCount = (int)$configs['itemPerCategory']; |
35
|
|
|
|
36
|
|
|
// build special model with content list and category list information |
37
|
|
|
$model = new EntityCategoryList($path, $configs, $page, $sort); |
38
|
|
|
|
39
|
|
|
// prepare query string (?a=b) for pagination if sort is defined |
40
|
|
|
$sortQuery = null; |
41
|
|
|
if (Arr::in($sort, ['rating', 'views'])) { |
42
|
|
|
$sortQuery = ['sort' => $sort]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// build pagination |
46
|
|
|
$pagination = new SimplePagination([ |
47
|
|
|
'url' => ['content/list', $path, null, $sortQuery], |
48
|
|
|
'page' => $page, |
49
|
|
|
'step' => $itemCount, |
50
|
|
|
'total' => $model->getContentCount() |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
// define list event |
54
|
|
|
App::$Event->run(static::EVENT_CONTENT_LIST, [ |
55
|
|
|
'model' => $model |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
// draw response view |
59
|
|
|
return $this->view->render('list', [ |
60
|
|
|
'model' => $model, |
61
|
|
|
'pagination' => $pagination, |
62
|
|
|
'configs' => $configs, |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.