diff --git a/element/outcome/classes/element.php b/element/outcome/classes/element.php new file mode 100644 index 0000000..1306aa8 --- /dev/null +++ b/element/outcome/classes/element.php @@ -0,0 +1,158 @@ +. + +/** + * This file contains the customcert element outcome's core interaction API. + * + * @package customcertelement_outcome + * @copyright 2020 Mark Nelson + * @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 + * @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); + } +} diff --git a/element/outcome/classes/privacy/provider.php b/element/outcome/classes/privacy/provider.php new file mode 100644 index 0000000..4077741 --- /dev/null +++ b/element/outcome/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_outcome. + * + * @package customcertelement_outcome + * @copyright 2020 Mark Nelson + * @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 + * @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'; + } +} diff --git a/element/outcome/lang/en/customcertelement_outcome.php b/element/outcome/lang/en/customcertelement_outcome.php new file mode 100644 index 0000000..7610174 --- /dev/null +++ b/element/outcome/lang/en/customcertelement_outcome.php @@ -0,0 +1,27 @@ +. + +/** + * Strings for component 'customcertelement_outcome', language 'en'. + * + * @package customcertelement_outcome + * @copyright 2020 Mark Nelson + * @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.'; \ No newline at end of file diff --git a/element/outcome/version.php b/element/outcome/version.php new file mode 100644 index 0000000..175d6c3 --- /dev/null +++ b/element/outcome/version.php @@ -0,0 +1,29 @@ +. + +/** + * This file contains the version information for the outcome plugin. + * + * @package customcertelement_outcome + * @copyright 2020 Mark Nelson + * @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'; diff --git a/tests/behat/managing_elements.feature b/tests/behat/managing_elements.feature index 43d1cce..cf53b75 100644 --- a/tests/behat/managing_elements.feature +++ b/tests/behat/managing_elements.feature @@ -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: