D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
public_html
/
cas
/
application
/
models
/
admin
/
Filename :
RelationManagement.php
back
Copy
<?php /** * Model For Handling All DB Operations Related To Relations * * @author Softpro India Pvt. Ltd. */ defined('BASEPATH') OR exit('No direct script access allowed'); class RelationManagement extends CI_Model { function createNewRelation(array $newRelationInfo) { $this->db->insert('tbl_relation_master', $newRelationInfo); return $this->db->insert_id(); } function getAllRelations() { $this->db->select("TRLM.rel_id,TRLM.rel_title,TRLM.rel_code,TRLM.rel_active_status,TRLM.rel_delete_status," . "TRLM.rel_added_by,TRLM.rel_added_on,TRLM.rel_updated_by,TRLM.rel_updated_on," . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin," . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin"); $this->db->from('tbl_relation_master TRLM'); $this->db->join('tbl_staff_members TSMA', 'TRLM.rel_added_by = TSMA.smember_id'); $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id'); $this->db->join('tbl_staff_members TSMU', 'TRLM.rel_updated_by = TSMU.smember_id'); $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id'); $this->db->order_by("TRLM.rel_updated_on", "desc"); return $this->db->get(); } function getAllNonDeletedActiveRelations() { $this->db->select('*'); $this->db->from('tbl_relation_master TRM'); $this->db->where('TRM.rel_active_status', 'T'); $this->db->where('TRM.rel_delete_status', 'F'); return $this->db->get(); } function getRelationInfoBy($rel_id) { $this->db->select("TRLM.rel_id,TRLM.rel_title,TRLM.rel_code,TRLM.rel_active_status,TRLM.rel_delete_status," . "TRLM.rel_added_by,TRLM.rel_added_on,TRLM.rel_updated_by,TRLM.rel_updated_on," . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin," . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin"); $this->db->from('tbl_relation_master TRLM'); $this->db->join('tbl_staff_members TSMA', 'TRLM.rel_added_by = TSMA.smember_id'); $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id'); $this->db->join('tbl_staff_members TSMU', 'TRLM.rel_updated_by = TSMU.smember_id'); $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id'); $this->db->where("TRLM.rel_id", $rel_id); return $this->db->get(); } function getRelationInfoByName($rel_title) { $this->db->select("TRLM.rel_id,TRLM.rel_title,TRLM.rel_code,TRLM.rel_active_status,TRLM.rel_delete_status," . "TRLM.rel_added_by,TRLM.rel_added_on,TRLM.rel_updated_by,TRLM.rel_updated_on," . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin," . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin"); $this->db->from('tbl_relation_master TRLM'); $this->db->join('tbl_staff_members TSMA', 'TRLM.rel_added_by = TSMA.smember_id'); $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id'); $this->db->join('tbl_staff_members TSMU', 'TRLM.rel_updated_by = TSMU.smember_id'); $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id'); $this->db->where("TRLM.rel_title", $rel_title); return $this->db->get(); } function getRelationInfoByCode($rel_code) { $this->db->select("TRLM.rel_id,TRLM.rel_title,TRLM.rel_code,TRLM.rel_active_status,TRLM.rel_delete_status," . "TRLM.rel_added_by,TRLM.rel_added_on,TRLM.rel_updated_by,TRLM.rel_updated_on," . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin," . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin"); $this->db->from('tbl_relation_master TRLM'); $this->db->join('tbl_staff_members TSMA', 'TRLM.rel_added_by = TSMA.smember_id'); $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id'); $this->db->join('tbl_staff_members TSMU', 'TRLM.rel_updated_by = TSMU.smember_id'); $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id'); $this->db->where("TRLM.rel_code", $rel_code); return $this->db->get(); } function isRelationNameSafeUpdate($rel_id, $rel_title) { $this->db->select("*"); $this->db->from('tbl_relation_master'); $this->db->where('rel_title', $rel_title); $this->db->where('rel_id != ' . $rel_id); $result = $this->db->get()->result(); if (sizeof($result)) { return FALSE; } else { return TRUE; } } function isRelationCodeSafeUpdate($rel_id, $rel_code) { $this->db->select("*"); $this->db->from('tbl_relation_master'); $this->db->where('rel_code', $rel_code); $this->db->where('rel_id != ' . $rel_id); $result = $this->db->get()->result(); if (sizeof($result)) { return FALSE; } else { return TRUE; } } function updateRelationInfo(array $relationUpdatedInfo) { $this->db->where('rel_id', $relationUpdatedInfo['rel_id']); return $this->db->update('tbl_relation_master', $relationUpdatedInfo); } /* Functions For Family Background Info */ function getRelativeInfoBy($mapping_id, $rel_id, $user_type) { $this->db->select("*"); $this->db->from('tbl_family_background_info'); $this->db->where('tfbi_mapping_id', $mapping_id); $this->db->where('tfbi_user_type_flag', $user_type); $this->db->where('tfbi_relation', $rel_id); return $this->db->get(); } }