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 =<< __('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?> __('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?> __('Lasts %s', $this->renderTime($this->getBuildingRemainingTime()))?> __('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?> __('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?> getDescription()?> __('Building time: %s', $this->renderTime($this->getBuildingTimeForNextLevel(), false))?>
__('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 @@