form_responses did join users table

This commit is contained in:
jostheta 2024-07-23 13:11:51 +05:30
parent ac5bc10376
commit 1f3d8d3848
5 changed files with 15 additions and 18 deletions

View File

@ -290,6 +290,9 @@ class Forms extends CI_Controller
$user_id = $this->session->userdata('user_id'); $user_id = $this->session->userdata('user_id');
$data['responses'] = $this->Form_model->get_responses_by_form($form_id); $data['responses'] = $this->Form_model->get_responses_by_form($form_id);
$data['form'] = $this->Form_model->get_form($form_id); $data['form'] = $this->Form_model->get_form($form_id);
$responses = $this->Form_model->get_responses_by_form($form_id);
$this->load->view('templates/header'); $this->load->view('templates/header');
$this->load->view('forms/form_responses', $data); $this->load->view('forms/form_responses', $data);

View File

@ -138,7 +138,7 @@ class Form_model extends CI_Model {
$response_data = [ $response_data = [
'form_id' => $form_id, 'form_id' => $form_id,
'user_id' => $this->session->userdata('user_id'), // Set user_id if applicable 'user_id' => $this->session->userdata('user_id'), // Set user_id if applicable
'created_at' => date('Y-m-d H:i:s'), 'submitted_at' => date('Y-m-d H:i:s'),
]; ];
$this->db->insert('responses', $response_data); $this->db->insert('responses', $response_data);
$response_id = $this->db->insert_id(); $response_id = $this->db->insert_id();
@ -176,13 +176,16 @@ class Form_model extends CI_Model {
$query = $this->db->get('forms'); $query = $this->db->get('forms');
return $query->result(); return $query->result();
} }
public function get_responses_by_form($form_id) { public function get_responses_by_form($form_id) {
$this->db->where('form_id', $form_id); $this->db->select('responses.user_id, users.username, responses.submitted_at,responses.response_id');
$query = $this->db->get('responses'); $this->db->from('responses');
$this->db->join('users', 'responses.user_id = users.user_id');
$this->db->where('responses.form_id', $form_id);
$query = $this->db->get();
return $query->result(); return $query->result();
} }
public function get_response($response_id) { public function get_response($response_id) {
$this->db->where('response_id', $response_id); $this->db->where('response_id', $response_id);
$query = $this->db->get('responses'); $query = $this->db->get('responses');

View File

@ -7,6 +7,7 @@
<thead> <thead>
<tr> <tr>
<th>Response ID</th> <th>Response ID</th>
<th>User Name</th>
<th>Submitted At</th> <th>Submitted At</th>
</tr> </tr>
</thead> </thead>
@ -14,8 +15,9 @@
<?php if (!empty($responses)) : ?> <?php if (!empty($responses)) : ?>
<?php foreach ($responses as $response) : ?> <?php foreach ($responses as $response) : ?>
<tr> <tr>
<td><a href="<?= base_url('forms/view_response/' . $response->response_id) ?>"><?= $response->response_id ?></a></td> <td><?= $response->response_id ?></td>
<td><?= date('Y-m-d H:i:s', strtotime($response->created_at)) ?></td> <td><a href="<?= base_url('forms/view_response/' . $response->response_id) ?>"><?= $response->username ?></a></td>
<td><?= date('Y-m-d H:i:s', strtotime($response->submitted_at)) ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<?php else : ?> <?php else : ?>

View File

@ -15,7 +15,7 @@
Response ID: <?= $response->response_id ?> Response ID: <?= $response->response_id ?>
</div> </div>
<div class="form_container_top_user-details"> <div class="form_container_top_user-details">
Submitted At: <?= date('Y-m-d H:i:s', strtotime($response->created_at)) ?> Submitted At: <?= date('Y-m-d H:i:s', strtotime($response->submitted_at)) ?>
</div> </div>
</div> </div>
</div> </div>

View File

@ -115,17 +115,6 @@ $(document).ready(function() {
// Add active class to the clicked question box // Add active class to the clicked question box
questionBox.addClass('active'); questionBox.addClass('active');
// Scroll sidebar to the active question
var offset = questionBox.offset().top - $('.sidebar').offset().top;
console.log(questionBox.offset().top,'question');
console.log($('.sidebar').offset().top,'sidebar');
console.log(offset,'offset');
console.log(offset + $('.sidebar').scrollTop(),'offset plus sidebar');
$('.sidebar').animate({
scrollTop: offset + $('.sidebar').scrollTop()
}, 500);
} }
// Add click event listener to all question boxes to set active question // Add click event listener to all question boxes to set active question