/**
  * Validate user evidence ID.
  *
  * @param  int $value ID.
  * @return true|lang_string
  */
 protected function validate_userevidenceid($value)
 {
     if (!user_evidence::record_exists($value)) {
         return new lang_string('invaliddata', 'error');
     }
     return true;
 }
 /**
  * Construct this renderable.
  *
  * @param int $userid
  */
 public function __construct($userid)
 {
     $this->userid = $userid;
     $this->context = context_user::instance($userid);
     $this->evidence = api::list_user_evidence($userid);
     $this->canmanage = user_evidence::can_manage_user($this->userid);
     if ($this->canmanage) {
         $addevidence = new single_button(new moodle_url('/admin/tool/lp/user_evidence_edit.php', array('userid' => $userid)), get_string('addnewuserevidence', 'tool_lp'), 'get');
         $this->navigation[] = $addevidence;
     }
 }
Beispiel #3
0
/**
 * This function extends the user navigation.
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user The user object
 * @param context_user $usercontext The user context
 * @param stdClass $course The course object
 * @param context_course $coursecontext The context of the course
 */
function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $course, $coursecontext)
{
    if (!get_config('core_competency', 'enabled')) {
        return;
    }
    if (\core_competency\plan::can_read_user($user->id)) {
        $node = $navigation->add(get_string('learningplans', 'tool_lp'), new moodle_url('/admin/tool/lp/plans.php', array('userid' => $user->id)));
        if (\core_competency\user_evidence::can_read_user($user->id)) {
            $node->add(get_string('userevidence', 'tool_lp'), new moodle_url('/admin/tool/lp/user_evidence_list.php', array('userid' => $user->id)));
        }
    }
}
 /**
  * Convenience method to instantiate the event.
  *
  * @param user_evidence $userevidence The evidence of prior learning.
  * @return self
  */
 public static final function create_from_user_evidence(user_evidence $userevidence)
 {
     if (!$userevidence->get_id()) {
         throw new \coding_exception('The evidence of prior learning ID must be set.');
     }
     $event = static::create(array('contextid' => $userevidence->get_context()->id, 'objectid' => $userevidence->get_id(), 'relateduserid' => $userevidence->get_userid()));
     $event->add_record_snapshot(user_evidence::TABLE, $userevidence->to_record());
     return $event;
 }
Beispiel #5
0
 /**
  * Export this data so it can be used as the context for a mustache template.
  *
  * @param renderer_base $output
  * @return stdClass
  */
 public function export_for_template(renderer_base $output)
 {
     $data = new stdClass();
     $data->userid = $this->userid;
     $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
     $data->canreaduserevidence = user_evidence::can_read_user($this->userid);
     $data->canmanageuserplans = plan::can_manage_user($this->userid);
     // Attach standard objects as mustache can not parse \core_competency\plan objects.
     $data->plans = array();
     if ($this->plans) {
         foreach ($this->plans as $plan) {
             $exporter = new plan_exporter($plan, array('template' => $plan->get_template()));
             $record = $exporter->export($output);
             $data->plans[] = $record;
         }
     }
     $data->navigation = array();
     foreach ($this->navigation as $button) {
         $data->navigation[] = $output->render($button);
     }
     return $data;
 }
Beispiel #6
0
 /**
  * Send request review for user evidence competencies.
  *
  * @param  int $id The user evidence ID.
  * @return bool
  */
 public static function request_review_of_user_evidence_linked_competencies($id)
 {
     $userevidence = new user_evidence($id);
     $context = $userevidence->get_context();
     $userid = $userevidence->get_userid();
     if (!$userevidence->can_manage()) {
         throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
     }
     $usercompetencies = user_evidence_competency::get_user_competencies_by_userevidenceid($id);
     foreach ($usercompetencies as $usercompetency) {
         if ($usercompetency->get_status() == user_competency::STATUS_IDLE) {
             static::user_competency_request_review($userid, $usercompetency->get_competencyid());
         }
     }
     return true;
 }
Beispiel #7
0
 /**
  * Create a new user_evidence.
  *
  * @param array|stdClass $record
  * @return evidence
  */
 public function create_user_evidence($record = null)
 {
     $this->userevidencecount++;
     $i = $this->userevidencecount;
     $record = (object) $record;
     if (!isset($record->userid)) {
         throw new coding_exception('The userid value is required.');
     }
     if (!isset($record->name)) {
         $record->name = "Evidence {$i} name";
     }
     if (!isset($record->description)) {
         $record->description = "Evidence {$i} description";
     }
     if (!isset($record->descriptionformat)) {
         $record->descriptionformat = FORMAT_HTML;
     }
     $ue = new user_evidence(0, $record);
     $ue->create();
     return $ue;
 }
Beispiel #8
0
 /**
  * Set-up a user evidence page.
  *
  * Example:
  * list($title, $subtitle) = page_helper::setup_for_user_evidence($url, $template, $pagetitle);
  * echo $OUTPUT->heading($title);
  * echo $OUTPUT->heading($subtitle, 3);
  *
  * @param  int $userid The user ID.
  * @param  moodle_url $url The current page.
  * @param  \core_competency\user_evidence $evidence The user evidence, if any.
  * @param  string $subtitle The title of the subpage, if any.
  * @param  string $returntype The desired return page.
  * @return array With the following:
  *               - Page title
  *               - Page sub title
  *               - Return URL (main plan page)
  */
 public static function setup_for_user_evidence($userid, moodle_url $url, $evidence = null, $subtitle = '', $returntype = null)
 {
     global $PAGE, $USER;
     // Check that the user is a valid user.
     $user = core_user::get_user($userid);
     if (!$user || !core_user::is_real_user($userid)) {
         throw new \moodle_exception('invaliduser', 'error');
     }
     $context = context_user::instance($user->id);
     $evidencelisturl = new moodle_url('/admin/tool/lp/user_evidence_list.php', array('userid' => $userid));
     $evidenceurl = null;
     if ($evidence) {
         $evidenceurl = new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $evidence->get_id()));
     }
     $returnurl = $evidencelisturl;
     if ($returntype != 'list' && $evidenceurl) {
         $returnurl = $evidenceurl;
     }
     $PAGE->navigation->override_active_url($evidencelisturl);
     $PAGE->set_context($context);
     // If not his own evidence, we want to extend the navigation for the user.
     $iscurrentuser = $USER->id == $user->id;
     if (!$iscurrentuser) {
         $PAGE->navigation->extend_for_user($user);
         $PAGE->navigation->set_userid_for_parent_checks($user->id);
     }
     if (!empty($evidence)) {
         $title = format_string($evidence->get_name(), true, array('context' => $context));
     } else {
         $title = get_string('userevidence', 'tool_lp');
     }
     $PAGE->set_pagelayout('standard');
     $PAGE->set_url($url);
     $PAGE->set_title($title);
     $PAGE->set_heading($title);
     if (!empty($evidence)) {
         $PAGE->navbar->add($title, $evidenceurl);
         if (!empty($subtitle)) {
             $PAGE->navbar->add($subtitle, $url);
         }
     } else {
         if (!empty($subtitle)) {
             // We're in a sub page without a specific evidence.
             $PAGE->navbar->add($subtitle, $url);
         }
     }
     return array($title, $subtitle, $returnurl);
 }
Beispiel #9
0
/**
 * File serving.
 *
 * @param stdClass $course The course object.
 * @param stdClass $cm The cm object.
 * @param context $context The context object.
 * @param string $filearea The file area.
 * @param array $args List of arguments.
 * @param bool $forcedownload Whether or not to force the download of the file.
 * @param array $options Array of options.
 * @return void|false
 */
function core_competency_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG;
    if (!get_config('core_competency', 'enabled')) {
        return false;
    }
    $fs = get_file_storage();
    $file = null;
    $itemid = array_shift($args);
    $filename = array_shift($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if ($filearea == 'userevidence' && $context->contextlevel == CONTEXT_USER) {
        if (user_evidence::can_read_user($context->instanceid)) {
            $file = $fs->get_file($context->id, 'core_competency', $filearea, $itemid, $filepath, $filename);
        }
    }
    if (!$file) {
        return false;
    }
    send_stored_file($file, null, 0, $forcedownload);
}
Beispiel #10
0
    }
    $pagetitle = get_string('edituserevidence', 'tool_lp');
    list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_user_evidence($userid, $url, $userevidence, $pagetitle, $returntype);
}
// The context has been set to the user context in the page_helper.
$context = $PAGE->context;
$fileareaoptions = array('subdirs' => false);
$customdata = array('fileareaoptions' => $fileareaoptions, 'persistent' => $userevidence, 'userid' => $userid);
// Check if user has permissions to manage user evidence.
if ($userevidence != null) {
    if (!$userevidence->can_manage()) {
        throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
    }
    $customdata['evidence'] = $userevidence;
} else {
    if (!\core_competency\user_evidence::can_manage_user($userid)) {
        throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
    }
}
$form = new \tool_lp\form\user_evidence($url->out(false), $customdata);
if ($form->is_cancelled()) {
    redirect($returnurl);
}
// Load existing user evidence.
$itemid = null;
if ($userevidence) {
    $itemid = $userevidence->get_id();
}
// Massaging the file API.
$draftitemid = file_get_submitted_draft_itemid('files');
file_prepare_draft_area($draftitemid, $context->id, 'core_competency', 'userevidence', $itemid, $fileareaoptions);