<?php
use App\Libraries\Onaylasms;
use Config\Database;
/**
* The goal of this file is to allow developers a location
* where they can overwrite core procedural functions and
* replace them with their own. This file is loaded during
* the bootstrap process and is called during the frameworks
* execution.
*
* This can be looked at as a `master helper` file that is
* loaded early on, and may also contain additional functions
* that you'd like to use throughout your entire application
*
* @see: https://codeigniter4.github.io/CodeIgniter4/
*/
function user()
{
if (session('user') != null) {
$user = model('User')->find(session('user')['id']);
return $user['last_session'] == session_id() ? $user : NULL;
} else {
return NULL;
}
}
function isRoute($path)
{
return uri_string() == $path;
}
function settings($key, $value = null)
{
$db = Database::connect();
$handler = $db->table('configs');
if ($value != null) {
$handler
->set('config_value', $value)
->where('config_name', $key)
->update();
}
$val = $handler->where('config_name', $key)->get()->getFirstRow();
return $val != null ? $val->config_value : NULL;
}
function db($table, $insertId = null)
{
$db = Database::connect();
if ($insertId) {
return $db->insertID();
}
return $db->table($table);
}
function getProviderCategories()
{
if (!$providerCategories = cache('categories.json')) {
$providerCategories = json_encode((new Onaylasms())->getCategories());
cache()->save('categories.json', $providerCategories, 60 * 60 * 24);
} else if ($providerCategories == null) {
$providerCategories = json_encode((new Onaylasms())->getCategories());
cache()->save('categories.json', $providerCategories, 60 * 60 * 24);
}
return json_decode($providerCategories, true);
}
function createMeta($currentPage)
{
return [
'name' => $currentPage,
'title' => $currentPage . " - " . settings('site_name')
];
}
function currentTheme()
{
return settings('site_theme');
}
function assets($path)
{
return base_url("assets/" . currentTheme() . "/$path");
}