diff --git a/site/application/controllers/Question.php b/site/application/controllers/Question.php new file mode 100644 index 0000000..833cde4 --- /dev/null +++ b/site/application/controllers/Question.php @@ -0,0 +1,85 @@ +load->view ( 'question/view' ); + } + + public function ask() { + $this->load->view ( 'question/ask' ); + } + + public function details() { + $this->load->view ( 'question/details' ); + } + + public function search_phrase() { + $rules = array ( + 'field' => 'srch_phrase', + 'label' => 'phrase', + 'rules' => 'trim|htmlspecialchars|required' + ); + + $this->form_validation->set_rules ( $rules ); + + if ($this->form_validation->run () === TRUE) { + $phrase = $this->input->post ( 'srch_phrase' ); + $answered = $this->input->post ( 'srch_answered' ); + + if ((int) $answered == 0) { + $results = $this->get_by_phrase($phrase); + } else { + $results = $this->get_by_answered($phrase, $answered); + } + } + } + + public function search_tag() { + + } + + public function search_all() { + $results = $this->get_all(); + } + + public function ask_question() { + $rules = array ( + array( + 'field' => 'qstn_title', + 'label' => 'title', + 'rules' => 'trim|htmlspecialchars|required' + ), + + array( + 'field' => 'qstn_body', + 'label' => 'body', + 'rules' => 'trim|htmlspecialchars|required' + ) + ); + + $this->form_validation->set_rules ( $rules ); + + if ($this->form_validation->run () === TRUE) { + $questiondata = array ( + 'title' => $this->input->post ( 'qstn_title' ), + 'body' => $this->input->post ( 'qstn_body' ) + ); + + $result = $this->insert_question($questiondata); + $arr ["notification_message"] = ""; + + if ($result === TRUE) { + $arr ["notification_message"] .= "Success! Your question has been submitted."; + } else if ($result === FALSE) { + $arr ["notification_message"] .= "Something went wrong, please try again."; + } + } + + } + +} diff --git a/site/application/models/Question_model.php b/site/application/models/Question_model.php new file mode 100644 index 0000000..2c7219d --- /dev/null +++ b/site/application/models/Question_model.php @@ -0,0 +1,120 @@ +user_model->get_logged_in (); + $insertdata = array ( + 'submitterID' => $user ['userid'], + 'dateAsked' => date ( 'Y-m-d' ), + 'title' => $questiondata ['title'], + 'body' => $questiondata ['body'], + 'answered' => 0 + ); + + if (! $this->db->insert ( 'questions', $insertdata )) { + log_message ( 'error', "Insert failed on database when creating question: " . $this->db->error () ['message'] ); + return FALSE; + } else { + syslog ( LOG_INFO, "Successfully created question {$insertdata['title']}." ); + return TRUE; + } + } + + public function get_by_phrase($phrase_to_fetch) { + $this->db->like('title', $phrase_to_fetch); + $this->db->or_like('body', $phrase_to_fetch); + $this->db->order_by('dateAsked', 'desc'); + $query = $this->db->get ( 'questions' ); + + if ($query->num_rows() > 0) { + return $query->result(); + } else { + return null; + } + } + + public function get_by_tag($tags_to_fetch) { + + } + + public function get_by_answered($phrase_to_fetch, $answered) { + $this->db->like('title', $phrase_to_fetch); + $this->db->or_like('body', $phrase_to_fetch); + $this->db->order_by('dateAsked', 'desc'); + $query = $this->db->get_where ( 'questions', array ( + 'answered' => $answered + ) ); + + if ($query->num_rows() > 0) { + return $query->result(); + } else { + return null; + } + } + + public function get_all() { + $this->db->order_by('dateAsked', 'desc'); + $query = $this->db->get ( 'questions' ); + + if ($query->num_rows() > 0) { + return $query->result(); + } else { + return null; + } + } + + public function mark_answered($questiondata) { + + } + + //Answers + + public function insert_answer($answerdata) { + $user = ( array ) $this->user_model->get_logged_in (); + $insertdata = array ( + 'submitterID' => $user ['userid'], + 'questionID' => $answerdata ['id'], + 'dateAnswered' => date ( 'Y-m-d' ), + 'body' => $answerdata ['body'], + 'helpful' => 0 + ); + + if (! $this->db->insert ( 'questions', $insertdata )) { + log_message ( 'error', "Insert failed on database when adding answer: " . $this->db->error () ['message'] ); + return FALSE; + } else { + syslog ( LOG_INFO, "Successfully added answer to question {$insertdata['questionID']}." ); + return TRUE; + } + } + + public function get_answers($questiondata) { + $this->db->order_by('helpful', 'desc'); + $query = $this->db->get_where ( 'answers', array ( + 'questionID' => $questiondata ["questionID"] + ) ); + + if ($query->num_rows() > 0) { + return $query->result(); + } else { + return null; + } + } + + public function mark_helpful($answerdata) { + + } +} diff --git a/site/application/views/include/navbar.php b/site/application/views/include/navbar.php index 1d38290..b0908b1 100644 --- a/site/application/views/include/navbar.php +++ b/site/application/views/include/navbar.php @@ -24,6 +24,7 @@ class="icon-bar">
Got a question? Ask us here and get an answer from committee members and other site users!
+ + +Body
+ +Got a question? Ask us here and get an answer from committee members and other site users!
+You can search by phrases or tags, as well as for answered and unanswered questions.
+ +