This commit is contained in:
Naden
2026-04-25 04:41:23 +07:00
commit 7e9668a552
195 changed files with 20254 additions and 0 deletions

View File

@@ -0,0 +1,187 @@
<?php
namespace App\Models\MongoModel;
use Dhiva\Core\MongoLib;
class BaseMongoNoSql
{
/**
* @var Mongo
*/
protected $m;
protected $container = [];
protected $collection;
protected $providers = [
];
/**
*
*/
public function __construct()
{
$this->m = new MongoLib();
}
public function __get($name)
{
if (!isset($this->providers[$name])) {
throw new \Exception("class not found");
} else {
if (!isset($this->container[$name]) || !$this->container[$name]) {
try {
$this->container["{$name}"] = new $this->providers[$name]();
} catch (\Exception $e) {
throw new $e;
}
}
return $this->container["{$name}"];
}
}
/**
* @return mixed
*/
public function getIndexes()
{
return $this->m->listindexes($this->collection);
}
/**
* @param array $credentials
* @return mixed
*/
public function create( array $credentials)
{
return $this->m->insertMany($this->collection, $credentials);
}
/**
* @param array $credentials
* @return mixed
*/
public function createOne( array $credentials)
{
return $this->m->insertOne($this->collection, $credentials);
}
/**
* @param array $where
* @param array $options
* @param array $select
* @return mixed
* @throws \Exception
*/
public function getList( array $where = [], array $options = [], array $select = [])
{
$t = $this->m->options($options)->select($select)->where($where)->find($this->collection)->toArray();
unset($t['_id']);
return $t;
}
/**
* @param array $where
* @param array $options
* @param array $select
* @return mixed
* @throws \Exception
*/
public function getOne( array $where = [], array $options = [], array $select = [])
{
$t = $this->m->options($options)->select($select)->where($where)->findOne($this->collection);
unset($t['_id']);
return $t;
}
/**
* @param array $credentials
* @return mixed
* @throws \Exception
*/
public function get_where(array $credentials, )
{
$t = $this->m->options(['limit' => 1])->where($credentials)->count($this->collection);
unset($t['_id']);
return $t;
}
/**
* @param array $where
* @param array $set
* @param array $options
* @return mixed
* @throws \Exception
*/
public function updateMany( array $where, array $set, array $options = [])
{
return $this->m->options($options)->where($where)->set($set)->updateMany($this->collection);
}
/**
* @param array $where
* @param array $set
* @param array $options
* @return mixed
* @throws \Exception
*/
public function updateOne( array $where, array $set, array $options = [])
{
return $this->m->options($options)->where($where)->set($set)->updateOne($this->collection);
}
/**
* @param array $where
* @param array $set
* @param array $options
* @return mixed
* @throws \Exception
*/
public function findOneAndUpdate($update = [])
{
return $this->m->findOneAndUpdate($this->collection, $update);
}
/**
* @param array $where
* @param array $options
* @return mixed
* @throws \Exception
*/
public function deleteOne( array $where, array $options = [])
{
return $this->m->options($options)->where($where)->deleteOne($this->collection);
}
/**
* @param array $where
* @param array $options
* @return mixed
* @throws \Exception
*/
public function deleteMany( array $where, array $options = [])
{
return $this->m->options($options)->where($where)->deleteMany($this->collection);
}
/**
* @param array $where
* @param array $options
* @return mixed
* @throws \Exception
*/
public function count( array $where, array $options = [])
{
return $this->m->options($options)->where($where)->count($this->collection);
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class PersonelModel extends Model
{
protected $table = 'kta_digital.personel';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $allowedFields = [
'nrp', 'nama', 'pangkat', 'jabatan', 'satuan', 'foto_url',
'tmt_jabatan', 'lama_jabatan', 'tempat_lahir', 'tanggal_lahir',
'agama', 'suku', 'status_personel'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
/**
* Get full profile including all DRH related data
*/
public function getFullDRH($nrp)
{
$personel = $this->where('nrp', $nrp)->first();
if (!$personel) {
return null;
}
$db = \Config\Database::connect();
return [
'personel' => $personel,
'pendidikan_kepolisian' => $db->table('kta_digital.pendidikan_kepolisian')->where('nrp', $nrp)->get()->getResultArray(),
'pendidikan_umum' => $db->table('kta_digital.pendidikan_umum')->where('nrp', $nrp)->get()->getResultArray(),
'riwayat_pangkat' => $db->table('kta_digital.riwayat_pangkat')->where('nrp', $nrp)->get()->getResultArray(),
'riwayat_jabatan' => $db->table('kta_digital.riwayat_jabatan')->where('nrp', $nrp)->get()->getResultArray(),
'pendidikan_pengembangan' => $db->table('kta_digital.pendidikan_pengembangan')->where('nrp', $nrp)->get()->getResultArray(),
'tanda_kehormatan' => $db->table('kta_digital.tanda_kehormatan')->where('nrp', $nrp)->get()->getResultArray(),
'kemampuan_bahasa' => $db->table('kta_digital.kemampuan_bahasa')->where('nrp', $nrp)->get()->getResultArray(),
'penugasan_luar_struktur' => $db->table('kta_digital.penugasan_luar_struktur')->where('nrp', $nrp)->get()->getResultArray(),
];
}
}

View File

@@ -0,0 +1,254 @@
<?php
namespace App\Models\SqlModel;
use Dhiva\Core\DhivaAES;
class BaseModelSql
{
/**
* @var string
*/
protected $table = '';
/**
* @var string
*/
protected $primaryKey = '';
/**
* Unique Key pada table
*
* @var string
*/
protected $uniqueKey = '';
protected $db;
protected $container = [];
/**
* @property EndpointModelSql $endpoint
* @property SuperUserModelSql $super_user
* @property PerekamanFotoModelSql $perekaman_foto
* @property PesertaModelSql $peserta
*/
protected $providers = [
"endpoint" => EndpointModelSql::class,
"super_user" => SuperUserModelSql::class,
];
public function __construct()
{
$this->db = \Config\Database::connect();
$this->primaryKey = $this->table . '_id';
$this->uniqueKey = $this->table . '_unique';
}
/**
* @param $name
* @return mixed
* @throws \Exception
*/
public function __get($name)
{
if (!isset($this->providers[$name])) {
throw new \Exception("class not found");
} else {
if (!isset($this->container[$name]) || !$this->container[$name]) {
try {
$this->container["{$name}"] = new $this->providers[$name]();
} catch (\Exception $e) {
throw new $e;
}
}
return $this->container["{$name}"];
}
}
public function index()
{
$result = $this->db
->table($this->table)
->get()
->getResult();
return $result ? $result : false;
}
public function show($value)
{
$result = $this->db
->table($this->table)
->where($this->primaryKey, $value)
->get()
->getRow();
return $result ? $result : false;
}
public function showBy($columnName, $value)
{
$result = $this->db
->table($this->table)
->where($columnName, $value)
->get()
->getRow();
return $result ? $result : false;
}
public function allBy($columnName, $value)
{
$result = $this->db
->table($this->table)
->where($columnName, $value)
->get();
return $result ? $result->getResult() : false;
}
public function insert($data)
{
$id = DhivaAES::aesencodeid(strval(intval(microtime(true) * 1000)), 5);
$data[$this->primaryKey] = $id;
$result = $this->db
->table($this->table)
->insert($data);
return $result ? $id : false;
}
public function pagination($limit, $page, $where = false)
{
if (!$page) {
return 'HALAMAN DIMULAI DARI 1';
}
$wh = $where ?: $this->table . '_id is not null';
$result = $this->db
->table($this->table)
->where($wh)
->countAllResults();
$pagination['total_data'] = $result;
$pagination['total_pages'] = ceil($pagination['total_data'] / $limit);
$pagination['curr_page'] = intval($page);
$pagination['next_page'] = ($page >= $pagination['total_pages']) ? $pagination['total_pages'] : $page + 1;
if ($page > 1) {
$pagination['prev_page'] = $page - 1;
}
$pagination['data_per_page'] = intval($limit);
$offset = ($page - 1) * $limit;
$pagination['data'] = $this->db
->table($this->table)
->where($wh)
->limit($limit, $offset)
->orderBy($this->table . '_unique', 'DESC')
->get()
->getResult();
return $pagination;
}
public function paginationpost()
{
$result = $this->db
->table($this->table);
if (isset($_POST["to"]) && trim($_POST["to"]) != "") {
$result->where('DATE(created_at) <=', date('Y-m-d', strtotime($_POST['to'])));
}
if (((isset($_POST["where"]) && trim($_POST["where"]) != "") && (isset($_POST["where"]) && trim($_POST["where"]) != ""))) {
$result->where($_POST['where'], $_POST['set']);
}
if ((isset($_POST["groupby"]) && trim($_POST["groupby"]) != "")) {
$result->groupBy($_POST['groupby']);
}
if (((isset($_POST["orderby"]) && trim($_POST["orderby"]) != "")) && ((isset($_POST["sort"]) && trim($_POST["sort"]) != ""))) {
$result->orderBy($_POST['orderby'], $_POST['sort']);
}
$result = $result->countAllResults();
$pagination['total_data'] = $result;
$pagination['total_pages'] = ceil($result / intval($_POST['limit']));
$pagination['curr_page'] = intval($_POST['page']);
$pagination['next_page'] = ($_POST['page'] >= $pagination['total_pages']) ? $pagination['total_pages'] : $_POST['page'] + 1;
if ($_POST['page'] > 1) {
$pagination['prev_page'] = $_POST['page'] - 1;
}
$pagination['data_per_page'] = intval($_POST['limit']);
$offset = ($_POST['page'] - 1) * $_POST['limit'];
$pg = $this->db
->table($this->table)
->limit($_POST['limit'], $offset);
if (isset($_POST["from"]) && trim($_POST["from"]) != "") {
$pg->where('DATE(created_at) >=', date('Y-m-d', strtotime($_POST['from'])));
}
if (isset($_POST["to"]) && trim($_POST["to"]) != "") {
$pg->where('DATE(created_at) <=', date('Y-m-d', strtotime($_POST['to'])));
}
if (((isset($_POST["where"]) && trim($_POST["where"]) != "") && (isset($_POST["where"]) && trim($_POST["where"]) != ""))) {
$pg->where($_POST['where'], $_POST['set']);
}
if ((isset($_POST["groupby"]) && trim($_POST["groupby"]) != "")) {
$pg->groupBy($_POST['groupby']);
}
if (((isset($_POST["orderby"]) && trim($_POST["orderby"]) != "")) && ((isset($_POST["sort"]) && trim($_POST["sort"]) != ""))) {
$pg->orderBy($_POST['orderby'], $_POST['sort']);
}
$pagination['data'] = $pg->get()
->getResult();
return $pagination;
}
public function paginationByDate($limit, $page, $from, $to, $where = false)
{
if (!$page) {
return 'HALAMAN DIMULAI DARI 1';
}
$wh = $where ?: $this->table . '_id is not null';
$result = $this->db
->table($this->table)
->where(['created_at >=' => $from, 'created_at <=', $to])
->where($wh)
->countAllResults();
$pagination['total_data'] = $result;
$pagination['total_pages'] = ceil($pagination['total_data'] / $limit);
$pagination['curr_page'] = intval($page);
$pagination['next_page'] = ($page >= $pagination['total_pages']) ? $pagination['total_pages'] : $page + 1;
if ($page > 1) {
$pagination['prev_page'] = $page - 1;
}
$pagination['data_per_page'] = intval($limit);
$offset = ($page - 1) * $limit;
$pagination['data'] = $this->db
->table($this->table)
->where($wh)
->limit($limit, $offset)
->orderBy($this->table . '_unique', 'DESC')
->get()
->getResult();
return $pagination;
}
public function update($data, $id)
{
unset($data[$this->primaryKey]);
return $this->db
->table($this->table)
->where($this->primaryKey, $id)
->set($data)
->update();
}
public function updateBy($data, $id, $where = 0)
{
return $this->db
->table($this->table)
->where($where, $id)
->set($data)
->update();
}
public function destroy($id)
{
return $this->db
->table($this->table)
->where($this->primaryKey, $id)
->delete();
}
public function findByAnd($arrWhere)
{
return $this->db
->table($this->table)
->where($arrWhere)
->get()
->getRow();
}
public function allByAnd($arrWhere)
{
return $this->db
->table($this->table)
->where($arrWhere)
->get()
->getResult();
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Models\SqlModel;
class EndpointModelSql extends BaseModelSql
{
protected $table = 'endpoint';
public function insert($data)
{
return $this->db
->table($this->table)
->insert($data);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Models\SqlModel;
class SuperUserModelSql extends BaseModelSql
{
protected $table = 'super_user';
// public function auth($username, $password)
// {
// $data = $this->db
// ->table($this->table)
// ->where('password', $password)
// ->groupStart()
// ->where('username', $username)
// ->orWhere('nrp', $username)
// ->groupEnd()
// ->get()
// ->getRow();
// return $data;
// }
public function auth($username)
{
$data = $this->db
->table($this->table)
->where('username', $username)
->get()
->getRow();
return $data;
}
public function showUser($set, $where)
{
$data = $this->db
->table($this->table)
->join('satuan', 'satuan.satuan_id = CAST(super_user.satuan_id AS TEXT)', 'left')
->select('satuan.*, super_user.name, super_user.avatar, super_user.satuan_id, super_user.jabatan, super_user.email,
super_user.nrp as operator_nrp, super_user.satuan_id as operator_unit_id, super_user.no_wa as operator_no_wa, super_user.pangkat as operator_pangkat,
super_user.jabatan as operator_jabatan')
->where($this->table . '.' . $where, $set)
->get()
->getRow();
return $data;
}
public function showByUser($columnName, $value)
{
$result = $this->db
->table($this->table)
->select('satuan.*, super_user.nrp, super_user.name, super_user.avatar, super_user.satuan_id, super_user.jabatan')
->join('satuan', 'CAST(satuan.satuan_id AS INTEGER) = super_user.satuan_id')
->where($columnName, $value)
->groupBy(['super_user.super_user_id', 'super_user.satuan_id', 'satuan.satuan_id'])
->get()
->getRow();
return $result ?: false;
}
public function getalluser()
{
$db = \Config\Database::connect();
$builder = $db->table($this->table);
$data = $builder
->select('name,nrp,pangkat,jabatan')
->where('super_group_id !=', 1)
->where('super_group_id !=', 2)
->get()
->getResult();
return $data;
}
}