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">
  • About Us
  • Bits
  • Projects
  • +
  • Questions
  • Lectures
  • Calendar
  • diff --git a/site/application/views/question/ask.php b/site/application/views/question/ask.php new file mode 100644 index 0000000..6f0e383 --- /dev/null +++ b/site/application/views/question/ask.php @@ -0,0 +1,67 @@ + + + + + +load->view ( 'include/head_common.php' ); +?> + +CompSoc :: Questions + + + + load->view ( 'include/navbar.php' ); + ?> + +
    + load->view('include/sitewide_banner.php'); ?> +
    + +
    +
    +
    + + +

    Got a question? Ask us here and get an answer from committee members and other site users!

    + + +
    +
    + + +
    + +
    + + +
    + + + + +
    + +
    +
    +
    + +
    + load->view('include/social_sidebar.php'); ?> +
    + + + load->view ( 'include/footer.php' ); + $this->load->view ( 'include/bootstrapjs.php' ); + ?> + + + diff --git a/site/application/views/question/details.php b/site/application/views/question/details.php new file mode 100644 index 0000000..7f0b899 --- /dev/null +++ b/site/application/views/question/details.php @@ -0,0 +1,48 @@ + + + + + +load->view ( 'include/head_common.php' ); +?> + +CompSoc :: Questions + + + + load->view ( 'include/navbar.php' ); + ?> + +
    + load->view('include/sitewide_banner.php'); ?> +
    + +
    +
    +
    + + +

    Body

    + +
    +
    +
    + +
    + load->view('include/social_sidebar.php'); ?> +
    + + + load->view ( 'include/footer.php' ); + $this->load->view ( 'include/bootstrapjs.php' ); + ?> + + + diff --git a/site/application/views/question/view.php b/site/application/views/question/view.php new file mode 100644 index 0000000..2c95656 --- /dev/null +++ b/site/application/views/question/view.php @@ -0,0 +1,92 @@ + + + + + +load->view ( 'include/head_common.php' ); +?> + +CompSoc :: Questions + + + + load->view ( 'include/navbar.php' ); + ?> + +
    + load->view('include/sitewide_banner.php'); ?> +
    + +
    +
    +
    + + +

    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.

    + +
    +
    +
    + + session->userdata('logged_in')): ?> +
    +
    +
    + + +

    Can't find what you're looking for? Ask away!

    + Ask + +
    +
    +
    + + +
    +
    +
    + + + +
    +
    + + +
    + +
    + +
    + + + + +
    + +
    +
    +
    + +
    + load->view('include/social_sidebar.php'); ?> +
    + + + load->view ( 'include/footer.php' ); + $this->load->view ( 'include/bootstrapjs.php' ); + ?> + + + diff --git a/sql/compsoc.sql b/sql/compsoc.sql index 36832ed..4e416e4 100644 --- a/sql/compsoc.sql +++ b/sql/compsoc.sql @@ -138,3 +138,66 @@ CREATE TABLE batch_mails ( ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0; + +CREATE TABLE tags ( + id INT NOT NULL AUTO_INCREMENT UNIQUE, + + tag VARCHAR(40) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0; + +CREATE TABLE questions ( + id INT NOT NULL AUTO_INCREMENT UNIQUE, + + submitterID INT NOT NULL, + dateAsked DATETIME NOT NULL, + title VARCHAR(255) NOT NULL, + body TEXT NOT NULL, + answered BOOLEAN NOT NULL, + + PRIMARY KEY (id), + + FOREIGN KEY (submitterID) + REFERENCES users(userid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0; + +CREATE TABLE question_tags ( + questionID INT NOT NULL, + tagID INT NOT NULL, + + PRIMARY KEY (questionID, tagID), + + FOREIGN KEY (questionID) + REFERENCES questions(id) + ON DELETE CASCADE + ON UPDATE CASCADE, + + FOREIGN KEY (tagID) + REFERENCES tags(id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE answers ( + id INT NOT NULL AUTO_INCREMENT UNIQUE, + + submitterID INT NOT NULL, + questionID INT NOT NULL, + dateAnswered DATETIME NOT NULL, + body TEXT NOT NULL, + helpful INT NOT NULL, + + PRIMARY KEY (id), + + FOREIGN KEY (questionID) + REFERENCES questions(id) + ON DELETE CASCADE + ON UPDATE CASCADE, + + FOREIGN KEY (submitterID) + REFERENCES users(userid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;