Viewing file: mo_rg_curriculumstructure.php (10.86 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php include_once("da_rg_CurriculumStructure.php"); class Mo_rg_curriculumstructure extends Da_rg_CurriculumStructure { /** * หน้าที่ของฟังก์ชั่น คือ หาข้อมูลโครงสร้างหลักสูตร ตามเงื่อนไข * * @access public * @param array condition โดยรูปแบบของ array จะอยู่ในรูป condition('key' => value) ไว้สำหรับระบุเงื่อนไขของคำสั่ง SELECT * @param array order โดยรูปแบบของ array จะอยู่ในรูป condition('key' => value) ไว้สำหรับระบุเงื่อนไขการเรียงลำดับ ORDER BY * @param array group โดยรูปแบบของ array จะอยู่ในรูป condition('key' => value) ไว้สำหรับระบุเงื่อนไขการจัดกลุ่ม GROUP BY * @return query >= 1 rows : rg_CurriculumStructure.* * @todo use */ public function qryCs($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->rg_dbname.rg_CurriculumStructure $c1 $c3 $c2"; $query = $this->db->query($sql); return $query; }
function qryCsJoinCd1($curId, $cdId1, $cdId2) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure INNER JOIN $this->rg_dbname.rg_Condition ON csCdId1 = cdId WHERE csCurId = ? AND csCdId1 = ? AND csCdId2 = ?"; $query = $this->db->query($sql, array($curId, $cdId1, $cdId2)); return $query; }
function qryCsJoinCd2($curId, $cdId1, $cdId2) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure INNER JOIN $this->rg_dbname.rg_Condition ON csCdId2 = cdId WHERE csCurId = ? AND csCdId1 = ? AND csCdId2 = ?"; $query = $this->db->query($sql, array($curId, $cdId1, $cdId2)); return $query; }
function qryCsByCurIdGroupCdId1($curId) { $sql = "SELECT MIN(csSeq) AS csSeq, csCdId1, MAX(csCreditTotal) AS csCreditTotal FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId = ? GROUP BY csCdId1 ORDER BY csSeq"; $query = $this->db->query($sql, array($curId)); return $query; }
// use function qryCsCdId1ByCsCurId($csCurId) { $sql = "SELECT csCdId1, MAX(csCreditTotal) AS csCreditToTal, rg_Condition.* FROM $this->rg_dbname.rg_CurriculumStructure INNER JOIN $this->rg_dbname.rg_Condition ON csCdId1 = cdId WHERE csCurId=? GROUP BY csCdId1 ORDER BY csSeq"; $query = $this->db->query($sql,array($csCurId)); return $query; }
function qryCsByCurIdCdId1CdId2GT1($curId, $cdId1) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId = ? AND csCdId1 = ? AND csCdId2 > 1 ORDER BY csSeq"; $query = $this->db->query($sql, array($curId, $cdId1)); return $query; }
/** * หน้าที่ของฟังก์ชั่น คือ หาข้อมูลโครงสร้างหลักสูตร ตามหมวด csCdId=1 และจำนวนหน่วยกิตตามเงื่อนไข * * @access public * @param array condition โดยรูปแบบของ array จะอยู่ในรูป condition('key' => value) ไว้สำหรับระบุเงื่อนไขของคำสั่ง SELECT * @return query = 1 rows : csCdId1, csCreditTotal * @todo use */ public function qryCsCdId1AndMaxCreditTotal($condition="") { $where = $this->checkCondition($condition);
$c1 = substr($where, 0, -3);
$sql = "SELECT csCdId1, MAX(csCreditTotal) AS csCreditTotal FROM $this->rg_dbname.rg_CurriculumStructure $c1 GROUP BY csCdId1 ORDER BY csSeq"; $query = $this->db->query($sql); return $query; }
/** * หน้าที่ของฟังก์ชั่น คือ หาข้อมูล หมวด หรือ กลุ่ม/หน่วย ที่ยังไม่ได้บันทึกบน โครงสร้าง * * @access public * @param cdType, csCurId, csCdId1, * @return query = 1 rows : condition * @todo use */ public function qryCdNotInCs($cdType="",$condition2="",$group="") {
$where2 = $this->checkCondition($condition2); $group = $this->checkGroupBy($group);
$w2 = substr($where2, 0, -3); $g = substr($group, 0, -1);
$w1 = ($cdType!='')?"AND cdType = '$cdType' ":""; $sql = "SELECT * FROM $this->rg_dbname.rg_Condition WHERE cdId NOT IN ( SELECT csCdId1 FROM $this->rg_dbname.rg_CurriculumStructure $w2 $g ) $w1 ORDER BY CONVERT(cdName USING tis620)"; $query = $this->db->query($sql); return $query; } public function get_opt_qryCdNotInCs($cdType="",$condition2="",$group="", $optional=false) { $query = $this->qryCdNotInCs($cdType,$condition2,$group); if($optional) $opt[''] = $optional; foreach($query->result() as $row) { $opt[$row->cdId] = str_pad($row->cdId, 3, '0', STR_PAD_LEFT).' '.$row->cdName.' ('.$row->cdNameE.')'; } return $opt; }
/* ย้ายมาจาก m_rg_curriculumstructure */ public function qryByCurIdOredrBySeq($curId) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? ORDER BY csSeq"; $query = $this->db->query($sql,array($curId)); return $query; } public function qryByCurIdCdId1CdId2($curId,$cdId1,$cdId2) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=? AND csCdId2=? ORDER BY csSeq"; $query = $this->db->query($sql,array($curId,$cdId1,$cdId2)); return $query; } public function CountCdId1($curId,$cdId1) { $sql = "SELECT COUNT(csCdId1) AS num FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=?"; $query = $this->db->query($sql,array($curId,$cdId1)); if ($row=$query->row()) return $row->num; } public function qryByCurIdGroupCdId1_2($curId) { $sql = "SELECT csCdId1, cdName, MAX(csCreditTotal) AS csCreditTotal FROM $this->rg_dbname.rg_CurriculumStructure, $this->rg_dbname.rg_Condition WHERE csCurId=? AND csCdId1=cdId GROUP BY csCdId1 ORDER BY csSeq"; $query = $this->db->query($sql, array($curId)); return $query; } public function qryByCurIdAndCdId2IsH($curId) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId2=1"; $query = $this->db->query($sql,array($curId)); return $query; } public function qryByCurIdOrderSeq1($curId) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId2=1 ORDER BY csSeq"; $query = $this->db->query($sql,array($curId)); $v = $this->db->last_query($query); echo $v; return $query; } public function qryByCurIdOrderSeq2($curId,$cdId1) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=? AND csCdId2!=1 ORDER BY csSeq"; $query = $this->db->query($sql,array($curId,$cdId1)); return $query; } public function getSumCurIdCreditTotal($curId) { $sql = "SELECT SUM(csCreditTotal) AS num FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId2=1"; $query = $this->db->query($sql,array($curId)); if ($row=$query->row()) return $row->num; } public function getSumCurIdCreditTotal2($curId,$cdId1) { $sql = "SELECT SUM(csCreditTotal) AS num FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=? AND csCdId2=1"; $query = $this->db->query($sql,array($curId,$cdId1)); if ($row=$query->row()) return $row->num; } public function getSumCdId1CreditTotal($curId,$cdId1) { $sql = "SELECT SUM(csCreditTotal) AS num FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=? AND csCdId2>1"; $query = $this->db->query($sql,array($curId,$cdId1)); if ($row=$query->row()) return $row->num; } public function getSumCdId1CreditTotal2($curId,$cdId1,$cdId2) { $sql = "SELECT SUM(csCreditTotal) AS num FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=? AND csCdId2=?"; $query = $this->db->query($sql,array($curId,$cdId1,$cdId2)); if ($row=$query->row()) return $row->num; } public function qryByCurIdAndCdId1($curId,$cdId1) { $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=? AND csCdId2>1"; $query = $this->db->query($sql,array($curId,$cdId1)); return $query; } public function getNextCodeCG($curId,$cdId1) { $sql = "SELECT MAX(csSeq) AS num FROM $this->rg_dbname.rg_CurriculumStructure WHERE csCurId=? AND csCdId1=?"; $query = $this->db->query($sql,array($curId,$cdId1)); if ($row=$query->row()) return $row->num+1; }
public function qryCdByCurId($curId) { $sql = "SELECT q1.* , q2.cdName AS DcdName FROM ( SELECT csCdId1, csCdId2, csSeq, csCreditTotal, cdName AS HcdName FROM $this->rg_dbname.rg_CurriculumStructure JOIN $this->rg_dbname.rg_Condition cd ON csCdId1 = cdId WHERE csCurId = ? ORDER BY csSeq ) AS q1 LEFT JOIN $this->rg_dbname.rg_Condition q2 ON q1.csCdId2 = q2.cdId WHERE 1=1 ORDER BY q1.csSeq "; $query = $this->db->query($sql,array($curId)); return $query; }
// -- ค้นหา condition level 1 function qryCsLv1(){ $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure INNER JOIN $this->rg_dbname.rg_Condition cd ON csCdId1 = cdId WHERE csCurId = ? AND csCdId2 = 1 ORDER BY csSeq "; $query = $this->db->query($sql,array($this->csCurId)); return $query; }
// -- ค้นหา condition level 2 function qryCsLv2(){ $sql = "SELECT * FROM $this->rg_dbname.rg_CurriculumStructure INNER JOIN $this->rg_dbname.rg_Condition cd ON csCdId2 = cdId WHERE csCurId = ? AND csCdId1 = ? ORDER BY csSeq "; //AND csCdId2 != 1 $query = $this->db->query($sql,array($this->csCurId,$this->csCdId1)); return $query; } /* end ย้ายมาจาก m_rg_curriculumstructure */ } ?>
|