File:  [Local Repository] / db / prgsrc / drupal / modules / chgk_db / classes / DbDatabase.class.php
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Sat Apr 24 21:45:49 2010 UTC (14 years ago) by roma7
Branches: MAIN
CVS tags: HEAD
Version 2 big update

    1: <?php  
    2: 
    3: 
    4: class DbDatabase  {
    5:   const QUESTION_TABLE='Questions';
    6:   const TOURNAMENT_TABLE='Tournaments';
    7:   const PEOPLE_TABLE = 'People';
    8:   const P2T_TABLE = 'P2T';
    9:   public function getTournament($id) {
   10:       if (is_numeric($id)) {
   11:           return $this->getTournamentByDatabaseId($id);
   12:       } else {
   13:           return $this->getTournamentByTextId($id);
   14:       }
   15:   }
   16: 
   17:   public function getAllEditorsRes() {
   18:       $res = db_query("SELECT People.* from  P2T LEFT JOIN People ON (P2T.Author=People.CharId)
   19:             GROUP BY CharId ORDER BY TNumber DESC");
   20:       return $res;
   21: 
   22:   }
   23:   
   24:   public function getEditors($id) {
   25:     $sql = "SELECT People.* from  P2T LEFT JOIN People ON (P2T.Author=People.CharId)
   26:     WHERE P2T.Tour='$id'";
   27:     $res = db_query($sql);
   28:     $result = array();
   29:     while ($e = db_fetch_object($res)) {
   30:       $result[] = $e;
   31:     }
   32:     return $result;
   33:   }
   34: 
   35:   public function getTournamentByDatabaseId($id){
   36:     $sql = sprintf ("SELECT * FROM %s t
   37:       WHERE t.Id = '%d'", self::TOURNAMENT_TABLE, $id);
   38:     $res = db_query($sql);
   39:     return db_fetch_object($res);
   40:   }
   41:   public function getTournamentByTextId($id){
   42: /*    if (!preg_match('/\./', $id)) {
   43:       $id .= '.txt';
   44:     }*/
   45: 
   46:     $sql = sprintf ("SELECT * FROM %s t
   47:       WHERE t.FileName = '%s.txt' OR t.FileName = '%s'", 
   48:       self::TOURNAMENT_TABLE, $id, $id);
   49:     $res = db_query($sql);
   50:     return db_fetch_object($res);
   51:   }
   52: 
   53:   public function getPersonById($id){
   54:     $sql = sprintf ("SELECT * FROM %s a
   55:       WHERE a.CharId = '%s'",
   56:       self::PEOPLE_TABLE, $id);
   57:     $res = db_query($sql);
   58:     return db_fetch_object($res);
   59:   }
   60: 
   61:   public function editorToursRes($id) {
   62:     $res = db_query("SELECT t.* FROM %s t
   63:                 LEFT JOIN %s p2t ON
   64:                 (p2t.Tour = t.Id)
   65:                 WHERE p2t.Author = '%s'
   66:                 ORDER BY PlayedAt DESC, Title ",
   67:             self::TOURNAMENT_TABLE,
   68:             self::P2T_TABLE,
   69:             $id);
   70:     return $res;
   71:   }
   72: 
   73:   public function getQuestionsRes($id) {
   74:     $sql = sprintf("SELECT * FROM {%s} WHERE ParentId=%d ORDER BY Number", self::QUESTION_TABLE, $id);
   75:     return db_query($sql);
   76:   }
   77: 
   78:   public function getChildrenRes($id) {
   79:     $sql = sprintf("SELECT * FROM {%s} WHERE ParentId=%d ORDER BY Number, Id", self::TOURNAMENT_TABLE, $id);
   80:     return db_query($sql);
   81:   }
   82:   
   83:   public function fetch_row($res) {
   84:     return db_fetch_object($res);
   85:   }
   86: 
   87:   public function getFulltextSearchRes( $sstr, $options = array()) {
   88:     $sql="SELECT
   89:       t.FileName as tourFileName,
   90:       t1.FileName as tournamentFileName,
   91:       q.*,
   92:       t.Id as tourId,
   93:       t1.id as tournamentId,
   94:       t.Title as tourTitle,
   95:       t1.Title as tournamentTitle,
   96:       t.Type as tourType,
   97:       t1.Type as tournamentType
   98: 
   99:     FROM %1\$s q
  100:     LEFT JOIN %2\$s t ON (q.ParentId=t.Id)
  101:     LEFT JOIN  %2\$s t1 ON (t.ParentId=t1.Id)
  102:     WHERE
  103:      MATCH (Question,Answer,PassCriteria,Comments) AGAINST ('%3\$s' IN BOOLEAN MODE)
  104:     ORDER BY MATCH (Question,Answer,PassCriteria,Comments) AGAINST
  105:      ('%3\$s' IN BOOLEAN MODE) DESC LIMIT %4\$s";
  106:     $limit = 20;
  107:     $sql = sprintf($sql,
  108:             self::QUESTION_TABLE,
  109:             self::TOURNAMENT_TABLE,
  110:             $sstr,
  111:             $limit);
  112:       return db_query($sql);    
  113:   }
  114: 
  115: }
  116: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>