akaunting/app/Traits/Modules.php

684 lines
16 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Traits;
2019-12-04 18:10:38 +03:00
use App\Models\Module\Module;
2019-11-16 10:21:14 +03:00
use App\Traits\SiteApi;
2019-12-03 15:41:56 +03:00
use App\Utilities\Console;
2017-09-19 12:32:06 +03:00
use App\Utilities\Info;
2018-12-12 20:28:16 +03:00
use Cache;
use Date;
2017-09-14 22:21:00 +03:00
use File;
2019-11-16 10:21:14 +03:00
use Illuminate\Support\Str;
2017-09-19 12:32:06 +03:00
use ZipArchive;
2017-09-14 22:21:00 +03:00
trait Modules
{
2019-11-16 10:21:14 +03:00
use SiteApi;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
public function checkToken($apiKey)
2018-04-25 16:56:01 +03:00
{
$data = [
'form_params' => [
2019-11-16 10:21:14 +03:00
'token' => $apiKey,
2018-04-25 16:56:01 +03:00
]
];
2019-12-04 18:10:38 +03:00
if (!$response = static::getResponse('POST', 'token/check', $data)) {
return false;
2018-04-25 16:56:01 +03:00
}
2019-12-04 18:10:38 +03:00
$result = json_decode($response->getBody());
return $result->success ? true : false;
2018-04-25 16:56:01 +03:00
}
2019-11-16 10:21:14 +03:00
// Get All Modules
2020-05-20 21:14:49 +03:00
public function getModules($data = [])
2017-09-14 22:21:00 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.app.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$items = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($items)) {
return $items;
}
2019-12-04 18:10:38 +03:00
$items = static::getResponseData('GET', 'apps/items');
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $items, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $items;
2017-09-14 22:21:00 +03:00
}
2019-11-16 10:21:14 +03:00
// Get Module
2017-09-14 22:21:00 +03:00
public function getModule($alias)
{
2019-12-04 18:10:38 +03:00
$item = static::getResponseData('GET', 'apps/' . $alias);
2019-11-19 16:52:44 +03:00
return $item;
2017-09-14 22:21:00 +03:00
}
public function getDocumentation($alias)
{
2020-06-17 23:07:31 +03:00
$key = 'apps.' . $alias . '.docs.' . $this->getDataKey($data);
2020-05-20 21:14:49 +03:00
$documentation = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($documentation)) {
return $documentation;
}
2019-12-04 18:10:38 +03:00
$documentation = static::getResponseData('GET', 'apps/docs/' . $alias);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $documentation, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $documentation;
}
2018-09-20 18:35:24 +03:00
public function getModuleReviews($alias, $data = [])
{
2020-06-17 23:07:31 +03:00
$key = 'apps.' . $alias . '.reviews.' . $this->getDataKey($data);
2020-05-20 21:14:49 +03:00
$reviews = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($reviews)) {
return $reviews;
}
2019-12-04 18:10:38 +03:00
$reviews = static::getResponseData('GET', 'apps/' . $alias . '/reviews', $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $reviews, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $reviews;
2018-09-20 18:35:24 +03:00
}
2020-05-20 21:14:49 +03:00
public function getCategories($data = [])
2017-09-14 22:21:00 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.categories.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$categories = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($categories)) {
return $categories;
}
2019-12-04 18:10:38 +03:00
$categories = static::getResponseData('GET', 'apps/categories');
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $categories, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $categories;
2017-09-14 22:21:00 +03:00
}
2018-09-20 11:16:56 +03:00
public function getModulesByCategory($alias, $data = [])
2017-09-14 22:21:00 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.categories.' . $alias . '.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$category = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($category)) {
return $category;
}
2019-12-04 18:10:38 +03:00
$category = static::getResponseData('GET', 'apps/categories/' . $alias, $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $category, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $category;
2017-09-14 22:21:00 +03:00
}
2020-05-20 21:14:49 +03:00
public function getVendors($data = [])
2018-10-03 12:10:59 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.vendors.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$vendors = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($vendors)) {
return $vendors;
}
2019-12-04 18:10:38 +03:00
$vendors = static::getResponseData('GET', 'apps/vendors');
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $vendors, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $vendors;
2018-10-03 12:10:59 +03:00
}
public function getModulesByVendor($alias, $data = [])
{
2020-06-17 23:07:31 +03:00
$key = 'apps.vendors.' . $alias . '.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$vendor = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($vendor)) {
return $vendor;
}
2019-12-04 18:10:38 +03:00
$vendor = static::getResponseData('GET', 'apps/vendors/' . $alias, $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $vendor, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $vendor;
2018-10-03 12:10:59 +03:00
}
public function getMyModules($data = [])
{
2019-12-04 18:10:38 +03:00
return static::getResponseData('GET', 'apps/my', $data);
}
2020-05-20 21:14:49 +03:00
public function getInstalledModules()
{
2020-05-20 21:14:49 +03:00
$key = 'apps.installed.' . session('company_id');
2020-05-17 02:46:03 +03:00
if ($installed = Cache::get($key)) {
return $installed;
}
$installed = [];
2019-11-16 10:21:14 +03:00
2020-05-17 02:46:03 +03:00
Module::all()->each(function($module) use (&$installed) {
if (!$this->moduleExists($module->alias)) {
return;
}
2020-05-17 02:46:03 +03:00
if (!$result = $this->getModule($module->alias)) {
return;
}
2020-05-17 02:46:03 +03:00
$installed[] = $result;
});
Cache::put($key, $installed, Date::now()->addHour(6));
return $installed;
}
2019-01-30 18:39:39 +03:00
public function getPreSaleModules($data = [])
{
2020-06-17 23:07:31 +03:00
$key = 'apps.pre_sale.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$pre_sale = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($pre_sale)) {
return $pre_sale;
}
2019-12-04 18:10:38 +03:00
$pre_sale = static::getResponseData('GET', 'apps/pre_sale', $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $pre_sale, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $pre_sale;
2019-01-30 18:39:39 +03:00
}
public function getPaidModules($data = [])
2017-09-14 22:21:00 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.paid.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$paid = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($paid)) {
return $paid;
}
2019-12-04 18:10:38 +03:00
$paid = static::getResponseData('GET', 'apps/paid', $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $paid, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $paid;
2017-09-14 22:21:00 +03:00
}
public function getNewModules($data = [])
2017-09-14 22:21:00 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.new.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$new = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($new)) {
return $new;
}
2019-12-04 18:10:38 +03:00
$new = static::getResponseData('GET', 'apps/new', $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $new, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $new;
2017-09-14 22:21:00 +03:00
}
public function getFreeModules($data = [])
2017-09-14 22:21:00 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.free.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$free = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($free)) {
return $free;
}
2019-12-04 18:10:38 +03:00
$free = static::getResponseData('GET', 'apps/free', $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $free, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $free;
2018-04-25 19:28:10 +03:00
}
2019-11-19 16:52:44 +03:00
public function getFeaturedModules($data = [])
2018-04-25 19:28:10 +03:00
{
2020-06-17 23:07:31 +03:00
$key = 'apps.featured.' . $this->getDataKey($data);
2020-05-20 01:01:06 +03:00
2020-05-20 21:14:49 +03:00
$featured = Cache::get($key);
2019-11-19 16:52:44 +03:00
if (!empty($featured)) {
return $featured;
}
2019-12-04 18:10:38 +03:00
$featured = static::getResponseData('GET', 'apps/featured', $data);
2019-11-19 16:52:44 +03:00
2020-05-20 21:14:49 +03:00
Cache::put($key, $featured, Date::now()->addHour());
2019-11-19 16:52:44 +03:00
return $featured;
2017-09-14 22:21:00 +03:00
}
2019-11-19 16:52:44 +03:00
public function getSearchModules($data = [])
{
2019-12-04 18:10:38 +03:00
return static::getResponseData('GET', 'apps/search', $data);
}
2017-09-14 22:21:00 +03:00
public function getCoreVersion()
{
$data['query'] = Info::all();
2019-12-04 18:10:38 +03:00
if (!$response = static::getResponse('GET', 'core/version', $data)) {
return [];
2017-09-14 22:21:00 +03:00
}
2019-12-04 18:10:38 +03:00
return $response->json();
2017-09-14 22:21:00 +03:00
}
public function downloadModule($path)
{
2020-05-07 17:17:04 +03:00
if (empty($path)) {
return [
'success' => false,
'error' => true,
'message' => trans('modules.errors.download', ['module' => '']),
'data' => null,
];
}
2019-12-04 18:10:38 +03:00
if (!$response = static::getResponse('GET', $path)) {
return [
'success' => false,
'error' => true,
2020-05-07 17:17:04 +03:00
'message' => trans('modules.errors.download', ['module' => '']),
2019-12-04 18:10:38 +03:00
'data' => null,
];
}
2017-09-14 22:21:00 +03:00
2019-12-04 18:10:38 +03:00
$file = $response->getBody()->getContents();
2017-09-14 22:21:00 +03:00
2019-12-04 18:10:38 +03:00
$path = 'temp-' . md5(mt_rand());
$temp_path = storage_path('app/temp') . '/' . $path;
2017-09-14 22:21:00 +03:00
2019-12-04 18:10:38 +03:00
$file_path = $temp_path . '/upload.zip';
2017-09-14 22:21:00 +03:00
2019-12-04 18:10:38 +03:00
// Create tmp directory
if (!File::isDirectory($temp_path)) {
File::makeDirectory($temp_path);
}
2017-09-14 22:21:00 +03:00
2019-12-04 18:10:38 +03:00
// Add content to the Zip file
$uploaded = is_int(file_put_contents($file_path, $file)) ? true : false;
2017-09-14 22:21:00 +03:00
2019-12-04 18:10:38 +03:00
if (!$uploaded) {
2017-10-11 16:01:23 +03:00
return [
2019-12-04 18:10:38 +03:00
'success' => false,
'error' => true,
2020-05-07 17:17:04 +03:00
'message' => trans('modules.errors.download', ['module' => '']),
2019-12-04 18:10:38 +03:00
'data' => null,
2017-10-11 16:01:23 +03:00
];
2017-09-14 22:21:00 +03:00
}
2017-10-11 16:01:23 +03:00
return [
2019-12-04 18:10:38 +03:00
'success' => true,
'error' => false,
2019-11-20 17:11:35 +03:00
'message' => null,
2019-12-04 18:10:38 +03:00
'data' => [
'path' => $path,
],
2017-10-11 16:01:23 +03:00
];
2017-09-14 22:21:00 +03:00
}
public function unzipModule($path)
{
2020-05-07 17:17:04 +03:00
if (empty($path)) {
return [
'success' => false,
'error' => true,
'message' => trans('modules.errors.unzip', ['module' => '']),
'data' => null,
];
}
2017-09-14 22:21:00 +03:00
$temp_path = storage_path('app/temp') . '/' . $path;
$file = $temp_path . '/upload.zip';
// Unzip the file
2017-09-19 12:32:06 +03:00
$zip = new ZipArchive();
if (!$zip->open($file) || !$zip->extractTo($temp_path)) {
return [
2017-09-14 22:21:00 +03:00
'success' => false,
2019-11-20 17:11:35 +03:00
'error' => true,
2020-05-07 17:17:04 +03:00
'message' => trans('modules.errors.unzip', ['module' => '']),
2017-09-14 22:21:00 +03:00
'data' => null,
2017-09-19 12:32:06 +03:00
];
2017-09-14 22:21:00 +03:00
}
2017-09-19 12:32:06 +03:00
$zip->close();
2017-09-14 22:21:00 +03:00
// Remove Zip
2017-09-19 12:32:06 +03:00
File::delete($file);
2017-09-14 22:21:00 +03:00
2017-09-19 12:32:06 +03:00
$data = [
2017-09-14 22:21:00 +03:00
'path' => $path
2017-09-19 12:32:06 +03:00
];
2017-09-14 22:21:00 +03:00
2017-09-19 12:32:06 +03:00
return [
2017-09-14 22:21:00 +03:00
'success' => true,
2019-11-20 17:11:35 +03:00
'error' => false,
'message' => null,
2017-09-14 22:21:00 +03:00
'data' => $data,
2017-09-19 12:32:06 +03:00
];
2017-09-14 22:21:00 +03:00
}
public function installModule($path)
{
2020-05-07 17:17:04 +03:00
if (empty($path)) {
return [
'success' => false,
'error' => true,
'message' => trans('modules.errors.finish', ['module' => '']),
'data' => null,
];
}
2017-09-14 22:21:00 +03:00
$temp_path = storage_path('app/temp') . '/' . $path;
2020-05-07 17:17:04 +03:00
$modules_path = config('module.paths.modules');
2017-09-14 22:21:00 +03:00
// Create modules directory
if (!File::isDirectory($modules_path)) {
File::makeDirectory($modules_path);
}
$module = json_decode(file_get_contents($temp_path . '/module.json'));
2019-11-16 10:21:14 +03:00
$module_path = $modules_path . '/' . Str::studly($module->alias);
2017-09-14 22:21:00 +03:00
// Create module directory
if (!File::isDirectory($module_path)) {
File::makeDirectory($module_path);
}
// Move all files/folders from temp path then delete it
File::copyDirectory($temp_path, $module_path);
File::deleteDirectory($temp_path);
2020-06-11 23:32:13 +03:00
event(new \App\Events\Module\Copied($module->alias, session('company_id')));
2017-09-14 22:21:00 +03:00
2019-12-03 15:41:56 +03:00
$company_id = session('company_id');
2020-02-03 18:57:31 +03:00
$locale = app()->getLocale();
2019-12-03 15:41:56 +03:00
2020-05-07 17:17:04 +03:00
$command = "module:install {$module->alias} {$company_id} {$locale}";
if (true !== $result = Console::run($command)) {
$message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $module->alias]);
return [
'success' => false,
'error' => true,
'message' => $message,
'data' => null,
];
}
2019-12-03 15:41:56 +03:00
2017-10-11 16:01:23 +03:00
return [
2017-09-14 22:21:00 +03:00
'success' => true,
2020-05-07 17:17:04 +03:00
'redirect' => route('apps.app.show', $module->alias),
2019-11-20 17:11:35 +03:00
'error' => false,
'message' => null,
2020-06-11 23:32:13 +03:00
'data' => [
'path' => $path,
'name' => module($module->alias)->getName(),
'alias' => $module->alias,
],
2017-10-11 16:01:23 +03:00
];
2017-09-14 22:21:00 +03:00
}
public function uninstallModule($alias)
{
2019-11-16 10:21:14 +03:00
$module = module($alias);
2020-06-11 23:32:13 +03:00
$name = $module->getName();
$category = $module->get('category');
$version = $module->get('version');
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
$company_id = session('company_id');
$locale = app()->getLocale();
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
$command = "module:uninstall {$alias} {$company_id} {$locale}";
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
if (true !== $result = Console::run($command)) {
return [
'success' => false,
'error' => true,
'message' => $result,
'data' => null,
];
}
2017-09-14 22:21:00 +03:00
2017-10-11 16:01:23 +03:00
return [
2017-09-14 22:21:00 +03:00
'success' => true,
2019-11-20 17:11:35 +03:00
'error' => false,
'message' => null,
2020-06-11 23:32:13 +03:00
'data' => [
'name' => $name,
'category' => $category,
'version' => $version,
],
2017-10-11 16:01:23 +03:00
];
2017-09-14 22:21:00 +03:00
}
public function enableModule($alias)
2017-09-14 22:21:00 +03:00
{
2019-11-16 10:21:14 +03:00
$module = module($alias);
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
$company_id = session('company_id');
$locale = app()->getLocale();
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
$command = "module:enable {$alias} {$company_id} {$locale}";
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
if (true !== $result = Console::run($command)) {
return [
'success' => false,
'error' => true,
'message' => $result,
'data' => null,
];
}
2017-09-14 22:21:00 +03:00
2017-10-11 16:01:23 +03:00
return [
2017-09-14 22:21:00 +03:00
'success' => true,
2019-11-20 17:11:35 +03:00
'error' => false,
'message' => null,
2020-06-11 23:32:13 +03:00
'data' => [
'name' => $module->getName(),
'category' => $module->get('category'),
'version' => $module->get('version'),
],
2017-10-11 16:01:23 +03:00
];
2017-09-14 22:21:00 +03:00
}
public function disableModule($alias)
2017-09-14 22:21:00 +03:00
{
2019-11-16 10:21:14 +03:00
$module = module($alias);
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
$company_id = session('company_id');
$locale = app()->getLocale();
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
$command = "module:disable {$alias} {$company_id} {$locale}";
2017-09-14 22:21:00 +03:00
2020-06-11 23:32:13 +03:00
if (true !== $result = Console::run($command)) {
return [
'success' => false,
'error' => true,
'message' => $result,
'data' => null,
];
}
2017-09-14 22:21:00 +03:00
2017-10-11 16:01:23 +03:00
return [
2017-09-14 22:21:00 +03:00
'success' => true,
2019-11-20 17:11:35 +03:00
'error' => false,
'message' => null,
2020-06-11 23:32:13 +03:00
'data' => [
'name' => $module->getName(),
'category' => $module->get('category'),
'version' => $module->get('version'),
],
2017-10-11 16:01:23 +03:00
];
2017-09-14 22:21:00 +03:00
}
2018-12-24 16:53:10 +03:00
public function moduleExists($alias)
{
2020-05-17 02:46:03 +03:00
if (!module($alias) instanceof \Akaunting\Module\Module) {
return false;
}
return true;
}
public function moduleEnabled($alias)
{
if (!$this->moduleExists($alias)) {
return false;
}
2018-12-24 16:53:10 +03:00
2020-05-17 02:46:03 +03:00
if (!Module::alias($alias)->enabled()->first()) {
return false;
2018-12-24 16:53:10 +03:00
}
2020-05-17 02:46:03 +03:00
return true;
2018-12-24 16:53:10 +03:00
}
2018-05-25 16:57:58 +03:00
public function loadSuggestions()
{
2020-05-20 21:14:49 +03:00
$key = 'apps.suggestions';
$data = Cache::get($key);
2018-05-25 16:57:58 +03:00
if (!empty($data)) {
return $data;
}
$data = [];
2019-12-04 18:10:38 +03:00
if (!$suggestions = static::getResponseData('GET', 'apps/suggestions')) {
return $data;
2018-05-25 16:57:58 +03:00
}
2019-12-04 18:10:38 +03:00
foreach ($suggestions as $suggestion) {
$data[$suggestion->path] = $suggestion;
2018-05-25 16:57:58 +03:00
}
2020-05-20 21:14:49 +03:00
Cache::put($key, $data, Date::now()->addHour(6));
2018-05-25 16:57:58 +03:00
return $data;
}
2018-11-16 18:33:39 +03:00
public function loadNotifications()
{
2020-05-20 21:14:49 +03:00
$key = 'apps.notifications';
$data = Cache::get($key);
2018-11-16 18:33:39 +03:00
if (!empty($data)) {
return $data;
}
$data = [];
2019-12-04 18:10:38 +03:00
if (!$notifications = static::getResponse('GET', 'apps/notifications')) {
return $data;
2018-11-16 18:33:39 +03:00
}
foreach ($notifications as $notification) {
$data[$notification->path][] = $notification;
}
2020-05-20 21:14:49 +03:00
Cache::put($key, $data, Date::now()->addHour(6));
2018-11-16 18:33:39 +03:00
return $data;
}
2018-05-25 16:57:58 +03:00
public function getSuggestions($path)
{
2020-05-20 21:14:49 +03:00
$key = 'apps.suggestions';
$data = Cache::get($key);
2018-05-25 16:57:58 +03:00
if (empty($data)) {
$data = $this->loadSuggestions();
}
2018-06-13 15:07:43 +03:00
if (!empty($data) && array_key_exists($path, $data)) {
2018-05-25 16:57:58 +03:00
return $data[$path];
}
return false;
}
2018-11-16 18:33:39 +03:00
public function getNotifications($path)
{
2020-05-20 21:14:49 +03:00
$key = 'apps.notifications';
$data = Cache::get($key);
2018-11-16 18:33:39 +03:00
if (empty($data)) {
$data = $this->loadNotifications();
}
if (!empty($data) && array_key_exists($path, $data)) {
return $data[$path];
}
return false;
}
2020-05-20 21:14:49 +03:00
public function getPageNumber($data = [])
{
if (empty($data['query']) || empty($data['query']['page'])) {
return 1;
}
return $data['query']['page'];
}
2020-06-17 23:07:31 +03:00
public function getDataKey($data = [])
{
2020-06-18 17:33:55 +03:00
$result = 'language.' . language()->getShortCode() . '.page.' . $this->getPageNumber($data);
2020-06-17 23:07:31 +03:00
if (isset($data['query']['page'])) {
unset($data['query']['page']);
}
if (isset($data['query'])){
foreach($data['query'] as $key => $value) {
$result .= '.' . $key . '.' . $value;
}
}
return $result;
}
2017-09-14 22:21:00 +03:00
}