Return the current depth of a competency framework.

@param int $frameworkid The framework ID.
@return int
763777
public static function get_framework_depth($frameworkid) {
        global $DB;
        $totallength = $DB->sql_length('path');
        $trimmedlength = $DB->sql_length("REPLACE(path, '/', '')");
        $sql = "SELECT ($totallength - $trimmedlength - 1) AS depth
                  FROM {" . self::TABLE . "}
                 WHERE competencyframeworkid = :id
              ORDER BY depth DESC";
        $record = $DB->get_record_sql($sql, array('id' => $frameworkid), IGNORE_MULTIPLE);
        if (!$record) {
            $depth = 0;
        } else {
            $depth = $record->depth;
        }
        return $depth;
    }
1014136
public function get_framework_from_competency(competency $competency) {
        $frameworkid = $competency->get('competencyframeworkid');
        if (!isset($this->frameworks[$frameworkid])) {
            $this->frameworks[$frameworkid] = $competency->get_framework();
        }
        return $this->frameworks[$frameworkid];
    }
1182086
public static function move_up_competency($id) {
        static::require_enabled();
        $current = new competency($id);

        // First we do a permissions check.
        require_capability('moodle/competency:competencymanage', $current->get_context());

        $sortorder = $current->get('sortorder');
        if ($sortorder == 0) {
            return false;
        }

        $sortorder = $sortorder - 1;
        $current->set('sortorder', $sortorder);

        $filters = array('parentid' => $current->get('parentid'),
                         'competencyframeworkid' => $current->get('competencyframeworkid'),
                         'sortorder' => $sortorder);
        $children = self::list_competencies($filters, 'id');
        foreach ($children as $needtoswap) {
            $needtoswap->set('sortorder', $sortorder + 1);
            $needtoswap->update();
        }

        // OK - all set.
        $result = $current->update();

        return $result;
    }
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']);
    }
875531
public static function update_competency_framework($competencyframework) {

        $params = self::validate_parameters(self::update_competency_framework_parameters(), array(
            'competencyframework' => $competencyframework
        ));
        $params = $params['competencyframework'];

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

        $params = (object) $params;

        return api::update_framework($params);
    }
342291
public static function get_related_competencies($competencyid) {
        global $DB;

        $fields = competency::get_sql_fields('c', 'c_');
        $sql = "(SELECT $fields, " . $DB->sql_concat('rc.relatedcompetencyid', "'_'", 'rc.competencyid') . " AS rid
                   FROM {" . self::TABLE . "} rc
                   JOIN {" . competency::TABLE . "} c
                     ON c.id = rc.relatedcompetencyid
                  WHERE rc.competencyid = :cid)
              UNION ALL
                (SELECT $fields, " . $DB->sql_concat('rc.competencyid', "'_'", 'rc.relatedcompetencyid') . " AS rid
                   FROM {" . self::TABLE . "} rc
                   JOIN {" . competency::TABLE . "} c
                     ON c.id = rc.competencyid
                  WHERE rc.relatedcompetencyid = :cid2)
               ORDER BY c_path ASC, c_sortorder ASC";

        $competencies = array();
        $records = $DB->get_recordset_sql($sql, array('cid' => $competencyid, 'cid2' => $competencyid));
        foreach ($records as $record) {
            unset($record->rid);
            $competencies[$record->c_id] = new competency(null, competency::extract_record($record, 'c_'));
        }
        $records->close();

        return $competencies;
    }
996777
public static function read_competency_framework($id) {
        global $PAGE;

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

        $framework = api::read_framework($params['id']);
        self::validate_context($framework->get_context());
        $output = $PAGE->get_renderer('core');
        $exporter = new competency_framework_exporter($framework);
        $record = $exporter->export($output);
        return $record;
    }
86947
public function get_scale_from_competency(competency $competency) {
        $scaleid = $competency->get('scaleid');
        if ($scaleid !== null && !isset($this->scales[$scaleid])) {
            $this->scales[$scaleid] = $competency->get_scale();

        } else if ($scaleid === null) {
            $framework = $this->get_framework_from_competency($competency);
            $scaleid = $framework->get('scaleid');
            if (!isset($this->scales[$scaleid])) {
                $this->scales[$scaleid] = $framework->get_scale();
            }
        }

        return $this->scales[$scaleid];
    }
461262
private function getVolume($volumeId = null)
    {
        $volumeManager = $this->get('phlexible_media_manager.volume_manager');

        if ($volumeId) {
            return $volumeManager->getById($volumeId);
        }

        return current($volumeManager->all());
    }
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;
    }
149347
public function getRankFromSiteId($siteId, $format = null)
    {
        $url = $this->sitesManager->getSiteUrlsFromId($siteId)[0];

        return $this->getRank($url, $format);
    }
816937
protected static function transform_framework_brief(competency_framework $framework) {
        global $OUTPUT;
        $exporter = new \core_competency\external\competency_framework_exporter($framework);
        $data = $exporter->export($OUTPUT);
        return [
            'name' => $data->shortname,
            'idnumber' => $data->idnumber,
            'description' => $data->description
        ];
    }
193061
public function getRoot($folderId)
    {
        $folder = FolderQuery::create()->findPk($folderId);

        if (0 !== $folder->getParent()) {
            $parentFolder = FolderQuery::create()->findPk($folder->getParent());

            if (null !== $parentFolder) {
                $folderId = $this->getRoot($parentFolder->getId());
            }
        }

        return $folderId;
    }
1267380
public static function move_down_competency($competencyid) {
        $params = self::validate_parameters(self::move_down_competency_parameters(), array(
            'id' => $competencyid,
        ));

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

        return api::move_down_competency($params['id']);
    }
576874
public static function move_up_competency($competencyid) {
        $params = self::validate_parameters(self::move_up_competency_parameters(), array(
            'id' => $competencyid,
        ));

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

        return api::move_up_competency($params['id']);
    }
1188949
public function getFromId( $diskId){
        $rest = $this->getService( self::API_STORAGE_PARTITION . $diskId);
        $rest->GET();

        return $rest->getResult( models\Storage\DiskPartition::class);
    }
308155
public static function count_competencies_in_course($courseid) {
        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 course_competency::count_competencies($courseid);
    }