Annotation of db/prgsrc/drupal/modules/chgk_db/classes/DbDatabase.class.php, revision 1.4

1.4     ! roma7       1: <?php  
        !             2: 
1.1       roma7       3: 
                      4: class DbDatabase  {
                      5:   const QUESTION_TABLE='Questions';
                      6:   const TOURNAMENT_TABLE='Tournaments';
1.4     ! roma7       7:   const PEOPLE_TABLE = 'People';
        !             8:   const P2T_TABLE = 'P2T';
1.1       roma7       9:   public function getTournament($id) {
1.2       roma7      10:       if (is_numeric($id)) {
                     11:           return $this->getTournamentByDatabaseId($id);
                     12:       } else {
                     13:           return $this->getTournamentByTextId($id);
                     14:       }
                     15:   }
                     16: 
1.4     ! roma7      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: 
1.2       roma7      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){
1.4     ! roma7      42: /*    if (!preg_match('/\./', $id)) {
1.1       roma7      43:       $id .= '.txt';
1.4     ! roma7      44:     }*/
1.1       roma7      45: 
1.2       roma7      46:     $sql = sprintf ("SELECT * FROM %s t
1.4     ! roma7      47:       WHERE t.FileName = '%s.txt' OR t.FileName = '%s'", 
        !            48:       self::TOURNAMENT_TABLE, $id, $id);
1.2       roma7      49:     $res = db_query($sql);
1.1       roma7      50:     return db_fetch_object($res);
                     51:   }
1.4     ! roma7      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: 
1.1       roma7      73:   public function getQuestionsRes($id) {
1.3       roma7      74:     $sql = sprintf("SELECT * FROM {%s} WHERE ParentId=%d ORDER BY Number", self::QUESTION_TABLE, $id);
1.1       roma7      75:     return db_query($sql);
                     76:   }
1.2       roma7      77: 
1.4     ! roma7      78:   public function getChildrenRes($id) {
        !            79:     $sql = sprintf("SELECT * FROM {%s} WHERE ParentId=%d ORDER BY Number, Id", self::TOURNAMENT_TABLE, $id);
1.2       roma7      80:     return db_query($sql);
                     81:   }
1.1       roma7      82:   
                     83:   public function fetch_row($res) {
                     84:     return db_fetch_object($res);
                     85:   }
1.4     ! roma7      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: 
1.1       roma7     115: }
                    116: 

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