MDL-53189 tool_lp: Create event for user competency viewed
This commit is contained in:
committed by
Frederic Massart
parent
915725250a
commit
640201536a
@@ -3290,6 +3290,98 @@ class api {
|
||||
return $uc->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency viewed event.
|
||||
*
|
||||
* @param user_competency|int $usercompetencyorid The user competency object or user competency id
|
||||
* @return bool
|
||||
*/
|
||||
public static function user_competency_viewed($usercompetencyorid) {
|
||||
$uc = $usercompetencyorid;
|
||||
if (!is_object($uc)) {
|
||||
$uc = new user_competency($uc);
|
||||
}
|
||||
|
||||
if (!$uc || !$uc->can_read()) {
|
||||
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', '');
|
||||
}
|
||||
|
||||
\tool_lp\event\user_competency_viewed::create_from_user_competency_viewed($uc)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency viewed in plan event.
|
||||
*
|
||||
* @param user_competency|int $usercompetencyorid The user competency object or user competency id
|
||||
* @param int $planid The plan ID
|
||||
* @return bool
|
||||
*/
|
||||
public static function user_competency_viewed_in_plan($usercompetencyorid, $planid) {
|
||||
$uc = $usercompetencyorid;
|
||||
if (!is_object($uc)) {
|
||||
$uc = new user_competency($uc);
|
||||
}
|
||||
|
||||
if (!$uc || !$uc->can_read()) {
|
||||
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', '');
|
||||
}
|
||||
$plan = new plan($planid);
|
||||
if ($plan->get_status() == plan::STATUS_COMPLETE) {
|
||||
throw new coding_exception('To log the user competency in completed plan use user_competency_plan_viewed method.');
|
||||
}
|
||||
|
||||
\tool_lp\event\user_competency_viewed_in_plan::create_from_user_competency_viewed_in_plan($uc, $planid)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency viewed in course event.
|
||||
*
|
||||
* @param user_competency|int $usercompetencyorid The user competency object or user competency id
|
||||
* @param int $courseid The course ID
|
||||
* @return bool
|
||||
*/
|
||||
public static function user_competency_viewed_in_course($usercompetencyorid, $courseid) {
|
||||
$uc = $usercompetencyorid;
|
||||
if (!is_object($uc)) {
|
||||
$uc = new user_competency($uc);
|
||||
}
|
||||
|
||||
if (!$uc || !$uc->can_read()) {
|
||||
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', '');
|
||||
}
|
||||
// Validate the course, this will throw an exception if not valid.
|
||||
self::validate_course($courseid);
|
||||
|
||||
\tool_lp\event\user_competency_viewed_in_course::create_from_user_competency_viewed_in_course($uc, $courseid)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency plan viewed event.
|
||||
*
|
||||
* @param user_competency_plan|int $usercompetencyplanorid The user competency plan object or user competency plan id
|
||||
* @return bool
|
||||
*/
|
||||
public static function user_competency_plan_viewed($usercompetencyplanorid) {
|
||||
$ucp = $usercompetencyplanorid;
|
||||
if (!is_object($ucp)) {
|
||||
$ucp = new user_competency_plan($ucp);
|
||||
}
|
||||
|
||||
if (!$ucp || !user_competency::can_read_user($ucp->get_userid())) {
|
||||
throw new required_capability_exception($ucp->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', '');
|
||||
}
|
||||
$plan = new plan($ucp->get_planid());
|
||||
if ($plan->get_status() != plan::STATUS_COMPLETE) {
|
||||
throw new coding_exception('To log the user competency in non-completed plan use user_competency_viewed_in_plan method.');
|
||||
}
|
||||
|
||||
\tool_lp\event\user_competency_plan_viewed::create_from_user_competency_plan($ucp)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if template has related data.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* User competency plan viewed 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\user_competency_plan;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* User competency plan viewed event class.
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* - int planid: id of plan for which competency is associated.
|
||||
* - int competencyid: id of the competency.
|
||||
* }
|
||||
*
|
||||
* @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 user_competency_plan_viewed extends base {
|
||||
|
||||
/**
|
||||
* Convenience method to instantiate the event.
|
||||
*
|
||||
* @param user_competency_plan $usercompetencyplan The user competency plan.
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_user_competency_plan(user_competency_plan $usercompetencyplan) {
|
||||
if (!$usercompetencyplan->get_id()) {
|
||||
throw new \coding_exception('The user competency plan ID must be set.');
|
||||
}
|
||||
$event = static::create(array(
|
||||
'contextid' => $usercompetencyplan->get_context()->id,
|
||||
'objectid' => $usercompetencyplan->get_id(),
|
||||
'relateduserid' => $usercompetencyplan->get_userid(),
|
||||
'other' => array(
|
||||
'planid' => $usercompetencyplan->get_planid(),
|
||||
'competencyid' => $usercompetencyplan->get_competencyid()
|
||||
)
|
||||
));
|
||||
$event->add_record_snapshot(user_competency_plan::TABLE, $usercompetencyplan->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' viewed the user competency plan with id '$this->objectid'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventusercompetencyplanviewed', 'tool_lp');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/admin/tool/lp/user_competency_in_plan.php', array(
|
||||
'competencyid' => $this->other['competencyid'],
|
||||
'userid' => $this->relateduserid,
|
||||
'planid' => $this->other['planid']
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = user_competency_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* Throw \coding_exception notice in case of any problems.
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if ($this->other === null) {
|
||||
throw new \coding_exception('The \'competencyid\' and \'planid\' values must be set.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['competencyid'])) {
|
||||
throw new \coding_exception('The \'competencyid\' value must be set.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['planid'])) {
|
||||
throw new \coding_exception('The \'planid\' value must be set.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* User competency viewed 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\user_competency;
|
||||
use context_course;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* User competency viewed event class.
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* - int competencyid: id of competency.
|
||||
* }
|
||||
*
|
||||
* @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 user_competency_viewed extends base {
|
||||
|
||||
/**
|
||||
* Convenience method to instantiate the event.
|
||||
*
|
||||
* @param user_competency $usercompetency The user competency.
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_user_competency_viewed(user_competency $usercompetency) {
|
||||
if (!$usercompetency->get_id()) {
|
||||
throw new \coding_exception('The user competency ID must be set.');
|
||||
}
|
||||
$params = array(
|
||||
'contextid' => $usercompetency->get_context()->id,
|
||||
'objectid' => $usercompetency->get_id(),
|
||||
'relateduserid' => $usercompetency->get_userid(),
|
||||
'other' => array(
|
||||
'competencyid' => $usercompetency->get_competencyid()
|
||||
)
|
||||
);
|
||||
|
||||
$event = static::create($params);
|
||||
$event->add_record_snapshot(user_competency::TABLE, $usercompetency->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' viewed the user competency with id '$this->objectid'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventusercompetencyviewed', 'tool_lp');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/admin/tool/lp/user_competency.php', array(
|
||||
'id' => $this->objectid
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = user_competency::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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* Throw \coding_exception notice in case of any problems.
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (!isset($this->other) || !isset($this->other['competencyid'])) {
|
||||
throw new \coding_exception('The \'competencyid\' value must be set.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* User competency viewed 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\user_competency;
|
||||
use context_course;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* User competency viewed in course event class.
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* - int competencyid: id of competency.
|
||||
* }
|
||||
*
|
||||
* @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 user_competency_viewed_in_course extends base {
|
||||
|
||||
/**
|
||||
* Convenience method to instantiate the event in course.
|
||||
*
|
||||
* @param user_competency $usercompetency The user competency.
|
||||
* @param int $courseid The course ID
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_user_competency_viewed_in_course(user_competency $usercompetency, $courseid) {
|
||||
if (!$usercompetency->get_id()) {
|
||||
throw new \coding_exception('The user competency ID must be set.');
|
||||
}
|
||||
$params = array(
|
||||
'objectid' => $usercompetency->get_id(),
|
||||
'relateduserid' => $usercompetency->get_userid(),
|
||||
'other' => array(
|
||||
'competencyid' => $usercompetency->get_competencyid()
|
||||
)
|
||||
);
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
$params['contextid'] = $coursecontext->id;
|
||||
$params['courseid'] = $courseid;
|
||||
|
||||
$event = static::create($params);
|
||||
$event->add_record_snapshot(user_competency::TABLE, $usercompetency->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' viewed the user competency with id '$this->objectid' "
|
||||
. "in course with id '$this->courseid'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventusercompetencyviewedincourse', 'tool_lp');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/admin/tool/lp/user_competency_in_course.php', array(
|
||||
'competencyid' => $this->other['competencyid'],
|
||||
'userid' => $this->relateduserid,
|
||||
'courseid' => $this->courseid
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = user_competency::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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* Throw \coding_exception notice in case of any problems.
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (!$this->courseid) {
|
||||
throw new \coding_exception('The \'courseid\' value must be set.');
|
||||
}
|
||||
|
||||
if (!isset($this->other) || !isset($this->other['competencyid'])) {
|
||||
throw new \coding_exception('The \'competencyid\' value must be set.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* User competency viewed 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\user_competency;
|
||||
use context_course;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* User competency viewed in plan event class.
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* - int planid: id of plan for which competency is associated.
|
||||
* - int competencyid: id of competency.
|
||||
* }
|
||||
*
|
||||
* @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 user_competency_viewed_in_plan extends base {
|
||||
|
||||
/**
|
||||
* Convenience method to instantiate the event in plan.
|
||||
*
|
||||
* @param user_competency $usercompetency The user competency.
|
||||
* @param int $planid The pland ID
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_user_competency_viewed_in_plan(user_competency $usercompetency, $planid) {
|
||||
if (!$usercompetency->get_id()) {
|
||||
throw new \coding_exception('The user competency ID must be set.');
|
||||
}
|
||||
$params = array(
|
||||
'contextid' => $usercompetency->get_context()->id,
|
||||
'objectid' => $usercompetency->get_id(),
|
||||
'relateduserid' => $usercompetency->get_userid(),
|
||||
'other' => array(
|
||||
'competencyid' => $usercompetency->get_competencyid(),
|
||||
'planid' => $planid
|
||||
)
|
||||
);
|
||||
|
||||
$event = static::create($params);
|
||||
$event->add_record_snapshot(user_competency::TABLE, $usercompetency->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' viewed the user competency with id '$this->objectid' "
|
||||
. "in plan with id '" . $this->other['planid'] . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventusercompetencyviewedinplan', 'tool_lp');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/admin/tool/lp/user_competency_in_plan.php', array(
|
||||
'competencyid' => $this->other['competencyid'],
|
||||
'userid' => $this->relateduserid,
|
||||
'planid' => $this->other['planid']
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = user_competency::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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* Throw \coding_exception notice in case of any problems.
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if ($this->other === null) {
|
||||
throw new \coding_exception('The \'competencyid\' and \'planid\' values must be set.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['competencyid'])) {
|
||||
throw new \coding_exception('The \'competencyid\' value must be set.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['planid'])) {
|
||||
throw new \coding_exception('The \'planid\' value must be set.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5179,6 +5179,227 @@ class external extends external_api {
|
||||
return user_competency_summary_in_course_exporter::get_read_structure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_viewed() parameters.
|
||||
*
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function user_competency_viewed_parameters() {
|
||||
$usercompetencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The user competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$params = array(
|
||||
'usercompetencyid' => $usercompetencyid
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency viewed event.
|
||||
*
|
||||
* @param int $usercompetencyid The user competency ID.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function user_competency_viewed($usercompetencyid) {
|
||||
$params = self::validate_parameters(self::user_competency_viewed_parameters(),
|
||||
array(
|
||||
'usercompetencyid' => $usercompetencyid
|
||||
));
|
||||
|
||||
$uc = api::get_user_competency_by_id($params['usercompetencyid']);
|
||||
$result = api::user_competency_viewed($uc);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_viewed() result value.
|
||||
*
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function user_competency_viewed_returns() {
|
||||
return new external_value(PARAM_BOOL, 'True if the event user competency viewed was logged');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_viewed_in_plan() parameters.
|
||||
*
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function user_competency_viewed_in_plan_parameters() {
|
||||
$competencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$userid = new external_value(
|
||||
PARAM_INT,
|
||||
'The user id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$planid = new external_value(
|
||||
PARAM_INT,
|
||||
'The plan id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$params = array(
|
||||
'competencyid' => $competencyid,
|
||||
'userid' => $userid,
|
||||
'planid' => $planid
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency viewed in plan event.
|
||||
*
|
||||
* @param int $competencyid The competency ID.
|
||||
* @param int $userid The user ID.
|
||||
* @param int $planid The plan ID.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function user_competency_viewed_in_plan($competencyid, $userid, $planid) {
|
||||
$params = self::validate_parameters(self::user_competency_viewed_in_plan_parameters(),
|
||||
array(
|
||||
'competencyid' => $competencyid,
|
||||
'userid' => $userid,
|
||||
'planid' => $planid
|
||||
));
|
||||
$pl = api::get_plan_competency($params['planid'], $params['competencyid']);
|
||||
$result = api::user_competency_viewed_in_plan($pl->usercompetency, $params['planid']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_viewed_in_plan() result value.
|
||||
*
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function user_competency_viewed_in_plan_returns() {
|
||||
return new external_value(PARAM_BOOL, 'True if the event user competency viewed in plan was logged');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_viewed_in_course() parameters.
|
||||
*
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function user_competency_viewed_in_course_parameters() {
|
||||
$competencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$userid = new external_value(
|
||||
PARAM_INT,
|
||||
'The user id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$courseid = new external_value(
|
||||
PARAM_INT,
|
||||
'The course id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$params = array(
|
||||
'competencyid' => $competencyid,
|
||||
'userid' => $userid,
|
||||
'courseid' => $courseid
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency viewed in course event.
|
||||
*
|
||||
* @param int $competencyid The competency ID.
|
||||
* @param int $userid The user ID.
|
||||
* @param int $courseid The course ID.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function user_competency_viewed_in_course($competencyid, $userid, $courseid) {
|
||||
$params = self::validate_parameters(self::user_competency_viewed_in_course_parameters(),
|
||||
array(
|
||||
'competencyid' => $competencyid,
|
||||
'userid' => $userid,
|
||||
'courseid' => $courseid
|
||||
));
|
||||
$uc = api::get_user_competency_in_course($params['courseid'], $params['userid'], $params['competencyid']);
|
||||
$result = api::user_competency_viewed_in_course($uc, $params['courseid']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_viewed_in_course() result value.
|
||||
*
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function user_competency_viewed_in_course_returns() {
|
||||
return new external_value(PARAM_BOOL, 'True if the event user competency viewed in course was logged');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_plan_viewed() parameters.
|
||||
*
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function user_competency_plan_viewed_parameters() {
|
||||
$competencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$userid = new external_value(
|
||||
PARAM_INT,
|
||||
'The user id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$planid = new external_value(
|
||||
PARAM_INT,
|
||||
'The plan id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$params = array(
|
||||
'competencyid' => $competencyid,
|
||||
'userid' => $userid,
|
||||
'planid' => $planid
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log user competency plan viewed event.
|
||||
*
|
||||
* @param int $competencyid The competency ID.
|
||||
* @param int $userid The user ID.
|
||||
* @param int $planid The plan ID.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function user_competency_plan_viewed($competencyid, $userid, $planid) {
|
||||
$params = self::validate_parameters(self::user_competency_viewed_in_plan_parameters(),
|
||||
array(
|
||||
'competencyid' => $competencyid,
|
||||
'userid' => $userid,
|
||||
'planid' => $planid
|
||||
));
|
||||
$pl = api::get_plan_competency($params['planid'], $params['competencyid']);
|
||||
$result = api::user_competency_plan_viewed($pl->usercompetencyplan);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of user_competency_plan_viewed() result value.
|
||||
*
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function user_competency_plan_viewed_returns() {
|
||||
return new external_value(PARAM_BOOL, 'True if the event user competency plan viewed was logged');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of grade_competency_in_course() parameters.
|
||||
*
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace tool_lp;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use lang_string;
|
||||
use context_user;
|
||||
|
||||
/**
|
||||
* Class for loading/storing user_competency_plan from the DB.
|
||||
@@ -79,6 +80,15 @@ class user_competency_plan extends persistent {
|
||||
return new competency($this->get_competencyid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context.
|
||||
*
|
||||
* @return context The context.
|
||||
*/
|
||||
public function get_context() {
|
||||
return context_user::instance($this->get_userid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the user ID.
|
||||
*
|
||||
@@ -212,7 +222,7 @@ class user_competency_plan extends persistent {
|
||||
|
||||
if (!empty($competenciesorids)) {
|
||||
$test = reset($competenciesorids);
|
||||
if (is_int($test)) {
|
||||
if (is_number($test)) {
|
||||
$ids = $competenciesorids;
|
||||
} else {
|
||||
$ids = array();
|
||||
|
||||
@@ -791,6 +791,42 @@ $functions = array(
|
||||
'capabilities' => 'tool/lp:planview',
|
||||
'ajax' => true,
|
||||
),
|
||||
'tool_lp_user_competency_viewed' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'user_competency_viewed',
|
||||
'classpath' => '',
|
||||
'description' => 'Log the user competency viewed event.',
|
||||
'type' => 'read',
|
||||
'capabilities' => 'tool/lp:usercompetencyread',
|
||||
'ajax' => true,
|
||||
),
|
||||
'tool_lp_user_competency_viewed_in_plan' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'user_competency_viewed_in_plan',
|
||||
'classpath' => '',
|
||||
'description' => 'Log the user competency viewed in plan event.',
|
||||
'type' => 'read',
|
||||
'capabilities' => 'tool/lp:usercompetencyread',
|
||||
'ajax' => true,
|
||||
),
|
||||
'tool_lp_user_competency_viewed_in_course' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'user_competency_viewed_in_course',
|
||||
'classpath' => '',
|
||||
'description' => 'Log the user competency viewed in course event',
|
||||
'type' => 'read',
|
||||
'capabilities' => 'tool/lp:usercompetencyread',
|
||||
'ajax' => true,
|
||||
),
|
||||
'tool_lp_user_competency_plan_viewed' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'user_competency_plan_viewed',
|
||||
'classpath' => '',
|
||||
'description' => 'Log the user competency plan viewed event.',
|
||||
'type' => 'read',
|
||||
'capabilities' => 'tool/lp:usercompetencyread',
|
||||
'ajax' => true,
|
||||
),
|
||||
'tool_lp_grade_competency' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'grade_competency',
|
||||
|
||||
@@ -116,6 +116,10 @@ $string['eventtemplatecreated'] = 'Template created.';
|
||||
$string['eventtemplatedeleted'] = 'Template deleted.';
|
||||
$string['eventtemplateupdated'] = 'Template updated.';
|
||||
$string['eventtemplateviewed'] = 'Template viewed.';
|
||||
$string['eventusercompetencyplanviewed'] = 'User competency plan viewed.';
|
||||
$string['eventusercompetencyviewed'] = 'User competency viewed.';
|
||||
$string['eventusercompetencyviewedincourse'] = 'User competency viewed in a course.';
|
||||
$string['eventusercompetencyviewedinplan'] = 'User competency viewed in a plan.';
|
||||
$string['eventuserevidencecreated'] = 'Evidence of prior learning created.';
|
||||
$string['eventuserevidencedeleted'] = 'Evidence of prior learning deleted.';
|
||||
$string['eventuserevidenceupdated'] = 'Evidence of prior learning updated.';
|
||||
|
||||
@@ -760,4 +760,282 @@ class tool_lp_event_testcase extends advanced_testcase {
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertDebuggingNotCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user competency viewed event in plan.
|
||||
*
|
||||
*/
|
||||
public function test_user_competency_viewed_in_plan() {
|
||||
$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));
|
||||
$fr = $lpg->create_framework();
|
||||
$c = $lpg->create_competency(array('competencyframeworkid' => $fr->get_id()));
|
||||
$pc = $lpg->create_plan_competency(array('planid' => $plan->get_id(), 'competencyid' => $c->get_id()));
|
||||
$uc = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c->get_id()));
|
||||
|
||||
// Can not log the event for user competency using completed plan.
|
||||
api::complete_plan($plan);
|
||||
|
||||
try {
|
||||
api::user_competency_viewed_in_plan($uc, $plan->get_id());
|
||||
$this->fail('To log the user competency in completed plan '
|
||||
. 'use user_competency_plan_viewed method.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp('/To log the user competency in completed plan '
|
||||
. 'use user_competency_plan_viewed method./', $e->getMessage());
|
||||
}
|
||||
|
||||
api::reopen_plan($plan);
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
api::user_competency_viewed_in_plan($uc, $plan->get_id());
|
||||
|
||||
// Get our event event.
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\tool_lp\event\user_competency_viewed_in_plan', $event);
|
||||
$this->assertEquals($uc->get_id(), $event->objectid);
|
||||
$this->assertEquals($uc->get_context()->id, $event->contextid);
|
||||
$this->assertEquals($uc->get_userid(), $event->relateduserid);
|
||||
$this->assertEquals($plan->get_id(), $event->other['planid']);
|
||||
$this->assertEquals($c->get_id(), $event->other['competencyid']);
|
||||
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertDebuggingNotCalled();
|
||||
|
||||
// Test validation.
|
||||
$params = array (
|
||||
'objectid' => $uc->get_id(),
|
||||
'contextid' => $uc->get_context()->id,
|
||||
'other' => null
|
||||
);
|
||||
|
||||
// Other value null.
|
||||
try {
|
||||
\tool_lp\event\user_competency_viewed_in_plan::create($params)->trigger();
|
||||
$this->fail('The \'competencyid\' and \'planid\' values must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'competencyid' and 'planid' values must be set./", $e->getMessage());
|
||||
}
|
||||
|
||||
$params['other']['anythingelse'] = '';
|
||||
// Missing competencyid.
|
||||
try {
|
||||
\tool_lp\event\user_competency_viewed_in_plan::create($params)->trigger();
|
||||
$this->fail('The \'competencyid\' value must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'competencyid' value must be set./", $e->getMessage());
|
||||
}
|
||||
|
||||
$params['other']['competencyid'] = $c->get_id();
|
||||
// Missing planid.
|
||||
try {
|
||||
\tool_lp\event\user_competency_viewed_in_plan::create($params)->trigger();
|
||||
$this->fail('The \'planid\' value must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'planid' value must be set./", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user competency viewed event in course.
|
||||
*
|
||||
*/
|
||||
public function test_user_competency_viewed_in_course() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$dg = $this->getDataGenerator();
|
||||
$lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp');
|
||||
$user = $dg->create_user();
|
||||
$course = $dg->create_course();
|
||||
$fr = $lpg->create_framework();
|
||||
$c = $lpg->create_competency(array('competencyframeworkid' => $fr->get_id()));
|
||||
$pc = $lpg->create_course_competency(array('courseid' => $course->id, 'competencyid' => $c->get_id()));
|
||||
$uc = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c->get_id()));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
api::user_competency_viewed_in_course($uc, $course->id);
|
||||
|
||||
// Get our event event.
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\tool_lp\event\user_competency_viewed_in_course', $event);
|
||||
$this->assertEquals($uc->get_id(), $event->objectid);
|
||||
$this->assertEquals(context_course::instance($course->id)->id, $event->contextid);
|
||||
$this->assertEquals($uc->get_userid(), $event->relateduserid);
|
||||
$this->assertEquals($course->id, $event->courseid);
|
||||
$this->assertEquals($c->get_id(), $event->other['competencyid']);
|
||||
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertDebuggingNotCalled();
|
||||
|
||||
// Test validation.
|
||||
$params = array (
|
||||
'objectid' => $uc->get_id(),
|
||||
'contextid' => $uc->get_context()->id,
|
||||
'other' => null
|
||||
);
|
||||
|
||||
// Missing courseid.
|
||||
try {
|
||||
\tool_lp\event\user_competency_viewed_in_course::create($params)->trigger();
|
||||
$this->fail('The \'courseid\' value must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'courseid' value must be set./", $e->getMessage());
|
||||
}
|
||||
|
||||
$params['contextid'] = context_course::instance($course->id)->id;
|
||||
$params['courseid'] = $course->id;
|
||||
// Missing competencyid.
|
||||
try {
|
||||
\tool_lp\event\user_competency_viewed_in_course::create($params)->trigger();
|
||||
$this->fail('The \'competencyid\' value must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'competencyid' value must be set./", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user competency plan viewed event.
|
||||
*
|
||||
*/
|
||||
public function test_user_competency_plan_viewed() {
|
||||
$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));
|
||||
$fr = $lpg->create_framework();
|
||||
$c = $lpg->create_competency(array('competencyframeworkid' => $fr->get_id()));
|
||||
$ucp = $lpg->create_user_competency_plan(array(
|
||||
'userid' => $user->id,
|
||||
'competencyid' => $c->get_id(),
|
||||
'planid' => $plan->get_id()
|
||||
));
|
||||
|
||||
// Can not log the event for user competency using non completed plan.
|
||||
try {
|
||||
api::user_competency_plan_viewed($ucp);
|
||||
$this->fail('To log the user competency in non-completed plan '
|
||||
. 'use user_competency_viewed_in_plan method.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp('/To log the user competency in non-completed plan '
|
||||
. 'use user_competency_viewed_in_plan method./', $e->getMessage());
|
||||
}
|
||||
|
||||
// Complete the plan.
|
||||
api::complete_plan($plan);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
api::user_competency_plan_viewed($ucp);
|
||||
|
||||
// Get our event event.
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\tool_lp\event\user_competency_plan_viewed', $event);
|
||||
$this->assertEquals($ucp->get_id(), $event->objectid);
|
||||
$this->assertEquals($ucp->get_context()->id, $event->contextid);
|
||||
$this->assertEquals($ucp->get_userid(), $event->relateduserid);
|
||||
$this->assertEquals($plan->get_id(), $event->other['planid']);
|
||||
$this->assertEquals($c->get_id(), $event->other['competencyid']);
|
||||
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertDebuggingNotCalled();
|
||||
|
||||
// Test validation.
|
||||
$params = array (
|
||||
'objectid' => $ucp->get_id(),
|
||||
'contextid' => $ucp->get_context()->id,
|
||||
'other' => null
|
||||
);
|
||||
|
||||
// Other value null.
|
||||
try {
|
||||
\tool_lp\event\user_competency_plan_viewed::create($params)->trigger();
|
||||
$this->fail('The \'competencyid\' and \'planid\' values must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'competencyid' and 'planid' values must be set./", $e->getMessage());
|
||||
}
|
||||
|
||||
$params['other']['anythingelse'] = '';
|
||||
// Missing competencyid.
|
||||
try {
|
||||
\tool_lp\event\user_competency_plan_viewed::create($params)->trigger();
|
||||
$this->fail('The \'competencyid\' value must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'competencyid' value must be set./", $e->getMessage());
|
||||
}
|
||||
|
||||
$params['other']['competencyid'] = $c->get_id();
|
||||
// Missing planid.
|
||||
try {
|
||||
\tool_lp\event\user_competency_plan_viewed::create($params)->trigger();
|
||||
$this->fail('The \'planid\' value must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'planid' value must be set./", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user competency viewed event.
|
||||
*
|
||||
*/
|
||||
public function test_user_competency_viewed() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$dg = $this->getDataGenerator();
|
||||
$lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp');
|
||||
$user = $dg->create_user();
|
||||
$fr = $lpg->create_framework();
|
||||
$c = $lpg->create_competency(array('competencyframeworkid' => $fr->get_id()));
|
||||
$uc = $lpg->create_user_competency(array(
|
||||
'userid' => $user->id,
|
||||
'competencyid' => $c->get_id()
|
||||
));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
api::user_competency_viewed($uc);
|
||||
|
||||
// Get our event event.
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\tool_lp\event\user_competency_viewed', $event);
|
||||
$this->assertEquals($uc->get_id(), $event->objectid);
|
||||
$this->assertEquals($uc->get_context()->id, $event->contextid);
|
||||
$this->assertEquals($uc->get_userid(), $event->relateduserid);
|
||||
$this->assertEquals($c->get_id(), $event->other['competencyid']);
|
||||
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertDebuggingNotCalled();
|
||||
|
||||
// Test validation.
|
||||
$params = array (
|
||||
'objectid' => $uc->get_id(),
|
||||
'contextid' => $uc->get_context()->id
|
||||
);
|
||||
|
||||
// Missing competencyid.
|
||||
try {
|
||||
\tool_lp\event\user_competency_viewed::create($params)->trigger();
|
||||
$this->fail('The \'competencyid\' value must be set.');
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertRegExp("/The 'competencyid' value must be set./", $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,7 @@ $PAGE->set_heading($compdata->shortname);
|
||||
echo $output->header();
|
||||
$page = new \tool_lp\output\user_competency_summary($uc);
|
||||
echo $output->render($page);
|
||||
// Trigger viewed event.
|
||||
\tool_lp\api::user_competency_viewed($uc);
|
||||
|
||||
echo $output->footer();
|
||||
|
||||
@@ -89,6 +89,10 @@ echo $output->render($nav);
|
||||
if ($userid > 0) {
|
||||
$page = new \tool_lp\output\user_competency_summary_in_course($userid, $competencyid, $courseid);
|
||||
echo $output->render($page);
|
||||
|
||||
// Trigger the viewed event.
|
||||
$uc = \tool_lp\api::get_user_competency_in_course($courseid, $userid, $competencyid);
|
||||
\tool_lp\api::user_competency_viewed_in_course($uc, $courseid);
|
||||
} else {
|
||||
echo $output->container('', 'clearfix');
|
||||
echo $output->notify_problem(get_string('noparticipants', 'tool_lp'));
|
||||
|
||||
@@ -48,5 +48,14 @@ echo $output->heading($title);
|
||||
|
||||
$page = new \tool_lp\output\user_competency_summary_in_plan($competencyid, $planid);
|
||||
echo $output->render($page);
|
||||
// Trigger the viewed event.
|
||||
$pc = \tool_lp\api::get_plan_competency($plan, $competency->get_id());
|
||||
if ($plan->get_status() == \tool_lp\plan::STATUS_COMPLETE) {
|
||||
$usercompetencyplan = $pc->usercompetencyplan;
|
||||
\tool_lp\api::user_competency_plan_viewed($usercompetencyplan);
|
||||
} else {
|
||||
$usercompetency = $pc->usercompetency;
|
||||
\tool_lp\api::user_competency_viewed_in_plan($usercompetency, $plan->get_id());
|
||||
}
|
||||
|
||||
echo $output->footer();
|
||||
|
||||
@@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$plugin->version = 2016020906; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2016020908; // 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).
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
define(["jquery","core/notification","core/str","core/ajax","core/log","core/templates","tool_lp/dialogue"],function(a,b,c,d,e,f,g){var h=function(b,c){this._regionSelector=b,this._userCompetencySelector=c,a(this._regionSelector).on("click",this._userCompetencySelector,this._handleClick.bind(this))};return h.prototype._handleClick=function(c){var f=a(c.target).closest(this._userCompetencySelector),g=a(f).data("competencyid"),h=a(f).data("courseid"),i=a(f).data("userid");e.debug("Clicked on cell: competencyId="+g+", courseId="+h+", userId="+i),d.call([{methodname:"tool_lp_data_for_user_competency_summary_in_course",args:{userid:i,competencyid:g,courseid:h},done:this._contextLoaded.bind(this),fail:b.exception}])},h.prototype._contextLoaded=function(a){var d=this;a.displayuser=!0,f.render("tool_lp/user_competency_summary_in_course",a).done(function(a,e){c.get_string("usercompetencysummary","report_competency").done(function(b){new g(b,a,f.runTemplateJS.bind(f,e),d._refresh.bind(d),!0)}).fail(b.exception)}).fail(b.exception)},h.prototype._refresh=function(){var c=a(this._regionSelector),e=c.data("courseid"),f=c.data("userid");d.call([{methodname:"report_competency_data_for_report",args:{courseid:e,userid:f},done:this._pageContextLoaded.bind(this),fail:b.exception}])},h.prototype._pageContextLoaded=function(a){var c=this;f.render("report_competency/report",a).done(function(a,b){f.replaceNode(c._regionSelector,a,b)}).fail(b.exception)},h.prototype._regionSelector=null,h.prototype._userCompetencySelector=null,h});
|
||||
define(["jquery","core/notification","core/str","core/ajax","core/log","core/templates","tool_lp/dialogue"],function(a,b,c,d,e,f,g){var h=function(b,c){this._regionSelector=b,this._userCompetencySelector=c,a(this._regionSelector).on("click",this._userCompetencySelector,this._handleClick.bind(this))};return h.prototype._handleClick=function(c){var f=a(c.target).closest(this._userCompetencySelector),g=a(f).data("competencyid"),h=a(f).data("courseid"),i=a(f).data("userid");e.debug("Clicked on cell: competencyId="+g+", courseId="+h+", userId="+i);var j=d.call([{methodname:"tool_lp_data_for_user_competency_summary_in_course",args:{userid:i,competencyid:g,courseid:h},done:this._contextLoaded.bind(this),fail:b.exception}]);j[0].then(function(){d.call([{methodname:"tool_lp_user_competency_viewed_in_course",args:{userid:i,competencyid:g,courseid:h},fail:b.exception}])})},h.prototype._contextLoaded=function(a){var d=this;a.displayuser=!0,f.render("tool_lp/user_competency_summary_in_course",a).done(function(a,e){c.get_string("usercompetencysummary","report_competency").done(function(b){new g(b,a,f.runTemplateJS.bind(f,e),d._refresh.bind(d),!0)}).fail(b.exception)}).fail(b.exception)},h.prototype._refresh=function(){var c=a(this._regionSelector),e=c.data("courseid"),f=c.data("userid");d.call([{methodname:"report_competency_data_for_report",args:{courseid:e,userid:f},done:this._pageContextLoaded.bind(this),fail:b.exception}])},h.prototype._pageContextLoaded=function(a){var c=this;f.render("report_competency/report",a).done(function(a,b){f.replaceNode(c._regionSelector,a,b)}).fail(b.exception)},h.prototype._regionSelector=null,h.prototype._userCompetencySelector=null,h});
|
||||
@@ -51,12 +51,21 @@ define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/log', 'cor
|
||||
|
||||
log.debug('Clicked on cell: competencyId=' + competencyId + ', courseId=' + courseId + ', userId=' + userId);
|
||||
|
||||
ajax.call([{
|
||||
var requests = ajax.call([{
|
||||
methodname : 'tool_lp_data_for_user_competency_summary_in_course',
|
||||
args: { userid: userId, competencyid: competencyId, courseid: courseId },
|
||||
done: this._contextLoaded.bind(this),
|
||||
fail: notification.exception
|
||||
}]);
|
||||
|
||||
// Log the user competency viewed in course event.
|
||||
requests[0].then(function(){
|
||||
ajax.call([{
|
||||
methodname : 'tool_lp_user_competency_viewed_in_course',
|
||||
args: { userid: userId, competencyid: competencyId, courseid: courseId },
|
||||
fail: notification.exception
|
||||
}]);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user