Skip to content

Commit

Permalink
API vrača značke.
Browse files Browse the repository at this point in the history
  • Loading branch information
atlet committed May 9, 2024
1 parent 7915d37 commit 1f7d2c8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
59 changes: 46 additions & 13 deletions classes/external/bookings.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ class bookings extends external_api {
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'courseid' => new external_value(PARAM_INT, 'Course id', (bool) VALUE_DEFAULT, 0),
'printusers' => new external_value(PARAM_INT, 'Print user profiles', (bool) VALUE_DEFAULT, 0),
'days' => new external_value(PARAM_INT, 'How old bookings to retrive - in days.', (bool) VALUE_DEFAULT, 0)
return new external_function_parameters(
[
'courseid' => new external_value(PARAM_INT, 'Course id', (bool) VALUE_DEFAULT, 0),
'printusers' => new external_value(PARAM_INT, 'Print user profiles', (bool) VALUE_DEFAULT, 0),
'days' => new external_value(PARAM_INT, 'How old bookings to retrive - in days.', (bool) VALUE_DEFAULT, 0)
]
);
}
Expand All @@ -77,8 +78,10 @@ public static function execute(int $courseid = 0, int $printusers = 0, int $days

$returns = array();

$params = self::validate_parameters(self::execute_parameters(),
['courseid' => $courseid, 'printusers' => $printusers, 'days' => $days]);
$params = self::validate_parameters(
self::execute_parameters(),
['courseid' => $courseid, 'printusers' => $printusers, 'days' => $days]
);

$bookings = $DB->get_records_select("booking", "course = {$courseid}");

Expand All @@ -103,8 +106,14 @@ public static function execute(int $courseid = 0, int $printusers = 0, int $days
$bookingdata->apply_tags();
$context = context_module::instance($cm->id);

$bookingdata->settings->intro = file_rewrite_pluginfile_urls($bookingdata->settings->intro,
'pluginfile.php', $context->id, 'mod_booking', 'intro', null);
$bookingdata->settings->intro = file_rewrite_pluginfile_urls(
$bookingdata->settings->intro,
'pluginfile.php',
$context->id,
'mod_booking',
'intro',
null
);

$manager = $DB->get_record('user', array('username' => $bookingdata->settings->bookingmanager));

Expand All @@ -123,6 +132,7 @@ public static function execute(int $courseid = 0, int $printusers = 0, int $days
$ret['bookingmanageremail'] = $manager->email;
$ret['myfilemanager'] = external_util::get_area_files($context->id, 'mod_booking', 'myfilemanager');
$ret['categories'] = array();
$ret['tags'] = [];
$ret['options'] = array();

if ($bookingdata->settings->categoryid != '0' && $bookingdata->settings->categoryid != '') {
Expand All @@ -139,8 +149,21 @@ public static function execute(int $courseid = 0, int $printusers = 0, int $days
}
}

foreach ($bookingdata->get_all_options(0, 0, '', '*') as $record) {
$tags = \core_tag_tag::get_item_tags(
'mod_booking',
'booking',
$bookingdata->settings->id
);

foreach ($tags as $key => $value) {
$tag = array();
$tag['id'] = $value->id;
$tag['name'] = $value->name;

$ret['tags'][] = $tag;
}

foreach ($bookingdata->get_all_options(0, 0, '', '*') as $record) {
$option = array();
$option['id'] = $record->id;
$option['text'] = $record->text;
Expand All @@ -156,8 +179,10 @@ public static function execute(int $courseid = 0, int $printusers = 0, int $days
$option['teachers'] = array();

if ($printusers) {
$users = $DB->get_records('booking_answers',
array('optionid' => $record->id));
$users = $DB->get_records(
'booking_answers',
array('optionid' => $record->id)
);
foreach ($users as $user) {
$tmpuser = array();
$ruser = $DB->get_record('user', array('id' => $user->userid));
Expand All @@ -171,8 +196,10 @@ public static function execute(int $courseid = 0, int $printusers = 0, int $days
}
}

$users = $DB->get_records('booking_teachers',
array('bookingid' => $record->bookingid, 'optionid' => $record->id));
$users = $DB->get_records(
'booking_teachers',
array('bookingid' => $record->bookingid, 'optionid' => $record->id)
);
foreach ($users as $user) {
$teacher = array();
$ruser = $DB->get_record('user', array('id' => $user->userid));
Expand Down Expand Up @@ -224,6 +251,12 @@ public static function execute_returns(): external_multiple_structure {
'name' => new external_value(PARAM_TEXT, 'Category name')
)
)),
'tags' => new external_multiple_structure(new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'Tag ID'),
'name' => new external_value(PARAM_TEXT, 'Tag name')
)
)),
'options' => new external_multiple_structure(new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'Option ID'),
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023120501;
$plugin->version = 2024050900;
$plugin->requires = 2022041900; // Requires this Moodle version. Current: Moodle 4.0.0.
$plugin->release = '8.0.33';
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit 1f7d2c8

Please sign in to comment.