Add group operator to giftcard query

This commit is contained in:
jekkos
2016-03-08 08:11:10 +01:00
parent 3cb9aaa055
commit 9cd42e0614

View File

@@ -187,18 +187,18 @@ class Giftcard extends CI_Model
$suggestions[]=$row->giftcard_number;
}
$this->db->from('customers');
$this->db->join('people', 'customers.person_id=people.person_id', 'left');
$this->db->from('customers');
$this->db->join('people', 'customers.person_id=people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
$this->db->order_by('last_name', 'asc');
$by_name = $this->db->get();
$this->db->where('deleted', 0);
$this->db->order_by('last_name', 'asc');
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[]=$row->first_name.' '.$row->last_name;
foreach($by_name->result() as $row)
{
$suggestions[]=$row->first_name.' '.$row->last_name;
}
//only return $limit suggestions
@@ -209,59 +209,61 @@ class Giftcard extends CI_Model
return $suggestions;
}
/*
Get search suggestions to find customers
*/
function get_person_search_suggestions($search,$limit=25)
{
$suggestions = array();
$this->db->select('person_id');
/*
Get search suggestions to find customers
*/
function get_person_search_suggestions($search,$limit=25)
{
$suggestions = array();
$this->db->select('person_id');
$this->db->from('people');
$this->db->like('person_id', $this->db->escape_like_str($search));
$this->db->or_like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('email', $this->db->escape_like_str($search));
$this->db->or_like('phone_number', $this->db->escape_like_str($search));
$this->db->order_by('person_id', 'asc');
$by_person_id = $this->db->get();
foreach($by_person_id->result() as $row)
{
$suggestions[]=$row->person_id;
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
$this->db->like('person_id', $this->db->escape_like_str($search));
$this->db->or_like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('email', $this->db->escape_like_str($search));
$this->db->or_like('phone_number', $this->db->escape_like_str($search));
$this->db->order_by('person_id', 'asc');
$by_person_id = $this->db->get();
foreach($by_person_id->result() as $row)
{
$suggestions[]=$row->person_id;
}
return $suggestions;
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
}
return $suggestions;
}
/*
Preform a search on giftcards
*/
function search($search, $rows = 0, $limit_from = 0)
{
$this->db->from('giftcards');
{
$this->db->from('giftcards');
$this->db->join('people', 'giftcards.person_id=people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_group_start();
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('giftcard_number', $this->db->escape_like_str($search));
$this->db->or_like('giftcards.person_id', $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
$this->db->group_end();
$this->db->where('giftcards.deleted', 0);
$this->db->order_by('giftcard_number', 'asc');
if ($rows > 0)
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
@@ -270,12 +272,13 @@ class Giftcard extends CI_Model
$this->db->from('giftcards');
$this->db->join('people', 'giftcards.person_id=people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_group_start();
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('giftcard_number', $this->db->escape_like_str($search));
$this->db->or_like('giftcards.person_id', $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
$this->db->group_end();
$this->db->where('giftcards.deleted', 0);
return $this->db->get()->num_rows();
}