PluginProbe
User Access Manager / 2.2.23
User Access Manager v2.2.23
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/UserGroup/DynamicUserGroup.php +56 -7 2.3.142.2.23 View file →
@@ -1,5 +1,18 @@
1 1 <?php
2 +/**
3 + * DynamicUserGroup.php
4 + *
5 + * The DynamicUserGroup class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
2 15
3 16 declare(strict_types=1);
4 17
5 18 namespace UserAccessManager\UserGroup;
@@ -11,15 +24,35 @@
11 24 use UserAccessManager\Util\Util;
12 25 use UserAccessManager\Wrapper\Php;
13 26 use UserAccessManager\Wrapper\Wordpress;
14 27
28 +/**
29 + * Class DynamicUserGroup
30 + *
31 + * @package UserAccessManager\UserGroup
32 + */
15 33 class DynamicUserGroup extends AbstractUserGroup
16 34 {
17 - public const USER_TYPE = 'user';
18 - public const ROLE_TYPE = 'role';
19 - public const NOT_LOGGED_IN_USER_ID = 0;
35 + const USER_TYPE = 'user';
36 + const ROLE_TYPE = 'role';
37 + const NOT_LOGGED_IN_USER_ID = 0;
20 38
21 39 /**
40 + * @var string
41 + */
42 + protected $type = null;
43 +
44 + /**
45 + * DynamicUserGroup constructor.
46 + * @param Php $php
47 + * @param Wordpress $wordpress
48 + * @param Database $database
49 + * @param MainConfig $config
50 + * @param Util $util
51 + * @param ObjectHandler $objectHandler
52 + * @param AssignmentInformationFactory $assignmentInformationFactory
53 + * @param string $type
54 + * @param int|string $id
22 55 * @throws UserGroupTypeException
23 56 */
24 57 public function __construct(
25 58 Php $php,
@@ -28,11 +61,13 @@
28 61 MainConfig $config,
29 62 Util $util,
30 63 ObjectHandler $objectHandler,
31 64 AssignmentInformationFactory $assignmentInformationFactory,
32 - protected ?string $type,
33 - int|string $id
65 + string $type,
66 + $id
34 67 ) {
68 + $this->type = $type;
69 +
35 70 parent::__construct(
36 71 $php,
37 72 $wordpress,
38 73 $database,
@@ -42,18 +77,26 @@
42 77 $assignmentInformationFactory,
43 78 $id
44 79 );
45 80
46 - if ($this->type !== self::USER_TYPE && $this->type !== self::ROLE_TYPE) {
81 + if ($type !== self::USER_TYPE && $type !== self::ROLE_TYPE) {
47 82 throw new UserGroupTypeException('Invalid dynamic group type.');
48 83 }
49 84 }
50 85
86 + /**
87 + * Returns the dynamic user group id.
88 + * @return string
89 + */
51 90 public function getId(): string
52 91 {
53 92 return $this->type . '|' . $this->id;
54 93 }
55 94
95 + /**
96 + * Returns the dynamic group name.
97 + * @return string
98 + */
56 99 public function getName(): string
57 100 {
58 101 if ($this->name === null) {
59 102 $this->name = '';
@@ -74,12 +117,18 @@
74 117 return $this->name;
75 118 }
76 119
77 120 /**
121 + * Checks if the user group is assigned to a user.
122 + * @param string $objectType
123 + * @param int|string $objectId
124 + * @param null $fromDate
125 + * @param null $toDate
126 + * @return bool
78 127 * @throws UserGroupAssignmentException
79 128 * @throws Exception
80 129 */
81 - public function addObject(string $objectType, int|string|null $objectId, $fromDate = null, $toDate = null): bool
130 + public function addObject(string $objectType, $objectId, $fromDate = null, $toDate = null): bool
82 131 {
83 132 if ($this->objectHandler->getGeneralObjectType($objectType) === ObjectHandler::GENERAL_USER_OBJECT_TYPE) {
84 133 throw new UserGroupAssignmentException('Dynamic user groups can\'t be assigned to user.');
85 134 }