Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view page: fully templated #130

Open
wants to merge 1 commit into
base: V3.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions classes/output/homelink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
//
// VPL for 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.
//
// VPL for 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* Class for mod_vpl home link widget
*
* @package mod_vpl
* @copyright 2022 CDO-Global
* @author Valentin Afanasev
*/

namespace mod_vpl\output;

defined('MOODLE_INTERNAL') || die();
require_once("{$CFG->dirroot}/mod/vpl/locallib.php");

use renderer_base;

class homelink implements \renderable, \templatable {
public function export_for_template(renderer_base $output) {
return [
'version' => vpl_get_version(),
];
}
}
144 changes: 144 additions & 0 deletions classes/output/infoblock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
//
// VPL for 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.
//
// VPL for 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* Class for mod_vpl infoblock widget
*
* @package mod_vpl
* @copyright 2022 CDO-Global
* @author Valentin Afanasev
*/

namespace mod_vpl\output;

defined('MOODLE_INTERNAL') || die();
require_once("{$CFG->dirroot}/mod/vpl/locallib.php");
require_once("{$CFG->dirroot}/mod/vpl/vpl.class.php");

use renderer_base;
use mod_vpl;
use html_writer;

class infoblock implements \renderable, \templatable {
private mod_vpl $vpl;
private int $userid;

public function __construct(mod_vpl $vpl, int $userid) {
$this->vpl = $vpl;
$this->userid = $userid;
}

public function export_for_template(renderer_base $output) {
global $CFG;
$requestedfiles = null;
$filegroup = $this->vpl->get_required_fgm();
$files = $filegroup->getfilelist();
if (count( $files )) {
$requestedfiles = [
'text' => join(', ', $files),
'href' => vpl_mod_href(
'views/downloadrequiredfiles.php', 'id', $this->vpl->get_course_module()->id,
),
];
}
$instance = $this->vpl->get_instance();
$maxfiles = null;
if (count($files) != $instance->maxfiles) {
$maxfiles = $instance->maxfiles;
}
$maxfilesize = null;
if ($instance->maxfilesize) {
$maxfilesize = vpl_conv_size_to_string(
$this->vpl->get_maxfilesize()
);
}
$grader = $this->vpl->has_capability( VPL_GRADE_CAPABILITY );
$grademax = null;
$gradehidden = null;
$gradelocked = null;
$nograde = true;
$gradetypescale = false;
if ($grader) {
require_once("{$CFG->libdir}/gradelib.php");
if ($gie = $this->vpl->get_grade_info()) {
$nograde = false;
if ($gie->scaleid == 0) {
$grademax = format_float($gie->grademax, 5, true, true);
$gradehidden = $gie->hidden;
$gradelocked = $gie->locked;
} else {
$gradetypescale = true;
}
}
}
$reductionbyevaluation = $this->vpl->get_effective_setting(
'reductionbyevaluation',
$this->userid,
);
$freeevaluations = null;
if ($reductionbyevaluation) {
$freeevaluations = $this->vpl->get_effective_setting(
'freeevaluations',
$this->userid,
);
}
$graderextra = [];
if ($grader) {
if (!$this->vpl->get_course_module()->visible) {
$graderextra['hidden'] = true;
}
if ($instance->basedon) {
try {
$basedon = new mod_vpl( null, $instance->basedon );
$graderextra['basedon'] = html_writer::link(
vpl_mod_href('view.php', 'id', $basedon->cm->id),
$basedon->get_printable_name(),
);
} catch (Exception $e) {
$graderextra['basedon'] = $e->getMessage();
}
}
if ($instance->maxexememory) {
$graderextra['maxexememory'] = vpl_conv_size_to_string($instance->maxexememory);
}
if ($instance->maxexefilesize) {
$graderextra['maxexefilesize'] = vpl_conv_size_to_string($instance->maxexefilesize);
}
}

return [
'startdate' => $this->vpl->get_effective_setting('startdate', $this->userid),
'duedate' => $this->vpl->get_effective_setting('duedate', $this->userid),
'requestedfiles' => $requestedfiles,
'maxfiles' => $maxfiles,
'maxfilesize' => $maxfilesize,
'instance' => $instance,
'grader' => $grader,
'nograde' => $nograde,
'grademax' => $grademax,
'gradehidden' => $gradehidden,
'gradelocked' => $gradelocked,
'gradetypescale' => $gradetypescale,
'reductionbyevaluation' => $reductionbyevaluation,
'freeevaluations' => $freeevaluations,
'graderextra' => $graderextra,
'variation' => $this->vpl->get_variation_html($this->userid),
'fulldescription' => $this->vpl->get_fulldescription_with_basedon(),
'shortdescription' => format_text($instance->shortdescription, FORMAT_PLAIN),
];
}
}
33 changes: 33 additions & 0 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
//
// VPL for 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.
//
// VPL for 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* Class for mod_vpl renderer
*
* @package mod_vpl
* @copyright 2022 CDO-Global
* @author Valentin Afanasev
*/

namespace mod_vpl\output;

defined('MOODLE_INTERNAL') || die();

use plugin_renderer_base;
use renderable;

class renderer extends plugin_renderer_base {}
146 changes: 146 additions & 0 deletions classes/output/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
//
// VPL for 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.
//
// VPL for 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* Class for mod_vpl view page
*
* @package mod_vpl
* @copyright 2022 CDO-Global
* @author Valentin Afanasev
*/

namespace mod_vpl\output;

defined('MOODLE_INTERNAL') || die();
require_once("{$CFG->dirroot}/mod/vpl/locallib.php");
require_once("{$CFG->dirroot}/mod/vpl/vpl.class.php");

use renderer_base;
use mod_vpl;

class view implements \renderable, \templatable {
private $vpl;
private $userid;

/**
* Constructor for renderable
*
* @param mod_vpl $vpl
* @param int $userid
* @return void
*/
public function __construct(mod_vpl $vpl, int $userid) {
$this->vpl = $vpl;
$this->userid = $userid;
}

/**
* export_for_template
*
* @param renderer_base $output
* @return array
*/
public function export_for_template(renderer_base $output) {
global $CFG;
$showfr = false;
$fr_files = '';
$fr = $this->vpl->get_required_fgm();
if ( $fr->is_populated() ) {
$showfr = true;
ob_start();
$fr->print_files(false);
$fr_files = ob_get_clean();
}

$showfe = false;
$fe_files = '';
$fe = $this->vpl->get_execution_fgm();
if ( $this->vpl->has_capability( VPL_GRADE_CAPABILITY ) &&
$fe->is_populated() ) {
$showfe = true;
ob_start();
$fe->print_files(false);
$fe_files = ob_get_clean();
}
if ( $showfr || $showfe ) {
require_once("{$CFG->dirroot}/mod/vpl/views/sh_factory.class.php");
\vpl_sh_factory::include_js();
}

return [
'tabs' => $this->get_tabs($output),
'heading' => $this->get_heading($output),
'infoblock' => $this->get_infoblock($output),
'showfe' => $showfe,
'showfr' => $showfr,
'fe_files' => $fe_files,
'fr_files' => $fr_files,
'cmid' => $this->vpl->get_course_module()->id,
'ws_available' => vpl_get_webservice_available(),
'homelink' => $this->get_homelink($output),
];
}

/**
* Get heading for page
*
* @param renderer_base $output
* @return string
*/
protected function get_heading(renderer_base $output) {
ob_start();
$this->vpl->print_name();
return ob_get_clean();
}

/**
* Get html for infoblock
*
* @param renderer_base $output
* @return string
*/
protected function get_infoblock(renderer_base $output) {
return $output->render(new infoblock($this->vpl, $this->userid));
}

/**
* Get html for tabs
*
* @param renderer_base $output
* @param string
*/
protected function get_tabs(renderer_base $output) {
ob_start();
$this->vpl->print_view_tabs( basename( __FILE__ ) );
return ob_get_clean();
}

/**
* Get html for home link
*
* @param renderer_base $output
* @return string
*/
protected function get_homelink(renderer_base $output) {
$inst = $this->vpl->get_instance();
if ($inst->sebrequired || $inst->sebkeys > '') {
return '';
}
return $output->render(new homelink());
}
}

9 changes: 9 additions & 0 deletions templates/homelink.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{!
vim: ts=2 sts=2 sw=2 syntax=mustache
@template: mod_vpl/homelink

Show VPL homelink
}}
<div style="float:right; right:10px; padding:8px; background-color: white;text-align:center;">
<a href="http://vpl.dis.ulpgc.es/">VPL {{version}}</a>
</div>
Loading