From 25deee17049fd7ce6c2f328c4f931929787ae2b6 Mon Sep 17 00:00:00 2001 From: Issam Taboubi Date: Wed, 2 Mar 2016 15:53:13 -0500 Subject: [PATCH] MDL-53182 tool_lp: Create events for plan workflow --- admin/tool/lp/classes/api.php | 34 +- .../tool/lp/classes/event/comment_created.php | 57 +++ .../tool/lp/classes/event/comment_deleted.php | 48 +++ admin/tool/lp/classes/event/plan_approved.php | 114 +++++ .../tool/lp/classes/event/plan_completed.php | 114 +++++ admin/tool/lp/classes/event/plan_reopened.php | 114 +++++ .../event/plan_review_request_cancelled.php | 114 +++++ .../classes/event/plan_review_requested.php | 114 +++++ .../lp/classes/event/plan_review_started.php | 114 +++++ .../lp/classes/event/plan_review_stopped.php | 114 +++++ .../tool/lp/classes/event/plan_unapproved.php | 114 +++++ admin/tool/lp/classes/event/plan_unlinked.php | 111 +++++ admin/tool/lp/lang/en/tool_lp.php | 9 + admin/tool/lp/tests/event_test.php | 403 ++++++++++++++---- admin/tool/lp/version.php | 2 +- 15 files changed, 1485 insertions(+), 91 deletions(-) create mode 100644 admin/tool/lp/classes/event/comment_created.php create mode 100644 admin/tool/lp/classes/event/comment_deleted.php create mode 100644 admin/tool/lp/classes/event/plan_approved.php create mode 100644 admin/tool/lp/classes/event/plan_completed.php create mode 100644 admin/tool/lp/classes/event/plan_reopened.php create mode 100644 admin/tool/lp/classes/event/plan_review_request_cancelled.php create mode 100644 admin/tool/lp/classes/event/plan_review_requested.php create mode 100644 admin/tool/lp/classes/event/plan_review_started.php create mode 100644 admin/tool/lp/classes/event/plan_review_stopped.php create mode 100644 admin/tool/lp/classes/event/plan_unapproved.php create mode 100644 admin/tool/lp/classes/event/plan_unlinked.php diff --git a/admin/tool/lp/classes/api.php b/admin/tool/lp/classes/api.php index aab2647bc7b..67c81cdf9a4 100644 --- a/admin/tool/lp/classes/api.php +++ b/admin/tool/lp/classes/api.php @@ -2563,8 +2563,8 @@ class api { $success = $plan->update(); $transaction->allow_commit(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger unlinked event. + \tool_lp\event\plan_unlinked::create_from_plan($plan)->trigger(); return $success; } @@ -2730,8 +2730,8 @@ class api { $plan->set_status(plan::STATUS_DRAFT); $result = $plan->update(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger review request cancelled event. + \tool_lp\event\plan_review_request_cancelled::create_from_plan($plan)->trigger(); return $result; } @@ -2765,8 +2765,8 @@ class api { $plan->set_status(plan::STATUS_WAITING_FOR_REVIEW); $result = $plan->update(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger review requested event. + \tool_lp\event\plan_review_requested::create_from_plan($plan)->trigger(); return $result; } @@ -2802,8 +2802,8 @@ class api { $plan->set_reviewerid($USER->id); $result = $plan->update(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger review started event. + \tool_lp\event\plan_review_started::create_from_plan($plan)->trigger(); return $result; } @@ -2838,8 +2838,8 @@ class api { $plan->set_reviewerid(null); $result = $plan->update(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger review stopped event. + \tool_lp\event\plan_review_stopped::create_from_plan($plan)->trigger(); return $result; } @@ -2877,8 +2877,8 @@ class api { $plan->set_reviewerid(null); $result = $plan->update(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger approved event. + \tool_lp\event\plan_approved::create_from_plan($plan)->trigger(); return $result; } @@ -2914,8 +2914,8 @@ class api { $plan->set_status(plan::STATUS_DRAFT); $result = $plan->update(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger unapproved event. + \tool_lp\event\plan_unapproved::create_from_plan($plan)->trigger(); return $result; } @@ -2970,7 +2970,7 @@ class api { $transaction->allow_commit(); // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + \tool_lp\event\plan_completed::create_from_plan($plan)->trigger(); return $success; } @@ -3028,8 +3028,8 @@ class api { $transaction->allow_commit(); - // Trigger updated event. - \tool_lp\event\plan_updated::create_from_plan($plan)->trigger(); + // Trigger reopened event. + \tool_lp\event\plan_reopened::create_from_plan($plan)->trigger(); return $success; } diff --git a/admin/tool/lp/classes/event/comment_created.php b/admin/tool/lp/classes/event/comment_created.php new file mode 100644 index 00000000000..c561fe8f096 --- /dev/null +++ b/admin/tool/lp/classes/event/comment_created.php @@ -0,0 +1,57 @@ +. + +/** + * Comment created event for tool_lp areas. + * + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace tool_lp\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Comment created event class for tool_lp areas. + * + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class comment_created extends \core\event\comment_created { + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' added the comment with id '$this->objectid' to the '$this->component'"; + } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return null; + } +} diff --git a/admin/tool/lp/classes/event/comment_deleted.php b/admin/tool/lp/classes/event/comment_deleted.php new file mode 100644 index 00000000000..4b0f4c690a7 --- /dev/null +++ b/admin/tool/lp/classes/event/comment_deleted.php @@ -0,0 +1,48 @@ +. + +/** + * Comment deleted event for tool_lp areas. + * + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace tool_lp\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Comment deleted event class for tool_lp areas. + * + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class comment_deleted extends \core\event\comment_deleted { + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' deleted the comment with id '$this->objectid' from '$this->component'"; + } +} diff --git a/admin/tool/lp/classes/event/plan_approved.php b/admin/tool/lp/classes/event/plan_approved.php new file mode 100644 index 00000000000..ed0faf96d8c --- /dev/null +++ b/admin/tool/lp/classes/event/plan_approved.php @@ -0,0 +1,114 @@ +. + +/** + * Plan approved event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan approved event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_approved extends base { + + /** + * Convenience method to instantiate the plan approved event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' approved the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanapproved', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_completed.php b/admin/tool/lp/classes/event/plan_completed.php new file mode 100644 index 00000000000..de7dd4d6e0b --- /dev/null +++ b/admin/tool/lp/classes/event/plan_completed.php @@ -0,0 +1,114 @@ +. + +/** + * Plan completed event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan completed event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_completed extends base { + + /** + * Convenience method to instantiate the plan completed event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' completed the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplancompleted', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_reopened.php b/admin/tool/lp/classes/event/plan_reopened.php new file mode 100644 index 00000000000..cca9de16f2e --- /dev/null +++ b/admin/tool/lp/classes/event/plan_reopened.php @@ -0,0 +1,114 @@ +. + +/** + * Plan reopened event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan reopened event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_reopened extends base { + + /** + * Convenience method to instantiate the plan reopened event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' reopened the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanreopened', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_review_request_cancelled.php b/admin/tool/lp/classes/event/plan_review_request_cancelled.php new file mode 100644 index 00000000000..e1ad9e5bf2c --- /dev/null +++ b/admin/tool/lp/classes/event/plan_review_request_cancelled.php @@ -0,0 +1,114 @@ +. + +/** + * Plan review request cancelled event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan review request cancelled event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_review_request_cancelled extends base { + + /** + * Convenience method to instantiate the plan review request cancelled event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' cancelled a review request for the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanreviewrequestcancelled', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_review_requested.php b/admin/tool/lp/classes/event/plan_review_requested.php new file mode 100644 index 00000000000..c11b412337f --- /dev/null +++ b/admin/tool/lp/classes/event/plan_review_requested.php @@ -0,0 +1,114 @@ +. + +/** + * Plan review requested event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan review requested event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_review_requested extends base { + + /** + * Convenience method to instantiate the plan review requested event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' sent a review request for the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanreviewrequested', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_review_started.php b/admin/tool/lp/classes/event/plan_review_started.php new file mode 100644 index 00000000000..22275655cc8 --- /dev/null +++ b/admin/tool/lp/classes/event/plan_review_started.php @@ -0,0 +1,114 @@ +. + +/** + * Plan review started event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan review started event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_review_started extends base { + + /** + * Convenience method to instantiate the plan review started event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' started a review for the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanreviewstarted', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_review_stopped.php b/admin/tool/lp/classes/event/plan_review_stopped.php new file mode 100644 index 00000000000..d804b81057e --- /dev/null +++ b/admin/tool/lp/classes/event/plan_review_stopped.php @@ -0,0 +1,114 @@ +. + +/** + * Plan review stopped event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan review stopped event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_review_stopped extends base { + + /** + * Convenience method to instantiate the plan review stopped event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' stopped a review for the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanreviewstopped', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_unapproved.php b/admin/tool/lp/classes/event/plan_unapproved.php new file mode 100644 index 00000000000..32261f0a3cf --- /dev/null +++ b/admin/tool/lp/classes/event/plan_unapproved.php @@ -0,0 +1,114 @@ +. + +/** + * Plan unapproved event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan unapproved event class. + * + * @property-read array $other { + * Extra information about event. + * } + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_unapproved extends base { + + /** + * Convenience method to instantiate the plan unapproved event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' unapproved the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanunapproved', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/classes/event/plan_unlinked.php b/admin/tool/lp/classes/event/plan_unlinked.php new file mode 100644 index 00000000000..d5f9cf8c32f --- /dev/null +++ b/admin/tool/lp/classes/event/plan_unlinked.php @@ -0,0 +1,111 @@ +. + +/** + * Plan unlinked event. + * + * @package tool_lp + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_lp\event; + +use core\event\base; +use tool_lp\plan; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Plan unlinked event class. + * + * + * @package tool_lp + * @since Moodle 3.1 + * @copyright 2016 Issam Taboubi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class plan_unlinked extends base { + + /** + * Convenience method to instantiate the plan unlinked event. + * + * + * @param plan $plan The plan. + * @return self + */ + public static final function create_from_plan(plan $plan) { + if (!$plan->get_id()) { + throw new \coding_exception('The plan ID must be set.'); + } + $event = static::create(array( + 'contextid' => $plan->get_context()->id, + 'objectid' => $plan->get_id(), + 'relateduserid' => $plan->get_userid(), + )); + $event->add_record_snapshot(plan::TABLE, $plan->to_record()); + return $event; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' unlinked the learning plan with id '$this->objectid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventplanunlinked', 'tool_lp'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/admin/tool/lp/plan.php', + array('id' => $this->objectid, 'pagecontextid' => $this->contextid)); + } + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = plan::TABLE; + } + + /** + * Get_objectid_mapping method. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + return base::NOT_MAPPED; + } + +} diff --git a/admin/tool/lp/lang/en/tool_lp.php b/admin/tool/lp/lang/en/tool_lp.php index 1ea407f9426..1497be1ea46 100644 --- a/admin/tool/lp/lang/en/tool_lp.php +++ b/admin/tool/lp/lang/en/tool_lp.php @@ -112,9 +112,18 @@ $string['eventcompetencycreated'] = 'Competency created.'; $string['eventcompetencydeleted'] = 'Competency deleted.'; $string['eventcompetencyupdated'] = 'Competency updated.'; $string['eventcompetencyviewed'] = 'Competency viewed.'; +$string['eventplanapproved'] = 'Plan approved.'; +$string['eventplancompleted'] = 'Plan completed.'; $string['eventplancreated'] = 'Plan created.'; $string['eventplandeleted'] = 'Plan deleted.'; +$string['eventplanreopened'] = 'Plan reopened.'; +$string['eventplanreviewrequestcancelled'] = 'Plan review request cancelled.'; +$string['eventplanreviewrequested'] = 'Plan review requested.'; +$string['eventplanreviewstarted'] = 'Plan review started.'; +$string['eventplanreviewstopped'] = 'Plan review stopped.'; +$string['eventplanunlinked'] = 'Plan unlinked.'; $string['eventplanupdated'] = 'Plan updated.'; +$string['eventplanunapproved'] = 'Plan unapproved.'; $string['eventplanviewed'] = 'Plan viewed.'; $string['eventtemplatecreated'] = 'Template created.'; $string['eventtemplatedeleted'] = 'Template deleted.'; diff --git a/admin/tool/lp/tests/event_test.php b/admin/tool/lp/tests/event_test.php index ff7c4c7978c..e05301a4e9b 100644 --- a/admin/tool/lp/tests/event_test.php +++ b/admin/tool/lp/tests/event_test.php @@ -24,6 +24,7 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; +require_once($CFG->dirroot . '/comment/lib.php'); use tool_lp\api; @@ -535,47 +536,10 @@ class tool_lp_event_testcase extends advanced_testcase { $sink = $this->redirectEvents(); $plan = api::update_plan($record); $this->assertEquals('Plan updated', $plan->get_name()); - // Complete plan. - api::complete_plan($plan); - // Reopen plan. - api::reopen_plan($plan); - // Unapprove plan. - api::unapprove_plan($plan); - // Approve plan. - api::approve_plan($plan); - // Get our event event. - $events = $sink->get_events(); - $this->assertCount(5, $events); - // Check that the event data is valid. - foreach ($events as $event) { - $this->assertInstanceOf('\tool_lp\event\plan_updated', $event); - $this->assertEquals($plan->get_id(), $event->objectid); - $this->assertEquals($plan->get_context()->id, $event->contextid); - $this->assertEventContextNotUsed($event); - } - $this->assertDebuggingNotCalled(); - } - /** - * Test the plan updated event by unlink. - * - */ - public function test_plan_updated_by_unlink() { - $this->resetAfterTest(true); - $this->setAdminUser(); - $dg = $this->getDataGenerator(); - $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); - $user1 = $dg->create_user(); - $t1 = $lpg->create_template(); - $plan = $lpg->create_plan(array('userid' => $user1->id, 'templateid' => $t1->get_id())); - // Trigger and capture the event. - $sink = $this->redirectEvents(); - $result = api::unlink_plan_from_template($plan); - $this->assertTrue($result); // Get our event event. $events = $sink->get_events(); $event = reset($events); - // Check that the event data is valid. $this->assertInstanceOf('\tool_lp\event\plan_updated', $event); $this->assertEquals($plan->get_id(), $event->objectid); $this->assertEquals($plan->get_context()->id, $event->contextid); @@ -583,42 +547,6 @@ class tool_lp_event_testcase extends advanced_testcase { $this->assertDebuggingNotCalled(); } - /** - * Test the plan updated event by review. - * - */ - public function test_plan_updated_by_review() { - $this->resetAfterTest(true); - $this->setAdminUser(); - $dg = $this->getDataGenerator(); - $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); - $user1 = $dg->create_user(); - $plan = $lpg->create_plan(array('userid' => $user1->id)); - // Trigger and capture the event. - $sink = $this->redirectEvents(); - $result = api::plan_request_review($plan); - $this->assertTrue($result); - $result = api::plan_start_review($plan); - $this->assertTrue($result); - $result = api::plan_stop_review($plan); - $this->assertTrue($result); - $result = api::plan_request_review($plan); - $this->assertTrue($result); - $result = api::plan_cancel_review_request($plan); - $this->assertTrue($result); - // Get our event event. - $events = $sink->get_events(); - $this->assertCount(5, $events); - // Check that the event data is valid. - foreach ($events as $event) { - $this->assertInstanceOf('\tool_lp\event\plan_updated', $event); - $this->assertEquals($plan->get_id(), $event->objectid); - $this->assertEquals($plan->get_context()->id, $event->contextid); - $this->assertEventContextNotUsed($event); - } - $this->assertDebuggingNotCalled(); - } - /** * Test the plan deleted event. * @@ -1038,4 +966,333 @@ class tool_lp_event_testcase extends advanced_testcase { $this->assertRegExp("/The 'competencyid' value must be set./", $e->getMessage()); } } + + /** + * Test the plan approved event. + * + */ + public function test_plan_approved() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::approve_plan($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_approved', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan unapproved event. + * + */ + public function test_plan_unapproved() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id, 'status' => \tool_lp\plan::STATUS_ACTIVE)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::unapprove_plan($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_unapproved', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan reopened event. + * + */ + public function test_plan_reopened() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id, 'status' => \tool_lp\plan::STATUS_COMPLETE)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::reopen_plan($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_reopened', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan completed event. + * + */ + public function test_plan_completed() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id, 'status' => \tool_lp\plan::STATUS_ACTIVE)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::complete_plan($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_completed', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan unlinked event. + * + */ + public function test_plan_unlinked() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $template = $lpg->create_template(); + $plan = $lpg->create_plan(array( + 'userid' => $user1->id, + 'status' => \tool_lp\plan::STATUS_ACTIVE, + 'templateid' => $template->get_id() + )); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::unlink_plan_from_template($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_unlinked', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan review requested event. + * + */ + public function test_plan_review_requested() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::plan_request_review($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_review_requested', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan review request cancelled event. + * + */ + public function test_plan_review_request_cancelled() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id, 'status' => \tool_lp\plan::STATUS_WAITING_FOR_REVIEW)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::plan_cancel_review_request($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_review_request_cancelled', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan review started event. + * + */ + public function test_plan_review_started() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id, 'status' => \tool_lp\plan::STATUS_WAITING_FOR_REVIEW)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::plan_start_review($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_review_started', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test the plan review stopped event. + * + */ + public function test_plan_review_stopped() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id, 'status' => \tool_lp\plan::STATUS_IN_REVIEW)); + $planid = $plan->get_id(); + $contextid = $plan->get_context()->id; + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $result = api::plan_stop_review($plan->get_id()); + $this->assertTrue($result); + // Get our event event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertInstanceOf('\tool_lp\event\plan_review_stopped', $event); + $this->assertEquals($planid, $event->objectid); + $this->assertEquals($contextid, $event->contextid); + $this->assertEquals($plan->get_userid(), $event->relateduserid); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test plan comment created event. + */ + public function test_plan_comment_created() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user->id)); + + $context = context_user::instance($user->id); + $cmt = new stdClass(); + $cmt->context = $context; + $cmt->area = 'plan'; + $cmt->itemid = $plan->get_id(); + $cmt->component = 'tool_lp'; + $cmt->showcount = 1; + $manager = new comment($cmt); + + // Triggering and capturing the event. + $sink = $this->redirectEvents(); + $manager->add("New comment for plan"); + $events = $sink->get_events(); + // Add comment will trigger 2 other events message_viewed and message_sent. + $this->assertCount(3, $events); + $event = $events[2]; + + // Checking that the event contains the expected values. + $this->assertInstanceOf('\tool_lp\event\comment_created', $event); + $this->assertEquals($context, $event->get_context()); + $this->assertEquals($plan->get_id(), $event->other['itemid']); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } + + /** + * Test plan comment deleted event. + */ + public function test_plan_comment_deleted() { + $this->resetAfterTest(true); + $this->setAdminUser(); + $dg = $this->getDataGenerator(); + $lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp'); + $user1 = $dg->create_user(); + $plan = $lpg->create_plan(array('userid' => $user1->id)); + + $context = context_user::instance($user1->id); + + $cmt = new stdClass(); + $cmt->context = $context; + $cmt->area = 'plan'; + $cmt->itemid = $plan->get_id(); + $cmt->component = 'tool_lp'; + $manager = new comment($cmt); + $newcomment = $manager->add("Comment to be deleted"); + + // Triggering and capturing the event. + $sink = $this->redirectEvents(); + $manager->delete($newcomment->id); + $events = $sink->get_events(); + $this->assertCount(1, $events); + $event = reset($events); + + // Checking that the event contains the expected values. + $this->assertInstanceOf('\tool_lp\event\comment_deleted', $event); + $this->assertEquals($context, $event->get_context()); + $this->assertEquals($plan->get_id(), $event->other['itemid']); + $this->assertEventContextNotUsed($event); + $this->assertDebuggingNotCalled(); + } } diff --git a/admin/tool/lp/version.php b/admin/tool/lp/version.php index 232dd25f7e6..7ff2ee0bcd2 100644 --- a/admin/tool/lp/version.php +++ b/admin/tool/lp/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016020913; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2016020914; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2014110400; // Requires this Moodle version. $plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics).