Viewing file:      m_ea_curriculumdetails.php (3.17 KB)      -rwxr-xr-x Select action/file-type:    (+) |   (+) |   (+) | Code (+) | Session (+) |   (+) | SDB (+) |   (+) |   (+) |   (+) |   (+) |   (+) |
 
<?php
 
 include_once("da_ea_CurriculumDetails.php");
 
 class M_ea_curriculumdetails extends Da_ea_curriculumdetails {
 
     /*
      * aOrderBy = array('fieldname' => 'ASC|DESC', ... )
      */
     function get_all($aOrderBy=""){
         $orderBy = "";
         if ( is_array($aOrderBy) ) {
             $orderBy.= "ORDER BY "; 
             foreach ($aOrderBy as $key => $value) {
                 $orderBy.= "$key $value, ";
             }
             $orderBy = substr($orderBy, 0, strlen($orderBy)-2);
         }
         $sql = "SELECT * 
                 FROM $this->ea_dbname.ea_CurriculumDetails 
                 $orderBy";
         $query = $this->db->query($sql);
         return $query;
     }
 
     public function qryCurd($condition="",$order="",$group="") {
         $where = $this->checkCondition($condition);
         $order = $this->checkOrderBy($order);
         $group = $this->checkGroupBy($group);
 
         $c1 = substr($where, 0, -3);
         $c2 = substr($order, 0, -1);
         $c3 = substr($group, 0, -1);
 
         $sql = "SELECT *
                     FROM $this->ea_dbname.ea_CurriculumDetails
                     $c1
                     $c2
                     $c3";
         $query = $this->db->query($sql);
         return $query;
     }
 
     public function get_options($condition="",$order="",$group="",$optional='y') {
         $query = $this->qryCurd($condition,$order,$group);
         if($optional=='y') $opt[''] = '';
         foreach($query->result() as $row) {
             $opt[$row->curId] = $row->curName;
         }
         return $opt;
     }
 
     public function qryMaxIdByCurAddTypeIsA() {
         // เพิ่มหลักสูตรเองได้ โดยมี id เริ่มต้นที่ 9001
         $sql = "SELECT IFNULL(MAX(curId), 9000) + 1 AS curId
                 FROM $this->ea_dbname.ea_CurriculumDetails
                 WHERE curAddType='A'";
         $query = $this->db->query($sql);
         return $query->row()->curId;
     }
 
     public function qryCurdNotId($curName, $curCcId, $curEdgId, $curElvId, $curId) {
         $sql = "SELECT *
                 FROM $this->ea_dbname.ea_CurriculumDetails
                 WHERE curName=?
                 AND curCcId=?
                 AND curEdgId=?
                 AND curElvId=?
                 AND curId <> ?";
         $query = $this->db->query($sql,array($curName, $curCcId, $curEdgId, $curElvId, $curId));
         return $query;
     }
 
     public function get_optionsCurId() {
         $sql = "SELECT programId
                 FROM $this->ea_dbname.AlumniMain
                 GROUP BY programId";
         $query = $this->db->query($sql);
 
         $opt[''] = "";
         if($query->num_rows()) {
             foreach($query->result() as $row) {
                 $this->curId = $row->programId;
                 $this->get_by_key(TRUE);
                 $opt[$row->programId] = $this->curName;
             }
         }
         return $opt;
     }
 
     public function qryCurdJoinLev($condition="",$order="",$group="") {
         $where = $this->checkCondition($condition);
         $order = $this->checkOrderBy($order);
         $group = $this->checkGroupBy($group);
 
         $c1 = substr($where, 0, -3);
         $c2 = substr($order, 0, -1);
         $c3 = substr($group, 0, -1);
 
         $sql = "SELECT *
                 FROM $this->ea_dbname.ea_CurriculumDetails
                 LEFT JOIN $this->ppc_dbname.Level ON curElvId=levelId
                 $c1
                 $c3
                 $c2";
         $query = $this->db->query($sql);
         return $query;
     }
 
     public function get_countAll() {
         $sql = "SELECT COUNT(curId) AS curId
                 FROM $this->ea_dbname.ea_CurriculumDetails";
         $query = $this->db->query($sql);
         return $query->row()->curId;
     }
     // add your functions here
 
 } // end class M_ea_curriculumdetails
 ?>
  |