mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-01 21:02:54 +09:00
Mirgate to PSR12 and other small fixes
This commit is contained in:
1 parent
84ae07b788
commit
f4c4f6bac7
184 files changed
+15781
-13117
No files matched your search
+6
-1
@@ -18,9 +18,14 @@ composer.phar
|
||||
public
|
||||
report/*
|
||||
data/db
|
||||
|
||||
### phpunit/phpunit ###
|
||||
.phpunit.result.cache
|
||||
|
||||
### node_moduels ###
|
||||
### node_modules ###
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.history/
|
||||
|
||||
### friendsofphp/php-cs-fixer ###
|
||||
src/.php-cs-fixer.cache
|
||||
@@ -0,0 +1,82 @@
|
||||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
# Change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# We recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.feature]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.js]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.md]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.neon]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.php]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.sh]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.{yaml,yml}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[.babelrc]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[.gitmodules]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[.php_cs{,.dist}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[composer.json]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[package.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[phpspec.yml{,.dist}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[phpstan.neon]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[phpunit.xml{,.dist}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
return (new PhpCsFixer\Config())
|
||||
->setRules([
|
||||
'@PHP71Migration' => true,
|
||||
'@Symfony' => true,
|
||||
'protected_to_private' => false,
|
||||
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => false],
|
||||
'phpdoc_to_comment' => false,
|
||||
])
|
||||
->setRiskyAllowed(false)
|
||||
->setFinder(
|
||||
(new PhpCsFixer\Finder())
|
||||
->in(__DIR__)
|
||||
->exclude([
|
||||
'bb-data',
|
||||
'bb-library',
|
||||
'bb-locale',
|
||||
'bb-themes',
|
||||
'bb-vendor',
|
||||
'install',
|
||||
'bb-modules/Wysiwyg'
|
||||
])
|
||||
->notPath('rb.php')
|
||||
)
|
||||
;
|
||||
+71
-70
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling configuration file example
|
||||
* BoxBilling configuration file example.
|
||||
*
|
||||
* If you are not using the web installer, you can rename this file
|
||||
* to "bb-config.php" and fill in the values.
|
||||
@@ -10,190 +10,191 @@
|
||||
* Remove /install directory
|
||||
*/
|
||||
|
||||
return array(
|
||||
|
||||
'salt' => '',
|
||||
return [
|
||||
'salt' => '',
|
||||
|
||||
/**
|
||||
* Full URL where BoxBilling is installed with trailing slash
|
||||
* Full URL where BoxBilling is installed with trailing slash.
|
||||
*/
|
||||
'url' => 'http://localhost/',
|
||||
'url' => 'http://localhost/',
|
||||
|
||||
/**
|
||||
* The URL prefix to access the BB admin area. Ex: '/bb-admin' for https://example.com/bb-admin
|
||||
* The URL prefix to access the BB admin area. Ex: '/bb-admin' for https://example.com/bb-admin.
|
||||
*/
|
||||
'admin_area_prefix' => '/bb-admin',
|
||||
'admin_area_prefix' => '/bb-admin',
|
||||
|
||||
/**
|
||||
* Enable or disable displaying advanced debugging messages.
|
||||
* You should keep this disabled unless you're making tests as it can reveal some information about your server.
|
||||
*/
|
||||
'debug' => false,
|
||||
'debug' => false,
|
||||
|
||||
'maintenance_mode' => array(
|
||||
'maintenance_mode' => [
|
||||
/**
|
||||
* Enable or disable the system maintenance mode.
|
||||
* Enabling this will block public access to your website, and API endpoints except the allowed ones won't work
|
||||
* However, this will not block access to the administrator area.
|
||||
*
|
||||
*
|
||||
* @since 4.22.0
|
||||
*/
|
||||
'enabled' => false,
|
||||
'enabled' => false,
|
||||
|
||||
/**
|
||||
* Don't block these URLs when the maintenance is going on.
|
||||
* Supports wildcard (e.g. '/api/guest/staff/*')
|
||||
* Supports wildcard (e.g. '/api/guest/staff/*').
|
||||
*
|
||||
* @since 4.22.0
|
||||
*/
|
||||
'allowed_urls' => array(),
|
||||
'allowed_urls' => [],
|
||||
|
||||
/**
|
||||
* Don't block these IP/Subnet addresses when the maintenance is going on.
|
||||
* Supported formats: 127.0.0.1、127.0.0.1/32
|
||||
* Supported formats: 127.0.0.1、127.0.0.1/32.
|
||||
*
|
||||
* @since 4.22.0
|
||||
*/
|
||||
'allowed_ips' => array(),
|
||||
),
|
||||
|
||||
'allowed_ips' => [],
|
||||
],
|
||||
|
||||
/**
|
||||
* Enable or disable search engine friendly URLs.
|
||||
* Configure .htaccess file before enabling this feature
|
||||
* Set to TRUE if using nginx
|
||||
* Set to TRUE if using nginx.
|
||||
*/
|
||||
'sef_urls' => true,
|
||||
'sef_urls' => true,
|
||||
|
||||
/**
|
||||
* System timezone
|
||||
* System timezone.
|
||||
*/
|
||||
'timezone' => 'UTC',
|
||||
'timezone' => 'UTC',
|
||||
|
||||
/**
|
||||
* BoxBilling locale
|
||||
* BoxBilling locale.
|
||||
*/
|
||||
'locale' => 'en_US',
|
||||
'locale' => 'en_US',
|
||||
|
||||
/**
|
||||
* Set default date format for localized strings
|
||||
* Set default date format for localized strings.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.strftime.php
|
||||
*/
|
||||
'locale_date_format' => '%A, %d %B %G',
|
||||
'locale_date_format' => '%A, %d %B %G',
|
||||
|
||||
/**
|
||||
* Set default time format for localized strings
|
||||
* Set default time format for localized strings.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.strftime.php
|
||||
*/
|
||||
'locale_time_format' => ' %T',
|
||||
'locale_time_format' => ' %T',
|
||||
|
||||
/**
|
||||
* Set location to store sensitive data
|
||||
* Set location to store sensitive data.
|
||||
*/
|
||||
'path_data' => dirname(__FILE__) . '/bb-data',
|
||||
'path_data' => dirname(__FILE__).'/bb-data',
|
||||
|
||||
'path_logs' => dirname(__FILE__) . '/bb-data/log/application.log',
|
||||
'path_logs' => dirname(__FILE__).'/bb-data/log/application.log',
|
||||
|
||||
'log_to_db' => true,
|
||||
'log_to_db' => true,
|
||||
|
||||
'db' => array(
|
||||
'db' => [
|
||||
/**
|
||||
* Database type. Don't change this if in doubt.
|
||||
*/
|
||||
'type' => 'mysql',
|
||||
'type' => 'mysql',
|
||||
|
||||
/**
|
||||
* Database hostname. Don't change this if in doubt.
|
||||
*/
|
||||
'host' => getenv('DB_HOST') ?: '127.0.0.1',
|
||||
'host' => getenv('DB_HOST') ?: '127.0.0.1',
|
||||
|
||||
/**
|
||||
* The name of the database for BoxBilling
|
||||
* The name of the database for BoxBilling.
|
||||
*/
|
||||
'name' => getenv('DB_NAME') ?: 'boxbilling',
|
||||
'name' => getenv('DB_NAME') ?: 'boxbilling',
|
||||
|
||||
/**
|
||||
* Database username
|
||||
* Database username.
|
||||
*/
|
||||
'user' => getenv('DB_USER') ?: 'foo',
|
||||
'user' => getenv('DB_USER') ?: 'foo',
|
||||
|
||||
/**
|
||||
* Database password
|
||||
* Database password.
|
||||
*/
|
||||
'password' => getenv('DB_PASS') ?: 'foo',
|
||||
'password' => getenv('DB_PASS') ?: 'foo',
|
||||
|
||||
/**
|
||||
* Database Port
|
||||
* Database Port.
|
||||
*/
|
||||
'port' => getenv('DB_PORT') ?: '3306',
|
||||
),
|
||||
'port' => getenv('DB_PORT') ?: '3306',
|
||||
],
|
||||
|
||||
'twig' => array(
|
||||
'debug' => false,
|
||||
'auto_reload' => false,
|
||||
'cache' => dirname(__FILE__) . '/bb-data/cache',
|
||||
),
|
||||
'twig' => [
|
||||
'debug' => false,
|
||||
'auto_reload' => false,
|
||||
'cache' => dirname(__FILE__).'/bb-data/cache',
|
||||
],
|
||||
|
||||
'api' => array(
|
||||
'api' => [
|
||||
// All requests made to the API must have referrer request header with the same URL as the BoxBilling installation
|
||||
'require_referrer_header' => false,
|
||||
'require_referrer_header' => false,
|
||||
|
||||
// Empty array will allow all IPs to access the API
|
||||
'allowed_ips' => array(),
|
||||
'allowed_ips' => [],
|
||||
|
||||
// Time span for limit in seconds
|
||||
'rate_span' => 60 * 60,
|
||||
'rate_span' => 60 * 60,
|
||||
|
||||
// How many requests allowed per time span
|
||||
'rate_limit' => 1000,
|
||||
'rate_limit' => 1000,
|
||||
|
||||
/**
|
||||
* Note about rate-limiting login attempts:
|
||||
* When the limit is reached, a default delay of 2 seconds is added to the request.
|
||||
* When the limit is reached, a default delay of 2 seconds is added to the request.
|
||||
* This makes brute-forcing a password useless while not outright blocking legitimate traffic.
|
||||
* When calculating, ensure the rate-limited traffic can still make enough requests to stay rate limited
|
||||
* Ex: One request every 2 seconds is more than 20 times in 1 minute, so the IP will remain throttled
|
||||
* Ex: One request every 2 seconds is more than 20 times in 1 minute, so the IP will remain throttled.
|
||||
*
|
||||
* @since 4.22.0
|
||||
*/
|
||||
|
||||
// Throttling delay
|
||||
'throttle_delay' => 2,
|
||||
'throttle_delay' => 2,
|
||||
|
||||
// Time span login for limit in seconds
|
||||
'rate_span_login' => 60,
|
||||
'rate_span_login' => 60,
|
||||
|
||||
// How many login requests allowed per time span
|
||||
'rate_limit_login' => 20,
|
||||
),
|
||||
'rate_limit_login' => 20,
|
||||
],
|
||||
|
||||
'guzzle' => array(
|
||||
'guzzle' => [
|
||||
/**
|
||||
* The user agent to be used when making requests to external services
|
||||
* The user agent to be used when making requests to external services.
|
||||
*
|
||||
* @since 4.22.0
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
|
||||
*/
|
||||
'user_agent' => 'Mozilla/5.0 (RedHatEnterpriseLinux; Linux x86_64; BoxBilling; +http://boxbilling.org) Gecko/20100101 Firefox/93.0',
|
||||
'user_agent' => 'Mozilla/5.0 (RedHatEnterpriseLinux; Linux x86_64; BoxBilling; +http://boxbilling.org) Gecko/20100101 Firefox/93.0',
|
||||
|
||||
/**
|
||||
* Default request timeout
|
||||
* Setting 0 will disable this limitation
|
||||
* Setting 0 will disable this limitation.
|
||||
*
|
||||
* @since 4.22.0
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout
|
||||
*/
|
||||
'timeout' => 0,
|
||||
'timeout' => 0,
|
||||
|
||||
/**
|
||||
* The HTTP Upgrade-Insecure-Requests header sends a signal to the server
|
||||
* expressing the client’s preference for an encrypted response.
|
||||
*
|
||||
*
|
||||
* 0: don't ask for an encrypted response
|
||||
* 1: ask for an encrypted response
|
||||
*
|
||||
*
|
||||
* @since 4.22.0
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests
|
||||
*/
|
||||
'upgrade_insecure_requests' => 0
|
||||
),
|
||||
);
|
||||
'upgrade_insecure_requests' => 0,
|
||||
],
|
||||
];
|
||||
+13
-15
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -9,31 +9,29 @@
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
require_once dirname(__FILE__) . '/bb-load.php';
|
||||
$di = include dirname(__FILE__) . '/bb-di.php';
|
||||
require_once dirname(__FILE__).'/bb-load.php';
|
||||
$di = include dirname(__FILE__).'/bb-di.php';
|
||||
|
||||
$di['translate']();
|
||||
|
||||
try {
|
||||
if (php_sapi_name() == 'cli') {
|
||||
print ("\e[33m- Welcome to BoxBilling.\n");
|
||||
if ('cli' == php_sapi_name()) {
|
||||
echo "\e[33m- Welcome to BoxBilling.\n";
|
||||
}
|
||||
$interval = isset($argv[1]) ? $argv[1] : null;
|
||||
$interval = $argv[1] ?? null;
|
||||
$service = $di['mod_service']('cron');
|
||||
if (php_sapi_name() == 'cli') {
|
||||
print ("\e[34mLast executed: " . $service->getLastExecutionTime() . ".\e[0m");
|
||||
if ('cli' == php_sapi_name()) {
|
||||
echo "\e[34mLast executed: ".$service->getLastExecutionTime().".\e[0m";
|
||||
}
|
||||
$service->runCrons($interval);
|
||||
} catch (Exception $exception) {
|
||||
} catch (Exception $exception) {
|
||||
throw new Exception($exception);
|
||||
} finally {
|
||||
if (php_sapi_name() == 'cli') {
|
||||
print ("\e[32mSuccessfully ran the cron jobs.\e[0m");
|
||||
} finally {
|
||||
if ('cli' == php_sapi_name()) {
|
||||
echo "\e[32mSuccessfully ran the cron jobs.\e[0m";
|
||||
} else {
|
||||
$login_url = $di['url']->link('bb-admin');
|
||||
unset($service, $interval, $di);
|
||||
header("Location: $login_url");
|
||||
}
|
||||
}
|
||||
}
|
||||
+131
-110
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -9,134 +9,140 @@
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
$di = new Box_Di();
|
||||
$di['config'] = function() {
|
||||
$array = include BB_PATH_ROOT . '/bb-config.php';
|
||||
$di['config'] = function () {
|
||||
$array = include BB_PATH_ROOT.'/bb-config.php';
|
||||
|
||||
return new Box_Config($array);
|
||||
};
|
||||
$di['logger'] = function () use ($di) {
|
||||
$log = new Box_Log();
|
||||
$log = new Box_Log();
|
||||
$log->setDi($di);
|
||||
|
||||
$log_to_db = isset($di['config']['log_to_db']) && $di['config']['log_to_db'];
|
||||
if ($log_to_db) {
|
||||
$activity_service = $di['mod_service']('activity');
|
||||
$writer2 = new Box_LogDb($activity_service);
|
||||
if ($di['auth']->isAdminLoggedIn()){
|
||||
$admin = $di['loggedin_admin'];
|
||||
$log->setEventItem('admin_id', $admin->id);
|
||||
}
|
||||
elseif ($di['auth']->isClientLoggedIn()) {
|
||||
$writer2 = new Box_LogDb($activity_service);
|
||||
if ($di['auth']->isAdminLoggedIn()) {
|
||||
$admin = $di['loggedin_admin'];
|
||||
$log->setEventItem('admin_id', $admin->id);
|
||||
} elseif ($di['auth']->isClientLoggedIn()) {
|
||||
$client = $di['loggedin_client'];
|
||||
$log->setEventItem('client_id', $client->id);
|
||||
}
|
||||
$log->addWriter($writer2);
|
||||
} else {
|
||||
$logFile = $di['config']['path_logs'];
|
||||
$writer = new Box_LogStream($logFile);
|
||||
$writer = new Box_LogStream($logFile);
|
||||
$log->addWriter($writer);
|
||||
}
|
||||
|
||||
return $log;
|
||||
};
|
||||
$di['crypt'] = function() use ($di) {
|
||||
$crypt = new Box_Crypt();
|
||||
$di['crypt'] = function () use ($di) {
|
||||
$crypt = new Box_Crypt();
|
||||
$crypt->setDi($di);
|
||||
|
||||
return $crypt;
|
||||
};
|
||||
$di['pdo'] = function() use ($di) {
|
||||
$di['pdo'] = function () use ($di) {
|
||||
$c = $di['config']['db'];
|
||||
|
||||
$pdo = new PDO($c['type'].':host='.$c['host'].';port='.$c['port'].';dbname='.$c['name'],
|
||||
$c['user'],
|
||||
$c['password'],
|
||||
array(
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
)
|
||||
[
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]
|
||||
);
|
||||
|
||||
if(isset($c['debug']) && $c['debug']) {
|
||||
$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array ('Box_DbLoggedPDOStatement'));
|
||||
if (isset($c['debug']) && $c['debug']) {
|
||||
$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['Box_DbLoggedPDOStatement']);
|
||||
}
|
||||
|
||||
if($c['type'] == 'mysql') {
|
||||
$pdo->exec( 'SET NAMES "utf8"' );
|
||||
$pdo->exec( 'SET CHARACTER SET utf8' );
|
||||
$pdo->exec( 'SET CHARACTER_SET_CONNECTION = utf8' );
|
||||
$pdo->exec( 'SET character_set_results = utf8' );
|
||||
$pdo->exec( 'SET character_set_server = utf8' );
|
||||
$pdo->exec( 'SET SESSION interactive_timeout = 28800' );
|
||||
$pdo->exec( 'SET SESSION wait_timeout = 28800' );
|
||||
if ('mysql' == $c['type']) {
|
||||
$pdo->exec('SET NAMES "utf8"');
|
||||
$pdo->exec('SET CHARACTER SET utf8');
|
||||
$pdo->exec('SET CHARACTER_SET_CONNECTION = utf8');
|
||||
$pdo->exec('SET character_set_results = utf8');
|
||||
$pdo->exec('SET character_set_server = utf8');
|
||||
$pdo->exec('SET SESSION interactive_timeout = 28800');
|
||||
$pdo->exec('SET SESSION wait_timeout = 28800');
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
};
|
||||
$di['db'] = function() use ($di) {
|
||||
|
||||
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'rb.php';
|
||||
$di['db'] = function () use ($di) {
|
||||
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'rb.php';
|
||||
R::setup($di['pdo']);
|
||||
\RedBeanPHP\Util\DispenseHelper::setEnforceNamingPolicy( false );
|
||||
\RedBeanPHP\Util\DispenseHelper::setEnforceNamingPolicy(false);
|
||||
|
||||
$helper = new Box_BeanHelper();
|
||||
$helper->setDi($di);
|
||||
|
||||
$mapper = new \RedBeanPHP\Facade();
|
||||
$mapper->getRedBean()->setBeanHelper($helper);
|
||||
$freeze = isset($di['config']['db']['freeze']) ? (bool)$di['config']['db']['freeze'] : true;
|
||||
$freeze = isset($di['config']['db']['freeze']) ? (bool) $di['config']['db']['freeze'] : true;
|
||||
$mapper->freeze($freeze);
|
||||
|
||||
$db = new Box_Database();
|
||||
$db->setDi($di);
|
||||
$db->setDataMapper($mapper);
|
||||
|
||||
return $db;
|
||||
};
|
||||
$di['pager'] = function() use($di) {
|
||||
$di['pager'] = function () use ($di) {
|
||||
$service = new Box_Pagination();
|
||||
$service->setDi($di);
|
||||
|
||||
return $service;
|
||||
};
|
||||
$di['url'] = function() use ($di) {
|
||||
$url = new Box_Url();
|
||||
$di['url'] = function () use ($di) {
|
||||
$url = new Box_Url();
|
||||
$url->setDi($di);
|
||||
$url->setBaseUri(BB_URL);
|
||||
|
||||
return $url;
|
||||
};
|
||||
$di['mod'] = $di->protect(function ($name) use($di) {
|
||||
$di['mod'] = $di->protect(function ($name) use ($di) {
|
||||
$mod = new Box_Mod($name);
|
||||
$mod->setDi($di);
|
||||
|
||||
return $mod;
|
||||
});
|
||||
$di['mod_service'] = $di->protect(function ($mod, $sub = '') use($di) {
|
||||
$di['mod_service'] = $di->protect(function ($mod, $sub = '') use ($di) {
|
||||
return $di['mod']($mod)->getService($sub);
|
||||
});
|
||||
$di['mod_config'] = $di->protect(function ($name) use($di) {
|
||||
$di['mod_config'] = $di->protect(function ($name) use ($di) {
|
||||
return $di['mod']($name)->getConfig();
|
||||
});
|
||||
$di['events_manager'] = function() use ($di) {
|
||||
$di['events_manager'] = function () use ($di) {
|
||||
$service = new Box_EventManager();
|
||||
$service->setDi($di);
|
||||
|
||||
return $service;
|
||||
};
|
||||
$di['session'] = function () use ($di) {
|
||||
$handler = new PdoSessionHandler($di['pdo']);
|
||||
|
||||
return new Box_Session($handler);
|
||||
};
|
||||
$di['cookie'] = function () use ($di) {
|
||||
$service = new Box_Cookie();
|
||||
$service->setDi($di);
|
||||
|
||||
return $service;
|
||||
};
|
||||
$di['request'] = function () use ($di) {
|
||||
$service = new Box_Request();
|
||||
$service->setDi($di);
|
||||
|
||||
return $service;
|
||||
};
|
||||
$di['cache'] = function () use ($di) { return new FileCache();};
|
||||
$di['auth'] = function () use ($di) { return new Box_Authorization($di);};
|
||||
$di['cache'] = function () { return new FileCache(); };
|
||||
$di['auth'] = function () use ($di) { return new Box_Authorization($di); };
|
||||
$di['twig'] = $di->factory(function () use ($di) {
|
||||
$config = $di['config'];
|
||||
$options = $config['twig'];
|
||||
@@ -147,18 +153,17 @@ $di['twig'] = $di->factory(function () use ($di) {
|
||||
$box_extensions = new Box_TwigExtensions();
|
||||
$box_extensions->setDi($di);
|
||||
|
||||
//$twig->addExtension(new Twig\Extension\OptimizerExtension());
|
||||
$twig->addExtension(new \Twig\Extension\StringLoaderExtension());
|
||||
$twig->addExtension(new Twig\Extension\DebugExtension());
|
||||
$twig->addExtension(new Twig\Extensions\I18nExtension());
|
||||
// $twig->addExtension(new Twig\Extension\OptimizerExtension());
|
||||
$twig->addExtension(new \Twig\Extension\StringLoaderExtension());
|
||||
$twig->addExtension(new Twig\Extension\DebugExtension());
|
||||
$twig->addExtension(new Twig\Extensions\I18nExtension());
|
||||
$twig->addExtension($box_extensions);
|
||||
$twig->getExtension(Twig\Extension\CoreExtension::class)->setDateFormat($config['locale_date_format']);
|
||||
$twig->getExtension(Twig\Extension\CoreExtension::class)->setTimezone($config['timezone']);
|
||||
|
||||
$twig->getExtension(Twig\Extension\CoreExtension::class)->setDateFormat($config['locale_date_format']);
|
||||
$twig->getExtension(Twig\Extension\CoreExtension::class)->setTimezone($config['timezone']);
|
||||
|
||||
// add globals
|
||||
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
|
||||
$_GET['ajax'] = TRUE;
|
||||
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
|
||||
$_GET['ajax'] = true;
|
||||
}
|
||||
|
||||
$twig->addGlobal('request', $_GET);
|
||||
@@ -167,58 +172,58 @@ $di['twig'] = $di->factory(function () use ($di) {
|
||||
return $twig;
|
||||
});
|
||||
|
||||
$di['is_client_logged'] = function() use($di) {
|
||||
if(!$di['auth']->isClientLoggedIn()) {
|
||||
$di['is_client_logged'] = function () use ($di) {
|
||||
if (!$di['auth']->isClientLoggedIn()) {
|
||||
$api_str = '/api/';
|
||||
$url = $di['request']->getQuery('_url');
|
||||
if (strncasecmp($url, $api_str , strlen($api_str)) === 0) {
|
||||
//Throw Exception if api request
|
||||
if (0 === strncasecmp($url, $api_str, strlen($api_str))) {
|
||||
// Throw Exception if api request
|
||||
throw new Exception('Client is not logged in');
|
||||
}
|
||||
else {
|
||||
//Redirect to login page if browser request
|
||||
} else {
|
||||
// Redirect to login page if browser request
|
||||
$login_url = $di['url']->link('login');
|
||||
header("Location: $login_url");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$di['is_admin_logged'] = function() use($di) {
|
||||
|
||||
if(!$di['auth']->isAdminLoggedIn()) {
|
||||
$api_str = '/api/';
|
||||
$url = $di['request']->getQuery('_url');
|
||||
if (strncasecmp($url, $api_str , strlen($api_str)) === 0) {
|
||||
//Throw Exception if api request
|
||||
throw new Exception('Admin is not logged in');
|
||||
}
|
||||
else {
|
||||
//Redirect to login page if browser request
|
||||
$login_url = $di['url']->adminLink('staff/login');
|
||||
header("Location: $login_url");
|
||||
$di['is_admin_logged'] = function () use ($di) {
|
||||
if (!$di['auth']->isAdminLoggedIn()) {
|
||||
$api_str = '/api/';
|
||||
$url = $di['request']->getQuery('_url');
|
||||
if (0 === strncasecmp($url, $api_str, strlen($api_str))) {
|
||||
// Throw Exception if api request
|
||||
throw new Exception('Admin is not logged in');
|
||||
} else {
|
||||
// Redirect to login page if browser request
|
||||
$login_url = $di['url']->adminLink('staff/login');
|
||||
header("Location: $login_url");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$di['loggedin_client'] = function() use ($di) {
|
||||
$di['loggedin_client'] = function () use ($di) {
|
||||
$di['is_client_logged'];
|
||||
$client_id = $di['session']->get('client_id');
|
||||
|
||||
return $di['db']->getExistingModelById('Client', $client_id);
|
||||
};
|
||||
$di['loggedin_admin'] = function() use ($di) {
|
||||
if(php_sapi_name() == 'cli' || substr(php_sapi_name(), 0, 3) == 'cgi') {
|
||||
$di['loggedin_admin'] = function () use ($di) {
|
||||
if ('cli' == php_sapi_name() || 'cgi' == substr(php_sapi_name(), 0, 3)) {
|
||||
return $di['mod_service']('staff')->getCronAdmin();
|
||||
}
|
||||
|
||||
$di['is_admin_logged'];
|
||||
$admin = $di['session']->get('admin');
|
||||
|
||||
return $di['db']->getExistingModelById('Admin', $admin['id']);
|
||||
};
|
||||
|
||||
$di['api'] = $di->protect(function($role) use($di) {
|
||||
$di['api'] = $di->protect(function ($role) use ($di) {
|
||||
switch ($role) {
|
||||
case 'guest':
|
||||
$identity = new \Model_Guest();
|
||||
@@ -241,31 +246,34 @@ $di['api'] = $di->protect(function($role) use($di) {
|
||||
}
|
||||
$api = new Api_Handler($identity);
|
||||
$api->setDi($di);
|
||||
|
||||
return $api;
|
||||
});
|
||||
$di['api_guest'] = function() use ($di) { return $di['api']('guest'); };
|
||||
$di['api_client'] = function() use ($di) { return $di['api']('client');};
|
||||
$di['api_admin'] = function() use ($di) { return $di['api']('admin'); };
|
||||
$di['api_system'] = function() use ($di) { return $di['api']('system'); };
|
||||
$di['api_guest'] = function () use ($di) { return $di['api']('guest'); };
|
||||
$di['api_client'] = function () use ($di) { return $di['api']('client'); };
|
||||
$di['api_admin'] = function () use ($di) { return $di['api']('admin'); };
|
||||
$di['api_system'] = function () use ($di) { return $di['api']('system'); };
|
||||
|
||||
$di['tools'] = function () use ($di){
|
||||
$di['tools'] = function () use ($di) {
|
||||
$service = new Box_Tools();
|
||||
$service->setDi($di);
|
||||
|
||||
return $service;
|
||||
};
|
||||
|
||||
$di['validator'] = function () use ($di){
|
||||
$di['validator'] = function () use ($di) {
|
||||
$validator = new Box_Validate();
|
||||
$validator->setDi($di);
|
||||
|
||||
return $validator;
|
||||
};
|
||||
$di['guzzle_client'] = function () use($di) {
|
||||
$di['guzzle_client'] = function () use ($di) {
|
||||
return new GuzzleHttp\Client([
|
||||
'headers' => [
|
||||
'User-Agent' => $di['config']['guzzle']['user_agent'],
|
||||
'Upgrade-Insecure-Requests' => $di['config']['guzzle']['upgrade_insecure_requests']
|
||||
'Upgrade-Insecure-Requests' => $di['config']['guzzle']['upgrade_insecure_requests'],
|
||||
],
|
||||
'timeout' => $di['config']['guzzle']['timeout']
|
||||
'timeout' => $di['config']['guzzle']['timeout'],
|
||||
]);
|
||||
};
|
||||
$di['mail'] = function () {
|
||||
@@ -274,97 +282,110 @@ $di['mail'] = function () {
|
||||
$di['extension'] = function () use ($di) {
|
||||
$extension = new \Box_Extension();
|
||||
$extension->setDi($di);
|
||||
|
||||
return $extension;
|
||||
};
|
||||
$di['updater'] = function () use ($di) {
|
||||
$updater = new \Box_Update();
|
||||
$updater->setDi($di);
|
||||
|
||||
return $updater;
|
||||
};
|
||||
$di['curl'] = function ($url) use ($di) {
|
||||
$curl = new \Box_Curl($url);
|
||||
$curl->setDi($di);
|
||||
|
||||
return $curl;
|
||||
|
||||
};
|
||||
$di['zip_archive'] = function () use ($di) {return new ZipArchive();};
|
||||
$di['zip_archive'] = function () {return new ZipArchive(); };
|
||||
|
||||
$di['server_package'] = function () use ($di) {return new Server_Package();};
|
||||
$di['server_client'] = function () use ($di) {return new Server_Client();};
|
||||
$di['server_account'] = function () use ($di) {return new Server_Account();};
|
||||
$di['server_package'] = function () {return new Server_Package(); };
|
||||
$di['server_client'] = function () {return new Server_Client(); };
|
||||
$di['server_account'] = function () {return new Server_Account(); };
|
||||
|
||||
$di['server_manager'] = $di->protect(function ($manager, $config) use($di) {
|
||||
$di['server_manager'] = $di->protect(function ($manager, $config) {
|
||||
$class = sprintf('Server_Manager_%s', ucfirst($manager));
|
||||
|
||||
return new $class($config);
|
||||
});
|
||||
|
||||
$di['requirements'] = function () use ($di) {
|
||||
$r = new Box_Requirements();
|
||||
$r->setDi($di);
|
||||
|
||||
return $r;
|
||||
};
|
||||
|
||||
$di['period'] = $di->protect(function($code) use($di){ return new \Box_Period($code); });
|
||||
$di['period'] = $di->protect(function ($code) { return new \Box_Period($code); });
|
||||
|
||||
$di['theme'] = function() use($di) {
|
||||
$di['theme'] = function () use ($di) {
|
||||
$service = $di['mod_service']('theme');
|
||||
|
||||
return $service->getCurrentClientAreaTheme();
|
||||
};
|
||||
$di['cart'] = function() use($di) {
|
||||
$di['cart'] = function () use ($di) {
|
||||
$service = $di['mod_service']('cart');
|
||||
|
||||
return $service->getSessionCart();
|
||||
};
|
||||
|
||||
$di['table'] = $di->protect(function ($name) use($di) {
|
||||
$di['table'] = $di->protect(function ($name) use ($di) {
|
||||
$tools = new Box_Tools();
|
||||
$tools->setDi($di);
|
||||
$table = $tools->getTable($name);
|
||||
$table = $tools->getTable($name);
|
||||
$table->setDi($di);
|
||||
|
||||
return $table;
|
||||
});
|
||||
|
||||
$di['license_server'] = function () use ($di) {
|
||||
$server = new \Box\Mod\Servicelicense\Server($di['logger']);
|
||||
$server->setDi($di);
|
||||
|
||||
return $server;
|
||||
};
|
||||
|
||||
$di['solusvm'] = $di->protect(function ($config) use($di) {
|
||||
$di['solusvm'] = $di->protect(function ($config) use ($di) {
|
||||
$solusVM = new \Box\Mod\Servicesolusvm\SolusVM();
|
||||
$solusVM->setDi($di);
|
||||
$solusVM->setConfig($config);
|
||||
|
||||
return $solusVM;
|
||||
});
|
||||
|
||||
$di['service_boxbilling'] = $di->protect(function ($config) use($di) {
|
||||
$di['service_boxbilling'] = $di->protect(function ($config) {
|
||||
$service = new \Box\Mod\Serviceboxbillinglicense\ServiceBoxbilling($config);
|
||||
|
||||
return $service;
|
||||
});
|
||||
|
||||
$di['ftp'] = $di->protect(function($params) use($di){ return new \Box_Ftp($params); });
|
||||
$di['ftp'] = $di->protect(function ($params) { return new \Box_Ftp($params); });
|
||||
|
||||
$di['pdf'] = function () use ($di) {
|
||||
include BB_PATH_LIBRARY . '/PDF_ImageAlpha.php';
|
||||
include BB_PATH_LIBRARY.'/PDF_ImageAlpha.php';
|
||||
|
||||
return new \PDF_ImageAlpha();
|
||||
};
|
||||
|
||||
$di['geoip'] = function () use ($di) { return new \GeoIp2\Database\Reader(BB_PATH_LIBRARY . '/GeoLite2-Country.mmdb'); };
|
||||
$di['geoip'] = function () { return new \GeoIp2\Database\Reader(BB_PATH_LIBRARY.'/GeoLite2-Country.mmdb'); };
|
||||
|
||||
$di['password'] = function() use ($di) { return new Box_Password();};
|
||||
$di['translate'] = $di->protect(function($textDomain = '') use ($di) {
|
||||
$di['password'] = function () { return new Box_Password(); };
|
||||
$di['translate'] = $di->protect(function ($textDomain = '') use ($di) {
|
||||
$tr = new Box_Translate();
|
||||
if (!empty($textDomain)){
|
||||
if (!empty($textDomain)) {
|
||||
$tr->setDomain($textDomain);
|
||||
}
|
||||
$cookieBBlang = $di['cookie']->get('BBLANG');
|
||||
$locale = !empty($cookieBBlang) ? $cookieBBlang : $di['config']['locale'];
|
||||
$locale = !empty($cookieBBlang) ? $cookieBBlang : $di['config']['locale'];
|
||||
|
||||
$tr->setDi($di);
|
||||
$tr->setLocale($locale);
|
||||
$tr->setup();
|
||||
|
||||
return $tr;
|
||||
});
|
||||
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use ($di) {
|
||||
return array_key_exists($key, $array) ? $array[$key] : $default;
|
||||
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) {
|
||||
return array_key_exists($key, $array) ? $array[$key] : $default;
|
||||
});
|
||||
|
||||
return $di;
|
||||
+22
-23
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -9,48 +9,47 @@
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/bb-load.php';
|
||||
$di = include dirname(__FILE__) . '/bb-di.php';
|
||||
require_once dirname(__FILE__).'/bb-load.php';
|
||||
$di = include dirname(__FILE__).'/bb-di.php';
|
||||
$di['translate']();
|
||||
|
||||
$bb_invoice_id = null;
|
||||
if(isset($_GET['bb_invoice_id'])) {
|
||||
if (isset($_GET['bb_invoice_id'])) {
|
||||
$bb_invoice_id = $_GET['bb_invoice_id'];
|
||||
}
|
||||
if(isset($_POST['bb_invoice_id'])) {
|
||||
if (isset($_POST['bb_invoice_id'])) {
|
||||
$bb_invoice_id = $_POST['bb_invoice_id'];
|
||||
}
|
||||
|
||||
$bb_gateway_id = null;
|
||||
if(isset($_GET['bb_gateway_id'])) {
|
||||
if (isset($_GET['bb_gateway_id'])) {
|
||||
$bb_gateway_id = $_GET['bb_gateway_id'];
|
||||
}
|
||||
if(isset($_POST['bb_gateway_id'])) {
|
||||
if (isset($_POST['bb_gateway_id'])) {
|
||||
$bb_gateway_id = $_POST['bb_gateway_id'];
|
||||
}
|
||||
|
||||
$ipn = array(
|
||||
'skip_validation' => true,
|
||||
'bb_invoice_id' => $bb_invoice_id,
|
||||
'bb_gateway_id' => $bb_gateway_id,
|
||||
'get' => $_GET,
|
||||
'post' => $_POST,
|
||||
'server' => $_SERVER,
|
||||
'http_raw_post_data' => file_get_contents("php://input"),
|
||||
);
|
||||
$ipn = [
|
||||
'skip_validation' => true,
|
||||
'bb_invoice_id' => $bb_invoice_id,
|
||||
'bb_gateway_id' => $bb_gateway_id,
|
||||
'get' => $_GET,
|
||||
'post' => $_POST,
|
||||
'server' => $_SERVER,
|
||||
'http_raw_post_data' => file_get_contents('php://input'),
|
||||
];
|
||||
|
||||
try {
|
||||
$service = $di['mod_service']('invoice', 'transaction');
|
||||
$output = $service->createAndProcess($ipn);
|
||||
$res = array('result'=>$output, 'error'=>null);
|
||||
} catch(Exception $e) {
|
||||
$res = array('result'=>null, 'error'=> array('message' => $e->getMessage()));
|
||||
$res = ['result' => $output, 'error' => null];
|
||||
} catch (Exception $e) {
|
||||
$res = ['result' => null, 'error' => ['message' => $e->getMessage()]];
|
||||
$output = false;
|
||||
}
|
||||
|
||||
// redirect to invoice if gateways requires
|
||||
if(isset($_GET['bb_redirect']) && isset($_GET['bb_invoice_hash'])) {
|
||||
if (isset($_GET['bb_redirect']) && isset($_GET['bb_invoice_hash'])) {
|
||||
$url = $di['url']->link('invoice/'.$_GET['bb_invoice_hash']);
|
||||
header("Location: $url");
|
||||
exit;
|
||||
@@ -58,6 +57,6 @@ if(isset($_GET['bb_redirect']) && isset($_GET['bb_invoice_hash'])) {
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Content-type: application/json; charset=utf-8');
|
||||
print json_encode($res);
|
||||
echo json_encode($res);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
+94
-93
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -9,70 +9,72 @@
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
define('BB_PATH_ROOT', dirname(__FILE__));
|
||||
define('BB_PATH_VENDOR', BB_PATH_ROOT . '/bb-vendor');
|
||||
define('BB_PATH_LIBRARY', BB_PATH_ROOT . '/bb-library');
|
||||
define('BB_PATH_THEMES', BB_PATH_ROOT . '/bb-themes');
|
||||
define('BB_PATH_MODS', BB_PATH_ROOT . '/bb-modules');
|
||||
define('BB_PATH_LANGS', BB_PATH_ROOT . '/bb-locale');
|
||||
define('BB_PATH_UPLOADS', BB_PATH_ROOT . '/bb-uploads');
|
||||
define('BB_PATH_DATA', BB_PATH_ROOT . '/bb-data');
|
||||
define('isCLI', php_sapi_name() == 'cli');
|
||||
define('BB_PATH_ROOT', dirname(__FILE__));
|
||||
define('BB_PATH_VENDOR', BB_PATH_ROOT.'/bb-vendor');
|
||||
define('BB_PATH_LIBRARY', BB_PATH_ROOT.'/bb-library');
|
||||
define('BB_PATH_THEMES', BB_PATH_ROOT.'/bb-themes');
|
||||
define('BB_PATH_MODS', BB_PATH_ROOT.'/bb-modules');
|
||||
define('BB_PATH_LANGS', BB_PATH_ROOT.'/bb-locale');
|
||||
define('BB_PATH_UPLOADS', BB_PATH_ROOT.'/bb-uploads');
|
||||
define('BB_PATH_DATA', BB_PATH_ROOT.'/bb-data');
|
||||
define('isCLI', 'cli' == php_sapi_name());
|
||||
|
||||
function handler_error(int $number, string $message, string $file, int $line)
|
||||
{
|
||||
if (E_RECOVERABLE_ERROR===$number) {
|
||||
if (isCLI) {
|
||||
echo "Error #[$number] occurred in [$file] at line [$line]: [$message]";
|
||||
} else {
|
||||
handler_exception(new ErrorException($message, $number, 0, $file, $line));
|
||||
}
|
||||
if (E_RECOVERABLE_ERROR === $number) {
|
||||
if (isCLI) {
|
||||
echo "Error #[$number] occurred in [$file] at line [$line]: [$message]";
|
||||
} else {
|
||||
handler_exception(new ErrorException($message, $number, 0, $file, $line));
|
||||
}
|
||||
} else {
|
||||
error_log($number." ".$message." ".$file." ".$line);
|
||||
error_log($number.' '.$message.' '.$file.' '.$line);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Removed Exception type. Some errors are thrown as exceptions causing fatal errors.
|
||||
function handler_exception($e)
|
||||
{
|
||||
if (isCLI) {
|
||||
echo "Error #[". $e->getCode() ."] occurred in [". $e->getFile() ."] at line [". $e->getLine() ."]: [". trim(strip_tags($e->getMessage())) ."]";
|
||||
} else {
|
||||
if(APPLICATION_ENV == 'testing') {
|
||||
print $e->getMessage() . PHP_EOL;
|
||||
return ;
|
||||
}
|
||||
error_log($e->getMessage());
|
||||
|
||||
if(defined('BB_MODE_API')) {
|
||||
$code = $e->getCode() ? $e->getCode() : 9998;
|
||||
$result = array('result'=>NULL, 'error'=>array('message'=>$e->getMessage(), 'code'=>$code));
|
||||
print json_encode($result);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(defined('BB_DEBUG') && BB_DEBUG && file_exists(BB_PATH_VENDOR)) {
|
||||
/**
|
||||
* If advanced debugging is enabled, print Whoops instead of our error page.
|
||||
* flip/whoops documentation: https://github.com/filp/whoops/blob/master/docs/API%20Documentation.md
|
||||
*/
|
||||
$whoops = new \Whoops\Run;
|
||||
$prettyPage = new \Whoops\Handler\PrettyPageHandler;
|
||||
$prettyPage->setPageTitle("An error ocurred");
|
||||
$prettyPage->addDataTable('BoxBilling environment', [
|
||||
'PHP Version' => phpversion(),
|
||||
'Error code' => $e->getCode()
|
||||
]);
|
||||
$whoops->pushHandler($prettyPage);
|
||||
$whoops->allowQuit(false);
|
||||
$whoops->writeToOutput(false);
|
||||
|
||||
print($whoops->handleException($e));
|
||||
if (isCLI) {
|
||||
echo 'Error #['.$e->getCode().'] occurred in ['.$e->getFile().'] at line ['.$e->getLine().']: ['.trim(strip_tags($e->getMessage())).']';
|
||||
} else {
|
||||
$page = "<!DOCTYPE html>
|
||||
if (APPLICATION_ENV == 'testing') {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
|
||||
return;
|
||||
}
|
||||
error_log($e->getMessage());
|
||||
|
||||
if (defined('BB_MODE_API')) {
|
||||
$code = $e->getCode() ? $e->getCode() : 9998;
|
||||
$result = ['result' => null, 'error' => ['message' => $e->getMessage(), 'code' => $code]];
|
||||
echo json_encode($result);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (defined('BB_DEBUG') && BB_DEBUG && file_exists(BB_PATH_VENDOR)) {
|
||||
/**
|
||||
* If advanced debugging is enabled, print Whoops instead of our error page.
|
||||
* flip/whoops documentation: https://github.com/filp/whoops/blob/master/docs/API%20Documentation.md.
|
||||
*/
|
||||
$whoops = new \Whoops\Run();
|
||||
$prettyPage = new \Whoops\Handler\PrettyPageHandler();
|
||||
$prettyPage->setPageTitle('An error ocurred');
|
||||
$prettyPage->addDataTable('BoxBilling environment', [
|
||||
'PHP Version' => phpversion(),
|
||||
'Error code' => $e->getCode(),
|
||||
]);
|
||||
$whoops->pushHandler($prettyPage);
|
||||
$whoops->allowQuit(false);
|
||||
$whoops->writeToOutput(false);
|
||||
|
||||
echo $whoops->handleException($e);
|
||||
} else {
|
||||
$page = "<!DOCTYPE html>
|
||||
<html lang=\"en\">
|
||||
|
||||
<head>
|
||||
@@ -205,57 +207,56 @@ function handler_exception($e)
|
||||
<div class=\"error-container\"></div>
|
||||
<h1>Error</h1>";
|
||||
|
||||
$page = str_replace(PHP_EOL, "", $page);
|
||||
print $page;
|
||||
if($e->getCode()) {
|
||||
print sprintf('<h2>Error code: <em>%s</em></h1>', $e->getCode());
|
||||
}
|
||||
print sprintf('<p>%s</p>', $e->getMessage());
|
||||
|
||||
print sprintf('<center><p><a href="http://docs.boxbilling.com/en/latest/search.html?q=%s&check_keywords=yes&area=default" target="_blank">Look for detailed error explanation</a></p></center>', urlencode($e->getMessage()));
|
||||
print('<center><hr><p>Powered by <a href="https://github.com/boxbilling/boxbilling/">BoxBilling</a></p></center>
|
||||
$page = str_replace(PHP_EOL, '', $page);
|
||||
echo $page;
|
||||
if ($e->getCode()) {
|
||||
echo sprintf('<h2>Error code: <em>%s</em></h1>', $e->getCode());
|
||||
}
|
||||
echo sprintf('<p>%s</p>', $e->getMessage());
|
||||
|
||||
echo sprintf('<center><p><a href="http://docs.boxbilling.com/en/latest/search.html?q=%s&check_keywords=yes&area=default" target="_blank">Look for detailed error explanation</a></p></center>', urlencode($e->getMessage()));
|
||||
echo '<center><hr><p>Powered by <a href="https://github.com/boxbilling/boxbilling/">BoxBilling</a></p></center>
|
||||
</body>
|
||||
|
||||
</html>');
|
||||
</html>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_exception_handler("handler_exception");
|
||||
set_exception_handler('handler_exception');
|
||||
set_error_handler('handler_error');
|
||||
|
||||
// Check for Composer packages
|
||||
if(!file_exists(BB_PATH_VENDOR)) {
|
||||
throw new Exception("It seems like Composer packages are missing. You have to run \"<code>composer install</code>\" in order to install them. For detailed instruction, you can see <a href=\"https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies\">Composer's getting started guide</a>.<br /><br />If you have downloaded BoxBilling from <a href=\"https://github.com/boxbilling/boxbilling/releases\">GitHub releases</a>, this shouldn't happen.", 110);
|
||||
if (!file_exists(BB_PATH_VENDOR)) {
|
||||
throw new Exception("It seems like Composer packages are missing. You have to run \"<code>composer install</code>\" in order to install them. For detailed instruction, you can see <a href=\"https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies\">Composer's getting started guide</a>.<br /><br />If you have downloaded BoxBilling from <a href=\"https://github.com/boxbilling/boxbilling/releases\">GitHub releases</a>, this shouldn't happen.", 110);
|
||||
}
|
||||
|
||||
// Multisite support. Load new configuration depending on the current hostname
|
||||
// If being run from CLI, first parameter must be the hostname
|
||||
$configPath = BB_PATH_ROOT.'/bb-config.php';
|
||||
if((isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) || (php_sapi_name() == 'cli' && isset($argv[1]) ) ) {
|
||||
if(php_sapi_name() == 'cli') {
|
||||
if ((isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) || ('cli' == php_sapi_name() && isset($argv[1]))) {
|
||||
if ('cli' == php_sapi_name()) {
|
||||
$host = $argv[1];
|
||||
} else {
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
|
||||
|
||||
$predictConfigPath = BB_PATH_ROOT.'/bb-config-'.$host.'.php';
|
||||
if(file_exists($predictConfigPath)) {
|
||||
if (file_exists($predictConfigPath)) {
|
||||
$configPath = $predictConfigPath;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to check if configuration is available
|
||||
if(!file_exists($configPath) || 0 == filesize($configPath)) {
|
||||
|
||||
if (!file_exists($configPath) || 0 == filesize($configPath)) {
|
||||
// Try to create an empty configuration file
|
||||
@file_put_contents($configPath, '');
|
||||
|
||||
$base_url = "http".(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ? 's' : '')."://".$_SERVER['HTTP_HOST'];
|
||||
$base_url .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME']));
|
||||
$url = $base_url . '/install/index.php';
|
||||
|
||||
if(file_exists(BB_PATH_ROOT.'/install/index.php')){
|
||||
$base_url = 'http'.(isset($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'] || 1 == $_SERVER['HTTPS']) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ? 's' : '').'://'.$_SERVER['HTTP_HOST'];
|
||||
$base_url .= preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME']));
|
||||
$url = $base_url.'/install/index.php';
|
||||
|
||||
if (file_exists(BB_PATH_ROOT.'/install/index.php')) {
|
||||
header("Location: $url");
|
||||
}
|
||||
|
||||
@@ -265,34 +266,34 @@ if(!file_exists($configPath) || 0 == filesize($configPath)) {
|
||||
}
|
||||
|
||||
// Try to check if /install directory still exists, even after the installation was completed
|
||||
if(file_exists($configPath) && 0 !== filesize($configPath) && file_exists(BB_PATH_ROOT.'/install/index.php')) {
|
||||
throw new Exception("For safety reasons, you have to delete the <b><em>/install</em></b> directory to start using BoxBilling.</p><p>Please delete the <b><em>/install</em></b> directory from your web server.", 102);
|
||||
if (file_exists($configPath) && 0 !== filesize($configPath) && file_exists(BB_PATH_ROOT.'/install/index.php')) {
|
||||
throw new Exception('For safety reasons, you have to delete the <b><em>/install</em></b> directory to start using BoxBilling.</p><p>Please delete the <b><em>/install</em></b> directory from your web server.', 102);
|
||||
}
|
||||
|
||||
$config = require_once $configPath;
|
||||
require BB_PATH_VENDOR . '/autoload.php';
|
||||
require BB_PATH_VENDOR.'/autoload.php';
|
||||
|
||||
date_default_timezone_set($config['timezone']);
|
||||
|
||||
define('BB_DEBUG', $config['debug']);
|
||||
define('BB_URL', $config['url']);
|
||||
define('BB_SEF_URLS', $config['sef_urls']);
|
||||
define('BB_PATH_CACHE', $config['path_data'] . '/cache');
|
||||
define('BB_PATH_LOG', $config['path_data'] . '/log');
|
||||
define('BB_SSL', (substr($config['url'], 0, 5) === 'https'));
|
||||
define('BB_DEBUG', $config['debug']);
|
||||
define('BB_URL', $config['url']);
|
||||
define('BB_SEF_URLS', $config['sef_urls']);
|
||||
define('BB_PATH_CACHE', $config['path_data'].'/cache');
|
||||
define('BB_PATH_LOG', $config['path_data'].'/log');
|
||||
define('BB_SSL', ('https' === substr($config['url'], 0, 5)));
|
||||
|
||||
if($config['sef_urls']) {
|
||||
define('BB_URL_API', $config['url'] . 'api/');
|
||||
if ($config['sef_urls']) {
|
||||
define('BB_URL_API', $config['url'].'api/');
|
||||
} else {
|
||||
define('BB_URL_API', $config['url'] . 'index.php?_url=/api/');
|
||||
define('BB_URL_API', $config['url'].'index.php?_url=/api/');
|
||||
}
|
||||
|
||||
include_once BB_PATH_LIBRARY .'/Security/CSRF-Protector-PHP/libs/csrf/csrfprotector.php';
|
||||
include_once BB_PATH_LIBRARY.'/Security/CSRF-Protector-PHP/libs/csrf/csrfprotector.php';
|
||||
|
||||
// Initialize CSRFProtector library
|
||||
csrfProtector::init();
|
||||
|
||||
if($config['debug']) {
|
||||
if ($config['debug']) {
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
@@ -303,5 +304,5 @@ if($config['debug']) {
|
||||
}
|
||||
|
||||
ini_set('log_errors', '1');
|
||||
ini_set('html_errors', FALSE);
|
||||
ini_set('error_log', BB_PATH_LOG . '/php_error.log');
|
||||
ini_set('html_errors', false);
|
||||
ini_set('error_log', BB_PATH_LOG.'/php_error.log');
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* System activity messages management
|
||||
* System activity messages management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Activity\Api;
|
||||
@@ -19,24 +19,24 @@ namespace Box\Mod\Activity\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of activity messages
|
||||
* Get list of activity messages.
|
||||
*/
|
||||
public function log_get_list($data)
|
||||
{
|
||||
$data['no_debug'] = true;
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
if (isset($item['staff_id'])) {
|
||||
$pager['list'][$key]['staff']['id'] = $item['staff_id'];
|
||||
$pager['list'][$key]['staff']['name'] = $item['staff_name'];
|
||||
$pager['list'][$key]['staff']['id'] = $item['staff_id'];
|
||||
$pager['list'][$key]['staff']['name'] = $item['staff_name'];
|
||||
$pager['list'][$key]['staff']['email'] = $item['staff_email'];
|
||||
}
|
||||
if (isset($item['client_id'])) {
|
||||
$pager['list'][$key]['client']['id'] = $item['client_id'];
|
||||
$pager['list'][$key]['client']['name'] = $item['client_name'];
|
||||
$pager['list'][$key]['client']['id'] = $item['client_id'];
|
||||
$pager['list'][$key]['client']['name'] = $item['client_name'];
|
||||
$pager['list'][$key]['client']['email'] = $item['client_email'];
|
||||
}
|
||||
}
|
||||
@@ -45,38 +45,38 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Add message to log
|
||||
* Add message to log.
|
||||
*
|
||||
* @param string $m - Message text
|
||||
* @optional int $admin_id - admin id
|
||||
* @optional int $client_id - client id
|
||||
* @optional string $priority - log priority
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function log($data)
|
||||
{
|
||||
if(!isset($data['m'])) {
|
||||
if (!isset($data['m'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$priority = $this->di['array_get']($data, 'priority', 6);
|
||||
|
||||
$entry = $this->di['db']->dispense('ActivitySystem');
|
||||
$entry->client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$entry->admin_id = $this->di['array_get']($data, 'admin_id', NULL);
|
||||
$entry->priority = $priority;
|
||||
$entry->message = $data['m'];
|
||||
$entry->created_at = date('Y-m-d H:i:s');
|
||||
$entry->updated_at = date('Y-m-d H:i:s');
|
||||
$entry->ip = $this->di['request']->getClientAddress();
|
||||
$entry->client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
$entry->admin_id = $this->di['array_get']($data, 'admin_id', null);
|
||||
$entry->priority = $priority;
|
||||
$entry->message = $data['m'];
|
||||
$entry->created_at = date('Y-m-d H:i:s');
|
||||
$entry->updated_at = date('Y-m-d H:i:s');
|
||||
$entry->ip = $this->di['request']->getClientAddress();
|
||||
$this->di['db']->store($entry);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add email to log
|
||||
* Add email to log.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -84,39 +84,41 @@ class Admin extends \Api_Abstract
|
||||
{
|
||||
if (!isset($data['subject'])) {
|
||||
error_log('Email was not logged. Subject not passed');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$sender = $this->di['array_get']($data, 'sender', NULL);
|
||||
$recipients = $this->di['array_get']($data, 'recipients', NULL);
|
||||
$subject = $data['subject'];
|
||||
$content_html = $this->di['array_get']($data, 'content_html', NULL);
|
||||
$content_text = $this->di['array_get']($data, 'content_text', NULL);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
$sender = $this->di['array_get']($data, 'sender', null);
|
||||
$recipients = $this->di['array_get']($data, 'recipients', null);
|
||||
$subject = $data['subject'];
|
||||
$content_html = $this->di['array_get']($data, 'content_html', null);
|
||||
$content_text = $this->di['array_get']($data, 'content_text', null);
|
||||
|
||||
return $this->getService()->logEmail($subject, $client_id, $sender, $recipients, $content_html, $content_text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove activity message
|
||||
* Remove activity message.
|
||||
*
|
||||
* @param int $id - Message ID
|
||||
*/
|
||||
public function log_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('ActivitySystem', $data['id'], 'Event not found');
|
||||
|
||||
$this->di['db']->trash($model);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes logs with given IDs
|
||||
* Deletes logs with given IDs.
|
||||
*
|
||||
* @param array $ids - IDs for deletion
|
||||
*
|
||||
@@ -124,13 +126,13 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function batch_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ids' => 'IDs not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
foreach ($data['ids'] as $id) {
|
||||
$this->log_delete(array('id' => $id));
|
||||
$this->log_delete(['id' => $id]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Activity\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,34 +34,35 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'group'=> array(
|
||||
'index' => 700,
|
||||
'location' => 'activity',
|
||||
return [
|
||||
'group' => [
|
||||
'index' => 700,
|
||||
'location' => 'activity',
|
||||
'label' => 'Activity',
|
||||
'class' => 'graphs',
|
||||
'class' => 'graphs',
|
||||
'sprite_class' => 'dark-sprite-icon sprite-graph',
|
||||
),
|
||||
'subpages'=> array(
|
||||
array(
|
||||
'location' => 'activity',
|
||||
],
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'activity',
|
||||
'label' => 'Events history',
|
||||
'index' => 100,
|
||||
'index' => 100,
|
||||
'uri' => $this->di['url']->adminLink('activity'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/activity', 'get_index', array(), get_class($this));
|
||||
$app->get('/activity', 'get_index', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_activity_index');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,9 +10,10 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Activity;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class Service implements InjectionAwareInterface
|
||||
{
|
||||
protected $di = null;
|
||||
@@ -30,118 +31,117 @@ class Service implements InjectionAwareInterface
|
||||
public function logEvent($data)
|
||||
{
|
||||
$entry = $this->di['db']->dispense('ActivitySystem');
|
||||
$entry->client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$entry->admin_id = $this->di['array_get']($data, 'admin_id', NULL);
|
||||
$entry->priority = $this->di['array_get']($data, 'priority', NULL);
|
||||
$entry->message = $data['message'];
|
||||
$entry->created_at = date('Y-m-d H:i:s');
|
||||
$entry->updated_at = date('Y-m-d H:i:s');
|
||||
$entry->ip = $this->di['request']->getClientAddress();
|
||||
$entry->client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
$entry->admin_id = $this->di['array_get']($data, 'admin_id', null);
|
||||
$entry->priority = $this->di['array_get']($data, 'priority', null);
|
||||
$entry->message = $data['message'];
|
||||
$entry->created_at = date('Y-m-d H:i:s');
|
||||
$entry->updated_at = date('Y-m-d H:i:s');
|
||||
$entry->ip = $this->di['request']->getClientAddress();
|
||||
$this->di['db']->store($entry);
|
||||
}
|
||||
|
||||
/** EVENTS **/
|
||||
|
||||
public static function onAfterClientLogin(\Box_Event $event)
|
||||
{
|
||||
$params = $event->getParameters();
|
||||
$di = $event->getDi();
|
||||
|
||||
$log = $di['db']->dispense('ActivityClientHistory');
|
||||
$log->client_id = $params['id'];
|
||||
$log->ip = $params['ip'];
|
||||
$log->created_at = date('Y-m-d H:i:s');
|
||||
$log->updated_at = date('Y-m-d H:i:s');
|
||||
$log->client_id = $params['id'];
|
||||
$log->ip = $params['ip'];
|
||||
$log->created_at = date('Y-m-d H:i:s');
|
||||
$log->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
$di['db']->store($log);
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterAdminLogin(\Box_Event $event)
|
||||
{
|
||||
$params = $event->getParameters();
|
||||
$di = $event->getDi();
|
||||
|
||||
$log= $di['db']->dispense('ActivityAdminHistory');
|
||||
$log->admin_id = $params['id'];
|
||||
$log->ip = $params['ip'];
|
||||
$log->created_at = date('Y-m-d H:i:s');
|
||||
$log->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
$log = $di['db']->dispense('ActivityAdminHistory');
|
||||
$log->admin_id = $params['id'];
|
||||
$log->ip = $params['ip'];
|
||||
$log->created_at = date('Y-m-d H:i:s');
|
||||
$log->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
$di['db']->store($log);
|
||||
}
|
||||
|
||||
public function getSearchQuery($data)
|
||||
{
|
||||
|
||||
$sql = 'SELECT m.*, a.id as staff_id, a.email as staff_email, a.name as staff_name, c.id as client_id, CONCAT(c.first_name, " ", c.last_name) as client_name, c.email as client_email
|
||||
FROM activity_system as m
|
||||
left join admin as a on a.id = m.admin_id
|
||||
left join client as c on c.id = m.client_id';
|
||||
|
||||
$params = array();
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$priority = $this->di['array_get']($data, 'priority', NULL);
|
||||
$only_staff = $this->di['array_get']($data, 'only_staff', NULL);
|
||||
$admin_id = $this->di['array_get']($data, 'admin_id', NULL);
|
||||
$only_clients = $this->di['array_get']($data, 'only_clients', NULL);
|
||||
$no_info = $this->di['array_get']($data, 'no_info', NULL);
|
||||
$no_debug = $this->di['array_get']($data, 'no_debug', NULL);
|
||||
$where = array ();
|
||||
if($priority) {
|
||||
$params = [];
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$priority = $this->di['array_get']($data, 'priority', null);
|
||||
$only_staff = $this->di['array_get']($data, 'only_staff', null);
|
||||
$admin_id = $this->di['array_get']($data, 'admin_id', null);
|
||||
$only_clients = $this->di['array_get']($data, 'only_clients', null);
|
||||
$no_info = $this->di['array_get']($data, 'no_info', null);
|
||||
$no_debug = $this->di['array_get']($data, 'no_debug', null);
|
||||
$where = [];
|
||||
if ($priority) {
|
||||
$where[] = 'm.priority = :priority';
|
||||
$params[':priority'] = $priority;
|
||||
}
|
||||
|
||||
if($no_info) {
|
||||
if ($no_info) {
|
||||
$where[] = 'm.priority < :priority';
|
||||
$params[':priority'] = \Box_Log::INFO;
|
||||
}
|
||||
|
||||
if($no_debug) {
|
||||
if ($no_debug) {
|
||||
$where[] = 'm.priority < :priority';
|
||||
$params[':priority'] = \Box_Log::DEBUG;
|
||||
}
|
||||
|
||||
if($only_staff) {
|
||||
if ($only_staff) {
|
||||
$where[] = 'm.admin_id IS NOT NULL';
|
||||
}
|
||||
|
||||
if($admin_id) {
|
||||
if ($admin_id) {
|
||||
$where[] = 'm.admin_id = :admin_id';
|
||||
$params[':admin_id'] = $admin_id;
|
||||
}
|
||||
|
||||
if($only_clients) {
|
||||
if ($only_clients) {
|
||||
$where[] = 'm.client_id IS NOT NULL';
|
||||
}
|
||||
|
||||
if($search) {
|
||||
if ($search) {
|
||||
$where[] = 'm.message LIKE :search OR m.ip LIKE :search2';
|
||||
$params[':search'] = $search;
|
||||
$params[':search2'] = $search;
|
||||
}
|
||||
|
||||
if (!empty($where)){
|
||||
if (!empty($where)) {
|
||||
$whereStatment = implode(' and ', $where);
|
||||
$sql .= ' WHERE '.$whereStatment;
|
||||
}
|
||||
|
||||
$sql .= ' ORDER by m.id desc';
|
||||
return array($sql, $params);
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function logEmail($subject, $clientId = null, $sender = null, $recipients = null, $content_html = null, $content_text = null)
|
||||
{
|
||||
$entry = $this->di['db']->dispense('ActivityClientEmail');
|
||||
|
||||
$entry->client_id = $clientId;
|
||||
$entry->sender = $sender;
|
||||
$entry->recipients = $recipients;
|
||||
$entry->subject = $subject;
|
||||
$entry->client_id = $clientId;
|
||||
$entry->sender = $sender;
|
||||
$entry->recipients = $recipients;
|
||||
$entry->subject = $subject;
|
||||
$entry->content_html = $content_html;
|
||||
$entry->content_text = $content_text;
|
||||
$entry->created_at = date('Y-m-d H:i:s');
|
||||
$entry->updated_at = date('Y-m-d H:i:s');
|
||||
$entry->created_at = date('Y-m-d H:i:s');
|
||||
$entry->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
$this->di['db']->store($entry);
|
||||
|
||||
@@ -151,24 +151,25 @@ class Service implements InjectionAwareInterface
|
||||
public function toApiArray(\Model_ActivityClientHistory $model)
|
||||
{
|
||||
$client = $this->di['db']->getExistingModelById('Client', $model->client_id, 'Client not found');
|
||||
return array(
|
||||
'id' => $model->id,
|
||||
'ip' => $model->ip,
|
||||
'created_at' => $model->created_at,
|
||||
'client' => array(
|
||||
'id' => $client->id,
|
||||
'first_name' => $client->first_name,
|
||||
'last_name' => $client->last_name,
|
||||
'email' => $client->email,
|
||||
)
|
||||
);
|
||||
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'ip' => $model->ip,
|
||||
'created_at' => $model->created_at,
|
||||
'client' => [
|
||||
'id' => $client->id,
|
||||
'first_name' => $client->first_name,
|
||||
'last_name' => $client->last_name,
|
||||
'email' => $client->email,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function rmByClient(\Model_Client $client)
|
||||
{
|
||||
$models = $this->di['db']->find('ActivitySystem', 'client_id = ?', array($client->id));
|
||||
foreach($models as $model){
|
||||
$models = $this->di['db']->find('ActivitySystem', 'client_id = ?', [$client->id]);
|
||||
foreach ($models as $model) {
|
||||
$this->di['db']->trash($model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file connects BoxBilling client area interface and API
|
||||
* This file connects BoxBilling client area interface and API.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Api\Controller;
|
||||
@@ -20,8 +20,8 @@ use Box\InjectionAwareInterface;
|
||||
|
||||
class Client implements InjectionAwareInterface
|
||||
{
|
||||
private $_requests_left = NULL;
|
||||
private $_api_config = NULL;
|
||||
private $_requests_left = null;
|
||||
private $_api_config = null;
|
||||
protected $di;
|
||||
|
||||
/**
|
||||
@@ -42,37 +42,40 @@ class Client implements InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->post('/api/:role/:class/:method', 'post_method', array('role', 'class', 'method'), get_class($this));
|
||||
$app->get('/api/:role/:class/:method', 'get_method', array('role', 'class', 'method'), get_class($this));
|
||||
|
||||
//all other requests are error requests
|
||||
$app->get('/api/:page', 'show_error', array('page' => '(.?)+'), get_class($this));
|
||||
$app->post('/api/:page', 'show_error', array('page' => '(.?)+'), get_class($this));
|
||||
$app->post('/api/:role/:class/:method', 'post_method', ['role', 'class', 'method'], get_class($this));
|
||||
$app->get('/api/:role/:class/:method', 'get_method', ['role', 'class', 'method'], get_class($this));
|
||||
|
||||
// all other requests are error requests
|
||||
$app->get('/api/:page', 'show_error', ['page' => '(.?)+'], get_class($this));
|
||||
$app->post('/api/:page', 'show_error', ['page' => '(.?)+'], get_class($this));
|
||||
}
|
||||
|
||||
|
||||
public function show_error(\Box_App $app, $page)
|
||||
{
|
||||
$exc = new \Box_Exception('Unknown API call :call', array(':call'=>$page), 879);
|
||||
$exc = new \Box_Exception('Unknown API call :call', [':call' => $page], 879);
|
||||
|
||||
return $this->renderJson(null, $exc);
|
||||
}
|
||||
|
||||
|
||||
public function get_method(\Box_App $app, $role, $class, $method)
|
||||
{
|
||||
$call = $class.'_'.$method;
|
||||
|
||||
return $this->tryCall($role, $call, $_GET);
|
||||
}
|
||||
|
||||
public function post_method(\Box_App $app, $role, $class, $method)
|
||||
{
|
||||
$p = $_POST;
|
||||
|
||||
|
||||
// adding support for raw post input with json string
|
||||
$input = file_get_contents("php://input");
|
||||
if(empty($p) && !empty($input)) {
|
||||
$input = file_get_contents('php://input');
|
||||
if (empty($p) && !empty($input)) {
|
||||
$p = @json_decode($input, 1);
|
||||
}
|
||||
|
||||
|
||||
$call = $class.'_'.$method;
|
||||
|
||||
return $this->tryCall($role, $call, $p);
|
||||
}
|
||||
|
||||
@@ -87,23 +90,23 @@ class Client implements InjectionAwareInterface
|
||||
$this->renderJson(null, $exc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _loadConfig()
|
||||
{
|
||||
if(is_null($this->_api_config)) {
|
||||
if (is_null($this->_api_config)) {
|
||||
$this->_api_config = $this->di['config']['api'];
|
||||
}
|
||||
}
|
||||
|
||||
private function checkRateLimit($method=null)
|
||||
private function checkRateLimit($method = null)
|
||||
{
|
||||
$isLoginMethod = false;
|
||||
if($method == 'staff_login' || $method == 'client_login'){
|
||||
$rate_span = $this->_api_config['rate_span_login'];
|
||||
if ('staff_login' == $method || 'client_login' == $method) {
|
||||
$rate_span = $this->_api_config['rate_span_login'];
|
||||
$rate_limit = $this->_api_config['rate_limit_login'];
|
||||
$isLoginMethod = true;
|
||||
} else {
|
||||
$rate_span = $this->_api_config['rate_span'];
|
||||
$rate_span = $this->_api_config['rate_span'];
|
||||
$rate_limit = $this->_api_config['rate_limit'];
|
||||
}
|
||||
|
||||
@@ -114,41 +117,44 @@ class Client implements InjectionAwareInterface
|
||||
if ($requests_left < 0) {
|
||||
sleep($this->_api_config['throttle_delay']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkHttpReferer()
|
||||
{
|
||||
// snake oil: check request is from the same domain as BoxBilling is installed if present
|
||||
$check_referer_header = isset($this->_api_config['require_referrer_header']) ? (bool)$this->_api_config['require_referrer_header'] : false;
|
||||
if($check_referer_header) {
|
||||
$check_referer_header = isset($this->_api_config['require_referrer_header']) ? (bool) $this->_api_config['require_referrer_header'] : false;
|
||||
if ($check_referer_header) {
|
||||
$url = strtolower(BB_URL);
|
||||
$referer = isset($_SERVER['HTTP_REFERER']) ? strtolower($_SERVER['HTTP_REFERER']) : null ;
|
||||
if(!$referer || $url != substr($referer, 0, strlen($url))) {
|
||||
throw new \Box_Exception('Invalid request. Make sure request origin is :from', array(':from'=>BB_URL), 1004);
|
||||
$referer = isset($_SERVER['HTTP_REFERER']) ? strtolower($_SERVER['HTTP_REFERER']) : null;
|
||||
if (!$referer || $url != substr($referer, 0, strlen($url))) {
|
||||
throw new \Box_Exception('Invalid request. Make sure request origin is :from', [':from' => BB_URL], 1004);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkAllowedIps()
|
||||
{
|
||||
$ips = $this->_api_config['allowed_ips'];
|
||||
if(!empty($ips) && !in_array($this->_getIp(), $ips)) {
|
||||
if (!empty($ips) && !in_array($this->_getIp(), $ips)) {
|
||||
throw new \Box_Exception('Unauthorized IP', null, 1002);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function isRoleLoggedIn($role)
|
||||
{
|
||||
if ($role == 'client'){
|
||||
if ('client' == $role) {
|
||||
$this->di['is_client_logged'];
|
||||
|
||||
}
|
||||
if ($role == 'admin'){
|
||||
if ('admin' == $role) {
|
||||
$this->di['is_admin_logged'];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -163,65 +169,66 @@ class Client implements InjectionAwareInterface
|
||||
$this->checkHttpReferer();
|
||||
$this->isRoleAllowed($role);
|
||||
|
||||
try{
|
||||
try {
|
||||
$this->isRoleLoggedIn($role);
|
||||
}catch (\Exception $e){
|
||||
} catch (\Exception $e) {
|
||||
$this->_tryTokenLogin();
|
||||
}
|
||||
|
||||
$api = $this->di['api']($role);
|
||||
$result = $api->$method($params);
|
||||
|
||||
return $this->renderJson($result);
|
||||
}
|
||||
|
||||
private function getAuth()
|
||||
{
|
||||
if(isset($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
$auth_params = explode(":" , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
|
||||
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||
$auth_params = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
|
||||
$_SERVER['PHP_AUTH_USER'] = $auth_params[0];
|
||||
unset($auth_params[0]);
|
||||
$_SERVER['PHP_AUTH_PW'] = implode('',$auth_params);
|
||||
$_SERVER['PHP_AUTH_PW'] = implode('', $auth_params);
|
||||
}
|
||||
|
||||
if(!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
throw new \Box_Exception('Authentication Failed', null, 201);
|
||||
}
|
||||
|
||||
if(!isset($_SERVER['PHP_AUTH_PW'])) {
|
||||
if (!isset($_SERVER['PHP_AUTH_PW'])) {
|
||||
throw new \Box_Exception('Authentication Failed', null, 202);
|
||||
}
|
||||
|
||||
if(empty($_SERVER['PHP_AUTH_PW'])) {
|
||||
if (empty($_SERVER['PHP_AUTH_PW'])) {
|
||||
throw new \Box_Exception('Authentication Failed', null, 206);
|
||||
}
|
||||
|
||||
return array($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
|
||||
return [$_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']];
|
||||
}
|
||||
|
||||
private function _tryTokenLogin()
|
||||
{
|
||||
list($username, $password) = $this->getAuth();
|
||||
[$username, $password] = $this->getAuth();
|
||||
|
||||
switch ($username) {
|
||||
case 'client':
|
||||
$model = $this->di['db']->findOne('Client', 'api_token = ?', array($password));
|
||||
if(!$model instanceof \Model_Client) {
|
||||
$model = $this->di['db']->findOne('Client', 'api_token = ?', [$password]);
|
||||
if (!$model instanceof \Model_Client) {
|
||||
throw new \Box_Exception('Authentication Failed', null, 204);
|
||||
}
|
||||
$this->di['session']->set('client_id', $model->id);
|
||||
break;
|
||||
|
||||
case 'admin':
|
||||
$model = $this->di['db']->findOne('Admin', 'api_token = ?', array($password));
|
||||
if(!$model instanceof \Model_Admin) {
|
||||
$model = $this->di['db']->findOne('Admin', 'api_token = ?', [$password]);
|
||||
if (!$model instanceof \Model_Admin) {
|
||||
throw new \Box_Exception('Authentication Failed', null, 205);
|
||||
}
|
||||
$sessionAdminArray = array(
|
||||
'id' => $model->id,
|
||||
'email' => $model->email,
|
||||
'name' => $model->name,
|
||||
'role' => $model->role,
|
||||
);
|
||||
$sessionAdminArray = [
|
||||
'id' => $model->id,
|
||||
'email' => $model->email,
|
||||
'name' => $model->name,
|
||||
'role' => $model->role,
|
||||
];
|
||||
$this->di['session']->set('admin', $sessionAdminArray);
|
||||
break;
|
||||
|
||||
@@ -233,26 +240,28 @@ class Client implements InjectionAwareInterface
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
private function isRoleAllowed($role)
|
||||
{
|
||||
$allowed = array('guest', 'client', 'admin');
|
||||
if (!in_array($role, $allowed)){
|
||||
$allowed = ['guest', 'client', 'admin'];
|
||||
if (!in_array($role, $allowed)) {
|
||||
throw new \Box_Exception('Unknow API call', null, 701);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function renderJson($data = NULL, \Exception $e = NULL)
|
||||
public function renderJson($data = null, \Exception $e = null)
|
||||
{
|
||||
// do not emit response if headers already sent
|
||||
if (headers_sent()) {
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$this->_loadConfig();
|
||||
|
||||
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Content-type: application/json; charset=utf-8');
|
||||
@@ -260,14 +269,14 @@ class Client implements InjectionAwareInterface
|
||||
header('X-RateLimit-Span: '.$this->_api_config['rate_span']);
|
||||
header('X-RateLimit-Limit: '.$this->_api_config['rate_limit']);
|
||||
header('X-RateLimit-Remaining: '.$this->_requests_left);
|
||||
if(NULL !== $e) {
|
||||
if (null !== $e) {
|
||||
error_log($e->getMessage().' '.$e->getCode());
|
||||
$code = $e->getCode() ? $e->getCode() : 9999;
|
||||
$result = array('result'=>NULL, 'error'=>array('message'=>$e->getMessage(), 'code'=>$code));
|
||||
$result = ['result' => null, 'error' => ['message' => $e->getMessage(), 'code' => $code]];
|
||||
} else {
|
||||
$result = array('result'=>$data, 'error'=> NULL);
|
||||
$result = ['result' => $data, 'error' => null];
|
||||
}
|
||||
print json_encode($result);
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -275,4 +284,4 @@ class Client implements InjectionAwareInterface
|
||||
{
|
||||
return $this->di['request']->getClientAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -38,51 +38,53 @@ class Service implements \Box\InjectionAwareInterface
|
||||
public function logRequest()
|
||||
{
|
||||
$request = $this->di['request'];
|
||||
$sql="
|
||||
$sql = '
|
||||
INSERT INTO api_request (ip, request, created_at)
|
||||
VALUES(:ip, :request, NOW())
|
||||
";
|
||||
$values = array(
|
||||
'ip' => $request->getClientAddress(),
|
||||
'request' => $request->getURI(),
|
||||
);
|
||||
';
|
||||
$values = [
|
||||
'ip' => $request->getClientAddress(),
|
||||
'request' => $request->getURI(),
|
||||
];
|
||||
|
||||
return $this->di['db']->exec($sql, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $since - timestamp
|
||||
* @param int $since - timestamp
|
||||
* @param string|null $ip
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRequestCount($since, $ip = null, $isLoginMethod = false)
|
||||
{
|
||||
if (!is_numeric($since)){
|
||||
if (!is_numeric($since)) {
|
||||
$since = strtotime($since);
|
||||
}
|
||||
$sinceIso = date('Y-m-d H:i:s', $since);
|
||||
$values = array(
|
||||
'since' => $sinceIso,
|
||||
);
|
||||
if($isLoginMethod){
|
||||
$sql="
|
||||
$values = [
|
||||
'since' => $sinceIso,
|
||||
];
|
||||
if ($isLoginMethod) {
|
||||
$sql = '
|
||||
SELECT COUNT(id) as cclogin
|
||||
FROM api_request
|
||||
WHERE created_at > :since
|
||||
";
|
||||
';
|
||||
} else {
|
||||
$sql="
|
||||
$sql = '
|
||||
SELECT COUNT(id) as cc
|
||||
FROM api_request
|
||||
WHERE created_at > :since
|
||||
";
|
||||
';
|
||||
}
|
||||
|
||||
if(null != $ip) {
|
||||
$sql .= " AND ip = :ip";
|
||||
if (null != $ip) {
|
||||
$sql .= ' AND ip = :ip';
|
||||
$values['ip'] = $ip;
|
||||
}
|
||||
|
||||
return (int)$this->di['db']->getCell($sql, $values);
|
||||
return (int) $this->di['db']->getCell($sql, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +95,6 @@ class Service implements \Box\InjectionAwareInterface
|
||||
return $this->di['api_guest'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use DI
|
||||
*/
|
||||
@@ -109,4 +110,4 @@ class Service implements \Box\InjectionAwareInterface
|
||||
{
|
||||
return $this->di['api_admin'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Branding;
|
||||
|
||||
class Service implements \Box\InjectionAwareInterface
|
||||
@@ -37,5 +36,4 @@ class Service implements \Box\InjectionAwareInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,11 +10,10 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Cart\Api;
|
||||
|
||||
/**
|
||||
* Shopping cart management
|
||||
* Shopping cart management.
|
||||
*/
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
@@ -24,12 +23,12 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
|
||||
foreach ($pager['list'] as $key => $cartArr){
|
||||
$cart = $this->di['db']->getExistingModelById('Cart', $cartArr['id'], 'Cart not found');
|
||||
foreach ($pager['list'] as $key => $cartArr) {
|
||||
$cart = $this->di['db']->getExistingModelById('Cart', $cartArr['id'], 'Cart not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($cart);
|
||||
}
|
||||
|
||||
@@ -37,15 +36,17 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shopping cart contents by id
|
||||
* Get shopping cart contents by id.
|
||||
*
|
||||
* @param int $id - shopping cart id
|
||||
*
|
||||
* @return array - shopping cart contents
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Shopping cart id is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$cart = $this->di['db']->getExistingModelById('Cart', $data['id'], 'Shopping cart not found');
|
||||
@@ -54,25 +55,26 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove shopping carts that are older than a week and was not ordered
|
||||
* Remove shopping carts that are older than a week and was not ordered.
|
||||
*
|
||||
* @BOXBILLING_CRON
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function batch_expire($data)
|
||||
{
|
||||
$this->di['logger']->info('Executed action to clear expired shopping carts from database');
|
||||
|
||||
$query = "SELECT id, created_at FROM `cart` WHERE DATEDIFF(CURDATE(), created_at) > 7;";
|
||||
$list = $this->di['db']->getAssoc($query);
|
||||
$query = 'SELECT id, created_at FROM `cart` WHERE DATEDIFF(CURDATE(), created_at) > 7;';
|
||||
$list = $this->di['db']->getAssoc($query);
|
||||
if ($list) {
|
||||
foreach ($list as $id => $created_at) {
|
||||
$this->di['db']->exec('DELETE FROM `cart_product` WHERE cart_id = :id', array(':id' => $id));
|
||||
$this->di['db']->exec('DELETE FROM `cart` WHERE id = :id', array(':id' => $id));
|
||||
$this->di['db']->exec('DELETE FROM `cart_product` WHERE cart_id = :id', [':id' => $id]);
|
||||
$this->di['db']->exec('DELETE FROM `cart` WHERE id = :id', [':id' => $id]);
|
||||
}
|
||||
$this->di['logger']->info('Removed %s expired shopping carts', count($list));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,16 +10,15 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Cart\Api;
|
||||
|
||||
/**
|
||||
* Shopping cart management
|
||||
* Shopping cart management.
|
||||
*/
|
||||
class Client extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Checkout cart which has products
|
||||
* Checkout cart which has products.
|
||||
*
|
||||
* @optional int $gateway_id - payment gateway id. Which payment gateway will be used to make payment
|
||||
*
|
||||
@@ -27,9 +26,10 @@ class Client extends \Api_Abstract
|
||||
*/
|
||||
public function checkout($data)
|
||||
{
|
||||
$gateway_id = $this->di['array_get']($data, 'gateway_id');
|
||||
$gateway_id = $this->di['array_get']($data, 'gateway_id');
|
||||
$cart = $this->getService()->getSessionCart();
|
||||
$client = $this->getIdentity();
|
||||
|
||||
return $this->getService()->checkoutCart($cart, $client, $gateway_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,16 +10,15 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Cart\Api;
|
||||
|
||||
/**
|
||||
* Shopping cart management
|
||||
* Shopping cart management.
|
||||
*/
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get shopping cart contents
|
||||
* Get shopping cart contents.
|
||||
*
|
||||
* @return array - shopping cart contents
|
||||
*/
|
||||
@@ -31,7 +30,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Completely remove shopping cart contents
|
||||
* Completely remove shopping cart contents.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -43,7 +42,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shopping cart currency
|
||||
* Set shopping cart currency.
|
||||
*
|
||||
* @param string $currency - New currency code to applied to shopping cart
|
||||
*
|
||||
@@ -51,13 +50,13 @@ class Guest extends \Api_Abstract
|
||||
*/
|
||||
public function set_currency($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'currency' => 'Currency code not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$currencyService = $this->di['mod_service']('currency');
|
||||
$currency = $currencyService->getByCode($data['currency']);
|
||||
$currency = $currencyService->getByCode($data['currency']);
|
||||
if (!$currency instanceof \Model_Currency) {
|
||||
throw new \Box_Exception('Currency not found');
|
||||
}
|
||||
@@ -67,7 +66,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve information about currently selected shopping cart currency
|
||||
* Retrieve information about currently selected shopping cart currency.
|
||||
*
|
||||
* @return array - Currency details
|
||||
*/
|
||||
@@ -76,7 +75,7 @@ class Guest extends \Api_Abstract
|
||||
$cart = $this->getService()->getSessionCart();
|
||||
|
||||
$currencyService = $this->di['mod_service']('currency');
|
||||
$currency = $this->di['db']->load('Currency', $cart->currency_id);
|
||||
$currency = $this->di['db']->load('Currency', $cart->currency_id);
|
||||
if (!$currency instanceof \Model_Currency) {
|
||||
$currency = $currencyService->getDefault();
|
||||
}
|
||||
@@ -85,7 +84,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Promo code to shopping cart
|
||||
* Apply Promo code to shopping cart.
|
||||
*
|
||||
* @param string $promocode - Promo code string
|
||||
*
|
||||
@@ -93,18 +92,17 @@ class Guest extends \Api_Abstract
|
||||
*/
|
||||
public function apply_promo($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'promocode' => 'Promo code not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
|
||||
$promo = $this->getService()->findActivePromoByCode($data['promocode']);
|
||||
if (!$promo instanceof \Model_Promo) {
|
||||
throw new \Box_Exception('Promo code is expired or does not exist');
|
||||
}
|
||||
|
||||
if (!$this->getService()->isPromoAvailableForClientGroup($promo)){
|
||||
if (!$this->getService()->isPromoAvailableForClientGroup($promo)) {
|
||||
throw new \Box_Exception('Promo can not be applied to your account');
|
||||
}
|
||||
|
||||
@@ -118,7 +116,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes promo from shopping cart and resets discounted prices if any
|
||||
* Removes promo from shopping cart and resets discounted prices if any.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -130,7 +128,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes product from shopping cart
|
||||
* Removes product from shopping cart.
|
||||
*
|
||||
* @param int $id - Shopping cart item id
|
||||
*
|
||||
@@ -138,9 +136,9 @@ class Guest extends \Api_Abstract
|
||||
*/
|
||||
public function remove_item($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Cart item id not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$cart = $this->getService()->getSessionCart();
|
||||
@@ -149,7 +147,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds product to shopping cart
|
||||
* Adds product to shopping cart.
|
||||
*
|
||||
* @param int $id - Product ID
|
||||
*
|
||||
@@ -163,20 +161,20 @@ class Guest extends \Api_Abstract
|
||||
*/
|
||||
public function add_item($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Product id not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$cart = $this->getService()->getSessionCart();
|
||||
|
||||
$product = $this->di['db']->getExistingModelById('Product', $data['id'], 'Product not found');
|
||||
|
||||
//reset cart by default
|
||||
// reset cart by default
|
||||
if (!isset($data['multiple']) || !$data['multiple']) {
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
return $this->getService()->addItem($cart, $product, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Cart\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,11 +34,11 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/cart', 'get_cart', array(), get_class($this));
|
||||
$app->get('/cart', 'get_cart', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_cart(\Box_App $app)
|
||||
{
|
||||
return $app->render('mod_cart_index');
|
||||
}
|
||||
}
|
||||
}
|
||||
+200
-201
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -16,7 +16,6 @@ use Box\InjectionAwareInterface;
|
||||
|
||||
class Service implements InjectionAwareInterface
|
||||
{
|
||||
|
||||
protected $di;
|
||||
|
||||
public function setDi($di)
|
||||
@@ -31,12 +30,12 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function getSearchQuery($data)
|
||||
{
|
||||
$sql = "
|
||||
$sql = '
|
||||
SELECT cart.id FROM cart
|
||||
LEFT JOIN currency ON cart.currency_id = currency.id
|
||||
LEFT JOIN promo ON cart.promo_id = promo.id";
|
||||
LEFT JOIN promo ON cart.promo_id = promo.id';
|
||||
|
||||
return array($sql, array());
|
||||
return [$sql, []];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,8 +43,8 @@ class Service implements InjectionAwareInterface
|
||||
*/
|
||||
public function getSessionCart()
|
||||
{
|
||||
$sqlBindings = array(':session_id' => $this->di['session']->getId());
|
||||
$cart = $this->di['db']->findOne('Cart', 'session_id = :session_id', $sqlBindings);
|
||||
$sqlBindings = [':session_id' => $this->di['session']->getId()];
|
||||
$cart = $this->di['db']->findOne('Cart', 'session_id = :session_id', $sqlBindings);
|
||||
|
||||
if ($cart instanceof \Model_Cart) {
|
||||
return $cart;
|
||||
@@ -55,16 +54,16 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
if ($this->di['session']->get('client_id')) {
|
||||
$client_id = $this->di['session']->get('client_id');
|
||||
$currency = $cc->getCurrencyByClientId($client_id);
|
||||
$currency = $cc->getCurrencyByClientId($client_id);
|
||||
} else {
|
||||
$currency = $cc->getDefault();
|
||||
}
|
||||
|
||||
$cart = $this->di['db']->dispense('Cart');
|
||||
$cart->session_id = $this->di['session']->getId();
|
||||
$cart = $this->di['db']->dispense('Cart');
|
||||
$cart->session_id = $this->di['session']->getId();
|
||||
$cart->currency_id = $currency->id;
|
||||
$cart->created_at = date('Y-m-d H:i:s');
|
||||
$cart->updated_at = date('Y-m-d H:i:s');
|
||||
$cart->created_at = date('Y-m-d H:i:s');
|
||||
$cart->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($cart);
|
||||
|
||||
return $cart;
|
||||
@@ -72,15 +71,15 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function addItem(\Model_Cart $cart, \Model_Product $product, array $data)
|
||||
{
|
||||
$event_params = array_merge($data, array('cart_id' => $cart->id, 'product_id' => $product->id));
|
||||
$this->di['events_manager']->fire(array('event' => 'onBeforeProductAddedToCart', 'params' => $event_params));
|
||||
$event_params = array_merge($data, ['cart_id' => $cart->id, 'product_id' => $product->id]);
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeProductAddedToCart', 'params' => $event_params]);
|
||||
|
||||
$productService = $product->getService();
|
||||
|
||||
if ($this->isRecurrentPricing($product)) {
|
||||
$required = array(
|
||||
$required = [
|
||||
'period' => 'Period parameter not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if (!$this->isPeriodEnabledForProduct($product, $data['period'])) {
|
||||
@@ -88,23 +87,23 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
}
|
||||
|
||||
$qty = $this->di['array_get']($data, 'quantity', 1);
|
||||
$qty = $this->di['array_get']($data, 'quantity', 1);
|
||||
// check stock
|
||||
if (!$this->isStockAvailable($product, $qty)) {
|
||||
throw new \Box_Exception("I'm afraid we are out of stock.");
|
||||
}
|
||||
|
||||
$addons = $this->di['array_get']($data, 'addons', array());
|
||||
$addons = $this->di['array_get']($data, 'addons', []);
|
||||
unset($data['id']);
|
||||
unset($data['addons']);
|
||||
|
||||
$list = array();
|
||||
$list[] = array(
|
||||
$list = [];
|
||||
$list[] = [
|
||||
'product' => $product,
|
||||
'config' => $data,
|
||||
);
|
||||
'config' => $data,
|
||||
];
|
||||
|
||||
//check for required domain product
|
||||
// check for required domain product
|
||||
if (method_exists($productService, 'getDomainProductFromConfig')) {
|
||||
$dc = $productService->getDomainProductFromConfig($product, $data);
|
||||
if (isset($dc['config']) && $dc['product'] && $dc['product'] instanceof \Model_Product) {
|
||||
@@ -114,14 +113,13 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$productService = $this->di['mod_service']('Product');
|
||||
foreach ($addons as $id => $ac) {
|
||||
if (isset($ac['selected']) && (bool)$ac['selected']) {
|
||||
if (isset($ac['selected']) && (bool) $ac['selected']) {
|
||||
$addon = $productService->getAddonById($id);
|
||||
if ($addon instanceof \Model_Product) {
|
||||
if ($this->isRecurrentPricing($addon)) {
|
||||
|
||||
$required = array(
|
||||
$required = [
|
||||
'period' => 'Addon period parameter not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $ac);
|
||||
|
||||
if (!$this->isPeriodEnabledForProduct($addon, $ac['period'])) {
|
||||
@@ -130,12 +128,12 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
$ac['parent_id'] = $product->id;
|
||||
|
||||
$list[] = array(
|
||||
$list[] = [
|
||||
'product' => $addon,
|
||||
'config' => $ac,
|
||||
);
|
||||
'config' => $ac,
|
||||
];
|
||||
} else {
|
||||
error_log('Addon not found by id ' . $id);
|
||||
error_log('Addon not found by id '.$id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,14 +144,14 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$productServiceFromList = $productFromList->getService();
|
||||
|
||||
//@deprecated logic
|
||||
// @deprecated logic
|
||||
if (method_exists($productServiceFromList, 'prependOrderConfig')) {
|
||||
$productFromListConfig = $productServiceFromList->prependOrderConfig($productFromList, $productFromListConfig);
|
||||
}
|
||||
|
||||
if (method_exists($productServiceFromList, 'attachOrderConfig')) {
|
||||
$model = $this->di['db']->load('Product', $productFromList->id);
|
||||
$productFromListConfig = $productServiceFromList->attachOrderConfig($model, $productFromListConfig);
|
||||
$productFromListConfig = $productServiceFromList->attachOrderConfig($model, $productFromListConfig);
|
||||
}
|
||||
if (method_exists($productServiceFromList, 'validateOrderData')) {
|
||||
$productServiceFromList->validateOrderData($productFromListConfig);
|
||||
@@ -166,7 +164,7 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$this->di['logger']->info('Added "%s" to shopping cart', $product->title);
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onAfterProductAddedToCart', 'params' => $event_params));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterProductAddedToCart', 'params' => $event_params]);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -174,25 +172,26 @@ class Service implements InjectionAwareInterface
|
||||
public function isStockAvailable(\Model_Product $product, $qty)
|
||||
{
|
||||
if ($product->stock_control) {
|
||||
return ($product->quantity_in_stock >= $qty);
|
||||
return $product->quantity_in_stock >= $qty;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isRecurrentPricing(\Model_Product $model)
|
||||
{
|
||||
$productTable = $model->getTable();
|
||||
$pricing = $productTable->getPricingArray($model);
|
||||
return (isset($pricing['type']) && $pricing['type'] == \Model_ProductPayment::RECURRENT);
|
||||
$pricing = $productTable->getPricingArray($model);
|
||||
|
||||
return isset($pricing['type']) && \Model_ProductPayment::RECURRENT == $pricing['type'];
|
||||
}
|
||||
|
||||
public function isPeriodEnabledForProduct(\Model_Product $model, $period)
|
||||
{
|
||||
$productTable = $model->getTable();
|
||||
$pricing = $productTable->getPricingArray($model);
|
||||
if ($pricing['type'] == \Model_ProductPayment::RECURRENT) {
|
||||
return (bool)$pricing['recurrent'][$period]['enabled'];
|
||||
$pricing = $productTable->getPricingArray($model);
|
||||
if (\Model_ProductPayment::RECURRENT == $pricing['type']) {
|
||||
return (bool) $pricing['recurrent'][$period]['enabled'];
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -200,10 +199,10 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
protected function addProduct(\Model_Cart $cart, \Model_Product $product, array $data)
|
||||
{
|
||||
$item = $this->di['db']->dispense('CartProduct');
|
||||
$item->cart_id = $cart->id;
|
||||
$item = $this->di['db']->dispense('CartProduct');
|
||||
$item->cart_id = $cart->id;
|
||||
$item->product_id = $product->id;
|
||||
$item->config = json_encode($data);
|
||||
$item->config = json_encode($data);
|
||||
$this->di['db']->store($item);
|
||||
|
||||
return true;
|
||||
@@ -211,10 +210,10 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function removeProduct(\Model_Cart $cart, $id, $removeAddons = true)
|
||||
{
|
||||
$bindings = array(
|
||||
$bindings = [
|
||||
':cart_id' => $cart->id,
|
||||
':id' => $id
|
||||
);
|
||||
':id' => $id,
|
||||
];
|
||||
|
||||
$cartProduct = $this->di['db']->findOne('CartProduct', 'id = :id AND cart_id = :cart_id', $bindings);
|
||||
if (!$cartProduct instanceof \Model_CartProduct) {
|
||||
@@ -222,8 +221,8 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
if ($removeAddons) {
|
||||
$allCartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', array(':cart_id' => $cart->id));
|
||||
foreach ((array)$allCartProducts as $cProduct) {
|
||||
$allCartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', [':cart_id' => $cart->id]);
|
||||
foreach ((array) $allCartProducts as $cProduct) {
|
||||
$config = json_decode($cProduct->config, true);
|
||||
if (isset($config['parent_id']) && $config['parent_id'] == $cartProduct->product_id) {
|
||||
$this->di['db']->trash($cProduct);
|
||||
@@ -251,11 +250,11 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function resetCart(\Model_Cart $cart)
|
||||
{
|
||||
$cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', array(':cart_id' => $cart->id));
|
||||
$cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', [':cart_id' => $cart->id]);
|
||||
foreach ($cartProducts as $cartProduct) {
|
||||
$this->di['db']->trash($cartProduct);
|
||||
}
|
||||
$cart->promo_id = NULL;
|
||||
$cart->promo_id = null;
|
||||
$cart->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($cart);
|
||||
|
||||
@@ -264,7 +263,7 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function removePromo(\Model_Cart $cart)
|
||||
{
|
||||
$cart->promo_id = NULL;
|
||||
$cart->promo_id = null;
|
||||
$cart->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($cart);
|
||||
|
||||
@@ -293,14 +292,14 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
protected function isEmptyCart(\Model_Cart $cart)
|
||||
{
|
||||
$cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', array(':cart_id' => $cart->id));
|
||||
$cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', [':cart_id' => $cart->id]);
|
||||
|
||||
return (count($cartProducts) == 0);
|
||||
return 0 == count($cartProducts);
|
||||
}
|
||||
|
||||
public function rm(\Model_Cart $cart)
|
||||
{
|
||||
$cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', array(':cart_id' => $cart->id));
|
||||
$cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', [':cart_id' => $cart->id]);
|
||||
|
||||
foreach ($cartProducts as $cartProduct) {
|
||||
$this->di['db']->trash($cartProduct);
|
||||
@@ -317,9 +316,9 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$currency = $this->di['db']->getExistingModelById('Currency', $model->currency_id);
|
||||
|
||||
$items = array();
|
||||
$total = 0;
|
||||
$cart_discount = 0;
|
||||
$items = [];
|
||||
$total = 0;
|
||||
$cart_discount = 0;
|
||||
$items_discount = 0;
|
||||
foreach ($products as $product) {
|
||||
$p = $this->cartProductToApiArray($product);
|
||||
@@ -332,18 +331,18 @@ class Service implements InjectionAwareInterface
|
||||
$promo = $this->di['db']->getExistingModelById('Promo', $model->promo_id, 'Promo not found');
|
||||
$promocode = $promo->code;
|
||||
} else {
|
||||
$promocode = NULL;
|
||||
$promocode = null;
|
||||
}
|
||||
|
||||
$currencyService = $this->di['mod_service']('currency');
|
||||
$result = array(
|
||||
$result = [
|
||||
'promocode' => $promocode,
|
||||
'discount' => $items_discount,
|
||||
'subtotal' => $total,
|
||||
'total' => $total - $items_discount,
|
||||
'items' => $items,
|
||||
'currency' => $currencyService->toApiArray($currency),
|
||||
);
|
||||
'discount' => $items_discount,
|
||||
'subtotal' => $total,
|
||||
'total' => $total - $items_discount,
|
||||
'items' => $items,
|
||||
'currency' => $currencyService->toApiArray($currency),
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -396,7 +395,7 @@ class Service implements InjectionAwareInterface
|
||||
$client = null;
|
||||
}
|
||||
|
||||
if (is_null($client)){
|
||||
if (is_null($client)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -409,15 +408,15 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
protected function clientHadUsedPromo(\Model_Client $client, \Model_Promo $promo)
|
||||
{
|
||||
$sql = "SELECT id FROM client_order WHERE promo_id = :promo AND client_id = :cid LIMIT 1";
|
||||
$promoId = $this->di['db']->getCell($sql, array(':promo' => $promo->id, ':cid' => $client->id));
|
||||
$sql = 'SELECT id FROM client_order WHERE promo_id = :promo AND client_id = :cid LIMIT 1';
|
||||
$promoId = $this->di['db']->getCell($sql, [':promo' => $promo->id, ':cid' => $client->id]);
|
||||
|
||||
return ($promoId !== null);
|
||||
return null !== $promoId;
|
||||
}
|
||||
|
||||
public function getCartProducts(\Model_Cart $model)
|
||||
{
|
||||
return $this->di['db']->find('CartProduct', 'cart_id = :cart_id ORDER BY id ASC', array(':cart_id' => $model->id));
|
||||
return $this->di['db']->find('CartProduct', 'cart_id = :cart_id ORDER BY id ASC', [':cart_id' => $model->id]);
|
||||
}
|
||||
|
||||
public function checkoutCart(\Model_Cart $cart, \Model_Client $client, $gateway_id = null)
|
||||
@@ -430,41 +429,41 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
$this->di['events_manager']->fire(
|
||||
array(
|
||||
'event' => 'onBeforeClientCheckout',
|
||||
'params' => array(
|
||||
'ip' => $this->di['request']->getClientAddress(),
|
||||
[
|
||||
'event' => 'onBeforeClientCheckout',
|
||||
'params' => [
|
||||
'ip' => $this->di['request']->getClientAddress(),
|
||||
'client_id' => $client->id,
|
||||
'cart_id' => $cart->id)
|
||||
)
|
||||
'cart_id' => $cart->id, ],
|
||||
]
|
||||
);
|
||||
|
||||
list($order, $invoice, $orders) = $this->createFromCart($client, $gateway_id);
|
||||
[$order, $invoice, $orders] = $this->createFromCart($client, $gateway_id);
|
||||
|
||||
$this->rm($cart);
|
||||
|
||||
$this->di['logger']->info('Checked out shopping cart');
|
||||
|
||||
$this->di['events_manager']->fire(
|
||||
array(
|
||||
'event' => 'onAfterClientOrderCreate',
|
||||
'params' => array(
|
||||
'ip' => $this->di['request']->getClientAddress(),
|
||||
[
|
||||
'event' => 'onAfterClientOrderCreate',
|
||||
'params' => [
|
||||
'ip' => $this->di['request']->getClientAddress(),
|
||||
'client_id' => $client->id,
|
||||
'id' => $order->id
|
||||
)
|
||||
)
|
||||
'id' => $order->id,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$result = array(
|
||||
'gateway_id' => $gateway_id,
|
||||
$result = [
|
||||
'gateway_id' => $gateway_id,
|
||||
'invoice_hash' => null,
|
||||
'order_id' => $order->id,
|
||||
'orders' => $orders,
|
||||
);
|
||||
'order_id' => $order->id,
|
||||
'orders' => $orders,
|
||||
];
|
||||
|
||||
// invoice may not be created if total is 0
|
||||
if ($invoice instanceof \Model_Invoice && $invoice->status == \Model_Invoice::STATUS_UNPAID) {
|
||||
if ($invoice instanceof \Model_Invoice && \Model_Invoice::STATUS_UNPAID == $invoice->status) {
|
||||
$result['invoice_hash'] = $invoice->hash;
|
||||
}
|
||||
|
||||
@@ -475,31 +474,29 @@ class Service implements InjectionAwareInterface
|
||||
{
|
||||
$cart = $this->getSessionCart();
|
||||
$ca = $this->toApiArray($cart);
|
||||
if (count($ca['items']) == 0) {
|
||||
if (0 == count($ca['items'])) {
|
||||
throw new \Box_Exception('Can not checkout empty cart.');
|
||||
}
|
||||
|
||||
|
||||
$currency = $this->di['db']->getExistingModelById('Currency', $cart->currency_id, 'Currency not found.');
|
||||
|
||||
//set default client currency
|
||||
// set default client currency
|
||||
if (!$client->currency) {
|
||||
$client->currency = $currency->code;
|
||||
$this->di['db']->store($client);
|
||||
}
|
||||
|
||||
if ($client->currency != $currency->code) {
|
||||
throw new \Box_Exception('Selected currency :selected does not match your profile currency :code. Please change cart currency to continue.',
|
||||
array(':selected' => $currency->code, ':code' => $client->currency));
|
||||
throw new \Box_Exception('Selected currency :selected does not match your profile currency :code. Please change cart currency to continue.', [':selected' => $currency->code, ':code' => $client->currency]);
|
||||
}
|
||||
|
||||
$clientService = $this->di['mod_service']('client');
|
||||
$taxed = $clientService->isClientTaxable($client);
|
||||
$taxed = $clientService->isClientTaxable($client);
|
||||
|
||||
$orders = array();
|
||||
$invoice_items = array();
|
||||
$master_order = null;
|
||||
$i = 0;
|
||||
$orders = [];
|
||||
$invoice_items = [];
|
||||
$master_order = null;
|
||||
$i = 0;
|
||||
|
||||
foreach ($this->getCartProducts($cart) as $p) {
|
||||
$item = $this->cartProductToApiArray($p);
|
||||
@@ -517,28 +514,28 @@ class Service implements InjectionAwareInterface
|
||||
$item['domain']['register_sld'] = strtolower($item['domain']['register_sld']);
|
||||
$item['domain']['transfer_sld'] = strtolower($item['domain']['transfer_sld']);
|
||||
|
||||
$order = $this->di['db']->dispense('ClientOrder');
|
||||
$order->client_id = $client->id;
|
||||
$order->promo_id = $cart->promo_id;
|
||||
$order = $this->di['db']->dispense('ClientOrder');
|
||||
$order->client_id = $client->id;
|
||||
$order->promo_id = $cart->promo_id;
|
||||
$order->product_id = $item['product_id'];
|
||||
$order->form_id = $item['form_id'];
|
||||
$order->form_id = $item['form_id'];
|
||||
|
||||
$order->group_id = $cart->id;
|
||||
$order->group_master = ($i == 0);
|
||||
$order->group_id = $cart->id;
|
||||
$order->group_master = (0 == $i);
|
||||
$order->invoice_option = 'issue-invoice';
|
||||
$order->title = $item['title'];
|
||||
$order->currency = $currency->code;
|
||||
$order->service_type = $item['type'];
|
||||
$order->unit = $this->di['array_get']($item, 'unit', NULL);
|
||||
$order->period = $this->di['array_get']($item, 'period', NULL);
|
||||
$order->quantity = $this->di['array_get']($item, 'quantity', NULL);
|
||||
$order->price = $item['price'] * $currency->conversion_rate;
|
||||
$order->discount = $item['discount_price'] * $currency->conversion_rate;
|
||||
$order->status = \Model_ClientOrder::STATUS_PENDING_SETUP;
|
||||
$order->notes = $this->di['array_get']($item, 'notes', NULL);
|
||||
$order->config = json_encode($item);
|
||||
$order->created_at = date('Y-m-d H:i:s');
|
||||
$order->updated_at = date('Y-m-d H:i:s');
|
||||
$order->title = $item['title'];
|
||||
$order->currency = $currency->code;
|
||||
$order->service_type = $item['type'];
|
||||
$order->unit = $this->di['array_get']($item, 'unit', null);
|
||||
$order->period = $this->di['array_get']($item, 'period', null);
|
||||
$order->quantity = $this->di['array_get']($item, 'quantity', null);
|
||||
$order->price = $item['price'] * $currency->conversion_rate;
|
||||
$order->discount = $item['discount_price'] * $currency->conversion_rate;
|
||||
$order->status = \Model_ClientOrder::STATUS_PENDING_SETUP;
|
||||
$order->notes = $this->di['array_get']($item, 'notes', null);
|
||||
$order->config = json_encode($item);
|
||||
$order->created_at = date('Y-m-d H:i:s');
|
||||
$order->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($order);
|
||||
|
||||
$orders[] = $order;
|
||||
@@ -548,69 +545,68 @@ class Service implements InjectionAwareInterface
|
||||
$promo = $this->di['db']->getExistingModelById('Promo', $cart->promo_id, 'Promo not found.');
|
||||
$this->usePromo($promo);
|
||||
|
||||
//set promo info for later use
|
||||
// set promo info for later use
|
||||
$order->promo_recurring = $promo->recurring;
|
||||
$order->promo_used = 1;
|
||||
$order->promo_used = 1;
|
||||
$this->di['db']->store($order);
|
||||
}
|
||||
|
||||
$orderService = $this->di['mod_service']('order');
|
||||
$orderService->saveStatusChange($order, 'Order created');
|
||||
|
||||
$invoice_items[] = array(
|
||||
'title' => $order->title,
|
||||
'price' => $order->price,
|
||||
$invoice_items[] = [
|
||||
'title' => $order->title,
|
||||
'price' => $order->price,
|
||||
'quantity' => $order->quantity,
|
||||
'unit' => $order->unit,
|
||||
'period' => $order->period,
|
||||
'taxed' => $taxed,
|
||||
'type' => \Model_InvoiceItem::TYPE_ORDER,
|
||||
'rel_id' => $order->id,
|
||||
'task' => \Model_InvoiceItem::TASK_ACTIVATE,
|
||||
);
|
||||
'unit' => $order->unit,
|
||||
'period' => $order->period,
|
||||
'taxed' => $taxed,
|
||||
'type' => \Model_InvoiceItem::TYPE_ORDER,
|
||||
'rel_id' => $order->id,
|
||||
'task' => \Model_InvoiceItem::TASK_ACTIVATE,
|
||||
];
|
||||
|
||||
if($order->discount > 0){
|
||||
$invoice_items[] = array(
|
||||
'title' => __('Discount: :product', array(':product' => $order->title)),
|
||||
'price' => $order->discount * -1,
|
||||
if ($order->discount > 0) {
|
||||
$invoice_items[] = [
|
||||
'title' => __('Discount: :product', [':product' => $order->title]),
|
||||
'price' => $order->discount * -1,
|
||||
'quantity' => 1,
|
||||
'unit' => 'discount',
|
||||
'rel_id' => $order->id,
|
||||
'taxed' => $taxed,
|
||||
);
|
||||
'unit' => 'discount',
|
||||
'rel_id' => $order->id,
|
||||
'taxed' => $taxed,
|
||||
];
|
||||
}
|
||||
|
||||
if ($item['setup_price'] > 0) {
|
||||
$setup_price = ($item['setup_price'] * $currency->conversion_rate) - ($item['discount_setup'] * $currency->conversion_rate);
|
||||
$invoice_items[] = array(
|
||||
'title' => __(':product setup', array(':product' => $order->title)),
|
||||
'price' => $setup_price,
|
||||
$setup_price = ($item['setup_price'] * $currency->conversion_rate) - ($item['discount_setup'] * $currency->conversion_rate);
|
||||
$invoice_items[] = [
|
||||
'title' => __(':product setup', [':product' => $order->title]),
|
||||
'price' => $setup_price,
|
||||
'quantity' => 1,
|
||||
'unit' => 'service',
|
||||
'taxed' => $taxed,
|
||||
);
|
||||
'unit' => 'service',
|
||||
'taxed' => $taxed,
|
||||
];
|
||||
}
|
||||
|
||||
//define master order to be returned
|
||||
// define master order to be returned
|
||||
if (null === $master_order) {
|
||||
$master_order = $order;
|
||||
}
|
||||
|
||||
$i++;
|
||||
++$i;
|
||||
}
|
||||
|
||||
if ($ca['total'] > 0) { //crete invoice if order total > 0
|
||||
|
||||
$invoiceService = $this->di['mod_service']('Invoice');
|
||||
$invoiceModel = $invoiceService->prepareInvoice($client, array('client_id' => $client->id, 'items' => $invoice_items, 'gateway_id' => $gateway_id));
|
||||
if ($ca['total'] > 0) { // crete invoice if order total > 0
|
||||
$invoiceService = $this->di['mod_service']('Invoice');
|
||||
$invoiceModel = $invoiceService->prepareInvoice($client, ['client_id' => $client->id, 'items' => $invoice_items, 'gateway_id' => $gateway_id]);
|
||||
|
||||
$clientBalanceService = $this->di['mod_service']('Client', 'Balance');
|
||||
$balanceAmount = $clientBalanceService->getClientBalance($client);
|
||||
$useCredits = $balanceAmount >= $ca['total'];
|
||||
|
||||
$invoiceService->approveInvoice($invoiceModel, array('id' => $invoiceModel->id, 'use_credits' => $useCredits));
|
||||
$invoiceService->approveInvoice($invoiceModel, ['id' => $invoiceModel->id, 'use_credits' => $useCredits]);
|
||||
|
||||
if ($invoiceModel->status == \Model_Invoice::STATUS_UNPAID) {
|
||||
if (\Model_Invoice::STATUS_UNPAID == $invoiceModel->status) {
|
||||
foreach ($orders as $order) {
|
||||
$order->unpaid_invoice_id = $invoiceModel->id;
|
||||
$this->di['db']->store($order);
|
||||
@@ -618,51 +614,50 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
}
|
||||
|
||||
//activate orders if product is setup to be activated after order place or order total is $0
|
||||
// activate orders if product is setup to be activated after order place or order total is $0
|
||||
$orderService = $this->di['mod_service']('Order');
|
||||
$ids = array();
|
||||
$ids = [];
|
||||
foreach ($orders as $order) {
|
||||
$ids[] = $order->id;
|
||||
$oa = $orderService->toApiArray($order, false, $client);
|
||||
$oa = $orderService->toApiArray($order, false, $client);
|
||||
$product = $this->di['db']->getExistingModelById('Product', $oa['product_id']);
|
||||
try {
|
||||
if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER){
|
||||
if (\Model_ProductTable::SETUP_AFTER_ORDER == $product->setup) {
|
||||
$orderService->activateOrder($order);
|
||||
}
|
||||
|
||||
if ($ca['total'] <= 0 && $product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $oa['total'] - $oa['discount'] <= 0){
|
||||
if ($ca['total'] <= 0 && \Model_ProductTable::SETUP_AFTER_PAYMENT == $product->setup && $oa['total'] - $oa['discount'] <= 0) {
|
||||
$orderService->activateOrder($order);
|
||||
}
|
||||
|
||||
if ($ca['total'] > 0 && $product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $invoiceModel->status == \Model_Invoice::STATUS_PAID ){
|
||||
if ($ca['total'] > 0 && \Model_ProductTable::SETUP_AFTER_PAYMENT == $product->setup && \Model_Invoice::STATUS_PAID == $invoiceModel->status) {
|
||||
$orderService->activateOrder($order);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
$status = 'error';
|
||||
$notes = 'Order could not be activated after checkout due to error: ' . $e->getMessage();
|
||||
$notes = 'Order could not be activated after checkout due to error: '.$e->getMessage();
|
||||
$orderService->orderStatusAdd($order, $status, $notes);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
$master_order,
|
||||
isset($invoiceModel) ? $invoiceModel : null,
|
||||
$invoiceModel ?? null,
|
||||
$ids,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function usePromo(\Model_Promo $promo)
|
||||
{
|
||||
$promo->used++;
|
||||
++$promo->used;
|
||||
$promo->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($promo);
|
||||
}
|
||||
|
||||
public function findActivePromoByCode($code)
|
||||
{
|
||||
return $this->di['db']->findOne('Promo', 'code = :code AND active = 1 ORDER BY id ASC', array(':code' => $code));
|
||||
return $this->di['db']->findOne('Promo', 'code = :code AND active = 1 ORDER BY id ASC', [':code' => $code]);
|
||||
}
|
||||
|
||||
private function getItemPrice(\Model_CartProduct $model)
|
||||
@@ -670,6 +665,7 @@ class Service implements InjectionAwareInterface
|
||||
$product = $this->di['db']->load('Product', $model->product_id);
|
||||
$config = $this->getItemConfig($model);
|
||||
$repo = $product->getTable();
|
||||
|
||||
return $repo->getProductPrice($product, $config);
|
||||
}
|
||||
|
||||
@@ -678,15 +674,14 @@ class Service implements InjectionAwareInterface
|
||||
$product = $this->di['db']->load('Product', $model->product_id);
|
||||
$config = $this->getItemConfig($model);
|
||||
$repo = $product->getTable();
|
||||
|
||||
return $repo->getProductSetupPrice($product, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function checks if product is related to other products in cart
|
||||
* If relation exists then count discount for this
|
||||
* If relation exists then count discount for this.
|
||||
*
|
||||
* @param \Model_Cart $cart
|
||||
* @param \Model_CartProduct $model
|
||||
* @return number
|
||||
*/
|
||||
protected function getRelatedItemsDiscount(\Model_Cart $cart, \Model_CartProduct $model)
|
||||
@@ -696,16 +691,17 @@ class Service implements InjectionAwareInterface
|
||||
$config = $this->getItemConfig($model);
|
||||
|
||||
$discount = 0;
|
||||
if(method_exists($repo, 'getRelatedDiscount')) {
|
||||
$list = array();
|
||||
if (method_exists($repo, 'getRelatedDiscount')) {
|
||||
$list = [];
|
||||
$products = $this->getCartProducts($cart);
|
||||
foreach($products as $p) {
|
||||
foreach ($products as $p) {
|
||||
$item = $this->di['db']->toArray($p);
|
||||
$item['config'] = $this->getItemConfig($p);
|
||||
$list[] = $item;
|
||||
}
|
||||
$discount = $repo->getRelatedDiscount($list, $product, $config);
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
|
||||
@@ -714,10 +710,10 @@ class Service implements InjectionAwareInterface
|
||||
$product = $this->di['db']->load('Product', $model->product_id);
|
||||
$config = $this->getItemConfig($model);
|
||||
$service = $product->getService();
|
||||
if(method_exists($service, 'getCartProductTitle')) {
|
||||
if (method_exists($service, 'getCartProductTitle')) {
|
||||
return $service->getCartProductTitle($product, $config);
|
||||
} else {
|
||||
return __(':product_title', array(':product_title'=>$product->title));
|
||||
return __(':product_title', [':product_title' => $product->title]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -726,6 +722,7 @@ class Service implements InjectionAwareInterface
|
||||
$product = $this->di['db']->load('Product', $model->product_id);
|
||||
$repo = $this->di['mod_service']('product');
|
||||
$config = $this->getItemConfig($model);
|
||||
|
||||
return $repo->getProductDiscount($product, $promo, $config);
|
||||
}
|
||||
|
||||
@@ -741,33 +738,34 @@ class Service implements InjectionAwareInterface
|
||||
$config = $this->getItemConfig($model);
|
||||
$setup = $repo->getProductSetupPrice($product, $config);
|
||||
$price = $repo->getProductPrice($product, $config);
|
||||
$qty = $this->di['array_get']($config, 'quantity', 1) ;
|
||||
$qty = $this->di['array_get']($config, 'quantity', 1);
|
||||
|
||||
list ($discount_price, $discount_setup) = $this->getProductDiscount($model, $setup);
|
||||
[$discount_price, $discount_setup] = $this->getProductDiscount($model, $setup);
|
||||
|
||||
$discount_total = $discount_price + $discount_setup;
|
||||
|
||||
$subtotal = ($price * $qty);
|
||||
if(abs($discount_total) > ($subtotal + $setup) ) {
|
||||
$subtotal = ($price * $qty);
|
||||
if (abs($discount_total) > ($subtotal + $setup)) {
|
||||
$discount_total = $subtotal;
|
||||
$discount_price = $subtotal;
|
||||
}
|
||||
|
||||
$data = array_merge($config, array(
|
||||
'id' => $model->id,
|
||||
'product_id' => $product->id,
|
||||
'form_id' => $product->form_id,
|
||||
'title' => $this->getItemTitle($model),
|
||||
'type' => $product->type,
|
||||
'quantity' => $qty,
|
||||
'unit' => $repo->getUnit($product),
|
||||
'price' => $price,
|
||||
'setup_price' => $setup,
|
||||
'discount' => $discount_total,
|
||||
'discount_price'=> $discount_price,
|
||||
'discount_setup'=> $discount_setup,
|
||||
'total' => $subtotal,
|
||||
));
|
||||
$data = array_merge($config, [
|
||||
'id' => $model->id,
|
||||
'product_id' => $product->id,
|
||||
'form_id' => $product->form_id,
|
||||
'title' => $this->getItemTitle($model),
|
||||
'type' => $product->type,
|
||||
'quantity' => $qty,
|
||||
'unit' => $repo->getUnit($product),
|
||||
'price' => $price,
|
||||
'setup_price' => $setup,
|
||||
'discount' => $discount_total,
|
||||
'discount_price' => $discount_price,
|
||||
'discount_setup' => $discount_setup,
|
||||
'total' => $subtotal,
|
||||
]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -776,15 +774,16 @@ class Service implements InjectionAwareInterface
|
||||
$cart = $this->di['db']->load('Cart', $cartProduct->cart_id);
|
||||
$discount_price = $this->getRelatedItemsDiscount($cart, $cartProduct);
|
||||
$discount_setup = 0; // discount for setup price
|
||||
if($cart->promo_id) {
|
||||
if ($cart->promo_id) {
|
||||
$promo = $this->di['db']->getExistingModelById('Promo', $cart->promo_id, 'Promo not found');
|
||||
//Promo discount should override related item discount
|
||||
// Promo discount should override related item discount
|
||||
$discount_price = $this->getItemPromoDiscount($cartProduct, $promo);
|
||||
|
||||
if($promo->freesetup) {
|
||||
if ($promo->freesetup) {
|
||||
$discount_setup = $setup;
|
||||
}
|
||||
}
|
||||
return array($discount_price, $discount_setup);
|
||||
|
||||
return [$discount_price, $discount_setup];
|
||||
}
|
||||
}
|
||||
}
|
||||
+187
-172
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Client management
|
||||
* Client management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Client\Api;
|
||||
@@ -19,7 +19,7 @@ namespace Box\Mod\Client\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of clients
|
||||
* Get list of clients.
|
||||
*
|
||||
* @optional string $status - Filters client by status. Available options: active, suspended, canceled
|
||||
*
|
||||
@@ -28,10 +28,10 @@ class Admin extends \Api_Abstract
|
||||
public function get_list($data)
|
||||
{
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
|
||||
foreach($pager['list'] as $key => $clientArr){
|
||||
foreach ($pager['list'] as $key => $clientArr) {
|
||||
$client = $this->di['db']->getExistingModelById('Client', $clientArr['id'], 'Client not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($client, true, $this->getIdentity());
|
||||
}
|
||||
@@ -40,34 +40,36 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get clients index
|
||||
* Get clients index.
|
||||
*
|
||||
* @return array - list of clients in id => full name pair
|
||||
*/
|
||||
public function get_pairs($data)
|
||||
{
|
||||
$service = $this->di['mod_service']('client');
|
||||
|
||||
return $service->getPairs($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client by id or email. Email is also unique in database
|
||||
* Get client by id or email. Email is also unique in database.
|
||||
*
|
||||
* @param int $id - client ID
|
||||
*
|
||||
*
|
||||
* @optional string $email - client email
|
||||
*
|
||||
*
|
||||
* @return array - client details
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
$client = $service->get($data);
|
||||
|
||||
return $service->toApiArray($client, true, $this->getIdentity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Login to clients area with client id
|
||||
* Login to clients area with client id.
|
||||
*
|
||||
* @param int $id - client ID
|
||||
*
|
||||
@@ -75,9 +77,9 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function login($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'ID required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found');
|
||||
@@ -88,15 +90,16 @@ class Admin extends \Api_Abstract
|
||||
$session = $this->di['session'];
|
||||
$session->set('client_id', $client->id);
|
||||
$this->di['logger']->info('Logged in as client #%s', $client->id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new client
|
||||
* Creates new client.
|
||||
*
|
||||
* @param string $email - client email, must not be registered on system
|
||||
* @param string $email - client email, must not be registered on system
|
||||
* @param string $first_name - client first name
|
||||
*
|
||||
*
|
||||
* @optional string $password - client password
|
||||
* @optional string $auth_type - client authorization type. Default null
|
||||
* @optional string $last_name - client last name
|
||||
@@ -134,22 +137,22 @@ class Admin extends \Api_Abstract
|
||||
* @optional string $custom_8 - Custom field 8
|
||||
* @optional string $custom_9 - Custom field 9
|
||||
* @optional string $custom_10 - Custom field 10
|
||||
*
|
||||
*
|
||||
* @return int - client id
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
$required = array(
|
||||
'email' => 'Email required',
|
||||
$required = [
|
||||
'email' => 'Email required',
|
||||
'first_name' => 'First name is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$validator = $this->di['validator'];
|
||||
$validator->isEmailValid($data['email']);
|
||||
|
||||
$service = $this->getService();
|
||||
if($service->emailAreadyRegistered($data['email'])) {
|
||||
if ($service->emailAreadyRegistered($data['email'])) {
|
||||
throw new \Box_Exception('Email is already registered.');
|
||||
}
|
||||
|
||||
@@ -157,7 +160,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes client from system
|
||||
* Deletes client from system.
|
||||
*
|
||||
* @param string $id - client ID
|
||||
*
|
||||
@@ -165,28 +168,29 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Client id is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found');
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminClientDelete', 'params'=>array('id'=>$model->id)));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminClientDelete', 'params' => ['id' => $model->id]]);
|
||||
|
||||
$id = $model->id;
|
||||
$this->getService()->remove($model);
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminClientDelete', 'params'=>array('id'=>$id)));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminClientDelete', 'params' => ['id' => $id]]);
|
||||
|
||||
$this->di['logger']->info('Removed client #%s', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update client profile
|
||||
* Update client profile.
|
||||
*
|
||||
* @param string $id - client ID
|
||||
*
|
||||
*
|
||||
* @optional string $email - client email
|
||||
* @optional string $first_name - client first_name
|
||||
* @optional string $last_name - client last_name
|
||||
@@ -221,72 +225,72 @@ class Admin extends \Api_Abstract
|
||||
* @optional string $custom_8 - Custom field 8
|
||||
* @optional string $custom_9 - Custom field 9
|
||||
* @optional string $custom_10 - Custom field 10
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update($data = array())
|
||||
public function update($data = [])
|
||||
{
|
||||
$required = array('id' => 'Id required');
|
||||
$required = ['id' => 'Id required'];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$client = $this->di['db']->getExistingModelById('Client', $this->di['array_get']($data, 'id'), 'Client not found');
|
||||
|
||||
$service = $this->di['mod_service']('client');
|
||||
|
||||
if(!is_null($this->di['array_get']($data, 'email'))) {
|
||||
$email = $this->di['array_get']($data, 'email');
|
||||
if (!is_null($this->di['array_get']($data, 'email'))) {
|
||||
$email = $this->di['array_get']($data, 'email');
|
||||
$this->di['validator']->isEmailValid($email);
|
||||
if($service->emailAreadyRegistered($email, $client)) {
|
||||
if ($service->emailAreadyRegistered($email, $client)) {
|
||||
throw new \Box_Exception('Can not change email. It is already registered.');
|
||||
}
|
||||
}
|
||||
$this->di['validator']->isBirthdayValid($this->di['array_get']($data, 'birthday'));
|
||||
|
||||
if($this->di['array_get']($data, 'currency') && $service->canChangeCurrency($client, $this->di['array_get']($data, 'currency'))) {
|
||||
if ($this->di['array_get']($data, 'currency') && $service->canChangeCurrency($client, $this->di['array_get']($data, 'currency'))) {
|
||||
$client->currency = $this->di['array_get']($data, 'currency', $client->currency);
|
||||
}
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminClientUpdate', 'params'=>$data));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminClientUpdate', 'params' => $data]);
|
||||
|
||||
$phoneCC = $this->di['array_get']($data, 'phone_cc', $client->phone_cc);
|
||||
if(!empty($phoneCC)){
|
||||
if (!empty($phoneCC)) {
|
||||
$client->phone_cc = intval($phoneCC);
|
||||
}
|
||||
|
||||
$client->email = $this->di['array_get']($data, 'email', $client->email);
|
||||
$client->first_name = $this->di['array_get']($data, 'first_name', $client->first_name);
|
||||
$client->last_name = $this->di['array_get']($data, 'last_name', $client->last_name);
|
||||
$client->aid = $this->di['array_get']($data, 'aid', $client->aid);
|
||||
$client->gender = $this->di['array_get']($data, 'gender', $client->gender);
|
||||
$client->birthday = $this->di['array_get']($data, 'birthday', $client->birthday);
|
||||
$client->company = $this->di['array_get']($data, 'company', $client->company);
|
||||
$client->company_vat = $this->di['array_get']($data, 'company_vat', $client->company_vat);
|
||||
$client->address_1 = $this->di['array_get']($data, 'address_1', $client->address_1);
|
||||
$client->address_2 = $this->di['array_get']($data, 'address_2', $client->address_2);
|
||||
$client->phone = $this->di['array_get']($data, 'phone', $client->phone);
|
||||
$client->document_type = $this->di['array_get']($data, 'document_type', $client->document_type);
|
||||
$client->document_nr = $this->di['array_get']($data, 'document_nr', $client->document_nr);
|
||||
$client->notes = $this->di['array_get']($data, 'notes', $client->notes);
|
||||
$client->country = $this->di['array_get']($data, 'country', $client->country);
|
||||
$client->postcode = $this->di['array_get']($data, 'postcode', $client->postcode);
|
||||
$client->state = $this->di['array_get']($data, 'state', $client->state);
|
||||
$client->city = $this->di['array_get']($data, 'city', $client->city);
|
||||
$client->email = $this->di['array_get']($data, 'email', $client->email);
|
||||
$client->first_name = $this->di['array_get']($data, 'first_name', $client->first_name);
|
||||
$client->last_name = $this->di['array_get']($data, 'last_name', $client->last_name);
|
||||
$client->aid = $this->di['array_get']($data, 'aid', $client->aid);
|
||||
$client->gender = $this->di['array_get']($data, 'gender', $client->gender);
|
||||
$client->birthday = $this->di['array_get']($data, 'birthday', $client->birthday);
|
||||
$client->company = $this->di['array_get']($data, 'company', $client->company);
|
||||
$client->company_vat = $this->di['array_get']($data, 'company_vat', $client->company_vat);
|
||||
$client->address_1 = $this->di['array_get']($data, 'address_1', $client->address_1);
|
||||
$client->address_2 = $this->di['array_get']($data, 'address_2', $client->address_2);
|
||||
$client->phone = $this->di['array_get']($data, 'phone', $client->phone);
|
||||
$client->document_type = $this->di['array_get']($data, 'document_type', $client->document_type);
|
||||
$client->document_nr = $this->di['array_get']($data, 'document_nr', $client->document_nr);
|
||||
$client->notes = $this->di['array_get']($data, 'notes', $client->notes);
|
||||
$client->country = $this->di['array_get']($data, 'country', $client->country);
|
||||
$client->postcode = $this->di['array_get']($data, 'postcode', $client->postcode);
|
||||
$client->state = $this->di['array_get']($data, 'state', $client->state);
|
||||
$client->city = $this->di['array_get']($data, 'city', $client->city);
|
||||
|
||||
$client->status = $this->di['array_get']($data, 'status', $client->status);
|
||||
$client->status = $this->di['array_get']($data, 'status', $client->status);
|
||||
$client->email_approved = $this->di['array_get']($data, 'email_approved', $client->email_approved);
|
||||
$client->tax_exempt = $this->di['array_get']($data, 'tax_exempt', $client->tax_exempt);
|
||||
$client->created_at = $this->di['array_get']($data, 'created_at', $client->created_at);
|
||||
$client->tax_exempt = $this->di['array_get']($data, 'tax_exempt', $client->tax_exempt);
|
||||
$client->created_at = $this->di['array_get']($data, 'created_at', $client->created_at);
|
||||
|
||||
$client->custom_1 = $this->di['array_get']($data, 'custom_1', $client->custom_1);
|
||||
$client->custom_2 = $this->di['array_get']($data, 'custom_2', $client->custom_2);
|
||||
$client->custom_3 = $this->di['array_get']($data, 'custom_3', $client->custom_3);
|
||||
$client->custom_4 = $this->di['array_get']($data, 'custom_4', $client->custom_4);
|
||||
$client->custom_5 = $this->di['array_get']($data, 'custom_5', $client->custom_5);
|
||||
$client->custom_6 = $this->di['array_get']($data, 'custom_6', $client->custom_6);
|
||||
$client->custom_7 = $this->di['array_get']($data, 'custom_7', $client->custom_7);
|
||||
$client->custom_8 = $this->di['array_get']($data, 'custom_8', $client->custom_8);
|
||||
$client->custom_9 = $this->di['array_get']($data, 'custom_9', $client->custom_9);
|
||||
$client->custom_10 = $this->di['array_get']($data, 'custom_10', $client->custom_10);
|
||||
$client->custom_1 = $this->di['array_get']($data, 'custom_1', $client->custom_1);
|
||||
$client->custom_2 = $this->di['array_get']($data, 'custom_2', $client->custom_2);
|
||||
$client->custom_3 = $this->di['array_get']($data, 'custom_3', $client->custom_3);
|
||||
$client->custom_4 = $this->di['array_get']($data, 'custom_4', $client->custom_4);
|
||||
$client->custom_5 = $this->di['array_get']($data, 'custom_5', $client->custom_5);
|
||||
$client->custom_6 = $this->di['array_get']($data, 'custom_6', $client->custom_6);
|
||||
$client->custom_7 = $this->di['array_get']($data, 'custom_7', $client->custom_7);
|
||||
$client->custom_8 = $this->di['array_get']($data, 'custom_8', $client->custom_8);
|
||||
$client->custom_9 = $this->di['array_get']($data, 'custom_9', $client->custom_9);
|
||||
$client->custom_10 = $this->di['array_get']($data, 'custom_10', $client->custom_10);
|
||||
|
||||
$client->client_group_id = $this->di['array_get']($data, 'group_id', $client->client_group_id);
|
||||
$client->company_number = $this->di['array_get']($data, 'company_number', $client->company_number);
|
||||
@@ -295,75 +299,77 @@ class Admin extends \Api_Abstract
|
||||
|
||||
$client->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($client);
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminClientUpdate', 'params'=>array('id'=>$client->id)));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminClientUpdate', 'params' => ['id' => $client->id]]);
|
||||
|
||||
$this->di['logger']->info('Updated client #%s profile', $client->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change client password
|
||||
* Change client password.
|
||||
*
|
||||
* @param int $id - Client ID
|
||||
* @param string $password - new client password
|
||||
* @param int $id - Client ID
|
||||
* @param string $password - new client password
|
||||
* @param string $password_confirm - repeat same new client password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function change_password($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'ID required',
|
||||
'password' => 'Password required',
|
||||
$required = [
|
||||
'id' => 'ID required',
|
||||
'password' => 'Password required',
|
||||
'password_confirm' => 'Password confirmation required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if($data['password'] != $data['password_confirm']) {
|
||||
if ($data['password'] != $data['password_confirm']) {
|
||||
throw new \Box_Exception('Passwords do not match');
|
||||
}
|
||||
|
||||
$client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found');
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminClientPasswordChange', 'params'=>$data));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminClientPasswordChange', 'params' => $data]);
|
||||
|
||||
$client->pass = $this->di['password']->hashIt($data['password']);
|
||||
$client->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($client);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminClientPasswordChange', 'params'=>array('id'=>$client->id, 'password'=>$data['password'])));
|
||||
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminClientPasswordChange', 'params' => ['id' => $client->id, 'password' => $data['password']]]);
|
||||
|
||||
$this->di['logger']->info('Changed client #%s password', $client->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of client payments
|
||||
* Returns list of client payments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balance_get_list($data)
|
||||
{
|
||||
$service = $this->di['mod_service']('Client', 'Balance');
|
||||
list($q, $params) = $service->getSearchQuery($data);
|
||||
[$q, $params] = $service->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($q, $params, $per_page);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($q, $params, $per_page);
|
||||
|
||||
foreach($pager['list'] as $key => $item){
|
||||
$pager['list'][$key] = array(
|
||||
'id' => $item['id'],
|
||||
'description' => $item['description'],
|
||||
'amount' => $item['amount'],
|
||||
'currency' => $item['currency'],
|
||||
'created_at' => $item['created_at'],
|
||||
);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$pager['list'][$key] = [
|
||||
'id' => $item['id'],
|
||||
'description' => $item['description'],
|
||||
'amount' => $item['amount'],
|
||||
'currency' => $item['currency'],
|
||||
'created_at' => $item['created_at'],
|
||||
];
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove row from clients balance
|
||||
* Remove row from clients balance.
|
||||
*
|
||||
* @param int $id - Balance line id
|
||||
*
|
||||
@@ -371,13 +377,13 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function balance_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Client ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('ClientBalance', $data['id'], 'Balance line not found');
|
||||
|
||||
|
||||
$id = $model->id;
|
||||
$client_id = $model->client_id;
|
||||
$amount = $model->amount;
|
||||
@@ -385,16 +391,17 @@ class Admin extends \Api_Abstract
|
||||
$this->di['db']->trash($model);
|
||||
|
||||
$this->di['logger']->info('Removed line %s from client #%s balance for %s', $id, $client_id, $amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds funds to clients balance
|
||||
* Adds funds to clients balance.
|
||||
*
|
||||
* @param int $id - Client ID
|
||||
* @param int $amount - Amount of clients currency to added to balance
|
||||
* @param int $id - Client ID
|
||||
* @param int $amount - Amount of clients currency to added to balance
|
||||
* @param int $description - Description of this transaction
|
||||
*
|
||||
*
|
||||
* @optional string $type - Related item type
|
||||
* @optional string $rel_id - Related item id
|
||||
*
|
||||
@@ -402,22 +409,23 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function balance_add_funds($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'Client ID required',
|
||||
'amount' => 'Amount is required',
|
||||
$required = [
|
||||
'id' => 'Client ID required',
|
||||
'amount' => 'Amount is required',
|
||||
'description' => 'Description is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found');
|
||||
|
||||
$service = $this->di['mod_service']('client');
|
||||
$service->addFunds($client, $data['amount'], $data['description'], $data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove password reminders which were not confirmed in 2 hours
|
||||
* Remove password reminders which were not confirmed in 2 hours.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -425,171 +433,179 @@ class Admin extends \Api_Abstract
|
||||
{
|
||||
$service = $this->di['mod_service']('client');
|
||||
$expired = $service->getExpiredPasswordReminders();
|
||||
foreach($expired as $model) {
|
||||
foreach ($expired as $model) {
|
||||
$this->di['db']->trash($model);
|
||||
}
|
||||
|
||||
|
||||
$this->di['logger']->info('Executed action to delete expired clients password reminders');
|
||||
return TRUE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of clients logins history
|
||||
* Get list of clients logins history.
|
||||
*
|
||||
* @optional int $client_id - filter by client
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function login_history_get_list($data)
|
||||
{
|
||||
list($q, $params) = $this->getService()->getHistorySearchQuery($data);
|
||||
[$q, $params] = $this->getService()->getHistorySearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($q, $params, $per_page);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($q, $params, $per_page);
|
||||
|
||||
foreach($pager['list'] as $key => $item){
|
||||
$pager['list'][$key] = array(
|
||||
'id' => $item['id'],
|
||||
'ip' => $item['ip'],
|
||||
'created_at' => $item['created_at'],
|
||||
'client' => array(
|
||||
'id' => $item['client_id'],
|
||||
'first_name' => $item['first_name'],
|
||||
'last_name' => $item['last_name'],
|
||||
'email' => $item['email'],
|
||||
)
|
||||
);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$pager['list'][$key] = [
|
||||
'id' => $item['id'],
|
||||
'ip' => $item['ip'],
|
||||
'created_at' => $item['created_at'],
|
||||
'client' => [
|
||||
'id' => $item['client_id'],
|
||||
'first_name' => $item['first_name'],
|
||||
'last_name' => $item['last_name'],
|
||||
'email' => $item['email'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove log entry form clients logins history
|
||||
*
|
||||
* Remove log entry form clients logins history.
|
||||
*
|
||||
* @param int $id - Log entry ID
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function login_history_delete($data)
|
||||
{
|
||||
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Id not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
$model = $this->di['db']->getExistingModelById('ActivityClientHistory', $data['id']);
|
||||
|
||||
if(!$model instanceof \Model_ActivityClientHistory) {
|
||||
if (!$model instanceof \Model_ActivityClientHistory) {
|
||||
throw new \Box_Exception('Event not found');
|
||||
}
|
||||
$this->di['db']->trash($model);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return client statuses with counter.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_statuses($data)
|
||||
{
|
||||
$service = $this->di['mod_service']('client');
|
||||
|
||||
return $service->counter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return client groups. Id and title pairs
|
||||
*
|
||||
* Return client groups. Id and title pairs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function group_get_pairs($data)
|
||||
{
|
||||
$service = $this->di['mod_service']('client');
|
||||
|
||||
return $service->getGroupPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new clients group
|
||||
*
|
||||
* Create new clients group.
|
||||
*
|
||||
* @param string $title - New group title
|
||||
*
|
||||
*
|
||||
* @return int $id - newly created group id
|
||||
*/
|
||||
public function group_create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'title' => 'Group title is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
return $this->getService()->createGroup($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update client group
|
||||
*
|
||||
* Update client group.
|
||||
*
|
||||
* @param int $id - client group ID
|
||||
* @optional string $title - new group title
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* @throws ErrorException
|
||||
*
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function group_update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Group id is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('ClientGroup', $data['id'], 'Group not found');
|
||||
|
||||
|
||||
$model->title = $this->di['array_get']($data, 'title', $model->title);
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete client group
|
||||
*
|
||||
* Delete client group.
|
||||
*
|
||||
* @param int $id - client group ID
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* @throws ErrorException
|
||||
*
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function group_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Group id is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('ClientGroup', $data['id'], 'Group not found');
|
||||
|
||||
return $this->getService()->deleteGroup($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client group details
|
||||
*
|
||||
* Get client group details.
|
||||
*
|
||||
* @param int $id - client group ID
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* @throws ErrorException
|
||||
*
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function group_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Group id is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('ClientGroup', $data['id'], 'Group not found');
|
||||
|
||||
|
||||
return $this->di['db']->toArray($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes clients with given IDs
|
||||
* Deletes clients with given IDs.
|
||||
*
|
||||
* @param array $ids - IDs for deletion
|
||||
*
|
||||
@@ -597,21 +613,20 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function batch_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ids' => 'IDs not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
foreach ($data['ids'] as $id) {
|
||||
$this->delete(array('id' => $id));
|
||||
$this->delete(['id' => $id]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes client login logs with given IDs
|
||||
* Deletes client login logs with given IDs.
|
||||
*
|
||||
* @param array $ids - IDs for deletion
|
||||
*
|
||||
@@ -619,15 +634,15 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function batch_delete_log($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ids' => 'IDs not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
foreach ($data['ids'] as $id) {
|
||||
$this->login_history_delete(array('id' => $id));
|
||||
$this->login_history_delete(['id' => $id]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*Client management
|
||||
*Client management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Client\Api;
|
||||
@@ -19,7 +19,8 @@ namespace Box\Mod\Client\Api;
|
||||
class Client extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get currently logged in client details
|
||||
* Get currently logged in client details.
|
||||
*
|
||||
* @deprecated moved to profile module
|
||||
*/
|
||||
public function get()
|
||||
@@ -28,8 +29,8 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Update currencty logged in client details
|
||||
*
|
||||
* Update currencty logged in client details.
|
||||
*
|
||||
* @optional string $email - new client email. Must not exist on system
|
||||
* @optional string $last_name - last name
|
||||
* @optional string $aid - Alternative id. Usually used by import tools.
|
||||
@@ -60,165 +61,177 @@ class Client extends \Api_Abstract
|
||||
* @optional string $custom_8 - Custom field 8
|
||||
* @optional string $custom_9 - Custom field 9
|
||||
* @optional string $custom_10 - Custom field 10
|
||||
*
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @deprecated moved to profile module
|
||||
*/
|
||||
public function update($data = array())
|
||||
public function update($data = [])
|
||||
{
|
||||
$client = $this->getIdentity();
|
||||
|
||||
$event_params = $data;
|
||||
$event_params = $data;
|
||||
$event_params['id'] = $client->id;
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeClientProfileUpdate', 'params'=>$event_params));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeClientProfileUpdate', 'params' => $event_params]);
|
||||
|
||||
$email = $this->di['array_get']($data, 'email', '');
|
||||
if(!empty($email)) {
|
||||
if (!empty($email)) {
|
||||
$this->di['validator']->isEmailValid($email);
|
||||
|
||||
$this->getService()->canChangeEmail($client, $email);
|
||||
|
||||
if($this->getService()->emailAreadyRegistered($email, $client)) {
|
||||
if ($this->getService()->emailAreadyRegistered($email, $client)) {
|
||||
throw new \Box_Exception('Can not change email. It is already registered.');
|
||||
}
|
||||
$client->email = strtolower(trim($email));
|
||||
}
|
||||
|
||||
$phoneCC = $this->di['array_get']($data, 'phone_cc', $client->phone_cc);
|
||||
if(!empty($phoneCC)){
|
||||
if (!empty($phoneCC)) {
|
||||
$client->phone_cc = intval($phoneCC);
|
||||
}
|
||||
|
||||
$client->first_name = $this->di['array_get']($data, 'first_name', $client->first_name);
|
||||
$client->last_name = $this->di['array_get']($data, 'last_name', $client->last_name);
|
||||
$client->gender = $this->di['array_get']($data, 'gender', $client->gender);
|
||||
$client->birthday = $this->di['array_get']($data, 'birthday', $client->birthday);
|
||||
$client->company = $this->di['array_get']($data, 'company', $client->company);
|
||||
$client->company_vat = $this->di['array_get']($data, 'company_vat', $client->company_vat);
|
||||
$client->first_name = $this->di['array_get']($data, 'first_name', $client->first_name);
|
||||
$client->last_name = $this->di['array_get']($data, 'last_name', $client->last_name);
|
||||
$client->gender = $this->di['array_get']($data, 'gender', $client->gender);
|
||||
$client->birthday = $this->di['array_get']($data, 'birthday', $client->birthday);
|
||||
$client->company = $this->di['array_get']($data, 'company', $client->company);
|
||||
$client->company_vat = $this->di['array_get']($data, 'company_vat', $client->company_vat);
|
||||
$client->company_number = $this->di['array_get']($data, 'company_number', $client->company_number);
|
||||
$client->type = $this->di['array_get']($data, 'type', $client->type);
|
||||
$client->address_1 = $this->di['array_get']($data, 'address_1', $client->address_1);
|
||||
$client->address_2 = $this->di['array_get']($data, 'address_2', $client->address_2);
|
||||
$client->phone = $this->di['array_get']($data, 'phone', $client->phone);
|
||||
$client->country = $this->di['array_get']($data, 'country', $client->country);
|
||||
$client->postcode = $this->di['array_get']($data, 'postcode', $client->postcode);
|
||||
$client->city = $this->di['array_get']($data, 'city', $client->city);
|
||||
$client->state = $this->di['array_get']($data, 'state', $client->state);
|
||||
$client->document_type = $this->di['array_get']($data, 'document_type', 'passport');
|
||||
$client->document_nr = $this->di['array_get']($data, 'document_nr', '');
|
||||
$client->notes = $this->di['array_get']($data, 'notes', $client->notes);
|
||||
$client->type = $this->di['array_get']($data, 'type', $client->type);
|
||||
$client->address_1 = $this->di['array_get']($data, 'address_1', $client->address_1);
|
||||
$client->address_2 = $this->di['array_get']($data, 'address_2', $client->address_2);
|
||||
$client->phone = $this->di['array_get']($data, 'phone', $client->phone);
|
||||
$client->country = $this->di['array_get']($data, 'country', $client->country);
|
||||
$client->postcode = $this->di['array_get']($data, 'postcode', $client->postcode);
|
||||
$client->city = $this->di['array_get']($data, 'city', $client->city);
|
||||
$client->state = $this->di['array_get']($data, 'state', $client->state);
|
||||
$client->document_type = $this->di['array_get']($data, 'document_type', 'passport');
|
||||
$client->document_nr = $this->di['array_get']($data, 'document_nr', '');
|
||||
$client->notes = $this->di['array_get']($data, 'notes', $client->notes);
|
||||
|
||||
$client->custom_1 = $this->di['array_get']($data, 'custom_1', $client->custom_1);
|
||||
$client->custom_2 = $this->di['array_get']($data, 'custom_2', $client->custom_2);
|
||||
$client->custom_3 = $this->di['array_get']($data, 'custom_3', $client->custom_3);
|
||||
$client->custom_4 = $this->di['array_get']($data, 'custom_4', $client->custom_4);
|
||||
$client->custom_5 = $this->di['array_get']($data, 'custom_5', $client->custom_5);
|
||||
$client->custom_6 = $this->di['array_get']($data, 'custom_6', $client->custom_6);
|
||||
$client->custom_7 = $this->di['array_get']($data, 'custom_7', $client->custom_7);
|
||||
$client->custom_8 = $this->di['array_get']($data, 'custom_8', $client->custom_8);
|
||||
$client->custom_9 = $this->di['array_get']($data, 'custom_9', $client->custom_9);
|
||||
$client->custom_1 = $this->di['array_get']($data, 'custom_1', $client->custom_1);
|
||||
$client->custom_2 = $this->di['array_get']($data, 'custom_2', $client->custom_2);
|
||||
$client->custom_3 = $this->di['array_get']($data, 'custom_3', $client->custom_3);
|
||||
$client->custom_4 = $this->di['array_get']($data, 'custom_4', $client->custom_4);
|
||||
$client->custom_5 = $this->di['array_get']($data, 'custom_5', $client->custom_5);
|
||||
$client->custom_6 = $this->di['array_get']($data, 'custom_6', $client->custom_6);
|
||||
$client->custom_7 = $this->di['array_get']($data, 'custom_7', $client->custom_7);
|
||||
$client->custom_8 = $this->di['array_get']($data, 'custom_8', $client->custom_8);
|
||||
$client->custom_9 = $this->di['array_get']($data, 'custom_9', $client->custom_9);
|
||||
$client->custom_10 = $this->di['array_get']($data, 'custom_10', $client->custom_10);
|
||||
|
||||
$client->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($client);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterClientProfileUpdate', 'params'=>array('id'=>$client->id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientProfileUpdate', 'params' => ['id' => $client->id]]);
|
||||
|
||||
$this->di['logger']->info('Updated profile');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve current API key
|
||||
* Retrieve current API key.
|
||||
*
|
||||
* @deprecated moved to profile module
|
||||
*/
|
||||
public function api_key_get($data)
|
||||
{
|
||||
$client = $this->getIdentity();
|
||||
|
||||
return $client->api_token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate new API key
|
||||
* Generate new API key.
|
||||
*
|
||||
* @deprecated moved to profile module
|
||||
*/
|
||||
public function api_key_reset($data)
|
||||
{
|
||||
$client = $this->getIdentity();
|
||||
|
||||
|
||||
$client->api_token = $this->di['tools']->generatePassword(32);
|
||||
$client->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($client);
|
||||
|
||||
$this->di['logger']->info('Generated new API key');
|
||||
|
||||
return $client->api_token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change client area password
|
||||
* Change client area password.
|
||||
*
|
||||
* @deprecated moved to profile module
|
||||
*/
|
||||
public function change_password($data)
|
||||
{
|
||||
$required = array(
|
||||
'password' => 'Password required',
|
||||
$required = [
|
||||
'password' => 'Password required',
|
||||
'password_confirm' => 'Password confirmation required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if($data['password'] != $data['password_confirm']) {
|
||||
if ($data['password'] != $data['password_confirm']) {
|
||||
throw new \Box_Exception('Passwords do not match.');
|
||||
}
|
||||
|
||||
$event_params = $data;
|
||||
$event_params['id'] = $this->getIdentity()->id;
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeClientProfilePasswordChange', 'params'=>$event_params));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeClientProfilePasswordChange', 'params' => $event_params]);
|
||||
|
||||
$this->di['validator']->isPasswordStrong($data['password']);
|
||||
|
||||
$client = $this->getIdentity();
|
||||
$client->pass = $this->di['password']->hashIt($data['password']);
|
||||
$this->di['db']->store($client);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterClientProfilePasswordChange', 'params'=>array('id'=>$client->id)));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientProfilePasswordChange', 'params' => ['id' => $client->id]]);
|
||||
|
||||
$this->di['logger']->info('Changed profile password');
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear session and logout
|
||||
* @return boolean
|
||||
* Clear session and logout.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated moved to profile module
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
if($_COOKIE) { // testing env fix
|
||||
$this->di['cookie']->set('BOXCLR', "", time() - 3600, '/');
|
||||
if ($_COOKIE) { // testing env fix
|
||||
$this->di['cookie']->set('BOXCLR', '', time() - 3600, '/');
|
||||
}
|
||||
$this->di['session']->delete('client');
|
||||
$this->di['session']->delete('client_id');
|
||||
$this->di['logger']->info('Logged out');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get payments information
|
||||
* @return array
|
||||
* Get payments information.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balance_get_list($data)
|
||||
{
|
||||
$service = $this->di['mod_service']('Client', 'Balance');
|
||||
$service = $this->di['mod_service']('Client', 'Balance');
|
||||
$data['client_id'] = $this->identity->id;
|
||||
|
||||
list($q, $params) = $service->getSearchQuery($data);
|
||||
[$q, $params] = $service->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($q, $params, $per_page);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$balance = $this->di['db']->getExistingModelById('ClientBalance', $item['id'], 'Balance not found');
|
||||
$balance = $this->di['db']->getExistingModelById('ClientBalance', $item['id'], 'Balance not found');
|
||||
$pager['list'][$key] = $service->toApiArray($balance);
|
||||
}
|
||||
|
||||
@@ -226,12 +239,14 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client balance
|
||||
* Get client balance.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function balance_get_total()
|
||||
{
|
||||
$service = $this->di['mod_service']('Client', 'Balance');
|
||||
|
||||
return $service->getClientBalance($this->identity);
|
||||
}
|
||||
|
||||
@@ -239,5 +254,4 @@ class Client extends \Api_Abstract
|
||||
{
|
||||
return $this->getService()->isClientTaxable($this->identity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Clients API methods
|
||||
* Clients API methods.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Client\Api;
|
||||
@@ -19,15 +19,15 @@ namespace Box\Mod\Client\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Client signup action.
|
||||
*
|
||||
* @param string $email - Email
|
||||
* @param string $first_name - First name
|
||||
* @param string $password - password
|
||||
* Client signup action.
|
||||
*
|
||||
* @param string $email - Email
|
||||
* @param string $first_name - First name
|
||||
* @param string $password - password
|
||||
* @param string $password_confirm - must be same as password
|
||||
*
|
||||
*
|
||||
* @optional bool $auto_login - Auto login client after signup
|
||||
*
|
||||
*
|
||||
* @optional string $last_name - last name
|
||||
* @optional string $aid - Alternative id. Usually used by import tools.
|
||||
* @optional string $gender - Gender - values: male|female
|
||||
@@ -58,23 +58,23 @@ class Guest extends \Api_Abstract
|
||||
* @optional string $custom_9 - Custom field 9
|
||||
* @optional string $custom_10 - Custom field 10
|
||||
*/
|
||||
public function create($data = array())
|
||||
public function create($data = [])
|
||||
{
|
||||
$config = $this->di['mod_config']('client');
|
||||
|
||||
if(isset($config['allow_signup']) && !$config['allow_signup']) {
|
||||
if (isset($config['allow_signup']) && !$config['allow_signup']) {
|
||||
throw new \Box_Exception('New registrations are temporary disabled');
|
||||
}
|
||||
|
||||
$required = array(
|
||||
$required = [
|
||||
'email' => 'Email required',
|
||||
'first_name' => 'First name required',
|
||||
'password' => 'Password required',
|
||||
'password_confirm' => 'Password confirmation required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if($data['password'] != $data['password_confirm']) {
|
||||
if ($data['password'] != $data['password_confirm']) {
|
||||
throw new \Box_Exception('Passwords do not match.');
|
||||
}
|
||||
|
||||
@@ -87,20 +87,20 @@ class Guest extends \Api_Abstract
|
||||
$email = $this->di['array_get']($data, 'email');
|
||||
$this->di['validator']->isEmailValid($email);
|
||||
$email = strtolower(trim($email));
|
||||
if($service->clientAlreadyExists($email)) {
|
||||
if ($service->clientAlreadyExists($email)) {
|
||||
throw new \Box_Exception('Email is already registered. You may want to login instead of registering.');
|
||||
}
|
||||
|
||||
$client = $service->guestCreateClient($data);
|
||||
|
||||
if (isset($config['require_email_confirmation']) && (int)$config['require_email_confirmation'] && !$client->email_approved) {
|
||||
throw new \Box_Exception('Account has been created. Please check your mailbox and confirm email address.', null, 7777);
|
||||
if (isset($config['require_email_confirmation']) && (int) $config['require_email_confirmation'] && !$client->email_approved) {
|
||||
throw new \Box_Exception('Account has been created. Please check your mailbox and confirm email address.', null, 7777);
|
||||
}
|
||||
|
||||
if($this->di['array_get']($data, 'auto_login', 0)) {
|
||||
if ($this->di['array_get']($data, 'auto_login', 0)) {
|
||||
try {
|
||||
$this->login(array('email'=>$client->email, 'password' => $this->di['array_get']($data, 'password')));
|
||||
} catch(\Exception $e) {
|
||||
$this->login(['email' => $client->email, 'password' => $this->di['array_get']($data, 'password')]);
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -109,172 +109,181 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Client login action
|
||||
*
|
||||
* @param string $email - client email
|
||||
* Client login action.
|
||||
*
|
||||
* @param string $email - client email
|
||||
* @param string $password - client password
|
||||
*
|
||||
*
|
||||
* @return array - session data
|
||||
* @throws Box_Exception
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function login($data)
|
||||
{
|
||||
$required = array(
|
||||
'email' => 'Email required',
|
||||
$required = [
|
||||
'email' => 'Email required',
|
||||
'password' => 'Password required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
|
||||
$event_params = $data;
|
||||
$event_params['ip'] = $this->ip;
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeClientLogin', 'params'=>$event_params));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeClientLogin', 'params' => $event_params]);
|
||||
|
||||
$service = $this->getService();
|
||||
$client = $service->authorizeClient($data['email'], $data['password']);
|
||||
if(!$client instanceof \Model_Client ) {
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onEventClientLoginFailed', 'params'=>$event_params));
|
||||
|
||||
throw new \Box_Exception('Please check your login details', array(), 403);
|
||||
if (!$client instanceof \Model_Client) {
|
||||
$this->di['events_manager']->fire(['event' => 'onEventClientLoginFailed', 'params' => $event_params]);
|
||||
|
||||
throw new \Box_Exception('Please check your login details', [], 403);
|
||||
}
|
||||
|
||||
if(isset($data['remember'])) {
|
||||
|
||||
if (isset($data['remember'])) {
|
||||
$email = $data['email'];
|
||||
$cookie_time = (3600 * 24 * 30); // 30 days
|
||||
$this->di['cookie']->set('BOXCLR', 'e='.base64_encode($email).'&p='.base64_encode($client->pass), time() + $cookie_time, '/');
|
||||
}
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterClientLogin', 'params'=>array('id'=>$client->id, 'ip'=>$this->ip)));
|
||||
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientLogin', 'params' => ['id' => $client->id, 'ip' => $this->ip]]);
|
||||
|
||||
$result = $service->toSessionArray($client);
|
||||
$this->di['session']->set('client_id', $client->id);
|
||||
|
||||
$this->di['logger']->info('Client #%s logged in', $client->id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Password reset confirmation email will be sent to email.
|
||||
*
|
||||
*
|
||||
* @param string $email - client email
|
||||
* @return boolean
|
||||
* @throws Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function reset_password($data)
|
||||
{
|
||||
$required = array(
|
||||
'email' => 'Email required',
|
||||
);
|
||||
$required = [
|
||||
'email' => 'Email required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeGuestPasswordResetRequest', 'params'=>$data));
|
||||
|
||||
$c = $this->di['db']->findOne('Client', 'email = ?', array($data['email']));
|
||||
if(!$c instanceof \Model_Client ) {
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeGuestPasswordResetRequest', 'params' => $data]);
|
||||
|
||||
$c = $this->di['db']->findOne('Client', 'email = ?', [$data['email']]);
|
||||
if (!$c instanceof \Model_Client) {
|
||||
throw new \Box_Exception('Email not found in our database');
|
||||
}
|
||||
|
||||
$hash = sha1(time() . uniqid());
|
||||
|
||||
$hash = sha1(time().uniqid());
|
||||
|
||||
$reset = $this->di['db']->dispense('ClientPasswordReset');
|
||||
$reset->client_id = $c->id;
|
||||
$reset->ip = $this->ip;
|
||||
$reset->hash = $hash;
|
||||
$reset->created_at = date('Y-m-d H:i:s');
|
||||
$reset->updated_at = date('Y-m-d H:i:s');
|
||||
$reset->client_id = $c->id;
|
||||
$reset->ip = $this->ip;
|
||||
$reset->hash = $hash;
|
||||
$reset->created_at = date('Y-m-d H:i:s');
|
||||
$reset->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($reset);
|
||||
|
||||
//send email
|
||||
$email = array();
|
||||
// send email
|
||||
$email = [];
|
||||
$email['to_client'] = $c->id;
|
||||
$email['code'] = 'mod_client_password_reset_request';
|
||||
$email['hash'] = $hash;
|
||||
$email['code'] = 'mod_client_password_reset_request';
|
||||
$email['hash'] = $hash;
|
||||
$emailSerivce = $this->di['mod_service']('email');
|
||||
$emailSerivce->sendTemplate($email);
|
||||
|
||||
|
||||
$this->di['logger']->info('Client requested password reset. Sent to email %s', $c->email);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm password reset action
|
||||
*
|
||||
* Confirm password reset action.
|
||||
*
|
||||
* @param string $hash - hash received in email
|
||||
* @return boolean
|
||||
* @throws Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function confirm_reset($data)
|
||||
{
|
||||
$required = array(
|
||||
'hash' => 'Hash required',
|
||||
);
|
||||
$required = [
|
||||
'hash' => 'Hash required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$reset = $this->di['db']->findOne('ClientPasswordReset', 'hash = ?', array($data['hash']));
|
||||
if(!$reset instanceof \Model_ClientPasswordReset) {
|
||||
$reset = $this->di['db']->findOne('ClientPasswordReset', 'hash = ?', [$data['hash']]);
|
||||
if (!$reset instanceof \Model_ClientPasswordReset) {
|
||||
throw new \Box_Exception('The link have expired or you have already confirmed password reset.');
|
||||
}
|
||||
|
||||
$new_pass = substr(md5(time() . uniqid()), 0, 10);
|
||||
|
||||
$new_pass = substr(md5(time().uniqid()), 0, 10);
|
||||
|
||||
$c = $this->di['db']->getExistingModelById('Client', $reset->client_id, 'Client not found');
|
||||
$c->pass = $this->di['password']->hashIt($new_pass);
|
||||
$this->di['db']->store($c);
|
||||
|
||||
//send email
|
||||
$email = array();
|
||||
|
||||
// send email
|
||||
$email = [];
|
||||
$email['to_client'] = $reset->client_id;
|
||||
$email['code'] = 'mod_client_password_reset_approve';
|
||||
$email['password'] = $new_pass;
|
||||
$email['code'] = 'mod_client_password_reset_approve';
|
||||
$email['password'] = $new_pass;
|
||||
$emailService = $this->di['mod_service']('email');
|
||||
$emailService->sendTemplate($email);
|
||||
|
||||
$this->di['db']->trash($reset);
|
||||
$this->di['logger']->info('Client password reset request was approved');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if given vat number is valid EU country VAT number
|
||||
* This method uses http://isvat.appspot.com/ method to validate VAT
|
||||
*
|
||||
* @param string $country - Country CODE: FR - France etc.
|
||||
* @param string $vat - VAT number
|
||||
*
|
||||
* This method uses http://isvat.appspot.com/ method to validate VAT.
|
||||
*
|
||||
* @param string $country - Country CODE: FR - France etc
|
||||
* @param string $vat - VAT number
|
||||
*
|
||||
* @return bool- true if VAT is valid, false if not
|
||||
*/
|
||||
public function is_vat($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'country' => 'Country code',
|
||||
'vat' => 'Country VAT is required',
|
||||
);
|
||||
'vat' => 'Country VAT is required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$cc = $data['country'];
|
||||
$cc = $data['country'];
|
||||
$vatnum = $data['vat'];
|
||||
|
||||
//@todo add new service provider https://vatlayer.com/ check
|
||||
// @todo add new service provider https://vatlayer.com/ check
|
||||
// $url = 'http://isvat.appspot.com/' . rawurlencode($cc) . '/' . rawurlencode($vatnum) . '/';
|
||||
// $result = $this->di['guzzle_client']->get($url);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List of required fields for client registration
|
||||
* List of required fields for client registration.
|
||||
*/
|
||||
public function required()
|
||||
{
|
||||
$config = $this->di['mod_config']('client');
|
||||
return isset($config['required']) ? $config['required'] : array();
|
||||
|
||||
return $config['required'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of custom fields for client registration
|
||||
* Array of custom fields for client registration.
|
||||
*/
|
||||
public function custom_fields()
|
||||
{
|
||||
$config = $this->di['mod_config']('client');
|
||||
return isset($config['custom_fields']) ? $config['custom_fields'] : array();
|
||||
|
||||
return $config['custom_fields'] ?? [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Client\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,92 +34,96 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'group' => array(
|
||||
return [
|
||||
'group' => [
|
||||
'index' => 200,
|
||||
'location' => 'client',
|
||||
'label' => 'Clients',
|
||||
'uri' => $this->di['url']->adminLink('client'),
|
||||
'class' => 'contacts',
|
||||
'class' => 'contacts',
|
||||
'sprite_class' => 'dark-sprite-icon sprite-users',
|
||||
),
|
||||
'subpages' => array(
|
||||
array(
|
||||
],
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'client',
|
||||
'label' => 'Overview',
|
||||
'uri' => $this->di['url']->adminLink('client'),
|
||||
'index' => 100,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'client',
|
||||
'label' => 'Advanced search',
|
||||
'uri' => $this->di['url']->adminLink('client', array('show_filter' => 1)),
|
||||
'uri' => $this->di['url']->adminLink('client', ['show_filter' => 1]),
|
||||
'index' => 200,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'activity',
|
||||
'index' => 900,
|
||||
'index' => 900,
|
||||
'label' => 'Client logins history',
|
||||
'uri' => $this->di['url']->adminLink('client/logins'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/client', 'get_index', array(), get_class($this));
|
||||
$app->get('/client/', 'get_index', array(), get_class($this));
|
||||
$app->get('/client/index', 'get_index', array(), get_class($this));
|
||||
$app->get('/client/login/:id', 'get_login', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/client/manage/:id', 'get_manage', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/client/group/:id', 'get_group', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/client/create', 'get_create', array(), get_class($this));
|
||||
$app->get('/client/logins', 'get_history', array(), get_class($this));
|
||||
$app->get('/client', 'get_index', [], get_class($this));
|
||||
$app->get('/client/', 'get_index', [], get_class($this));
|
||||
$app->get('/client/index', 'get_index', [], get_class($this));
|
||||
$app->get('/client/login/:id', 'get_login', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/client/manage/:id', 'get_manage', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/client/group/:id', 'get_group', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/client/create', 'get_create', [], get_class($this));
|
||||
$app->get('/client/logins', 'get_history', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_client_index');
|
||||
}
|
||||
|
||||
public function get_manage(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$client = $api->client_get(array('id'=>$id));
|
||||
return $app->render('mod_client_manage', array('client'=>$client));
|
||||
$client = $api->client_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_client_manage', ['client' => $client]);
|
||||
}
|
||||
|
||||
public function get_group(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$model = $api->client_group_get(array('id'=>$id));
|
||||
return $app->render('mod_client_group', array('group'=>$model));
|
||||
$model = $api->client_group_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_client_group', ['group' => $model]);
|
||||
}
|
||||
|
||||
|
||||
public function get_history(\Box_App $app)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
|
||||
return $app->render('mod_client_login_history');
|
||||
}
|
||||
|
||||
public function get_login(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$api->client_login(array('id'=>$id));
|
||||
$api->client_login(['id' => $id]);
|
||||
|
||||
$redirect_to = '/';
|
||||
if ($this->di['request']->getQuery('r')) {
|
||||
$r = $this->di['request']->getQuery('r');
|
||||
$redirect_to = '/' . trim($r, '/');
|
||||
$r = $this->di['request']->getQuery('r');
|
||||
$redirect_to = '/'.trim($r, '/');
|
||||
}
|
||||
|
||||
Header( "HTTP/1.1 301 Moved Permanently" );
|
||||
Header( "Location: ".$this->di['tools']->url($redirect_to) );
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
header('Location: '.$this->di['tools']->url($redirect_to));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Client\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,18 +34,19 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
//@deprecated
|
||||
$app->get('/client/me', 'get_profile', array(), get_class($this));
|
||||
// @deprecated
|
||||
$app->get('/client/me', 'get_profile', [], get_class($this));
|
||||
|
||||
$app->get('/client/reset-password-confirm/:hash', 'get_reset_password_confirm', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->get('/client', 'get_client_index', array(), get_class($this));
|
||||
$app->get('/client/logout', 'get_client_logout', array(), get_class($this));
|
||||
$app->get('/client/:page', 'get_client_page', array('page'=>'[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/client/confirm-email/:hash', 'get_client_confirmation', array('page'=>'[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/client/reset-password-confirm/:hash', 'get_reset_password_confirm', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
$app->get('/client', 'get_client_index', [], get_class($this));
|
||||
$app->get('/client/logout', 'get_client_logout', [], get_class($this));
|
||||
$app->get('/client/:page', 'get_client_page', ['page' => '[a-z0-9-]+'], get_class($this));
|
||||
$app->get('/client/confirm-email/:hash', 'get_client_confirmation', ['page' => '[a-z0-9-]+'], get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Box_App $app
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function get_profile(\Box_App $app)
|
||||
@@ -56,6 +56,7 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
/**
|
||||
* @param Box_App $app
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function get_balance(\Box_App $app)
|
||||
@@ -66,6 +67,7 @@ class Client implements \Box\InjectionAwareInterface
|
||||
public function get_client_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_client_logged'];
|
||||
|
||||
return $app->render('mod_client_index');
|
||||
}
|
||||
|
||||
@@ -89,17 +91,17 @@ class Client implements \Box\InjectionAwareInterface
|
||||
{
|
||||
$this->di['is_client_logged'];
|
||||
$template = 'mod_client_'.$page;
|
||||
|
||||
return $app->render($template);
|
||||
}
|
||||
|
||||
public function get_reset_password_confirm(\Box_App $app, $hash)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
'hash' => $hash,
|
||||
);
|
||||
$data = [
|
||||
'hash' => $hash,
|
||||
];
|
||||
$api->client_confirm_reset($data);
|
||||
$app->redirect('/login');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+198
-189
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Client;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -38,32 +37,33 @@ class Service implements InjectionAwareInterface
|
||||
public function approveClientEmailByHash($hash)
|
||||
{
|
||||
$db = $this->di['db'];
|
||||
$result = $db->getRow('SELECT id, client_id FROM extension_meta WHERE extension = "mod_client" AND meta_key = "confirm_email" AND meta_value = :hash', array(':hash'=>$hash));
|
||||
if(!$result) {
|
||||
$result = $db->getRow('SELECT id, client_id FROM extension_meta WHERE extension = "mod_client" AND meta_key = "confirm_email" AND meta_value = :hash', [':hash' => $hash]);
|
||||
if (!$result) {
|
||||
throw new \Box_Exception('Invalid email confirmation link');
|
||||
}
|
||||
$db->exec('UPDATE client SET email_approved = 1 WHERE id = :id', array('id'=>$result['client_id']));
|
||||
$db->exec('DELETE FROM extension_meta WHERE id = :id', array('id'=>$result['id']));
|
||||
$db->exec('UPDATE client SET email_approved = 1 WHERE id = :id', ['id' => $result['client_id']]);
|
||||
$db->exec('DELETE FROM extension_meta WHERE id = :id', ['id' => $result['id']]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function generateEmailConfirmationLink($client_id)
|
||||
{
|
||||
$hash = strtolower($this->di['tools']->generatePassword(50));
|
||||
$db = $this->di['db'];
|
||||
|
||||
$meta = $db->dispense('ExtensionMeta');
|
||||
$meta->extension = 'mod_client';
|
||||
$meta->client_id = $client_id;
|
||||
$meta->meta_key = 'confirm_email';
|
||||
$meta->meta_value = $hash;
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
$meta->extension = 'mod_client';
|
||||
$meta->client_id = $client_id;
|
||||
$meta->meta_key = 'confirm_email';
|
||||
$meta->meta_value = $hash;
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
$db->store($meta);
|
||||
|
||||
return $this->di['tools']->url('/client/confirm-email/'.$hash);
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterClientSignUp(\Box_Event $event)
|
||||
{
|
||||
$di = $event->getDi();
|
||||
@@ -71,22 +71,22 @@ class Service implements InjectionAwareInterface
|
||||
$config = $di['mod_config']('client');
|
||||
$emailService = $di['mod_service']('email');
|
||||
try {
|
||||
$email = array();
|
||||
$email = [];
|
||||
$email['to_client'] = $params['id'];
|
||||
$email['code'] = 'mod_client_signup';
|
||||
$email['password'] = $params['password'];
|
||||
$email['require_email_confirmation'] = false;
|
||||
if(isset($config['require_email_confirmation']) && $config['require_email_confirmation']) {
|
||||
$email['code'] = 'mod_client_signup';
|
||||
$email['password'] = $params['password'];
|
||||
$email['require_email_confirmation'] = false;
|
||||
if (isset($config['require_email_confirmation']) && $config['require_email_confirmation']) {
|
||||
$clientService = $di['mod_service']('client');
|
||||
$email['require_email_confirmation'] = true;
|
||||
$email['require_email_confirmation'] = true;
|
||||
$email['email_confirmation_link'] = $clientService->generateEmailConfirmationLink($params['id']);
|
||||
}
|
||||
|
||||
$emailService->sendTemplate($email);
|
||||
} catch(\Exception $exc) {
|
||||
} catch (\Exception $exc) {
|
||||
error_log($exc->getMessage());
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,77 +95,77 @@ class Service implements InjectionAwareInterface
|
||||
$sql = $selectStmt;
|
||||
$sql .= ' FROM client as c left join client_group as cg on c.client_group_id = cg.id';
|
||||
|
||||
$search = (isset($data['search']) && !empty($data['search'])) ? $data['search'] : NULL;
|
||||
$client_id = (isset($data['client_id']) && !empty($data['client_id'])) ? $data['client_id'] : NULL;
|
||||
$group_id = (isset($data['group_id']) && !empty($data['group_id'])) ? $data['group_id'] : NULL;
|
||||
$id = (isset($data['id']) && !empty($data['id'])) ? $data['id'] : NULL;
|
||||
$status = (isset($data['status']) && !empty($data['status'])) ? $data['status'] : NULL;
|
||||
$name = (isset($data['name']) && !empty($data['name'])) ? $data['name'] : NULL;
|
||||
$company = (isset($data['company']) && !empty($data['company'])) ? $data['company'] : NULL;
|
||||
$email = (isset($data['email']) && !empty($data['email'])) ? $data['email'] : NULL;
|
||||
$created_at = (isset($data['created_at']) && !empty($data['created_at'])) ? $data['created_at'] : NULL;
|
||||
$date_from = (isset($data['date_from']) && !empty($data['date_from'])) ? $data['date_from'] : NULL;
|
||||
$date_to = (isset($data['date_to']) && !empty($data['date_to'])) ? $data['date_to'] : NULL;
|
||||
$search = (isset($data['search']) && !empty($data['search'])) ? $data['search'] : null;
|
||||
$client_id = (isset($data['client_id']) && !empty($data['client_id'])) ? $data['client_id'] : null;
|
||||
$group_id = (isset($data['group_id']) && !empty($data['group_id'])) ? $data['group_id'] : null;
|
||||
$id = (isset($data['id']) && !empty($data['id'])) ? $data['id'] : null;
|
||||
$status = (isset($data['status']) && !empty($data['status'])) ? $data['status'] : null;
|
||||
$name = (isset($data['name']) && !empty($data['name'])) ? $data['name'] : null;
|
||||
$company = (isset($data['company']) && !empty($data['company'])) ? $data['company'] : null;
|
||||
$email = (isset($data['email']) && !empty($data['email'])) ? $data['email'] : null;
|
||||
$created_at = (isset($data['created_at']) && !empty($data['created_at'])) ? $data['created_at'] : null;
|
||||
$date_from = (isset($data['date_from']) && !empty($data['date_from'])) ? $data['date_from'] : null;
|
||||
$date_to = (isset($data['date_to']) && !empty($data['date_to'])) ? $data['date_to'] : null;
|
||||
|
||||
$where = array();
|
||||
$params = array();
|
||||
if($id) {
|
||||
$where = [];
|
||||
$params = [];
|
||||
if ($id) {
|
||||
$where[] = 'c.id = :client_id or c.aid = :alt_client_id';
|
||||
$params[':client_id'] = $id;
|
||||
$params[':alt_client_id'] = $id;
|
||||
}
|
||||
|
||||
if($name) {
|
||||
if ($name) {
|
||||
$where[] = '(c.first_name LIKE :first_name or c.last_name LIKE :last_name )';
|
||||
$name = "%" . $name . "%";
|
||||
$name = '%'.$name.'%';
|
||||
$params[':first_name'] = $name;
|
||||
$params[':last_name'] = $name;
|
||||
}
|
||||
|
||||
if($email) {
|
||||
if ($email) {
|
||||
$where[] = 'c.email LIKE :email';
|
||||
$params[':email'] = "%" . $email . "%";
|
||||
$params[':email'] = '%'.$email.'%';
|
||||
}
|
||||
|
||||
if($company) {
|
||||
if ($company) {
|
||||
$where[] = 'c.company LIKE :company';
|
||||
$params[':company'] = "%" . $company . "%";
|
||||
$params[':company'] = '%'.$company.'%';
|
||||
}
|
||||
|
||||
if($status) {
|
||||
if ($status) {
|
||||
$where[] = 'c.status = :status';
|
||||
$params[':status'] = $status;
|
||||
}
|
||||
|
||||
if($group_id) {
|
||||
if ($group_id) {
|
||||
$where[] = 'c.client_group_id = :group_id';
|
||||
$params[':group_id'] = $group_id;
|
||||
}
|
||||
|
||||
if($created_at) {
|
||||
if ($created_at) {
|
||||
$where[] = "DATE_FORMAT(c.created_at, '%Y-%m-%d') = :created_at";
|
||||
$params[':created_at'] = date('Y-m-d', strtotime($created_at)) ;
|
||||
$params[':created_at'] = date('Y-m-d', strtotime($created_at));
|
||||
}
|
||||
|
||||
if($date_from) {
|
||||
if ($date_from) {
|
||||
$where[] = 'UNIX_TIMESTAMP(c.created_at) >= :date_from';
|
||||
$params[':date_from'] = strtotime($date_from);
|
||||
}
|
||||
|
||||
if($date_to) {
|
||||
if ($date_to) {
|
||||
$where[] = 'UNIX_TIMESTAMP(c.created_at) <= :date_from';
|
||||
$params[':date_to'] = strtotime($date_to);
|
||||
}
|
||||
|
||||
//smartSearch
|
||||
if($search) {
|
||||
if(is_numeric($search)) {
|
||||
// smartSearch
|
||||
if ($search) {
|
||||
if (is_numeric($search)) {
|
||||
$where[] = 'c.id = :cid or c.aid = :caid';
|
||||
$params[':cid'] = $search;
|
||||
$params[':caid'] = $search;
|
||||
} else {
|
||||
$where[] = "c.company LIKE :s_company OR c.first_name LIKE :s_first_time OR c.last_name LIKE :s_last_name OR c.email LIKE :s_email OR CONCAT(c.first_name, ' ', c.last_name ) LIKE :full_name";
|
||||
$search = "%" . $search . "%";
|
||||
$search = '%'.$search.'%';
|
||||
$params[':s_company'] = $search;
|
||||
$params[':s_first_time'] = $search;
|
||||
$params[':s_last_name'] = $search;
|
||||
@@ -174,39 +174,40 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($where)){
|
||||
if (!empty($where)) {
|
||||
$sql .= ' WHERE '.implode(' AND ', $where);
|
||||
}
|
||||
$sql = $sql.' ORDER BY c.created_at desc';
|
||||
|
||||
return array($sql, $params);
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function getPairs($data)
|
||||
{
|
||||
$limit = $this->di['array_get']($data, 'per_page', 30);
|
||||
list($sql, $params) = $this->getSearchQuery($data, "SELECT c.id, CONCAT(c.first_name, ' ', c.last_name) as full_name");
|
||||
$limit = $this->di['array_get']($data, 'per_page', 30);
|
||||
[$sql, $params] = $this->getSearchQuery($data, "SELECT c.id, CONCAT(c.first_name, ' ', c.last_name) as full_name");
|
||||
$sql = $sql.' LIMIT '.$limit;
|
||||
|
||||
return $this->di['db']->getAssoc($sql, $params);
|
||||
}
|
||||
|
||||
public function toSessionArray(\Model_Client $model)
|
||||
{
|
||||
return array(
|
||||
'id' => $model->id,
|
||||
'email' => $model->email,
|
||||
'name' => $model->getFullName(),
|
||||
'role' => $model->role,
|
||||
);
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'email' => $model->email,
|
||||
'name' => $model->getFullName(),
|
||||
'role' => $model->role,
|
||||
];
|
||||
}
|
||||
|
||||
public function emailAreadyRegistered($new_email, \Model_Client $model = null)
|
||||
{
|
||||
if($model && $model->email == $new_email) {
|
||||
if ($model && $model->email == $new_email) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->di['db']->findOne('Client', 'email = ?', array($new_email));
|
||||
$result = $this->di['db']->findOne('Client', 'email = ?', [$new_email]);
|
||||
|
||||
return ($result) ? true : false;
|
||||
}
|
||||
@@ -221,12 +222,12 @@ class Service implements InjectionAwareInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
$invoice = $this->di['db']->findOne('Invoice', 'client_id = :client_id', array(':client_id' => $model->id));
|
||||
$invoice = $this->di['db']->findOne('Invoice', 'client_id = :client_id', [':client_id' => $model->id]);
|
||||
if ($invoice instanceof \Model_Invoice) {
|
||||
throw new \Box_Exception('Currency can not be changed. Client already have invoices issued.');
|
||||
}
|
||||
|
||||
$order = $this->di['db']->findOne('ClientOrder', 'client_id = :client_id', array(':client_id' => $model->id));
|
||||
$order = $this->di['db']->findOne('ClientOrder', 'client_id = :client_id', [':client_id' => $model->id]);
|
||||
if ($order instanceof \Model_ClientOrder) {
|
||||
throw new \Box_Exception('Currency can not be changed. Client already have orders.');
|
||||
}
|
||||
@@ -234,38 +235,40 @@ class Service implements InjectionAwareInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addFunds(\Model_Client $client, $amount, $description, array $data = array())
|
||||
public function addFunds(\Model_Client $client, $amount, $description, array $data = [])
|
||||
{
|
||||
if(!$client->currency) {
|
||||
if (!$client->currency) {
|
||||
throw new \Box_Exception('Define clients currency before adding funds.');
|
||||
}
|
||||
|
||||
if(!is_numeric($amount)) {
|
||||
if (!is_numeric($amount)) {
|
||||
throw new \Box_Exception('Funds amount is not valid');
|
||||
}
|
||||
|
||||
if(empty($description)) {
|
||||
if (empty($description)) {
|
||||
throw new \Box_Exception('Funds description is not valid');
|
||||
}
|
||||
|
||||
$credit = $this->di['db']->dispense('ClientBalance');
|
||||
|
||||
$credit->client_id = $client->id;
|
||||
$credit->type = $this->di['array_get']($data, 'type', 'gift');
|
||||
$credit->rel_id = $this->di['array_get']($data, 'rel_id');
|
||||
$credit->type = $this->di['array_get']($data, 'type', 'gift');
|
||||
$credit->rel_id = $this->di['array_get']($data, 'rel_id');
|
||||
$credit->description = $description;
|
||||
$credit->amount = $amount;
|
||||
$credit->created_at = date('Y-m-d H:i:s');
|
||||
$credit->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
$this->di['db']->store($credit);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getExpiredPasswordReminders()
|
||||
{
|
||||
$expire_after_hours = 2;
|
||||
$expired = $this->di['db']->find('ClientPasswordReset', 'UNIX_TIMESTAMP() - ? > UNIX_TIMESTAMP(created_at)', array($expire_after_hours * 60 * 60));
|
||||
$expired = $this->di['db']->find('ClientPasswordReset', 'UNIX_TIMESTAMP() - ? > UNIX_TIMESTAMP(created_at)', [$expire_after_hours * 60 * 60]);
|
||||
|
||||
return $expired;
|
||||
}
|
||||
|
||||
@@ -275,30 +278,30 @@ class Service implements InjectionAwareInterface
|
||||
FROM activity_client_history as ach
|
||||
LEFT JOIN client as c on ach.client_id = c.id ';
|
||||
|
||||
$search = $this->di['array_get']($data, 'search');
|
||||
$client_id = $this->di['array_get']($data, 'client_id');
|
||||
$search = $this->di['array_get']($data, 'search');
|
||||
$client_id = $this->di['array_get']($data, 'client_id');
|
||||
|
||||
$where = array();
|
||||
$params = array();
|
||||
if($search) {
|
||||
$where = [];
|
||||
$params = [];
|
||||
if ($search) {
|
||||
$where[] = 'c.first_name LIKE :first_name OR c.last_name LIKE :last_name OR c.id LIKE :id';
|
||||
$params[':first_name'] = "%".$search."%";
|
||||
$params[':last_name'] = "%".$search."%";
|
||||
$params[':first_name'] = '%'.$search.'%';
|
||||
$params[':last_name'] = '%'.$search.'%';
|
||||
$params[':id'] = $search;
|
||||
}
|
||||
|
||||
if($client_id) {
|
||||
if ($client_id) {
|
||||
$where[] = 'ach.client_id = :client_id';
|
||||
$params[':client_id'] = $client_id;
|
||||
}
|
||||
|
||||
if (!empty($where)){
|
||||
if (!empty($where)) {
|
||||
$q .= ' WHERE '.implode(' AND ', $where);
|
||||
}
|
||||
|
||||
$q .= ' ORDER BY ach.id desc';
|
||||
|
||||
return array($q, $params);
|
||||
return [$q, $params];
|
||||
}
|
||||
|
||||
public function counter()
|
||||
@@ -307,84 +310,87 @@ class Service implements InjectionAwareInterface
|
||||
FROM client
|
||||
group by status';
|
||||
$data = $this->di['db']->getAssoc($sql);
|
||||
return array(
|
||||
'total' => array_sum($data),
|
||||
\Model_Client::ACTIVE => isset($data[\Model_Client::ACTIVE]) ? $data[\Model_Client::ACTIVE] : 0,
|
||||
\Model_Client::SUSPENDED => isset($data[\Model_Client::SUSPENDED]) ? $data[\Model_Client::SUSPENDED] : 0,
|
||||
\Model_Client::CANCELED => isset($data[\Model_Client::CANCELED]) ? $data[\Model_Client::CANCELED] : 0,
|
||||
);
|
||||
|
||||
return [
|
||||
'total' => array_sum($data),
|
||||
\Model_Client::ACTIVE => $data[\Model_Client::ACTIVE] ?? 0,
|
||||
\Model_Client::SUSPENDED => $data[\Model_Client::SUSPENDED] ?? 0,
|
||||
\Model_Client::CANCELED => $data[\Model_Client::CANCELED] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
public function getGroupPairs()
|
||||
{
|
||||
$sql = 'SELECT id, title
|
||||
FROM client_group';
|
||||
|
||||
return $this->di['db']->getAssoc($sql);
|
||||
}
|
||||
|
||||
public function clientAlreadyExists($email)
|
||||
{
|
||||
$client = $this->di['db']->findOne('Client', 'email = :email ', array(':email' => $email));
|
||||
$client = $this->di['db']->findOne('Client', 'email = :email ', [':email' => $email]);
|
||||
|
||||
return ($client instanceof \Model_Client);
|
||||
return $client instanceof \Model_Client;
|
||||
}
|
||||
|
||||
public function getByLoginDetails($email, $password)
|
||||
{
|
||||
$client = $this->di['db']->findOne('Client', 'email = ? and pass = ? and status = ?', array($email, $password, \Model_Client::ACTIVE));
|
||||
$client = $this->di['db']->findOne('Client', 'email = ? and pass = ? and status = ?', [$email, $password, \Model_Client::ACTIVE]);
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
public function toApiArray(\Model_Client $model, $deep = false, $identity = null)
|
||||
{
|
||||
$details = array(
|
||||
'id' => $model->id,
|
||||
'aid' => $model->aid,
|
||||
'email' => $model->email,
|
||||
'type' => $model->type,
|
||||
$details = [
|
||||
'id' => $model->id,
|
||||
'aid' => $model->aid,
|
||||
'email' => $model->email,
|
||||
'type' => $model->type,
|
||||
'group_id' => $model->client_group_id,
|
||||
'company' => $model->company,
|
||||
'company_vat' => $model->company_vat,
|
||||
'company_number' => $model->company_number,
|
||||
'first_name' => $model->first_name,
|
||||
'last_name' => $model->last_name,
|
||||
'gender' => $model->gender,
|
||||
'birthday' => $model->birthday,
|
||||
'phone_cc' => $model->phone_cc,
|
||||
'phone' => $model->phone,
|
||||
'address_1' => $model->address_1,
|
||||
'address_2' => $model->address_2,
|
||||
'city' => $model->city,
|
||||
'state' => $model->state,
|
||||
'postcode' => $model->postcode,
|
||||
'country' => $model->country,
|
||||
'currency' => $model->currency,
|
||||
'notes' => $model->notes,
|
||||
'created_at' => $model->created_at,
|
||||
'company' => $model->company,
|
||||
'company_vat' => $model->company_vat,
|
||||
'company_number' => $model->company_number,
|
||||
'first_name' => $model->first_name,
|
||||
'last_name' => $model->last_name,
|
||||
'gender' => $model->gender,
|
||||
'birthday' => $model->birthday,
|
||||
'phone_cc' => $model->phone_cc,
|
||||
'phone' => $model->phone,
|
||||
'address_1' => $model->address_1,
|
||||
'address_2' => $model->address_2,
|
||||
'city' => $model->city,
|
||||
'state' => $model->state,
|
||||
'postcode' => $model->postcode,
|
||||
'country' => $model->country,
|
||||
'currency' => $model->currency,
|
||||
'notes' => $model->notes,
|
||||
'created_at' => $model->created_at,
|
||||
'document_nr' => $model->document_nr,
|
||||
);
|
||||
];
|
||||
|
||||
if($deep) {
|
||||
if ($deep) {
|
||||
$details['balance'] = $this->getClientBalance($model);
|
||||
}
|
||||
|
||||
$m = $this->di['db']->toArray($model);
|
||||
for ($i = 1; $i < 11; $i++) {
|
||||
for ($i = 1; $i < 11; ++$i) {
|
||||
$k = 'custom_'.$i;
|
||||
if(isset($m[$k]) && !empty($m[$k])) {
|
||||
if (isset($m[$k]) && !empty($m[$k])) {
|
||||
$details[$k] = $m[$k];
|
||||
}
|
||||
}
|
||||
|
||||
$clientGroup = $this->di['db']->load('ClientGroup', $model->client_group_id);
|
||||
|
||||
if($identity instanceof \Model_Admin) {
|
||||
if ($identity instanceof \Model_Admin) {
|
||||
$details['auth_type'] = $model->auth_type;
|
||||
$details['api_token'] = $model->api_token;
|
||||
$details['ip'] = $model->ip;
|
||||
$details['status'] = $model->status;
|
||||
$details['tax_exempt'] = $model->tax_exempt;
|
||||
$details['group'] = ($clientGroup) ? $clientGroup->title : NULL;
|
||||
$details['group'] = ($clientGroup) ? $clientGroup->title : null;
|
||||
$details['updated_at'] = $model->updated_at;
|
||||
$details['email_approved'] = $model->email_approved;
|
||||
}
|
||||
@@ -399,30 +405,31 @@ class Service implements InjectionAwareInterface
|
||||
WHERE client_id = ?
|
||||
GROUP BY client_id';
|
||||
|
||||
$balance = $this->di['db']->getCell($sql, array($c->id));
|
||||
$balance = $this->di['db']->getCell($sql, [$c->id]);
|
||||
|
||||
return $balance;
|
||||
}
|
||||
|
||||
public function get($data)
|
||||
{
|
||||
if(!isset($data['id']) && !isset($data['email'])) {
|
||||
if (!isset($data['id']) && !isset($data['email'])) {
|
||||
throw new \Box_Exception('Client ID or email is required');
|
||||
}
|
||||
|
||||
$db = $this->di['db'];
|
||||
$client = null;
|
||||
if(isset($data['id'])) {
|
||||
$client = $db->findOne('Client', 'id = ?', array($data['id']));
|
||||
if (isset($data['id'])) {
|
||||
$client = $db->findOne('Client', 'id = ?', [$data['id']]);
|
||||
}
|
||||
|
||||
if(!$client && isset($data['email'])) {
|
||||
$client = $db->findOne('Client', 'email = ?', array($data['email']));
|
||||
if (!$client && isset($data['email'])) {
|
||||
$client = $db->findOne('Client', 'email = ?', [$data['email']]);
|
||||
}
|
||||
|
||||
if(!$client instanceof \Model_Client ) {
|
||||
if (!$client instanceof \Model_Client) {
|
||||
throw new \Box_Exception('Client not found');
|
||||
}
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
@@ -455,18 +462,20 @@ class Service implements InjectionAwareInterface
|
||||
$group_id = $this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Created new client group #%s', $model->id);
|
||||
|
||||
return $group_id;
|
||||
}
|
||||
|
||||
public function deleteGroup(\Model_ClientGroup $model)
|
||||
{
|
||||
$client = $this->di['db']->findOne('Client', 'client_group_id = ?', array($model->id));
|
||||
if($client) {
|
||||
$client = $this->di['db']->findOne('Client', 'client_group_id = ?', [$model->id]);
|
||||
if ($client) {
|
||||
throw new \Box_Exception('Can not remove group with clients');
|
||||
}
|
||||
|
||||
$this->di['db']->trash($model);
|
||||
$this->di['logger']->info('Removed client group #%s', $model->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -476,48 +485,48 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$client = $this->di['db']->dispense('Client');
|
||||
|
||||
$client->auth_type = $this->di['array_get']($data, 'auth_type');
|
||||
$client->email = strtolower(trim($this->di['array_get']($data, 'email')));
|
||||
$client->auth_type = $this->di['array_get']($data, 'auth_type');
|
||||
$client->email = strtolower(trim($this->di['array_get']($data, 'email')));
|
||||
$client->first_name = ucwords($this->di['array_get']($data, 'first_name'));
|
||||
$client->pass = $this->di['password']->hashIt($password);
|
||||
$client->pass = $this->di['password']->hashIt($password);
|
||||
|
||||
$phoneCC = $this->di['array_get']($data, 'phone_cc', $client->phone_cc);
|
||||
if(!empty($phoneCC)){
|
||||
if (!empty($phoneCC)) {
|
||||
$client->phone_cc = intval($phoneCC);
|
||||
}
|
||||
|
||||
$client->aid = $this->di['array_get']($data, 'aid');
|
||||
$client->last_name = $this->di['array_get']($data, 'last_name');
|
||||
$client->aid = $this->di['array_get']($data, 'aid');
|
||||
$client->last_name = $this->di['array_get']($data, 'last_name');
|
||||
$client->client_group_id = $this->di['array_get']($data, 'group_id');
|
||||
$client->status = $this->di['array_get']($data, 'status');
|
||||
$client->gender = $this->di['array_get']($data, 'gender');
|
||||
$client->birthday = $this->di['array_get']($data, 'birthday');
|
||||
$client->phone = $this->di['array_get']($data, 'phone');
|
||||
$client->company = $this->di['array_get']($data, 'company');
|
||||
$client->company_vat = $this->di['array_get']($data, 'company_vat');
|
||||
$client->company_number = $this->di['array_get']($data, 'company_number');
|
||||
$client->type = $this->di['array_get']($data, 'type');
|
||||
$client->address_1 = $this->di['array_get']($data, 'address_1');
|
||||
$client->address_2 = $this->di['array_get']($data, 'address_2');
|
||||
$client->city = $this->di['array_get']($data, 'city');
|
||||
$client->state = $this->di['array_get']($data, 'state');
|
||||
$client->postcode = $this->di['array_get']($data, 'postcode');
|
||||
$client->country = $this->di['array_get']($data, 'country');
|
||||
$client->document_type = $this->di['array_get']($data, 'document_type');
|
||||
$client->document_nr = $this->di['array_get']($data, 'document_nr');
|
||||
$client->notes = $this->di['array_get']($data, 'notes');
|
||||
$client->lang = $this->di['array_get']($data, 'lang');
|
||||
$client->currency = $this->di['array_get']($data, 'currency');
|
||||
$client->status = $this->di['array_get']($data, 'status');
|
||||
$client->gender = $this->di['array_get']($data, 'gender');
|
||||
$client->birthday = $this->di['array_get']($data, 'birthday');
|
||||
$client->phone = $this->di['array_get']($data, 'phone');
|
||||
$client->company = $this->di['array_get']($data, 'company');
|
||||
$client->company_vat = $this->di['array_get']($data, 'company_vat');
|
||||
$client->company_number = $this->di['array_get']($data, 'company_number');
|
||||
$client->type = $this->di['array_get']($data, 'type');
|
||||
$client->address_1 = $this->di['array_get']($data, 'address_1');
|
||||
$client->address_2 = $this->di['array_get']($data, 'address_2');
|
||||
$client->city = $this->di['array_get']($data, 'city');
|
||||
$client->state = $this->di['array_get']($data, 'state');
|
||||
$client->postcode = $this->di['array_get']($data, 'postcode');
|
||||
$client->country = $this->di['array_get']($data, 'country');
|
||||
$client->document_type = $this->di['array_get']($data, 'document_type');
|
||||
$client->document_nr = $this->di['array_get']($data, 'document_nr');
|
||||
$client->notes = $this->di['array_get']($data, 'notes');
|
||||
$client->lang = $this->di['array_get']($data, 'lang');
|
||||
$client->currency = $this->di['array_get']($data, 'currency');
|
||||
|
||||
$client->custom_1 = $this->di['array_get']($data, 'custom_1');
|
||||
$client->custom_2 = $this->di['array_get']($data, 'custom_2');
|
||||
$client->custom_3 = $this->di['array_get']($data, 'custom_3');
|
||||
$client->custom_4 = $this->di['array_get']($data, 'custom_4');
|
||||
$client->custom_5 = $this->di['array_get']($data, 'custom_5');
|
||||
$client->custom_6 = $this->di['array_get']($data, 'custom_6');
|
||||
$client->custom_7 = $this->di['array_get']($data, 'custom_7');
|
||||
$client->custom_8 = $this->di['array_get']($data, 'custom_8');
|
||||
$client->custom_9 = $this->di['array_get']($data, 'custom_9');
|
||||
$client->custom_1 = $this->di['array_get']($data, 'custom_1');
|
||||
$client->custom_2 = $this->di['array_get']($data, 'custom_2');
|
||||
$client->custom_3 = $this->di['array_get']($data, 'custom_3');
|
||||
$client->custom_4 = $this->di['array_get']($data, 'custom_4');
|
||||
$client->custom_5 = $this->di['array_get']($data, 'custom_5');
|
||||
$client->custom_6 = $this->di['array_get']($data, 'custom_6');
|
||||
$client->custom_7 = $this->di['array_get']($data, 'custom_7');
|
||||
$client->custom_8 = $this->di['array_get']($data, 'custom_8');
|
||||
$client->custom_9 = $this->di['array_get']($data, 'custom_9');
|
||||
$client->custom_10 = $this->di['array_get']($data, 'custom_10');
|
||||
|
||||
$client->ip = $this->di['array_get']($data, 'ip');
|
||||
@@ -526,14 +535,15 @@ class Service implements InjectionAwareInterface
|
||||
$client->created_at = !empty($created_at) ? date('Y-m-d H:i:s', strtotime($created_at)) : date('Y-m-d H:i:s');
|
||||
$client->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($client);
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
public function adminCreateClient(array $data)
|
||||
{
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminCreateClient', 'params'=>$data));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminCreateClient', 'params' => $data]);
|
||||
$client = $this->createClient($data);
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminCreateClient', 'params'=>array('id'=>$client->id, 'password'=>$data['password'])));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminCreateClient', 'params' => ['id' => $client->id, 'password' => $data['password']]]);
|
||||
$this->di['logger']->info('Created new client #%s', $client->id);
|
||||
|
||||
return $client->id;
|
||||
@@ -543,13 +553,13 @@ class Service implements InjectionAwareInterface
|
||||
{
|
||||
$event_params = $data;
|
||||
$event_params['ip'] = $this->di['request']->getClientAddress();
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeClientSignUp', 'params'=>$event_params));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeClientSignUp', 'params' => $event_params]);
|
||||
|
||||
$data['ip'] = $this->di['request']->getClientAddress();
|
||||
$data['status'] = \Model_Client::ACTIVE;
|
||||
$client = $this->createClient($data);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterClientSignUp', 'params'=>array('id'=>$client->id, 'password'=>$data['password'])));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientSignUp', 'params' => ['id' => $client->id, 'password' => $data['password']]]);
|
||||
$this->di['logger']->info('Client #%s signed up', $client->id);
|
||||
|
||||
return $client;
|
||||
@@ -581,25 +591,24 @@ class Service implements InjectionAwareInterface
|
||||
$table = $this->di['table']('ClientPasswordReset');
|
||||
$table->rmByClient($model);
|
||||
|
||||
|
||||
$pdo = $this->di['pdo'];
|
||||
$stmt = $pdo->prepare('DELETE FROM extension_meta WHERE client_id = :id');
|
||||
$stmt->execute(array('id'=>$model->id));
|
||||
$stmt->execute(['id' => $model->id]);
|
||||
|
||||
$this->di['db']->trash($model);
|
||||
}
|
||||
|
||||
public function authorizeClient($email, $plainTextPassword)
|
||||
{
|
||||
$model = $this->di['db']->findOne('Client', 'email = ? AND status = ?', array($email, \Model_Client::ACTIVE));
|
||||
if ($model == null) {
|
||||
$model = $this->di['db']->findOne('Client', 'email = ? AND status = ?', [$email, \Model_Client::ACTIVE]);
|
||||
if (null == $model) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$config = $this->di['mod_config']('client');
|
||||
if (isset($config['require_email_confirmation']) && (int)$config['require_email_confirmation']) {
|
||||
if (isset($config['require_email_confirmation']) && (int) $config['require_email_confirmation']) {
|
||||
if (!$model->email_approved) {
|
||||
$meta = $this->di['db']->findOne('ExtensionMeta', ' extension = "mod_client" AND meta_key = "confirm_email" AND client_id = :client_id', array(':client_id' => $model->id));
|
||||
$meta = $this->di['db']->findOne('ExtensionMeta', ' extension = "mod_client" AND meta_key = "confirm_email" AND client_id = :client_id', [':client_id' => $model->id]);
|
||||
if (!is_null($meta)) {
|
||||
throw new \Box_Exception('Please check your mailbox and confirm email address.');
|
||||
} else {
|
||||
@@ -615,11 +624,11 @@ class Service implements InjectionAwareInterface
|
||||
private function sendEmailConfirmationForClient(\Model_Client $client)
|
||||
{
|
||||
try {
|
||||
$email = array();
|
||||
$email['to_client'] = $client->id;
|
||||
$email['code'] = 'mod_client_confirm';
|
||||
$email = [];
|
||||
$email['to_client'] = $client->id;
|
||||
$email['code'] = 'mod_client_confirm';
|
||||
$email['require_email_confirmation'] = true;
|
||||
$email['email_confirmation_link'] = $this->generateEmailConfirmationLink($client->id);
|
||||
$email['email_confirmation_link'] = $this->generateEmailConfirmationLink($client->id);
|
||||
|
||||
$emailService = $this->di['mod_service']('email');
|
||||
$emailService->sendTemplate($email);
|
||||
@@ -630,25 +639,25 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function canChangeEmail(\Model_Client $client, $email)
|
||||
{
|
||||
$config = $this->di['mod_config']('client');
|
||||
$config = $this->di['mod_config']('client');
|
||||
|
||||
if ($client->email != $email
|
||||
&& isset($config['allow_change_email'])
|
||||
&& !$config['allow_change_email']) {
|
||||
throw new \Box_Exception('Email can not be changed');
|
||||
}
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkExtraRequiredFields(array $checkArr)
|
||||
{
|
||||
$config = $this->di['mod_config']('client');
|
||||
$required = $this->di['array_get']($config, 'required', array());
|
||||
foreach($required as $field) {
|
||||
if(!isset($checkArr[$field]) || empty($checkArr[$field])) {
|
||||
$required = $this->di['array_get']($config, 'required', []);
|
||||
foreach ($required as $field) {
|
||||
if (!isset($checkArr[$field]) || empty($checkArr[$field])) {
|
||||
$name = ucwords(str_replace('_', ' ', $field));
|
||||
throw new \Box_Exception('It is required that you provide details for field ":field"', array(':field'=>$name));
|
||||
throw new \Box_Exception('It is required that you provide details for field ":field"', [':field' => $name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -656,16 +665,16 @@ class Service implements InjectionAwareInterface
|
||||
public function checkCustomFields(array $checkArr)
|
||||
{
|
||||
$config = $this->di['mod_config']('client');
|
||||
$customFields = $this->di['array_get']($config, 'custom_fields', array());
|
||||
$customFields = $this->di['array_get']($config, 'custom_fields', []);
|
||||
foreach ($customFields as $cFieldName => $cField) {
|
||||
$active = isset($cField['active']) && $cField['active'] ? true : false;
|
||||
$active = isset($cField['active']) && $cField['active'] ? true : false;
|
||||
$required = isset($cField['required']) && $cField['required'] ? true : false;
|
||||
if ($active && $required) {
|
||||
if (!isset($checkArr[$cFieldName]) || empty($checkArr[$cFieldName])) {
|
||||
$name = isset($cField['title']) && !empty($cField['title']) ? $cField['title'] : ucwords(str_replace('_', ' ', $cFieldName));;
|
||||
throw new \Box_Exception('It is required that you provide details for field ":field"', array(':field' => $name));
|
||||
$name = isset($cField['title']) && !empty($cField['title']) ? $cField['title'] : ucwords(str_replace('_', ' ', $cFieldName));
|
||||
throw new \Box_Exception('It is required that you provide details for field ":field"', [':field' => $name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Client;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -40,24 +39,25 @@ class ServiceBalance implements InjectionAwareInterface
|
||||
|
||||
public function getClientBalance(Model_Client $c)
|
||||
{
|
||||
return (float)$this->clientTotal($c);
|
||||
return (float) $this->clientTotal($c);
|
||||
}
|
||||
|
||||
public function clientTotal(Model_Client $c)
|
||||
{
|
||||
$sql="
|
||||
$sql = '
|
||||
SELECT SUM(amount) as client_total
|
||||
FROM client_balance
|
||||
WHERE client_id = ?
|
||||
GROUP BY client_id
|
||||
";
|
||||
return $this->di['db']->getCell($sql, array($c->id));
|
||||
';
|
||||
|
||||
return $this->di['db']->getCell($sql, [$c->id]);
|
||||
}
|
||||
|
||||
public function rmByClient(Model_Client $client)
|
||||
{
|
||||
$clientBalances = $this->di['db']->find('ClientBalance', 'client_id = ?', array($client->id));
|
||||
foreach ($clientBalances as $balanceModel){
|
||||
$clientBalances = $this->di['db']->find('ClientBalance', 'client_id = ?', [$client->id]);
|
||||
foreach ($clientBalances as $balanceModel) {
|
||||
$this->di['db']->trash($balanceModel);
|
||||
}
|
||||
}
|
||||
@@ -70,13 +70,14 @@ class ServiceBalance implements InjectionAwareInterface
|
||||
public function toApiArray(Model_ClientBalance $model)
|
||||
{
|
||||
$client = $this->di['db']->getExistingModelById('Client', $model->client_id, 'Client not found');
|
||||
return array(
|
||||
'id' => $model->id,
|
||||
'description' => $model->description,
|
||||
'amount' => $model->amount,
|
||||
'currency' => $client->currency,
|
||||
'created_at' => $model->created_at,
|
||||
);
|
||||
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'description' => $model->description,
|
||||
'amount' => $model->amount,
|
||||
'currency' => $client->currency,
|
||||
'created_at' => $model->created_at,
|
||||
];
|
||||
}
|
||||
|
||||
public function getSearchQuery($data)
|
||||
@@ -85,57 +86,58 @@ class ServiceBalance implements InjectionAwareInterface
|
||||
FROM client_balance as m
|
||||
LEFT JOIN client as c on c.id = m.client_id';
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$date_from = $this->di['array_get']($data, 'date_from', NULL);
|
||||
$date_to = $this->di['array_get']($data, 'date_to', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
$date_from = $this->di['array_get']($data, 'date_from', null);
|
||||
$date_to = $this->di['array_get']($data, 'date_to', null);
|
||||
|
||||
$where = array();
|
||||
$params = array();
|
||||
$where = [];
|
||||
$params = [];
|
||||
|
||||
if(NULL !== $id) {
|
||||
if (null !== $id) {
|
||||
$where[] = 'm.id = :id';
|
||||
$params[':id'] = $id;
|
||||
}
|
||||
|
||||
if(NULL !== $client_id) {
|
||||
if (null !== $client_id) {
|
||||
$where[] = 'm.client_id = :client_id';
|
||||
$params[':client_id'] = $client_id;
|
||||
}
|
||||
|
||||
if(NULL !== $date_from) {
|
||||
if (null !== $date_from) {
|
||||
$where[] = 'm.created_at >= :date_from';
|
||||
$params[':date_from'] = strtotime($date_from);
|
||||
}
|
||||
|
||||
if(NULL !== $date_to) {
|
||||
if (null !== $date_to) {
|
||||
$where[] = 'm.created_at <= :date_to';
|
||||
$params[':date_to'] = strtotime($date_to);
|
||||
}
|
||||
|
||||
if (!empty($where)){
|
||||
if (!empty($where)) {
|
||||
$q .= ' WHERE '.implode(' AND ', $where);
|
||||
}
|
||||
$q .= ' ORDER by m.id DESC';
|
||||
|
||||
return array($q, $params);
|
||||
return [$q, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model_Client $client
|
||||
* @param double $amount
|
||||
* @param string $description
|
||||
* @param array $data
|
||||
* @param float $amount
|
||||
* @param string $description
|
||||
* @param array $data
|
||||
*
|
||||
* @return Model_ClientBalance
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function deductFunds(Model_Client $client, $amount, $description, array $data = null)
|
||||
{
|
||||
if(!is_numeric($amount)) {
|
||||
if (!is_numeric($amount)) {
|
||||
throw new Box_Exception('Funds amount is not valid');
|
||||
}
|
||||
|
||||
if(strlen(trim($description)) == 0) {
|
||||
if (0 == strlen(trim($description))) {
|
||||
throw new Box_Exception('Funds description is not valid');
|
||||
}
|
||||
|
||||
@@ -151,4 +153,4 @@ class ServiceBalance implements InjectionAwareInterface
|
||||
|
||||
return $credit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -14,7 +14,6 @@
|
||||
* Cookies consent notification bar.
|
||||
*
|
||||
* Show cookie consent message to comply with European Cookie Law
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Cookieconsent\Api;
|
||||
@@ -22,13 +21,14 @@ namespace Box\Mod\Cookieconsent\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get message which should be shown in notification bar
|
||||
* Get message which should be shown in notification bar.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return $this->getService()->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Cookieconsent\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,27 +34,28 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'subpages'=> array(
|
||||
array(
|
||||
'location' => 'extensions',
|
||||
'label' => 'Cookie consent',
|
||||
'index' => 2000,
|
||||
'uri' => $this->di['url']->adminLink('cookieconsent'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
return [
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'extensions',
|
||||
'label' => 'Cookie consent',
|
||||
'index' => 2000,
|
||||
'uri' => $this->di['url']->adminLink('cookieconsent'),
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/cookieconsent', 'get_index', array(), get_class($this));
|
||||
$app->get('/cookieconsent', 'get_index', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_cookieconsent_index');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Cookieconsent;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -35,4 +34,4 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
return $this->di['array_get']($config, 'message', 'This website uses cookies. By continuing to use this website, you consent to our use of these cookies.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cron management
|
||||
* Cron management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Cron\Api;
|
||||
@@ -21,21 +21,21 @@ class Admin extends \Api_Abstract
|
||||
/**
|
||||
* Returns cron job information. When it was last executed, where cron job
|
||||
* file is located.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function info($data)
|
||||
{
|
||||
return $this->getService()->getCronInfo();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run cron
|
||||
*
|
||||
* Run cron.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function run($data)
|
||||
{
|
||||
return $this->getService()->runCrons();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cron checker
|
||||
* Cron checker.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Cron\Api;
|
||||
@@ -19,7 +19,7 @@ namespace Box\Mod\Cron\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Run cron if is late and web based cron is enabled
|
||||
* Run cron if is late and web based cron is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -29,7 +29,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cron settings
|
||||
* Get cron settings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if cron is late
|
||||
* Tells if cron is late.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -47,4 +47,4 @@ class Guest extends \Api_Abstract
|
||||
{
|
||||
return $this->getService()->isLate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -33,17 +33,20 @@ class Service
|
||||
{
|
||||
$service = $this->di['mod_service']('system');
|
||||
|
||||
$result = array(
|
||||
'cron_url' => BB_URL . 'bb-cron.php',
|
||||
'cron_path' => BB_PATH_ROOT . DIRECTORY_SEPARATOR . 'bb-cron.php',
|
||||
'last_cron_exec' => $service->getParamValue('last_cron_exec'),
|
||||
);
|
||||
$result = [
|
||||
'cron_url' => BB_URL.'bb-cron.php',
|
||||
'cron_path' => BB_PATH_ROOT.DIRECTORY_SEPARATOR.'bb-cron.php',
|
||||
'last_cron_exec' => $service->getParamValue('last_cron_exec'),
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $interval - parameter from CLI, pass to filter crons to run
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @todo finish fixing, time to sleep
|
||||
*/
|
||||
public function runCrons($interval = null)
|
||||
@@ -51,9 +54,9 @@ class Service
|
||||
$api = $this->di['api_system'];
|
||||
$this->di['logger']->info('- Started executing cron');
|
||||
|
||||
//@core tasks
|
||||
// @core tasks
|
||||
$this->_exec($api, 'hook_batch_connect');
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminCronRun'));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminCronRun']);
|
||||
|
||||
$this->_exec($api, 'invoice_batch_pay_with_credits');
|
||||
$this->_exec($api, 'invoice_batch_activate_paid');
|
||||
@@ -72,9 +75,10 @@ class Service
|
||||
$ss = $this->di['mod_service']('system');
|
||||
$ss->setParamValue('last_cron_exec', date('Y-m-d H:i:s'), $create);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminCronRun'));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminCronRun']);
|
||||
|
||||
$this->di['logger']->info('- Finished executing cron');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,11 +89,11 @@ class Service
|
||||
{
|
||||
try {
|
||||
$api->{$method}($params);
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw new Exception($e);
|
||||
} finally {
|
||||
if (php_sapi_name() == 'cli') {
|
||||
print ("\e[32mSuccessfully ran " . $method . "(" . $params . ")" . ".\e[0m\n");
|
||||
if ('cli' == php_sapi_name()) {
|
||||
echo "\e[32mSuccessfully ran ".$method.'('.$params.')'.".\e[0m\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,6 +105,7 @@ class Service
|
||||
{
|
||||
$service = $this->di['mod_service']('system');
|
||||
$last_exec = $service->getParamValue('last_cron_exec');
|
||||
|
||||
return $last_exec;
|
||||
}
|
||||
|
||||
@@ -108,6 +113,7 @@ class Service
|
||||
{
|
||||
$t1 = new \DateTime($this->getLastExecutionTime());
|
||||
$t2 = new \DateTime('-6min');
|
||||
return ($t1 < $t2);
|
||||
|
||||
return $t1 < $t2;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,187 +11,197 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Currency management
|
||||
* Currency management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Currency\Api;
|
||||
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of available currencies on system
|
||||
*
|
||||
* Get list of available currencies on system.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
list($query, $params) = $this->getService()->getSearchQuery();
|
||||
[$query, $params] = $this->getService()->getSearchQuery();
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($query, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$currency = $this->di['db']->getExistingModelById('Currency', $item['id'], 'Currency not found');
|
||||
$currency = $this->di['db']->getExistingModelById('Currency', $item['id'], 'Currency not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($currency);
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get code title pairs of currencies
|
||||
*
|
||||
* Get code title pairs of currencies.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_pairs()
|
||||
{
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->getAvailableCurrencies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return currency details by cde
|
||||
*
|
||||
* Return currency details by cde.
|
||||
*
|
||||
* @param string $code - currency code USD
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'code' => 'Currency code is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$service = $this->getService();
|
||||
$model = $service->getByCode($data['code']);
|
||||
|
||||
if(!$model instanceof \Model_Currency) {
|
||||
if (!$model instanceof \Model_Currency) {
|
||||
throw new \Box_Exception('Currency not found');
|
||||
}
|
||||
|
||||
return $service->toApiArray($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default system currency
|
||||
*
|
||||
* Return default system currency.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_default($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
$currency = $service->getDefault();
|
||||
|
||||
return $service->toApiArray($currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new currency to system
|
||||
*
|
||||
* @param string $code - currency ISO 4217 code
|
||||
* @param string $format - must have {{price}} tag.
|
||||
*
|
||||
* Add new currency to system.
|
||||
*
|
||||
* @param string $code - currency ISO 4217 code
|
||||
* @param string $format - must have {{price}} tag
|
||||
*
|
||||
* @optional string $title - custom currency title
|
||||
*
|
||||
*
|
||||
* @return string - currency code
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create($data = array())
|
||||
public function create($data = [])
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'code' => 'Currency code is missing',
|
||||
'format' => 'Currency format is missing',
|
||||
);
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$service = $this->getService();
|
||||
|
||||
if($service->getByCode($this->di['array_get']($data, 'code'))) {
|
||||
if ($service->getByCode($this->di['array_get']($data, 'code'))) {
|
||||
throw new \Box_Exception('Currency already registered');
|
||||
}
|
||||
|
||||
if(!array_key_exists($this->di['array_get']($data, 'code'), $service->getAvailableCurrencies())) {
|
||||
if (!array_key_exists($this->di['array_get']($data, 'code'), $service->getAvailableCurrencies())) {
|
||||
throw new \Box_Exception('Currency code is not valid');
|
||||
}
|
||||
|
||||
$title = $this->di['array_get']($data, 'title');
|
||||
$title = $this->di['array_get']($data, 'title');
|
||||
$conversionRate = $this->di['array_get']($data, 'conversion_rate', 1);
|
||||
|
||||
return $service->createCurrency($this->di['array_get']($data, 'code'), $this->di['array_get']($data, 'format'), $title, $conversionRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates system currency settings
|
||||
*
|
||||
* Updates system currency settings.
|
||||
*
|
||||
* @param string $code - currency ISO 4217 code
|
||||
*
|
||||
*
|
||||
* @optional string $title - new currency title
|
||||
* @optional string $format - new currency format
|
||||
* @optional float $conversion_rate - new currency conversion rate
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'code' => 'Currency code is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$format = $this->di['array_get']($data, 'format');
|
||||
$title = $this->di['array_get']($data, 'title');
|
||||
$priceFormat = $this->di['array_get']($data, 'price_format');
|
||||
$format = $this->di['array_get']($data, 'format');
|
||||
$title = $this->di['array_get']($data, 'title');
|
||||
$priceFormat = $this->di['array_get']($data, 'price_format');
|
||||
$conversionRate = $this->di['array_get']($data, 'conversion_rate');
|
||||
|
||||
return $this->getService()->updateCurrency($data['code'], $format, $title, $priceFormat, $conversionRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the API key for currencylayer
|
||||
*
|
||||
* Gets the API key for currencylayer.
|
||||
*
|
||||
* @since 4.22.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_key($data)
|
||||
{
|
||||
{
|
||||
return $this->getService()->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the API key for currencylayer
|
||||
*
|
||||
* Updates the API key for currencylayer.
|
||||
*
|
||||
* @since 4.22.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update_rate_settings($data)
|
||||
{
|
||||
{
|
||||
$this->getService()->updateKey($this->di['array_get']($data, 'currencylayer_key'));
|
||||
|
||||
if ($this->di['array_get']($data, 'crons_enabled') == "1") {
|
||||
$set = "1";
|
||||
|
||||
if ($this->di['array_get']($data, 'crons_enabled') == '1') {
|
||||
$set = '1';
|
||||
} else {
|
||||
$set = "0";
|
||||
$set = '0';
|
||||
}
|
||||
|
||||
|
||||
$this->getService()->setCron($set);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if CRON jobs are enabled for currency rates
|
||||
*
|
||||
* See if CRON jobs are enabled for currency rates.
|
||||
*
|
||||
* @todo why does this even return a string instead of a boolean?
|
||||
*
|
||||
* @since 4.22.0
|
||||
*
|
||||
* @return string (0/1)
|
||||
*/
|
||||
public function is_cron_enabled($data)
|
||||
{
|
||||
{
|
||||
return $this->getService()->isCronEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically update all currency rates.
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update_rates($data)
|
||||
@@ -201,17 +211,18 @@ class Admin extends \Api_Abstract
|
||||
|
||||
/**
|
||||
* Remove currency. Default currency can not be removed.
|
||||
*
|
||||
*
|
||||
* @param string $code - currency ISO 4217 code
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'code' => 'Currency code is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
return $this->getService()->deleteCurrencyByCode($data['code']);
|
||||
@@ -220,21 +231,22 @@ class Admin extends \Api_Abstract
|
||||
/**
|
||||
* Set default currency. If you have active orders or invoices
|
||||
* not recalculation on profits and refunds are made.
|
||||
*
|
||||
*
|
||||
* @param string $code - currency ISO 4217 code
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function set_default($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'code' => 'Currency code is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$service = $this->getService();
|
||||
$model = $service->getByCode($data['code']);
|
||||
$model = $service->getByCode($data['code']);
|
||||
if (!$model instanceof \Model_currency) {
|
||||
throw new \Box_Exception('Currency not found');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*Currency management
|
||||
*Currency management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Currency\Api;
|
||||
@@ -19,48 +19,51 @@ namespace Box\Mod\Currency\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of available currencies
|
||||
*
|
||||
* Get list of available currencies.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_pairs($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->getPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currency by code
|
||||
*
|
||||
* Get currency by code.
|
||||
*
|
||||
* @param string $code - currency code, ie: USD
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
if(isset($data['code']) && !empty($data['code'])) {
|
||||
if (isset($data['code']) && !empty($data['code'])) {
|
||||
$model = $service->getByCode($data['code']);
|
||||
} else {
|
||||
$model = $service->getDefault();
|
||||
}
|
||||
|
||||
if(!$model instanceof \Model_Currency) {
|
||||
|
||||
if (!$model instanceof \Model_Currency) {
|
||||
throw new \Box_Exception('Currency not found');
|
||||
}
|
||||
|
||||
return $service->toApiArray($model);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format price by currency settings
|
||||
*
|
||||
* @optional bool $convert - covert to default currency rate. Default - true;
|
||||
* Format price by currency settings.
|
||||
*
|
||||
* @optional bool $convert - covert to default currency rate. Default - true;
|
||||
* @optional bool $without_currency - Show only number. No symbols are attached Default - false;
|
||||
* @optional float $price - Price to be formated. Default 0
|
||||
* @optional string $code - currency code, ie: USD. Default - default currency
|
||||
*
|
||||
*
|
||||
* @return string - formated string
|
||||
*/
|
||||
public function format($data = array())
|
||||
public function format($data = [])
|
||||
{
|
||||
$c = $this->get($data);
|
||||
|
||||
@@ -69,7 +72,7 @@ class Guest extends \Api_Abstract
|
||||
$without_currency = (bool) $this->di['array_get']($data, 'without_currency', false);
|
||||
|
||||
$p = $price;
|
||||
if($convert) {
|
||||
if ($convert) {
|
||||
$p = $price * $c['conversion_rate'];
|
||||
}
|
||||
|
||||
@@ -77,29 +80,29 @@ class Guest extends \Api_Abstract
|
||||
case 2:
|
||||
$p = number_format($p, 2, '.', ',');
|
||||
break;
|
||||
|
||||
|
||||
case 3:
|
||||
$p = number_format($p, 2, ',', '.');
|
||||
break;
|
||||
|
||||
|
||||
case 4:
|
||||
$p = number_format($p, 0, '', ',');
|
||||
break;
|
||||
|
||||
|
||||
case 5:
|
||||
$p = number_format($p, 0, '', '');
|
||||
break;
|
||||
|
||||
case 1:
|
||||
default:
|
||||
$p = number_format($p, 2, '.', '');
|
||||
$p = number_format($p, 2, '.', '');
|
||||
break;
|
||||
}
|
||||
|
||||
if($without_currency) {
|
||||
if ($without_currency) {
|
||||
return $p;
|
||||
}
|
||||
|
||||
return str_replace('{{price}}', $p, $c['format']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Currency\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,14 +34,15 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/currency/manage/:code', 'get_manage', array('code'=>'[a-zA-Z]+'), get_class($this));
|
||||
$app->get('/currency/manage/:code', 'get_manage', ['code' => '[a-zA-Z]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_manage(\Box_App $app, $code)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
$guest_api = $this->di['api_guest'];
|
||||
$currency = $guest_api->currency_get(array('code'=>$code));
|
||||
return $app->render('mod_currency_manage', array('currency'=>$currency));
|
||||
$currency = $guest_api->currency_get(['code' => $code]);
|
||||
|
||||
return $app->render('mod_currency_manage', ['currency' => $currency]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+108
-101
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Currency;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -31,14 +30,14 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function getSearchQuery()
|
||||
{
|
||||
$sql = "SELECT * FROM currency WHERE 1";
|
||||
$filter = array();
|
||||
$sql = 'SELECT * FROM currency WHERE 1';
|
||||
$filter = [];
|
||||
|
||||
return array($sql, $filter);
|
||||
return [$sql, $filter];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert foreign price back to default currency
|
||||
* Convert foreign price back to default currency.
|
||||
*/
|
||||
public function toBaseCurrency($foreign_code, $amount)
|
||||
{
|
||||
@@ -56,7 +55,7 @@ class Service implements InjectionAwareInterface
|
||||
public function getBaseCurrencyRate($foreign_code)
|
||||
{
|
||||
$f_rate = $this->getRateByCode($foreign_code);
|
||||
if ($f_rate == 0) {
|
||||
if (0 == $f_rate) {
|
||||
throw new \Box_Exception('Currency conversion rate can not be zero');
|
||||
}
|
||||
|
||||
@@ -65,13 +64,13 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function getCurrencyByClientId($client_id)
|
||||
{
|
||||
$sql = "SELECT currency FROM client WHERE id = :client_id";
|
||||
$values = array(':client_id' => $client_id);
|
||||
$sql = 'SELECT currency FROM client WHERE id = :client_id';
|
||||
$values = [':client_id' => $client_id];
|
||||
|
||||
$db = $this->di['db'];
|
||||
$db = $this->di['db'];
|
||||
$currency = $db->getCell($sql, $values);
|
||||
|
||||
if (NULL === $currency) {
|
||||
if (null === $currency) {
|
||||
return $this->getDefault();
|
||||
}
|
||||
|
||||
@@ -88,15 +87,15 @@ class Service implements InjectionAwareInterface
|
||||
*/
|
||||
public function getByCode($code)
|
||||
{
|
||||
return $this->di['db']->findOne('Currency', 'code = :code', array(':code' => $code));
|
||||
return $this->di['db']->findOne('Currency', 'code = :code', [':code' => $code]);
|
||||
}
|
||||
|
||||
public function getRateByCode($code)
|
||||
{
|
||||
$sql = "SELECT conversion_rate FROM currency WHERE code = :code";
|
||||
$values = array(':code' => $code);
|
||||
$sql = 'SELECT conversion_rate FROM currency WHERE code = :code';
|
||||
$values = [':code' => $code];
|
||||
|
||||
$db = $this->di['db'];
|
||||
$db = $this->di['db'];
|
||||
$rate = $db->getCell($sql, $values);
|
||||
|
||||
return is_numeric($rate) ? $rate : 1;
|
||||
@@ -107,7 +106,7 @@ class Service implements InjectionAwareInterface
|
||||
$db = $this->di['db'];
|
||||
$default = $db->findOne('Currency', 'is_default = 1');
|
||||
|
||||
if (is_array($default) && count($default) == 0) {
|
||||
if (is_array($default) && 0 == count($default)) {
|
||||
$default = $db->load('Currency', '1');
|
||||
}
|
||||
|
||||
@@ -116,20 +115,19 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function setAsDefault(\Model_Currency $currency)
|
||||
{
|
||||
|
||||
$db = $this->di['db'];
|
||||
|
||||
if ($currency->is_default) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($currency->code === null || empty($currency->code)) {
|
||||
if (null === $currency->code || empty($currency->code)) {
|
||||
throw new \Box_Exception('Currency code not provided');
|
||||
}
|
||||
|
||||
$sql1 = "UPDATE currency SET is_default = 0 WHERE 1";
|
||||
$sql2 = "UPDATE currency SET is_default = 1 WHERE code = :code";
|
||||
$values2 = array(':code' => $currency->code);
|
||||
$sql1 = 'UPDATE currency SET is_default = 0 WHERE 1';
|
||||
$sql2 = 'UPDATE currency SET is_default = 1 WHERE code = :code';
|
||||
$values2 = [':code' => $currency->code];
|
||||
|
||||
$db->exec($sql1);
|
||||
$db->exec($sql2, $values2);
|
||||
@@ -141,22 +139,22 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function getPairs()
|
||||
{
|
||||
$sql = "SELECT code, title FROM currency";
|
||||
$db = $this->di['db'];
|
||||
$sql = 'SELECT code, title FROM currency';
|
||||
$db = $this->di['db'];
|
||||
|
||||
$pairs = $db->getAssoc($sql);
|
||||
|
||||
return $pairs;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a list of available currencies.
|
||||
*
|
||||
*
|
||||
* @return string List of currencies in the "[short code] - [name]" format
|
||||
*/
|
||||
*/
|
||||
public function getAvailableCurrencies()
|
||||
{
|
||||
$options = array(
|
||||
$options = [
|
||||
'AED' => 'United Arab Emirates dirham',
|
||||
'AFN' => 'Afghan afghani',
|
||||
'ALL' => 'Albanian lek',
|
||||
@@ -310,10 +308,10 @@ class Service implements InjectionAwareInterface
|
||||
'ZAR' => 'South African rand',
|
||||
'ZMK' => 'Zambian kwacha',
|
||||
'ZWL' => 'Zimbabwe dollar',
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($options as $key => &$name) {
|
||||
$name = $key . ' - ' . $name;
|
||||
$name = $key.' - '.$name;
|
||||
}
|
||||
|
||||
return $options;
|
||||
@@ -325,103 +323,110 @@ class Service implements InjectionAwareInterface
|
||||
throw new \Box_Exception('Can not remove default currency');
|
||||
}
|
||||
|
||||
if ($model->code === null || empty($model->code)) {
|
||||
if (null === $model->code || empty($model->code)) {
|
||||
throw new \Box_Exception('Currency code not found');
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM currency WHERE code = :code";
|
||||
$values = array(':code' => $model->code);
|
||||
$sql = 'DELETE FROM currency WHERE code = :code';
|
||||
$values = [':code' => $model->code];
|
||||
|
||||
$db = $this->di['db'];
|
||||
$db->exec($sql, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the API credentials for currencylayer.
|
||||
*
|
||||
*
|
||||
* @todo maybe make this extensible so people can choose their data provider?
|
||||
*
|
||||
* @since 4.22.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
$sql = "SELECT `param`, `value` FROM setting";
|
||||
$db = $this->di['db'];
|
||||
$sql = 'SELECT `param`, `value` FROM setting';
|
||||
$db = $this->di['db'];
|
||||
|
||||
$pairs = $db->getAssoc($sql);
|
||||
|
||||
return $pairs['currencylayer'];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Updates the API credentials for currencylayer.
|
||||
*
|
||||
*
|
||||
* @todo maybe make this extensible so people can choose their data provider?
|
||||
*
|
||||
* @since 4.22.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
*/
|
||||
public function updateKey($key)
|
||||
{
|
||||
$sql = "INSERT INTO `setting` (`param`, `value`, `public`, `created_at`, `updated_at`) VALUES ('currencylayer', :key, '0', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE `value`=:key, `updated_at`=CURRENT_TIMESTAMP()";
|
||||
$values = array(':key' => $key);
|
||||
$sql = "INSERT INTO `setting` (`param`, `value`, `public`, `created_at`, `updated_at`) VALUES ('currencylayer', :key, '0', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE `value`=:key, `updated_at`=CURRENT_TIMESTAMP()";
|
||||
$values = [':key' => $key];
|
||||
|
||||
$db = $this->di['db'];
|
||||
$db = $this->di['db'];
|
||||
$currency = $db->exec($sql, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* See if we should update exchange rates whenever the CRON jobs are run.
|
||||
*
|
||||
*
|
||||
* @since 4.22.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
*/
|
||||
public function isCronEnabled()
|
||||
{
|
||||
$sql = "SELECT `param`, `value` FROM setting";
|
||||
$db = $this->di['db'];
|
||||
$sql = 'SELECT `param`, `value` FROM setting';
|
||||
$db = $this->di['db'];
|
||||
|
||||
$pairs = $db->getAssoc($sql);
|
||||
|
||||
if (isset($pairs['currency_cron_enabled']) && $pairs['currency_cron_enabled'] == "1") {
|
||||
if (isset($pairs['currency_cron_enabled']) && '1' == $pairs['currency_cron_enabled']) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Enable or disable updating exchange rates whenever the CRON jobs are run.
|
||||
*
|
||||
*
|
||||
* @since 4.22.0
|
||||
* @var int $data
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
*/
|
||||
public function setCron($data)
|
||||
{
|
||||
$sql = "INSERT INTO `setting` (`param`, `value`, `public`, `created_at`, `updated_at`) VALUES ('currency_cron_enabled', :key, '0', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE `value`=:key, `updated_at`=CURRENT_TIMESTAMP()";
|
||||
|
||||
if ($data == "1") {
|
||||
$key = "1";
|
||||
$sql = "INSERT INTO `setting` (`param`, `value`, `public`, `created_at`, `updated_at`) VALUES ('currency_cron_enabled', :key, '0', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE `value`=:key, `updated_at`=CURRENT_TIMESTAMP()";
|
||||
|
||||
if ('1' == $data) {
|
||||
$key = '1';
|
||||
} else {
|
||||
$key = "0";
|
||||
$key = '0';
|
||||
}
|
||||
|
||||
$values = array(':key' => $key);
|
||||
$values = [':key' => $key];
|
||||
|
||||
$db = $this->di['db'];
|
||||
$db = $this->di['db'];
|
||||
$currency = $db->exec($sql, $values);
|
||||
}
|
||||
|
||||
public function toApiArray(\Model_Currency $model)
|
||||
{
|
||||
return array(
|
||||
'code' => $model->code,
|
||||
'title' => $model->title,
|
||||
'conversion_rate' => (float)$model->conversion_rate,
|
||||
'format' => $model->format,
|
||||
'price_format' => $model->price_format,
|
||||
'default' => $model->is_default,
|
||||
);
|
||||
return [
|
||||
'code' => $model->code,
|
||||
'title' => $model->title,
|
||||
'conversion_rate' => (float) $model->conversion_rate,
|
||||
'format' => $model->format,
|
||||
'price_format' => $model->price_format,
|
||||
'default' => $model->is_default,
|
||||
];
|
||||
}
|
||||
|
||||
public function createCurrency($code, $format, $title = null, $conversionRate = 1)
|
||||
@@ -431,13 +436,13 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$this->validateCurrencyFormat($format);
|
||||
|
||||
$model = $this->di['db']->dispense('Currency');
|
||||
$model->code = $code;
|
||||
$model->title = $title;
|
||||
$model->format = $format;
|
||||
$model = $this->di['db']->dispense('Currency');
|
||||
$model->code = $code;
|
||||
$model->title = $title;
|
||||
$model->format = $format;
|
||||
$model->conversion_rate = $conversionRate;
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Added new currency %s', $model->code);
|
||||
@@ -447,7 +452,7 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function validateCurrencyFormat($format)
|
||||
{
|
||||
if (strpos($format, '{{price}}') === false) {
|
||||
if (false === strpos($format, '{{price}}')) {
|
||||
throw new \Exception('Currency format must include {{price}} tag', 3569);
|
||||
}
|
||||
}
|
||||
@@ -493,7 +498,7 @@ class Service implements InjectionAwareInterface
|
||||
{
|
||||
$dc = $this->getDefault();
|
||||
|
||||
$db = $this->di['db'];
|
||||
$db = $this->di['db'];
|
||||
|
||||
$all = $db->find('Currency'); // should return Array of beans
|
||||
|
||||
@@ -517,37 +522,38 @@ class Service implements InjectionAwareInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Fetch exchange rates from external sources.
|
||||
* Uses data from the European Central Bank and currencylayer when the base currencies are Euro and US Dollar respectively
|
||||
*
|
||||
* Uses data from the European Central Bank and currencylayer when the base currencies are Euro and US Dollar respectively.
|
||||
*
|
||||
* @todo use Guzzle instead of simplexml_load_file()
|
||||
* @var string $from Short code for the base currency
|
||||
* @var string $to Short code for the target currency
|
||||
* @return float Exchange rate
|
||||
*
|
||||
* @var string Short code for the base currency
|
||||
* @var string Short code for the target currency
|
||||
*
|
||||
* @return float Exchange rate
|
||||
*/
|
||||
protected function _getRate($from, $to)
|
||||
{
|
||||
$from_Currency = urlencode($from);
|
||||
$to_Currency = urlencode($to);
|
||||
$to_Currency = urlencode($to);
|
||||
|
||||
if ($from_Currency == "EUR") {
|
||||
$XML = simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
|
||||
if ('EUR' == $from_Currency) {
|
||||
$XML = simplexml_load_file('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
|
||||
foreach ($XML->Cube->Cube->Cube as $rate) {
|
||||
if ($rate["currency"] == $to_Currency) {
|
||||
return (float) $rate["rate"];
|
||||
};
|
||||
if ($rate['currency'] == $to_Currency) {
|
||||
return (float) $rate['rate'];
|
||||
}
|
||||
}
|
||||
} else if ($from_Currency == "USD") {
|
||||
$res = $this->di['guzzle_client']->get("http://api.currencylayer.com/live?access_key=". $this->getKey() ."¤cies=". $to_Currency ."&format=1");
|
||||
} elseif ('USD' == $from_Currency) {
|
||||
$res = $this->di['guzzle_client']->get('http://api.currencylayer.com/live?access_key='.$this->getKey().'¤cies='.$to_Currency.'&format=1');
|
||||
$array = json_decode($res->getBody(), true);
|
||||
if ($array["success"] !== true) {
|
||||
throw new \Box_Exception("<b>Currencylayer threw an error:</b><br />" . $array["error"]["info"]);
|
||||
if (true !== $array['success']) {
|
||||
throw new \Box_Exception('<b>Currencylayer threw an error:</b><br />'.$array['error']['info']);
|
||||
} else {
|
||||
return (float) $array["quotes"]["USD".$to_Currency];
|
||||
return (float) $array['quotes']['USD'.$to_Currency];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteCurrencyByCode($code)
|
||||
@@ -559,29 +565,30 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
$code = $model->code;
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onBeforeAdminDeleteCurrency', 'params' => array('code' => $code)));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminDeleteCurrency', 'params' => ['code' => $code]]);
|
||||
|
||||
$this->rm($model);
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onAfterAdminDeleteCurrency', 'params' => array('code' => $code)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminDeleteCurrency', 'params' => ['code' => $code]]);
|
||||
|
||||
$this->di['logger']->info('Removed currency %s', $code);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If enabled, automatically call _getRate to fetch exchange rates whenever CRON jobs are run
|
||||
/**
|
||||
* If enabled, automatically call _getRate to fetch exchange rates whenever CRON jobs are run.
|
||||
*
|
||||
* @since 4.22.0
|
||||
*/
|
||||
public static function onBeforeAdminCronRun(\Box_Event $event)
|
||||
{
|
||||
$di = $event->getDi();
|
||||
$currencyService = $di['mod_service']('currency');
|
||||
$di = $event->getDi();
|
||||
$currencyService = $di['mod_service']('currency');
|
||||
|
||||
try {
|
||||
if ($currencyService->isCronEnabled()) {
|
||||
$currencyService->updateCurrencyRates("");
|
||||
$currencyService->updateCurrencyRates('');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log($e);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -15,7 +15,7 @@ namespace Box\Mod\Custompages\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of custom pages
|
||||
* Get paginated list of custom pages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete custom page
|
||||
* Delete custom page.
|
||||
*
|
||||
* @param int $id - custom page ID
|
||||
*
|
||||
@@ -40,17 +40,18 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Custom Page ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$this->getService()->deletePage($data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete custom pages
|
||||
* Delete custom pages.
|
||||
*
|
||||
* @param array $ids - custom page IDs
|
||||
*
|
||||
@@ -58,19 +59,20 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function batch_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ids' => 'Custom Page IDs not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$this->getService()->deletePage($data['ids']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new custom page
|
||||
* Create new custom page.
|
||||
*
|
||||
* @param string $title - custom page title
|
||||
* @param string $title - custom page title
|
||||
* @param string $content - custom page content
|
||||
*
|
||||
* @optional string $description - custom page meta description
|
||||
@@ -80,26 +82,26 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'title' => 'Custom page title not passed',
|
||||
'content' => 'Custom page content not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$title = $data['title'];
|
||||
$title = $data['title'];
|
||||
|
||||
$content = $data['content'];
|
||||
$description = $this->di['array_get']($data, 'description', NULL);
|
||||
$keywords = $this->di['array_get']($data, 'keywords', NULL);
|
||||
$content = $data['content'];
|
||||
$description = $this->di['array_get']($data, 'description', null);
|
||||
$keywords = $this->di['array_get']($data, 'keywords', null);
|
||||
|
||||
return $this->getService()->createPage($title, $description, $keywords, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update custom page
|
||||
* Update custom page.
|
||||
*
|
||||
* @param string $id - custom page id
|
||||
* @param string $slug - custom page slug
|
||||
* @param string $id - custom page id
|
||||
* @param string $slug - custom page slug
|
||||
* @param string $content - custom page content
|
||||
*
|
||||
* @optional string $description - custom page meta description
|
||||
@@ -109,26 +111,26 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Custom page id not passed',
|
||||
'title' => 'Custom page title not passed',
|
||||
'slug' => 'Custom page slug not passed',
|
||||
'content' => 'Custom page content not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$id = $data['id'];
|
||||
$title = $data['title'];
|
||||
$content = $data['content'];
|
||||
$slug = $data['slug'];
|
||||
$description = $this->di['array_get']($data, 'description', NULL);
|
||||
$keywords = $this->di['array_get']($data, 'keywords', NULL);
|
||||
$description = $this->di['array_get']($data, 'description', null);
|
||||
$keywords = $this->di['array_get']($data, 'keywords', null);
|
||||
|
||||
return $this->getService()->updatePage($id, $title, $description, $keywords, $content, $slug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom page by id
|
||||
* Get custom page by id.
|
||||
*
|
||||
* @param string $id - custom page id
|
||||
*
|
||||
@@ -138,4 +140,4 @@ class Admin extends \Api_Abstract
|
||||
{
|
||||
return $this->getService()->getPage($data['page_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -34,34 +34,34 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'subpages'=> array(
|
||||
array(
|
||||
'location' => 'extensions',
|
||||
'label' => 'Custom Pages',
|
||||
'index' => 2000,
|
||||
'uri' => $this->di['url']->adminLink('custompages'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return [
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'extensions',
|
||||
'label' => 'Custom Pages',
|
||||
'index' => 2000,
|
||||
'uri' => $this->di['url']->adminLink('custompages'),
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/custompages', 'get_index', array(), get_class($this));
|
||||
$app->get('/custompages/:id', 'get_page', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/custompages', 'get_index', [], get_class($this));
|
||||
$app->get('/custompages/:id', 'get_page', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_custompages_index');
|
||||
}
|
||||
|
||||
public function get_page(\Box_App $app, $id)
|
||||
{
|
||||
return $app->render('mod_custompages_page', array('page_id' => $id));
|
||||
return $app->render('mod_custompages_page', ['page_id' => $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/**
|
||||
* This file connects BoxBilling client area interface and API
|
||||
* Class does not extend any other class
|
||||
* Class does not extend any other class.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Custompages\Controller;
|
||||
@@ -40,13 +40,13 @@ class Client implements \Box\InjectionAwareInterface
|
||||
/**
|
||||
* Methods maps client areas urls to corresponding methods
|
||||
* Always use your module prefix to avoid conflicts with other modules
|
||||
* in future
|
||||
* in future.
|
||||
*
|
||||
* @param \Box_App $app - returned by reference
|
||||
*/
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/custompages/:slug', 'get_page', array('slug' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/custompages/:slug', 'get_page', ['slug' => '[a-z0-9-]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_page(\Box_App $app, $slug)
|
||||
@@ -54,11 +54,10 @@ class Client implements \Box\InjectionAwareInterface
|
||||
$service = new \Box\Mod\Custompages\Service();
|
||||
$service->setDi($this->di);
|
||||
$page = $service->getPage($slug, 'slug');
|
||||
if(isset($page['id'])) {
|
||||
return $app->render('mod_custompages_content', array('page' => $page));
|
||||
}
|
||||
else {
|
||||
die(header('Location: '.$this->di['url']->get('')));
|
||||
if (isset($page['id'])) {
|
||||
return $app->render('mod_custompages_content', ['page' => $page]);
|
||||
} else {
|
||||
exit(header('Location: '.$this->di['url']->get('')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -24,47 +24,52 @@ class Service
|
||||
public function install()
|
||||
{
|
||||
$db = $this->di['db'];
|
||||
$db->exec("CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8");
|
||||
$db->exec('CREATE TABLE IF NOT EXISTS `custom_pages` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` varchar(555) NOT NULL, `keywords` varchar(555) NOT NULL, `content` text NOT NULL, `slug` varchar(255) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function searchPages($search = null, $per_page = 100, $page = null)
|
||||
{
|
||||
$filter = array();
|
||||
$sql = "SELECT * FROM custom_pages WHERE 1";
|
||||
$filter = [];
|
||||
$sql = 'SELECT * FROM custom_pages WHERE 1';
|
||||
if ($search) {
|
||||
$sql .= " AND title LIKE :q OR content LIKE :q";
|
||||
$sql .= ' AND title LIKE :q OR content LIKE :q';
|
||||
$filter[':q'] = "%$search%";
|
||||
}
|
||||
$sql .= " ORDER BY id DESC";
|
||||
$sql .= ' ORDER BY id DESC';
|
||||
|
||||
return $this->di['pager']->getSimpleResultSet($sql, $filter, $per_page, $page);
|
||||
}
|
||||
|
||||
public function deletePage($id) {
|
||||
if(is_array($id)) {
|
||||
foreach($id as $i => $x) {
|
||||
$id[$i] = (int)$x;
|
||||
public function deletePage($id)
|
||||
{
|
||||
if (is_array($id)) {
|
||||
foreach ($id as $i => $x) {
|
||||
$id[$i] = (int) $x;
|
||||
}
|
||||
$this->di['pdo']->query('DELETE from custom_pages WHERE id in ('.join(', ', $id).')');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->di['pdo']->prepare('DELETE from custom_pages WHERE id = ?')->execute([$id]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPage($id, $type = 'id') {
|
||||
public function getPage($id, $type = 'id')
|
||||
{
|
||||
$q = $this->di['pdo']->prepare('SELECT * from custom_pages WHERE '.$type.' = ?');
|
||||
$q->execute([$id]);
|
||||
|
||||
return $q->fetch();
|
||||
}
|
||||
|
||||
public function createPage($title, $description, $keywords, $content) {
|
||||
public function createPage($title, $description, $keywords, $content)
|
||||
{
|
||||
$slug = $this->di['tools']->slug($title);
|
||||
$i = 0;
|
||||
$ex = $this->di['pdo']->prepare('SELECT id from custom_pages WHERE slug = ?');
|
||||
$ex->execute([$slug]);
|
||||
$ex = $ex->rowCount();
|
||||
while($ex > 0) {
|
||||
while ($ex > 0) {
|
||||
$slug = $this->di['tools']->slug($title).'-'.++$i;
|
||||
$ex = $this->di['pdo']->prepare('SELECT id from custom_pages WHERE slug = ?');
|
||||
$ex->execute([$slug]);
|
||||
@@ -73,18 +78,21 @@ class Service
|
||||
$this->di['pdo']->prepare('INSERT into custom_pages (title, description, keywords, content, slug) VALUES (?, ?, ?, ?, ?)')->execute([$title, $description, $keywords, $content, $slug]);
|
||||
$id = $this->di['pdo']->lastInsertId();
|
||||
$this->di['logger']->info('Created new custom page #%s', $id);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function updatePage($id, $title, $description, $keywords, $content, $slug) {
|
||||
public function updatePage($id, $title, $description, $keywords, $content, $slug)
|
||||
{
|
||||
$slug = $this->di['tools']->slug($slug);
|
||||
$ex = $this->di['pdo']->prepare('SELECT id from custom_pages WHERE slug = ? AND id <> ?');
|
||||
$ex->execute([$slug, $id]);
|
||||
if($ex->rowCount() > 0) {
|
||||
die(json_encode(['result' => null, 'error' => ['message' => 'You need to set unique slug.', 'code' => 9999]]));
|
||||
if ($ex->rowCount() > 0) {
|
||||
exit(json_encode(['result' => null, 'error' => ['message' => 'You need to set unique slug.', 'code' => 9999]]));
|
||||
}
|
||||
$this->di['pdo']->prepare('UPDATE custom_pages SET title = ?, description = ?, keywords = ?, content = ?, slug = ? WHERE id = ?')->execute([$title, $description, $keywords, $content, $slug, $id]);
|
||||
$this->di['logger']->info('Updated custom page #%s', $id);
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Dashboard\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,12 +34,13 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/dashboard', 'get_dashboard_index', array(), get_class($this));
|
||||
$app->get('/dashboard', 'get_dashboard_index', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_dashboard_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_client_logged'];
|
||||
|
||||
return $app->render('mod_dashboard_index');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,86 +11,91 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*Email logs and templates management
|
||||
*Email logs and templates management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Email\Api;
|
||||
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of sent emails
|
||||
* Get list of sent emails.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function email_get_list($data)
|
||||
{
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$pager['list'][$key] = array(
|
||||
'id' => $item['id'],
|
||||
'client_id' => $item['client_id'],
|
||||
'sender' => $item['sender'],
|
||||
'recipients' => $item['recipients'],
|
||||
'subject' => $item['subject'],
|
||||
$pager['list'][$key] = [
|
||||
'id' => $item['id'],
|
||||
'client_id' => $item['client_id'],
|
||||
'sender' => $item['sender'],
|
||||
'recipients' => $item['recipients'],
|
||||
'subject' => $item['subject'],
|
||||
'content_html' => $item['content_html'],
|
||||
'content_text' => $item['content_text'],
|
||||
'created_at' => $item['created_at'],
|
||||
'updated_at' => $item['updated_at'],
|
||||
);
|
||||
'created_at' => $item['created_at'],
|
||||
'updated_at' => $item['updated_at'],
|
||||
];
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sent email details
|
||||
* Get sent email details.
|
||||
*
|
||||
* @param int $id - email ID
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function email_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$service = $this->getService();
|
||||
$model = $service->getEmailById($data['id']);
|
||||
|
||||
return $service->toApiArray($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Email send
|
||||
* Email send.
|
||||
*
|
||||
* @param string $to - email to
|
||||
* @param string $to_name - to name
|
||||
* @param string $to - email to
|
||||
* @param string $to_name - to name
|
||||
* @param string $from_name - from name
|
||||
* @param string $from - from email
|
||||
* @param string $subject - from email
|
||||
* @param string $content - from email
|
||||
* @param string $from - from email
|
||||
* @param string $subject - from email
|
||||
* @param string $content - from email
|
||||
*
|
||||
* @optional int $client_id - log this message to client history
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function send($data = array())
|
||||
public function send($data = [])
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'to' => 'Receiver Email is required',
|
||||
'to_name' => 'Receiver Name is required',
|
||||
'from' => 'Sender Name is required',
|
||||
'from_name' => 'Sender email is required',
|
||||
'subject' => 'Email subject is required',
|
||||
'content' => 'Email content is required',
|
||||
);
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
$client_id = $this->di['array_get']($data, 'client_id');
|
||||
$emailService = $this->getService();
|
||||
|
||||
@@ -106,21 +111,23 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Resend email
|
||||
* Resend email.
|
||||
*
|
||||
* @param int $id - email ID
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function email_resend($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('ActivityClientEmail', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('ActivityClientEmail', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_ActivityClientEmail) {
|
||||
throw new \Box_Exception('Email not found');
|
||||
@@ -130,21 +137,23 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete sent email from logs
|
||||
* Delete sent email from logs.
|
||||
*
|
||||
* @param int $id - email ID
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function email_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('ActivityClientEmail', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('ActivityClientEmail', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_ActivityClientEmail) {
|
||||
throw new \Box_Exception('Email not found');
|
||||
@@ -159,44 +168,45 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of email templates
|
||||
* Return list of email templates.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function template_get_list($data)
|
||||
{
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list($sql, $params) = $this->getService()->templateGetSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->templateGetSearchQuery($data);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$pager['list'][$key] = array(
|
||||
'id' => $this->di['array_get']($item, 'id', ''),
|
||||
$pager['list'][$key] = [
|
||||
'id' => $this->di['array_get']($item, 'id', ''),
|
||||
'action_code' => $this->di['array_get']($item, 'action_code', ''),
|
||||
'category' => $this->di['array_get']($item, 'category', ''),
|
||||
'enabled' => $this->di['array_get']($item, 'enabled', ''),
|
||||
'subject' => $this->di['array_get']($item, 'subject', ''),
|
||||
'category' => $this->di['array_get']($item, 'category', ''),
|
||||
'enabled' => $this->di['array_get']($item, 'enabled', ''),
|
||||
'subject' => $this->di['array_get']($item, 'subject', ''),
|
||||
'description' => $this->di['array_get']($item, 'description', ''),
|
||||
);
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email template full details
|
||||
* Get email template full details.
|
||||
*
|
||||
* @param int $id - template id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function template_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('EmailTemplate', $data['id'], 'Email template not found');
|
||||
@@ -205,21 +215,23 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete email template
|
||||
* Delete email template.
|
||||
*
|
||||
* @param int $id - email template ID
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function template_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('EmailTemplate', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('EmailTemplate', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_EmailTemplate) {
|
||||
throw new \Box_Exception('Email template not found');
|
||||
@@ -238,22 +250,23 @@ class Admin extends \Api_Abstract
|
||||
* combined with custom event hook.
|
||||
*
|
||||
* @param string $action_code - template action code
|
||||
* @param string $subject - Email subject
|
||||
* @param string $content - Email body
|
||||
* @param string $subject - Email subject
|
||||
* @param string $content - Email body
|
||||
*
|
||||
* @return int - newly created template id
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function template_create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'action_code' => 'Email template code is required',
|
||||
'subject' => 'Email template subject is required',
|
||||
'content' => 'Email template content is required',
|
||||
);
|
||||
'subject' => 'Email template subject is required',
|
||||
'content' => 'Email template content is required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$enabled = $this->di['array_get']($data, 'enabled', 0);
|
||||
$enabled = $this->di['array_get']($data, 'enabled', 0);
|
||||
$category = $this->di['array_get']($data, 'category');
|
||||
|
||||
$templateModel = $this->getService()->templateCreate($data['action_code'], $data['subject'], $data['content'], $enabled, $category);
|
||||
@@ -262,104 +275,109 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Update email template
|
||||
* Update email template.
|
||||
*
|
||||
* @param int $id - template id
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function template_update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$enabled = $this->di['array_get']($data, 'enabled');
|
||||
$enabled = $this->di['array_get']($data, 'enabled');
|
||||
$category = $this->di['array_get']($data, 'category');
|
||||
$subject = $this->di['array_get']($data, 'subject');
|
||||
$content = $this->di['array_get']($data, 'content');
|
||||
$subject = $this->di['array_get']($data, 'subject');
|
||||
$content = $this->di['array_get']($data, 'content');
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('EmailTemplate', $data['id'], 'Email template not found');
|
||||
|
||||
return $this->getService()->updateTemplate($model, $enabled, $category, $subject, $content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset email template to default
|
||||
* Reset email template to default.
|
||||
*
|
||||
* @param string $code - template code
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function template_reset($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'code' => 'Email template code was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
return $this->getService()->resetTemplateByCode($data['code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates email template preview
|
||||
* Generates email template preview.
|
||||
*
|
||||
* @param int $id - template id
|
||||
* @optional string $_tpl - string to be rendered. Default is email template.
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function template_render($data)
|
||||
{
|
||||
$t = $this->template_get($data);
|
||||
$vars = $t['vars'];
|
||||
$t = $this->template_get($data);
|
||||
$vars = $t['vars'];
|
||||
$vars['_tpl'] = $this->di['array_get']($data, '_tpl', $t['content']);
|
||||
$systemService = $this->di['mod_service']('System');
|
||||
|
||||
return $systemService->renderString($vars['_tpl'], true, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate email templates according to enabled extensions
|
||||
* Generate email templates according to enabled extensions.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function batch_template_generate()
|
||||
{
|
||||
return $this->getService()->templateBatchGenerate();
|
||||
return $this->getService()->templateBatchGenerate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable all email templates at once.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function batch_template_disable($data)
|
||||
{
|
||||
return $this->getService()->templateBatchDisable();
|
||||
return $this->getService()->templateBatchDisable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable all email templates at once
|
||||
* Enable all email templates at once.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function batch_template_enable($data)
|
||||
{
|
||||
return $this->getService()->templateBatchEnable();
|
||||
return $this->getService()->templateBatchEnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends test email to admins
|
||||
* Sends test email to admins.
|
||||
*
|
||||
* @param type $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send_test($data)
|
||||
{
|
||||
$email = array();
|
||||
$email = [];
|
||||
$email['to_staff'] = true;
|
||||
$email['code'] = 'mod_email_test';
|
||||
$email['code'] = 'mod_email_test';
|
||||
|
||||
return $this->getService()->sendTemplate($email);
|
||||
}
|
||||
@@ -369,10 +387,9 @@ class Admin extends \Api_Abstract
|
||||
return $this->getService()->batchSend();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send email template to email, client or staff members. If template with code does not exist,
|
||||
* it will be created. Default email template file must exist at mod_example/html_email/mod_example_code.phtml file
|
||||
* it will be created. Default email template file must exist at mod_example/html_email/mod_example_code.phtml file.
|
||||
*
|
||||
* @param string $code - Template code to send. Must be mod_%s_%s structure
|
||||
*
|
||||
@@ -393,9 +410,9 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function template_send($data)
|
||||
{
|
||||
$required = array(
|
||||
'code' => 'Template code not passed',
|
||||
);
|
||||
$required = [
|
||||
'code' => 'Template code not passed',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if (!isset($data['to']) && !isset($data['to_staff']) && !isset($data['to_client'])) {
|
||||
@@ -406,7 +423,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes email logs with given IDs
|
||||
* Deletes email logs with given IDs.
|
||||
*
|
||||
* @param array $ids - IDs for deletion
|
||||
*
|
||||
@@ -414,16 +431,15 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function batch_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ids' => 'IDs not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
foreach ($data['ids'] as $id) {
|
||||
$this->email_delete(array('id' => $id));
|
||||
$this->email_delete(['id' => $id]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*Emails history listing and management
|
||||
*Emails history listing and management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Email\Api;
|
||||
@@ -19,46 +19,50 @@ namespace Box\Mod\Email\Api;
|
||||
class Client extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of emails system had sent to client
|
||||
* Get list of emails system had sent to client.
|
||||
*
|
||||
* @return array - paginated list
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$client = $this->getIdentity();
|
||||
$client = $this->getIdentity();
|
||||
$data['client_id'] = $client->id;
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$pager['list'][$key] = array(
|
||||
'id' => $item['id'],
|
||||
'client_id' => $item['client_id'],
|
||||
'sender' => $item['sender'],
|
||||
'recipients' => $item['recipients'],
|
||||
'subject' => $item['subject'],
|
||||
$pager['list'][$key] = [
|
||||
'id' => $item['id'],
|
||||
'client_id' => $item['client_id'],
|
||||
'sender' => $item['sender'],
|
||||
'recipients' => $item['recipients'],
|
||||
'subject' => $item['subject'],
|
||||
'content_html' => $item['content_html'],
|
||||
'content_text' => $item['content_text'],
|
||||
'created_at' => $item['created_at'],
|
||||
'updated_at' => $item['updated_at'],
|
||||
);
|
||||
'created_at' => $item['created_at'],
|
||||
'updated_at' => $item['updated_at'],
|
||||
];
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email details
|
||||
* Get email details.
|
||||
*
|
||||
* @param int $id - Email id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->getService()->findOneForClientById($this->getIdentity(), $data['id']);
|
||||
@@ -71,22 +75,24 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Resend email to client once again
|
||||
*
|
||||
* Resend email to client once again.
|
||||
*
|
||||
* @param int $id - Email id
|
||||
*
|
||||
* @return type
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function resend($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->getService()->findOneForClientById($this->getIdentity(), $data['id']);
|
||||
if(!$model instanceof \Model_ActivityClientEmail) {
|
||||
if (!$model instanceof \Model_ActivityClientEmail) {
|
||||
throw new \Box_Exception('Email not found');
|
||||
}
|
||||
|
||||
@@ -95,16 +101,19 @@ class Client extends \Api_Abstract
|
||||
|
||||
/**
|
||||
* Remove email from system.
|
||||
*
|
||||
* @param int $id - Email id
|
||||
*
|
||||
* @return type
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'Email ID is required',
|
||||
);
|
||||
$required = [
|
||||
'id' => 'Email ID is required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->getService()->findOneForClientById($this->getIdentity(), $data['id']);
|
||||
@@ -114,4 +123,4 @@ class Client extends \Api_Abstract
|
||||
|
||||
return $this->getService()->rm($model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Email\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,45 +34,48 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'subpages' => array(
|
||||
array(
|
||||
'location' => 'activity',
|
||||
'index' => 200,
|
||||
return [
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'activity',
|
||||
'index' => 200,
|
||||
'label' => 'Email history',
|
||||
'uri' => $this->di['url']->adminLink('email/history'),
|
||||
'uri' => $this->di['url']->adminLink('email/history'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/email/history/', 'get_history', array(), get_class($this));
|
||||
$app->get('/email/history', 'get_history', array(), get_class($this));
|
||||
$app->get('/email/templates', 'get_index', array(), get_class($this));
|
||||
$app->get('/email/template/:id', 'get_template', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/email/:id', 'get_email', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/email/history/', 'get_history', [], get_class($this));
|
||||
$app->get('/email/history', 'get_history', [], get_class($this));
|
||||
$app->get('/email/templates', 'get_index', [], get_class($this));
|
||||
$app->get('/email/template/:id', 'get_template', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/email/:id', 'get_email', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_history(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_email_history');
|
||||
}
|
||||
|
||||
|
||||
public function get_template(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$template = $api->email_template_get(array('id'=>$id));
|
||||
return $app->render('mod_email_template', array('template'=>$template));
|
||||
$template = $api->email_template_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_email_template', ['template' => $template]);
|
||||
}
|
||||
|
||||
|
||||
public function get_email(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$template = $api->email_email_get(array('id'=>$id));
|
||||
return $app->render('mod_email_details', array('email'=>$template));
|
||||
$template = $api->email_email_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_email_details', ['email' => $template]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Email\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,21 +34,23 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/email', 'get_emails', array(), get_class($this));
|
||||
$app->get('/email/:id', 'get_email', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/email', 'get_emails', [], get_class($this));
|
||||
$app->get('/email/:id', 'get_email', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_emails(\Box_App $app)
|
||||
{
|
||||
$this->di['is_client_logged'];
|
||||
|
||||
return $app->render('mod_email_index');
|
||||
}
|
||||
|
||||
public function get_email(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_client'];
|
||||
$data = array('id'=>$id);
|
||||
$data = ['id' => $id];
|
||||
$email = $api->email_get($data);
|
||||
return $app->render('mod_email_email', array('email'=>$email));
|
||||
}
|
||||
|
||||
}
|
||||
return $app->render('mod_email_email', ['email' => $email]);
|
||||
}
|
||||
}
|
||||
+167
-157
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -30,13 +30,13 @@ class Service implements \Box\InjectionAwareInterface
|
||||
{
|
||||
$query = 'SELECT * FROM activity_client_email';
|
||||
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
|
||||
$where = array();
|
||||
$bindings = array();
|
||||
$where = [];
|
||||
$bindings = [];
|
||||
|
||||
if($search) {
|
||||
if ($search) {
|
||||
$search = "%$search%";
|
||||
$where[] = '(sender LIKE :sender OR recipients LIKE :recipient OR subject LIKE :subject OR content_text LIKE :content_text OR content_html LIKE :content_html)';
|
||||
$bindings[':sender'] = $search;
|
||||
@@ -46,37 +46,38 @@ class Service implements \Box\InjectionAwareInterface
|
||||
$bindings[':content_html'] = $search;
|
||||
}
|
||||
|
||||
if(NULL !== $client_id) {
|
||||
$where[] = "client_id = :client_id";
|
||||
if (null !== $client_id) {
|
||||
$where[] = 'client_id = :client_id';
|
||||
$bindings[':client_id'] = $client_id;
|
||||
}
|
||||
|
||||
if (!empty($where)){
|
||||
$query = $query . ' WHERE '.implode(' AND ', $where);
|
||||
if (!empty($where)) {
|
||||
$query = $query.' WHERE '.implode(' AND ', $where);
|
||||
}
|
||||
$query .= ' ORDER BY id DESC';
|
||||
|
||||
return array($query, $bindings);
|
||||
return [$query, $bindings];
|
||||
}
|
||||
|
||||
public function findOneForClientById(\Model_Client $client, $id)
|
||||
{
|
||||
$bindings = array(
|
||||
$bindings = [
|
||||
':id' => $id,
|
||||
':client_id' => $client->id
|
||||
);
|
||||
':client_id' => $client->id,
|
||||
];
|
||||
|
||||
$db = $this->di['db'];
|
||||
|
||||
return $db->findOne('ActivityClientEmail', 'id = :id AND client_id = :client_id ORDER BY id DESC', $bindings);
|
||||
}
|
||||
|
||||
public function rmByClient(\Model_Client $client)
|
||||
{
|
||||
$models = $this->di['db']->find('ActivityClientEmail', 'client_id = ?', array($client->id));
|
||||
foreach($models as $model)
|
||||
{
|
||||
$models = $this->di['db']->find('ActivityClientEmail', 'client_id = ?', [$client->id]);
|
||||
foreach ($models as $model) {
|
||||
$this->di['db']->trash($model);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -84,22 +85,24 @@ class Service implements \Box\InjectionAwareInterface
|
||||
{
|
||||
$db = $this->di['db'];
|
||||
$db->trash($email);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function toApiArray(\Model_ActivityClientEmail $model, $deep = true)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $model->id,
|
||||
'client_id' => $model->client_id,
|
||||
'sender' => $model->sender,
|
||||
'recipients' => $model->recipients,
|
||||
'subject' => $model->subject,
|
||||
$data = [
|
||||
'id' => $model->id,
|
||||
'client_id' => $model->client_id,
|
||||
'sender' => $model->sender,
|
||||
'recipients' => $model->recipients,
|
||||
'subject' => $model->subject,
|
||||
'content_html' => $model->content_html,
|
||||
'content_text' => $model->content_text,
|
||||
'created_at' => $model->created_at,
|
||||
'updated_at' => $model->updated_at,
|
||||
);
|
||||
'created_at' => $model->created_at,
|
||||
'updated_at' => $model->updated_at,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -123,9 +126,9 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
public function sendTemplate($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'code' => 'Template code not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if (!isset($data['to']) && !isset($data['to_staff']) && !isset($data['to_client'])) {
|
||||
@@ -135,69 +138,68 @@ class Service implements \Box\InjectionAwareInterface
|
||||
unset($vars['to'], $vars['to_client'], $vars['to_staff'], $vars['to_name'], $vars['from'], $vars['from_name']);
|
||||
unset($vars['default_description'], $vars['default_subject'], $vars['default_template'], $vars['code']);
|
||||
|
||||
//add aditional variables to template
|
||||
// add aditional variables to template
|
||||
if (isset($data['to_staff']) && $data['to_staff']) {
|
||||
$staffService = $this->di['mod_service']('staff');
|
||||
$staff = $staffService->getList(array('status' => 'active', 'no_cron' => true));
|
||||
$staffService = $this->di['mod_service']('staff');
|
||||
$staff = $staffService->getList(['status' => 'active', 'no_cron' => true]);
|
||||
$vars['staff'] = $staff['list'][0];
|
||||
}
|
||||
|
||||
//add aditional variables to template
|
||||
// add aditional variables to template
|
||||
if (isset($data['to_client']) && $data['to_client'] > 0) {
|
||||
$clientService = $this->di['mod_service']('client');
|
||||
$customer = $clientService->get(array('id' => $data['to_client']));
|
||||
$customer = $clientService->toApiArray($customer);
|
||||
$clientService = $this->di['mod_service']('client');
|
||||
$customer = $clientService->get(['id' => $data['to_client']]);
|
||||
$customer = $clientService->toApiArray($customer);
|
||||
$vars['c'] = $customer;
|
||||
}
|
||||
|
||||
$db = $this->di['db'];
|
||||
|
||||
$t = $db->findOne('EmailTemplate', 'action_code = :action', array(':action' => $data['code']));
|
||||
$t = $db->findOne('EmailTemplate', 'action_code = :action', [':action' => $data['code']]);
|
||||
if (!$t instanceof \Model_EmailTemplate) {
|
||||
|
||||
list($s, $c, $desc, $enabled, $mod) = $this->_getDefaults($data);
|
||||
$t = $db->dispense('EmailTemplate');
|
||||
$t->enabled = $enabled;
|
||||
[$s, $c, $desc, $enabled, $mod] = $this->_getDefaults($data);
|
||||
$t = $db->dispense('EmailTemplate');
|
||||
$t->enabled = $enabled;
|
||||
$t->action_code = $data['code'];
|
||||
$t->category = $mod;
|
||||
$t->subject = $s;
|
||||
$t->content = $c;
|
||||
$t->category = $mod;
|
||||
$t->subject = $s;
|
||||
$t->content = $c;
|
||||
$t->description = $desc;
|
||||
$db->store($t);
|
||||
}
|
||||
|
||||
//update template vars with latest variables
|
||||
// update template vars with latest variables
|
||||
$this->setVars($t, $vars);
|
||||
|
||||
// do not send inactive template
|
||||
if (!$t->enabled) {
|
||||
return false;
|
||||
}
|
||||
$systemService = $this->di['mod_service']('system');
|
||||
$systemService = $this->di['mod_service']('system');
|
||||
|
||||
list($subject, $content) = $this->_parse($t, $vars);
|
||||
$from = $this->di['array_get']($data, 'from', $systemService->getParamValue('company_email'));
|
||||
[$subject, $content] = $this->_parse($t, $vars);
|
||||
$from = $this->di['array_get']($data, 'from', $systemService->getParamValue('company_email'));
|
||||
$from_name = $this->di['array_get']($data, 'from_name', $systemService->getParamValue('company_name'));
|
||||
$sent = false;
|
||||
$sent = false;
|
||||
|
||||
if (!$from){
|
||||
if (!$from) {
|
||||
throw new \Box_Exception('From email address can not be empty');
|
||||
}
|
||||
|
||||
if (isset($staff)) {
|
||||
foreach ($staff['list'] as $staff) {
|
||||
$to = $staff['email'];
|
||||
$to = $staff['email'];
|
||||
$to_name = $staff['name'];
|
||||
$sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name, null, $staff['id']);
|
||||
$sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name, null, $staff['id']);
|
||||
}
|
||||
} else if (isset($customer)) {
|
||||
$to = $customer['email'];
|
||||
$to_name = $customer['first_name'] . ' ' . $customer['last_name'];
|
||||
$sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name, $customer['id']);
|
||||
} elseif (isset($customer)) {
|
||||
$to = $customer['email'];
|
||||
$to_name = $customer['first_name'].' '.$customer['last_name'];
|
||||
$sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name, $customer['id']);
|
||||
} else {
|
||||
$to = $data['to'];
|
||||
$to = $data['to'];
|
||||
$to_name = $this->di['array_get']($data, 'to_name', null);
|
||||
$sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name);
|
||||
$sent = $this->sendMail($to, $from, $subject, $content, $to_name, $from_name);
|
||||
}
|
||||
|
||||
return $sent;
|
||||
@@ -207,6 +209,7 @@ class Service implements \Box\InjectionAwareInterface
|
||||
{
|
||||
$email = $this->_queue($to, $from, $subject, $content, $to_name, $from_name, $client_id, $admin_id);
|
||||
$this->_sendFromQueue($email);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -214,26 +217,26 @@ class Service implements \Box\InjectionAwareInterface
|
||||
{
|
||||
$code = $data['code'];
|
||||
|
||||
$enabled = 0;
|
||||
$subject = $this->di['array_get']($data, 'default_subject', ucwords(str_replace('_', ' ', $code)));
|
||||
$content = $this->di['array_get']($data, 'default_template', $this->_getVarsString());
|
||||
$enabled = 0;
|
||||
$subject = $this->di['array_get']($data, 'default_subject', ucwords(str_replace('_', ' ', $code)));
|
||||
$content = $this->di['array_get']($data, 'default_template', $this->_getVarsString());
|
||||
$description = $this->di['array_get']($data, 'default_description', null);
|
||||
|
||||
$matches = array();
|
||||
preg_match("/mod_([a-zA-Z0-9]+)_([a-zA-Z0-9]+)/i", $code, $matches);
|
||||
$mod = $matches[1];
|
||||
$path = BB_PATH_MODS . '/' . ucfirst($mod) . '/html_email/' . $code . '.phtml';
|
||||
$matches = [];
|
||||
preg_match('/mod_([a-zA-Z0-9]+)_([a-zA-Z0-9]+)/i', $code, $matches);
|
||||
$mod = $matches[1];
|
||||
$path = BB_PATH_MODS.'/'.ucfirst($mod).'/html_email/'.$code.'.phtml';
|
||||
|
||||
if (file_exists($path)) {
|
||||
$tpl = file_get_contents($path);
|
||||
|
||||
$ms = array();
|
||||
$ms = [];
|
||||
preg_match('#{%.?block subject.?%}((.*?)+){%.?endblock.?%}#', $tpl, $ms);
|
||||
if (isset($ms[1])) {
|
||||
$subject = $ms[1];
|
||||
}
|
||||
|
||||
$mc = array();
|
||||
$mc = [];
|
||||
preg_match('/{%.?block content.?%}((.*?\n)+){%.?endblock.?%}/m', $tpl, $mc);
|
||||
if (isset($mc[1])) {
|
||||
$content = $mc[1];
|
||||
@@ -241,27 +244,27 @@ class Service implements \Box\InjectionAwareInterface
|
||||
}
|
||||
}
|
||||
|
||||
return array($subject, $content, $description, $enabled, $mod);
|
||||
return [$subject, $content, $description, $enabled, $mod];
|
||||
}
|
||||
|
||||
private function _queue($to, $from, $subject, $content, $to_name = null, $from_name = null, $client_id = null, $admin_id = null)
|
||||
{
|
||||
$db = $this->di['db'];
|
||||
$db = $this->di['db'];
|
||||
|
||||
$queue = $db->dispense('ModEmailQueue');
|
||||
$queue->recipient = $to;
|
||||
$queue->sender = $from;
|
||||
$queue->subject = $subject;
|
||||
$queue->content = $content;
|
||||
$queue->to_name = $to_name;
|
||||
$queue->from_name = $from_name;
|
||||
$queue->client_id = $client_id;
|
||||
$queue->admin_id = $admin_id;
|
||||
$queue->status = 'unsent';
|
||||
$queue = $db->dispense('ModEmailQueue');
|
||||
$queue->recipient = $to;
|
||||
$queue->sender = $from;
|
||||
$queue->subject = $subject;
|
||||
$queue->content = $content;
|
||||
$queue->to_name = $to_name;
|
||||
$queue->from_name = $from_name;
|
||||
$queue->client_id = $client_id;
|
||||
$queue->admin_id = $admin_id;
|
||||
$queue->status = 'unsent';
|
||||
$queue->created_at = date('Y-m-d H:i:s');
|
||||
$queue->updated_at = date('Y-m-d H:i:s');
|
||||
$queue->priority = 1;
|
||||
$queue->tries = 0;
|
||||
$queue->priority = 1;
|
||||
$queue->tries = 0;
|
||||
try {
|
||||
$db->store($queue);
|
||||
} catch (\Exception $e) {
|
||||
@@ -273,15 +276,16 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
private function _getVarsString()
|
||||
{
|
||||
$str = '{% apply markdown %}' . PHP_EOL . PHP_EOL;
|
||||
$str .= 'This email template was automatically generated by BoxBilling extension. ' . PHP_EOL;
|
||||
$str .= 'Template is ready to be modified. ' . PHP_EOL;
|
||||
$str .= 'Email template is just like BoxBilling theme file. ' . PHP_EOL;
|
||||
$str .= 'Use **admin** and **guest** API calls to get additional information using variables passed to template.' . PHP_EOL . PHP_EOL;
|
||||
$str .= 'Example API usage in email template:' . PHP_EOL . PHP_EOL;
|
||||
$str .= '{{ guest.system_version }}' . PHP_EOL . PHP_EOL;
|
||||
$str .= "{{ now|date('Y-m-d') }}" . PHP_EOL . PHP_EOL;
|
||||
$str = '{% apply markdown %}'.PHP_EOL.PHP_EOL;
|
||||
$str .= 'This email template was automatically generated by BoxBilling extension. '.PHP_EOL;
|
||||
$str .= 'Template is ready to be modified. '.PHP_EOL;
|
||||
$str .= 'Email template is just like BoxBilling theme file. '.PHP_EOL;
|
||||
$str .= 'Use **admin** and **guest** API calls to get additional information using variables passed to template.'.PHP_EOL.PHP_EOL;
|
||||
$str .= 'Example API usage in email template:'.PHP_EOL.PHP_EOL;
|
||||
$str .= '{{ guest.system_version }}'.PHP_EOL.PHP_EOL;
|
||||
$str .= "{{ now|date('Y-m-d') }}".PHP_EOL.PHP_EOL;
|
||||
$str .= '{% endapply %}';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
@@ -290,9 +294,9 @@ class Service implements \Box\InjectionAwareInterface
|
||||
$systemService = $this->di['mod_service']('System');
|
||||
$pc = $systemService->renderString($t->content, false, $vars);
|
||||
$ps = $systemService->renderString($t->subject, false, $vars);
|
||||
return array($ps, $pc);
|
||||
}
|
||||
|
||||
return [$ps, $pc];
|
||||
}
|
||||
|
||||
public function resend(\Model_ActivityClientEmail $email)
|
||||
{
|
||||
@@ -304,27 +308,27 @@ class Service implements \Box\InjectionAwareInterface
|
||||
$mail->setSubject($email->subject);
|
||||
$mail->addTo($email->recipients);
|
||||
|
||||
$settings = $this->di['mod_config']('email');
|
||||
$transport = $this->di['array_get']($settings, 'mailer', 'sendmail');
|
||||
$settings = $this->di['mod_config']('email');
|
||||
$transport = $this->di['array_get']($settings, 'mailer', 'sendmail');
|
||||
|
||||
if (APPLICATION_ENV == 'testing') {
|
||||
if (BB_DEBUG) error_log('Skipping email sending in test environment');
|
||||
if (BB_DEBUG) {
|
||||
error_log('Skipping email sending in test environment');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$mod = $this->di['mod']('email');
|
||||
$mod = $this->di['mod']('email');
|
||||
$settings = $mod->getConfig();
|
||||
|
||||
if (isset($settings['log_enabled']) && $settings['log_enabled']) {
|
||||
$activityService = $this->di['mod_service']('activity');
|
||||
$activityService = $this->di['mod_service']('activity');
|
||||
$activityService->logEmail($email->subject, $email->client_id, $email->sender, $email->recipients, $email->content_html, $email->content_text);
|
||||
}
|
||||
|
||||
$mail->send($transport, $settings);
|
||||
|
||||
|
||||
$mail->send($transport, $settings);
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
@@ -336,52 +340,52 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
public function templateGetSearchQuery($data)
|
||||
{
|
||||
$query = "SELECT * FROM email_template";
|
||||
$query = 'SELECT * FROM email_template';
|
||||
|
||||
$code = $this->di['array_get']($data, 'code', NULL);
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$code = $this->di['array_get']($data, 'code', null);
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
|
||||
$where = array();
|
||||
$bindings = array();
|
||||
$where = [];
|
||||
$bindings = [];
|
||||
|
||||
if ($code) {
|
||||
$where[] = "action_code LIKE :code";
|
||||
$where[] = 'action_code LIKE :code';
|
||||
|
||||
$bindings[':code'] = "%$code%";
|
||||
}
|
||||
|
||||
if ($search) {
|
||||
$search = "%$search%";
|
||||
$search = "%$search%";
|
||||
|
||||
$where[] = "(action_code LIKE :action_code OR subject LIKE :subject OR content LIKE :content)";
|
||||
$where[] = '(action_code LIKE :action_code OR subject LIKE :subject OR content LIKE :content)';
|
||||
|
||||
$bindings[':action_code'] = $search;
|
||||
$bindings[':subject'] = $search;
|
||||
$bindings[':content'] = $search;
|
||||
$bindings[':subject'] = $search;
|
||||
$bindings[':content'] = $search;
|
||||
}
|
||||
|
||||
if (!empty($where)) {
|
||||
$query = $query . ' WHERE ' . implode(' AND ', $where);
|
||||
$query = $query.' WHERE '.implode(' AND ', $where);
|
||||
}
|
||||
|
||||
$query .= " ORDER BY category ASC";
|
||||
$query .= ' ORDER BY category ASC';
|
||||
|
||||
return array($query, $bindings);
|
||||
return [$query, $bindings];
|
||||
}
|
||||
|
||||
public function templateToApiArray(\Model_EmailTemplate $model, $deep = false)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $model->id,
|
||||
$data = [
|
||||
'id' => $model->id,
|
||||
'action_code' => $model->action_code,
|
||||
'category' => $model->category,
|
||||
'enabled' => $model->enabled,
|
||||
'subject' => $model->subject,
|
||||
'category' => $model->category,
|
||||
'enabled' => $model->enabled,
|
||||
'subject' => $model->subject,
|
||||
'description' => $model->description,
|
||||
);
|
||||
];
|
||||
if ($deep) {
|
||||
$data['content'] = $model->content;
|
||||
$data['vars'] = $this->getVars($model);
|
||||
$data['vars'] = $this->getVars($model);
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -425,24 +429,23 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
public function resetTemplateByCode($code)
|
||||
{
|
||||
$t = $this->di['db']->findOne('EmailTemplate', 'action_code = :action', array(':action' => $code));
|
||||
$t = $this->di['db']->findOne('EmailTemplate', 'action_code = :action', [':action' => $code]);
|
||||
|
||||
if (!$t instanceof \Model_EmailTemplate) {
|
||||
throw new \Box_Exception('Email template :code was not found', array(':code' => $code));
|
||||
throw new \Box_Exception('Email template :code was not found', [':code' => $code]);
|
||||
}
|
||||
|
||||
$d = array('code' => $code);
|
||||
list($s, $c) = $this->_getDefaults($d);
|
||||
$d = ['code' => $code];
|
||||
[$s, $c] = $this->_getDefaults($d);
|
||||
$this->updateTemplate($t, null, null, $s, $c);
|
||||
$this->di['logger']->info('Reset email template: %s', $t->action_code);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function getEmailById($id)
|
||||
{
|
||||
$model = $this->di['db']->findOne('ActivityClientEmail', 'id = ?', array($id));
|
||||
$model = $this->di['db']->findOne('ActivityClientEmail', 'id = ?', [$id]);
|
||||
if (!$model instanceof \Model_ActivityClientEmail) {
|
||||
throw new \Box_Exception('Email not found');
|
||||
}
|
||||
@@ -452,12 +455,12 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
public function templateCreate($actionCode, $subject, $content, $enabled = 0, $category = null)
|
||||
{
|
||||
$model = $this->di['db']->dispense('EmailTemplate');
|
||||
$model = $this->di['db']->dispense('EmailTemplate');
|
||||
$model->action_code = $actionCode;
|
||||
$model->subject = $subject;
|
||||
$model->enabled = $enabled;
|
||||
$model->category = $category;
|
||||
$model->content = $content;
|
||||
$model->subject = $subject;
|
||||
$model->enabled = $enabled;
|
||||
$model->category = $category;
|
||||
$model->content = $content;
|
||||
|
||||
$modelId = $this->di['db']->store($model);
|
||||
|
||||
@@ -468,29 +471,28 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
public function templateBatchGenerate()
|
||||
{
|
||||
$pattern = BB_PATH_MODS . '/*/html_email/*.phtml';
|
||||
$list = glob($pattern);
|
||||
$pattern = BB_PATH_MODS.'/*/html_email/*.phtml';
|
||||
$list = glob($pattern);
|
||||
foreach ($list as $path) {
|
||||
$code = pathinfo($path, PATHINFO_FILENAME);
|
||||
$dir = pathinfo($path, PATHINFO_DIRNAME);
|
||||
$dir = pathinfo($dir, PATHINFO_DIRNAME);
|
||||
$dir = pathinfo($dir, PATHINFO_FILENAME);
|
||||
$dir = pathinfo($path, PATHINFO_DIRNAME);
|
||||
$dir = pathinfo($dir, PATHINFO_DIRNAME);
|
||||
$dir = pathinfo($dir, PATHINFO_FILENAME);
|
||||
$mod = strtolower($dir);
|
||||
|
||||
//skip if disableda
|
||||
// skip if disableda
|
||||
$extensionService = $this->di['mod_service']('extension');
|
||||
|
||||
|
||||
if (!$extensionService->isExtensionActive('mod', $mod)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip if already exists
|
||||
if ($this->di['db']->findOne('EmailTemplate', 'action_code = :code', array(':code' => $code))) {
|
||||
if ($this->di['db']->findOne('EmailTemplate', 'action_code = :code', [':code' => $code])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($subject, $content, $desc, $enabled, $mod) = $this->_getDefaults(array('code' => $code));
|
||||
[$subject, $content, $desc, $enabled, $mod] = $this->_getDefaults(['code' => $code]);
|
||||
$t = $this->templateCreate($code, $subject, $content, $enabled, $mod);
|
||||
if ($desc) {
|
||||
$t->description = $desc;
|
||||
@@ -505,7 +507,7 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
public function templateBatchDisable()
|
||||
{
|
||||
$sql = "UPDATE email_template SET enabled = 0 WHERE 1";
|
||||
$sql = 'UPDATE email_template SET enabled = 0 WHERE 1';
|
||||
$this->di['db']->exec($sql);
|
||||
$this->di['logger']->info('Disabled all email templates');
|
||||
|
||||
@@ -514,24 +516,29 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
public function templateBatchEnable()
|
||||
{
|
||||
$sql = "UPDATE email_template SET enabled = 1 WHERE 1";
|
||||
$sql = 'UPDATE email_template SET enabled = 1 WHERE 1';
|
||||
$this->di['db']->exec($sql);
|
||||
$this->di['logger']->info('Enabled all email templates');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function batchSend(){
|
||||
$mod = $this->di['mod']('email');
|
||||
$settings = $mod->getConfig();
|
||||
$tries = 0;
|
||||
public function batchSend()
|
||||
{
|
||||
$mod = $this->di['mod']('email');
|
||||
$settings = $mod->getConfig();
|
||||
$tries = 0;
|
||||
$time_limit = ($this->di['array_get']($settings, 'time_limit', 5)) * 60;
|
||||
$start = time();
|
||||
$start = time();
|
||||
while ($email = $this->di['db']->findOne('ModEmailQueue', ' status = \'unsent\' ORDER BY updated_at ')) {
|
||||
$this->_sendFromQueue($email);
|
||||
$tries++;
|
||||
if (isset($settings['queue_once']) && $settings['queue_once'] && $settings['queue_once'] <= $tries) break;
|
||||
if ($time_limit && time() - $start > $time_limit) break;
|
||||
++$tries;
|
||||
if (isset($settings['queue_once']) && $settings['queue_once'] && $settings['queue_once'] <= $tries) {
|
||||
break;
|
||||
}
|
||||
if ($time_limit && time() - $start > $time_limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,11 +549,11 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
$queue->content .= PHP_EOL;
|
||||
|
||||
$mod = $this->di['mod']('email');
|
||||
$mod = $this->di['mod']('email');
|
||||
$settings = $mod->getConfig();
|
||||
|
||||
if (isset($settings['log_enabled']) && $settings['log_enabled']) {
|
||||
$activityService = $this->di['mod_service']('activity');
|
||||
$activityService = $this->di['mod_service']('activity');
|
||||
$activityService->logEmail($queue->subject, $queue->client_id, $queue->sender, $queue->recipient, $queue->content);
|
||||
}
|
||||
|
||||
@@ -561,6 +568,7 @@ class Service implements \Box\InjectionAwareInterface
|
||||
|
||||
if (APPLICATION_ENV != 'production') {
|
||||
error_log('Skip email sending. Application ENV: '.APPLICATION_ENV);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -572,16 +580,18 @@ class Service implements \Box\InjectionAwareInterface
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
if ($queue->priority) $queue->priority--;
|
||||
if ($queue->priority) {
|
||||
--$queue->priority;
|
||||
}
|
||||
$queue->status = 'unsent';
|
||||
$queue->tries++;
|
||||
++$queue->tries;
|
||||
$queue->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($queue);
|
||||
if ($settings['cancel_after'] && $queue->tries > $settings['cancel_after']) $this->di['db']->trash($queue);
|
||||
if ($settings['cancel_after'] && $queue->tries > $settings['cancel_after']) {
|
||||
$this->di['db']->trash($queue);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -34,27 +34,28 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'subpages'=> array(
|
||||
array(
|
||||
'location' => 'extensions',
|
||||
'label' => 'Embed and integrate',
|
||||
'index' => 1500,
|
||||
'uri' => $this->di['url']->adminLink('embed'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
return [
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'extensions',
|
||||
'label' => 'Embed and integrate',
|
||||
'index' => 1500,
|
||||
'uri' => $this->di['url']->adminLink('embed'),
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/embed', 'get_index', array(), get_class($this));
|
||||
$app->get('/embed', 'get_index', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_embed_index');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -35,18 +35,19 @@ class Client implements \Box\InjectionAwareInterface
|
||||
/**
|
||||
* Methods maps client areas urls to corresponding methods
|
||||
* Always use your module prefix to avoid conflicts with other modules
|
||||
* in future
|
||||
* in future.
|
||||
*
|
||||
* @param \Box_App $app - returned by reference
|
||||
*/
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/embed/:what', 'get_object', array('what' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/embed/:what', 'get_object', ['what' => '[a-z0-9-]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_object(\Box_App $app, $what)
|
||||
{
|
||||
$tpl = 'mod_embed_'.$what;
|
||||
|
||||
return $app->render($tpl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,8 +11,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example module Admin API
|
||||
*
|
||||
* Example module Admin API.
|
||||
*
|
||||
* API can be access only by admins
|
||||
*/
|
||||
|
||||
@@ -21,22 +21,22 @@ namespace Box\Mod\Example\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Return list of example objects
|
||||
*
|
||||
* Return list of example objects.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_something($data)
|
||||
{
|
||||
$result = array(
|
||||
$result = [
|
||||
'apple',
|
||||
'google',
|
||||
'facebook',
|
||||
);
|
||||
];
|
||||
|
||||
if(isset($data['microsoft'])) {
|
||||
if (isset($data['microsoft'])) {
|
||||
$result[] = 'microsoft';
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/**
|
||||
* All public methods in this class are exposed to the client using API.
|
||||
* Always think about the information you are exposing.
|
||||
* Always think about the information you are exposing.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Example\Api;
|
||||
@@ -20,18 +20,18 @@ namespace Box\Mod\Example\Api;
|
||||
class Client extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* From client API you can call any other module API
|
||||
*
|
||||
* From client API you can call any other module API.
|
||||
*
|
||||
* This method will collect data from all APIs and merge
|
||||
* into one result.
|
||||
*
|
||||
*
|
||||
* Be careful not to expose sensitive data from the Admin API.
|
||||
*/
|
||||
public function get_info($data)
|
||||
{
|
||||
// call custom event hook. All active modules will be notified
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterClientCalledExampleModule', 'params'=>array('key'=>'value')));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientCalledExampleModule', 'params' => ['key' => 'value']]);
|
||||
|
||||
// Log message
|
||||
$this->di['logger']->info('Log message to log file');
|
||||
|
||||
@@ -40,11 +40,11 @@ class Client extends \Api_Abstract
|
||||
|
||||
$type = $this->di['array_get']($data, 'type', 'info');
|
||||
|
||||
return array(
|
||||
'data' => $data,
|
||||
'version' => $systemService->getVersion(),
|
||||
'profile' => $clientService->toApiArray($this->di['loggedin_client']),
|
||||
'messages' => $systemService->getMessages($type)
|
||||
);
|
||||
return [
|
||||
'data' => $data,
|
||||
'version' => $systemService->getVersion(),
|
||||
'profile' => $clientService->toApiArray($this->di['loggedin_client']),
|
||||
'messages' => $systemService->getMessages($type),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -12,21 +12,21 @@
|
||||
|
||||
/**
|
||||
* All public methods in this class are exposed to public. Always think
|
||||
* what kind of information you are exposing. Emails, passwords and other
|
||||
* information should NOT be returned by functions in this class
|
||||
*
|
||||
* what kind of information you are exposing. Emails, passwords and other
|
||||
* information should NOT be returned by functions in this class.
|
||||
*
|
||||
* This module can be called from API or in template
|
||||
*
|
||||
*/
|
||||
|
||||
// Change "Example" with your module's name
|
||||
|
||||
namespace Box\Mod\Example\Api;
|
||||
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Return extension README.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function readme($data)
|
||||
@@ -36,17 +36,18 @@ class Guest extends \Api_Abstract
|
||||
// Our example admin and client area pages will use this function to fetch the README data
|
||||
// Then, we'll tell Twig to parse and display the markdown output
|
||||
|
||||
$readme = $this->di['tools']->file_get_contents(BB_PATH_MODS . '/Example/README.md');
|
||||
$readme = $this->di['tools']->file_get_contents(BB_PATH_MODS.'/Example/README.md');
|
||||
|
||||
return $readme;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a random number between 1 and 100
|
||||
*
|
||||
* Return a random number between 1 and 100.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function random_number()
|
||||
{
|
||||
return random_int(1, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/**
|
||||
* This file connects BoxBilling admin area interface and API
|
||||
* Class does not extend any other class
|
||||
* Class does not extend any other class.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Example\Controller;
|
||||
@@ -40,53 +40,52 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
/**
|
||||
* This method registers menu items in admin area navigation block
|
||||
* This navigation is cached in bb-data/cache/{hash}. To see changes please
|
||||
* remove the file
|
||||
*
|
||||
* remove the file.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'group' => array(
|
||||
'index' => 1500, // menu sort order
|
||||
'location' => 'example', // menu group identificator for subitems
|
||||
'label' => 'Example module', // menu group title
|
||||
'class' => 'example', // used for css styling menu item
|
||||
),
|
||||
'subpages'=> array(
|
||||
array(
|
||||
'location' => 'example', // place this module in extensions group
|
||||
'label' => 'Example module submenu',
|
||||
'index' => 1500,
|
||||
'uri' => $this->di['url']->adminLink('example'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
return [
|
||||
'group' => [
|
||||
'index' => 1500, // menu sort order
|
||||
'location' => 'example', // menu group identificator for subitems
|
||||
'label' => 'Example module', // menu group title
|
||||
'class' => 'example', // used for css styling menu item
|
||||
],
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'example', // place this module in extensions group
|
||||
'label' => 'Example module submenu',
|
||||
'index' => 1500,
|
||||
'uri' => $this->di['url']->adminLink('example'),
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods maps admin areas urls to corresponding methods
|
||||
* Always use your module prefix to avoid conflicts with other modules
|
||||
* in future
|
||||
*
|
||||
* in future.
|
||||
*
|
||||
* @example $app->get('/example/test', 'get_test', null, get_class($this)); // calls get_test method on this class
|
||||
* @example $app->get('/example/:id', 'get_index', array('id'=>'[0-9]+'), get_class($this));
|
||||
* @param \Box_App $app
|
||||
*/
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/example', 'get_index', array(), get_class($this));
|
||||
$app->get('/example/test', 'get_test', array(), get_class($this));
|
||||
$app->get('/example/user/:id', 'get_user', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/example/api', 'get_api', array(), get_class($this));
|
||||
$app->get('/example', 'get_index', [], get_class($this));
|
||||
$app->get('/example/test', 'get_test', [], get_class($this));
|
||||
$app->get('/example/user/:id', 'get_user', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/example/api', 'get_api', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
// always call this method to validate if admin is logged in
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_example_index');
|
||||
}
|
||||
|
||||
@@ -95,7 +94,7 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
// always call this method to validate if admin is logged in
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
$params = array();
|
||||
$params = [];
|
||||
$params['youparamname'] = 'yourparamvalue';
|
||||
|
||||
return $app->render('mod_example_index', $params);
|
||||
@@ -106,21 +105,22 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
// always call this method to validate if admin is logged in
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
$params = array();
|
||||
$params = [];
|
||||
$params['userid'] = $id;
|
||||
|
||||
return $app->render('mod_example_index', $params);
|
||||
}
|
||||
|
||||
|
||||
public function get_api(\Box_App $app, $id = null)
|
||||
{
|
||||
// always call this method to validate if admin is logged in
|
||||
$api = $this->di['api_admin'];
|
||||
$list_from_controller = $api->example_get_something();
|
||||
|
||||
$params = array();
|
||||
$params = [];
|
||||
$params['api_example'] = true;
|
||||
$params['list_from_controller'] = $list_from_controller;
|
||||
|
||||
return $app->render('mod_example_index', $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/**
|
||||
* This file connects BoxBilling client area interface and API
|
||||
* Class does not extend any other class
|
||||
* Class does not extend any other class.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Example\Controller;
|
||||
@@ -40,14 +40,14 @@ class Client implements \Box\InjectionAwareInterface
|
||||
/**
|
||||
* Methods maps client areas urls to corresponding methods
|
||||
* Always use your module prefix to avoid conflicts with other modules
|
||||
* in future
|
||||
* in future.
|
||||
*
|
||||
* @param \Box_App $app - returned by reference
|
||||
*/
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/example', 'get_index', array(), get_class($this));
|
||||
$app->get('/example/protected', 'get_protected', array(), get_class($this));
|
||||
$app->get('/example', 'get_index', [], get_class($this));
|
||||
$app->get('/example/protected', 'get_protected', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
@@ -59,6 +59,7 @@ class Client implements \Box\InjectionAwareInterface
|
||||
{
|
||||
// call $this->di['is_client_logged'] method to validate if client is logged in
|
||||
$this->di['is_client_logged'];
|
||||
return $app->render('mod_example_index', array('show_protected'=>true));
|
||||
|
||||
return $app->render('mod_example_index', ['show_protected' => true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,11 +11,10 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is a delegate for module. Class does not extend any other class
|
||||
* This file is a delegate for module. Class does not extend any other class.
|
||||
*
|
||||
* All methods provided in this example are optional, but function names are
|
||||
* still reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Example;
|
||||
@@ -40,15 +39,16 @@ class Service
|
||||
* database table might be enough.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
// execute sql script if needed
|
||||
$db = $this->di['db'];
|
||||
$db->exec("SELECT NOW()");
|
||||
$db->exec('SELECT NOW()');
|
||||
|
||||
//throw new \Box_Exception("Throw exception to terminate module installation process with a message", array(), 123);
|
||||
// throw new \Box_Exception("Throw exception to terminate module installation process with a message", array(), 123);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,11 +56,12 @@ class Service
|
||||
* Method to uninstall module.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
//throw new \Box_Exception("Throw exception to terminate module uninstallation process with a message", array(), 124);
|
||||
// throw new \Box_Exception("Throw exception to terminate module uninstallation process with a message", array(), 124);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -70,46 +71,50 @@ class Service
|
||||
* after new files are placed.
|
||||
*
|
||||
* @param array $manifest - information about new module version
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function update($manifest)
|
||||
{
|
||||
//throw new \Box_Exception("Throw exception to terminate module update process with a message", array(), 125);
|
||||
// throw new \Box_Exception("Throw exception to terminate module update process with a message", array(), 125);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method is used to create search query for paginated list.
|
||||
* Usually there is one paginated list per module
|
||||
* Usually there is one paginated list per module.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array() = list of 2 parameters: array($sql, $params)
|
||||
*/
|
||||
public function getSearchQuery($data)
|
||||
{
|
||||
$params = array();
|
||||
$sql="SELECT meta_key, meta_value
|
||||
$params = [];
|
||||
$sql = "SELECT meta_key, meta_value
|
||||
FROM extension_meta
|
||||
WHERE extension = 'example' ";
|
||||
|
||||
$client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
|
||||
if(NULL !== $client_id) {
|
||||
if (null !== $client_id) {
|
||||
$sql .= ' AND client_id = :client_id';
|
||||
$params[':client_id'] = $client_id;
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY created_at DESC';
|
||||
return array($sql, $params);
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods is a delegate for one database row.
|
||||
*
|
||||
* @param array $row - array representing one database row
|
||||
* @param array $row - array representing one database row
|
||||
* @param string $role - guest|client|admin who is calling this method
|
||||
* @param bool $deep - true|false deep or light version of result to return to API
|
||||
* @param bool $deep - true|false deep or light version of result to return to API
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -119,7 +124,7 @@ class Service
|
||||
}
|
||||
|
||||
/**
|
||||
* Example event hook. Any module can hook to any BoxBilling event and perform actions
|
||||
* Example event hook. Any module can hook to any BoxBilling event and perform actions.
|
||||
*
|
||||
* Make sure extension is enabled before testing this event.
|
||||
*
|
||||
@@ -130,44 +135,43 @@ class Service
|
||||
* In this example we are going to count how many times client failed
|
||||
* to enter correct login details
|
||||
*
|
||||
* @param \Box_Event $event
|
||||
* @return void
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public static function onEventClientLoginFailed(\Box_Event $event)
|
||||
{
|
||||
//getting Dependency Injector
|
||||
// getting Dependency Injector
|
||||
$di = $event->getDi();
|
||||
|
||||
//@note almost in all cases you will need Admin API
|
||||
// @note almost in all cases you will need Admin API
|
||||
$api = $di['api_admin'];
|
||||
|
||||
//sometimes you may need guest API
|
||||
//$api_guest = $di['api_guest'];
|
||||
// sometimes you may need guest API
|
||||
// $api_guest = $di['api_guest'];
|
||||
|
||||
$params = $event->getParameters();
|
||||
|
||||
//@note To debug parameters by throwing an exception
|
||||
//throw new Exception(print_r($params, 1));
|
||||
// @note To debug parameters by throwing an exception
|
||||
// throw new Exception(print_r($params, 1));
|
||||
|
||||
// Use RedBean ORM in any place of BoxBilling where API call is not enough
|
||||
// First we need to find if we already have a counter for this IP
|
||||
// We will use extension_meta table to store this data.
|
||||
$values = array(
|
||||
'ext' => 'example',
|
||||
'rel_type' => 'ip',
|
||||
'rel_id' => $params['ip'],
|
||||
'meta_key' => 'counter',
|
||||
);
|
||||
$values = [
|
||||
'ext' => 'example',
|
||||
'rel_type' => 'ip',
|
||||
'rel_id' => $params['ip'],
|
||||
'meta_key' => 'counter',
|
||||
];
|
||||
$meta = $di['db']->findOne('extension_meta', 'extension = :ext AND rel_type = :rel_type AND rel_id = :rel_id AND meta_key = :meta_key', $values);
|
||||
if(!$meta) {
|
||||
if (!$meta) {
|
||||
$meta = $di['db']->dispense('extension_meta');
|
||||
//$count->client_id = null; // client id is not known in this situation
|
||||
$meta->extension = 'mod_example';
|
||||
$meta->rel_type = 'ip';
|
||||
$meta->rel_id = $params['ip'];
|
||||
$meta->meta_key = 'counter';
|
||||
// $count->client_id = null; // client id is not known in this situation
|
||||
$meta->extension = 'mod_example';
|
||||
$meta->rel_type = 'ip';
|
||||
$meta->rel_id = $params['ip'];
|
||||
$meta->meta_key = 'counter';
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
}
|
||||
$meta->meta_value = $meta->meta_value + 1;
|
||||
@@ -177,30 +181,29 @@ class Service
|
||||
// Now we can perform task depending on how many times wrong details were entered
|
||||
|
||||
// We can log event if it repeats for 2 time
|
||||
if($meta->meta_value > 2) {
|
||||
$api->activity_log(array('m' => 'Client failed to enter correct login details ' . $meta->meta_value . ' time(s)'));
|
||||
if ($meta->meta_value > 2) {
|
||||
$api->activity_log(['m' => 'Client failed to enter correct login details '.$meta->meta_value.' time(s)']);
|
||||
}
|
||||
|
||||
// if client gets funky, we block him
|
||||
if($meta->meta_value > 30) {
|
||||
if ($meta->meta_value > 30) {
|
||||
throw new \Box_Exception('You have failed to login too many times. Contact support.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event hook is registered in example module client API call
|
||||
* @param \Box_Event $event
|
||||
* This event hook is registered in example module client API call.
|
||||
*/
|
||||
public static function onAfterClientCalledExampleModule(\Box_Event $event)
|
||||
{
|
||||
//error_log('Called event from example module');
|
||||
// error_log('Called event from example module');
|
||||
|
||||
$di = $event->getDi();
|
||||
$params = $event->getParameters();
|
||||
|
||||
$meta = $di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_example';
|
||||
$meta->meta_key = 'event_params';
|
||||
$meta = $di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_example';
|
||||
$meta->meta_key = 'event_params';
|
||||
$meta->meta_value = json_encode($params);
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
@@ -208,12 +211,11 @@ class Service
|
||||
}
|
||||
|
||||
/**
|
||||
* Example event hook for public ticket and set event return value
|
||||
* @param \Box_Event $event
|
||||
* Example event hook for public ticket and set event return value.
|
||||
*/
|
||||
public static function onBeforeGuestPublicTicketOpen(\Box_Event $event)
|
||||
{
|
||||
/* Uncomment lines below in order to see this function in action */
|
||||
/* Uncomment lines below in order to see this function in action */
|
||||
|
||||
/*
|
||||
$data = $event->getParameters();
|
||||
@@ -225,8 +227,7 @@ class Service
|
||||
}
|
||||
|
||||
/**
|
||||
* Example email sending
|
||||
* @param \Box_Event $event
|
||||
* Example email sending.
|
||||
*/
|
||||
public static function onAfterClientOrderCreate(\Box_Event $event)
|
||||
{
|
||||
@@ -248,4 +249,4 @@ class Service
|
||||
$api->email_template_send($email);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,39 +10,40 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Extension\Api;
|
||||
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of active and inactive extensions on system
|
||||
*
|
||||
* Get list of active and inactive extensions on system.
|
||||
*
|
||||
* @optional bool $installed - return installed only extensions
|
||||
* @optional bool $active - return installed and core extensions
|
||||
* @optional bool $has_settings - return extensions with configuration pages only
|
||||
* @optional string $search - filter extensions by search keyword
|
||||
* @optional string $type - filter extensions by type
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->getExtensionsList($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of extensions from extensions.boxbilling.org
|
||||
* which can be installed on current version of BoxBilling
|
||||
*
|
||||
* which can be installed on current version of BoxBilling.
|
||||
*
|
||||
* @param string $type - mod, gateway ...
|
||||
* @return array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_latest($data)
|
||||
{
|
||||
//@todo enable when extensions are available
|
||||
return array();
|
||||
// @todo enable when extensions are available
|
||||
return [];
|
||||
/*
|
||||
$type = $this->di['array_get']($data, 'type', null);
|
||||
try {
|
||||
@@ -55,238 +56,249 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get admin area navigation
|
||||
*
|
||||
* @return array
|
||||
* Get admin area navigation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_navigation($data)
|
||||
{
|
||||
$url = null;
|
||||
if(isset($data['url'])) {
|
||||
if (isset($data['url'])) {
|
||||
$url = $data['url'];
|
||||
}
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->getAdminNavigation($this->identity, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of available languages on the system
|
||||
*
|
||||
* @return array
|
||||
* Get list of available languages on the system.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function languages()
|
||||
{
|
||||
$systemService = $this->di['mod_service']('system');
|
||||
|
||||
return $systemService->getLanguages(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update BoxBilling core
|
||||
*
|
||||
*
|
||||
* Update BoxBilling core.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
*
|
||||
* @throws Box_Exception
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update_core($data)
|
||||
{
|
||||
|
||||
$updater = $this->di['updater'];
|
||||
if(!$updater->getCanUpdate()) {
|
||||
if (!$updater->getCanUpdate()) {
|
||||
throw new \Box_Exception('You have latest version of BoxBilling. You do not need to update.', null, 930);
|
||||
}
|
||||
|
||||
|
||||
$new_version = $updater->getLatestVersion();
|
||||
$updater->performUpdate();
|
||||
|
||||
|
||||
$this->di['logger']->info('Updated BoxBilling from %s to %s', \Box_Version::VERSION, $new_version);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update existing extension
|
||||
*
|
||||
* Update existing extension.
|
||||
*
|
||||
* @param string $type - extensions type: mod, theme, gateway ...
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*
|
||||
* @throws Box_Exception
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
|
||||
$ext = $this->_getExtension($data);
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->update($ext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate existing extension
|
||||
*
|
||||
* Activate existing extension.
|
||||
*
|
||||
* @param string $type - extensions type: mod, theme, gateway ...
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*
|
||||
* @throws Box_Exception
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function activate($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'Extension ID was not passed',
|
||||
$required = [
|
||||
'id' => 'Extension ID was not passed',
|
||||
'type' => 'Extension type was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$service = $this->getService();
|
||||
$result = $service->activateExistingExtension($data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate existing extension
|
||||
*
|
||||
* Deactivate existing extension.
|
||||
*
|
||||
* @param string $type - extensions type: mod, theme, gateway ...
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @return bool - true
|
||||
*
|
||||
*
|
||||
* @throws Box_Exception
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deactivate($data)
|
||||
{
|
||||
$ext = $this->_getExtension($data);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminDeactivateExtension', 'params'=>array('id'=>$ext->id)));
|
||||
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminDeactivateExtension', 'params' => ['id' => $ext->id]]);
|
||||
|
||||
$service = $this->getService();
|
||||
$service->deactivate($ext);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminDeactivateExtension', 'params'=>array('id'=>$data['id'], 'type'=>$data['type'])));
|
||||
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminDeactivateExtension', 'params' => ['id' => $data['id'], 'type' => $data['type']]]);
|
||||
|
||||
$this->di['logger']->info('Deactivated extension "%s"', $data['type'].' '.$data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Completely remove extension from BoxBilling
|
||||
*
|
||||
* Completely remove extension from BoxBilling.
|
||||
*
|
||||
* @param string $type - extensions type: mod, theme, gateway ...
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @return boolean
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uninstall($data)
|
||||
{
|
||||
$ext = $this->_getExtension($data);
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminUninstallExtension', 'params'=>array('id'=>$ext->id)));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminUninstallExtension', 'params' => ['id' => $ext->id]]);
|
||||
|
||||
$service = $this->getService();
|
||||
$service->uninstall($ext);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminUninstallExtension', 'params'=>array('id'=>$ext->id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminUninstallExtension', 'params' => ['id' => $ext->id]]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Install new extension from extensions site
|
||||
*
|
||||
* Install new extension from extensions site.
|
||||
*
|
||||
* @param string $type - extensions type: mod, theme, gateway ...
|
||||
* @param string $id - extension id
|
||||
* @param string $id - extension id
|
||||
*
|
||||
* @return array
|
||||
* @throws Box_Exception
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function install($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'Extension ID was not passed',
|
||||
$required = [
|
||||
'id' => 'Extension ID was not passed',
|
||||
'type' => 'Extension type was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminInstallExtension', 'params'=>$data));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminInstallExtension', 'params' => $data]);
|
||||
|
||||
$service = $this->getService();
|
||||
$service->downloadAndExtract($data['type'], $data['id']);
|
||||
|
||||
|
||||
try {
|
||||
$this->activate($data);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminInstallExtension', 'params'=>$data));
|
||||
return array(
|
||||
'success' => true,
|
||||
'id' => $data['id'],
|
||||
'type' => $data['type'],
|
||||
);
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminInstallExtension', 'params' => $data]);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'id' => $data['id'],
|
||||
'type' => $data['type'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Universal method for BoxBilling extensions
|
||||
* Universal method for BoxBilling extensions
|
||||
* to retrieve configuration from database
|
||||
* It is recommended to store your extension configuration
|
||||
* using this method. Automatic decryption is available
|
||||
* All parameters in "public" array will be accessible by guest API
|
||||
*
|
||||
* All parameters in "public" array will be accessible by guest API.
|
||||
*
|
||||
* @param string $ext - extension name, ie: mod_news
|
||||
*
|
||||
* @return array - configuration parameters
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function config_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ext' => 'Parameter ext was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$service = $this->getService();
|
||||
$config = $service->getConfig($data['ext']);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Universal method for BoxBilling extensions
|
||||
* Universal method for BoxBilling extensions
|
||||
* to update or save extension configuration to database
|
||||
* Always pass all configuration parameters to this method.
|
||||
*
|
||||
*
|
||||
* Config is automatically encrypted and stored in database
|
||||
*
|
||||
*
|
||||
* @param string $ext - extension name, ie: mod_news
|
||||
* @optional string $any - Any variable passed to this method is config parameter
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* @throws Box_Exception
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function config_save($data)
|
||||
{
|
||||
$required = array(
|
||||
'ext' => 'Parameter ext was not passed',
|
||||
);
|
||||
$required = [
|
||||
'ext' => 'Parameter ext was not passed',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
return $this->getService()->setConfig($data);
|
||||
}
|
||||
|
||||
|
||||
private function _getExtension($data)
|
||||
{
|
||||
$required = array(
|
||||
'id' => 'Extension ID was not passed',
|
||||
$required = [
|
||||
'id' => 'Extension ID was not passed',
|
||||
'type' => 'Extension type was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$service = $this->getService();
|
||||
$ext = $service->findExtension($data['type'], $data['id']);
|
||||
if(!$ext instanceof \Model_Extension) {
|
||||
if (!$ext instanceof \Model_Extension) {
|
||||
throw new \Box_Exception('Extension not found');
|
||||
}
|
||||
|
||||
|
||||
return $ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,67 +10,75 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Extension\Api;
|
||||
|
||||
/**
|
||||
* Extensions
|
||||
* Extensions.
|
||||
*/
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Checks if extensions is available
|
||||
*
|
||||
* Checks if extensions is available.
|
||||
*
|
||||
* @param string $mod - module name to be checked
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_on($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
if(isset($data['mod']) && !empty($data['mod'])) {
|
||||
if (isset($data['mod']) && !empty($data['mod'])) {
|
||||
return $service->isExtensionActive('mod', $data['mod']);
|
||||
}
|
||||
|
||||
if(isset($data['id']) && !empty($data['type'])) {
|
||||
|
||||
if (isset($data['id']) && !empty($data['type'])) {
|
||||
return $service->isExtensionActive($data['type'], $data['id']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return active theme info
|
||||
* Return active theme info.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function theme($client = true)
|
||||
{
|
||||
$systemService = $this->di['mod_service']('theme');
|
||||
|
||||
return $systemService->getThemeConfig($client, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve extension public settings
|
||||
* Retrieve extension public settings.
|
||||
*
|
||||
* @param string $ext - extension name
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function settings($data)
|
||||
{
|
||||
if(!isset($data['ext'])) {
|
||||
if (!isset($data['ext'])) {
|
||||
throw new \Box_Exception('Parameter ext is missing');
|
||||
}
|
||||
$service = $this->getService();
|
||||
$config = $service->getConfig($data['ext']);
|
||||
return (isset($config['public']) && is_array($config['public'])) ? $config['public'] : array();
|
||||
|
||||
return (isset($config['public']) && is_array($config['public'])) ? $config['public'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve list of available languages
|
||||
* Retrieve list of available languages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function languages()
|
||||
{
|
||||
$service = $this->di['mod_service']('system');
|
||||
|
||||
return $service->getLanguages();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Extension\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,56 +34,59 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'group' => array(
|
||||
'location' => 'extensions',
|
||||
'index' => 1000,
|
||||
return [
|
||||
'group' => [
|
||||
'location' => 'extensions',
|
||||
'index' => 1000,
|
||||
'label' => 'Extensions',
|
||||
'class' => 'iPlugin',
|
||||
'sprite_class' => 'dark-sprite-icon sprite-electroPlug',
|
||||
),
|
||||
'subpages' => array(
|
||||
array(
|
||||
'location' => 'extensions',
|
||||
],
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'extensions',
|
||||
'label' => 'Overview',
|
||||
'uri' => $this->di['url']->adminLink('extension'),
|
||||
'index' => 100,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'location' => 'extensions',
|
||||
'index' => 100,
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'extensions',
|
||||
'label' => 'Languages',
|
||||
'index' => 200,
|
||||
'index' => 200,
|
||||
'uri' => $this->di['url']->adminLink('extension/languages'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/extension', 'get_index', array(), get_class($this));
|
||||
$app->get('/extension/settings/:mod', 'get_settings', array('mod' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/extension/languages', 'get_langs', array(), get_class($this));
|
||||
$app->get('/extension', 'get_index', [], get_class($this));
|
||||
$app->get('/extension/settings/:mod', 'get_settings', ['mod' => '[a-z0-9-]+'], get_class($this));
|
||||
$app->get('/extension/languages', 'get_langs', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_extension_index');
|
||||
}
|
||||
|
||||
public function get_langs(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_extension_languages');
|
||||
}
|
||||
|
||||
|
||||
public function get_settings(\Box_App $app, $mod)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
$file = 'mod_'.$mod.'_settings';
|
||||
|
||||
return $app->render($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Extension;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -32,12 +31,13 @@ class Service implements InjectionAwareInterface
|
||||
public function isCoreModule($mod)
|
||||
{
|
||||
$core = $this->di['mod']('extension')->getCoreModules();
|
||||
|
||||
return in_array($mod, $core);
|
||||
}
|
||||
|
||||
public function isExtensionActive($type, $id)
|
||||
{
|
||||
if($type == 'mod' && $this->isCoreModule($id)) {
|
||||
if ('mod' == $type && $this->isCoreModule($id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -49,17 +49,18 @@ class Service implements InjectionAwareInterface
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
$id_or_null = $this->di['db']->getCell($query, array('type'=>$type, 'id'=>$id));
|
||||
return (bool)$id_or_null;
|
||||
$id_or_null = $this->di['db']->getCell($query, ['type' => $type, 'id' => $id]);
|
||||
|
||||
return (bool) $id_or_null;
|
||||
}
|
||||
|
||||
public static function onBeforeAdminCronRun(\Box_Event $event)
|
||||
{
|
||||
$di = $event->getDi();
|
||||
$di = $event->getDi();
|
||||
$extensionService = $di['mod_service']('extension');
|
||||
|
||||
try {
|
||||
$extensionService->getExtensionsList(array());
|
||||
$extensionService->getExtensionsList([]);
|
||||
} catch (\Exception $e) {
|
||||
error_log($e);
|
||||
}
|
||||
@@ -71,76 +72,78 @@ class Service implements InjectionAwareInterface
|
||||
{
|
||||
$list = $this->di['db']->find('Extension', "type = 'mod'");
|
||||
$removedItems = 0;
|
||||
foreach($list as $ext) {
|
||||
foreach ($list as $ext) {
|
||||
try {
|
||||
$mod = $this->di['mod']($ext->name);
|
||||
$mod->getManifest();
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->di['db']->trash($ext);
|
||||
$removedItems++;
|
||||
++$removedItems;
|
||||
}
|
||||
}
|
||||
return $removedItems == 0 ? true : $removedItems;
|
||||
|
||||
return 0 == $removedItems ? true : $removedItems;
|
||||
}
|
||||
|
||||
public function getSearchQuery($filter)
|
||||
{
|
||||
$search = $this->di['array_get']($filter, 'search', NULL);
|
||||
$type = $this->di['array_get']($filter, 'type', NULL);
|
||||
$search = $this->di['array_get']($filter, 'search', null);
|
||||
$type = $this->di['array_get']($filter, 'type', null);
|
||||
|
||||
$params = array();
|
||||
$sql="SELECT * FROM extension
|
||||
$params = [];
|
||||
$sql = "SELECT * FROM extension
|
||||
WHERE status = 'installed' ";
|
||||
|
||||
if(NULL !== $type) {
|
||||
if (null !== $type) {
|
||||
$sql .= ' AND type = :type';
|
||||
$params[':type'] = $type;
|
||||
}
|
||||
|
||||
if(NULL !== $search) {
|
||||
if (null !== $search) {
|
||||
$sql .= ' AND name LIKE :search';
|
||||
$params[':search'] = '%'.$search.'%';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY type ASC, status DESC, id ASC';
|
||||
return array($sql, $params);
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function getExtensionsList($filter)
|
||||
{
|
||||
$this->removeNotExistingModules();
|
||||
|
||||
list($sql, $params) = $this->getSearchQuery($filter);
|
||||
[$sql, $params] = $this->getSearchQuery($filter);
|
||||
$installed = $this->di['db']->getAll($sql, $params);
|
||||
|
||||
$has_settings = $this->di['array_get']($filter, 'has_settings');
|
||||
$only_installed = $this->di['array_get']($filter, 'installed');
|
||||
$has_settings = $this->di['array_get']($filter, 'has_settings');
|
||||
$only_installed = $this->di['array_get']($filter, 'installed');
|
||||
$installed_and_core = $this->di['array_get']($filter, 'active');
|
||||
$search = isset($filter['search']) ? strtolower($filter['search']) : NULL;
|
||||
$result = array();
|
||||
$search = isset($filter['search']) ? strtolower($filter['search']) : null;
|
||||
$result = [];
|
||||
|
||||
if ($installed_and_core) {
|
||||
$core = $this->di['mod']('extension')->getCoreModules();
|
||||
foreach ($core as $core_mod) {
|
||||
$m = $this->di['mod']($core_mod);
|
||||
$manifest = $m->getManifest();
|
||||
$manifest['status'] = 'core';
|
||||
$m = $this->di['mod']($core_mod);
|
||||
$manifest = $m->getManifest();
|
||||
$manifest['status'] = 'core';
|
||||
$manifest['has_settings'] = $m->hasSettingsPage();
|
||||
$result[] = $manifest;
|
||||
$result[] = $manifest;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($installed as $im) {
|
||||
$manifest = json_decode($im['manifest'], 1);
|
||||
if (!is_array($manifest)) {
|
||||
error_log('Error decoding module json file. ' . $im['name']);
|
||||
error_log('Error decoding module json file. '.$im['name']);
|
||||
continue;
|
||||
}
|
||||
$m = $this->di['mod']($im['name']);
|
||||
$m = $this->di['mod']($im['name']);
|
||||
$manifest['version'] = $im['version'];
|
||||
|
||||
$manifest['status'] = $im['status'];
|
||||
if ($im['type'] == 'mod' && $im['status'] == 'installed' && $m->hasSettingsPage()) {
|
||||
if ('mod' == $im['type'] && 'installed' == $im['status'] && $m->hasSettingsPage()) {
|
||||
$manifest['has_settings'] = true;
|
||||
} else {
|
||||
$manifest['has_settings'] = false;
|
||||
@@ -150,10 +153,10 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
if (!$only_installed && !$installed_and_core) {
|
||||
//add inactive modules
|
||||
// add inactive modules
|
||||
$a = $this->_getAvailable();
|
||||
|
||||
//unset installed modules
|
||||
// unset installed modules
|
||||
foreach ($installed as $ins) {
|
||||
if (in_array($ins['name'], $a)) {
|
||||
$key = array_search($ins['name'], $a);
|
||||
@@ -162,9 +165,9 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
foreach ($a as $mod) {
|
||||
$m = $this->di['mod']($mod);
|
||||
$manifest = $m->getManifest();
|
||||
$manifest['status'] = null;
|
||||
$m = $this->di['mod']($mod);
|
||||
$manifest = $m->getManifest();
|
||||
$manifest['status'] = null;
|
||||
$manifest['has_settings'] = false;
|
||||
|
||||
$result[] = $manifest;
|
||||
@@ -182,18 +185,17 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
if (!empty($search)) {
|
||||
foreach ($result as $idx => $mod) {
|
||||
if (strpos(strtolower($mod['name']), $search) === false) {
|
||||
if (false === strpos(strtolower($mod['name']), $search)) {
|
||||
unset($result[$idx]);
|
||||
}
|
||||
|
||||
}
|
||||
$result = array_values($result);
|
||||
}
|
||||
|
||||
foreach ($result as $key => $value){
|
||||
foreach ($result as $key => $value) {
|
||||
$iconPath = 'images/icons/middlenav/cog.png';
|
||||
$icon_url = $this->di['array_get']($value, 'icon_url');
|
||||
if ($icon_url){
|
||||
if ($icon_url) {
|
||||
$iconPath = $this->di['config']['url'].$icon_url;
|
||||
}
|
||||
$result[$key]['icon_url'] = $iconPath;
|
||||
@@ -204,17 +206,17 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
private function _getAvailable()
|
||||
{
|
||||
$mods = array();
|
||||
$mods = [];
|
||||
$handle = opendir(BB_PATH_MODS);
|
||||
while($name = readdir($handle)) {
|
||||
if(ctype_alnum($name)) {
|
||||
while ($name = readdir($handle)) {
|
||||
if (ctype_alnum($name)) {
|
||||
$m = $name;
|
||||
$mod = $this->di['mod']($m);
|
||||
if($mod->isCore()) {
|
||||
if ($mod->isCore()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$mod->hasManifest()) {
|
||||
if (!$mod->hasManifest()) {
|
||||
error_log('Module '.$m.' manifest file is missing or is not readable.');
|
||||
continue;
|
||||
}
|
||||
@@ -223,6 +225,7 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
return $mods;
|
||||
}
|
||||
|
||||
@@ -231,37 +234,36 @@ class Service implements InjectionAwareInterface
|
||||
$staff_service = $this->di['mod_service']('staff');
|
||||
$current_mod = null;
|
||||
$current_url = null;
|
||||
$nav = array();
|
||||
$subpages = array();
|
||||
$nav = [];
|
||||
$subpages = [];
|
||||
|
||||
$modules = $this->di['mod']('extension')->getCoreModules();
|
||||
$installed = $this->getInstalledMods();
|
||||
$list = array_merge($modules, $installed);
|
||||
foreach ($list as $mod) {
|
||||
if(!$staff_service->hasPermission($admin, $mod)) {
|
||||
if (!$staff_service->hasPermission($admin, $mod)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$m = $this->di['mod']($mod);
|
||||
$obj = $m->getAdminController();
|
||||
} catch(\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
if(method_exists($obj, 'fetchNavigation')) {
|
||||
if (method_exists($obj, 'fetchNavigation')) {
|
||||
$n = $obj->fetchNavigation();
|
||||
|
||||
if(isset($n['group'])) {
|
||||
if (isset($n['group'])) {
|
||||
$l = $n['group']['location'];
|
||||
unset($n['group']['location']);
|
||||
$n['group']['active'] = false;
|
||||
$nav[$l] = $n['group'];
|
||||
}
|
||||
|
||||
if(isset($n['subpages'])) {
|
||||
foreach($n['subpages'] as $nn) {
|
||||
if(is_array($nn)) {
|
||||
if (isset($n['subpages'])) {
|
||||
foreach ($n['subpages'] as $nn) {
|
||||
if (is_array($nn)) {
|
||||
$nn['active'] = false;
|
||||
array_push($subpages, $nn);
|
||||
}
|
||||
@@ -272,12 +274,12 @@ class Service implements InjectionAwareInterface
|
||||
// groups sorting
|
||||
$nav = $this->di['tools']->sortByOneKey($nav, 'index');
|
||||
foreach ($subpages as $page) {
|
||||
if(!isset($page['location'])) {
|
||||
if (!isset($page['location'])) {
|
||||
error_log('Invalid module menu item: '.print_r($page, 1));
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!isset($nav[$page['location']])) {
|
||||
if (!isset($nav[$page['location']])) {
|
||||
error_log('Submenu item belongs to not existing location: '.$page['location']);
|
||||
continue;
|
||||
}
|
||||
@@ -288,7 +290,7 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
// submenu sorting
|
||||
foreach($nav as &$group){
|
||||
foreach ($nav as &$group) {
|
||||
$group['subpages'] = $this->di['tools']->sortByOneKey($group['subpages'], 'index');
|
||||
}
|
||||
|
||||
@@ -300,37 +302,36 @@ class Service implements InjectionAwareInterface
|
||||
*/
|
||||
public function findExtension($type, $id)
|
||||
{
|
||||
$extension = $this->di['db']->findOne('Extension', 'type = ? and name = ? ', array($type, $id));
|
||||
$extension = $this->di['db']->findOne('Extension', 'type = ? and name = ? ', [$type, $id]);
|
||||
|
||||
return $extension;
|
||||
}
|
||||
|
||||
public function update(\Model_Extension $model)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
if($model->type == 'mod') {
|
||||
$result = [];
|
||||
|
||||
if ('mod' == $model->type) {
|
||||
$ext = $this->di['extension'];
|
||||
$latest = $ext->getLatestExtensionVersion($model->name);
|
||||
if(empty($latest)) {
|
||||
throw new \Box_Exception('Could not retrieve version information for extension :ext', array(':ext'=>$model->name), 745);
|
||||
if (empty($latest)) {
|
||||
throw new \Box_Exception('Could not retrieve version information for extension :ext', [':ext' => $model->name], 745);
|
||||
}
|
||||
$haveUpdate = (version_compare($model->version, $latest) < 0);
|
||||
if(!$haveUpdate) {
|
||||
throw new \Box_Exception('Latest :mod version installed. No need to update', array(':mod'=>$model->name), 785);
|
||||
if (!$haveUpdate) {
|
||||
throw new \Box_Exception('Latest :mod version installed. No need to update', [':mod' => $model->name], 785);
|
||||
}
|
||||
|
||||
$extension = $ext->getExtension($model->name);
|
||||
if(empty($extension)) {
|
||||
throw new \Box_Exception('Could not retrieve :ext information', array(':ext'=>$model->name), 744);
|
||||
if (empty($extension)) {
|
||||
throw new \Box_Exception('Could not retrieve :ext information', [':ext' => $model->name], 744);
|
||||
}
|
||||
|
||||
throw new \Box_Exception('Visit extension site for update information.', null, 252);
|
||||
|
||||
$result = array(
|
||||
$result = [
|
||||
'version_old' => $model->version,
|
||||
'version_new' => $latest,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -338,12 +339,12 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function activate(\Model_Extension $ext)
|
||||
{
|
||||
$result = array(
|
||||
'id' => $ext->name,
|
||||
'type' => $ext->type,
|
||||
'redirect' => false,
|
||||
'has_settings' => false,
|
||||
);
|
||||
$result = [
|
||||
'id' => $ext->name,
|
||||
'type' => $ext->type,
|
||||
'redirect' => false,
|
||||
'has_settings' => false,
|
||||
];
|
||||
|
||||
switch ($ext->type) {
|
||||
case \Box_Extension::TYPE_MOD:
|
||||
@@ -371,23 +372,23 @@ class Service implements InjectionAwareInterface
|
||||
switch ($ext->type) {
|
||||
case \Box_Extension::TYPE_HOOK:
|
||||
$file = ucfirst($ext->name).'.php';
|
||||
$destination = BB_PATH_LIBRARY . '/Hook/'.$file;
|
||||
if(file_exists($destination)) {
|
||||
$destination = BB_PATH_LIBRARY.'/Hook/'.$file;
|
||||
if (file_exists($destination)) {
|
||||
unlink($destination);
|
||||
}
|
||||
break;
|
||||
|
||||
case \Box_Extension::TYPE_MOD:
|
||||
$mod = $ext->name;
|
||||
if($this->isCoreModule($mod)) {
|
||||
throw new \Box_Exception("BoxBilling core modules can not be managed");
|
||||
if ($this->isCoreModule($mod)) {
|
||||
throw new \Box_Exception('BoxBilling core modules can not be managed');
|
||||
}
|
||||
|
||||
try {
|
||||
$mm = $this->di['mod']($mod);
|
||||
$mm->uninstall();
|
||||
} catch (\Box_Exception $e) {
|
||||
if($e->getCode() != 408) {
|
||||
if (408 != $e->getCode()) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -399,6 +400,7 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
$this->di['db']->trash($ext);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -408,7 +410,6 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
switch ($ext->type) {
|
||||
case \Box_Extension::TYPE_MOD:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -416,6 +417,7 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
$this->di['db']->trash($ext);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -424,7 +426,7 @@ class Service implements InjectionAwareInterface
|
||||
$ext = $this->di['extension'];
|
||||
$manifest = $ext->getExtension($id, $type);
|
||||
|
||||
if(!isset($manifest['download_url'])) {
|
||||
if (!isset($manifest['download_url'])) {
|
||||
throw new \Exception('Extensions download url is not valid');
|
||||
}
|
||||
|
||||
@@ -436,41 +438,41 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$em = $this->di['zip_archive'];
|
||||
$res = $em->open($zip);
|
||||
if ($res === TRUE) {
|
||||
if (true === $res) {
|
||||
$em->extractTo($extracted);
|
||||
$em->close();
|
||||
} else {
|
||||
throw new \Box_Exception('Could not extract extension zip file');
|
||||
}
|
||||
|
||||
//install by type
|
||||
// install by type
|
||||
switch ($type) {
|
||||
case \Box_Extension::TYPE_MOD:
|
||||
$destination = BB_PATH_MODS . '/mod_'.$id;
|
||||
if($this->di['tools']->fileExists($destination)) {
|
||||
$destination = BB_PATH_MODS.'/mod_'.$id;
|
||||
if ($this->di['tools']->fileExists($destination)) {
|
||||
throw new \Box_Exception('Module already installed.', null, 436);
|
||||
}
|
||||
if(!$this->di['tools']->rename($extracted, $destination)) {
|
||||
if (!$this->di['tools']->rename($extracted, $destination)) {
|
||||
throw new \Box_Exception('Extension can not be moved. Make sure your server write permissions to bb-modules folder.', null, 437);
|
||||
}
|
||||
break;
|
||||
|
||||
case \Box_Extension::TYPE_THEME:
|
||||
$destination = BB_PATH_THEMES . '/'.$id;
|
||||
if(!$this->di['tools']->fileExists($destination)) {
|
||||
if(!$this->di['tools']->rename($extracted, $destination)) {
|
||||
$destination = BB_PATH_THEMES.'/'.$id;
|
||||
if (!$this->di['tools']->fileExists($destination)) {
|
||||
if (!$this->di['tools']->rename($extracted, $destination)) {
|
||||
throw new \Box_Exception('Extension can not be moved. Make sure your server write permissions to bb-themes folder.', null, 439);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case \Box_Extension::TYPE_TRANSLATION:
|
||||
$destination = BB_PATH_LANGS . '/'.$id.'/LC_MESSAGES';
|
||||
$destination = BB_PATH_LANGS.'/'.$id.'/LC_MESSAGES';
|
||||
$this->di['tools']->emptyFolder($destination);
|
||||
if(!$this->di['tools']->fileExists($destination)) {
|
||||
if (!$this->di['tools']->fileExists($destination)) {
|
||||
$this->di['tools']->mkdir($destination, 0777, true);
|
||||
}
|
||||
if(!$this->di['tools']->rename($extracted, $destination)) {
|
||||
if (!$this->di['tools']->rename($extracted, $destination)) {
|
||||
throw new \Box_Exception('Extension can not be moved. Make sure your server write permissions to bb-locale folder.', null, 440);
|
||||
}
|
||||
break;
|
||||
@@ -479,7 +481,7 @@ class Service implements InjectionAwareInterface
|
||||
throw new \Box_Exception('Extension does not support auto-install feature. Extension must be installed manually');
|
||||
}
|
||||
|
||||
if (file_exists($zip)){
|
||||
if (file_exists($zip)) {
|
||||
unlink($zip);
|
||||
}
|
||||
$this->di['tools']->emptyFolder($extracted);
|
||||
@@ -487,7 +489,6 @@ class Service implements InjectionAwareInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function getInstalledMods()
|
||||
{
|
||||
$query = "SELECT name
|
||||
@@ -498,21 +499,21 @@ class Service implements InjectionAwareInterface
|
||||
$pdo = $this->di['pdo'];
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
private function installModule(\Model_Extension $ext)
|
||||
{
|
||||
$mod = $this->di['mod']($ext->name);
|
||||
|
||||
if($mod->isCore()) {
|
||||
throw new \Box_Exception("BoxBilling core modules can not be installed or removed");
|
||||
if ($mod->isCore()) {
|
||||
throw new \Box_Exception('BoxBilling core modules can not be installed or removed');
|
||||
}
|
||||
|
||||
$info = $mod->getManifest();
|
||||
if(isset($info['minimum_boxbilling_version']) && Box_Version::compareVersion($info['minimum_boxbilling_version']) > 0) {
|
||||
throw new \Box_Exception('Module can not be installed. It requires at least :min version of BoxBilling. You are using :v', array(':min'=>$info['minimum_boxbilling_version'], ':v'=>Box_Version::VERSION));
|
||||
if (isset($info['minimum_boxbilling_version']) && Box_Version::compareVersion($info['minimum_boxbilling_version']) > 0) {
|
||||
throw new \Box_Exception('Module can not be installed. It requires at least :min version of BoxBilling. You are using :v', [':min' => $info['minimum_boxbilling_version'], ':v' => Box_Version::VERSION]);
|
||||
}
|
||||
|
||||
// Allow install module even if no installer exists
|
||||
@@ -521,37 +522,38 @@ class Service implements InjectionAwareInterface
|
||||
try {
|
||||
$mod->install();
|
||||
} catch (\Box_Exception $e) {
|
||||
if($e->getCode() != 408) {
|
||||
if (408 != $e->getCode()) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$ext->version = $info['version'];
|
||||
$ext->version = $info['version'];
|
||||
$this->di['db']->store($ext);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function activateExistingExtension($data)
|
||||
{
|
||||
$ext = $this->findExtension($data['type'], $data['id']);
|
||||
if(!$ext instanceof \Model_Extension) {
|
||||
if (!$ext instanceof \Model_Extension) {
|
||||
$ext = $this->di['db']->dispense('Extension');
|
||||
$ext->name = $data['id'];
|
||||
$ext->type = $data['type'];
|
||||
$ext->version = null;
|
||||
$ext->status = 'deactivated';
|
||||
$ext->manifest = null;
|
||||
$ext->name = $data['id'];
|
||||
$ext->type = $data['type'];
|
||||
$ext->version = null;
|
||||
$ext->status = 'deactivated';
|
||||
$ext->manifest = null;
|
||||
$ext_id = $this->di['db']->store($ext);
|
||||
}
|
||||
$ext_id = isset($ext_id) ? $ext_id : $ext->id;
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminActivateExtension', 'params'=>array('id'=>$ext_id)));
|
||||
$ext_id = $ext_id ?? $ext->id;
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminActivateExtension', 'params' => ['id' => $ext_id]]);
|
||||
try {
|
||||
$result = $this->activate($ext);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->di['db']->trash($ext);
|
||||
throw $e;
|
||||
}
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminActivateExtension', 'params'=>array('id'=>$ext_id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminActivateExtension', 'params' => ['id' => $ext_id]]);
|
||||
$this->di['logger']->info('Activated extension "%s"', $data['id']);
|
||||
|
||||
return $result;
|
||||
@@ -559,8 +561,8 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function getConfig($ext)
|
||||
{
|
||||
$c = $this->di['db']->findOne('ExtensionMeta', 'extension = :ext AND meta_key = :key', array(':ext'=>$ext, ':key'=>'config'));
|
||||
if(is_null($c)) {
|
||||
$c = $this->di['db']->findOne('ExtensionMeta', 'extension = :ext AND meta_key = :key', [':ext' => $ext, ':key' => 'config']);
|
||||
if (is_null($c)) {
|
||||
$c = $this->di['db']->dispense('ExtensionMeta');
|
||||
$c->extension = $ext;
|
||||
$c->meta_key = 'config';
|
||||
@@ -568,20 +570,21 @@ class Service implements InjectionAwareInterface
|
||||
$c->created_at = date('Y-m-d H:i:s');
|
||||
$c->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($c);
|
||||
$config = array();
|
||||
$config = [];
|
||||
} else {
|
||||
$config = $this->di['crypt']->decrypt($c->meta_value, $this->_getSalt());
|
||||
$config = $this->di['tools']->decodeJ($config);
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function setConfig($data)
|
||||
{
|
||||
$this->getConfig($data['ext']); //Creates new config if it does not exist in DB
|
||||
$this->getConfig($data['ext']); // Creates new config if it does not exist in DB
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminExtensionConfigSave', 'params'=>$data));
|
||||
$sql="
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminExtensionConfigSave', 'params' => $data]);
|
||||
$sql = "
|
||||
UPDATE extension_meta
|
||||
SET meta_value = :config
|
||||
WHERE extension = :ext
|
||||
@@ -592,12 +595,12 @@ class Service implements InjectionAwareInterface
|
||||
$config = json_encode($data);
|
||||
$config = $this->di['crypt']->encrypt($config, $this->_getSalt());
|
||||
|
||||
$params = array(
|
||||
'ext' => $data['ext'],
|
||||
'config' => $config,
|
||||
);
|
||||
$params = [
|
||||
'ext' => $data['ext'],
|
||||
'config' => $config,
|
||||
];
|
||||
$this->di['db']->exec($sql, $params);
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminExtensionConfigSave', 'params'=>$data));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminExtensionConfigSave', 'params' => $data]);
|
||||
$this->di['logger']->info('Updated extension "%s" configuration', $data['ext']);
|
||||
|
||||
return true;
|
||||
@@ -619,8 +622,8 @@ class Service implements InjectionAwareInterface
|
||||
$stmt->execute();
|
||||
$extensions = $stmt->fetchAll(\PDO::FETCH_KEY_PAIR);
|
||||
|
||||
if(!$extensions) {
|
||||
$list = array();
|
||||
if (!$extensions) {
|
||||
$list = [];
|
||||
} else {
|
||||
$list = array_values($extensions);
|
||||
}
|
||||
@@ -631,7 +634,6 @@ class Service implements InjectionAwareInterface
|
||||
$result = array_merge($mods, $list);
|
||||
sort($result);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Manage custom orders forms
|
||||
* Manage custom orders forms.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Formbuilder\Api;
|
||||
@@ -19,25 +19,25 @@ namespace Box\Mod\Formbuilder\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Create custom order form for product
|
||||
* Create custom order form for product.
|
||||
*
|
||||
* @param string $name - Name of new form
|
||||
*
|
||||
* @optional string $style - Style/Type of the form. Default value is "horizontal". Other possible types are "inline", "search", "actions"
|
||||
*
|
||||
*
|
||||
* @return int - ID of the created form
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function create_form($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'name' => 'Form name was not provided',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if (isset($data["type"]) && (strtolower($data["type"])!= "horizontal" || strtolower($data["type"])!= "default" )){
|
||||
throw new \Box_Exception ("Form style was not found in predefined list", null, 3657);
|
||||
if (isset($data['type']) && ('horizontal' != strtolower($data['type']) || 'default' != strtolower($data['type']))) {
|
||||
throw new \Box_Exception('Form style was not found in predefined list', null, 3657);
|
||||
}
|
||||
|
||||
$service = $this->getService();
|
||||
@@ -47,10 +47,10 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new field to form
|
||||
* Add new field to form.
|
||||
*
|
||||
* @param string $type - Field type
|
||||
* @param int $form_id - ID of the field form
|
||||
* @param string $type - Field type
|
||||
* @param int $form_id - ID of the field form
|
||||
*
|
||||
* @optional
|
||||
* @optional string $label - Label of the field which will be shown. Default value "Type X" where X is number of fields in form. For example "Checkbox 2"
|
||||
@@ -71,6 +71,7 @@ class Admin extends \Api_Abstract
|
||||
* @optional int $text_size - Prefered text size
|
||||
*
|
||||
* @return int - ID of created field
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function add_field($data)
|
||||
@@ -87,42 +88,45 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
$fieldId = $service->addNewField($data);
|
||||
|
||||
return $fieldId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get form data by it's id
|
||||
* Get form data by it's id.
|
||||
*
|
||||
* @param int $id - ID of the form
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
|
||||
public function get_form($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Form id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data, null, 2391);
|
||||
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->getForm($data['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fields data by form's id
|
||||
* Get fields data by form's id.
|
||||
*
|
||||
* @param int $form_id - ID of form
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get_form_fields($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'form_id' => 'Form id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data, null, 1822);
|
||||
|
||||
$service = $this->getService();
|
||||
@@ -131,20 +135,20 @@ class Admin extends \Api_Abstract
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get field data by field id
|
||||
* Get field data by field id.
|
||||
*
|
||||
* @param int $id - ID of the fields
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get_field($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Field id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data, null, 3547);
|
||||
|
||||
$service = $this->getService();
|
||||
@@ -154,70 +158,70 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of forms
|
||||
*
|
||||
*
|
||||
* Get array of forms.
|
||||
*
|
||||
* @return multidimensional array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get_forms()
|
||||
{
|
||||
$service = $this->getService();
|
||||
$forms = $service->getForms();
|
||||
|
||||
return $forms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete form and it's form fields
|
||||
* Delete form and it's form fields.
|
||||
*
|
||||
* @param int $id - ID of the form
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function delete_form($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Form id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data, null, 9958);
|
||||
|
||||
$service = $this->getService();
|
||||
$service->removeForm($data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete field by id
|
||||
* Delete field by id.
|
||||
*
|
||||
* @param int $id - ID of the field
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function delete_field($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Field id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data, null, 9959);
|
||||
|
||||
$service = $this->getService();
|
||||
$service->removeField($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update form
|
||||
* Update form.
|
||||
*
|
||||
* @param array
|
||||
*
|
||||
* @param string $type - Field type
|
||||
* @param int $form_id - ID of the field form
|
||||
* @param string $type - Field type
|
||||
* @param int $form_id - ID of the field form
|
||||
*
|
||||
* @optional
|
||||
* @optional string $label - Label of the field which will be shown. Default value "Type X" where X is number of fields in form. For example "Checkbox 2"
|
||||
@@ -238,13 +242,14 @@ class Admin extends \Api_Abstract
|
||||
* @optional int $text_size - Prefered text size
|
||||
*
|
||||
* @return int - ID of the field
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function update_field($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Field id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data, null, 9958);
|
||||
|
||||
$service = $this->getService();
|
||||
@@ -257,27 +262,26 @@ class Admin extends \Api_Abstract
|
||||
return $fieldId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get form pairs
|
||||
* Get form pairs.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_pairs($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->getFormPairs();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Duplicate form with its fields in database
|
||||
*
|
||||
* @param int $form_id - ID of the origin form
|
||||
* @param string $name - Name of copied form
|
||||
* Duplicate form with its fields in database.
|
||||
*
|
||||
* @param int $form_id - ID of the origin form
|
||||
* @param string $name - Name of copied form
|
||||
*
|
||||
* @return int - ID of the new form
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function copy_form($data)
|
||||
@@ -291,20 +295,21 @@ class Admin extends \Api_Abstract
|
||||
|
||||
$service = $this->getService();
|
||||
$new_form_id = $service->duplicateForm($data);
|
||||
|
||||
return $new_form_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update form name and style
|
||||
* Update form name and style.
|
||||
*
|
||||
* @param int $form_id - ID of the form
|
||||
* @param int $form_id - ID of the form
|
||||
* @param string $form_name - New name of the form
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update_form_settings($data)
|
||||
{
|
||||
if (!isset($data['form_id']) || (trim($data['form_id']) == "")) {
|
||||
if (!isset($data['form_id']) || ('' == trim($data['form_id']))) {
|
||||
throw new \Box_Exception('Form id was not passed', null, 1654);
|
||||
}
|
||||
if (!isset($data['form_name'])) {
|
||||
@@ -315,14 +320,12 @@ class Admin extends \Api_Abstract
|
||||
throw new \Box_Exception('Form type was not passed', null, 3794);
|
||||
}
|
||||
|
||||
if ($data['type'] !='horizontal' && $data['type'] != 'default') {
|
||||
if ('horizontal' != $data['type'] && 'default' != $data['type']) {
|
||||
throw new \Box_Exception('Field type not supported', null, 3207);
|
||||
}
|
||||
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->updateFormSettings($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Custom forms
|
||||
* Custom forms.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Formbuilder\Api;
|
||||
@@ -19,21 +19,23 @@ namespace Box\Mod\Formbuilder\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get custom order form details for product
|
||||
*
|
||||
* Get custom order form details for product.
|
||||
*
|
||||
* @param int $product_id - Product id
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* @throws Box_Exception
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Form id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->getForm($data['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Formbuilder\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,11 +34,11 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/formbuilder/:id', 'get_form', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/formbuilder/:id', 'get_form', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_form(\Box_App $app, $id)
|
||||
{
|
||||
return $app->render('mod_formbuilder_build', array('id'=>$id));
|
||||
return $app->render('mod_formbuilder_build', ['id' => $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,8 +10,8 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Formbuilder;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class Service implements InjectionAwareInterface
|
||||
@@ -37,16 +37,15 @@ class Service implements InjectionAwareInterface
|
||||
return $this->di;
|
||||
}
|
||||
|
||||
|
||||
public function getFormFieldsTypes()
|
||||
{
|
||||
return array(
|
||||
"text" => 'Text input',
|
||||
"select" => 'Dropdown',
|
||||
"radio" => 'Radio select',
|
||||
"checkbox" => 'Checkbox',
|
||||
"textarea" => 'Text area'
|
||||
);
|
||||
return [
|
||||
'text' => 'Text input',
|
||||
'select' => 'Dropdown',
|
||||
'radio' => 'Radio select',
|
||||
'checkbox' => 'Checkbox',
|
||||
'textarea' => 'Text area',
|
||||
];
|
||||
}
|
||||
|
||||
public function typeValidation($type)
|
||||
@@ -57,48 +56,49 @@ class Service implements InjectionAwareInterface
|
||||
public function isArrayUnique($data)
|
||||
{
|
||||
$unique = array_unique($data);
|
||||
return (count($data) === count($unique));
|
||||
|
||||
return count($data) === count($unique);
|
||||
}
|
||||
|
||||
public function addNewForm($data)
|
||||
{
|
||||
$data["style"]["type"] = isset ($data["type"])? $data["type"] : "horizontal";
|
||||
$data["style"]["show_title"] = isset ($data["show_title"])? $data["show_title"] : "0";
|
||||
$data["style"] = json_encode($data["style"],JSON_FORCE_OBJECT);
|
||||
$data['style']['type'] = $data['type'] ?? 'horizontal';
|
||||
$data['style']['show_title'] = $data['show_title'] ?? '0';
|
||||
$data['style'] = json_encode($data['style'], JSON_FORCE_OBJECT);
|
||||
|
||||
$bean = $this->di['db']->dispense('Form');
|
||||
$bean->name = $data['name'];
|
||||
$bean->style = $data['style'];
|
||||
$bean->style = $data['style'];
|
||||
$bean->created_at = date('Y-m-d H:i:s');
|
||||
$bean->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
$form_id = $this->di['db']->store($bean);
|
||||
$this->di['logger']->info('Created new form %s with id %s', $data['name'], $form_id);
|
||||
|
||||
return $form_id;
|
||||
}
|
||||
|
||||
public function addNewField($field) //TODO server-side required check
|
||||
public function addNewField($field) // TODO server-side required check
|
||||
{
|
||||
$field_number = (int)$this->getFormFieldsCount($field['form_id']) + 1;
|
||||
$field_number = (int) $this->getFormFieldsCount($field['form_id']) + 1;
|
||||
|
||||
$formId = $field['form_id'];
|
||||
$types = $this->getFormFieldsTypes();
|
||||
$type = $field["type"];
|
||||
$type = $field['type'];
|
||||
|
||||
$label = $this->di['array_get']($field, 'label', $types[$type] . " " . $field_number);
|
||||
$name = $this->di['array_get']($field, 'name', ($this->slugify("new_" . $type) . "_" . $field_number));
|
||||
$label = $this->di['array_get']($field, 'label', $types[$type].' '.$field_number);
|
||||
$name = $this->di['array_get']($field, 'name', ($this->slugify('new_'.$type).'_'.$field_number));
|
||||
|
||||
if ($type == "select" || $type == "checkbox" || $type == "radio") {
|
||||
if ('select' == $type || 'checkbox' == $type || 'radio' == $type) {
|
||||
$field['options'] = '{"First option":"1", "Second option": "2", "Third option":"3"}';
|
||||
}
|
||||
if ($field['type'] == "textarea" && !isset($field['options'])) {
|
||||
if ('textarea' == $field['type'] && !isset($field['options'])) {
|
||||
$field['options'] = '{"height":"100", "width": "300"}';
|
||||
}
|
||||
if (isset($field['default_value'])) {
|
||||
$field['default_value'] = is_array($field['default_value']) ? json_encode($field['default_value'], JSON_FORCE_OBJECT) : $field['default_value'];
|
||||
}
|
||||
if (isset ($field['options']) && is_array($field['options'])) {
|
||||
if (isset($field['options']) && is_array($field['options'])) {
|
||||
$field['options'] = json_encode($field['options'], JSON_FORCE_OBJECT);
|
||||
}
|
||||
$bean = $this->di['db']->dispense('FormField');
|
||||
@@ -129,10 +129,8 @@ class Service implements InjectionAwareInterface
|
||||
return $fieldId;
|
||||
}
|
||||
|
||||
|
||||
private function slugify($text)
|
||||
{
|
||||
|
||||
// replace non letter or digits by _
|
||||
$text = preg_replace('~[^\\pL\d]+~u', '_', $text);
|
||||
|
||||
@@ -149,49 +147,48 @@ class Service implements InjectionAwareInterface
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
|
||||
if (is_numeric(substr($text, 0, 1))) {
|
||||
throw new \Box_Exception ('Field name can not start with number.', null, 1649);
|
||||
throw new \Box_Exception('Field name can not start with number.', null, 1649);
|
||||
}
|
||||
|
||||
if (empty($text)) {
|
||||
throw new \Box_Exception ('Field name can not be empty. Please make sure it is not empty and does not contain special characters.', null, 3502);
|
||||
throw new \Box_Exception('Field name can not be empty. Please make sure it is not empty and does not contain special characters.', null, 3502);
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
public function updateField($field)
|
||||
{
|
||||
$fieldId = $field['id'];
|
||||
|
||||
$label = isset($field['label']) ? $field['label'] : 'New field';
|
||||
$label = $field['label'] ?? 'New field';
|
||||
$name = $this->slugify($field['name']);
|
||||
|
||||
$get_field = $this->getField($field['id']);
|
||||
$field['form_id'] = $get_field['form_id'];
|
||||
|
||||
if ($this->formFieldNameExists(array("form_id" => $field["form_id"], "field_name" => $field["name"], "field_id" => $fieldId))) {
|
||||
throw new \Box_Exception ('Unfortunately field with this name exists in this form already. Form must have different field names.', null, 7628);
|
||||
if ($this->formFieldNameExists(['form_id' => $field['form_id'], 'field_name' => $field['name'], 'field_id' => $fieldId])) {
|
||||
throw new \Box_Exception('Unfortunately field with this name exists in this form already. Form must have different field names.', null, 7628);
|
||||
}
|
||||
|
||||
$field['options'] = isset($field['options']) ? json_encode($field['options']) : "";
|
||||
$field['options'] = isset($field['options']) ? json_encode($field['options']) : '';
|
||||
if (isset($field['default_value'])) {
|
||||
$field['default_value'] = is_array($field['default_value']) ? json_encode($field['default_value'], JSON_FORCE_OBJECT) : $field['default_value'];
|
||||
}
|
||||
|
||||
if (isset($field['type'])) {
|
||||
if ($field['type'] == "checkbox" || $field['type'] == "radio" || $field['type'] == "select") {
|
||||
if ('checkbox' == $field['type'] || 'radio' == $field['type'] || 'select' == $field['type']) {
|
||||
if (!$this->isArrayUnique(array_filter($field['values'], 'strlen'))) {
|
||||
throw new \Box_Exception(ucfirst($field['type']) . ' values must be unique', null, 1597);
|
||||
throw new \Box_Exception(ucfirst($field['type']).' values must be unique', null, 1597);
|
||||
}
|
||||
if (!$this->isArrayUnique(array_filter($field['labels'], 'strlen'))) {
|
||||
throw new \Box_Exception(ucfirst($field['type']) . ' labels must be unique', null, 1598);
|
||||
throw new \Box_Exception(ucfirst($field['type']).' labels must be unique', null, 1598);
|
||||
}
|
||||
$field['options'] = array_combine($field['labels'], $field['values']);
|
||||
$field['options'] = array_filter($field['options'], 'strlen');
|
||||
$field['options'] = json_encode($field['options'], JSON_FORCE_OBJECT);
|
||||
}
|
||||
if ($field['type'] == "textarea") {
|
||||
if ('textarea' == $field['type']) {
|
||||
if (count($field['textarea_size']) != count(array_filter($field['textarea_size'], 'is_numeric'))) {
|
||||
throw new \Box_Exception('Textarea size options must be integer values', null, 3510);
|
||||
}
|
||||
@@ -222,6 +219,7 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$this->di['db']->store($bean);
|
||||
$this->di['logger']->info('Updated custom form %s', $fieldId);
|
||||
|
||||
return $fieldId;
|
||||
}
|
||||
|
||||
@@ -233,20 +231,21 @@ class Service implements InjectionAwareInterface
|
||||
$result['style'] = json_decode($result['style'], true);
|
||||
$result['fields'] = $this->getFormFields($result['id']);
|
||||
$result['fields'] = $this->fieldsJsonDecode($result['fields']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getFormFields($formId)
|
||||
{
|
||||
$sql = ("
|
||||
$sql = ('
|
||||
SELECT *
|
||||
FROM form_field
|
||||
WHERE form_id = :form_id
|
||||
ORDER BY ID asc
|
||||
");
|
||||
$result = $this->di['db']->getAll($sql, array(':form_id' => $formId));
|
||||
return $result;
|
||||
');
|
||||
$result = $this->di['db']->getAll($sql, [':form_id' => $formId]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function fieldsJsonDecode($fields)
|
||||
@@ -255,124 +254,125 @@ class Service implements InjectionAwareInterface
|
||||
$fields[$key]['options'] = json_decode($r['options'], true);
|
||||
$fields[$key]['default_value'] = (json_decode($r['default_value'])) ? (json_decode($r['default_value'], true)) : $r['default_value'];
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormFieldsCount($form_id)
|
||||
{
|
||||
$sql = ("
|
||||
$sql = ('
|
||||
SELECT COUNT(*)
|
||||
FROM form_field
|
||||
WHERE form_id = :form_id
|
||||
");
|
||||
');
|
||||
|
||||
return $this->di['db']->getCell($sql, array(':form_id' => $form_id));
|
||||
return $this->di['db']->getCell($sql, [':form_id' => $form_id]);
|
||||
}
|
||||
|
||||
|
||||
public function getFormPairs()
|
||||
{
|
||||
$sql = "
|
||||
$sql = '
|
||||
SELECT id, name
|
||||
FROM form
|
||||
";
|
||||
';
|
||||
|
||||
return $this->di['db']->getAssoc($sql);
|
||||
}
|
||||
|
||||
public function getField($fieldId)
|
||||
{
|
||||
$field = $this->di['db']->getExistingModelById('FormField', $fieldId, "Field was not found");
|
||||
$field = $this->di['db']->getExistingModelById('FormField', $fieldId, 'Field was not found');
|
||||
|
||||
$result = $this->di['db']->toArray($field);
|
||||
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Field was not found',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $result, null, 2575);
|
||||
|
||||
if (substr($result["options"], 0, 1) == "{" || substr($result["options"], 0, 1) == "[") {
|
||||
if ('{' == substr($result['options'], 0, 1) || '[' == substr($result['options'], 0, 1)) {
|
||||
$result['options'] = json_decode($result['options']);
|
||||
}
|
||||
return $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function removeForm($form_id)
|
||||
{
|
||||
$sql = "DELETE
|
||||
$sql = 'DELETE
|
||||
FROM form_field
|
||||
WHERE form_id = ?
|
||||
";
|
||||
$this->di['db']->exec($sql, array($form_id));
|
||||
';
|
||||
$this->di['db']->exec($sql, [$form_id]);
|
||||
|
||||
$sql2 = "DELETE
|
||||
$sql2 = 'DELETE
|
||||
FROM form
|
||||
WHERE id = ?";
|
||||
$this->di['db']->exec($sql2, array($form_id));
|
||||
WHERE id = ?';
|
||||
$this->di['db']->exec($sql2, [$form_id]);
|
||||
|
||||
$sql3 = "UPDATE product
|
||||
$sql3 = 'UPDATE product
|
||||
SET form_id = NULL
|
||||
WHERE form_id = ?
|
||||
";
|
||||
$this->di['db']->exec($sql3, array($form_id));
|
||||
';
|
||||
$this->di['db']->exec($sql3, [$form_id]);
|
||||
|
||||
$sql4 = "UPDATE client_order
|
||||
$sql4 = 'UPDATE client_order
|
||||
SET form_id = NULL
|
||||
WHERE form_id = :form_id
|
||||
";
|
||||
$this->di['db']->exec($sql4, array(':form_id' => $form_id));
|
||||
';
|
||||
$this->di['db']->exec($sql4, [':form_id' => $form_id]);
|
||||
|
||||
$this->di['logger']->info('Deleted custom form %s', $form_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function removeField($data)
|
||||
{
|
||||
$fieldModel = $this->di['db']->getExistingModelById('FormField', $data['id'], "Field was not found");
|
||||
$fieldModel = $this->di['db']->getExistingModelById('FormField', $data['id'], 'Field was not found');
|
||||
$this->di['db']->trash($fieldModel);
|
||||
$this->di['logger']->info('Deleted custom field %s', $data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function formFieldNameExists($data)
|
||||
{
|
||||
$form_id = $data['form_id'];
|
||||
$field_name = $data['field_name'];
|
||||
$field_id = $data['field_id'];
|
||||
$sql = ("
|
||||
$sql = ('
|
||||
SELECT COUNT( * )
|
||||
FROM `form_field`
|
||||
WHERE form_id = :form_id
|
||||
AND name = :field_name
|
||||
AND id != :field_id
|
||||
");
|
||||
');
|
||||
|
||||
$result = $this->di['db']->findOne('FormField', 'form_id = ? and name = ? and id != ?', [$form_id, $field_name, $field_id]);
|
||||
|
||||
$result = $this->di['db']->findOne('FormField', 'form_id = ? and name = ? and id != ?', array($form_id, $field_name, $field_id));
|
||||
return ($result) ? true : false;
|
||||
}
|
||||
|
||||
public function getForms()
|
||||
{
|
||||
$sql = ("
|
||||
$sql = ('
|
||||
SELECT f.id, f.name, COUNT( p.id ) as product_count, COUNT( co.id ) as order_count
|
||||
FROM `form` f
|
||||
LEFT JOIN product p ON (f.id = p.form_id)
|
||||
LEFT JOIN client_order co ON (f.id = co.form_id)
|
||||
GROUP BY f.id
|
||||
");
|
||||
');
|
||||
|
||||
return $this->di['db']->getAll($sql);
|
||||
}
|
||||
|
||||
public function duplicateForm($data)
|
||||
{
|
||||
|
||||
$fields = $this->getFormFields($data['form_id']);
|
||||
$new_form_id = $this->addNewForm(array(
|
||||
"name" => $data['name']
|
||||
));
|
||||
$new_form_id = $this->addNewForm([
|
||||
'name' => $data['name'],
|
||||
]);
|
||||
|
||||
if (isset($fields) && is_array($fields)) {
|
||||
foreach ($fields as $field_data) {
|
||||
@@ -381,33 +381,33 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
}
|
||||
$this->di['logger']->info('Copied form with id %s to new form %s with id %s', $data['form_id'], $data['name'], $new_form_id);
|
||||
|
||||
return $new_form_id;
|
||||
}
|
||||
|
||||
public function updateFormSettings($data)
|
||||
{
|
||||
$show_title = isset($data['show_title'])? $data['show_title'] : "1";
|
||||
$show_title = $data['show_title'] ?? '1';
|
||||
$type = $data['type'];
|
||||
|
||||
$sql = "UPDATE `form`
|
||||
$sql = 'UPDATE `form`
|
||||
SET `name` = :form_name
|
||||
WHERE id = :id";
|
||||
$this->di['db']->exec($sql, array(':form_name' => $data['form_name'], ':id' => $data['form_id']));
|
||||
WHERE id = :id';
|
||||
$this->di['db']->exec($sql, [':form_name' => $data['form_name'], ':id' => $data['form_id']]);
|
||||
|
||||
$this->di['logger']->info('Updated form %s name to %s', $data['form_id'], $data['form_name']);
|
||||
|
||||
$style = array(
|
||||
"type" => $type,
|
||||
"show_title" => $show_title
|
||||
);
|
||||
$style = [
|
||||
'type' => $type,
|
||||
'show_title' => $show_title,
|
||||
];
|
||||
|
||||
$sql2 = "UPDATE `form`
|
||||
$sql2 = 'UPDATE `form`
|
||||
SET `style` = :type
|
||||
WHERE id = :id";
|
||||
$this->di['db']->exec($sql2, array(':type' => json_encode($style, JSON_FORCE_OBJECT), ':id' => $data['form_id']));
|
||||
WHERE id = :id';
|
||||
$this->di['db']->exec($sql2, [':type' => json_encode($style, JSON_FORCE_OBJECT), ':id' => $data['form_id']]);
|
||||
$this->di['logger']->info('Updated form %s type to %s', $data['form_id'], $data['type']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+219
-183
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Forum management
|
||||
* Forum management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Forum\Api;
|
||||
@@ -19,64 +19,68 @@ namespace Box\Mod\Forum\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get pairs of forums
|
||||
*
|
||||
* Get pairs of forums.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_pairs($data)
|
||||
{
|
||||
$table = $this->di['table']('Forum');
|
||||
|
||||
return $table->getPairs();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get paginated list of forums
|
||||
*
|
||||
* Get paginated list of forums.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$table = $this->di['table']('Forum');
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list ($sql, $params)= $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach($pager['list'] as $key => $item){
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$forum = $this->di['db']->getExistingModelById('Forum', $item['id'], 'Forum not found');
|
||||
$pager['list'][$key] = $table->toApiArray($forum);
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get forums list grouped by category name
|
||||
*
|
||||
* Get forums list grouped by category name.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_categories($data)
|
||||
{
|
||||
$table = $this->di['table']('Forum');
|
||||
$list = $this->di['db']->find('Forum');
|
||||
|
||||
$result = array();
|
||||
foreach($list as $f) {
|
||||
|
||||
$result = [];
|
||||
foreach ($list as $f) {
|
||||
$result[$f->category][] = $table->toApiArray($f);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get forum details
|
||||
*
|
||||
* Get forum details.
|
||||
*
|
||||
* @param int $id - forum id
|
||||
*
|
||||
* @return array
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Forum id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$table = $this->di['table']('Forum');
|
||||
@@ -84,74 +88,76 @@ class Admin extends \Api_Abstract
|
||||
|
||||
return $table->toApiArray($model, true, $this->getIdentity());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new forum
|
||||
*
|
||||
* Create new forum.
|
||||
*
|
||||
* @param string $title - new forum title
|
||||
*
|
||||
*
|
||||
* @optional string $category - new forum category
|
||||
*
|
||||
*
|
||||
* @return int - new forum id
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'title' => 'Forum title was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$systemService = $this->di['mod_service']('system');
|
||||
$systemService->checkLimits('Model_Forum', 3);
|
||||
|
||||
$priority = $this->di['db']->getCell("SELECT MAX(priority) FROM forum LIMIT 1");
|
||||
$priority = $this->di['db']->getCell('SELECT MAX(priority) FROM forum LIMIT 1');
|
||||
|
||||
$model = $this->di['db']->dispense('Forum');
|
||||
$model->category = $this->di['array_get']($data, 'category', NULL);
|
||||
$model->title = $data['title'];
|
||||
$model->slug = $this->di['tools']->slug($data['title']);
|
||||
$model->status = isset($data['status']) ? $data['status'] : \Model_Forum::STATUS_ACTIVE;
|
||||
$model->description = $this->di['array_get']($data, 'description', NULL);
|
||||
$model->priority = $priority + 1;
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$model = $this->di['db']->dispense('Forum');
|
||||
$model->category = $this->di['array_get']($data, 'category', null);
|
||||
$model->title = $data['title'];
|
||||
$model->slug = $this->di['tools']->slug($data['title']);
|
||||
$model->status = $data['status'] ?? \Model_Forum::STATUS_ACTIVE;
|
||||
$model->description = $this->di['array_get']($data, 'description', null);
|
||||
$model->priority = $priority + 1;
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Created new forum "%s"', $model->title);
|
||||
|
||||
return $model->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update existing forum
|
||||
*
|
||||
* Update existing forum.
|
||||
*
|
||||
* @param int $id - forum id
|
||||
*
|
||||
*
|
||||
* @optional string $category - new forum category
|
||||
* @optional string $title - new forum title
|
||||
* @optional string $status - new forum status
|
||||
* @optional string $slug - new forum slug
|
||||
* @optional string $description - new forum description
|
||||
* @optional string $priority - new forum priority
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Forum id missing',
|
||||
);
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('Forum', $data['id'], 'Forum not found');
|
||||
|
||||
$category = $this->di['array_get']($data, 'category');
|
||||
if($category) {
|
||||
if($this->di['array_get']($data, 'update_categories')) {
|
||||
$this->di['db']->exec('UPDATE forum SET category = :cat WHERE category = :old_cat',
|
||||
array('cat'=>$category, 'old_cat'=>$model->category));
|
||||
if ($category) {
|
||||
if ($this->di['array_get']($data, 'update_categories')) {
|
||||
$this->di['db']->exec('UPDATE forum SET category = :cat WHERE category = :old_cat',
|
||||
['cat' => $category, 'old_cat' => $model->category]);
|
||||
}
|
||||
$model->category = $category;
|
||||
}
|
||||
@@ -166,74 +172,79 @@ class Admin extends \Api_Abstract
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Updated forum "%s"', $model->title);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change forums sorting order
|
||||
*
|
||||
* Change forums sorting order.
|
||||
*
|
||||
* @param array $priority - forum id => priority pairs
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function update_priority($data)
|
||||
{
|
||||
if(!isset($data['priority']) || !is_array($data['priority'])) {
|
||||
if (!isset($data['priority']) || !is_array($data['priority'])) {
|
||||
throw new \Box_Exception('priority params is missing');
|
||||
}
|
||||
|
||||
foreach($data['priority'] as $id => $p) {
|
||||
foreach ($data['priority'] as $id => $p) {
|
||||
$model = $this->di['db']->getExistingModelById('Forum', $id);
|
||||
if($model instanceof \Model_Forum) {
|
||||
if ($model instanceof \Model_Forum) {
|
||||
$model->priority = $p;
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->di['logger']->info('Changed forums priorities');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove forum with all topics
|
||||
*
|
||||
* Remove forum with all topics.
|
||||
*
|
||||
* @param int $id - forum id
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Forum id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$table = $this->di['table']('Forum');
|
||||
$model = $this->di['db']->getExistingModelById('Forum', $data['id'], 'Forum not found');
|
||||
|
||||
|
||||
$id = $model->id;
|
||||
$table->rm($model);
|
||||
|
||||
|
||||
$this->di['logger']->info('Deleted forum #%s', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated list of topics
|
||||
*
|
||||
* Get paginated list of topics.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function topic_get_list($data)
|
||||
{
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$topic = $this->di['db']->getExistingModelById('ForumTopic', $item['id'], 'Forum topic not found');
|
||||
$topic = $this->di['db']->getExistingModelById('ForumTopic', $item['id'], 'Forum topic not found');
|
||||
$pager['list'][$key] = $table->toApiArray($topic);
|
||||
}
|
||||
|
||||
@@ -241,37 +252,41 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get topic details
|
||||
*
|
||||
* Get topic details.
|
||||
*
|
||||
* @param int $id - topic id
|
||||
*
|
||||
* @return array
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function topic_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Topic id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
$model = $this->di['db']->getExistingModelById('ForumTopic', $data['id'], 'Forum Topic not found');
|
||||
|
||||
|
||||
return $table->toApiArray($model, true, $this->getIdentity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove topic
|
||||
*
|
||||
* Remove topic.
|
||||
*
|
||||
* @param int $id - topic id
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function topic_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Topic id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
@@ -280,31 +295,33 @@ class Admin extends \Api_Abstract
|
||||
$id = $model->id;
|
||||
$table->rm($model);
|
||||
$this->di['logger']->info('Deleted forum topic #%s', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new topic
|
||||
*
|
||||
* @param int $forum_id - forum id
|
||||
* @param string $title - topic title
|
||||
* @param string $message - topic message
|
||||
*
|
||||
* Create new topic.
|
||||
*
|
||||
* @param int $forum_id - forum id
|
||||
* @param string $title - topic title
|
||||
* @param string $message - topic message
|
||||
*
|
||||
* @optional string $status - initial topic status
|
||||
*
|
||||
*
|
||||
* @return int - new topic id
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function topic_create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'forum_id' => 'Forum ID was not passed',
|
||||
'title' => 'Forum topic title not passed',
|
||||
'message' => 'Forum topic message not passed',
|
||||
);
|
||||
'title' => 'Forum topic title not passed',
|
||||
'message' => 'Forum topic message not passed',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if(strlen($data['message']) < 2) {
|
||||
if (strlen($data['message']) < 2) {
|
||||
throw new \Box_Exception('Your message is too short');
|
||||
}
|
||||
|
||||
@@ -315,7 +332,7 @@ class Admin extends \Api_Abstract
|
||||
$topic->forum_id = $forum->id;
|
||||
$topic->title = $data['title'];
|
||||
$topic->slug = $this->di['tools']->slug($data['title']);
|
||||
$topic->status = isset($data['status']) ? $data['status'] : \Model_ForumTopic::STATUS_ACTIVE;
|
||||
$topic->status = $data['status'] ?? \Model_ForumTopic::STATUS_ACTIVE;
|
||||
$topic->created_at = date('Y-m-d H:i:s');
|
||||
$topic->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($topic);
|
||||
@@ -331,33 +348,34 @@ class Admin extends \Api_Abstract
|
||||
|
||||
$this->di['logger']->info('Started new forum topic "%s"', $topic->title);
|
||||
|
||||
return (int)$topic->id;
|
||||
return (int) $topic->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update forum topic
|
||||
*
|
||||
* Update forum topic.
|
||||
*
|
||||
* @param int $id - topic id
|
||||
*
|
||||
*
|
||||
* @optional string $title - topic title
|
||||
* @optional string $message - topic message
|
||||
* @optional string $status - topic status
|
||||
* @optional string $slug - topic slug
|
||||
* @optional int $views - topic views count
|
||||
* @optional bool $sticky - topic sticky flag
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function topic_update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Forum topic id was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('ForumTopic', $data['id'], 'Forum Topic not found');
|
||||
|
||||
|
||||
$model->forum_id = $this->di['array_get']($data, 'forum_id', $model->forum_id);
|
||||
$model->title = $this->di['array_get']($data, 'title', $model->title);
|
||||
$model->status = $this->di['array_get']($data, 'status', $model->status);
|
||||
@@ -368,49 +386,54 @@ class Admin extends \Api_Abstract
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Updated forum topic "%s"', $model->title);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get topic messages list
|
||||
*
|
||||
* Get topic messages list.
|
||||
*
|
||||
* @optional int $forum_topic_id - topic id
|
||||
* @optional int $client_id - filter by client id
|
||||
* @optional bool $with_points - get messages with points only
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function message_get_list($data)
|
||||
{
|
||||
$data['orderby'] = 'created_at';
|
||||
$data['sortorder'] = 'desc';
|
||||
$data['orderby'] = 'created_at';
|
||||
$data['sortorder'] = 'desc';
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
list($sql, $params) = $this->getService()->getMessagesQuery($data);
|
||||
[$sql, $params] = $this->getService()->getMessagesQuery($data);
|
||||
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach($pager['list'] as &$entry) {
|
||||
foreach ($pager['list'] as &$entry) {
|
||||
$entry['author'] = $this->getService()->getProfile($entry['client_id']);
|
||||
if (!$entry['client_id'] && $entry['admin_id']){
|
||||
if (!$entry['client_id'] && $entry['admin_id']) {
|
||||
$admin = $this->di['db']->getExistingModelById('Admin', $entry['admin_id'], 'Admin not found');
|
||||
$entry['author']['gravatar'] = 'https://gravatar.com/avatar/' . md5($admin->email);
|
||||
$entry['author']['gravatar'] = 'https://gravatar.com/avatar/'.md5($admin->email);
|
||||
}
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get forum topic message
|
||||
*
|
||||
* Get forum topic message.
|
||||
*
|
||||
* @param int $id - message id
|
||||
*
|
||||
* @return type
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function message_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Forum Topic message ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$table = $this->di['table']('ForumTopicMessage');
|
||||
@@ -421,20 +444,21 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Update forum topic message
|
||||
*
|
||||
* Update forum topic message.
|
||||
*
|
||||
* @param int $id - message id
|
||||
*
|
||||
*
|
||||
* @optional string $message - topic message
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function message_update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Forum Topic message ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('ForumTopicMessage', $data['id'], 'Forum Topic Message not found');
|
||||
@@ -444,52 +468,56 @@ class Admin extends \Api_Abstract
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Updated forum topic message #%s', $model->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete topic message
|
||||
*
|
||||
* Delete topic message.
|
||||
*
|
||||
* @param int $id - message id
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function message_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Forum Topic message ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$table = $table = $this->di['table']('ForumTopicMessage');
|
||||
$model = $this->di['db']->getExistingModelById('ForumTopicMessage', $data['id'], 'Forum Topic Message not found');
|
||||
$model = $this->di['db']->getExistingModelById('ForumTopicMessage', $data['id'], 'Forum Topic Message not found');
|
||||
|
||||
$id = $model->id;
|
||||
$table->rm($model);
|
||||
|
||||
$this->di['logger']->info('Admin removed forum topic message #%s', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post new message to topic
|
||||
*
|
||||
* @param int $forum_topic_id - forum topic id
|
||||
* @param string $message - topic message
|
||||
*
|
||||
* Post new message to topic.
|
||||
*
|
||||
* @param int $forum_topic_id - forum topic id
|
||||
* @param string $message - topic message
|
||||
*
|
||||
* @return id
|
||||
* @throws \Box_Exception
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function message_create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'forum_topic_id' => 'Forum Topic ID not passed',
|
||||
'message' => 'Topic message not passed',
|
||||
);
|
||||
'message' => 'Topic message not passed',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if(strlen($data['message']) < 2) {
|
||||
if (strlen($data['message']) < 2) {
|
||||
throw new \Box_Exception('Your message is too short');
|
||||
}
|
||||
|
||||
@@ -509,73 +537,81 @@ class Admin extends \Api_Abstract
|
||||
$topic->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($topic);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminRepliedInForum', 'params'=>array('id'=>$topic->id, 'message_id'=>$msg->id, 'admin_id'=>$admin->id)));
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminRepliedInForum', 'params' => ['id' => $topic->id, 'message_id' => $msg->id, 'admin_id' => $admin->id]]);
|
||||
|
||||
$this->di['logger']->info('Posted new forum message %s', $msg->id);
|
||||
return (int)$msg->id;
|
||||
|
||||
return (int) $msg->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decline post. Post will be considered as not worth the points.
|
||||
*
|
||||
*
|
||||
* @param int $id - message id
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function points_deduct($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Message ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
|
||||
$service = $service = $this->di['mod_service']('forum');
|
||||
$service->declinePointsForPost($data['id']);
|
||||
|
||||
$service->declinePointsForPost($data['id']);
|
||||
|
||||
$this->di['logger']->info('Deducted points from forum message #%s', $data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update total points for client
|
||||
*
|
||||
* @param int $client_id - client id
|
||||
* @param float $amount - new points total
|
||||
*
|
||||
* @return boolean
|
||||
* Update total points for client.
|
||||
*
|
||||
* @param int $client_id - client id
|
||||
* @param float $amount - new points total
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function points_update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'client_id' => 'Client ID not passed',
|
||||
'amount' => 'Amount not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
|
||||
$service = $service = $this->di['mod_service']('forum');
|
||||
$service->updateTotalPoints($data['client_id'], $data['amount']);
|
||||
|
||||
$service->updateTotalPoints($data['client_id'], $data['amount']);
|
||||
|
||||
$this->di['logger']->info('Updated client %s forum points balance to %s', $data['client_id'], $data['amount']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Client forum profile
|
||||
*
|
||||
* Client forum profile.
|
||||
*
|
||||
* @param int $client_id - client id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Box_Exception
|
||||
*/
|
||||
public function profile_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'client_id' => 'Client ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
|
||||
$forumService = $this->di['mod_service']('forum');
|
||||
|
||||
return $forumService->getProfile($data['client_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
+123
-105
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Forum management
|
||||
* Forum management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Forum\Api;
|
||||
@@ -19,18 +19,18 @@ namespace Box\Mod\Forum\Api;
|
||||
class Client extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of forums
|
||||
* Get paginated list of forums.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$table = $this->di['table']('Forum');
|
||||
list($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$forum = $this->di['db']->getExistingModelById('Forum', $item['id'], 'Forum not found');
|
||||
$forum = $this->di['db']->getExistingModelById('Forum', $item['id'], 'Forum not found');
|
||||
$pager['list'][$key] = $table->toApiArray($forum);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get forums list grouped by category name
|
||||
* Get forums list grouped by category name.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ class Client extends \Api_Abstract
|
||||
|
||||
$list = $this->di['db']->find('Forum', 'ORDER BY priority ASC, category ASC');
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($list as $f) {
|
||||
$result[$f->category][] = $table->toApiArray($f);
|
||||
}
|
||||
@@ -57,11 +57,12 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get forum details
|
||||
* Get forum details.
|
||||
*
|
||||
* @param int $id - forum id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get($data)
|
||||
@@ -70,12 +71,12 @@ class Client extends \Api_Abstract
|
||||
throw new \Box_Exception('ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
|
||||
$table = $this->di['table']('Forum');
|
||||
|
||||
$model = FALSE;
|
||||
$model = false;
|
||||
if ($id) {
|
||||
$model = $table->findOneActiveById($id);
|
||||
} else {
|
||||
@@ -90,24 +91,26 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated list of topics
|
||||
* Get paginated list of topics.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_topic_list($data)
|
||||
{
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
list($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
|
||||
return $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get topic details
|
||||
* Get topic details.
|
||||
*
|
||||
* @param int $id - topic id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get_topic($data)
|
||||
@@ -116,16 +119,16 @@ class Client extends \Api_Abstract
|
||||
throw new \Box_Exception('ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
|
||||
$model = FALSE;
|
||||
$model = false;
|
||||
if ($id) {
|
||||
$model = $this->di['db']->getExistingModelById('ForumTopic', $id, 'Forum topic not found');
|
||||
} else {
|
||||
$model = $this->di['db']->findOne('ForumTopic', 'slug = :slug', array(':slug' => $slug));
|
||||
$model = $this->di['db']->findOne('ForumTopic', 'slug = :slug', [':slug' => $slug]);
|
||||
}
|
||||
|
||||
if (!$model instanceof \Model_ForumTopic) {
|
||||
@@ -137,15 +140,16 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new topic
|
||||
* Create new topic.
|
||||
*
|
||||
* @param int $forum_id - forum id
|
||||
* @param string $topic - topic title
|
||||
* @param string $message - topic message
|
||||
* @param int $forum_id - forum id
|
||||
* @param string $topic - topic title
|
||||
* @param string $message - topic message
|
||||
*
|
||||
* @optional string $status - initial topic status
|
||||
*
|
||||
* @return int - new topic id
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function start_topic($data)
|
||||
@@ -164,59 +168,61 @@ class Client extends \Api_Abstract
|
||||
throw new \Box_Exception('Your message is too short');
|
||||
}
|
||||
|
||||
$event_params = $data;
|
||||
$event_params = $data;
|
||||
$event_params['client_id'] = $this->getIdentity()->id;
|
||||
$this->di['events_manager']->fire(array('event' => 'onBeforeClientCreateForumTopic', 'params' => $event_params));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeClientCreateForumTopic', 'params' => $event_params]);
|
||||
|
||||
$table = $this->di['table']('Forum');;
|
||||
$table = $this->di['table']('Forum');
|
||||
$forum = $table->findOneActiveById($data['forum_id']);
|
||||
if (!$forum instanceof \Model_Forum) {
|
||||
throw new \Box_Exception('Forum not found');
|
||||
}
|
||||
|
||||
if ($forum->status == \Model_Forum::STATUS_LOCKED) {
|
||||
if (\Model_Forum::STATUS_LOCKED == $forum->status) {
|
||||
throw new \Box_Exception('Forum is locked. No new topics can be started');
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
|
||||
$topic = $this->di['db']->dispense('ForumTopic');
|
||||
$topic->forum_id = $forum->id;
|
||||
$topic->title = $data['topic'];
|
||||
$topic->slug = $this->di['tools']->slug($data['topic']);
|
||||
$topic->status = 'active';
|
||||
$topic = $this->di['db']->dispense('ForumTopic');
|
||||
$topic->forum_id = $forum->id;
|
||||
$topic->title = $data['topic'];
|
||||
$topic->slug = $this->di['tools']->slug($data['topic']);
|
||||
$topic->status = 'active';
|
||||
$topic->created_at = date('Y-m-d H:i:s');
|
||||
$topic->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($topic);
|
||||
|
||||
$msg = $this->di['db']->dispense('ForumTopicMessage');
|
||||
$msg->client_id = $client->id;
|
||||
$msg = $this->di['db']->dispense('ForumTopicMessage');
|
||||
$msg->client_id = $client->id;
|
||||
$msg->forum_topic_id = $topic->id;
|
||||
$msg->message = $data['message'];
|
||||
$msg->ip = $this->getIp();
|
||||
$msg->created_at = date('Y-m-d H:i:s');
|
||||
$msg->updated_at = date('Y-m-d H:i:s');
|
||||
$msg->message = $data['message'];
|
||||
$msg->ip = $this->getIp();
|
||||
$msg->created_at = date('Y-m-d H:i:s');
|
||||
$msg->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($msg);
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onAfterClientCreateForumTopic', 'params' => array('id' => $topic->id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientCreateForumTopic', 'params' => ['id' => $topic->id]]);
|
||||
|
||||
$this->subscribe(array('id' => $topic->id));
|
||||
$this->subscribe(['id' => $topic->id]);
|
||||
|
||||
$this->di['logger']->info('Started new forum topic "%s"', $topic->title);
|
||||
|
||||
//@EasterEgg to return slug instead of id
|
||||
if (isset($data['return']) && $data['return'] == 'slug') {
|
||||
// @EasterEgg to return slug instead of id
|
||||
if (isset($data['return']) && 'slug' == $data['return']) {
|
||||
return $topic->slug;
|
||||
}
|
||||
|
||||
return (int)$topic->id;
|
||||
return (int) $topic->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get topic messages list
|
||||
* Get topic messages list.
|
||||
*
|
||||
* @param int $forum_topic_id - topic id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get_topic_message_list($data)
|
||||
@@ -225,19 +231,20 @@ class Client extends \Api_Abstract
|
||||
throw new \Box_Exception('Forum Topic ID not passed');
|
||||
}
|
||||
$table = $this->di['table']('ForumTopicMessage');
|
||||
list($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
|
||||
return $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post new message to topic
|
||||
* Post new message to topic.
|
||||
*
|
||||
* @param int $forum_topic_id - forum topic id
|
||||
* @param string $message - topic message
|
||||
* @param int $forum_topic_id - forum topic id
|
||||
* @param string $message - topic message
|
||||
*
|
||||
* @return id
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function post_message($data)
|
||||
@@ -256,38 +263,39 @@ class Client extends \Api_Abstract
|
||||
|
||||
$topic = $this->di['db']->getExistingModelById('ForumTopic', $data['forum_topic_id'], 'Forum Topic not found');
|
||||
|
||||
if ($topic->status == \Model_ForumTopic::STATUS_LOCKED) {
|
||||
if (\Model_ForumTopic::STATUS_LOCKED == $topic->status) {
|
||||
throw new \Box_Exception('Forum topic is locked. No new message can be posted');
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
|
||||
$data['client_id'] = $client->id;
|
||||
$this->di['events_manager']->fire(array('event' => 'onBeforeClientRepliedInForum', 'params' => $data));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeClientRepliedInForum', 'params' => $data]);
|
||||
|
||||
$msg = $this->di['db']->dispense('ForumTopicMessage');
|
||||
$msg->client_id = $client->id;
|
||||
$msg = $this->di['db']->dispense('ForumTopicMessage');
|
||||
$msg->client_id = $client->id;
|
||||
$msg->forum_topic_id = $topic->id;
|
||||
$msg->message = $data['message'];
|
||||
$msg->ip = $this->getIp();
|
||||
$msg->created_at = date('Y-m-d H:i:s');
|
||||
$msg->updated_at = date('Y-m-d H:i:s');
|
||||
$msg->message = $data['message'];
|
||||
$msg->ip = $this->getIp();
|
||||
$msg->created_at = date('Y-m-d H:i:s');
|
||||
$msg->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($msg);
|
||||
|
||||
$topic->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($topic);
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onAfterClientRepliedInForum', 'params' => array('id' => $topic->id, 'message_id' => $msg->id, 'client_id' => $client->id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientRepliedInForum', 'params' => ['id' => $topic->id, 'message_id' => $msg->id, 'client_id' => $client->id]]);
|
||||
|
||||
$this->di['logger']->info('Posted message in topic #%s', $topic->id);
|
||||
|
||||
return (int)$msg->id;
|
||||
return (int) $msg->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current client is subscribed to forum notifications
|
||||
* Check if current client is subscribed to forum notifications.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function is_subscribed($data)
|
||||
@@ -297,7 +305,7 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
$sql = "
|
||||
$sql = '
|
||||
SELECT meta_value
|
||||
FROM extension_meta
|
||||
WHERE client_id = :cid
|
||||
@@ -305,18 +313,19 @@ class Client extends \Api_Abstract
|
||||
AND rel_type = :type
|
||||
AND rel_id = :rid
|
||||
AND meta_key = :key
|
||||
";
|
||||
$tid = $data['id'];
|
||||
';
|
||||
$tid = $data['id'];
|
||||
|
||||
$value = $this->di['db']->getCell($sql, array('cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'notification'));
|
||||
$value = $this->di['db']->getCell($sql, ['cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'notification']);
|
||||
|
||||
return (bool)$value;
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe client from topic notifications
|
||||
* Unsubscribe client from topic notifications.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function unsubscribe($data)
|
||||
@@ -326,17 +335,17 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
$sql = "
|
||||
$sql = '
|
||||
DELETE FROM extension_meta
|
||||
WHERE client_id = :cid
|
||||
AND extension = :ext
|
||||
AND rel_type = :type
|
||||
AND rel_id = :rid
|
||||
AND meta_key = :key
|
||||
";
|
||||
$tid = $data['id'];
|
||||
';
|
||||
$tid = $data['id'];
|
||||
|
||||
$this->di['db']->exec($sql, array('cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'notification'));
|
||||
$this->di['db']->exec($sql, ['cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'notification']);
|
||||
|
||||
$this->di['logger']->info('Unsubscribed from forum topic %s', $data['id']);
|
||||
|
||||
@@ -344,10 +353,12 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe client to forum topic notifications
|
||||
* Subscribe client to forum topic notifications.
|
||||
*
|
||||
* @param int $id - forum topic id
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function subscribe($data)
|
||||
@@ -360,13 +371,13 @@ class Client extends \Api_Abstract
|
||||
throw new \Exception('You have already subscribed to this topic notifications');
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_forum';
|
||||
$meta->client_id = $client->id;
|
||||
$meta->rel_type = 'forum_topic';
|
||||
$meta->rel_id = $data['id'];
|
||||
$meta->meta_key = 'notification';
|
||||
$client = $this->getIdentity();
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_forum';
|
||||
$meta->client_id = $client->id;
|
||||
$meta->rel_type = 'forum_topic';
|
||||
$meta->rel_id = $data['id'];
|
||||
$meta->meta_key = 'notification';
|
||||
$meta->meta_value = 1;
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
@@ -378,24 +389,24 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of topics added to favorites
|
||||
* Get list of topics added to favorites.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function favorites($data)
|
||||
{
|
||||
$client = $this->getIdentity();
|
||||
$sql = "
|
||||
$sql = '
|
||||
SELECT rel_id
|
||||
FROM extension_meta
|
||||
WHERE client_id = :cid
|
||||
AND extension = :ext
|
||||
AND rel_type = :type
|
||||
AND meta_key = :key
|
||||
";
|
||||
$list = $this->di['db']->getAssoc($sql, array('cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'key' => 'favorite'));
|
||||
$result = array();
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
';
|
||||
$list = $this->di['db']->getAssoc($sql, ['cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'key' => 'favorite']);
|
||||
$result = [];
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
$topics = $table->getTopicsByIds(array_values($list));
|
||||
foreach ($topics as $topic) {
|
||||
$result[] = $table->toApiArray($topic);
|
||||
@@ -405,10 +416,12 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if topic is added to favorites
|
||||
* Check if topic is added to favorites.
|
||||
*
|
||||
* @param int $id - forum topic id
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function is_favorite($data)
|
||||
@@ -418,7 +431,7 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
$sql = "
|
||||
$sql = '
|
||||
SELECT meta_value
|
||||
FROM extension_meta
|
||||
WHERE client_id = :cid
|
||||
@@ -426,19 +439,21 @@ class Client extends \Api_Abstract
|
||||
AND rel_type = :type
|
||||
AND rel_id = :rid
|
||||
AND meta_key = :key
|
||||
";
|
||||
$tid = $data['id'];
|
||||
';
|
||||
$tid = $data['id'];
|
||||
|
||||
$value = $this->di['db']->getCell($sql, array('cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'favorite'));
|
||||
$value = $this->di['db']->getCell($sql, ['cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'favorite']);
|
||||
|
||||
return (bool)$value;
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add topic to favorites
|
||||
* Add topic to favorites.
|
||||
*
|
||||
* @param int $id - forum topic id
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -452,13 +467,13 @@ class Client extends \Api_Abstract
|
||||
throw new \Exception('You have already added this topic to favorites');
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_forum';
|
||||
$meta->client_id = $client->id;
|
||||
$meta->rel_type = 'forum_topic';
|
||||
$meta->rel_id = $data['id'];
|
||||
$meta->meta_key = 'favorite';
|
||||
$client = $this->getIdentity();
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_forum';
|
||||
$meta->client_id = $client->id;
|
||||
$meta->rel_type = 'forum_topic';
|
||||
$meta->rel_id = $data['id'];
|
||||
$meta->meta_key = 'favorite';
|
||||
$meta->meta_value = 1;
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
@@ -470,10 +485,12 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove topic from favorites
|
||||
* Remove topic from favorites.
|
||||
*
|
||||
* @param int $id - forum topic id
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function favorite_remove($data)
|
||||
@@ -483,17 +500,17 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
$client = $this->getIdentity();
|
||||
$sql = "
|
||||
$sql = '
|
||||
DELETE FROM extension_meta
|
||||
WHERE client_id = :cid
|
||||
AND extension = :ext
|
||||
AND rel_type = :type
|
||||
AND rel_id = :rid
|
||||
AND meta_key = :key
|
||||
";
|
||||
$tid = $data['id'];
|
||||
';
|
||||
$tid = $data['id'];
|
||||
|
||||
$this->di['db']->exec($sql, array('cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'favorite'));
|
||||
$this->di['db']->exec($sql, ['cid' => $client->id, 'ext' => 'mod_forum', 'type' => 'forum_topic', 'rid' => $tid, 'key' => 'favorite']);
|
||||
|
||||
$this->di['logger']->info('Removed forum topic %s from favorites', $data['id']);
|
||||
|
||||
@@ -501,13 +518,14 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Forum profile
|
||||
* Forum profile.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function profile($data)
|
||||
{
|
||||
return $this->getService()->getProfile($this->getIdentity()->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Forum management
|
||||
* Forum management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Forum\Api;
|
||||
@@ -19,18 +19,18 @@ namespace Box\Mod\Forum\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of forums
|
||||
* Get paginated list of forums.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$table = $this->di['table']('Forum');
|
||||
list ($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$forum = $this->di['db']->getExistingModelById('Forum', $item['id'], 'Forum not found');
|
||||
$forum = $this->di['db']->getExistingModelById('Forum', $item['id'], 'Forum not found');
|
||||
$pager['list'][$key] = $table->toApiArray($forum);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get forums list grouped by category name
|
||||
* Get forums list grouped by category name.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ class Guest extends \Api_Abstract
|
||||
|
||||
$list = $this->di['db']->find('Forum', 'ORDER BY priority ASC, category ASC');
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($list as $f) {
|
||||
$result[$f->category][] = $table->toApiArray($f);
|
||||
}
|
||||
@@ -57,11 +57,12 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get forum details
|
||||
* Get forum details.
|
||||
*
|
||||
* @param int $id - forum id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get($data)
|
||||
@@ -70,12 +71,12 @@ class Guest extends \Api_Abstract
|
||||
throw new \Box_Exception('ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
|
||||
$table = $this->di['table']('Forum');
|
||||
|
||||
$model = FALSE;
|
||||
$model = false;
|
||||
if ($id) {
|
||||
$model = $table->findOneActiveById($id);
|
||||
} else {
|
||||
@@ -90,18 +91,18 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated list of topics
|
||||
* Get paginated list of topics.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_topic_list($data)
|
||||
{
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
list($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach($pager['list'] as $key => $item){
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$forum = $this->di['db']->getExistingModelById('ForumTopic', $item['id'], 'Forum topic not found');
|
||||
$pager['list'][$key] = $table->toApiArray($forum);
|
||||
}
|
||||
@@ -110,10 +111,12 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get topic details
|
||||
* Get topic details.
|
||||
*
|
||||
* @param int $id - topic id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get_topic($data)
|
||||
@@ -122,16 +125,16 @@ class Guest extends \Api_Abstract
|
||||
throw new \Box_Exception('ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
|
||||
$table = $this->di['table']('ForumTopic');
|
||||
|
||||
$model = FALSE;
|
||||
$model = false;
|
||||
if ($id) {
|
||||
$model = $this->di['db']->getExistingModelById('ForumTopic', $id, 'Forum topic not found');
|
||||
} else {
|
||||
$model = $this->di['db']->findOne('ForumTopic', 'slug = :slug', array(':slug' => $slug));
|
||||
$model = $this->di['db']->findOne('ForumTopic', 'slug = :slug', [':slug' => $slug]);
|
||||
}
|
||||
if (!$model instanceof \Model_ForumTopic) {
|
||||
throw new \Box_Exception('Forum Topic not found');
|
||||
@@ -142,10 +145,12 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get topic messages list
|
||||
* Get topic messages list.
|
||||
*
|
||||
* @param int $forum_topic_id - topic id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get_topic_message_list($data)
|
||||
@@ -154,11 +159,11 @@ class Guest extends \Api_Abstract
|
||||
throw new \Box_Exception('Forum Topic ID not passed');
|
||||
}
|
||||
$table = $this->di['table']('ForumTopicMessage');
|
||||
list($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach($pager['list'] as $key => $item){
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$forum = $this->di['db']->getExistingModelById('ForumTopicMessage', $item['id'], 'Forum topic message not found');
|
||||
$pager['list'][$key] = $table->toApiArray($forum);
|
||||
}
|
||||
@@ -167,17 +172,19 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Search topic messages
|
||||
* Search topic messages.
|
||||
*
|
||||
* @param string $q - query string
|
||||
*
|
||||
* @return array - paginated list of results
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function search($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'q' => 'Enter some keywords for search',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
if (strlen($data['q']) < 3) {
|
||||
@@ -185,16 +192,18 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
$table = $this->di['table']('ForumTopicMessage');
|
||||
list($sql, $params) = $table->getSearchQuery($data);
|
||||
[$sql, $params] = $table->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
|
||||
return $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
}
|
||||
|
||||
public function members_list($data)
|
||||
{
|
||||
list($sql, $params) = $this->getService()->getMembersListQuery($data);
|
||||
[$sql, $params] = $this->getService()->getMembersListQuery($data);
|
||||
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
|
||||
return $this->di['pager']->getAdvancedResultSet($sql, $params, $per_page);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Forum\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,50 +34,54 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'subpages'=>array(
|
||||
array(
|
||||
'location' => 'support',
|
||||
'index' => 700,
|
||||
return [
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'support',
|
||||
'index' => 700,
|
||||
'label' => 'Forum',
|
||||
'uri' => $this->di['url']->adminLink('forum'),
|
||||
'uri' => $this->di['url']->adminLink('forum'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/forum', 'get_index', array(), get_class($this));
|
||||
$app->get('/forum/profile/:id', 'get_profile', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/forum/:id', 'get_forum', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/forum/topic/:id', 'get_topic', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/forum', 'get_index', [], get_class($this));
|
||||
$app->get('/forum/profile/:id', 'get_profile', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/forum/:id', 'get_forum', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/forum/topic/:id', 'get_topic', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_forum_index');
|
||||
}
|
||||
|
||||
|
||||
public function get_forum(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$forum = $api->forum_get(array('id'=>$id));
|
||||
return $app->render('mod_forum_forum', array('forum'=>$forum));
|
||||
$forum = $api->forum_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_forum_forum', ['forum' => $forum]);
|
||||
}
|
||||
|
||||
|
||||
public function get_topic(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$topic = $api->forum_topic_get(array('id'=>$id));
|
||||
return $app->render('mod_forum_topic', array('topic'=>$topic));
|
||||
$topic = $api->forum_topic_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_forum_topic', ['topic' => $topic]);
|
||||
}
|
||||
|
||||
|
||||
public function get_profile(\Box_App $app, $id)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
return $app->render('mod_forum_profile', array('client_id'=>$id));
|
||||
|
||||
return $app->render('mod_forum_profile', ['client_id' => $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Forum\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,11 +34,11 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/forum', 'get_index', array(), get_class($this));
|
||||
$app->get('/forum/members-list', 'get_members', array(), get_class($this));
|
||||
$app->get('/forum/topics.rss', 'get_rss', array(), get_class($this));
|
||||
$app->get('/forum/:forum', 'get_forum', array('forum' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/forum/:forum/:topic', 'get_forum_topic', array('forum' => '[a-z0-9-]+', 'topic' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/forum', 'get_index', [], get_class($this));
|
||||
$app->get('/forum/members-list', 'get_members', [], get_class($this));
|
||||
$app->get('/forum/topics.rss', 'get_rss', [], get_class($this));
|
||||
$app->get('/forum/:forum', 'get_forum', ['forum' => '[a-z0-9-]+'], get_class($this));
|
||||
$app->get('/forum/:forum/:topic', 'get_forum_topic', ['forum' => '[a-z0-9-]+', 'topic' => '[a-z0-9-]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
@@ -50,36 +49,39 @@ class Client implements \Box\InjectionAwareInterface
|
||||
public function get_rss(\Box_App $app)
|
||||
{
|
||||
header('Content-Type: application/rss+xml;');
|
||||
|
||||
return $app->render('mod_forum_rss');
|
||||
}
|
||||
|
||||
|
||||
public function get_forum(\Box_App $app, $forum)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
'slug' => $forum,
|
||||
);
|
||||
$data = [
|
||||
'slug' => $forum,
|
||||
];
|
||||
$f = $api->forum_get($data);
|
||||
return $app->render('mod_forum_forum', array('forum'=>$f));
|
||||
|
||||
return $app->render('mod_forum_forum', ['forum' => $f]);
|
||||
}
|
||||
|
||||
public function get_forum_topic(\Box_App $app, $forum, $topic)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
'slug' => $forum,
|
||||
);
|
||||
$data = [
|
||||
'slug' => $forum,
|
||||
];
|
||||
$f = $api->forum_get($data);
|
||||
|
||||
$data = array(
|
||||
'slug' => $topic,
|
||||
);
|
||||
$data = [
|
||||
'slug' => $topic,
|
||||
];
|
||||
$t = $api->forum_get_topic($data);
|
||||
return $app->render('mod_forum_topic', array('topic'=>$t, 'forum'=>$f));
|
||||
|
||||
return $app->render('mod_forum_topic', ['topic' => $t, 'forum' => $f]);
|
||||
}
|
||||
|
||||
|
||||
public function get_members(\Box_App $app)
|
||||
{
|
||||
return $app->render('mod_forum_members_list', array());
|
||||
return $app->render('mod_forum_members_list', []);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Forum;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -31,7 +30,7 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function getProfile($client_id)
|
||||
{
|
||||
$sql='SELECT
|
||||
$sql = 'SELECT
|
||||
id,
|
||||
CONCAT(c.first_name, " ", c.last_name) as name,
|
||||
CONCAT("https://gravatar.com/avatar/", MD5(c.email)) as gravatar,
|
||||
@@ -39,30 +38,31 @@ class Service implements InjectionAwareInterface
|
||||
FROM client c
|
||||
WHERE c.id = :cid
|
||||
';
|
||||
|
||||
$details = $this->di['db']->getRow($sql, array(':cid'=>$client_id));
|
||||
$posts = $this->di['db']->getCell('SELECT COUNT(id) FROM forum_topic_message WHERE client_id = :cid', array(':cid'=>$client_id));
|
||||
|
||||
|
||||
$details = $this->di['db']->getRow($sql, [':cid' => $client_id]);
|
||||
$posts = $this->di['db']->getCell('SELECT COUNT(id) FROM forum_topic_message WHERE client_id = :cid', [':cid' => $client_id]);
|
||||
|
||||
$points = $this->di['db']->getCell('SELECT meta_value
|
||||
FROM extension_meta
|
||||
WHERE extension = "mod_forum"
|
||||
AND meta_key = "points_total"
|
||||
AND client_id = :cid',
|
||||
array('cid'=>$client_id));
|
||||
AND client_id = :cid',
|
||||
['cid' => $client_id]);
|
||||
|
||||
$profile = [];
|
||||
$profile['id'] = $details['id'];
|
||||
$profile['posts'] = $posts;
|
||||
$profile['points'] = ($points) ? $points : 0;
|
||||
$profile['gravatar'] = $details['gravatar'];
|
||||
$profile['name'] = $details['name'];
|
||||
$profile['created_at'] = $details['created_at'];
|
||||
|
||||
$profile = array();
|
||||
$profile['id'] = $details['id'];
|
||||
$profile['posts'] = $posts;
|
||||
$profile['points'] = ($points) ? $points : 0;
|
||||
$profile['gravatar'] = $details['gravatar'];
|
||||
$profile['name'] = $details['name'];
|
||||
$profile['created_at'] = $details['created_at'];
|
||||
return $profile;
|
||||
}
|
||||
|
||||
|
||||
public function getMembersListQuery($data)
|
||||
{
|
||||
$sql='
|
||||
$sql = '
|
||||
SELECT
|
||||
0 as posts,
|
||||
CONCAT(c.first_name, " ", c.last_name) as name,
|
||||
@@ -72,23 +72,24 @@ class Service implements InjectionAwareInterface
|
||||
RIGHT JOIN forum_topic_message fp ON (fp.client_id = c.id)
|
||||
WHERE fp.id > 0
|
||||
';
|
||||
|
||||
$params = array();
|
||||
|
||||
$first_char = $this->di['array_get']($data, 'first_char', NULL);
|
||||
|
||||
if(NULL !== $first_char) {
|
||||
|
||||
$params = [];
|
||||
|
||||
$first_char = $this->di['array_get']($data, 'first_char', null);
|
||||
|
||||
if (null !== $first_char) {
|
||||
$sql .= ' AND c.first_name LIKE :first_char';
|
||||
$params['first_char'] = $first_char.'%';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY c.first_name DESC ';
|
||||
return array($sql, $params);
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
|
||||
public function getMessagesQuery($data)
|
||||
{
|
||||
$sql='
|
||||
$sql = '
|
||||
SELECT fp.id, fp.client_id, fp.admin_id, fp.message, fp.points,
|
||||
ft.slug as forum_topic_slug,
|
||||
f.slug as forum_slug,
|
||||
@@ -102,61 +103,61 @@ class Service implements InjectionAwareInterface
|
||||
LEFT JOIN forum f ON (f.id = ft.forum_id)
|
||||
WHERE 1
|
||||
';
|
||||
|
||||
$params = array();
|
||||
|
||||
$search = (isset($data['q']) && !empty($data['q'])) ? $data['q'] : NULL;
|
||||
$search2 = (isset($data['search']) && !empty($data['search'])) ? $data['search'] : NULL;
|
||||
$forum_topic_id = (isset($data['forum_topic_id']) && !empty($data['forum_topic_id'])) ? $data['forum_topic_id'] : NULL;
|
||||
$forum_id = $this->di['array_get']($data, 'forum_id', NULL);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$with_points = $this->di['array_get']($data, 'with_points', NULL);
|
||||
|
||||
if($with_points) {
|
||||
$params = [];
|
||||
|
||||
$search = (isset($data['q']) && !empty($data['q'])) ? $data['q'] : null;
|
||||
$search2 = (isset($data['search']) && !empty($data['search'])) ? $data['search'] : null;
|
||||
$forum_topic_id = (isset($data['forum_topic_id']) && !empty($data['forum_topic_id'])) ? $data['forum_topic_id'] : null;
|
||||
$forum_id = $this->di['array_get']($data, 'forum_id', null);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
$with_points = $this->di['array_get']($data, 'with_points', null);
|
||||
|
||||
if ($with_points) {
|
||||
$sql .= ' AND fp.points IS NOT NULL AND fp.points != "" ';
|
||||
}
|
||||
|
||||
if($forum_topic_id) {
|
||||
|
||||
if ($forum_topic_id) {
|
||||
$sql .= ' AND ft.id = :forum_topic_id';
|
||||
$params['forum_topic_id'] = $forum_topic_id;
|
||||
}
|
||||
|
||||
if($forum_id) {
|
||||
if ($forum_id) {
|
||||
$sql .= ' AND f.id = :forum_id';
|
||||
$params['forum_id'] = $forum_id;
|
||||
}
|
||||
|
||||
if($client_id) {
|
||||
|
||||
if ($client_id) {
|
||||
$sql .= ' AND fp.client_id = :cid';
|
||||
$params['cid'] = $client_id;
|
||||
}
|
||||
|
||||
if($search) {
|
||||
if ($search) {
|
||||
$sql .= ' AND fp.message LIKE :search';
|
||||
$params['search'] = "%$search%";
|
||||
}
|
||||
|
||||
if($search2) {
|
||||
|
||||
if ($search2) {
|
||||
$sql .= ' AND fp.message LIKE :search2';
|
||||
$params['search2'] = "%$search2%";
|
||||
}
|
||||
|
||||
if(isset($data['orderby'])) {
|
||||
if(in_array(strtolower($data['orderby']), array('id', 'created_at'))) {
|
||||
$sortorder = (isset($data['sortorder']) && in_array(strtolower($data['sortorder']), array('asc', 'desc'))) ? $data['sortorder'] : 'asc' ;
|
||||
|
||||
if (isset($data['orderby'])) {
|
||||
if (in_array(strtolower($data['orderby']), ['id', 'created_at'])) {
|
||||
$sortorder = (isset($data['sortorder']) && in_array(strtolower($data['sortorder']), ['asc', 'desc'])) ? $data['sortorder'] : 'asc';
|
||||
$sql .= ' ORDER BY '.sprintf('fp.%s %s', $data['orderby'], strtoupper($sortorder));
|
||||
}
|
||||
} else {
|
||||
$sql .= ' ORDER BY fp.id DESC';
|
||||
}
|
||||
|
||||
return array($sql, $params);
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
|
||||
public function updateTotalPoints($client_id, $amount, $increment = false)
|
||||
{
|
||||
$meta = $this->getTotalPointsMeta($client_id);
|
||||
if($increment) {
|
||||
if ($increment) {
|
||||
$amount = $meta->meta_value + $amount;
|
||||
}
|
||||
$meta->meta_value = $amount;
|
||||
@@ -170,19 +171,19 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$minus_points = -$post->points;
|
||||
|
||||
$post->points = null;
|
||||
$post->points = null;
|
||||
$post->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($post);
|
||||
|
||||
$this->updateTotalPoints($post->client_id, $minus_points, true);
|
||||
}
|
||||
|
||||
|
||||
private function getTotalPointsMeta($client_id)
|
||||
{
|
||||
$meta = $this->di['db']->findOne('extension_meta',
|
||||
'extension = "mod_forum" AND meta_key = "points_total" AND client_id = :cid',
|
||||
array('cid'=>$client_id));
|
||||
if(!$meta) {
|
||||
$meta = $this->di['db']->findOne('extension_meta',
|
||||
'extension = "mod_forum" AND meta_key = "points_total" AND client_id = :cid',
|
||||
['cid' => $client_id]);
|
||||
if (!$meta) {
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_forum';
|
||||
$meta->client_id = $client_id;
|
||||
@@ -191,13 +192,14 @@ class Service implements InjectionAwareInterface
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($meta);
|
||||
}
|
||||
}
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
|
||||
public function getTopicSubscribers($topic_id)
|
||||
{
|
||||
$sql="
|
||||
$sql = "
|
||||
SELECT client_id
|
||||
FROM extension_meta
|
||||
WHERE extension = 'mod_forum'
|
||||
@@ -206,15 +208,15 @@ class Service implements InjectionAwareInterface
|
||||
AND meta_key = 'notification'
|
||||
";
|
||||
|
||||
return $this->di['db']->getAssoc($sql, array(':rid'=>$topic_id));
|
||||
return $this->di['db']->getAssoc($sql, [':rid' => $topic_id]);
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterClientCreateForumTopic(\Box_Event $event)
|
||||
{
|
||||
$params = $event->getParameters();
|
||||
$id = $params['id'];
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterAdminRepliedInForum(\Box_Event $event)
|
||||
{
|
||||
$di = $event->getDi();
|
||||
@@ -226,27 +228,27 @@ class Service implements InjectionAwareInterface
|
||||
$service = $di['mod_service']('forum');
|
||||
$list = $service->getTopicSubscribers($id);
|
||||
|
||||
$message = $api->forum_message_get(array('id'=>$message_id));
|
||||
$topic = $api->forum_topic_get(array('id'=>$id));
|
||||
|
||||
foreach($list as $cid) {
|
||||
$email = array();
|
||||
$message = $api->forum_message_get(['id' => $message_id]);
|
||||
$topic = $api->forum_topic_get(['id' => $id]);
|
||||
|
||||
foreach ($list as $cid) {
|
||||
$email = [];
|
||||
$email['to_client'] = $cid;
|
||||
$email['code'] = 'mod_forum_new_post';
|
||||
$email['topic_id'] = $id;
|
||||
$email['message_id'] = $message_id;
|
||||
|
||||
|
||||
$email['message'] = $message;
|
||||
$email['topic'] = $topic;
|
||||
|
||||
|
||||
try {
|
||||
$api->email_template_send($email);
|
||||
} catch(\Exception $exc) {
|
||||
} catch (\Exception $exc) {
|
||||
error_log($exc->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterClientRepliedInForum(\Box_Event $event)
|
||||
{
|
||||
$di = $event->getDi();
|
||||
@@ -255,54 +257,53 @@ class Service implements InjectionAwareInterface
|
||||
$id = $params['id'];
|
||||
$message_id = $params['message_id'];
|
||||
$client_id = $params['client_id'];
|
||||
|
||||
|
||||
$service = $di['mod_service']('forum');
|
||||
$list = $service->getTopicSubscribers($id);
|
||||
|
||||
$message = $api->forum_message_get(array('id'=>$message_id));
|
||||
$topic = $api->forum_topic_get(array('id'=>$id));
|
||||
|
||||
foreach($list as $cid) {
|
||||
if($client_id == $cid) {
|
||||
//do not send email to author
|
||||
$message = $api->forum_message_get(['id' => $message_id]);
|
||||
$topic = $api->forum_topic_get(['id' => $id]);
|
||||
|
||||
foreach ($list as $cid) {
|
||||
if ($client_id == $cid) {
|
||||
// do not send email to author
|
||||
continue;
|
||||
}
|
||||
|
||||
$email = array();
|
||||
|
||||
$email = [];
|
||||
$email['to_client'] = $cid;
|
||||
$email['code'] = 'mod_forum_new_post';
|
||||
$email['topic_id'] = $id;
|
||||
$email['message_id'] = $message_id;
|
||||
|
||||
|
||||
$email['message'] = $message;
|
||||
$email['topic'] = $topic;
|
||||
|
||||
|
||||
try {
|
||||
$api->email_template_send($email);
|
||||
} catch(\Exception $exc) {
|
||||
} catch (\Exception $exc) {
|
||||
error_log($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//forum points
|
||||
|
||||
// forum points
|
||||
|
||||
$mod = $di['mod']('forum');
|
||||
$config = $mod->getConfig();
|
||||
$points = $di['array_get']($config, 'points', 0);
|
||||
$points_forums = $di['array_get']($config, 'points_forums', array());
|
||||
$points_forums = $di['array_get']($config, 'points_forums', []);
|
||||
|
||||
if(isset($config['forum_points_enable'])
|
||||
&& $config['forum_points_enable']
|
||||
if (isset($config['forum_points_enable'])
|
||||
&& $config['forum_points_enable']
|
||||
&& !empty($points_forums)
|
||||
&& in_array($topic['forum']['id'], $points_forums)
|
||||
&& strlen($message['message']) >= $config['post_length']
|
||||
&& $points > 0) {
|
||||
|
||||
$di['db']->exec('UPDATE forum_topic_message SET points = :points WHERE id = :id',
|
||||
array('points'=>$points, 'id'=>$message_id));
|
||||
|
||||
['points' => $points, 'id' => $message_id]);
|
||||
|
||||
$service = $mod->getService();
|
||||
$service->updateTotalPoints($client_id, $points, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hooks management module
|
||||
* Hooks management module.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Hook\Api;
|
||||
@@ -19,59 +19,61 @@ namespace Box\Mod\Hook\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of hooks
|
||||
* Get paginated list of hooks.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
list($sql, $params) = $service->getSearchQuery($data);
|
||||
[$sql, $params] = $service->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
|
||||
return $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoke hook with params
|
||||
*
|
||||
* Invoke hook with params.
|
||||
*
|
||||
* @param string $event - event name, ie: onEventBeforeInvoiceIsDue
|
||||
* @optional array $params - what params are passed to event method $event->getParams()
|
||||
*
|
||||
*
|
||||
* @return mixed - event return value
|
||||
*/
|
||||
public function call($data)
|
||||
{
|
||||
if(!isset($data['event']) || empty($data['event'])) {
|
||||
if (!isset($data['event']) || empty($data['event'])) {
|
||||
error_log('Invoked event call without providing event name');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$event = $data['event'];
|
||||
$params = $this->di['array_get']($data, 'params', null);
|
||||
if($this->di['config']['debug']) {
|
||||
if ($this->di['config']['debug']) {
|
||||
try {
|
||||
$this->di['logger']->info($event. ': '. var_export($params, 1));
|
||||
} catch(\Exception $e) {
|
||||
$this->di['logger']->info($event.': '.var_export($params, 1));
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->di['events_manager']->fire($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reinstall and activate all existing hooks from module or all
|
||||
* activated modules. Does not connect already connected event
|
||||
*
|
||||
* Reinstall and activate all existing hooks from module or all
|
||||
* activated modules. Does not connect already connected event.
|
||||
*
|
||||
* @optional string $mod - module name to connect hooks
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function batch_connect($data)
|
||||
{
|
||||
$mod = $this->di['array_get']($data, 'mod', null);
|
||||
$service = $this->getService();
|
||||
|
||||
return $service->batchConnect($mod);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,8 +10,8 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Hook;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class Service implements InjectionAwareInterface
|
||||
@@ -39,78 +39,80 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function getSearchQuery($filter)
|
||||
{
|
||||
$q="SELECT id, rel_type, rel_id, meta_value as event, created_at, updated_at
|
||||
$q = "SELECT id, rel_type, rel_id, meta_value as event, created_at, updated_at
|
||||
FROM extension_meta
|
||||
WHERE extension = 'mod_hook'
|
||||
AND rel_type = 'mod'
|
||||
AND meta_key = 'listener'
|
||||
";
|
||||
return array($q, array());
|
||||
|
||||
return [$q, []];
|
||||
}
|
||||
|
||||
|
||||
public function toApiArray($row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterAdminActivateExtension(\Box_Event $event)
|
||||
{
|
||||
$params = $event->getParameters();
|
||||
if(!isset($params['id'])) {
|
||||
$event->setReturnValue(FALSE);
|
||||
if (!isset($params['id'])) {
|
||||
$event->setReturnValue(false);
|
||||
} else {
|
||||
$di = $event->getDi();
|
||||
$ext = $di['db']->load('extension', $params['id']);
|
||||
if(is_object($ext) && $ext->type == 'mod') {
|
||||
if (is_object($ext) && 'mod' == $ext->type) {
|
||||
$service = $di['mod_service']('hook');
|
||||
$service->batchConnect($ext->name);
|
||||
}
|
||||
$event->setReturnValue(TRUE);
|
||||
$event->setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterAdminDeactivateExtension(\Box_Event $event)
|
||||
{
|
||||
$di = $event->getDi();
|
||||
$params = $event->getParameters();
|
||||
if($params['type'] == 'mod') {
|
||||
$q="DELETE FROM extension_meta
|
||||
if ('mod' == $params['type']) {
|
||||
$q = "DELETE FROM extension_meta
|
||||
WHERE extension = 'mod_hook'
|
||||
AND rel_type = 'mod'
|
||||
AND rel_id = :mod
|
||||
AND meta_key = 'listener'";
|
||||
$di['db']->exec($q, array('mod'=>$params['id']));
|
||||
$di['db']->exec($q, ['mod' => $params['id']]);
|
||||
}
|
||||
|
||||
$event->setReturnValue(TRUE);
|
||||
|
||||
$event->setReturnValue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mod module name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function batchConnect($mod_name = null)
|
||||
{
|
||||
$mods = array();
|
||||
if(null !== $mod_name) {
|
||||
$mods = [];
|
||||
if (null !== $mod_name) {
|
||||
$mods[] = $mod_name;
|
||||
} else {
|
||||
$extensionService = $this->di['mod_service']('extension');
|
||||
$mods = $extensionService->getCoreAndActiveModules();
|
||||
}
|
||||
|
||||
foreach($mods as $m) {
|
||||
foreach ($mods as $m) {
|
||||
$mod = $this->di['mod']($m);
|
||||
if($mod->hasService()) {
|
||||
if ($mod->hasService()) {
|
||||
$class = $mod->getService();
|
||||
$reflector = new \Reflectionclass($class);
|
||||
foreach($reflector->getMethods() as $method) {
|
||||
$reflector = new \ReflectionClass($class);
|
||||
foreach ($reflector->getMethods() as $method) {
|
||||
$p = $method->getParameters();
|
||||
if($method->isPublic()
|
||||
if ($method->isPublic()
|
||||
&& isset($p[0])
|
||||
&& $p[0]->getclass()
|
||||
&& in_array($p[0]->getclass()->getName(), array('Box_Event', '\Box_Event'))) {
|
||||
$this->connect(array('event'=>$method->getName(), 'mod'=>$mod->getName()));
|
||||
&& in_array($p[0]->getclass()->getName(), ['Box_Event', '\Box_Event'])) {
|
||||
$this->connect(['event' => $method->getName(), 'mod' => $mod->getName()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,26 +124,27 @@ class Service implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect event for module
|
||||
* Connect event for module.
|
||||
*
|
||||
* @param string $event - event name, ie: onAfterAdminDeactivateExtension
|
||||
* @param string $mod - module name where hook is located
|
||||
* @param string $mod - module name where hook is located
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @return boolean
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
private function connect($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'event' => 'Hook event not passed',
|
||||
'mod' => 'Param mod not passed',
|
||||
);
|
||||
'mod' => 'Param mod not passed',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$event = $data['event'];
|
||||
$mod = $data['mod'];
|
||||
|
||||
$q="SELECT id
|
||||
$q = "SELECT id
|
||||
FROM extension_meta
|
||||
WHERE extension = 'mod_hook'
|
||||
AND rel_type = 'mod'
|
||||
@@ -149,32 +152,32 @@ class Service implements InjectionAwareInterface
|
||||
AND meta_key = 'listener'
|
||||
AND meta_value = :event
|
||||
";
|
||||
if($this->di['db']->getCell($q, array('mod'=>$mod, 'event'=>$event))) {
|
||||
if ($this->di['db']->getCell($q, ['mod' => $mod, 'event' => $event])) {
|
||||
// already connected
|
||||
return true;
|
||||
}
|
||||
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_hook';
|
||||
$meta->rel_type = 'mod';
|
||||
$meta->rel_id = $mod;
|
||||
$meta->meta_key = 'listener';
|
||||
$meta->meta_value = $event;
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
$meta->extension = 'mod_hook';
|
||||
$meta->rel_type = 'mod';
|
||||
$meta->rel_id = $mod;
|
||||
$meta->meta_key = 'listener';
|
||||
$meta->meta_value = $event;
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($meta);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect unavailable listeners
|
||||
* Disconnect unavailable listeners.
|
||||
*/
|
||||
private function _disconnectUnavailable()
|
||||
{
|
||||
$rm_sql="DELETE FROM extension_meta WHERE id = :id";
|
||||
$rm_sql = 'DELETE FROM extension_meta WHERE id = :id';
|
||||
|
||||
$sql="SELECT id, rel_id, meta_value
|
||||
$sql = "SELECT id, rel_id, meta_value
|
||||
FROM extension_meta
|
||||
WHERE extension = 'mod_hook'
|
||||
AND rel_type = 'mod'
|
||||
@@ -182,37 +185,37 @@ class Service implements InjectionAwareInterface
|
||||
";
|
||||
$list = $this->di['db']->getAll($sql);
|
||||
$extensionService = $this->di['mod_service']('extension');
|
||||
foreach($list as $listener) {
|
||||
foreach ($list as $listener) {
|
||||
try {
|
||||
$mod_name = $listener['rel_id'];
|
||||
$event = $listener['meta_value'];
|
||||
|
||||
// do not disconnect core modules
|
||||
if($extensionService->isCoreModule($mod_name)) {
|
||||
if ($extensionService->isCoreModule($mod_name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// disconect modules without service class
|
||||
$mod = $this->di['mod']($mod_name);
|
||||
if(!$mod->hasService()) {
|
||||
$this->di['db']->exec($rm_sql, array('id'=>$listener['id']));
|
||||
if (!$mod->hasService()) {
|
||||
$this->di['db']->exec($rm_sql, ['id' => $listener['id']]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$ext = $this->di['db']->findOne('extension', "type = 'mod' AND name = :mod AND status = 'installed'", array('mod'=>$mod_name));
|
||||
if(!$ext) {
|
||||
$this->di['db']->exec($rm_sql, array('id'=>$listener['id']));
|
||||
$ext = $this->di['db']->findOne('extension', "type = 'mod' AND name = :mod AND status = 'installed'", ['mod' => $mod_name]);
|
||||
if (!$ext) {
|
||||
$this->di['db']->exec($rm_sql, ['id' => $listener['id']]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$s = $mod->getService();
|
||||
if(!method_exists($s, $event)) {
|
||||
$this->di['db']->exec($rm_sql, array('id'=>$listener['id']));
|
||||
if (!method_exists($s, $event)) {
|
||||
$this->di['db']->exec($rm_sql, ['id' => $listener['id']]);
|
||||
continue;
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Index\Controller;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -37,18 +36,18 @@ class Admin implements InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('', 'get_index', array(), get_class($this));
|
||||
$app->get('/', 'get_index', array(), get_class($this));
|
||||
$app->get('/index', 'get_index', array(), get_class($this));
|
||||
$app->get('/index/', 'get_index', array(), get_class($this));
|
||||
$app->get('', 'get_index', [], get_class($this));
|
||||
$app->get('/', 'get_index', [], get_class($this));
|
||||
$app->get('/index', 'get_index', [], get_class($this));
|
||||
$app->get('/index/', 'get_index', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
if($this->di['auth']->isAdminLoggedIn()) {
|
||||
if ($this->di['auth']->isAdminLoggedIn()) {
|
||||
return $app->render('mod_index_dashboard');
|
||||
} else {
|
||||
return $app->redirect('/staff/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*Invoice management
|
||||
*Invoice management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Invoice\Api;
|
||||
@@ -19,19 +19,19 @@ namespace Box\Mod\Invoice\Api;
|
||||
class Client extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of invoices
|
||||
*
|
||||
* Get paginated list of invoices.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$data['client_id'] = $this->getIdentity()->id;
|
||||
$data['approved'] = true;
|
||||
list ($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
$data['approved'] = true;
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getAdvancedResultSet($sql, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$invoice = $this->di['db']->getExistingModelById('Invoice', $item['id'], 'Invoice not found');
|
||||
$invoice = $this->di['db']->getExistingModelById('Invoice', $item['id'], 'Invoice not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($invoice);
|
||||
}
|
||||
|
||||
@@ -39,85 +39,93 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get invoice details
|
||||
*
|
||||
* Get invoice details.
|
||||
*
|
||||
* @param string $hash - invoice hash
|
||||
*
|
||||
* @return type
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'hash' => 'Invoice hash not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('Invoice', 'hash = :hash', array('hash'=>$data['hash']));
|
||||
if(!$model) {
|
||||
$model = $this->di['db']->findOne('Invoice', 'hash = :hash', ['hash' => $data['hash']]);
|
||||
if (!$model) {
|
||||
throw new \Box_Exception('Invoice was not found');
|
||||
}
|
||||
|
||||
return $this->getService()->toApiArray($model, true, $this->getIdentity());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update Invoice details. Only unpaid invoice details can be updated.
|
||||
*
|
||||
*
|
||||
* @param string $hash - invoice hash
|
||||
*
|
||||
*
|
||||
* @optional int $gateway_id - selected payment gateway id
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'hash' => 'Invoice hash not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$invoice = $this->di['db']->findOne('Invoice', 'hash = :hash', array('hash'=>$data['hash']));
|
||||
if(!$invoice) {
|
||||
$invoice = $this->di['db']->findOne('Invoice', 'hash = :hash', ['hash' => $data['hash']]);
|
||||
if (!$invoice) {
|
||||
throw new \Box_Exception('Invoice was not found');
|
||||
}
|
||||
if($invoice->status == 'paid') {
|
||||
if ('paid' == $invoice->status) {
|
||||
throw new \Box_Exception('Paid Invoice can not be modified');
|
||||
}
|
||||
|
||||
$updateParams = array();
|
||||
$updateParams = [];
|
||||
$updateParams['gateway_id'] = $this->di['array_get']($data, 'gateway_id', null);
|
||||
|
||||
return $this->getService()->updateInvoice($invoice, $updateParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new invoice for selected order. If unpaid invoice for selected order
|
||||
* already exists, new invoice will not be generated, and old invoice hash
|
||||
* is returned
|
||||
*
|
||||
* is returned.
|
||||
*
|
||||
* @param int $order_id - ID of order to generate new invoice for
|
||||
*
|
||||
* @return string - invoice hash
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function renewal_invoice($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'order_id' => 'Order id required',
|
||||
);
|
||||
];
|
||||
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('ClientOrder', 'client_id = ? and id = ?', array($this->getIdentity()->id, $data['order_id']));
|
||||
if(!$model instanceof \Model_ClientOrder) {
|
||||
$model = $this->di['db']->findOne('ClientOrder', 'client_id = ? and id = ?', [$this->getIdentity()->id, $data['order_id']]);
|
||||
if (!$model instanceof \Model_ClientOrder) {
|
||||
throw new \Box_Exception('Order not found');
|
||||
}
|
||||
if($model->price <= 0) {
|
||||
throw new \Box_Exception('Order :id is free. No need to generate invoice.', array(':id'=>$model->id));
|
||||
if ($model->price <= 0) {
|
||||
throw new \Box_Exception('Order :id is free. No need to generate invoice.', [':id' => $model->id]);
|
||||
}
|
||||
$service = $this->getService();
|
||||
$invoice = $service->generateForOrder($model);
|
||||
$service->approveInvoice($invoice, array('id'=>$invoice->id, 'use_credits'=>true));
|
||||
$service->approveInvoice($invoice, ['id' => $invoice->id, 'use_credits' => true]);
|
||||
$this->di['logger']->info('Generated new renewal invoice #%s', $invoice->id);
|
||||
|
||||
return $invoice->hash;
|
||||
}
|
||||
|
||||
@@ -125,14 +133,15 @@ class Client extends \Api_Abstract
|
||||
* Deposit money in advance. Generates new invoice for depositing money.
|
||||
* Clients currency must be defined.
|
||||
*
|
||||
* @param float $amount - amount to be deposited.
|
||||
* @param float $amount - amount to be deposited
|
||||
*
|
||||
* @return string - invoice hash
|
||||
*/
|
||||
public function funds_invoice($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'amount' => 'Amount is required',
|
||||
);
|
||||
];
|
||||
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
@@ -142,27 +151,30 @@ class Client extends \Api_Abstract
|
||||
|
||||
$service = $this->getService();
|
||||
$invoice = $service->generateFundsInvoice($this->getIdentity(), $data['amount']);
|
||||
$service->approveInvoice($invoice, array('id'=>$invoice->id));
|
||||
$service->approveInvoice($invoice, ['id' => $invoice->id]);
|
||||
$this->di['logger']->info('Generated add funds invoice #%s', $invoice->id);
|
||||
|
||||
return $invoice->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client removes unpaid invoice.
|
||||
*
|
||||
*
|
||||
* @param string $hash - invoice hash
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'hash' => 'Invoice hash not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('Invoice', 'hash = :hash', array('hash'=>$data['hash']));
|
||||
if(!$model) {
|
||||
$model = $this->di['db']->findOne('Invoice', 'hash = :hash', ['hash' => $data['hash']]);
|
||||
if (!$model) {
|
||||
throw new \Box_Exception('Invoice was not found');
|
||||
}
|
||||
|
||||
@@ -171,26 +183,27 @@ class Client extends \Api_Abstract
|
||||
|
||||
/**
|
||||
* Get paginated list of transactions.
|
||||
*
|
||||
*
|
||||
* @optional string $invoice_hash - filter transactions by invoice hash
|
||||
* @optional int $gateway_id - filter transactions by payment gateway id
|
||||
* @optional string $status - filter transactions by status
|
||||
* @optional string $currency - filter transactions by currency code
|
||||
* @optional string $date_from - filter transactions by date
|
||||
* @optional string $date_to - filter transactions by date
|
||||
* @return type
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function transaction_get_list($data)
|
||||
{
|
||||
$data['client_id'] = $this->getIdentity()->id;
|
||||
$data['status'] = 'processed';
|
||||
$data['client_id'] = $this->getIdentity()->id;
|
||||
$data['status'] = 'processed';
|
||||
$transactionService = $this->di['mod_service']('Invoice', 'Transaction');
|
||||
list ($sql, $params) = $transactionService->getSearchQuery($data);
|
||||
[$sql, $params] = $transactionService->getSearchQuery($data);
|
||||
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$transaction = $this->di['db']->getExistingModelById('Transaction', $item['id'], 'Transaction not found');
|
||||
$transaction = $this->di['db']->getExistingModelById('Transaction', $item['id'], 'Transaction not found');
|
||||
$pager['list'][$key] = $transactionService->toApiArray($transaction);
|
||||
}
|
||||
|
||||
@@ -200,6 +213,7 @@ class Client extends \Api_Abstract
|
||||
public function get_tax_rate()
|
||||
{
|
||||
$service = $this->di['mod_service']('Invoice', 'Tax');
|
||||
|
||||
return $service->getTaxRateForClient($this->identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Invoice processing
|
||||
* Invoice processing.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Invoice\Api;
|
||||
@@ -19,20 +19,22 @@ namespace Box\Mod\Invoice\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get invoice details
|
||||
* Get invoice details.
|
||||
*
|
||||
* @param string $hash - invoice hash
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'hash' => 'Invoice hash not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('Invoice', 'hash = :hash', array('hash' => $data['hash']));
|
||||
$model = $this->di['db']->findOne('Invoice', 'hash = :hash', ['hash' => $data['hash']]);
|
||||
if (!$model) {
|
||||
throw new \Box_Exception('Invoice was not found');
|
||||
}
|
||||
@@ -48,31 +50,32 @@ class Guest extends \Api_Abstract
|
||||
* @optional int $gateway_id - selected payment gateway id
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'hash' => 'Invoice hash not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$invoice = $this->di['db']->findOne('Invoice', 'hash = :hash', array('hash' => $data['hash']));
|
||||
$invoice = $this->di['db']->findOne('Invoice', 'hash = :hash', ['hash' => $data['hash']]);
|
||||
if (!$invoice) {
|
||||
throw new \Box_Exception('Invoice was not found');
|
||||
}
|
||||
if ($invoice->status == 'paid') {
|
||||
if ('paid' == $invoice->status) {
|
||||
throw new \Box_Exception('Paid Invoice can not be modified');
|
||||
}
|
||||
|
||||
$updateParams = array();
|
||||
$updateParams = [];
|
||||
$updateParams['gateway_id'] = $this->di['array_get']($data, 'gateway_id', null);
|
||||
|
||||
return $this->getService()->updateInvoice($invoice, $updateParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of available payment gateways to pay for invoices
|
||||
* Get list of available payment gateways to pay for invoices.
|
||||
*
|
||||
* @optional string $format - if format is "pairs" then id=>name values are returned
|
||||
*
|
||||
@@ -93,12 +96,13 @@ class Guest extends \Api_Abstract
|
||||
* Tries to detect if invoice can be subscribed and if payment gateway supports subscriptions
|
||||
* uses subscription payment.
|
||||
*
|
||||
* @param string $hash - invoice hash
|
||||
* @param int $gateway_id - payment gateway id
|
||||
* @param string $hash - invoice hash
|
||||
* @param int $gateway_id - payment gateway id
|
||||
*
|
||||
* @optional bool $auto_redirect - should payment adapter automatically redirect client or just print pay now button
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws LogicException
|
||||
*/
|
||||
@@ -115,23 +119,20 @@ class Guest extends \Api_Abstract
|
||||
return $this->getService()->processInvoice($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates PDF for given invoice
|
||||
* Generates PDF for given invoice.
|
||||
*
|
||||
* @param string $hash - invoice hash
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function pdf($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'hash' => 'Invoice hash is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
return $this->getService()->generatePDF($data['hash'], $this->getIdentity());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Invoice\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,158 +34,167 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'group' => array(
|
||||
'index' => 400,
|
||||
return [
|
||||
'group' => [
|
||||
'index' => 400,
|
||||
'location' => 'invoice',
|
||||
'label' => 'Invoices',
|
||||
'uri' => 'invoice',
|
||||
'class' => 'invoices',
|
||||
'label' => 'Invoices',
|
||||
'uri' => 'invoice',
|
||||
'class' => 'invoices',
|
||||
'sprite_class' => 'dark-sprite-icon sprite-money',
|
||||
),
|
||||
'subpages' => array(
|
||||
array(
|
||||
],
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'invoice',
|
||||
'label' => 'Overview',
|
||||
'uri' => $this->di['url']->adminLink('invoice'),
|
||||
'index' => 100,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'index' => 100,
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'invoice',
|
||||
'label' => 'Advanced search',
|
||||
'uri' => $this->di['url']->adminLink('invoice', array('show_filter' => 1)),
|
||||
'index' => 200,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'uri' => $this->di['url']->adminLink('invoice', ['show_filter' => 1]),
|
||||
'index' => 200,
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'invoice',
|
||||
'label' => 'Subscriptions',
|
||||
'uri' => $this->di['url']->adminLink('invoice/subscriptions'),
|
||||
'index' => 300,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'index' => 300,
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'invoice',
|
||||
'label' => 'Transactions overview',
|
||||
'uri' => $this->di['url']->adminLink('invoice/transactions'),
|
||||
'index' => 400,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'index' => 400,
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'invoice',
|
||||
'label' => 'Transactions search',
|
||||
'uri' => $this->di['url']->adminLink('invoice/transactions', array('show_filter' => 1)),
|
||||
'index' => 500,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'uri' => $this->di['url']->adminLink('invoice/transactions', ['show_filter' => 1]),
|
||||
'index' => 500,
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'system',
|
||||
'label' => 'Tax rules',
|
||||
'uri' => $this->di['url']->adminLink('invoice/tax'),
|
||||
'index' => 180,
|
||||
'class' => '',
|
||||
),
|
||||
array(
|
||||
'index' => 180,
|
||||
'class' => '',
|
||||
],
|
||||
[
|
||||
'location' => 'system',
|
||||
'label' => 'Payment gateways',
|
||||
'uri' => $this->di['url']->adminLink('invoice/gateways'),
|
||||
'index' => 160,
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
'index' => 160,
|
||||
'class' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/invoice', 'get_index', array(), get_class($this));
|
||||
$app->get('/invoice/subscriptions', 'get_subscriptions', array(), get_class($this));
|
||||
$app->get('/invoice/transactions', 'get_transactions', array(), get_class($this));
|
||||
$app->get('/invoice/gateways', 'get_gateways', array(), get_class($this));
|
||||
$app->get('/invoice/gateway/:id', 'get_gateway', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/invoice/manage/:id','get_invoice', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/invoice/transaction/:id','get_transaction', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/invoice/subscription/:id','get_subscription', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/invoice/tax', 'get_taxes', array(), get_class($this));
|
||||
$app->get('/invoice/tax/:id', 'get_tax', array(), get_class($this));
|
||||
$app->get('/invoice/pdf/:hash', 'get_pdf', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->get('/invoice', 'get_index', [], get_class($this));
|
||||
$app->get('/invoice/subscriptions', 'get_subscriptions', [], get_class($this));
|
||||
$app->get('/invoice/transactions', 'get_transactions', [], get_class($this));
|
||||
$app->get('/invoice/gateways', 'get_gateways', [], get_class($this));
|
||||
$app->get('/invoice/gateway/:id', 'get_gateway', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/invoice/manage/:id', 'get_invoice', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/invoice/transaction/:id', 'get_transaction', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/invoice/subscription/:id', 'get_subscription', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/invoice/tax', 'get_taxes', [], get_class($this));
|
||||
$app->get('/invoice/tax/:id', 'get_tax', [], get_class($this));
|
||||
$app->get('/invoice/pdf/:hash', 'get_pdf', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_taxes(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_invoice_tax');
|
||||
}
|
||||
|
||||
public function get_tax(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$tax = $api->invoice_tax_get(array('id' => $id));
|
||||
$tax = $api->invoice_tax_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_invoice_taxupdate', array('tax' => $tax));
|
||||
return $app->render('mod_invoice_taxupdate', ['tax' => $tax]);
|
||||
}
|
||||
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_invoice_index');
|
||||
}
|
||||
|
||||
|
||||
public function get_invoice(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$invoice = $api->invoice_get(array('id'=>$id));
|
||||
return $app->render('mod_invoice_invoice', array('invoice'=>$invoice));
|
||||
$invoice = $api->invoice_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_invoice_invoice', ['invoice' => $invoice]);
|
||||
}
|
||||
|
||||
public function get_transaction(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$tx = $api->invoice_transaction_get(array('id'=>$id));
|
||||
return $app->render('mod_invoice_transaction', array('transaction'=>$tx));
|
||||
$tx = $api->invoice_transaction_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_invoice_transaction', ['transaction' => $tx]);
|
||||
}
|
||||
|
||||
public function get_transactions(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_invoice_transactions');
|
||||
}
|
||||
|
||||
|
||||
public function get_subscriptions(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_invoice_subscriptions');
|
||||
}
|
||||
|
||||
public function get_subscription(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$tx = $api->invoice_subscription_get(array('id'=>$id));
|
||||
return $app->render('mod_invoice_subscription', array('subscription'=>$tx));
|
||||
$tx = $api->invoice_subscription_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_invoice_subscription', ['subscription' => $tx]);
|
||||
}
|
||||
|
||||
public function get_gateways(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_invoice_gateways');
|
||||
}
|
||||
|
||||
public function get_gateway(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$gateway = $api->invoice_gateway_get(array('id'=>$id));
|
||||
return $app->render('mod_invoice_gateway', array('gateway'=>$gateway));
|
||||
$gateway = $api->invoice_gateway_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_invoice_gateway', ['gateway' => $gateway]);
|
||||
}
|
||||
|
||||
public function get_pdf (\Box_App $app, $hash)
|
||||
public function get_pdf(\Box_App $app, $hash)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
$data = [
|
||||
'hash' => $hash,
|
||||
);
|
||||
];
|
||||
$invoice = $api->invoice_pdf($data);
|
||||
return $app->render('mod_invoice_pdf', array('invoice'=>$invoice));
|
||||
}
|
||||
|
||||
}
|
||||
return $app->render('mod_invoice_pdf', ['invoice' => $invoice]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Invoice\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,75 +34,81 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/invoice', 'get_invoices', array(), get_class($this));
|
||||
$app->post('/invoice', 'get_invoices', array(), get_class($this));
|
||||
$app->get('/invoice/:hash', 'get_invoice', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->post('/invoice/:hash', 'get_invoice', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->get('/invoice/print/:hash', 'get_invoice_print', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->post('/invoice/print/:hash', 'get_invoice_print', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->get('/invoice/banklink/:hash/:id', 'get_banklink', array('id'=>'[0-9]+', 'hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->get('/invoice/thank-you/:hash', 'get_thankyoupage', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->get('/invoice/pdf/:hash', 'get_pdf', array('hash'=>'[a-z0-9]+'), get_class($this));
|
||||
$app->get('/invoice', 'get_invoices', [], get_class($this));
|
||||
$app->post('/invoice', 'get_invoices', [], get_class($this));
|
||||
$app->get('/invoice/:hash', 'get_invoice', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
$app->post('/invoice/:hash', 'get_invoice', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
$app->get('/invoice/print/:hash', 'get_invoice_print', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
$app->post('/invoice/print/:hash', 'get_invoice_print', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
$app->get('/invoice/banklink/:hash/:id', 'get_banklink', ['id' => '[0-9]+', 'hash' => '[a-z0-9]+'], get_class($this));
|
||||
$app->get('/invoice/thank-you/:hash', 'get_thankyoupage', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
$app->get('/invoice/pdf/:hash', 'get_pdf', ['hash' => '[a-z0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_invoices(\Box_App $app)
|
||||
{
|
||||
$this->di['is_client_logged'];
|
||||
|
||||
return $app->render('mod_invoice_index');
|
||||
}
|
||||
|
||||
public function get_invoice(\Box_App $app, $hash)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
$data = [
|
||||
'hash' => $hash,
|
||||
);
|
||||
];
|
||||
$invoice = $api->invoice_get($data);
|
||||
return $app->render('mod_invoice_invoice', array('invoice'=>$invoice));
|
||||
|
||||
return $app->render('mod_invoice_invoice', ['invoice' => $invoice]);
|
||||
}
|
||||
|
||||
public function get_invoice_print(\Box_App $app, $hash)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
$data = [
|
||||
'hash' => $hash,
|
||||
);
|
||||
];
|
||||
$invoice = $api->invoice_get($data);
|
||||
return $app->render('mod_invoice_print', array('invoice'=>$invoice));
|
||||
|
||||
return $app->render('mod_invoice_print', ['invoice' => $invoice]);
|
||||
}
|
||||
|
||||
public function get_thankyoupage(\Box_App $app, $hash)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
$data = [
|
||||
'hash' => $hash,
|
||||
);
|
||||
];
|
||||
$invoice = $api->invoice_get($data);
|
||||
return $app->render('mod_invoice_thankyou', array('invoice'=>$invoice));
|
||||
|
||||
return $app->render('mod_invoice_thankyou', ['invoice' => $invoice]);
|
||||
}
|
||||
|
||||
|
||||
public function get_banklink(\Box_App $app, $hash, $id)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
'subscription' => $this->di['request']->getQuery('subscription'),
|
||||
'hash' => $hash,
|
||||
'gateway_id' => $id,
|
||||
'auto_redirect' => true,
|
||||
);
|
||||
$data = [
|
||||
'subscription' => $this->di['request']->getQuery('subscription'),
|
||||
'hash' => $hash,
|
||||
'gateway_id' => $id,
|
||||
'auto_redirect' => true,
|
||||
];
|
||||
|
||||
$invoice = $api->invoice_get($data);
|
||||
$result = $api->invoice_payment($data);
|
||||
return $app->render('mod_invoice_banklink', array('payment'=>$result, 'invoice'=>$invoice));
|
||||
|
||||
return $app->render('mod_invoice_banklink', ['payment' => $result, 'invoice' => $invoice]);
|
||||
}
|
||||
|
||||
public function get_pdf (\Box_App $app, $hash)
|
||||
public function get_pdf(\Box_App $app, $hash)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array(
|
||||
$data = [
|
||||
'hash' => $hash,
|
||||
);
|
||||
];
|
||||
$invoice = $api->invoice_pdf($data);
|
||||
return $app->render('mod_invoice_pdf', array('invoice'=>$invoice));
|
||||
|
||||
return $app->render('mod_invoice_pdf', ['invoice' => $invoice]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+502
-471
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Invoice;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
@@ -36,23 +37,23 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
return $this->di;
|
||||
}
|
||||
|
||||
public function markAsPaid(\Model_InvoiceItem $item, $charge = TRUE)
|
||||
public function markAsPaid(\Model_InvoiceItem $item, $charge = true)
|
||||
{
|
||||
if($charge && !$item->charged) {
|
||||
if ($charge && !$item->charged) {
|
||||
$this->creditInvoiceItem($item);
|
||||
$item->charged = TRUE;
|
||||
$item->updated_at = date('Y-m-d H:i:s');
|
||||
$item->charged = true;
|
||||
$item->updated_at = date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
$item->status = \Model_InvoiceItem::STATUS_PENDING_SETUP;
|
||||
$item->updated_at = date('Y-m-d H:i:s');
|
||||
$item->status = \Model_InvoiceItem::STATUS_PENDING_SETUP;
|
||||
$item->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($item);
|
||||
|
||||
$oid = $this->getOrderId($item);
|
||||
if(NULL !== $oid) {
|
||||
if (null !== $oid) {
|
||||
$orderService = $this->di['mod_service']('Order');
|
||||
$order = $this->di['db']->load('ClientOrder', $oid);
|
||||
if($order instanceof \Model_ClientOrder) {
|
||||
if ($order instanceof \Model_ClientOrder) {
|
||||
$orderService->unsetUnpaidInvoice($order);
|
||||
}
|
||||
}
|
||||
@@ -60,24 +61,24 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
|
||||
public function executeTask(\Model_InvoiceItem $item)
|
||||
{
|
||||
if($item->status == \Model_InvoiceItem::STATUS_EXECUTED) {
|
||||
if (\Model_InvoiceItem::STATUS_EXECUTED == $item->status) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if($item->type == \Model_InvoiceItem::TYPE_ORDER) {
|
||||
if (\Model_InvoiceItem::TYPE_ORDER == $item->type) {
|
||||
$order_id = $this->getOrderId($item);
|
||||
$order = $this->di['db']->load('ClientOrder', $order_id);
|
||||
if(!$order instanceof \Model_ClientOrder) {
|
||||
throw new \Box_Exception('Could not activate proforma item. Order :id not found', array(':id'=>$order_id));
|
||||
if (!$order instanceof \Model_ClientOrder) {
|
||||
throw new \Box_Exception('Could not activate proforma item. Order :id not found', [':id' => $order_id]);
|
||||
}
|
||||
$orderService = $this->di['mod_service']('Order');
|
||||
switch ($item->task) {
|
||||
case \Model_InvoiceItem::TASK_ACTIVATE:
|
||||
$product = $this->di['db']->getExistingModelById('Product', $order->product_id);
|
||||
if($product->setup == \Model_Product::SETUP_AFTER_PAYMENT) {
|
||||
if (\Model_Product::SETUP_AFTER_PAYMENT == $product->setup) {
|
||||
try {
|
||||
$orderService->activateOrder($order);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
$orderService->saveStatusChange($order, 'Order could not be activated due to error: '.$e->getMessage());
|
||||
}
|
||||
@@ -86,14 +87,14 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
|
||||
case \Model_InvoiceItem::TASK_RENEW:
|
||||
try {
|
||||
//Unsuspend order if suspended before renew
|
||||
if($order->status == \Model_ClientOrder::STATUS_SUSPENDED) {
|
||||
$orderService->unsuspendFromOrder($order);
|
||||
}
|
||||
|
||||
// Unsuspend order if suspended before renew
|
||||
if (\Model_ClientOrder::STATUS_SUSPENDED == $order->status) {
|
||||
$orderService->unsuspendFromOrder($order);
|
||||
}
|
||||
|
||||
$order = $this->di['db']->load('ClientOrder', $order_id);
|
||||
$orderService->renewOrder($order);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
$orderService->saveStatusChange($order, 'Order could not renew due to error: '.$e->getMessage());
|
||||
}
|
||||
@@ -107,32 +108,32 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
$this->markAsExecuted($item);
|
||||
}
|
||||
|
||||
if($item->type == \Model_InvoiceItem::TYPE_HOOK_CALL) {
|
||||
if (\Model_InvoiceItem::TYPE_HOOK_CALL == $item->type) {
|
||||
try {
|
||||
$params = json_decode($item->rel_id);
|
||||
$this->di['events_manager']->fire(array('event'=>$item->task, 'params'=>$params));
|
||||
} catch(\Exception $e) {
|
||||
$this->di['events_manager']->fire(['event' => $item->task, 'params' => $params]);
|
||||
} catch (\Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
$this->markAsExecuted($item);
|
||||
}
|
||||
|
||||
if($item->type == \Model_InvoiceItem::TYPE_DEPOSIT) {
|
||||
if (\Model_InvoiceItem::TYPE_DEPOSIT == $item->type) {
|
||||
$clientService = $this->di['mod_service']('Client');
|
||||
|
||||
$invoice = $this->di['db']->getExistingModelById('Invoice', $item->invoice_id);
|
||||
$client = $this->di['db']->getExistingModelById('Client', $invoice->client_id);
|
||||
$data = array(
|
||||
$data = [
|
||||
'type' => 'invoice',
|
||||
'rel_id' => $item->invoice_id,
|
||||
);
|
||||
];
|
||||
$clientService->addFunds($client, $this->getTotal($item), $item->title, $data);
|
||||
|
||||
$this->markAsExecuted($item);
|
||||
}
|
||||
|
||||
if($item->type == \Model_InvoiceItem::TYPE_CUSTOM) {
|
||||
//@todo ?
|
||||
if (\Model_InvoiceItem::TYPE_CUSTOM == $item->type) {
|
||||
// @todo ?
|
||||
$this->markAsExecuted($item);
|
||||
}
|
||||
}
|
||||
@@ -140,12 +141,12 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
public function addNew(\Model_Invoice $proforma, array $data)
|
||||
{
|
||||
$title = $this->di['array_get']($data, 'title', '');
|
||||
if(empty($title)) {
|
||||
if (empty($title)) {
|
||||
throw new \Box_Exception('Invoice item title is missing');
|
||||
}
|
||||
|
||||
$period = $this->di['array_get']($data, 'period', 0);
|
||||
if($period) {
|
||||
if ($period) {
|
||||
$periodCheck = $this->di['period']($period);
|
||||
}
|
||||
|
||||
@@ -155,20 +156,20 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
$status = $this->di['array_get']($data, 'status', \Model_InvoiceItem::STATUS_PENDING_PAYMENT);
|
||||
|
||||
$pi = $this->di['db']->dispense('InvoiceItem');
|
||||
$pi->invoice_id = $proforma->id;
|
||||
$pi->type = $type;
|
||||
$pi->rel_id = $rel_id;
|
||||
$pi->task = $task;
|
||||
$pi->status = $status;
|
||||
$pi->title = $data['title'];
|
||||
$pi->period = $period;
|
||||
$pi->quantity = $this->di['array_get']($data, 'quantity', 1);
|
||||
$pi->unit = $this->di['array_get']($data, 'unit');
|
||||
$pi->charged = $this->di['array_get']($data, 'charged', 0);
|
||||
$pi->price = (double) $this->di['array_get']($data, 'price', 0);
|
||||
$pi->taxed = $this->di['array_get']($data, 'taxed', false);
|
||||
$pi->created_at = date('Y-m-d H:i:s');
|
||||
$pi->updated_at = date('Y-m-d H:i:s');
|
||||
$pi->invoice_id = $proforma->id;
|
||||
$pi->type = $type;
|
||||
$pi->rel_id = $rel_id;
|
||||
$pi->task = $task;
|
||||
$pi->status = $status;
|
||||
$pi->title = $data['title'];
|
||||
$pi->period = $period;
|
||||
$pi->quantity = $this->di['array_get']($data, 'quantity', 1);
|
||||
$pi->unit = $this->di['array_get']($data, 'unit');
|
||||
$pi->charged = $this->di['array_get']($data, 'charged', 0);
|
||||
$pi->price = (float) $this->di['array_get']($data, 'price', 0);
|
||||
$pi->taxed = $this->di['array_get']($data, 'taxed', false);
|
||||
$pi->created_at = date('Y-m-d H:i:s');
|
||||
$pi->updated_at = date('Y-m-d H:i:s');
|
||||
$itemId = $this->di['db']->store($pi);
|
||||
|
||||
return (int) $itemId;
|
||||
@@ -181,12 +182,12 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
|
||||
public function getTax(\Model_InvoiceItem $item)
|
||||
{
|
||||
if(!$item->taxed) {
|
||||
if (!$item->taxed) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$rate = $this->di['db']->getCell('SELECT taxrate FROM invoice WHERE id = :id', array('id'=>$item->invoice_id));
|
||||
if($rate <= 0) {
|
||||
$rate = $this->di['db']->getCell('SELECT taxrate FROM invoice WHERE id = :id', ['id' => $item->invoice_id]);
|
||||
if ($rate <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -197,15 +198,15 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
{
|
||||
$item->title = $this->di['array_get']($data, 'title', $item->title);
|
||||
$item->price = $this->di['array_get']($data, 'price', $item->price);
|
||||
|
||||
$item_quantity = $this->di['array_get']($data, 'quantity', 1);
|
||||
|
||||
if($item_quantity != $item->quantity){
|
||||
$item->quantity = $item_quantity > 0 ? $item_quantity : 1 ;
|
||||
}
|
||||
|
||||
if(isset($data['taxed']) && !empty($data['taxed'])) {
|
||||
$item->taxed = (bool)$data['taxed'];
|
||||
|
||||
$item_quantity = $this->di['array_get']($data, 'quantity', 1);
|
||||
|
||||
if ($item_quantity != $item->quantity) {
|
||||
$item->quantity = $item_quantity > 0 ? $item_quantity : 1;
|
||||
}
|
||||
|
||||
if (isset($data['taxed']) && !empty($data['taxed'])) {
|
||||
$item->taxed = (bool) $data['taxed'];
|
||||
} else {
|
||||
$item->taxed = false;
|
||||
}
|
||||
@@ -214,40 +215,40 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
$this->di['db']->store($item);
|
||||
}
|
||||
|
||||
|
||||
public function remove(\Model_InvoiceItem $model)
|
||||
{
|
||||
$id = $model->id;
|
||||
$this->di['db']->trash($model);
|
||||
$this->di['logger']->info('Removed invoice item "%s"', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function generateForAddFunds(\Model_Invoice $proforma, $amount)
|
||||
{
|
||||
$pi = $this->di['db']->dispense('InvoiceItem');
|
||||
$pi->invoice_id = $proforma->id;
|
||||
$pi->type = \Model_InvoiceItem::TYPE_DEPOSIT;
|
||||
$pi->rel_id = NULL;
|
||||
$pi->task = \Model_InvoiceItem::TASK_VOID;
|
||||
$pi->status = \Model_InvoiceItem::STATUS_PENDING_PAYMENT;
|
||||
$pi->title = __('Add funds to account');
|
||||
$pi->period = NULL;
|
||||
$pi->quantity = 1;
|
||||
$pi->unit = NULL;
|
||||
$pi->charged = 1;
|
||||
$pi->price = $amount;
|
||||
$pi->taxed = FALSE;
|
||||
$pi->created_at = date('Y-m-d H:i:s');
|
||||
$pi->updated_at = date('Y-m-d H:i:s');
|
||||
$pi->invoice_id = $proforma->id;
|
||||
$pi->type = \Model_InvoiceItem::TYPE_DEPOSIT;
|
||||
$pi->rel_id = null;
|
||||
$pi->task = \Model_InvoiceItem::TASK_VOID;
|
||||
$pi->status = \Model_InvoiceItem::STATUS_PENDING_PAYMENT;
|
||||
$pi->title = __('Add funds to account');
|
||||
$pi->period = null;
|
||||
$pi->quantity = 1;
|
||||
$pi->unit = null;
|
||||
$pi->charged = 1;
|
||||
$pi->price = $amount;
|
||||
$pi->taxed = false;
|
||||
$pi->created_at = date('Y-m-d H:i:s');
|
||||
$pi->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($pi);
|
||||
}
|
||||
|
||||
public function creditInvoiceItem(\Model_InvoiceItem $item)
|
||||
{
|
||||
$total = $this->getTotalWithTax($item);
|
||||
if($total <= 0) {
|
||||
return TRUE;
|
||||
if ($total <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$invoice = $this->di['db']->getExistingModelById('Invoice', $item->invoice_id, 'Invoice not found');
|
||||
@@ -274,16 +275,17 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
|
||||
public function getOrderId(\Model_InvoiceItem $item)
|
||||
{
|
||||
if($item->type == \Model_InvoiceItem::TYPE_ORDER) {
|
||||
if (\Model_InvoiceItem::TYPE_ORDER == $item->type) {
|
||||
return (int) $item->rel_id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function markAsExecuted(\Model_InvoiceItem $item)
|
||||
{
|
||||
$item->status = \Model_InvoiceItem::STATUS_EXECUTED;
|
||||
$item->updated_at = date('Y-m-d H:i:s');
|
||||
$item->status = \Model_InvoiceItem::STATUS_EXECUTED;
|
||||
$item->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($item);
|
||||
}
|
||||
|
||||
@@ -296,61 +298,62 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
$taxed = $clientService->isClientTaxable($client);
|
||||
|
||||
$pi = $this->di['db']->dispense('InvoiceItem');
|
||||
$pi->invoice_id = $proforma->id;
|
||||
$pi->type = \Model_InvoiceItem::TYPE_ORDER;
|
||||
$pi->rel_id = $order->id;
|
||||
$pi->task = $task;
|
||||
$pi->status = \Model_InvoiceItem::STATUS_PENDING_PAYMENT;
|
||||
$pi->title = $order->title;
|
||||
$pi->period = $order->period;
|
||||
$pi->quantity = $order->quantity;
|
||||
$pi->unit = $order->unit;
|
||||
$pi->price = $price;
|
||||
$pi->taxed = $taxed;
|
||||
$pi->created_at = date('Y-m-d H:i:s');
|
||||
$pi->updated_at = date('Y-m-d H:i:s');
|
||||
$pi->invoice_id = $proforma->id;
|
||||
$pi->type = \Model_InvoiceItem::TYPE_ORDER;
|
||||
$pi->rel_id = $order->id;
|
||||
$pi->task = $task;
|
||||
$pi->status = \Model_InvoiceItem::STATUS_PENDING_PAYMENT;
|
||||
$pi->title = $order->title;
|
||||
$pi->period = $order->period;
|
||||
$pi->quantity = $order->quantity;
|
||||
$pi->unit = $order->unit;
|
||||
$pi->price = $price;
|
||||
$pi->taxed = $taxed;
|
||||
$pi->created_at = date('Y-m-d H:i:s');
|
||||
$pi->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($pi);
|
||||
|
||||
$corderService->setUnpaidInvoice($order, $proforma);
|
||||
|
||||
|
||||
// apply discount for new invoice if promo code is recurrent
|
||||
if($order->promo_recurring) {
|
||||
if ($order->promo_recurring) {
|
||||
$order_total = $order->price * $order->quantity;
|
||||
$promo_discount = $order->discount;
|
||||
if($promo_discount > $order_total) {
|
||||
if ($promo_discount > $order_total) {
|
||||
$promo_discount = $order_total;
|
||||
}
|
||||
|
||||
$discount_title = $this->_getTitleForPromoDiscount($order->promo_id, $order->currency);
|
||||
|
||||
$pd = [
|
||||
'title' => $discount_title,
|
||||
'price' => $promo_discount * -1,
|
||||
'title' => $discount_title,
|
||||
'price' => $promo_discount * -1,
|
||||
'quantity' => 1,
|
||||
'unit' => 'discount',
|
||||
'rel_id' => $order->id,
|
||||
'taxed' => $taxed,
|
||||
'unit' => 'discount',
|
||||
'rel_id' => $order->id,
|
||||
'taxed' => $taxed,
|
||||
];
|
||||
|
||||
$this->addNew($proforma, $pd);
|
||||
$order->promo_used +=1;
|
||||
++$order->promo_used;
|
||||
$this->di['db']->store($order);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _getTitleForPromoDiscount($promo_id, $currency)
|
||||
{
|
||||
{
|
||||
$promo = $this->di['db']->findOne('Promo', 'id = ?', [$promo_id]);
|
||||
|
||||
$api_guest = $this->di['api_guest'];
|
||||
|
||||
|
||||
switch ($promo->type) {
|
||||
case \Model_Promo::ABSOLUTE:
|
||||
$currencyAmount = $api_guest->currency_format(['code' => $currency, 'price' => $promo->value]);
|
||||
return __('Promotional Code: :code - :value Discount', [':code' => $promo->code, ':value' => $currencyAmount]);
|
||||
|
||||
return __('Promotional Code: :code - :value Discount', [':code' => $promo->code, ':value' => $currencyAmount]);
|
||||
|
||||
case \Model_Promo::PERCENTAGE:
|
||||
return __('Promotional Code: :code - :value%', [':code' => $promo->code, ':value' => $promo->value]);
|
||||
return __('Promotional Code: :code - :value%', [':code' => $promo->code, ':value' => $promo->value]);
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -358,20 +361,21 @@ class ServiceInvoiceItem implements InjectionAwareInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of paid invoice not executed invoice items
|
||||
* Get list of paid invoice not executed invoice items.
|
||||
*
|
||||
* @return array - array of Model_InvoiceItem items
|
||||
*/
|
||||
public function getAllNotExecutePaidItems()
|
||||
{
|
||||
$sql = 'SELECT invoice_item.*
|
||||
$sql = 'SELECT invoice_item.*
|
||||
FROM invoice_item
|
||||
left join invoice on invoice_item.invoice_id = invoice.id
|
||||
WHERE invoice_item.status != :item_status and invoice.status = :invoice_status';
|
||||
$bindings = array(
|
||||
':item_status' => \Model_InvoiceItem::STATUS_EXECUTED,
|
||||
$bindings = [
|
||||
':item_status' => \Model_InvoiceItem::STATUS_EXECUTED,
|
||||
':invoice_status' => \Model_Invoice::STATUS_PAID,
|
||||
);
|
||||
];
|
||||
|
||||
return $this->di['db']->getAll($sql, $bindings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Invoice;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class ServicePayGateway implements InjectionAwareInterface
|
||||
@@ -36,23 +37,22 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
return $this->di;
|
||||
}
|
||||
|
||||
|
||||
public function getSearchQuery(array $data)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM pay_gateway
|
||||
WHERE 1 ';
|
||||
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$params = array();
|
||||
if($search) {
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$params = [];
|
||||
if ($search) {
|
||||
$sql .= 'AND m.name LIKE :search';
|
||||
$params['search'] = "%$search%";
|
||||
}
|
||||
|
||||
$sql .= ' ORDER by gateway ASC';
|
||||
|
||||
return array($sql, $params);
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function getPairs()
|
||||
@@ -61,10 +61,11 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
FROM pay_gateway';
|
||||
|
||||
$rows = $this->di['db']->getAll($sql);
|
||||
$result = array();
|
||||
foreach ($rows as $row){
|
||||
$result[ $row['id'] ] = $row['name'];
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$result[$row['id']] = $row['name'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -74,16 +75,16 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
FROM pay_gateway';
|
||||
|
||||
$rows = $this->di['db']->getAll($sql);
|
||||
$exists = array();
|
||||
foreach ($rows as $row){
|
||||
$exists[ $row['gateway'] ] = $row['name'];
|
||||
$exists = [];
|
||||
foreach ($rows as $row) {
|
||||
$exists[$row['gateway']] = $row['name'];
|
||||
}
|
||||
|
||||
$pattern = BB_PATH_LIBRARY.'/Payment/Adapter/*.php';
|
||||
$adapters = array();
|
||||
foreach(glob($pattern) as $path) {
|
||||
$adapters = [];
|
||||
foreach (glob($pattern) as $path) {
|
||||
$adapter = pathinfo($path, PATHINFO_FILENAME);
|
||||
if(!array_key_exists($adapter, $exists)) {
|
||||
if (!array_key_exists($adapter, $exists)) {
|
||||
$adapters[] = $adapter;
|
||||
}
|
||||
}
|
||||
@@ -94,7 +95,7 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
public function install($code)
|
||||
{
|
||||
$available = $this->getAvailable();
|
||||
if(!in_array($code, $available)) {
|
||||
if (!in_array($code, $available)) {
|
||||
throw new \Box_Exception('Payment gateway is not available for installation.');
|
||||
}
|
||||
|
||||
@@ -102,37 +103,38 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
$new->name = $code;
|
||||
$new->gateway = $code;
|
||||
$new->enabled = 0;
|
||||
$new->accepted_currencies = NULL;
|
||||
$new->accepted_currencies = null;
|
||||
$new->test_mode = 0;
|
||||
$new->config = NULL;
|
||||
$new->config = null;
|
||||
$this->di['db']->store($new);
|
||||
|
||||
$this->di['logger']->info('Installed new payment gateway %s', $code);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function toApiArray(\Model_PayGateway $model, $deep = false, $identity = null)
|
||||
{
|
||||
list($single, $recurrent) = $this->_getAllowTuple($model);
|
||||
[$single, $recurrent] = $this->_getAllowTuple($model);
|
||||
|
||||
$result = array(
|
||||
'id' => $model->id,
|
||||
'code' => $model->gateway,
|
||||
'title' => $model->name,
|
||||
'allow_single' => $model->allow_single,
|
||||
'allow_recurrent' => $model->allow_recurrent,
|
||||
'accepted_currencies' => $this->getAcceptedCurrencies($model),
|
||||
);
|
||||
$result = [
|
||||
'id' => $model->id,
|
||||
'code' => $model->gateway,
|
||||
'title' => $model->name,
|
||||
'allow_single' => $model->allow_single,
|
||||
'allow_recurrent' => $model->allow_recurrent,
|
||||
'accepted_currencies' => $this->getAcceptedCurrencies($model),
|
||||
];
|
||||
|
||||
if($identity instanceof \Model_Admin) {
|
||||
$result['supports_one_time_payments'] = $single;
|
||||
$result['supports_subscriptions'] = $recurrent;
|
||||
$result['config'] = json_decode($model->config, 1);
|
||||
$result['form'] = $this->getFormElements($model);
|
||||
$result['description'] = $this->getDescription($model);
|
||||
$result['enabled'] = $model->enabled;
|
||||
$result['test_mode'] = $model->test_mode;
|
||||
$result['callback'] = $this->getCallbackUrl($model);
|
||||
if ($identity instanceof \Model_Admin) {
|
||||
$result['supports_one_time_payments'] = $single;
|
||||
$result['supports_subscriptions'] = $recurrent;
|
||||
$result['config'] = json_decode($model->config, 1);
|
||||
$result['form'] = $this->getFormElements($model);
|
||||
$result['description'] = $this->getDescription($model);
|
||||
$result['enabled'] = $model->enabled;
|
||||
$result['test_mode'] = $model->test_mode;
|
||||
$result['callback'] = $this->getCallbackUrl($model);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -141,7 +143,7 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
public function copy(\Model_PayGateway $model)
|
||||
{
|
||||
$new = $this->di['db']->dispense('PayGateway');
|
||||
$new->name = $model->name . ' (Copy)';
|
||||
$new->name = $model->name.' (Copy)';
|
||||
$new->gateway = $model->gateway;
|
||||
$new->enabled = 0;
|
||||
$new->accepted_currencies = $model->accepted_currencies;
|
||||
@@ -149,26 +151,28 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
$new->config = $model->config;
|
||||
$newId = $this->di['db']->store($new);
|
||||
$this->di['logger']->info('Copied payment gateway #%s - %s', $newId, $model->gateway);
|
||||
|
||||
return $newId;
|
||||
}
|
||||
|
||||
public function update(\Model_PayGateway $model, array $data)
|
||||
{
|
||||
$model->name = $this->di['array_get']($data, 'title', $model->name);
|
||||
if(isset($data['config']) && is_array($data['config'])) {
|
||||
if (isset($data['config']) && is_array($data['config'])) {
|
||||
$model->config = json_encode($data['config']);
|
||||
}
|
||||
|
||||
if(isset($data['accepted_currencies']) && is_array($data['accepted_currencies'])) {
|
||||
if (isset($data['accepted_currencies']) && is_array($data['accepted_currencies'])) {
|
||||
$model->accepted_currencies = json_encode($data['accepted_currencies']);
|
||||
}
|
||||
|
||||
$model->enabled = $this->di['array_get']($data, 'enabled', $model->enabled);
|
||||
$model->allow_single = (bool)$this->di['array_get']($data, 'allow_single', $model->allow_single);
|
||||
$model->allow_recurrent = (bool)$this->di['array_get']($data, 'allow_recurrent', $model->allow_recurrent);
|
||||
$model->test_mode = $this->di['array_get']($data, 'test_mode', $model->test_mode);
|
||||
$model->enabled = $this->di['array_get']($data, 'enabled', $model->enabled);
|
||||
$model->allow_single = (bool) $this->di['array_get']($data, 'allow_single', $model->allow_single);
|
||||
$model->allow_recurrent = (bool) $this->di['array_get']($data, 'allow_recurrent', $model->allow_recurrent);
|
||||
$model->test_mode = $this->di['array_get']($data, 'test_mode', $model->test_mode);
|
||||
$this->di['db']->store($model);
|
||||
$this->di['logger']->info('Updated payment gateway %s', $model->gateway);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -186,40 +190,41 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
$format = $this->di['array_get']($data, 'format', null);
|
||||
|
||||
$gateways = $this->di['db']->find('PayGateway', 'enabled = 1 ORDER BY id desc');
|
||||
$result = array();
|
||||
foreach($gateways as $gtw) {
|
||||
if($format == 'pairs') {
|
||||
$result = [];
|
||||
foreach ($gateways as $gtw) {
|
||||
if ('pairs' == $format) {
|
||||
$result[$gtw->id] = $gtw->name;
|
||||
} else {
|
||||
$result[] = $this->toApiArray($gtw);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function canPerformRecurrentPayment(\Model_PayGateway $model)
|
||||
{
|
||||
return (bool)$model->allow_recurrent;
|
||||
return (bool) $model->allow_recurrent;
|
||||
}
|
||||
|
||||
public function getPaymentAdapter(\Model_PayGateway $pg, \Model_Invoice $model = null, $optional = array())
|
||||
public function getPaymentAdapter(\Model_PayGateway $pg, \Model_Invoice $model = null, $optional = [])
|
||||
{
|
||||
$config = $this->di['tools']->decodeJ($pg->config);
|
||||
$defaults = array();
|
||||
$defaults['auto_redirect'] = false;
|
||||
$defaults['test_mode'] = $pg->test_mode;
|
||||
$defaults['return_url'] = $this->getReturnUrl($pg, $model);
|
||||
$defaults['cancel_url'] = $this->getCancelUrl($pg, $model);
|
||||
$defaults['notify_url'] = $this->getCallbackUrl($pg, $model);
|
||||
$defaults['redirect_url'] = $this->getCallbackRedirect($pg, $model);
|
||||
$defaults = [];
|
||||
$defaults['auto_redirect'] = false;
|
||||
$defaults['test_mode'] = $pg->test_mode;
|
||||
$defaults['return_url'] = $this->getReturnUrl($pg, $model);
|
||||
$defaults['cancel_url'] = $this->getCancelUrl($pg, $model);
|
||||
$defaults['notify_url'] = $this->getCallbackUrl($pg, $model);
|
||||
$defaults['redirect_url'] = $this->getCallbackRedirect($pg, $model);
|
||||
$defaults['continue_shopping_url'] = $this->di['tools']->url('/order');
|
||||
$defaults['single_page'] = true;
|
||||
if($model instanceof \Model_Invoice) {
|
||||
$defaults['thankyou_url'] = $this->di['tools']->url('/invoice/thank-you/'.$model->hash);
|
||||
$defaults['invoice_url'] = $this->di['tools']->url('/invoice/'.$model->hash);
|
||||
if ($model instanceof \Model_Invoice) {
|
||||
$defaults['thankyou_url'] = $this->di['tools']->url('/invoice/thank-you/'.$model->hash);
|
||||
$defaults['invoice_url'] = $this->di['tools']->url('/invoice/'.$model->hash);
|
||||
}
|
||||
|
||||
if(isset($optional['auto_redirect'])) {
|
||||
if (isset($optional['auto_redirect'])) {
|
||||
$defaults['auto_redirect'] = $optional['auto_redirect'];
|
||||
}
|
||||
|
||||
@@ -227,13 +232,13 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
|
||||
$class = $this->getAdapterClassName($pg);
|
||||
|
||||
if(!class_exists($class)) {
|
||||
throw new \Box_Exception("Payment gateway :adapter was not found", array(':adapter'=>$class));
|
||||
if (!class_exists($class)) {
|
||||
throw new \Box_Exception('Payment gateway :adapter was not found', [':adapter' => $class]);
|
||||
}
|
||||
|
||||
$adapter = new $class($config);
|
||||
|
||||
if(method_exists($adapter, 'setDi')) {
|
||||
if (method_exists($adapter, 'setDi')) {
|
||||
$adapter->setDi($this->di);
|
||||
}
|
||||
|
||||
@@ -243,32 +248,33 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
private function _getAllowTuple(\Model_PayGateway $model)
|
||||
{
|
||||
$adapter_config = $this->getAdapterConfig($model);
|
||||
$single = $this->di['array_get']($adapter_config, 'supports_one_time_payments', FALSE);
|
||||
$recurrent = $this->di['array_get']($adapter_config, 'supports_subscriptions', FALSE);
|
||||
$single = $this->di['array_get']($adapter_config, 'supports_one_time_payments', false);
|
||||
$recurrent = $this->di['array_get']($adapter_config, 'supports_subscriptions', false);
|
||||
|
||||
return array(
|
||||
return [
|
||||
$single,
|
||||
$recurrent,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function getAdapterConfig(\Model_PayGateway $pg)
|
||||
{
|
||||
$class = $this->getAdapterClassName($pg);
|
||||
if(!file_exists(BB_PATH_LIBRARY.'/Payment/Adapter/'.$pg->gateway.'.php')) {
|
||||
throw new \Box_Exception("Payment gateway :adapter was not found", array(':adapter'=>$pg->gateway));
|
||||
if (!file_exists(BB_PATH_LIBRARY.'/Payment/Adapter/'.$pg->gateway.'.php')) {
|
||||
throw new \Box_Exception('Payment gateway :adapter was not found', [':adapter' => $pg->gateway]);
|
||||
}
|
||||
|
||||
if(!class_exists($class)) {
|
||||
if (!class_exists($class)) {
|
||||
throw new \Box_Exception("Payment gateway class $class was not found");
|
||||
}
|
||||
|
||||
if(!method_exists($class, 'getConfig')) {
|
||||
if (!method_exists($class, 'getConfig')) {
|
||||
error_log("Payment $class gateway does not have getConfig method");
|
||||
return array();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
return call_user_func(array($class, 'getConfig'));
|
||||
return call_user_func([$class, 'getConfig']);
|
||||
}
|
||||
|
||||
public function getAdapterClassName(\Model_PayGateway $pg)
|
||||
@@ -278,8 +284,9 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
|
||||
public function getAcceptedCurrencies(\Model_PayGateway $model)
|
||||
{
|
||||
if(null === $model->accepted_currencies || empty($model->accepted_currencies)) {
|
||||
if (null === $model->accepted_currencies || empty($model->accepted_currencies)) {
|
||||
$currencyService = $this->di['mod_service']('Currency');
|
||||
|
||||
return array_keys($currencyService->getPairs());
|
||||
}
|
||||
|
||||
@@ -289,16 +296,18 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
public function getFormElements(\Model_PayGateway $model)
|
||||
{
|
||||
$config = $this->getAdapterConfig($model);
|
||||
if(isset($config['form']) && is_array($config['form'])) {
|
||||
if (isset($config['form']) && is_array($config['form'])) {
|
||||
return $config['form'];
|
||||
}
|
||||
return array();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getDescription(\Model_PayGateway $model)
|
||||
{
|
||||
$config = $this->getAdapterConfig($model);
|
||||
return (isset($config['description'])) ? $config['description'] : NULL;
|
||||
|
||||
return (isset($config['description'])) ? $config['description'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -306,13 +315,14 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
*/
|
||||
public function getCallbackUrl(\Model_PayGateway $pg, $model = null)
|
||||
{
|
||||
$p = array(
|
||||
'bb_gateway_id' => $pg->id,
|
||||
);
|
||||
if($model instanceof \Model_Invoice) {
|
||||
$p = [
|
||||
'bb_gateway_id' => $pg->id,
|
||||
];
|
||||
if ($model instanceof \Model_Invoice) {
|
||||
$p['bb_invoice_id'] = $model->id;
|
||||
}
|
||||
return $this->di['config']['url'] . 'bb-ipn.php?'.http_build_query($p);
|
||||
|
||||
return $this->di['config']['url'].'bb-ipn.php?'.http_build_query($p);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,22 +330,23 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
*/
|
||||
private function getReturnUrl(\Model_PayGateway $pg, $model = null)
|
||||
{
|
||||
if($model instanceof \Model_Invoice) {
|
||||
return $this->di['url']->link('/invoice/'.$model->hash, array('status'=> 'ok'));
|
||||
if ($model instanceof \Model_Invoice) {
|
||||
return $this->di['url']->link('/invoice/'.$model->hash, ['status' => 'ok']);
|
||||
}
|
||||
return $this->di['url']->link('/invoice', array('status'=> 'ok'));
|
||||
}
|
||||
|
||||
return $this->di['url']->link('/invoice', ['status' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Model_Invoice $model
|
||||
*/
|
||||
private function getCancelUrl(\Model_PayGateway $pg, $model = null)
|
||||
{
|
||||
if($model instanceof \Model_Invoice) {
|
||||
return $this->di['url']->link('/invoice/'.$model->hash, array('status'=> 'cancel'));
|
||||
if ($model instanceof \Model_Invoice) {
|
||||
return $this->di['url']->link('/invoice/'.$model->hash, ['status' => 'cancel']);
|
||||
}
|
||||
return $this->di['url']->link('/invoice', array('status'=> 'cancel'));
|
||||
|
||||
return $this->di['url']->link('/invoice', ['status' => 'cancel']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,15 +354,16 @@ class ServicePayGateway implements InjectionAwareInterface
|
||||
*/
|
||||
private function getCallbackRedirect(\Model_PayGateway $pg, $model = null)
|
||||
{
|
||||
$p = array(
|
||||
'bb_gateway_id' => $pg->id,
|
||||
);
|
||||
$p = [
|
||||
'bb_gateway_id' => $pg->id,
|
||||
];
|
||||
|
||||
if($model instanceof \Model_Invoice) {
|
||||
$p['bb_invoice_id'] = $model->id;
|
||||
$p['bb_invoice_hash'] = $model->hash;
|
||||
$p['bb_redirect'] = 1;
|
||||
if ($model instanceof \Model_Invoice) {
|
||||
$p['bb_invoice_id'] = $model->id;
|
||||
$p['bb_invoice_hash'] = $model->hash;
|
||||
$p['bb_redirect'] = 1;
|
||||
}
|
||||
return $this->di['config']['url'] . 'bb-ipn.php?'.http_build_query($p);
|
||||
|
||||
return $this->di['config']['url'].'bb-ipn.php?'.http_build_query($p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -9,7 +9,9 @@
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Invoice;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class ServiceSubscription implements InjectionAwareInterface
|
||||
@@ -37,22 +39,22 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
|
||||
public function create(\Model_Client $cient, \Model_PayGateway $pg, array $data)
|
||||
{
|
||||
$model = $this->di['db']->dispense('Subscription');
|
||||
$model->client_id = $data['client_id'];
|
||||
$model = $this->di['db']->dispense('Subscription');
|
||||
$model->client_id = $data['client_id'];
|
||||
$model->pay_gateway_id = $data['gateway_id'];
|
||||
|
||||
$model->sid = $this->di['array_get']($data, 'sid', NULL);
|
||||
$model->status = $this->di['array_get']($data, 'status', NULL);
|
||||
$model->period = $this->di['array_get']($data, 'period', NULL);
|
||||
$model->amount = $this->di['array_get']($data, 'amount', NULL);
|
||||
$model->currency = $this->di['array_get']($data, 'currency', NULL);
|
||||
$model->rel_id = $this->di['array_get']($data, 'rel_id', NULL);
|
||||
$model->rel_type = $this->di['array_get']($data, 'rel_type', NULL);
|
||||
$model->sid = $this->di['array_get']($data, 'sid', null);
|
||||
$model->status = $this->di['array_get']($data, 'status', null);
|
||||
$model->period = $this->di['array_get']($data, 'period', null);
|
||||
$model->amount = $this->di['array_get']($data, 'amount', null);
|
||||
$model->currency = $this->di['array_get']($data, 'currency', null);
|
||||
$model->rel_id = $this->di['array_get']($data, 'rel_id', null);
|
||||
$model->rel_type = $this->di['array_get']($data, 'rel_type', null);
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$newId = $this->di['db']->store($model);
|
||||
$newId = $this->di['db']->store($model);
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onAfterAdminSubscriptionCreate', 'params' => array('id' => $newId)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminSubscriptionCreate', 'params' => ['id' => $newId]]);
|
||||
|
||||
$this->di['logger']->info('Created subscription %s', $newId);
|
||||
|
||||
@@ -61,37 +63,37 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
|
||||
public function update(\Model_Subscription $model, array $data)
|
||||
{
|
||||
$model->status = $this->di['array_get']($data, 'status', $model->status);
|
||||
$model->sid = $this->di['array_get']($data, 'sid', $model->sid);
|
||||
$model->period = $this->di['array_get']($data, 'period', $model->period);
|
||||
$model->amount = $this->di['array_get']($data, 'amount', $model->amount);
|
||||
$model->currency = $this->di['array_get']($data, 'currency', $model->currency);
|
||||
$model->status = $this->di['array_get']($data, 'status', $model->status);
|
||||
$model->sid = $this->di['array_get']($data, 'sid', $model->sid);
|
||||
$model->period = $this->di['array_get']($data, 'period', $model->period);
|
||||
$model->amount = $this->di['array_get']($data, 'amount', $model->amount);
|
||||
$model->currency = $this->di['array_get']($data, 'currency', $model->currency);
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$newId = $this->di['db']->store($model);
|
||||
$newId = $this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Updated subscription %s', $newId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function toApiArray(\Model_Subscription $model, $deep = false, $identity = null)
|
||||
{
|
||||
$result = array(
|
||||
'id' => $model->id,
|
||||
'sid' => $model->sid,
|
||||
'period' => $model->period,
|
||||
'amount' => $model->amount,
|
||||
'currency' => $model->currency,
|
||||
'status' => $model->status,
|
||||
$result = [
|
||||
'id' => $model->id,
|
||||
'sid' => $model->sid,
|
||||
'period' => $model->period,
|
||||
'amount' => $model->amount,
|
||||
'currency' => $model->currency,
|
||||
'status' => $model->status,
|
||||
'created_at' => $model->created_at,
|
||||
'updated_at' => $model->updated_at,
|
||||
);
|
||||
];
|
||||
$client = $this->di['db']->load('Client', $model->client_id);
|
||||
if ($client instanceof \Model_Client) {
|
||||
$clientService = $this->di['mod_service']('Client');
|
||||
$clientService = $this->di['mod_service']('Client');
|
||||
$result['client'] = $clientService->toApiArray($client, false, $identity);
|
||||
} else {
|
||||
$result['client'] = array();
|
||||
$result['client'] = [];
|
||||
}
|
||||
|
||||
$gtw = $this->di['db']->load('PayGateway', $model->pay_gateway_id);
|
||||
@@ -99,7 +101,7 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
$payGatewayService = $this->di['mod_service']('Invoice', 'PayGateway');
|
||||
$result['gateway'] = $payGatewayService->toApiArray($gtw, false, $identity);
|
||||
} else {
|
||||
$result['gateway'] = array();
|
||||
$result['gateway'] = [];
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -110,9 +112,10 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
$id = $model->id;
|
||||
$this->di['db']->trash($model);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminSubscriptionDelete', 'params'=>array('id'=>$id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminSubscriptionDelete', 'params' => ['id' => $id]]);
|
||||
|
||||
$this->di['logger']->info('Removed subscription %s', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,19 +125,18 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
FROM subscription
|
||||
WHERE 1 ';
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$sid = $this->di['array_get']($data, 'sid', null);
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$invoice_id = $this->di['array_get']($data, 'invoice_id', null);
|
||||
$gateway_id = $this->di['array_get']($data, 'gateway_id', null);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
$currency = $this->di['array_get']($data, 'currency', null);
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$sid = $this->di['array_get']($data, 'sid', NULL);
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$invoice_id = $this->di['array_get']($data, 'invoice_id', NULL);
|
||||
$gateway_id = $this->di['array_get']($data, 'gateway_id', NULL);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$status = $this->di['array_get']($data, 'status', NULL);
|
||||
$currency = $this->di['array_get']($data, 'currency', NULL);
|
||||
|
||||
$date_from = $this->di['array_get']($data, 'date_from', NULL);
|
||||
$date_to = $this->di['array_get']($data, 'date_to', NULL);
|
||||
$params = array();
|
||||
$date_from = $this->di['array_get']($data, 'date_from', null);
|
||||
$date_to = $this->di['array_get']($data, 'date_to', null);
|
||||
$params = [];
|
||||
if ($status) {
|
||||
$sql .= ' AND status = :status';
|
||||
$params['status'] = $status;
|
||||
@@ -163,7 +165,6 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
if ($date_from) {
|
||||
$sql .= ' AND UNIX_TIMESTAMP(m.created_at) >= :date_from';
|
||||
$params['date_from'] = $date_from;
|
||||
|
||||
}
|
||||
|
||||
if ($date_to) {
|
||||
@@ -187,33 +188,32 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
$params['sid'] = $sid;
|
||||
}
|
||||
|
||||
|
||||
$sql .= ' ORDER BY id DESC';
|
||||
|
||||
return array($sql, $params);
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function isSubscribable($invoice_id)
|
||||
{
|
||||
$query = "SELECT COUNT(id) as cc
|
||||
$query = 'SELECT COUNT(id) as cc
|
||||
FROM invoice_item
|
||||
WHERE invoice_id = :id
|
||||
GROUP BY invoice_id
|
||||
";
|
||||
$count = $this->di['db']->getCell($query, array('id'=>$invoice_id));
|
||||
if($count > 1) {
|
||||
';
|
||||
$count = $this->di['db']->getCell($query, ['id' => $invoice_id]);
|
||||
if ($count > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if first invoice line has deined period
|
||||
$query = "SELECT id, period
|
||||
$query = 'SELECT id, period
|
||||
FROM invoice_item
|
||||
WHERE invoice_id = :id
|
||||
LIMIT 1
|
||||
";
|
||||
$list = $this->di['db']->getAll($query, array(':id' => $invoice_id));
|
||||
';
|
||||
$list = $this->di['db']->getAll($query, [':id' => $invoice_id]);
|
||||
|
||||
if(isset($list[0])
|
||||
if (isset($list[0])
|
||||
&& isset($list[0]['period'])
|
||||
&& !empty($list[0]['period'])) {
|
||||
return true;
|
||||
@@ -224,16 +224,17 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
|
||||
public function getSubscriptionPeriod(\Model_Invoice $invoice)
|
||||
{
|
||||
if(!$this->isSubscribable($invoice->id)) {
|
||||
return NULL;
|
||||
if (!$this->isSubscribable($invoice->id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = "SELECT period
|
||||
$query = 'SELECT period
|
||||
FROM invoice_item
|
||||
WHERE invoice_id = :id
|
||||
LIMIT 1
|
||||
";
|
||||
return $this->di['db']->getCell($query, array('id'=>$invoice->id));
|
||||
';
|
||||
|
||||
return $this->di['db']->getCell($query, ['id' => $invoice->id]);
|
||||
}
|
||||
|
||||
public function unsubscribe(\Model_Subscription $model)
|
||||
@@ -242,4 +243,4 @@ class ServiceSubscription implements InjectionAwareInterface
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -9,7 +9,9 @@
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Invoice;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class ServiceTax implements InjectionAwareInterface
|
||||
@@ -38,29 +40,32 @@ class ServiceTax implements InjectionAwareInterface
|
||||
public function getTaxRateForClient(\Model_Client $model, &$title = null)
|
||||
{
|
||||
$clientService = $this->di['mod_service']('client');
|
||||
if(!$clientService->isClientTaxable($model)) {
|
||||
if (!$clientService->isClientTaxable($model)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$tax = $this->di['db']->findOne('Tax', 'state = ? and country = ?', array($model->state, $model->country));
|
||||
$tax = $this->di['db']->findOne('Tax', 'state = ? and country = ?', [$model->state, $model->country]);
|
||||
// find rate which matches clients country and state
|
||||
|
||||
if($tax instanceof \Model_Tax) {
|
||||
if ($tax instanceof \Model_Tax) {
|
||||
$title = $tax->name;
|
||||
|
||||
return $tax->taxrate;
|
||||
}
|
||||
|
||||
// find rate which matches clients country
|
||||
$tax = $this->di['db']->findOne('Tax', 'country = ?', array($model->country));
|
||||
if($tax instanceof \Model_Tax) {
|
||||
$tax = $this->di['db']->findOne('Tax', 'country = ?', [$model->country]);
|
||||
if ($tax instanceof \Model_Tax) {
|
||||
$title = $tax->name;
|
||||
|
||||
return $tax->taxrate;
|
||||
}
|
||||
|
||||
// find global rate
|
||||
$tax = $this->di['db']->findOne('Tax', '(state is NULL or state = "") and (country is null or country = "")');
|
||||
if($tax instanceof \Model_Tax) {
|
||||
if ($tax instanceof \Model_Tax) {
|
||||
$title = $tax->name;
|
||||
|
||||
return $tax->taxrate;
|
||||
}
|
||||
|
||||
@@ -69,16 +74,17 @@ class ServiceTax implements InjectionAwareInterface
|
||||
|
||||
public function getTax(\Model_Invoice $invoice)
|
||||
{
|
||||
if($invoice->taxrate <= 0) {
|
||||
if ($invoice->taxrate <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$tax = 0;
|
||||
$invoiceItems = $this->di['db']->find('InvoiceItem', 'invoice_id = ?', array($invoice->id));
|
||||
$invoiceItems = $this->di['db']->find('InvoiceItem', 'invoice_id = ?', [$invoice->id]);
|
||||
$invoiceItemService = $this->di['mod_service']('Invoice', 'InvoiceItem');
|
||||
foreach($invoiceItems as $item) {
|
||||
foreach ($invoiceItems as $item) {
|
||||
$tax += $invoiceItemService->getTax($item) * $item->quantity;
|
||||
}
|
||||
|
||||
return $tax;
|
||||
}
|
||||
|
||||
@@ -87,6 +93,7 @@ class ServiceTax implements InjectionAwareInterface
|
||||
$name = $model->name;
|
||||
$this->di['db']->trash($model);
|
||||
$this->di['logger']->info('Deleted tax rule %s', $name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -97,29 +104,31 @@ class ServiceTax implements InjectionAwareInterface
|
||||
|
||||
$model = $this->di['db']->dispense('Tax');
|
||||
$model->name = $data['name'];
|
||||
$model->country = (!isset($data['country']) || empty($data['country'])) ? NULL : $data['country'];
|
||||
$model->state = (!isset($data['state']) || empty($data['state'])) ? NULL : $data['state'];
|
||||
$model->country = (!isset($data['country']) || empty($data['country'])) ? null : $data['country'];
|
||||
$model->state = (!isset($data['state']) || empty($data['state'])) ? null : $data['state'];
|
||||
$model->taxrate = $data['taxrate'];
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$newId = $this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Created new tax rule %s', $model->name);
|
||||
return $newId ;
|
||||
|
||||
return $newId;
|
||||
}
|
||||
|
||||
public function update(\Model_Tax $model, array $data)
|
||||
{
|
||||
$model->name = $data['name'];
|
||||
$model->country = (!isset($data['country']) || empty($data['country'])) ? NULL : $data['country'];
|
||||
$model->state = (!isset($data['state']) || empty($data['state'])) ? NULL : $data['state'];
|
||||
$model->country = (!isset($data['country']) || empty($data['country'])) ? null : $data['country'];
|
||||
$model->state = (!isset($data['state']) || empty($data['state'])) ? null : $data['state'];
|
||||
$model->taxrate = $data['taxrate'];
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Created new tax rule %s', $model->name);
|
||||
return true ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getSearchQuery($data)
|
||||
@@ -128,19 +137,19 @@ class ServiceTax implements InjectionAwareInterface
|
||||
FROM tax
|
||||
ORDER BY id desc';
|
||||
|
||||
return array($sql, array());
|
||||
return [$sql, []];
|
||||
}
|
||||
|
||||
public function setupEUTaxes(array $data)
|
||||
{
|
||||
$sql = "TRUNCATE tax;";
|
||||
$sql = 'TRUNCATE tax;';
|
||||
$this->di['db']->exec($sql);
|
||||
|
||||
$systemService = $this->di['mod_service']('System');
|
||||
$eu_countries = $systemService->getEuCountries();
|
||||
$eu_vat = $systemService->getEuVat();
|
||||
$eu_countries = $systemService->getEuCountries();
|
||||
$eu_vat = $systemService->getEuVat();
|
||||
foreach ($eu_vat as $code => $taxRate) {
|
||||
$this->create(array('name' => $eu_countries[$code], 'taxrate' => $taxRate, 'country' => $code));
|
||||
$this->create(['name' => $eu_countries[$code], 'taxrate' => $taxRate, 'country' => $code]);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -150,5 +159,4 @@ class ServiceTax implements InjectionAwareInterface
|
||||
{
|
||||
return $this->di['db']->toArray($model);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -9,7 +9,9 @@
|
||||
* This source file is subject to the Apache-2.0 License that is bundled
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Invoice;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
|
||||
class ServiceTransaction implements InjectionAwareInterface
|
||||
@@ -39,16 +41,17 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
{
|
||||
$this->di['logger']->info('Executed action to process received transactions');
|
||||
$received = $this->getReceived();
|
||||
foreach($received as $transaction) {
|
||||
foreach ($received as $transaction) {
|
||||
$model = $this->di['db']->getExistingModelById('Transaction', $transaction['id']);
|
||||
$this->preProcessTransaction($model);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update(\Model_Transaction $model, array $data)
|
||||
{
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminTransactionUpdate', 'params'=>array('id'=>$model->id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminTransactionUpdate', 'params' => ['id' => $model->id]]);
|
||||
|
||||
$model->invoice_id = $this->di['array_get']($data, 'invoice_id', $model->invoice_id);
|
||||
$model->txn_id = $this->di['array_get']($data, 'txn_id', $model->txn_id);
|
||||
@@ -64,9 +67,10 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$model->validate_ipn = $this->di['array_get']($data, 'validate_ipn', $model->validate_ipn);
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminTransactionUpdate', 'params'=>array('id'=>$model->id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminTransactionUpdate', 'params' => ['id' => $model->id]]);
|
||||
|
||||
$this->di['logger']->info('Updated transaction #%s', $model->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -74,48 +78,49 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
{
|
||||
$id = $this->create($ipn);
|
||||
$this->processTransaction($id);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
$this->di['events_manager']->fire(array('event'=>'onBeforeAdminTransactionCreate', 'params'=>$data));
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeAdminTransactionCreate', 'params' => $data]);
|
||||
|
||||
$skip_validation = isset($data['skip_validation']) ? (bool)$data['skip_validation'] : false;
|
||||
if(!$skip_validation) {
|
||||
if(!isset($data['bb_invoice_id'])) {
|
||||
$skip_validation = isset($data['skip_validation']) ? (bool) $data['skip_validation'] : false;
|
||||
if (!$skip_validation) {
|
||||
if (!isset($data['bb_invoice_id'])) {
|
||||
throw new \Box_Exception('Transaction invoice id is missing');
|
||||
}
|
||||
|
||||
if(!isset($data['bb_gateway_id'])) {
|
||||
if (!isset($data['bb_gateway_id'])) {
|
||||
throw new \Box_Exception('Payment gateway id is missing');
|
||||
}
|
||||
$this->di['db']->getExistingModelById('Invoice', $data['bb_invoice_id'], 'Invoice was not found');
|
||||
$this->di['db']->getExistingModelById('PayGateway', $data['bb_gateway_id'], 'Gateway was not found');
|
||||
}
|
||||
|
||||
$ipn = array(
|
||||
'get' => (isset($data['get']) && is_array($data['get'])) ? $data['get'] : NULL,
|
||||
'post' => (isset($data['post']) && is_array($data['post'])) ? $data['post'] : NULL,
|
||||
'http_raw_post_data' => $this->di['array_get']($data, 'http_raw_post_data', NULL),
|
||||
'server' => $this->di['array_get']($data, 'server', NULL),
|
||||
);
|
||||
$ipn = [
|
||||
'get' => (isset($data['get']) && is_array($data['get'])) ? $data['get'] : null,
|
||||
'post' => (isset($data['post']) && is_array($data['post'])) ? $data['post'] : null,
|
||||
'http_raw_post_data' => $this->di['array_get']($data, 'http_raw_post_data', null),
|
||||
'server' => $this->di['array_get']($data, 'server', null),
|
||||
];
|
||||
|
||||
$transaction = $this->di['db']->dispense('Transaction');
|
||||
$transaction->gateway_id = $this->di['array_get']($data, 'bb_gateway_id', NULL);
|
||||
$transaction->invoice_id = $this->di['array_get']($data, 'bb_invoice_id', NULL);
|
||||
$transaction->txn_id = $this->di['array_get']($data, 'txn_id', NULL);
|
||||
$transaction->status = 'received';
|
||||
$transaction->ip = $this->di['request']->getClientAddress();
|
||||
$transaction->ipn = json_encode($ipn);
|
||||
$transaction->note = (isset($data['note'])) ? $data['note'] : NULL;
|
||||
$transaction->created_at = date('Y-m-d H:i:s');
|
||||
$transaction->updated_at = date('Y-m-d H:i:s');
|
||||
$transaction->gateway_id = $this->di['array_get']($data, 'bb_gateway_id', null);
|
||||
$transaction->invoice_id = $this->di['array_get']($data, 'bb_invoice_id', null);
|
||||
$transaction->txn_id = $this->di['array_get']($data, 'txn_id', null);
|
||||
$transaction->status = 'received';
|
||||
$transaction->ip = $this->di['request']->getClientAddress();
|
||||
$transaction->ipn = json_encode($ipn);
|
||||
$transaction->note = (isset($data['note'])) ? $data['note'] : null;
|
||||
$transaction->created_at = date('Y-m-d H:i:s');
|
||||
$transaction->updated_at = date('Y-m-d H:i:s');
|
||||
$newId = $this->di['db']->store($transaction);
|
||||
|
||||
$this->di['logger']->info('Received transaction %s from payment gateway %s', $newId, $transaction->gateway_id);
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminTransactionCreate', 'params'=>array('id'=>$newId)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminTransactionCreate', 'params' => ['id' => $newId]]);
|
||||
|
||||
return $newId;
|
||||
}
|
||||
@@ -125,41 +130,43 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$id = $model->id;
|
||||
$this->di['db']->trash($model);
|
||||
$this->di['logger']->info('Removed transaction #%s', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function toApiArray(\Model_Transaction $model, $deep = false, $identity = null)
|
||||
{
|
||||
$gateway = NULL;
|
||||
if($model->gateway_id) {
|
||||
$gateway = null;
|
||||
if ($model->gateway_id) {
|
||||
$gtw = $this->di['db']->load('PayGateway', $model->gateway_id);
|
||||
if($gtw instanceof \Model_PayGateway) {
|
||||
if ($gtw instanceof \Model_PayGateway) {
|
||||
$gateway = $gtw->name;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'id' => $model->id,
|
||||
'invoice_id' => $model->invoice_id,
|
||||
'txn_id' => $model->txn_id,
|
||||
'txn_status' => $model->txn_status,
|
||||
'gateway_id' => $model->gateway_id,
|
||||
'gateway' => $gateway,
|
||||
'amount' => $model->amount,
|
||||
'currency' => $model->currency,
|
||||
'type' => $model->type,
|
||||
'status' => $model->status,
|
||||
'ip' => $model->ip,
|
||||
'validate_ipn' => $model->validate_ipn,
|
||||
'error' => $model->error,
|
||||
'error_code' => $model->error_code,
|
||||
'note' => $model->note,
|
||||
'created_at' => $model->created_at,
|
||||
'updated_at' => $model->updated_at,
|
||||
);
|
||||
if($deep) {
|
||||
$result = [
|
||||
'id' => $model->id,
|
||||
'invoice_id' => $model->invoice_id,
|
||||
'txn_id' => $model->txn_id,
|
||||
'txn_status' => $model->txn_status,
|
||||
'gateway_id' => $model->gateway_id,
|
||||
'gateway' => $gateway,
|
||||
'amount' => $model->amount,
|
||||
'currency' => $model->currency,
|
||||
'type' => $model->type,
|
||||
'status' => $model->status,
|
||||
'ip' => $model->ip,
|
||||
'validate_ipn' => $model->validate_ipn,
|
||||
'error' => $model->error,
|
||||
'error_code' => $model->error_code,
|
||||
'note' => $model->note,
|
||||
'created_at' => $model->created_at,
|
||||
'updated_at' => $model->updated_at,
|
||||
];
|
||||
if ($deep) {
|
||||
$result['ipn'] = json_decode($model->ipn, true);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -170,21 +177,21 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
LEFT JOIN invoice as i on m.invoice_id = i.id
|
||||
WHERE 1 ';
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$invoice_hash = $this->di['array_get']($data, 'invoice_hash', NULL);
|
||||
$invoice_id = $this->di['array_get']($data, 'invoice_id', NULL);
|
||||
$gateway_id = $this->di['array_get']($data, 'gateway_id', NULL);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', NULL);
|
||||
$status = $this->di['array_get']($data, 'status', NULL);
|
||||
$currency = $this->di['array_get']($data, 'currency', NULL);
|
||||
$type = $this->di['array_get']($data, 'type', NULL);
|
||||
$txn_id = $this->di['array_get']($data, 'txn_id', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$invoice_hash = $this->di['array_get']($data, 'invoice_hash', null);
|
||||
$invoice_id = $this->di['array_get']($data, 'invoice_id', null);
|
||||
$gateway_id = $this->di['array_get']($data, 'gateway_id', null);
|
||||
$client_id = $this->di['array_get']($data, 'client_id', null);
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
$currency = $this->di['array_get']($data, 'currency', null);
|
||||
$type = $this->di['array_get']($data, 'type', null);
|
||||
$txn_id = $this->di['array_get']($data, 'txn_id', null);
|
||||
|
||||
$date_from = $this->di['array_get']($data, 'date_from', NULL);
|
||||
$date_to = $this->di['array_get']($data, 'date_to', NULL);
|
||||
$date_from = $this->di['array_get']($data, 'date_from', null);
|
||||
$date_to = $this->di['array_get']($data, 'date_to', null);
|
||||
|
||||
$params = array();
|
||||
$params = [];
|
||||
if ($id) {
|
||||
$sql .= ' AND m.id = :id';
|
||||
$params['id'] = $id;
|
||||
@@ -242,15 +249,15 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
|
||||
if ($search) {
|
||||
$sql .= ' AND m.note LIKE :note OR m.invoice_id LIKE :search_invoice_id OR m.txn_id LIKE :search_txn_id OR m.ipn LIKE :ipn';
|
||||
$params['note'] = "%$search%";
|
||||
$params['note'] = "%$search%";
|
||||
$params['search__invoice_id'] = "%$search%";
|
||||
$params['search_txn_id'] = "%$search%";
|
||||
$params['ipn'] = "%$search%";
|
||||
$params['search_txn_id'] = "%$search%";
|
||||
$params['ipn'] = "%$search%";
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY m.id DESC';
|
||||
|
||||
return array($sql, $params);
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function counter()
|
||||
@@ -259,59 +266,58 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
FROM transaction
|
||||
GROUP BY status';
|
||||
$rows = $this->di['db']->getAll($sql);
|
||||
$data = array();
|
||||
foreach($rows as $row){
|
||||
$data[ $row['status'] ] = $row['counter'];
|
||||
$data = [];
|
||||
foreach ($rows as $row) {
|
||||
$data[$row['status']] = $row['counter'];
|
||||
}
|
||||
|
||||
return array(
|
||||
'total' => array_sum($data),
|
||||
\Model_Transaction::STATUS_RECEIVED => isset($data[\Model_Transaction::STATUS_RECEIVED]) ? $data[\Model_Transaction::STATUS_RECEIVED] : 0,
|
||||
\Model_Transaction::STATUS_APPROVED => isset($data[\Model_Transaction::STATUS_APPROVED]) ? $data[\Model_Transaction::STATUS_APPROVED] : 0,
|
||||
\Model_Transaction::STATUS_PROCESSED => isset($data[\Model_Transaction::STATUS_PROCESSED]) ? $data[\Model_Transaction::STATUS_PROCESSED] : 0,
|
||||
\Model_Transaction::STATUS_ERROR => isset($data[\Model_Transaction::STATUS_ERROR]) ? $data[\Model_Transaction::STATUS_ERROR] : 0,
|
||||
);
|
||||
return [
|
||||
'total' => array_sum($data),
|
||||
\Model_Transaction::STATUS_RECEIVED => $data[\Model_Transaction::STATUS_RECEIVED] ?? 0,
|
||||
\Model_Transaction::STATUS_APPROVED => $data[\Model_Transaction::STATUS_APPROVED] ?? 0,
|
||||
\Model_Transaction::STATUS_PROCESSED => $data[\Model_Transaction::STATUS_PROCESSED] ?? 0,
|
||||
\Model_Transaction::STATUS_ERROR => $data[\Model_Transaction::STATUS_ERROR] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatusPairs()
|
||||
{
|
||||
return array(
|
||||
\Model_Transaction::STATUS_RECEIVED => 'Received',
|
||||
\Model_Transaction::STATUS_APPROVED => 'Approved',
|
||||
return [
|
||||
\Model_Transaction::STATUS_RECEIVED => 'Received',
|
||||
\Model_Transaction::STATUS_APPROVED => 'Approved',
|
||||
\Model_Transaction::STATUS_PROCESSED => 'Processed',
|
||||
\Model_Transaction::STATUS_ERROR => 'Error',
|
||||
);
|
||||
\Model_Transaction::STATUS_ERROR => 'Error',
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatuses()
|
||||
{
|
||||
return array(
|
||||
\Model_Transaction::STATUS_RECEIVED => 'Received',
|
||||
\Model_Transaction::STATUS_APPROVED => 'Approved/Verified',
|
||||
\Model_Transaction::STATUS_PROCESSED => 'Processed',
|
||||
\Model_Transaction::STATUS_ERROR => 'Error',
|
||||
);
|
||||
return [
|
||||
\Model_Transaction::STATUS_RECEIVED => 'Received',
|
||||
\Model_Transaction::STATUS_APPROVED => 'Approved/Verified',
|
||||
\Model_Transaction::STATUS_PROCESSED => 'Processed',
|
||||
\Model_Transaction::STATUS_ERROR => 'Error',
|
||||
];
|
||||
}
|
||||
|
||||
public function getGatewayStatuses()
|
||||
{
|
||||
return array(
|
||||
\Payment_Transaction::STATUS_PENDING => 'Pending validation',
|
||||
\Payment_Transaction::STATUS_COMPLETE => 'Complete',
|
||||
\Payment_Transaction::STATUS_UNKNOWN => 'Unknown',
|
||||
|
||||
);
|
||||
return [
|
||||
\Payment_Transaction::STATUS_PENDING => 'Pending validation',
|
||||
\Payment_Transaction::STATUS_COMPLETE => 'Complete',
|
||||
\Payment_Transaction::STATUS_UNKNOWN => 'Unknown',
|
||||
];
|
||||
}
|
||||
|
||||
public function getTypes()
|
||||
{
|
||||
return array(
|
||||
\Payment_Transaction::TXTYPE_PAYMENT => 'Payment',
|
||||
\Payment_Transaction::TXTYPE_REFUND => 'Refund',
|
||||
\Payment_Transaction::TXTYPE_SUBSCR_CREATE => 'Subscription create',
|
||||
\Payment_Transaction::TXTYPE_SUBSCR_CANCEL => 'Subscription cancel',
|
||||
\Payment_Transaction::TXTYPE_UNKNOWN => 'Unknown',
|
||||
);
|
||||
return [
|
||||
\Payment_Transaction::TXTYPE_PAYMENT => 'Payment',
|
||||
\Payment_Transaction::TXTYPE_REFUND => 'Refund',
|
||||
\Payment_Transaction::TXTYPE_SUBSCR_CREATE => 'Subscription create',
|
||||
\Payment_Transaction::TXTYPE_SUBSCR_CANCEL => 'Subscription cancel',
|
||||
\Payment_Transaction::TXTYPE_UNKNOWN => 'Unknown',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,6 +326,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
public function oldProcessLogic($model)
|
||||
{
|
||||
$tx = $this->process($model);
|
||||
|
||||
return !empty($tx->output) ? $tx->output : null;
|
||||
}
|
||||
|
||||
@@ -329,7 +336,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$output = $this->processTransaction($model->id);
|
||||
} catch (\Box_Exception $e) {
|
||||
// if gateway does not support new logic use old logic
|
||||
if($e->getCode() == 705) {
|
||||
if (705 == $e->getCode()) {
|
||||
$output = $this->oldProcessLogic($model);
|
||||
} else {
|
||||
$model->status = \Model_Transaction::STATUS_ERROR;
|
||||
@@ -341,52 +348,56 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
}
|
||||
}
|
||||
|
||||
$this->di['events_manager']->fire(array('event'=>'onAfterAdminTransactionProcess', 'params'=>array('id'=>$model->id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminTransactionProcess', 'params' => ['id' => $model->id]]);
|
||||
$this->di['logger']->info('Processed transaction #%s', $model->id);
|
||||
return !empty($output) ? $output : true;
|
||||
|
||||
return !empty($output) ? $output : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* New simplified transaction processing logic
|
||||
* New simplified transaction processing logic.
|
||||
*
|
||||
* @since 2.9.11
|
||||
*
|
||||
* @param type $id
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function processTransaction($id)
|
||||
{
|
||||
$tx = $this->di['db']->load('Transaction', $id);
|
||||
if(!$tx) {
|
||||
throw new \Box_Exception('Transaction :id not found.', array('id'=>$id), 404);
|
||||
if (!$tx) {
|
||||
throw new \Box_Exception('Transaction :id not found.', ['id' => $id], 404);
|
||||
}
|
||||
|
||||
if(empty($tx->gateway_id)) {
|
||||
if (empty($tx->gateway_id)) {
|
||||
throw new \Box_Exception('Could not determine transaction origin. Transaction payment gateway is unknown.', null, 701);
|
||||
}
|
||||
|
||||
$gtw = $this->di['db']->load('PayGateway', $tx->gateway_id);
|
||||
if(!$gtw instanceof \Model_PayGateway) {
|
||||
throw new \Box_Exception('Can not handle transaction received from unknown payment gateway: :id', array(':id'=>$tx->gateway_id), 704);
|
||||
if (!$gtw instanceof \Model_PayGateway) {
|
||||
throw new \Box_Exception('Can not handle transaction received from unknown payment gateway: :id', [':id' => $tx->gateway_id], 704);
|
||||
}
|
||||
|
||||
$payGatewayService = $this->di['mod_service']('Invoice', 'PayGateway');
|
||||
$adapter = $payGatewayService->getPaymentAdapter($gtw);
|
||||
if(!method_exists($adapter, 'processTransaction')) {
|
||||
throw new \Box_Exception('Payment adapter :adapter does not support action :action', array(':adapter'=>$gtw->name, ':action'=>'processTransaction'), 705);
|
||||
if (!method_exists($adapter, 'processTransaction')) {
|
||||
throw new \Box_Exception('Payment adapter :adapter does not support action :action', [':adapter' => $gtw->name, ':action' => 'processTransaction'], 705);
|
||||
}
|
||||
|
||||
$ipn = json_decode($tx->ipn, 1);
|
||||
|
||||
return $adapter->processTransaction($this->di['api_system'], $id, $ipn, $tx->gateway_id);
|
||||
}
|
||||
|
||||
public function getReceived()
|
||||
{
|
||||
$filter = array(
|
||||
'status' => 'received'
|
||||
);
|
||||
list($sql, $params) = $this->getSearchQuery($filter);
|
||||
$filter = [
|
||||
'status' => 'received',
|
||||
];
|
||||
[$sql, $params] = $this->getSearchQuery($filter);
|
||||
|
||||
return $this->di['db']->getAll($sql, $params);
|
||||
}
|
||||
@@ -395,7 +406,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
{
|
||||
$transaction = $this->di['db']->load('Transaction', $tx->id);
|
||||
|
||||
if($this->_isProcessed($transaction)) {
|
||||
if ($this->_isProcessed($transaction)) {
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
@@ -420,17 +431,21 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Box_Exception('Unknown transaction #:id type: :type', array(':id'=>$transaction->id, ':type'=>$transaction->type), 632);
|
||||
throw new \Box_Exception('Unknown transaction #:id type: :type', [':id' => $transaction->id, ':type' => $transaction->type], 632);
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$transaction->status = \Model_Transaction::STATUS_ERROR;
|
||||
$transaction->error = $e->getMessage();
|
||||
$transaction->error_code = $e->getCode();
|
||||
$transaction->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($transaction);
|
||||
|
||||
if(BB_DEBUG) error_log($e->getMessage());
|
||||
if(APPLICATION_ENV == 'testing') throw $e;
|
||||
if (BB_DEBUG) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
if (APPLICATION_ENV == 'testing') {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return $transaction;
|
||||
@@ -438,21 +453,22 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
|
||||
private function _isProcessed(\Model_Transaction $tx)
|
||||
{
|
||||
if($tx->status == \Model_Transaction::STATUS_PROCESSED) {
|
||||
$tx->error = NULL;
|
||||
$tx->error_code = NULL;
|
||||
if (\Model_Transaction::STATUS_PROCESSED == $tx->status) {
|
||||
$tx->error = null;
|
||||
$tx->error_code = null;
|
||||
$tx->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($tx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($this->hasProcessedTransaction($tx)) {
|
||||
|
||||
$tx->note .= 'Transaction was marked as processed. Transaction with same ID is already processed';
|
||||
if ($this->hasProcessedTransaction($tx)) {
|
||||
$tx->note .= 'Transaction was marked as processed. Transaction with same ID is already processed';
|
||||
$tx->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($tx);
|
||||
|
||||
$this->_markAsProcessed($tx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -461,18 +477,19 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
|
||||
private function hasProcessedTransaction(\Model_Transaction $tx)
|
||||
{
|
||||
if(!$tx->txn_id) {
|
||||
if (!$tx->txn_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->di['db']->findOne('Transaction', 'status = "processed" and txn_id = ?', array($tx->txn_id));
|
||||
$res = $this->di['db']->findOne('Transaction', 'status = "processed" and txn_id = ?', [$tx->txn_id]);
|
||||
|
||||
return empty($res);
|
||||
}
|
||||
|
||||
private function _markAsProcessed(\Model_Transaction $tx)
|
||||
{
|
||||
$tx->error = NULL;
|
||||
$tx->error_code = NULL;
|
||||
$tx->error = null;
|
||||
$tx->error_code = null;
|
||||
$tx->status = \Model_Transaction::STATUS_PROCESSED;
|
||||
$tx->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($tx);
|
||||
@@ -480,7 +497,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
|
||||
private function _parseIpnAndApprove(\Model_Transaction &$tx)
|
||||
{
|
||||
if($tx->status == \Model_Transaction::STATUS_APPROVED) {
|
||||
if (\Model_Transaction::STATUS_APPROVED == $tx->status) {
|
||||
return $tx;
|
||||
}
|
||||
|
||||
@@ -488,63 +505,63 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$payGatewayService = $this->di['mod_service']('Invoice', 'PayGateway');
|
||||
$ipn = $this->di['tools']->decodeJ($tx->ipn);
|
||||
|
||||
if(empty($tx->gateway_id)) {
|
||||
if (empty($tx->gateway_id)) {
|
||||
throw new \Box_Exception('Could not determine transaction origin. Transaction payment gateway is unknown.', null, 701);
|
||||
}
|
||||
|
||||
$gtw = $this->di['db']->load('PayGateway', $tx->gateway_id);
|
||||
if(!$gtw instanceof \Model_PayGateway) {
|
||||
throw new \Box_Exception('Can not handle transaction received from unknown payment gateway: :id', array(':id'=>$tx->gateway_id), 704);
|
||||
if (!$gtw instanceof \Model_PayGateway) {
|
||||
throw new \Box_Exception('Can not handle transaction received from unknown payment gateway: :id', [':id' => $tx->gateway_id], 704);
|
||||
}
|
||||
|
||||
$adapter = $payGatewayService->getPaymentAdapter($gtw);
|
||||
if(!$tx->invoice_id && method_exists($adapter, 'getInvoiceId')) {
|
||||
if (!$tx->invoice_id && method_exists($adapter, 'getInvoiceId')) {
|
||||
$tx->invoice_id = $adapter->getInvoiceId($ipn);
|
||||
}
|
||||
|
||||
if(!$tx->invoice_id) {
|
||||
throw new \Box_Exception('Transaction :id is not associated with an invoice.', array(':id'=>$tx->id), 702);
|
||||
if (!$tx->invoice_id) {
|
||||
throw new \Box_Exception('Transaction :id is not associated with an invoice.', [':id' => $tx->id], 702);
|
||||
}
|
||||
|
||||
$invoice = $this->di['db']->load('Invoice', $tx->invoice_id);
|
||||
if(!$invoice instanceof \Model_Invoice) {
|
||||
throw new \Box_Exception('Invoice #:id not found', array(':id'=>$tx->invoice_id), 703);
|
||||
if (!$invoice instanceof \Model_Invoice) {
|
||||
throw new \Box_Exception('Invoice #:id not found', [':id' => $tx->invoice_id], 703);
|
||||
}
|
||||
|
||||
$adapter = $payGatewayService->getPaymentAdapter($gtw, $invoice);
|
||||
$mpi = $invoiceService->getPaymentInvoice($invoice);
|
||||
|
||||
if(APPLICATION_ENV != 'testing' && $tx->validate_ipn) {
|
||||
if(!$adapter->isIpnValid($ipn, $mpi)) {
|
||||
$tx->output = $adapter->getOutput();
|
||||
throw new \Box_Exception('Instant payment notification (IPN) did not pass gateway :id validation', array(':id'=>$gtw->gateway), 706);
|
||||
if (APPLICATION_ENV != 'testing' && $tx->validate_ipn) {
|
||||
if (!$adapter->isIpnValid($ipn, $mpi)) {
|
||||
$tx->output = $adapter->getOutput();
|
||||
throw new \Box_Exception('Instant payment notification (IPN) did not pass gateway :id validation', [':id' => $gtw->gateway], 706);
|
||||
}
|
||||
$tx->output = $adapter->getOutput();
|
||||
$tx->output = $adapter->getOutput();
|
||||
}
|
||||
|
||||
if(!method_exists($adapter, 'getTransaction')) {
|
||||
throw new \Box_Exception('Payment adapter :adapter does not support action :action', array(':adapter'=>$gtw->name, ':action'=>'getTransaction'), 705);
|
||||
if (!method_exists($adapter, 'getTransaction')) {
|
||||
throw new \Box_Exception('Payment adapter :adapter does not support action :action', [':adapter' => $gtw->name, ':action' => 'getTransaction'], 705);
|
||||
}
|
||||
|
||||
$response = $adapter->getTransaction($ipn, $mpi);
|
||||
if(!$response instanceof \Payment_Transaction) {
|
||||
throw new \Box_Exception('Payment gateway :id method getTransaction should return Payment_Transaction object', array(':id'=>$gtw->gateway), 705);
|
||||
if (!$response instanceof \Payment_Transaction) {
|
||||
throw new \Box_Exception('Payment gateway :id method getTransaction should return Payment_Transaction object', [':id' => $gtw->gateway], 705);
|
||||
}
|
||||
|
||||
// if tx type is already defined, do not set them again
|
||||
if($response->getType()) {
|
||||
$tx->type = $response->getType();
|
||||
if ($response->getType()) {
|
||||
$tx->type = $response->getType();
|
||||
}
|
||||
|
||||
if($response->getId()) {
|
||||
$tx->txn_id = $response->getId();
|
||||
if ($response->getId()) {
|
||||
$tx->txn_id = $response->getId();
|
||||
}
|
||||
|
||||
if($response->getStatus()) {
|
||||
$tx->txn_status = $response->getStatus();
|
||||
if ($response->getStatus()) {
|
||||
$tx->txn_status = $response->getStatus();
|
||||
}
|
||||
|
||||
if($response->getSubscriptionId()) {
|
||||
if ($response->getSubscriptionId()) {
|
||||
$tx->s_id = $response->getSubscriptionId();
|
||||
}
|
||||
|
||||
@@ -556,7 +573,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$tx->currency = $response->getCurrency();
|
||||
}
|
||||
|
||||
$tx->status = \Model_Transaction::STATUS_APPROVED;
|
||||
$tx->status = \Model_Transaction::STATUS_APPROVED;
|
||||
$tx->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($tx);
|
||||
|
||||
@@ -565,7 +582,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
|
||||
private function _debit(\Model_Transaction $tx)
|
||||
{
|
||||
if($this->_isProcessed($tx)) {
|
||||
if ($this->_isProcessed($tx)) {
|
||||
return $tx;
|
||||
}
|
||||
|
||||
@@ -576,12 +593,12 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$this->_markAsProcessed($tx);
|
||||
|
||||
// try pay for invoice after debit
|
||||
if($tx->invoice_id) {
|
||||
if ($tx->invoice_id) {
|
||||
try {
|
||||
$invoiceService = $this->di['mod_service']('Invoice');
|
||||
$invoiceService->tryPayWithCredits($tx->Invoice);
|
||||
} catch(\Exception $e) {
|
||||
if($this->di['config']['debug']){
|
||||
} catch (\Exception $e) {
|
||||
if ($this->di['config']['debug']) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -590,7 +607,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
|
||||
private function _refund(\Model_Transaction $tx)
|
||||
{
|
||||
if($this->_isProcessed($tx)) {
|
||||
if ($this->_isProcessed($tx)) {
|
||||
return $tx;
|
||||
}
|
||||
|
||||
@@ -603,18 +620,19 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$invoiceService->refund($invoice, $note);
|
||||
|
||||
$this->_markAsProcessed($tx);
|
||||
|
||||
return $tx;
|
||||
}
|
||||
|
||||
private function _subscribe(\Model_Transaction $tx)
|
||||
{
|
||||
if($this->_isProcessed($tx)) {
|
||||
if ($this->_isProcessed($tx)) {
|
||||
return $tx;
|
||||
}
|
||||
|
||||
$this->_validateApprovedTransaction($tx);
|
||||
|
||||
if(empty($tx->s_id)) {
|
||||
if (empty($tx->s_id)) {
|
||||
throw new \Box_Exception('Can not create subscription. Subscription id from payment gateway was not received');
|
||||
}
|
||||
|
||||
@@ -637,62 +655,63 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$this->di['db']->store($s);
|
||||
|
||||
$this->_markAsProcessed($tx);
|
||||
|
||||
return $tx;
|
||||
}
|
||||
|
||||
private function _unsubscribe(\Model_Transaction $tx)
|
||||
{
|
||||
if($this->_isProcessed($tx)) {
|
||||
if ($this->_isProcessed($tx)) {
|
||||
return $tx;
|
||||
}
|
||||
|
||||
|
||||
$serviceSubscription = $this->di['mod_service']("Subscription");
|
||||
$serviceSubscription = $this->di['mod_service']('Subscription');
|
||||
$model = $this->di['db']->load('Subscription', $tx->s_id);
|
||||
if(!$model instanceof \Model_Subscription) {
|
||||
throw new \Box_Exception('Subscription #:id was not found. Could not unsubscribe', array(':id'=>$tx->s_id));
|
||||
if (!$model instanceof \Model_Subscription) {
|
||||
throw new \Box_Exception('Subscription #:id was not found. Could not unsubscribe', [':id' => $tx->s_id]);
|
||||
}
|
||||
|
||||
$serviceSubscription->unsubscribe($model);
|
||||
|
||||
$this->_markAsProcessed($tx);
|
||||
|
||||
return $tx;
|
||||
}
|
||||
|
||||
private function _validateApprovedTransaction(\Model_Transaction $tx)
|
||||
{
|
||||
if($tx->status != \Model_Transaction::STATUS_APPROVED) {
|
||||
if (\Model_Transaction::STATUS_APPROVED != $tx->status) {
|
||||
throw new \Box_Exception('Only approved transaction can be processed');
|
||||
}
|
||||
|
||||
if(empty($tx->invoice_id)) {
|
||||
throw new \Box_Exception('Transaction :id is not associated with an invoice.', array(':id'=>$tx->id), 7022);
|
||||
if (empty($tx->invoice_id)) {
|
||||
throw new \Box_Exception('Transaction :id is not associated with an invoice.', [':id' => $tx->id], 7022);
|
||||
}
|
||||
|
||||
$invoice = $this->di['db']->load('Invoice', $tx->invoice_id);
|
||||
|
||||
// check that payment currency is correct
|
||||
if($invoice->currency != $tx->currency) {
|
||||
throw new \Box_Exception('Transaction currency :code do not match required currency :required', array(':code'=>$tx->currency, ':required'=>$invoice->currency), 709);
|
||||
if ($invoice->currency != $tx->currency) {
|
||||
throw new \Box_Exception('Transaction currency :code do not match required currency :required', [':code' => $tx->currency, ':required' => $invoice->currency], 709);
|
||||
}
|
||||
|
||||
// check that payment status is completed if
|
||||
if($tx->txn_status == \Payment_Transaction::STATUS_PENDING) {
|
||||
if (\Payment_Transaction::STATUS_PENDING == $tx->txn_status) {
|
||||
throw new \Box_Exception('Transaction status on payment gateway is Pending. Only Complete or Unknown transactions can be processed.', null, 712);
|
||||
}
|
||||
}
|
||||
|
||||
public function debitTransaction(\Model_Transaction $tx)
|
||||
{
|
||||
$proforma = $this->di['db']->load('Invoice', $tx->invoice_id);
|
||||
$client = $this->di['db']->load('Client', $proforma->client_id);
|
||||
$proforma = $this->di['db']->load('Invoice', $tx->invoice_id);
|
||||
$client = $this->di['db']->load('Client', $proforma->client_id);
|
||||
|
||||
if($client->currency != $proforma->currency) {
|
||||
if ($client->currency != $proforma->currency) {
|
||||
throw new \Box_Exception('Client currency do not match invoice currency');
|
||||
}
|
||||
|
||||
// do not debit negative or zero amount
|
||||
if($tx->amount < 0) {
|
||||
if ($tx->amount < 0) {
|
||||
throw new \Box_Exception('Can not add negative amount to client balance for debit transaction');
|
||||
}
|
||||
|
||||
@@ -700,11 +719,10 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$credit->client_id = $client->id;
|
||||
$credit->type = 'transaction';
|
||||
$credit->rel_id = $tx->id;
|
||||
$credit->description = "Invoice #".$proforma->id . ' payment received from transaction #'.$tx->id;
|
||||
$credit->description = 'Invoice #'.$proforma->id.' payment received from transaction #'.$tx->id;
|
||||
$credit->amount = $tx->amount;
|
||||
$credit->created_at = date('Y-m-d H:i:s');
|
||||
$credit->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($credit);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Knowledge base API
|
||||
* Knowledge base API.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Kb\Api;
|
||||
@@ -19,7 +19,7 @@ namespace Box\Mod\Kb\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of knowledge base articles
|
||||
* Get paginated list of knowledge base articles.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -27,12 +27,12 @@ class Admin extends \Api_Abstract
|
||||
{
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$cat = $this->di['array_get']($data, 'cat', null);
|
||||
$cat = $this->di['array_get']($data, 'cat', null);
|
||||
|
||||
$pager = $this->getService()->searchArticles($status, $search, $cat);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$article = $this->di['db']->getExistingModelById('KbArticle', $item['id'], 'KB Article not found');
|
||||
$article = $this->di['db']->getExistingModelById('KbArticle', $item['id'], 'KB Article not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($article);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get knowledge base article
|
||||
* Get knowledge base article.
|
||||
*
|
||||
* @param int $id - knowledge base article ID
|
||||
*
|
||||
@@ -48,12 +48,12 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function article_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Article id not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('KbArticle', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('KbArticle', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_KbArticle) {
|
||||
throw new \Box_Exception('Article not found');
|
||||
@@ -63,10 +63,10 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new knowledge base article
|
||||
* Create new knowledge base article.
|
||||
*
|
||||
* @param int $kb_article_category_id - knowledge base category ID
|
||||
* @param string $title - knowledge base article title
|
||||
* @param int $kb_article_category_id - knowledge base category ID
|
||||
* @param string $title - knowledge base article title
|
||||
*
|
||||
* @optional string $status - knowledge base article status
|
||||
* @optional string $content - knowledge base article content
|
||||
@@ -75,22 +75,22 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function article_create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'kb_article_category_id' => 'Article category id not passed',
|
||||
'title' => 'Article title not passed',
|
||||
);
|
||||
'title' => 'Article title not passed',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$articleCategoryId = $data['kb_article_category_id'];
|
||||
$title = $data['title'];
|
||||
$status = isset($data['status']) ? $data['status'] : \Model_KbArticle::DRAFT;
|
||||
$content = $this->di['array_get']($data, 'content', NULL);
|
||||
$title = $data['title'];
|
||||
$status = $data['status'] ?? \Model_KbArticle::DRAFT;
|
||||
$content = $this->di['array_get']($data, 'content', null);
|
||||
|
||||
return $this->getService()->createArticle($articleCategoryId, $title, $status, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update knowledge base article
|
||||
* Update knowledge base article.
|
||||
*
|
||||
* @param int $id - knowledge base article ID
|
||||
*
|
||||
@@ -105,24 +105,23 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function article_update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Article ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$articleCategoryId = $this->di['array_get']($data, 'kb_article_category_id', null);
|
||||
$title = $this->di['array_get']($data, 'title', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
$content = $this->di['array_get']($data, 'content', null);
|
||||
$views = $this->di['array_get']($data, 'views', null);
|
||||
|
||||
$title = $this->di['array_get']($data, 'title', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
$content = $this->di['array_get']($data, 'content', null);
|
||||
$views = $this->di['array_get']($data, 'views', null);
|
||||
|
||||
return $this->getService()->updateArticle($data['id'], $articleCategoryId, $title, $slug, $status, $content, $views);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete knowledge base article
|
||||
* Delete knowledge base article.
|
||||
*
|
||||
* @param int $id - knowledge base article ID
|
||||
*
|
||||
@@ -130,12 +129,12 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function article_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Article ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('KbArticle', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('KbArticle', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_KbArticle) {
|
||||
throw new \Box_Exception('Article not found');
|
||||
@@ -147,18 +146,18 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated list of knowledge base categories
|
||||
* Get paginated list of knowledge base categories.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function category_get_list($data)
|
||||
{
|
||||
list($sql, $bindings) = $this->getService()->categoryGetSearchQuery($data);
|
||||
[$sql, $bindings] = $this->getService()->categoryGetSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getAdvancedResultSet($sql, $bindings, $per_page);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$category = $this->di['db']->getExistingModelById('KbArticleCategory', $item['id'], 'KB Article not found');
|
||||
$category = $this->di['db']->getExistingModelById('KbArticleCategory', $item['id'], 'KB Article not found');
|
||||
$pager['list'][$key] = $this->getService()->categoryToApiArray($category, $this->getIdentity());
|
||||
}
|
||||
|
||||
@@ -166,7 +165,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get knowledge base category
|
||||
* Get knowledge base category.
|
||||
*
|
||||
* @param int $id - knowledge base category ID
|
||||
*
|
||||
@@ -174,12 +173,12 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function category_get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Category ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_KbArticleCategory) {
|
||||
throw new \Box_Exception('Article Category not found');
|
||||
@@ -189,7 +188,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new knowledge base category
|
||||
* Create new knowledge base category.
|
||||
*
|
||||
* @param string $title - knowledge base category title
|
||||
*
|
||||
@@ -199,19 +198,19 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function category_create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'title' => 'Category title not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$title = $data['title'];
|
||||
$description = $this->di['array_get']($data, 'description', NULL);
|
||||
$title = $data['title'];
|
||||
$description = $this->di['array_get']($data, 'description', null);
|
||||
|
||||
return $this->getService()->createCategory($title, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update knowledge base category
|
||||
* Update knowledge base category.
|
||||
*
|
||||
* @param int $id - knowledge base category ID
|
||||
*
|
||||
@@ -223,26 +222,26 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function category_update($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Category ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_KbArticleCategory) {
|
||||
throw new \Box_Exception('Article Category not found');
|
||||
}
|
||||
|
||||
$title = $this->di['array_get']($data, 'title', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$description = $this->di['array_get']($data, 'description', NULL);
|
||||
$title = $this->di['array_get']($data, 'title', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
$description = $this->di['array_get']($data, 'description', null);
|
||||
|
||||
return $this->getService()->updateCategory($model, $title, $slug, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete knowledge base category
|
||||
* Delete knowledge base category.
|
||||
*
|
||||
* @param int $id - knowledge base category ID
|
||||
*
|
||||
@@ -250,12 +249,12 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function category_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Category ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', array($data['id']));
|
||||
$model = $this->di['db']->findOne('KbArticleCategory', 'id = ?', [$data['id']]);
|
||||
|
||||
if (!$model instanceof \Model_KbArticleCategory) {
|
||||
throw new \Box_Exception('Category not found');
|
||||
@@ -265,7 +264,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get knowledge base categories id, title pairs
|
||||
* Get knowledge base categories id, title pairs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -273,4 +272,4 @@ class Admin extends \Api_Abstract
|
||||
{
|
||||
return $this->getService()->categoryGetPairs();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Knowledge base API
|
||||
* Knowledge base API.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Kb\Api;
|
||||
@@ -28,16 +28,16 @@ class Guest extends \Api_Abstract
|
||||
{
|
||||
$data['status'] = 'active';
|
||||
|
||||
$status = $this->di['array_get']($data, 'status', NULL);
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$cat = $this->di['array_get']($data, 'kb_article_category_id', NULL);
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$cat = $this->di['array_get']($data, 'kb_article_category_id', null);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$page = $this->di['array_get']($data, 'page');
|
||||
|
||||
$pager = $this->getService()->searchArticles($status, $search, $cat, $per_page, $page);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$article = $this->di['db']->getExistingModelById('KbArticle', $item['id'], 'KB Article not found');
|
||||
$article = $this->di['db']->getExistingModelById('KbArticle', $item['id'], 'KB Article not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($article);
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active knowledge base article
|
||||
* Get active knowledge base article.
|
||||
*
|
||||
* @param int $id - knowledge base article ID. Required only if SLUG is not passed.
|
||||
* @param int $id - knowledge base article ID. Required only if SLUG is not passed.
|
||||
* @param string $slug - knowledge base article slug. Required only if ID is not passed.
|
||||
*
|
||||
* @return array
|
||||
@@ -58,10 +58,10 @@ class Guest extends \Api_Abstract
|
||||
throw new \Box_Exception('ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
|
||||
$model = FALSE;
|
||||
$model = false;
|
||||
if ($id) {
|
||||
$model = $this->getService()->findActiveArticleById($id);
|
||||
} else {
|
||||
@@ -77,13 +77,14 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated list of knowledge base categories
|
||||
* Get paginated list of knowledge base categories.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function category_get_list($data)
|
||||
{
|
||||
$data['article_status'] = \Model_KbArticle::ACTIVE;
|
||||
list($query, $bindings) = $this->getService()->categoryGetSearchQuery($data);
|
||||
[$query, $bindings] = $this->getService()->categoryGetSearchQuery($data);
|
||||
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getAdvancedResultSet($query, $bindings, $per_page);
|
||||
@@ -91,14 +92,15 @@ class Guest extends \Api_Abstract
|
||||
$q = $this->di['array_get']($data, 'q', null);
|
||||
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$category = $this->di['db']->getExistingModelById('KbArticleCategory', $item['id'], 'KB Article not found');
|
||||
$category = $this->di['db']->getExistingModelById('KbArticleCategory', $item['id'], 'KB Article not found');
|
||||
$pager['list'][$key] = $this->getService()->categoryToApiArray($category, $this->getIdentity(), $q);
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get knowledge base categories id, title pairs
|
||||
* Get knowledge base categories id, title pairs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -108,9 +110,9 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get knowledge base category by ID or SLUG
|
||||
* Get knowledge base category by ID or SLUG.
|
||||
*
|
||||
* @param int $id - knowledge base category ID. Required only if SLUG is not passed.
|
||||
* @param int $id - knowledge base category ID. Required only if SLUG is not passed.
|
||||
* @param string $slug - knowledge base category slug. Required only if ID is not passed.
|
||||
*
|
||||
* @return array
|
||||
@@ -121,11 +123,10 @@ class Guest extends \Api_Abstract
|
||||
throw new \Box_Exception('Category ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
|
||||
|
||||
$model = FALSE;
|
||||
$model = false;
|
||||
if ($id) {
|
||||
$model = $this->getService()->findCategoryById($id);
|
||||
} else {
|
||||
@@ -138,4 +139,4 @@ class Guest extends \Api_Abstract
|
||||
|
||||
return $this->getService()->categoryToApiArray($model, $this->getIdentity());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Kb\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,52 +34,54 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'group' => array(
|
||||
return [
|
||||
'group' => [
|
||||
'index' => 501,
|
||||
'location' => 'kb',
|
||||
'label' => 'Knowledge Base',
|
||||
'uri' => $this->di['url']->adminLink('kb'),
|
||||
'class' => 'support',
|
||||
'sprite_class' => 'dark-sprite-icon sprite-docs',
|
||||
),
|
||||
'subpages' => array(
|
||||
array(
|
||||
'location' => 'kb',
|
||||
'index' => 800,
|
||||
],
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'kb',
|
||||
'index' => 800,
|
||||
'label' => 'Knowledge Base',
|
||||
'uri' => $this->di['url']->adminLink('kb'),
|
||||
'uri' => $this->di['url']->adminLink('kb'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/kb', 'get_index', array(), get_class($this));
|
||||
$app->get('/kb/article/:id', 'get_post', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/kb/category/:id', 'get_cat', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/kb', 'get_index', [], get_class($this));
|
||||
$app->get('/kb/article/:id', 'get_post', ['id' => '[0-9]+'], get_class($this));
|
||||
$app->get('/kb/category/:id', 'get_cat', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_kb_index');
|
||||
}
|
||||
|
||||
|
||||
public function get_post(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$post = $api->kb_article_get(array('id'=>$id));
|
||||
return $app->render('mod_kb_article', array('post'=>$post));
|
||||
$post = $api->kb_article_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_kb_article', ['post' => $post]);
|
||||
}
|
||||
|
||||
public function get_cat(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$cat = $api->kb_category_get(array('id'=>$id));
|
||||
return $app->render('mod_kb_category', array('category'=>$cat));
|
||||
}
|
||||
$cat = $api->kb_category_get(['id' => $id]);
|
||||
|
||||
}
|
||||
return $app->render('mod_kb_category', ['category' => $cat]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Kb\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,9 +34,9 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/kb', 'get_kb', array(), get_class($this));
|
||||
$app->get('/kb/:category', 'get_kb_category', array('category' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/kb/:category/:slug', 'get_kb_article', array('category' => '[a-z0-9-]+', 'slug' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/kb', 'get_kb', [], get_class($this));
|
||||
$app->get('/kb/:category', 'get_kb_category', ['category' => '[a-z0-9-]+'], get_class($this));
|
||||
$app->get('/kb/:category/:slug', 'get_kb_article', ['category' => '[a-z0-9-]+', 'slug' => '[a-z0-9-]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_kb(\Box_App $app)
|
||||
@@ -48,16 +47,18 @@ class Client implements \Box\InjectionAwareInterface
|
||||
public function get_kb_category(\Box_App $app, $category)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array('slug'=>$category);
|
||||
$data = ['slug' => $category];
|
||||
$model = $api->kb_category_get($data);
|
||||
return $app->render('mod_kb_category', array('category'=>$model));
|
||||
|
||||
return $app->render('mod_kb_category', ['category' => $model]);
|
||||
}
|
||||
|
||||
public function get_kb_article(\Box_App $app, $category, $slug)
|
||||
{
|
||||
$api = $this->di['api_guest'];
|
||||
$data = array('slug'=>$slug);
|
||||
$data = ['slug' => $slug];
|
||||
$article = $api->kb_article_get($data);
|
||||
return $app->render('mod_kb_article', array('article'=>$article));
|
||||
|
||||
return $app->render('mod_kb_article', ['article' => $article]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Kb;
|
||||
|
||||
class Service
|
||||
@@ -27,63 +26,62 @@ class Service
|
||||
|
||||
public function searchArticles($status = null, $search = null, $cat = null, $per_page = 100, $page = null)
|
||||
{
|
||||
$filter = array();
|
||||
$filter = [];
|
||||
|
||||
$sql = "
|
||||
$sql = '
|
||||
SELECT *
|
||||
FROM kb_article
|
||||
WHERE 1
|
||||
";
|
||||
';
|
||||
|
||||
if ($cat) {
|
||||
$sql .= " AND kb_article_category_id = :cid";
|
||||
$sql .= ' AND kb_article_category_id = :cid';
|
||||
$filter[':cid'] = $cat;
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$sql .= " AND status = :status";
|
||||
$sql .= ' AND status = :status';
|
||||
$filter[':status'] = $status;
|
||||
}
|
||||
|
||||
if ($search) {
|
||||
$sql .= " AND title LIKE :q OR content LIKE :q";
|
||||
$sql .= ' AND title LIKE :q OR content LIKE :q';
|
||||
$filter[':q'] = "%$search%";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY kb_article_category_id DESC, views DESC";
|
||||
$sql .= ' ORDER BY kb_article_category_id DESC, views DESC';
|
||||
|
||||
return $this->di['pager']->getSimpleResultSet($sql, $filter, $per_page, $page);
|
||||
}
|
||||
|
||||
|
||||
public function findActiveArticleById($id)
|
||||
{
|
||||
$bindings = array(
|
||||
':id' => $id,
|
||||
':status' => \Model_KbArticle::ACTIVE
|
||||
);
|
||||
$bindings = [
|
||||
':id' => $id,
|
||||
':status' => \Model_KbArticle::ACTIVE,
|
||||
];
|
||||
|
||||
return $this->di['db']->findOne('KbArticle', 'id = :id AND status=:status', $bindings);
|
||||
}
|
||||
|
||||
public function findActiveArticleBySlug($slug)
|
||||
{
|
||||
$bindings = array(
|
||||
':slug' => $slug,
|
||||
':status' => \Model_KbArticle::ACTIVE
|
||||
);
|
||||
$bindings = [
|
||||
':slug' => $slug,
|
||||
':status' => \Model_KbArticle::ACTIVE,
|
||||
];
|
||||
|
||||
return $this->di['db']->findOne('KbArticle', 'slug = :slug AND status=:status', $bindings);
|
||||
}
|
||||
|
||||
public function findActive()
|
||||
{
|
||||
return $this->di['db']->find('KbArticle', 'status=:status', array(':status' => \Model_KbArticle::ACTIVE));
|
||||
return $this->di['db']->find('KbArticle', 'status=:status', [':status' => \Model_KbArticle::ACTIVE]);
|
||||
}
|
||||
|
||||
public function hitView(\Model_KbArticle $model)
|
||||
{
|
||||
$model->views++;
|
||||
++$model->views;
|
||||
$this->di['db']->store($model);
|
||||
}
|
||||
|
||||
@@ -96,29 +94,29 @@ class Service
|
||||
|
||||
public function toApiArray(\Model_KbArticle $model, $deep = false, $identity = null)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $model->id,
|
||||
'slug' => $model->slug,
|
||||
'title' => $model->title,
|
||||
'views' => $model->views,
|
||||
$data = [
|
||||
'id' => $model->id,
|
||||
'slug' => $model->slug,
|
||||
'title' => $model->title,
|
||||
'views' => $model->views,
|
||||
'created_at' => $model->created_at,
|
||||
'status' => $model->status,
|
||||
'status' => $model->status,
|
||||
'updated_at' => $model->updated_at,
|
||||
);
|
||||
];
|
||||
|
||||
$cat = $this->di['db']->getExistingModelById('KbArticleCategory', $model->kb_article_category_id, 'Knowledge Base category not found');
|
||||
$data['category'] = array(
|
||||
'id' => $cat->id,
|
||||
'slug' => $cat->slug,
|
||||
$data['category'] = [
|
||||
'id' => $cat->id,
|
||||
'slug' => $cat->slug,
|
||||
'title' => $cat->title,
|
||||
);
|
||||
];
|
||||
|
||||
if ($deep) {
|
||||
$data['content'] = $model->content;
|
||||
}
|
||||
|
||||
if ($identity instanceof \Model_Admin) {
|
||||
$data['status'] = $model->status;
|
||||
$data['status'] = $model->status;
|
||||
$data['kb_article_category_id'] = $model->kb_article_category_id;
|
||||
}
|
||||
|
||||
@@ -127,19 +125,19 @@ class Service
|
||||
|
||||
public function createArticle($articleCategoryId, $title, $status = null, $content = null)
|
||||
{
|
||||
if(!isset($status)){
|
||||
if (!isset($status)) {
|
||||
$status = \Model_KbArticle::DRAFT;
|
||||
}
|
||||
|
||||
$model = $this->di['db']->dispense('KbArticle');
|
||||
$model = $this->di['db']->dispense('KbArticle');
|
||||
$model->kb_article_category_id = $articleCategoryId;
|
||||
$model->title = $title;
|
||||
$model->slug = $this->di['tools']->slug($title);
|
||||
$model->status = $status;
|
||||
$model->content = $content;
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$id = $this->di['db']->store($model);
|
||||
$model->title = $title;
|
||||
$model->slug = $this->di['tools']->slug($title);
|
||||
$model->status = $status;
|
||||
$model->content = $content;
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$id = $this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Created new knowledge base article #%s', $id);
|
||||
|
||||
@@ -148,7 +146,7 @@ class Service
|
||||
|
||||
public function updateArticle($id, $articleCategoryId = null, $title = null, $slug = null, $status = null, $content = null, $views = null)
|
||||
{
|
||||
$model = $this->di['db']->findOne('KbArticle', 'id = ?', array($id));
|
||||
$model = $this->di['db']->findOne('KbArticle', 'id = ?', [$id]);
|
||||
|
||||
if (!$model instanceof \Model_KbArticle) {
|
||||
throw new \Box_Exception('Article not found');
|
||||
@@ -188,52 +186,52 @@ class Service
|
||||
|
||||
public function categoryGetSearchQuery($data)
|
||||
{
|
||||
$sql = "
|
||||
$sql = '
|
||||
SELECT kac.*
|
||||
FROM kb_article_category kac
|
||||
LEFT JOIN kb_article ka ON kac.id = ka.kb_article_category_id";
|
||||
LEFT JOIN kb_article ka ON kac.id = ka.kb_article_category_id';
|
||||
|
||||
$article_status = $this->di['array_get']($data, 'article_status', NULL);
|
||||
$query = $this->di['array_get']($data, 'q', NULL);
|
||||
$article_status = $this->di['array_get']($data, 'article_status', null);
|
||||
$query = $this->di['array_get']($data, 'q', null);
|
||||
|
||||
$where = array();
|
||||
$bindings = array();
|
||||
$where = [];
|
||||
$bindings = [];
|
||||
if ($article_status) {
|
||||
$where[] = "ka.status = :status";
|
||||
$where[] = 'ka.status = :status';
|
||||
|
||||
$bindings[':status'] = $article_status;
|
||||
}
|
||||
|
||||
if ($query) {
|
||||
$where[] = "(ka.title LIKE :title OR ka.content LIKE :content)";
|
||||
$where[] = '(ka.title LIKE :title OR ka.content LIKE :content)';
|
||||
|
||||
$bindings[':title'] = "%$query%";
|
||||
$bindings[':title'] = "%$query%";
|
||||
$bindings[':content'] = "%$query%";
|
||||
}
|
||||
|
||||
if (!empty($where)) {
|
||||
$sql = $sql . ' WHERE ' . implode(' AND ', $where);
|
||||
$sql = $sql.' WHERE '.implode(' AND ', $where);
|
||||
}
|
||||
|
||||
$sql = $sql . " GROUP BY kac.id ORDER BY kac.id DESC";
|
||||
$sql = $sql.' GROUP BY kac.id ORDER BY kac.id DESC';
|
||||
|
||||
return array($sql, $bindings);
|
||||
return [$sql, $bindings];
|
||||
}
|
||||
|
||||
public function categoryFindAll()
|
||||
{
|
||||
$sql = "SELECT kac.*, a.*
|
||||
$sql = 'SELECT kac.*, a.*
|
||||
FROM kb_article_category kac
|
||||
LEFT JOIN kb_article ka
|
||||
ON kac.id = ka.kb_article_category_id
|
||||
";
|
||||
';
|
||||
|
||||
return $this->di['db']->getAll($sql);
|
||||
}
|
||||
|
||||
public function categoryGetPairs()
|
||||
{
|
||||
$sql = "SELECT id, title FROM kb_article_category";
|
||||
$sql = 'SELECT id, title FROM kb_article_category';
|
||||
$pairs = $this->di['db']->getAssoc($sql);
|
||||
|
||||
return $pairs;
|
||||
@@ -241,11 +239,11 @@ class Service
|
||||
|
||||
public function categoryRm(\Model_KbArticleCategory $model)
|
||||
{
|
||||
$bindings = array(
|
||||
':kb_article_category_id' => $model->id
|
||||
);
|
||||
$bindings = [
|
||||
':kb_article_category_id' => $model->id,
|
||||
];
|
||||
|
||||
$articlesCount = $this->di['db']->getCell("SELECT count(*) as cnt FROM kb_article WHERE kb_article_category_id = :kb_article_category_id", $bindings);
|
||||
$articlesCount = $this->di['db']->getCell('SELECT count(*) as cnt FROM kb_article WHERE kb_article_category_id = :kb_article_category_id', $bindings);
|
||||
|
||||
if ($articlesCount > 0) {
|
||||
throw new \Box_Exception('Can not remove category which has articles');
|
||||
@@ -264,17 +262,17 @@ class Service
|
||||
{
|
||||
$data = $this->di['db']->toArray($model);
|
||||
|
||||
$sql = "kb_article_category_id = :category_id";
|
||||
$bindings = array(
|
||||
':category_id' => $model->id
|
||||
);
|
||||
$sql = 'kb_article_category_id = :category_id';
|
||||
$bindings = [
|
||||
':category_id' => $model->id,
|
||||
];
|
||||
|
||||
if (!$identity instanceof \Model_Admin){
|
||||
if (!$identity instanceof \Model_Admin) {
|
||||
$sql .= " AND status = 'active'";
|
||||
}
|
||||
|
||||
if ($query){
|
||||
$sql .= "AND (title LIKE :title OR content LIKE :content)";
|
||||
if ($query) {
|
||||
$sql .= 'AND (title LIKE :title OR content LIKE :content)';
|
||||
$query = "%$query%";
|
||||
$bindings[':content'] = $query;
|
||||
$bindings[':title'] = $query;
|
||||
@@ -294,12 +292,12 @@ class Service
|
||||
$systemService = $this->di['mod_service']('system');
|
||||
$systemService->checkLimits('Model_KbArticleCategory', 2);
|
||||
|
||||
$model = $this->di['db']->dispense('KbArticleCategory');
|
||||
$model->title = $title;
|
||||
$model = $this->di['db']->dispense('KbArticleCategory');
|
||||
$model->title = $title;
|
||||
$model->description = $description;
|
||||
$model->slug = $this->di['tools']->slug($title);
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->slug = $this->di['tools']->slug($title);
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
|
||||
$id = $this->di['db']->store($model);
|
||||
|
||||
@@ -338,10 +336,10 @@ class Service
|
||||
|
||||
public function findCategoryBySlug($slug)
|
||||
{
|
||||
$bindings = array(
|
||||
':slug' => $slug,
|
||||
);
|
||||
$bindings = [
|
||||
':slug' => $slug,
|
||||
];
|
||||
|
||||
return $this->di['db']->findOne('KbArticleCategory', 'slug = :slug', $bindings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,13 +10,12 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Massmailer\Api;
|
||||
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of active mail messages
|
||||
* Get paginated list of active mail messages.
|
||||
*
|
||||
* @optional string $status - filter list by status
|
||||
* @optional string $search - search query to search for mail messages
|
||||
@@ -25,17 +24,18 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($item);
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mail message by id
|
||||
* Get mail message by id.
|
||||
*
|
||||
* @param int $id - mail message ID
|
||||
*
|
||||
@@ -44,11 +44,12 @@ class Admin extends \Api_Abstract
|
||||
public function get($data)
|
||||
{
|
||||
$model = $this->_getMessage($data);
|
||||
|
||||
return $this->getService()->toApiArray($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update mail message
|
||||
* Update mail message.
|
||||
*
|
||||
* @param int $id - mail message id
|
||||
*
|
||||
@@ -68,18 +69,18 @@ class Admin extends \Api_Abstract
|
||||
$model->content = $this->di['array_get']($data, 'content', $model->content);
|
||||
$model->subject = $this->di['array_get']($data, 'subject', $model->subject);
|
||||
$model->status = $this->di['array_get']($data, 'status', $model->status);
|
||||
if(isset($data['filter'])) {
|
||||
if (isset($data['filter'])) {
|
||||
$model->filter = json_encode($data['filter']);
|
||||
}
|
||||
|
||||
if(isset($data['from_name'])) {
|
||||
if(empty($data['from_name'])) {
|
||||
if (isset($data['from_name'])) {
|
||||
if (empty($data['from_name'])) {
|
||||
throw new \Box_Exception('Message from name can not be empty');
|
||||
}
|
||||
$model->from_name = $data['from_name'];
|
||||
}
|
||||
|
||||
if(isset($data['from_email'])) {
|
||||
if (isset($data['from_email'])) {
|
||||
$this->di['validator']->isEmailValid($data['from_email']);
|
||||
$model->from_email = $data['from_email'];
|
||||
}
|
||||
@@ -88,11 +89,12 @@ class Admin extends \Api_Abstract
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Updated mail message #%s', $model->id);
|
||||
return TRUE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create mail message
|
||||
* Create mail message.
|
||||
*
|
||||
* @param string $subject - mail message subject
|
||||
*
|
||||
@@ -102,9 +104,9 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'subject' => 'Message subject not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$default_content = '{% apply markdown %}
|
||||
@@ -132,7 +134,7 @@ Order our services at {{ "order"|link }}
|
||||
$model->from_email = $company['email'];
|
||||
$model->from_name = $company['name'];
|
||||
$model->subject = $data['subject'];
|
||||
$model->content = isset($data['content']) ? $data['content'] : $default_content;
|
||||
$model->content = $data['content'] ?? $default_content;
|
||||
$model->status = 'draft';
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
@@ -140,11 +142,12 @@ Order our services at {{ "order"|link }}
|
||||
$id = $this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Created mail message #%s', $model->id);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send test mail message by ID to client
|
||||
* Send test mail message by ID to client.
|
||||
*
|
||||
* @param int $id - mail message ID
|
||||
*
|
||||
@@ -155,18 +158,19 @@ Order our services at {{ "order"|link }}
|
||||
$model = $this->_getMessage($data);
|
||||
$client_id = $this->_getTestClientId();
|
||||
|
||||
if(empty($model->content)) {
|
||||
if (empty($model->content)) {
|
||||
throw new \Box_Exception('Add some content before sending message');
|
||||
}
|
||||
|
||||
$this->getService()->sendMessage($model, $client_id);
|
||||
|
||||
$this->di['logger']->info('Sent test mail message #%s to client ', $model->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send mail message by ID
|
||||
* Send mail message by ID.
|
||||
*
|
||||
* @param int $id - mail message ID
|
||||
*
|
||||
@@ -176,25 +180,25 @@ Order our services at {{ "order"|link }}
|
||||
{
|
||||
$model = $this->_getMessage($data);
|
||||
|
||||
if(empty($model->content)) {
|
||||
if (empty($model->content)) {
|
||||
throw new \Box_Exception('Add some content before sending message');
|
||||
}
|
||||
|
||||
$mod = $this->di['mod']('massmailer');
|
||||
$c = $mod->getConfig();
|
||||
$interval = isset($c['interval']) ? (int)$c['interval'] : 30;
|
||||
$max = isset($c['limit']) ? (int)$c['limit'] : 25;
|
||||
$interval = isset($c['interval']) ? (int) $c['interval'] : 30;
|
||||
$max = isset($c['limit']) ? (int) $c['limit'] : 25;
|
||||
|
||||
$clients = $this->getService()->getMessageReceivers($model, $data);
|
||||
foreach($clients as $c) {
|
||||
$d = array(
|
||||
'queue' => 'massmailer',
|
||||
'mod' => 'massmailer',
|
||||
'handler' => 'sendMail',
|
||||
'max' => $max,
|
||||
'interval' => $interval,
|
||||
'params' => array('msg_id'=>$model->id, 'client_id'=>$c['id']),
|
||||
);
|
||||
foreach ($clients as $c) {
|
||||
$d = [
|
||||
'queue' => 'massmailer',
|
||||
'mod' => 'massmailer',
|
||||
'handler' => 'sendMail',
|
||||
'max' => $max,
|
||||
'interval' => $interval,
|
||||
'params' => ['msg_id' => $model->id, 'client_id' => $c['id']],
|
||||
];
|
||||
$this->di['api_admin']->queue_message_add($d);
|
||||
}
|
||||
|
||||
@@ -203,11 +207,12 @@ Order our services at {{ "order"|link }}
|
||||
$id = $this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Added mass mail messages #%s to queue', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy mail message by ID
|
||||
* Copy mail message by ID.
|
||||
*
|
||||
* @param int $id - mail message ID
|
||||
*
|
||||
@@ -217,13 +222,13 @@ Order our services at {{ "order"|link }}
|
||||
{
|
||||
$model = $this->_getMessage($data);
|
||||
|
||||
$copy = $this->di['db']->dispense('mod_massmailer');
|
||||
$copy = $this->di['db']->dispense('mod_massmailer');
|
||||
$copy->from_email = $model->from_email;
|
||||
$copy->from_name = $model->from_name;
|
||||
$copy->subject = $model->subject . ' (Copy)';
|
||||
$copy->content = $model->content;
|
||||
$copy->filter = $model->filter;
|
||||
$copy->status = 'draft';
|
||||
$copy->from_name = $model->from_name;
|
||||
$copy->subject = $model->subject.' (Copy)';
|
||||
$copy->content = $model->content;
|
||||
$copy->filter = $model->filter;
|
||||
$copy->status = 'draft';
|
||||
$copy->created_at = date('Y-m-d H:i:s');
|
||||
$copy->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
@@ -235,7 +240,7 @@ Order our services at {{ "order"|link }}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message receivers list
|
||||
* Get message receivers list.
|
||||
*
|
||||
* @param int $id - mail message ID
|
||||
*
|
||||
@@ -244,11 +249,12 @@ Order our services at {{ "order"|link }}
|
||||
public function receivers($data)
|
||||
{
|
||||
$model = $this->_getMessage($data);
|
||||
|
||||
return $this->getService()->getMessageReceivers($model, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete mail message by ID
|
||||
* Delete mail message by ID.
|
||||
*
|
||||
* @param int $id - mail message ID
|
||||
*
|
||||
@@ -262,11 +268,12 @@ Order our services at {{ "order"|link }}
|
||||
$this->di['db']->trash($model);
|
||||
|
||||
$this->di['logger']->info('Removed mail message #%s', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate preview text
|
||||
* Generate preview text.
|
||||
*
|
||||
* @param int $id - message id
|
||||
*
|
||||
@@ -276,11 +283,12 @@ Order our services at {{ "order"|link }}
|
||||
{
|
||||
$model = $this->_getMessage($data);
|
||||
$client_id = $this->_getTestClientId();
|
||||
list($ps, $pc) = $this->getService()->getParsed($model, $client_id);
|
||||
return array(
|
||||
'subject' => $ps,
|
||||
'content' => $pc,
|
||||
);
|
||||
[$ps, $pc] = $this->getService()->getParsed($model, $client_id);
|
||||
|
||||
return [
|
||||
'subject' => $ps,
|
||||
'content' => $pc,
|
||||
];
|
||||
}
|
||||
|
||||
private function _getTestClientId()
|
||||
@@ -288,23 +296,23 @@ Order our services at {{ "order"|link }}
|
||||
$mod = $this->di['mod']('massmailer');
|
||||
$c = $mod->getConfig();
|
||||
|
||||
$required = array(
|
||||
$required = [
|
||||
'test_client_id' => 'Client ID needs to be configured in mass mailer settings.',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $c);
|
||||
|
||||
return (int)$c['test_client_id'];
|
||||
return (int) $c['test_client_id'];
|
||||
}
|
||||
|
||||
private function _getMessage($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Message ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('mod_massmailer', $data['id'], 'Message not found');
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Massmailer\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,35 +34,37 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'subpages'=>array(
|
||||
array(
|
||||
'location' => 'extensions',
|
||||
'index' => 4000,
|
||||
return [
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'extensions',
|
||||
'index' => 4000,
|
||||
'label' => 'Mass mailer',
|
||||
'uri' => $this->di['url']->adminLink('massmailer'),
|
||||
'uri' => $this->di['url']->adminLink('massmailer'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/massmailer', 'get_index', array(), get_class($this));
|
||||
$app->get('/massmailer/message/:id', 'get_edit', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/massmailer', 'get_index', [], get_class($this));
|
||||
$app->get('/massmailer/message/:id', 'get_edit', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_massmailer_index');
|
||||
}
|
||||
|
||||
|
||||
public function get_edit(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$model = $api->massmailer_get(array('id'=>$id));
|
||||
return $app->render('mod_massmailer_message', array('msg'=>$model));
|
||||
$model = $api->massmailer_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_massmailer_message', ['msg' => $model]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Massmailer;
|
||||
|
||||
class Service implements \Box\InjectionAwareInterface
|
||||
@@ -30,9 +29,9 @@ class Service implements \Box\InjectionAwareInterface
|
||||
public function install()
|
||||
{
|
||||
$extensionService = $this->di['mod_service']('extension');
|
||||
$extensionService->activateExistingExtension(array('id'=>'queue', 'type'=>'mod'));
|
||||
|
||||
$sql="
|
||||
$extensionService->activateExistingExtension(['id' => 'queue', 'type' => 'mod']);
|
||||
|
||||
$sql = '
|
||||
CREATE TABLE IF NOT EXISTS `mod_massmailer` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`from_email` varchar(255) DEFAULT NULL,
|
||||
@@ -46,116 +45,116 @@ class Service implements \Box\InjectionAwareInterface
|
||||
`updated_at` varchar(35) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
||||
";
|
||||
';
|
||||
$this->di['db']->exec($sql);
|
||||
|
||||
//default config values
|
||||
$extensionService->setConfig(array('ext'=>'mod_massmailer', 'limit'=>'2','interval'=>'10', 'test_client_id'=>1));
|
||||
|
||||
// default config values
|
||||
$extensionService->setConfig(['ext' => 'mod_massmailer', 'limit' => '2', 'interval' => '10', 'test_client_id' => 1]);
|
||||
}
|
||||
|
||||
|
||||
public function getSearchQuery($data)
|
||||
{
|
||||
$sql="SELECT *
|
||||
$sql = 'SELECT *
|
||||
FROM mod_massmailer
|
||||
WHERE 1 ";
|
||||
|
||||
$params = array();
|
||||
|
||||
$search = (isset($data['search']) && !empty($data['search'])) ? $data['search'] : NULL;
|
||||
$status = $this->di['array_get']($data, 'status', NULL);
|
||||
|
||||
if(NULL !== $status) {
|
||||
WHERE 1 ';
|
||||
|
||||
$params = [];
|
||||
|
||||
$search = (isset($data['search']) && !empty($data['search'])) ? $data['search'] : null;
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
|
||||
if (null !== $status) {
|
||||
$sql .= ' AND status = :status';
|
||||
$params[':status'] = $status;
|
||||
}
|
||||
|
||||
if(NULL !== $search) {
|
||||
|
||||
if (null !== $search) {
|
||||
$sql .= ' AND (subject LIKE :search OR content LIKE :search OR from_email LIKE :search OR from_name LIKE :search)';
|
||||
$params[':search'] = '%'.$search.'%';
|
||||
}
|
||||
|
||||
|
||||
$sql .= ' ORDER BY created_at DESC';
|
||||
|
||||
return array($sql, $params);
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function getMessageReceivers($model, $data = array())
|
||||
|
||||
public function getMessageReceivers($model, $data = [])
|
||||
{
|
||||
$row = $this->toApiArray($model);
|
||||
$filter = $row['filter'];
|
||||
|
||||
$sql="SELECT c.id, c.first_name, c.last_name
|
||||
|
||||
$sql = 'SELECT c.id, c.first_name, c.last_name
|
||||
FROM client c
|
||||
LEFT JOIN client_order co ON (co.client_id = c.id)
|
||||
WHERE 1
|
||||
";
|
||||
|
||||
$values = array();
|
||||
if(!empty($filter)) {
|
||||
if(isset($filter['client_status']) && !empty($filter['client_status'])) {
|
||||
';
|
||||
|
||||
$values = [];
|
||||
if (!empty($filter)) {
|
||||
if (isset($filter['client_status']) && !empty($filter['client_status'])) {
|
||||
$sql .= sprintf(" AND c.status IN ('%s')", implode("', '", $filter['client_status']));
|
||||
}
|
||||
|
||||
if(isset($filter['client_groups']) && !empty($filter['client_groups'])) {
|
||||
|
||||
if (isset($filter['client_groups']) && !empty($filter['client_groups'])) {
|
||||
$sql .= sprintf(" AND c.client_group_id IN ('%s')", implode("', '", $filter['client_groups']));
|
||||
}
|
||||
|
||||
if(isset($filter['has_order']) && !empty($filter['has_order'])) {
|
||||
|
||||
if (isset($filter['has_order']) && !empty($filter['has_order'])) {
|
||||
$sql .= sprintf(" AND co.product_id IN ('%s')", implode("', '", $filter['has_order']));
|
||||
}
|
||||
|
||||
if(isset($filter['has_order_with_status']) && !empty($filter['has_order_with_status'])) {
|
||||
|
||||
if (isset($filter['has_order_with_status']) && !empty($filter['has_order_with_status'])) {
|
||||
$sql .= sprintf(" AND co.status IN ('%s')", implode("', '", $filter['has_order_with_status']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sql .= ' ORDER BY c.id DESC';
|
||||
|
||||
if(isset($data['debug']) && $data['debug']) {
|
||||
throw new \Exception($sql. ' '. print_r($values, 1));
|
||||
|
||||
if (isset($data['debug']) && $data['debug']) {
|
||||
throw new \Exception($sql.' '.print_r($values, 1));
|
||||
}
|
||||
|
||||
|
||||
return $this->di['db']->getAll($sql, $values);
|
||||
}
|
||||
|
||||
|
||||
public function getParsed($model, $client_id)
|
||||
{
|
||||
$clientService = $this->di['mod_service']('client');
|
||||
$systemService = $this->di['mod_service']('system');
|
||||
|
||||
$client = $clientService->get(array('id'=>$client_id));
|
||||
$client = $clientService->get(['id' => $client_id]);
|
||||
$clientArr = $clientService->toApiArray($client, true, null);
|
||||
|
||||
$vars = array();
|
||||
$vars = [];
|
||||
$vars['c'] = $clientArr;
|
||||
$vars['_tpl'] = $model->subject;
|
||||
$ps = $systemService->renderString($vars['_tpl'], false, $vars);
|
||||
|
||||
$vars = array();
|
||||
|
||||
$vars = [];
|
||||
$vars['c'] = $clientArr;
|
||||
$vars['_tpl'] = $model->content;
|
||||
$pc = $systemService->renderString($vars['_tpl'], false, $vars);
|
||||
|
||||
return array($ps, $pc);
|
||||
|
||||
return [$ps, $pc];
|
||||
}
|
||||
|
||||
public function sendMessage($model, $client_id)
|
||||
{
|
||||
list($ps, $pc) = $this->getParsed($model, $client_id);
|
||||
[$ps, $pc] = $this->getParsed($model, $client_id);
|
||||
|
||||
$clientService = $this->di['mod_service']('client');
|
||||
|
||||
$client = $clientService->get(array('id' => $client_id));
|
||||
$client = $clientService->get(['id' => $client_id]);
|
||||
|
||||
$data = array(
|
||||
'to' => $client->email,
|
||||
'to_name' => $client->first_name . ' ' . $client->last_name,
|
||||
'from' => $model->from_email,
|
||||
$data = [
|
||||
'to' => $client->email,
|
||||
'to_name' => $client->first_name.' '.$client->last_name,
|
||||
'from' => $model->from_email,
|
||||
'from_name' => $model->from_name,
|
||||
'subject' => $ps,
|
||||
'content' => $pc,
|
||||
'subject' => $ps,
|
||||
'content' => $pc,
|
||||
'client_id' => $client_id,
|
||||
);
|
||||
];
|
||||
|
||||
$mail = $this->di['mail'];
|
||||
$mail->setSubject($data['subject']);
|
||||
@@ -164,58 +163,60 @@ class Service implements \Box\InjectionAwareInterface
|
||||
$mail->addTo($data['to'], $data['to_name']);
|
||||
|
||||
if (APPLICATION_ENV != 'production') {
|
||||
if($this->di['config']['debug'])
|
||||
if ($this->di['config']['debug']) {
|
||||
error_log('Skip email sending. Application ENV: '.APPLICATION_ENV);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$mod = $this->di['mod']('email');
|
||||
$mod = $this->di['mod']('email');
|
||||
$settings = $mod->getConfig();
|
||||
|
||||
if (isset($settings['log_enabled']) && $settings['log_enabled']) {
|
||||
$activityService = $this->di['mod_service']('activity');
|
||||
$activityService = $this->di['mod_service']('activity');
|
||||
$activityService->logEmail($data['subject'], $client_id, $data['from'], $data['to'], $data['content']);
|
||||
}
|
||||
|
||||
|
||||
$emailSettings = $this->di['mod_config']('email');
|
||||
$transport = $this->di['array_get']($emailSettings, 'mailer', 'sendmail');
|
||||
$transport = $this->di['array_get']($emailSettings, 'mailer', 'sendmail');
|
||||
|
||||
$mail->send($transport, $emailSettings);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function toApiArray($row)
|
||||
{
|
||||
if($row instanceof \RedBeanPHP\OODBBean) {
|
||||
if ($row instanceof \RedBeanPHP\OODBBean) {
|
||||
$row = $row->export();
|
||||
}
|
||||
|
||||
if($row['filter']) {
|
||||
|
||||
if ($row['filter']) {
|
||||
$row['filter'] = json_decode($row['filter'], 1);
|
||||
} else {
|
||||
$row['filter'] = array();
|
||||
$row['filter'] = [];
|
||||
}
|
||||
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
public static function onAfterAdminCronRun(\Box_Event $event)
|
||||
{
|
||||
try {
|
||||
$di = $event->getDi();
|
||||
$di['api_admin']->queue_execute(array('queue'=>'massmailer'));
|
||||
} catch(\Exception $e) {
|
||||
$di['api_admin']->queue_execute(['queue' => 'massmailer']);
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error executing massmailer queue: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function sendMail($params)
|
||||
{
|
||||
$model = $this->di['db']->load('mod_massmailer', $params['msg_id']);
|
||||
if(!$model) {
|
||||
if (!$model) {
|
||||
throw new \Exception('Mass mail message not found');
|
||||
}
|
||||
$this->sendMessage($model, $params['client_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* News management
|
||||
* News management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\News\Api;
|
||||
@@ -19,18 +19,18 @@ namespace Box\Mod\News\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of active news items
|
||||
* Get paginated list of active news items.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
list ($sql, $params) = $service->getSearchQuery($data);
|
||||
[$sql, $params] = $service->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$post = $this->di['db']->getExistingModelById('Post', $item['id'], 'Post not found');
|
||||
$post = $this->di['db']->getExistingModelById('Post', $item['id'], 'Post not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($post, 'admin');
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get news item by ID
|
||||
* Get news item by ID.
|
||||
*
|
||||
* @param int $id - news item ID
|
||||
*
|
||||
@@ -50,7 +50,7 @@ class Admin extends \Api_Abstract
|
||||
throw new \Box_Exception('ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id');
|
||||
$id = $this->di['array_get']($data, 'id');
|
||||
$slug = $this->di['array_get']($data, 'slug');
|
||||
|
||||
$model = null;
|
||||
@@ -58,7 +58,7 @@ class Admin extends \Api_Abstract
|
||||
$model = $this->di['db']->load('Post', $id);
|
||||
} else {
|
||||
if (!empty($slug)) {
|
||||
$model = $this->di['db']->findOne('Post', 'slug = :slug', array('slug' => $slug));
|
||||
$model = $this->di['db']->findOne('Post', 'slug = :slug', ['slug' => $slug]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,23 +85,25 @@ class Admin extends \Api_Abstract
|
||||
public function update($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Post ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('Post', $data['id'], 'News item not found');
|
||||
|
||||
$description = $this->di['array_get']($data, 'description', $model->description);
|
||||
if (empty($description)) $description = $service->generateDescriptionFromContent($this->di['array_get']($data, 'content', $model->content));
|
||||
if (empty($description)) {
|
||||
$description = $service->generateDescriptionFromContent($this->di['array_get']($data, 'content', $model->content));
|
||||
}
|
||||
|
||||
$model->content = $this->di['array_get']($data, 'content', $model->content);
|
||||
$model->title = $this->di['array_get']($data, 'title', $model->title);
|
||||
$model->content = $this->di['array_get']($data, 'content', $model->content);
|
||||
$model->title = $this->di['array_get']($data, 'title', $model->title);
|
||||
$model->description = $description;
|
||||
$model->slug = $this->di['array_get']($data, 'slug', $model->slug);
|
||||
$model->image = $this->di['array_get']($data, 'image', $model->image);
|
||||
$model->section = $this->di['array_get']($data, 'section', $model->section);
|
||||
$model->status = $this->di['array_get']($data, 'status', $model->status);
|
||||
$model->slug = $this->di['array_get']($data, 'slug', $model->slug);
|
||||
$model->image = $this->di['array_get']($data, 'image', $model->image);
|
||||
$model->section = $this->di['array_get']($data, 'section', $model->section);
|
||||
$model->status = $this->di['array_get']($data, 'status', $model->status);
|
||||
|
||||
$publish_at = $this->di['array_get']($data, 'publish_at', 0);
|
||||
if ($publish_at) {
|
||||
@@ -132,7 +134,7 @@ class Admin extends \Api_Abstract
|
||||
|
||||
$this->di['logger']->info('Updated news item #%s', $model->id);
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,20 +150,20 @@ class Admin extends \Api_Abstract
|
||||
public function create($data)
|
||||
{
|
||||
$service = $this->getService();
|
||||
$required = array(
|
||||
$required = [
|
||||
'title' => 'Post title not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->dispense('Post');
|
||||
$model->admin_id = $this->getIdentity()->id;
|
||||
$model->title = $data['title'];
|
||||
$model = $this->di['db']->dispense('Post');
|
||||
$model->admin_id = $this->getIdentity()->id;
|
||||
$model->title = $data['title'];
|
||||
$model->description = null;
|
||||
$model->slug = $this->di['tools']->slug($data['title']);
|
||||
$model->status = $this->di['array_get']($data, 'status', NULL);
|
||||
$model->content = $this->di['array_get']($data, 'content', NULL);
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$model->slug = $this->di['tools']->slug($data['title']);
|
||||
$model->status = $this->di['array_get']($data, 'status', null);
|
||||
$model->content = $this->di['array_get']($data, 'content', null);
|
||||
$model->created_at = date('Y-m-d H:i:s');
|
||||
$model->updated_at = date('Y-m-d H:i:s');
|
||||
$this->di['db']->store($model);
|
||||
|
||||
$this->di['logger']->info('Created news item #%s', $model->id);
|
||||
@@ -170,7 +172,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete news item by ID
|
||||
* Delete news item by ID.
|
||||
*
|
||||
* @param int $id - news item ID
|
||||
*
|
||||
@@ -178,13 +180,13 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Post ID not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$model = $this->di['db']->getExistingModelById('Post', $data['id'], 'News item not found');
|
||||
$id = $model->id;
|
||||
$id = $model->id;
|
||||
$this->di['db']->trash($model);
|
||||
$this->di['logger']->info('Removed news item #%s', $id);
|
||||
|
||||
@@ -192,7 +194,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes news items with given IDs
|
||||
* Deletes news items with given IDs.
|
||||
*
|
||||
* @param array $ids - IDs for deletion
|
||||
*
|
||||
@@ -200,15 +202,15 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function batch_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ids' => 'IDs not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
foreach ($data['ids'] as $id) {
|
||||
$this->delete(array('id' => $id));
|
||||
$this->delete(['id' => $id]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* News and announcements management
|
||||
* News and announcements management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\News\Api;
|
||||
@@ -19,19 +19,19 @@ namespace Box\Mod\News\Api;
|
||||
class Guest extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of active news items
|
||||
* Get paginated list of active news items.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$data['status'] = 'active';
|
||||
list ($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$page = $this->di['array_get']($data, 'page');
|
||||
$pager = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page, $page);
|
||||
foreach ($pager['list'] as $key => $item) {
|
||||
$post = $this->di['db']->getExistingModelById('Post', $item['id'], 'Post not found');
|
||||
$post = $this->di['db']->getExistingModelById('Post', $item['id'], 'Post not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($post);
|
||||
}
|
||||
|
||||
@@ -39,31 +39,32 @@ class Guest extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get news item by ID or SLUG
|
||||
* Get news item by ID or SLUG.
|
||||
*
|
||||
* @param int $id - news item ID. Required only if SLUG is not passed.
|
||||
* @param int $id - news item ID. Required only if SLUG is not passed.
|
||||
* @param string $slug - news item slug. Required only if ID is not passed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
if(!isset($data['id']) && !isset($data['slug'])) {
|
||||
if (!isset($data['id']) && !isset($data['slug'])) {
|
||||
throw new \Box_Exception('ID or slug is missing');
|
||||
}
|
||||
|
||||
$id = $this->di['array_get']($data, 'id', NULL);
|
||||
$slug = $this->di['array_get']($data, 'slug', NULL);
|
||||
$id = $this->di['array_get']($data, 'id', null);
|
||||
$slug = $this->di['array_get']($data, 'slug', null);
|
||||
|
||||
if($id) {
|
||||
if ($id) {
|
||||
$model = $this->getService()->findOneActiveById($id);
|
||||
} else {
|
||||
$model = $this->getService()->findOneActiveBySlug($slug);
|
||||
}
|
||||
|
||||
if(!$model || $model->status !== 'active') {
|
||||
if (!$model || 'active' !== $model->status) {
|
||||
throw new \Box_Exception('News item not found');
|
||||
}
|
||||
|
||||
return $this->getService()->toApiArray($model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\News\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,38 +34,40 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function fetchNavigation()
|
||||
{
|
||||
return array(
|
||||
'subpages' => array(
|
||||
array(
|
||||
'location' => 'support',
|
||||
'index' => 900,
|
||||
return [
|
||||
'subpages' => [
|
||||
[
|
||||
'location' => 'support',
|
||||
'index' => 900,
|
||||
'label' => 'Announcements',
|
||||
'uri' => $this->di['url']->adminLink('news'),
|
||||
'uri' => $this->di['url']->adminLink('news'),
|
||||
'class' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/news', 'get_index', array(), get_class($this));
|
||||
$app->get('/news/', 'get_index', array(), get_class($this));
|
||||
$app->get('/news/index', 'get_index', array(), get_class($this));
|
||||
$app->get('/news/index/', 'get_index', array(), get_class($this));
|
||||
$app->get('/news/post/:id', 'get_post', array('id'=>'[0-9]+'), get_class($this));
|
||||
$app->get('/news', 'get_index', [], get_class($this));
|
||||
$app->get('/news/', 'get_index', [], get_class($this));
|
||||
$app->get('/news/index', 'get_index', [], get_class($this));
|
||||
$app->get('/news/index/', 'get_index', [], get_class($this));
|
||||
$app->get('/news/post/:id', 'get_post', ['id' => '[0-9]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_news_index');
|
||||
}
|
||||
|
||||
|
||||
public function get_post(\Box_App $app, $id)
|
||||
{
|
||||
$api = $this->di['api_admin'];
|
||||
$post = $api->news_get(array('id'=>$id));
|
||||
return $app->render('mod_news_post', array('post'=>$post));
|
||||
$post = $api->news_get(['id' => $id]);
|
||||
|
||||
return $app->render('mod_news_post', ['post' => $post]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\News\Controller;
|
||||
|
||||
class Client implements \Box\InjectionAwareInterface
|
||||
@@ -35,8 +34,8 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/news', 'get_news', array(), get_class($this));
|
||||
$app->get('/news/:slug', 'get_news_item', array('slug' => '[a-z0-9-]+'), get_class($this));
|
||||
$app->get('/news', 'get_news', [], get_class($this));
|
||||
$app->get('/news/:slug', 'get_news_item', ['slug' => '[a-z0-9-]+'], get_class($this));
|
||||
}
|
||||
|
||||
public function get_news(\Box_App $app)
|
||||
@@ -46,8 +45,8 @@ class Client implements \Box\InjectionAwareInterface
|
||||
|
||||
public function get_news_item(\Box_App $app, $slug)
|
||||
{
|
||||
$post = $this->di['api_guest']->news_get(array('slug'=>$slug));
|
||||
return $app->render('mod_news_post', array('post'=>$post));
|
||||
}
|
||||
$post = $this->di['api_guest']->news_get(['slug' => $slug]);
|
||||
|
||||
}
|
||||
return $app->render('mod_news_post', ['post' => $post]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\News;
|
||||
|
||||
class Service
|
||||
@@ -27,12 +26,12 @@ class Service
|
||||
|
||||
public function findOneActiveById($id)
|
||||
{
|
||||
return $this->di['db']->findOne('Post', 'id = :id AND status = "active"', array('id'=>$id));
|
||||
return $this->di['db']->findOne('Post', 'id = :id AND status = "active"', ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
public function findOneActiveBySlug($slug)
|
||||
{
|
||||
return $this->di['db']->findOne('Post', 'slug = :slug AND status = "active"', array('slug'=>$slug));
|
||||
return $this->di['db']->findOne('Post', 'slug = :slug AND status = "active"', ['slug' => $slug]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,68 +45,69 @@ class Service
|
||||
{
|
||||
$desc = utf8_encode($content);
|
||||
$desc = strip_tags($desc);
|
||||
$desc = str_replace(array("\n", "\r", "\t"), ' ', $desc);
|
||||
$desc = str_replace(["\n", "\r", "\t"], ' ', $desc);
|
||||
$desc = substr($desc, 0, 125);
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
public function getSearchQuery($data)
|
||||
{
|
||||
$sql='SELECT *
|
||||
$sql = 'SELECT *
|
||||
FROM post
|
||||
WHERE 1 ';
|
||||
|
||||
$params = array();
|
||||
$params = [];
|
||||
|
||||
$search = $this->di['array_get']($data, 'search', NULL);
|
||||
$status = $this->di['array_get']($data, 'status', NULL);
|
||||
$search = $this->di['array_get']($data, 'search', null);
|
||||
$status = $this->di['array_get']($data, 'status', null);
|
||||
|
||||
if(NULL !== $status) {
|
||||
if (null !== $status) {
|
||||
$sql .= ' AND status = :status';
|
||||
$params['status'] = $status;
|
||||
}
|
||||
|
||||
if(NULL !== $search) {
|
||||
if (null !== $search) {
|
||||
$sql .= ' AND (m.title LIKE :search OR m.content LIKE :search)';
|
||||
$params['search'] = '%'.$search.'%';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY created_at DESC';
|
||||
|
||||
return array($sql, $params);
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
public function toApiArray($row, $role = 'guest', $deep = true)
|
||||
{
|
||||
$admin = $this->di['db']->getRow('SELECT name, email FROM admin WHERE id=:id', array('id' => $row->admin_id));
|
||||
$admin = $this->di['db']->getRow('SELECT name, email FROM admin WHERE id=:id', ['id' => $row->admin_id]);
|
||||
|
||||
$pos = strpos($row->content, '<!--more-->');
|
||||
$pos = strpos($row->content, '<!--more-->');
|
||||
$excerpt = ($pos) ? substr($row->content, 0, $pos) : null;
|
||||
|
||||
|
||||
// Remove <!--more--> from post content
|
||||
$content = str_replace("<!--more-->", "", $row->content);
|
||||
$content = str_replace('<!--more-->', '', $row->content);
|
||||
|
||||
$data = array(
|
||||
'id' => $row->id,
|
||||
'title' => $row->title,
|
||||
'description' => $row->description,
|
||||
'content' => $content,
|
||||
'slug' => $row->slug,
|
||||
'image' => $row->image,
|
||||
'section' => $row->section,
|
||||
'publish_at' => $row->publish_at,
|
||||
$data = [
|
||||
'id' => $row->id,
|
||||
'title' => $row->title,
|
||||
'description' => $row->description,
|
||||
'content' => $content,
|
||||
'slug' => $row->slug,
|
||||
'image' => $row->image,
|
||||
'section' => $row->section,
|
||||
'publish_at' => $row->publish_at,
|
||||
'published_at' => $row->published_at,
|
||||
'expires_at' => $row->expires_at,
|
||||
'created_at' => $row->created_at,
|
||||
'updated_at' => $row->updated_at,
|
||||
'author' => array(
|
||||
'name' => $admin['name'],
|
||||
'expires_at' => $row->expires_at,
|
||||
'created_at' => $row->created_at,
|
||||
'updated_at' => $row->updated_at,
|
||||
'author' => [
|
||||
'name' => $admin['name'],
|
||||
'email' => $admin['email'],
|
||||
),
|
||||
'excerpt' => $excerpt,
|
||||
);
|
||||
],
|
||||
'excerpt' => $excerpt,
|
||||
];
|
||||
|
||||
if ($role == 'admin') {
|
||||
if ('admin' == $role) {
|
||||
$data['status'] = $row->status;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -24,33 +24,36 @@ namespace Box\Mod\Notification\Api;
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get paginated list of notifications
|
||||
* Get paginated list of notifications.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
|
||||
return $resultSet = $this->di['pager']->getSimpleResultSet($sql, $params, $per_page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification message
|
||||
* Get notification message.
|
||||
*
|
||||
* @param int $id - message id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Notification ID is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$meta = $this->di['db']->load('extension_meta', $data['id']);
|
||||
if ($meta->extension != 'mod_notification' || $meta->meta_key != 'message') {
|
||||
if ('mod_notification' != $meta->extension || 'message' != $meta->meta_key) {
|
||||
throw new \Box_Exception('Notification message was not found');
|
||||
}
|
||||
|
||||
@@ -58,9 +61,10 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new notification message
|
||||
* Add new notification message.
|
||||
*
|
||||
* @param string $message - message text
|
||||
*
|
||||
* @return int|false - new message id
|
||||
*/
|
||||
public function add($data)
|
||||
@@ -75,21 +79,23 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove notification message
|
||||
* Remove notification message.
|
||||
*
|
||||
* @param int $id - message id
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Notification ID is missing',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$meta = $this->di['db']->load('extension_meta', $data['id']);
|
||||
if ($meta->extension != 'mod_notification' || $meta->meta_key != 'message') {
|
||||
if ('mod_notification' != $meta->extension || 'message' != $meta->meta_key) {
|
||||
throw new \Box_Exception('Notification message was not found');
|
||||
}
|
||||
$this->di['db']->trash($meta);
|
||||
@@ -98,9 +104,10 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all notification messages
|
||||
* Remove all notification messages.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @return boolean
|
||||
* @throws Box_Exception
|
||||
*/
|
||||
public function delete_all()
|
||||
@@ -113,4 +120,4 @@ class Admin extends \Api_Abstract
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Notification\Controller;
|
||||
|
||||
class Admin implements \Box\InjectionAwareInterface
|
||||
@@ -35,12 +34,13 @@ class Admin implements \Box\InjectionAwareInterface
|
||||
|
||||
public function register(\Box_App &$app)
|
||||
{
|
||||
$app->get('/notification', 'get_index', array(), get_class($this));
|
||||
$app->get('/notification', 'get_index', [], get_class($this));
|
||||
}
|
||||
|
||||
public function get_index(\Box_App $app)
|
||||
{
|
||||
$this->di['is_admin_logged'];
|
||||
|
||||
return $app->render('mod_notification_index');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -10,7 +10,6 @@
|
||||
* with this source code in the file LICENSE
|
||||
*/
|
||||
|
||||
|
||||
namespace Box\Mod\Notification;
|
||||
|
||||
use Box\InjectionAwareInterface;
|
||||
@@ -38,7 +37,7 @@ class Service implements InjectionAwareInterface
|
||||
ORDER BY id DESC
|
||||
";
|
||||
|
||||
return array($q, array());
|
||||
return [$q, []];
|
||||
}
|
||||
|
||||
public function toApiArray($row)
|
||||
@@ -48,18 +47,18 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function create($message)
|
||||
{
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_notification';
|
||||
$meta->rel_type = 'staff';
|
||||
$meta->rel_id = 1;
|
||||
$meta->meta_key = 'message';
|
||||
$meta = $this->di['db']->dispense('extension_meta');
|
||||
$meta->extension = 'mod_notification';
|
||||
$meta->rel_type = 'staff';
|
||||
$meta->rel_id = 1;
|
||||
$meta->meta_key = 'message';
|
||||
$meta->meta_value = $message;
|
||||
$meta->created_at = date('Y-m-d H:i:s');
|
||||
$meta->updated_at = date('Y-m-d H:i:s');
|
||||
$id = $this->di['db']->store($meta);
|
||||
$id = $this->di['db']->store($meta);
|
||||
|
||||
$this->di['events_manager']->fire(array('event' => 'onAfterAdminNotificationAdd', 'params' => array('id' => $id)));
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterAdminNotificationAdd', 'params' => ['id' => $id]]);
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,14 +11,15 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Orders management
|
||||
* Orders management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Order\Api;
|
||||
|
||||
class Admin extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get order details
|
||||
* Get order details.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -26,14 +27,14 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function get($data)
|
||||
{
|
||||
$deep = isset($data['deep']) ? (bool)$data['deep'] : true;
|
||||
$deep = isset($data['deep']) ? (bool) $data['deep'] : true;
|
||||
$order = $this->_getOrder($data);
|
||||
|
||||
return $this->getService()->toApiArray($order, $deep, $this->getIdentity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return paginated list of orders
|
||||
* Return paginated list of orders.
|
||||
*
|
||||
* @optional string $date_from - show only order places after this date
|
||||
* @optional string $date_to - show only order places till this date
|
||||
@@ -42,15 +43,15 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$orderConfig = $this->di['mod']('order')->getConfig();
|
||||
$orderConfig = $this->di['mod']('order')->getConfig();
|
||||
$data['hide_addons'] = (isset($orderConfig['show_addons']) && $orderConfig['show_addons']) ? 0 : 1;
|
||||
list($sql, $params) = $this->getService()->getSearchQuery($data);
|
||||
[$sql, $params] = $this->getService()->getSearchQuery($data);
|
||||
$paginator = $this->di['pager'];
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$resultSet = $paginator->getAdvancedResultSet($sql, $params, $per_page);
|
||||
|
||||
foreach ($resultSet['list'] as $key => $result) {
|
||||
$orderObj = $this->di['db']->getExistingModelById('ClientOrder', $result['id'], 'Order not found');
|
||||
$orderObj = $this->di['db']->getExistingModelById('ClientOrder', $result['id'], 'Order not found');
|
||||
$resultSet['list'][$key] = $this->getService()->toApiArray($orderObj, true, $this->getIdentity());
|
||||
}
|
||||
|
||||
@@ -60,7 +61,7 @@ class Admin extends \Api_Abstract
|
||||
/**
|
||||
* Place new order for client. Admin is able to order disabled products.
|
||||
*
|
||||
* @param int $client_id - Client id
|
||||
* @param int $client_id - Client id
|
||||
* @param int $product_id - Product id to be ordered
|
||||
*
|
||||
* @optional array $config - Depending on product type, you may need to pass product configuration options
|
||||
@@ -78,20 +79,20 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'client_id' => 'Client id not passed',
|
||||
'product_id' => 'Product id not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$client = $this->di['db']->getExistingModelById('Client', $data['client_id'], 'Client not found');
|
||||
$client = $this->di['db']->getExistingModelById('Client', $data['client_id'], 'Client not found');
|
||||
$product = $this->di['db']->getExistingModelById('Product', $data['product_id'], 'Product not found');
|
||||
|
||||
return $this->getService()->createOrder($client, $product, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update order settings
|
||||
* Update order settings.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -140,7 +141,7 @@ class Admin extends \Api_Abstract
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
|
||||
if ($order->status == \Model_ClientOrder::STATUS_PENDING_SETUP || $order->status == \Model_ClientOrder::STATUS_FAILED_SETUP) {
|
||||
if (\Model_ClientOrder::STATUS_PENDING_SETUP == $order->status || \Model_ClientOrder::STATUS_FAILED_SETUP == $order->status) {
|
||||
return $this->activate($data);
|
||||
}
|
||||
|
||||
@@ -148,7 +149,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend order
|
||||
* Suspend order.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -159,16 +160,16 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function suspend($data)
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
$skip_event = isset($data['skip_event']) ? (bool)$data['skip_event'] : false;
|
||||
$order = $this->_getOrder($data);
|
||||
$skip_event = isset($data['skip_event']) ? (bool) $data['skip_event'] : false;
|
||||
|
||||
$reason = $this->di['array_get']($data, 'reason', NULL);
|
||||
$reason = $this->di['array_get']($data, 'reason', null);
|
||||
|
||||
return $this->getService()->suspendFromOrder($order, $reason, $skip_event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsuspend suspended order
|
||||
* Unsuspend suspended order.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -177,7 +178,7 @@ class Admin extends \Api_Abstract
|
||||
public function unsuspend($data)
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
if ($order->status != \Model_ClientOrder::STATUS_SUSPENDED) {
|
||||
if (\Model_ClientOrder::STATUS_SUSPENDED != $order->status) {
|
||||
throw new \Box_Exception('Only suspended orders can be unsuspended');
|
||||
}
|
||||
|
||||
@@ -185,7 +186,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel order
|
||||
* Cancel order.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -195,16 +196,16 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function cancel($data)
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
$skip_event = isset($data['skip_event']) ? (bool)$data['skip_event'] : false;
|
||||
$order = $this->_getOrder($data);
|
||||
$skip_event = isset($data['skip_event']) ? (bool) $data['skip_event'] : false;
|
||||
|
||||
$reason = $this->di['array_get']($data, 'reason', NULL);
|
||||
$reason = $this->di['array_get']($data, 'reason', null);
|
||||
|
||||
return $this->getService()->cancelFromOrder($order, $reason, $skip_event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uncancel canceled order
|
||||
* Uncancel canceled order.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -213,7 +214,7 @@ class Admin extends \Api_Abstract
|
||||
public function uncancel($data)
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
if ($order->status != \Model_ClientOrder::STATUS_CANCELED) {
|
||||
if (\Model_ClientOrder::STATUS_CANCELED != $order->status) {
|
||||
throw new \Box_Exception('Only canceled orders can be uncanceled');
|
||||
}
|
||||
|
||||
@@ -221,7 +222,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete order
|
||||
* Delete order.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -231,8 +232,8 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
$delete_addons = isset($data['delete_addons']) ? (bool)$data['delete_addons'] : false;
|
||||
$order = $this->_getOrder($data);
|
||||
$delete_addons = isset($data['delete_addons']) ? (bool) $data['delete_addons'] : false;
|
||||
|
||||
if ($delete_addons) {
|
||||
$list = $this->getService()->getOrderAddonsList($order);
|
||||
@@ -256,7 +257,7 @@ class Admin extends \Api_Abstract
|
||||
|
||||
/**
|
||||
* Cancel all suspended orders.
|
||||
* Configure how many days suspended order should be kept before canceling
|
||||
* Configure how many days suspended order should be kept before canceling.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -266,9 +267,9 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Update order config
|
||||
* Update order config.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
* @param int $id - Order id
|
||||
* @param array $config - list of key value pairs of configuration fields
|
||||
*
|
||||
* @return bool
|
||||
@@ -287,7 +288,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order service data
|
||||
* Get order service data.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -301,7 +302,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated order statuses history list
|
||||
* Get paginated order statuses history list.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -313,16 +314,16 @@ class Admin extends \Api_Abstract
|
||||
|
||||
$data['client_order_id'] = $order->id;
|
||||
|
||||
list($sql, $bindings) = $this->getService()->getOrderStatusSearchQuery($data);
|
||||
[$sql, $bindings] = $this->getService()->getOrderStatusSearchQuery($data);
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
|
||||
return $this->di['pager']->getSimpleResultSet($sql, $bindings, $per_page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add order status history change
|
||||
* Add order status history change.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
* @param int $id - Order id
|
||||
* @param string $status - order status
|
||||
*
|
||||
* @return array
|
||||
@@ -331,9 +332,9 @@ class Admin extends \Api_Abstract
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
|
||||
$required = array(
|
||||
$required = [
|
||||
'status' => 'Order status was not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$notes = $this->di['array_get']($data, 'notes', null);
|
||||
@@ -342,7 +343,7 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove order status history item
|
||||
* Remove order status history item.
|
||||
*
|
||||
* @param int $id - History line id
|
||||
*
|
||||
@@ -350,16 +351,16 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function status_history_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Order history line id not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
return $this->getService()->orderStatusRm($data['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return order statuses codes with counter
|
||||
* Return order statuses codes with counter.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -369,36 +370,36 @@ class Admin extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Return available invoice options
|
||||
* Return available invoice options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_invoice_options($data)
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'issue-invoice' => __('Automatically issue renewal invoices'),
|
||||
'no-invoice' => __('Issue invoices manually'),
|
||||
);
|
||||
'no-invoice' => __('Issue invoices manually'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return order statuses codes with titles
|
||||
* Return order statuses codes with titles.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_status_pairs($data)
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
\Model_ClientOrder::STATUS_PENDING_SETUP => 'Pending setup',
|
||||
\Model_ClientOrder::STATUS_FAILED_SETUP => 'Setup failed',
|
||||
\Model_ClientOrder::STATUS_ACTIVE => 'Active',
|
||||
\Model_ClientOrder::STATUS_SUSPENDED => 'Suspended',
|
||||
\Model_ClientOrder::STATUS_CANCELED => 'Canceled',
|
||||
);
|
||||
\Model_ClientOrder::STATUS_FAILED_SETUP => 'Setup failed',
|
||||
\Model_ClientOrder::STATUS_ACTIVE => 'Active',
|
||||
\Model_ClientOrder::STATUS_SUSPENDED => 'Suspended',
|
||||
\Model_ClientOrder::STATUS_CANCELED => 'Canceled',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return order addons list
|
||||
* Return order addons list.
|
||||
*
|
||||
* @param int $id - Order id
|
||||
*
|
||||
@@ -406,9 +407,9 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function addons($data)
|
||||
{
|
||||
$model = $this->_getOrder($data);
|
||||
$list = $this->getService()->getOrderAddonsList($model);
|
||||
$result = array();
|
||||
$model = $this->_getOrder($data);
|
||||
$list = $this->getService()->getOrderAddonsList($model);
|
||||
$result = [];
|
||||
foreach ($list as $order) {
|
||||
$result[] = $this->getService()->toApiArray($order);
|
||||
}
|
||||
@@ -418,16 +419,16 @@ class Admin extends \Api_Abstract
|
||||
|
||||
protected function _getOrder($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Order id not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
return $this->di['db']->getExistingModelById('ClientOrder', $data['id'], 'Order not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes orders with given IDs
|
||||
* Deletes orders with given IDs.
|
||||
*
|
||||
* @param array $ids - Order ids for deletion
|
||||
*
|
||||
@@ -437,17 +438,17 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function batch_delete($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'ids' => 'Orders ids not passed',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$delete_addons = isset($data['delete_addons']) ? (bool)$data['delete_addons'] : false;
|
||||
$delete_addons = isset($data['delete_addons']) ? (bool) $data['delete_addons'] : false;
|
||||
|
||||
foreach ($data['ids'] as $id) {
|
||||
$this->delete(array('id' => $id, 'delete_addons' => $delete_addons));
|
||||
$this->delete(['id' => $id, 'delete_addons' => $delete_addons]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxBilling
|
||||
* BoxBilling.
|
||||
*
|
||||
* @copyright BoxBilling, Inc (https://www.boxbilling.org)
|
||||
* @license Apache-2.0
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Client orders management
|
||||
* Client orders management.
|
||||
*/
|
||||
|
||||
namespace Box\Mod\Order\Api;
|
||||
@@ -19,18 +19,18 @@ namespace Box\Mod\Order\Api;
|
||||
class Client extends \Api_Abstract
|
||||
{
|
||||
/**
|
||||
* Get list of orders
|
||||
* Get list of orders.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_list($data)
|
||||
{
|
||||
$identity = $this->getIdentity();
|
||||
$identity = $this->getIdentity();
|
||||
$data['client_id'] = $identity->id;
|
||||
if (isset($data['expiring'])) {
|
||||
list($query, $bindings) = $this->getService()->getSoonExpiringActiveOrdersQuery($data);
|
||||
[$query, $bindings] = $this->getService()->getSoonExpiringActiveOrdersQuery($data);
|
||||
} else {
|
||||
list($query, $bindings) = $this->getService()->getSearchQuery($data);
|
||||
[$query, $bindings] = $this->getService()->getSearchQuery($data);
|
||||
}
|
||||
$per_page = $this->di['array_get']($data, 'per_page', $this->di['pager']->getPer_page());
|
||||
$pager = $this->di['pager']->getAdvancedResultSet($query, $bindings, $per_page);
|
||||
@@ -39,13 +39,15 @@ class Client extends \Api_Abstract
|
||||
$order = $this->di['db']->getExistingModelById('ClientOrder', $item['id'], 'Client order not found');
|
||||
$pager['list'][$key] = $this->getService()->toApiArray($order);
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order details
|
||||
* Get order details.
|
||||
*
|
||||
* @param int $id - order id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get($data)
|
||||
@@ -56,16 +58,17 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order addons
|
||||
* Get order addons.
|
||||
*
|
||||
* @param int $id - order id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function addons($data)
|
||||
{
|
||||
$model = $this->_getOrder($data);
|
||||
$list = $this->getService()->getOrderAddonsList($model);
|
||||
$result = array();
|
||||
$model = $this->_getOrder($data);
|
||||
$list = $this->getService()->getOrderAddonsList($model);
|
||||
$result = [];
|
||||
foreach ($list as $order) {
|
||||
$result[] = $this->getService()->toApiArray($order);
|
||||
}
|
||||
@@ -77,37 +80,41 @@ class Client extends \Api_Abstract
|
||||
* Get order service. Order must be activated before service can be retrieved.
|
||||
*
|
||||
* @param int $id - order id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function service($data)
|
||||
{
|
||||
$order = $this->_getOrder($data);
|
||||
|
||||
return $this->getService()->getOrderServiceData($order, $data['id'], $this->getIdentity());;
|
||||
return $this->getService()->getOrderServiceData($order, $data['id'], $this->getIdentity());
|
||||
}
|
||||
|
||||
/**
|
||||
* List of product pairs offered as an upgrade
|
||||
* List of product pairs offered as an upgrade.
|
||||
*
|
||||
* @param int $id - order id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function upgradables($data)
|
||||
{
|
||||
$model = $this->_getOrder($data);
|
||||
$product = $this->di['db']->getExistingModelById('Product', $model->product_id);
|
||||
$model = $this->_getOrder($data);
|
||||
$product = $this->di['db']->getExistingModelById('Product', $model->product_id);
|
||||
$productService = $this->di['mod_service']('product');
|
||||
|
||||
return $productService->getUpgradablePairs($product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can delete only pending setup and failed setup orders
|
||||
* Can delete only pending setup and failed setup orders.
|
||||
*
|
||||
* @param int $id - order id
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$model = $this->_getOrder($data);
|
||||
if (!in_array($model->status, array(\Model_ClientOrder::STATUS_PENDING_SETUP, \Model_ClientOrder::STATUS_FAILED_SETUP))) {
|
||||
if (!in_array($model->status, [\Model_ClientOrder::STATUS_PENDING_SETUP, \Model_ClientOrder::STATUS_FAILED_SETUP])) {
|
||||
throw new \Box_Exception('Only pending and failed setup orders can be deleted.');
|
||||
}
|
||||
|
||||
@@ -116,9 +123,9 @@ class Client extends \Api_Abstract
|
||||
|
||||
protected function _getOrder($data)
|
||||
{
|
||||
$required = array(
|
||||
$required = [
|
||||
'id' => 'Order id required',
|
||||
);
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$order = $this->getService()->findForClientById($this->getIdentity(), $data['id']);
|
||||
@@ -128,4 +135,4 @@ class Client extends \Api_Abstract
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 184 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user