Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions Section #31

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
85 changes: 85 additions & 0 deletions site/application/controllers/Question.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Question extends CI_Controller {

public function __construct() {
parent::__construct ();
}

public function index() {
$this->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.";
}
}

}

}
120 changes: 120 additions & 0 deletions site/application/models/Question_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
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' => 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) {

}
}
1 change: 1 addition & 0 deletions site/application/views/include/navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class="icon-bar"></span>
<li><a href="/about">About Us</a></li>
<li><a href="/bits">Bits</a></li>
<li><a href="/projects">Projects</a></li>
<li><a href="/question">Questions</a></li>
<li><a href="/lectures">Lectures</a></li>
<li><a href="/calendar">Calendar</a></li>

Expand Down
67 changes: 67 additions & 0 deletions site/application/views/question/ask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );

Permissions::require_logged_in ();
?>
<!DOCTYPE html>
<html lang="en">

<head>
<?php
$this->load->view ( 'include/head_common.php' );
?>

<title>CompSoc :: Questions</title>
</head>

<body>
<?php
$this->load->view ( 'include/navbar.php' );
?>

<div class="container">
<?php $this->load->view('include/sitewide_banner.php'); ?>
<div class="col-lg-9">

<div class="row">
<div class="panel panel-default">
<div class="panel-body">
<div class="page-header">
<h2>Ask a question</h2>
</div>

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

<?php echo form_open('question/ask_question'); ?>
<div class="form-group">
<div class="form-group">
<label for="qstn_title">Question</label>
<input type="text" name="qstn_title" id="qstn_title" class="form-control" placeholder="Question" value="<?php echo set_value('qstn_title');?>" autofocus>
</div>

<div class="form-group">
<label for="qstn_body">Details</label>
<textarea rows="10" cols="10" name="qstn_body" id="qstn_body" class="form-control"></textarea>
</div>

<input type="submit" value="Submit" name="qstn_submit" id="qstn_submit" class="btn btn-primary" style="margin-right: 6px">
<input type="reset" value="Reset" name="qstn_reset" id="qstn_reset" class="btn btn-secondary">
<?php echo form_close(); ?>
</div>

</div>
</div>
</div>

</div>
<?php $this->load->view('include/social_sidebar.php'); ?>
</div>


<?php
$this->load->view ( 'include/footer.php' );
$this->load->view ( 'include/bootstrapjs.php' );
?>
</div>
</body>
</html>
48 changes: 48 additions & 0 deletions site/application/views/question/details.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
?>
<!DOCTYPE html>
<html lang="en">

<head>
<?php
$this->load->view ( 'include/head_common.php' );
?>

<title>CompSoc :: Questions</title>
</head>

<body>
<?php
$this->load->view ( 'include/navbar.php' );
?>

<div class="container">
<?php $this->load->view('include/sitewide_banner.php'); ?>
<div class="col-lg-9">

<div class="row">
<div class="panel panel-default">
<div class="panel-body">
<div class="page-header">
<h2>Title</h2>
</div>

<p>Body</p>

</div>
</div>
</div>

</div>
<?php $this->load->view('include/social_sidebar.php'); ?>
</div>


<?php
$this->load->view ( 'include/footer.php' );
$this->load->view ( 'include/bootstrapjs.php' );
?>
</div>
</body>
</html>
Loading