Viewing file: sa_target_group_model.php (2.68 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include_once("da_sa_target_group.php");
class Sa_target_group_model extends Da_sa_target_group {
/*
* 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->sa_dbname.sa_target_group
$orderBy";
$query = $this->db->query($sql);
return $query;
}
/*
* create array of pk field and value for generate select list in view, must edit PK_FIELD and FIELD_NAME manually
* the first line of select list is '-----เลือก-----' by default.
* if you do not need the first list of select list is '-----เลือก-----', please pass $optional parameter to other values.
* you can delete this function if it not necessary.
*/
function get_options($optional='y') {
$qry = $this->get_all();
if ($optional=='y') $opt[''] = '-----เลือก-----';
foreach ($qry->result() as $row) {
$opt[$row->PK_FIELD] = $row->FIELD_NAME;
}
return $opt;
}
// add your functions here
function get_by_dpj() {
$sql = "SELECT *
FROM $this->sa_dbname.sa_target_group
LEFT JOIN $this->rg_dbname.rg_Curriculum ON curId = tg_cur_id
LEFT JOIN $this->sa_dbname.sa_smo_club ON sc_id = tg_sc_id
WHERE tg_dpj_id = ?";
$query = $this->db->query($sql,array($this->tg_dpj_id));
return $query;
}
function get_by_dpj_type() {
$sql = "SELECT *
FROM $this->sa_dbname.sa_target_group
WHERE tg_dpj_id = ?
AND tg_type = ?";
$query = $this->db->query($sql,array($this->tg_dpj_id, $this->tg_type));
return $query;
}
function get_by_dpj_type_cur_tm() {
$cond = "";
if ($this->tg_cur_id) {
$cond .= " AND tg_cur_id = ".$this->tg_cur_id;
}
if ($this->tg_tm_id && ($this->tg_tm_id != 'NULL')) {
$cond .= " AND tg_tm_id = ".$this->tg_tm_id;
} else if ($this->tg_tm_id == 'NULL') {
$cond .= " AND tg_tm_id IS NULL";
}
if ($this->tg_sc_id) {
$cond .= " AND tg_sc_id = ".$this->tg_sc_id;
}
$sql = "SELECT IFNULL(SUM(tg_num), 0) AS num
FROM $this->sa_dbname.sa_target_group
WHERE tg_dpj_id = ?
AND tg_type = ?".$cond;
$query = $this->db->query($sql,array($this->tg_dpj_id, $this->tg_type));
if ($query->num_rows())
return $query->row()->num;
else
return 0;
}
function delete_tg($mpj) {
$sql = "DELETE
FROM $this->sa_dbname.sa_target_group
WHERE tg_dpj_id = ?";
$this->db->query($sql,array($mpj));
}
} // end class Sa_target_group_model
?>
|