public static function delete_plan($id) {
        global $DB;
        static::require_enabled();

        $plan = new plan($id);

        if (!$plan->can_manage()) {
            $context = context_user::instance($plan->get('userid'));
            throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
        }

        // Wrap the suppression in a DB transaction.
        $transaction = $DB->start_delegated_transaction();

        // Delete plan competencies.
        $plancomps = plan_competency::get_records(array('planid' => $plan->get('id')));
        foreach ($plancomps as $plancomp) {
            $plancomp->delete();
        }

        // Delete archive user competencies if the status of the plan is complete.
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
            self::remove_archived_user_competencies_in_plan($plan);
        }
        $event = \core\event\competency_plan_deleted::create_from_plan($plan);
        $success = $plan->delete();

        $transaction->allow_commit();

        // Trigger deleted event.
        $event->trigger();

        return $success;
    }
public static function delete_plan($id) {
        global $DB;
        static::require_enabled();

        $plan = new plan($id);

        if (!$plan->can_manage()) {
            $context = context_user::instance($plan->get('userid'));
            throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
        }

        // Wrap the suppression in a DB transaction.
        $transaction = $DB->start_delegated_transaction();

        // Delete plan competencies.
        $plancomps = plan_competency::get_records(array('planid' => $plan->get('id')));
        foreach ($plancomps as $plancomp) {
            $plancomp->delete();
        }

        // Delete archive user competencies if the status of the plan is complete.
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
            self::remove_archived_user_competencies_in_plan($plan);
        }
        $event = \core\event\competency_plan_deleted::create_from_plan($plan);
        $success = $plan->delete();

        $transaction->allow_commit();

        // Trigger deleted event.
        $event->trigger();

        return $success;
    }
public static function delete_plan ( $ id ) { global $ DB ; static :: require_enabled ( ) ; $ plan = new plan ( $ id ) ; if ( ! $ plan -> can_manage ( ) ) { $ context = context_user :: instance ( $ plan -> get ( 'userid' ) ) ; throw new required_capability_exception ( $ context , 'moodle/competency:planmanage' , 'nopermissions' , '' ) ; } // Wrap the suppression in a DB transaction. $ transaction = $ DB -> start_delegated_transaction ( ) ; // Delete plan competencies. $ plancomps = plan_competency :: get_records ( array ( 'planid' => $ plan -> get ( 'id' ) ) ) ; foreach ( $ plancomps as $ plancomp ) { $ plancomp -> delete ( ) ; } // Delete archive user competencies if the status of the plan is complete. if ( $ plan -> get ( 'status' ) == plan :: STATUS_COMPLETE ) { self :: remove_archived_user_competencies_in_plan ( $ plan ) ; } $ event = \ core \ event \ competency_plan_deleted :: create_from_plan ( $ plan ) ; $ success = $ plan -> delete ( ) ; $ transaction -> allow_commit ( ) ; // Trigger deleted event. $ event -> trigger ( ) ; return $ success ; }
Deletes a plan.

Plans based on a template can be removed just like any other one.

@param int $id
@return bool Success?
Deletes a plan .