Mysql_User_Theme_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:5k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. class Mysql_User_Theme_Db extends BaseObject {
  3.    var $debug;
  4.    var $user_db;
  5.    Function Mysql_User_Theme_Db( $db_config = '' ) {
  6.       $this->BaseObject( 'Mysql_User_Theme_Db' );
  7.       $this->user_db           = new Mysql_Db();
  8.       if ( is_object( $db_config ) ) {
  9.         $this->user_db->db = $db_config;
  10.       }
  11.       $this->debug                  = new Debug();
  12.       $this->debug->prefix          = 'Mysql_Db::Mysql_User_Theme';
  13.       $this->debug->Off();
  14.       $this->user_db->debug->Off();
  15.    }
  16.    Function InitDbConnection() {
  17.       /*
  18.         Make sure the database handle is available 
  19.         ( if not try to open it ) 
  20.       */
  21.       $returns = Array();
  22.       if ( $this->user_db->connection_init == false) {
  23.          $returns = $this->user_db->CreateConnection();
  24.       }
  25.       /* Oh no we failed to open the connection */
  26.       if ( $this->user_db->connection_init == false ) {
  27.          return array( false, 'Database not connected', $returns );
  28.       }
  29.       return array( true );
  30.    }
  31.    Function ListAll() { /* NA */ }
  32.    Function Add( $theme_obj ) {
  33.       /* Make sure the database handle is available */
  34.       /* Init the database connection and bubble up errors */
  35.       $this->debug->Message( 'Init connection' );
  36.       list( $ret_val, $reason ) = $this->InitDbConnection();
  37.       if ( $ret_val == false ) {
  38.       $this->debug->Message( 'connect failed' );
  39.          return array( $ret_val, $reason );
  40.       }
  41.       $sql_util = new SqlUtil();
  42.       /* Look ma no hands, and out comes a nice formated sql */
  43.       $insert_theme = $this->user_db->PrepareSql(
  44.          $sql_util->InsertStatement(
  45.             'user_theme_table',
  46.             Array(
  47.                'user_id'      => $theme_obj->user_id,
  48.                'theme'        => $theme_obj->theme_name
  49.             )
  50.          )
  51.       );
  52.       list( $ret_val, $reason ) = $insert_theme->Exec();
  53.       if ( ! $ret_val ) {
  54.          return Array( false, 'Insert to table failed.' );
  55.       } else {
  56.          return Array( true );
  57.       }
  58.    } /* End add */
  59.    Function Delete( $user_id ) { 
  60.       /* Make sure the database handle is available */
  61.       /* Init the database connection and bubble up errors */
  62.       $this->debug->Message( 'Init connection' );
  63.       list( $ret_val, $reason ) = $this->InitDbConnection();
  64.       if ( $ret_val == false ) {
  65.       $this->debug->Message( 'connect failed' );
  66.          return array( $ret_val, $reason );
  67.       }
  68.       $sql_util = new SqlUtil();
  69.       /* Look ma no hands, and out comes a nice formated sql */
  70.       $delete_theme = $this->user_db->PrepareSql(
  71.          $sql_util->DeleteStatement(
  72.             'user_theme_table',
  73.             'user_id = ' . $user_id
  74.          )
  75.       );
  76.       list( $ret_val, $reason ) = $delete_theme->Exec();
  77.       if ( ! $ret_val ) {
  78.          return Array( false, 'Delete of theme failed.' );
  79.       } else {
  80.          return Array( true );
  81.       }
  82.    }
  83.    Function Get( $user_id )    { 
  84.       /* Make sure the database handle is available */
  85.       /* Init the database connection and bubble up errors */
  86.       $this->debug->Message( 'Init connection' );
  87.       list( $ret_val, $reason ) = $this->InitDbConnection();
  88.       if ( $ret_val == false ) {
  89.       $this->debug->Message( 'connect failed' );
  90.          return array( $ret_val, $reason );
  91.       }
  92.       $sql_util = new SqlUtil();
  93.       /* Look ma no hands, and out comes a nice formated sql */
  94.       $get_theme = $this->user_db->PrepareSql(
  95.          $sql_util->SelectStatement(
  96.             Array( 'user_theme_table' ),
  97.             Array( 'user_id', 'theme' ),
  98.             'user_id = ' . $user_id
  99.          )
  100.       );
  101.       if ( ! (
  102.          list( $user_id, $theme_name ) = $get_theme->FetchRow()
  103.          ) ) {
  104.          return Array( false, 'No match found.' );
  105.       } else {
  106.          $theme_obj = new User_Theme();
  107.          $theme_obj->user_id       = $user_id;
  108.          $theme_obj->theme_name     = $theme_name;
  109.          return Array( true, $theme_obj );
  110.       }
  111.    }
  112.    Function Modify( $theme_obj ) {
  113.       /* Make sure the database handle is available */
  114.       /* Init the database connection and bubble up errors */
  115.       $this->debug->Message( 'Init connection' );
  116.       list( $ret_val, $reason ) = $this->InitDbConnection();
  117.       if ( $ret_val == false ) {
  118.       $this->debug->Message( 'connect failed' );
  119.          return array( $ret_val, $reason );
  120.       }
  121.       $sql_util = new SqlUtil();
  122.       /* Look ma no hands, and out comes a nice formated sql */
  123.       $update_theme = $this->user_db->PrepareSql(
  124.          $sql_util->UpdateStatement(
  125.             'user_theme_table',
  126.             Array(
  127.                'theme'       => $theme_obj->theme_name
  128.             ),
  129.             'user_id = ' . $theme_obj->user_id
  130.          )
  131.       );
  132.       list( $ret_val, $reason ) = $update_theme->Exec();
  133.       if ( ! $ret_val ) {
  134.          return Array( false, 'Update of theme failed.' );
  135.       } else {
  136.          return Array( true );
  137.       }
  138.    }
  139. }
  140. ?>