Added building/research-lab/shipyard/defenses MVC controllers
Refactored View & Model base classes Added database adapter error messages and status utility methods Fixed login error Fixed HTTP 404 error on home page Fixed minor bugs Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
802be5f8c3
commit
3dde300c80
65 changed files with 1242 additions and 646 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -2,4 +2,6 @@ config.php
|
|||
.buildpath
|
||||
.project
|
||||
.settings/
|
||||
.idea/
|
||||
coverage/
|
||||
src/application/cache/*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: Greg
|
||||
* Date: 19/03/12
|
||||
* Time: 18:11
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class Legacies_Empire_Controller_DefenseController
|
||||
extends Wootook_Player_Mvc_Controller_Registered
|
||||
{
|
||||
public function preDispatch()
|
||||
{
|
||||
$planet = $this->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('*/*/');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: Greg
|
||||
* Date: 19/03/12
|
||||
* Time: 18:11
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class Legacies_Empire_Controller_ResearchLabController
|
||||
extends Wootook_Player_Mvc_Controller_Registered
|
||||
{
|
||||
public function preDispatch()
|
||||
{
|
||||
$planet = $this->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('*/*/');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: Greg
|
||||
* Date: 19/03/12
|
||||
* Time: 18:11
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class Legacies_Empire_Controller_ShipyardController
|
||||
extends Wootook_Player_Mvc_Controller_Registered
|
||||
{
|
||||
public function preDispatch()
|
||||
{
|
||||
$planet = $this->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('*/*/');
|
||||
}
|
||||
}
|
||||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Concat
|
||||
extends Wootook_Core_View
|
||||
extends Wootook_Core_Mvc_View_View
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,32 @@ class Wootook_Core_Block_Html_Navigation
|
|||
|
||||
return $this;
|
||||
}
|
||||
public function addStaticLink($name, $label, $title, $uri, Array $params = array(), Array $classes = array(), $template = null, Array $attributes = array())
|
||||
{
|
||||
$explodedPath = explode('/', $name);
|
||||
$baseName = array_pop($explodedPath);
|
||||
$parent = $this->_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())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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,11 +157,19 @@ class Wootook_Core_Block_Html_Navigation_Link
|
|||
|
||||
if (isset($data['url'])) {
|
||||
if (is_array($data['url']) && isset($data['url']['uri'])) {
|
||||
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 {
|
||||
if (isset($data['url']['params'])) {
|
||||
$this->setUrl($data['url']['uri'], $data['url']['params']);
|
||||
} else {
|
||||
$this->setUrl($data['url']['uri']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->setExternalUrl($data['url']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Template
|
||||
extends Wootook_Core_View
|
||||
extends Wootook_Core_Mvc_View_View
|
||||
{
|
||||
protected function _getTemplatePath($file)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Text
|
||||
extends Wootook_Core_View
|
||||
extends Wootook_Core_Mvc_View_View
|
||||
{
|
||||
protected $_content = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function errorCode();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function errorMessage();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
abstract public function errorInfo();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function errorState();
|
||||
}
|
||||
|
|
@ -119,4 +119,40 @@ class Wootook_Core_Database_Adapter_Pdo_Mysql
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Database_Resource
|
||||
extends Wootook_Core_Model
|
||||
extends Wootook_Core_Mvc_Model_Model
|
||||
{
|
||||
protected $_readConnection = null;
|
||||
protected $_writeConnection = null;
|
||||
|
|
@ -34,6 +34,9 @@ abstract class Wootook_Core_Database_Resource
|
|||
return $this->_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) {
|
||||
|
|
|
|||
120
src/application/code/core/Wootook/Core/Database/Sql/Delete.php
Normal file
120
src/application/code/core/Wootook/Core/Database/Sql/Delete.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Database_Sql_Delete
|
||||
extends Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
{
|
||||
const SET = 'SET';
|
||||
const INTO = 'INTO';
|
||||
|
||||
protected function _init($tableName = null)
|
||||
{
|
||||
if ($tableName !== null) {
|
||||
$this->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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
extends Wootook_Core_Database_Sql_DmlQuery
|
||||
{
|
||||
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';
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
142
src/application/code/core/Wootook/Core/Database/Sql/Insert.php
Normal file
142
src/application/code/core/Wootook/Core/Database/Sql/Insert.php
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Database_Sql_Insert
|
||||
extends Wootook_Core_Database_Sql_DmlQuery
|
||||
{
|
||||
const SET = 'SET';
|
||||
const INTO = 'INTO';
|
||||
const SELECT = 'SELECT';
|
||||
|
||||
protected function _init($tableName = null)
|
||||
{
|
||||
if ($tableName !== null) {
|
||||
$this->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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement)
|
||||
{
|
||||
parent::beforeExecute($statement);
|
||||
|
||||
foreach ($this->_params as $paramName => $value) {
|
||||
$statement->bindValue($paramName, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,4 +3,26 @@
|
|||
class Wootook_Core_Database_Sql_Placeholder_Param
|
||||
extends Wootook_Core_Database_Sql_Placeholder_Placeholder
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Database_Sql_Select
|
||||
extends Wootook_Core_Database_Sql_DmlQuery
|
||||
class Wootook_Core_Database_Sql_Select
|
||||
extends Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
{
|
||||
const COLUMNS = 'COLUMNS';
|
||||
const FROM = 'FROM';
|
||||
|
|
@ -25,27 +25,6 @@ abstract class Wootook_Core_Database_Sql_Select
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
* @deprecated
|
||||
*/
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
$this->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) {
|
||||
|
|
|
|||
123
src/application/code/core/Wootook/Core/Database/Sql/Update.php
Normal file
123
src/application/code/core/Wootook/Core/Database/Sql/Update.php
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Database_Sql_Update
|
||||
extends Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
{
|
||||
const SET = 'SET';
|
||||
const INTO = 'INTO';
|
||||
|
||||
protected function _init($tableName = null)
|
||||
{
|
||||
if ($tableName !== null) {
|
||||
$this->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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Helper_Config_ConfigHandler
|
||||
extends Wootook_Core_Model
|
||||
extends Wootook_Core_Mvc_Model_Model
|
||||
implements Iterator, Countable
|
||||
{
|
||||
protected function _initData($filename)
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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.'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
protected function _prepareLayoutMessages($namespace)
|
||||
{
|
||||
$this->getLayout()
|
||||
->getMessagesBlock()
|
||||
->prepareMessages($namespace);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Entity
|
||||
abstract class Wootook_Core_Mvc_Model_Entity
|
||||
extends Wootook_Core_Database_Resource
|
||||
implements Wootook_Core_EntityInterface
|
||||
implements Wootook_Core_Mvc_Model_EntityInterface
|
||||
{
|
||||
protected $_idFieldName = null;
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ abstract class Wootook_Core_Entity
|
|||
->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;
|
||||
$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));
|
||||
}
|
||||
$fields[] = "{$database->quoteIdentifier($field)}=:{$field}";
|
||||
$values[$field] = $value;
|
||||
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);
|
||||
}
|
||||
|
||||
$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.');
|
||||
}
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
UPDATE {$database->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;
|
||||
foreach ($this->getDataMapper()->encode($this, $this->getAllDatas()) as $field => $value) {
|
||||
$insert->set($field, new Wootook_Core_Database_Sql_Placeholder_Param($field, $value));
|
||||
}
|
||||
$tokens[] = ":{$field}";
|
||||
$fields[] = $database->quoteIdentifier($field);
|
||||
$values[$field] = strval($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.');
|
||||
}
|
||||
|
||||
$table = $database->getTable($this->getTableName());
|
||||
$sql =<<<SQL_EOF
|
||||
INSERT INTO {$database->quoteIdentifier($table)} ({$database->quoteIdentifier($this->getIdFieldName())}, $fieldsImploded)
|
||||
VALUES (NULL, {$tokensImploded})
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
$statement->execute($values);
|
||||
|
||||
$id = $database->lastInsertId($table);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
@ -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;
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
* @author Greg
|
||||
*
|
||||
*/
|
||||
interface Wootook_Core_EntityInterface
|
||||
interface Wootook_Core_Mvc_Model_EntityInterface
|
||||
{
|
||||
public function getId();
|
||||
public function setId($id);
|
||||
|
|
@ -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()
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Wootook_Core_View
|
||||
class Wootook_Core_Mvc_View_View
|
||||
extends Wootook_Object
|
||||
{
|
||||
protected $_template = null;
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: Greg
|
||||
* Date: 19/03/12
|
||||
* Time: 18:46
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class Wootook_Empire_Controller_BuildingsController
|
||||
extends Wootook_Player_Mvc_Controller_Registered
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->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('*/*/');
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Galaxy_Position
|
||||
extends Wootook_Core_Entity_SubTable
|
||||
extends Wootook_Core_Mvc_Model_Entity_SubTable
|
||||
{
|
||||
protected function _init()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ class Wootook_Player_Controller_AccountController
|
|||
}
|
||||
|
||||
$this->loadLayout('player.login');
|
||||
$this->_prepareLayoutMessages(Wootook_Player_Model_Entity::SESSION_KEY);
|
||||
$this->renderLayout();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Player_Model_Message
|
||||
extends Wootook_Core_Entity_SubTable
|
||||
extends Wootook_Core_Mvc_Model_Entity_SubTable
|
||||
{
|
||||
protected $_eventObject = 'message';
|
||||
protected $_eventPrefix = 'player.message';
|
||||
|
|
|
|||
|
|
@ -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,13 +56,15 @@ 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)) {
|
||||
} else if (Wootook::getRequest() !== null &&
|
||||
($cookieData = Wootook::getRequest()->getCookie($this->_player->getCookieName())) !== null &&
|
||||
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)
|
||||
'key' => (isset($cookieData['key']) ? $adapter->quote($cookieData['key']) : null)
|
||||
);
|
||||
|
||||
$select
|
||||
|
|
@ -64,13 +77,12 @@ class Wootook_Player_Model_Session
|
|||
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);
|
||||
}
|
||||
|
||||
$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;
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -29,114 +29,111 @@
|
|||
<param name="name">planet/overview</param>
|
||||
<param name="label">Overview</param>
|
||||
<param name="title">Overview</param>
|
||||
<param name="uri">overview.php</param>
|
||||
<param name="uri">player/overview</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<param name="name">planet/buildings</param>
|
||||
<param name="label">Buildings</param>
|
||||
<param name="title">Buildings</param>
|
||||
<param name="uri">buildings.php</param>
|
||||
<param name="uri">empire/buildings</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<param name="name">planet/research-lab</param>
|
||||
<param name="label">Research Lab</param>
|
||||
<param name="title">Research Lab</param>
|
||||
<param name="uri">buildings.php</param>
|
||||
<param name="params"><mode>research</mode></param>
|
||||
<param name="uri">legacies-empire/research-lab</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<param name="name">planet/shipyard</param>
|
||||
<param name="label">Shipyard</param>
|
||||
<param name="title">Shipyard</param>
|
||||
<param name="uri">buildings.php</param>
|
||||
<param name="params"><mode>fleet</mode></param>
|
||||
<param name="uri">legacies-empire/shipyard</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<param name="name">planet/defenses</param>
|
||||
<param name="label">Defenses</param>
|
||||
<param name="title">Defenses</param>
|
||||
<param name="uri">buildings.php</param>
|
||||
<param name="params"><mode>defense</mode></param>
|
||||
<param name="uri">legacies-empire/defense</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">universe/galaxy</param>
|
||||
<param name="label">Check out the Galaxy</param>
|
||||
<param name="title">Check out the Galaxy</param>
|
||||
<param name="uri">galaxy.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">universe/fleet</param>
|
||||
<param name="label">Send a Fleet</param>
|
||||
<param name="title">Send a Fleet</param>
|
||||
<param name="uri">fleet.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">universe/retailer</param>
|
||||
<param name="label">Retailer</param>
|
||||
<param name="title">Retailer</param>
|
||||
<param name="uri">marchand.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">universe/records</param>
|
||||
<param name="label">All Records</param>
|
||||
<param name="title">All Records</param>
|
||||
<param name="uri">records.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">universe/statistics</param>
|
||||
<param name="label">My Stats</param>
|
||||
<param name="title">My Stats</param>
|
||||
<param name="uri">stat.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">universe/search-player</param>
|
||||
<param name="label">Search a Player</param>
|
||||
<param name="title">Search a Player</param>
|
||||
<param name="uri">search.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">universe/empire</param>
|
||||
<param name="label">Empire</param>
|
||||
<param name="title">Empire</param>
|
||||
<param name="uri">imperium.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">account/officers</param>
|
||||
<param name="label">Officers</param>
|
||||
<param name="title">Officers</param>
|
||||
<param name="uri">officier.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">account/alliance</param>
|
||||
<param name="label">My Alliance</param>
|
||||
<param name="title">My Alliance</param>
|
||||
<param name="uri">alliance.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">account/messages</param>
|
||||
<param name="label">My Messages</param>
|
||||
<param name="title">My Messages</param>
|
||||
<param name="uri">messages.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">account/resources</param>
|
||||
<param name="label">My Resources Production</param>
|
||||
<param name="title">My Resources Production</param>
|
||||
<param name="uri">resources.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">account/tech-tree</param>
|
||||
<param name="label">Technology Tree</param>
|
||||
<param name="title">Technology Tree</param>
|
||||
<param name="uri">techtree.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">tools/notes</param>
|
||||
<param name="label">Note Pad</param>
|
||||
<param name="title">Note Pad</param>
|
||||
<param name="uri">notes.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">tools/options</param>
|
||||
<param name="label">Account Options</param>
|
||||
<param name="title">Account Options</param>
|
||||
|
|
@ -146,7 +143,7 @@
|
|||
<param name="name">tools/logout</param>
|
||||
<param name="label">Log Out</param>
|
||||
<param name="title">Log Out</param>
|
||||
<param name="uri">logout.php</param>
|
||||
<param name="uri">player/account/logout</param>
|
||||
</action>
|
||||
<action method="addExternalLink">
|
||||
<param name="name">community/board</param>
|
||||
|
|
@ -154,37 +151,37 @@
|
|||
<param name="title">Forum board</param>
|
||||
<param name="url">http://wootook.org/board/</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">community/chat</param>
|
||||
<param name="label">Chat</param>
|
||||
<param name="title">Chat</param>
|
||||
<param name="uri">chat.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">community/announcement</param>
|
||||
<param name="label">Announcements</param>
|
||||
<param name="title">Announcements</param>
|
||||
<param name="uri">annonce.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">community/multi</param>
|
||||
<param name="label">Declare Multi-account</param>
|
||||
<param name="title">Declare Multi-account</param>
|
||||
<param name="uri">delclare_multi.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">community/rules</param>
|
||||
<param name="label">Rules</param>
|
||||
<param name="title">Rules</param>
|
||||
<param name="uri">rules.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">community/contact</param>
|
||||
<param name="label">Contact Admin</param>
|
||||
<param name="title">Contact Admin</param>
|
||||
<param name="uri">contact.php</param>
|
||||
</action>
|
||||
<action method="addLink">
|
||||
<action method="addStaticLink">
|
||||
<param name="name">community/banned</param>
|
||||
<param name="label">Banned Players</param>
|
||||
<param name="title">Banned Players</param>
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@
|
|||
</reference>
|
||||
|
||||
<reference name="content">
|
||||
<block name="login" type="core/template" template="page/home.phtml" />
|
||||
<block name="login" type="core/template" template="page/html/home.phtml" />
|
||||
</reference>
|
||||
</handle>
|
||||
</layout>
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
</div>
|
||||
<?php else:?>
|
||||
<div class="buy">
|
||||
<p><a class="build" href="<?php echo $this->getStaticUrl('buildings.php', array('building' => $this->getItemId()))?>"><?php echo $this->__('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?></a></p>
|
||||
<p><a class="build" href="<?php echo $this->getUrl('empire/buildings/build', array('id' => $this->getItemId()))?>"><?php echo $this->__('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?></a></p>
|
||||
</div>
|
||||
<?php endif?>
|
||||
<div class="details">
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@
|
|||
</p>
|
||||
<p class="time"><?php echo $this->__('Lasts %s', $this->renderTime($this->getBuildingRemainingTime()))?></p>
|
||||
<div class="cancel">
|
||||
<p><a class="build" href="<?php echo $this->getStaticUrl('buildings.php', array('cancel' => $this->getItem()->getIndex()))?>"><?php echo $this->__('Cancel')?></a></p>
|
||||
<p><a class="build" href="<?php echo $this->getUrl('empire/buildings/cancel', array('id' => $this->getItem()->getIndex()))?>"><?php echo $this->__('Cancel')?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
<div class="item details">
|
||||
<a href="<?php echo $this->getItemInfoUrl()?>" class="image"><img src="<?php echo $this->getItemImageUrl()?>" alt="" width="120" height="120" /></a>
|
||||
<div class="buy">
|
||||
<p><a class="build" href="<?php echo $this->getStaticUrl('buildings.php', array('research' => $this->getItemId(), 'mode' => 'research'))?>"><?php echo $this->__('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?></a></p>
|
||||
<p><a class="build" href="<?php echo $this->getUrl('empire/research-lab/build', array('id' => $this->getItemId()))?>"><?php echo $this->__('Build next level (%s)', $this->renderNumber($this->getNextLevel()))?></a></p>
|
||||
</div>
|
||||
<div class="details">
|
||||
<p><?php echo $this->getDescription()?></p>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@
|
|||
</p>
|
||||
<p class="time"><?php echo $this->__('Lasts %s', $this->renderTime($this->getBuildingRemainingTime()))?></p>
|
||||
<div class="cancel">
|
||||
<p><a class="build" href="<?php echo $this->getStaticUrl('buildings.php', array('cancel' => $this->getItem()->getIndex()))?>"><?php echo $this->__('Cancel')?></a></p>
|
||||
<p><a class="build" href="<?php echo $this->getUrl('empire/research-lab/cancel', array('id' => $this->getItem()->getIndex()))?>"><?php echo $this->__('Cancel')?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<div class="shipyard item-list countable" id="shipyard">
|
||||
<h1><?php echo $this->__('Shipyard')?></h1>
|
||||
<form action="<?php echo $this->getStaticUrl('buildings.php', array('mode' => 'fleet'))?>" method="post" id="shipyard-form">
|
||||
<form action="<?php echo $this->getUrl('empire/shipyard/build')?>" method="post" id="shipyard-form">
|
||||
<?php echo $this->getPartial('item-list.items')->render()?>
|
||||
<input type="submit" value="<?php echo $this->__('Build')?>">
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
<?php echo $this->getLayout()->getMessagesBlock()->renderGroupedHtml()?>
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
<?php echo $this->getLayout()->getMessagesBlock()->renderGroupedHtml()?>
|
||||
<form id="login-form" name="login-form" action="<?php echo $this->getUrl('player/account/login-post')?>" method="post" class="main-form">
|
||||
<fieldset>
|
||||
<legend><?php echo $this->__('Login')?></legend>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
<?php echo $this->getLayout()->getMessagesBlock()->renderGroupedHtml()?>
|
||||
<form id="lost-password-form" name="lost-password-form" action="<?php echo $this->getStaticUrl('player/account/lost-password-post')?>" method="post" class="main-form">
|
||||
<fieldset>
|
||||
<legend><?php echo $this->__('Lost your password?')?></legend>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
<?php echo $this->getLayout()->getMessagesBlock()->renderGroupedHtml()?>
|
||||
<div id="overview" class="overview">
|
||||
<h1><?php echo $this->__('Overview')?></h1>
|
||||
<div class="left">
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
<?php echo $this->getLayout()->getMessagesBlock()->renderGroupedHtml()?>
|
||||
<form id="register-form" name="register-form" action="<?php echo $this->getStaticUrl('player/account/register-post')?>" method="post" class="main-form">
|
||||
<h1><?php echo $this->__('Register')?></h1>
|
||||
<fieldset>
|
||||
|
|
|
|||
|
|
@ -1,182 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.txt
|
||||
* @see http://wootook.org/
|
||||
*
|
||||
* Copyright (c) 2009-Present, Wootook Support Team <http://wootook.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --> 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;
|
||||
}
|
||||
|
||||
|
|
@ -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) ? '-' : "<a href=\"buildings.php?cp={$p['id']}&re=0&planettype={$p['planet_type']}\">{$p[$resource[$i]]}</a>";
|
||||
$data['text'] = ($p[$resource[$i]] == 0) ? '-' : '<a href="' . Wootook::getUrl('empire/buildings', array('cp' => $p['id'], 're' => 0, 'planettype' => $p['planet_type'])) . '">' . $p[$resource[$i]] . '</a>';
|
||||
elseif (in_array($i, $reslist['tech']))
|
||||
$data['text'] = ($user[$resource[$i]] == 0) ? '-' : "<a href=\"buildings.php?mode=research&cp={$p['id']}&re=0&planettype={$p['planet_type']}\">{$user[$resource[$i]]}</a>";
|
||||
$data['text'] = ($p[$resource[$i]] == 0) ? '-' : '<a href="' . Wootook::getUrl('empire/research-lab', array('cp' => $p['id'], 're' => 0, 'planettype' => $p['planet_type'])) . '">' . $p[$resource[$i]] . '</a>';
|
||||
elseif (in_array($i, $reslist['fleet']))
|
||||
$data['text'] = ($p[$resource[$i]] == 0) ? '-' : "<a href=\"buildings.php?mode=fleet&cp={$p['id']}&re=0&planettype={$p['planet_type']}\">{$p[$resource[$i]]}</a>";
|
||||
$data['text'] = ($p[$resource[$i]] == 0) ? '-' : '<a href="' . Wootook::getUrl('empire/shipyard', array('cp' => $p['id'], 're' => 0, 'planettype' => $p['planet_type'])) . '">' . $p[$resource[$i]] . '</a>';
|
||||
elseif (in_array($i, $reslist['defense']))
|
||||
$data['text'] = ($p[$resource[$i]] == 0) ? '-' : "<a href=\"buildings.php?mode=defense&cp={$p['id']}&re=0&planettype={$p['planet_type']}\">{$p[$resource[$i]]}</a>";
|
||||
$data['text'] = ($p[$resource[$i]] == 0) ? '-' : '<a href="' . Wootook::getUrl('empire/defenses', array('cp' => $p['id'], 're' => 0, 'planettype' => $p['planet_type'])) . '">' . $p[$resource[$i]] . '</a>';
|
||||
|
||||
$r[$i] .= parsetemplate($row2, $data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue