Enable searching for projects

This commit is contained in:
Karsten Heiken
2011-04-22 01:02:39 +02:00
parent c3ae2eb716
commit bfddf1af9a
2 changed files with 40 additions and 0 deletions

View File

@@ -94,4 +94,29 @@ class Project extends CI_Model {
return array('count' => $configuration_count, 'configs' => $configurations);
}
/**
* Search for a specific project and return a list of possible results.
*
* @param type $needle The needle to look for in the haystack.
*/
public function search($needle) {
// get matching projects that are public or belong directly to the user
$query = $this->db->where('public','1')
->or_where('owner', $this->session->userdata('id'))
->like('name', $needle)->get('projects');
$results = $query->result_array();
// get matching projects that are shared to the user
$this->db->select('*')->from('shares')
->where(array('user_id' => $this->session->userdata('id')))
->like('name', $needle);
$this->db->join('projects', 'projects.id = shares.project_id');
$query = $this->db->get();
$own_results = $query->result_array();
return array_merge($results, $own_results);
}
}