MDL-53182 tool_lp: Create events for plan workflow

This commit is contained in:
Issam Taboubi
2016-04-18 10:58:55 +08:00
committed by Frederic Massart
parent 3e0b090c7b
commit 25deee1704
15 changed files with 1485 additions and 91 deletions
+17 -17
View File
@@ -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;
}
@@ -0,0 +1,57 @@
<?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/>.
/**
* Comment created event for tool_lp areas.
*
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,48 @@
<?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/>.
/**
* Comment deleted event for tool_lp areas.
*
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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'";
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan approved event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan completed event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan reopened event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan review request cancelled event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan review requested event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan review started event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan review stopped event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* Plan unapproved event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
@@ -0,0 +1,111 @@
<?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/>.
/**
* Plan unlinked event.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <[email protected]>
* @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 <[email protected]>
* @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;
}
}
+9
View File
@@ -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.';
+330 -73
View File
@@ -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();
}
}
+1 -1
View File
@@ -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).