added statisticcollector class
This commit is contained in:
parent
d6ed139265
commit
d8513733ec
71
application/core/Statistics/StatisticCollector.php
Normal file
71
application/core/Statistics/StatisticCollector.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Statistic Collector Class
|
||||||
|
*
|
||||||
|
* @author steeffeen & kremsy
|
||||||
|
*/
|
||||||
|
namespace ManiaControl\Statistics;
|
||||||
|
|
||||||
|
|
||||||
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
|
|
||||||
|
class StatisticCollector implements CallbackListener {
|
||||||
|
/**
|
||||||
|
* Constants
|
||||||
|
*/
|
||||||
|
const SETTING_COLLECT_STATS_ENABLED = 'Collect Stats Enabled';
|
||||||
|
const SETTING_COLLECT_STATS_MINPLAYERS = 'Minimum Playercount for Collecting Stats';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Statistics
|
||||||
|
*/
|
||||||
|
const STAT_ON_SHOOT = 'onShoot';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private Properties
|
||||||
|
*/
|
||||||
|
private $maniaControl = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct player manager
|
||||||
|
*
|
||||||
|
* @param \ManiaControl\ManiaControl $maniaControl
|
||||||
|
*/
|
||||||
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
|
//Register Callbacks
|
||||||
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks');
|
||||||
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks');
|
||||||
|
|
||||||
|
//Initialize Settings
|
||||||
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_ENABLED, true);
|
||||||
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 4);
|
||||||
|
|
||||||
|
//Define Stats MetaData
|
||||||
|
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_ON_SHOOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle stats on callbacks
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handleCallbacks(array $callback) {
|
||||||
|
|
||||||
|
//Check if Stat Collecting is enabled
|
||||||
|
if(!$this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_ENABLED)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check for Minplayer
|
||||||
|
if(count($this->maniaControl->playerManager->getPlayers()) < $this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var_dump($callback);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use ManiaControl\Statistics\StatisticCollector;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/StatisticCollector.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistic Manager Class
|
* Statistic Manager Class
|
||||||
@ -18,6 +21,11 @@ class StatisticManager {
|
|||||||
|
|
||||||
const STAT_TYPE_INT = '0';
|
const STAT_TYPE_INT = '0';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public Properties
|
||||||
|
*/
|
||||||
|
public $statisticCollector = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -35,6 +43,8 @@ class StatisticManager {
|
|||||||
$this->mysqli = $this->maniaControl->database->mysqli;
|
$this->mysqli = $this->maniaControl->database->mysqli;
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
|
$this->statisticCollector = new StatisticCollector($maniaControl);
|
||||||
|
|
||||||
//Store Stats MetaData
|
//Store Stats MetaData
|
||||||
$this->storeStatMetaData();
|
$this->storeStatMetaData();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user