Data for user competency summary.

@param int $userid The user ID
@param int $competencyid The competency ID
@return \stdClass
773978
public static function data_for_user_competency_summary($userid, $competencyid) {
        global $PAGE;
        $params = self::validate_parameters(self::data_for_user_competency_summary_parameters(), array(
            'userid' => $userid,
            'competencyid' => $competencyid,
        ));

        $uc = api::get_user_competency($params['userid'], $params['competencyid']);
        self::validate_context($uc->get_context());
        $output = $PAGE->get_renderer('tool_lp');

        $renderable = new \tool_lp\output\user_competency_summary($uc);
        return $renderable->export_for_template($output);
    }
1045470
public static function count_proficient_competencies_in_course_for_user($courseid, $userid) {
        static::require_enabled();
        // Check the user have access to the course.
        self::validate_course($courseid);

        // First we do a permissions check.
        $context = context_course::instance($courseid);

        $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
        if (!has_any_capability($capabilities, $context)) {
             throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
        }

        // OK - all set.
        return user_competency_course::count_proficient_competencies($courseid, $userid);
    }
6867
public static function add_competency_to_course($courseid, $competencyid) {
        static::require_enabled();
        // Check the user have access to the course.
        self::validate_course($courseid);

        // First we do a permissions check.
        $context = context_course::instance($courseid);

        require_capability('moodle/competency:coursecompetencymanage', $context);

        $record = new stdClass();
        $record->courseid = $courseid;
        $record->competencyid = $competencyid;

        $competency = new competency($competencyid);

        // Can not add a competency that belong to a hidden framework.
        if ($competency->get_framework()->get('visible') == false) {
            throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
        }

        $coursecompetency = new course_competency();
        $exists = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyid));
        if (!$exists) {
            $coursecompetency->from_record($record);
            if ($coursecompetency->create()) {
                return true;
            }
        }
        return false;
    }
398925
public static function user_competency_cancel_review_request($userid, $competencyid) {
        $params = self::validate_parameters(self::user_competency_cancel_review_request_parameters(), array(
            'userid' => $userid,
            'competencyid' => $competencyid
        ));

        $context = context_user::instance($params['userid']);
        self::validate_context($context);

        return api::user_competency_cancel_review_request($userid, $competencyid);
    }
1137829
public static function list_courses($competencyid) {
        global $DB;

        $results = $DB->get_records_sql('SELECT course.id, course.visible, course.shortname, course.idnumber,
                                                course.fullname, course.summary, course.summaryformat, course.startdate,
                                                course.enddate, course.category
                                           FROM {course} course
                                           JOIN {' . self::TABLE . '} coursecomp
                                             ON coursecomp.courseid = course.id
                                          WHERE coursecomp.competencyid = ? ', array($competencyid));

        return $results;
    }
425076
public function matches(user_competency $usercompetency) {
        global $DB;

        // TODO Improve performance here, perhaps the caller could already provide records.
        $children = competency::get_records(array('parentid' => $this->competency->get('id')));

        if (empty($children)) {
            // Leaves are not compatible with this rule.
            return false;
        }

        $ids = array();
        foreach ($children as $child) {
            $ids[] = $child->get('id');
        }

        list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
        $sql = "userid = :userid
            AND proficiency = :proficiency
            AND competencyid $insql";
        $params['userid'] = $usercompetency->get('userid');
        $params['proficiency'] = 1;

        // Is the user is marked as proficient in all children?
        return user_competency::count_records_select($sql, $params) === count($ids);
    }
333810
public static function create_user_evidence_competency($userevidenceorid, $competencyid) {
        global $USER;
        static::require_enabled();

        $userevidence = $userevidenceorid;
        if (!is_object($userevidence)) {
            $userevidence = self::read_user_evidence($userevidence);
        }

        // Perform user evidence capability checks.
        if (!$userevidence->can_manage()) {
            $context = $userevidence->get_context();
            throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
        }

        // Perform competency capability checks.
        $competency = self::read_competency($competencyid);

        // Get (and create) the relation.
        $relation = user_evidence_competency::get_relation($userevidence->get('id'), $competency->get('id'));
        if (!$relation->get('id')) {
            $relation->create();

            $link = url::user_evidence($userevidence->get('id'));
            self::add_evidence(
                $userevidence->get('userid'),
                $competency,
                $userevidence->get_context(),
                evidence::ACTION_LOG,
                'evidence_evidenceofpriorlearninglinked',
                'core_competency',
                $userevidence->get('name'),
                false,
                $link->out(false),
                null,
                $USER->id
            );
        }

        return $relation;
    }
260541
public static function user_competency_stop_review($userid, $competencyid) {
        $params = self::validate_parameters(self::user_competency_stop_review_parameters(), array(
            'userid' => $userid,
            'competencyid' => $competencyid
        ));

        $context = context_user::instance($params['userid']);
        self::validate_context($context);

        return api::user_competency_stop_review($userid, $competencyid);
    }
1161184
public static function count_courses_using_competency($competencyid) {
        $params = self::validate_parameters(self::count_courses_using_competency_parameters(), array(
            'id' => $competencyid,
        ));

        $competency = api::read_competency($params['id']);
        self::validate_context($competency->get_context());

        return api::count_courses_using_competency($params['id']);
    }
886974
public static function user_competency_viewed($usercompetencyorid) {
        static::require_enabled();
        $uc = $usercompetencyorid;
        if (!is_object($uc)) {
            $uc = new user_competency($uc);
        }

        if (!$uc || !$uc->can_read()) {
            throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
                'nopermissions', '');
        }

        \core\event\competency_user_competency_viewed::create_from_user_competency_viewed($uc)->trigger();
        return true;
    }
733575
public static function count_competencies_in_course($courseid) {
        $params = self::validate_parameters(self::count_competencies_in_course_parameters(), array(
            'id' => $courseid,
        ));

        self::validate_context(context_course::instance($params['id']));

        return api::count_competencies_in_course($params['id']);
    }
40799
public function findByCompetencyAndUser(Competency $competency, User $user)
    {
        $groupQb = $this->_em->createQueryBuilder()
            ->select('g')
            ->from('Claroline\CoreBundle\Entity\Group', 'g')
            ->join('g.users', 'gu')
            ->where('gu = :user');

        return $this->createQueryBuilder('o')
            ->select('o')
            ->leftJoin('o.objectiveCompetencies', 'oc')
            ->leftJoin('o.users', 'ou')
            ->leftJoin('o.groups', 'og')
            ->where('oc.competency = :competency')
            ->andWhere($groupQb->expr()->orX(
                'ou = :user',
                $groupQb->expr()->in('og', $groupQb->getQuery()->getDQL())
            ))
            ->setParameters([
                'competency' => $competency,
                'user' => $user,
            ])
            ->distinct()
            ->getQuery()
            ->getResult();
    }
1078074
public static function read_competency($id) {
        global $PAGE;

        $params = self::validate_parameters(self::read_competency_parameters(), array(
            'id' => $id,
        ));

        $competency = api::read_competency($params['id']);
        $context = $competency->get_context();
        self::validate_context($context);
        $output = $PAGE->get_renderer('core');
        $exporter = new competency_exporter($competency, array('context' => $context));
        $record = $exporter->export($output);
        return $record;
    }
1284171
public static function list_courses_using_competency($competencyid) {
        static::require_enabled();

        // OK - all set.
        $courses = course_competency::list_courses($competencyid);
        $result = array();

        // Now check permissions on each course.
        foreach ($courses as $id => $course) {
            $context = context_course::instance($course->id);
            $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
            if (!has_any_capability($capabilities, $context)) {
                unset($courses[$id]);
                continue;
            }
            if (!self::validate_course($course, false)) {
                unset($courses[$id]);
                continue;
            }
            array_push($result, $course);
        }

        return $result;
    }
1222100
protected static function transform_evidence($userid, evidence $evidence, competency $competency, performance_helper $helper) {
        $action = $evidence->get('action');
        $actiontxt = '?';
        if ($action == evidence::ACTION_LOG) {
            $actiontxt = get_string('privacy:evidence:action:log', 'core_competency');
        } else if ($action == evidence::ACTION_COMPLETE) {
            $actiontxt = get_string('privacy:evidence:action:complete', 'core_competency');
        } else if ($action == evidence::ACTION_OVERRIDE) {
            $actiontxt = get_string('privacy:evidence:action:override', 'core_competency');
        }

        $actionuserid = $evidence->get('actionuserid');

        return [
            'action' => $actiontxt,
            'actionuserid' => $actionuserid ? transform::user($actionuserid) : '-',
            'acting_user_is_you' => transform::yesno($userid == $actionuserid),
            'description' => (string) $evidence->get_description(),
            'url' => $evidence->get('url'),
            'grade' => static::transform_competency_grade($competency, $evidence->get('grade'), $helper),
            'note' => $evidence->get('note'),
            'timecreated' => transform::datetime($evidence->get('timecreated')),
            'timemodified' => transform::datetime($evidence->get('timemodified')),
            'created_or_modified_by_you' => transform::yesno($userid == $evidence->get('usermodified'))
        ];
    }
740169
public static function remove_competency_from_course($courseid, $competencyid) {
        $params = self::validate_parameters(self::remove_competency_from_course_parameters(), array(
            'courseid' => $courseid,
            'competencyid' => $competencyid,
        ));
        self::validate_context(context_course::instance($params['courseid']));
        return api::remove_competency_from_course($params['courseid'], $params['competencyid']);
    }
158976
public static function list_courses_min($competencyid) {
        global $DB;

        $results = $DB->get_records_sql('SELECT course.id as id, course.visible as visible
                                           FROM {' . self::TABLE . '} coursecomp
                                           JOIN {course} course
                                             ON coursecomp.courseid = course.id
                                          WHERE coursecomp.competencyid = ? ', array($competencyid));

        return $results;
    }