public static function list_evidence($userid = 0, $competencyid = 0, $planid = 0, $sort = 'timecreated',
                                         $order = 'DESC', $skip = 0, $limit = 0) {
        static::require_enabled();

        if (!user_competency::can_read_user($userid)) {
            $context = context_user::instance($userid);
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
        }

        $usercompetency = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
        if (!$usercompetency) {
            return array();
        }

        $plancompleted = false;
        if ($planid != 0) {
            $plan = new plan($planid);
            if ($plan->get('status') == plan::STATUS_COMPLETE) {
                $plancompleted = true;
            }
        }

        $select = 'usercompetencyid = :usercompetencyid';
        $params = array('usercompetencyid' => $usercompetency->get('id'));
        if ($plancompleted) {
            $select .= ' AND timecreated <= :timecompleted';
            $params['timecompleted'] = $plan->get('timemodified');
        }

        $orderby = $sort . ' ' . $order;
        $orderby .= !empty($orderby) ? ', id DESC' : 'id DESC'; // Prevent random ordering.

        $evidence = evidence::get_records_select($select, $params, $orderby, '*', $skip, $limit);
        return $evidence;
    }