mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-75137-master' of https://github.com/aanabit/moodle
This commit is contained in:
commit
e550cb5bba
@ -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})';
|
||||
|
@ -982,6 +982,12 @@ class mod_data_external extends external_api {
|
||||
$fieldnotifications = array();
|
||||
|
||||
list($database, $course, $cm, $context) = self::validate_database($params['databaseid']);
|
||||
|
||||
$fields = $DB->get_records('data_fields', ['dataid' => $database->id]);
|
||||
if (empty($fields)) {
|
||||
throw new moodle_exception('nofieldindatabase', 'data');
|
||||
}
|
||||
|
||||
// Check database is open in time.
|
||||
data_require_time_available($database, null, $context);
|
||||
|
||||
@ -1009,7 +1015,6 @@ class mod_data_external extends external_api {
|
||||
$datarecord->{'field_' . $data['fieldid'] . $subfield} = json_decode($data['value']);
|
||||
}
|
||||
// Validate to ensure that enough data was submitted.
|
||||
$fields = $DB->get_records('data_fields', array('dataid' => $database->id));
|
||||
$processeddata = data_process_submission($database, $fields, $datarecord);
|
||||
|
||||
// Format notifications.
|
||||
|
@ -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';
|
||||
|
@ -2139,7 +2139,12 @@ function data_print_header($course, $cm, $data, $currenttab='', string $actionba
|
||||
* @return bool
|
||||
*/
|
||||
function data_user_can_add_entry($data, $currentgroup, $groupmode, $context = null) {
|
||||
global $USER;
|
||||
global $DB;
|
||||
|
||||
// Don't let add entry to a database that has no fields.
|
||||
if (!$DB->record_exists('data_fields', ['dataid' => $data->id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($context)) {
|
||||
$cm = get_coursemodule_from_instance('data', $data->id, 0, false, MUST_EXIST);
|
||||
|
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>
|
@ -73,7 +73,7 @@ Feature: Users can add entries to database activities
|
||||
And I press "Select all"
|
||||
And I press "Delete selected"
|
||||
And I press "Delete"
|
||||
And I should see "No entries in database"
|
||||
And I should see "No entries yet"
|
||||
|
||||
@javascript @editor @editor_atto @atto @atto_h5p
|
||||
Scenario: If a new text area entry is added, the filepicker is displayed in the H5P Atto button
|
||||
@ -128,3 +128,21 @@ Feature: Users can add entries to database activities
|
||||
And I log out
|
||||
When I am on the "Test database name" "data activity" page logged in as "guest"
|
||||
Then I should not see "Add entry"
|
||||
|
||||
@javascript
|
||||
Scenario Outline: Users see the Add entry button in the view page when some field has been created only.
|
||||
Given I am on the "Test database name" "data activity" page logged in as <user>
|
||||
And I should not see "Add entry"
|
||||
When I log out
|
||||
And I am on the "Test database name" "data activity" page logged in as teacher1
|
||||
And I add a "Text input" field to "Test database name" database and I fill the form with:
|
||||
| Field name | Test field name |
|
||||
| Field description | Test field description |
|
||||
And I log out
|
||||
And I am on the "Test database name" "data activity" page logged in as <user>
|
||||
Then I should see "Add entry"
|
||||
|
||||
Examples:
|
||||
| user |
|
||||
| teacher1 |
|
||||
| student1 |
|
||||
|
@ -42,6 +42,10 @@ Feature: View activity completion in the database activity
|
||||
|
||||
Scenario: View automatic completion items as a teacher
|
||||
Given I am on the "Music history" "data activity" page logged in as teacher1
|
||||
# We add an entry to let the user change to a different view.
|
||||
When I add an entry to "Music history" database with:
|
||||
| Instrument types | Drums |
|
||||
And I press "Save"
|
||||
Then "Music history" should have the "View" completion condition
|
||||
And "Music history" should have the "Make entries: 2" completion condition
|
||||
And "Music history" should have the "Receive a grade" completion condition
|
||||
|
@ -55,9 +55,11 @@ Feature: Completion pass grade
|
||||
And I log out
|
||||
|
||||
Scenario: View automatic completion items as a teacher
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
When I follow "Music history"
|
||||
Given I am on the "Music history" "data activity" page logged in as teacher1
|
||||
# We add an entry to let the user change to a different view.
|
||||
When I add an entry to "Music history" database with:
|
||||
| Instrument types | Drums |
|
||||
And I press "Save"
|
||||
Then "Music history" should have the "View" completion condition
|
||||
And "Music history" should have the "Make entries: 2" completion condition
|
||||
And "Music history" should have the "Receive a grade" completion condition
|
||||
|
@ -151,7 +151,7 @@ Feature: Users can be required to specify certain fields when adding entries to
|
||||
And ".alert" "css_element" should not exist in the "Not required Multimenu" "table_row"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Test database name"
|
||||
And I should see "No entries in database"
|
||||
And I should see "No entries yet"
|
||||
|
||||
Scenario: Students recieve no error for filled in required fields
|
||||
When I log in as "student1"
|
||||
|
31
mod/data/tests/behat/zero_state.feature
Normal file
31
mod/data/tests/behat/zero_state.feature
Normal file
@ -0,0 +1,31 @@
|
||||
@mod @mod_data
|
||||
Feature: Zero state page (no fields created)
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| data | Test database name | n | C1 | data1 |
|
||||
|
||||
@javascript
|
||||
Scenario: Teachers see buttons to manage database when there is no field created
|
||||
Given I am on the "Test database name" "data activity" page logged in as "teacher1"
|
||||
And "Import a preset" "button" should exist
|
||||
When I click on "Import a preset" "button"
|
||||
Then I should see "Import from zip file"
|
||||
And I am on the "Test database name" "data activity" page
|
||||
And "Create a new field" "button" should exist
|
||||
And I click on "Create a new field" "button"
|
||||
And I should see "Manage fields"
|
||||
And I am on the "Test database name" "data activity" page
|
||||
And "Use preset" "button" should exist
|
||||
And I click on "Use preset" "button"
|
||||
And I should see "Presets"
|
@ -113,6 +113,21 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
groups_add_member($this->group2, $this->student3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a test field to the database activity instance to be used in the unit tests.
|
||||
*
|
||||
* @return \data_field_base
|
||||
*/
|
||||
protected function add_test_field(): \data_field_base {
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_data');
|
||||
|
||||
// Add fields.
|
||||
$fieldrecord = new \stdClass();
|
||||
$fieldrecord->name = 'Test field'; // Identifier of the records for testing.
|
||||
$fieldrecord->type = 'text';
|
||||
return $generator->create_field($fieldrecord, $this->database);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get databases by courses
|
||||
*/
|
||||
@ -321,6 +336,10 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
*/
|
||||
public function test_get_data_access_information_student() {
|
||||
global $DB;
|
||||
|
||||
// Add a field to database to let users add new entries.
|
||||
$this->add_test_field();
|
||||
|
||||
// Modify the database to add access restrictions.
|
||||
$this->database->timeavailablefrom = time() + DAYSECS;
|
||||
$this->database->requiredentries = 2;
|
||||
@ -350,6 +369,10 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
*/
|
||||
public function test_get_data_access_information_teacher() {
|
||||
global $DB;
|
||||
|
||||
// Add a field to database to let users add new entries.
|
||||
$this->add_test_field();
|
||||
|
||||
// Modify the database to add access restrictions.
|
||||
$this->database->timeavailablefrom = time() + DAYSECS;
|
||||
$this->database->requiredentries = 2;
|
||||
@ -380,6 +403,9 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
public function test_get_data_access_information_groups() {
|
||||
global $DB;
|
||||
|
||||
// Add a field to database to let users add new entries.
|
||||
$this->add_test_field();
|
||||
|
||||
$DB->set_field('course', 'groupmode', VISIBLEGROUPS, ['id' => $this->course->id]);
|
||||
|
||||
// Check I can see my group.
|
||||
@ -1088,6 +1114,10 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
* Test add_entry empty_form.
|
||||
*/
|
||||
public function test_add_entry_empty_form() {
|
||||
|
||||
// Add a field to database to let users add new entries.
|
||||
$this->add_test_field();
|
||||
|
||||
$result = mod_data_external::add_entry($this->database->id, 0, []);
|
||||
$result = \external_api::clean_returnvalue(mod_data_external::add_entry_returns(), $result);
|
||||
$this->assertEquals(0, $result['newentryid']);
|
||||
@ -1133,12 +1163,26 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
* Test add_entry invalid group.
|
||||
*/
|
||||
public function test_add_entry_invalid_group() {
|
||||
|
||||
// Add a field to database to let users add new entries.
|
||||
$this->add_test_field();
|
||||
|
||||
$this->setUser($this->student1);
|
||||
$this->expectExceptionMessage(get_string('noaccess', 'data'));
|
||||
$this->expectException('moodle_exception');
|
||||
mod_data_external::add_entry($this->database->id, $this->group2->id, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add_entry for an empty database (no fields).
|
||||
*
|
||||
* @covers \mod_data\mod_data_external::add_entry
|
||||
*/
|
||||
public function test_add_entry_empty_database() {
|
||||
$this->expectException('moodle_exception');
|
||||
mod_data_external::add_entry($this->database->id, 0, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update_entry.
|
||||
*/
|
||||
|
@ -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().
|
||||
*
|
||||
|
@ -13,6 +13,8 @@ information provided here is intended especially for developers.
|
||||
- data_presets_generate_xml
|
||||
- data_presets_save
|
||||
- is_directory_a_preset
|
||||
* mod_data_external::add_entry() function throws an error when trying to add an entry to a database with no field created.
|
||||
* data_user_can_add_entry() function returns false for any user if there is no field created on the database.
|
||||
|
||||
=== 3.7 ===
|
||||
* External functions get_entries, get_entry and search_entries now return an additional field "tags" containing the entry tags.
|
||||
|
@ -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…
x
Reference in New Issue
Block a user