MDL-75137 mod_data: Redesign zero state page

Co-authored-by: Ferran Recio <ferran@moodle.com>
This commit is contained in:
Amaia Anabitarte 2022-07-13 19:02:12 +02:00
parent cb01747608
commit 8768a7adb9
14 changed files with 527 additions and 20 deletions

View file

@ -38,6 +38,7 @@ $string['activityiscurrentlyhidden'] = 'Sorry, this activity is currently hidden
$string['activityheader'] = 'Activity menu'; $string['activityheader'] = 'Activity menu';
$string['activitymodule'] = 'Activity module'; $string['activitymodule'] = 'Activity module';
$string['activitymodules'] = 'Activity modules'; $string['activitymodules'] = 'Activity modules';
$string['activitynotready'] = 'Activity not ready yet';
$string['activityreport'] = 'Activity report'; $string['activityreport'] = 'Activity report';
$string['activityreports'] = 'Activity reports'; $string['activityreports'] = 'Activity reports';
$string['activityselect'] = 'Select this activity to be moved elsewhere'; $string['activityselect'] = 'Select this activity to be moved elsewhere';
@ -267,6 +268,7 @@ $string['closebuttontitle'] = 'Close';
$string['collapse'] = 'Collapse'; $string['collapse'] = 'Collapse';
$string['collapseall'] = 'Collapse all'; $string['collapseall'] = 'Collapse all';
$string['collapsecategory'] = 'Collapse {$a}'; $string['collapsecategory'] = 'Collapse {$a}';
$string['comebacklater'] = 'Please come back later.';
$string['commentincontext'] = 'Find this comment in context'; $string['commentincontext'] = 'Find this comment in context';
$string['comments'] = 'Comments'; $string['comments'] = 'Comments';
$string['commentscount'] = 'Comments ({$a})'; $string['commentscount'] = 'Comments ({$a})';

View file

@ -192,6 +192,19 @@ class manager {
$event->trigger(); $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. * Return the database fields.
* *

View 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;
}
}

View 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;
}
}

View file

@ -64,16 +64,8 @@ class view_action_bar implements templatable, renderable {
'urlselect' => $this->urlselect->export_for_template($output), 'urlselect' => $this->urlselect->export_for_template($output),
]; ];
$database = $DB->get_record('data', ['id' => $this->id]); $addentrybutton = new add_entries_action($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); $data['addentrybutton'] = $addentrybutton->export_for_template($output);
}
if (has_capability('mod/data:manageentries', $PAGE->context)) { if (has_capability('mod/data:manageentries', $PAGE->context)) {
$importentrieslink = new moodle_url('/mod/data/import.php', $importentrieslink = new moodle_url('/mod/data/import.php',

View 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;
}
}

View file

@ -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['confirmdeletefield'] = 'You are about to delete this field, are you sure?';
$string['confirmdeleterecord'] = 'Are you sure you want to delete this entry?'; $string['confirmdeleterecord'] = 'Are you sure you want to delete this entry?';
$string['confirmdeleterecords'] = 'Are you sure you want to delete these entries?'; $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['csstemplate'] = 'CSS template';
$string['csvfailed'] = 'Unable to read the raw data from the CSV file'; $string['csvfailed'] = 'Unable to read the raw data from the CSV file';
$string['csvfile'] = '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['nolisttemplate'] = 'List template is not yet defined';
$string['nomatch'] = 'No matching entries found!'; $string['nomatch'] = 'No matching entries found!';
$string['nomaximum'] = 'No maximum'; $string['nomaximum'] = 'No maximum';
$string['norecords'] = 'No entries in database'; $string['norecords'] = 'No entries yet';
$string['nosingletemplate'] = 'Single template is not yet defined'; $string['nosingletemplate'] = 'Single template is not yet defined';
$string['notapproved'] = 'Entry is not approved yet.'; $string['notapproved'] = 'Entry is not approved yet.';
$string['notinjectivemap'] = 'Not an injective map'; $string['notinjectivemap'] = 'Not an injective map';
@ -389,6 +390,7 @@ $string['showall'] = 'Show all entries';
$string['single'] = 'View single'; $string['single'] = 'View single';
$string['singleview'] = 'Single view'; $string['singleview'] = 'Single view';
$string['singletemplate'] = 'Single template'; $string['singletemplate'] = 'Single template';
$string['startbuilding'] = 'Start building your activity';
$string['subplugintype_datafield'] = 'Database field type'; $string['subplugintype_datafield'] = 'Database field type';
$string['subplugintype_datafield_plural'] = 'Database field types'; $string['subplugintype_datafield_plural'] = 'Database field types';
$string['subplugintype_datapreset'] = 'Preset'; $string['subplugintype_datapreset'] = 'Preset';
@ -407,6 +409,7 @@ $string['timemodified'] = 'Time modified';
$string['todatabase'] = 'to this database.'; $string['todatabase'] = 'to this database.';
$string['type'] = 'Field type'; $string['type'] = 'Field type';
$string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action "{$a}".'; $string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action "{$a}".';
$string['underconstruction_title'] = 'Under construction';
$string['unsupportedfields'] = 'Unsupported fields'; $string['unsupportedfields'] = 'Unsupported fields';
$string['unsupportedfieldslist'] = 'The following fields cannot be exported:'; $string['unsupportedfieldslist'] = 'The following fields cannot be exported:';
$string['updatefield'] = 'Update an existing field'; $string['updatefield'] = 'Update an existing field';

41
mod/data/pix/nofields.svg Normal file
View 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

View file

@ -139,4 +139,42 @@ class mod_data_renderer extends plugin_renderer_base {
$data = $presets->export_for_template($this); $data = $presets->export_for_template($this);
return $this->render_from_template('mod_data/presets', $data); 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);
}
} }

View 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>

View 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>

View file

@ -163,6 +163,32 @@ class manager_test extends \advanced_testcase {
$this->assertNotEmpty($event->get_name()); $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(). * Test for get_available_presets().
* *

View file

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die(); 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->requires = 2022041200; // Requires this Moodle version.
$plugin->component = 'mod_data'; // Full name of the plugin (used for diagnostics) $plugin->component = 'mod_data'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0; $plugin->cron = 0;

View file

@ -72,14 +72,6 @@ comment::init();
require_capability('mod/data:viewentry', $context); 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 /// Check further parameters that set browsing preferences
if (!isset($SESSION->dataprefs)) { if (!isset($SESSION->dataprefs)) {
$SESSION->dataprefs = array(); $SESSION->dataprefs = array();
@ -247,6 +239,15 @@ $groupmode = groups_get_activity_groupmode($cm);
$canmanageentries = has_capability('mod/data:manageentries', $context); $canmanageentries = has_capability('mod/data:manageentries', $context);
echo $OUTPUT->header(); 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. // Detect entries not approved yet and show hint instead of not found error.
if ($record and !data_can_view_record($data, $record, $currentgroup, $canmanageentries)) { if ($record and !data_can_view_record($data, $record, $currentgroup, $canmanageentries)) {
throw new \moodle_exception('notapproved', 'data'); 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); data_search_entries($data, $cm, $context, $mode, $currentgroup, $search, $sort, $order, $page, $perpage, $advanced, $search_array, $record);
$hasrecords = !empty($records); $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); $actionbar = new \mod_data\output\action_bar($data->id, $pageurl);
echo $actionbar->get_view_action_bar($hasrecords); echo $actionbar->get_view_action_bar($hasrecords);