|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Apps\Controller\Front\Content; |
|
4
|
|
|
|
|
5
|
|
|
use Ffcms\Core\App; |
|
6
|
|
|
use Ffcms\Core\Arch\View; |
|
7
|
|
|
use Ffcms\Core\Exception\ForbiddenException; |
|
8
|
|
|
use Ffcms\Core\Exception\NotFoundException; |
|
9
|
|
|
use Ffcms\Core\Helper\HTML\SimplePagination; |
|
10
|
|
|
use Ffcms\Core\Network\Request; |
|
11
|
|
|
use Ffcms\Core\Network\Response; |
|
12
|
|
|
use Apps\ActiveRecord\Content as ContentRecord; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait ActionMy |
|
16
|
|
|
* @package Apps\Controller\Front\Content |
|
17
|
|
|
* @property View $view |
|
18
|
|
|
* @property Request $request |
|
19
|
|
|
* @property Response $response |
|
20
|
|
|
* @method array getConfigs |
|
21
|
|
|
*/ |
|
22
|
|
|
trait ActionMy |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Show user added content list |
|
27
|
|
|
* @return string |
|
28
|
|
|
* @throws ForbiddenException |
|
29
|
|
|
* @throws NotFoundException |
|
30
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
|
31
|
|
|
*/ |
|
32
|
|
|
public function my() |
|
33
|
|
|
{ |
|
34
|
|
|
// check if user is auth |
|
35
|
|
|
if (!App::$User->isAuth()) { |
|
36
|
|
|
throw new ForbiddenException(__('Only authorized users can manage content')); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// check if user add enabled |
|
40
|
|
|
$configs = $this->getConfigs(); |
|
|
|
|
|
|
41
|
|
|
if (!(bool)$configs['userAdd']) { |
|
42
|
|
|
throw new NotFoundException(__('User add is disabled')); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// prepare query |
|
46
|
|
|
$page = (int)$this->request->query->get('page', 0); |
|
47
|
|
|
$offset = $page * 10; |
|
48
|
|
|
$query = ContentRecord::where('author_id', App::$User->identity()->getId()); |
|
49
|
|
|
|
|
50
|
|
|
// build pagination |
|
51
|
|
|
$pagination = new SimplePagination([ |
|
52
|
|
|
'url' => ['content/my'], |
|
53
|
|
|
'page' => $page, |
|
54
|
|
|
'step' => 10, |
|
55
|
|
|
'total' => $query->count() |
|
56
|
|
|
]); |
|
57
|
|
|
|
|
58
|
|
|
// build records object |
|
59
|
|
|
$records = $query->skip($offset)->take(10)->orderBy('id', 'DESC')->get(); |
|
60
|
|
|
|
|
61
|
|
|
// render output view |
|
62
|
|
|
return $this->view->render('my', [ |
|
63
|
|
|
'records' => $records, |
|
64
|
|
|
'pagination' => $pagination |
|
65
|
|
|
]); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
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
Idableprovides a methodequalsIdthat 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.