2024-07-16 12:29:59 +00:00
|
|
|
|
|
|
|
<?php
|
|
|
|
|
2024-08-09 12:04:48 +00:00
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Frontend_model extends CI_Model
|
|
|
|
{
|
2024-07-19 10:46:18 +00:00
|
|
|
public function getforms()
|
|
|
|
{
|
|
|
|
// Get the user_id from session
|
|
|
|
$user_id = $this->session->userdata('user_id');
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
// Ensure user_id is set
|
|
|
|
if (!$user_id) {
|
2024-08-09 12:04:48 +00:00
|
|
|
return [];
|
2024-07-19 10:46:18 +00:00
|
|
|
}
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-22 09:49:37 +00:00
|
|
|
// Filter forms by user_id and order by created_at in descending order
|
2024-08-09 12:04:48 +00:00
|
|
|
$this->db->where('user_id', $user_id);
|
|
|
|
$this->db->order_by('created_at', 'DESC');
|
2024-07-19 10:46:18 +00:00
|
|
|
$query = $this->db->get('forms');
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
return $query->result(); // Return the result as an array of objects
|
2024-07-16 12:29:59 +00:00
|
|
|
}
|
2024-08-09 12:04:48 +00:00
|
|
|
|
|
|
|
public function deleteForm($id)
|
|
|
|
{
|
2024-07-16 12:29:59 +00:00
|
|
|
return $this->db->delete('forms', ['id' => $id]);
|
2024-08-09 12:04:48 +00:00
|
|
|
}
|
2024-07-22 09:49:37 +00:00
|
|
|
public function getFormById($form_id)
|
2024-08-09 12:04:48 +00:00
|
|
|
{
|
|
|
|
$query = $this->db->get_where('forms', ['id' => $form_id]);
|
|
|
|
return $query->row_array();
|
|
|
|
}
|
|
|
|
public function getforms_draft($user_id)
|
|
|
|
{
|
|
|
|
$this->db->where('is_published', 0);
|
|
|
|
$this->db->where('user_id', $user_id);
|
|
|
|
$this->db->order_by('created_at', 'DESC');
|
|
|
|
$query = $this->db->get('forms');
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
}
|