Skip to content

Commit

Permalink
Merge branch 'MDL-75146-master' of https://github.com/sarjona/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Jul 26, 2022
2 parents b32b486 + bc9b915 commit cfc6ec6
Show file tree
Hide file tree
Showing 21 changed files with 2,698 additions and 688 deletions.
2 changes: 1 addition & 1 deletion mod/data/amd/build/templateseditor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mod/data/amd/build/templateseditor.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions mod/data/amd/src/templateseditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const selectors = {
const registerEventListeners = (d, mode) => {
const toggleTemplateEditor = document.querySelector(selectors.toggleTemplateEditor);

if (!toggleTemplateEditor) {
return;
}

toggleTemplateEditor.addEventListener('click', async(event) => {
event.preventDefault();
// Whether the event action attempts to enable or disable the template editor.
Expand Down
34 changes: 19 additions & 15 deletions mod/data/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use mod_data\external\record_exporter;
use mod_data\external\content_exporter;
use mod_data\external\field_exporter;
use mod_data\manager;

/**
* Database module external functions
Expand Down Expand Up @@ -206,11 +207,13 @@ public static function view_database($databaseid) {
list($database, $course, $cm, $context) = self::validate_database($params['databaseid']);

// Call the data/lib API.
data_view($database, $course, $cm, $context);
$manager = manager::create_from_coursemodule($cm);
$manager->set_module_viewed($course);

$result = array();
$result['status'] = true;
$result['warnings'] = $warnings;
$result = [
'status' => true,
'warnings' => $warnings,
];
return $result;
}

Expand Down Expand Up @@ -404,6 +407,8 @@ public static function get_entries($databaseid, $groupid = 0, $returncontents =
}
}

$manager = manager::create_from_instance($database);

list($records, $maxcount, $totalcount, $page, $nowperpage, $sort, $mode) =
data_search_entries($database, $cm, $context, 'list', $groupid, '', $params['sort'], $params['order'],
$params['page'], $params['perpage']);
Expand Down Expand Up @@ -446,11 +451,8 @@ public static function get_entries($databaseid, $groupid = 0, $returncontents =

// Check if we should return the list rendered.
if ($params['returncontents']) {
ob_start();
// The return parameter stops the execution after the first record.
data_print_template('listtemplate', $records, $database, '', $page, false);
$result['listviewcontents'] = ob_get_contents();
ob_end_clean();
$parser = $manager->get_template('listtemplate', ['page' => $page]);
$result['listviewcontents'] = $parser->parse_entries($records);
}

return $result;
Expand Down Expand Up @@ -515,6 +517,8 @@ public static function get_entry($entryid, $returncontents = false) {
$canmanageentries = has_capability('mod/data:manageentries', $context);
data_require_time_available($database, $canmanageentries);

$manager = manager::create_from_instance($database);

if ($record->groupid != 0) {
if (!groups_group_visible($record->groupid, $course, $cm)) {
throw new moodle_exception('notingroup');
Expand Down Expand Up @@ -543,7 +547,8 @@ public static function get_entry($entryid, $returncontents = false) {
// Check if we should return the entry rendered.
if ($params['returncontents']) {
$records = [$record];
$result['entryviewcontents'] = data_print_template('singletemplate', $records, $database, '', 0, true);
$parser = $manager->get_template('singletemplate');
$result['entryviewcontents'] = $parser->parse_entries($records);
}

return $result;
Expand Down Expand Up @@ -714,6 +719,8 @@ public static function search_entries($databaseid, $groupid = 0, $returncontents
// Check database is open in time.
data_require_time_available($database, null, $context);

$manager = manager::create_from_instance($database);

if (!empty($params['groupid'])) {
$groupid = $params['groupid'];
// Determine is the group is visible to user.
Expand Down Expand Up @@ -779,11 +786,8 @@ public static function search_entries($databaseid, $groupid = 0, $returncontents

// Check if we should return the list rendered.
if ($params['returncontents']) {
ob_start();
// The return parameter stops the execution after the first record.
data_print_template('listtemplate', $records, $database, '', $page, false);
$result['listviewcontents'] = ob_get_contents();
ob_end_clean();
$parser = $manager->get_template('listtemplate', ['page' => $page]);
$result['listviewcontents'] = $parser->parse_entries($records);
}

return $result;
Expand Down
Loading

0 comments on commit cfc6ec6

Please sign in to comment.