Commit 25deee17 authored by Issam Taboubi's avatar Issam Taboubi Committed by Frederic Massart
Browse files

MDL-53182 tool_lp: Create events for plan workflow

parent 3e0b090c
......@@ -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;
}
......
<?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 <issam.taboubi@umontreal.ca>
* @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 <issam.taboubi@umontreal.ca>
* @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;
}
}
<?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 <issam.taboubi@umontreal.ca>
* @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 <issam.taboubi@umontreal.ca>
* @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'";
}
}
<?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 <issam.taboubi@umontreal.ca>
* @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 <issam.taboubi@umontreal.ca>
* @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;
}
}
<?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 <issam.taboubi@umontreal.ca>
* @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 <issam.taboubi@umontreal.ca>
* @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;
}
}
<?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 <issam.taboubi@umontreal.ca>
* @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 <issam.taboubi@umontreal.ca>
* @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;
}
}
<?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 <issam.taboubi@umontreal.ca>
* @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 <issam.taboubi@umontreal.ca>
* @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'.";
}