Skip to content

Commit

Permalink
MDL-53182 tool_lp: Create events for plan workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
taboubi authored and Frederic Massart committed Apr 18, 2016
1 parent 3e0b090 commit 25deee1
Show file tree
Hide file tree
Showing 15 changed files with 1,485 additions and 91 deletions.
34 changes: 17 additions & 17 deletions admin/tool/lp/classes/api.php
Expand Up @@ -2563,8 +2563,8 @@ public static function unlink_plan_from_template($planorid) {
$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;
}
Expand Down Expand Up @@ -2730,8 +2730,8 @@ public static function plan_cancel_review_request($planorid) {
$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;
}
Expand Down Expand Up @@ -2765,8 +2765,8 @@ public static function plan_request_review($planorid) {
$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;
}
Expand Down Expand Up @@ -2802,8 +2802,8 @@ public static function plan_start_review($planorid) {
$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;
}
Expand Down Expand Up @@ -2838,8 +2838,8 @@ public static function plan_stop_review($planorid) {
$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;
}
Expand Down Expand Up @@ -2877,8 +2877,8 @@ public static function approve_plan($planorid) {
$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;
}
Expand Down Expand Up @@ -2914,8 +2914,8 @@ public static function unapprove_plan($planorid) {
$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;
}
Expand Down Expand Up @@ -2970,7 +2970,7 @@ public static function complete_plan($planorid) {
$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;
}
Expand Down Expand Up @@ -3028,8 +3028,8 @@ public static function reopen_plan($planorid) {

$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;
}
Expand Down
57 changes: 57 additions & 0 deletions admin/tool/lp/classes/event/comment_created.php
@@ -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 <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;
}
}
48 changes: 48 additions & 0 deletions admin/tool/lp/classes/event/comment_deleted.php
@@ -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 <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'";
}
}
114 changes: 114 additions & 0 deletions admin/tool/lp/classes/event/plan_approved.php
@@ -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 <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;
}

}

0 comments on commit 25deee1

Please sign in to comment.