Exemplo n.º 1
0
}
\core_competency\api::require_enabled();
$uc = \core_competency\api::get_user_competency_by_id($id);
$params = array('id' => $id);
$url = new moodle_url('/admin/tool/lp/user_competency.php', $params);
$user = core_user::get_user($uc->get_userid());
if (!$user || !core_user::is_real_user($user->id)) {
    throw new moodle_exception('invaliduser', 'error');
}
$iscurrentuser = $USER->id == $user->id;
$competency = $uc->get_competency();
$compexporter = new \core_competency\external\competency_exporter($competency, array('context' => $competency->get_context()));
$PAGE->set_pagelayout('standard');
$PAGE->set_url($url);
$PAGE->navigation->override_active_url(new moodle_url('/admin/tool/lp/plans.php', array('userid' => $uc->get_userid())));
$PAGE->set_context($uc->get_context());
if (!$iscurrentuser) {
    $PAGE->navigation->extend_for_user($user);
    $PAGE->navigation->set_userid_for_parent_checks($user->id);
}
$output = $PAGE->get_renderer('tool_lp');
$compdata = $compexporter->export($output);
$PAGE->navbar->add($compdata->shortname, $url);
$PAGE->set_title($compdata->shortname);
$PAGE->set_heading($compdata->shortname);
echo $output->header();
$page = new \tool_lp\output\user_competency_summary($uc);
echo $output->render($page);
// Trigger viewed event.
\core_competency\api::user_competency_viewed($uc);
echo $output->footer();
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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('core_competency');
     $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('\\core\\event\\competency_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 {
         \core\event\competency_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());
     }
 }