diff --git a/server/controllers/system.php b/server/controllers/system.php index 2cde4fe2..534f556e 100644 --- a/server/controllers/system.php +++ b/server/controllers/system.php @@ -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(); \ No newline at end of file diff --git a/server/controllers/system/edit-settings.php b/server/controllers/system/edit-settings.php index c78f1f97..22454e62 100644 --- a/server/controllers/system/edit-settings.php +++ b/server/controllers/system/edit-settings.php @@ -1,5 +1,4 @@ '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(); + } +} \ No newline at end of file diff --git a/server/controllers/system/init-settings.php b/server/controllers/system/init-settings.php index 98fce211..89842b5c 100644 --- a/server/controllers/system/init-settings.php +++ b/server/controllers/system/init-settings.php @@ -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 ]); } diff --git a/server/models/Log.php b/server/models/Log.php index ebe24469..966f3b3a 100644 --- a/server/models/Log.php +++ b/server/models/Log.php @@ -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 ]; } } \ No newline at end of file diff --git a/server/models/Staff.php b/server/models/Staff.php index cca0bc4c..9ec69341 100644 --- a/server/models/Staff.php +++ b/server/models/Staff.php @@ -18,7 +18,8 @@ class Staff extends DataStore { 'level', 'sharedDepartmentList', 'sharedTicketList', - 'lastLogin' + 'lastLogin', + 'sharedStatList' ]; } diff --git a/server/models/Stat.php b/server/models/Stat.php new file mode 100644 index 00000000..08e90572 --- /dev/null +++ b/server/models/Stat.php @@ -0,0 +1,17 @@ +