Esempio n. 1
0
 /**
  * List the competencies in a user plan.
  *
  * @param  int $planorid The plan, or its ID.
  * @return array((object) array(
  *                            'competency' => \core_competency\competency,
  *                            'usercompetency' => \core_competency\user_competency
  *                            'usercompetencyplan' => \core_competency\user_competency_plan
  *                        ))
  *         The values of of keys usercompetency and usercompetencyplan cannot be defined at the same time.
  */
 public static function list_plan_competencies($planorid)
 {
     static::require_enabled();
     $plan = $planorid;
     if (!is_object($planorid)) {
         $plan = new plan($planorid);
     }
     if (!$plan->can_read()) {
         $context = context_user::instance($plan->get_userid());
         throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
     }
     $result = array();
     $competencies = $plan->get_competencies();
     // Get user competencies from user_competency_plan if the plan status is set to complete.
     $iscompletedplan = $plan->get_status() == plan::STATUS_COMPLETE;
     if ($iscompletedplan) {
         $usercompetencies = user_competency_plan::get_multiple($plan->get_userid(), $plan->get_id(), $competencies);
         $ucresultkey = 'usercompetencyplan';
     } else {
         $usercompetencies = user_competency::get_multiple($plan->get_userid(), $competencies);
         $ucresultkey = 'usercompetency';
     }
     // Build the return values.
     foreach ($competencies as $key => $competency) {
         $found = false;
         foreach ($usercompetencies as $uckey => $uc) {
             if ($uc->get_competencyid() == $competency->get_id()) {
                 $found = true;
                 unset($usercompetencies[$uckey]);
                 break;
             }
         }
         if (!$found) {
             if ($iscompletedplan) {
                 throw new coding_exception('A user competency plan is missing');
             } else {
                 $uc = user_competency::create_relation($plan->get_userid(), $competency->get_id());
             }
         }
         $plancompetency = (object) array('competency' => $competency, 'usercompetency' => null, 'usercompetencyplan' => null);
         $plancompetency->{$ucresultkey} = $uc;
         $result[] = $plancompetency;
     }
     return $result;
 }
Esempio n. 2
0
/**
 * Return the permissions of for the comments.
 *
 * @param  stdClass $params The parameters.
 * @return array
 */
function core_competency_comment_permissions($params)
{
    if (!get_config('core_competency', 'enabled')) {
        return array('post' => false, 'view' => false);
    }
    if ($params->commentarea == 'user_competency') {
        $uc = new user_competency($params->itemid);
        if ($uc->can_read()) {
            return array('post' => $uc->can_comment(), 'view' => $uc->can_read_comments());
        }
    } else {
        if ($params->commentarea == 'plan') {
            $plan = new plan($params->itemid);
            if ($plan->can_read()) {
                return array('post' => $plan->can_comment(), 'view' => $plan->can_read_comments());
            }
        }
    }
    return array('post' => false, 'view' => false);
}