| Server IP : 188.114.97.2 / Your IP : 104.23.197.230 Web Server : Apache/2.4.59 (Debian) System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : edlftp ( 1002) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/nicolasj/www/sms.formationlangues.be/application/models/ |
Upload File : |
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Mail_log_model extends CI_Model
{
protected $table = 'mail_log';
public function __construct()
{
parent::__construct(array('no_cache' => 1));
$this->load->database();
}
public function get_entry(int $id)
{
if ($id <= 0) {
return null;
}
$result = $this->db->get_where($this->table, ['id' => $id])->result();
return isset($result[0]) ? $result[0] : null;
}
public function update_entry(int $id, array $fields): bool
{
if ($id <= 0 || empty($fields)) {
return false;
}
return $this->db->update($this->table, $fields, ['id' => $id]);
}
public function count_all()
{
return (int) $this->db->count_all($this->table);
}
private function apply_search($search)
{
if ($search !== '') {
$this->db->group_start()
->like('to_mail', $search)
->or_like('from_mail', $search)
->or_like('subject', $search)
->group_end();
}
}
public function count_filtered($search)
{
$this->db->from($this->table);
$this->apply_search($search);
return (int) $this->db->count_all_results();
}
public function get_filtered($search, $order_col, $order_dir, $start, $length)
{
$this->db->select('id, to_mail, from_mail, subject, sended_at,
GROUP_CONCAT(DISTINCT(to_mail)) AS emails')
->from($this->table);
$this->apply_search($search);
$this->db->group_by('group_id');
$allowed_order = ['id','to_mail','from_mail','subject','sended_at'];
if (!in_array($order_col, $allowed_order, true)) {
$order_col = 'sended_at';
}
$order_dir = strtolower($order_dir) === 'asc' ? 'asc' : 'desc';
$this->db->order_by($order_col, $order_dir);
if ((int)$length !== -1) {
$this->db->limit((int)$length, (int)$start);
}
return $this->db->get()->result_array();
}
}