mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Continuo migrando, estoy perfilando activity y los settings
This commit is contained in:
39
ci4/app/Models/CollectionModel.php
Normal file
39
ci4/app/Models/CollectionModel.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class CollectionModel
|
||||
{
|
||||
/**
|
||||
* Generate a data table response.
|
||||
*
|
||||
* @param array $data The data to be displayed in the table.
|
||||
* @param int $recordsTotal The total number of records without filtering.
|
||||
* @param int $recordsFiltered The total number of records after filtering.
|
||||
* @param string|null $error An optional error message to be included in the response.
|
||||
* @return array The data table response containing the draw count, total records, filtered records,
|
||||
* the data, and a CSRF token (in case it is regenerated).
|
||||
*/
|
||||
public static function datatable(array $data, int $recordsTotal, int $recordsFiltered, string $error = null)
|
||||
{
|
||||
$req = service('request');
|
||||
$reqData = $req->getPostGet('data') ?? [];
|
||||
$draw = $reqData['draw'] ?? $req->getPostGet('draw') ?? 1;
|
||||
|
||||
$response = [
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $recordsTotal,
|
||||
'recordsFiltered' => $recordsFiltered,
|
||||
'data' => $data,
|
||||
'token' => csrf_hash(), // in case the CSRF token is regenerated
|
||||
];
|
||||
|
||||
if (!empty($error)) {
|
||||
$response['error'] = $error;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
class CountriesModel extends BaseModel
|
||||
{
|
||||
protected $table = 'auth_countries';
|
||||
protected $primaryKey = 'id_country';
|
||||
protected $allowedFields = [
|
||||
'phone',
|
||||
'code',
|
||||
'name',
|
||||
'symbol',
|
||||
'capital',
|
||||
'currency',
|
||||
'continent',
|
||||
'continent_code',
|
||||
'alpha_3',
|
||||
'data_lang'
|
||||
];
|
||||
}
|
||||
100
ci4/app/Models/Sistema/ActivityModel.php
Normal file
100
ci4/app/Models/Sistema/ActivityModel.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sistema;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class ActivityModel extends BaseModel
|
||||
{
|
||||
protected $table = 'auth_activity';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $returnType = "App\Entities\Sistema\ActivityEntity";
|
||||
|
||||
const SORTABLE = [
|
||||
1 => "t1.id",
|
||||
2 => "t2.username",
|
||||
3 => "t1.level",
|
||||
4 => "t1.event",
|
||||
5 => "t1.ip",
|
||||
6 => "t1.os",
|
||||
7 => "t1.browser",
|
||||
8 => "t1.detail"
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
'user_id',
|
||||
'level',
|
||||
'event',
|
||||
'ip',
|
||||
'os',
|
||||
'browser',
|
||||
'detail'
|
||||
];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a resource from the database based on the given search string.
|
||||
*
|
||||
* @param string $search The search string to filter the resource by. Defaults to an empty string.
|
||||
* @return mixed The resource query builder instance if search string is empty, otherwise the filtered resource query builder instance.
|
||||
*/
|
||||
public function getResource(string $search = "")
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t2.username AS user, t1.level AS level, t1.event AS event, t1.ip AS ip, t1.os AS os,
|
||||
t1.browser AS browser, t1.created_at AS created_at"
|
||||
)
|
||||
->join("users t2", "t1.user_id = t2.id", "left")
|
||||
->orderBy('t1.created_at', 'DESC');
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.id", $search)
|
||||
->orLike("t2.username", $search)
|
||||
->orLike("t1.level", $search)
|
||||
->orLike("t1.event", $search)
|
||||
->orLike("t1.ip", $search)
|
||||
->orLike("t1.os", $search)
|
||||
->orLike("t1.browser", $search)
|
||||
->orLike("t1.created_at", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function getLogs()
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
'SUM( IF( os LIKE "%Windows%", 1, 0 ) ) AS windows,
|
||||
SUM( IF( os = "Mac OS X", 1, 0 ) ) AS mac,
|
||||
SUM( IF( os = "Linux", 1, 0 ) ) AS linux,
|
||||
SUM( IF( os = "Android", 1, 0 ) ) AS android,
|
||||
SUM( IF( os = "iOS", 1, 0 ) ) AS iphone,
|
||||
SUM( IF( browser LIKE "%Chrome%", 1, 0 ) ) AS chrome,
|
||||
SUM( IF( browser LIKE "%Firefox%", 1, 0 ) ) AS firefox,
|
||||
SUM( IF( browser LIKE "%Safari%", 1, 0 ) ) AS safari,
|
||||
SUM( IF( browser LIKE "%Internet Explorer%", 1, 0 ) ) AS ie,
|
||||
SUM( IF( browser LIKE "%Edge%", 1, 0 ) ) AS edge,
|
||||
SUM( IF( browser LIKE "%Opera%", 1, 0 ) ) AS opera'
|
||||
);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
}
|
||||
38
ci4/app/Models/Sistema/SettingsModel.php
Normal file
38
ci4/app/Models/Sistema/SettingsModel.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace App\Models\Sistema;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class SettingsModel extends BaseModel
|
||||
{
|
||||
protected $table = 'auth_settings';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $returnType = "App\Entities\Sistema\SettingsEntity";
|
||||
|
||||
const SORTABLE = [
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
'email_gateway',
|
||||
'email_name',
|
||||
'email_address',
|
||||
'email_smtp',
|
||||
'email_port',
|
||||
'email_pass',
|
||||
'email_cert',
|
||||
'remove_log',
|
||||
'remove_log_time',
|
||||
'remove_log_latest',
|
||||
'storage_gateway',
|
||||
'backup_storage',
|
||||
'backup_table',
|
||||
'backup_email',
|
||||
'backup_notification_email',
|
||||
'backup_automatic',
|
||||
'backup_time',
|
||||
'backup_latest'
|
||||
];
|
||||
protected $useTimestamps = true;
|
||||
protected $updatedField = 'updated_at';
|
||||
}
|
||||
Reference in New Issue
Block a user