Refactored to 2 namespaces: Wootook & Legacies
Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
cfeb6aca6d
commit
ec7e40e1aa
1004 changed files with 4808 additions and 2971 deletions
0
application/code/community/.placeholder
Normal file
0
application/code/community/.placeholder
Normal file
158
application/code/core/Legacies/Empire.php
Normal file
158
application/code/core/Legacies/Empire.php
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
class Legacies_Empire
|
||||
{
|
||||
const TYPE_BUILDING = 'build';
|
||||
const TYPE_BUILDING_MOON = 'build_moon';
|
||||
const TYPE_BUILDING_PLANET = 'build_planet';
|
||||
const TYPE_RESEARCH = 'tech';
|
||||
const TYPE_SHIP = 'fleet';
|
||||
const TYPE_DEFENSE = 'defense';
|
||||
const TYPE_SPECIAL = 'special';
|
||||
const TYPE_OFFICER = 'officier';
|
||||
const TYPE_PRODUCTION = 'prod';
|
||||
const TYPE_FLEET_MISSION = 'mission';
|
||||
|
||||
const RESOURCE_METAL = 'metal';
|
||||
const RESOURCE_CRISTAL = 'cristal';
|
||||
const RESOURCE_DEUTERIUM = 'deuterium';
|
||||
const RESOURCE_ENERGY = 'energy';
|
||||
|
||||
const RESOURCE_MULTIPLIER = 'factor';
|
||||
const RESOURCE_FORMULA = 'formule';
|
||||
const RESOURCE_CLASS = 'class';
|
||||
const BASE_BUILDING_TIME = 'base_time';
|
||||
|
||||
const SHIPS_CONSUMPTION_PRIMARY = 'consumption';
|
||||
const SHIPS_CELERITY_PRIMARY = 'speed';
|
||||
const SHIPS_CONSUMPTION_SECONDARY = 'consumption2';
|
||||
const SHIPS_CELERITY_SECONDARY = 'speed2';
|
||||
const SHIPS_CAPACITY = 'capacity';
|
||||
|
||||
const ID_BUILDING_METAL_MINE = 1;
|
||||
const ID_BUILDING_CRISTAL_MINE = 2;
|
||||
const ID_BUILDING_DEUTERIUM_SYNTHETISER = 3;
|
||||
const ID_BUILDING_SOLAR_PLANT = 4;
|
||||
const ID_BUILDING_FUSION_REACTOR = 12;
|
||||
const ID_BUILDING_ROBOTIC_FACTORY = 14;
|
||||
const ID_BUILDING_NANITE_FACTORY = 15;
|
||||
const ID_BUILDING_SHIPYARD = 21;
|
||||
const ID_BUILDING_METAL_STORAGE = 22;
|
||||
const ID_BUILDING_CRISTAL_STORAGE = 23;
|
||||
const ID_BUILDING_DEUTERIUM_TANK = 24;
|
||||
const ID_BUILDING_RESEARCH_LAB = 31;
|
||||
const ID_BUILDING_TERRAFORMER = 33;
|
||||
const ID_BUILDING_ALLIANCE_DEPOT = 34;
|
||||
const ID_BUILDING_LUNAR_BASE = 41;
|
||||
const ID_BUILDING_SENSOR_PHALANX = 42;
|
||||
const ID_BUILDING_JUMP_GATE = 43;
|
||||
const ID_BUILDING_MISSILE_SILO = 44;
|
||||
|
||||
const ID_RESEARCH_ESPIONAGE_TECHNOLOGY = 106;
|
||||
const ID_RESEARCH_COMPUTER_TECHNOLOGY = 108;
|
||||
const ID_RESEARCH_WEAPON_TECHNOLOGY = 109;
|
||||
const ID_RESEARCH_SHIELDING_TECHNOLOGY = 110;
|
||||
const ID_RESEARCH_ARMOUR_TECHNOLOGY = 111;
|
||||
const ID_RESEARCH_ENERGY_TECHNOLOGY = 113;
|
||||
const ID_RESEARCH_HYPERSPACE_TECHNOLOGY = 114;
|
||||
const ID_RESEARCH_COMBUSTION_DRIVE = 115;
|
||||
const ID_RESEARCH_IMPULSE_DRIVE = 117;
|
||||
const ID_RESEARCH_HYPERSPACE_DRIVE = 118;
|
||||
const ID_RESEARCH_LASER_TECHNOLOGY = 120;
|
||||
const ID_RESEARCH_ION_TECHNOLOGY = 121;
|
||||
const ID_RESEARCH_PLASMA_TECHNOLOGY = 122;
|
||||
const ID_RESEARCH_INTERGALACTIC_RESEARCH_NETWORK = 123;
|
||||
const ID_RESEARCH_EXPEDITION_TECHNOLOGY = 124;
|
||||
const ID_RESEARCH_ASTROPHYSICS = 124;
|
||||
const ID_RESEARCH_GRAVITON_TECHNOLOGY = 199;
|
||||
|
||||
const ID_SHIP_LIGHT_TRANSPORT = 202;
|
||||
const ID_SHIP_LARGE_TRANSPORT = 203;
|
||||
const ID_SHIP_LIGHT_FIGHTER = 204;
|
||||
const ID_SHIP_HEAVY_FIGHTER = 205;
|
||||
const ID_SHIP_CRUISER = 206;
|
||||
const ID_SHIP_BATTLESHIP = 207;
|
||||
const ID_SHIP_COLONY_SHIP = 208;
|
||||
const ID_SHIP_RECYCLER = 209;
|
||||
const ID_SHIP_SPY_DRONE = 210;
|
||||
const ID_SHIP_BOMBER = 211;
|
||||
const ID_SHIP_SOLAR_SATELLITE = 212;
|
||||
const ID_SHIP_DESTRUCTOR = 213;
|
||||
const ID_SHIP_DEATH_STAR = 214;
|
||||
const ID_SHIP_BATTLECRUISER = 215;
|
||||
const ID_SHIP_SUPERNOVA = 216;
|
||||
|
||||
const ID_DEFENSE_ROCKET_LAUNCHER = 401;
|
||||
const ID_DEFENSE_LIGHT_LASER = 402;
|
||||
const ID_DEFENSE_HEAVY_LASER = 403;
|
||||
const ID_DEFENSE_ION_CANNON = 404;
|
||||
const ID_DEFENSE_GAUSS_CANNON = 405;
|
||||
const ID_DEFENSE_PLASMA_TURRET = 406;
|
||||
const ID_DEFENSE_SMALL_SHIELD_DOME = 407;
|
||||
const ID_DEFENSE_LARGE_SHIELD_DOME = 408;
|
||||
|
||||
const ID_SPECIAL_ANTIBALLISTIC_MISSILE = 502;
|
||||
const ID_SPECIAL_INTERPLANETARY_MISSILE = 503;
|
||||
|
||||
const ID_COMBAT_SHIELDS = 'shield';
|
||||
const ID_COMBAT_FIREPOWER = 'attack';
|
||||
const ID_COMBAT_RAPID_FIRE = 'sd';
|
||||
|
||||
const ID_MISSION_ATTACK = 1;
|
||||
const ID_MISSION_GROUP_ATTACK = 2;
|
||||
const ID_MISSION_TRANSPORT = 3;
|
||||
const ID_MISSION_STATION = 4;
|
||||
const ID_MISSION_STATION_ALLY = 5;
|
||||
const ID_MISSION_SPY = 6;
|
||||
const ID_MISSION_SETTLE_COLONY = 7;
|
||||
const ID_MISSION_RECYCLE = 8;
|
||||
const ID_MISSION_DESTROY = 9;
|
||||
const ID_MISSION_MISSILES = 10;
|
||||
const ID_MISSION_EXPEDITION = 15;
|
||||
|
||||
public static function getFieldName($id)
|
||||
{
|
||||
$fieldsAlias = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
if (!isset($fieldsAlias[$id])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $fieldsAlias[$id];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Block_Planet_ResearchLab
|
||||
extends Wootook_Empire_Block_Planet_BuilderAbstract
|
||||
{
|
||||
protected $_planet = null;
|
||||
|
||||
public function setPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_planet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlanet()
|
||||
{
|
||||
if ($this->_planet === null) {
|
||||
$this->_planet = Wootook_Empire_Model_User::getSingleton()
|
||||
->getCurrentPlanet()
|
||||
;
|
||||
}
|
||||
return $this->_planet;
|
||||
}
|
||||
|
||||
public function _initChildBlocks()
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
|
||||
/** @var Wootook_Core_Block_Concat $parentBlock */
|
||||
$parentBlock = $this->getLayout()->getBlock('item-list.items');
|
||||
foreach ($types->getData(Legacies_Empire::TYPE_RESEARCH) as $itemId) {
|
||||
if (!$this->getPlanet()->getResearchLab()->checkAvailability($itemId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$block = $this->getItemBlock($itemId);
|
||||
$parentBlock->setPartial($block->getName(), $block);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Block_Planet_ResearchLab_Item
|
||||
extends Wootook_Empire_Block_Planet_Builder_ItemAbstract
|
||||
{
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->getUser()->getElement($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($level)
|
||||
{
|
||||
return $this->getPlanet()->getResearchLab()->getResourcesNeeded($this->getItemId(), $level);
|
||||
}
|
||||
|
||||
public function getQueuedLevel()
|
||||
{
|
||||
return $this->getPlanet()->getResearchLab()->getResearchLevelQueued($this->getItemId());
|
||||
}
|
||||
|
||||
public function getBuildingTime($level)
|
||||
{
|
||||
return $this->getPlanet()->getResearchLab()->getResearchTime($this->getItemId(), $level);
|
||||
}
|
||||
|
||||
public function getResourcesConfigForLevel($level)
|
||||
{
|
||||
$resources = $this->getResourcesNeeded($level);
|
||||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
||||
$amount = $this->getPlanet()->getResourceAmount($resourceId);
|
||||
if (Math::comp($amount, $resourceValue) < 0) {
|
||||
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
|
||||
} else {
|
||||
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
|
||||
}
|
||||
}
|
||||
return $resourceConfig;
|
||||
}
|
||||
|
||||
public function getResourcesConfigForNextLevel()
|
||||
{
|
||||
return $this->getResourcesConfigForLevel($this->getNextLevel());
|
||||
}
|
||||
|
||||
public function getBuildingTimeForNextLevel()
|
||||
{
|
||||
return $this->getBuildingTime($this->getNextLevel());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Block_Planet_ResearchLab_Queue
|
||||
extends Wootook_Empire_Block_Planet_Builder_QueueAbstract
|
||||
{
|
||||
public function getQueue()
|
||||
{
|
||||
return $this->getPlanet()->getResearchLab()->getBuilder();
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->getQueue()->count() == 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Block_Planet_ResearchLab_Queue_Item
|
||||
extends Wootook_Empire_Block_Planet_Builder_Queue_ItemAbstract
|
||||
{
|
||||
protected $_itemIdField = 'research_id';
|
||||
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->getUser()->getElement($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($level)
|
||||
{
|
||||
return $this->getPlanet()->getResearchLab()->getResourcesNeeded($this->getItemId(), $this->getQueuedLevel() + 1);
|
||||
}
|
||||
|
||||
public function getItemQueuedLevel()
|
||||
{
|
||||
return $this->getItem()->getData('level');
|
||||
}
|
||||
|
||||
public function getQueuedLevel()
|
||||
{
|
||||
return $this->getPlanet()->getResearchLab()->getResearchLevelQueued($this->getItemId());
|
||||
}
|
||||
|
||||
public function getBuildingTime($level)
|
||||
{
|
||||
return $this->getPlanet()->getResearchLab()->getBuildingTime($this->getItemId(), $level);
|
||||
}
|
||||
|
||||
public function getResourcesConfigForLevel($level)
|
||||
{
|
||||
$resources = $this->getResourcesNeeded($level);
|
||||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
||||
$amount = $this->getPlanet()->getResourceAmount($resourceId);
|
||||
if (Math::comp($amount, $resourceValue) < 0) {
|
||||
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
|
||||
} else {
|
||||
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
|
||||
}
|
||||
}
|
||||
return $resourceConfig;
|
||||
}
|
||||
|
||||
public function getResourcesConfigForNextLevel()
|
||||
{
|
||||
return $this->getResourcesConfigForLevel($this->getNextLevel());
|
||||
}
|
||||
|
||||
public function getBuildingTimeForNextLevel()
|
||||
{
|
||||
return $this->getBuildingTime($this->getNextLevel());
|
||||
}
|
||||
}
|
||||
115
application/code/core/Legacies/Empire/Block/Planet/Shipyard.php
Normal file
115
application/code/core/Legacies/Empire/Block/Planet/Shipyard.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Block_Planet_Shipyard
|
||||
extends Wootook_Empire_Block_Planet_BuilderAbstract
|
||||
{
|
||||
protected $_planet = null;
|
||||
protected $_type = Legacies_Empire::TYPE_SHIP;
|
||||
|
||||
protected $_allowedTypes = array(
|
||||
Legacies_Empire::TYPE_SHIP,
|
||||
Legacies_Empire::TYPE_DEFENSE
|
||||
);
|
||||
|
||||
public function setPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_planet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlanet()
|
||||
{
|
||||
if ($this->_planet === null) {
|
||||
$this->_planet = Wootook_Empire_Model_User::getSingleton()
|
||||
->getCurrentPlanet()
|
||||
;
|
||||
}
|
||||
return $this->_planet;
|
||||
}
|
||||
|
||||
public function setAllowedTypes($types)
|
||||
{
|
||||
if (is_array($types)) {
|
||||
$this->_allowedTypes = $types;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addAllowedType($type)
|
||||
{
|
||||
if (!in_array($type, $this->_allowedTypes)) {
|
||||
$this->_allowedTypes[] = $type;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAllowedTypes()
|
||||
{
|
||||
return $this->_allowedTypes;
|
||||
}
|
||||
|
||||
public function setType($type)
|
||||
{
|
||||
if (in_array($type, $this->_allowedTypes)) {
|
||||
$this->_type = $type;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
public function _initChildBlocks()
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
|
||||
/** @var Wootook_Core_Block_Concat $parentBlock */
|
||||
$parentBlock = $this->getLayout()->getBlock('item-list.items');
|
||||
foreach ($types->getData($this->getType()) as $itemId) {
|
||||
if (!$this->getPlanet()->getShipyard()->checkAvailability($itemId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$block = $this->getItemBlock($itemId);
|
||||
$parentBlock->setPartial($block->getName(), $block);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Block_Planet_Shipyard_Item
|
||||
extends Wootook_Empire_Block_Planet_Builder_ItemAbstract
|
||||
{
|
||||
public function getQty()
|
||||
{
|
||||
return $this->getPlanet()->getElement($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($qty)
|
||||
{
|
||||
return $this->getPlanet()->getShipyard()->getResourcesNeeded($this->getItemId(), $qty);
|
||||
}
|
||||
|
||||
public function getBuildingTime($qty)
|
||||
{
|
||||
return $this->getPlanet()->getShipyard()->getBuildingTime($this->getItemId(), $qty);
|
||||
}
|
||||
|
||||
public function getMaximumBuildableElementsCount()
|
||||
{
|
||||
return $this->getPlanet()->getShipyard()->getMaximumBuildableElementsCount($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesConfigForQty($qty)
|
||||
{
|
||||
$resources = $this->getResourcesNeeded($qty);
|
||||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
||||
$amount = $this->getPlanet()->getResourceAmount($resourceId);
|
||||
if (Math::comp($amount, $resourceValue) < 0) {
|
||||
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
|
||||
} else {
|
||||
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
|
||||
}
|
||||
}
|
||||
return $resourceConfig;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Block_Planet_Shipyard_Queue
|
||||
extends Wootook_Empire_Block_Planet_Builder_QueueAbstract
|
||||
{
|
||||
public function getQueue()
|
||||
{
|
||||
return $this->getPlanet()->getShipyard()->getBuilder();
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->getQueue()->count() == 0;
|
||||
}
|
||||
}
|
||||
37
application/code/core/Legacies/Empire/Exception.php
Normal file
37
application/code/core/Legacies/Empire/Exception.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
interface Legacies_Empire_Exception {}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_CristalMine
|
||||
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
public function getProductionRatios($level, $produtionRatio, $planet, $user)
|
||||
{
|
||||
return array(
|
||||
Legacies_Empire::RESOURCE_CRISTAL => 10 + 20 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
|
||||
Legacies_Empire::RESOURCE_ENERGY => -10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_DeuteriumSynthetiser
|
||||
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
public function getProductionRatios($level, $produtionRatio, $planet, $user)
|
||||
{
|
||||
return array(
|
||||
Legacies_Empire::RESOURCE_DEUTERIUM => 10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
|
||||
Legacies_Empire::RESOURCE_ENERGY => -30 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_FusionReactor
|
||||
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
public function getProductionRatios($level, $produtionRatio, $planet, $user)
|
||||
{
|
||||
return array(
|
||||
Legacies_Empire::RESOURCE_DEUTERIUM => -10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
|
||||
Legacies_Empire::RESOURCE_ENERGY => 50 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
class Legacies_Empire_Model_Planet_Building_MetalMine
|
||||
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
public function getProductionRatios($level, $produtionRatio, $planet, $user)
|
||||
{
|
||||
return array(
|
||||
Legacies_Empire::RESOURCE_METAL => 20 + 30 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
|
||||
Legacies_Empire::RESOURCE_ENERGY => -10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_NaniteFactory
|
||||
implements Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
public static function buildingTimeListener($event)
|
||||
{
|
||||
$planet = $event->getData('planet');
|
||||
|
||||
if (!$planet->getId() || ($level = $planet->getElement(Legacies_Empire::ID_BUILDING_NANITE_FACTORY)) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$time = $event->getData('time');
|
||||
|
||||
$speedFactor = pow(2, $level);
|
||||
$event->setData('time', $time / $speedFactor);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,269 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Research lab building, manages researches queue on each planet
|
||||
*
|
||||
* @access public
|
||||
* @category Empire
|
||||
* @category Planet
|
||||
* @package Legacies
|
||||
* @subpackage Legacies_Empire
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
implements Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
private $_eventPrefix = 'planet.laboratory.';
|
||||
|
||||
/**
|
||||
* Planet instance
|
||||
* @var Legacies_Empire_Model_Planet
|
||||
*/
|
||||
protected $_currentPlanet = null;
|
||||
|
||||
/**
|
||||
* User instance
|
||||
* @var Legacies_Empire_Model_User
|
||||
*/
|
||||
protected $_currentUser = null;
|
||||
|
||||
/**
|
||||
* construction queue
|
||||
* @var array
|
||||
*/
|
||||
protected $_builder = null;
|
||||
|
||||
/**
|
||||
* Multiton instances
|
||||
* @var array
|
||||
*/
|
||||
protected static $_instances = array();
|
||||
|
||||
/**
|
||||
* Multiton factory. Retruns the planet's research lab instance or created it if
|
||||
* it doesn't yet exist.
|
||||
*
|
||||
* @param Legacies_Empire_Model_Planet $currentPlanet
|
||||
* @param Legacies_Empire_Model_User $currentUser
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public static function factory($currentPlanet, $currentUser)
|
||||
{
|
||||
if ($currentPlanet->getId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset(self::$_instances[$currentPlanet->getId()])) {
|
||||
self::$_instances[$currentPlanet->getId()] = new self($currentPlanet, $currentUser);
|
||||
}
|
||||
return self::$_instances[$currentPlanet->getId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Used for specific usage, use the factory for standard usage.
|
||||
*
|
||||
* @see Legacies_Empire_Model_Planet_Building_ResearchLab::factory()
|
||||
*
|
||||
* @param Legacies_Empire_Model_Planet $currentPlanet
|
||||
* @param Legacies_Empire_Model_User $currentUser
|
||||
*/
|
||||
public function __construct($currentPlanet, $currentUser)
|
||||
{
|
||||
$this->_currentPlanet = $currentPlanet;
|
||||
$this->_currentUser = $currentUser;
|
||||
|
||||
$this->_builder = new Legacies_Empire_Model_Planet_Building_ResearchLab_Builder($currentPlanet, $currentUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->_currentPlanet->save();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append items to build to the construction list
|
||||
*
|
||||
* @param int $researchId
|
||||
* @param int|string $level
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function appendQueue($researchId, $destroy = false, $time = null)
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = Wootook::now();
|
||||
}
|
||||
|
||||
if ($destroy === false) {
|
||||
$level = $this->_currentUser->getElement($researchId) + 1;
|
||||
} else {
|
||||
$level = max($this->_currentUser->getElement($researchId) - 1, 0);
|
||||
}
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'append-queue.before', array(
|
||||
'research_id' => $researchId,
|
||||
'level' => &$level,
|
||||
'time' => &$time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
$this->_builder->appendQueue($researchId, $level, $time);
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'append-queue.after', array(
|
||||
'research_id' => $researchId,
|
||||
'level' => $level,
|
||||
'time' => $time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function updateQueue($time = null)
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = Wootook::now();
|
||||
}
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'update-queue.before', array(
|
||||
'time' => &$time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
$this->_builder->updateQueue($time);
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'update-queue.after', array(
|
||||
'time' => $time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the construction queue
|
||||
* @see Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBuilder()
|
||||
{
|
||||
return $this->_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a ship or defense type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $resourceId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($researchId)
|
||||
{
|
||||
try {
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'check-availability', array(
|
||||
'research_id' => $researchId,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
} catch (Legacies_Core_Event_Break $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_builder->checkAvailability($researchId);
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($researchId, $level)
|
||||
{
|
||||
return $this->_builder->getResourcesNeeded($researchId, $level);
|
||||
}
|
||||
|
||||
public function getResearchTime($researchId, $level)
|
||||
{
|
||||
$this->_builder->getBuildingTime($researchId, $level);
|
||||
}
|
||||
|
||||
public function getResearchLevelQueued($researchId)
|
||||
{
|
||||
$level = $this->_currentUser->getElement($researchId);
|
||||
foreach ($this->_builder as $item) {
|
||||
if ($item->getData('research_id') != $researchId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$level = $item->getData('level');
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
|
||||
public static function planetUpdateListener($eventData)
|
||||
{
|
||||
if (isset($eventData['planet'])) {
|
||||
$planet = $eventData['planet'];
|
||||
|
||||
if ($planet === null || !$planet instanceof Legacies_Empire_Model_Planet || !$planet->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$time = null;
|
||||
if (isset($eventData['time'])) {
|
||||
$time = $eventData['time'];
|
||||
}
|
||||
|
||||
$shipyard = $planet->getResearchLab();
|
||||
if ($shipyard !== null) {
|
||||
$shipyard->updateQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
|
||||
extends Wootook_Empire_Model_BuilderAbstract
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_maxLength = 0;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_unserializeQueue($this->_currentUser->getData('b_laboratory_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $buildingId
|
||||
* @param int $level
|
||||
* @param int $time
|
||||
*/
|
||||
protected function _initItem(Array $params)
|
||||
{
|
||||
if (!isset($params['technology_id']) || !isset($params['level'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$technologyId = $params['technology_id'];
|
||||
$level = $params['level'];
|
||||
if (!isset($params['created_at'])) {
|
||||
$createdAt = time();
|
||||
} else {
|
||||
$createdAt = $params['created_at'];
|
||||
}
|
||||
if (!isset($params['updated_at'])) {
|
||||
$updatedAt = $createdAt;
|
||||
} else {
|
||||
$updatedAt = $params['updated_at'];
|
||||
}
|
||||
|
||||
return new Legacies_Empire_Model_Planet_Building_ResearchLab_Item(array(
|
||||
'technology_id' => $technologyId,
|
||||
'level' => $level,
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $updatedAt
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a technology type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $technologyId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($technologyId)
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
|
||||
if (!$types->is($technologyId, Legacies_Empire::TYPE_RESEARCH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::checkAvailability($technologyId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time needed to build $level of $technologyId
|
||||
*
|
||||
* @param int $technologyId
|
||||
* @param int $level
|
||||
*/
|
||||
public function getBuildingTime($technologyId, $level)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
$gameConfig = Wootook_Core_Model_Config::getSingleton();
|
||||
|
||||
Math::setPrecision(50);
|
||||
|
||||
// FIXME: Resource dependency
|
||||
$totalCost = Math::mul(Math::add($prices[$technologyId][Legacies_Empire::RESOURCE_METAL], $prices[$technologyId][Legacies_Empire::RESOURCE_CRISTAL]), $level);
|
||||
$speedFactor = $gameConfig->getData('game_speed');
|
||||
|
||||
// FIXME: Building & Technology dependency
|
||||
$extraLaboratoriesLevels = 0;
|
||||
$researchNetworkLevel = $this->_currentUser->getElement(Legacies_Empire::ID_RESEARCH_INTERGALACTIC_RESEARCH_NETWORK);
|
||||
if ($researchNetworkLevel > 0) {
|
||||
$laboratoriesLevels = array();
|
||||
foreach ($this->_currentUser->getPlanetCollection() as $planet) {
|
||||
if ($this->_currentPlanet->getId() == $planet->getId()) {
|
||||
continue;
|
||||
}
|
||||
$level = $planet->getElement(Legacies_Empire::ID_BUILDING_RESEARCH_LAB);
|
||||
if ($level > 0) {
|
||||
$laboratoriesLevels[] = (int) $level;
|
||||
}
|
||||
}
|
||||
sort($laboratoriesLevels, SORT_NUMERIC);
|
||||
$extraLaboratoriesLevels = array_sum(array_slice(array_reverse($laboratoriesLevels), 0, $researchNetworkLevel));
|
||||
}
|
||||
|
||||
$laboratorySpeedup = Math::div($totalCost, ($this->_currentPlanet->getElement(Legacies_Empire::ID_BUILDING_RESEARCH_LAB) + 1 + $extraLaboratoriesLevels));
|
||||
|
||||
Math::setPrecision();
|
||||
|
||||
$baseTime = ($totalCost / $speedFactor) * $laboratorySpeedup;
|
||||
|
||||
return (int) Math::floor($baseTime * 3600);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see Legacies_Empire_Model_BuilderAbstract::getResourcesNeeded()
|
||||
*/
|
||||
public function getResourcesNeeded($technologyId, $level)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
$resources = Wootook_Empire_Model_Game_Resources::getSingleton();
|
||||
|
||||
if (!isset($prices[$technologyId])) {
|
||||
return array();
|
||||
}
|
||||
$resourcesNeeded = array();
|
||||
foreach ($resources as $resourceId => $resourceConfig) {
|
||||
if (!isset($prices[$technologyId][$resourceId])) {
|
||||
continue;
|
||||
}
|
||||
if (Math::isPositive($prices[$technologyId][$resourceId])) {
|
||||
$firstLevelCost = $prices[$technologyId][$resourceId];
|
||||
$partialLevelCost = Math::mul($firstLevelCost, Math::pow($prices[$technologyId][Legacies_Empire::RESOURCE_MULTIPLIER], $level));
|
||||
$resourcesNeeded[$resourceId] = Math::sub($partialLevelCost, $firstLevelCost);
|
||||
}
|
||||
}
|
||||
|
||||
return $resourcesNeeded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function updateQueue($time)
|
||||
{
|
||||
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
$elapsedTime = $time - $this->_currentUser->getData('b_laboratory');
|
||||
|
||||
foreach ($this->getQueue() as $element) {
|
||||
$technologyId = $element->getData('research_id');
|
||||
$level = $element->getData('level');
|
||||
$buildTime = $this->getBuildingTime($technologyId, $level);
|
||||
|
||||
if ($elapsedTime >= $buildTime) {
|
||||
$this->_currentUser[$fields[$technologyId]] = Math::add($this->_currentUser[$fields[$technologyId]], $level);
|
||||
$elapsedTime -= $buildTime;
|
||||
$this->dequeue($element);
|
||||
continue;
|
||||
}
|
||||
|
||||
$timeRatio = $elapsedTime / $buildTime;
|
||||
$itemsBuilt = Math::mul($timeRatio, $level);
|
||||
|
||||
$element->setData('updated_at', $time);
|
||||
$element->setData('level', Math::sub($level, $itemsBuilt));
|
||||
$this->_currentUser->setData($fields[$technologyId], Math::add($this->_currentUser->getData($fields[$technologyId]), $itemsBuilt));
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_currentUser->setData('b_laboratory_id', $this->serialize());
|
||||
$this->_currentUser->setData('b_laboratory', $time);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append items to build to the construction list
|
||||
*
|
||||
* @param int $technologyId
|
||||
* @param int|string $level
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function appendQueue($technologyId, $level, $time)
|
||||
{
|
||||
if ($this->_maxLength > 0 && $this->count() >= $this->_maxLength) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!Math::isPositive($level)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
if (!$types->is($technologyId, Legacies_Empire::TYPE_RESEARCH)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!$this->checkAvailability($technologyId)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$resourcesNeeded = $this->getResourcesNeeded($technologyId, $level);
|
||||
$remainingAmounts = $this->_calculateResourceRemainingAmounts($resourcesNeeded);
|
||||
if ($remainingAmounts === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->enqueue($technologyId, $level, $time);
|
||||
$this->_currentUser->setData('b_laboratory_id', $this->serialize());
|
||||
|
||||
foreach ($remainingAmounts as $resourceId => $resourceAmount) {
|
||||
$this->_currentPlanet[$resourceId] = $resourceAmount;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_ResearchLab_Item
|
||||
extends Wootook_Empire_Model_Builder_Item
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_RoboticFactory
|
||||
implements Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
public static function buildingTimeListener($event)
|
||||
{
|
||||
$planet = $event->getData('planet');
|
||||
|
||||
if (!$planet->getId() || ($level = $planet->getElement(Legacies_Empire::ID_BUILDING_ROBOTIC_FACTORY)) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$time = $event->getData('time');
|
||||
|
||||
$speedFactor = 1 + $level;
|
||||
$event->setData('time', $time / $speedFactor);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,285 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Shipyard building, manages ship and defenses building queue on each planet
|
||||
*
|
||||
* @access public
|
||||
* @category Empire
|
||||
* @category Planet
|
||||
* @package Legacies
|
||||
* @subpackage Legacies_Empire
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_Shipyard
|
||||
implements Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
private $_eventPrefix = 'planet.shipyard.';
|
||||
|
||||
/**
|
||||
* Planet instance
|
||||
* @var Legacies_Empire_Model_Planet
|
||||
*/
|
||||
protected $_currentPlanet = null;
|
||||
|
||||
/**
|
||||
* User instance
|
||||
* @var Legacies_Empire_Model_User
|
||||
*/
|
||||
protected $_currentUser = null;
|
||||
|
||||
/**
|
||||
* construction queue
|
||||
* @var array
|
||||
*/
|
||||
protected $_builder = null;
|
||||
|
||||
/**
|
||||
* Resource list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_resourcesTypes = array(
|
||||
Legacies_Empire::RESOURCE_METAL,
|
||||
Legacies_Empire::RESOURCE_CRISTAL,
|
||||
Legacies_Empire::RESOURCE_DEUTERIUM,
|
||||
Legacies_Empire::RESOURCE_ENERGY
|
||||
);
|
||||
|
||||
/**
|
||||
* Multiton instances
|
||||
* @var array
|
||||
*/
|
||||
protected static $_instances = array();
|
||||
|
||||
/**
|
||||
* Multiton factory. Retruns the planet's shipyard instance or created it if
|
||||
* it doesn't yet exist.
|
||||
*
|
||||
* @param Legacies_Empire_Model_Planet $currentPlanet
|
||||
* @param Legacies_Empire_Model_User $currentUser
|
||||
* @return Legacies_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public static function factory($currentPlanet, $currentUser)
|
||||
{
|
||||
if ($currentPlanet->getId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset(self::$_instances[$currentPlanet->getId()])) {
|
||||
self::$_instances[$currentPlanet->getId()] = new self($currentPlanet, $currentUser);
|
||||
}
|
||||
return self::$_instances[$currentPlanet->getId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Used for specific usage, use the factory for standard usage.
|
||||
*
|
||||
* @see Legacies_Empire_Model_Planet_Building_Shipyard::factory()
|
||||
*
|
||||
* @param Legacies_Empire_Model_Planet $currentPlanet
|
||||
* @param Legacies_Empire_Model_User $currentUser
|
||||
*/
|
||||
public function __construct($currentPlanet, $currentUser)
|
||||
{
|
||||
$this->_currentPlanet = $currentPlanet;
|
||||
$this->_currentUser = $currentUser;
|
||||
|
||||
$this->_builder = new Legacies_Empire_Model_Planet_Building_Shipyard_Builder($currentPlanet, $currentUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp at the instance creation.
|
||||
*
|
||||
* @deprecated
|
||||
* @return int
|
||||
*/
|
||||
protected function _now()
|
||||
{
|
||||
return Wootook::now();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return Legacies_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->_currentPlanet->save();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append items to build to the construction list
|
||||
*
|
||||
* @param int $shipId
|
||||
* @param int|string $qty
|
||||
* @return Legacies_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public function appendQueue($shipId, $qty, $time = null)
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = Wootook::now();
|
||||
}
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'append-queue.before', array(
|
||||
'ship_id' => $shipId,
|
||||
'qty' => &$qty,
|
||||
'time' => &$time,
|
||||
'shipyard' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
$this->_builder->appendQueue($shipId, $qty, $time);
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'append-queue.before', array(
|
||||
'ship_id' => $shipId,
|
||||
'qty' => $qty,
|
||||
'time' => $time,
|
||||
'shipyard' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
* @return Legacies_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public function updateQueue($time = null)
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = Wootook::now();
|
||||
}
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'update-queue.before', array(
|
||||
'time' => &$time,
|
||||
'shipyard' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
$this->_builder->updateQueue($time);
|
||||
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'update-queue.after', array(
|
||||
'time' => $time,
|
||||
'shipyard' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the construction queue
|
||||
* @see Legacies_Empire_Model_Planet_Building_Shipyard_Builder
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBuilder()
|
||||
{
|
||||
return $this->_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a ship or defense type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $shipId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($shipId)
|
||||
{
|
||||
try {
|
||||
// Dispatch event
|
||||
Wootook::dispatchEvent($this->_eventPrefix . 'check-availability', array(
|
||||
'ship_id' => $shipId,
|
||||
'shipyard' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
} catch (Legacies_Core_Event_Break $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_builder->checkAvailability($shipId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum quantity of elements that are possible to build on
|
||||
* the current planet.
|
||||
*
|
||||
* @param int $shipId
|
||||
* @return int|string
|
||||
*/
|
||||
public function getMaximumBuildableElementsCount($shipId)
|
||||
{
|
||||
return $this->_builder->getMaximumBuildableElementsCount($shipId);
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($shipId, $qty)
|
||||
{
|
||||
return $this->_builder->getResourcesNeeded($shipId, $qty);
|
||||
}
|
||||
|
||||
public function getBuildingTime($shipId, $qty)
|
||||
{
|
||||
return $this->_builder->getBuildingTime($shipId, $qty);
|
||||
}
|
||||
|
||||
public static function planetUpdateListener($eventData)
|
||||
{
|
||||
if (isset($eventData['planet'])) {
|
||||
$planet = $eventData['planet'];
|
||||
|
||||
if ($planet === null || !$planet instanceof Legacies_Empire_Model_Planet || !$planet->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$time = null;
|
||||
if (isset($eventData['time'])) {
|
||||
$time = $eventData['time'];
|
||||
}
|
||||
|
||||
$shipyard = self::factory($planet, $planet->getUser());
|
||||
if ($shipyard !== null) {
|
||||
$shipyard->updateQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,337 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
|
||||
extends Wootook_Empire_Model_BuilderAbstract
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_maxLength = 0;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_unserializeQueue($this->_currentPlanet->getData('b_hangar_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $buildingId
|
||||
* @param int $qty
|
||||
* @param int $time
|
||||
*/
|
||||
protected function _initItem(Array $params)
|
||||
{
|
||||
if (!isset($params['ship_id']) || !isset($params['qty'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$shipId = $params['ship_id'];
|
||||
$qty = $params['qty'];
|
||||
if (!isset($params['created_at'])) {
|
||||
$createdAt = time();
|
||||
} else {
|
||||
$createdAt = $params['created_at'];
|
||||
}
|
||||
if (!isset($params['updated_at'])) {
|
||||
$updatedAt = $createdAt;
|
||||
} else {
|
||||
$updatedAt = $params['updated_at'];
|
||||
}
|
||||
|
||||
return new Legacies_Empire_Model_Planet_Building_Shipyard_Item(array(
|
||||
'ship_id' => $shipId,
|
||||
'qty' => $qty,
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $updatedAt
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a ship or defense type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $shipId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($shipId)
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
|
||||
if (!$types->is($shipId, Legacies_Empire::TYPE_SHIP) && !$types->is($shipId, Legacies_Empire::TYPE_DEFENSE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::checkAvailability($shipId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum quantity of elements that are possible to build on
|
||||
* the current planet.
|
||||
*
|
||||
* @param int $shipId
|
||||
* @return int|string
|
||||
*/
|
||||
public function getMaximumBuildableElementsCount($shipId)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
$resources = Wootook_Empire_Model_Game_Resources::getSingleton();
|
||||
|
||||
$qty = 0;
|
||||
foreach ($resources as $resourceId => $_) {
|
||||
if (isset($prices[$shipId]) && isset($prices[$shipId][$resourceId]) && Math::comp($prices[$shipId][$resourceId], 0) > 0) {
|
||||
$maxQty = Math::floor(Math::div($this->_currentPlanet->getData($resourceId), $prices[$shipId][$resourceId]));
|
||||
|
||||
if ($maxQty == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($qty == 0 || Math::comp($maxQty, $qty) < 0) {
|
||||
$qty = $maxQty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($qty == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$limitedElementsQty = array(
|
||||
Legacies_Empire::ID_DEFENSE_SMALL_SHIELD_DOME => array(
|
||||
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_SMALL_SHIELD_DOME]],
|
||||
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_SMALL_SHIELD_DOME]],
|
||||
'limit' => 1
|
||||
),
|
||||
Legacies_Empire::ID_DEFENSE_LARGE_SHIELD_DOME => array(
|
||||
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_LARGE_SHIELD_DOME]],
|
||||
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_LARGE_SHIELD_DOME]],
|
||||
'limit' => 1
|
||||
),
|
||||
Legacies_Empire::ID_SPECIAL_ANTIBALLISTIC_MISSILE => array(
|
||||
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_ANTIBALLISTIC_MISSILE]],
|
||||
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_ANTIBALLISTIC_MISSILE]],
|
||||
'limit' => $this->_currentPlanet[$fields[Legacies_Empire::ID_BUILDING_MISSILE_SILO]] * 10
|
||||
),
|
||||
Legacies_Empire::ID_SPECIAL_INTERPLANETARY_MISSILE => array(
|
||||
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_INTERPLANETARY_MISSILE]],
|
||||
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_INTERPLANETARY_MISSILE]],
|
||||
'limit' => $this->_currentPlanet[$fields[Legacies_Empire::ID_BUILDING_MISSILE_SILO]] * 5
|
||||
)
|
||||
);
|
||||
|
||||
if (in_array($shipId, array_keys($limitedElementsQty))) {
|
||||
foreach ($this->getQueue() as $element) {
|
||||
if ($element['ship_id'] != $shipId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$limitedElementsQty[$shipId]['requested'] = Math::add($limitedElementsQty[$shipId]['requested'], $element['qty']);
|
||||
if (Math::comp($limitedElementsQty[$shipId]['requested'], $limitedElementsQty[$shipId]['limit']) >= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (Math::comp($limitedElementsQty[$shipId]['current'], $limitedElementsQty[$shipId]['limit']) >= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (Math::comp($qty, $limitedElementsQty[$shipId]['limit']) >= 0) {
|
||||
return $limitedElementsQty[$shipId]['limit'];
|
||||
}
|
||||
}
|
||||
|
||||
return $qty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time needed to build $qty of $shipId
|
||||
*
|
||||
* @param int $shipId
|
||||
* @param int $qty
|
||||
*/
|
||||
public function getBuildingTime($shipId, $qty)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
$gameConfig = Wootook_Core_Model_Config::getSingleton();
|
||||
|
||||
Math::setPrecision(50);
|
||||
$buildingTime = Math::mul($prices[$shipId][Legacies_Empire::BASE_BUILDING_TIME], $qty);
|
||||
|
||||
$speedFactor = $gameConfig->getData('game_speed');
|
||||
$baseTime = Math::div($buildingTime, $speedFactor);
|
||||
|
||||
Math::setPrecision();
|
||||
|
||||
$event = Wootook::dispatchEvent('planet.shipyard.building-time', array(
|
||||
'time' => $baseTime,
|
||||
'base_time' => $baseTime,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser,
|
||||
'ship_id' => $shipId,
|
||||
'qty' => $qty
|
||||
));
|
||||
|
||||
return $event->getData('time');
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see Legacies_Empire_Model_BuilderAbstract::getResourcesNeeded()
|
||||
*/
|
||||
public function getResourcesNeeded($shipId, $qty)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
$resources = Wootook_Empire_Model_Game_Resources::getSingleton();
|
||||
|
||||
if (!isset($prices[$shipId])) {
|
||||
return array();
|
||||
}
|
||||
$resourcesNeeded = array();
|
||||
foreach ($resources as $resourceId => $resourceConfig) {
|
||||
if (!isset($prices[$shipId][$resourceId])) {
|
||||
continue;
|
||||
}
|
||||
if (Math::isPositive($prices[$shipId][$resourceId])) {
|
||||
$resourcesNeeded[$resourceId] = Math::mul($prices[$shipId][$resourceId], $qty);
|
||||
}
|
||||
}
|
||||
|
||||
return $resourcesNeeded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quantity set in parameter or the maximum buildable elements
|
||||
* if the quantity requested exeeds this number.
|
||||
*
|
||||
* @param int $shipId
|
||||
* @param int|string $qty
|
||||
* @return int|stirng
|
||||
*/
|
||||
protected function _checkMaximumQuantity($shipId, $qty)
|
||||
{
|
||||
return Math::min($qty, $this->getMaximumBuildableElementsCount($shipId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
* @return Legacies_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public function updateQueue($time)
|
||||
{
|
||||
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
$elapsedTime = $time - $this->_currentPlanet->getData('b_hangar');
|
||||
|
||||
foreach ($this->getQueue() as $element) {
|
||||
$shipId = $element->getData('ship_id');
|
||||
$qty = $element->getData('qty');
|
||||
$buildTime = $this->getBuildingTime($shipId, $qty);
|
||||
|
||||
if ($elapsedTime >= $buildTime) {
|
||||
$this->_currentPlanet[$fields[$shipId]] = Math::add($this->_currentPlanet[$fields[$shipId]], $qty);
|
||||
$elapsedTime -= $buildTime;
|
||||
$this->dequeue($element);
|
||||
continue;
|
||||
}
|
||||
|
||||
$timeRatio = $elapsedTime / $buildTime;
|
||||
$itemsBuilt = Math::mul($timeRatio, $qty);
|
||||
|
||||
$element->setData('updated_at', $time);
|
||||
$element->setData('qty', Math::sub($qty, $itemsBuilt));
|
||||
$this->_currentPlanet->setData($fields[$shipId], Math::add($this->_currentPlanet->getData($fields[$shipId]), $itemsBuilt));
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_currentPlanet->setData('b_hangar_id', $this->serialize());
|
||||
$this->_currentPlanet->setData('b_hangar', $time);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append items to build to the construction list
|
||||
*
|
||||
* @param int $shipId
|
||||
* @param int|string $qty
|
||||
* @return Legacies_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public function appendQueue($shipId, $qty, $time)
|
||||
{
|
||||
if ($this->_maxLength > 0 && $this->count() >= $this->_maxLength) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!Math::isPositive($qty)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
if (!$types->is($shipId, Legacies_Empire::TYPE_SHIP) && !$types->is($shipId, Legacies_Empire::TYPE_DEFENSE)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!$this->checkAvailability($shipId)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (MAX_FLEET_OR_DEFS_PER_ROW > 0) {
|
||||
$qty = Math::min($this->_checkMaximumQuantity($shipId, $qty), MAX_FLEET_OR_DEFS_PER_ROW);
|
||||
} else {
|
||||
$qty = $this->_checkMaximumQuantity($shipId, $qty);
|
||||
}
|
||||
|
||||
if (!Math::isPositive($qty)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$resourcesNeeded = $this->getResourcesNeeded($shipId, $qty);
|
||||
$remainingAmounts = $this->_calculateResourceRemainingAmounts($resourcesNeeded);
|
||||
if ($remainingAmounts === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->enqueue($shipId, $qty, $time);
|
||||
$this->_currentPlanet->setData('b_hangar_id', $this->serialize());
|
||||
|
||||
foreach ($remainingAmounts as $resourceId => $resourceAmount) {
|
||||
$this->_currentPlanet[$resourceId] = $resourceAmount;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_Shipyard_Item
|
||||
extends Wootook_Empire_Model_Builder_Item
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
class Legacies_Empire_Model_Planet_Building_SolarPlant
|
||||
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
public function getProductionRatios($level, $produtionRatio, $planet, $user)
|
||||
{
|
||||
return array(
|
||||
Legacies_Empire::RESOURCE_ENERGY => 20 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
class Legacies_Empire_Model_Planet_Ship_LargeTransport
|
||||
extends Wootook_Empire_Model_Planet_ShipAbstract
|
||||
{
|
||||
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE = 4;
|
||||
|
||||
public function getBaseSpeed(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
|
||||
return $prices[Legacies_Empire::ID_SHIP_LARGE_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
|
||||
}
|
||||
|
||||
public function getSpeedMultiplier(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
return pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_COMBUSTION_DRIVE));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
class Legacies_Empire_Model_Planet_Ship_LightTransport
|
||||
extends Wootook_Empire_Model_Planet_ShipAbstract
|
||||
{
|
||||
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE = 4;
|
||||
|
||||
public function getBaseSpeed(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
|
||||
if ($user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE) {
|
||||
return $prices[Legacies_Empire::ID_SHIP_LIGHT_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
|
||||
} else {
|
||||
return $prices[Legacies_Empire::ID_SHIP_LIGHT_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_SECONDARY];
|
||||
}
|
||||
}
|
||||
|
||||
public function getSpeedMultiplier(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE) {
|
||||
return pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_COMBUSTION_DRIVE));
|
||||
} else {
|
||||
return pow(1.2, $user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Ship_SolarSatellite
|
||||
extends Wootook_Empire_Model_Planet_ShipAbstract
|
||||
implements Wootook_Empire_Model_Planet_ResourceProductionInterface
|
||||
{
|
||||
public function getProductionRatios($quantity, $produtionRatio, $planet, $user)
|
||||
{
|
||||
return array(
|
||||
Legacies_Empire::RESOURCE_ENERGY => ((floatval($planet->getData('temp_max')) / 4) + 20) * (0.1 * $produtionRatio) * floatval($quantity)
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseSpeed(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getSpeedMultiplier(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getActualSpeed(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getBaseConsumption(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Ship_Supernova
|
||||
extends Wootook_Empire_Model_Planet_ShipAbstract
|
||||
implements Wootook_Empire_Model_Planet_ResourceProductionInterface
|
||||
{
|
||||
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE = 20;
|
||||
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY = 15;
|
||||
|
||||
public function getProductionRatios($quantity, $produtionRatio, $planet, $user)
|
||||
{
|
||||
return array(
|
||||
Legacies_Empire::RESOURCE_ENERGY => ((floatval($planet->getData('temp_max')) / 4) + 20) * (0.1 * $produtionRatio) * floatval($quantity) * -1250
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseSpeed(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
|
||||
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE &&
|
||||
$user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY) {
|
||||
return $prices[Legacies_Empire::ID_SHIP_SUPERNOVA][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
|
||||
} else {
|
||||
return $prices[Legacies_Empire::ID_SHIP_SUPERNOVA][Legacies_Empire::SHIPS_CELERITY_SECONDARY];
|
||||
}
|
||||
}
|
||||
|
||||
public function getSpeedMultiplier(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE &&
|
||||
$user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY) {
|
||||
return pow(1.2, $user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE));
|
||||
} else {
|
||||
return pow(1.3, $user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE)) *
|
||||
pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY));
|
||||
}
|
||||
}
|
||||
|
||||
public function getBaseConsumption(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
37
application/code/core/Legacies/Exception.php
Normal file
37
application/code/core/Legacies/Exception.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
interface Legacies_Exception {}
|
||||
37
application/code/core/Legacies/Officers/Exception.php
Normal file
37
application/code/core/Legacies/Officers/Exception.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
interface Legacies_Officers_Exception {}
|
||||
70
application/code/core/Legacies/Officers/Model/Observer.php
Normal file
70
application/code/core/Legacies/Officers/Model/Observer.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
class Legacies_Officers_Model_Observer
|
||||
{
|
||||
public static function planetUpdateListener($eventData)
|
||||
{
|
||||
if (isset($eventData['planet'])) {
|
||||
$planet = $eventData['planet'];
|
||||
|
||||
$user = $planet->getUser();
|
||||
|
||||
$level = floor(sqrt($user->getData('xpminier') / 500));
|
||||
if ($user->getData('lvl_minier') < $level) {
|
||||
$difference = $level - $user->getData('lvl_minier');
|
||||
if ($difference == 1) {
|
||||
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
|
||||
->addInfo('You gained 1 miner level.');
|
||||
} else {
|
||||
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
|
||||
->addInfo('You gained %1$d miner level.', (int) $difference);
|
||||
}
|
||||
}
|
||||
|
||||
$level = floor(sqrt($user->getData('xpraid')));
|
||||
if ($user->getData('lvl_raid') < $level) {
|
||||
$difference = $level - $user->getData('lvl_raid');
|
||||
if ($difference == 1) {
|
||||
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
|
||||
->addInfo('You gained 1 raider level.');
|
||||
} else {
|
||||
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
|
||||
->addInfo('You gained %1$d raider level.', (int) $difference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
application/code/core/Legacies/Oficers.php
Normal file
40
application/code/core/Legacies/Oficers.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @author Greg
|
||||
*
|
||||
*/
|
||||
|
||||
class Legacies_Officers
|
||||
{
|
||||
|
||||
}
|
||||
285
application/code/core/Wootook.php
Normal file
285
application/code/core/Wootook.php
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.txt
|
||||
* @see http://www.wootook.com/
|
||||
*
|
||||
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Bootstrap class, used to access main and global functionalities
|
||||
*
|
||||
* @package Wootook
|
||||
* @category core
|
||||
*/
|
||||
class Wootook
|
||||
{
|
||||
/**
|
||||
* Static list of application event listeners
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $_listeners = array();
|
||||
|
||||
/**
|
||||
* Static list of all locale translators
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $_translators = array();
|
||||
|
||||
/**
|
||||
* HTTP request management object
|
||||
*
|
||||
* @var Legacies_Core_Controller_Request_Http
|
||||
*/
|
||||
protected static $_request = null;
|
||||
|
||||
/**
|
||||
* HTTP response management object
|
||||
*
|
||||
* @var Legacies_Core_Controller_Response
|
||||
*/
|
||||
protected static $_response = null;
|
||||
|
||||
/**
|
||||
* The current timestamp
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected static $_now = null;
|
||||
|
||||
/**
|
||||
* Default locale identifier
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $_defaultLocale = 'fr_FR';
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @var array
|
||||
*/
|
||||
protected static $_config = null;
|
||||
|
||||
/**
|
||||
* Registers an event listener to be called later in the application.
|
||||
*
|
||||
* @param string $event The event identifier
|
||||
* @param callback $listener The event callback to be called
|
||||
*/
|
||||
public static function registerListener($event, $listener)
|
||||
{
|
||||
if (!isset(self::$_listeners[$event])) {
|
||||
self::$_listeners[$event] = array();
|
||||
}
|
||||
self::$_listeners[$event][] = $listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all event listeners
|
||||
*/
|
||||
public static function clearAllListeners()
|
||||
{
|
||||
self::$_listeners = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a specific event's listeners
|
||||
*
|
||||
* @param unknown_type $event
|
||||
*/
|
||||
public static function clearEventListeners($event)
|
||||
{
|
||||
if (isset(self::$_listeners[$event])) {
|
||||
self::$_listeners[$event] = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches an event, calls all callbacks that were previously registered
|
||||
*
|
||||
* @param string $event The event identifier
|
||||
* @param array $params The event params
|
||||
*/
|
||||
public static function dispatchEvent($event, $params)
|
||||
{
|
||||
$eventObject = new Wootook_Core_Event($params);
|
||||
|
||||
if (!isset(self::$_listeners[$event])) {
|
||||
return $eventObject;
|
||||
}
|
||||
|
||||
foreach (self::$_listeners[$event] as $listener) {
|
||||
call_user_func($listener, $eventObject);
|
||||
}
|
||||
|
||||
return $eventObject;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $namespace
|
||||
* @return Legacies_Core_Model_Session
|
||||
*/
|
||||
public static function getSession($namespace)
|
||||
{
|
||||
return Wootook_Core_Model_Session::factory($namespace);
|
||||
}
|
||||
|
||||
public static function getTranslator($locale = null)
|
||||
{
|
||||
if ($locale === null) {
|
||||
$locale = self::getDefaultLocale();
|
||||
}
|
||||
|
||||
if (!isset($translator[$locale])) {
|
||||
$path = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'locale';
|
||||
$translator[$locale] = new Wootook_Core_Model_Translator($path, $locale);
|
||||
}
|
||||
return $translator[$locale];
|
||||
}
|
||||
|
||||
public static function translate($locale, $message, Array $args)
|
||||
{
|
||||
return self::getTranslator($locale)->translateArgs($message, $args);
|
||||
}
|
||||
|
||||
public static function __($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return self::getTranslator(self::getDefaultLocale())->translateArgs($message, $args);
|
||||
}
|
||||
|
||||
public static function setDefaultLocale($locale)
|
||||
{
|
||||
$oldLocale = self::$_defaultLocale;
|
||||
self::$_defaultLocale = $locale;
|
||||
|
||||
return $oldLocale;
|
||||
}
|
||||
|
||||
public static function getDefaultLocale()
|
||||
{
|
||||
return self::$_defaultLocale;
|
||||
}
|
||||
|
||||
public static function now()
|
||||
{
|
||||
if (self::$_now === null) {
|
||||
self::$_now = time();
|
||||
}
|
||||
return self::$_now;
|
||||
}
|
||||
|
||||
public static function getRequest()
|
||||
{
|
||||
if (self::$_request === null) {
|
||||
self::$_request = new Wootook_Core_Controller_Request_Http();
|
||||
}
|
||||
return self::$_request;
|
||||
}
|
||||
|
||||
public static function setRequest($request)
|
||||
{
|
||||
self::$_request = $request;
|
||||
}
|
||||
|
||||
public static function getResponse()
|
||||
{
|
||||
if (self::$_response === null) {
|
||||
self::$_response = new Wootook_Core_Controller_Response_Http();
|
||||
}
|
||||
return self::$_response;
|
||||
}
|
||||
|
||||
public static function setResponse($response)
|
||||
{
|
||||
self::$_response = $response;
|
||||
}
|
||||
|
||||
public static function getConfig($path = null)
|
||||
{
|
||||
if (self::$_config === null) {
|
||||
self::$_config = include ROOT_PATH . DIRECTORY_SEPARATOR . 'config.php';
|
||||
}
|
||||
|
||||
if ($path === null || !is_string($path)) {
|
||||
return self::$_config;
|
||||
}
|
||||
$config = self::$_config;
|
||||
foreach (explode('/', $path) as $chunk) {
|
||||
if (!isset($config[$chunk])) {
|
||||
return null;
|
||||
}
|
||||
$config = $config[$chunk];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function getBaseUrl()
|
||||
{
|
||||
return self::getConfig('global/web/base_url');
|
||||
}
|
||||
|
||||
public static function getSkinUrl($package, $theme, $uri, Array $params = array())
|
||||
{
|
||||
return self::getUrl("skin/{$package}/{$theme}/{$uri}", $params);
|
||||
}
|
||||
|
||||
public static function getUrl($uri, Array $params = array())
|
||||
{
|
||||
$baseUrl = self::getBaseUrl();
|
||||
|
||||
$serializedParams = array();
|
||||
foreach ($params as $paramKey => $paramValue) {
|
||||
if ($paramValue) {
|
||||
$serializedParams[] = "{$paramKey}={$paramValue}";
|
||||
}
|
||||
}
|
||||
|
||||
if (count($serializedParams) > 0) {
|
||||
return $baseUrl . $uri . '?' . implode('&', $serializedParams);
|
||||
}
|
||||
return $baseUrl . $uri;
|
||||
}
|
||||
|
||||
public static function fileExists($path)
|
||||
{
|
||||
if ($path === null || empty($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($fp = @fopen($path, 'r', true)) === false) {
|
||||
return false;
|
||||
}
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
14
application/code/core/Wootook/Core/Block/Concat.php
Normal file
14
application/code/core/Wootook/Core/Block/Concat.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Concat
|
||||
extends Wootook_Core_View
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
$content = '';
|
||||
foreach ($this->_partials as $partial) {
|
||||
$content .= $partial->render();
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
10
application/code/core/Wootook/Core/Block/Deprecated.php
Normal file
10
application/code/core/Wootook/Core/Block/Deprecated.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Deprecated
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
public function getScriptPath()
|
||||
{
|
||||
return $this->getLayout()->getScriptPath();
|
||||
}
|
||||
}
|
||||
11
application/code/core/Wootook/Core/Block/Html/Form.php
Normal file
11
application/code/core/Wootook/Core/Block/Html/Form.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Html_Form
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
public function getFormKey()
|
||||
{
|
||||
$session = Wootook::getSession('security');
|
||||
return $session->getFormKey(true);
|
||||
}
|
||||
}
|
||||
145
application/code/core/Wootook/Core/Block/Html/Head.php
Normal file
145
application/code/core/Wootook/Core/Block/Html/Head.php
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Html_Head
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
const TYPE_GLOBAL_JS = 'global_js';
|
||||
|
||||
const TYPE_SKIN_CSS = 'skin_css';
|
||||
const TYPE_SKIN_JS = 'skin_js';
|
||||
|
||||
const TYPE_INLINE_CSS = 'inline_css';
|
||||
const TYPE_INLINE_JS = 'inline_js';
|
||||
|
||||
protected $_items = array();
|
||||
|
||||
public function addItem($type, Array $options = array())
|
||||
{
|
||||
if (!isset($this->_items[$type])) {
|
||||
$this->_items[$type] = array();
|
||||
}
|
||||
$this->_items[$type][] = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addJs($script, $type = 'text/javascript', Array $options = array())
|
||||
{
|
||||
$options['type'] = $type;
|
||||
$options['path'] = $script;
|
||||
|
||||
$this->addItem(self::TYPE_GLOBAL_JS, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addCss($stylesheet, $type = 'text/css', $condition = null, Array $options = array())
|
||||
{
|
||||
$options['type'] = $type;
|
||||
$options['path'] = $stylesheet;
|
||||
$options['condition'] = $condition;
|
||||
|
||||
$this->addItem(self::TYPE_SKIN_CSS, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSkinJs($script, $type = 'text/javascript', Array $options = array())
|
||||
{
|
||||
$options['type'] = $type;
|
||||
$options['path'] = $script;
|
||||
|
||||
$this->addItem(self::TYPE_SKIN_JS, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addInlineJs($content, $type = 'text/javascript', Array $options = array())
|
||||
{
|
||||
$options['type'] = $type;
|
||||
$options['content'] = $content;
|
||||
|
||||
$this->addItem(self::TYPE_INLINE_JS, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addInlineCss($content, $type = 'text/css', Array $options = array())
|
||||
{
|
||||
$options['type'] = $type;
|
||||
$options['path'] = $path;
|
||||
$options['content'] = $content;
|
||||
|
||||
$this->addItem(self::TYPE_INLINE_CSS, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCss()
|
||||
{
|
||||
if (isset($this->_items[self::TYPE_SKIN_CSS])) {
|
||||
return $this->_items[self::TYPE_SKIN_CSS];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getInlineCss()
|
||||
{
|
||||
if (isset($this->_items[self::TYPE_INLINE_CSS])) {
|
||||
return $this->_items[self::TYPE_INLINE_CSS];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getJs()
|
||||
{
|
||||
if (isset($this->_items[self::TYPE_GLOBAL_JS])) {
|
||||
return $this->_items[self::TYPE_GLOBAL_JS];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getSkinJs()
|
||||
{
|
||||
if (isset($this->_items[self::TYPE_SKIN_JS])) {
|
||||
return $this->_items[self::TYPE_SKIN_JS];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getInlineJs()
|
||||
{
|
||||
if (isset($this->_items[self::TYPE_INLINE_JS])) {
|
||||
return $this->_items[self::TYPE_INLINE_JS];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function renderCss()
|
||||
{
|
||||
$render = '';
|
||||
foreach ($this->getCss() as $css) {
|
||||
if (!isset($css['media'])) {
|
||||
$css['media'] = 'all';
|
||||
}
|
||||
$render .=<<<HTML_EOF
|
||||
<link rel="stylesheet" type="{$css['type']}" src="{$css['path']}" media="{$css['media']}" />
|
||||
HTML_EOF;
|
||||
}
|
||||
return $render;
|
||||
}
|
||||
|
||||
public function renderJs()
|
||||
{
|
||||
$render = '';
|
||||
foreach ($this->getJs() as $js) {
|
||||
if (!isset($js['type'])) {
|
||||
$js['type'] = 'text/javascript';
|
||||
}
|
||||
$render .=<<<HTML_EOF
|
||||
<script type="{$js['type']}" src="{$js['path']}"></script>
|
||||
HTML_EOF;
|
||||
}
|
||||
return $render;
|
||||
}
|
||||
}
|
||||
66
application/code/core/Wootook/Core/Block/Html/Navigation.php
Normal file
66
application/code/core/Wootook/Core/Block/Html/Navigation.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Html_Navigation
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
public function addLink($name, $label, $title, $uri, Array $params = array(), Array $classes = array(), $template = null)
|
||||
{
|
||||
$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
|
||||
),
|
||||
'label' => $label,
|
||||
'title' => $title,
|
||||
'classes' => $classes
|
||||
));
|
||||
$parent->setPartial($baseName, $child);
|
||||
|
||||
if ($template !== null) {
|
||||
$child->setTemplate($template);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNodeTitle($path, $title)
|
||||
{
|
||||
return $this->getNode($path)->setTitle($title);
|
||||
}
|
||||
|
||||
public function setNodeTemplate($path, $template)
|
||||
{
|
||||
return $this->getNode($path)->setTemplate($template);
|
||||
}
|
||||
|
||||
public function getNode($path)
|
||||
{
|
||||
return $this->_getNode(explode('/', $path));
|
||||
}
|
||||
|
||||
protected function _getNode($explodedPath)
|
||||
{
|
||||
$name = array_shift($explodedPath);
|
||||
|
||||
if ($this->hasPartial($name)) {
|
||||
$child = $this->getPartial($name)->_getNode($explodedPath);
|
||||
} else {
|
||||
$child = $this->getLayout()
|
||||
->createBlock('core/html.navigation.node', $this->getNameInLayout() . '.' . $name);
|
||||
}
|
||||
|
||||
if ($child instanceof Wootook_Core_Block_Html_Navigation_Link) {
|
||||
throw new Wootook_Core_Exception_RuntimeException('Node is a link. Could not append a child node to a link node.');
|
||||
}
|
||||
|
||||
if (count($explodedPath) == 0) {
|
||||
return $child;
|
||||
}
|
||||
return $child->_getNode($explodedPath);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Html_Navigation_Link
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
protected $_label = '';
|
||||
protected $_title = '';
|
||||
protected $_uri = '';
|
||||
protected $_params = array();
|
||||
protected $_classes = array('link');
|
||||
|
||||
public function getTemplate()
|
||||
{
|
||||
if ($this->_template !== null) {
|
||||
return $this->_template;
|
||||
}
|
||||
return 'page/html/navigation/link.phtml';
|
||||
}
|
||||
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->_label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
}
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->_title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
public function setUrl($uri, $params = array())
|
||||
{
|
||||
$this->_uri = $uri;
|
||||
$this->_params = $params;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLinkUrl($moreParams = array())
|
||||
{
|
||||
$params = array_merge($this->_params, $moreParams);
|
||||
return $this->getUrl($this->_uri, $params);
|
||||
}
|
||||
|
||||
public function addClass($class)
|
||||
{
|
||||
$this->_classes[] = $class;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearClasses()
|
||||
{
|
||||
$this->_classes = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderClasses($moreClasses)
|
||||
{
|
||||
$classes = array_merge($this->_classes, $moreClasses);
|
||||
return implode(' ', $classes);
|
||||
}
|
||||
|
||||
public function __construct(Array $data = array())
|
||||
{
|
||||
if (isset($data['label'])) {
|
||||
$this->setLabel($data['label']);
|
||||
unset($data['label']);
|
||||
}
|
||||
|
||||
if (isset($data['title'])) {
|
||||
$this->setTitle($data['title']);
|
||||
unset($data['title']);
|
||||
}
|
||||
|
||||
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']);
|
||||
} else {
|
||||
$this->setUrl($data['url']['uri']);
|
||||
}
|
||||
} else {
|
||||
$this->setUrl($data['url']);
|
||||
}
|
||||
unset($data['url']);
|
||||
}
|
||||
|
||||
if (isset($data['classes'])) {
|
||||
$classes = (array) $data['classes'];
|
||||
unset($data['classes']);
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$this->set($class);
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Html_Navigation_Node
|
||||
extends Wootook_Core_Block_Html_Navigation
|
||||
{
|
||||
protected $_title = '';
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->_title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
public function getTemplate()
|
||||
{
|
||||
if ($this->_template !== null) {
|
||||
return $this->_template;
|
||||
}
|
||||
return 'page/html/navigation/node.phtml';
|
||||
}
|
||||
}
|
||||
19
application/code/core/Wootook/Core/Block/Html/Page.php
Normal file
19
application/code/core/Wootook/Core/Block/Html/Page.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Html_Page
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
protected $_bodyClasses = array();
|
||||
|
||||
public function getBodyClasses()
|
||||
{
|
||||
return implode(' ', $this->_bodyClasses);
|
||||
}
|
||||
|
||||
public function addBodyClass($class)
|
||||
{
|
||||
$this->_bodyClasses[] = $class;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
36
application/code/core/Wootook/Core/Block/Template.php
Normal file
36
application/code/core/Wootook/Core/Block/Template.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Template
|
||||
extends Wootook_Core_View
|
||||
{
|
||||
protected function _getTemplatePath($file)
|
||||
{
|
||||
$pattern = "{$this->getScriptPath()}/%s/%s/scripts/{$file}";
|
||||
if (($layout = $this->getLayout()) !== null) {
|
||||
$package = $this->getLayout()->getPackage();
|
||||
$theme = $this->getLayout()->getTheme();
|
||||
|
||||
if ($package !== Wootook_Core_Layout::DEFAULT_PACKAGE) {
|
||||
if ($theme !== Wootook_Core_Layout::DEFAULT_THEME) {
|
||||
$path = sprintf($pattern, $package, $theme);
|
||||
if (Wootook::fileExists($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
$path = sprintf($pattern, $package, Wootook_Core_Layout::DEFAULT_THEME);
|
||||
if (Wootook::fileExists($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$path = sprintf($pattern, Wootook_Core_Layout::DEFAULT_PACKAGE, Wootook_Core_Layout::DEFAULT_THEME);
|
||||
if (Wootook::fileExists($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
trigger_error("Template '{$file}' could not be found.", E_USER_ERROR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
28
application/code/core/Wootook/Core/Block/Text.php
Normal file
28
application/code/core/Wootook/Core/Block/Text.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Text
|
||||
extends Wootook_Core_View
|
||||
{
|
||||
protected $_content = null;
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->_content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->_content;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$content = $this->getContent();
|
||||
if (empty($content)) {
|
||||
return null;
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
366
application/code/core/Wootook/Core/Collection.php
Normal file
366
application/code/core/Wootook/Core/Collection.php
Normal file
|
|
@ -0,0 +1,366 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Collection
|
||||
extends Wootook_Core_Model
|
||||
implements Iterator, Countable
|
||||
{
|
||||
protected $_tableName = null;
|
||||
protected $_tableAlias = null;
|
||||
protected $_entityClassName = 'Wootook_Object';
|
||||
|
||||
protected $_columns = array();
|
||||
protected $_where = array();
|
||||
protected $_join = array();
|
||||
protected $_order = array();
|
||||
protected $_union = array();
|
||||
protected $_limit = null;
|
||||
protected $_offset = null;
|
||||
protected $_group = array();
|
||||
|
||||
protected $_items = array();
|
||||
|
||||
public function __construct($tableName = null, $entityClassName = null)
|
||||
{
|
||||
if ($tableName !== null) {
|
||||
$this->setTableName($tableName);
|
||||
}
|
||||
if ($entityClassName != null) {
|
||||
$this->setEntityClassName($entityClassName);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
if (!is_array($tableName)) {
|
||||
$this->_tableName = $tableName;
|
||||
} else {
|
||||
$this->_tableName = current($tableName);
|
||||
$this->_tableAlias = key($tableName);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->_tableName;
|
||||
}
|
||||
|
||||
public function setEntityClassName($entityClassName)
|
||||
{
|
||||
$this->_entityClassName = $entityClassName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEntityClassName()
|
||||
{
|
||||
return $this->_entityClassName;
|
||||
}
|
||||
|
||||
public function quote($data)
|
||||
{
|
||||
static $database = null;
|
||||
|
||||
if ($database === null) {
|
||||
$database = Wootook_Database::getSingleton();
|
||||
}
|
||||
|
||||
return $database->quote($data);
|
||||
}
|
||||
|
||||
public function column($column = '*', $alias = null)
|
||||
{
|
||||
if (is_array($column)) {
|
||||
foreach ($column as $alias => $field) {
|
||||
if (is_int($alias)) {
|
||||
$this->_columns[] = array($field);
|
||||
} else {
|
||||
$this->_columns[] = array($alias => $field);
|
||||
}
|
||||
}
|
||||
} else if ($alias === null || is_int($alias)) {
|
||||
$this->_columns[] = array($column);
|
||||
} else {
|
||||
$this->_columns[] = array($alias => $column);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function where($condition)
|
||||
{
|
||||
$this->_where[] = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function join($table, $condition, $fields = array('*'), $mode = 'INNER')
|
||||
{
|
||||
static $database = null;
|
||||
|
||||
if ($database === null) {
|
||||
$database = Wootook_Database::getSingleton();
|
||||
}
|
||||
|
||||
if (is_array($table)) {
|
||||
$alias = key($table);
|
||||
$table = current($table);
|
||||
|
||||
foreach ($fields as $fieldAlias => $fieldName) {
|
||||
$this->column("{$alias}.{$field}", $fieldAlias);
|
||||
}
|
||||
|
||||
$this->_join[] = "{$mode} JOIN {$database->getTable($table)} AS {$alias} ON {$condition}";
|
||||
} else {
|
||||
foreach ($fields as $field) {
|
||||
$this->column("{$field}");
|
||||
}
|
||||
|
||||
$this->_join[] = "{$mode} JOIN {$database->getTable($table)} ON {$condition}";
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function order($field, $direction = 'ASC')
|
||||
{
|
||||
$this->_order[] = "{$field} {$direction}";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function union($collection)
|
||||
{
|
||||
$this->_union[] = $collection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limit($limit, $offset = null)
|
||||
{
|
||||
$this->_limit = intval($limit);
|
||||
$this->_offset = $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function group($groupField)
|
||||
{
|
||||
$this->_group[] = $groupField;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _prepareSql()
|
||||
{
|
||||
if (empty($this->_union)) {
|
||||
$database = Wootook_Database::getSingleton();
|
||||
|
||||
$fields = array();
|
||||
foreach ($this->_columns as $field) {
|
||||
$fieldName = current($field);
|
||||
$fieldAlias = key($field);
|
||||
if (is_string($fieldAlias)) {
|
||||
$fields[] = "{$fieldName} AS {$fieldAlias}";
|
||||
} else {
|
||||
$fields[] = $fieldName;
|
||||
}
|
||||
}
|
||||
if (!empty($fields)) {
|
||||
$fields = implode(", ", $fields);
|
||||
} else {
|
||||
$fields = '*';
|
||||
}
|
||||
if (!empty($this->_where)) {
|
||||
$where = 'WHERE (' . implode(") AND (", $this->_where) . ')';
|
||||
} else {
|
||||
$where = '';
|
||||
}
|
||||
$joinedTables = implode("\n ", $this->_join);
|
||||
|
||||
$order = '';
|
||||
if (!empty($this->_order)) {
|
||||
$order = 'ORDER BY ' . implode(", ", $this->_order);
|
||||
}
|
||||
$alias = '';
|
||||
if ($this->_tableAlias !== null) {
|
||||
$alias = " AS {$this->_tableAlias}";
|
||||
}
|
||||
$limit = '';
|
||||
if ($this->_limit) {
|
||||
if ($this->_offset) {
|
||||
$limit = "LIMIT {$this->_limit}, {$this->_offset}";
|
||||
} else {
|
||||
$limit = "LIMIT {$this->_limit}";
|
||||
}
|
||||
}
|
||||
$group = '';
|
||||
if (!empty($this->_group)) {
|
||||
$group = 'GROUP BY ' . implode(', ', $this->_group);
|
||||
}
|
||||
|
||||
return <<<SQL_EOF
|
||||
SELECT {$fields}
|
||||
FROM {$database->getTable($this->getTableName())}{$alias}
|
||||
{$joinedTables}
|
||||
{$where}
|
||||
{$group}
|
||||
{$order}
|
||||
{$limit}
|
||||
SQL_EOF;
|
||||
} else {
|
||||
$statements = array();
|
||||
foreach ($this->_union as $statement) {
|
||||
$statements[] = $statement->_prepareSql();
|
||||
}
|
||||
|
||||
$statements = '(' . implode(') UNION (', $statements) . ')';
|
||||
if (!empty($where)) {
|
||||
$where = 'WHERE ' . implode(" AND ", $this->_where);
|
||||
} else {
|
||||
$where = '';
|
||||
}
|
||||
$where = implode(" AND ", $this->_where);
|
||||
|
||||
$limit = '';
|
||||
if ($this->_limit) {
|
||||
if ($this->_offset) {
|
||||
$limit = "LIMIT {$this->_limit}, {$this->_offset}";
|
||||
} else {
|
||||
$limit = "LIMIT {$this->_limit}";
|
||||
}
|
||||
}
|
||||
|
||||
return <<<SQL_EOF
|
||||
$statements
|
||||
{$where}
|
||||
{$limit}
|
||||
SQL_EOF;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_prepareSql();
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
$sql = $this->_prepareSql();
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
$args = func_get_args();
|
||||
$statement->execute(array_shift($args));
|
||||
|
||||
$this->_items = array();
|
||||
if (func_num_args() > 1) {
|
||||
$reflection = new ReflectionClass(array_shift($args));
|
||||
} else {
|
||||
$reflection = new ReflectionClass($this->getEntityClassName());
|
||||
}
|
||||
|
||||
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
|
||||
$params = array_merge(array($row), $args);
|
||||
$this->_items[] = $reflection->newInstanceArgs($params);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
foreach ($this->_items as $child) {
|
||||
$child->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
foreach ($this->_items as $child) {
|
||||
$child->delete();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
$clone = clone $this;
|
||||
$clone->_fields = array();
|
||||
$clone->column('1');
|
||||
|
||||
$sql = $clone->_prepareSql();
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
$args = func_get_args();
|
||||
$statement->execute(array_shift($args));
|
||||
$count = $statement->rowCount();
|
||||
$statement->closeCursor();
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->_items);
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return current($this->_items);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
next($this->_items);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_items);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->_items);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return current($this->_items) !== false;
|
||||
}
|
||||
|
||||
public function getFirstItem()
|
||||
{
|
||||
if (!$this->_)
|
||||
if (count($this->_items) > 0) {
|
||||
return $this->_items[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getLastItem()
|
||||
{
|
||||
$size = count($this->_items);
|
||||
if ($size > 0) {
|
||||
return $this->_items[$size - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
50
application/code/core/Wootook/Core/Controller/Action.php
Normal file
50
application/code/core/Wootook/Core/Controller/Action.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Controller_Action
|
||||
{
|
||||
private $_request = null;
|
||||
private $_response = null;
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public function preDispatch()
|
||||
{
|
||||
}
|
||||
|
||||
public function postDispatch()
|
||||
{
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
protected function _forward($action, $controller = null, $module = null)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$request->setAction($action);
|
||||
if ($controller !== null) {
|
||||
$request->setController($controller);
|
||||
if ($module != null) {
|
||||
$request->setModule($module);
|
||||
}
|
||||
}
|
||||
$request->setIsDispatched(false);
|
||||
}
|
||||
|
||||
protected function _redirect($url)
|
||||
{
|
||||
$this->getResponse()->setRedirect($url);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
102
application/code/core/Wootook/Core/Controller/Request/Http.php
Normal file
102
application/code/core/Wootook/Core/Controller/Request/Http.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Controller_Request_Http
|
||||
extends Wootook_Object
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(array());
|
||||
}
|
||||
|
||||
public function setParam($key, $value)
|
||||
{
|
||||
return $this->setData($key, $value);
|
||||
}
|
||||
|
||||
public function getParam($key, $default = null)
|
||||
{
|
||||
if ($this->hasData($key)) {
|
||||
return $this->getData($key);
|
||||
}
|
||||
if (isset($_POST[$key])) {
|
||||
return $_POST[$key];
|
||||
}
|
||||
if (isset($_GET[$key])) {
|
||||
return $_GET[$key];
|
||||
}
|
||||
if (isset($_FILES[$key])) {
|
||||
return $_FILES[$key];
|
||||
}
|
||||
if (isset($_COOKIE[$key])) {
|
||||
return $_COOKIE[$key];
|
||||
}
|
||||
if (isset($_SERVER[$key])) {
|
||||
return $_SERVER[$key];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getQuery($key, $default = null)
|
||||
{
|
||||
if (!isset($_GET[$key])) {
|
||||
return $default;
|
||||
}
|
||||
return $_GET[$key];
|
||||
}
|
||||
|
||||
public function getFile($key, $default = null)
|
||||
{
|
||||
if (!isset($_FILES[$key])) {
|
||||
return $default;
|
||||
}
|
||||
return $_FILES[$key];
|
||||
}
|
||||
|
||||
public function getCookie($key, $default = null)
|
||||
{
|
||||
if (!isset($_COOKIE[$key])) {
|
||||
return $default;
|
||||
}
|
||||
return unserialize(stripslashes($_COOKIE[$key]));
|
||||
}
|
||||
|
||||
public function getRawCookie($key, $default = null)
|
||||
{
|
||||
if (!isset($_COOKIE[$key])) {
|
||||
return $default;
|
||||
}
|
||||
return $_COOKIE[$key];
|
||||
}
|
||||
|
||||
public function getPost($key, $default = null)
|
||||
{
|
||||
if (!isset($_POST[$key])) {
|
||||
return $default;
|
||||
}
|
||||
return $_POST[$key];
|
||||
}
|
||||
|
||||
public function getServer($key, $default = null)
|
||||
{
|
||||
if (!isset($_SERVER[$key])) {
|
||||
return $default;
|
||||
}
|
||||
return $_SERVER[$key];
|
||||
}
|
||||
|
||||
public function isPost()
|
||||
{
|
||||
if (strtoupper($this->getServer('REQUEST_METHOD')) == 'POST') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isGet()
|
||||
{
|
||||
if (strtoupper($this->getServer('REQUEST_METHOD')) == 'GET') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
158
application/code/core/Wootook/Core/Controller/Response/Http.php
Normal file
158
application/code/core/Wootook/Core/Controller/Response/Http.php
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Controller_Response_Http
|
||||
extends Wootook_Object
|
||||
{
|
||||
const REDIRECT_MOVED_PERMANENTLY = 301;
|
||||
const REDIRECT_FOUND = 302;
|
||||
const REDIRECT_SEE_OTHER = 303;
|
||||
const REDIRECT_TEMPORARY = 307;
|
||||
|
||||
protected static $_redirectCodes = array(
|
||||
REDIRECT_MOVED_PERMANENTLY => 'Moved Permanently',
|
||||
REDIRECT_FOUND => 'Found',
|
||||
REDIRECT_SEE_OTHER => 'See Other',
|
||||
REDIRECT_TEMPORARY => 'Temporary Redirect'
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(array());
|
||||
}
|
||||
|
||||
public function setBody($data)
|
||||
{
|
||||
$this->clearBody();
|
||||
|
||||
return $this->appendBody($data);
|
||||
}
|
||||
|
||||
public function appendBody($data)
|
||||
{
|
||||
if (!isset($this->_data['body']) || !is_array($this->_data['body'])) {
|
||||
$this->clearBody();
|
||||
}
|
||||
$this->_data['body'][] = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearBody()
|
||||
{
|
||||
$this->_data['body'] = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sendBody()
|
||||
{
|
||||
return implode('', $this->_data['body']);
|
||||
}
|
||||
|
||||
public function clearHeaders()
|
||||
{
|
||||
$this->_data['headers'] = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearRawHeaders()
|
||||
{
|
||||
$this->_data['raw_headers'] = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearAllHeaders()
|
||||
{
|
||||
$this->clearHeaders();
|
||||
$this->clearRawHeaders();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setHeader($name, $value)
|
||||
{
|
||||
if (!isset($this->_data['headers']) || !is_array($this->_data['headers'])) {
|
||||
$this->clearHeaders();
|
||||
}
|
||||
$this->_data['headers'][$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRawHeader($name, $value)
|
||||
{
|
||||
if (!isset($this->_data['raw_headers']) || !is_array($this->_data['raw_headers'])) {
|
||||
$this->clearRawHeaders();
|
||||
}
|
||||
$this->_data['raw_headers'][] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sendHeaders()
|
||||
{
|
||||
if (isset($this->_data['raw_headers'])) {
|
||||
foreach ($this->_data['raw_headers'] as $header) {
|
||||
header($header);
|
||||
}
|
||||
}
|
||||
if (isset($this->_data['headers'])) {
|
||||
foreach ($this->_data['headers'] as $headerName => $headerValue) {
|
||||
header("{$headerName}: {$headerValue}");
|
||||
}
|
||||
}
|
||||
$this->clearAllHeaders();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setIsRedirect($value = null)
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
$this->_data['is_redirect'] = $value;
|
||||
}
|
||||
return $this->_data['is_redirect'];
|
||||
}
|
||||
|
||||
public function setIsDispatched($dispatched = true)
|
||||
{
|
||||
return $this->setData('id_dispatched', $dispatched);
|
||||
}
|
||||
|
||||
public function getIsDispatched()
|
||||
{
|
||||
return $this->getData('id_dispatched');
|
||||
}
|
||||
|
||||
public function setCookie($name, $value, $lifetime = null, $path = null, $domain = null)
|
||||
{
|
||||
return $this->setRawCookie($name, serialize($value), $lifetime, $path, $domain);
|
||||
}
|
||||
|
||||
public function unsetCookie($name, $path = null, $domain = null)
|
||||
{
|
||||
return $this->setRawCookie($name, null, 0, $path, $domain);
|
||||
}
|
||||
|
||||
public function setRawCookie($name, $value, $lifetime = null, $path = null, $domain = null)
|
||||
{
|
||||
setcookie($name, $value, time() + $lifetime, $path, $domain);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRedirect($url, $code = self::REDIRECT_FOUND)
|
||||
{
|
||||
if (!in_array($code, self::$_redirectCodes)) {
|
||||
$code = self::REDIRECT_FOUND;
|
||||
}
|
||||
|
||||
$statusText = self::$_redirectCodes[$code];
|
||||
$this->setRawHeader("HTTP/1.1 {$code} {$statusText}")
|
||||
->setHeader('Location', $url)
|
||||
->setIsRedirect(true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
32
application/code/core/Wootook/Core/Email.php
Normal file
32
application/code/core/Wootook/Core/Email.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Email
|
||||
{
|
||||
protected static $_defaultHeadrs = array(
|
||||
);
|
||||
|
||||
protected $_headers = array();
|
||||
|
||||
public function send($to, $from, $subject, $body, Array $headers = array())
|
||||
{
|
||||
$this->_prepareHeaders($headers);
|
||||
}
|
||||
|
||||
public function setHeader($name, $value)
|
||||
{
|
||||
$this->_headers[$name] = $value;
|
||||
}
|
||||
|
||||
protected function _prepareHeaders($headers)
|
||||
{
|
||||
foreach ($headers as $name => $value) {
|
||||
$this->setHeader($name, $value);
|
||||
}
|
||||
|
||||
$this->addHeader('X-Mailer', 'PHP/' . PHP_VERSION . ' Wootook/' . VERSION);
|
||||
$this->addHeader('Content-Transfer-Encoding', '7bit');
|
||||
$this->addHeader('Content-Type', 'text/plain; charset=utf-8');
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
153
application/code/core/Wootook/Core/Entity.php
Normal file
153
application/code/core/Wootook/Core/Entity.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Entity
|
||||
extends Wootook_Core_Model
|
||||
implements Wootook_Core_EntityInterface
|
||||
{
|
||||
protected $_idFieldName = null;
|
||||
protected $_tableName = null;
|
||||
|
||||
public function setIdFieldName($fieldName)
|
||||
{
|
||||
$this->_idFieldName = $fieldName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIdFieldName()
|
||||
{
|
||||
return $this->_idFieldName;
|
||||
}
|
||||
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
$this->_tableName = $tableName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->_tableName;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->setData($this->getIdFieldName(), $id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->getData($this->getIdFieldName());
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
$id = func_get_arg(0);
|
||||
|
||||
$idFieldName = self::getIdFieldName();
|
||||
$database = Wootook_Database::getSingleton();
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
SELECT * FROM {$database->getTable(self::getTableName())}
|
||||
WHERE {$idFieldName}=:id
|
||||
LIMIT 1
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
$statement->execute(array(
|
||||
'id' => $id
|
||||
));
|
||||
|
||||
$datas = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
if (!is_array($datas) || empty($datas)) {
|
||||
throw new Wootook_Core_Exception_DataAccessException('Could not load data: this id could not be found.');
|
||||
}
|
||||
unset($datas[self::getIdFieldName()]);
|
||||
|
||||
$this->_data = $datas;
|
||||
$this->setId($id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
if ($this->getId() !== null) {
|
||||
$fields = array();
|
||||
$values = array();
|
||||
foreach ($this->getAllDatas() as $field => $value) {
|
||||
if ($field == self::getIdFieldName()) {
|
||||
continue;
|
||||
}
|
||||
$fields[] = "{$field}=:{$field}";
|
||||
$values[$field] = $value;
|
||||
}
|
||||
|
||||
$fieldsImploded = implode(', ', $fields);
|
||||
$idFieldName = self::getIdFieldName();
|
||||
$values[$idFieldName] = $this->getId();
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$sql =<<<SQL_EOF
|
||||
UPDATE {$database->getTable(self::getTableName())}
|
||||
SET {$fieldsImploded}
|
||||
WHERE {$idFieldName}=:{$idFieldName}
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
$statement->execute($values);
|
||||
} else {
|
||||
$datas = $this->getAllDatas();
|
||||
$fieldsImploded = implode(', ', array_keys($datas));
|
||||
|
||||
$tokens = array();
|
||||
$values = array();
|
||||
foreach ($datas as $field => $value) {
|
||||
if ($field == self::getIdFieldName()) {
|
||||
continue;
|
||||
}
|
||||
$tokens[] = ":{$field}";
|
||||
$values[$field] = $value;
|
||||
}
|
||||
$tokensImploded = implode(', ', $tokens);
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$sql =<<<SQL_EOF
|
||||
INSERT INTO {$database->getTable(self::getTableName())} ($fieldsImploded)
|
||||
VALUES ({$tokensImploded})
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
$statement->execute($values);
|
||||
|
||||
$this->setId($database->lastInsertId());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
$fields = array();
|
||||
foreach ($this->getAllDatas() as $field => $value) {
|
||||
if ($field == self::getIdFieldName()) {
|
||||
continue;
|
||||
}
|
||||
$fields[] = "{$field}=:{$field}";
|
||||
}
|
||||
|
||||
$fieldsImploded = implod(', ', $fields);
|
||||
$idFieldName = self::getIdFieldName();
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$sql =<<<SQL_EOF
|
||||
DELETE {$database->getTable(self::getTableName())}
|
||||
WHERE {$idFieldName}=:{$idFieldName}
|
||||
SQL_EOF;
|
||||
|
||||
$statement->execute($this->getAllDatas());
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
133
application/code/core/Wootook/Core/Entity/SubTable.php
Normal file
133
application/code/core/Wootook/Core/Entity/SubTable.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
* @uses Wootook_Empire_Model_User
|
||||
*/
|
||||
abstract class Wootook_Core_Entity_SubTable
|
||||
extends Wootook_Core_Model
|
||||
{
|
||||
private $_isLoaded = false;
|
||||
protected $_tableName = null;
|
||||
protected $_idFieldNames = array();
|
||||
|
||||
protected $_eventPrefix = 'entity.sub-table';
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
if ($this->_isLoaded !== false) {
|
||||
$fields = array();
|
||||
$values = array();
|
||||
$idFields = array();
|
||||
foreach ($this->getAllDatas() as $field => $value) {
|
||||
if (in_array($field, $this->_idFieldNames)) {
|
||||
$idFields[] = "{$field}=:{$field}";
|
||||
} else {
|
||||
$fields[] = "{$field}=:{$field}";
|
||||
}
|
||||
$values[$field] = $value;
|
||||
}
|
||||
$idFields = '(' . implode(') AND (', $idFields) . ')';
|
||||
$fields = implode(', ', $fields);
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$sql =<<<SQL_EOF
|
||||
UPDATE {$database->getTable(self::getTableName())}
|
||||
SET {$fields}
|
||||
WHERE {$idFields}
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
$statement->execute($values);
|
||||
} else {
|
||||
$datas = $this->getAllDatas();
|
||||
$fields = implode(', ', array_keys($datas));
|
||||
|
||||
$tokens = array();
|
||||
foreach ($datas as $field => $value) {
|
||||
$tokens[] = ":{$field}";
|
||||
}
|
||||
$tokens = implode(', ', $tokens);
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$sql =<<<SQL_EOF
|
||||
INSERT INTO {$database->getTable(self::getTableName())} ($fields)
|
||||
VALUES ({$tokens})
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
$statement->execute($datas);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
$idValues = func_get_arg(0);
|
||||
$database = Wootook_Database::getSingleton();
|
||||
|
||||
$idFields = array();
|
||||
foreach ($this->_idFieldNames as $field) {
|
||||
$idFields[] = "{$field}=:{$field}";
|
||||
}
|
||||
$idFields = '(' . implode(') AND (', $idFields) . ')';
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
SELECT * FROM {$database->getTable(self::getTableName())}
|
||||
WHERE $idFields
|
||||
LIMIT 1
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
$statement->execute($idValues);
|
||||
|
||||
$datas = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
if (!is_array($datas) || empty($datas)) {
|
||||
throw new Wootook_Core_Exception_DataAccessException('Could not load data: this id combination could not be found.');
|
||||
}
|
||||
|
||||
$this->_data = $datas;
|
||||
$this->_isLoaded = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
$database = Wootook_Database::getSingleton();
|
||||
|
||||
$idFields = array();
|
||||
$idValues = array();
|
||||
foreach ($this->_idFieldNames as $field) {
|
||||
$idFields[] = "{$field}=:{$field}";
|
||||
$idValues[$field] = $this->getData($field);
|
||||
}
|
||||
$idFields = '(' . implode(') AND (', $idFields) . ')';
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
DELETE {$database->getTable(self::getTableName())}
|
||||
WHERE $idFields
|
||||
LIMIT 1
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
$statement->execute($idValues);
|
||||
|
||||
$this->_data = array();
|
||||
$this->_isLoaded = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
$this->_tableName = $tableName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->_tableName;
|
||||
}
|
||||
}
|
||||
13
application/code/core/Wootook/Core/EntityInterface.php
Normal file
13
application/code/core/Wootook/Core/EntityInterface.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
interface Wootook_Core_EntityInterface
|
||||
{
|
||||
public function getId();
|
||||
public function setId($id);
|
||||
|
||||
public function getIdFieldName();
|
||||
public function setIdFieldName($fieldName);
|
||||
|
||||
public function getTableName();
|
||||
public function setTableName($tableName);
|
||||
}
|
||||
202
application/code/core/Wootook/Core/ErrorProfiler.php
Normal file
202
application/code/core/Wootook/Core/ErrorProfiler.php
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_ErrorProfiler
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
protected $_errors = array();
|
||||
protected $_warnings = array();
|
||||
protected $_notices = array();
|
||||
protected $_otherErrors = array();
|
||||
protected $_exceptions = array();
|
||||
|
||||
private static $_isTraceRegistered = false;
|
||||
|
||||
private static $_listen = true;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self;
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
public function errorManager($errno, $errstr, $errfile = null, $errline = null, Array $errcontext = array())
|
||||
{
|
||||
if (!self::$_listen) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($errno) {
|
||||
case E_USER_ERROR:
|
||||
case E_ERROR:
|
||||
$this->_errors[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext
|
||||
);
|
||||
break;
|
||||
|
||||
case E_USER_WARNING:
|
||||
case E_WARNING:
|
||||
$this->_warnings[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext
|
||||
);
|
||||
break;
|
||||
|
||||
case E_USER_NOTICE:
|
||||
case E_NOTICE:
|
||||
$this->_notices[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!isset($this->_otherErrors[$errno])) {
|
||||
$this->_otherErrors[$errno] = array();
|
||||
}
|
||||
|
||||
$this->_otherErrors[$errno][] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function exceptionManager($exception)
|
||||
{
|
||||
if (!self::$_listen) {
|
||||
return;
|
||||
}
|
||||
$this->_exceptions[] = $exception;
|
||||
}
|
||||
|
||||
protected function _renderError($id, $error)
|
||||
{
|
||||
$types = array(
|
||||
0x0001 => 'E_ERROR',
|
||||
0x0002 => 'E_WARNING',
|
||||
0x0004 => 'E_PARSE',
|
||||
0x0008 => 'E_NOTICE',
|
||||
0x0010 => 'E_CORE_ERROR',
|
||||
0x0020 => 'E_CORE_WARNING',
|
||||
0x0040 => 'E_COMPILE_ERROR',
|
||||
0x0080 => 'E_COMPILE_WARNING',
|
||||
0x0100 => 'E_USER_ERROR',
|
||||
0x0200 => 'E_USER_WARNING',
|
||||
0x0400 => 'E_USER_NOTICE',
|
||||
0x0800 => 'E_STRICT',
|
||||
0x1000 => 'E_RECOVERABLE_ERROR',
|
||||
0x2000 => 'E_DEPRECATED',
|
||||
0x4000 => 'E_USER_DEPRECATED',
|
||||
);
|
||||
|
||||
if (isset($error['code']) && isset($types[$error['code']])) {
|
||||
$code = $types[$error['code']];
|
||||
} else {
|
||||
$code = "Unknown ({$error['code']})";
|
||||
}
|
||||
|
||||
$date = date('Y-m-d H:i:s', (int) $error['time'][1]);
|
||||
$microsec = (int) ($error['time'][0] * 1000000);
|
||||
|
||||
return <<<ERROR_EOF
|
||||
Message #{$id}
|
||||
On: {$date} +{$microsec}µs
|
||||
Type: {$code}
|
||||
Message: {$error['message']}
|
||||
File: {$error['file']}
|
||||
Line: {$error['line']}
|
||||
\n
|
||||
ERROR_EOF;
|
||||
}
|
||||
|
||||
public function shutdownManager()
|
||||
{
|
||||
$index = 0;
|
||||
echo '<div style="background:#FFF;border:1px solid #F00;color:#000;padding:10px;margin:20px;text-align:left;">';
|
||||
echo '<h1>Debug profiler</h1>';
|
||||
if (count($this->_errors) <= 0 && count($this->_warnings) <= 0 &&
|
||||
count($this->_notices) <= 0 && count($this->_otherErrors) <= 0 &&
|
||||
count($this->_exceptions) <= 0) {
|
||||
echo '<p>Profiler was empty.</p>';
|
||||
} else {
|
||||
echo '<pre>';
|
||||
foreach ($this->_errors as $error) {
|
||||
echo $this->_renderError(++$index, $error);
|
||||
}
|
||||
foreach ($this->_warnings as $error) {
|
||||
echo $this->_renderError(++$index, $error);
|
||||
}
|
||||
foreach ($this->_notices as $error) {
|
||||
echo $this->_renderError(++$index, $error);
|
||||
}
|
||||
foreach ($this->_otherErrors as $errorList) {
|
||||
foreach ($errorList as $error) {
|
||||
echo $this->_renderError(++$index, $error);
|
||||
}
|
||||
}
|
||||
foreach ($this->_exceptions as $exception) {
|
||||
$index++;
|
||||
echo "Message #{$index}". PHP_EOL;
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
echo $exception->getTraceAsString();
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public static function register()
|
||||
{
|
||||
set_error_handler(array(self::getSingleton(), 'errorManager'));
|
||||
set_exception_handler(array(self::getSingleton(), 'exceptionManager'));
|
||||
|
||||
if (self::$_isTraceRegistered === false && defined('DEBUG')) {
|
||||
self::$_isTraceRegistered = true;
|
||||
register_shutdown_function(array(self::getSingleton(), 'shutdownManager'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function unregister($force = false)
|
||||
{
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
|
||||
if ((self::$_isTraceRegistered && defined('DEBUG')) || $force) {
|
||||
self::$_isTraceRegistered = false;
|
||||
register_shutdown_function(array(self::getSingleton(), 'shutdownManager'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function sleep()
|
||||
{
|
||||
self::$_listen = false;
|
||||
}
|
||||
|
||||
public static function wakeup()
|
||||
{
|
||||
self::$_listen = true;
|
||||
}
|
||||
}
|
||||
6
application/code/core/Wootook/Core/Event.php
Normal file
6
application/code/core/Wootook/Core/Event.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Event
|
||||
extends Wootook_Object
|
||||
{
|
||||
}
|
||||
7
application/code/core/Wootook/Core/Event/Break.php
Normal file
7
application/code/core/Wootook/Core/Event/Break.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Event_Break
|
||||
extends Exception
|
||||
implements Wootook_Core_Exception
|
||||
{
|
||||
}
|
||||
3
application/code/core/Wootook/Core/Exception.php
Normal file
3
application/code/core/Wootook/Core/Exception.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
interface Wootook_Core_Exception extends Wootook_Exception {}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Exception_DataAccessException
|
||||
extends Wootook_Core_Exception_RuntimeException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Exception_Exception
|
||||
extends Exception
|
||||
implements Wootook_Core_Exception
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Exception_RuntimeException
|
||||
extends RuntimeException
|
||||
implements Wootook_Core_Exception
|
||||
{
|
||||
}
|
||||
399
application/code/core/Wootook/Core/Layout.php
Normal file
399
application/code/core/Wootook/Core/Layout.php
Normal file
|
|
@ -0,0 +1,399 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Layout
|
||||
extends Wootook_Core_Model
|
||||
{
|
||||
const DEFAULT_PACKAGE = 'base';
|
||||
const DEFAULT_THEME = 'default';
|
||||
|
||||
protected $_blocks = array();
|
||||
|
||||
protected $_view = null;
|
||||
protected $_eventPrefix = 'layout';
|
||||
protected $_eventObject = 'layout';
|
||||
|
||||
protected $_package = self::DEFAULT_PACKAGE;
|
||||
protected $_theme = self::DEFAULT_THEME;
|
||||
|
||||
protected $_namespaces = array(
|
||||
'core' => array(
|
||||
'Wootook_Core_Block_' => 'Wootook/core/Block'
|
||||
)
|
||||
);
|
||||
|
||||
public function _init()
|
||||
{
|
||||
$modules = Wootook_Core_Model_Config_Modules::getSingleton();
|
||||
|
||||
foreach ($modules['block'] as $module => $moduleNamespaces) {
|
||||
foreach ($moduleNamespaces as $namespace => $path) {
|
||||
$this->registerBlockNamespace($module, $namespace, $path);
|
||||
}
|
||||
}
|
||||
|
||||
$config = include ROOT_PATH . 'config.php';
|
||||
$fileList = array();
|
||||
if (isset($config['global'])) {
|
||||
if (isset($config['global']['layout'])) {
|
||||
$fileList = $config['global']['layout'];
|
||||
}
|
||||
if (isset($config['global']['package'])) {
|
||||
$this->setPackage($config['global']['package']);
|
||||
}
|
||||
if (isset($config['global']['theme'])) {
|
||||
$this->setTheme($config['global']['theme']);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fileList as $layoutFile) {
|
||||
foreach (include $this->_getLayoutPath($layoutFile) as $layoutId => $layoutConfig) {
|
||||
if ($this->hasData($layoutId)) {
|
||||
$declared = $this->getData($layoutId);
|
||||
|
||||
$layoutConfig = array_merge($declared, $layoutConfig);
|
||||
}
|
||||
|
||||
$this->setData($layoutId, $layoutConfig);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
$layoutId = func_get_arg(0);
|
||||
|
||||
if (!$this->hasData($layoutId)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$layoutConfigs = array($this->getData($layoutId));
|
||||
if (isset($layoutConfigs[0]['update'])) {
|
||||
$parent = $layoutConfigs[0]['update'];
|
||||
|
||||
$i = 0;
|
||||
while (true) {
|
||||
$layoutConfigs[++$i] = $this->getData($parent);
|
||||
|
||||
if (!isset($layoutConfigs[$i]['update'])) {
|
||||
break;
|
||||
}
|
||||
$parent = $layoutConfigs[$i]['update'];
|
||||
}
|
||||
}
|
||||
|
||||
$layoutUpdates = array();
|
||||
$layoutConfig = array();
|
||||
foreach (array_reverse($layoutConfigs) as $config) {
|
||||
$layoutConfig = array_merge($layoutConfig, $config);
|
||||
|
||||
if (isset($layoutConfig['reference'])) {
|
||||
foreach ($layoutConfig['reference'] as $name => $update) {
|
||||
if (!isset($layoutUpdates[$name])) {
|
||||
$layoutUpdates[$name] = array();
|
||||
}
|
||||
$layoutUpdates[$name][] = $update;
|
||||
}
|
||||
unset($layoutConfig['reference']);
|
||||
}
|
||||
}
|
||||
unset($layoutConfigs, $layoutConfig['update']);
|
||||
|
||||
if (isset($layoutConfig['type'])) {
|
||||
$type = $layoutConfig['type'];
|
||||
$name = isset($layoutConfig['name']) ? $layoutConfig['name'] : 'root';
|
||||
|
||||
$this->_view = $this->_createBlock($type, $name, $layoutConfig);
|
||||
} else if (!isset($this->_view)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
foreach ($layoutUpdates as $block => $updates) {
|
||||
if (!isset($this->_blocks[$block])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$parent = $this->_blocks[$block];
|
||||
foreach ($updates as $update) {
|
||||
if (isset($update['children'])) {
|
||||
foreach ($update['children'] as $childName => $childConfig) {
|
||||
$type = $childConfig['type'];
|
||||
$alias = isset($childConfig['alias']) ? $childConfig['alias'] : $childName;
|
||||
|
||||
$parent->$alias = $this->_createBlock($type, $childName, $childConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($layoutUpdates as $block => $updates) {
|
||||
if (!isset($this->_blocks[$block])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($updates as $update) {
|
||||
if (isset($update['actions'])) {
|
||||
$this->_callActions($this->_blocks[$block], $update['actions']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->_blocks as $block) {
|
||||
$block->prepareLayout();
|
||||
}
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
}
|
||||
|
||||
protected function _resolveBlockClassType($type)
|
||||
{
|
||||
$offset = strpos($type, '/');
|
||||
if ($offset === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$module = substr($type, 0, $offset);
|
||||
$block = substr($type, $offset + 1);
|
||||
|
||||
/*
|
||||
$module = str_replace(' ', '', ucwords(str_replace('-', ' ', $module)));
|
||||
$module = str_replace(' ', '_', ucwords(str_replace('.', ' ', $module)));
|
||||
*/
|
||||
$block = str_replace(' ', '', ucwords(str_replace('-', ' ', $block)));
|
||||
$block = str_replace(' ', '_', ucwords(str_replace('.', ' ', $block)));
|
||||
|
||||
if (isset($this->_namespaces[$module])) {
|
||||
foreach ($this->_namespaces[$module] as $namespace => $path) {
|
||||
$className = $namespace . $block;
|
||||
$fileName = $path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $block) . '.php';
|
||||
|
||||
Wootook_Core_ErrorProfiler::sleep();
|
||||
if (!($fp = @fopen($fileName, 'r', true))) {
|
||||
Wootook_Core_ErrorProfiler::wakeup();
|
||||
continue;
|
||||
}
|
||||
Wootook_Core_ErrorProfiler::wakeup();
|
||||
fclose($fp);
|
||||
|
||||
if (!class_exists($className, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
}
|
||||
|
||||
trigger_error(Wootook::__('Class type "%s" could not be resolved.', $type), E_USER_INFO);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function registerBlockNamespace($module, $namespace, $path = null)
|
||||
{
|
||||
if ($path === null) {
|
||||
$path = str_replace('_', DIRECTORY_SEPARATOR, $namespace);
|
||||
}
|
||||
if (!isset($this->_namespaces[$module])) {
|
||||
$this->_namespaces[$module] = array();
|
||||
}
|
||||
$this->_namespaces[$module][$namespace] = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function unregisterBlockNamespace($module, $namespace)
|
||||
{
|
||||
if (isset($this->_namespaces[$module]) && isset($this->_namespaces[$module][$namespace])) {
|
||||
unset($this->_namespaces[$module][$namespace]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function createBlock($type, $name, $config = array())
|
||||
{
|
||||
$instance = $this->_createBlock($type, $name, $config);
|
||||
|
||||
$instance->prepareLayout();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
protected function _createBlock($type, $name, $config = array())
|
||||
{
|
||||
$className = $this->_resolveBlockClassType($type);
|
||||
|
||||
if ($className === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$children = array();
|
||||
if (isset($config['children'])) {
|
||||
$children = $config['children'];
|
||||
unset($config['children']);
|
||||
}
|
||||
$actions = array();
|
||||
if (isset($config['actions'])) {
|
||||
$actions = $config['actions'];
|
||||
unset($config['actions']);
|
||||
}
|
||||
|
||||
try {
|
||||
$reflectionClass = new ReflectionClass($className);
|
||||
|
||||
$instance = $reflectionClass->newInstance($config);
|
||||
$this->_blocks[$name] = $instance;
|
||||
$instance->setNameInLayout($name);
|
||||
|
||||
$instance->setLayout($this);
|
||||
|
||||
foreach ($children as $name => $config) {
|
||||
if (isset($config['alias'])) {
|
||||
$alias = $config['alias'];
|
||||
} else {
|
||||
$alias = $name;
|
||||
}
|
||||
|
||||
if (!isset($config['type'])) {
|
||||
$instance->$alias = new Wootook_Core_View($config);
|
||||
} else {
|
||||
$instance->$alias = $this->_createBlock($config['type'], $name, $config);
|
||||
}
|
||||
}
|
||||
} catch (ReflectionException $e) {
|
||||
trigger_error($e->getMessage(), E_USER_INFO);
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->_callActions($instance, $actions);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
protected function _callActions($block, $actions)
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($block);
|
||||
|
||||
foreach ($actions as $action) {
|
||||
if (!isset($action['method'])) {
|
||||
continue;
|
||||
}
|
||||
$method = $action['method'];
|
||||
|
||||
$params = array();
|
||||
if (isset($action['params'])) {
|
||||
$params = $action['params'];
|
||||
}
|
||||
|
||||
try {
|
||||
$reflectionMethod = $reflectionClass->getMethod($method);
|
||||
$requiredParameterCount = $reflectionMethod->getNumberOfRequiredParameters();
|
||||
$callParamaters = array();
|
||||
foreach ($reflectionMethod->getParameters() as $parameter) {
|
||||
$paramterName = $parameter->getName();
|
||||
$paramterPosition = $parameter->getPosition();
|
||||
|
||||
if (isset($params[$paramterName])) {
|
||||
$callParamaters[$paramterPosition] = $params[$paramterName];
|
||||
} else if ($parameter->isDefaultValueAvailable()) {
|
||||
$callParamaters[$paramterPosition] = $parameter->getDefaultValue();
|
||||
//} else if (!$parameter->isOptionnal()) {
|
||||
} else if ($paramterPosition <= $requiredParameterCount) {
|
||||
throw new Wootook_Core_Exception_RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
$reflectionMethod->invokeArgs($block, $callParamaters);
|
||||
} catch (ReflectionException $e) {
|
||||
trigger_error($e->getMessage(), E_USER_INFO);
|
||||
continue;
|
||||
} catch (RuntimeException $e) {
|
||||
trigger_error($e->getMessage(), E_USER_WARNING);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getPackage()
|
||||
{
|
||||
return $this->_package;
|
||||
}
|
||||
|
||||
public function setPackage($package)
|
||||
{
|
||||
$this->_package = $package;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTheme()
|
||||
{
|
||||
return $this->_theme;
|
||||
}
|
||||
|
||||
public function setTheme($theme)
|
||||
{
|
||||
$this->_theme = $theme;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getScriptPath()
|
||||
{
|
||||
return APPLICATION_PATH . DIRECTORY_SEPARATOR . 'design';
|
||||
}
|
||||
|
||||
public function getBlock($code)
|
||||
{
|
||||
if (isset($this->_blocks[$code])) {
|
||||
return $this->_blocks[$code];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$scriptPath = $this->getScriptPath();
|
||||
foreach ($this->_blocks as $block) {
|
||||
if ($block instanceof Wootook_Core_Block_Template) {
|
||||
$block->setScriptPath($scriptPath);
|
||||
}
|
||||
$block->beforeToHtml();
|
||||
}
|
||||
unset($block);
|
||||
|
||||
return $this->_view->render();
|
||||
}
|
||||
|
||||
protected function _getLayoutPath($file)
|
||||
{
|
||||
$package = $this->getPackage();
|
||||
$theme = $this->getTheme();
|
||||
$pattern = "{$this->getScriptPath()}/%s/%s/layouts/{$file}";
|
||||
|
||||
$path = sprintf($pattern, $package, $theme);
|
||||
if (Wootook::fileExists($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$path = sprintf($pattern, $package, self::DEFAULT_THEME);
|
||||
if (Wootook::fileExists($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$path = sprintf($pattern, self::DEFAULT_PACKAGE, self::DEFAULT_THEME);
|
||||
if (Wootook::fileExists($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
trigger_error(Legacies::__("Layout file '%s' does not exist.", $file), E_USER_INFO);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
158
application/code/core/Wootook/Core/Model.php
Normal file
158
application/code/core/Wootook/Core/Model.php
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Model
|
||||
extends Wootook_Object
|
||||
{
|
||||
protected $_originalData = array();
|
||||
|
||||
protected $_eventPrefix = null;
|
||||
protected $_eventObject = null;
|
||||
|
||||
public function __construct(Array $data = array())
|
||||
{
|
||||
$this->_data = $data;
|
||||
|
||||
$this->_init();
|
||||
$this->_setOriginalData($this->_data);
|
||||
}
|
||||
|
||||
abstract protected function _init();
|
||||
|
||||
protected function _setOriginalData(Array $data)
|
||||
{
|
||||
$this->_originalData = $data;
|
||||
}
|
||||
|
||||
final public function save()
|
||||
{
|
||||
try {
|
||||
$params = func_get_args();
|
||||
call_user_func_array(array($this, '_beforeSave'), $params);
|
||||
call_user_func_array(array($this, '_save'), $params);
|
||||
call_user_func_array(array($this, '_afterSave'), $params);
|
||||
$this->_setOriginalData($this->_data);
|
||||
} catch (PDOException $e) {
|
||||
throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), 0);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract protected function _save();
|
||||
|
||||
protected function _beforeSave()
|
||||
{
|
||||
Wootook::dispatchEvent('model.before-save', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Wootook::dispatchEvent($this->_eventPrefix . '.before-save', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _afterSave()
|
||||
{
|
||||
Wootook::dispatchEvent('model.after-save', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Wootook::dispatchEvent($this->_eventPrefix . '.after-save', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function load()
|
||||
{
|
||||
try {
|
||||
$params = func_get_args();
|
||||
call_user_func_array(array($this, '_beforeLoad'), $params);
|
||||
call_user_func_array(array($this, '_load'), $params);
|
||||
call_user_func_array(array($this, '_afterLoad'), $params);
|
||||
$this->_setOriginalData($this->_data);
|
||||
} catch (PDOException $e) {
|
||||
throw new Wootook_Core_Exception_DataAccessException('Could not load data: ' . $e->getMessage(), 0);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract protected function _load();
|
||||
|
||||
protected function _beforeLoad()
|
||||
{
|
||||
Wootook::dispatchEvent('model.before-load', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Wootook::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _afterLoad()
|
||||
{
|
||||
Wootook::dispatchEvent('model.after-load', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Wootook::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function delete()
|
||||
{
|
||||
try {
|
||||
$params = func_get_args();
|
||||
call_user_func_array(array($this, '_beforeDelete'), $params);
|
||||
call_user_func_array(array($this, '_delete'), $params);
|
||||
call_user_func_array(array($this, '_afterDelete'), $params);
|
||||
} catch (PDOException $e) {
|
||||
throw new Wootook_Core_Exception_DataAccessException('Could not delete entity: ' . $e->getMessage(), 0);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract protected function _delete();
|
||||
|
||||
protected function _beforeDelete()
|
||||
{
|
||||
Wootook::dispatchEvent('model.before-delete', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Wootook::dispatchEvent($this->_eventPrefix . '.before-delete', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _afterDelete()
|
||||
{
|
||||
Wootook::dispatchEvent('model.after-delete', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Wootook::dispatchEvent($this->_eventPrefix . '.after-delete', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __set($key, $value)
|
||||
{
|
||||
return $this->setData($key, $value);
|
||||
}
|
||||
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->getData($key);
|
||||
}
|
||||
|
||||
public function __unset($key)
|
||||
{
|
||||
return $this->unsetData($key);
|
||||
}
|
||||
|
||||
public function __isset($key)
|
||||
{
|
||||
return $this->hasData($key);
|
||||
}
|
||||
}
|
||||
88
application/code/core/Wootook/Core/Model/Config.php
Normal file
88
application/code/core/Wootook/Core/Model/Config.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Core_Model_Config
|
||||
extends Wootook_Core_Model
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
protected $_eventPrefix = 'core.config';
|
||||
protected $_eventObject = 'config';
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
$database = Wootook_Database::getSingleton();
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
SELECT config_name AS attribute, config_value AS value
|
||||
FROM {$database->getTable('config')} AS config
|
||||
SQL_EOF;
|
||||
|
||||
$attributeName = null;
|
||||
$attributeValue = null;
|
||||
|
||||
$statement = $database->prepare($sql);
|
||||
$statement->execute();
|
||||
|
||||
$statement->bindColumn('attribute', $attributeName, PDO::PARAM_STR);
|
||||
$statement->bindColumn('value', $attributeValue, PDO::PARAM_STR);
|
||||
|
||||
while ($statement->fetch(PDO::FETCH_BOUND)) {
|
||||
$this->setData($attributeName, $attributeValue);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$fields = array();
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
UPDATE {{table}}
|
||||
SET config_value=:value
|
||||
WHERE config_name=:name
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
foreach ($this->getAllDatas() as $attributeName => $attributeValue) {
|
||||
$statement->execute(array(
|
||||
'name' => $attributeName,
|
||||
'value' => $attributeValue
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return (bool) $this->getData('game_disable');
|
||||
}
|
||||
}
|
||||
52
application/code/core/Wootook/Core/Model/Config/Abstract.php
Normal file
52
application/code/core/Wootook/Core/Model/Config/Abstract.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Model_Config_Abstract
|
||||
extends Wootook_Core_Model
|
||||
implements Iterator, Countable
|
||||
{
|
||||
protected function _initData($filename)
|
||||
{
|
||||
$config = include ROOT_PATH . 'config.php';
|
||||
$universe = $config['global']['storyline']['universe'];
|
||||
$episode = $config['global']['storyline']['episode'];
|
||||
|
||||
$path = 'gamedata' . DIRECTORY_SEPARATOR . $universe . DIRECTORY_SEPARATOR
|
||||
. $episode . DIRECTORY_SEPARATOR . $filename . '.php';
|
||||
|
||||
foreach (include APPLICATION_PATH . $path as $elementId => $fieldName) {
|
||||
$this->setData($elementId, $fieldName);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->_data);
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return current($this->_data);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
return next($this->_data);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->_data);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return $this->current() !== false;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_data);
|
||||
}
|
||||
}
|
||||
56
application/code/core/Wootook/Core/Model/Config/Events.php
Normal file
56
application/code/core/Wootook/Core/Model/Config/Events.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Core_Model_Config_Events
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
public static function registerEvents()
|
||||
{
|
||||
foreach (self::getSingleton() as $event => $listenerList) {
|
||||
foreach ($listenerList as $listener) {
|
||||
Wootook::registerListener($event, $listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('events');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
47
application/code/core/Wootook/Core/Model/Config/Modules.php
Normal file
47
application/code/core/Wootook/Core/Model/Config/Modules.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Core_Model_Config_Modules
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('modules');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
145
application/code/core/Wootook/Core/Model/Session.php
Normal file
145
application/code/core/Wootook/Core/Model/Session.php
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Core_Model_Session
|
||||
extends Wootook_Object
|
||||
{
|
||||
const CRIT = 0x80;
|
||||
const ERROR = 0x40;
|
||||
const WARN = 0x20;
|
||||
const INFO = 0x10;
|
||||
const DEBUG = 0x01;
|
||||
const SUCCESS = 0;
|
||||
|
||||
protected static $_instances = null;
|
||||
|
||||
protected static $_levels = null;
|
||||
|
||||
public static function factory($namespace)
|
||||
{
|
||||
$namespace = (string) $namespace;
|
||||
if (!isset(self::$_instances[$namespace])) {
|
||||
if (self::$_levels === null) {
|
||||
$reflection = new ReflectionClass(__CLASS__);
|
||||
self::$_levels = array_flip($reflection->getConstants());
|
||||
}
|
||||
|
||||
self::$_instances[$namespace] = new self($namespace);
|
||||
}
|
||||
return self::$_instances[$namespace];
|
||||
}
|
||||
|
||||
public static function destroy()
|
||||
{
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
public function __construct($namespace)
|
||||
{
|
||||
if (session_id() == '') {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (!isset($_SESSION[$namespace])) {
|
||||
$_SESSION[$namespace] = array();
|
||||
}
|
||||
|
||||
$this->_data = &$_SESSION[$namespace];
|
||||
$this->_data['messages'] = array();
|
||||
}
|
||||
|
||||
public function getMessages($clear = true)
|
||||
{
|
||||
$messages = $this->_data['messages'];
|
||||
if ($clear == true) {
|
||||
$this->_data['messages'] = array();
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
|
||||
public function addMessage($message, $type = self::DEBUG)
|
||||
{
|
||||
if (!isset(self::$_levels[$type])) {
|
||||
$type = self::DEBUG;
|
||||
}
|
||||
|
||||
if (!isset($this->_data['messages'])) {
|
||||
$this->_data['messages'] = array();
|
||||
}
|
||||
if (!isset($this->_data['messages'][self::$_levels[$type]])) {
|
||||
$this->_data['messages'][self::$_levels[$type]] = array();
|
||||
}
|
||||
$this->_data['messages'][self::$_levels[$type]][] = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addCritical($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return $this->addMessage(vsprintf($message, $args), self::CRIT);
|
||||
}
|
||||
|
||||
public function addError($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return $this->addMessage(vsprintf($message, $args), self::ERROR);
|
||||
}
|
||||
|
||||
public function addWarning($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return $this->addMessage(vsprintf($message, $args), self::WARN);
|
||||
}
|
||||
|
||||
public function addSuccess($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return $this->addMessage(vsprintf($message, $args), self::SUCCESS);
|
||||
}
|
||||
|
||||
public function addInfo($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return $this->addMessage(vsprintf($message, $args), self::INFO);
|
||||
}
|
||||
|
||||
public function addDebug($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return $this->addMessage(vsprintf($message, $args), self::DEBUG);
|
||||
}
|
||||
|
||||
public function getFormKey($reset = false)
|
||||
{
|
||||
if (!$this->getData('form_key')) {
|
||||
$this->setData('form_key', uniqid());
|
||||
return $this->getData('form_key');
|
||||
}
|
||||
|
||||
$key = $this->getData('form_key');
|
||||
if ($reset == true) {
|
||||
$this->setData('form_key', uniqid());
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
37
application/code/core/Wootook/Core/Model/Translator.php
Normal file
37
application/code/core/Wootook/Core/Model/Translator.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Model_Translator
|
||||
{
|
||||
protected $_translations = array();
|
||||
|
||||
public function __construct($path, $locale)
|
||||
{
|
||||
$fileList = glob($path . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . '*.csv');
|
||||
foreach ($fileList as $file) {
|
||||
$fp = fopen($file, 'r');
|
||||
while (!feof($fp)) {
|
||||
$line = fgetcsv($fp);
|
||||
if (count($line) >= 2) {
|
||||
$this->_translations[$line[0]] = $line[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function translate($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return $this->translateArgs($message, $args);
|
||||
}
|
||||
|
||||
public function translateArgs($message, Array $args = array())
|
||||
{
|
||||
if (isset($this->_translations[$message])) {
|
||||
$message = $this->_translations[$message];
|
||||
}
|
||||
|
||||
return vsprintf($message, $args);
|
||||
}
|
||||
}
|
||||
76
application/code/core/Wootook/Core/Plugin/LoaderAbstract.php
Normal file
76
application/code/core/Wootook/Core/Plugin/LoaderAbstract.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Plugin_LoaderAbstract
|
||||
{
|
||||
protected $_pluginInstances = array();
|
||||
protected $_namespaces = array();
|
||||
|
||||
public function load($pluginName, $useSingleton = false)
|
||||
{
|
||||
if (isset($this->_pluginInstances[$pluginName])) {
|
||||
return $this->_pluginInstances[$pluginName];
|
||||
}
|
||||
|
||||
foreach ($this->_namespaces as $namespace => $path) {
|
||||
$className = $namespace . ucfirst($pluginName);
|
||||
$fileName = $path . DIRECTORY_SEPARATOR . ucfirst($pluginName) . '.php';
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!class_exists($className, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->_load($className, $useSingleton);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function registerNamespace($namespace, $path = null)
|
||||
{
|
||||
if ($path === null) {
|
||||
$path = str_replace('_', DIRECTORY_SEPARATOR, $namespace);
|
||||
}
|
||||
$this->_namespaces[$namespace] = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function unregisterNamespace($namespace)
|
||||
{
|
||||
if (isset($this->_namespaces[$namespace])) {
|
||||
unset($this->_namespaces[$namespace]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract protected function _load($className);
|
||||
|
||||
public function getPlugin($pluginName)
|
||||
{
|
||||
return $this->load($pluginName);
|
||||
}
|
||||
|
||||
public function setPlugin($pluginName, $pluginInstance)
|
||||
{
|
||||
$this->_pluginInstances[$pluginName] = $pluginInstance;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasPlugin($pluginName)
|
||||
{
|
||||
return isset($this->_pluginInstances[$pluginName]);
|
||||
}
|
||||
|
||||
public function unsetPlugin($pluginName)
|
||||
{
|
||||
unset($this->_pluginInstances[$pluginName]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
444
application/code/core/Wootook/Core/Setup/Updater/ScriptQueue.php
Normal file
444
application/code/core/Wootook/Core/Setup/Updater/ScriptQueue.php
Normal file
|
|
@ -0,0 +1,444 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Setup_Model_Updater_ScriptQueue
|
||||
implements Iterator, Countable, ArrayAccess
|
||||
{
|
||||
const PCRE_FILE_PATTERN = '%^(?<action>install|upgrade|uninstall|downgrade)-(?<version1>[0-9]+\.[0-9]+\.[0-9]+)(?:\.(?<stage1>[a-z]+)(?<level1>[0-9]+))?(?:-(?<version2>[0-9]+\.[0-9]+\.[0-9]+)(?:\.(?<stage2>[a-z]+)(?<level2>[0-9]+))?)?$%';
|
||||
const PCRE_VERSION_PATTERN = '%^(?<version>[0-9]+\.[0-9]+\.[0-9]+)(?:-(?<stage>[a-z]+)(?<level>[0-9]+)?)?$%';
|
||||
|
||||
const STAGE_ALPHA = 'alpha';
|
||||
const STAGE_BETA = 'beta';
|
||||
const STAGE_RC = 'rc';
|
||||
const STAGE_STABLE = 'stable';
|
||||
|
||||
const MODE_INSTALL = 'install';
|
||||
const MODE_UNINSTALL = 'uninstall';
|
||||
const MODE_UPGRADE = 'upgrade';
|
||||
const MODE_DOWNGRADE = 'downgrade';
|
||||
|
||||
const VERSION_NULL = '0.0.0';
|
||||
|
||||
protected $_installVersions = array();
|
||||
protected $_upgradeVersions = array();
|
||||
protected $_uninstallVersions = array();
|
||||
protected $_downgradeVersions = array();
|
||||
|
||||
protected $_finalVersion = null;
|
||||
|
||||
protected $_scripts = array();
|
||||
|
||||
public function __construct($path, $fromVersion = null, $toVersion = null)
|
||||
{
|
||||
try {
|
||||
$this->_analyzePath($path);
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($fromVersion === null) {
|
||||
$fromVersion = '0.0.0';
|
||||
}
|
||||
|
||||
if ($toVersion === null) {
|
||||
$toVersion = '0.0.0';
|
||||
}
|
||||
|
||||
preg_match(self::PCRE_VERSION_PATTERN, $fromVersion, $matches);
|
||||
$fromVersion = array(
|
||||
'version' => isset($matches['version']) ? $matches['version'] : self::VERSION_NULL,
|
||||
'stage' => isset($matches['stage']) && !empty($matches['stage']) ? $matches['stage'] : self::STAGE_STABLE,
|
||||
'level' => isset($matches['level']) && !empty($matches['level']) ? (int) $matches['level'] : 0,
|
||||
);
|
||||
|
||||
preg_match(self::PCRE_VERSION_PATTERN, $toVersion, $matches);
|
||||
$toVersion = array(
|
||||
'version' => isset($matches['version']) ? $matches['version'] : self::VERSION_NULL,
|
||||
'stage' => isset($matches['stage']) && !empty($matches['stage']) ? $matches['stage'] : self::STAGE_STABLE,
|
||||
'level' => isset($matches['level']) && !empty($matches['level']) ? (int) $matches['level'] : 0,
|
||||
);
|
||||
|
||||
switch (version_compare($toVersion['version'], $fromVersion['version'])) {
|
||||
case 1:
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
break;
|
||||
|
||||
case -1:
|
||||
$this->_downgradeToVersion($fromVersion, $toVersion);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if ($toVersion['stage'] === self::STAGE_STABLE) {
|
||||
if ($fromVersion['stage'] !== self::STAGE_STABLE) {
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
} else {
|
||||
$this->_downgradeToVersion($fromVersion, $toVersion);
|
||||
}
|
||||
} else if ($toVersion['stage'] === self::STAGE_RC) {
|
||||
if ($fromVersion['stage'] === self::STAGE_STABLE) {
|
||||
$this->_downgradeToVersion($fromVersion, $toVersion);
|
||||
} else if ($fromVersion['stage'] === self::STAGE_RC) {
|
||||
if ($fromVersion['level'] < $toVersion['level']) {
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
} else {
|
||||
// throw new Wootook_Core_Exception_RuntimeException("Version already installed.");
|
||||
}
|
||||
} else {
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
}
|
||||
} else if ($toVersion['stage'] === self::STAGE_BETA) {
|
||||
if (in_array($fromVersion['stage'], array(self::STAGE_STABLE, self::STAGE_RC))) {
|
||||
$this->_downgradeToVersion($fromVersion, $toVersion);
|
||||
} else if ($fromVersion['stage'] === self::STAGE_BETA) {
|
||||
if ($fromVersion['level'] < $toVersion['level']) {
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
} else {
|
||||
// throw new Wootook_Core_Exception_RuntimeException("Version already installed.");
|
||||
}
|
||||
} else {
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
}
|
||||
} else if ($toVersion['stage'] === self::STAGE_ALPHA) {
|
||||
if (in_array($fromVersion['stage'], array(self::STAGE_STABLE, self::STAGE_RC, self::STAGE_BETA))) {
|
||||
$this->_downgradeToVersion($fromVersion, $toVersion);
|
||||
} else if ($fromVersion['stage'] === self::STAGE_ALPHA) {
|
||||
if ($fromVersion['level'] < $toVersion['level']) {
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
} else {
|
||||
// throw new Wootook_Core_Exception_RuntimeException("Version already installed.");
|
||||
}
|
||||
} else {
|
||||
$this->_upgradeToVersion($fromVersion, $toVersion);
|
||||
}
|
||||
} else {
|
||||
throw new Wootook_Core_Exception_RuntimeException("Invalid version stage.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFinalVersion()
|
||||
{
|
||||
return $this->_finalVersion;
|
||||
}
|
||||
|
||||
protected function _installHighestInstaller($currentVersion, $toVersion)
|
||||
{
|
||||
$highestVersion = self::VERSION_NULL;
|
||||
foreach (array_keys($this->_installVersions) as $version) {
|
||||
if (version_compare($version, $highestVersion, '>') && version_compare($version, $toVersion['version'], '<=')) {
|
||||
$highestVersion = $version;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->_installVersions[$highestVersion][self::STAGE_STABLE][0])) {
|
||||
$version = array(
|
||||
'version' => $highestVersion,
|
||||
'stage' => self::STAGE_STABLE,
|
||||
'level' => 0,
|
||||
);
|
||||
$this->enqueue(array($version, $this->_installVersions[$highestVersion][self::STAGE_STABLE][0]));
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
if (isset($this->_installVersions[$highestVersion][self::STAGE_RC])) {
|
||||
$stage = self::STAGE_RC;
|
||||
} else if (isset($this->_installVersions[$highestVersion][self::STAGE_BETA])) {
|
||||
$stage = self::STAGE_BETA;
|
||||
} else if (isset($this->_installVersions[$highestVersion][self::STAGE_ALPHA])) {
|
||||
$stage = self::STAGE_ALPHA;
|
||||
} else {
|
||||
throw new Wootook_Core_Exception_RuntimeException("Invalid version stage.");
|
||||
}
|
||||
|
||||
$levelList = array_keys($this->_installVersions[$highestVersion][$stage]);
|
||||
|
||||
$highestLevel = 0;
|
||||
foreach ($levelList as $level) {
|
||||
if ($level > $highestLevel) {
|
||||
$highestLevel = $level;
|
||||
}
|
||||
}
|
||||
|
||||
$version = array(
|
||||
'version' => $highestVersion,
|
||||
'stage' => $stage,
|
||||
'level' => $highestLevel,
|
||||
);
|
||||
|
||||
$this->enqueue(array($version, $this->_installVersions[$highestVersion][$stage][$highestLevel]));
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
protected function _downgradeToVersion($fromVersion, $toVersion)
|
||||
{
|
||||
throw new Wootook_Core_Exception_RuntimeException("Downgrade isn't yet implemented.");
|
||||
}
|
||||
|
||||
protected function _upgradeToVersion($fromVersion, $toVersion)
|
||||
{
|
||||
$currentVersion = $fromVersion;
|
||||
|
||||
if ($fromVersion['version'] === self::VERSION_NULL) {
|
||||
// run the higher install script
|
||||
$currentVersion = $this->_installHighestInstaller($currentVersion, $toVersion);
|
||||
}
|
||||
|
||||
$upgradeVersions = $this->_upgradeVersions;
|
||||
while (true) {
|
||||
|
||||
if ($currentVersion['version'] === $toVersion['version'] &&
|
||||
$currentVersion['stage'] === $toVersion['stage'] &&
|
||||
$currentVersion['level'] === $toVersion['level']) {
|
||||
break;
|
||||
}
|
||||
|
||||
$versionPointer = &$upgradeVersions[$currentVersion['version']][$currentVersion['stage']][$currentVersion['level']];
|
||||
if (empty($versionPointer)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$highestVersion = $currentVersion['version'];
|
||||
foreach ($versionPointer as $version => $stages) {
|
||||
if (version_compare($version, $highestVersion['version'], '>') && version_compare($version, $toVersion['version'], '<=')) {
|
||||
$highestVersion = $version;
|
||||
}
|
||||
}
|
||||
|
||||
if (version_compare($highestVersion, $toVersion['version'], '<')) {
|
||||
$stage = self::STAGE_STABLE;
|
||||
$level = 0;
|
||||
} else if (version_compare($highestVersion, $toVersion['version']) === 0) {
|
||||
if (isset($versionPointer[$highestVersion][self::STAGE_STABLE]) && $toVersion['stage'] === self::STAGE_STABLE) {
|
||||
$stage = self::STAGE_STABLE;
|
||||
} else if (isset($versionPointer[$highestVersion][self::STAGE_RC]) &&
|
||||
in_array($toVersion['stage'], array(self::STAGE_RC, self::STAGE_STABLE))) {
|
||||
|
||||
$stage = self::STAGE_RC;
|
||||
} else if (isset($versionPointer[$highestVersion][self::STAGE_BETA]) &&
|
||||
in_array($toVersion['stage'], array(self::STAGE_RC, self::STAGE_STABLE, self::STAGE_BETA))) {
|
||||
|
||||
$stage = self::STAGE_BETA;
|
||||
} else if (isset($versionPointer[$highestVersion][self::STAGE_ALPHA]) &&
|
||||
in_array($toVersion['stage'], array(self::STAGE_RC, self::STAGE_STABLE, self::STAGE_BETA, self::STAGE_ALPHA))) {
|
||||
|
||||
$stage = self::STAGE_ALPHA;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
$level = max(array_keys($versionPointer[$highestVersion][$stage]));
|
||||
} else {
|
||||
throw new Wootook_Core_Exception_RuntimeException("Invalid version value.");
|
||||
}
|
||||
|
||||
$currentVersion = array(
|
||||
'version' => $highestVersion,
|
||||
'stage' => $stage,
|
||||
'level' => $level
|
||||
);
|
||||
$this->enqueue(array($currentVersion, $versionPointer[$highestVersion][$stage][$level]));
|
||||
}
|
||||
|
||||
$this->_finalVersion = $currentVersion;
|
||||
}
|
||||
|
||||
protected function _analyzePath($path)
|
||||
{
|
||||
$iterator = new DirectoryIterator($path);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isDir() || $file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!preg_match(self::PCRE_FILE_PATTERN, $file->getBasename('.php'), $matches)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($matches['action']) {
|
||||
case self::MODE_INSTALL:
|
||||
$this->_addInstallFile(
|
||||
$file->getPathname(),
|
||||
$matches['version1'],
|
||||
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
|
||||
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0)
|
||||
);
|
||||
break;
|
||||
|
||||
case self::MODE_UNINSTALL:
|
||||
$this->_addUninstallFile(
|
||||
$file->getPathname(),
|
||||
$matches['version1'],
|
||||
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
|
||||
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0)
|
||||
);
|
||||
break;
|
||||
|
||||
case self::MODE_UPGRADE:
|
||||
$this->_addUpgradeFile(
|
||||
$file->getPathname(),
|
||||
$matches['version1'],
|
||||
$matches['version2'],
|
||||
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
|
||||
(isset($matches['stage2']) && !empty($matches['stage2']) ? $matches['stage2'] : self::STAGE_STABLE),
|
||||
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0),
|
||||
(isset($matches['level2']) && !empty($matches['level2']) ? (int) $matches['level2'] : 0)
|
||||
);
|
||||
break;
|
||||
|
||||
case self::MODE_DOWNGRADE:
|
||||
$this->_addDowngradeFile(
|
||||
$file->getPathname(),
|
||||
$matches['version1'],
|
||||
$matches['version2'],
|
||||
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
|
||||
(isset($matches['stage2']) && !empty($matches['stage2']) ? $matches['stage2'] : self::STAGE_STABLE),
|
||||
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0),
|
||||
(isset($matches['level2']) && !empty($matches['level2']) ? (int) $matches['level2'] : 0)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _addInstallFile($file, $version, $stage = self::STAGE_STABLE, $level = null)
|
||||
{
|
||||
if (!isset($this->_installVersions[$version])) {
|
||||
$this->_installVersions[$version] = array();
|
||||
}
|
||||
if (!isset($this->_installVersions[$version][$stage])) {
|
||||
$this->_installVersions[$version][$stage] = array();
|
||||
}
|
||||
|
||||
$this->_installVersions[$version][$stage][$level] = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function _addUpgradeFile($file, $upperVersion, $lowerVersion, $upperStage = self::STAGE_STABLE, $lowerStage = self::STAGE_STABLE, $upperLevel = null, $lowerLevel = null)
|
||||
{
|
||||
if (!isset($this->_upgradeVersions[$upperVersion])) {
|
||||
$this->_upgradeVersions[$upperVersion] = array();
|
||||
}
|
||||
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage])) {
|
||||
$this->_upgradeVersions[$upperVersion][$upperStage] = array();
|
||||
}
|
||||
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel])) {
|
||||
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel] = array();
|
||||
}
|
||||
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion])) {
|
||||
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion] = array();
|
||||
}
|
||||
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage])) {
|
||||
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage] = array();
|
||||
}
|
||||
|
||||
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage][$lowerLevel] = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function _addUninstallFile($file, $version, $stage = self::STAGE_STABLE, $level = null)
|
||||
{
|
||||
if (!isset($this->_uninstallVersions[$version])) {
|
||||
$this->_uninstallVersions[$version] = array();
|
||||
}
|
||||
if (!isset($this->_uninstallVersions[$version][$stage])) {
|
||||
$this->_uninstallVersions[$version][$stage] = array();
|
||||
}
|
||||
|
||||
$this->_uninstallVersions[$version][$stage][$level] = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function _addDowngradeFile($file, $upperVersion, $lowerVersion, $upperStage = self::STAGE_STABLE, $lowerStage = self::STAGE_STABLE, $upperLevel = null, $lowerLevel = null)
|
||||
{
|
||||
if (!isset($this->_downgradeVersions[$upperVersion])) {
|
||||
$this->_downgradeVersions[$upperVersion] = array();
|
||||
}
|
||||
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage])) {
|
||||
$this->_downgradeVersions[$upperVersion][$upperStage] = array();
|
||||
}
|
||||
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel])) {
|
||||
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel] = array();
|
||||
}
|
||||
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion])) {
|
||||
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion] = array();
|
||||
}
|
||||
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage])) {
|
||||
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage] = array();
|
||||
}
|
||||
|
||||
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage][$lowerLevel] = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->_scripts);
|
||||
}
|
||||
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists($offset, $this->_scripts);
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->_scripts[(int) $offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
if ($this->offsetExists($offset)) {
|
||||
return $this->_scripts[(int) $offset];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
if ($this->offsetExists($offset)) {
|
||||
unset($this->_scripts[(int) $offset]);
|
||||
}
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return current($this->_scripts);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->_scripts);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
next($this->_scripts);
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_scripts);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return (bool) (key($this->_scripts) !== null);
|
||||
}
|
||||
|
||||
public function enqueue($data)
|
||||
{
|
||||
$this->_scripts[] = array(
|
||||
'script' => $data[1],
|
||||
'version' => $data[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
6
application/code/core/Wootook/Core/Singleton.php
Normal file
6
application/code/core/Wootook/Core/Singleton.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
interface Wootook_Core_Singleton
|
||||
{
|
||||
public static function getSingleton();
|
||||
}
|
||||
13
application/code/core/Wootook/Core/Time.php
Normal file
13
application/code/core/Wootook/Core/Time.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
|
||||
class Wootook_Core_Time
|
||||
{
|
||||
public static function init()
|
||||
{
|
||||
$config = include ROOT_PATH . 'config.php';
|
||||
$timezone = $config['global']['date']['timezone'];
|
||||
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
}
|
||||
252
application/code/core/Wootook/Core/View.php
Normal file
252
application/code/core/Wootook/Core/View.php
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_View
|
||||
extends Wootook_Object
|
||||
{
|
||||
protected $_template = null;
|
||||
protected $_partials = array();
|
||||
protected $_layout = null;
|
||||
protected $_nameInLayout = null;
|
||||
|
||||
protected $_scriptPath = null;
|
||||
|
||||
public function __construct(Array $data = array())
|
||||
{
|
||||
if (isset($data['template'])) {
|
||||
$this->_template = $data['template'];
|
||||
unset($data['template']);
|
||||
}
|
||||
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
protected function _prepareRender()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderNumber($number)
|
||||
{
|
||||
return Math::render($number);
|
||||
}
|
||||
|
||||
public function renderTime($time, $unique = false)
|
||||
{
|
||||
if ($time >= 10) {
|
||||
$seconds = $time % 60;
|
||||
$minutes = (int) (($time - $seconds) / 60) % 60;
|
||||
$hours = (int) ((($time - $seconds) / 60) - $minutes) / 60;
|
||||
|
||||
if ($hours > 24) {
|
||||
$dayHours = (int) $hours % 24;
|
||||
$days = (int) ($hours - $dayHours) / 24;
|
||||
|
||||
return $this->__('%1$d day(s) and %2$d hour(s)', $days, $dayHours);
|
||||
} else if ($hours > 0) {
|
||||
return $this->__('%1$d hour(s), %2$d minute(s) and %3$d second(s)', $hours, $minutes, $seconds);
|
||||
} else if ($minutes > 0) {
|
||||
return $this->__('%1$d minute(s) and %2$d second(s)', $minutes, $seconds);
|
||||
} else {
|
||||
return $this->__('%1$d second(s)', $seconds);
|
||||
}
|
||||
} else if (!$unique && $time > 0) {
|
||||
return $this->__('%1$d per minute', 60 / $time);
|
||||
} else {
|
||||
return $this->__('instantaneous');
|
||||
}
|
||||
}
|
||||
|
||||
protected function escape($unescaped)
|
||||
{
|
||||
return htmlspecialchars($unescaped, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
public function __($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return Wootook::translate(Wootook::getDefaultLocale(), $message, $args);
|
||||
}
|
||||
|
||||
public function translate($message, $_ = null)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
return Wootook::translate(Wootook::getLocale(), $message, $args);
|
||||
}
|
||||
|
||||
public function renderScript($file)
|
||||
{
|
||||
$this->_prepareRender();
|
||||
|
||||
$templatePath = $this->_getTemplatePath($file);
|
||||
if ($templatePath !== null) {
|
||||
ob_start();
|
||||
include $this->_getTemplatePath($file);
|
||||
$contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $contents;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function _getTemplatePath($file)
|
||||
{
|
||||
return $this->getScriptPath() . DIRECTORY_SEPARATOR . $file;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$template = $this->getTemplate();
|
||||
if (empty($template)) {
|
||||
return null;
|
||||
}
|
||||
return $this->renderScript($template);
|
||||
}
|
||||
|
||||
public function setTemplate($template)
|
||||
{
|
||||
$this->_template = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTemplate()
|
||||
{
|
||||
return $this->_template;
|
||||
}
|
||||
|
||||
public function getUrl($uri, Array $params = array())
|
||||
{
|
||||
return Wootook::getUrl($uri, $params);
|
||||
}
|
||||
|
||||
public function getSkinUrl($uri, Array $params = array())
|
||||
{
|
||||
$package = $this->getLayout()->getPackage();
|
||||
if (empty($package)) {
|
||||
$package = Wootook_Core_Layout::DEFAULT_PACKAGE;
|
||||
}
|
||||
|
||||
$user = Wootook_Empire_Model_User::getSingleton();
|
||||
if ($user !== null && $user->getId()) {
|
||||
$theme = $user->getSkinPath();
|
||||
}
|
||||
if (empty($theme)) {
|
||||
$theme = $this->getLayout()->getTheme();
|
||||
}
|
||||
if (empty($theme)) {
|
||||
$theme = Wootook_Core_Layout::DEFAULT_THEME;
|
||||
}
|
||||
|
||||
return Wootook::getSkinUrl($package, $theme, $uri, $params);
|
||||
}
|
||||
|
||||
public function setPartial($name, $content)
|
||||
{
|
||||
if (!is_string($content) && !$content instanceof self) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->_partials[$name] = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPartial($name)
|
||||
{
|
||||
return $this->_partials[$name];
|
||||
}
|
||||
|
||||
public function getAllPartials()
|
||||
{
|
||||
return $this->_partials;
|
||||
}
|
||||
|
||||
public function unsetPartial($name)
|
||||
{
|
||||
if (isset($this->_partials[$name])) {
|
||||
unset($this->_partials[$name]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasPartial($name)
|
||||
{
|
||||
return isset($this->_partials[$name]) && (is_string($this->_partials[$name]) || $this->_partials[$name] instanceof self);
|
||||
}
|
||||
|
||||
public function __set($name, $content)
|
||||
{
|
||||
return $this->setPartial($name, $content);
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
$name = str_replace(' ', '', ucwords(str_replace('-', ' ', $name)));
|
||||
$name[0] = strtolower($name[0]);
|
||||
return $this->getPartial($name);
|
||||
}
|
||||
|
||||
public function __unset($name)
|
||||
{
|
||||
return $this->unsetPartial($name);
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
{
|
||||
return $this->hasPartial($name);
|
||||
}
|
||||
|
||||
public function setLayout($layout)
|
||||
{
|
||||
$this->_layout = $layout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Wootook_Core_Layout
|
||||
*/
|
||||
public function getLayout()
|
||||
{
|
||||
return $this->_layout;
|
||||
}
|
||||
|
||||
public function prepareLayout()
|
||||
{
|
||||
}
|
||||
|
||||
public function beforeToHtml()
|
||||
{
|
||||
}
|
||||
|
||||
public function setNameInLayout($name)
|
||||
{
|
||||
$this->_nameInLayout = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameInLayout()
|
||||
{
|
||||
return $this->_nameInLayout;
|
||||
}
|
||||
|
||||
public function setScriptPath($scriptPath)
|
||||
{
|
||||
$this->_scriptPath = $scriptPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getScriptPath()
|
||||
{
|
||||
return $this->_scriptPath;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,792 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license Modified BSD
|
||||
* @see https://github.com/gplanchat/one.platform
|
||||
*
|
||||
* Copyright (c) 2009-2010, Grégory PLANCHAT <g.planchat at gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Grégory PLANCHAT nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* --> 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 One.Platform.
|
||||
*
|
||||
*/
|
||||
|
||||
$this->setSetupConnection('legacies_setup');
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/aks')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(50) NULL,
|
||||
`teilnehmer` TEXT NULL,
|
||||
`flotten` TEXT NULL,
|
||||
`ankunft` INT UNSIGNED NULL,
|
||||
`galaxy` TINYINT UNSIGNED NULL,
|
||||
`system` SMALLINT UNSIGNED NULL,
|
||||
`planet` TINYINT UNSIGNED NULL,
|
||||
`eingeladen` INT UNSIGNED NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/aks', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/aks', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/aks', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/alliance')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`ally_name` VARCHAR(32) NOT NULL,
|
||||
`ally_tag` VARCHAR(8) NOT NULL,
|
||||
`ally_owner` BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`ally_register_time` TIMESTAMP NOT NULL,
|
||||
`ally_description` TEXT NULL,
|
||||
`ally_web` VARCHAR(255) NULL,
|
||||
`ally_text` TEXT NULL,
|
||||
`ally_image` VARCHAR(255) NULL,
|
||||
`ally_request` TEXT NULL,
|
||||
`ally_request_waiting` TEXT NULL,
|
||||
`ally_request_notallow` BOOL NOT NULL DEFAULT FALSE,
|
||||
`ally_owner_range` VARCHAR(32) NULL,
|
||||
`ally_ranks` TEXT NULL,
|
||||
`ally_members` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/alliance', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/alliance', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/alliance', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/annonce')} (
|
||||
`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`user` TEXT NOT NULL,
|
||||
`galaxie` TINYINT UNSIGNED NOT NULL,
|
||||
`systeme` SMALLINT UNSIGNED NOT NULL,
|
||||
`metala` DECIMAL(65,0) NOT NULL,
|
||||
`cristala` DECIMAL(65,0) NOT NULL,
|
||||
`deuta` DECIMAL(65,0) NOT NULL,
|
||||
`metals` DECIMAL(65,0) NOT NULL,
|
||||
`cristals` DECIMAL(65,0) NOT NULL,
|
||||
`deuts` DECIMAL(65,0) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/annonce', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/annonce', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/annonce', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/banned')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`who` BIGINT UNSIGNED NOT NULL,
|
||||
`theme` TEXT NOT NULL,
|
||||
`who2` BIGINT UNSIGNED NOT NULL,
|
||||
`time` TIMESTAMP NOT NULL,
|
||||
`longer` INT UNSIGNED NOT NULL DEFAULT 3600,
|
||||
`author` BIGINT UNSIGNED NOT NULL,
|
||||
`email` VARCHAR(100) NOT NULL,
|
||||
KEY `ID` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/banned', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/banned', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/banned', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/buddy')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`sender` BIGINT UNSIGNED NOT NULL,
|
||||
`owner` BIGINT UNSIGNED NOT NULL,
|
||||
`active` BOOL NOT NULL DEFAULT TRUE,
|
||||
`text` TEXT,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/buddy', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/buddy', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/buddy', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/chat')} (
|
||||
`messageid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`user` VARCHAR(255) NOT NULL,
|
||||
`message` TEXT NOT NULL,
|
||||
`timestamp` TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (`messageid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/chat', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/chat', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/chat', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/config')} (
|
||||
`config_name` VARCHAR(64) NOT NULL,
|
||||
`config_value` TEXT NOT NULL,
|
||||
UNIQUE KEY (`config_name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/config', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/config', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/config', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
INSERT INTO {$this->getTableName('legacies/config')} (`config_name`, `config_value`) VALUES
|
||||
('game_speed', '2500'),
|
||||
('fleet_speed', '2500'),
|
||||
('resource_multiplier', '1000'),
|
||||
('Fleet_Cdr', '30'),
|
||||
('Defs_Cdr', '30'),
|
||||
('initial_fields', '5000'),
|
||||
('COOKIE_NAME', 'xnova-legacies'),
|
||||
('game_name', 'Wootook:Legacies'),
|
||||
('game_disable', '1'),
|
||||
('close_reason', 'Le jeu est clos pour le moment!'),
|
||||
('metal_basic_income', '20'),
|
||||
('crystal_basic_income', '10'),
|
||||
('deuterium_basic_income', '0'),
|
||||
('energy_basic_income', '0'),
|
||||
('BuildLabWhileRun', '0'),
|
||||
('LastSettedGalaxyPos', '1'),
|
||||
('LastSettedSystemPos', '1'),
|
||||
('LastSettedPlanetPos', '1'),
|
||||
('urlaubs_modus_erz', '1'),
|
||||
('noobprotection', '1'),
|
||||
('noobprotectiontime', '5000'),
|
||||
('noobprotectionmulti', '5'),
|
||||
('forum_url', 'http://board.xnova-ng.org/'),
|
||||
('OverviewNewsFrame', '1'),
|
||||
('OverviewNewsTEXT', 'Bienvenue sur le nouveau serveur Wootook Legacies'),
|
||||
('OverviewExternChat', '0'),
|
||||
('OverviewExternChatCmd', ''),
|
||||
('OverviewBanner', '0'),
|
||||
('OverviewClickBanner', ''),
|
||||
('ExtCopyFrame', '0'),
|
||||
('ExtCopyOwner', ''),
|
||||
('ExtCopyFunct', ''),
|
||||
('ForumBannerFrame', '0'),
|
||||
('stat_settings', '1000'),
|
||||
('link_enable', '0'),
|
||||
('link_name', ''),
|
||||
('link_url', ''),
|
||||
('enable_announces', '1'),
|
||||
('enable_marchand', '1'),
|
||||
('enable_notes', '1'),
|
||||
('bot_name', 'XNoviana Reali'),
|
||||
('bot_adress', 'xnova@xnova.fr'),
|
||||
('banner_source_post', '../images/bann.png'),
|
||||
('ban_duration', '30'),
|
||||
('enable_bot', '0'),
|
||||
('enable_bbcode', '1'),
|
||||
('debug', '0');
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/declared')} (
|
||||
`declarator` TEXT NOT NULL,
|
||||
`declared_1` TEXT NOT NULL,
|
||||
`declared_2` TEXT NOT NULL,
|
||||
`declared_3` TEXT NOT NULL,
|
||||
`reason` TEXT NOT NULL,
|
||||
`declarator_name` TEXT NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/declared', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/declared', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/declared', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/errors')} (
|
||||
`error_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`error_sender` VARCHAR(32) NOT NULL,
|
||||
`error_time` TIMESTAMP NOT NULL,
|
||||
`error_type` VARCHAR(32) NOT NULL DEFAULT 'unknown',
|
||||
`error_text` TEXT,
|
||||
PRIMARY KEY (`error_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/errors', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/errors', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/errors', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/fleets')} (
|
||||
`fleet_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`fleet_owner` BIGINT UNSIGNED NOT NULL,
|
||||
`fleet_mission` TINYINT UNSIGNED NOT NULL,
|
||||
`fleet_amount` DECIMAL(65,0) NOT NULL,
|
||||
`fleet_array` TEXT NULL,
|
||||
`fleet_start_time` TIMESTAMP NOT NULL,
|
||||
`fleet_start_galaxy` TINYINT UNSIGNED NOT NULL,
|
||||
`fleet_start_system` SMALLINT UNSIGNED NOT NULL,
|
||||
`fleet_start_planet` TINYINT UNSIGNED NOT NULL,
|
||||
`fleet_start_type` TINYINT UNSIGNED NOT NULL,
|
||||
`fleet_end_time` TIMESTAMP NOT NULL,
|
||||
`fleet_end_stay` TIMESTAMP NOT NULL,
|
||||
`fleet_end_galaxy` TINYINT UNSIGNED NOT NULL,
|
||||
`fleet_end_system` SMALLINT UNSIGNED NOT NULL,
|
||||
`fleet_end_planet` TINYINT UNSIGNED NOT NULL,
|
||||
`fleet_end_type` TINYINT UNSIGNED NOT NULL,
|
||||
`fleet_taget_owner` BIGINT UNSIGNED NOT NULL,
|
||||
`fleet_resource_metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`fleet_resource_crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`fleet_resource_deuterium` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`fleet_target_owner` BIGINT UNSIGNED NOT NULL,
|
||||
`fleet_group` BIGINT UNSIGNED NOT NULL,
|
||||
`fleet_mess` BIGINT UNSIGNED NOT NULL,
|
||||
`start_time` INT,
|
||||
PRIMARY KEY (`fleet_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/fleets', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/fleets', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/fleets', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/galaxy')} (
|
||||
`galaxy` TINYINT UNSIGNED NOT NULL,
|
||||
`system` SMALLINT UNSIGNED NOT NULL,
|
||||
`planet` TINYINT UNSIGNED NOT NULL,
|
||||
`id_planet` BIGINT UNSIGNED NOT NULL,
|
||||
`metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`id_luna` BIGINT UNSIGNED NULL,
|
||||
`luna` BOOL NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY (`galaxy`, `system`, `planet`),
|
||||
KEY `galaxy` (`galaxy`),
|
||||
KEY `system` (`system`),
|
||||
KEY `planet` (`planet`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/galaxy', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/galaxy', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/galaxy', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/iraks')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`zeit` TIMESTAMP NOT NULL,
|
||||
`galaxy` TINYINT UNSIGNED NOT NULL,
|
||||
`system` SMALLINT UNSIGNED NOT NULL,
|
||||
`planet` TINYINT UNSIGNED NOT NULL,
|
||||
`galaxy_angreifer` TINYINT UNSIGNED NOT NULL,
|
||||
`system_angreifer` SMALLINT UNSIGNED NOT NULL,
|
||||
`planet_angreifer` TINYINT UNSIGNED NOT NULL,
|
||||
`owner` BIGINT UNSIGNED NOT NULL,
|
||||
`zielid` BIGINT UNSIGNED NOT NULL,
|
||||
`anzahl` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`primaer` SMALLINT UNSIGNED,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/iraks', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/iraks', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/iraks', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/lunas')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_luna` BIGINT UNSIGNED NOT NULL,
|
||||
`name` VARCHAR(100) NOT NULL DEFAULT 'Lune',
|
||||
`image` VARCHAR(50) NOT NULL DEFAULT 'mond',
|
||||
`destruyed` BOOL NOT NULL DEFAULT FALSE,
|
||||
`id_owner` BIGINT UNSIGNED NOT NULL,
|
||||
`galaxy` TINYINT UNSIGNED NOT NULL,
|
||||
`system` SMALLINT UNSIGNED NOT NULL,
|
||||
`lunapos` TINYINT UNSIGNED NOT NULL,
|
||||
`temp_min` TINYINT NOT NULL DEFAULT 0,
|
||||
`temp_max` TINYINT NOT NULL DEFAULT 0,
|
||||
`diameter` INT UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/lunas', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/lunas', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/lunas', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/messages')} (
|
||||
`message_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`message_owner` BIGINT UNSIGNED NOT NULL,
|
||||
`message_sender` BIGINT UNSIGNED NOT NULL,
|
||||
`message_time` TIMESTAMP NOT NULL,
|
||||
`message_type` TINYINT UNSIGNED NOT NULL,
|
||||
`message_from` VARCHAR(50),
|
||||
`message_subject` VARCHAR(150),
|
||||
`message_text` TEXT,
|
||||
PRIMARY KEY (`message_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/messages', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/messages', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/messages', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/multi')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`player` BIGINT UNSIGNED NOT NULL,
|
||||
`sharer` BIGINT UNSIGNED NOT NULL,
|
||||
`reason` TEXT NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/multi', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/multi', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/multi', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/notes')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`owner` BIGINT UNSIGNED NOT NULL,
|
||||
`time` TIMESTAMP NOT NULL,
|
||||
`priority` TINYINT UNSIGNED NOT NULL,
|
||||
`title` VARCHAR(32) NOT NULL,
|
||||
`TEXT` TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/notes', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/notes', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/notes', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/planets')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`id_owner` BIGINT UNSIGNED NOT NULL,
|
||||
`id_level` TINYINT UNSIGNED NOT NULL,
|
||||
`galaxy` TINYINT UNSIGNED NOT NULL,
|
||||
`system` SMALLINT UNSIGNED NOT NULL,
|
||||
`planet` TINYINT UNSIGNED NOT NULL,
|
||||
`last_update` TIMESTAMP NOT NULL,
|
||||
`planet_type` TINYINT UNSIGNED NOT NULL,
|
||||
`destruyed` BOOL NOT NULL DEFAULT FALSE,
|
||||
`b_building` SMALLINT UNSIGNED NOT NULL,
|
||||
`b_building_id` TEXT NOT NULL,
|
||||
`b_tech` SMALLINT UNSIGNED NOT NULL,
|
||||
`b_tech_id` SMALLINT UNSIGNED NOT NULL,
|
||||
`b_hangar` SMALLINT UNSIGNED NOT NULL,
|
||||
`b_hangar_id` TEXT NOT NULL,
|
||||
`b_hangar_plus` SMALLINT UNSIGNED NOT NULL,
|
||||
`image` VARCHAR(50) NOT NULL DEFAULT 'normaltempplanet01',
|
||||
`diameter` INT UNSIGNED NOT NULL DEFAULT 12800,
|
||||
`points` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`ranks` BIGINT UNSIGNED NOT NULL,
|
||||
`field_current` INT UNSIGNED NOT NULL DEFAULT 163,
|
||||
`field_max` INT UNSIGNED NOT NULL DEFAULT 163,
|
||||
`temp_min` INT NOT NULL DEFAULT 0,
|
||||
`temp_max` INT NOT NULL DEFAULT 0,
|
||||
`metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`metal_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`metal_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`crystal_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`crystal_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`deuterium` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`deuterium_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`deuterium_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`energy_used` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`energy_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`metal_mine` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`crystal_mine` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`deuterium_sintetizer` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`solar_plant` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`fusion_plant` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`robot_factory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`nano_factory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`hangar` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`metal_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`crystal_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`deuterium_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`laboratory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`terraformer` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`ally_deposit` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`silo` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`mondbasis` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`phalanx` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`sprungtor` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`small_ship_cargo` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`big_ship_cargo` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`light_hunter` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`heavy_hunter` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`crusher` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`battle_ship` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`colonizer` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`recycler` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`spy_sonde` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`bomber_ship` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`solar_satelit` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`destructor` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`dearth_star` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`battleship` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`misil_launcher` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`small_laser` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`big_laser` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`gauss_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`ionic_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`buster_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
|
||||
`small_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0,
|
||||
`big_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0,
|
||||
`interceptor_misil` SMALLINT NOT NULL DEFAULT 0,
|
||||
`interplanetary_misil` SMALLINT NOT NULL DEFAULT 0,
|
||||
`metal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
|
||||
`crystal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
|
||||
`deuterium_sintetizer_porcent` TINYINT NOT NULL DEFAULT 10,
|
||||
`solar_plant_porcent` TINYINT NOT NULL DEFAULT 10,
|
||||
`fusion_plant_porcent` TINYINT NOT NULL DEFAULT 10,
|
||||
`solar_satelit_porcent` TINYINT NOT NULL DEFAULT 10,
|
||||
`last_jump_time` TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/planets', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/planets', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/planets', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/rw')} (
|
||||
`id_owner1` BIGINT UNSIGNED NOT NULL,
|
||||
`id_owner2` BIGINT UNSIGNED NOT NULL,
|
||||
`rid` VARCHAR(72) NOT NULL,
|
||||
`raport` LONGTEXT NOT NULL,
|
||||
`a_zestrzelona` TINYINT UNSIGNED NOT NULL,
|
||||
`time` TIMESTAMP NOT NULL,
|
||||
KEY (`rid`),
|
||||
UNIQUE KEY `id_owner1` (`id_owner1`,`rid`),
|
||||
UNIQUE KEY `id_owner2` (`id_owner2`,`rid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/rw', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/rw', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/rw', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/statpoints')} (
|
||||
`id_owner` BIGINT UNSIGNED NOT NULL,
|
||||
`id_ally` BIGINT UNSIGNED NOT NULL,
|
||||
`stat_type` TINYINT UNSIGNED NOT NULL,
|
||||
`stat_code` TINYINT UNSIGNED NOT NULL,
|
||||
`tech_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`tech_old_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`tech_points` DECIMAL(65,0) NOT NULL,
|
||||
`tech_count` BIGINT UNSIGNED NOT NULL,
|
||||
`build_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`build_old_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`build_points` DECIMAL(65,0) NOT NULL,
|
||||
`build_count` BIGINT UNSIGNED NOT NULL,
|
||||
`defs_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`defs_old_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`defs_points` DECIMAL(65,0) NOT NULL,
|
||||
`defs_count` BIGINT UNSIGNED NOT NULL,
|
||||
`fleet_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`fleet_old_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`fleet_points` DECIMAL(65,0) NOT NULL,
|
||||
`fleet_count` BIGINT UNSIGNED NOT NULL,
|
||||
`total_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`total_old_rank` BIGINT UNSIGNED NOT NULL,
|
||||
`total_points` DECIMAL(65,0) NOT NULL,
|
||||
`total_count` BIGINT UNSIGNED NOT NULL,
|
||||
`stat_date` TIMESTAMP NOT NULL,
|
||||
KEY (`tech_points`),
|
||||
KEY (`build_points`),
|
||||
KEY (`defs_points`),
|
||||
KEY (`fleet_points`),
|
||||
KEY (`total_points`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/statpoints', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/statpoints', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/statpoints', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/users')} (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`username` VARCHAR(100) NOT NULL, -- FIXME
|
||||
`password` VARCHAR(64) NOT NULL, -- FIXME
|
||||
`email` VARCHAR(200) NOT NULL, -- FIXME
|
||||
`email_2` VARCHAR(200) NOT NULL, -- FIXME
|
||||
`lang` VARCHAR(3) NOT NULL DEFAULT 'fr',
|
||||
`authlevel` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
|
||||
`sex` ENUM('M','F') NULL DEFAULT NULL,
|
||||
`avatar` VARCHAR(255) NULL DEFAULT NULL,
|
||||
`sign` TEXT NULL,
|
||||
`id_planet` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`galaxy` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`system` SMALLINT UNSIGNED NOT NULL, -- FIXME
|
||||
`planet` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`current_planet` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`user_lastip` VARCHAR(16) NOT NULL, -- FIXME
|
||||
`ip_at_reg` VARCHAR(16) NOT NULL, -- FIXME
|
||||
`user_agent` TEXT NOT NULL, -- FIXME
|
||||
`current_page` TEXT NOT NULL, -- FIXME
|
||||
`register_time` TIMESTAMP NOT NULL, -- FIXME
|
||||
`onlinetime` TIMESTAMP NOT NULL, -- FIXME
|
||||
`dpath` VARCHAR(255) NOT NULL, -- FIXME
|
||||
`design` TINYINT NOT NULL DEFAULT 1, -- FIXME
|
||||
`noipcheck` BOOL NOT NULL DEFAULT TRUE, -- FIXME
|
||||
`planet_sort` TINYINT NOT NULL DEFAULT 0, -- FIXME
|
||||
`planet_sort_order` TINYINT NOT NULL DEFAULT 0, -- FIXME
|
||||
`spio_anz` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
|
||||
`settings_tooltiptime` TINYINT UNSIGNED NOT NULL DEFAULT 5, -- FIXME
|
||||
`settings_fleetactions` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
|
||||
`settings_allylogo` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
|
||||
`settings_esp` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
|
||||
`settings_wri` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
|
||||
`settings_bud` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
|
||||
`settings_mis` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
|
||||
`settings_rep` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
|
||||
`urlaubs_modus` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
|
||||
`urlaubs_until` TIMESTAMP NOT NULL, -- FIXME
|
||||
`db_deaktjava` BOOL NOT NULL DEFAULT FALSE, -- FIXME
|
||||
`new_message` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
|
||||
`fleet_shortcut` TEXT NULL,
|
||||
`b_tech_planet` INT NOT NULL, -- FIXME
|
||||
`spy_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`computer_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`military_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`defence_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`shield_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`energy_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`hyperspace_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`combustion_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`impulse_motor_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`hyperspace_motor_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`laser_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`ionic_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`buster_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`intergalactic_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`expedition_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`graviton_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`ally_id` BIGINT UNSIGNED NOT NULL,
|
||||
`ally_name` VARCHAR(32) NULL, -- FIXME
|
||||
`ally_request` BOOL NOT NULL DEFAULT FALSE, -- FIXME
|
||||
`ally_request_text` TEXT NULL, -- FIXME
|
||||
`ally_register_time` TIMESTAMP NOT NULL, -- FIXME
|
||||
`ally_rank_id` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`current_luna` INT NOT NULL, -- FIXME
|
||||
`kolorminus` VARCHAR(11) NOT NULL DEFAULT 'red',
|
||||
`kolorplus` VARCHAR(11) NOT NULL DEFAULT '#00FF00',
|
||||
`kolorpoziom` VARCHAR(11) NOT NULL DEFAULT 'yellow',
|
||||
`rpg_geologue` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_amiral` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_ingenieur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_technocrate` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_espion` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_constructeur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_scientifique` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_commandant` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_points` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_stockeur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_defenseur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_destructeur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_general` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_bunker` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_raideur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`rpg_empereur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`lvl_minier` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`lvl_raid` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`xpraid` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`xpminier` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`raids` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`p_infligees` DECIMAL(65,0) NOT NULL, -- FIXME
|
||||
`mnl_alliance` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_joueur` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_attaque` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_spy` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_exploit` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_transport` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_expedition` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_general` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`mnl_buildlist` TINYINT UNSIGNED NOT NULL, -- FIXME
|
||||
`bana` BOOL NOT NULL DEFAULT FALSE, -- FIXME
|
||||
`multi_validated` BOOL NOT NULL DEFAULT FALSE, -- FIXME
|
||||
`banaday` TIMESTAMP NULL DEFAULT NULL, -- FIXME
|
||||
`raids1` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`raidswin` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
`raidsloose` BIGINT UNSIGNED NOT NULL, -- FIXME
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$this
|
||||
->grant('legacies/users', 'legacies_read', array('SELECT'))
|
||||
->grant('legacies/users', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
|
||||
->grant('legacies/users', 'legacies_setup')
|
||||
;
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
INSERT INTO {$this->getTableName('legacies/alliance')} (
|
||||
`id`, `ally_name`, `ally_tag`, `ally_owner`, `ally_register_time`, `ally_description`,
|
||||
`ally_web`, `ally_text`, `ally_image`, `ally_request`, `ally_request_waiting`,
|
||||
`ally_request_notallow`, `ally_owner_range`, `ally_ranks`, `ally_members`
|
||||
)
|
||||
VALUES
|
||||
('1', 'Admin', 'Admin', 1, NOW(), 'Administrator alliance', 'http://www.xnova-ng.org/',
|
||||
'', '', '', '', '', '', '', '')
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
INSERT INTO {$this->getTableName('legacies/users')} (
|
||||
`id`, `username`, `password`, `email`, `email_2`, `lang`, `authlevel`, `sex`,
|
||||
`avatar`, `sign`, `id_planet`, `galaxy`, `system`, `planet`, `current_planet`,
|
||||
`user_lastip`, `ip_at_reg`, `user_agent`, `current_page`, `register_time`,
|
||||
`onlinetime`, `dpath`, `design`, `noipcheck`, `planet_sort`, `planet_sort_order`,
|
||||
`spio_anz`, `settings_tooltiptime`, `settings_fleetactions`, `settings_allylogo`,
|
||||
`settings_esp`, `settings_wri`, `settings_bud`, `settings_mis`, `settings_rep`,
|
||||
`urlaubs_modus`, `urlaubs_until`, `db_deaktjava`, `new_message`, `fleet_shortcut`,
|
||||
`b_tech_planet`, `spy_tech`, `computer_tech`, `military_tech`, `defence_tech`,
|
||||
`shield_tech`, `energy_tech`, `hyperspace_tech`, `combustion_tech`,
|
||||
`impulse_motor_tech`, `hyperspace_motor_tech`, `laser_tech`, `ionic_tech`,
|
||||
`buster_tech`, `intergalactic_tech`, `expedition_tech`, `graviton_tech`,
|
||||
`ally_id`, `ally_name`, `ally_request`, `ally_request_text`, `ally_register_time`,
|
||||
`ally_rank_id`, `current_luna`, `kolorminus`, `kolorplus`, `kolorpoziom`,
|
||||
`rpg_geologue`, `rpg_amiral`, `rpg_ingenieur`, `rpg_technocrate`, `rpg_espion`,
|
||||
`rpg_constructeur`, `rpg_scientifique`, `rpg_commandant`, `rpg_points`, `rpg_stockeur`,
|
||||
`rpg_defenseur`, `rpg_destructeur`, `rpg_general`, `rpg_bunker`, `rpg_raideur`,
|
||||
`rpg_empereur`, `lvl_minier`, `lvl_raid`, `xpraid`, `xpminier`, `raids`,
|
||||
`p_infligees`, `mnl_alliance`, `mnl_joueur`, `mnl_attaque`, `mnl_spy`,
|
||||
`mnl_exploit`, `mnl_transport`, `mnl_expedition`, `mnl_general`, `mnl_buildlist`,
|
||||
`bana`, `multi_validated`, `banaday`, `raids1`, `raidswin`, `raidsloose`
|
||||
)
|
||||
VALUES
|
||||
('1', 'Admin', '', '', '', 'fr', '3', NULL, '', '', '1', '1', '1', '1',
|
||||
'1', '127.0.0.1', '', '', '', '1254743313', '1269391977', '', '1', '1', '0',
|
||||
'0', '1', '5', '0', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '', '0',
|
||||
'16', '20', '11', '11', '11', '12', '10', '14', '10', '9', '0', '0', '0', '0',
|
||||
'0', '1', 1, 'Admin', '0', '', NOW(), '0', '0', 'red', '#00FF00', 'yellow', '20',
|
||||
'20', '10', '10', '0', '3', '3', '0', '27', '2', '2', '0', '0', '0', '0', '0',
|
||||
'98', '1', '0', '1133583738', '0', '0', '0', '0', '0', '0', '0', '0', '0',
|
||||
'0', '0', '0', '0', '0', '0', '0', '0')
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Wootook
|
||||
*
|
||||
* @license Modified BSD
|
||||
* @see https://github.com/gplanchat/one.platform
|
||||
*
|
||||
* Copyright (c) 2009-2010, Grégory PLANCHAT <g.planchat at gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Grégory PLANCHAT nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* --> 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 One.Platform.
|
||||
*
|
||||
*/
|
||||
|
||||
$this->setSetupConnection('legacies_setup');
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/aks')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/alliance')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/annonce')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/banned')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/buddy')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/chat')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/config')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/declared')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/errors')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/fleets')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/galaxy')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/iraks')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/lunas')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/messages')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/multi')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/notes')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/planets')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/rw')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/statpoints')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
|
||||
$sql = <<<SQL_EOF
|
||||
DROP TABLE {$this->getTableName('legacies/users')};
|
||||
SQL_EOF;
|
||||
|
||||
$this->query($sql);
|
||||
51
application/code/core/Wootook/Database.php
Normal file
51
application/code/core/Wootook/Database.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Database
|
||||
extends PDO
|
||||
{
|
||||
protected static $_singleton = null;
|
||||
|
||||
protected static $_prefix = null;
|
||||
|
||||
public static $options = array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
$config = include ROOT_PATH . 'config.php';
|
||||
$hostname = $config['global']['database']['options']['hostname'];
|
||||
$username = $config['global']['database']['options']['username'];
|
||||
$password = $config['global']['database']['options']['password'];
|
||||
$database = $config['global']['database']['options']['database'];
|
||||
$port = 3306;
|
||||
|
||||
if (isset($config['global']['database']['options']['port'])) {
|
||||
$port = $config['global']['database']['options']['port'];
|
||||
}
|
||||
|
||||
$event = Wootook::dispatchEvent('database.prepare-options', array(
|
||||
'options' => self::$options
|
||||
));
|
||||
|
||||
self::$options = $event->getData('options');
|
||||
|
||||
self::$_singleton = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, self::$options);
|
||||
|
||||
Wootook::dispatchEvent('database.init', array(
|
||||
'handler' => self::$_singleton
|
||||
));
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
public function getTable($name)
|
||||
{
|
||||
if (self::$_prefix === null) {
|
||||
$config = include ROOT_PATH . 'config.php';
|
||||
self::$_prefix = $config['global']['database']['table_prefix'];
|
||||
}
|
||||
return self::$_prefix . $name;
|
||||
}
|
||||
}
|
||||
7
application/code/core/Wootook/Empire/Block/Overview.php
Normal file
7
application/code/core/Wootook/Empire/Block/Overview.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Overview
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Overview_DestroyPlanet
|
||||
extends Wootook_Core_Block_Html_Form
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Overview_RenamePlanet
|
||||
extends Wootook_Core_Block_Html_Form
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Empire_Block_Planet_Builder_ItemAbstract
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
protected $_user = null;
|
||||
protected $_planet = null;
|
||||
protected $_itemId = null;
|
||||
|
||||
public function setUser(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
if ($this->_user === null) {
|
||||
$this->_user = Wootook_Empire_Model_User::getSingleton();
|
||||
}
|
||||
|
||||
return $this->_user;
|
||||
}
|
||||
|
||||
public function setPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_planet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlanet()
|
||||
{
|
||||
if ($this->_planet === null) {
|
||||
$this->_planet = $this->getUser()->getCurrentPlanet();
|
||||
}
|
||||
|
||||
return $this->_planet;
|
||||
}
|
||||
|
||||
public function setItemId($itemId)
|
||||
{
|
||||
$this->_itemId = $itemId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemId()
|
||||
{
|
||||
return $this->_itemId;
|
||||
}
|
||||
|
||||
public function getItemInfoUrl()
|
||||
{
|
||||
return $this->getUrl('infos.php', array('gid' => $this->getItemId()));
|
||||
}
|
||||
|
||||
public function getItemImageUrl()
|
||||
{
|
||||
// TODO : Upgrade theme
|
||||
return $this->getSkinUrl('graphics/gebaeude/' . $this->getItemId() . '.gif');
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('tech');
|
||||
}
|
||||
|
||||
if (isset($lang['tech']) && isset($lang['tech'][$this->getItemId()])) {
|
||||
return $this->__($lang['tech'][$this->getItemId()]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('tech');
|
||||
}
|
||||
|
||||
if (isset($lang['res']) && isset($lang['res']['descriptions']) && isset($lang['res']['descriptions'][$this->getItemId()])) {
|
||||
return $this->__($lang['res']['descriptions'][$this->getItemId()]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getResourceName($resourceId)
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('imperium');
|
||||
}
|
||||
if ($resourceId == 'cristal') {
|
||||
$resourceId = 'crystal';
|
||||
}
|
||||
|
||||
if (isset($lang[$resourceId])) {
|
||||
return $this->__($lang[$resourceId]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getNextLevel()
|
||||
{
|
||||
return $this->getQueuedLevel() + 1;
|
||||
}
|
||||
|
||||
abstract public function getResourcesNeeded($level);
|
||||
|
||||
abstract public function getBuildingTime($level);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Empire_Block_Planet_Builder_Queue_ItemAbstract
|
||||
extends Wootook_Empire_Block_Planet_Builder_ItemAbstract
|
||||
{
|
||||
protected $_item = null;
|
||||
|
||||
protected $_itemIdField = null;
|
||||
|
||||
public function setItem(Wootook_Empire_Model_Builder_Item $item)
|
||||
{
|
||||
$this->_item = $item;
|
||||
$this->setItemId($item->getData($this->_itemIdField));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItem()
|
||||
{
|
||||
return $this->_item;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Empire_Block_Planet_Builder_QueueAbstract
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
protected $_user = null;
|
||||
protected $_planet = null;
|
||||
protected $_itemTemplate = null;
|
||||
protected $_itemBlock = null;
|
||||
|
||||
public function setUser(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
if ($this->_user === null) {
|
||||
$this->_user = Wootook_Empire_Model_User::getSingleton();
|
||||
}
|
||||
|
||||
return $this->_user;
|
||||
}
|
||||
|
||||
public function setPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_planet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlanet()
|
||||
{
|
||||
if ($this->_planet === null) {
|
||||
$this->_planet = $this->getUser()->getCurrentPlanet();
|
||||
}
|
||||
|
||||
return $this->_planet;
|
||||
}
|
||||
|
||||
public function setItemTemplate($template)
|
||||
{
|
||||
$this->_itemTemplate = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemTemplate()
|
||||
{
|
||||
return $this->_itemTemplate;
|
||||
}
|
||||
|
||||
public function setItemBlockType($blockType)
|
||||
{
|
||||
$this->_itemBlockType = $blockType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemBlockType()
|
||||
{
|
||||
return $this->_itemBlockType;
|
||||
}
|
||||
|
||||
public function getItemBlock(Wootook_Empire_Model_Builder_Item $item)
|
||||
{
|
||||
$index = $item->getIndex();
|
||||
$blockName = "item({$index})";
|
||||
|
||||
return $this->getLayout()
|
||||
->createBlock($this->getItemBlockType(), $blockName)
|
||||
->setTemplate($this->getItemTemplate())
|
||||
->setPlanet($this->getPlanet())
|
||||
->setItem($item);
|
||||
}
|
||||
|
||||
public function prepareLayout()
|
||||
{
|
||||
$parentBlock = $this->getLayout()
|
||||
->createBlock('core/concat', $this->getNameInLayout() . '.item-list')
|
||||
;
|
||||
$this->setPartial('item-list', $parentBlock);
|
||||
|
||||
foreach ($this->getQueue() as $item) {
|
||||
$block = $this->getItemBlock($item);
|
||||
$parentBlock->setPartial($block->getNameInLayout(), $block);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract public function getQueue();
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Empire_Block_Planet_BuilderAbstract
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
protected $_itemTemplate = null;
|
||||
protected $_itemBlock = null;
|
||||
|
||||
public function setItemTemplate($template)
|
||||
{
|
||||
$this->_itemTemplate = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemTemplate()
|
||||
{
|
||||
return $this->_itemTemplate;
|
||||
}
|
||||
|
||||
public function setItemBlockType($blockType)
|
||||
{
|
||||
$this->_itemBlockType = $blockType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemBlockType()
|
||||
{
|
||||
return $this->_itemBlockType;
|
||||
}
|
||||
|
||||
public function getItemBlock($itemId)
|
||||
{
|
||||
$blockName = "item({$itemId})";
|
||||
|
||||
return $this->getLayout()
|
||||
->createBlock($this->getItemBlockType(), $blockName)
|
||||
->setTemplate($this->getItemTemplate())
|
||||
->setPlanet($this->getPlanet())
|
||||
->setItemId($itemId);
|
||||
}
|
||||
|
||||
public function prepareLayout()
|
||||
{
|
||||
parent::prepareLayout();
|
||||
|
||||
$this->_initChildBlocks();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract protected function _initChildBlocks();
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Planet_Buildings
|
||||
extends Wootook_Empire_Block_Planet_BuilderAbstract
|
||||
{
|
||||
protected $_planet = null;
|
||||
|
||||
public function setPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_planet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlanet()
|
||||
{
|
||||
if ($this->_planet === null) {
|
||||
$this->_planet = Wootook_Empire_Model_User::getSingleton()
|
||||
->getCurrentPlanet()
|
||||
;
|
||||
}
|
||||
return $this->_planet;
|
||||
}
|
||||
|
||||
public function _initChildBlocks()
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
$type = Legacies_Empire::TYPE_BUILDING_PLANET;
|
||||
if ($this->getPlanet()->isMoon()) {
|
||||
$type = Legacies_Empire::TYPE_BUILDING_MOON;
|
||||
}
|
||||
|
||||
/** @var Wootook_Core_Block_Concat $parentBlock */
|
||||
$parentBlock = $this->getLayout()->getBlock('item-list.items');
|
||||
foreach ($types->getData($type) as $itemId) {
|
||||
if (!$this->getPlanet()->checkAvailability($itemId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$block = $this->getItemBlock($itemId);
|
||||
$parentBlock->setPartial($block->getName(), $block);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Planet_Buildings_Item
|
||||
extends Wootook_Empire_Block_Planet_Builder_ItemAbstract
|
||||
{
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->getPlanet()->getElement($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($level)
|
||||
{
|
||||
return $this->getPlanet()->getResourcesNeeded($this->getItemId(), $level);
|
||||
}
|
||||
|
||||
public function getQueuedLevel()
|
||||
{
|
||||
return $this->getPlanet()->getBuildingLevelQueued($this->getItemId());
|
||||
}
|
||||
|
||||
public function getBuildingTime($level)
|
||||
{
|
||||
return $this->getPlanet()->getBuildingTime($this->getItemId(), $level);
|
||||
}
|
||||
|
||||
public function getResourcesConfigForLevel($level)
|
||||
{
|
||||
$resources = $this->getResourcesNeeded($level);
|
||||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
||||
$amount = $this->getPlanet()->getResourceAmount($resourceId);
|
||||
if (Math::comp($amount, $resourceValue) < 0) {
|
||||
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
|
||||
} else {
|
||||
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
|
||||
}
|
||||
}
|
||||
return $resourceConfig;
|
||||
}
|
||||
|
||||
public function getResourcesConfigForNextLevel()
|
||||
{
|
||||
return $this->getResourcesConfigForLevel($this->getNextLevel());
|
||||
}
|
||||
|
||||
public function getBuildingTimeForNextLevel()
|
||||
{
|
||||
return $this->getBuildingTime($this->getNextLevel());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Planet_Buildings_Queue
|
||||
extends Wootook_Empire_Block_Planet_Builder_QueueAbstract
|
||||
{
|
||||
public function getQueue()
|
||||
{
|
||||
return $this->getPlanet()->getBuildingQueue();
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->getQueue()->count() == 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Planet_Buildings_Queue_Item
|
||||
extends Wootook_Empire_Block_Planet_Builder_Queue_ItemAbstract
|
||||
{
|
||||
protected $_itemIdField = 'building_id';
|
||||
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->getPlanet()->getElement($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($level)
|
||||
{
|
||||
return $this->getPlanet()->getResourcesNeeded($this->getItemId(), $this->getQueuedLevel() + 1);
|
||||
}
|
||||
|
||||
public function getItemQueuedLevel()
|
||||
{
|
||||
return $this->getItem()->getData('level');
|
||||
}
|
||||
|
||||
public function getQueuedLevel()
|
||||
{
|
||||
return $this->getPlanet()->getBuildingLevelQueued($this->getItemId());
|
||||
}
|
||||
|
||||
public function getBuildingTime($level)
|
||||
{
|
||||
return $this->getPlanet()->getBuildingTime($this->getItemId(), $level);
|
||||
}
|
||||
|
||||
public function getResourcesConfigForLevel($level)
|
||||
{
|
||||
$resources = $this->getResourcesNeeded($level);
|
||||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
||||
$amount = $this->getPlanet()->getResourceAmount($resourceId);
|
||||
if (Math::comp($amount, $resourceValue) < 0) {
|
||||
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
|
||||
} else {
|
||||
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
|
||||
}
|
||||
}
|
||||
return $resourceConfig;
|
||||
}
|
||||
|
||||
public function getResourcesConfigForNextLevel()
|
||||
{
|
||||
return $this->getResourcesConfigForLevel($this->getNextLevel());
|
||||
}
|
||||
|
||||
public function getBuildingTimeForNextLevel()
|
||||
{
|
||||
return $this->getBuildingTime($this->getNextLevel());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_PlanetList
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
|
||||
}
|
||||
32
application/code/core/Wootook/Empire/Block/Topnav.php
Normal file
32
application/code/core/Wootook/Empire/Block/Topnav.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Block_Topnav
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return Wootook_Empire_Model_User
|
||||
*/
|
||||
public function getCurrentUser()
|
||||
{
|
||||
return Wootook_Empire_Model_User::getSingleton();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Wootook_Empire_Model_Planet
|
||||
*/
|
||||
public function getCurrentPlanet()
|
||||
{
|
||||
return $this->getCurrentUser()->getCurrentPlanet();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Wootook_Core_Collection
|
||||
*/
|
||||
public function getPlanetCollection()
|
||||
{
|
||||
return $this->getCurrentUser()->getPlanetCollection();
|
||||
}
|
||||
}
|
||||
3
application/code/core/Wootook/Empire/Exception.php
Normal file
3
application/code/core/Wootook/Empire/Exception.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
interface Legacies_Empire_Exception extends Legacies_Exception {}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Exception_Exception
|
||||
extends Exception
|
||||
implements Wootook_Empire_Exception
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Exception_RuntimeException
|
||||
extends RuntimeException
|
||||
implements Wootook_Empire_Exception
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Builder_Break
|
||||
extends Exception
|
||||
{
|
||||
|
||||
}
|
||||
19
application/code/core/Wootook/Empire/Model/Builder/Item.php
Normal file
19
application/code/core/Wootook/Empire/Model/Builder/Item.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Builder_Item
|
||||
extends Wootook_Object
|
||||
{
|
||||
protected $_index = null;
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
return $this->_index;
|
||||
}
|
||||
|
||||
public function setIndex($index)
|
||||
{
|
||||
$this->_index = $index;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
247
application/code/core/Wootook/Empire/Model/BuilderAbstract.php
Normal file
247
application/code/core/Wootook/Empire/Model/BuilderAbstract.php
Normal file
|
|
@ -0,0 +1,247 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Empire_Model_BuilderAbstract
|
||||
implements Countable, Serializable, Iterator
|
||||
{
|
||||
/**
|
||||
* Planet instance
|
||||
* @var Wootook_Empire_Model_Planet
|
||||
*/
|
||||
protected $_currentPlanet = null;
|
||||
|
||||
/**
|
||||
* User instance
|
||||
* @var Wootook_Empire_Model_User
|
||||
*/
|
||||
protected $_currentUser = null;
|
||||
|
||||
/**
|
||||
* construction queue
|
||||
* @var array
|
||||
*/
|
||||
protected $_queue = null;
|
||||
|
||||
/**
|
||||
* construction queue
|
||||
* @var array
|
||||
*/
|
||||
protected $_itemClass = 'Wootook_Empire_Model_Builder_Item';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Wootook_Empire_Model_Planet $currentPlanet
|
||||
* @param Wootook_Empire_Model_User $currentUser
|
||||
*/
|
||||
public function __construct(Wootook_Empire_Model_Planet $currentPlanet, Wootook_Empire_Model_User $currentUser)
|
||||
{
|
||||
$this->_currentPlanet = $currentPlanet;
|
||||
$this->_currentUser = $currentUser;
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
abstract public function init();
|
||||
|
||||
abstract protected function _initItem(Array $params);
|
||||
|
||||
public function enqueue($params, $index = null)
|
||||
{
|
||||
$item = $this->_initItem($params);
|
||||
if ($item === null) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($index === null) {
|
||||
$index = $this->_generateIndex();
|
||||
}
|
||||
$item->setIndex($index);
|
||||
$this->_queue[$index] = $item;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dequeue($item)
|
||||
{
|
||||
unset($this->_queue[$item->getIndex()]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _generateIndex()
|
||||
{
|
||||
return uniqid();
|
||||
}
|
||||
|
||||
public function getItem($itemIndex)
|
||||
{
|
||||
if (isset($this->_queue[$itemIndex])) {
|
||||
return $this->_queue[$itemIndex];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function _serializeQueue()
|
||||
{
|
||||
$serialize = array();
|
||||
foreach ($this->_queue as $itemIndex => $itemInstance) {
|
||||
$serialize[$itemIndex] = $itemInstance->getAllDatas();
|
||||
}
|
||||
return serialize($serialize);
|
||||
}
|
||||
|
||||
protected function _unserializeQueue($serialized)
|
||||
{
|
||||
$this->clearQueue();
|
||||
|
||||
$unserialized = @unserialize($serialized);
|
||||
if ($unserialized === false) {
|
||||
$this->_queue = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
foreach ($unserialized as $itemIndex => $itemData) {
|
||||
$this->enqueue($itemData, $itemIndex);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_serializeQueue();
|
||||
}
|
||||
|
||||
public function getQueue()
|
||||
{
|
||||
return $this->_queue;
|
||||
}
|
||||
|
||||
public function clearQueue()
|
||||
{
|
||||
$this->_queue = array();
|
||||
}
|
||||
|
||||
abstract public function updateQueue($time);
|
||||
abstract public function appendQueue($typeId, $qty, $time);
|
||||
|
||||
/**
|
||||
* Check if an item type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $typeId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($typeId)
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
$requirements = Wootook_Empire_Model_Game_Requirements::getSingleton();
|
||||
|
||||
if (!isset($requirements[$typeId]) || empty($requirements[$typeId])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($requirements[$typeId] as $requirement => $level) {
|
||||
if ($types->is($requirement, Legacies_Empire::TYPE_BUILDING) && $this->_currentPlanet->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
} else if ($types->is($requirement, Legacies_Empire::TYPE_RESEARCH) && $this->_currentUser->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
} else if ($types->is($requirement, Legacies_Empire::TYPE_DEFENSE) && $this->_currentPlanet->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
} else if ($types->is($requirement, Legacies_Empire::TYPE_SHIP) && $this->_currentPlanet->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract public function getResourcesNeeded($typeId, $level);
|
||||
abstract public function getBuildingTime($typeId, $level);
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return $this->_serializeQueue();
|
||||
}
|
||||
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$this->_unserializeQueue($serialized);
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->_queue);
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return current($this->_queue);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
return next($this->_queue);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->_queue);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return current($this->_queue) !== false;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_queue);
|
||||
}
|
||||
|
||||
public function getCurrentPlanet()
|
||||
{
|
||||
return $this->_currentPlanet;
|
||||
}
|
||||
|
||||
public function getCurrentUser()
|
||||
{
|
||||
return $this->_currentUser;
|
||||
}
|
||||
|
||||
public function setCurrentPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_currentPlanet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCurrentUser(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$this->_currentUser = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _calculateResourceRemainingAmounts($resourceNeeded)
|
||||
{
|
||||
$resourceAmounts = array();
|
||||
foreach ($resourceNeeded as $resourceId => $resourceAmount) {
|
||||
$resourceAmounts[$resourceId] = Math::sub($this->_currentPlanet[$resourceId], $resourceAmount);
|
||||
if (Math::isNegative($resourceAmounts[$resourceId])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $resourceAmounts;
|
||||
}
|
||||
|
||||
protected function _calculateResourceReclaimedAmounts($resourceNeeded)
|
||||
{
|
||||
$resourceAmounts = array();
|
||||
foreach ($resourceNeeded as $resourceId => $resourceAmount) {
|
||||
$resourceAmounts[$resourceId] = Math::add($this->_currentPlanet[$resourceId], $resourceAmount);
|
||||
}
|
||||
return $resourceAmounts;
|
||||
}
|
||||
}
|
||||
155
application/code/core/Wootook/Empire/Model/Fleet.php
Normal file
155
application/code/core/Wootook/Empire/Model/Fleet.php
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Fleet
|
||||
extends Wootook_Core_Entity
|
||||
{
|
||||
protected static $_instances = array();
|
||||
|
||||
protected $_eventPrefix = 'fleet';
|
||||
protected $_eventObject = 'fleet';
|
||||
|
||||
public static function factory($id)
|
||||
{
|
||||
if ($id === null) {
|
||||
return new self();
|
||||
}
|
||||
|
||||
$id = intval($id);
|
||||
if (!isset(self::$_instances[$id])) {
|
||||
$instance = new self();
|
||||
$params = func_get_args();
|
||||
call_user_func_array(array($instance, 'load'), $params);
|
||||
self::$_instances[$id] = $instance;
|
||||
}
|
||||
return self::$_instances[$id];
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->setIdFieldName('fleet_id');
|
||||
$this->setTableName('fleets');
|
||||
}
|
||||
|
||||
public static function planetListener($eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public function isOwnedBy(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
if ($this->getData('fleet_owner') == $user->getId()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getOwner()
|
||||
{
|
||||
if ($id = $this->getData('fleet_owner')) {
|
||||
return Wootook_Empire_Model_User::factory($id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isMission($missionType)
|
||||
{
|
||||
if ($this->getData('fleet_mission') == $missionType) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRowClass(Wootook_Empire_Model_User $user = null)
|
||||
{
|
||||
if ($this->isMission(Legacies_Empire::ID_MISSION_ATTACK) || $this->isMission(Legacies_Empire::ID_MISSION_GROUP_ATTACK)) {
|
||||
if ($user !== null && $this->isOwnedBy($user)) {
|
||||
return 'attack';
|
||||
} else {
|
||||
return 'ownattack';
|
||||
}
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_TRANSPORT)) {
|
||||
return 'transport';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)) {
|
||||
return 'station';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_SETTLE_COLONY)) {
|
||||
return 'settle';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_RECYCLE)) {
|
||||
return 'recycle';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_DESTROY)) {
|
||||
return 'destroy';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_MISSILES)) {
|
||||
return 'missiles';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_EXPEDITION)) {
|
||||
return 'expedition';
|
||||
}
|
||||
}
|
||||
|
||||
public function getMissionLabel()
|
||||
{
|
||||
if ($this->isMission(Legacies_Empire::ID_MISSION_ATTACK) || $this->isMission(Legacies_Empire::ID_MISSION_GROUP_ATTACK)) {
|
||||
return Wootook::__('Attack');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_TRANSPORT)) {
|
||||
return Wootook::__('Transport');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)) {
|
||||
return Wootook::__('Station');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_SETTLE_COLONY)) {
|
||||
return Wootook::__('Settle');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_RECYCLE)) {
|
||||
return Wootook::__('Recycle');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_DESTROY)) {
|
||||
return Wootook::__('Destroy');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_MISSILES)) {
|
||||
return Wootook::__('Missiles Launch');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_EXPEDITION)) {
|
||||
return Wootook::__('Expedition');
|
||||
}
|
||||
return Legacies::__('Unknown');
|
||||
}
|
||||
|
||||
public function getStartTime()
|
||||
{
|
||||
return $this->getData('fleet_start_time');
|
||||
}
|
||||
|
||||
public function getActionTime()
|
||||
{
|
||||
return $this->getData('fleet_end_stay');
|
||||
}
|
||||
|
||||
public function getArrivalTime()
|
||||
{
|
||||
if ($this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)) {
|
||||
return $this->getActionTime();
|
||||
}
|
||||
return $this->getData('fleet_end_time');
|
||||
}
|
||||
|
||||
public function getOriginPlanet()
|
||||
{
|
||||
$coords = array(
|
||||
'galaxy' => $this->getData('fleet_start_galaxy'),
|
||||
'system' => $this->getData('fleet_start_system'),
|
||||
'position' => $this->getData('fleet_start_planet')
|
||||
);
|
||||
$type = $this->getData('fleet_start_type');
|
||||
|
||||
return Wootook_Empire_Model_Planet::factoryFromCoords($coords, $type);
|
||||
}
|
||||
|
||||
public function getDestinationPlanet()
|
||||
{
|
||||
$coords = array(
|
||||
'galaxy' => $this->getData('fleet_end_galaxy'),
|
||||
'system' => $this->getData('fleet_end_system'),
|
||||
'position' => $this->getData('fleet_end_planet')
|
||||
);
|
||||
$type = $this->getData('fleet_end_type');
|
||||
|
||||
return Wootook_Empire_Model_Planet::factoryFromCoords($coords, $type);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Galaxy_Position
|
||||
extends Wootook_Core_Entity_SubTable
|
||||
{
|
||||
protected function _init()
|
||||
{
|
||||
$this->_tableName = 'galaxy';
|
||||
$this->_idFieldNames = array('id_planet');
|
||||
}
|
||||
|
||||
static function initPlanetListerner($eventData)
|
||||
{
|
||||
if (!isset($eventData['planet'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$planet = $eventData['planet'];
|
||||
if (!$planet->isPlanet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$galaxy = new self();
|
||||
$galaxy
|
||||
->setData('galaxy', $planet->getGalaxy())
|
||||
->setData('system', $planet->getSystem())
|
||||
->setData('planet', $planet->getPosition())
|
||||
->setData('id_planet', $planet->getId())
|
||||
->save()
|
||||
;
|
||||
}
|
||||
}
|
||||
47
application/code/core/Wootook/Empire/Model/Game/Combat.php
Normal file
47
application/code/core/Wootook/Empire/Model/Game/Combat.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Combat
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('combat');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_FieldsAlias
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('fields-alias');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
47
application/code/core/Wootook/Empire/Model/Game/Prices.php
Normal file
47
application/code/core/Wootook/Empire/Model/Game/Prices.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Prices
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('prices');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Production
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('production');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Requirements
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('requirements');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Resources
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('resources');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue