original_string: public function can_delete_full() {
          global $DB;
          if (!$this->id) {
              // Fool-proof.
              return false;
          }
  
          $context = $this->get_context();
          if (!$this->is_uservisible() ||
                  !has_capability('moodle/category:manage', $context)) {
              return false;
          }
  
          // Check all child categories (not only direct children).
          $sql = context_helper::get_preload_record_columns_sql('ctx');
          $childcategories = $DB->get_records_sql('SELECT c.id, c.visible, '. $sql.
              ' FROM {context} ctx '.
              ' JOIN {course_categories} c ON c.id = ctx.instanceid'.
              ' WHERE ctx.path like ? AND ctx.contextlevel = ?',
                  array($context->path. '/%', CONTEXT_COURSECAT));
          foreach ($childcategories as $childcat) {
              context_helper::preload_from_record($childcat);
              $childcontext = context_coursecat::instance($childcat->id);
              if ((!$childcat->visible && !has_capability('moodle/category:viewhiddencategories', $childcontext)) ||
                      !has_capability('moodle/category:manage', $childcontext)) {
                  return false;
              }
          }
  
          // Check courses.
          $sql = context_helper::get_preload_record_columns_sql('ctx');
          $coursescontexts = $DB->get_records_sql('SELECT ctx.instanceid AS courseid, '.
                      $sql. ' FROM {context} ctx '.
                      'WHERE ctx.path like :pathmask and ctx.contextlevel = :courselevel',
                  array('pathmask' => $context->path. '/%',
                      'courselevel' => CONTEXT_COURSE));
          foreach ($coursescontexts as $ctxrecord) {
              context_helper::preload_from_record($ctxrecord);
              if (!can_delete_course($ctxrecord->courseid)) {
                  return false;
              }
          }
  
          return true;
      }
code: public function can_delete_full() {
          global $DB;
          if (!$this->id) {
              // Fool-proof.
              return false;
          }
  
          $context = $this->get_context();
          if (!$this->is_uservisible() ||
                  !has_capability('moodle/category:manage', $context)) {
              return false;
          }
  
          // Check all child categories (not only direct children).
          $sql = context_helper::get_preload_record_columns_sql('ctx');
          $childcategories = $DB->get_records_sql('SELECT c.id, c.visible, '. $sql.
              ' FROM {context} ctx '.
              ' JOIN {course_categories} c ON c.id = ctx.instanceid'.
              ' WHERE ctx.path like ? AND ctx.contextlevel = ?',
                  array($context->path. '/%', CONTEXT_COURSECAT));
          foreach ($childcategories as $childcat) {
              context_helper::preload_from_record($childcat);
              $childcontext = context_coursecat::instance($childcat->id);
              if ((!$childcat->visible && !has_capability('moodle/category:viewhiddencategories', $childcontext)) ||
                      !has_capability('moodle/category:manage', $childcontext)) {
                  return false;
              }
          }
  
          // Check courses.
          $sql = context_helper::get_preload_record_columns_sql('ctx');
          $coursescontexts = $DB->get_records_sql('SELECT ctx.instanceid AS courseid, '.
                      $sql. ' FROM {context} ctx '.
                      'WHERE ctx.path like :pathmask and ctx.contextlevel = :courselevel',
                  array('pathmask' => $context->path. '/%',
                      'courselevel' => CONTEXT_COURSE));
          foreach ($coursescontexts as $ctxrecord) {
              context_helper::preload_from_record($ctxrecord);
              if (!can_delete_course($ctxrecord->courseid)) {
                  return false;
              }
          }
  
          return true;
      }
code_tokens: public function can_delete_full ( ) { global $ DB ; if ( ! $ this -> id ) { // Fool-proof. return false ; } $ context = $ this -> get_context ( ) ; if ( ! $ this -> is_uservisible ( ) || ! has_capability ( 'moodle/category:manage' , $ context ) ) { return false ; } // Check all child categories (not only direct children). $ sql = context_helper :: get_preload_record_columns_sql ( 'ctx' ) ; $ childcategories = $ DB -> get_records_sql ( 'SELECT c.id, c.visible, ' . $ sql . ' FROM {context} ctx ' . ' JOIN {course_categories} c ON c.id = ctx.instanceid' . ' WHERE ctx.path like ? AND ctx.contextlevel = ?' , array ( $ context -> path . '/%' , CONTEXT_COURSECAT ) ) ; foreach ( $ childcategories as $ childcat ) { context_helper :: preload_from_record ( $ childcat ) ; $ childcontext = context_coursecat :: instance ( $ childcat -> id ) ; if ( ( ! $ childcat -> visible && ! has_capability ( 'moodle/category:viewhiddencategories' , $ childcontext ) ) || ! has_capability ( 'moodle/category:manage' , $ childcontext ) ) { return false ; } } // Check courses. $ sql = context_helper :: get_preload_record_columns_sql ( 'ctx' ) ; $ coursescontexts = $ DB -> get_records_sql ( 'SELECT ctx.instanceid AS courseid, ' . $ sql . ' FROM {context} ctx ' . 'WHERE ctx.path like :pathmask and ctx.contextlevel = :courselevel' , array ( 'pathmask' => $ context -> path . '/%' , 'courselevel' => CONTEXT_COURSE ) ) ; foreach ( $ coursescontexts as $ ctxrecord ) { context_helper :: preload_from_record ( $ ctxrecord ) ; if ( ! can_delete_course ( $ ctxrecord -> courseid ) ) { return false ; } } return true ; }
docstring: Returns true if user can delete current category and all its contents
  
  To be able to delete course category the user must have permission
  'moodle/category:manage' in ALL child course categories AND
  be able to delete all courses
  
  @return bool
docstring_tokens: Returns true if user can delete current category and all its contents