diff --git a/.gitignore b/.gitignore index 3ca62fc..c40f034 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ config.php .buildpath .project .settings/ +.idea/ coverage/ +src/application/cache/* diff --git a/src/application/code/core/Legacies/Empire/Controller/DefenseController.php b/src/application/code/core/Legacies/Empire/Controller/DefenseController.php new file mode 100644 index 0000000..e6a1f87 --- /dev/null +++ b/src/application/code/core/Legacies/Empire/Controller/DefenseController.php @@ -0,0 +1,54 @@ +getCurrentPlanet(); + + if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) { + $this->getSession() + ->addError(Wootook::__('In order to build defenses you will need to build a shipyard building.')); + + $this->_redirect('player/overview'); + return; + } + } + + public function indexAction() + { + $this->loadLayout('planet.defense'); + + /** @var Legacies_Empire_Block_Planet_Shipyard $block */ + $block = $this->getLayout()->getBlock('item-list'); + $block->setType(Legacies_Empire::TYPE_DEFENSE); + + $this->renderLayout(); + } + + public function buildAction() + { + if (!$this->getRequest()->isPost() || !is_array($defenseList = $this->getRequest()->getPost('id'))) { + $this->_redirect('*/*/view'); + return; + } + + $shipyard = $this->getCurrentPlanet()->getShipyard(); + foreach ($defenseList as $defenseId => $count) { + $defenseId = intval($defenseId); + $count = intval($count); + + $shipyard->appendQueue($defenseId, $count); + } + $this->getCurrentPlanet()->save(); + + $this->_redirect('*/*/'); + } +} diff --git a/src/application/code/core/Legacies/Empire/Controller/ResearchLabController.php b/src/application/code/core/Legacies/Empire/Controller/ResearchLabController.php new file mode 100644 index 0000000..40e05f7 --- /dev/null +++ b/src/application/code/core/Legacies/Empire/Controller/ResearchLabController.php @@ -0,0 +1,58 @@ +getCurrentPlanet(); + + if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) { + $this->getSession() + ->addError(Wootook::__('In order to do technological researches, you will need to build a research lab building.')); + + $this->_redirect('player/overview'); + return; + } + } + + public function indexAction() + { + $this->loadLayout('planet.research-lab'); + $this->renderLayout(); + } + + public function buildAction() + { + if (!is_numeric($researchId = $this->getRequest()->getParam('id'))) { + $this->_redirect('*/*/view'); + return; + } + + $this->getCurrentPlanet()->getResearchLab()->appendQueue($researchId); + $this->getCurrentPlanet()->save(); + $this->getPlayer()->save(); + + $this->_redirect('*/*/'); + } + + public function cancelAction() + { + if (!is_numeric($researchId = $this->getRequest()->getParam('id'))) { + $this->_redirect('*/*/view'); + return; + } + + $this->getCurrentPlanet()->getResearchLab()->dequeueItem($researchId); + $this->getCurrentPlanet()->save(); + $this->getPlayer()->save(); + + $this->_redirect('*/*/'); + } +} diff --git a/src/application/code/core/Legacies/Empire/Controller/ShipyardController.php b/src/application/code/core/Legacies/Empire/Controller/ShipyardController.php new file mode 100644 index 0000000..dd42c30 --- /dev/null +++ b/src/application/code/core/Legacies/Empire/Controller/ShipyardController.php @@ -0,0 +1,49 @@ +getCurrentPlanet(); + + if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) { + $this->getSession() + ->addError(Wootook::__('In order to build ships you will need to build a shipyard building.')); + + $this->_redirect('player/overview'); + return; + } + } + + public function indexAction() + { + $this->loadLayout('planet.shipyard'); + $this->renderLayout(); + } + + public function buildAction() + { + if (!$this->getRequest()->isPost() || !is_array($shipList = $this->getRequest()->getPost('id'))) { + $this->_redirect('*/*/view'); + return; + } + + $shipyard = $this->getCurrentPlanet()->getShipyard(); + foreach ($shipList as $shipId => $count) { + $shipId = intval($shipId); + $count = intval($count); + + $shipyard->appendQueue($shipId, $count); + } + $this->getCurrentPlanet()->save(); + + $this->_redirect('*/*/'); + } +} diff --git a/src/application/code/core/Wootook.php b/src/application/code/core/Wootook.php index fc838ac..8a69efc 100644 --- a/src/application/code/core/Wootook.php +++ b/src/application/code/core/Wootook.php @@ -182,7 +182,7 @@ class Wootook * * Enter description here ... * @param unknown_type $namespace - * @return Legacies_Core_Model_Session + * @return Wootook_Core_Model_Session */ public static function getSession($namespace) { @@ -759,17 +759,29 @@ class Wootook { $baseUrl = self::getBaseUrl(); + $queryParams = array(); + if (isset($params['_query'])) { + $queryParams = $params['_query']; + } + $serializedParams = array(); foreach ($params as $paramKey => $paramValue) { if ($paramValue) { - $serializedParams[] = "{$paramKey}={$paramValue}"; + $serializedParams[] = "{$paramKey}/{$paramValue}"; } } - if (count($serializedParams) > 0) { - return $baseUrl . $uri . '?' . implode('&', $serializedParams); + $serializedQueryParams = array(); + foreach ($queryParams as $paramKey => $paramValue) { + if ($paramValue) { + $serializedQueryParams[] = "{$paramKey}={$paramValue}"; + } } - return $baseUrl . $uri; + + if (count($serializedQueryParams) > 0) { + return $baseUrl . $uri . '/' . implode('/', $serializedParams) . '?' . implode('&', $serializedQueryParams); + } + return $baseUrl . $uri . '/' . implode('/', $serializedParams); } public static function getStaticUrl($uri, Array $params = array()) @@ -804,4 +816,4 @@ class Wootook Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); return true; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Block/Concat.php b/src/application/code/core/Wootook/Core/Block/Concat.php index 5c9afc5..cb8dc89 100644 --- a/src/application/code/core/Wootook/Core/Block/Concat.php +++ b/src/application/code/core/Wootook/Core/Block/Concat.php @@ -1,7 +1,7 @@ _getNode($explodedPath); + + $child = $this->getLayout() + ->createBlock('core/html.navigation.link', $this->getNameInLayout() . '.' . $baseName, array( + 'url' => array( + 'uri' => $uri, + 'params' => $params, + 'static' => true + ), + 'label' => $label, + 'title' => $title, + 'classes' => $classes, + 'attributes' => $attributes + )); + $parent->setPartial($baseName, $child); + + if ($template !== null) { + $child->setTemplate($template); + } + + return $this; + } public function addExternalLink($name, $label, $title, $url, Array $classes = array(), $template = null, Array $attributes = array()) { @@ -98,4 +124,4 @@ class Wootook_Core_Block_Html_Navigation } return $child->_getNode($explodedPath); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Block/Html/Navigation/Link.php b/src/application/code/core/Wootook/Core/Block/Html/Navigation/Link.php index 4405d65..82a09fa 100644 --- a/src/application/code/core/Wootook/Core/Block/Html/Navigation/Link.php +++ b/src/application/code/core/Wootook/Core/Block/Html/Navigation/Link.php @@ -43,7 +43,7 @@ class Wootook_Core_Block_Html_Navigation_Link return $this->_title; } - public function setUrl($uri, $params = array()) + public function setStaticUrl($uri, $params = array()) { if ($uri === null) { return $this; @@ -56,6 +56,19 @@ class Wootook_Core_Block_Html_Navigation_Link return $this; } + public function setUrl($uri, $params = array()) + { + if ($uri === null) { + return $this; + } + + $this->_uri = $uri; + $this->_params = $params; + $this->_url = $this->getUrl($uri, $params); + + return $this; + } + public function setExternalUrl($url) { $this->_url = $url; @@ -144,10 +157,18 @@ class Wootook_Core_Block_Html_Navigation_Link if (isset($data['url'])) { if (is_array($data['url']) && isset($data['url']['uri'])) { - if (isset($data['url']['params'])) { - $this->setUrl($data['url']['uri'], $data['url']['params']); + if (isset($data['url']['static']) && $data['url']['static']) { + if (isset($data['url']['params'])) { + $this->setStaticUrl($data['url']['uri'], $data['url']['params']); + } else { + $this->setStaticUrl($data['url']['uri']); + } } else { - $this->setUrl($data['url']['uri']); + if (isset($data['url']['params'])) { + $this->setUrl($data['url']['uri'], $data['url']['params']); + } else { + $this->setUrl($data['url']['uri']); + } } } else { $this->setExternalUrl($data['url']); @@ -177,4 +198,4 @@ class Wootook_Core_Block_Html_Navigation_Link return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Block/Messages.php b/src/application/code/core/Wootook/Core/Block/Messages.php index 08d5184..5aa7cb4 100644 --- a/src/application/code/core/Wootook/Core/Block/Messages.php +++ b/src/application/code/core/Wootook/Core/Block/Messages.php @@ -44,4 +44,4 @@ class Wootook_Core_Block_Messages return $output; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Block/Template.php b/src/application/code/core/Wootook/Core/Block/Template.php index dd78ee5..1383a4e 100644 --- a/src/application/code/core/Wootook/Core/Block/Template.php +++ b/src/application/code/core/Wootook/Core/Block/Template.php @@ -1,7 +1,7 @@ addException(new Wootook_Core_Exception_RuntimeException("Template '{$file}' could not be found.")); return null; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Block/Text.php b/src/application/code/core/Wootook/Core/Block/Text.php index 129df11..dabe336 100644 --- a/src/application/code/core/Wootook/Core/Block/Text.php +++ b/src/application/code/core/Wootook/Core/Block/Text.php @@ -1,7 +1,7 @@ loadLayout('home'); $this->renderLayout(); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php b/src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php index 1bcf543..5e6de28 100644 --- a/src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php +++ b/src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php @@ -89,7 +89,7 @@ abstract class Wootook_Core_Database_Adapter_Adapter */ public function quoteInto($string, $values) { - $parts = preg_split('#(\?|:[\w_]+)#', $identifier, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $parts = preg_split('#(\?|:[\w_]+)#', $string, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $result = ''; if (is_array($values)) { @@ -171,4 +171,24 @@ abstract class Wootook_Core_Database_Adapter_Adapter * @return bool */ abstract public function lastInsertId(); -} \ No newline at end of file + + /** + * @return string + */ + abstract public function errorCode(); + + /** + * @return string + */ + abstract public function errorMessage(); + + /** + * @return array + */ + abstract public function errorInfo(); + + /** + * @return string + */ + abstract public function errorState(); +} diff --git a/src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php b/src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php index 29c98c4..b45bf6a 100644 --- a/src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php +++ b/src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php @@ -119,4 +119,40 @@ class Wootook_Core_Database_Adapter_Pdo_Mysql } return false; } -} \ No newline at end of file + + /** + * @return string + */ + public function errorCode() + { + return $this->_handler->errorCode(); + } + + /** + * @return array + */ + public function errorInfo() + { + return $this->_handler->errorInfo(); + } + + /** + * @return string + */ + public function errorMessage() + { + $info = $this->_handler->errorInfo(); + + return $info[2]; + } + + /** + * @return string + */ + public function errorState() + { + $info = $this->_handler->errorInfo(); + + return $info[0]; + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Resource.php b/src/application/code/core/Wootook/Core/Database/Resource.php index 60d79de..5501b32 100644 --- a/src/application/code/core/Wootook/Core/Database/Resource.php +++ b/src/application/code/core/Wootook/Core/Database/Resource.php @@ -1,7 +1,7 @@ _tableName; } + /** + * @return Wootook_Core_Database_Adapter_Adapter + */ public function getReadConnection() { if ($this->_readConnection === null) { @@ -58,6 +61,9 @@ abstract class Wootook_Core_Database_Resource return $this; } + /** + * @return Wootook_Core_Database_Adapter_Adapter + */ public function getWriteConnection() { if ($this->_writeConnection === null) { @@ -80,4 +86,4 @@ abstract class Wootook_Core_Database_Resource return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Delete.php b/src/application/code/core/Wootook/Core/Database/Sql/Delete.php new file mode 100644 index 0000000..7b497ed --- /dev/null +++ b/src/application/code/core/Wootook/Core/Database/Sql/Delete.php @@ -0,0 +1,120 @@ +into($tableName); + } + + return $this; + } + + public function reset($part = null) + { + if ($part === null) { + $this->_parts = array( + self::INTO => array(), + self::SET => array(), + ); + } else if (isset($this->_parts[$part])) { + $this->_parts[$part] = array(); + } + + return $this; + } + + public function set($column, $value) + { + if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + $this->_placeholders[] = $column; + } + + $this->_parts[self::COLUMNS][] = array( + 'value' => $value, + 'field' => $column + ); + + return $this; + } + + public function into($table, $schema = null) + { + $this->_parts[self::INTO] = array( + 'table' => $table, + 'schema' => $schema, + ); + + return $this; + } + + public function __toString() + { + return $this->render(); + } + + public function toString($part = null) + { + if ($part === null) { + return $this->render(); + } + + switch ($part) { + case self::COLUMNS: + return $this->renderSet(); + break; + case self::INTO: + return $this->renderInto(); + break; + } + + return null; + } + + public function renderSet() + { + $fields = array(); + foreach ($this->_parts[self::SET] as $field) { + if ($field['value'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}"; + } else { + $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}"; + } + } + + if (!empty($fields)) { + return "\nSET " . implode(", ", $fields); + } + } + + public function renderInto() + { + if ($this->_parts[self::INTO]['schema'] !== null) { + $output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['schema'])}.{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}"; + } else { + $output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}"; + } + + return "INSERT INTO " . $output; + } + + public function render() + { + if (empty($this->_parts[self::SELECT])) { + return implode('', array( + $this->renderInto(), + $this->renderColumns(), + )); + } else { + return implode('', array( + $this->renderInto(), + $this->renderSelect(), + )); + } + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Dml.php b/src/application/code/core/Wootook/Core/Database/Sql/Dml.php index fe29798..de0c17b 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Dml.php +++ b/src/application/code/core/Wootook/Core/Database/Sql/Dml.php @@ -4,12 +4,6 @@ interface Wootook_Core_Database_Sql_Dml { function __construct(Wootook_Core_Database_Adapter_Adapter $connection, $param = null); - function where($condition); - function limit($limit, $offset = null); - - function renderWhere(); - function renderLimit(); - function render(); function toString($part = null); @@ -27,4 +21,4 @@ interface Wootook_Core_Database_Sql_Dml function beforeExecute(Wootook_Core_Database_Statement_Statement $statement); function afterExecute(Wootook_Core_Database_Statement_Statement $statement); -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/DmlFilterableQuery.php b/src/application/code/core/Wootook/Core/Database/Sql/DmlFilterableQuery.php new file mode 100644 index 0000000..c2e3efc --- /dev/null +++ b/src/application/code/core/Wootook/Core/Database/Sql/DmlFilterableQuery.php @@ -0,0 +1,211 @@ +_parts[self::WHERE][] = $condition; + } else if (is_string($condition)) { + if ($value === null) { + $this->_parts[self::WHERE][] = $condition; + } else { + $adapter = $this->getReadConnection(); + $this->_parts[self::WHERE][] = $adapter->quoteInto($condition, $value); + } + } else if (is_array($condition)) { + $where = $this->_translateSqlWhere($condition, 'or', $value); + if ($where !== null) { + $this->_parts[self::WHERE][] = $where; + } + } + + return $this; + } + + public function limit($limit, $offset = null) + { + $this->_parts[self::LIMIT] = intval($limit); + $this->_parts[self::OFFSET] = intval($offset); + + return $this; + } + + public function renderWhere() + { + if (count($this->_parts[self::WHERE]) <= 0) { + return ''; + } + + return "\nWHERE (" . implode(') AND (', $this->_parts[self::WHERE]) . ')'; + } + + public function renderLimit() + { + if (!$this->_parts[self::LIMIT]) { + return ''; + } + if (!$this->_parts[self::OFFSET]) { + return sprintf("\nLIMIT %d", $this->_parts[self::LIMIT]); + } + return sprintf("\nLIMIT %d,%d", $this->_parts[self::LIMIT], $this->_parts[self::OFFSET]); + } + + protected function _translateSqlWhere($field, $operator, $value) + { + if ($value === null) { + return null; + } + $operator = strtoupper($operator); + $adapter = $this->getReadConnection(); + + $basicBinayOperatorList = array( + self::OPERATOR_EQUALS => '=', + self::OPERATOR_NOT_EQUALS => '!=', + self::OPERATOR_LOWER => '<', + self::OPERATOR_GREATER => '>', + self::OPERATOR_LOWER_EQUALS => '<=', + self::OPERATOR_GREATER_EQUALS => '>=' + ); + + if (in_array($operator, $basicBinayOperatorList)) { + if ($value === true) { + return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}TRUE"; + } else if ($value === false) { + return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}FALSE"; + } else if (is_numeric($value)) { + return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%d", $value); + } else if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + $this->_placeholders[] = $value; + return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString())); + } else { + return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value)); + } + } + + switch ($operator) { + case self::OPERATOR_IS_NULL: + if ($value == false) { + return "{$adapter->quoteIdentifier($field)} IS NOT NULL"; + } else { + return "{$adapter->quoteIdentifier($field)} IS NULL"; + } + break; + + case self::OPERATOR_AND: + case self::OPERATOR_OR: + case self::OPERATOR_XOR: + $where = array(); + foreach ($value as $valueItem) { + $subOperator = key($valueItem); + $realValue = current($valueItem); + + if (is_array($realValue) && isset($realValue['field'])) { + if (!isset($realValue['value'])) { + continue; + } + + $realField = $realValue['field']; + $realValue = $realValue['value']; + } else { + $realField = $field; + } + + if ($realValue === null) { + continue; + } + $actualValue = $this->_translateSqlWhere($realField, $subOperator, $realValue); + if ($actualValue !== null) { + $where[] = $actualValue; + } + } + + if (count($where)) { + return '((' . implode(') ' . strtoupper($operator) . ' (', $where) . '))'; + } + break; + + case self::OPERATOR_IN: + $valueList = array(); + foreach ($value as $setValue) { + $valueList[] = $adapter->quote($setValue); + } + $implodedList = implode(',', $valueList); + return "{$adapter->quoteIdentifier($field)} IN({$implodedList})"; + break; + + case self::OPERATOR_NOT_IN: + $valueList = array(); + foreach ($value as $setValue) { + $valueList[] = $adapter->quote($setValue); + } + $implodedList = implode(',', $valueList); + return "{$adapter->quoteIdentifier($field)} NOT IN({$implodedList})"; + break; + + case self::OPERATOR_FIND_IN_SET: + if (is_array($value)) { + $subField = current($value); + $subOperator = key($value); + + if (in_array($subOperator, $basicBinayOperatorList)) { + return "FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)}){$basicBinayOperatorList[$operator]}{$adapter->quoteIdentifier($subField)}"; + } + } else { + return "0 < FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})"; + } + break; + + case self::OPERATOR_NOT_FIND_IN_SET: + return "0 = FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})"; + break; + + case self::OPERATOR_DATE: + $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']))}"; + } else if (is_string($value['from'])) { + $dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}"; + } else if (is_numeric($value['from'])) { + $dateValues['from'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) >= {$adapter->quote($value['from'])}"; + } + } + 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']))}"; + } else if (is_string($value['to'])) { + $dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}"; + } else if (is_numeric($value['to'])) { + $dateValues['to'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) <= {$adapter->quote($value['to'])}"; + } + } + + return '(' . implode(' AND ', $dateValues) . ')'; + break; + } + + return null; + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/DmlQuery.php b/src/application/code/core/Wootook/Core/Database/Sql/DmlQuery.php index 6872426..19b38f7 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/DmlQuery.php +++ b/src/application/code/core/Wootook/Core/Database/Sql/DmlQuery.php @@ -3,26 +3,6 @@ abstract class Wootook_Core_Database_Sql_DmlQuery implements Wootook_Core_Database_Sql_Dml { - const WHERE = 'WHERE'; - const LIMIT = 'LIMIT'; - const OFFSET = 'OFFSET'; - - const OPERATOR_AND = 'AND'; - const OPERATOR_OR = 'OR'; - const OPERATOR_XOR = 'XOR'; - const OPERATOR_EQUALS = 'EQ'; - const OPERATOR_NOT_EQUALS = 'NEQ'; - const OPERATOR_LOWER = 'LT'; - const OPERATOR_GREATER = 'GT'; - const OPERATOR_LOWER_EQUALS = 'LTEQ'; - const OPERATOR_GREATER_EQUALS = 'GTEQ'; - const OPERATOR_IS_NULL = 'NULL'; - const OPERATOR_IN = 'IN'; - const OPERATOR_NOT_IN = 'NIN'; - const OPERATOR_FIND_IN_SET = 'FINSET'; - const OPERATOR_NOT_FIND_IN_SET = 'NFINSET'; - const OPERATOR_DATE = 'DATE'; - protected $_parts = array(); protected $_connection = null; @@ -79,192 +59,6 @@ abstract class Wootook_Core_Database_Sql_DmlQuery return $this->getConnection()->quoteIdentifier($identifier); } - public function where($condition, $value = null) - { - if ($condition instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { - $this->_parts[self::WHERE][] = $condition; - } else if (is_string($condition)) { - if ($value === null) { - $this->_parts[self::WHERE][] = $condition; - } else { - $adapter = $this->getReadConnection(); - $this->_parts[self::WHERE][] = $adapter->quoteInto($condition, $value); - } - } else if (is_array($condition)) { - $where = $this->_translateSqlWhere($condition, 'or', $value); - if ($where !== null) { - $this->_parts[self::WHERE][] = $where; - } - } - - return $this; - } - - public function limit($limit, $offset = null) - { - $this->_parts[self::LIMIT] = intval($limit); - $this->_parts[self::OFFSET] = intval($offset); - - return $this; - } - - public function renderWhere() - { - if (count($this->_parts[self::WHERE]) <= 0) { - return ''; - } - - return "\nWHERE (" . implode(') AND (', $this->_parts[self::WHERE]) . ')'; - } - - public function renderLimit() - { - if (!$this->_parts[self::LIMIT]) { - return ''; - } - if (!$this->_parts[self::OFFSET]) { - return sprintf("\nLIMIT %d", $this->_parts[self::LIMIT]); - } - return sprintf("\nLIMIT %d,%d", $this->_parts[self::LIMIT], $this->_parts[self::OFFSET]); - } - - protected function _translateSqlWhere($field, $operator, $value) - { - if ($value === null) { - return null; - } - $operator = strtoupper($operator); - $adapter = $this->getReadConnection(); - - $basicBinayOperatorList = array( - self::OPERATOR_EQUALS => '=', - self::OPERATOR_NOT_EQUALS => '!=', - self::OPERATOR_LOWER => '<', - self::OPERATOR_GREATER => '>', - self::OPERATOR_LOWER_EQUALS => '<=', - self::OPERATOR_GREATER_EQUALS => '>=' - ); - - if (in_array($operator, $basicBinayOperatorList)) { - if ($value === true) { - return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}TRUE"; - } else if ($value === false) { - return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}FALSE"; - } else if (is_numeric($value)) { - return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%d", $value); - } else if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { - $this->_placeholders[] = $value; - return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString())); - } else { - return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value)); - } - } - - switch ($operator) { - case self::OPERATOR_IS_NULL: - if ($value == false) { - return "{$adapter->quoteIdentifier($field)} IS NOT NULL"; - } else { - return "{$adapter->quoteIdentifier($field)} IS NULL"; - } - break; - - case self::OPERATOR_AND: - case self::OPERATOR_OR: - case self::OPERATOR_XOR: - $where = array(); - foreach ($value as $valueItem) { - $subOperator = key($valueItem); - $realValue = current($valueItem); - - if (is_array($realValue) && isset($realValue['field'])) { - if (!isset($realValue['value'])) { - continue; - } - - $realField = $realValue['field']; - $realValue = $realValue['value']; - } else { - $realField = $field; - } - - if ($realValue === null) { - continue; - } - $actualValue = $this->_translateSqlWhere($realField, $subOperator, $realValue); - if ($actualValue !== null) { - $where[] = $actualValue; - } - } - - if (count($where)) { - return '((' . implode(') ' . strtoupper($operator) . ' (', $where) . '))'; - } - break; - - case self::OPERATOR_IN: - $valueList = array(); - foreach ($value as $setValue) { - $valueList[] = $adapter->quote($setValue); - } - $implodedList = implode(',', $valueList); - return "{$adapter->quoteIdentifier($field)} IN({$implodedList})"; - break; - - case self::OPERATOR_NOT_IN: - $valueList = array(); - foreach ($value as $setValue) { - $valueList[] = $adapter->quote($setValue); - } - $implodedList = implode(',', $valueList); - return "{$adapter->quoteIdentifier($field)} NOT IN({$implodedList})"; - break; - - case self::OPERATOR_FIND_IN_SET: - if (is_array($value)) { - $subField = current($value); - $subOperator = key($value); - - if (in_array($subOperator, $basicBinayOperatorList)) { - return "FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)}){$basicBinayOperatorList[$operator]}{$adapter->quoteIdentifier($subField)}"; - } - } else { - return "0 < FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})"; - } - break; - - case self::OPERATOR_NOT_FIND_IN_SET: - return "0 = FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})"; - break; - - case self::OPERATOR_DATE: - $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']))}"; - } else if (is_string($value['from'])) { - $dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}"; - } else if (is_numeric($value['from'])) { - $dateValues['from'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) >= {$adapter->quote($value['from'])}"; - } - } - 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']))}"; - } else if (is_string($value['to'])) { - $dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}"; - } else if (is_numeric($value['to'])) { - $dateValues['to'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) <= {$adapter->quote($value['to'])}"; - } - } - - return '(' . implode(' AND ', $dateValues) . ')'; - break; - } - - return null; - } - public function beforePrepare(Wootook_Core_Database_Statement_Statement $statement) { foreach ($this->_placeholders as $placeholder) { @@ -310,4 +104,4 @@ abstract class Wootook_Core_Database_Sql_DmlQuery { return $this->getConnection()->execute($this); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Insert.php b/src/application/code/core/Wootook/Core/Database/Sql/Insert.php new file mode 100644 index 0000000..8f6dc51 --- /dev/null +++ b/src/application/code/core/Wootook/Core/Database/Sql/Insert.php @@ -0,0 +1,142 @@ +into($tableName); + } + + return $this; + } + + public function reset($part = null) + { + if ($part === null) { + $this->_parts = array( + self::INTO => array(), + self::SET => array(), + self::SELECT => array(), + ); + } else if (isset($this->_parts[$part])) { + $this->_parts[$part] = array(); + } + + return $this; + } + + public function set($column, $value) + { + if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + $this->_placeholders[] = $column; + } + + $this->_parts[self::COLUMNS][] = array( + 'value' => $value, + 'field' => $column + ); + + return $this; + } + + public function into($table, $schema = null) + { + $this->_parts[self::INTO] = array( + 'table' => $table, + 'schema' => $schema, + ); + + return $this; + } + + public function select() + { + if (!isset($this->_parts[self::SELECT])) { + $this->_parts[self::SELECT] = $this->getConnection()->select(); + } + + return $this->_parts[self::SELECT]; + } + + public function __toString() + { + return $this->render(); + } + + public function toString($part = null) + { + if ($part === null) { + return $this->render(); + } + + switch ($part) { + case self::COLUMNS: + return $this->renderSet(); + break; + case self::INTO: + return $this->renderInto(); + break; + case self::SELECT: + return $this->renderSelect(); + break; + } + + return null; + } + + public function renderSet() + { + $fields = array(); + foreach ($this->_parts[self::SET] as $field) { + if ($field['value'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}"; + } else { + $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}"; + } + } + + if (!empty($fields)) { + return "\nSET " . implode(", ", $fields); + } + } + + public function renderInto() + { + if ($this->_parts[self::INTO]['schema'] !== null) { + $output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['schema'])}.{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}"; + } else { + $output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}"; + } + + return "INSERT INTO " . $output; + } + + public function renderSelect() + { + if (isset($this->_parts[self::SELECT])) { + return ' ' . $this->_parts[self::SELECT]->render(); + } + return ''; + } + + public function render() + { + if (empty($this->_parts[self::SELECT])) { + return implode('', array( + $this->renderInto(), + $this->renderColumns(), + )); + } else { + return implode('', array( + $this->renderInto(), + $this->renderSelect(), + )); + } + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Expression.php b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Expression.php index e39501f..4b83e95 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Expression.php +++ b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Expression.php @@ -4,14 +4,27 @@ class Wootook_Core_Database_Sql_Placeholder_Expression extends Wootook_Core_Database_Sql_Placeholder_Placeholder { protected $_expression = null; + protected $_params = array(); - public function __construct($expression) + public function __construct($expression, Array $params) { $this->_expression = (string) $expression; + $this->_params = $params; } public function __toString() { return $this->_expression; } -} \ No newline at end of file + + public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement) + { + parent::beforeExecute($statement); + + foreach ($this->_params as $paramName => $value) { + $statement->bindValue($paramName, $value); + } + + return $this; + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php index 1c22a41..a6a9ec2 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php +++ b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php @@ -3,4 +3,26 @@ class Wootook_Core_Database_Sql_Placeholder_Param extends Wootook_Core_Database_Sql_Placeholder_Placeholder { -} \ No newline at end of file + protected $_paramName = null; + protected $_value = null; + + public function __construct($paramName, $value) + { + $this->_paramName = $paramName; + $this->_value = $value; + } + + public function __toString() + { + return ':' . $this->_paramName; + } + + public function beforeExcute(Wootook_Core_Database_Statement_Statement $statement) + { + parent::beforeExcute($statement); + + $statement->bindValue($this->_paramName, $this->_value); + + return $this; + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php index f0981ef..b601575 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php +++ b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php @@ -2,6 +2,11 @@ abstract class Wootook_Core_Database_Sql_Placeholder_Placeholder { + public function toString() + { + return $this->__toString(); + } + abstract public function __toString(); public function beforePrepare(Wootook_Core_Database_Statement_Statement $statement) @@ -14,7 +19,7 @@ abstract class Wootook_Core_Database_Sql_Placeholder_Placeholder return $this; } - public function beforeExcute(Wootook_Core_Database_Statement_Statement $statement) + public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement) { return $this; } @@ -23,4 +28,4 @@ abstract class Wootook_Core_Database_Sql_Placeholder_Placeholder { return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Select.php b/src/application/code/core/Wootook/Core/Database/Sql/Select.php index a64034b..f3ae5a6 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Select.php +++ b/src/application/code/core/Wootook/Core/Database/Sql/Select.php @@ -1,7 +1,7 @@ from($tableName); - - return $this; - } - - /** - * @deprecated - */ - public function getTableName() - { - $table = current($this->_parts[self::FROM]); - - return $table['table']; - } - public function reset($part = null) { if ($part === null) { @@ -348,4 +327,4 @@ abstract class Wootook_Core_Database_Sql_Select )); } } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Update.php b/src/application/code/core/Wootook/Core/Database/Sql/Update.php new file mode 100644 index 0000000..fd229ae --- /dev/null +++ b/src/application/code/core/Wootook/Core/Database/Sql/Update.php @@ -0,0 +1,123 @@ +into($tableName); + } + + return $this; + } + + public function reset($part = null) + { + if ($part === null) { + $this->_parts = array( + self::INTO => array(), + self::SET => array(), + ); + } else if (isset($this->_parts[$part])) { + $this->_parts[$part] = array(); + } + + return $this; + } + + public function set($column, $value) + { + if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + $this->_placeholders[] = $column; + } + + $this->_parts[self::COLUMNS][] = array( + 'value' => $value, + 'field' => $column + ); + + return $this; + } + + public function into($table, $schema = null) + { + $this->_parts[self::INTO] = array( + 'table' => $table, + 'schema' => $schema, + ); + + return $this; + } + + public function __toString() + { + return $this->render(); + } + + public function toString($part = null) + { + if ($part === null) { + return $this->render(); + } + + switch ($part) { + case self::COLUMNS: + return $this->renderSet(); + break; + case self::INTO: + return $this->renderInto(); + break; + case self::SELECT: + return $this->renderSelect(); + break; + } + + return null; + } + + public function renderSet() + { + $fields = array(); + foreach ($this->_parts[self::SET] as $field) { + if ($field['value'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}"; + } else { + $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}"; + } + } + + if (!empty($fields)) { + return "\nSET " . implode(", ", $fields); + } + } + + public function renderInto() + { + if ($this->_parts[self::INTO]['schema'] !== null) { + $output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['schema'])}.{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}"; + } else { + $output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}"; + } + + return "INSERT INTO " . $output; + } + + public function render() + { + if (empty($this->_parts[self::SELECT])) { + return implode('', array( + $this->renderInto(), + $this->renderColumns(), + )); + } else { + return implode('', array( + $this->renderInto(), + $this->renderSelect(), + )); + } + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Statement/Statement.php b/src/application/code/core/Wootook/Core/Database/Statement/Statement.php index 4bcac28..9142151 100644 --- a/src/application/code/core/Wootook/Core/Database/Statement/Statement.php +++ b/src/application/code/core/Wootook/Core/Database/Statement/Statement.php @@ -90,13 +90,13 @@ abstract class Wootook_Core_Database_Statement_Statement * @param array $config * @return Wootook_Object */ - public function fetchEntity($class = 'Wootook_Core_Entity', Array $constructorArgs = array()) + public function fetchEntity($class = 'Wootook_Core_Mvc_Model_Entity', Array $constructorArgs = array()) { $reflection = new ReflectionClass($class); $object = $reflection->newInstanceArgs($constructorArgs); if (!$object instanceof Wootook_Object) { - throw new Wootook_Core_Exception_Database_StatementError($this, 'Destination object should be a Wootook_Core_Entity instance.'); + throw new Wootook_Core_Exception_Database_StatementError($this, 'Destination object should be a Wootook_Core_Mvc_Model_Entity instance.'); } $data = $this->fetch(Wootook_Core_Database_ConnectionManager::FETCH_ASSOC); @@ -196,4 +196,4 @@ abstract class Wootook_Core_Database_Statement_Statement { return $this->_currentRow !== null; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php b/src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php index 8d3afdd..7421bad 100644 --- a/src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php +++ b/src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php @@ -1,7 +1,7 @@ _data); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Model/Config.php b/src/application/code/core/Wootook/Core/Model/Config.php index e5b0170..5607ddf 100644 --- a/src/application/code/core/Wootook/Core/Model/Config.php +++ b/src/application/code/core/Wootook/Core/Model/Config.php @@ -8,7 +8,7 @@ * @uses Legacies_Empire */ class Wootook_Core_Model_Config - extends Wootook_Core_Entity_SubTable + extends Wootook_Core_Mvc_Model_Entity_SubTable { protected $_eventPrefix = 'core.config'; protected $_eventObject = 'config'; @@ -58,4 +58,4 @@ class Wootook_Core_Model_Config { return $this->getData('config_value'); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Model/Game.php b/src/application/code/core/Wootook/Core/Model/Game.php index 1053df6..bc4c234 100644 --- a/src/application/code/core/Wootook/Core/Model/Game.php +++ b/src/application/code/core/Wootook/Core/Model/Game.php @@ -8,7 +8,7 @@ * @uses Legacies_Empire */ class Wootook_Core_Model_Game - extends Wootook_Core_Entity + extends Wootook_Core_Mvc_Model_Entity { const DEFAULT_CODE = 'default'; @@ -20,4 +20,4 @@ class Wootook_Core_Model_Game $this->_tableName = 'core_game'; $this->_idFieldName = 'game_id'; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Model/Layout.php b/src/application/code/core/Wootook/Core/Model/Layout.php index 6cdd519..b40fb1b 100644 --- a/src/application/code/core/Wootook/Core/Model/Layout.php +++ b/src/application/code/core/Wootook/Core/Model/Layout.php @@ -40,7 +40,7 @@ * @category layout */ class Wootook_Core_Model_Layout - extends Wootook_Core_Model + extends Wootook_Core_Mvc_Model_Model { const DEFAULT_PACKAGE = 'base'; const DEFAULT_THEME = 'default'; @@ -51,10 +51,10 @@ class Wootook_Core_Model_Layout /** @var array */ protected $_blocks = array(); - /** @var Wootook_Core_View */ + /** @var Wootook_Core_Mvc_View_View */ protected $_messageBlock = null; - /** @var Wootook_Core_View */ + /** @var Wootook_Core_Mvc_View_View */ protected $_rootView = null; /** @var string */ @@ -369,7 +369,7 @@ class Wootook_Core_Model_Layout * @param string $type * @param string $name * @param array $config - * @return Wootook_Core_View + * @return Wootook_Core_Mvc_View_View */ public function createBlock($type, $name, $config = array()) { @@ -419,7 +419,7 @@ class Wootook_Core_Model_Layout } if (!isset($config['type'])) { - $instance->$alias = new Wootook_Core_View($config); + $instance->$alias = new Wootook_Core_Mvc_View_View($config); } else { $child = $this->_createBlock($config['type'], $name, $config); if ($child !== null) { @@ -555,7 +555,7 @@ class Wootook_Core_Model_Layout public function render() { - if (!$this->_rootView instanceof Wootook_Core_View) { + if (!$this->_rootView instanceof Wootook_Core_Mvc_View_View) { throw new Wootook_Core_Exception_LayoutException(Wootook::__('No root view declared.')); } @@ -623,4 +623,4 @@ class Wootook_Core_Model_Layout { return $this->_messageBlock; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Model/Session.php b/src/application/code/core/Wootook/Core/Model/Session.php index d6d442f..2306f03 100644 --- a/src/application/code/core/Wootook/Core/Model/Session.php +++ b/src/application/code/core/Wootook/Core/Model/Session.php @@ -108,10 +108,11 @@ class Wootook_Core_Model_Session public function getMessages($clear = true) { + $messages = $this->_messages; if ($clear == true) { $this->_messages = array(); } - return $this->_messages; + return $messages; } public function addMessage($message, $type = self::DEBUG) @@ -222,4 +223,4 @@ class Wootook_Core_Model_Session } return $default; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Model/Website.php b/src/application/code/core/Wootook/Core/Model/Website.php index 4284aaa..018edac 100644 --- a/src/application/code/core/Wootook/Core/Model/Website.php +++ b/src/application/code/core/Wootook/Core/Model/Website.php @@ -8,7 +8,7 @@ * @uses Legacies_Empire */ class Wootook_Core_Model_Website - extends Wootook_Core_Entity + extends Wootook_Core_Mvc_Model_Entity { const DEFAULT_CODE = 'default'; @@ -20,4 +20,4 @@ class Wootook_Core_Model_Website $this->_tableName = 'core_website'; $this->_idFieldName = 'website_id'; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Action.php b/src/application/code/core/Wootook/Core/Mvc/Controller/Action.php index 7d69fcd..e6230ba 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Action.php +++ b/src/application/code/core/Wootook/Core/Mvc/Controller/Action.php @@ -73,8 +73,20 @@ abstract class Wootook_Core_Mvc_Controller_Action protected function _redirect($uri, Array $params = array(), $code = Wootook_Core_Mvc_Controller_Response_Http::REDIRECT_FOUND) { + $parts = explode('/', $uri); + $partsCount = count($parts); + if ($partsCount > 0 && $parts[0] == '*') { + $parts[0] = $this->getRequest()->getModuleName(); + if ($partsCount > 1 && $parts[1] == '*') { + $parts[1] = $this->getRequest()->getControllerName(); + if ($partsCount > 2 && $parts[2] == '*') { + $parts[2] = $this->getRequest()->getActionName(); + } + } + } + $uri = implode('/', array_slice($parts, 0, 3)); + $this->getResponse() - ->setIsDispatched(false) ->setRedirect(Wootook::getUrl($uri, $params), $code); Wootook_Core_ErrorProfiler::unregister(true); @@ -140,4 +152,13 @@ abstract class Wootook_Core_Mvc_Controller_Action return $this; } -} \ No newline at end of file + + protected function _prepareLayoutMessages($namespace) + { + $this->getLayout() + ->getMessagesBlock() + ->prepareMessages($namespace); + + return $this; + } +} diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Front.php b/src/application/code/core/Wootook/Core/Mvc/Controller/Front.php index 69ec62c..79ebb93 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Front.php +++ b/src/application/code/core/Wootook/Core/Mvc/Controller/Front.php @@ -5,7 +5,7 @@ class Wootook_Core_Mvc_Controller_Front const ROUTE_DEFAULT = 'default'; const ROUTE_ERROR = 'error'; - // FIXME: Create a router class to manage all this + // FIXME: Create a router class to manage all this mess protected $_routes = array( self::ROUTE_ERROR => array( 'modules' => array( @@ -37,6 +37,10 @@ class Wootook_Core_Mvc_Controller_Front 'empire' => array( 'class' => 'Wootook_Empire_Controller_', 'path' => 'Wootook/Empire/Controller' + ), + 'legacies-empire' => array( + 'class' => 'Legacies_Empire_Controller_', + 'path' => 'Legacies/Empire/Controller' ) ), 'defaults' => array( @@ -152,7 +156,7 @@ class Wootook_Core_Mvc_Controller_Front while ($loop++ < 100) { $moduleKey = $this->_request->getModuleName(); if (empty($moduleKey)) { - $this->_forward('no-route', 'error', 'core'); + $this->_forward('index', 'index', 'core'); continue; } @@ -219,4 +223,4 @@ class Wootook_Core_Mvc_Controller_Front { $this->_response->render(); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Entity.php b/src/application/code/core/Wootook/Core/Mvc/Model/Entity.php similarity index 55% rename from src/application/code/core/Wootook/Core/Entity.php rename to src/application/code/core/Wootook/Core/Mvc/Model/Entity.php index feff633..b32bb3c 100644 --- a/src/application/code/core/Wootook/Core/Entity.php +++ b/src/application/code/core/Wootook/Core/Mvc/Model/Entity.php @@ -1,8 +1,8 @@ where("{$database->quoteIdentifier($idFieldName)}=:id") ->limit(1); - $statement = $database->prepare($select); + $statement = $select->prepare(); $statement->execute(array( 'id' => $id )); @@ -70,68 +70,46 @@ abstract class Wootook_Core_Entity protected function _save() { - $database = $this->getWriteConnection(); + $adapter = $this->getWriteConnection(); + + if ($adapter === null) { + throw new Wootook_Core_Exception_DataAccessException('Could not save data: no write connection configured.'); + } if ($this->getId() !== null) { - $fields = array(); - $values = array(); - $datas = $this->getDataMapper()->encode($this, $this->getAllDatas()); - foreach ($datas as $field => $value) { - if ($field == $this->getIdFieldName()) { - continue; - } - $fields[] = "{$database->quoteIdentifier($field)}=:{$field}"; - $values[$field] = $value; + $update = $adapter->update() + ->into($adapter->getTable($this->getTableName())) + ->where("{$adapter->quoteIdentifier($this->getIdFieldName())}=:id"); + + foreach ($this->getDataMapper()->encode($this, $this->getChangedDatas()) as $field => $value) { + $update->set($field, new Wootook_Core_Database_Sql_Placeholder_Param($field, $value)); } - - $fieldsImploded = implode(', ', $fields); - $idFieldName = $this->getIdFieldName(); - $values[$idFieldName] = $this->getId(); - - if ($database === null) { - throw new Wootook_Core_Exception_DataAccessException('Could not load data: no write connection configured.'); + try { + $statement = $update->prepare(); + $statement->execute(array('id' => $this->getId())); + } catch (Wootook_Core_Exception_Database_AdapterError $e) { + throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); + } catch (Wootook_Core_Exception_Database_StatementError $e) { + throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); } - - $sql =<<getTable($this->getTableName())} - SET {$fieldsImploded} - WHERE {$idFieldName}=:{$idFieldName} -SQL_EOF; - $statement = $database->prepare($sql); - - $statement->execute($values); } else { - $datas = $this->getAllDatas(); + $insert = $adapter->insert() + ->into($adapter->getTable($this->getTableName())); - $fields = array(); - $tokens = array(); - $values = array(); - foreach ($datas as $field => $value) { - if ($field == $this->getIdFieldName()) { - continue; - } - $tokens[] = ":{$field}"; - $fields[] = $database->quoteIdentifier($field); - $values[$field] = strval($value); + foreach ($this->getDataMapper()->encode($this, $this->getAllDatas()) as $field => $value) { + $insert->set($field, new Wootook_Core_Database_Sql_Placeholder_Param($field, $value)); } - $tokensImploded = implode(', ', $tokens); - $fieldsImploded = implode(', ', $fields); + try { + $statement = $insert->prepare(); + $statement->execute(); - if ($database === null) { - throw new Wootook_Core_Exception_DataAccessException('Could not load data: no write connection configured.'); + $id = $adapter->lastInsertId($table); + $this->setId($id); + } catch (Wootook_Core_Exception_Database_AdapterError $e) { + throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); + } catch (Wootook_Core_Exception_Database_StatementError $e) { + throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); } - - $table = $database->getTable($this->getTableName()); - $sql =<<quoteIdentifier($table)} ({$database->quoteIdentifier($this->getIdFieldName())}, $fieldsImploded) - VALUES (NULL, {$tokensImploded}) -SQL_EOF; - $statement = $database->prepare($sql); - - $statement->execute($values); - - $id = $database->lastInsertId($table); - $this->setId($id); } return $this; @@ -163,4 +141,4 @@ SQL_EOF; return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Entity/SubTable.php b/src/application/code/core/Wootook/Core/Mvc/Model/Entity/SubTable.php similarity index 98% rename from src/application/code/core/Wootook/Core/Entity/SubTable.php rename to src/application/code/core/Wootook/Core/Mvc/Model/Entity/SubTable.php index ee90f75..791d481 100644 --- a/src/application/code/core/Wootook/Core/Entity/SubTable.php +++ b/src/application/code/core/Wootook/Core/Mvc/Model/Entity/SubTable.php @@ -6,7 +6,7 @@ * @uses Legacies_Empire * @uses Wootook_Player_Model_Entity */ -abstract class Wootook_Core_Entity_SubTable +abstract class Wootook_Core_Mvc_Model_Entity_SubTable extends Wootook_Core_Database_Resource { private $_isLoaded = false; @@ -117,4 +117,4 @@ SQL_EOF; return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/EntityInterface.php b/src/application/code/core/Wootook/Core/Mvc/Model/EntityInterface.php similarity index 96% rename from src/application/code/core/Wootook/Core/EntityInterface.php rename to src/application/code/core/Wootook/Core/Mvc/Model/EntityInterface.php index 0ed3eb7..e512a5d 100644 --- a/src/application/code/core/Wootook/Core/EntityInterface.php +++ b/src/application/code/core/Wootook/Core/Mvc/Model/EntityInterface.php @@ -34,7 +34,7 @@ * @author Greg * */ -interface Wootook_Core_EntityInterface +interface Wootook_Core_Mvc_Model_EntityInterface { public function getId(); public function setId($id); @@ -44,4 +44,4 @@ interface Wootook_Core_EntityInterface public function getTableName(); public function setTableName($tableName); -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Model.php b/src/application/code/core/Wootook/Core/Mvc/Model/Model.php similarity index 92% rename from src/application/code/core/Wootook/Core/Model.php rename to src/application/code/core/Wootook/Core/Mvc/Model/Model.php index bdd8a4e..e91265f 100644 --- a/src/application/code/core/Wootook/Core/Model.php +++ b/src/application/code/core/Wootook/Core/Mvc/Model/Model.php @@ -34,7 +34,7 @@ * @author Greg * */ -abstract class Wootook_Core_Model +abstract class Wootook_Core_Mvc_Model_Model extends Wootook_Object { protected $_originalData = array(); @@ -47,14 +47,27 @@ abstract class Wootook_Core_Model $this->_data = $data; $this->_init(); - $this->_setOriginalData($this->_data); + $this->_setOriginalData(); } abstract protected function _init(); - protected function _setOriginalData(Array $data) + protected function _setOriginalData() { - $this->_originalData = $data; + $this->_originalData = $this->_data; + } + + public function getChangedDatas() + { + return array_diff_assoc($this->_data, $this->_originalData); + } + + public function hasChangedDatas() + { + if (count($this->getChangedDatas()) > 0) { + return true; + } + return false; } final public function save() @@ -189,4 +202,4 @@ abstract class Wootook_Core_Model { return $this->hasData($key); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/View.php b/src/application/code/core/Wootook/Core/Mvc/View/View.php similarity index 99% rename from src/application/code/core/Wootook/Core/View.php rename to src/application/code/core/Wootook/Core/Mvc/View/View.php index 7a0e12c..2b371fb 100644 --- a/src/application/code/core/Wootook/Core/View.php +++ b/src/application/code/core/Wootook/Core/Mvc/View/View.php @@ -34,7 +34,7 @@ * @author Greg * */ -class Wootook_Core_View +class Wootook_Core_Mvc_View_View extends Wootook_Object { protected $_template = null; @@ -330,4 +330,4 @@ class Wootook_Core_View { return $this->_scriptPath; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Controller/BuildingsController.php b/src/application/code/core/Wootook/Empire/Controller/BuildingsController.php new file mode 100644 index 0000000..6a5234b --- /dev/null +++ b/src/application/code/core/Wootook/Empire/Controller/BuildingsController.php @@ -0,0 +1,43 @@ +loadLayout('planet.buildings'); + $this->renderLayout(); + } + + public function buildAction() + { + if (!is_numeric($buildingId = $this->getRequest()->getParam('id'))) { + $this->_redirect('*/*/view'); + return; + } + + $this->getCurrentPlanet()->appendBuildingQueue($buildingId); + $this->getCurrentPlanet()->save(); + + $this->_redirect('*/*/'); + } + + public function cancelAction() + { + if (!is_numeric($buildingId = $this->getRequest()->getParam('id'))) { + $this->_redirect('*/*/view'); + return; + } + + $this->getCurrentPlanet()->dequeueBuilding($buildingId); + $this->getCurrentPlanet()->save(); + + $this->_redirect('*/*/'); + } +} diff --git a/src/application/code/core/Wootook/Empire/Model/Fleet.php b/src/application/code/core/Wootook/Empire/Model/Fleet.php index fcda2d8..80d857a 100644 --- a/src/application/code/core/Wootook/Empire/Model/Fleet.php +++ b/src/application/code/core/Wootook/Empire/Model/Fleet.php @@ -7,7 +7,7 @@ * @uses Legacies_Empire */ class Wootook_Empire_Model_Fleet - extends Wootook_Core_Entity + extends Wootook_Core_Mvc_Model_Entity { protected static $_instances = array(); @@ -152,4 +152,4 @@ class Wootook_Empire_Model_Fleet return Wootook_Empire_Model_Planet::factoryFromCoords($coords, $type); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php b/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php index 8ca4d62..2ce4b24 100644 --- a/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php +++ b/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php @@ -1,11 +1,11 @@ _tableName = 'galaxy'; $this->_idFieldNames = array('id_planet'); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Model/Planet.php b/src/application/code/core/Wootook/Empire/Model/Planet.php index e2b7683..f3312f1 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet.php @@ -7,7 +7,7 @@ * @uses Wootook_Player_Model_Entity */ class Wootook_Empire_Model_Planet - extends Wootook_Core_Entity + extends Wootook_Core_Mvc_Model_Entity { const TYPE_PLANET = 1; const TYPE_DEBRIS = 2; @@ -965,4 +965,4 @@ class Wootook_Empire_Model_Planet } return false; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Object.php b/src/application/code/core/Wootook/Object.php index a9afd72..d3271ee 100644 --- a/src/application/code/core/Wootook/Object.php +++ b/src/application/code/core/Wootook/Object.php @@ -113,4 +113,4 @@ class Wootook_Object { return $this->unsetData($offset); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Player/Controller/AccountController.php b/src/application/code/core/Wootook/Player/Controller/AccountController.php index 7884ce0..98815cc 100644 --- a/src/application/code/core/Wootook/Player/Controller/AccountController.php +++ b/src/application/code/core/Wootook/Player/Controller/AccountController.php @@ -46,6 +46,7 @@ class Wootook_Player_Controller_AccountController } $this->loadLayout('player.login'); + $this->_prepareLayoutMessages(Wootook_Player_Model_Entity::SESSION_KEY); $this->renderLayout(); } @@ -111,4 +112,4 @@ class Wootook_Player_Controller_AccountController public function optionsAction() { } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Player/Model/Entity.php b/src/application/code/core/Wootook/Player/Model/Entity.php index cdf1b4b..a463aed 100644 --- a/src/application/code/core/Wootook/Player/Model/Entity.php +++ b/src/application/code/core/Wootook/Player/Model/Entity.php @@ -8,7 +8,7 @@ * @uses Legacies_Empire */ class Wootook_Player_Model_Entity - extends Wootook_Core_Entity + extends Wootook_Core_Mvc_Model_Entity { protected static $_instances = array(); @@ -620,4 +620,4 @@ class Wootook_Player_Model_Entity } return false; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Player/Model/Message.php b/src/application/code/core/Wootook/Player/Model/Message.php index 6532b71..0002d94 100644 --- a/src/application/code/core/Wootook/Player/Model/Message.php +++ b/src/application/code/core/Wootook/Player/Model/Message.php @@ -1,7 +1,7 @@ _tableName = 'messages'; $this->_idFieldNames = array('message_id', 'message_owner'); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Player/Model/Session.php b/src/application/code/core/Wootook/Player/Model/Session.php index 7b8683c..a27e7af 100644 --- a/src/application/code/core/Wootook/Player/Model/Session.php +++ b/src/application/code/core/Wootook/Player/Model/Session.php @@ -6,6 +6,9 @@ class Wootook_Player_Model_Session { protected static $_singleton = null; + /** + * @var Wootook_Player_Model_Entity + */ protected $_player = null; public function __construct() @@ -32,6 +35,14 @@ class Wootook_Player_Model_Session return $this->getData('player_id'); } + public function setPlayer(Wootook_Player_Model_Entity $player) + { + $this->_player = $player; + $this->setData('player_id', $player->getId()); + + return $this; + } + /** * * Enter description here ... @@ -45,32 +56,33 @@ class Wootook_Player_Model_Session try { if ($this->hasData('player_id')) { $id = intval($this->getData('player_id')); - } else if (Wootook::getRequest() !== null && ($cookieData = Wootook::getRequest()->getCookie($this->_player->getCookieName())) !== null) { - if (is_array($cookieData)) { - $adapter = $this->_player->getReadConnection(); - $select = $adapter->select(array('user' => 'users')); - $cookieData = array( - 'id' => (isset($cookieData['id']) ? intval($cookieData['id']) : 0), - 'key' => (isset($cookieData['key']) ? $collection->quote($cookieData['key']) : null) - ); + } else if (Wootook::getRequest() !== null && + ($cookieData = Wootook::getRequest()->getCookie($this->_player->getCookieName())) !== null && + is_array($cookieData)) { - $select - ->column('id') - ->where('user.id=:id') - ->where(':key=CONCAT((@salt:=MID(:key, 0, 4)), SHA1(CONCAT(user.username, user.password, @salt)))') - ; - try { - $statement = $adapter->prepare($select); - if (!$statement->execute($cookieData) || $statement->rowCount() <= 0) { - throw new Wootook_Player_Exception_Session('Your session has expired, please login.'); - } - } catch (PDOException $e) { - throw new Wootook_Core_Exception_DataAccessException('Session error.', null, $e); + $adapter = $this->_player->getReadConnection(); + $select = $adapter->select(array('user' => 'users')); + $cookieData = array( + 'id' => (isset($cookieData['id']) ? intval($cookieData['id']) : 0), + 'key' => (isset($cookieData['key']) ? $adapter->quote($cookieData['key']) : null) + ); + + $select + ->column('id') + ->where('user.id=:id') + ->where(':key=CONCAT((@salt:=MID(:key, 0, 4)), SHA1(CONCAT(user.username, user.password, @salt)))') + ; + try { + $statement = $adapter->prepare($select); + if (!$statement->execute($cookieData) || $statement->rowCount() <= 0) { + throw new Wootook_Player_Exception_Session('Your session has expired, please login.'); } - $this->setData(self::SESSION_KEY, $cookieData['id']); - } else { - throw new Wootook_Player_Exception_Session('Your session has expired, please login.'); + $id = $statement->fetchColumn(); + } catch (Wootook_Core_Exception_Database_AdapterError $e) { + throw new Wootook_Core_Exception_DataAccessException('Session error.', null, $e); + } catch (Wootook_Core_Exception_Database_StatementError $e) { + throw new Wootook_Core_Exception_DataAccessException('Session error.', null, $e); } } else { throw new Wootook_Player_Exception_Session('Your session has expired, please login.'); @@ -109,20 +121,26 @@ class Wootook_Player_Model_Session public function login($username, $password, $remember = false) { try { - if ($this->getPlayer()->getId()) { + if ($this->_player === null) { + $this->_player = new Wootook_Player_Model_Entity(); + } + + if ($this->_player->getId()) { return $this->_player; } $adapter = $this->_player->getReadConnection(); - $select = $adapter->select(array('user' => 'users')); + $select = $adapter->select(array('user' => $adapter->getTable($this->_player->getTableName()))); - $passwordHash = md5($password); + $passwordHash = $this->_player->hash($password); $select - ->column('user.id') - ->column('user.username') - ->column('user.password') - ->column('user.banaday') - ->column('CONCAT((@salt:=MID(MD5(RAND()), 0, 4)), SHA1(CONCAT(user.username, user.password, @salt))) AS login_rememberme') - ->column('(CASE WHEN user.password="' . $passwordHash . '" THEN 1 ELSE 0 END) AS login_success') + ->column(array( + 'id' => 'user.id', + 'username' => 'user.username', + 'password_hash' => 'user.password', + 'is_banned' => 'user.banaday', + 'login_rememberme' => new Wootook_Core_Database_Sql_Placeholder_Expression('CONCAT((@salt:=MID(MD5(RAND()), 0, 4)), SHA1(CONCAT(user.username, user.password, @salt)))'), + 'login_success' => new Wootook_Core_Database_Sql_Placeholder_Expression("(CASE WHEN user.password={$adapter->quote($passwordHash)} THEN 1 ELSE 0 END)") + )) ->where('user.username=:username'); $statement = $adapter->prepare($select); @@ -130,7 +148,7 @@ class Wootook_Player_Model_Session $this->addError(Wootook::__('No such user.')); return $this->_player; } - } catch (PDOException $e) { + } catch (Wootook_Core_Exception_Database_StatementError $e) { Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); $this->addError(Wootook::__('No such user.')); return $this->_player; @@ -185,4 +203,4 @@ class Wootook_Player_Model_Session return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php b/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php index 2db252e..3374acf 100644 --- a/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php +++ b/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php @@ -8,6 +8,16 @@ class Wootook_Player_Mvc_Controller_Registered return Wootook_Player_Model_Session::getSingleton(); } + public function getPlayer() + { + return $this->getSession()->getPlayer(); + } + + public function getCurrentPlanet() + { + return $this->getPlayer()->getCurrentPlanet(); + } + public function preDispatch() { if (!$this->getSession()->isLoggedIn()) { @@ -19,4 +29,4 @@ class Wootook_Player_Mvc_Controller_Registered { return $this->_redirect('player/account/login'); } -} \ No newline at end of file +} diff --git a/src/application/design/frontend/base/default/layouts/empire.xml b/src/application/design/frontend/base/default/layouts/empire.xml index 8740373..3b45efc 100644 --- a/src/application/design/frontend/base/default/layouts/empire.xml +++ b/src/application/design/frontend/base/default/layouts/empire.xml @@ -29,114 +29,111 @@ planet/overview Overview Overview - overview.php + player/overview planet/buildings Buildings Buildings - buildings.php + empire/buildings planet/research-lab Research Lab Research Lab - buildings.php - research + legacies-empire/research-lab planet/shipyard Shipyard Shipyard - buildings.php - fleet + legacies-empire/shipyard planet/defenses Defenses Defenses - buildings.php - defense + legacies-empire/defense - + universe/galaxy Check out the Galaxy Check out the Galaxy galaxy.php - + universe/fleet Send a Fleet Send a Fleet fleet.php - + universe/retailer Retailer Retailer marchand.php - + universe/records All Records All Records records.php - + universe/statistics My Stats My Stats stat.php - + universe/search-player Search a Player Search a Player search.php - + universe/empire Empire Empire imperium.php - + account/officers Officers Officers officier.php - + account/alliance My Alliance My Alliance alliance.php - + account/messages My Messages My Messages messages.php - + account/resources My Resources Production My Resources Production resources.php - + account/tech-tree Technology Tree Technology Tree techtree.php - + tools/notes Note Pad Note Pad notes.php - + tools/options Account Options Account Options @@ -146,7 +143,7 @@ tools/logout Log Out Log Out - logout.php + player/account/logout community/board @@ -154,37 +151,37 @@ Forum board http://wootook.org/board/ - + community/chat Chat Chat chat.php - + community/announcement Announcements Announcements annonce.php - + community/multi Declare Multi-account Declare Multi-account delclare_multi.php - + community/rules Rules Rules rules.php - + community/contact Contact Admin Contact Admin contact.php - + community/banned Banned Players Banned Players @@ -307,4 +304,4 @@ - \ No newline at end of file + diff --git a/src/application/design/frontend/base/default/layouts/page.xml b/src/application/design/frontend/base/default/layouts/page.xml index d04f3b8..02e472d 100644 --- a/src/application/design/frontend/base/default/layouts/page.xml +++ b/src/application/design/frontend/base/default/layouts/page.xml @@ -118,7 +118,7 @@ - + - \ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/empire/planet/buildings/item.phtml b/src/application/design/frontend/base/default/scripts/empire/planet/buildings/item.phtml index 4254d2f..1d3fb40 100644 --- a/src/application/design/frontend/base/default/scripts/empire/planet/buildings/item.phtml +++ b/src/application/design/frontend/base/default/scripts/empire/planet/buildings/item.phtml @@ -12,7 +12,7 @@
diff --git a/src/application/design/frontend/base/default/scripts/empire/planet/buildings/queue/item.phtml b/src/application/design/frontend/base/default/scripts/empire/planet/buildings/queue/item.phtml index f0ab9b0..827f75f 100644 --- a/src/application/design/frontend/base/default/scripts/empire/planet/buildings/queue/item.phtml +++ b/src/application/design/frontend/base/default/scripts/empire/planet/buildings/queue/item.phtml @@ -6,6 +6,6 @@

__('Lasts %s', $this->renderTime($this->getBuildingRemainingTime()))?>

-
\ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/item.phtml b/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/item.phtml index 87c1d88..de636cd 100644 --- a/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/item.phtml +++ b/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/item.phtml @@ -7,7 +7,7 @@

getDescription()?>

@@ -27,4 +27,4 @@

__('Building time: %s', $this->renderTime($this->getBuildingTimeForNextLevel(), false))?>

- \ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/queue/item.phtml b/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/queue/item.phtml index f0ab9b0..d1ffa3f 100644 --- a/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/queue/item.phtml +++ b/src/application/design/frontend/base/default/scripts/empire/planet/research-lab/queue/item.phtml @@ -6,6 +6,6 @@

__('Lasts %s', $this->renderTime($this->getBuildingRemainingTime()))?>

- \ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/empire/planet/shipyard.phtml b/src/application/design/frontend/base/default/scripts/empire/planet/shipyard.phtml index 4f19a2d..835cf47 100644 --- a/src/application/design/frontend/base/default/scripts/empire/planet/shipyard.phtml +++ b/src/application/design/frontend/base/default/scripts/empire/planet/shipyard.phtml @@ -1,6 +1,6 @@

__('Shipyard')?>

-
+ getPartial('item-list.items')->render()?>
@@ -28,4 +28,4 @@ jQuery(document).ready(function(){ }); /*]]>*/ -
\ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/page/html/home.phtml b/src/application/design/frontend/base/default/scripts/page/html/home.phtml new file mode 100644 index 0000000..2a5f5be --- /dev/null +++ b/src/application/design/frontend/base/default/scripts/page/html/home.phtml @@ -0,0 +1 @@ +getLayout()->getMessagesBlock()->renderGroupedHtml()?> diff --git a/src/application/design/frontend/base/default/scripts/player/login.phtml b/src/application/design/frontend/base/default/scripts/player/login.phtml index 6594e56..602e6be 100644 --- a/src/application/design/frontend/base/default/scripts/player/login.phtml +++ b/src/application/design/frontend/base/default/scripts/player/login.phtml @@ -1,3 +1,4 @@ +getLayout()->getMessagesBlock()->renderGroupedHtml()?>
__('Login')?> @@ -20,4 +21,4 @@

- \ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/player/lost-password.phtml b/src/application/design/frontend/base/default/scripts/player/lost-password.phtml index 9e074f0..67454ca 100644 --- a/src/application/design/frontend/base/default/scripts/player/lost-password.phtml +++ b/src/application/design/frontend/base/default/scripts/player/lost-password.phtml @@ -1,3 +1,4 @@ +getLayout()->getMessagesBlock()->renderGroupedHtml()?>
__('Lost your password?')?> @@ -13,4 +14,4 @@

- \ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/player/overview.phtml b/src/application/design/frontend/base/default/scripts/player/overview.phtml index 96f9e62..67eb785 100644 --- a/src/application/design/frontend/base/default/scripts/player/overview.phtml +++ b/src/application/design/frontend/base/default/scripts/player/overview.phtml @@ -1,3 +1,4 @@ +getLayout()->getMessagesBlock()->renderGroupedHtml()?>

__('Overview')?>

@@ -7,4 +8,4 @@ renderPartial('overview.center')?>
-
\ No newline at end of file + diff --git a/src/application/design/frontend/base/default/scripts/player/registration.phtml b/src/application/design/frontend/base/default/scripts/player/registration.phtml index 28aae6a..0be5fbc 100644 --- a/src/application/design/frontend/base/default/scripts/player/registration.phtml +++ b/src/application/design/frontend/base/default/scripts/player/registration.phtml @@ -1,3 +1,4 @@ +getLayout()->getMessagesBlock()->renderGroupedHtml()?>

__('Register')?>

@@ -36,4 +37,4 @@

- \ No newline at end of file + diff --git a/src/buildings.php b/src/buildings.php deleted file mode 100644 index 099956f..0000000 --- a/src/buildings.php +++ /dev/null @@ -1,182 +0,0 @@ - - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * --> NOTICE <-- - * This file is part of the core development branch, changing its contents will - * make you unable to use the automatic updates manager. Please refer to the - * documentation for further information about customizing Wootook. - * - */ - -define('INSIDE' , true); -define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; - -includeLang('buildings'); - -$player = Wootook_Player_Model_Session::getSingleton()->getPlayer(); -$planet = $player->getCurrentPlanet(); -$mode = isset($_GET['mode']) ? $_GET['mode'] : null; - -switch ($mode) { -case 'fleet': - if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) { - $layout = new Wootook_Core_Model_Layout(Wootook_Core_Model_Layout::DOMAIN_FRONTEND); - $layout->load('message'); - - $block = $layout->getBlock('message'); - $block['title'] = Wootook::__('Shipyard is required'); - $block['message'] = Wootook::__('In order to build ships you will need to build a shipyard building.'); - - echo $layout->render(); - break; - } - - /** @var Legacies_Empire_Model_Planet_Building_Shipyard $shipyard */ - $shipyard = $planet->getShipyard(); - if (isset($_POST['ship']) && is_array($_POST['ship'])) { - foreach ($_POST['ship'] as $shipId => $count) { - $shipId = intval($shipId); - $count = intval($count); - - $shipyard->appendQueue($shipId, $count); - } - $planet->save(); - - Wootook::getResponse() - ->setRedirect(Wootook::getStaticUrl('buildings.php', array('mode' => $mode))) - ->sendHeaders(); - exit(0); - } - - $layout = new Wootook_Core_Model_Layout(); - $layout->load('planet.shipyard'); - - echo $layout->render(); - break; - -case 'research': - if ($planet->getElement(Legacies_Empire::ID_BUILDING_RESEARCH_LAB) < 1) { - $layout = new Wootook_Core_Model_Layout(); - $layout->load('message'); - - $block = $layout->getBlock('message'); - $block['title'] = Wootook::__('Research lab is required'); - $block['message'] = Wootook::__('In order to do technological researches, you will need to build a research lab building.'); - - echo $layout->render(); - break; - } - - if (isset($_GET['research']) && !empty($_GET['research'])) { - $data = $planet->getAllDatas(); - $planet->getResearchLab()->appendQueue(intval($_GET['research'])); - $planet->save(); - $player->save(); - - Wootook::getResponse() - ->setRedirect(Wootook::getStaticUrl('buildings.php', array('mode' => $mode))) - ->sendHeaders(); - exit(0); - } else if (isset($_GET['cancel']) && !empty($_GET['cancel'])) { - $planet->dequeueItem($_GET['cancel']); - $planet->save(); - - Wootook::getResponse() - ->setRedirect(Wootook::getStaticUrl('buildings.php', array('mode' => $mode))) - ->sendHeaders(); - exit(0); - } - - $layout = new Wootook_Core_Model_Layout(); - $layout->load('planet.research-lab'); - - echo $layout->render(); - break; - -case 'defense': - if ($planet->getElement(Legacies_Empire::ID_BUILDING_SHIPYARD) < 1) { - $layout = new Wootook_Core_Model_Layout(); - $layout->load('message'); - - $block = $layout->getBlock('message'); - $block['title'] = Wootook::__('Shipyard is required'); - $block['message'] = Wootook::__('In order to build ships you will need to build a shipyard building.'); - - echo $layout->render(); - break; - } - - /** @var Legacies_Empire_Model_Planet_Building_Shipyard $shipyard */ - $shipyard = $planet->getShipyard(); - if (isset($_POST['defense']) && is_array($_POST['defense'])) { - foreach ($_POST['defense'] as $defenseId => $count) { - $defenseId = intval($defenseId); - $count = intval($count); - - $shipyard->appendQueue($defenseId, $count); - } - $planet->save(); - - Wootook::getResponse() - ->setRedirect(Wootook::getStaticUrl('buildings.php', array('mode' => $mode))) - ->sendHeaders(); - exit(0); - } - - $layout = new Wootook_Core_Model_Layout(); - $layout->load('planet.defense'); - - /** @var Legacies_Empire_Block_Planet_Shipyard $block */ - $block = $layout->getBlock('item-list'); - $block->setType(Legacies_Empire::TYPE_DEFENSE); - - echo $layout->render(); - break; - -default: - if (isset($_GET['building']) && !empty($_GET['building'])) { - $data = $planet->getAllDatas(); - $planet->appendBuildingQueue(intval($_GET['building']), isset($_GET['destroy'])); - $planet->save(); - - Wootook::getResponse() - ->setRedirect(Wootook::getStaticUrl('buildings.php', array('mode' => $mode))) - ->sendHeaders(); - exit(0); - } else if (isset($_GET['cancel']) && !empty($_GET['cancel'])) { - $planet->dequeueItem($_GET['cancel']); - $planet->save(); - - Wootook::getResponse() - ->setRedirect(Wootook::getStaticUrl('buildings.php', array('mode' => $mode))) - ->sendHeaders(); - exit(0); - } - - $layout = new Wootook_Core_Model_Layout(); - $layout->load('planet.buildings'); - echo $layout->render(); - break; -} - diff --git a/src/imperium.php b/src/imperium.php index 804c803..fb89688 100644 --- a/src/imperium.php +++ b/src/imperium.php @@ -77,13 +77,13 @@ foreach ($planet as $p) { foreach ($resource as $i => $res) { if (in_array($i, $reslist['build'])) - $data['text'] = ($p[$resource[$i]] == 0) ? '-' : "{$p[$resource[$i]]}"; + $data['text'] = ($p[$resource[$i]] == 0) ? '-' : '' . $p[$resource[$i]] . ''; elseif (in_array($i, $reslist['tech'])) - $data['text'] = ($user[$resource[$i]] == 0) ? '-' : "{$user[$resource[$i]]}"; + $data['text'] = ($p[$resource[$i]] == 0) ? '-' : '' . $p[$resource[$i]] . ''; elseif (in_array($i, $reslist['fleet'])) - $data['text'] = ($p[$resource[$i]] == 0) ? '-' : "{$p[$resource[$i]]}"; + $data['text'] = ($p[$resource[$i]] == 0) ? '-' : '' . $p[$resource[$i]] . ''; elseif (in_array($i, $reslist['defense'])) - $data['text'] = ($p[$resource[$i]] == 0) ? '-' : "{$p[$resource[$i]]}"; + $data['text'] = ($p[$resource[$i]] == 0) ? '-' : '' . $p[$resource[$i]] . ''; $r[$i] .= parsetemplate($row2, $data); } diff --git a/src/includes/deprecated.php b/src/includes/deprecated.php index 5c0c3d9..26a9645 100644 --- a/src/includes/deprecated.php +++ b/src/includes/deprecated.php @@ -536,7 +536,7 @@ function display($page, $title = '', $topnav = true, $metatags = '', $adminPage } $content = $layout->getBlock('content'); - if (!$content instanceof Wootook_Core_View) { + if (!$content instanceof Wootook_Core_Mvc_View_View) { exit(0); } $pageContent = $layout->createBlock('core/text', 'content'); @@ -670,4 +670,4 @@ function ResetThisFuckingCheater($userId) $user->setData('password', $password); $user->save(); return; -} \ No newline at end of file +} diff --git a/src/infos.php b/src/infos.php index bca54c0..0e33064 100644 --- a/src/infos.php +++ b/src/infos.php @@ -327,7 +327,7 @@ function ShowBuildingInfoPage ($CurrentUser, $CurrentPlanet, $BuildID) { // ---- Destruction $NeededRessources = GetBuildingPrice ($CurrentUser, $CurrentPlanet, $BuildID, true, true); $DestroyTime = GetBuildingTime ($CurrentUser, $CurrentPlanet, $BuildID) / 2; - $parse['destroyurl'] = "buildings.php?cmd=destroy&building=".$BuildID; // Non balisé les balises sont dans le tpl + $parse['destroyurl'] = Wootook::getUrl('empire/buildings/destroy', array('id' => $BuildID)); // Non balisé les balises sont dans le tpl $parse['levelvalue'] = $CurrentPlanet[$resource[$BuildID]]; // Niveau du batiment a detruire $parse['nfo_metal'] = $lang['Metal']; $parse['nfo_crysta'] = $lang['Crystal']; @@ -358,4 +358,4 @@ function ShowBuildingInfoPage ($CurrentUser, $CurrentPlanet, $BuildID) { // History version // 1.0 - Réécriture (réinventation de l'eau tiède) // 1.1 - Ajout JumpGate pour la porte de saut comme la présente OGame ... Enfin un peu mieux quand meme ! -?> \ No newline at end of file +?>