original_string: public static function delete_competency($id) {
          global $DB;
          static::require_enabled();
          $competency = new competency($id);
  
          // First we do a permissions check.
          require_capability('moodle/competency:competencymanage', $competency->get_context());
  
          $events = array();
          $competencyids = array(intval($competency->get('id')));
          $contextid = $competency->get_context()->id;
          $competencyids = array_merge(competency::get_descendants_ids($competency), $competencyids);
          if (!competency::can_all_be_deleted($competencyids)) {
              return false;
          }
          $transaction = $DB->start_delegated_transaction();
  
          try {
  
              // Reset the rule of the parent.
              $parent = $competency->get_parent();
              if ($parent) {
                  $parent->reset_rule();
                  $parent->update();
              }
  
              // Delete the competency separately so the after_delete event can be triggered.
              $competency->delete();
  
              // Delete the competencies.
              competency::delete_multiple($competencyids);
  
              // Delete the competencies relation.
              related_competency::delete_multiple_relations($competencyids);
  
              // Delete competency evidences.
              user_evidence_competency::delete_by_competencyids($competencyids);
  
              // Register the competencies deleted events.
              $events = \core\event\competency_deleted::create_multiple_from_competencyids($competencyids, $contextid);
  
          } catch (\Exception $e) {
              $transaction->rollback($e);
          }
  
          $transaction->allow_commit();
          // Trigger events.
          foreach ($events as $event) {
              $event->trigger();
          }
  
          return true;
      }
code: public static function delete_competency($id) {
          global $DB;
          static::require_enabled();
          $competency = new competency($id);
  
          // First we do a permissions check.
          require_capability('moodle/competency:competencymanage', $competency->get_context());
  
          $events = array();
          $competencyids = array(intval($competency->get('id')));
          $contextid = $competency->get_context()->id;
          $competencyids = array_merge(competency::get_descendants_ids($competency), $competencyids);
          if (!competency::can_all_be_deleted($competencyids)) {
              return false;
          }
          $transaction = $DB->start_delegated_transaction();
  
          try {
  
              // Reset the rule of the parent.
              $parent = $competency->get_parent();
              if ($parent) {
                  $parent->reset_rule();
                  $parent->update();
              }
  
              // Delete the competency separately so the after_delete event can be triggered.
              $competency->delete();
  
              // Delete the competencies.
              competency::delete_multiple($competencyids);
  
              // Delete the competencies relation.
              related_competency::delete_multiple_relations($competencyids);
  
              // Delete competency evidences.
              user_evidence_competency::delete_by_competencyids($competencyids);
  
              // Register the competencies deleted events.
              $events = \core\event\competency_deleted::create_multiple_from_competencyids($competencyids, $contextid);
  
          } catch (\Exception $e) {
              $transaction->rollback($e);
          }
  
          $transaction->allow_commit();
          // Trigger events.
          foreach ($events as $event) {
              $event->trigger();
          }
  
          return true;
      }
code_tokens: public static function delete_competency ( $ id ) { global $ DB ; static :: require_enabled ( ) ; $ competency = new competency ( $ id ) ; // First we do a permissions check. require_capability ( 'moodle/competency:competencymanage' , $ competency -> get_context ( ) ) ; $ events = array ( ) ; $ competencyids = array ( intval ( $ competency -> get ( 'id' ) ) ) ; $ contextid = $ competency -> get_context ( ) -> id ; $ competencyids = array_merge ( competency :: get_descendants_ids ( $ competency ) , $ competencyids ) ; if ( ! competency :: can_all_be_deleted ( $ competencyids ) ) { return false ; } $ transaction = $ DB -> start_delegated_transaction ( ) ; try { // Reset the rule of the parent. $ parent = $ competency -> get_parent ( ) ; if ( $ parent ) { $ parent -> reset_rule ( ) ; $ parent -> update ( ) ; } // Delete the competency separately so the after_delete event can be triggered. $ competency -> delete ( ) ; // Delete the competencies. competency :: delete_multiple ( $ competencyids ) ; // Delete the competencies relation. related_competency :: delete_multiple_relations ( $ competencyids ) ; // Delete competency evidences. user_evidence_competency :: delete_by_competencyids ( $ competencyids ) ; // Register the competencies deleted events. $ events = \ core \ event \ competency_deleted :: create_multiple_from_competencyids ( $ competencyids , $ contextid ) ; } catch ( \ Exception $ e ) { $ transaction -> rollback ( $ e ) ; } $ transaction -> allow_commit ( ) ; // Trigger events. foreach ( $ events as $ event ) { $ event -> trigger ( ) ; } return true ; }
docstring: Delete a competency 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
docstring_tokens: Delete a competency by id .