These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /*************************************************************************** |
||
3 | * for license information see LICENSE.md |
||
4 | ***************************************************************************/ |
||
5 | |||
6 | namespace Oc\Libse\CacheNote; |
||
7 | |||
8 | use Oc\Libse\Coordinate\CoordinateCoordinate; |
||
9 | use Oc\Libse\Coordinate\PresenterCoordinate; |
||
10 | use Oc\Libse\Validator\AlwaysValidValidator; |
||
11 | |||
12 | class PresenterCacheNote |
||
13 | { |
||
14 | const req_note = 'note'; |
||
15 | const req_incl_coord = 'incl_coord'; |
||
16 | const tpl_cache_id = 'cacheid'; |
||
17 | const tpl_note_id = 'noteid'; |
||
18 | const tpl_note = 'note'; |
||
19 | const tpl_incl_coord = 'inclCoord'; |
||
20 | const image = 'resource2/ocstyle/images/misc/wp_note.png'; |
||
21 | |||
22 | private $request; |
||
23 | private $translator; |
||
0 ignored issues
–
show
|
|||
24 | private $coordinate; |
||
25 | private $userId; |
||
26 | private $noteId; |
||
27 | private $cacheId; |
||
28 | private $note; |
||
29 | private $cacheNoteHandler; |
||
30 | |||
31 | public function __construct($request = false, $translator = false) |
||
32 | { |
||
33 | $this->request = $request; |
||
34 | $this->coordinate = new PresenterCoordinate($this->request, $translator); |
||
35 | } |
||
36 | |||
37 | public function init($cacheNoteHandler, $userId, $cacheId) |
||
38 | { |
||
39 | $this->cacheNoteHandler = $cacheNoteHandler; |
||
40 | $this->userId = $userId; |
||
41 | $this->cacheId = $cacheId; |
||
42 | |||
43 | $cacheNote = $cacheNoteHandler->getCacheNote($userId, $cacheId); |
||
44 | $this->noteId = $cacheNote['id']; |
||
45 | $this->note = $cacheNote['note']; |
||
46 | $this->coordinate->init($cacheNote['latitude'], $cacheNote['longitude']); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param \OcSmarty $template |
||
51 | */ |
||
52 | public function prepare($template) |
||
53 | { |
||
54 | $template->assign(self::tpl_note_id, $this->noteId); |
||
55 | $template->assign(self::tpl_cache_id, $this->cacheId); |
||
56 | $template->assign(self::tpl_note, $this->getNote()); |
||
57 | $template->assign(self::tpl_incl_coord, $this->coordinate->hasCoordinate()); |
||
58 | $this->coordinate->prepare($template); |
||
59 | } |
||
60 | |||
61 | public function validate() |
||
62 | { |
||
63 | $this->request->validate(self::req_incl_coord, new AlwaysValidValidator()); |
||
0 ignored issues
–
show
|
|||
64 | $this->request->validate(self::req_note, new AlwaysValidValidator()); |
||
0 ignored issues
–
show
|
|||
65 | |||
66 | if ($this->includeCoordinate()) { |
||
67 | $this->coordinate->validate(); |
||
68 | // Removed false-return for invalid coordinate, so that at least the note will be saved. |
||
69 | // validate() produces some formal valid coordinate. |
||
70 | // -- following 25 May 2015 |
||
71 | } else { |
||
72 | $this->coordinate->init(0, 0); |
||
73 | } |
||
74 | |||
75 | return true; |
||
76 | } |
||
77 | |||
78 | public function doSubmit() |
||
79 | { |
||
80 | $coordinate = $this->getCoordinate(); |
||
81 | |||
82 | $this->cacheNoteHandler->save( |
||
83 | $this->noteId, |
||
84 | $this->userId, |
||
85 | $this->cacheId, |
||
86 | $this->getNote(), |
||
87 | $coordinate->latitude(), |
||
88 | $coordinate->longitude() |
||
89 | ); |
||
90 | } |
||
91 | |||
92 | private function getNote() |
||
93 | { |
||
94 | return $this->request->get(self::req_note, $this->note); |
||
0 ignored issues
–
show
|
|||
95 | } |
||
96 | |||
97 | private function getCoordinate() |
||
98 | { |
||
99 | if ($this->includeCoordinate()) { |
||
100 | return $this->coordinate->getCoordinate(); |
||
101 | } |
||
102 | |||
103 | return new CoordinateCoordinate(0, 0); |
||
104 | } |
||
105 | |||
106 | private function includeCoordinate() |
||
107 | { |
||
108 | return $this->request->get(self::req_incl_coord); |
||
0 ignored issues
–
show
|
|||
109 | } |
||
110 | } |
||
111 |
This check marks private properties in classes that are never used. Those properties can be removed.