Enable searching for projects
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Karsten Heiken, karsten@disposed.de
|
||||
*/
|
||||
class Projects extends CI_Controller {
|
||||
|
||||
/**
|
||||
@@ -67,4 +70,16 @@ class Projects extends CI_Controller {
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode(array('result' => $result)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$results = $this->project->search($needle);
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode(array('count' => count($results), 'results' => $results)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user