File: /home/dmstechonline/crm.chaitanyahospitalvirar.com/application/models/Floor_model.php
<?php
class Floor_model extends MY_Model
{
public function valid_floor($str)
{
$name = $this->input->post('name');
if ($this->check_floor_exists($name)) {
$this->form_validation->set_message('check_exists', $this->lang->line('floor') . " " . $this->lang->line('record_already_exists'));
return false;
} else {
return true;
}
}
public function check_floor_exists($name)
{
if ($name != 0) {
$data = array('name' => $name);
$query = $this->db->where($data)->get('floor');
if ($query->num_rows() > 0) {
return true;
} else {
return false;
}
} else {
$this->db->where('name', $name);
$query = $this->db->get('floor');
if ($query->num_rows() > 0) {
return true;
} else {
return false;
}
}
}
public function saveFloor($data)
{
$this->db->trans_start(); # Starting Transaction
$this->db->trans_strict(false); # See Note 01. If you wish can remove as well
//=======================Code Start===========================
if (isset($data["id"])) {
$this->db->where("id", $data["id"])->update("floor", $data);
$message = UPDATE_RECORD_CONSTANT . " On Floor id " . $data['id'];
$action = "Update";
$record_id = $data['id'];
$this->log($message, $record_id, $action);
} else {
$this->db->insert("floor", $data);
$insert_id = $this->db->insert_id();
$message = INSERT_RECORD_CONSTANT . " On Floor id " . $insert_id;
$action = "Insert";
$record_id = $insert_id;
$this->log($message, $record_id, $action);
}
//======================Code End==============================
$this->db->trans_complete(); # Completing transaction
/* Optional */
if ($this->db->trans_status() === false) {
# Something went wrong.
$this->db->trans_rollback();
return false;
} else {
return $record_id;
}
}
public function floor_list($id = null)
{
$this->db->select()->from('floor');
if ($id != null) {
$this->db->where('floor.id', $id);
} else {
$this->db->order_by('floor.id', 'desc');
}
$query = $this->db->get();
if ($id != null) {
return $query->row_array();
} else {
return $query->result_array();
}
}
public function delete($id)
{
$this->db->trans_start(); # Starting Transaction
$this->db->trans_strict(false); # See Note 01. If you wish can remove as well
//=======================Code Start===========================
$this->db->where("id", $id)->delete("floor");
$message = DELETE_RECORD_CONSTANT . " On Floor id " . $id;
$action = "Delete";
$record_id = $id;
$this->log($message, $record_id, $action);
//======================Code End==============================
$this->db->trans_complete(); # Completing transaction
/* Optional */
if ($this->db->trans_status() === false) {
# Something went wrong.
$this->db->trans_rollback();
return false;
} else {
return $record_id;
}
}
}