mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-75137 mod_data: Redesign zero state page
Co-authored-by: Ferran Recio <ferran@moodle.com>
This commit is contained in:
parent
cb01747608
commit
8768a7adb9
14 changed files with 527 additions and 20 deletions
|
@ -38,6 +38,7 @@ $string['activityiscurrentlyhidden'] = 'Sorry, this activity is currently hidden
|
|||
$string['activityheader'] = 'Activity menu';
|
||||
$string['activitymodule'] = 'Activity module';
|
||||
$string['activitymodules'] = 'Activity modules';
|
||||
$string['activitynotready'] = 'Activity not ready yet';
|
||||
$string['activityreport'] = 'Activity report';
|
||||
$string['activityreports'] = 'Activity reports';
|
||||
$string['activityselect'] = 'Select this activity to be moved elsewhere';
|
||||
|
@ -267,6 +268,7 @@ $string['closebuttontitle'] = 'Close';
|
|||
$string['collapse'] = 'Collapse';
|
||||
$string['collapseall'] = 'Collapse all';
|
||||
$string['collapsecategory'] = 'Collapse {$a}';
|
||||
$string['comebacklater'] = 'Please come back later.';
|
||||
$string['commentincontext'] = 'Find this comment in context';
|
||||
$string['comments'] = 'Comments';
|
||||
$string['commentscount'] = 'Comments ({$a})';
|
||||
|
|
|
@ -192,6 +192,19 @@ class manager {
|
|||
$event->trigger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the database has fields.
|
||||
*
|
||||
* @return bool true if the database has fields
|
||||
*/
|
||||
public function has_fields(): bool {
|
||||
global $DB;
|
||||
if ($this->_fieldrecords === null) {
|
||||
return $DB->record_exists('data_fields', ['dataid' => $this->instance->id]);
|
||||
}
|
||||
return !empty($this->_fieldrecords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the database fields.
|
||||
*
|
||||
|
|
67
mod/data/classes/output/add_entries_action.php
Normal file
67
mod/data/classes/output/add_entries_action.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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 moodle_url;
|
||||
use templatable;
|
||||
use renderable;
|
||||
|
||||
/**
|
||||
* Renderable class for the Add entries button in the database activity.
|
||||
*
|
||||
* @package mod_data
|
||||
* @copyright 2022 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class add_entries_action implements templatable, renderable {
|
||||
|
||||
/** @var int $id The database module id. */
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @param int $id The database module id.
|
||||
* @param bool $hasentries Whether entries exist.
|
||||
*/
|
||||
public function __construct(int $id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the data for the mustache template.
|
||||
*
|
||||
* @param \renderer_base $output The renderer to be used to render the add entries button.
|
||||
* @return \stdClass or null if the user has no permission to add new entries.
|
||||
*/
|
||||
public function export_for_template(\renderer_base $output): ?\stdClass {
|
||||
global $PAGE, $DB;
|
||||
|
||||
$database = $DB->get_record('data', ['id' => $this->id]);
|
||||
$cm = get_coursemodule_from_instance('data', $this->id);
|
||||
$currentgroup = groups_get_activity_group($cm);
|
||||
$groupmode = groups_get_activity_groupmode($cm);
|
||||
|
||||
if (data_user_can_add_entry($database, $currentgroup, $groupmode, $PAGE->context)) {
|
||||
$addentrylink = new moodle_url('/mod/data/edit.php', ['d' => $this->id, 'backto' => $PAGE->url->out(false)]);
|
||||
$button = new \single_button($addentrylink, get_string('add', 'mod_data'), 'get', true);
|
||||
return $button->export_for_template($output);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
70
mod/data/classes/output/empty_database_action_bar.php
Normal file
70
mod/data/classes/output/empty_database_action_bar.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?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 mod_data\manager;
|
||||
use moodle_url;
|
||||
use templatable;
|
||||
use renderable;
|
||||
|
||||
/**
|
||||
* Renderable class for the action bar elements for an empty database activity.
|
||||
*
|
||||
* @package mod_data
|
||||
* @copyright 2022 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class empty_database_action_bar implements templatable, renderable {
|
||||
|
||||
/** @var manager The manager instance. */
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @param int $id The database module id.
|
||||
*/
|
||||
public function __construct(manager $manager) {
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$instance = $this->manager->get_instance();
|
||||
$addentrybutton = new add_entries_action($instance->id);
|
||||
$data = ['addentrybutton' => $addentrybutton->export_for_template($output)];
|
||||
|
||||
if (has_capability('mod/data:manageentries', $PAGE->context)) {
|
||||
$params = ['d' => $instance->id, 'backto' => $PAGE->url->out(false)];
|
||||
|
||||
$importentrieslink = new moodle_url('/mod/data/import.php', $params);
|
||||
$importentriesbutton = new \single_button($importentrieslink,
|
||||
get_string('importentries', 'mod_data'), 'get', false);
|
||||
$data['importentriesbutton'] = $importentriesbutton->export_for_template($output);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -64,16 +64,8 @@ class view_action_bar implements templatable, renderable {
|
|||
'urlselect' => $this->urlselect->export_for_template($output),
|
||||
];
|
||||
|
||||
$database = $DB->get_record('data', ['id' => $this->id]);
|
||||
$cm = get_coursemodule_from_instance('data', $this->id);
|
||||
$currentgroup = groups_get_activity_group($cm);
|
||||
$groupmode = groups_get_activity_groupmode($cm);
|
||||
|
||||
if (data_user_can_add_entry($database, $currentgroup, $groupmode, $PAGE->context)) {
|
||||
$addentrylink = new moodle_url('/mod/data/edit.php', ['d' => $this->id, 'backto' => $PAGE->url->out(false)]);
|
||||
$addentrybutton = new \single_button($addentrylink, get_string('add', 'mod_data'), 'get', true);
|
||||
$data['addentrybutton'] = $addentrybutton->export_for_template($output);
|
||||
}
|
||||
$addentrybutton = new add_entries_action($this->id);
|
||||
$data['addentrybutton'] = $addentrybutton->export_for_template($output);
|
||||
|
||||
if (has_capability('mod/data:manageentries', $PAGE->context)) {
|
||||
$importentrieslink = new moodle_url('/mod/data/import.php',
|
||||
|
|
79
mod/data/classes/output/zero_state_action_bar.php
Normal file
79
mod/data/classes/output/zero_state_action_bar.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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 mod_data\manager;
|
||||
use moodle_url;
|
||||
use templatable;
|
||||
use renderable;
|
||||
|
||||
/**
|
||||
* Renderable class for the action bar elements in the zero state (no fields created) pages in the database activity.
|
||||
*
|
||||
* @package mod_data
|
||||
* @copyright 2022 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class zero_state_action_bar implements templatable, renderable {
|
||||
|
||||
/** @var manager The manager instance. */
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @param manager $manager The manager instance.
|
||||
*/
|
||||
public function __construct(manager $manager) {
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$data = [];
|
||||
if (has_capability('mod/data:managetemplates', $PAGE->context)) {
|
||||
$instance = $this->manager->get_instance();
|
||||
$params = ['d' => $instance->id, 'backto' => $PAGE->url->out(false)];
|
||||
|
||||
$usepresetlink = new moodle_url('/mod/data/preset.php', $params);
|
||||
$usepresetbutton = new \single_button($usepresetlink,
|
||||
get_string('usepreset', 'mod_data'), 'get', true);
|
||||
$data['usepresetbutton'] = $usepresetbutton->export_for_template($output);
|
||||
|
||||
$createfieldlink = new moodle_url('/mod/data/field.php', $params);
|
||||
$createfieldbutton = new \single_button($createfieldlink,
|
||||
get_string('newfield', 'mod_data'), 'get', false);
|
||||
$data['createfieldbutton'] = $createfieldbutton->export_for_template($output);
|
||||
|
||||
$params['action'] = 'import';
|
||||
$importpresetlink = new moodle_url('/mod/data/preset.php', $params);
|
||||
$importpresetbutton = new \single_button($importpresetlink,
|
||||
get_string('importpreset', 'mod_data'), 'get', false);
|
||||
$data['importpresetbutton'] = $importpresetbutton->export_for_template($output);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -78,6 +78,7 @@ $string['configenablerssfeeds'] = 'This switch will enable the possibility of RS
|
|||
$string['confirmdeletefield'] = 'You are about to delete this field, are you sure?';
|
||||
$string['confirmdeleterecord'] = 'Are you sure you want to delete this entry?';
|
||||
$string['confirmdeleterecords'] = 'Are you sure you want to delete these entries?';
|
||||
$string['createfields'] = 'Create your own fields to collect data, or use a preset which includes fields already.';
|
||||
$string['csstemplate'] = 'CSS template';
|
||||
$string['csvfailed'] = 'Unable to read the raw data from the CSV file';
|
||||
$string['csvfile'] = 'CSV file';
|
||||
|
@ -293,7 +294,7 @@ $string['nofieldindatabase'] = 'There are no fields defined for this database.';
|
|||
$string['nolisttemplate'] = 'List template is not yet defined';
|
||||
$string['nomatch'] = 'No matching entries found!';
|
||||
$string['nomaximum'] = 'No maximum';
|
||||
$string['norecords'] = 'No entries in database';
|
||||
$string['norecords'] = 'No entries yet';
|
||||
$string['nosingletemplate'] = 'Single template is not yet defined';
|
||||
$string['notapproved'] = 'Entry is not approved yet.';
|
||||
$string['notinjectivemap'] = 'Not an injective map';
|
||||
|
@ -389,6 +390,7 @@ $string['showall'] = 'Show all entries';
|
|||
$string['single'] = 'View single';
|
||||
$string['singleview'] = 'Single view';
|
||||
$string['singletemplate'] = 'Single template';
|
||||
$string['startbuilding'] = 'Start building your activity';
|
||||
$string['subplugintype_datafield'] = 'Database field type';
|
||||
$string['subplugintype_datafield_plural'] = 'Database field types';
|
||||
$string['subplugintype_datapreset'] = 'Preset';
|
||||
|
@ -407,6 +409,7 @@ $string['timemodified'] = 'Time modified';
|
|||
$string['todatabase'] = 'to this database.';
|
||||
$string['type'] = 'Field type';
|
||||
$string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action "{$a}".';
|
||||
$string['underconstruction_title'] = 'Under construction';
|
||||
$string['unsupportedfields'] = 'Unsupported fields';
|
||||
$string['unsupportedfieldslist'] = 'The following fields cannot be exported:';
|
||||
$string['updatefield'] = 'Update an existing field';
|
||||
|
|
41
mod/data/pix/nofields.svg
Normal file
41
mod/data/pix/nofields.svg
Normal file
|
@ -0,0 +1,41 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="157 -1509 148 125" preserveAspectRatio="xMinYMid meet">
|
||||
<defs>
|
||||
<style>
|
||||
.cls-1 {
|
||||
clip-path: url(#clip-Activities);
|
||||
}
|
||||
|
||||
.cls-2 {
|
||||
fill: #eee;
|
||||
}
|
||||
|
||||
.cls-3 {
|
||||
fill: #c4c8cc;
|
||||
}
|
||||
|
||||
.cls-4 {
|
||||
fill: #fff;
|
||||
}
|
||||
</style>
|
||||
<clipPath id="clip-Activities">
|
||||
<rect x="157" y="-1509" width="148" height="125"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g id="Activities" class="cls-1">
|
||||
<g id="Group_42" data-name="Group 42" transform="translate(-268 -1985)">
|
||||
<ellipse id="Ellipse_37" data-name="Ellipse 37" class="cls-2" cx="74" cy="14.785" rx="74" ry="14.785" transform="translate(425 571.43)"/>
|
||||
<rect id="Rectangle_80" data-name="Rectangle 80" class="cls-3" width="94.182" height="110.215" transform="translate(451.909 476)"/>
|
||||
<g id="Group_41" data-name="Group 41" transform="translate(467.043 493)">
|
||||
<rect id="Rectangle_81" data-name="Rectangle 81" class="cls-4" width="44.456" height="5.625" transform="translate(21.16 0.549)"/>
|
||||
<rect id="Rectangle_82" data-name="Rectangle 82" class="cls-4" width="33.342" height="5.625" transform="translate(21.16 11.652)"/>
|
||||
<rect id="Rectangle_83" data-name="Rectangle 83" class="cls-4" width="44.456" height="5.625" transform="translate(21.16 30.772)"/>
|
||||
<rect id="Rectangle_84" data-name="Rectangle 84" class="cls-4" width="33.342" height="5.625" transform="translate(21.16 41.875)"/>
|
||||
<rect id="Rectangle_85" data-name="Rectangle 85" class="cls-4" width="44.456" height="5.625" transform="translate(21.16 61.291)"/>
|
||||
<rect id="Rectangle_86" data-name="Rectangle 86" class="cls-4" width="33.342" height="5.625" transform="translate(21.16 72.393)"/>
|
||||
<ellipse id="Ellipse_38" data-name="Ellipse 38" class="cls-4" cx="7.007" cy="7" rx="7.007" ry="7" transform="translate(0 0)"/>
|
||||
<ellipse id="Ellipse_39" data-name="Ellipse 39" class="cls-4" cx="7.007" cy="7" rx="7.007" ry="7" transform="translate(0 31)"/>
|
||||
<ellipse id="Ellipse_40" data-name="Ellipse 40" class="cls-4" cx="7.007" cy="7" rx="7.007" ry="7" transform="translate(0 61)"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.2 KiB |
|
@ -139,4 +139,42 @@ class mod_data_renderer extends plugin_renderer_base {
|
|||
$data = $presets->export_for_template($this);
|
||||
return $this->render_from_template('mod_data/presets', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the action bar for the zero state (no fields created) page.
|
||||
*
|
||||
* @param \mod_data\manager $manager The manager instance.
|
||||
*
|
||||
* @return string The HTML output
|
||||
*/
|
||||
public function render_zero_state(\mod_data\manager $manager): string {
|
||||
$actionbar = new \mod_data\output\zero_state_action_bar($manager);
|
||||
$data = $actionbar->export_for_template($this);
|
||||
if (empty($data)) {
|
||||
// No actions for the user.
|
||||
$data['title'] = get_string('activitynotready');
|
||||
$data['intro'] = get_string('comebacklater');
|
||||
} else {
|
||||
$data['title'] = get_string('startbuilding', 'mod_data');
|
||||
$data['intro'] = get_string('createfields', 'mod_data');
|
||||
}
|
||||
$data['noitemsimgurl'] = $this->output->image_url('nofields', 'mod_data')->out();
|
||||
|
||||
return $this->render_from_template('mod_data/zero_state', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the action bar for an empty database view page.
|
||||
*
|
||||
* @param \mod_data\manager $manager The manager instance.
|
||||
*
|
||||
* @return string The HTML output
|
||||
*/
|
||||
public function render_empty_database(\mod_data\manager $manager): string {
|
||||
$actionbar = new \mod_data\output\empty_database_action_bar($manager);
|
||||
$data = $actionbar->export_for_template($this);
|
||||
$data['noitemsimgurl'] = $this->output->image_url('nofields', 'mod_data')->out();
|
||||
|
||||
return $this->render_from_template('mod_data/view_noentries', $data);
|
||||
}
|
||||
}
|
||||
|
|
74
mod/data/templates/view_noentries.mustache
Normal file
74
mod/data/templates/view_noentries.mustache
Normal file
|
@ -0,0 +1,74 @@
|
|||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_data/view_no_fields_nomanagers
|
||||
|
||||
Form containing all database presets displayed within a table.
|
||||
|
||||
Context variables required for this template:
|
||||
* noitemsimgurl - The image url.
|
||||
* importentriesbutton stdClass - Import entries single button to be rendered
|
||||
* addentrybutton stdClass - Add entry single button to be rendered
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"noitemsimgurl": "https://moodlesite/theme/image.php/boost/mod_data/1535727318/nofields",
|
||||
"importentriesbutton": {
|
||||
"id" : "id1",
|
||||
"method" : "get",
|
||||
"url" : "#",
|
||||
"primary" : false,
|
||||
"tooltip" : "This is a tooltip",
|
||||
"label" : "Button1",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "data-attribute",
|
||||
"value": "no"
|
||||
}
|
||||
]
|
||||
},
|
||||
"addentrybutton": {
|
||||
"id" : "id2",
|
||||
"method" : "get",
|
||||
"url" : "#",
|
||||
"primary" : true,
|
||||
"tooltip" : "This is a tooltip",
|
||||
"label" : "Button2",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "data-attribute",
|
||||
"value": "yeah"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}}
|
||||
<div class="text-xs-center text-center mt-4" data-region="empty-message">
|
||||
<img
|
||||
src="{{noitemsimgurl}}"
|
||||
alt="{{#str}} norecords, mod_data {{/str}}"
|
||||
role="presentation"
|
||||
style="height: 70px; width: 70px;"
|
||||
>
|
||||
<h5 class="h5 mt-3 mb-0">{{#str}} norecords, mod_data {{/str}}</h5>
|
||||
|
||||
<div class="mt-5 mb-0" id="action_bar">
|
||||
{{#importentriesbutton}}
|
||||
{{> core/single_button }}
|
||||
{{/importentriesbutton}}
|
||||
{{#addentrybutton}}
|
||||
{{> core/single_button }}
|
||||
{{/addentrybutton}}
|
||||
</div>
|
||||
</div>
|
93
mod/data/templates/zero_state.mustache
Normal file
93
mod/data/templates/zero_state.mustache
Normal file
|
@ -0,0 +1,93 @@
|
|||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_data/zero_state
|
||||
|
||||
Form containing all database presets displayed within a table.
|
||||
|
||||
Context variables required for this template:
|
||||
* noitemsimgurl - The image url.
|
||||
* importpresetbutton stdClass - Import preset single button to be rendered
|
||||
* createfieldbutton stdClass - Create a new field single button to be rendered
|
||||
* usepresetbutton stdClass - Use a preset single button to be rendered
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"noitemsimgurl": "https://moodlesite/theme/image.php/boost/mod_data/1535727318/nofields",
|
||||
"importpresetbutton": {
|
||||
"id" : "id1",
|
||||
"method" : "get",
|
||||
"url" : "#",
|
||||
"primary" : false,
|
||||
"tooltip" : "This is a tooltip",
|
||||
"label" : "Button1",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "data-attribute",
|
||||
"value": "no"
|
||||
}
|
||||
]
|
||||
},
|
||||
"createfieldbutton": {
|
||||
"id" : "id2",
|
||||
"method" : "get",
|
||||
"url" : "#",
|
||||
"primary" : true,
|
||||
"tooltip" : "This is a tooltip",
|
||||
"label" : "Button2",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "data-attribute",
|
||||
"value": "yeah"
|
||||
}
|
||||
]
|
||||
},
|
||||
"usepresetbutton": {
|
||||
"id" : "id3",
|
||||
"method" : "get",
|
||||
"url" : "#",
|
||||
"primary" : false,
|
||||
"tooltip" : "This is a tooltip",
|
||||
"label" : "Button3",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "data-attribute",
|
||||
"value": "perhaps"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}}
|
||||
<div class="text-xs-center text-center mt-4" data-region="empty-message">
|
||||
<img
|
||||
src="{{noitemsimgurl}}"
|
||||
alt="{{{ title }}}"
|
||||
role="presentation"
|
||||
style="height: 70px; width: 70px;"
|
||||
>
|
||||
<h5 class="h5 mt-3 mb-0">{{{ title }}}</h5>
|
||||
<p class="mt-3 mb-0">{{{ intro }}}</p>
|
||||
|
||||
<div class="mt-5 mb-0" id="action_bar">
|
||||
{{#importpresetbutton}}
|
||||
{{>core/single_button}}
|
||||
{{/importpresetbutton}}
|
||||
{{#createfieldbutton}}
|
||||
{{>core/single_button}}
|
||||
{{/createfieldbutton}}
|
||||
{{#usepresetbutton}}
|
||||
{{>core/single_button}}
|
||||
{{/usepresetbutton}}
|
||||
</div>
|
||||
</div>
|
|
@ -163,6 +163,32 @@ class manager_test extends \advanced_testcase {
|
|||
$this->assertNotEmpty($event->get_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for has_fields().
|
||||
*
|
||||
* @covers ::has_fields
|
||||
*/
|
||||
public function test_has_fields() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$activity = $this->getDataGenerator()->create_module(manager::MODULE, ['course' => $course]);
|
||||
$manager = manager::create_from_instance($activity);
|
||||
|
||||
// Empty database should return false.
|
||||
$this->assertFalse($manager->has_fields());
|
||||
|
||||
// Add a field to the activity.
|
||||
$datagenerator = $this->getDataGenerator()->get_plugin_generator('mod_data');
|
||||
$fieldrecord = new \stdClass();
|
||||
$fieldrecord->name = 'field1';
|
||||
$fieldrecord->type = 'text';
|
||||
$datagenerator->create_field($fieldrecord, $activity);
|
||||
|
||||
// Database with fields should return true.
|
||||
$this->assertTrue($manager->has_fields());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_available_presets().
|
||||
*
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2022041900; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2022071201; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2022041200; // Requires this Moodle version.
|
||||
$plugin->component = 'mod_data'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->cron = 0;
|
||||
|
|
|
@ -72,14 +72,6 @@ comment::init();
|
|||
|
||||
require_capability('mod/data:viewentry', $context);
|
||||
|
||||
/// If we have an empty Database then redirect because this page is useless without data
|
||||
if (has_capability('mod/data:managetemplates', $context)) {
|
||||
if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database!
|
||||
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Check further parameters that set browsing preferences
|
||||
if (!isset($SESSION->dataprefs)) {
|
||||
$SESSION->dataprefs = array();
|
||||
|
@ -247,6 +239,15 @@ $groupmode = groups_get_activity_groupmode($cm);
|
|||
$canmanageentries = has_capability('mod/data:manageentries', $context);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if (!$manager->has_fields()) {
|
||||
// It's a brand-new database. There are no fields.
|
||||
$renderer = $PAGE->get_renderer('mod_data');
|
||||
echo $renderer->render_zero_state($manager);
|
||||
echo $OUTPUT->footer();
|
||||
// Don't check the rest of the options. There is no field, there is nothing else to work with.
|
||||
exit;
|
||||
}
|
||||
|
||||
// Detect entries not approved yet and show hint instead of not found error.
|
||||
if ($record and !data_can_view_record($data, $record, $currentgroup, $canmanageentries)) {
|
||||
throw new \moodle_exception('notapproved', 'data');
|
||||
|
@ -385,6 +386,14 @@ if ($showactivity) {
|
|||
data_search_entries($data, $cm, $context, $mode, $currentgroup, $search, $sort, $order, $page, $perpage, $advanced, $search_array, $record);
|
||||
$hasrecords = !empty($records);
|
||||
|
||||
if ($maxcount == 0) {
|
||||
$renderer = $PAGE->get_renderer('mod_data');
|
||||
echo $renderer->render_empty_database($manager);
|
||||
echo $OUTPUT->footer();
|
||||
// There is no entry, so makes no sense to check different views, pagination, etc.
|
||||
exit;
|
||||
}
|
||||
|
||||
$actionbar = new \mod_data\output\action_bar($data->id, $pageurl);
|
||||
echo $actionbar->get_view_action_bar($hasrecords);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue