/**
  * Export the data.
  *
  * @param renderer_base $output
  * @return stdClass
  */
 public function export_for_template(\renderer_base $output)
 {
     global $DB;
     $plan = api::read_plan($this->planid);
     $pc = api::get_plan_competency($plan, $this->competencyid);
     $competency = $pc->competency;
     $usercompetency = $pc->usercompetency;
     $usercompetencyplan = $pc->usercompetencyplan;
     if (empty($competency)) {
         throw new \invalid_parameter_exception('Invalid params. The competency does not belong to the plan.');
     }
     $relatedcompetencies = api::list_related_competencies($competency->get_id());
     $userid = $plan->get_userid();
     $user = $DB->get_record('user', array('id' => $userid));
     $evidence = api::list_evidence($userid, $this->competencyid, $plan->get_id());
     $params = array('competency' => $competency, 'usercompetency' => $usercompetency, 'usercompetencyplan' => $usercompetencyplan, 'evidence' => $evidence, 'user' => $user, 'plan' => $plan, 'relatedcompetencies' => $relatedcompetencies);
     $exporter = new user_competency_summary_in_plan_exporter(null, $params);
     $data = $exporter->export($output);
     return $data;
 }
示例#2
0
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
$userid = optional_param('userid', false, PARAM_INT);
$id = optional_param('id', false, PARAM_INT);
$returntype = optional_param('return', null, PARAM_ALPHA);
require_login(0, false);
\core_competency\api::require_enabled();
$url = new moodle_url('/admin/tool/lp/editplan.php', array('id' => $id, 'userid' => $userid, 'return' => $returntype));
$plan = null;
if (empty($id)) {
    $pagetitle = get_string('addnewplan', 'tool_lp');
    list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_plan($userid, $url, null, $pagetitle, $returntype);
} else {
    $plan = \core_competency\api::read_plan($id);
    // The userid parameter must be the same as the owner of the plan.
    if ($userid != $plan->get_userid()) {
        throw new coding_exception('Inconsistency between the userid parameter and the userid of the plan');
    }
    $pagetitle = get_string('editplan', 'tool_lp');
    list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_plan($userid, $url, $plan, $pagetitle, $returntype);
}
$output = $PAGE->get_renderer('tool_lp');
// Custom data to pass to the form.
$customdata = array('userid' => $userid, 'context' => $PAGE->context, 'persistent' => $plan);
// User can create plan if he can_manage_user with active/complete status
// or if he can_manage_user_draft with draft status.
$cancreate = \core_competency\plan::can_manage_user_draft($userid) || \core_competency\plan::can_manage_user($userid);
// If editing plan, check if user has permissions to edit it.
if ($plan != null) {
示例#3
0
 public function test_complete_plans_task()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $user = $dg->create_user();
     $up1 = $lpg->create_plan(array('userid' => $user->id, 'status' => \core_competency\plan::STATUS_DRAFT));
     $up2 = $lpg->create_plan(array('userid' => $user->id, 'status' => \core_competency\plan::STATUS_ACTIVE));
     // Set duedate in the past.
     $date = new \DateTime('yesterday');
     $record1 = $up1->to_record();
     $record2 = $up2->to_record();
     $record1->duedate = $date->getTimestamp();
     $record2->duedate = $date->getTimestamp();
     $DB->update_record(plan::TABLE, $record1);
     $DB->update_record(plan::TABLE, $record2);
     $task = \core\task\manager::get_scheduled_task('\\core\\task\\complete_plans_task');
     $this->assertInstanceOf('\\core\\task\\complete_plans_task', $task);
     // Test that draft plan can not be completed on running task.
     $task->execute();
     $plandraft = api::read_plan($up1->get_id());
     $this->assertEquals(\core_competency\plan::STATUS_DRAFT, $plandraft->get_status());
     // Test that active plan can be completed on running task.
     $task->execute();
     $planactive = api::read_plan($up2->get_id());
     $this->assertEquals(\core_competency\plan::STATUS_COMPLETE, $planactive->get_status());
 }
示例#4
0
 /**
  * List plan competencies.
  * @param  int $id The plan ID.
  * @return array
  */
 public static function list_plan_competencies($id)
 {
     global $PAGE;
     $params = self::validate_parameters(self::list_plan_competencies_parameters(), array('id' => $id));
     $id = $params['id'];
     $plan = api::read_plan($id);
     $usercontext = $plan->get_context();
     self::validate_context($usercontext);
     $output = $PAGE->get_renderer('core');
     $result = api::list_plan_competencies($plan);
     if ($plan->get_status() == plan::STATUS_COMPLETE) {
         $ucproperty = 'usercompetencyplan';
     } else {
         $ucproperty = 'usercompetency';
     }
     $contextcache = array();
     $scalecache = array();
     foreach ($result as $key => $r) {
         if (!isset($scalecache[$r->competency->get_competencyframeworkid()])) {
             $scalecache[$r->competency->get_competencyframeworkid()] = $r->competency->get_framework()->get_scale();
         }
         $scale = $scalecache[$r->competency->get_competencyframeworkid()];
         if (!isset($contextcache[$r->competency->get_competencyframeworkid()])) {
             $contextcache[$r->competency->get_competencyframeworkid()] = $r->competency->get_context();
         }
         $context = $contextcache[$r->competency->get_competencyframeworkid()];
         $exporter = new competency_exporter($r->competency, array('context' => $context));
         $r->competency = $exporter->export($output);
         if ($r->usercompetency) {
             $exporter = new user_competency_exporter($r->usercompetency, array('scale' => $scale));
             $r->usercompetency = $exporter->export($output);
             unset($r->usercompetencyplan);
         } else {
             $exporter = new user_competency_plan_exporter($r->usercompetencyplan, array('scale' => $scale));
             $r->usercompetencyplan = $exporter->export($output);
             unset($r->usercompetency);
         }
     }
     return $result;
 }
示例#5
0
 /**
  * Read a user competency summary.
  *
  * @param int $competencyid The competency id
  * @param int $planid The plan id
  * @return \stdClass
  */
 public static function data_for_user_competency_summary_in_plan($competencyid, $planid)
 {
     global $PAGE;
     $params = self::validate_parameters(self::data_for_user_competency_summary_in_plan_parameters(), array('competencyid' => $competencyid, 'planid' => $planid));
     $plan = api::read_plan($params['planid']);
     $context = $plan->get_context();
     self::validate_context($context);
     $output = $PAGE->get_renderer('tool_lp');
     $renderable = new user_competency_summary_in_plan($params['competencyid'], $params['planid']);
     return $renderable->export_for_template($output);
 }