diff --git a/application/controllers/search.php b/application/controllers/search.php
new file mode 100644
index 0000000..023fc81
--- /dev/null
+++ b/application/controllers/search.php
@@ -0,0 +1,37 @@
+
+ */
+class Search extends CI_Controller {
+
+ /**
+ * Calls the parent constructor.
+ */
+ public function __construct() {
+ parent::__construct();
+ $this->load->model('experiment');
+ $this->load->helper('typography');
+ }
+
+ /**
+ *
+ */
+ public function index() {
+ if ($this->input->get('query') != '') {
+ $query = explode(" ", $this->input->get('query'));
+
+ $data['projects'] = $this->project->search($this->input->get('query'));
+ $data['experiments'] = $this->experiment->search($this->input->get('query'));
+
+ $this->load->view('search/results', $data);
+ } else {
+ $this->load->view('search/new');
+ }
+ }
+}
+
+/* End of file search.php */
+/* Location: ./application/controllers/search.php */
diff --git a/application/models/experiment.php b/application/models/experiment.php
index d880ab2..e779097 100644
--- a/application/models/experiment.php
+++ b/application/models/experiment.php
@@ -152,14 +152,17 @@ class Experiment extends CI_Model {
/**
* Search for a specific experiment and return a list of possible results.
*
- * @param string $needle The needle to look for in the haystack.
+ * @param string $needle The needle to look for in the haystack
+ * @param string $projectId
*/
- public function search($project, $needle) {
- $query = $this->db->where('project_id', $project)
- ->like('name', $needle)->get('experiments');
- $results = $query->result_array();
+ public function search($needle, $projectId = false) {
+ if ($projectId) {
+ $this->db->where('project_id', $projectId);
+ }
- return $results;
+ $query = $this->db->like('name', $needle)->get('experiments');
+
+ return $query->result_array();
}
}
diff --git a/application/models/project.php b/application/models/project.php
index bb8d894..fc7f65c 100644
--- a/application/models/project.php
+++ b/application/models/project.php
@@ -155,14 +155,15 @@ class Project extends CI_Model {
/**
* Search for a specific project and return a list of possible results.
*
- * @param type $needle The needle to look for in the haystack.
+ * @param string $needle The needle to look for in the haystack.
*/
public function search($needle) {
// get matching projects that are public
- $query = $this->db->query("SELECT * FROM `projects` WHERE `public`='1' AND `name` LIKE ".$this->db->escape('%'.$needle.'%'));
+ $query = $this->db->where('public', 1)->like('name', $needle)->get('projects');
$public_results = $query->result_array();
// or belong directly to the user
+ $query = $this->db->where('owner', $this->session->userdata('user_id'));
$query = $this->db->query("SELECT * FROM `projects` WHERE `owner`=".$this->db->escape($this->session->userdata('user_id'))
." AND `name` LIKE ".$this->db->escape('%'.$needle.'%'));
$own_results = $query->result_array();
@@ -177,7 +178,7 @@ class Project extends CI_Model {
$shared_results = $query->result_array();
- return $this->_addShortNames(array_merge($own_results, $shared_results));
+ return $this->_addShortNames(array_merge($public_results, $own_results, $shared_results));
}
/**
diff --git a/application/views/header.php b/application/views/header.php
index e02b453..15fd6f3 100644
--- a/application/views/header.php
+++ b/application/views/header.php
@@ -200,9 +200,9 @@
-
diff --git a/application/views/search/index.html b/application/views/search/index.html
new file mode 100755
index 0000000..c942a79
--- /dev/null
+++ b/application/views/search/index.html
@@ -0,0 +1,10 @@
+
+
+ 403 Forbidden
+
+
+
+Directory access is forbidden.
+
+
+
\ No newline at end of file
diff --git a/application/views/search/results.php b/application/views/search/results.php
new file mode 100644
index 0000000..961ce5a
--- /dev/null
+++ b/application/views/search/results.php
@@ -0,0 +1,39 @@
+load->view('header');?>
+
+
+
+
+
=_('Search results');?>
+
+
+
+
Projects
+
+
+
=anchor('projects/detail/' . $project['id'], $project['name']);?>
+ =character_limiter($project['description'], 255);?>
+
+
+
+
+
+
Experiments
+
+
+
=anchor('experiments/detail/' . $experiment['id'], $experiment['name']);?>
+ =character_limiter($experiment['description'], 255);?>
+
+
+
+
+
+
+load->view('footer');?>
diff --git a/assets/css/style.css b/assets/css/style.css
index 0f5831c..beed572 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -248,6 +248,13 @@ div.error {
.search-submit {
left: 160px;
position: absolute;
+ border: 1px solid #d2d2d2;
+ border-left: 0;
+ height: 20px;
+ background-color: #f7f7f7;
+ font: 11px Arial, sans-serif;
+ line-height: 12px;
+ padding: 3px 2px;
}
/* Blog */