diff --git a/application/controllers/configurations.php b/application/controllers/configurations.php new file mode 100644 index 0000000..a0a4f1c --- /dev/null +++ b/application/controllers/configurations.php @@ -0,0 +1,46 @@ +load->model('configuration'); + + // load language file + // $this->lang->load(strtolower($this->router->class)); + } + + /** + * Get a specific configuration from the database. + * + * @param string $config_id The configuration id to get. + */ + public function get($config_id) { + $configs = $this->configuration->get($config_id); + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode($configs)); + } + + /** + * Search for a specific configuration and return a list of possible results. + * + * @param string $project The project in which to search for a configuration. + * @param string $needle The needle to look for in the haystack. + */ + public function search($project, $needle) { + $results = $this->configuration->search($project, $needle); + $this->output + ->set_content_type('application/json') + ->set_output(json_encode(array('count' => count($results), 'results' => $results))); + } +} \ No newline at end of file diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php new file mode 100644 index 0000000..03dad37 --- /dev/null +++ b/application/controllers/jobs.php @@ -0,0 +1,59 @@ +db->order_by('progress', 'desc') + ->get_where('jobs', array('started_by' => $this->session->user_data('id'))); + $count = $query->num_rows(); + $jobs = $query->result_array(); + + for($i=0; $idb->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name; + $progress = $jobs[$i]['progress']; + + switch($progress) { + case -1: + $progress = "Warte auf Start..."; + break; + case 100: + $progress = "Fertig"; + break; + default: + $progress = $progress . "%"; + break; + } + + $jobs[$i]['progress'] = $progress; + } + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode( + array( + 'count' => $count, + 'jobs' => $jobs + ) + )); + } + + public function listResultsNotSeen() { + $query = $this->db->order_by('started_at', 'asc') + ->get_where('jobs', array('started_by' => $this->session->user_data('id'), 'seen' => '0')); + $count = $query->num_rows(); + $jobs = $query->result_array(); + + for($i=0; $idb->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name; + } + + $this->output + ->set_content_type('application/json') + ->set_output(json_encode( + array( + 'count' => $count, + 'jobs' => $jobs + ) + )); + } +} \ No newline at end of file diff --git a/application/controllers/projects.php b/application/controllers/projects.php index 7687493..e897d6a 100644 --- a/application/controllers/projects.php +++ b/application/controllers/projects.php @@ -1,5 +1,8 @@ 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))); + } } diff --git a/application/models/configuration.php b/application/models/configuration.php new file mode 100644 index 0000000..4270301 --- /dev/null +++ b/application/models/configuration.php @@ -0,0 +1,34 @@ +db->get_where('configurations', array('id' => $configuration_id)); + + return $query->row_array(); + } + + /** + * Search for a specific configuration and return a list of possible results. + * + * @param string $needle The needle to look for in the haystack. + */ + public function search($project, $needle) { + $query = $this->db->where('project_id', $project) + ->like('name', $needle)->get('configurations'); + $results = $query->result_array(); + + return $results; + } +} \ No newline at end of file diff --git a/application/models/project.php b/application/models/project.php index e25a2ef..cee6f53 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -1,9 +1,20 @@ db->where(array('owner' => '215cd70f310ae6ae')) + $query = $this->db->where(array('owner' => $this->session->user_data('id'))) ->order_by('lastaccess', 'desc') ->get('projects'); $projects = $query->result_array(); @@ -21,8 +32,13 @@ class Project extends CI_Model { return $ownProjects; } + /** + * Get projects the user was invited to use. + * + * @return array The shared projects. + */ public function getShared() { - $this->db->select('*')->from('shares')->order_by('lastaccess', 'desc')->where(array('user_id' => '215cd70f310ae6ae')); + $this->db->select('*')->from('shares')->order_by('lastaccess', 'desc')->where(array('user_id' => $this->session->user_data('id'))); $this->db->join('projects', 'projects.id = shares.project_id'); $query = $this->db->get(); @@ -41,6 +57,11 @@ class Project extends CI_Model { return $sharedProjects; } + /** + * Get all publicly available projects. + * + * @return array All public projects. + */ public function getPublic() { $query = $this->db->where(array('public' => '1')) ->order_by('name', 'asc') @@ -59,4 +80,43 @@ class Project extends CI_Model { return $publicProjects; } + + /** + * Get all available configurations from a specific project. + * + * @param array $project_id The project to get the configuration from. + */ + public function get_configurations($project_id) { + $query = $this->db->get_where('configurations', array('project_id' => $project_id)); + + $configurations = $query->result_array(); + $configuration_count = $query->num_rows(); + + 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); + } } \ No newline at end of file