started own mxinfosearcher

This commit is contained in:
kremsy 2014-01-08 21:03:59 +01:00
parent 9d930ac85b
commit 132fa4cf01
5 changed files with 120 additions and 4 deletions

View File

@ -32,6 +32,7 @@ require_once __DIR__ . '/Formatter.php';
require_once __DIR__ . '/GbxDataFetcher/gbxdatafetcher.inc.php';
require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php';
require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php';
require_once __DIR__ . '/ManiaExchange/ManiaExchangeInfoSearcher.php';
require_once __DIR__ . '/Manialinks/ManialinkManager.php';
require_once __DIR__ . '/Statistics/StatisticManager.php';
require_once __DIR__ . '/Maps/MapManager.php';

View File

@ -0,0 +1,112 @@
<?php
namespace ManiaControl\Maps;
use ManiaControl\FileUtil;
use ManiaControl\ManiaControl;
class ManiaExchangeInfoSearcher {
/**
* Constants
*/
const SEARCH_ORDER_NONE = -1;
const SEARCH_ORDER_TRACK_NAME = 0;
const SEARCH_ORDER_AUTHOR = 1;
const SEARCH_ORDER_UPLOADED_NEWEST = 2;
const SEARCH_ORDER_UPLOADED_OLDEST = 3;
const SEARCH_ORDER_UPDATED_NEWEST = 4;
const SEARCH_ORDER_UPDATED_OLDEST = 5;
//TODO finish that list
/*
* [19:16] <TGYoshi> 6 => "Activity (Latest) [19:16] <TGYoshi> 7 => "Activity (Oldest) [19:16] <TGYoshi> 8 => "Awards (Most) [19:16] <TGYoshi> 9 => "Awards (Least) [19:16] <TGYoshi> 10 => "Comments (Most) [19:16] <TGYoshi> 11 => "Comments (Least) [19:16] <TGYoshi> 12 => "Difficulty (Easiest) [19:16] <TGYoshi> 13 => "Difficulty (Hardest) [19:16] <TGYoshi> 14 => "Length (Shortest) [19:16] <TGYoshi> 15 => "Length (Longest)
*/
/**
* Private Properties
*/
private $maniaControl = null;
/**
* Construct map manager
*
* @param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
}
public function getList($maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPLOADED_NEWEST, $env = '') {
//Get Title Id
$titleId = $this->maniaControl->server->titleId;
$title = strtoupper(substr($titleId, 0, 2));
//Get MapTypes
$this->maniaControl->client->query('GetModeScriptInfo');
$scriptInfos = $this->maniaControl->client->getResponse();
$mapTypes = $scriptInfos["CompatibleMapTypes"];
$mapTypeArray = explode(",", $mapTypes);
var_dump($mapTypes);
var_dump($mapTypeArray);
// compile search URL
$url = 'http://' . $title . '.mania-exchange.com/tracksearch?api=on';
/* if ($name != '')
$url .= '&trackname=' . $name;
if ($author != '')
$url .= '&author=' . $author;*/
if($env != '') {
$url .= '&environments=' . $this->getEnvironment($env);
}
$url .= '&priord=' . $searchOrder;
$url .= '&limit=' . $maxMapsReturned;
$url .= '&mtype=' . $mapTypeArray[0];
var_dump($url);
$mapInfo = FileUtil::loadFile($url, "application/json");
//TODO errors
/*if ($file === false) {
$this->error = 'Connection or response error on ' . $url;
return array();
} elseif ($file === -1) {
$this->error = 'Timed out while reading data from ' . $url;
return array();
} elseif ($file == '') {
if (empty($maps)) {
$this->error = 'No data returned from ' . $url;
return array();
} else {
break;
}
}*/
$mx = json_decode($mapInfo);
if($mx === null) {
$this->error = 'Cannot decode searched JSON data from ' . $url;
return array();
}
var_dump($mx);
// return list of maps as array of MX objects
//return $maps;
}
private function getEnvironment($env) {
switch($env) {
case 'TMCanyon':
case 'SMStorm':
return 1;
case 'TMStadium':
return 2;
case 'TMValley':
return 3;
default:
return -1;
}
}
}

View File

@ -120,6 +120,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$recent = false;
}
$this->maniaControl->mapManager->mxInfoSearcher->getList('');
// search for matching maps
$maps = new MXInfoSearcher($title, $searchString, $author, $environment, $recent);

View File

@ -31,6 +31,7 @@ class MapManager implements CallbackListener {
public $mapQueue = null;
public $mapCommands = null;
public $mapList = null;
public $mxInfoSearcher = null;
/**
* Private Properties
@ -53,6 +54,7 @@ class MapManager implements CallbackListener {
$this->mapList = new MapList($this->maniaControl);
$this->mapCommands = new MapCommands($maniaControl);
$this->mapQueue = new MapQueue($this->maniaControl);
$this->mxInfoSearcher = new ManiaExchangeInfoSearcher($this->maniaControl);
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');

View File

@ -418,7 +418,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$login = null;
$message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.';
} else {
$message = 'Donation successful! Thanks.';
}