From f9f2ea3a75b3856472f28c97ab4a45ff7a1637c4 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 6 Oct 2015 20:49:52 +0100 Subject: [PATCH 1/8] Added controller and views for questions section; started writing rules for search functionality --- site/application/controllers/Question.php | 31 ++++++++ site/application/views/include/navbar.php | 1 + site/application/views/question/ask.php | 47 +++++++++++++ site/application/views/question/view.php | 86 +++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 site/application/controllers/Question.php create mode 100644 site/application/views/question/ask.php create mode 100644 site/application/views/question/view.php diff --git a/site/application/controllers/Question.php b/site/application/controllers/Question.php new file mode 100644 index 0000000..2f60e72 --- /dev/null +++ b/site/application/controllers/Question.php @@ -0,0 +1,31 @@ +load->view ( 'question/view' ); + } + + public function ask() { + $this->load->view ( 'question/ask' ); + } + + public function search_phrase() { + $rules = array ( + 'field' => 'srch_phrase', + 'label' => 'phrase', + 'rules' => 'trim|required|alpha_dash' + ); + + $this->form_validation->set_rules ( $rules ); + + if ($this->form_validation->run () === TRUE) { + $phrase = $this->input->post ( 'srch_phrase' ); + } + + } +} diff --git a/site/application/views/include/navbar.php b/site/application/views/include/navbar.php index 6494cb5..d81825a 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
  • Events Calendar
  • session->userdata('logged_in')): ?> diff --git a/site/application/views/question/ask.php b/site/application/views/question/ask.php new file mode 100644 index 0000000..546dcf7 --- /dev/null +++ b/site/application/views/question/ask.php @@ -0,0 +1,47 @@ + + + + + +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/view.php b/site/application/views/question/view.php new file mode 100644 index 0000000..04f14c0 --- /dev/null +++ b/site/application/views/question/view.php @@ -0,0 +1,86 @@ + + + + + +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.

    + +
    +
    +
    + +
    +
    +
    + + +

    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' ); + ?> + + + From d022508b344be888b7b1724cedb1ef8e15e8a264 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 6 Oct 2015 21:01:21 +0100 Subject: [PATCH 2/8] Prevented users who are not logged in from asking questions --- site/application/views/question/ask.php | 2 ++ site/application/views/question/view.php | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/site/application/views/question/ask.php b/site/application/views/question/ask.php index 546dcf7..fd7e1e0 100644 --- a/site/application/views/question/ask.php +++ b/site/application/views/question/ask.php @@ -1,5 +1,7 @@ diff --git a/site/application/views/question/view.php b/site/application/views/question/view.php index 04f14c0..484d13b 100644 --- a/site/application/views/question/view.php +++ b/site/application/views/question/view.php @@ -35,19 +35,21 @@ -
    -
    -
    - + session->userdata('logged_in')): ?> +
    +
    +
    + -

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

    - Ask +

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

    + Ask -
    -
    -
    +
    +
    +
    +
    From 85b33fc2481cebe45786a9895ede902285c37f0a Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 6 Oct 2015 23:29:06 +0100 Subject: [PATCH 3/8] Made ask question form; started thinking about code for tags --- site/application/controllers/Question.php | 4 +++ site/application/views/question/ask.php | 41 ++++++++++++++++++----- site/application/views/question/view.php | 4 +-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/site/application/controllers/Question.php b/site/application/controllers/Question.php index 2f60e72..8fa2bbc 100644 --- a/site/application/controllers/Question.php +++ b/site/application/controllers/Question.php @@ -28,4 +28,8 @@ public function search_phrase() { } } + + public function ask_question() { + + } } diff --git a/site/application/views/question/ask.php b/site/application/views/question/ask.php index fd7e1e0..f9d301d 100644 --- a/site/application/views/question/ask.php +++ b/site/application/views/question/ask.php @@ -22,19 +22,44 @@
    load->view('include/sitewide_banner.php'); ?>
    - +
    -
    -
    - - -

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

    +
    +
    + + +

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

    + +
    +
    + + +
    + +
    + + +
    + +
    + +
    + + + + +
    +
    +
    load->view('include/social_sidebar.php'); ?>
    diff --git a/site/application/views/question/view.php b/site/application/views/question/view.php index 484d13b..0389544 100644 --- a/site/application/views/question/view.php +++ b/site/application/views/question/view.php @@ -61,8 +61,8 @@
    - - + +
    From f9b421ea3870a4bc7714906a5f2754fe28a4cc45 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 11 Oct 2015 17:34:23 +0100 Subject: [PATCH 4/8] Updated SQL file; added rules for submitting a question --- site/application/controllers/Question.php | 29 ++++++++++- sql/compsoc.sql | 62 +++++++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/site/application/controllers/Question.php b/site/application/controllers/Question.php index 8fa2bbc..bad6e76 100644 --- a/site/application/controllers/Question.php +++ b/site/application/controllers/Question.php @@ -18,7 +18,7 @@ public function search_phrase() { $rules = array ( 'field' => 'srch_phrase', 'label' => 'phrase', - 'rules' => 'trim|required|alpha_dash' + 'rules' => 'trim|htmlspecialchars|required' ); $this->form_validation->set_rules ( $rules ); @@ -30,6 +30,31 @@ public function search_phrase() { } 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) { + $title = $this->input->post ( 'qstn_title' ); + $body = $this->input->post ( 'qstn_body' ); + } } } + +//Yeah someone asks a question and it's put up to be answered, potentially by anyone. I'd say a question should have tags hinting what it's about, a title and a description + +//Then users can list open questions, search for relevant stuff including searching by tags + +//Question has a submitter, a list of tags, a date asked, title and body. Answer has date, body, submitter, and parent question diff --git a/sql/compsoc.sql b/sql/compsoc.sql index 5bf61f5..54051bb 100644 --- a/sql/compsoc.sql +++ b/sql/compsoc.sql @@ -138,3 +138,65 @@ 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, + question 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, + + 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; From 2e0ddc7f8cd9d55c1c016f86819d5c111590f236 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 11 Oct 2015 17:54:51 +0100 Subject: [PATCH 5/8] Added answer helpfulness counter to SQL file --- site/application/controllers/Question.php | 6 ------ sql/compsoc.sql | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/site/application/controllers/Question.php b/site/application/controllers/Question.php index bad6e76..289cffd 100644 --- a/site/application/controllers/Question.php +++ b/site/application/controllers/Question.php @@ -52,9 +52,3 @@ public function ask_question() { } } } - -//Yeah someone asks a question and it's put up to be answered, potentially by anyone. I'd say a question should have tags hinting what it's about, a title and a description - -//Then users can list open questions, search for relevant stuff including searching by tags - -//Question has a submitter, a list of tags, a date asked, title and body. Answer has date, body, submitter, and parent question diff --git a/sql/compsoc.sql b/sql/compsoc.sql index 54051bb..4a5a5a0 100644 --- a/sql/compsoc.sql +++ b/sql/compsoc.sql @@ -187,6 +187,7 @@ CREATE TABLE answers ( questionID INT NOT NULL, dateAnswered DATETIME NOT NULL, body TEXT NOT NULL, + helpfulCounter INT NOT NULL, PRIMARY KEY (id), From 34b757ca7a2aa9fc9c2244ae6989b52d914b6e88 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 11 Oct 2015 18:19:09 +0100 Subject: [PATCH 6/8] Added questions model --- site/application/models/Question_model.php | 9 +++++++++ sql/compsoc.sql | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 site/application/models/Question_model.php diff --git a/site/application/models/Question_model.php b/site/application/models/Question_model.php new file mode 100644 index 0000000..a1e207d --- /dev/null +++ b/site/application/models/Question_model.php @@ -0,0 +1,9 @@ + Date: Mon, 12 Oct 2015 17:59:46 +0100 Subject: [PATCH 7/8] Added database interaction to question model --- site/application/controllers/Question.php | 13 +++ site/application/models/Question_model.php | 110 +++++++++++++++++++++ site/application/views/question/ask.php | 4 - sql/compsoc.sql | 2 +- 4 files changed, 124 insertions(+), 5 deletions(-) diff --git a/site/application/controllers/Question.php b/site/application/controllers/Question.php index 289cffd..58f8adb 100644 --- a/site/application/controllers/Question.php +++ b/site/application/controllers/Question.php @@ -29,6 +29,18 @@ public function search_phrase() { } + public function search_tag() { + + } + + public function search_answered() { + + } + + public function search_all() { + + } + public function ask_question() { $rules = array ( array( @@ -51,4 +63,5 @@ public function ask_question() { $body = $this->input->post ( 'qstn_body' ); } } + } diff --git a/site/application/models/Question_model.php b/site/application/models/Question_model.php index a1e207d..5af3e56 100644 --- a/site/application/models/Question_model.php +++ b/site/application/models/Question_model.php @@ -2,8 +2,118 @@ defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' ); class Question_model extends CI_Model { // core details + var $id = -1; + var $submitterID = -1; + var $datePosted = ''; + var $title = ''; + var $body = ''; public function __construct() { parent::__construct (); } + + //Questions + + public function insert_question($questiondata) { + $user = ( array ) $this->user_model->get_logged_in (); + $insertdata = array ( + 'submitterID' => $user ['userid'], + 'dateAsked' => date ( 'Y-m-d' ), + 'title' => $questiondata ['title'], + 'body' => $questiondata ['body'], + 'answered' => FALSE + ); + + 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->select('*'); + $this->db->like('title', $phrase_to_fetch); + $this->db->or_like('body', $phrase_to_fetch); + $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($answered) { + $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->select('*'); + $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/question/ask.php b/site/application/views/question/ask.php index f9d301d..a3ed5ba 100644 --- a/site/application/views/question/ask.php +++ b/site/application/views/question/ask.php @@ -45,10 +45,6 @@
    -
    diff --git a/sql/compsoc.sql b/sql/compsoc.sql index 7b3003a..4e416e4 100644 --- a/sql/compsoc.sql +++ b/sql/compsoc.sql @@ -150,7 +150,7 @@ CREATE TABLE questions ( submitterID INT NOT NULL, dateAsked DATETIME NOT NULL, - question VARCHAR(255) NOT NULL, + title VARCHAR(255) NOT NULL, body TEXT NOT NULL, answered BOOLEAN NOT NULL, From 721a64d55ba19d40b9ac4c4c86e94106bad6ef29 Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 12 Oct 2015 23:38:48 +0100 Subject: [PATCH 8/8] Added more model and controller code; added a details view for showing a question with its answers --- site/application/controllers/Question.php | 36 ++++++++++++---- site/application/models/Question_model.php | 9 ++-- site/application/views/question/ask.php | 3 -- site/application/views/question/details.php | 48 +++++++++++++++++++++ site/application/views/question/view.php | 4 ++ 5 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 site/application/views/question/details.php diff --git a/site/application/controllers/Question.php b/site/application/controllers/Question.php index 58f8adb..833cde4 100644 --- a/site/application/controllers/Question.php +++ b/site/application/controllers/Question.php @@ -14,6 +14,10 @@ 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', @@ -25,20 +29,22 @@ public function search_phrase() { 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_answered() { - - } - public function search_all() { - + $results = $this->get_all(); } public function ask_question() { @@ -59,9 +65,21 @@ public function ask_question() { $this->form_validation->set_rules ( $rules ); if ($this->form_validation->run () === TRUE) { - $title = $this->input->post ( 'qstn_title' ); - $body = $this->input->post ( 'qstn_body' ); - } + $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 index 5af3e56..2c7219d 100644 --- a/site/application/models/Question_model.php +++ b/site/application/models/Question_model.php @@ -21,7 +21,7 @@ public function insert_question($questiondata) { 'dateAsked' => date ( 'Y-m-d' ), 'title' => $questiondata ['title'], 'body' => $questiondata ['body'], - 'answered' => FALSE + 'answered' => 0 ); if (! $this->db->insert ( 'questions', $insertdata )) { @@ -34,9 +34,9 @@ public function insert_question($questiondata) { } public function get_by_phrase($phrase_to_fetch) { - $this->db->select('*'); $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) { @@ -50,7 +50,9 @@ public function get_by_tag($tags_to_fetch) { } - public function get_by_answered($answered) { + 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 @@ -64,7 +66,6 @@ public function get_by_answered($answered) { } public function get_all() { - $this->db->select('*'); $this->db->order_by('dateAsked', 'desc'); $query = $this->db->get ( 'questions' ); diff --git a/site/application/views/question/ask.php b/site/application/views/question/ask.php index a3ed5ba..6f0e383 100644 --- a/site/application/views/question/ask.php +++ b/site/application/views/question/ask.php @@ -44,9 +44,6 @@
    -
    -
    - 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 index 0389544..2c95656 100644 --- a/site/application/views/question/view.php +++ b/site/application/views/question/view.php @@ -65,6 +65,10 @@
    +
    + +
    +