63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Blog_model extends CI_Model {
|
|
|
|
public function __constructor() {
|
|
parrent::__constructor();
|
|
}
|
|
|
|
public function getBlogs($params = null, $page = 0, $limit = 10) {
|
|
$queryString = 'SELECT * FROM blogs';
|
|
$countString = 'SELECT COUNT(*) FROM blogs';
|
|
$whereString = ' WHERE 1=1';
|
|
$orderByString = ' ORDER BY id DESC';
|
|
$offset = $page * $limit;
|
|
$paginationString = " LIMIT $limit OFFSET $offset";
|
|
|
|
if(isset($params['blog_id']) && !empty($params['blog_id'])) {
|
|
$whereString .= " AND blog_id = '" . pg_escape_string($params['blog_id']) . "' ";
|
|
}
|
|
|
|
if(isset($params['status']) && $params['status'] > -1) {
|
|
$whereString .= " AND status = '" . pg_escape_string($params['status']) . "' ";
|
|
}
|
|
|
|
if(isset($params['description']) && !empty($params['description'])) {
|
|
$whereString .= " AND description ILIKE '%" . pg_escape_string($params['description']) . "%' ";
|
|
}
|
|
|
|
$queryString .= $whereString . $orderByString . $paginationString;
|
|
$countString .= $whereString;
|
|
|
|
$query = $this->db->query($queryString);
|
|
$countQuery = $this->db->query($countString);
|
|
|
|
$data = [
|
|
'result' => $query->result_array(),
|
|
'total' => $countQuery->result_array()[0]['count'],
|
|
'pageSize' => $limit,
|
|
'pageNo' => $page
|
|
];
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function store($data) {
|
|
$this->db->insert('blogs', $data);
|
|
}
|
|
|
|
public function update($id, $data) {
|
|
$this->db->update('blogs', $data, "id = $id");
|
|
}
|
|
|
|
public function delete($params) {
|
|
$this->db->delete('blogs', $params);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|