From e961984274d8de5d968838ddf35629a4c44a2550 Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Thu, 21 Apr 2011 20:21:02 +0200 Subject: [PATCH 1/5] Add simple jobs handler --- application/controllers/jobs.php | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 application/controllers/jobs.php diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php new file mode 100644 index 0000000..eb53cc3 --- /dev/null +++ b/application/controllers/jobs.php @@ -0,0 +1,59 @@ +db->order_by('progress', 'desc') + ->get_where('jobs', array('started_by' => '215cd70f310ae6ae')); + $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' => '215cd70f310ae6ae', '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 From c3ae2eb71665fbb9ccd40b5985b15c6bdedf39bf Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 00:31:07 +0200 Subject: [PATCH 2/5] Add documentation --- application/models/project.php | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/application/models/project.php b/application/models/project.php index e25a2ef..c758780 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -1,7 +1,18 @@ db->where(array('owner' => '215cd70f310ae6ae')) ->order_by('lastaccess', 'desc') @@ -21,6 +32,11 @@ 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->join('projects', 'projects.id = shares.project_id'); @@ -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,18 @@ 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); + } } \ No newline at end of file From bfddf1af9ac4c0906a892b9d55427a488abf98fe Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 01:02:39 +0200 Subject: [PATCH 3/5] Enable searching for projects --- application/controllers/projects.php | 15 +++++++++++++++ application/models/project.php | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) 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/project.php b/application/models/project.php index c758780..8adad57 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -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); + } } \ No newline at end of file From e60f325a9464071525117a4c1eac8b54cb5c85e9 Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 01:03:16 +0200 Subject: [PATCH 4/5] Add basic support for configurations --- application/controllers/configurations.php | 46 ++++++++++++++++++++++ application/models/configuration.php | 34 ++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 application/controllers/configurations.php create mode 100644 application/models/configuration.php 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/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 From 32478703f60e2e53b33af757f813bd07f2593733 Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 01:07:05 +0200 Subject: [PATCH 5/5] Actually check which user is logged in --- application/controllers/jobs.php | 4 ++-- application/models/project.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php index eb53cc3..03dad37 100644 --- a/application/controllers/jobs.php +++ b/application/controllers/jobs.php @@ -4,7 +4,7 @@ class Jobs extends CI_Controller { public function getOwn() { $query = $this->db->order_by('progress', 'desc') - ->get_where('jobs', array('started_by' => '215cd70f310ae6ae')); + ->get_where('jobs', array('started_by' => $this->session->user_data('id'))); $count = $query->num_rows(); $jobs = $query->result_array(); @@ -39,7 +39,7 @@ class Jobs extends CI_Controller { public function listResultsNotSeen() { $query = $this->db->order_by('started_at', 'asc') - ->get_where('jobs', array('started_by' => '215cd70f310ae6ae', 'seen' => '0')); + ->get_where('jobs', array('started_by' => $this->session->user_data('id'), 'seen' => '0')); $count = $query->num_rows(); $jobs = $query->result_array(); diff --git a/application/models/project.php b/application/models/project.php index 8adad57..cee6f53 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -14,7 +14,7 @@ class Project extends CI_Model { * @return array The user's projects. */ public function getOwn() { - $query = $this->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(); @@ -38,7 +38,7 @@ class Project extends CI_Model { * @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();