Skip to content

Commit

Permalink
Merge branch 'catalyst-add-embed-options' into MOODLE_401_STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Oct 3, 2024
2 parents 1ada1cb + 81a83fa commit 6292431
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 22 deletions.
2 changes: 2 additions & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<FIELD NAME="cron" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"
COMMENT="Should we run this query on regular CRON"/>
<FIELD NAME="remote" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="displaytotalrecords" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="displayprintbutton" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="1" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
13 changes: 13 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,18 @@ function xmldb_block_configurable_reports_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2019062001, 'block', 'configurable_reports');
}

if ($oldversion < 2024051300) {
$table = new xmldb_table('block_configurable_reports');
$field = new xmldb_field('displaytotalrecords', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1', null);
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('displayprintbutton', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1', null);
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_plugin_savepoint(true, 2024051300, 'block', 'configurable_reports');
}

return true;
}
8 changes: 8 additions & 0 deletions editreport.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@
$data->cron = 0;
}

if (!isset($data->displaytotalrecords)) {
$data->displaytotalrecords = 0;
}

if (!isset($data->displayprintbutton)) {
$data->displayprintbutton = 0;
}

if (empty($report)) {
$data->ownerid = $USER->id;
$data->courseid = $courseid;
Expand Down
36 changes: 29 additions & 7 deletions editreport_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ public function definition(): void {
$mform->addHelpButton('jsordering', 'jsordering', 'block_configurable_reports');
$mform->setDefault('jsordering', 1);

$mform->addElement(
'checkbox',
'cron',
get_string('cron', 'block_configurable_reports'),
get_string('crondescription', 'block_configurable_reports')
);
$mform->addElement('checkbox', 'displaytotalrecords', get_string('displaytotalrecords', 'block_configurable_reports'), get_string('displaytotalrecordsdescription', 'block_configurable_reports'));
$mform->addElement('checkbox', 'displayprintbutton', get_string('displayprintbutton', 'block_configurable_reports'), get_string('displayprintbuttondescription', 'block_configurable_reports'));

$mform->addElement('checkbox', 'cron', get_string('cron', 'block_configurable_reports'), get_string('crondescription', 'block_configurable_reports'));
$mform->addHelpButton('cron', 'cron', 'block_configurable_reports');
$mform->setDefault('cron', 0);
$mform->disabledIf('cron', 'type', 'neq', 'sql');
Expand All @@ -116,6 +114,24 @@ public function definition(): void {
$mform->addHelpButton('remote', 'remote', 'block_configurable_reports');
$mform->setDefault('remote', 0);

// Adds an embed link for easy copy/paste once the report is saved.
if (isset($this->_customdata['report']->id) && $this->_customdata['report']->id) {

$params = [
'id' => $this->_customdata['report']->id,
'courseid' => $this->_customdata['courseid'],
'embed' => true
];
$url = new \moodle_url('/blocks/configurable_reports/viewreport.php', $params);

$mform->addElement('static', 'embedlink',
get_string('embedlink', 'block_configurable_reports'),
html_writer::tag('pre', $url, ['class' => 'mb-0']).
get_string('embedlinkdescription', 'block_configurable_reports')
);
}


$mform->addElement('header', 'exportoptions', get_string('exportoptions', 'block_configurable_reports'));
$options = cr_get_export_plugins();

Expand All @@ -140,8 +156,14 @@ public function definition(): void {
$mform->setType('courseid', PARAM_INT);
}

// Submit button string.
$submitstring = get_string('add');
if (!empty($this->_customdata['report']->id)) {
$submitstring = get_string('update');
}

// Buttons.
$this->add_action_buttons(true, get_string('add'));
$this->add_action_buttons(true, $submitstring);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions lang/en/block_configurable_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
$string['configurable_reports:viewreports'] = "View reports";

$string['exportoptions'] = "Export options";
$string['embedoptions'] = "Embed options";
$string['field'] = "Field";

// Report form.
Expand All @@ -77,6 +78,12 @@
$string['jsordering'] = 'JavaScript Ordering';
$string['cron'] = 'Auto run daily';
$string['crondescription'] = 'Schedule this query to run each day (At night)';
$string['displaytotalrecords'] = 'Total Records';
$string['displaytotalrecordsdescription'] = 'Displays the total number of results in the report';
$string['displayprintbutton'] = 'Print Button';
$string['displayprintbuttondescription'] = 'Displays the print button at the bottom of the report';
$string['embedlink'] = 'Embed Link';
$string['embedlinkdescription'] = 'You can copy this link to embed the report in an HTML block';
$string['cron_help'] = 'Schedule this query to run each day (At night)';
$string['remote'] = 'Run on remote db';
$string['remotedescription'] = 'Do you want to run this query on the remote db';
Expand Down
34 changes: 20 additions & 14 deletions report.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,11 @@ public function print_template($config, moodle_page $moodlepage): void {
echo format_text($pagecontents['header'], FORMAT_HTML);
}

$a = new stdClass();
$a->totalrecords = $this->totalrecords;
echo html_writer::tag('div', get_string('totalrecords', 'block_configurable_reports', $a), ['id' => 'totalrecords']);
if ($this->config->displaytotalrecords) {
$a = new \stdClass();
$a->totalrecords = $this->totalrecords;
echo \html_writer::tag('div', get_string('totalrecords', 'block_configurable_reports', $a), array('id' => 'totalrecords'));
}

if ($recordtpl) {
if ($this->config->pagination) {
Expand Down Expand Up @@ -897,11 +899,12 @@ public function print_template($config, moodle_page $moodlepage): void {
}

echo "</div>\n";
echo '<div class="centerpara"><br />';
echo $OUTPUT->pix_icon('print', get_string('printreport', 'block_configurable_reports'), 'block_configurable_reports');
echo "&nbsp;<a href=\"javascript: printDiv('printablediv')\">" . get_string('printreport', 'block_configurable_reports') .
"</a>";
echo "</div>\n";
if ($this->config->displayprintbutton) {
echo '<div class="centerpara"><br />';
echo $OUTPUT->pix_icon('print', get_string('printreport', 'block_configurable_reports'), 'block_configurable_reports');
echo "&nbsp;<a href=\"javascript: printDiv('printablediv')\">".get_string('printreport', 'block_configurable_reports')."</a>";
echo "</div>\n";
}
}

/**
Expand All @@ -913,7 +916,9 @@ public function print_template($config, moodle_page $moodlepage): void {
public function print_report_page(moodle_page $moodlepage) {
global $OUTPUT;

cr_print_js_function();
if ($this->config->displayprintbutton) {
cr_print_js_function();
}
$components = cr_unserialize($this->config->components);

$template = (isset($components['template']['config']) && $components['template']['config']->enabled &&
Expand Down Expand Up @@ -1011,11 +1016,12 @@ public function print_report_page(moodle_page $moodlepage) {
echo '<div class="centerpara">' . get_string('norecordsfound', 'block_configurable_reports') . '</div>';
}

echo '<div class="centerpara"><br />';
echo $OUTPUT->pix_icon('print', get_string('printreport', 'block_configurable_reports'), 'block_configurable_reports');
echo "&nbsp;<a href=\"javascript: printDiv('printablediv')\">" . get_string('printreport', 'block_configurable_reports') .
"</a>";
echo "</div>\n";
if ($this->config->displayprintbutton) {
echo '<div class="centerpara"><br />';
echo $OUTPUT->pix_icon('print', get_string('printreport', 'block_configurable_reports'), 'block_configurable_reports');
echo "&nbsp;<a href=\"javascript: printDiv('printablediv')\">".get_string('printreport', 'block_configurable_reports')."</a>";
echo "</div>\n";
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion viewreport.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$download = optional_param('download', false, PARAM_BOOL);
$format = optional_param('format', '', PARAM_ALPHA);
$courseid = optional_param('courseid', null, PARAM_INT);
$embed = optional_param('embed', false, PARAM_BOOL);

if (!$report = $DB->get_record('block_configurable_reports', ['id' => $id])) {
throw new moodle_exception('reportdoesnotexists', 'block_configurable_reports');
Expand Down Expand Up @@ -100,9 +101,13 @@
$PAGE->set_title($reportname);
$PAGE->set_heading($reportname);
$PAGE->set_cacheable(true);
if ($embed) {
$PAGE->set_pagelayout('embedded');
}
echo $OUTPUT->header();

if ($hasmanageallcap || ($hasmanageowncap && $report->ownerid == $USER->id)) {
$canmanage = ($hasmanageallcap || ($hasmanageowncap && $report->ownerid == $USER->id));
if (!$embed && $canmanage) {
$currenttab = 'viewreport';
include('tabs.php');
}
Expand Down

0 comments on commit 6292431

Please sign in to comment.