Added application handler

Fixed fleet bugs
Fixed colonization bug
Updated mail handler support
Fixed galaxy bugs
Updated license block

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2012-05-28 23:18:54 +02:00
commit 9e3c1e68bf
89 changed files with 4256 additions and 2168 deletions

View file

@ -126,7 +126,8 @@ if (!defined('DISABLE_IDENTITY_CHECK')) {
exit(0);
}
if (!Wootook::getGameConfig('game/general/active') && !in_array($user->getData('authlevel'), array(LEVEL_ADMIN, LEVEL_MODERATOR, LEVEL_OPERATOR))) {
//var_dump(Wootook::getGameConfig('game/general/active'));
if (!Wootook::getGameConfig('game/general/active')/* && !in_array($user->getData('authlevel'), array(LEVEL_ADMIN, LEVEL_MODERATOR, LEVEL_OPERATOR))*/) {
$layout = new Wootook_Core_Model_Layout(Wootook_Core_Model_Layout::DOMAIN_FRONTEND);
$layout->load('message');

View file

@ -13,10 +13,6 @@ class Legacies_Empire_Controller_DefenseController
{
parent::preDispatch();
if ($this->getResponse()->isDispatched()) {
return;
}
$planet = $this->getCurrentPlanet();
if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) {

View file

@ -13,10 +13,6 @@ class Legacies_Empire_Controller_ResearchLabController
{
parent::preDispatch();
if ($this->getResponse()->isDispatched()) {
return;
}
$planet = $this->getCurrentPlanet();
if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) {

View file

@ -13,10 +13,6 @@ class Legacies_Empire_Controller_ShipyardController
{
parent::preDispatch();
if ($this->getResponse()->isDispatched() || $this->getResponse()->isRedirect()) {
return;
}
$planet = $this->getCurrentPlanet();
if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) {

View file

@ -160,14 +160,13 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('fleets')} (
`fleet_end_system` SMALLINT UNSIGNED NOT NULL,
`fleet_end_planet` TINYINT UNSIGNED NOT NULL,
`fleet_end_type` TINYINT UNSIGNED NOT NULL,
`fleet_taget_owner` BIGINT UNSIGNED NOT NULL,
`fleet_target_owner` BIGINT UNSIGNED NOT NULL,
`fleet_resource_metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`fleet_resource_crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`fleet_resource_deuterium` DECIMAL(65,0) NOT NULL DEFAULT 0,
`fleet_target_owner` BIGINT UNSIGNED NOT NULL,
`fleet_group` BIGINT UNSIGNED NOT NULL,
`fleet_mess` BIGINT UNSIGNED NOT NULL,
`start_time` INT,
`start_time` TIMESTAMP NOT NULL,
PRIMARY KEY (`fleet_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
@ -286,7 +285,7 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('planets')} (
`planet` TINYINT UNSIGNED NOT NULL,
`last_update` DATETIME NOT NULL,
`planet_type` TINYINT UNSIGNED NOT NULL,
`destruyed` BOOL NOT NULL DEFAULT FALSE,
`destruyed` INT UNSIGNED NOT NULL DEFAULT FALSE,
`b_building` DATETIME NOT NULL,
`b_building_id` TEXT NOT NULL,
`b_tech` DATETIME NOT NULL,

View file

@ -22,7 +22,7 @@ class Legacies_Stats_Block_View
return $this->_statData;
}
public function getPlayerStatData($type)
public function getPlayerStatData()
{
if (empty($this->_statData)) {
$playerId = Wootook_Player_Model_Session::getSingleton()->getPlayerId();
@ -31,7 +31,6 @@ class Legacies_Stats_Block_View
$statement = $readAdapter->select()
->from($readAdapter->getTable('statpoints'))
->where('stat_type', $type)
->where('id_owner', $playerId)
->prepare()
;

View file

@ -189,6 +189,11 @@ class Wootook
return Wootook_Core_Model_Session::factory($namespace);
}
/**
* @static
* @param string|null $locale
* @return Wootook_Core_Model_Translator
*/
public static function getTranslator($locale = null)
{
if ($locale === null) {
@ -381,7 +386,7 @@ class Wootook
}
try {
$adapter = Wootook_Core_Database_ConnectionManager::getSingleton()
$adapter = Wootook_Core_Database_ConnectionManager::getSingleton()
->getConnection('core_read');
} catch (Wootook_Core_Exception_Database_AdapterError $e) {
self::$isInstalled = false;
@ -394,24 +399,21 @@ class Wootook
switch ($type) {
case 'website':
$select->where(new Wootook_Core_Database_Sql_Placeholder_Expression('website_id = :website_id', array('website_id' => $model->getId())));
$statement = $adapter->prepare($select);
$statement->execute();
break;
case 'game':
$select->where(new Wootook_Core_Database_Sql_Placeholder_Expression('game_id = :game_id', array('game_id' => $model->getId())));
$statement = $adapter->prepare($select);
$statement->execute();
break;
default:
$select->where('website_id', 0);
$select->where('game_id', 0);
$statement = $adapter->prepare($select);
$statement->execute();
break;
}
$statement = $select->prepare();
$statement->execute();
foreach ($statement as $row) {
$config->setConfig($row['config_path'], $row['config_value']);
}
@ -598,6 +600,7 @@ class Wootook
if (self::$_config === null) {
self::loadConfig();
}
if (!self::$isInstalled) {
if (isset(self::$_config['default'])) {
self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE] = clone self::$_config['default'];
@ -781,6 +784,7 @@ class Wootook
$queryParams = array();
if (isset($params['_query'])) {
$queryParams = $params['_query'];
unset($params['_query']);
}
$serializedParams = array();

View file

@ -112,44 +112,44 @@ class Wootook_Core_App
return $this->_newInstance($className, $constructorParams);
}
public function getModel($module, $class)
public function getModel($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->models, $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getResource($module, $class)
public function getResource($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->resources, $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getHelper($module, $class)
public function getHelper($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->helpers, $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getBlockSingleton($module, $class)
public function getBlockSingleton($module, $class, Array $constructorParams = array())
{
}
public function getModelSingleton($module, $class)
public function getModelSingleton($module, $class, Array $constructorParams = array())
{
}
public function getResourceSingleton($module, $class)
public function getResourceSingleton($module, $class, Array $constructorParams = array())
{
}
public function getHelperSingleton($module, $class)
public function getHelperSingleton($module, $class, Array $constructorParams = array())
{
}
}
}

View file

@ -16,4 +16,4 @@ class Wootook_Core_Block_Html_Page
return $this;
}
}
}

View file

@ -1,7 +1,7 @@
<?php
class Wootook_Core_Config_Node
implements ArrayAccess
implements ArrayAccess, Iterator, Countable
{
protected $_children = array();
@ -214,4 +214,34 @@ class Wootook_Core_Config_Node
unset($this->_children[$offset]);
}
}
}
public function valid()
{
return key($this->_children);
}
public function next()
{
next($this->_children);
}
public function current()
{
return current($this->_children);
}
public function rewind()
{
reset($this->_children);
}
public function key()
{
return key($this->_children);
}
public function count()
{
return count($this->_children);
}
}

View file

@ -11,6 +11,11 @@ abstract class Wootook_Core_Database_Adapter_Adapter
return $this->_handler;
}
public function getDataMapper()
{
return new Wootook_Core_Database_Orm_DataMapper();
}
/**
*
* @param string $prefix

View file

@ -35,4 +35,4 @@ class Wootook_Core_Database_Orm_DataMapper_DateTime
{
return new Wootook_Core_DateTime($value, $this->getFormat());
}
}
}

View file

@ -4,7 +4,7 @@ abstract class Wootook_Core_Database_Orm_DataMapper_FieldMapper
{
protected $_mapper = null;
public function __construct(Wootook_Core_Database_Orm_DataMapper $mapper)
public function __construct(Wootook_Core_Database_Orm_DataMapper $mapper = null)
{
$this->_mapper = $mapper;
}
@ -12,4 +12,4 @@ abstract class Wootook_Core_Database_Orm_DataMapper_FieldMapper
abstract public function encode($value);
abstract public function decode($value);
}
}

View file

@ -74,8 +74,9 @@ class Wootook_Core_Database_Sql_Delete
public function renderFrom()
{
if ($this->_parts[self::FROM]['schema'] !== null) {
return "DELETE FROM {$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['schema'])}.{$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['schema'])}";
return "DELETE FROM {$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['schema'])}.{$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['table'])}";
}
return "DELETE FROM {$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['table'])}";
}
public function render()

View file

@ -183,7 +183,7 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery
$dateValues = array();
if (isset($value['from'])) {
if ($value['from'] instanceof Wootook_Core_DateTime) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($this->getDataMapper()->load('DateTime')->encode($value['from']))}";
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['from']))}";
} else if (is_string($value['from'])) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}";
} else if (is_numeric($value['from'])) {
@ -192,7 +192,7 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery
}
if (isset($value['to'])) {
if ($value['to'] instanceof Wootook_Core_DateTime) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($this->getDataMapper()->load('DateTime')->encode($value['to']))}";
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['to']))}";
} else if (is_string($value['to'])) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}";
} else if (is_numeric($value['to'])) {

View file

@ -0,0 +1,20 @@
<?php
class Wootook_Core_Database_Sql_Placeholder_Variable
extends Wootook_Core_Database_Sql_Placeholder_Placeholder
{
protected $_paramType = null;
protected $_paramName = null;
protected $_value = null;
public function __construct($paramName, $type = null)
{
$this->_paramName = $paramName;
$this->_paramType = $type;
}
public function __toString()
{
return ':' . $this->_paramName;
}
}

View file

@ -3,6 +3,9 @@
class Wootook_Core_Database_Statement_Pdo_Mysql
extends Wootook_Core_Database_Statement_Statement
{
/**
* @var PDOStatement
*/
protected $_handler = null;
protected $_query = null;
@ -114,8 +117,20 @@ class Wootook_Core_Database_Statement_Pdo_Mysql
*/
public function fetchAll($style = null, $col = null)
{
throw new Wootook_Core_Exception_Database_StatementError($this, 'Unimplemented', null, $e);
return array();
try {
if ($style !== null) {
if ($col !== null) {
$result = $this->_handler->fetchAll($style, $col);
} else {
$result = $this->_handler->fetchAll($style);
}
} else {
$result = $this->_handler->fetchAll($style);
}
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return $result;
}
/**

View file

@ -100,7 +100,9 @@ abstract class Wootook_Core_Database_Statement_Statement
}
$data = $this->fetch(Wootook_Core_Database_ConnectionManager::FETCH_ASSOC);
$object->getDataMapper()->decode($object, $data);
if ($data !== false) {
$object->getDataMapper()->decode($object, $data);
}
return $object;
}
@ -202,11 +204,12 @@ abstract class Wootook_Core_Database_Statement_Statement
public function rewind()
{
return $this->_currentIndex = 0;
return $this->_currentIndex;
}
public function valid()
{
return $this->_currentRow !== null;
$rows = $this->rowCount();
return $rows > 0 && $this->_currentIndex <= $rows;
}
}

View file

@ -143,14 +143,14 @@ class Wootook_Core_DateTime
case self::SECOND:
$current = getdate($this->_datetime);
if ($type === self::OPERATOR_ADD) {
$parts = $current[$part] += $value;
$current[$part] += $value;
} else if ($type === self::OPERATOR_SUB) {
$parts = $current[$part] -= $value;
$current[$part] -= $value;
} else if ($type === self::OPERATOR_SET) {
$parts = $current[$part] = $value;
$current[$part] = $value;
}
$this->_datetime = $this->_mktime($parts);
$this->_datetime = $this->_mktime($current);
break;
case self::TIMESTAMP:
@ -173,6 +173,22 @@ class Wootook_Core_DateTime
return $this->_datetime - $date->_datetime;
}
public function isEarlier(self $date = null)
{
if ($date === null) {
$date = new self();
}
return (bool) ($this->diff($date) > 0);
}
public function isLater(self $date = null)
{
if ($date === null) {
$date = new self();
}
return (bool) ($this->diff($date) < 0);
}
protected function _mktime(Array $parts)
{
return mktime($parts[self::HOUR], $parts[self::MINUTE], $parts[self::SECOND],

View file

@ -2,30 +2,49 @@
class Wootook_Core_Email
{
protected static $_defaultHeadrs = array(
);
/**
* @var Wootook_Core_Email_Transport_Transport
*/
protected $_transport = null;
protected $_headers = array();
public function __construct(Wootook_Core_Email_Transport_Transport $transport = null)
{
if ($transport === null) {
$transport = new Wootook_Core_Email_Transport_Sendmail();
}
$this->setTransport($transport);
}
public function setTransport(Wootook_Core_Email_Transport_Transport $transport)
{
$this->_transport = $transport;
}
/**
* @return Wootook_Core_Email_Transport_Transport
*/
public function getTransport()
{
return $this->_transport;
}
public function send($to, $from, $subject, $body, Array $headers = array())
{
$this->_prepareHeaders($headers);
}
public function setHeader($name, $value)
{
$this->_headers[$name] = $value;
}
protected function _prepareHeaders($headers)
{
foreach ($headers as $name => $value) {
$this->setHeader($name, $value);
try {
$this->_transport
->addRecipient($to)
->setFrom($from)
->setSubject($subject)
->addPart(new Wootook_Core_Email_Part_Part($body))
->addHeaders($headers)
->connect()
->send()
;
} catch (Wootook_Core_Exception_RuntimeException $e) {
throw new Wootook_Core_Exception_RuntimeException('Could not send mail.', null, $e);
}
$this->addHeader('X-Mailer', 'PHP/' . PHP_VERSION . ' Wootook/' . VERSION);
$this->addHeader('Content-Transfer-Encoding', '7bit');
$this->addHeader('Content-Type', 'text/plain; charset=utf-8');
$this->_transport->disconnect();
return $this;
}

View file

@ -0,0 +1,16 @@
<?php
class Wootook_Core_Email_Part_Part
{
protected $_content = null;
public function __construct($content, $mime = 'text/plain')
{
$this->_content = $content;
}
public function render()
{
return $this->_content;
}
}

View file

@ -0,0 +1,162 @@
<?php
class Wootook_Core_Email_Transport_Sendmail
implements Wootook_Core_Email_Transport_Transport
{
protected static $_defaultHeaders = array();
protected $_headers = array();
protected $_parts = array();
protected $_from = null;
protected $_recipients = array();
protected $_subject = array();
public function __construct()
{
$this->_prepareHeaders();
}
public function setFrom($from)
{
if (is_array($from)) {
$this->_from = sprintf('"%s" <%s>', $this->_formatUnicode(current($from)), key($from));
} else {
$this->_from = $from;
}
return $this;
}
public function clearFrom()
{
$this->_from = null;
return $this;
}
public function addRecipient($recipient)
{
if (is_array($recipient)) {
foreach ($recipient as $email => $name) {
$this->_recipients[] = sprintf('"%s" <%s>', $this->_formatUnicode($name), $email);
}
} else {
$this->_recipients[] = $recipient;
}
return $this;
}
public function clearRecipients()
{
$this->_recipients = array();
return $this;
}
public function setSubject($subject)
{
$this->_subject = $this->_formatUnicode($subject);
return $this;
}
public function clearSubject()
{
$this->_subject = null;
return $this;
}
public function addHeader($name, $value)
{
$this->_headers[$name] = $value;
return $this;
}
public function addHeaders($headers)
{
foreach ($headers as $name => $value) {
$this->_headers[$name] = $value;
}
return $this;
}
public function clearHeaders()
{
$this->_headers = array();
return $this;
}
public function addPart(Wootook_Core_Email_Part_Part $part)
{
$this->_parts[] = $part;
return $this;
}
public function clearParts()
{
$this->_parts = array();
return $this;
}
protected function _formatUnicode($string)
{
return '=?UTF-8?B?' . base64_encode($string) . '?=';
}
protected function _prepareHeaders(Array $headers = array())
{
$this->addHeader('MIME-Version', '1.0');
foreach ($headers as $name => $value) {
$this->setHeader($name, $value);
}
$this->addHeader('X-Mailer', 'PHP/' . PHP_VERSION . ' Wootook/' . VERSION);
$this->addHeader('Content-Transfer-Encoding', '8bit');
$this->addHeader('Content-Type', 'text/plain; charset=utf-8; format=flowed');
return $this;
}
public function reset()
{
$this->clearHeaders();
$this->clearParts();
$this->clearFrom();
$this->clearRecipients();
$this->clearSubject();
return $this;
}
public function connect()
{
return $this;
}
public function disconnect()
{
return $this;
}
public function send()
{
$content = '';
foreach ($this->_parts as $part) {
$content .= $part->render();
}
$this->addHeader('To', implode(',', $this->_recipients));
if (!mail(implode(',', $this->_recipients), $this->_subject, $content, implode("\r\n", $this->_headers))) {
throw new Wootook_Core_Exception_RuntimeException('Could not send mail.');
}
return $this;
}
}

View file

@ -0,0 +1,22 @@
<?php
interface Wootook_Core_Email_Transport_Transport
{
public function setFrom($from);
public function addRecipient($recipient);
public function setSubject($subject);
public function addHeader($name, $value);
public function addPart(Wootook_Core_Email_Part_Part $part);
public function reset();
public function clearFrom();
public function clearHeaders();
public function clearRecipients();
public function clearSubject();
public function clearParts();
public function connect();
public function disconnect();
public function send();
}

View file

@ -68,7 +68,10 @@ class Wootook_Core_ErrorProfiler
return;
}
$trace = debug_backtrace();
switch ($errno) {
case E_RECOVERABLE_ERROR:
case E_USER_ERROR:
case E_ERROR:
$this->_errors[] = array(
@ -77,7 +80,8 @@ class Wootook_Core_ErrorProfiler
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
'context' => $errcontext,
'trace' => $trace
);
break;
@ -89,7 +93,8 @@ class Wootook_Core_ErrorProfiler
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
'context' => $errcontext,
'trace' => $trace
);
break;
@ -101,7 +106,8 @@ class Wootook_Core_ErrorProfiler
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
'context' => $errcontext,
'trace' => $trace
);
break;
@ -116,7 +122,8 @@ class Wootook_Core_ErrorProfiler
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
'context' => $errcontext,
'trace' => $trace
);
break;
}
@ -172,10 +179,87 @@ Type: {$code}
Message: {$error['message']}
File: {$error['file']}
Line: {$error['line']}
\n
{$this->_renderBacktrace($error['trace'])}
ERROR_EOF;
}
protected function _renderBacktrace(Array $traces)
{
$output = '<pre>';
foreach (array_slice($traces, 1) as $key => $trace) {
if (preg_match('#^(include|require)(_once)?$#', $trace['function'])) {
$output .= sprintf("#%d %s(%s) called at [%s:%s]\n",
$key, $trace['function'], $trace['args'][0], $trace['file'], $trace['line']);
} else if (!isset($trace['file']) || !isset($trace['line'])) {
if (isset($trace['class'])) {
$output .= sprintf("#%d Internal function <code>%s%s%s(%s)</code>\n",
$key, $trace['class'], $trace['type'], $trace['function'], implode(', ', $this->_formatArgs($trace['args'])));
} else {
$output .= sprintf("#%d Internal function <code>%s(%s)</code>\n",
$key, $trace['function'], implode(', ', $this->_formatArgs($trace['args'])));
}
} else {
if (isset($trace['class'])) {
$output .= sprintf("#%d <code>%s%s%s(%s)</code> called at [%s:%s]\n",
$key, $trace['class'], $trace['type'], $trace['function'], implode(', ', $this->_formatArgs($trace['args'])), $trace['file'], $trace['line']);
} else {
$output .= sprintf("#%d <code>%s(%s)</code> called at [%s:%s]\n",
$key, $trace['function'], implode(', ', $this->_formatArgs($trace['args'])), $trace['file'], $trace['line']);
}
}
}
return $output . '</pre>';
}
private function _formatArgs($args)
{
$argumentList = array();
foreach ($args as $argument) {
if (is_object($argument)) {
$argumentList[] = get_class($argument);
} else if (is_array($argument)) {
$keys = array_keys($argument);
$values = $this->_formatArgs($argument);
$length = count($values);
$output = array();
for ($index = 0; $index < $length; $index++) {
$output[] = sprintf('[%s] => %s', $keys[$index], $values[$index]);
}
$argumentList[] = '[' . implode(', ', $output) . ']';
} else {
$argumentList[] = var_export($argument, true);
}
}
return $argumentList;
}
protected function _renderConfig(Wootook_Core_Config_Node $config, $level = 0)
{
$output = '<ul style="list-style:none;padding:5px;margin:5px 10px;border:1px solid gray">';
foreach ($config as $key => $value) {
$output .= sprintf('<li style="">', $level);
$output .= sprintf('<span style="text-decoration:underline;padding-right:10px;font-family:monospace;color:darkred;font-weight:bold;font-size:12px;">%s</span>', $key);
if ($value instanceof Wootook_Core_Config_Node) {
if (count($value) > 0) {
$output .= $this->_renderConfig($value, $level + 1);
} else {
$output .= '<em>Empty node</em>';
}
} else {
$output .= '<code style="font-family:monospace;font-size:12px;">' . htmlspecialchars(var_export($value, true), ENT_QUOTES, 'UTF-8') . '</code>';
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
public function shutdownManager()
{
if ($this->_mute === true) {
@ -185,66 +269,140 @@ ERROR_EOF;
$index = 0;
echo '<div style="background:#FFF;border:5px solid #933;border-top-width:15px;border-radius:5px;color:#000;padding:0;margin:20px;text-align:left;margin:50px auto;width:800px;">';
echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Debug profiler</h1>';
if (count($this->_errors) <= 0 && count($this->_warnings) <= 0 &&
count($this->_notices) <= 0 && count($this->_otherErrors) <= 0 &&
count($this->_exceptions) <= 0) {
echo '<p style="color:#666;font-style:italic;margin:20px 10px 10px;">Error profiler was empty.</p>';
} else {
echo '<div style="margin:0;overflow:auto;">';
foreach ($this->_errors as $error) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:0 5px;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
foreach ($this->_warnings as $error) {
echo '<div style="margin:0;overflow:auto;">';
echo '</div>';
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="errors" class="error-profiler-link">Errors (' . count($this->_errors) . ')</h2>';
echo '<div class="error-profiler errors">';
foreach ($this->_errors as $error) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:0 5px;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
echo '</div>';
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="warnings" class="error-profiler-link">Warnings (' . count($this->_warnings) . ')</h2>';
echo '<div class="error-profiler warnings">';
foreach ($this->_warnings as $error) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
echo '</div>';
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="notices" class="error-profiler-link">Notices (' . count($this->_notices) . ')</h2>';
echo '<div class="error-profiler notices">';
foreach ($this->_notices as $error) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
echo '</div>';
foreach ($this->_otherErrors as $errno => $errorList) {
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="other' . $errno . '" class="error-profiler-link">Other error errno#' . $errno . ' (' . count($errorList) . ')</h2>';
echo '<div class="error-profiler other' . $errno . '">';
foreach ($errorList as $error) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
foreach ($this->_notices as $error) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
foreach ($this->_otherErrors as $errorList) {
foreach ($errorList as $error) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
}
foreach ($this->_exceptions as $exception) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $exception->getMessage() . PHP_EOL;
echo $exception->getTraceAsString() . PHP_EOL;
echo '</pre>';
echo '</div>';
}
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="exceptions" class="error-profiler-link">Exceptions (' . count($this->_exceptions) . ')</h2>';
echo '<div class="error-profiler exceptions">';
foreach ($this->_exceptions as $exception) {
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $exception->getMessage() . PHP_EOL;
echo $exception->getTraceAsString() . PHP_EOL;
echo '</pre>';
$child = 0;
$current = $exception;
while (($current = $current->getPrevious()) !== null) {
$child++;
echo '<h3 style="font-size:1em;text-decoration:none;margin:10px 30px 0;">Message #' . $index . ', child level #' . $child . '</h3>';
echo '<pre style="margin:0 30px;">';
echo $current->getMessage() . PHP_EOL;
echo $current->getTraceAsString() . PHP_EOL;
echo PHP_EOL;
echo '</pre>';
}
$child = 0;
$current = $exception;
while (($current = $current->getPrevious()) !== null) {
$child++;
echo '<h3 style="font-size:1em;text-decoration:none;margin:10px 30px 0;">Message #' . $index . ', child level #' . $child . '</h3>';
echo '<pre style="margin:0 30px;">';
echo $current->getMessage() . PHP_EOL;
echo $current->getTraceAsString() . PHP_EOL;
echo PHP_EOL;
echo '</pre>';
}
echo '</div>';
}
echo '</div>';
echo <<<JS_EOF
<script>
(function(){
var sections = jQuery('.error-profiler');
sections.each(function(){
var element = jQuery(this);
element.hide();
});
jQuery('.error-profiler-link').click(function(e){
var rel = jQuery(this).attr('rel');
sections.each(function(){
var element = jQuery(this);
if (element.hasClass(rel) && !element.hasClass('opened')) {
element.slideDown(500, function(){element.addClass('opened');});
} else {
element.slideUp(500, function(){element.removeClass('opened');});
}
});
});
})();
</script>
JS_EOF;
echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Configuration profiler</h1>';
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="global" class="config-profiler-link">Global configuration</h2>';
echo '<div class="config-profiler global">';
$config = clone Wootook::getConfig();
foreach ($config->getConfig('resource/database') as $node) {
if ($node->params) {
$node->params->reset();
}
}
echo $this->_renderConfig(Wootook::getConfig(), 0);
echo '</div>';
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="website" class="config-profiler-link">Website configuration</h2>';
echo '<div class="config-profiler website">';
echo $this->_renderConfig(Wootook::getWebsiteConfig());
echo '</div>';
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="game" class="config-profiler-link">Game configuration</h2>';
echo '<div class="config-profiler game">';
echo $this->_renderConfig(Wootook::getGameConfig());
echo '</div>';
echo '</div>';
echo <<<JS_EOF
<script>
(function(){
var sections = jQuery('.config-profiler');
sections.each(function(){
var element = jQuery(this);
element.hide();
});
jQuery('.config-profiler-link').click(function(e){
var rel = jQuery(this).attr('rel');
sections.each(function(){
var element = jQuery(this);
if (element.hasClass(rel) && !element.hasClass('opened')) {
element.slideDown(500, function(){element.addClass('opened');});
} else {
element.slideUp(500, function(){element.removeClass('opened');});
}
});
});
})();
</script>
JS_EOF;
}
public static function register()

View file

@ -197,6 +197,7 @@ class Wootook_Core_Mvc_Controller_Front
$this->_response->setIsDispatched();
$this->preDispatch();
$controller->preDispatch();
if (!$this->_response->isDispatched()) {
continue;
@ -212,6 +213,7 @@ class Wootook_Core_Mvc_Controller_Front
}
$controller->postDispatch();
$this->postDispatch();
if ($this->_response->isDispatched() || $this->_response->isRedirect()) {
break;
@ -246,4 +248,24 @@ class Wootook_Core_Mvc_Controller_Front
return $this;
}
public function preDispatch()
{
Wootook::dispatchEvent('core.mvc.controller.front.pre-dispatch', array(
'request' => $this->_request,
'response' => $this->_response
));
return $this;
}
public function postDispatch()
{
Wootook::dispatchEvent('core.mvc.controller.front.post-dispatch', array(
'request' => $this->_request,
'response' => $this->_response
));
return $this;
}
}

View file

@ -32,7 +32,12 @@ class Wootook_Core_Mvc_Controller_Request_Http
$params = '';
if (($offset = strpos($this->getServer('REQUEST_URI'), $baseUri)) !== false) {
$path = substr($this->getServer('REQUEST_URI'), $offset + strlen($baseUri));
$queryParamsOffset = strpos($this->getServer('REQUEST_URI'), '?');
if ($queryParamsOffset !== false) {
$path = substr($this->getServer('REQUEST_URI'), $offset + strlen($baseUri), $queryParamsOffset - $offset - 1);
} else {
$path = substr($this->getServer('REQUEST_URI'), $offset + strlen($baseUri));
}
$moduleOffset = strpos($path, '/');
if ($moduleOffset !== false) {

View file

@ -59,11 +59,12 @@ abstract class Wootook_Core_Mvc_Model_Entity
if (!is_array($datas) || empty($datas)) {
throw new Wootook_Core_Exception_DataAccessException('Could not load data: this id could not be found.');
}
$realId = $datas[$this->getIdFieldName()];
unset($datas[$this->getIdFieldName()]);
$this->_data = array();
$this->getDataMapper()->decode($this, $datas);
$this->setId($id);
$this->setId($realId);
return $this;
}

View file

@ -90,6 +90,17 @@ class Wootook_Core_Mvc_View_View
}
}
public function renderDateTime($dateTime, $format = null)
{
if ($format === null) {
$format = 'H:i:s';
}
if (!$dateTime instanceof Wootook_Core_DateTime) {
$dateTime = new Wootook_Core_DateTime($dateTime);
}
return $dateTime->toString($format);
}
public function escape($unescaped)
{
return htmlspecialchars($unescaped, ENT_QUOTES, 'UTF-8');

View file

@ -21,7 +21,7 @@ abstract class Wootook_Core_Resource_EntityCollection
protected $_items = array();
public function __construct(Wootook_Core_Database_Adapter_Pdo_Mysql $connection = null)
public function __construct(Wootook_Core_Database_Adapter_Adapter $connection = null)
{
$this->setReadConnection($connection);
@ -153,17 +153,28 @@ abstract class Wootook_Core_Resource_EntityCollection
return $this;
}
public function getSize()
public function getSize($maintainGrouping = array())
{
$clone = clone $this->_select;
$clone->_fields = array();
$clone->column('1');
$clone->reset(Wootook_Core_Database_Sql_Select::COLUMNS);
if (empty($maintainGrouping)) {
$clone->reset(Wootook_Core_Database_Sql_Select::GROUP);
} else {
$groupingFields = $clone->getPart(Wootook_Core_Database_Sql_Select::GROUP);
$clone->reset(Wootook_Core_Database_Sql_Select::GROUP);
foreach ($groupingFields as $field) {
if (in_array($field, $maintainGrouping)) {
$clone->group($field);
}
}
}
$clone->column(new Wootook_Core_Database_Sql_Placeholder_Expression('COUNT(*)'));
$database = $this->getReadConnection();
$statement = $database->prepare($clone);
$statement->execute();
$count = $statement->rowCount();
$count = $statement->fetchColumn();
$statement->closeCursor();
return $count;

View file

@ -0,0 +1,77 @@
<?php
class Wootook_Empire_Block_Overview_Fleet_List
extends Wootook_Core_Block_Template
{
protected $_itemTemplate = null;
protected $_itemBlockType = null;
protected $_fleetCollection = null;
public function getFleetCollection()
{
if ($this->_fleetCollection === null) {
$player = Wootook_Player_Model_Session::getSingleton()->getPlayer();
$this->_fleetCollection = $player->getVisibleFleets();
}
return $this->_fleetCollection;
}
public function setItemTemplate($template)
{
$this->_itemTemplate = $template;
return $this;
}
public function getItemTemplate()
{
return $this->_itemTemplate;
}
public function setItemBlockType($blockType)
{
$this->_itemBlockType = $blockType;
return $this;
}
public function getItemBlockType()
{
return $this->_itemBlockType;
}
public function getItemBlock($fleet)
{
$blockName = $this->getNameInLayout() . ".item({$fleet->getId()})";
return $this->getLayout()
->createBlock($this->getItemBlockType(), $blockName)
->setTemplate($this->getItemTemplate())
->setFleetItem($fleet);
}
public function prepareLayout()
{
parent::prepareLayout();
$this->_initChildBlocks();
return $this;
}
public function _initChildBlocks()
{
$parentBlock = $this->getLayout()
->createBlock('core/concat', $this->getNameInLayout() . '.item-list')
;
$this->setPartial('item-list', $parentBlock);
foreach ($this->getFleetCollection()->load() as $fleet) {
$block = $this->getItemBlock($fleet);
$parentBlock->setPartial($block->getNameInLayout(), $block);
}
return $this;
}
}

View file

@ -0,0 +1,153 @@
<?php
class Wootook_Empire_Block_Overview_Fleet_List_Item
extends Wootook_Core_Block_Template
{
protected $_fleet = null;
protected $_currentPlayer = null;
protected $_ownerCollection = null;
/**
* @return Wootook_Player_Model_Entity
*/
public function getPlayer()
{
if ($this->_currentPlayer == null) {
$this->_currentPlayer = Wootook_Player_Model_Session::getSingleton()->getPlayer();
}
return $this->_currentPlayer;
}
/**
* @return Wootook_Player_Resource_Entity_Collection
*/
public function getFleetOwnerCollection()
{
if ($this->_ownerCollection == null) {
$this->_ownerCollection = $this->getFleetItem()->getOwnerCollection();
}
return $this->_ownerCollection;
}
/**
* @return Wootook_Player_Resource_Entity_Collection
*/
public function getFleetOwnerUsernames()
{
$usernameList = array();
foreach ($this->getFleetOwnerCollection()->load() as $owner) {
$usernameList[] = $owner->getUsername();
}
return $usernameList;
}
public function setFleetItem(Wootook_Empire_Model_Fleet $fleetItem)
{
$this->_fleet = $fleetItem;
return $this;
}
/**
* @return Wootook_Empire_Model_Fleet
*/
public function getFleetItem()
{
return $this->_fleet;
}
public function getStartTime()
{
return $this->getFleetItem()->getStartTime();
}
public function getActionTime()
{
return $this->getFleetItem()->getActionTime();
}
public function getArrivalTime()
{
return $this->getFleetItem()->getArrivalTime();
}
public function isOwner()
{
return $this->getFleetItem()->isOwnedBy($this->getPlayer());
}
public function getRowClass()
{
return $this->getFleetItem()->getRowClass($this->getPlayer());
}
public function getOriginPlanet()
{
return $this->getFleetItem()->getOriginPlanet();
}
public function getOriginPlayer()
{
return $this->getOriginPlanet()->getPlayer();
}
public function getOriginPlayerName()
{
$player = $this->getOriginPlanet()->getPlayer();
if ($player !== null) {
return $player->getUsername();
}
return null;
}
public function getOriginPlanetName()
{
return $this->getOriginPlanetName();
}
public function getOriginPlanetCoords()
{
return $this->getOriginPlanetCoords();
}
public function getDestinationPlanet()
{
return $this->getFleetItem()->getDestinationPlanet();
}
public function getDestinationPlayer()
{
return $this->getDestinationPlanet()->getPlayer();
}
public function getDestinationPlayerName()
{
$player = $this->getDestinationPlanet()->getPlayer();
if ($player !== null) {
return $player->getUsername();
}
return null;
}
public function getDestinationPlanetName()
{
return $this->getDestinationPlanetName();
}
public function getDestinationPlanetCoords()
{
return $this->getDestinationPlanetCoords();
}
public function getMissionLabel()
{
return $this->getFleetItem()->getMissionLabel();
}
public function isMission($type)
{
return $this->getFleetItem()->isMission($type);
}
}

View file

@ -34,6 +34,12 @@ class Wootook_Empire_Model_Fleet
{
$this->setIdFieldName('fleet_id');
$this->setTableName('fleets');
$this->getDataMapper()
->addRule('fleet_start_time', 'date-time')
->addRule('fleet_end_time', 'date-time')
->addRule('fleet_end_stay', 'date-time')
;
}
public static function planetListener($eventData)
@ -48,10 +54,16 @@ class Wootook_Empire_Model_Fleet
return false;
}
public function getOwner()
/**
* @return null|Wootook_Player_Resource_Entity_Collection
*/
public function getOwnerCollection()
{
if ($id = $this->getData('fleet_owner')) {
return Wootook_Player_Model_Entity::factory($id);
$ownerCollection = new Wootook_Player_Resource_Entity_Collection($this->getReadConnection());
$ownerCollection->addFieldToFilter('id', $id);
return $ownerCollection;
}
return null;
}
@ -86,6 +98,8 @@ class Wootook_Empire_Model_Fleet
return 'missiles';
} else if ($this->isMission(Legacies_Empire::ID_MISSION_EXPEDITION)) {
return 'expedition';
} else if ($this->isMission(Legacies_Empire::ID_MISSION_ORE_MINING)) {
return 'ore-mining';
}
}
@ -107,25 +121,34 @@ class Wootook_Empire_Model_Fleet
return Wootook::__('Missiles Launch');
} else if ($this->isMission(Legacies_Empire::ID_MISSION_EXPEDITION)) {
return Wootook::__('Expedition');
} else if ($this->isMission(Legacies_Empire::ID_MISSION_ORE_MINING)) {
return Wootook::__('Ore mining');
}
return Legacies::__('Unknown');
}
/**
* @return Wootook_Core_DateTime
*/
public function getStartTime()
{
return $this->getData('fleet_start_time');
}
/**
* @return Wootook_Core_DateTime
*/
public function getActionTime()
{
return $this->getData('fleet_end_stay');
}
/**
* @return Wootook_Core_DateTime
*/
public function getArrivalTime()
{
if ($this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)) {
return $this->getActionTime();
}
return $this->getData('fleet_end_time');
}
@ -141,15 +164,85 @@ class Wootook_Empire_Model_Fleet
return Wootook_Empire_Model_Planet::factoryFromCoords($coords, $type);
}
public function getOriginPlanetName()
{
if (!($planet = $this->getOriginPlanet()->getId())) {
return '';
}
return $planet->getName();
}
public function getOriginPlanetCoords()
{
if (!($planet = $this->getOriginPlanet()->getId())) {
return sprintf('%s:%s:%s', $this->getData('fleet_start_galaxy'), $this->getData('fleet_start_system'), $this->getData('fleet_start_planet'));
}
return $planet->getCoords();
}
public function getDestinationPlanet()
{
$coords = array(
'galaxy' => $this->getData('fleet_end_galaxy'),
'system' => $this->getData('fleet_end_system'),
'position' => $this->getData('fleet_end_planet')
);
);
$type = $this->getData('fleet_end_type');
return Wootook_Empire_Model_Planet::factoryFromCoords($coords, $type);
}
public function getDestinationPlanetName()
{
if (!($planet = $this->getDestinationPlanet()->getId())) {
return '';
}
return $planet->getName();
}
public function getDestinationPlanetCoords()
{
if (!($planet = $this->getDestinationPlanet()->getId())) {
return sprintf('%s:%s:%s', $this->getData('fleet_end_galaxy'), $this->getData('fleet_end_system'), $this->getData('fleet_end_planet'));
}
return $planet->getCoords();
}
public function goBack()
{
$this->setData('fleet_mess', 1)->save();
return $this;
}
/**
* @param Wootook_Empire_Model_Planet $planet
* @return Wootook_Empire_Model_Fleet
*/
public function dock(Wootook_Empire_Model_Planet $planet)
{
// Backward-compatible way to unserialize fleet ships listing
$serializedFleetArray = $this->getData('fleet_array');
foreach (explode(';', $serializedFleetArray) as $fleetShipData) {
if (empty($fleetShipData)) {
continue;
}
$fleetShipData = explode(',', $fleetShipData);
if (count($fleetShipData) != 2) {
continue;
}
$planet->setElement($fleetShipData[0], Math::add($planet->getElement($fleetShipData[0]), $fleetShipData[1]));
}
$planet
->setData('metal', Math::add($planet->getData('metal'), $this->getData('fleet_resource_metal')))
->setData('cristal', Math::add($planet->getData('cristal'), $this->getData('fleet_resource_crystal')))
->setData('deuterium', Math::add($planet->getData('deuterium'), $this->getData('fleet_resource_deuterium')))
->save();
;
$this->delete();
return $this;
}
}

View file

@ -105,7 +105,8 @@ class Wootook_Empire_Model_Planet
->getConnection('core_read');
$collection = new Wootook_Empire_Resource_Planet_Collection($adapter);
$collection->addCoordsToFilter($coords['galaxy'], $coords['system'], $coords['position'], $coords['type'])
->setPage(1, 1);
->setPage(1, 1)
->load();
$planet = $collection->getFirstItem();
if ($planet !== null) {
@ -166,6 +167,9 @@ class Wootook_Empire_Model_Planet
throw new Wootook_Core_Exception_RuntimeException(Wootook::__('Undefined method %s::%s.', get_class($this), $method));
}
/**
* @return Wootook_Core_DateTime
*/
public function getLastUpdate()
{
return $this->getData('last_update');
@ -424,7 +428,7 @@ class Wootook_Empire_Model_Planet
public function getFleetCollection($time = null)
{
$collection = new Wootook_Empire_Resource_Fleet_Collection();
$collection = new Wootook_Empire_Resource_Fleet_Collection($this->getReadConnection());
$collection->addPlanetToFilter($this, $time);
return $collection;
@ -469,22 +473,18 @@ class Wootook_Empire_Model_Planet
public function getMoon()
{
static $statement = null;
if ($this->isMoon()) {
return null;
}
if ($this->_moon === null) {
if ($statement === null) {
$collection = new Wootook_Empire_Resource_Planet_Collection($this->getReadConnection());
$collection->addFieldToFilter('galaxy', $this->getGalaxy())
->addFieldToFilter('system', $this->getGalaxy())
->addFieldToFilter('planet', $this->getPosition())
->addFieldToFilter('planet_type', self::TYPE_MOON)
->load()
;
}
$collection = new Wootook_Empire_Resource_Planet_Collection($this->getReadConnection());
$collection->addFieldToFilter('galaxy', $this->getGalaxy())
->addFieldToFilter('system', $this->getGalaxy())
->addFieldToFilter('planet', $this->getPosition())
->addFieldToFilter('planet_type', self::TYPE_MOON)
->load()
;
$this->_moon = $collection->getFirstItem();
@ -606,7 +606,7 @@ class Wootook_Empire_Model_Planet
public function isDestroyed()
{
return (bool) $this->getData('destruyed');
return (bool) ($this->getData('destruyed') > 0);
}
public function destroy()
@ -641,13 +641,21 @@ class Wootook_Empire_Model_Planet
}
$this
->setData('destruyed', true)
->setData('destruyed', time() + 172800)
->setData('id_owner', 0)
->save();
return $this;
}
public function isErasable()
{
if ($this->isDestroyed() && $this->getData('destruyed') >= time()) {
return true;
}
return false;
}
public function getElement($elementId)
{
$fields = Wootook_Empire_Helper_Config_FieldsAlias::getSingleton();
@ -896,6 +904,32 @@ class Wootook_Empire_Model_Planet
return intval($value);
}
public static function planetChangeListener($eventData)
{
if (!isset($eventData['request']) || !$eventData['request'] instanceof Wootook_Core_Mvc_Controller_Request_Http) {
return;
}
/** @var Wootook_Core_Mvc_Controller_Request_Http $request */
$request = $eventData['request'];
if (!($planetId = $request->getQuery('___planet'))) {
return;
}
$session = Wootook_Player_Model_Session::getSingleton();
if (!$session->isLoggedIn()) {
return;
}
$planet = new Wootook_Empire_Model_Planet();
$planet->load($planetId);
if (!$planet->getId()) {
return;
}
$player = $session->getPlayer();
$player->setCurrentPlanet($planet);
}
public static function planetUpdateListener($eventData)
{
if (isset($eventData['planet'])) {

View file

@ -10,20 +10,23 @@ class Wootook_Empire_Resource_Fleet_Collection
public function addPlanetToFilter(Wootook_Empire_Model_Planet $planet, $time = null)
{
if ($time === null) {
$time = new Wootook_Core_DateTime();
}
$this->addFieldToFilter(null, array(
array('and' => array(
array('eq' => array('field' => 'fleet_start_galaxy', 'value' => $planet->getGalaxy())),
array('eq' => array('field' => 'fleet_start_system', 'value' => $planet->getSystem())),
array('eq' => array('field' => 'fleet_start_planet', 'value' => $planet->getPosition())),
array('eq' => array('field' => 'fleet_start_type', 'value' => $planet->getType())),
array('date' => array('field' => 'fleet_start_time', 'value' => array('to' => $time))),
//array('date' => array('field' => 'fleet_start_time', 'value' => array('to' => $time))),
)),
array('and' => array(
array('eq' => array('field' => 'fleet_end_galaxy', 'value' => $planet->getGalaxy())),
array('eq' => array('field' => 'fleet_end_system', 'value' => $planet->getSystem())),
array('eq' => array('field' => 'fleet_end_planet', 'value' => $planet->getPosition())),
array('eq' => array('field' => 'fleet_end_type', 'value' => $planet->getType())),
array('date' => array('field' => 'fleet_end_time', 'value' => array('to' => $time))),
//array('date' => array('field' => 'fleet_end_time', 'value' => array('to' => $time))),
))
));
@ -32,6 +35,9 @@ class Wootook_Empire_Resource_Fleet_Collection
public function addIsVisibleToFilter(Wootook_Player_Model_Entity $player, $time = null)
{
if ($time === null) {
$time = new Wootook_Core_DateTime();
}
$this->addFieldToFilter(null, array(
array('and' => array(
array('eq' => array('field' => 'fleet_owner', 'value' => $player->getId())),

View file

@ -41,7 +41,7 @@ class Wootook_Player_Controller_AccountController
{
$session = new Wootook_Player_Model_Session();
if ($session->isLoggedIn()) {
$this->_redirect('player/overview');
$this->_redirect('*/overview');
return;
}
@ -55,27 +55,29 @@ class Wootook_Player_Controller_AccountController
$request = $this->getRequest();
if (!$request->isPost()) {
$this->_redirect('player/account/login');
$this->_redirect('*/*/login');
return;
}
if ($request->getPost('username') === null || $request->getPost('password') === null) {
$this->_redirect('player/account/login');
$this->_redirect('*/*/login');
return;
}
$session = new Wootook_Player_Model_Session();
if ($session->isLoggedIn()) {
$this->_redirect('player/overview');
$this->_redirect('*/overview');
return;
}
$session->login($request->getPost('username'), $request->getPost('password'), (bool) $request->getPost('rememberme'));
if ($session->isLoggedIn()) {
$this->_redirect('player/overview');
$this->_redirect('*/overview');
return;
} else {
$this->_redirect('player/account/login');
$this->_redirect('*/*/login');
return;
}
}
@ -84,6 +86,9 @@ class Wootook_Player_Controller_AccountController
$session = Wootook_Player_Model_Session::getSingleton();
if ($session->isLoggedIn()) {
$session->logout();
} else {
$this->_redirect('*/*/login');
return;
}
$this->_redirect('');
@ -93,16 +98,131 @@ class Wootook_Player_Controller_AccountController
{
$session = new Wootook_Player_Model_Session();
if ($session->isLoggedIn()) {
$this->_redirect('player/overview');
$this->_redirect('*/overview');
return;
}
$this->loadLayout('player.registration');
$this->_prepareLayoutMessages(Wootook_Player_Model_Entity::SESSION_KEY);
$this->renderLayout();
}
public function logoutSuccessAction()
public function newPostAction()
{
$session = Wootook_Player_Model_Session::getSingleton();
if ($session->isLoggedIn()) {
$this->_redirect('*/overview');
return;
}
$request = $this->getRequest();
if ($request->getPost('password') != $request->getPost('password_confirm')) {
$session->addError(Wootook::__('Passwords does not match. Please check your input.'));
$this->_redirect('*/*/new');
return;
}
if ($request->getPost('email') != $request->getPost('email_confirm')) {
$session->addError(Wootook::__('Both emails does not match. Please check your input.'));
$this->_redirect('*/*/new');
return;
}
try {
$user = Wootook_Player_Model_Entity::register($request->getPost('username'), $request->getPost('email'), $request->getPost('password'));
} catch (Wootook_Empire_Exception_RuntimeException $e) {
$session->addError(Wootook::__('Could not create user: %s', $e->getMessage()));
$this->_redirect('*/*/new');
return;
}
if (!$user || !$user->getId()) {
$session->addError(Wootook::__('Could not create user. Please contact the game administrator for more information.'));
$this->_redirect('*/*/new');
return;
}
$session->setLoggedIn($user);
if ($request->getPost('planet_name') != '') {
$user->getHomePlanet()->setName($request->getPost('planet_name'))->save();
} else {
$user->getHomePlanet()->setName(Wootook::__('Planet'))->save();
}
$this->_redirect('*/overview');
}
public function lostPasswordAction()
{
$session = new Wootook_Player_Model_Session();
if ($session->isLoggedIn()) {
$this->_redirect('*/overview');
return;
}
$this->loadLayout('player.lost-password');
$this->_prepareLayoutMessages(Wootook_Player_Model_Entity::SESSION_KEY);
$this->renderLayout();
}
/**
* Send new password by mail
*/
public function lostPasswordPostAction()
{
$session = new Wootook_Player_Model_Session();
if ($session->isLoggedIn()) {
$this->_redirect('*/overview');
return;
}
if (!$this->getRequest()->isPost()) {
$this->_redirect('*/*/lost-password');
return;
}
$email = $this->getRequest()->getPost('email');
$username = $this->getRequest()->getPost('username');
$player = new Wootook_Player_Model_Entity();
$player->loadByEmail($email);
if (!$player->getId() || strtolower($player->getUsername()) != strtolower(trim($username))) {
$session->addError(Wootook::__('The information you entered could not be found.'));
$this->_redirect('*/*/lost-password');
return;
}
$chars = array(
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '2', '3', '4', '5', '6', '7', '8', '9'
);
shuffle($chars);
$passwordChars = array_slice($chars, 0, 10);
$newPassword = implode($passwordChars);
$player->setPassword($newPassword)->save();
try {
$mailer = new Wootook_Core_Email();
$mailer->send(
array($player->getEmail() => $player->getUsername()),
array('contact@wootook.org' => 'Wootook'),
Wootook::__('Your new password'),
Wootook::__('Your new password is %s', $newPassword));
} catch (Wootook_Core_Exception_RuntimeException $e) {
Wootook_Player_Model_Session::getSingleton()
->addError($e->getMessage());
$this->_redirect('*/*/lost-password');
return;
}
$this->_redirect('*/*/login');
}
public function editAction()

View file

@ -6,10 +6,7 @@ class Wootook_Player_Controller_OverviewController
public function indexAction()
{
$this->loadLayout('player.overview');
$this->_prepareLayoutMessages(Wootook_Player_Model_Entity::SESSION_KEY);
$this->renderLayout();
/*
$this->getResponse()
->setRedirect(Wootook::getStaticUrl('overview.php'), Wootook_Core_Mvc_Controller_Response_Http::REDIRECT_TEMPORARY);
*/
}
}

View file

@ -88,6 +88,21 @@ class Wootook_Player_Model_Entity
return $this->getData('username');
}
public function getEmail()
{
return $this->getData('email');
}
public function loadByEmail($email)
{
return $this->load($email, 'email');
}
public function setPassword($newPassword)
{
return $this->setData('password', $this->hash($newPassword));
}
public static function hash($password, $salt = null)
{
if ($salt === null) {
@ -222,12 +237,10 @@ class Wootook_Player_Model_Entity
public function createNewPlanet($galaxy, $system, $position, $type, $name, $size = null)
{
if ($size === null) {
$baseSize = Wootook::getGameConfig('planet/initial/fields');
$factor = $position * 10 / (1 + log($position * 10));
$fuzz = 2 * $factor * pow(sin($factor), 2) / 2 + $factor / 4;
$size = mt_rand(floor($factor / 10), ceil($factor * 5 / 4)) + mt_rand(0, $fuzz);
$size = Wootook::getGameConfig('planet/initial/fields');
}
if ($size === null) {
$size = 200;
}
$now = new Wootook_Core_DateTime();
@ -464,6 +477,11 @@ class Wootook_Player_Model_Entity
return $this;
}
/**
* Returns all the flying fleets owned by the player
*
* @return Wootook_Empire_Resource_Fleet_Collection
*/
public function getFleets()
{
$collection = new Wootook_Empire_Resource_Fleet_Collection($this->getReadConnection());
@ -473,15 +491,22 @@ class Wootook_Player_Model_Entity
return $collection;
}
/**
* Counts all the flying fleets owned by the player
*
* @return mixed
*/
public function getFleetCount()
{
$collection = new Wootook_Empire_Resource_Fleet_Collection($this->getReadConnection());
$this->_prepareFleetCollection($collection);
return $collection->getSize();
return $this->getFleets()->getSize();
}
/**
* Returns all the visible fleets
*
* @param null $time
* @return Wootook_Empire_Resource_Fleet_Collection
*/
public function getVisibleFleets($time = null)
{
$collection = new Wootook_Empire_Resource_Fleet_Collection($this->getReadConnection());
@ -494,6 +519,19 @@ class Wootook_Player_Model_Entity
return $collection;
}
/**
* Returns all the visible fleets
*
* @param null $time
* @return Wootook_Empire_Resource_Fleet_Collection
* @deprecated
* @alias getVisibleFleets
*/
public function getFleetCollection($time = null)
{
return $this->getVisibleFleets($time);
}
public function getElement($elementId)
{
$fields = Wootook_Empire_Helper_Config_FieldsAlias::getSingleton();
@ -538,14 +576,6 @@ class Wootook_Player_Model_Entity
return false;
}
public function getFleetCollection($time = null)
{
$fleetCollection = new Wootook_Empire_Resource_Fleet_Collection($this->getReadConnection());
$fleetCollection->addIsVisibleToFilter($this, $time);
return $fleetCollection;
}
public function getNewMessagesCount()
{
$messageCollection = new Wootook_Player_Resource_Message_Collection($this->getReadConnection());
@ -582,6 +612,11 @@ class Wootook_Player_Model_Entity
}
}
public function isBanned()
{
return $this->getData('bana') ? true : false;
}
public function isVacation()
{
return $this->getData('urlaubs_modus') ? true : false;
@ -592,6 +627,11 @@ class Wootook_Player_Model_Entity
return $this->getData('urlaubs_until');
}
public function getLastLoginDate()
{
return $this->getData('onlinetime');
}
public function setVacation($active = true)
{
$this->setData('urlaubs_modus', $active);

View file

@ -23,9 +23,12 @@ class Wootook_Player_Resource_Entity_Collection
{
$onlineTime = (int) $onlineTime;
$date = new Wootook_Core_DateTime();
$date->sub($onlineTime, Wootook_Core_DateTime::TIMESTAMP);
if ($onlineTime > 0) {
$this->addFieldToFilter('onlinetime', array(array(
'gt' => new Wootook_Core_Database_Sql_Placeholder_Expression('UNIX_TIMESTAMP() - :online_time))', array('online_time' => $onlineTime))
Wootook_Core_Database_Sql_Select::OPERATOR_DATE => array('from' => $date)
)));
}

View file

@ -0,0 +1 @@
<?php

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,41 @@
<?php
/**
* Test class for Wootook_Object.
* Generated by PHPUnit on 2011-09-01 at 11:24:52.
*/
class Test_Legacies_Core_LayoutTest extends PHPUnit_Framework_TestCase
{
/**
* @var Wootook_Object
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->markTestIncomplete();
/*
$layoutDir = vfsStreamWrapper::getContent('');
vfsStream::addStructure(array());
$this->_object = new Legacies_Core_Layout();
*/
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
public function testEmpty()
{
}
}

View file

@ -0,0 +1,237 @@
<?php
/**
* Test class for Wootook_Object.
* Generated by PHPUnit on 2011-09-01 at 11:24:52.
*/
class Test_Legacies_Empire_Model_BuilderTest extends PHPUnit_Framework_TestCase
{
/**
* @var Legacies_Empire_Model_Planet
*/
protected $_planet = null;
/**
* @var Legacies_Empire_Model_User
*/
protected $_user = null;
protected $_class = 'Legacies_Empire_Model_BuilderAbstract';
protected $_queueItemsData = null;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->_planet = new Legacies_Empire_Model_Planet(array(
'id' => 1,
'id_owner' => 1
));
$this->_user = new Legacies_Empire_Model_User(array(
'id' => 1
));
$this->_planet->setUser($this->_user);
$this->_user->setCurrentPlanet($this->_planet);
$this->_user->setHomePlanet($this->_planet);
$this->_queueItemsData = array(
'IDX0001' => array(
'item_id' => 1,
'level' => 1,
'created_at' => 0,
'updated_at' => 0
),
'IDX0002' => array(
'item_id' => 1,
'level' => 2,
'created_at' => 100,
'updated_at' => 100
),
'IDX0003' => array(
'item_id' => 1,
'level' => 3,
'created_at' => 150,
'updated_at' => 150
)
);
}
protected function _getMockedInstance($planet, $user, $methods = array())
{
$reflector = new ReflectionClass($this->_class);
foreach ($reflector->getMethods() as $method) {
if ($method->isAbstract()) {
$methods[] = $method->getName();
}
}
if (empty($methods)) {
$methods = null;
}
return $this->getMock($this->_class, $methods, array($planet, $user));
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
public function testInit()
{
$stub = $this->getMockBuilder('Legacies_Empire_Model_BuilderAbstract')
->disableOriginalConstructor()
->setMethods(array('init', '_initItem', 'updateQueue', 'appendQueue', 'getResourcesNeeded', 'getBuildingTime'))
->getMock();
$stub->expects($this->once())
->method('init')
->will($this->returnValue($stub));
$stub->expects($this->never())
->method('_serializeQueue')
->will($this->returnValue($stub));
$stub->expects($this->never())
->method('_unserializeQueue')
->will($this->returnValue($stub));
$stub->__construct($this->_planet, $this->_user);
}
public function testSerializingQueue()
{
$items = array(
'IDX0001' => array(
'item_id' => 1,
'level' => 1,
'created_at' => 0,
'updated_at' => 0
),
'IDX0002' => array(
'item_id' => 1,
'level' => 2,
'created_at' => 100,
'updated_at' => 100
),
'IDX0003' => array(
'item_id' => 1,
'level' => 3,
'created_at' => 150,
'updated_at' => 150
)
);
$stub = $this->_getMockedInstance($this->_planet, $this->_user, array('_generateIndex'));
$stub->expects($this->exactly(3))
->method('_initItem')
->will($this->onConsecutiveCalls(
new Legacies_Empire_Model_Builder_Item($this->_queueItemsData['IDX0001']),
new Legacies_Empire_Model_Builder_Item($this->_queueItemsData['IDX0002']),
new Legacies_Empire_Model_Builder_Item($this->_queueItemsData['IDX0003'])
));
$stub->expects($this->exactly(3))
->method('_generateIndex')
->will($this->onConsecutiveCalls(
'IDX0001',
'IDX0002',
'IDX0003'
));
$stub->enqueue($this->_queueItemsData['IDX0001']);
$stub->enqueue($this->_queueItemsData['IDX0002']);
$stub->enqueue($this->_queueItemsData['IDX0003']);
$this->assertEquals(serialize($this->_queueItemsData), $stub->serialize());
}
public function testUnSerializingQueue()
{
$serializedData = serialize($this->_queueItemsData);
$stub = $this->_getMockedInstance($this->_planet, $this->_user, array('_generateIndex'));
$stub->expects($this->exactly(3))
->method('_initItem')
->will($this->onConsecutiveCalls(
new Legacies_Empire_Model_Builder_Item($this->_queueItemsData['IDX0001']),
new Legacies_Empire_Model_Builder_Item($this->_queueItemsData['IDX0002']),
new Legacies_Empire_Model_Builder_Item($this->_queueItemsData['IDX0003'])
));
$stub->expects($this->never())
->method('_generateIndex');
$stub->unserialize($serializedData);
$this->assertAttributeNotEmpty('_queue', $stub);
$this->assertEquals(serialize($this->_queueItemsData), $stub->serialize());
}
public function testUnSerializingQueueWithInvalidData()
{
$serializedData = '';
$stub = $this->_getMockedInstance($this->_planet, $this->_user, array('_generateIndex'));
$stub->expects($this->never())
->method('_initItem');
$stub->expects($this->never())
->method('_generateIndex');
$stub->unserialize($serializedData);
$this->assertAttributeEmpty('_queue', $stub);
$this->assertEquals('a:0:{}', $stub->serialize());
}
public function testInitItemReturningNull()
{
$serializedData = serialize($this->_queueItemsData);
$stub = $this->_getMockedInstance($this->_planet, $this->_user, array('_generateIndex'));
$stub->expects($this->exactly(3))
->method('_initItem')
->will($this->returnValue(null));
$stub->unserialize($serializedData);
$this->assertAttributeEmpty('_queue', $stub);
$this->assertEquals('a:0:{}', $stub->serialize());
}
public function testCheckAvailability()
{
$serializedData = serialize($this->_queueItemsData);
$stub = $this->_getMockedInstance($this->_planet, $this->_user, array('_generateIndex'));
$stub->expects($this->any())
->method('_initItem')
->will($this->onConsecutiveCalls(
new Legacies_Empire_Model_Builder_Item($this->_queueItemsData['IDX0001'])
));
$this->assertTrue($stub->checkAvailability(Legacies_Empire::ID_BUILDING_METAL_MINE));
$this->assertTrue($stub->checkAvailability(Legacies_Empire::ID_BUILDING_CRISTAL_MINE));
$this->assertTrue($stub->checkAvailability(Legacies_Empire::ID_BUILDING_DEUTERIUM_SYNTHETISER));
$this->assertTrue($stub->checkAvailability(Legacies_Empire::ID_BUILDING_FUSION_REACTOR));
}
}

View file

@ -0,0 +1,205 @@
<?php
/**
* Test class for Wootook_Object.
* Generated by PHPUnit on 2011-09-01 at 11:24:52.
*/
class Test_Wootook_ObjectTest extends PHPUnit_Framework_TestCase
{
/**
* @var Wootook_Object
*/
protected $_object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->_object = new Wootook_Object();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @todo Implement testSetData().
*/
public function testSetData()
{
$this->assertAttributeEmpty('_data', $this->_object);
$this->_object->setData('test', true);
$expected = array('test' => true);
$this->assertAttributeEquals($expected, '_data', $this->_object);
$this->_object->setData('test', 'testing');
$expected = array('test' => 'testing');
$this->assertAttributeEquals($expected, '_data', $this->_object);
}
/**
* @requires testSetData
*/
public function testGetData()
{
$this->_object->setData('test', 'testing');
$this->assertEquals('testing', $this->_object->getData('test'));
$this->_object->setData('test', true);
$this->assertTrue($this->_object->getData('test'));
$this->assertNull($this->_object->getData('testing'));
}
/**
* @requires testSetData
* @requires testGetData
*/
public function testGetAllDatas()
{
$this->_object->setData('test', 'testing');
$expected = array('test' => 'testing');
$this->assertEquals($expected, $this->_object->getAllDatas());
$this->_object->setData('test', true);
$expected = array('test' => true);
$this->assertEquals($expected, $this->_object->getAllDatas());
}
/**
* @requires testSetData
* @requires testGetData
*/
public function testHasData()
{
$this->_object->setData('test', 'testing');
$this->assertTrue($this->_object->hasData('test'));
$this->assertFalse($this->_object->hasData('testing'));
}
/**
* @requires testSetData
*/
public function testAddData()
{
$this->_object->setData('test', 'testing');
$expected = array(
'test' => 'testing',
'testing' => true,
'legacies' => false
);
$this->_object->addData(array(
'testing' => true,
'legacies' => false
));
$this->assertAttributeEquals($expected, '_data', $this->_object);
$expected = array(
'test' => 'legacies',
'testing' => false,
'legacies' => 'Wootook_Object'
);
$this->_object->addData($expected);
$this->assertAttributeEquals($expected, '_data', $this->_object);
}
/**
* @requires testSetData
*/
public function testUnsetData()
{
$this->_object->setData('test', 'testing');
$this->_object->setData('testing', true);
$this->_object->setData('removed', 'me!');
$this->_object->setData('legacies', false);
$expected = array(
'test' => 'testing',
'testing' => true,
'legacies' => false
);
$this->_object->unsetData('removed');
$this->assertAttributeEquals($expected, '_data', $this->_object);
}
/**
* @todo Implement testClearData().
*/
public function testClearData()
{
$this->_object->setData('test', 'testing');
$this->_object->setData('testing', true);
$this->_object->setData('removed', 'me!');
$this->_object->setData('legacies', false);
$expected = array(
'test' => 'testing',
'testing' => true,
'legacies' => false
);
$this->_object->clearData();
$this->assertAttributeEmpty('_data', $this->_object);
}
/**
* @requires testSetData
* @requires testHasData
*/
public function testOffsetExists()
{
$this->_object->setData('test', 'testing');
$this->assertTrue(isset($this->_object['test']));
}
/**
* @requires testSetData
* @requires testGetData
*/
public function testOffsetGet()
{
$this->_object->setData('test', 'testing');
$this->assertEquals('testing', $this->_object['test']);
}
/**
* @requires testGetData
* @requires testSetData
*/
public function testOffsetSet()
{
$this->_object['test'] = 'testing';
$this->assertEquals('testing', $this->_object->getData('test'));
}
/**
* @requires testSetData
* @requires testGetData
*/
public function testOffsetUnset()
{
$this->_object->setData('test', 'testing');
unset($this->_object['test']);
$this->assertAttributeEmpty('_data', $this->_object);
$this->assertNull($this->_object->getData('test'));
}
}

View file

@ -0,0 +1,119 @@
<?php
class Test_WootookTest
extends PHPUnit_Framework_TestCase
{
protected function tearDown()
{
Wootook::clearAllListeners();
}
public function nonStaticListener($observer)
{
$observer->setData('success', true);
}
public static function staticListener($observer)
{
$observer->setData('success', true);
}
public function testRegisteringNonStaticEvent()
{
Wootook::registerListener('testing', array($this, 'nonStaticListener'));
$observer = Wootook::dispatchEvent('testing', array('success' => false));
$this->assertInstanceOf('Legacies_Core_Event', $observer);
$this->assertTrue($observer->getData('success'));
}
public function testRegisteringStaticEvent()
{
Wootook::registerListener('testing', array(get_class($this), 'staticListener'));
$observer = Wootook::dispatchEvent('testing', array('success' => false));
$this->assertInstanceOf('Legacies_Core_Event', $observer);
$this->assertTrue($observer->getData('success'));
}
public function testDispatchNonExistingEvent()
{
$observer = Wootook::dispatchEvent('testing', array('success' => true));
$this->assertInstanceOf('Legacies_Core_Event', $observer);
$this->assertTrue($observer->getData('success'));
}
/**
* @depends testRegisteringNonStaticEvent
*/
public function testUnregisteringNonStaticEvent()
{
Wootook::registerListener('testing', array($this, 'nonStaticListener'));
Wootook::clearEventListeners('testing');
$observer = Wootook::dispatchEvent('testing', array('success' => false));
$this->assertInstanceOf('Legacies_Core_Event', $observer);
$this->assertFalse($observer->getData('success'));
}
/**
* @depends testRegisteringStaticEvent
*/
public function testUnregisteringStaticEvent()
{
Wootook::registerListener('testing', array(get_class($this), 'staticListener'));
Wootook::clearEventListeners('testing');
$observer = Wootook::dispatchEvent('testing', array('success' => false));
$this->assertInstanceOf('Legacies_Core_Event', $observer);
$this->assertFalse($observer->getData('success'));
}
public function testGetSession()
{
$this->markTestSkipped('Sessions could not be tested in CLI.');
$this->assertInstanceOf('Legacies_Core_Model_Session', Wootook::getSession('test'));
}
public function testGetTranslator()
{
$this->assertInstanceOf('Legacies_Core_Model_Translator', Wootook::getTranslator('test'));
$this->assertInstanceOf('Legacies_Core_Model_Translator', Wootook::getTranslator());
}
public function testTranslate()
{
$this->assertEquals('My testing message!', Wootook::translate('test', 'My %s message!', array('testing')));
}
public function testTranslateGettextStyle()
{
$this->assertEquals('My testing message!', Wootook::__('My %s message!', 'testing'));
}
public function testSetDefaultLocale()
{
Wootook::setDefaultLocale('test');
$this->assertAttributeEquals('test', '_defaultLocale', 'Beyond');
}
/**
*
* @requires testSetDefaultLocale
*/
public function testGetDefaultLocale()
{
Wootook::setDefaultLocale('test');
$this->assertEquals('test', Wootook::getDefaultLocale());
}
}

View file

@ -0,0 +1,66 @@
<?php
set_include_path(implode(PATH_SEPARATOR, array(
dirname(__DIR__),
get_include_path()
)));
function frameworkAutoload($class) {
include_once str_replace('_', '/', $class) . '.php';
}
spl_autoload_register('frameworkAutoload');
include 'vfsStream/vfsStream.php';
vfsStream::create(array(
'includes' => array(
'application' => array(
'code' => array(
'community' => array(),
'core' => array(),
'libraries' => array(),
'local' => array(),
),
'design' => array(
'layouts' => array(),
'scripts' => array()
)
),
'data' => array(
'combat.php' => '<?php echo ' . var_export(array(), true),
'events.php' => '<?php echo ' . var_export(array(), true),
'fields-alias.php' => '<?php echo ' . var_export(array(), true),
'prices.php' => '<?php echo ' . var_export(array(), true),
'production.php' => '<?php echo ' . var_export(array(), true),
'requirements.php' => '<?php echo ' . var_export(array(), true),
'resources.php' => '<?php echo ' . var_export(array(), true),
'types.php' => '<?php echo ' . var_export(array(), true),
)
),
'config.php' => '<?php echo ' . var_export(array(
'global' => array(
'date' => array(
'timezone' => 'Europe/Paris'
),
'database' => array(
'engine' => 'mysql',
'options' => array(
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'db_xnova'
),
'table_prefix' => 'game_',
),
'layout' => array(
'page' => 'page.php',
'empire' => 'empire.php'
)
)
), true) . ';'
), 'root', 644);
define('ROOT_PATH', vfsStream::url(''));
define('APPLICATION_PATH', vfsStream::url('includes/application'));

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<layout version="1.0">
<handle name="admin">
<update name="1column" />
<reference name="header">
<block name="navigation" type="core/html.navigation" template="page/html/navigation.phtml">
<action method="setNodeTitle">
<param name="path">system</action>
<param name="title">System</action>
</action>
<action method="setNodeTitle">
<param name="path">players</action>
<param name="title">Player Accounts</action>
</action>
</block>
</reference>
</handle>
</layout>

View file

@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<layout version="1.0">
<handle name="empire">
<update name="1column" />
<reference name="header">
<block name="navigation" type="core/html.navigation" template="page/html/navigation.phtml">
<action method="setNodeTitle">
@ -186,23 +184,44 @@
</reference>
</handle>
<handle name="deprecated">
<update name="1column" />
<update name="empire" />
</handle>
<handle name="message">
<update name="1column" />
<update name="empire" />
</handle>
<handle name="player.overview">
<update name="2columns-left" />
<update name="empire" />
<reference name="overview.left">
<reference name="root">
<action method="addBodyClass">
<param name="class">overview</param>
</action>
</reference>
<reference name="left">
<block type="empire/planet.overview" name="overview.planet.mini" template="player/overview/planet/mini.phtml" />
<block type="legacies-stats/view" name="overview.player.stats" template="player/overview/stats/mini.phtml" />
</reference>
<reference name="center">
<reference name="content">
<block type="empire/overview.fleet.list" name="overview.fleet.list" template="player/overview/fleet/list.phtml">
<action method="setItemTemplate">
<param name="template">player/overview/fleet/item.phtml</param>
</action>
<action method="setItemBlockType">
<param name="blockType">empire/overview.fleet.list.item</param>
</action>
</block>
</reference>
</handle>
<handle name="overview.rename-planet">
<update name="player.overview" />
<update name="1column" />
<update name="empire" />
<reference name="overview.center">
<block name="rename-planet" type="empire/overview.rename-planet" template="player/overview/form/rename-planet.phtml" />
@ -210,7 +229,8 @@
</handle>
<handle name="overview.destroy-planet">
<update name="player.overview" />
<update name="1column" />
<update name="empire" />
<reference name="overview.center">
<block name="rename-planet" type="empire/overview.destroy-planet" template="player/overview/form/destroy-planet.phtml" />
@ -218,6 +238,7 @@
</handle>
<handle name="planet.buildings">
<update name="1column" />
<update name="empire" />
<reference name="content">
@ -242,6 +263,7 @@
</handle>
<handle name="planet.shipyard">
<update name="1column" />
<update name="empire" />
<reference name="content">
@ -276,6 +298,7 @@
</handle>
<handle name="planet.research-lab">
<update name="1column" />
<update name="empire" />
<reference name="content">

View file

@ -59,8 +59,6 @@
</block>
</handle>
<handle name="public">
<update name="1column" />
<reference name="root">
<action method="addBodyClass">
<param name="class">public</param>
@ -90,6 +88,7 @@
</reference>
</handle>
<handle name="no-route">
<update name="1column" />
<update name="public" />
<reference name="content">
@ -103,6 +102,7 @@
</reference>
</handle>
<handle name="home">
<update name="1column" />
<update name="public" />
<reference name="root">

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<layout version="1.0">
<handle name="player.login">
<update name="1column" />
<update name="public" />
<reference name="root">
@ -24,6 +25,7 @@
</handle>
<handle name="player.registration">
<update name="1column" />
<update name="public" />
<reference name="root">
@ -47,6 +49,7 @@
</handle>
<handle name="player.lost-password">
<update name="1column" />
<update name="public" />
<reference name="root">
@ -68,21 +71,4 @@
<block name="registration" type="core/template" template="player/lost-password.phtml" />
</reference>
</handle>
<handle name="player.overview">
<update name="default" />
<reference name="content">
<block name="overview" type="player/overview" template="player/overview.phtml">
<block type="core/concat" name="overview.left" />
<block type="core/concat" name="overview.center" />
</block>
</reference>
<reference name="head">
<action method="setTitle">
<param name="title">Overview</param>
</action>
</reference>
</handle>
</layout>
</layout>

View file

@ -1,6 +1,6 @@
<?php if (!$this->isEmpty()):?>
<div class="building queue">
<h1><?php echo $this->__('Work in progress')?></h1>
<?php echo $this->getPartial('item-list')->render() ?>
<?php echo $this->renderPartial('item-list') ?>
</div>
<?php endif?>
<?php endif?>

View file

@ -7,11 +7,11 @@
<p class="planet-name"><a href="<?php echo $this->getStaticUrl('overview.php', array('cp' => $planet->getId()))?>"><?php echo $this->escape($planet->getName())?></a></p>
<div class="planet-image">
<?php if (false && ($moon = $planet->getMoon()) !== null): ?>
<a href="<?php echo $this->getStaticUrl('overview.php', array('cp' => $moon->getId()))?>" class="moon">
<a href="<?php echo $this->getUrl('player/overview', array('_query' => array('___planet' => $moon->getId())))?>" class="moon">
<img src="<?php echo $this->getSkinUrl($moon->getImage())?>" width="20" height="20"/>
</a>
<?php endif?>
<a href="<?php echo $this->getStaticUrl('overview.php', array('cp' => $planet->getId()))?>" class="planet">
<a href="<?php echo $this->getUrl('player/overview', array('_query' => array('___planet' => $planet->getId())))?>" class="planet">
<img src="<?php echo $this->getSkinUrl($planet->getImage())?>" width="50" height="50"/>
</a>
</div>

View file

@ -7,11 +7,14 @@
<div class="header">
<?php echo $this->header->render()?>
</div>
<div class="left">
<?php echo $this->left->render()?>
</div>
<div class="content">
<?php echo $this->content->render()?>
<div class="container">
<div class="left">
<?php echo $this->left->render()?>
</div>
<div class="content">
<?php echo $this->content->render()?>
</div>
<div class="clear"></div>
</div>
</div>
</body>

View file

@ -7,11 +7,14 @@
<div class="header">
<?php echo $this->header->render()?>
</div>
<div class="content">
<?php echo $this->content->render()?>
</div>
<div class="right">
<?php echo $this->left->render()?>
<div class="container">
<div class="content">
<?php echo $this->content->render()?>
</div>
<div class="right">
<?php echo $this->left->render()?>
</div>
<div class="clear"></div>
</div>
</div>
</body>

View file

@ -7,14 +7,17 @@
<div class="header">
<?php echo $this->header->render()?>
</div>
<div class="left">
<?php echo $this->left->render()?>
</div>
<div class="content">
<?php echo $this->content->render()?>
</div>
<div class="right">
<?php echo $this->left->render()?>
<div class="container">
<div class="left">
<?php echo $this->left->render()?>
</div>
<div class="content">
<?php echo $this->content->render()?>
</div>
<div class="right">
<?php echo $this->left->render()?>
</div>
<div class="clear"></div>
</div>
</div>
</body>

View file

@ -15,7 +15,7 @@
<input name="rememberme" id="login:remember-me" type="checkbox" class="input-checkbox" />
</p>
<p class="form lost-password">
<a href="<?php echo $this->getStaticUrl('lostpassword.php')?>" title="<?php echo $this->__('I have lost my password.')?>"><?php echo $this->__('I have lost my password.')?></a>
<a href="<?php echo $this->getUrl('player/account/lost-password')?>" title="<?php echo $this->__('I have lost my password.')?>"><?php echo $this->__('I have lost my password.')?></a>
</p>
</fieldset>
<p class="form submit">

View file

@ -6,9 +6,9 @@
<label for="lost-password:username"><?php echo $this->__('Username')?></label>
<input name="username" id="lost-password:username" value="" type="text" class="input-text" />
</p>
<p class="form password">
<p class="form email">
<label for="lost-password:email"><?php echo $this->__('Email')?></label>
<input name="email" id="lost-password:email" value="" type="text" class="input-password" />
<input name="email" id="lost-password:email" value="" type="text" class="input-text" />
</p>
</fieldset>
<p class="form submit">

View file

@ -1,21 +1,39 @@
<?php $fleet = $this->getData('fleet')?>
<?php $user = $this->getData('user')?>
<tr class="<?php echo $this->getData('class')?>">
<?php echo $this->getData('fleet_javai')?>
<td>
<div class="z">-</div>
<font color="lime"><?php echo $fleet->getArrivalTime()?></font>
</td>
<td colspan="3">
<?php if (!$fleet->isOwnedBy($user) || $fleet->isMission(Legacies_Empire::ID_MISSION_TRANSPORT) || $fleet->isMission(Legacies_Empire::ID_MISSION_STATION) || $fleet->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)):?>
<span class="<?php echo $fleet->getRowClass($user)?>"><?php echo $this->__('An hostile fleet sent by %1$s, coming from %2$s, reaches your planet %3$d. It has been sent with the mission: %4$d', $fleet->getOwner()->getUsername(), $fleet->getOriginPlanet()->getName(), $fleet->getDestinationPlanet()->getName(), $fleet->getMissionLabel())?></span>
<?php elseif ($fleet->isOwnedBy($user) || $fleet->isMission(Legacies_Empire::ID_MISSION_ATTACK) || $fleet->isMission(Legacies_Empire::ID_MISSION_GROUP_ATTACK) || $fleet->isMission(Legacies_Empire::ID_MISSION_DESTROY) || $fleet->isMission(Legacies_Empire::ID_MISSION_MISSILES) || $fleet->isMission(Legacies_Empire::ID_MISSION_SPY)):?>
<span class="<?php echo $fleet->getRowClass($user)?>"><?php echo $this->__('Your hostile fleet, sent from %1$s, reaches %2$d\'s planet %3$d. It has been sent with the mission: %4$d', $fleet->getOriginPlanet()->getName(), $fleet->getDestinationPlanet()->getUser()->getUsername(), $fleet->getDestinationPlanet()->getName(), $fleet->getMissionLabel())?></span>
<?php elseif ($fleet->isOwnedBy($user)):?>
<span class="<?php echo $fleet->getRowClass($user)?>"><?php echo $this->__('Your peaceful fleet, sent from %2$s, reaches the planet %3$d. It has been sent with the mission: %4$d', $fleet->getOwner()->getUsername(), $fleet->getOriginPlanet()->getName(), $fleet->getDestinationPlanet()->getName(), $fleet->getMissionLabel())?></span>
<?php else:?>
<span class="<?php echo $fleet->getRowClass($user)?>"><?php echo $this->__('A peaceful fleet sent by %1$s, coming from %2$s, reaches your planet %3$d. It has been sent with the mission: %4$d', $fleet->getOwner()->getUsername(), $fleet->getOriginPlanet()->getName(), $fleet->getDestinationPlanet()->getName(), $fleet->getMissionLabel())?></span>
<?php endif?>
</td>
<?php echo $this->getData('fleet_javas')?>
</tr>
<div class="fleet">
<span class="start-time"><?php echo $this->renderDateTime($this->getStartTime())?></span>
<span class="start-time"><?php echo $this->renderDateTime($this->getActionTime())?></span>
<span class="arrival-time"><?php echo $this->renderDateTime($this->getArrivalTime())?></span>
<div class="fleet-message">
<?php $player = $this->getPlayer() ?>
<?php if (!$this->isOwner() && ($this->isMission(Legacies_Empire::ID_MISSION_TRANSPORT) || $this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY))):?>
<span class="<?php echo $this->getRowClass()?>">
<?php echo $this->__('An hostile fleet sent by %1$s, coming from %2$s[%3$s], reaches your planet %4$s[%5$s]. It has been sent with the mission: %6$s',
implode(', ', $this->getFleetOwnerUsernames()),
$this->getOriginPlanetName(), $this->getOriginPlanetCoords(),
$this->getDestinationPlanetName(), $this->getDestinationPlanetCoords(),
$this->getMissionLabel())?>
</span>
<?php elseif ($this->isOwner() && ($this->isMission(Legacies_Empire::ID_MISSION_ATTACK) || $this->isMission(Legacies_Empire::ID_MISSION_GROUP_ATTACK) || $this->isMission(Legacies_Empire::ID_MISSION_DESTROY) || $this->isMission(Legacies_Empire::ID_MISSION_MISSILES) || $this->isMission(Legacies_Empire::ID_MISSION_SPY))):?>
<span class="<?php echo $this->getRowClass()?>">
<?php echo $this->__('Your hostile fleet sent from %1$s[%2$s], reaches %3$s\'s planet %4$s[%5$s]. It has been sent with the mission: %6$s',
$this->getOriginPlanetName(), $this->getOriginPlanetCoords(),
implode(', ', $this->getFleetOwnerUsernames()),
$this->getDestinationPlanetName(), $this->getDestinationPlanetCoords(),
$this->getMissionLabel())?>
</span>
<?php elseif ($this->isOwner()):?>
<span class="<?php echo $this->getRowClass()?>">
<?php echo $this->__('Your peaceful fleet sent from %1$s[%2$s], reaches the planet %3$s[%4$s]. It has been sent with the mission: %5$s',
$this->getOriginPlanetName(), $this->getOriginPlanetCoords(),
$this->getDestinationPlanetName(), $this->getDestinationPlanetCoords(),
$this->getMissionLabel())?>
</span>
<?php else:?>
<span class="<?php echo $this->getRowClass()?>">
<?php echo $this->__('A peaceful fleet sent by %1$s, coming from %2$s[%3$s], reaches the planet %4$s[%5$s]. It has been sent with the mission: %6$s',
implode(', ', $this->getFleetOwnerUsernames()),
$this->getOriginPlanetName(), $this->getOriginPlanetCoords(),
$this->getDestinationPlanetName(), $this->getDestinationPlanetCoords(),
$this->getMissionLabel())?>
<?php endif?>
</div>
</div>

View file

@ -0,0 +1,9 @@
<div class="fleet item-container">
<h2><?php echo $this->__('Fleets') ?></h2>
<?php $collection = $this->getFleetCollection()?>
<?php if ($collection->getSize() > 0): ?>
<?php echo $this->renderPartial('item-list')?>
<?php else:?>
<p><?php echo $this->__('There are currently no fleets.')?></p>
<?php endif?>
</div>

View file

@ -1,7 +1,8 @@
<div id="overview:stats" class="item-container">
<h2><?php echo $this->escape($this->getPlanetName())?></h2>
<h3><?php echo $this->escape($this->getPlanetCoords())?></h3>
<p class="image">
<img src="<?php echo $this->getSkinUrl($this->getPlanetImage())?>" />
</p>
<h2><?php echo $this->__('Your statistics')?></h2>
<ul class="stats">
<?php foreach ($this->getPlayerStatData() as $stat): ?>
<li></li>
<?php endforeach ?>
</ul>
</div>

View file

@ -1,5 +1,5 @@
<?php echo $this->getLayout()->getMessagesBlock()->renderGroupedHtml()?>
<form id="register-form" name="register-form" action="<?php echo $this->getStaticUrl('player/account/register-post')?>" method="post" class="main-form">
<form id="register-form" name="register-form" action="<?php echo $this->getStaticUrl('player/account/new-post')?>" method="post" class="main-form">
<h1><?php echo $this->__('Register')?></h1>
<fieldset>
<legend><?php echo $this->__('User data:')?></legend>

View file

@ -9,14 +9,15 @@
'register.before' => array(),
'register.failure' => array(),
'register.success' => array(),
'planet.update' => array(
array('Wootook_Empire_Model_Planet', 'planetUpdateListener'),
array('Legacies_Empire_Model_Planet_Building_Shipyard', 'planetUpdateListener')
),
'user.init' => array(),
'planet.init' => array(
array('Wootook_Empire_Model_Galaxy_Position', 'initPlanetListerner')
),
'planet.update' => array(
array('Wootook_Empire_Model_Planet', 'planetUpdateListener'),
array('Legacies_Empire_Model_Planet_Building_Shipyard', 'planetUpdateListener'),
'flyingFleetListener'
),
'planet.shipyard.check-availability' => array(),
'planet.shipyard.update-queue.before' => array(),
'planet.shipyard.update-queue.after' => array(),
@ -34,5 +35,8 @@
),
'planet.research-lab.technology.speed-enhancement' => array(
array('Legacies_Empire_Model_Player_Technology_IntergalacticResearchNetwork', 'researchTechnologyEnhancementListener')
),
'core.mvc.controller.front.pre-dispatch' => array(
array('Wootook_Empire_Model_Planet', 'planetChangeListener')
)
);