major refactoring of almost all files
This commit is contained in:
@@ -1,91 +1,109 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
class Traffic extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Exception;
|
||||
use Froxlor\Api\ApiCommand;
|
||||
use Froxlor\Api\ResourceEntity;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\FroxlorLogger;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* @since 0.10.0
|
||||
*/
|
||||
class Traffic extends ApiCommand implements ResourceEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* You cannot add traffic data
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
throw new \Exception('You cannot add traffic data', 303);
|
||||
throw new Exception('You cannot add traffic data', 303);
|
||||
}
|
||||
|
||||
/**
|
||||
* to get specific traffic details use year, month and/or day parameter for Traffic.listing()
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
throw new \Exception('To get specific traffic details use year, month and/or day parameter for Traffic.listing()', 303);
|
||||
throw new Exception('To get specific traffic details use year, month and/or day parameter for Traffic.listing()', 303);
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot update traffic data
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
throw new \Exception('You cannot update traffic data', 303);
|
||||
throw new Exception('You cannot update traffic data', 303);
|
||||
}
|
||||
|
||||
/**
|
||||
* list traffic information
|
||||
*
|
||||
* @param int $year
|
||||
* optional, default empty
|
||||
* optional, default empty
|
||||
* @param int $month
|
||||
* optional, default empty
|
||||
* optional, default empty
|
||||
* @param int $day
|
||||
* optional, default empty
|
||||
* optional, default empty
|
||||
* @param int $date_from
|
||||
* optional timestamp, default empty, if specified, $year, $month and $day will be ignored
|
||||
* optional timestamp, default empty, if specified, $year, $month and $day will be ignored
|
||||
* @param int $date_until
|
||||
* optional timestamp, default empty, if specified, $year, $month and $day will be ignored
|
||||
* optional timestamp, default empty, if specified, $year, $month and $day will be ignored
|
||||
* @param bool $customer_traffic
|
||||
* optional, admin-only, whether to output ones own traffic or all of ones customers, default is 0 (false)
|
||||
* optional, admin-only, whether to output ones own traffic or all of ones customers, default is 0
|
||||
* (false)
|
||||
* @param int $customerid
|
||||
* optional, admin-only, select traffic of a specific customer by id
|
||||
* optional, admin-only, select traffic of a specific customer by id
|
||||
* @param string $loginname
|
||||
* optional, admin-only, select traffic of a specific customer by loginname
|
||||
*
|
||||
* optional, admin-only, select traffic of a specific customer by loginname
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
* @return string json-encoded array count|list
|
||||
* @throws Exception
|
||||
*/
|
||||
public function listing()
|
||||
{
|
||||
$year = $this->getParam('year', true, "");
|
||||
$month = $this->getParam('month', true, "");
|
||||
$day = $this->getParam('day', true, "");
|
||||
$date_from = $this->getParam('date_from', true, - 1);
|
||||
$date_until = $this->getParam('date_until', true, - 1);
|
||||
$date_from = $this->getParam('date_from', true, -1);
|
||||
$date_until = $this->getParam('date_until', true, -1);
|
||||
$customer_traffic = $this->getBoolParam('customer_traffic', true, 0);
|
||||
$customer_ids = $this->getAllowedCustomerIds();
|
||||
$result = array();
|
||||
$params = array();
|
||||
$result = [];
|
||||
$params = [];
|
||||
|
||||
// validate parameters
|
||||
if ($date_from >= 0 || $date_until >= 0) {
|
||||
@@ -105,15 +123,15 @@ class Traffic extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
|
||||
// check for year/month/day
|
||||
$where_str = "";
|
||||
if (! empty($year) && is_numeric($year)) {
|
||||
if (!empty($year) && is_numeric($year)) {
|
||||
$where_str .= " AND `year` = :year";
|
||||
$params['year'] = $year;
|
||||
}
|
||||
if (! empty($month) && is_numeric($month)) {
|
||||
if (!empty($month) && is_numeric($month)) {
|
||||
$where_str .= " AND `month` = :month";
|
||||
$params['month'] = $month;
|
||||
}
|
||||
if (! empty($day) && is_numeric($day)) {
|
||||
if (!empty($day) && is_numeric($day)) {
|
||||
$where_str .= " AND `day` = :day";
|
||||
$params['day'] = $day;
|
||||
}
|
||||
@@ -129,7 +147,7 @@ class Traffic extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
$params['du'] = $date_until;
|
||||
}
|
||||
|
||||
if (! $this->isAdmin() || ($this->isAdmin() && $customer_traffic)) {
|
||||
if (!$this->isAdmin() || ($this->isAdmin() && $customer_traffic)) {
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT * FROM `" . TABLE_PANEL_TRAFFIC . "`
|
||||
WHERE `customerid` IN (" . implode(", ", $customer_ids) . ")" . $where_str);
|
||||
@@ -140,33 +158,33 @@ class Traffic extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
WHERE `adminid` = :adminid" . $where_str);
|
||||
}
|
||||
Database::pexecute($result_stmt, $params, true, true);
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list traffic");
|
||||
return $this->response(array(
|
||||
$this->logger()->logAction($this->isAdmin() ? FroxlorLogger::ADM_ACTION : FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list traffic");
|
||||
return $this->response([
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot count the traffic data list
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function listingCount()
|
||||
{
|
||||
throw new \Exception('You cannot count the traffic data list', 303);
|
||||
throw new Exception('You cannot count the traffic data list', 303);
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot delete traffic data
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
throw new \Exception('You cannot delete traffic data', 303);
|
||||
throw new Exception('You cannot delete traffic data', 303);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user