PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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 +69 -19 2.3.13 → 2.1.11 View file →
@@ -1,11 +1,20 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * DynamicUserGroup.php
4 + *
5 + * The DynamicUserGroup class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
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 + */
5 15 namespace UserAccessManager\UserGroup;
6 16
7 -use Exception;
8 17 use UserAccessManager\Config\MainConfig;
9 18 use UserAccessManager\Database\Database;
10 19 use UserAccessManager\Object\ObjectHandler;
11 20 use UserAccessManager\Util\Util;
@@ -11,15 +20,37 @@
11 20 use UserAccessManager\Util\Util;
12 21 use UserAccessManager\Wrapper\Php;
13 22 use UserAccessManager\Wrapper\Wordpress;
14 23
24 +/**
25 + * Class DynamicUserGroup
26 + *
27 + * @package UserAccessManager\UserGroup
28 + */
15 29 class DynamicUserGroup extends AbstractUserGroup
16 30 {
17 - public const USER_TYPE = 'user';
18 - public const ROLE_TYPE = 'role';
19 - public const NOT_LOGGED_IN_USER_ID = 0;
31 + const USER_TYPE = 'user';
32 + const ROLE_TYPE = 'role';
33 + const NOT_LOGGED_IN_USER_ID = 0;
20 34
21 35 /**
36 + * @var string
37 + */
38 + protected $type = null;
39 +
40 + /**
41 + * DynamicUserGroup constructor.
42 + *
43 + * @param Php $php
44 + * @param Wordpress $wordpress
45 + * @param Database $database
46 + * @param MainConfig $config
47 + * @param Util $util
48 + * @param ObjectHandler $objectHandler
49 + * @param AssignmentInformationFactory $assignmentInformationFactory
50 + * @param string $type
51 + * @param string $id
52 + *
22 53 * @throws UserGroupTypeException
23 54 */
24 55 public function __construct(
25 56 Php $php,
@@ -28,11 +59,13 @@
28 59 MainConfig $config,
29 60 Util $util,
30 61 ObjectHandler $objectHandler,
31 62 AssignmentInformationFactory $assignmentInformationFactory,
32 - protected ?string $type,
33 - int|string $id
63 + $type,
64 + $id
34 65 ) {
66 + $this->type = $type;
67 +
35 68 parent::__construct(
36 69 $php,
37 70 $wordpress,
38 71 $database,
@@ -42,32 +75,41 @@
42 75 $assignmentInformationFactory,
43 76 $id
44 77 );
45 78
46 - if ($this->type !== self::USER_TYPE && $this->type !== self::ROLE_TYPE) {
79 + if ($type !== self::USER_TYPE && $type !== self::ROLE_TYPE) {
47 80 throw new UserGroupTypeException('Invalid dynamic group type.');
48 81 }
49 82 }
50 83
51 - public function getId(): string
84 + /**
85 + * Returns the dynamic user group id.
86 + *
87 + * @return string
88 + */
89 + public function getId()
52 90 {
53 - return $this->type . '|' . $this->id;
91 + return $this->type.'|'.$this->id;
54 92 }
55 93
56 - public function getName(): string
94 + /**
95 + * Returns the dynamic group name.
96 + *
97 + * @return string
98 + */
99 + public function getName()
57 100 {
58 101 if ($this->name === null) {
59 102 $this->name = '';
60 103
61 - if ($this->type === self::USER_TYPE && (int) $this->id === self::NOT_LOGGED_IN_USER_ID) {
104 + if ($this->type === self::USER_TYPE && (int)$this->id === self::NOT_LOGGED_IN_USER_ID) {
62 105 $this->name = TXT_UAM_ADD_DYNAMIC_NOT_LOGGED_IN_USERS;
63 106 } elseif ($this->type === self::USER_TYPE) {
64 107 $userData = $this->wordpress->getUserData($this->id);
65 - $userName = $userData !== false ? "$userData->display_name ($userData->user_login)" : '';
66 - $this->name = TXT_UAM_USER . ": $userName";
108 + $this->name = TXT_UAM_USER.": {$userData->display_name} ($userData->user_login)";
67 109 } elseif ($this->type === self::ROLE_TYPE) {
68 110 $roles = $this->wordpress->getRoles()->roles;
69 - $this->name = TXT_UAM_ROLE . ': ';
111 + $this->name = TXT_UAM_ROLE.': ';
70 112 $this->name .= (isset($roles[$this->id]['name']) === true) ? $roles[$this->id]['name'] : $this->id;
71 113 }
72 114 }
73 115
@@ -74,12 +116,20 @@
74 116 return $this->name;
75 117 }
76 118
77 119 /**
120 + * Checks if the user group is assigned to a user.
121 + *
122 + * @param string $objectType
123 + * @param string $objectId
124 + * @param string $fromDate
125 + * @param string $toDate
126 + *
127 + * @return bool
128 + *
78 129 * @throws UserGroupAssignmentException
79 - * @throws Exception
80 130 */
81 - public function addObject(string $objectType, int|string|null $objectId, $fromDate = null, $toDate = null): bool
131 + public function addObject($objectType, $objectId, $fromDate = null, $toDate = null)
82 132 {
83 133 if ($this->objectHandler->getGeneralObjectType($objectType) === ObjectHandler::GENERAL_USER_OBJECT_TYPE) {
84 134 throw new UserGroupAssignmentException('Dynamic user groups can\'t be assigned to user.');
85 135 }