You are here

class TaxonomyEdgeDatabaseTransaction in Taxonomy Edge 6

Class for simulating DBTNG transactions

Hierarchy

Expanded class hierarchy of TaxonomyEdgeDatabaseTransaction

File

./taxonomy_edge.module, line 601
Selecting all children of a given taxonomy term can be a pain. This module makes it easier to do this, by maintaining a complete list of edges for each term using the adjecency matrix graph theory.

View source
class TaxonomyEdgeDatabaseTransaction {
  private $end;
  private static $counter = 0;
  function __construct($begin = NULL, $end = NULL) {
    if ($begin && $end) {
      $this->end = $end;
      call_user_func($begin);
    }
    else {
      self::begin();
    }
  }
  function __destruct() {
    $this
      ->commit();
  }
  private static function begin() {
    if (self::$counter == 0) {
      db_query('BEGIN');
    }
    self::$counter++;
  }
  private static function end($commit = TRUE) {
    self::$counter--;
    if (self::$counter == 0) {
      if ($commit) {
        db_query('COMMIT');
      }
      else {
        db_query('ROLLBACK');
      }
    }
  }
  function commit() {
    if ($this->end) {
      return call_user_func($this->end, TRUE);
    }
    else {
      return self::end(TRUE);
    }
  }
  function rollback() {
    if ($this->end) {
      return call_user_func($this->end, FALSE);
    }
    else {
      return self::end(FALSE);
    }
  }

}

Members