PluginProbe
User Access Manager / 2.3.13
User Access Manager v2.3.13
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 +29 -19 trunk2.3.13 View file →
@@ -7,8 +7,10 @@
7 7 use Exception;
8 8 use UserAccessManager\Config\MainConfig;
9 9 use UserAccessManager\Database\Database;
10 10 use UserAccessManager\Object\ObjectHandler;
11 +use UserAccessManager\Util\Util;
12 +use UserAccessManager\Wrapper\Php;
11 13 use UserAccessManager\Wrapper\Wordpress;
12 14
13 15 class DynamicUserGroup extends AbstractUserGroup
14 16 {
@@ -19,17 +21,28 @@
19 21 /**
20 22 * @throws UserGroupTypeException
21 23 */
22 24 public function __construct(
25 + Php $php,
23 26 Wordpress $wordpress,
24 27 Database $database,
25 28 MainConfig $config,
29 + Util $util,
26 30 ObjectHandler $objectHandler,
27 - AssignedObjectsLoader $assignedObjectsLoader,
31 + AssignmentInformationFactory $assignmentInformationFactory,
28 32 protected ?string $type,
29 33 int|string $id
30 34 ) {
31 - parent::__construct($wordpress, $database, $config, $objectHandler, $assignedObjectsLoader, $id);
35 + parent::__construct(
36 + $php,
37 + $wordpress,
38 + $database,
39 + $config,
40 + $util,
41 + $objectHandler,
42 + $assignmentInformationFactory,
43 + $id
44 + );
32 45
33 46 if ($this->type !== self::USER_TYPE && $this->type !== self::ROLE_TYPE) {
34 47 throw new UserGroupTypeException('Invalid dynamic group type.');
35 48 }
@@ -41,28 +54,25 @@
41 54 }
42 55
43 56 public function getName(): string
44 57 {
45 - return $this->name ??= ($this->type === self::ROLE_TYPE) ? $this->createRoleName() : $this->createUserName();
46 - }
58 + if ($this->name === null) {
59 + $this->name = '';
47 60
48 - private function createRoleName(): string
49 - {
50 - $roles = $this->wordpress->getRoles()->roles;
51 -
52 - return TXT_UAM_ROLE . ': ' . ($roles[$this->id]['name'] ?? $this->id);
53 - }
54 -
55 - private function createUserName(): string
56 - {
57 - if ((int) $this->id === self::NOT_LOGGED_IN_USER_ID) {
58 - return TXT_UAM_ADD_DYNAMIC_NOT_LOGGED_IN_USERS;
61 + if ($this->type === self::USER_TYPE && (int) $this->id === self::NOT_LOGGED_IN_USER_ID) {
62 + $this->name = TXT_UAM_ADD_DYNAMIC_NOT_LOGGED_IN_USERS;
63 + } elseif ($this->type === self::USER_TYPE) {
64 + $userData = $this->wordpress->getUserData($this->id);
65 + $userName = $userData !== false ? "$userData->display_name ($userData->user_login)" : '';
66 + $this->name = TXT_UAM_USER . ": $userName";
67 + } elseif ($this->type === self::ROLE_TYPE) {
68 + $roles = $this->wordpress->getRoles()->roles;
69 + $this->name = TXT_UAM_ROLE . ': ';
70 + $this->name .= (isset($roles[$this->id]['name']) === true) ? $roles[$this->id]['name'] : $this->id;
71 + }
59 72 }
60 73
61 - $userData = $this->wordpress->getUserData($this->id);
62 - $userName = ($userData !== false) ? "$userData->display_name ($userData->user_login)" : '';
63 -
64 - return TXT_UAM_USER . ": $userName";
74 + return $this->name;
65 75 }
66 76
67 77 /**
68 78 * @throws UserGroupAssignmentException