|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
4
|
|
|
|
|
5
|
|
|
class NewsController extends CRUDController |
|
6
|
|
|
{ |
|
7
|
|
|
public function showAction(Player $me, News $article) |
|
8
|
|
|
{ |
|
9
|
|
|
if ($article->isDraft() && (!$me->isValid() || !$me->hasPermission(News::EDIT_PERMISSION))) { |
|
10
|
|
|
throw new ForbiddenException('You do not have permission to view draft posts.'); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
return [ |
|
14
|
|
|
'article' => $article, |
|
15
|
|
|
'categories' => $this->getCategories(), |
|
16
|
|
|
]; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function listAction(Request $request, Player $me, NewsCategory $category = null) |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
$currentPage = $this->getCurrentPage(); |
|
22
|
|
|
$qb = $this->getQueryBuilder(); |
|
23
|
|
|
|
|
24
|
|
|
$news = $qb |
|
|
|
|
|
|
25
|
|
|
->orderBy('created', 'DESC') |
|
26
|
|
|
->limit(5) |
|
27
|
|
|
->fromPage($currentPage) |
|
28
|
|
|
; |
|
29
|
|
|
|
|
30
|
|
|
if ($category !== null) { |
|
31
|
|
|
$news->where('category', '=', $category->getId()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (!$me->isValid() || !$me->hasPermission(News::CREATE_PERMISSION)) { |
|
35
|
|
|
$news->whereNot('is_draft', '=', true); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return [ |
|
39
|
|
|
'news' => $news->getModels(true), |
|
40
|
|
|
'categories' => $this->getCategories(), |
|
41
|
|
|
'category' => $category, |
|
42
|
|
|
'currentPage' => $currentPage, |
|
43
|
|
|
'totalPages' => $qb->countPages(), |
|
44
|
|
|
]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function createAction(Player $me) |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->create($me); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function editAction(Player $me, News $article) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->edit($article, $me, "article"); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function deleteAction(Player $me, News $article) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->delete($article, $me); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
private function getCategories() |
|
63
|
|
|
{ |
|
64
|
|
|
return NewsCategory::getQueryBuilder() |
|
65
|
|
|
->orderBy('name') |
|
66
|
|
|
->getModels(true) |
|
67
|
|
|
; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.