File: /home/cafsindia/crm_cafsindia_com/application/models/Team_model.php
<?php
class Team_model extends Person
{
/* SAT-Performs a search on Teams */
public function search($search, $rows = 0, $limit_from = 0, $sort = 'team_id', $order = 'asc'){
$this->db->from('team');
$this->db->join('employees', 'employees.id = team.teamleader');
$this->db->join('people', 'people.person_id = employees.person_id');
$this->db->join('category', 'category.cat_id = team.category');
$this->db->group_start();
$this->db->like('teamname', $search);
$this->db->or_like('team.category', $search);
$this->db->or_like('people.first_name', $search);
$this->db->group_end();
$this->db->where('team.deleted', 0);
$this->db->order_by($sort, $order);
if($rows > 0){
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
/* SAT-Gets rows */
public function get_found_rows($search){
$this->db->from('team');
$this->db->group_start();
$this->db->like('teamname', $search);
$this->db->or_like('category', $search);
$this->db->or_like('teamleader', $search);
$this->db->or_like('status', $search);
$this->db->group_end();
$this->db->where('deleted', 0);
return $this->db->get()->num_rows();
}
/* SAT-Gets information about a particular team */
public function get_info($team_id){
$this->db->from('team');
$this->db->where('team_id', $team_id);
$this->db->where('deleted', 0);
$query = $this->db->get();
if($query->num_rows() == 1){
return $query->row();
}else{
//Get empty base parent object, as $supplier_id is NOT an supplier
$person_obj = parent::get_info(-1);
//Get all the fields from supplier table
//append those fields to base parent object, we we have a complete empty object
foreach($this->db->list_fields('team') as $field){
$person_obj->$field = '';
}
return $person_obj;
}
}
/* SAT-Gets all of categories */
public function get_category() {
$this->db->from('category');
$this->db->order_by('cat_name', 'asc');
return $this->db->get();
}
/* SAT-Gets TL list */
public function get_leader($id) {
$this->db->from('employees');
$this->db->join('people', 'people.person_id = employees.person_id');
$this->db->where('role', '6');
$this->db->where('category',$id);
$this->db->order_by('first_name', 'asc');
return $this->db->get()->result_array();
}
public function teammembers($id){
$this->db->select('id,first_name');
$this->db->from('employees');
$this->db->join('people', 'people.person_id = employees.person_id');
$this->db->where('role', '3');
$this->db->where('reporting',$id);
$this->db->where('deleted', 0);
$this->db->order_by('first_name', 'asc');
return $this->db->get()->result();
}
/* Inserts or update a Team */
public function save_team(&$team_data,$team_id = FALSE){
$success = FALSE;
//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();
if(!$team_id || !$this->exists($team_id)){
$success = $this->db->insert('team', $team_data);
}else{
$this->db->where('team_id', $team_id);
$success = $this->db->update('team', $team_data);
}
$this->db->trans_complete();
$success &= $this->db->trans_status();
return $success;
}
/* Deletes a list of Team */
public function delete_list($team_ids){
$this->db->where_in('team_id', $team_ids);
return $this->db->update('team', array('deleted' => 1));
}
}
?>