-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathView.php
More file actions
49 lines (41 loc) · 1.55 KB
/
Copy pathView.php
File metadata and controls
49 lines (41 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace BNETDocs\Controllers\Document;
use \BNETDocs\Libraries\Comment;
use \BNETDocs\Libraries\Core\HttpCode;
use \BNETDocs\Models\Document\View as ViewModel;
class View extends \BNETDocs\Controllers\Base
{
/**
* Constructs a Controller, typically to initialize properties.
*/
public function __construct()
{
$this->model = new ViewModel();
}
/**
* Invoked by the Router class to handle the request.
*
* @param array|null $args The optional route arguments and any captured URI arguments.
* @return boolean Whether the Router should invoke the configured View.
*/
public function invoke(?array $args): bool
{
$this->model->document_id = array_shift($args);
try { $this->model->document = new \BNETDocs\Libraries\Document($this->model->document_id); }
catch (\BNETDocs\Exceptions\DocumentNotFoundException) { $this->model->document = null; }
if ($this->model->document && !$this->model->document->isPublished()
&& !($this->model->active_user && $this->model->active_user->isStaff()))
{
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
$this->model->error = $this->model->active_user ? ViewModel::ERROR_ACL_NOT_SET : ViewModel::ERROR_NOT_LOGGED_IN;
$this->model->document = null;
return true;
}
if ($this->model->document)
{
$this->model->comments = Comment::getAll(Comment::PARENT_TYPE_DOCUMENT, $this->model->document_id);
}
$this->model->_responseCode = $this->model->document ? HttpCode::HTTP_OK : HttpCode::HTTP_NOT_FOUND;
return true;
}
}