Viewing file:      my_model.php (3.11 KB)      -rwxr-xr-x Select action/file-type:    (+) |   (+) |   (+) | Code (+) | Session (+) |   (+) | SDB (+) |   (+) |   (+) |   (+) |   (+) |   (+) |
 
<?php
 /**
  * System in Educational Enterprise Resource Planning System
  *
  * LICENSE
  *
  * This source file is subject to the GPL license that is bundled
  * with this package in the file licence.txt.
  *
  * @package        System in Educational Enterprise Resource Planning System
  * @subpackage    Registration System
  * @copyright      Copyright (C) 2011 by Information System Engineering Research Labolatory, Burapha University
                 http://iserl.buu.ac.th
                 iserl.callcenter@gmail.com
  * @license        http://cvs.buu.ac.th/mis/license.php GNU GPL v1
  * @author         Information System Engineering Research Labolatory, Burapha University
  *
  *
  */
  ?>
 <?php
 class My_model extends CI_Model {
     protected $ppc_dbname;
     protected $rg_dbname;
 
     function __construct() {
         parent::__construct();
         $this->ppc_dbname = $this->config->item('ppc_dbname');
         $this->rg_dbname = $this->config->item('rg_dbname');
         $this->ums_dbname = $this->config->item('ums_dbname');
     }
 
     public $last_query;
 
     function row2attribute($rw) {
         foreach ($rw as $key => $value) {
             if ( is_null($value) ) 
                 eval("\$this->$key = NULL;");
             else
                 eval("\$this->$key = '$value';");
         }
     }
 
     /**
      * หน้าที่ของฟังก์ชั่น คือ ต่อสตริงของ sql->where
      *
      * @access    public
      * @param    array condition โดยรูปแบบของ array จะอยู่ในรูป condition('key' => value)
      * @return    string con โดยอยู่ในรูปแบบ WHERE $field='$value'
      */
     public function checkCondition($condition="") {
         $con = "";
         if($condition) {
             $con .= "WHERE";
             foreach($condition as $key => $value) {
                 if ($value=='NULL')
                     $con .= " $key IS $value AND";
                 else if ((substr($value, 0, 1) == '%') || (substr($value, -1) == '%'))
                     $con .= " $key LIKE '$value' AND";
                 else
                     $con .= " $key='$value' AND";
             }
         }
         return $con;
     }
 
     /**
      * หน้าที่ของฟังก์ชั่น คือ ต่อสตริงของ sql->order by
      *
      * @access    public
      * @param    array condition โดยรูปแบบของ array จะอยู่ในรูป condition('key' => value)
      * @return    string con โดยอยู่ในรูปแบบ ORDER $field
      */
     public function checkOrderBy($condition="") {
         $con = "";
         if($condition) {
             $con .= "ORDER BY";
             foreach ($condition as $key => $value) {
                 $con .= " CONVERT($key USING TIS620) $value,";
             }
         }
         return $con;
     }
 
     /**
      * หน้าที่ของฟังก์ชั่น คือ ต่อสตริงของ sql->group by
      *
      * @access    public
      * @param    array condition โดยรูปแบบของ array จะอยู่ในรูป condition('key' => value)
      * @return    string con โดยอยู่ในรูปแบบ GROUP BY $field
      */
     public function checkGroupBy($condition="") {
         $con = "";
         if($condition) {
             $con .= "GROUP BY";
             foreach ($condition as $key => $value) {
                 $con .= " $value ,";
             }
         }
         return $con;
     }
 
 }
 ?>
  |