Пример #1
0
 /**
  * Manually grade a user competency from the plans page.
  *
  * @param mixed $planorid
  * @param int $competencyid
  * @param int $grade
  * @param string $note A note to attach to the evidence
  * @return array of \core_competency\user_competency
  */
 public static function grade_competency_in_plan($planorid, $competencyid, $grade, $note = null)
 {
     global $USER;
     static::require_enabled();
     $plan = $planorid;
     if (!is_object($planorid)) {
         $plan = new plan($planorid);
     }
     $context = $plan->get_context();
     if (!user_competency::can_grade_user($plan->get_userid())) {
         throw new required_capability_exception($context, 'moodle/competency:competencygrade', 'nopermissions', '');
     }
     // Throws exception if competency not in plan.
     $competency = $plan->get_competency($competencyid);
     $competencycontext = $competency->get_context();
     if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $competencycontext)) {
         throw new required_capability_exception($competencycontext, 'moodle/competency:competencyview', 'nopermissions', '');
     }
     $action = evidence::ACTION_OVERRIDE;
     $desckey = 'evidence_manualoverrideinplan';
     $result = self::add_evidence($plan->get_userid(), $competency, $context->id, $action, $desckey, 'core_competency', $plan->get_name(), false, null, $grade, $USER->id, $note);
     if ($result) {
         $uc = static::get_user_competency($plan->get_userid(), $competency->get_id());
         $event = \core\event\competency_user_competency_rated_in_plan::create_from_user_competency($uc, $plan->get_id());
         $event->trigger();
     }
     return $result;
 }