Skip to content

Commit 7a4a2ac

Browse files
committed
Refactor to using active_user
1 parent 9f0c136 commit 7a4a2ac

File tree

10 files changed

+28
-50
lines changed

10 files changed

+28
-50
lines changed

src/controllers/Document/View.php

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace BNETDocs\Controllers\Document;
44

5+
use \BNETDocs\Libraries\Authentication;
56
use \BNETDocs\Libraries\Comment;
67
use \BNETDocs\Libraries\Document;
78
use \BNETDocs\Libraries\Exceptions\DocumentNotFoundException;
@@ -18,6 +19,7 @@
1819
class View extends Controller {
1920
public function &run(Router &$router, ViewLib &$view, array &$args) {
2021
$model = new DocumentViewModel();
22+
$model->active_user = Authentication::$user;
2123
$model->document_id = array_shift($args);
2224

2325
try {

src/controllers/News.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ class News extends Controller {
2424

2525
public function &run(Router &$router, View &$view, array &$args) {
2626
$model = new NewsModel();
27+
$model->active_user = Authentication::$user;
2728

28-
$model->user = Authentication::$user;
29-
30-
$model->acl_allowed = ($model->user && $model->user->getAcl(
29+
$model->acl_allowed = ($model->active_user && $model->active_user->getAcl(
3130
User::OPTION_ACL_NEWS_CREATE |
3231
User::OPTION_ACL_NEWS_MODIFY |
3332
User::OPTION_ACL_NEWS_DELETE

src/controllers/Packet/View.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace BNETDocs\Controllers\Packet;
44

5+
use \BNETDocs\Libraries\Authentication;
56
use \BNETDocs\Libraries\Comment;
67
use \BNETDocs\Libraries\Exceptions\PacketNotFoundException;
78
use \BNETDocs\Libraries\Packet;
@@ -18,7 +19,8 @@
1819

1920
class View extends Controller {
2021
public function &run(Router &$router, ViewLib &$view, array &$args) {
21-
$model = new PacketViewModel();
22+
$model = new PacketViewModel();
23+
$model->active_user = Authentication::$user;
2224
$model->packet_id = array_shift($args);
2325

2426
try {

src/models/Document/View.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
<?php
2-
3-
namespace BNETDocs\Models\Document;
4-
5-
use \CarlBennett\MVC\Libraries\Model;
6-
7-
class View extends Model {
8-
1+
<?php namespace BNETDocs\Models\Document;
2+
class View extends \BNETDocs\Models\ActiveUser
3+
{
94
public $acl_allowed;
105
public $comments;
116
public $document;
127
public $document_id;
13-
148
}

src/models/News.php

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
<?php
2-
3-
namespace BNETDocs\Models;
4-
5-
use \CarlBennett\MVC\Libraries\Model;
6-
7-
class News extends Model {
8-
1+
<?php namespace BNETDocs\Models;
2+
class News extends \BNETDocs\Models\ActiveUser
3+
{
94
public $acl_allowed;
105
public $news_posts;
116
public $pagination;
12-
public $user;
13-
147
}

src/models/Packet/View.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
<?php
2-
3-
namespace BNETDocs\Models\Packet;
4-
5-
use \CarlBennett\MVC\Libraries\Model;
6-
7-
class View extends Model {
8-
1+
<?php namespace BNETDocs\Models\Packet;
2+
class View extends \BNETDocs\Models\ActiveUser
3+
{
94
public $comments;
105
public $packet;
116
public $packet_id;
127
public $used_by;
13-
148
}

src/templates/Document/View.phtml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
22
namespace BNETDocs\Templates\Document;
3-
use \BNETDocs\Libraries\Authentication;
43
use \BNETDocs\Libraries\Comment;
54
use \BNETDocs\Libraries\User;
65
use \CarlBennett\MVC\Libraries\Common;
76
use \CarlBennett\MVC\Libraries\Pair;
7+
$active_user = $this->getContext()->active_user;
88
$comments = $this->getContext()->comments;
99
$object = $this->getContext()->document;
1010
$object_id = $this->getContext()->document_id;
11-
$logged_in = Authentication::$user;
12-
$logged_in_id = ($logged_in ? $logged_in->getId() : null);
1311
$title = 'Document Not Found';
1412
$description = 'The requested document does not exist or could not be found.';
1513
$this->opengraph->attach(new Pair('type', 'article'));
@@ -27,8 +25,8 @@ if ($object)
2725
$this->opengraph->attach(new Pair('url', $url));
2826
$edit_url = Common::relativeUrlToAbsolute('/document/edit?id=' . rawurlencode($object_id));
2927
$delete_url = Common::relativeUrlToAbsolute('/document/delete?id=' . rawurlencode($object_id));
30-
$edit_visible = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_DOCUMENT_MODIFY));
31-
$delete_visible = ($logged_in && ($logged_in->getOptionsBitmask() & User::OPTION_ACL_DOCUMENT_DELETE));
28+
$edit_visible = ($active_user && ($active_user->getOptionsBitmask() & User::OPTION_ACL_DOCUMENT_MODIFY));
29+
$delete_visible = ($active_user && ($active_user->getOptionsBitmask() & User::OPTION_ACL_DOCUMENT_DELETE));
3230
require_once('./MarkdownBootstrapFix.inc.php');
3331
require('./header.inc.phtml'); ?>
3432
<div class="container mb-3">

src/templates/News.phtml

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace BNETDocs\Templates;
44

5-
use \BNETDocs\Libraries\Authentication;
65
use \BNETDocs\Libraries\NewsPost;
76
use \BNETDocs\Libraries\User;
87

@@ -29,11 +28,10 @@ if (is_null($news_posts) || empty($news_posts)) {
2928
<?php
3029
} else {
3130

32-
$logged_in = Authentication::$user;
33-
34-
$edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
31+
$active_user = $this->getContext()->active_user;
32+
$edit_visible = ($active_user && ($active_user->getOptionsBitmask()
3533
& User::OPTION_ACL_NEWS_MODIFY));
36-
$delete_visible = ($logged_in && ($logged_in->getOptionsBitmask()
34+
$delete_visible = ($active_user && ($active_user->getOptionsBitmask()
3735
& User::OPTION_ACL_NEWS_DELETE));
3836

3937
$users = [];

src/templates/News/View.phtml

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use \CarlBennett\MVC\Libraries\Pair;
88
$comments = $this->getContext()->comments;
99
$object = $this->getContext()->news_post;
1010
$object_id = $this->getContext()->news_post_id;
11-
$logged_in = $this->getContext()->active_user;
12-
$logged_in_id = ($logged_in ? $logged_in->getId() : null);
11+
$active_user = $this->getContext()->active_user;
1312
$title = ($object ? $object->getTitle() : 'News Post Not Found');
1413
$description = filter_var(($object ? $object->getContent(true) : 'The requested news post does not exist or could not be found.'), FILTER_SANITIZE_STRING);
1514
$this->opengraph->attach(new Pair('type', 'article'));
@@ -33,9 +32,9 @@ $this->opengraph->attach(new Pair('url', $url));
3332

3433
$edit_url = Common::relativeUrlToAbsolute('/news/edit?id=' . urlencode($object_id));
3534
$delete_url = Common::relativeUrlToAbsolute('/news/delete?id=' . urlencode($object_id));
36-
$edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
35+
$edit_visible = ($active_user && ($active_user->getOptionsBitmask()
3736
& User::OPTION_ACL_NEWS_MODIFY));
38-
$delete_visible = ($logged_in && ($logged_in->getOptionsBitmask()
37+
$delete_visible = ($active_user && ($active_user->getOptionsBitmask()
3938
& User::OPTION_ACL_NEWS_DELETE));
4039

4140
if ($object)

src/templates/Packet/View.phtml

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use \CarlBennett\MVC\Libraries\Pair;
88
$title = 'Packet Not Found';
99
$description = 'The requested packet does not exist or could not be found.';
1010
$comments = $this->getContext()->comments;
11-
$logged_in = Authentication::$user;
12-
$logged_in_id = ($logged_in ? $logged_in->getId() : null);
11+
$active_user = Authentication::$user;
1312
$object = $this->getContext()->packet;
1413
$object_id = $this->getContext()->packet_id;
1514
$url = Common::relativeUrlToAbsolute('/packet/' . urlencode($object_id));
@@ -49,9 +48,9 @@ $this->opengraph->attach(new Pair('url', $url));
4948

5049
$edit_url = Common::relativeUrlToAbsolute('/packet/edit?id=' . urlencode($object_id));
5150
$delete_url = Common::relativeUrlToAbsolute('/packet/delete?id=' . urlencode($object_id));
52-
$edit_visible = ($logged_in && ($logged_in->getOptionsBitmask()
51+
$edit_visible = ($active_user && ($active_user->getOptionsBitmask()
5352
& User::OPTION_ACL_PACKET_MODIFY));
54-
$delete_visible = ($logged_in && ($logged_in->getOptionsBitmask()
53+
$delete_visible = ($active_user && ($active_user->getOptionsBitmask()
5554
& User::OPTION_ACL_PACKET_DELETE));
5655

5756
require_once('./MarkdownBootstrapFix.inc.php');

0 commit comments

Comments
 (0)