public static function delete_framework($id) {
        global $DB;
        static::require_enabled();
        $framework = new competency_framework($id);
        require_capability('moodle/competency:competencymanage', $framework->get_context());

        $events = array();
        $competenciesid = competency::get_ids_by_frameworkid($id);
        $contextid = $framework->get('contextid');
        if (!competency::can_all_be_deleted($competenciesid)) {
            return false;
        }
        $transaction = $DB->start_delegated_transaction();
        try {
            if (!empty($competenciesid)) {
                // Delete competencies.
                competency::delete_by_frameworkid($id);

                // Delete the related competencies.
                related_competency::delete_multiple_relations($competenciesid);

                // Delete the evidences for competencies.
                user_evidence_competency::delete_by_competencyids($competenciesid);
            }

            // Create a competency framework deleted event.
            $event = \core\event\competency_framework_deleted::create_from_framework($framework);
            $result = $framework->delete();

            // Register the deleted events competencies.
            $events = \core\event\competency_deleted::create_multiple_from_competencyids($competenciesid, $contextid);

        } catch (\Exception $e) {
            $transaction->rollback($e);
        }

        // Commit the transaction.
        $transaction->allow_commit();

        // If all operations are successfull then trigger the delete event.
        $event->trigger();

        // Trigger deleted event competencies.
        foreach ($events as $event) {
            $event->trigger();
        }

        return $result;
    }
public static function delete_framework($id) {
        global $DB;
        static::require_enabled();
        $framework = new competency_framework($id);
        require_capability('moodle/competency:competencymanage', $framework->get_context());

        $events = array();
        $competenciesid = competency::get_ids_by_frameworkid($id);
        $contextid = $framework->get('contextid');
        if (!competency::can_all_be_deleted($competenciesid)) {
            return false;
        }
        $transaction = $DB->start_delegated_transaction();
        try {
            if (!empty($competenciesid)) {
                // Delete competencies.
                competency::delete_by_frameworkid($id);

                // Delete the related competencies.
                related_competency::delete_multiple_relations($competenciesid);

                // Delete the evidences for competencies.
                user_evidence_competency::delete_by_competencyids($competenciesid);
            }

            // Create a competency framework deleted event.
            $event = \core\event\competency_framework_deleted::create_from_framework($framework);
            $result = $framework->delete();

            // Register the deleted events competencies.
            $events = \core\event\competency_deleted::create_multiple_from_competencyids($competenciesid, $contextid);

        } catch (\Exception $e) {
            $transaction->rollback($e);
        }

        // Commit the transaction.
        $transaction->allow_commit();

        // If all operations are successfull then trigger the delete event.
        $event->trigger();

        // Trigger deleted event competencies.
        foreach ($events as $event) {
            $event->trigger();
        }

        return $result;
    }
public static function delete_framework ( $ id ) { global $ DB ; static :: require_enabled ( ) ; $ framework = new competency_framework ( $ id ) ; require_capability ( 'moodle/competency:competencymanage' , $ framework -> get_context ( ) ) ; $ events = array ( ) ; $ competenciesid = competency :: get_ids_by_frameworkid ( $ id ) ; $ contextid = $ framework -> get ( 'contextid' ) ; if ( ! competency :: can_all_be_deleted ( $ competenciesid ) ) { return false ; } $ transaction = $ DB -> start_delegated_transaction ( ) ; try { if ( ! empty ( $ competenciesid ) ) { // Delete competencies. competency :: delete_by_frameworkid ( $ id ) ; // Delete the related competencies. related_competency :: delete_multiple_relations ( $ competenciesid ) ; // Delete the evidences for competencies. user_evidence_competency :: delete_by_competencyids ( $ competenciesid ) ; } // Create a competency framework deleted event. $ event = \ core \ event \ competency_framework_deleted :: create_from_framework ( $ framework ) ; $ result = $ framework -> delete ( ) ; // Register the deleted events competencies. $ events = \ core \ event \ competency_deleted :: create_multiple_from_competencyids ( $ competenciesid , $ contextid ) ; } catch ( \ Exception $ e ) { $ transaction -> rollback ( $ e ) ; } // Commit the transaction. $ transaction -> allow_commit ( ) ; // If all operations are successfull then trigger the delete event. $ event -> trigger ( ) ; // Trigger deleted event competencies. foreach ( $ events as $ event ) { $ event -> trigger ( ) ; } return $ result ; }
Delete a competency framework by id.

Requires moodle/competency:competencymanage capability at the system context.

@param int $id The record to delete. This will delete alot of related data - you better be sure.
@return boolean
Delete a competency framework by id .