Skip to content

Commit

Permalink
Coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Aug 8, 2024
1 parent 00ccd28 commit ae31046
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
13 changes: 7 additions & 6 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
* Condition to restrict access by user
*/
class condition extends \core_availability\condition {
/**
* @var int ID of the required user
*/
protected $userid;
/** @var int ID of the required user */
protected int $userid;

/** @var array $userids The user ids that the condition checks for */
protected array $userids;

/**
* Constructor
Expand Down Expand Up @@ -120,15 +121,15 @@ public function get_description($full, $not, \core_availability\info $info) {
array_push($usernames, fullname($user));
}
}
return get_string('requires_'.($not ? 'not_' : '').'users', 'availability_user', implode(', ', $usernames));
return get_string('requires_' . ($not ? 'not_' : '') . 'users', 'availability_user', implode(', ', $usernames));
} else {
$user = \core_user::get_user($this->userids[0]);
if (!$user) {
$fullname = get_string('unknown_user', 'availability_user');
} else {
$fullname = fullname($user);
}
return get_string('requires_'.($not ? 'not_' : '').'user', 'availability_user', $fullname);
return get_string('requires_' . ($not ? 'not_' : '') . 'user', 'availability_user', $fullname);
}
} else {
return get_string('requires_certain_user', 'availability_user');
Expand Down
2 changes: 1 addition & 1 deletion classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function get_javascript_init_params($course, \cm_info $cm = null, \sec
$participantlist = [];
foreach ($participants as $p) {
array_push($participantlist, ['firstname' => $p->firstname, 'lastname' => $p->lastname,
'fullname' => fullname($p), 'id' => $p->id]);
'fullname' => fullname($p), 'id' => $p->id, ]);
}
return [$participantlist];
}
Expand Down
3 changes: 1 addition & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
27 changes: 13 additions & 14 deletions tests/availability_user_condition_testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* Testcase for availability_user
*/
class availability_user_condition_testcase extends advanced_testcase {

/**
* Load necessary libs
*/
Expand All @@ -47,34 +46,34 @@ public function setUp(): void {
$this->capabilitychecker = new \core_availability\capability_checker($this->info->get_context());
$this->resetAfterTest();
$this->user1 = $this->getDataGenerator()->create_user(
array(
[
'email' => '[email protected]',
'username' => 'user1')
'username' => 'user1', ]
);
$this->user2 = $this->getDataGenerator()->create_user(
array(
[
'email' => '[email protected]',
'username' => 'user2')
'username' => 'user2', ]
);
$this->user3 = $this->getDataGenerator()->create_user(
array(
[
'email' => '[email protected]',
'username' => 'user3')
'username' => 'user3', ]
);
$this->user4 = $this->getDataGenerator()->create_user(
array(
[
'email' => '[email protected]',
'username' => 'user4')
'username' => 'user4', ]
);
$oldstructure = new stdClass;
$oldstructure = new stdClass();
$oldstructure->userid = $this->user1->id;
$this->cond = new condition($oldstructure);

$newstructure = new stdClass;
$newstructure = new stdClass();
$newstructure->userids = [$this->user1->id];
$this->newcond = new condition($newstructure);

$multiplestructure = new stdClass;
$multiplestructure = new stdClass();
$multiplestructure->userids = [$this->user1->id, $this->user2->id, $this->user3->id];
$this->multiplecond = new condition($multiplestructure);
}
Expand Down Expand Up @@ -243,7 +242,7 @@ public function test_users_multiple_filter() {
$this->user1->id => $this->user1,
$this->user2->id => $this->user2,
$this->user3->id => $this->user3,
$this->user4->id => $this->user4
$this->user4->id => $this->user4,
];
$filteredlist = $this->multiplecond->filter_user_list($users, false, $this->info, $this->capabilitychecker);
$filtereduserids = array_keys($filteredlist);
Expand All @@ -263,7 +262,7 @@ public function test_users_multiple_filter_not() {
$this->user1->id => $this->user1,
$this->user2->id => $this->user2,
$this->user3->id => $this->user3,
$this->user4->id => $this->user4
$this->user4->id => $this->user4,
];
$filteredlist = $this->multiplecond->filter_user_list($users, true, $this->info, $this->capabilitychecker);
$filtereduserids = array_keys($filteredlist);
Expand Down

0 comments on commit ae31046

Please sign in to comment.