1 | <?php |
||||
2 | |||||
3 | namespace Chuckbe\Chuckcms\Models; |
||||
4 | |||||
5 | use Chuckbe\Chuckcms\Chuck\PageBlockRepository; |
||||
6 | use Eloquent; |
||||
7 | |||||
8 | class PageBlock extends Eloquent |
||||
9 | { |
||||
10 | public function page() |
||||
11 | { |
||||
12 | return $this->belongsTo('Chuckbe\Chuckcms\Models\Page'); |
||||
13 | } |
||||
14 | |||||
15 | public function getAllByPageId($page_id) |
||||
16 | { |
||||
17 | $pageblocks = $this->where('page_id', $page_id)->where('lang', app()->getLocale())->orderBy('order', 'asc')->get(); |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
18 | |||||
19 | return $pageblocks; |
||||
20 | } |
||||
21 | |||||
22 | public function getRenderedById($pageblock_id, PageBlockRepository $pageBlockRepository) |
||||
23 | { |
||||
24 | $pageblock = $this->where('id', $pageblock_id)->first(); |
||||
25 | $new_pageblock = $pageBlockRepository->getRenderedByPageBlock($pageblock); |
||||
26 | |||||
27 | return $new_pageblock; |
||||
28 | } |
||||
29 | |||||
30 | public function getById($id) |
||||
31 | { |
||||
32 | return $this->find($id); |
||||
33 | } |
||||
34 | |||||
35 | public function getCountByPageId($page_id) |
||||
36 | { |
||||
37 | return $this->where('page_id', $page_id)->where('lang', app()->getLocale())->count(); |
||||
38 | } |
||||
39 | |||||
40 | public function moveUpById($id)//@todo add to pageblock repository |
||||
41 | { |
||||
42 | $pageblock = $this->find($id); |
||||
43 | $og_order = $pageblock->order; |
||||
44 | $target_pb = $this->where('page_id', $pageblock->page_id)->where('lang', $pageblock->lang)->where('order', ($og_order - 1))->first(); |
||||
45 | |||||
46 | $pageblock->order = $og_order - 1; |
||||
47 | $target_pb->order = $og_order; |
||||
48 | |||||
49 | $pageblock->update(); |
||||
50 | $target_pb->update(); |
||||
51 | |||||
52 | return $this->getRenderedById($pageblock->id); |
||||
0 ignored issues
–
show
The call to
Chuckbe\Chuckcms\Models\...lock::getRenderedById() has too few arguments starting with pageBlockRepository .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
53 | } |
||||
54 | |||||
55 | public function moveDownById($id)//@todo add to pageblock repository |
||||
56 | { |
||||
57 | $pageblock = $this->find($id); |
||||
58 | $og_order = $pageblock->order; |
||||
59 | $target_pb = $this->where('page_id', $pageblock->page_id)->where('lang', $pageblock->lang)->where('order', ($og_order + 1))->first(); |
||||
60 | |||||
61 | $pageblock->order = $og_order + 1; |
||||
62 | $target_pb->order = $og_order; |
||||
63 | |||||
64 | $pageblock->update(); |
||||
65 | $target_pb->update(); |
||||
66 | |||||
67 | return $this->getRenderedById($pageblock->id); |
||||
0 ignored issues
–
show
The call to
Chuckbe\Chuckcms\Models\...lock::getRenderedById() has too few arguments starting with pageBlockRepository .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
68 | } |
||||
69 | |||||
70 | public function moveOrderDownByPageId($id)//@todo add to pageblock repository |
||||
71 | { |
||||
72 | $pageblocks = $this->where('page_id', $id)->where('lang', app()->getLocale())->increment('order'); |
||||
0 ignored issues
–
show
|
|||||
73 | } |
||||
74 | |||||
75 | public function addBlockTop($contents, $page, $name)//@todo add to pageblock repository |
||||
76 | { |
||||
77 | $this->moveOrderDownByPageId($page->id); |
||||
78 | $pageblock = new PageBlock(); |
||||
79 | $pageblock->page_id = $page->id; |
||||
80 | $pageblock->name = $name; |
||||
81 | $pageblock->slug = $name; |
||||
82 | $pageblock->body = $contents; |
||||
83 | $pageblock->order = 1; |
||||
84 | $pageblock->lang = app()->getLocale(); |
||||
85 | $pageblock->save(); |
||||
86 | |||||
87 | return $pageblock; |
||||
88 | } |
||||
89 | |||||
90 | public function addBlockBottom($contents, $page, $name)//@todo add to pageblock repository |
||||
91 | { |
||||
92 | $pageblock = new PageBlock(); |
||||
93 | $pageblock->page_id = $page->id; |
||||
94 | $pageblock->name = $name; |
||||
95 | $pageblock->slug = $name; |
||||
96 | $pageblock->body = $contents; |
||||
97 | $pageblock->order = $this->getCountByPageId($page->id) + 1; |
||||
98 | $pageblock->lang = app()->getLocale(); |
||||
99 | $pageblock->save(); |
||||
100 | |||||
101 | return $pageblock; |
||||
102 | } |
||||
103 | } |
||||
104 |