public static function list_plans_with_competency($userid, $competencyorid) {
        global $USER;

        static::require_enabled();
        $competencyid = $competencyorid;
        $competency = null;
        if (is_object($competencyid)) {
            $competency = $competencyid;
            $competencyid = $competency->get('id');
        }

        $plans = plan::get_by_user_and_competency($userid, $competencyid);
        foreach ($plans as $index => $plan) {
            // Filter plans we cannot read.
            if (!$plan->can_read()) {
                unset($plans[$index]);
            }
        }
        return $plans;
    }