TrackManiaControl/application/core/mapHandler.php

79 lines
1.8 KiB
PHP
Raw Normal View History

2013-11-10 17:04:57 +01:00
<?php
/**
2013-11-10 19:31:35 +01:00
* Handler for maps
*
* @author kremsy & steeffeen
2013-11-10 17:04:57 +01:00
*/
namespace ManiaControl;
class mapHandler {
2013-11-10 19:50:24 +01:00
/**
2013-11-10 17:04:57 +01:00
* Private properties
*/
private $maniaControl = null;
private $mapList = array();
/**
* Construct map handler
* @param ManiaControl $maniaControl
*/
2013-11-10 19:31:35 +01:00
//TODO: database init
//TODO: erasemap from server
//TODO: implement of a method which are called by xlist command and results maplists from maniaexcahnge (or extra class for it)
//TODO: admin add from maniaexchange, would handle it here
2013-11-10 17:04:57 +01:00
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->initTables();
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MC_ONINIT, $this, 'onInit');
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_BEGINMAP, $this, 'beginMap');
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_ENDMAP, $this, 'endMap');
}
/**
* Initialize all necessary tables
*
* @return bool
*/
private function initTables() {
}
2013-11-10 19:31:35 +01:00
2013-11-10 17:04:57 +01:00
/**
* Handle OnInit callback
*
* @param array $callback
*/
public function onInit(){
2013-11-10 19:50:24 +01:00
2013-11-10 17:04:57 +01:00
$this->maniaControl->client->query('GetMapList', 300, 0);
$mapList = $this->maniaControl->client->getResponse();
foreach ($mapList as $map) {
2013-11-11 18:37:53 +01:00
$map = new Map($this->maniaControl, $map);
2013-11-10 17:04:57 +01:00
$this->addMap($map);
}
}
/**
* Add a map to the MapList
*
* @param Map $map
* @return bool
*/
private function addMap(Map $map) {
if (!$map) {
return false;
}
$this->mapList[$map->uid] = $map;
return true;
}
}