mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-75401-master-integration' of https://github.com/fer…
- Loading branch information
Showing
34 changed files
with
891 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?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 core\output; | ||
|
||
use renderable; | ||
|
||
/** | ||
* Class to render a sticky footer element. | ||
* | ||
* Sticky footer can be rendered at any moment if the page (even inside a form) but | ||
* it will be displayed at the bottom of the page. | ||
* | ||
* Important: note that pages can only display one sticky footer at once. | ||
* | ||
* Important: not all themes are compatible with sticky footer. If the current theme | ||
* is not compatible it will be rendered as a standard div element. | ||
* | ||
* @package core | ||
* @category output | ||
* @copyright 2022 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class sticky_footer implements named_templatable, renderable { | ||
|
||
/** | ||
* @var string content of the sticky footer. | ||
*/ | ||
protected $stickycontent = ''; | ||
|
||
/** | ||
* @var string extra CSS classes. By default, elements are justified to the end. | ||
*/ | ||
protected $stickyclasses = 'justify-content-end'; | ||
|
||
/** | ||
* @var array extra HTML attributes (attribute => value). | ||
*/ | ||
protected $attributes = []; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $stickycontent the footer content | ||
* @param string|null $stickyclasses extra CSS classes | ||
* @param array $attributes extra html attributes (attribute => value) | ||
*/ | ||
public function __construct(string $stickycontent = '', ?string $stickyclasses = null, array $attributes = []) { | ||
$this->stickycontent = $stickycontent; | ||
if ($stickyclasses !== null) { | ||
$this->stickyclasses = $stickyclasses; | ||
} | ||
$this->attributes = $attributes; | ||
} | ||
|
||
/** | ||
* Set the footer contents. | ||
* | ||
* @param string $stickycontent the footer content | ||
*/ | ||
public function set_content(string $stickycontent) { | ||
$this->stickycontent = $stickycontent; | ||
} | ||
|
||
/** | ||
* Add extra classes to the sticky footer. | ||
* | ||
* @param string $stickyclasses the extra classes | ||
*/ | ||
public function add_classes(string $stickyclasses) { | ||
if (!empty($this->stickyclasses)) { | ||
$this->stickyclasses .= ' '; | ||
} | ||
$this->stickyclasses = $stickyclasses; | ||
} | ||
|
||
/** | ||
* Add extra attributes to the sticky footer element. | ||
* | ||
* @param string $atribute the attribute | ||
* @param string $value the value | ||
*/ | ||
public function add_attribute(string $atribute, string $value) { | ||
$this->attributes[$atribute] = $value; | ||
} | ||
|
||
/** | ||
* Export this data so it can be used as the context for a mustache template (core/inplace_editable). | ||
* | ||
* @param renderer_base $output typically, the renderer that's calling this function | ||
* @return array data context for a mustache template | ||
*/ | ||
public function export_for_template(\renderer_base $output) { | ||
$extras = []; | ||
foreach ($this->attributes as $attribute => $value) { | ||
$extras[] = [ | ||
'attribute' => $attribute, | ||
'value' => $value, | ||
]; | ||
} | ||
return [ | ||
'stickycontent' => (string)$this->stickycontent, | ||
'stickyclasses' => $this->stickyclasses, | ||
'extras' => $extras, | ||
]; | ||
} | ||
|
||
/** | ||
* Get the name of the template to use for this templatable. | ||
* | ||
* @param \renderer_base $renderer The renderer requesting the template name | ||
* @return string the template name | ||
*/ | ||
public function get_template_name(\renderer_base $renderer): string { | ||
return 'core/sticky_footer'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{{! | ||
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 core/sticky_footer | ||
Displays a page sticky footer element. | ||
Sticky footer behaviour depends on the theme. The default template is | ||
a regular element. | ||
Example context (json): | ||
{ | ||
"stickycontent" : "<a href=\"#\">Moodle</a>", | ||
"extras" : [ | ||
{ | ||
"attribute" : "data-example", | ||
"value" : "stickyfooter" | ||
} | ||
], | ||
"stickyclasses" : "extraclasses" | ||
} | ||
}} | ||
<div | ||
id="sticky-footer" | ||
class="{{$ stickyclasses }}{{stickyclasses}}{{/ stickyclasses }}" | ||
{{#extras}} | ||
{{attribute}}="{{value}}" | ||
{{/extras}} | ||
> | ||
{{$ stickycontent }} | ||
{{{stickycontent}}} | ||
{{/ stickycontent }} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?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 action_link; | ||
use core\output\sticky_footer; | ||
use html_writer; | ||
use mod_data\manager; | ||
use mod_data\template; | ||
use moodle_url; | ||
use renderer_base; | ||
|
||
/** | ||
* Renderable class for sticky footer in the view pages of the database activity. | ||
* | ||
* @package mod_data | ||
* @copyright 2022 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class view_footer extends sticky_footer { | ||
|
||
/** @var int $totalcount the total records count. */ | ||
private $totalcount; | ||
|
||
/** @var int $currentpage the current page */ | ||
private $currentpage; | ||
|
||
/** @var int $nowperpage the number of elements per page */ | ||
private $nowperpage; | ||
|
||
/** @var moodle_url $baseurl the page base url */ | ||
private $baseurl; | ||
|
||
/** @var template $parser the template name */ | ||
private $parser; | ||
|
||
/** @var manager $manager if the user can manage capabilities or not */ | ||
private $manager; | ||
|
||
/** | ||
* The class constructor. | ||
* | ||
* @param manager $manager the activity manager | ||
* @param int $totalcount the total records count | ||
* @param int $currentpage the current page | ||
* @param int $nowperpage the number of elements per page | ||
* @param moodle_url $baseurl the page base url | ||
* @param template $parser the current template name | ||
*/ | ||
public function __construct( | ||
manager $manager, | ||
int $totalcount, | ||
int $currentpage, | ||
int $nowperpage, | ||
moodle_url $baseurl, | ||
template $parser | ||
) { | ||
$this->manager = $manager; | ||
$this->totalcount = $totalcount; | ||
$this->currentpage = $currentpage; | ||
$this->nowperpage = $nowperpage; | ||
$this->baseurl = $baseurl; | ||
$this->parser = $parser; | ||
} | ||
|
||
/** | ||
* Export this data so it can be used as the context for a mustache template (core/inplace_editable). | ||
* | ||
* @param renderer_base $output typically, the renderer that's calling this function | ||
* @return array data context for a mustache template | ||
*/ | ||
public function export_for_template(renderer_base $output) { | ||
$this->set_content( | ||
$this->get_footer_output($output) | ||
); | ||
return parent::export_for_template($output); | ||
} | ||
|
||
/** | ||
* Generate the pre-rendered footer content. | ||
* | ||
* @param \renderer_base $output The renderer to be used to render the action bar elements. | ||
* @return string the rendered content | ||
*/ | ||
public function get_footer_output(renderer_base $output): string { | ||
$data = []; | ||
|
||
$cm = $this->manager->get_coursemodule(); | ||
$instance = $this->manager->get_instance(); | ||
$currentgroup = groups_get_activity_group($cm); | ||
$groupmode = groups_get_activity_groupmode($cm); | ||
$context = $this->manager->get_context(); | ||
$canmanageentries = has_capability('mod/data:manageentries', $context); | ||
$parser = $this->parser; | ||
|
||
// Sticky footer content. | ||
$data['pagination'] = $output->paging_bar( | ||
$this->totalcount, | ||
$this->currentpage, | ||
$this->nowperpage, | ||
$this->baseurl | ||
); | ||
|
||
if ($parser->get_template_name() != 'singletemplate' && $canmanageentries) { | ||
// Build the select/deselect all control. | ||
$selectallid = 'selectall-listview-entries'; | ||
$togglegroup = 'listview-entries'; | ||
$mastercheckbox = new \core\output\checkbox_toggleall($togglegroup, true, [ | ||
'id' => $selectallid, | ||
'name' => $selectallid, | ||
'value' => 1, | ||
'label' => get_string('selectall'), | ||
'classes' => 'btn-secondary mr-1', | ||
], true); | ||
$data['selectall'] = $output->render($mastercheckbox); | ||
|
||
$data['deleteselected'] = html_writer::empty_tag('input', [ | ||
'class' => 'btn btn-secondary', | ||
'type' => 'submit', | ||
'value' => get_string('deleteselected'), | ||
'disabled' => true, | ||
'data-action' => 'toggle', | ||
'data-togglegroup' => $togglegroup, | ||
'data-toggle' => 'action', | ||
]); | ||
} | ||
if (data_user_can_add_entry($instance, $currentgroup, $groupmode, $context)) { | ||
$addentrylink = new moodle_url( | ||
'/mod/data/edit.php', | ||
['id' => $cm->id, 'backto' => $this->baseurl] | ||
); | ||
$addentrybutton = new action_link( | ||
$addentrylink, | ||
get_string('add', 'mod_data'), | ||
null, | ||
['class' => 'btn btn-primary', 'role' => 'button'] | ||
); | ||
$data['addentrybutton'] = $addentrybutton->export_for_template($output); | ||
} | ||
return $output->render_from_template('mod_data/view_footer', $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.