1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Nodes;
13
14 use ICanBoogie\ActiveRecord\Query;
15 use ICanBoogie\Event;
16 use ICanBoogie\Exception;
17 use ICanBoogie\HTTP\HTTPError;
18 use ICanBoogie\HTTP\NotFound;
19
20 class ViewProvider extends \Icybee\Modules\Views\ActiveRecordProvider
21 {
22 23 24 25 26 27 28
29 public function __invoke()
30 {
31 global $core;
32
33 $rc = parent::__invoke();
34
35 if ($rc instanceof Node)
36 {
37 if (!$rc)
38 {
39 throw new NotFound('The requested record was not found.');
40 }
41
42 if (!$rc->is_online)
43 {
44 if (!$core->user->has_permission(\ICanBoogie\Module::PERMISSION_ACCESS, $rc->constructor))
45 {
46 throw new HTTPError('The requested record requires authentication.', 401);
47 }
48
49 $rc->title .= ' ✎';
50 }
51
52 $page = isset($core->request->context->page) ? $core->request->context->page : null;
53
54 if ($page)
55 {
56 $page->title = $rc->title;
57
58 if ($this->view->type == 'view')
59 {
60 $page->node = $rc;
61 }
62 }
63 }
64
65 return $rc;
66 }
67
68 69 70
71 protected function alter_conditions(array $conditions)
72 {
73 return $conditions;
74 }
75
76 77 78 79 80 81 82 83 84
85 protected function alter_query(Query $query, array $conditions)
86 {
87 $query->own->similar_site->similar_language;
88
89 if (isset($conditions['nid']))
90 {
91 $query->filter_by_nid($conditions['nid']);
92 }
93 else if (isset($conditions['slug']))
94 {
95 $query->filter_by_slug($conditions['slug']);
96 }
97
98 if ($this->returns == self::RETURNS_MANY)
99 {
100 $query->filter_by_is_online(true);
101 }
102
103 return parent::alter_query($query, $conditions)->order('created_at DESC');
104 }
105
106 107 108
109 protected function alter_context(\BlueTihi\Context $context, Query $query, array $conditions)
110 {
111 return $context;
112 }
113 }