Skip to content

Commit

Permalink
GH-643 MUSI-612 fixes for campaigns
Browse files Browse the repository at this point in the history
Choose campaign to correctly load data
  • Loading branch information
eynimeni committed Oct 24, 2024
1 parent 3fb6ec4 commit cfcb728
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 6 additions & 5 deletions classes/booking_campaigns/campaigns/campaign_blockbooking.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,22 +350,23 @@ public function is_blocking(booking_option_settings $settings, int $userid): arr
// If there is a value, it has to match in order to block.
$blocking = false;
$operator = $this->cpoperator;
$operator = $this->cpvalue;

// TODO Handle other types of fields like arrays.
if (is_string($user->profile->$fieldname)) {
if (is_string($user->profile[$fieldname])) {
switch ($operator) {
case "=": // Equals.
$blocking = $user->profile->$fieldname === $this->cpvalue;
$blocking = $user->profile[$fieldname] === $this->cpvalue;
break;
case "~": // Contains.
$blocking = strpos($user->profile->$fieldname, $this->cpvalue) !== false;
$blocking = strpos($user->profile[$fieldname], $this->cpvalue) !== false;
break;
}
}
}
if ($blocking) {
return [
'status' => true,
'label' => $this->blockinglabel,
'label' => format_string($this->blockinglabel),
];
}
return [
Expand Down
3 changes: 1 addition & 2 deletions classes/booking_campaigns/campaigns_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public static function add_campaigns_to_mform(MoodleQuickForm &$mform,
$campaigns = self::get_campaigns();

$campaignsforselect = [];
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
/* $campaignsforselect['0'] = get_string('choose...', 'mod_booking'); */
$campaignsforselect['0'] = get_string('choose...', 'mod_booking');
foreach ($campaigns as $campaign) {
$fullclassname = get_class($campaign); // With namespace.
$classnameparts = explode('\\', $fullclassname);
Expand Down
9 changes: 6 additions & 3 deletions classes/singleton_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,25 @@ public static function get_instance_of_booking_option_settings($optionid, ?stdCl
* Service to create and return singleton instance of Moodle user.
*
* @param int $userid
* @param bool $includeprofilefields
*
* @return stdClass
*/
public static function get_instance_of_user(int $userid, bool $includeprofilefields = false) {
global $CFG;
$instance = self::get_instance();

if (isset($instance->users[$userid])) {
if ($includeprofilefields && !isset($instance->users[$userid]->profile)) {
$customfields = profile_user_record($userid);
$instance->users[$userid]->profile = $customfields;
require_once("{$CFG->dirroot}/user/profile/lib.php");
profile_load_custom_fields($instance->users[$userid]);
}
return $instance->users[$userid];
} else {
$user = core_user::get_user($userid);
if ($includeprofilefields) {
$user->profile = profile_user_record($userid);
require_once("{$CFG->dirroot}/user/profile/lib.php");
profile_load_custom_fields($user);
}
$instance->users[$userid] = $user;
return $user;
Expand Down

0 comments on commit cfcb728

Please sign in to comment.