79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
|
|
<?php if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Card_image_model extends CI_Model {
|
|
private $read_replica;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
|
}
|
|
|
|
public function get_card_image_records(
|
|
$filters = [],
|
|
$limit = null,
|
|
$offset = null
|
|
) {
|
|
|
|
$combo_array = [
|
|
];
|
|
|
|
$numberic_array = [
|
|
'category_id' => 'b.id',
|
|
];
|
|
|
|
$string_array = [
|
|
'unique_id' => 'a.uniqueid',
|
|
];
|
|
|
|
$this->read_replica->select([
|
|
'a.id',
|
|
'a.uniqueid',
|
|
'a.name',
|
|
'a.created',
|
|
'a.file_size',
|
|
'a.format',
|
|
'a.dimensions',
|
|
'b.description AS category_name',
|
|
'b.name AS bucket'
|
|
]);
|
|
|
|
$this->read_replica->from('card_images a');
|
|
$this->read_replica->join('card_image_category b', 'b.id = a.catid', 'left');
|
|
|
|
$this->read_replica->where('a.t1', 'FF');
|
|
foreach($filters as $key => $val) {
|
|
|
|
if (array_key_exists($key, $combo_array)) {
|
|
|
|
$this->read_replica->where($combo_array[$key], $val);
|
|
|
|
} else if (array_key_exists($key, $numberic_array)) {
|
|
|
|
$this->read_replica->where($numberic_array[$key], $val);
|
|
|
|
} else if (strpos($key, 'from') !== FALSE) {
|
|
|
|
$this->read_replica->where('DATE(a.created) >=', $val);
|
|
|
|
} else if (strpos($key, 'to') !== FALSE) {
|
|
|
|
$this->read_replica->where('DATE(a.created) <=', $val);
|
|
|
|
} else if (array_key_exists($key, $string_array)) {
|
|
|
|
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
|
|
|
}
|
|
}
|
|
|
|
if ($limit) {
|
|
$this->read_replica->limit($limit, $offset);
|
|
}
|
|
|
|
return $this->read_replica->get()->result_array();
|
|
}
|
|
} |