Files
FloatBackOfffice/application/models/Oauth2_model.php
T
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

119 lines
3.9 KiB
PHP

<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Oauth2_model extends CI_Model
{
private $read_replica;
public function __construct()
{
parent::__construct();
$this->read_replica = $this->load->database('savvy_replica', TRUE);
}
public function get_all_record_oauth2_tokens(
$filters,
$limit = null,
$offset = null
) {
$this->read_replica->select(
'ot.email,
ot.name,
op.name AS provider,
ot.created,
ot.updated,
ot.expires_in,
op.access_type'
);
$this->read_replica->from('oauth2_tokens ot');
$this->read_replica->join('oauth2_providers op', 'op.id=ot.oauth2_provider_id');
foreach ($filters as $key => $value) {
if ($key === 'member_id') {
$this->read_replica->where('ot.member_id', $value);
} else if ($key === 'start_date') {
$this->read_replica->where('DATE(ot.updated) >=', $value);
} else if ($key === 'end_date') {
$this->read_replica->where('DATE(ot.updated) <=', $value);
} else {
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
}
}
if ($limit) {
$this->read_replica->limit($limit, $offset);
$this->read_replica->order_by('ot.created DESC');
}
return $this->read_replica->get()->result_array();
}
public function get_all_record_oauth2_pull_jobs(
$filters,
$limit = null,
$offset = null
) {
$this->read_replica->select(
'created,
started,
completed'
);
$this->read_replica->from('oauth2_pull_jobs');
$this->read_replica->where('started IS NOT NULL');
foreach ($filters as $key => $value) {
if ($key === 'member_id') {
$this->read_replica->where('member_id', $value);
} else if ($key === 'start_date') {
$this->read_replica->where('DATE(completed) >=', $value);
} else if ($key === 'end_date') {
$this->read_replica->where('DATE(completed) <=', $value);
} else {
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
}
}
if ($limit) {
$this->read_replica->limit($limit, $offset);
$this->read_replica->order_by('started DESC');
}
return $this->read_replica->get()->result_array();
}
public function get_all_record_oauth2_pull_threads(
$filters,
$limit = null,
$offset = null
) {
$this->read_replica->select(
'pjt.created AS created,
pjt.started AS started,
pjt.completed AS completed ,
pjt.item_count AS item_count,
pjt.search_term AS search_term,
pjt.search_from AS search_from,
pjt.failed AS failed'
);
$this->read_replica->from('oauth2_pull_job_threads pjt');
$this->read_replica->join('oauth2_pull_jobs pj', 'pjt.id = pjt.oauth2_pull_job_id');
foreach ($filters as $key => $value) {
if ($key === 'member_id') {
$this->read_replica->where('pj.member_id', $value);
} else if ($key === 'start_date') {
$this->read_replica->where('DATE(pjt.completed) >=', $value);
} else if ($key === 'end_date') {
$this->read_replica->where('DATE(pjt.completed) <=', $value);
} else {
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
}
}
if ($limit) {
$this->read_replica->limit($limit, $offset);
$this->read_replica->order_by('pjt.id');
}
return $this->read_replica->get()->result_array();
}
}