61e8b806ec
On the Database page: - The List/single view is displayed in the right. - The buttons Import entries, export entries and Export to portfolio have been moved to the Actions menu. - The List/Single view headings have been removed. - The "Save settings" secondary button is hidden when advanced search is enabled. - The result (Found X out of Y entries, No records found) are not displayed as notifications anymore. On the Presets page: - The buttons (Import, Export and Save as preset) have been moved to an actions menu to the tertiary navigation. Some of these options have been renamed. - Remove the Action column heading from the table. On the Presets preview page: - Move the preset name to the heading in the tertiary navigation (Preview of xxxxx), and remove the current preset name from the page. - Align the List/single template to the right in the tertiary navigation. - Make primary the "Use this preset" button. On the Fields page: - Remove the "Manage fields" menu. - Remove the Export and Save as preset from the tertiary navigation. - Align Create a field to the right in the tertiary navigation. - Add a description at the top of the page. - Remove the Action column heading from the table. - Move field actions (Edit and Delete) to ellipsis. On the Templates page: - Move Export and Save as preset to the Actions menu. - Move the templates list to a tertiary navigation selector and remove the template heading. - Reorder the templates list (Add entry template should be displayed at the begining, instead of List template). - Rename "Enable editor" to "Enable code editor".
149 lines
5.4 KiB
PHP
149 lines
5.4 KiB
PHP
<?php
|
|
// This file is part of Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
namespace mod_data\output;
|
|
|
|
use data_portfolio_caller;
|
|
use mod_data\manager;
|
|
use moodle_url;
|
|
use portfolio_add_button;
|
|
use templatable;
|
|
use renderable;
|
|
|
|
/**
|
|
* Renderable class for the action bar elements in the view pages in the database activity.
|
|
*
|
|
* @package mod_data
|
|
* @copyright 2021 Mihail Geshoski <mihail@moodle.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class view_action_bar implements templatable, renderable {
|
|
|
|
/** @var int $id The database module id. */
|
|
private $id;
|
|
|
|
/** @var \url_select $urlselect The URL selector object. */
|
|
private $urlselect;
|
|
|
|
/** @var bool $hasentries Whether entries exist. */
|
|
private $hasentries;
|
|
|
|
/** @var bool $mode The current view mode (list, view...). */
|
|
private $mode;
|
|
|
|
/**
|
|
* The class constructor.
|
|
*
|
|
* @param int $id The database module id.
|
|
* @param \url_select $urlselect The URL selector object.
|
|
* @param bool $hasentries Whether entries exist.
|
|
* @param string $mode The current view mode (list, view...).
|
|
*/
|
|
public function __construct(int $id, \url_select $urlselect, bool $hasentries, string $mode) {
|
|
$this->id = $id;
|
|
$this->urlselect = $urlselect;
|
|
$this->hasentries = $hasentries;
|
|
$this->mode = $mode;
|
|
}
|
|
|
|
/**
|
|
* Export the data for the mustache template.
|
|
*
|
|
* @param \renderer_base $output The renderer to be used to render the action bar elements.
|
|
* @return array
|
|
*/
|
|
public function export_for_template(\renderer_base $output): array {
|
|
global $PAGE, $DB, $CFG;
|
|
|
|
$data = [
|
|
'urlselect' => $this->urlselect->export_for_template($output),
|
|
];
|
|
|
|
$activity = $DB->get_record('data', ['id' => $this->id], '*', MUST_EXIST);
|
|
$manager = manager::create_from_instance($activity);
|
|
|
|
$actionsselect = null;
|
|
// Import entries.
|
|
if (has_capability('mod/data:manageentries', $manager->get_context())) {
|
|
$actionsselect = new \action_menu();
|
|
$actionsselect->set_menu_trigger(get_string('actions'), 'btn btn-secondary');
|
|
|
|
$importentrieslink = new moodle_url('/mod/data/import.php', ['d' => $this->id, 'backto' => $PAGE->url->out(false)]);
|
|
$actionsselect->add(new \action_menu_link(
|
|
$importentrieslink,
|
|
null,
|
|
get_string('importentries', 'mod_data'),
|
|
false
|
|
));
|
|
}
|
|
|
|
// Export entries.
|
|
if (has_capability(DATA_CAP_EXPORT, $manager->get_context()) && $this->hasentries) {
|
|
if (!$actionsselect) {
|
|
$actionsselect = new \action_menu();
|
|
$actionsselect->set_menu_trigger(get_string('actions'), 'btn btn-secondary');
|
|
}
|
|
$exportentrieslink = new moodle_url('/mod/data/export.php', ['d' => $this->id, 'backto' => $PAGE->url->out(false)]);
|
|
$actionsselect->add(new \action_menu_link(
|
|
$exportentrieslink,
|
|
null,
|
|
get_string('exportentries', 'mod_data'),
|
|
false
|
|
));
|
|
}
|
|
|
|
// Export to portfolio. This is for exporting all records, not just the ones in the search.
|
|
if ($this->mode == '' && !empty($CFG->enableportfolios) && $this->hasentries) {
|
|
if ($manager->can_export_entries()) {
|
|
// Add the portfolio export button.
|
|
require_once($CFG->libdir . '/portfoliolib.php');
|
|
|
|
$cm = $manager->get_coursemodule();
|
|
|
|
$button = new portfolio_add_button();
|
|
$button->set_callback_options(
|
|
'data_portfolio_caller',
|
|
['id' => $cm->id],
|
|
'mod_data'
|
|
);
|
|
if (data_portfolio_caller::has_files($activity)) {
|
|
// No plain HTML.
|
|
$button->set_formats([PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A]);
|
|
}
|
|
$exporturl = $button->to_html(PORTFOLIO_ADD_MOODLE_URL);
|
|
if (!is_null($exporturl)) {
|
|
if (!$actionsselect) {
|
|
$actionsselect = new \action_menu();
|
|
$actionsselect->set_menu_trigger(get_string('actions'), 'btn btn-secondary');
|
|
}
|
|
$actionsselect->add(new \action_menu_link(
|
|
$exporturl,
|
|
null,
|
|
get_string('addtoportfolio', 'portfolio'),
|
|
false
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($actionsselect) {
|
|
$data['actionsselect'] = $actionsselect->export_for_template($output);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|