Guillermo - stats architecture [skip ci]

This commit is contained in:
AntonyAntonio 2017-01-11 04:25:26 -03:00
parent 149a18c52e
commit 845939f089
7 changed files with 63 additions and 6 deletions

View File

@ -9,6 +9,7 @@ require_once 'system/get-logs.php';
require_once 'system/get-mail-templates.php';
require_once 'system/edit-mail-template.php';
require_once 'system/recover-mail-template.php';
require_once 'system/get-stats.php';
$systemControllerGroup = new ControllerGroup();
$systemControllerGroup->setGroupPath('/system');
@ -23,5 +24,6 @@ $systemControllerGroup->addController(new GetLogsController);
$systemControllerGroup->addController(new GetMailTemplatesController);
$systemControllerGroup->addController(new EditMailTemplateController);
$systemControllerGroup->addController(new RecoverMailTemplateController);
$systemControllerGroup->addController(new GetStatsController);
$systemControllerGroup->finalize();

View File

@ -1,5 +1,4 @@
<?php
use Respect\Validation\Validator as DataValidator;
class EditSettingsController extends Controller {
const PATH = '/edit-settings';

View File

@ -0,0 +1,34 @@
<?php
class GetStatsController extends Controller {
const PATH = '/get-stats';
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => []
];
}
public function handler() {
$begin = new DateTime(Setting::getSetting('last-stat-day')->value);
$end = new DateTime(Date::getCurrentDate());
$interval = new DateInterval('P1D');
$dateRange = new DatePeriod($begin, $interval ,$end);
foreach($dateRange as $date){
$numberOfTickets = Log::count('type=? AND date LIKE ?',['CREATE_TICKET', $date->format('Ymd') . '%']);
$stat = new Stat();
$stat->setProperties([
'date' => $date->format('Ymd'),
'type' => 'CREATE_TICKET',
'general' => 1,
'value' => $numberOfTickets,
]);
$stat->store();
}
Response::respondSuccess();
}
}

View File

@ -40,7 +40,8 @@ class InitSettingsController extends Controller {
'allow-attachments' => 0,
'max-size' => 0,
'title' => 'Support Center',
'url' => 'http://www.opensupports.com/support'
'url' => 'http://www.opensupports.com/support',
'last-stat-day' => '20170101'//TODO: get current date
]);
}

View File

@ -9,7 +9,8 @@ class Log extends DataStore {
'type',
'authorUser',
'authorStaff',
'to'
'to',
'date'
];
}
@ -22,7 +23,8 @@ class Log extends DataStore {
$log->setProperties(array(
'type' => $type,
'to' => $to
'to' => $to,
'date' => Date::getCurrentDate()
));
if($author instanceof User) {
@ -44,7 +46,8 @@ class Log extends DataStore {
'name' => $author->name,
'id' => $author->id,
'staff' => $author instanceof Staff
]
],
'date' => $this->date
];
}
}

View File

@ -18,7 +18,8 @@ class Staff extends DataStore {
'level',
'sharedDepartmentList',
'sharedTicketList',
'lastLogin'
'lastLogin',
'sharedStatList'
];
}

17
server/models/Stat.php Normal file
View File

@ -0,0 +1,17 @@
<?php
class Stat extends DataStore {
const TABLE = 'stat';
public static function getProps() {
return array (
'date',
'type',
'general',
'value'
);
}
public function getDefaultProps() {
return array();
}
}