Skip to content

Commit 093522a

Browse files
fixed comments
1 parent b7a17c8 commit 093522a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/models/User.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -445,32 +445,38 @@ public function hasRole($role, $subject_id = null)
445445
}
446446

447447
/**
448-
*
449-
* @param string|array $role
448+
* Retrieves an array of subject IDs associated with a given user role.
449+
*
450+
* @param string $role The role code for which to retrieve subjects.
451+
* @return array An array of unique subject IDs associated with the specified role.
450452
*/
451453
public function getRoleSubjectsArray($role)
452454
{
455+
// Fetch roles and associated subject IDs from the database
453456
$roles = UserRoles::find()
454457
->select(['user_roles.subject_id', 'roles.function_to_get_all_subjects'])
455458
->leftJoin('roles', 'user_roles.role_id = roles.id')
456-
->where(['user_roles.user_id' => $this->id])
457-
->andWhere(['roles.code' => $role])
459+
->where(['user_roles.user_id' => $this->id]) // Filter by user ID
460+
->andWhere(['roles.code' => $role]) // Filter by role code
458461
->asArray()
459462
->all();
460463

461-
// list of subjects
464+
// Initialize an empty list for subjects
462465
$subjects = [];
463466

464467
foreach ($roles as $role) {
468+
// Check if a subject ID is set and add it to the subjects array
465469
if (isset($role['subject_id'])) {
466470
$subjects = array_unique(array_merge([$role['subject_id']], $subjects));
471+
// If a function to get all subjects is defined and callable
467472
} else if (isset($role['function_to_get_all_subjects']) && is_callable($role['function_to_get_all_subjects'])) {
468-
473+
// Call the function to get subjects and merge the results
469474
$result = $role['function_to_get_all_subjects']();
470475
$subjects = array_unique(array_merge(array_keys($result), $subjects));
471476
}
472477
}
473478

479+
// Return the array of unique subject IDs
474480
return $subjects;
475481
}
476482

0 commit comments

Comments
 (0)