added statisticcollector class

This commit is contained in:
kremsy 2013-12-31 21:41:52 +01:00
parent d6ed139265
commit d8513733ec
2 changed files with 81 additions and 0 deletions

View 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);
}
}

View File

@ -1,6 +1,9 @@
<?php
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Statistics\StatisticCollector;
require_once __DIR__ . '/StatisticCollector.php';
/**
* Statistic Manager Class
@ -18,6 +21,11 @@ class StatisticManager {
const STAT_TYPE_INT = '0';
/**
* Public Properties
*/
public $statisticCollector = null;
/**
* Private Properties
*/
@ -35,6 +43,8 @@ class StatisticManager {
$this->mysqli = $this->maniaControl->database->mysqli;
$this->initTables();
$this->statisticCollector = new StatisticCollector($maniaControl);
//Store Stats MetaData
$this->storeStatMetaData();
}