Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev testing 711 enrollonk gh 650 #731

Merged
merged 22 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ee9cb63
Improvment: New option enrolusersaction in customform multiplying pri…
eynimeni Nov 13, 2024
ed62c6f
Add enrollinkbot_triggered event & add to rules (#650)
eynimeni Nov 14, 2024
6412bc2
Return price as float
eynimeni Nov 18, 2024
9f90a48
Trigger event correctly (#650)
eynimeni Nov 18, 2024
6f0c40a
Version (2024111800) with new db tables
eynimeni Nov 18, 2024
55aeb52
Add field to bundle table
eynimeni Nov 18, 2024
905c094
Add bookingoption field to enrollink_bundle (Version 2024111802)
eynimeni Nov 18, 2024
a8d459b
Execute enrollink
eynimeni Nov 18, 2024
d1890fd
Refine enrolment function (#650)
eynimeni Nov 19, 2024
c7058a4
Remove wrong indexing (Version 2024111804)
eynimeni Nov 19, 2024
1fa7395
Add qrplaceholder & add ba json to eventdata (#650)
eynimeni Nov 19, 2024
eb5669f
Fix upgrade after version update due to rebase (Version 2024111904)
eynimeni Nov 19, 2024
3e9e674
Revert "Return price as float"
eynimeni Nov 19, 2024
2ad72cd
Linting and adding missing strings
eynimeni Nov 20, 2024
004b665
Change name of option multienrol (#650)
eynimeni Nov 21, 2024
9fbc4ef
start new behat scenario: Booking option enrollink: create and valida…
semteacher Nov 24, 2024
ae80911
Add alert about reference to moodle course (#711, #650)
eynimeni Nov 26, 2024
2e92c29
Version (2024112604) with db update
eynimeni Nov 26, 2024
06ca269
finalize behat Scenario: Booking option enrollink: create and validat…
semteacher Nov 26, 2024
c07f242
new phpunit test_rule_on_enrollink_and_enroll() (#711)
semteacher Nov 26, 2024
ae1c7bc
extension oft the phpunit test_rule_on_enrollink_and_enroll() - place…
semteacher Nov 26, 2024
dcea669
linting
semteacher Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions classes/bo_availability/conditions/customform.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use mod_booking\bo_availability\bo_condition;
use mod_booking\bo_availability\bo_info;
use mod_booking\booking_option_settings;
use mod_booking\event\enrollink_triggered;
use mod_booking\local\mobile\customformstore;
use mod_booking\singleton_service;
use mod_booking\utils\wb_payment;
Expand Down Expand Up @@ -224,6 +225,7 @@ public function add_condition_to_mform(MoodleQuickForm &$mform, int $optionid =
'url' => get_string('bocondcustomformurl', 'mod_booking'),
'mail' => get_string('bocondcustomformmail', 'mod_booking'),
'deleteinfoscheckboxuser' => get_string('bocondcustomformdeleteinfoscheckboxuser', 'mod_booking'),
'enrolusersaction' => get_string('enrolmultipleusers', 'mod_booking'),
];

// We add four potential elements.
Expand Down Expand Up @@ -284,6 +286,19 @@ public function add_condition_to_mform(MoodleQuickForm &$mform, int $optionid =
'',
get_string('customformselectoptions', 'mod_booking')
);

$mform->addElement(
'static',
'info_about_enrolusersaction' . $counter,
'',
get_string('enrolusersaction:alert', 'mod_booking'),
);
$mform->hideIf(
'info_about_enrolusersaction' . $counter,
'bo_cond_customform_select_1_' . $counter,
'neq',
'enrolusersaction'
);
}

$mform->hideIf('info_about_select_options_' . $counter, 'bo_cond_customform_restrict', 'notchecked');
Expand Down Expand Up @@ -610,6 +625,7 @@ public static function add_json_to_booking_answer(stdClass &$newanswer, int $use
"condition_customform" => $data,
];
$newanswer->json = json_encode($data);
self::update_places_with_customformdata($data, $newanswer);
}

// We only delete the json when it's booked.
Expand All @@ -618,6 +634,31 @@ public static function add_json_to_booking_answer(stdClass &$newanswer, int $use
}
}

/**
* Update places column in case there is a enrolusersaction field.
*
* @param mixed $data
* @param mixed $newanswer
*
* @return bool
*
*/
private static function update_places_with_customformdata($data, &$newanswer): bool {
global $USER;

if (!isset($data->condition_customform)) {
return false;
}
foreach ($data->condition_customform as $key => $value) {
// For the moment, we only support 1 enrolusersaction field.
if (strpos($key, 'customform_enrolusersaction_') === 0) {
$newanswer->places = $value;
return true;
}
}
return false;
}

/**
* This interprets the availability column, looks for an entry from this class and returns the fields.
* @param booking_option_settings $settings
Expand Down Expand Up @@ -664,4 +705,34 @@ public static function append_customform_elements($answer) {
}
return $answer;
}

/**
* This function adds error keys for form validation.
* @param array $data
* @param array $files
* @param array $errors
* @return array
*/
public static function validation(array $data, array $files, array &$errors) {

if (
empty($data['chooseorcreatecourse'])
|| (is_array($data['courseid']) && empty($data['courseid'][0]))
|| empty($data['courseid'])
) {
foreach ($data as $key => $value) {
// We need a courseid for the customform_enrolusersaction.
if (preg_match('/^bo_cond_customform_select_/', $key) && $data[$key] === "enrolusersaction") {
if (empty($data['chooseorcreatecourse'])) {
$errors['chooseorcreatecourse'] = get_string('relatedcourseidneeded', 'mod_booking');
} else {
$errors['courseid'] = get_string('relatedcourseidneeded', 'mod_booking');
}
return $errors;
}
}
return $errors;
}
return $errors;
}
}
18 changes: 16 additions & 2 deletions classes/booking_option.php
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,14 @@ public function after_successful_booking_routine(stdClass $user, int $waitinglis
'other' => $other,
]);
$event->trigger();

enrollink::trigger_enrolbot_actions(
$this->optionid,
$user->id,
$this->settings,
$ba,
$other['baid']
);
}

$settings = singleton_service::get_instance_of_booking_option_settings($this->optionid);
Expand Down Expand Up @@ -1457,13 +1465,15 @@ public function send_confirm_message(stdClass $user, bool $optionchanged = false
* @param int $roleid
* @param bool $isteacher true for teacher enrolments
* @param int $courseid can override given courseid.
* @param bool $enrolwithoutba Enrol a user event if there is no corresponding booking answer
*/
public function enrol_user(
int $userid,
bool $manual = false,
int $roleid = 0,
bool $isteacher = false,
int $courseid = 0
int $courseid = 0,
bool $enrolwithoutba = false
) {
global $DB;

Expand Down Expand Up @@ -1498,7 +1508,11 @@ public function enrol_user(
$bookinganswers = booking_answers::get_instance_from_optionid($this->optionid);

$instance = reset($instances); // Use the first manual enrolment plugin in the course.
if ($bookinganswers->user_status($userid) == MOD_BOOKING_STATUSPARAM_BOOKED || $isteacher) {
if (
$bookinganswers->user_status($userid) == MOD_BOOKING_STATUSPARAM_BOOKED
|| $isteacher
|| $enrolwithoutba
) {
// For self-learning courses, users will be enrolled from the time booked...
// ...until the duration of the self-learning course has passed #684.
if (!empty($this->settings->selflearningcourse) && !$isteacher) {
Expand Down
1 change: 1 addition & 0 deletions classes/booking_rules/rules/rule_react_on_event.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function add_rule_to_mform(MoodleQuickForm &$mform, array &$repeateloptio
'optiondates_teacher_added',
'optiondates_teacher_deleted',
'rest_script_success',
'enrollink_triggered',
];

// Get a list of all booking events.
Expand Down
Loading
Loading