From e185f72d58192682322dbb8222203037187c5d48 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 30 Jul 2013 17:21:13 +0800 Subject: [PATCH] MDL-39954 core: Abstract event assessable_submitted & assessable_uploaded --- lib/classes/event/assessable_submitted.php | 67 ++++++++++++++++++++ lib/classes/event/assessable_uploaded.php | 71 ++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 lib/classes/event/assessable_submitted.php create mode 100644 lib/classes/event/assessable_uploaded.php diff --git a/lib/classes/event/assessable_submitted.php b/lib/classes/event/assessable_submitted.php new file mode 100644 index 00000000000..dbdc54b4985 --- /dev/null +++ b/lib/classes/event/assessable_submitted.php @@ -0,0 +1,67 @@ +. + +/** + * Abstract assessable submitted event. + * + * @package core + * @copyright 2013 Frédéric Massart + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Abstract assessable submitted event class. + * + * This class has to be extended by any event which represent that some content, + * on which someone will be assessed, has been submitted and so made available + * for grading. See {@link \core\event\assessable_uploaded} for when the content + * has just been uploaded. + * + * Both events could be triggered in a row, first the uploaded, then the submitted. + * + * @package core + * @copyright 2013 Frédéric Massart + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +abstract class assessable_submitted extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['level'] = 50; // TODO MDL-37658. + } + + /** + * Custom validation. + * + * @throws coding_exception on error. + * @return void + */ + protected function validate_data() { + if (!$this->context->contextlevel === CONTEXT_MODULE) { + throw new coding_exception('Content level must be CONTEXT_MODULE.'); + } + } + +} diff --git a/lib/classes/event/assessable_uploaded.php b/lib/classes/event/assessable_uploaded.php new file mode 100644 index 00000000000..9d7389c5f2b --- /dev/null +++ b/lib/classes/event/assessable_uploaded.php @@ -0,0 +1,71 @@ +. + +/** + * Abstract assessable uploaded event. + * + * @package core + * @copyright 2013 Frédéric Massart + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Abstract assessable uploaded event class. + * + * This class has to be extended by any event which represent that some content, + * on which someone will be assessed, has been uploaded. This is different + * than other events such as assessable_submitted, which means that the content + * has been submitted and made available for grading. + * + * Both events could be triggered in a row, first the uploaded, then the submitted. + * + * @package core + * @copyright 2013 Frédéric Massart + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +abstract class assessable_uploaded extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['level'] = 50; // TODO MDL-37658. + } + + /** + * Validation that should be shared among child classes. + * + * @throws coding_exception when validation fails. + * @return void + */ + protected function validate_data() { + if (!$this->context->contextlevel === CONTEXT_MODULE) { + throw new coding_exception('Content level must be CONTEXT_MODULE.'); + } else if (!isset($this->other['pathnamehashes']) || !is_array($this->other['pathnamehashes'])) { + throw new coding_exception('pathnamehashes must be set in $other and must be an array.'); + } else if (!isset($this->other['content']) || !is_string($this->other['content'])) { + throw new coding_exception('content must be set in $other and must be a string.'); + } + } + +}