Add new Outcome element (#329)
This commit is contained in:
parent
4679c79e37
commit
3e26a6b7c1
5 changed files with 288 additions and 0 deletions
158
element/outcome/classes/element.php
Normal file
158
element/outcome/classes/element.php
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for 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/>.
|
||||
|
||||
/**
|
||||
* This file contains the customcert element outcome's core interaction API.
|
||||
*
|
||||
* @package customcertelement_outcome
|
||||
* @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace customcertelement_outcome;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The customcert element outcome's core interaction API.
|
||||
*
|
||||
* @package customcertelement_outcome
|
||||
* @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class element extends \mod_customcert\element {
|
||||
|
||||
/**
|
||||
* This function renders the form elements when adding a customcert element.
|
||||
*
|
||||
* @param \MoodleQuickForm $mform the edit_form instance
|
||||
*/
|
||||
public function render_form_elements($mform) {
|
||||
global $COURSE;
|
||||
|
||||
// Get grade items with outcomes/scales attached to them.
|
||||
$gradeitems = \grade_item::fetch_all(
|
||||
[
|
||||
'courseid' => $COURSE->id,
|
||||
'gradetype' => GRADE_TYPE_SCALE
|
||||
]
|
||||
);
|
||||
|
||||
$selectoutcomes = [];
|
||||
foreach ($gradeitems as $gradeitem) {
|
||||
// Get the name of the activity.
|
||||
$cm = get_coursemodule_from_instance($gradeitem->itemmodule, $gradeitem->iteminstance, $COURSE->id);
|
||||
$modcontext = \context_module::instance($cm->id);
|
||||
$modname = format_string($cm->name, true, array('context' => $modcontext));
|
||||
|
||||
$optionname = $modname . " - " . $gradeitem->get_name();
|
||||
$selectoutcomes[$gradeitem->id] = $optionname;
|
||||
}
|
||||
asort($selectoutcomes);
|
||||
|
||||
$mform->addElement('select', 'gradeitem', get_string('outcome', 'customcertelement_outcome'), $selectoutcomes);
|
||||
|
||||
parent::render_form_elements($mform);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will handle how form data will be saved into the data column in the
|
||||
* customcert_elements table.
|
||||
*
|
||||
* @param \stdClass $data the form data
|
||||
* @return string the json encoded array
|
||||
*/
|
||||
public function save_unique_data($data) {
|
||||
if (!empty($data->gradeitem)) {
|
||||
return $data->gradeitem;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles rendering the element on the pdf.
|
||||
*
|
||||
* @param \pdf $pdf the pdf object
|
||||
* @param bool $preview true if it is a preview, false otherwise
|
||||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gradeitem = \grade_item::fetch(['id' => $this->get_data()]);
|
||||
|
||||
if ($preview) {
|
||||
// Get the outcome.
|
||||
$outcome = \grade_outcome::fetch(['id' => $gradeitem->outcomeid]);
|
||||
|
||||
$display = $outcome->get_name();
|
||||
} else {
|
||||
// Get the grade.
|
||||
$grade = new \grade_grade(
|
||||
[
|
||||
'itemid' => $gradeitem->id,
|
||||
'userid' => $user->id
|
||||
]
|
||||
);
|
||||
|
||||
$display = grade_format_gradevalue($grade->finalgrade, $gradeitem);
|
||||
}
|
||||
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, $display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the element in html.
|
||||
*
|
||||
* This function is used to render the element when we are using the
|
||||
* drag and drop interface to position it.
|
||||
*
|
||||
* @return string the html
|
||||
*/
|
||||
public function render_html() {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->get_data())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get the grade item.
|
||||
$gradeitem = \grade_item::fetch(['id' => $this->get_data()]);
|
||||
|
||||
// Get the outcome.
|
||||
$outcome = \grade_outcome::fetch(['id' => $gradeitem->outcomeid]);
|
||||
|
||||
return \mod_customcert\element_helper::render_html_content($this, $outcome->get_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data on the form when editing an element.
|
||||
*
|
||||
* @param \MoodleQuickForm $mform the edit_form instance
|
||||
*/
|
||||
public function definition_after_data($mform) {
|
||||
// Set the item and format for this element.
|
||||
if (!empty($this->get_data())) {
|
||||
$element = $mform->getElement('gradeitem');
|
||||
$element->setValue($this->get_data());
|
||||
}
|
||||
|
||||
parent::definition_after_data($mform);
|
||||
}
|
||||
}
|
46
element/outcome/classes/privacy/provider.php
Normal file
46
element/outcome/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Privacy Subsystem implementation for customcertelement_outcome.
|
||||
*
|
||||
* @package customcertelement_outcome
|
||||
* @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace customcertelement_outcome\privacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Privacy Subsystem for customcertelement_outcome implementing null_provider.
|
||||
*
|
||||
* @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements \core_privacy\local\metadata\null_provider {
|
||||
|
||||
/**
|
||||
* Get the language string identifier with the component's language
|
||||
* file to explain why this plugin stores no data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_reason() : string {
|
||||
return 'privacy:metadata';
|
||||
}
|
||||
}
|
27
element/outcome/lang/en/customcertelement_outcome.php
Normal file
27
element/outcome/lang/en/customcertelement_outcome.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for 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/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'customcertelement_outcome', language 'en'.
|
||||
*
|
||||
* @package customcertelement_outcome
|
||||
* @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['outcome'] = 'Outcome';
|
||||
$string['pluginname'] = 'Outcome';
|
||||
$string['privacy:metadata'] = 'The Outcome plugin does not store any personal data.';
|
29
element/outcome/version.php
Normal file
29
element/outcome/version.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for 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/>.
|
||||
|
||||
/**
|
||||
* This file contains the version information for the outcome plugin.
|
||||
*
|
||||
* @package customcertelement_outcome
|
||||
* @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
$plugin->version = 2019111800; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2019111800; // Requires this Moodle version (3.8).
|
||||
$plugin->component = 'customcertelement_outcome';
|
|
@ -21,6 +21,14 @@ Feature: Being able to manage elements in a certificate template
|
|||
| assign | Assignment 1 | Assignment 1 intro | C1 | assign1 |
|
||||
| assign | Assignment 2 | Assignment 2 intro | C1 | assign2 |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
And the following config values are set as admin:
|
||||
| enableoutcomes | 1 |
|
||||
And the following "scales" exist:
|
||||
| name | scale |
|
||||
| Test Scale | Disappointing, Good, Very good, Excellent |
|
||||
And the following "grade outcomes" exist:
|
||||
| fullname | shortname | course | scale |
|
||||
| Outcome 1 | OT1 | C1 | Test Scale |
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
|
@ -251,6 +259,26 @@ Feature: Being able to manage elements in a certificate template
|
|||
| Height | 15 |
|
||||
| Alpha channel | 0.7 |
|
||||
And I press "Save changes"
|
||||
# Outcome.
|
||||
And I add the element "Outcome" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Outcome | Outcome 1 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Date" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Outcome" "table_row"
|
||||
And the following fields match these values:
|
||||
| Outcome | Outcome 1 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Student name.
|
||||
And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
|
|
Loading…
Reference in a new issue