PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/classes/class.GalaxyRows.php

http://2moons.googlecode.com/
PHP | 295 lines | 231 code | 39 blank | 25 comment | 46 complexity | bc0ecad286db653fe8d76dbd18c67d10 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, LGPL-3.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * 2Moons
  4. * Copyright (C) 2012 Jan Kr??pke
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package 2Moons
  20. * @author Jan Kr??pke <info@2moons.cc>
  21. * @copyright 2012 Jan Kr??pke <info@2moons.cc>
  22. * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
  23. * @version 1.7.1 (2013-01-18)
  24. * @info $Id: class.GalaxyRows.php 2604 2013-01-18 11:35:42Z slaver7 $
  25. * @link http://2moons.cc/
  26. */
  27. require_once(ROOT_PATH . 'includes/classes/class.FleetFunctions.php');
  28. require_once(ROOT_PATH . 'includes/pages/game/class.ShowPhalanxPage.php');
  29. class GalaxyRows
  30. {
  31. private $Galaxy;
  32. private $System;
  33. private $galaxyData;
  34. private $galaxyRow;
  35. const PLANET_DESTROYED = false;
  36. function __construct() {
  37. }
  38. public function setGalaxy($Galaxy) {
  39. $this->Galaxy = $Galaxy;
  40. return $this;
  41. }
  42. public function setSystem($System) {
  43. $this->System = $System;
  44. return $this;
  45. }
  46. public function getGalaxyData()
  47. {
  48. global $UNI, $USER;
  49. $galaxyResult = $GLOBALS['DATABASE']->query("SELECT SQL_BIG_RESULT DISTINCT
  50. p.galaxy, p.system, p.planet, p.id, p.id_owner, p.name, p.image, p.last_update, p.diameter, p.temp_min, p.destruyed, p.der_metal, p.der_crystal, p.id_luna,
  51. u.id as userid, u.ally_id, u.username, u.onlinetime, u.urlaubs_modus, u.banaday,
  52. m.id as m_id, m.diameter as m_diameter, m.name as m_name, m.temp_min as m_temp_min, m.last_update as m_last_update,
  53. s.total_points, s.total_rank,
  54. a.id as allyid, a.ally_tag, a.ally_web, a.ally_members, a.ally_name,
  55. allys.total_rank as ally_rank,
  56. COUNT(buddy.id) as buddy,
  57. d.level as diploLevel
  58. FROM ".PLANETS." p
  59. LEFT JOIN ".USERS." u ON p.id_owner = u.id
  60. LEFT JOIN ".PLANETS." m ON m.id = p.id_luna
  61. LEFT JOIN ".STATPOINTS." s ON s.id_owner = u.id AND s.stat_type = '1'
  62. LEFT JOIN ".ALLIANCE." a ON a.id = u.ally_id
  63. LEFT JOIN ".DIPLO." as d ON (d.owner_1 = ".$USER['ally_id']." AND d.owner_2 = a.id) OR (d.owner_1 = a.id AND d.owner_2 = ".$USER['ally_id'].") AND d.accept = 1
  64. LEFT JOIN ".STATPOINTS." allys ON allys.stat_type = '2' AND allys.id_owner = a.id
  65. LEFT JOIN ".BUDDY." buddy ON (buddy.sender = ".$USER['id']." AND buddy.owner = u.id ) OR (buddy.sender = u.id AND buddy.owner = ".$USER['id'].")
  66. WHERE p.universe = ".$UNI." AND p.galaxy = ".$this->Galaxy." AND p.system = ".$this->System." AND p.planet_type = '1'
  67. GROUP BY p.id;");
  68. while($this->galaxyRow = $GLOBALS['DATABASE']->fetch_array($galaxyResult))
  69. {
  70. if ($this->galaxyRow['destruyed'] != 0)
  71. {
  72. $this->galaxyData[$this->galaxyRow['planet']] = self::PLANET_DESTROYED;
  73. continue;
  74. }
  75. $this->galaxyData[$this->galaxyRow['planet']] = array();
  76. $this->isOwnPlanet();
  77. $this->setLastActivity();
  78. $this->getAllowedMissions();
  79. $this->getPlayerData();
  80. $this->getPlanetData();
  81. $this->getAllianceData();
  82. $this->getDebrisData();
  83. $this->getMoonData();
  84. $this->getActionButtons();
  85. }
  86. $GLOBALS['DATABASE']->free_result($galaxyResult);
  87. return $this->galaxyData;
  88. }
  89. protected function setLastActivity()
  90. {
  91. global $LNG;
  92. $lastActivity = floor((TIMESTAMP - max($this->galaxyRow['last_update'], $this->galaxyRow['m_last_update'])) / 60);
  93. if ($lastActivity < 4) {
  94. $this->galaxyData[$this->galaxyRow['planet']]['lastActivity'] = $LNG['gl_activity'];
  95. } elseif($lastActivity < 15) {
  96. $this->galaxyData[$this->galaxyRow['planet']]['lastActivity'] = sprintf($LNG['gl_activity_inactive'], $lastActivity);
  97. } else {
  98. $this->galaxyData[$this->galaxyRow['planet']]['lastActivity'] = '';
  99. }
  100. }
  101. protected function isOwnPlanet()
  102. {
  103. global $USER;
  104. $this->galaxyData[$this->galaxyRow['planet']]['ownPlanet'] = $this->galaxyRow['id_owner'] == $USER['id'];
  105. }
  106. protected function getAllowedMissions()
  107. {
  108. global $PLANET, $resource;
  109. $this->galaxyData[$this->galaxyRow['planet']]['missions'] = array(
  110. 1 => !$this->galaxyData[$this->galaxyRow['planet']]['ownPlanet'] && isModulAvalible(MODULE_MISSION_ATTACK),
  111. 3 => isModulAvalible(MODULE_MISSION_TRANSPORT),
  112. 4 => $this->galaxyData[$this->galaxyRow['planet']]['ownPlanet'] && isModulAvalible(MODULE_MISSION_STATION),
  113. 5 => !$this->galaxyData[$this->galaxyRow['planet']]['ownPlanet'] && isModulAvalible(MODULE_MISSION_HOLD),
  114. 6 => !$this->galaxyData[$this->galaxyRow['planet']]['ownPlanet'] && isModulAvalible(MODULE_MISSION_SPY),
  115. 8 => isModulAvalible(MODULE_MISSION_RECYCLE),
  116. 9 => !$this->galaxyData[$this->galaxyRow['planet']]['ownPlanet'] && $PLANET[$resource[214]] > 0 && isModulAvalible(MODULE_MISSION_DESTROY),
  117. 10 => !$this->galaxyData[$this->galaxyRow['planet']]['ownPlanet'] && $PLANET[$resource[503]] > 0 && isModulAvalible(MODULE_MISSION_ATTACK) && isModulAvalible(MODULE_MISSILEATTACK) && $this->inMissileRange(),
  118. );
  119. }
  120. protected function inMissileRange()
  121. {
  122. global $USER, $PLANET, $resource;
  123. if ($this->galaxyRow['galaxy'] != $PLANET['galaxy'])
  124. return false;
  125. $Range = FleetFunctions::GetMissileRange($USER[$resource[117]]);
  126. $systemMin = $PLANET['system'] - $Range;
  127. $systemMax = $PLANET['system'] + $Range;
  128. return $this->galaxyRow['system'] >= $systemMin && $this->galaxyRow['system'] <= $systemMax;
  129. }
  130. protected function getActionButtons()
  131. {
  132. global $USER;
  133. if($this->galaxyData[$this->galaxyRow['planet']]['ownPlanet']) {
  134. $this->galaxyData[$this->galaxyRow['planet']]['action'] = false;
  135. } else {
  136. $this->galaxyData[$this->galaxyRow['planet']]['action'] = array(
  137. 'esp' => $USER['settings_esp'] == 1 && $this->galaxyData[$this->galaxyRow['planet']]['missions'][6],
  138. 'message' => $USER['settings_wri'] == 1 && isModulAvalible(MODULE_MESSAGES),
  139. 'buddy' => $USER['settings_bud'] == 1 && isModulAvalible(MODULE_BUDDYLIST) && $this->galaxyRow['buddy'] == 0,
  140. 'missle' => $USER['settings_mis'] == 1 && $this->galaxyData[$this->galaxyRow['planet']]['missions'][10],
  141. );
  142. }
  143. }
  144. protected function getPlayerData()
  145. {
  146. global $USER, $LNG;
  147. $IsNoobProtec = CheckNoobProtec($USER, $this->galaxyRow, $this->galaxyRow);
  148. $Class = array();
  149. if ($this->galaxyRow['banaday'] > TIMESTAMP && $this->galaxyRow['urlaubs_modus'] == 1)
  150. {
  151. $Class = array('vacation', 'banned');
  152. }
  153. elseif ($this->galaxyRow['banaday'] > TIMESTAMP)
  154. {
  155. $Class = array('banned');
  156. }
  157. elseif ($this->galaxyRow['urlaubs_modus'] == 1)
  158. {
  159. $Class = array('vacation');
  160. }
  161. elseif ($this->galaxyRow['onlinetime'] < TIMESTAMP - INACTIVE_LONG)
  162. {
  163. $Class = array('inactive', 'longinactive');
  164. }
  165. elseif ($this->galaxyRow['onlinetime'] < TIMESTAMP - INACTIVE)
  166. {
  167. $Class = array('inactive');
  168. }
  169. elseif ($IsNoobProtec['NoobPlayer'])
  170. {
  171. $Class = array('noob');
  172. }
  173. elseif ($IsNoobProtec['StrongPlayer'])
  174. {
  175. $Class = array('strong');
  176. }
  177. $this->galaxyData[$this->galaxyRow['planet']]['user'] = array(
  178. 'id' => $this->galaxyRow['userid'],
  179. 'username' => htmlspecialchars($this->galaxyRow['username'], ENT_QUOTES, "UTF-8"),
  180. 'rank' => $this->galaxyRow['total_rank'],
  181. 'points' => pretty_number($this->galaxyRow['total_points']),
  182. 'playerrank' => isModulAvalible(25)?sprintf($LNG['gl_in_the_rank'], htmlspecialchars($this->galaxyRow['username'],ENT_QUOTES,"UTF-8"), $this->galaxyRow['total_rank']):htmlspecialchars($this->galaxyRow['username'],ENT_QUOTES,"UTF-8"),
  183. 'class' => $Class,
  184. 'isBuddy' => $this->galaxyRow['buddy'] == 0,
  185. );
  186. }
  187. protected function getAllianceData()
  188. {
  189. global $USER, $LNG;
  190. if(empty($this->galaxyRow['allyid'])) {
  191. $this->galaxyData[$this->galaxyRow['planet']]['alliance'] = false;
  192. } else {
  193. $Class = array();
  194. switch($this->galaxyRow['diploLevel'])
  195. {
  196. case 1:
  197. case 2:
  198. $Class = array('member');
  199. break;
  200. case 4:
  201. $Class = array('friend');
  202. break;
  203. case 5:
  204. $Class = array('enemy');
  205. break;
  206. }
  207. if($USER['ally_id'] == $this->galaxyRow['ally_id'])
  208. {
  209. $Class = array('member');
  210. }
  211. $this->galaxyData[$this->galaxyRow['planet']]['alliance'] = array(
  212. 'id' => $this->galaxyRow['allyid'],
  213. 'name' => htmlspecialchars($this->galaxyRow['ally_name'], ENT_QUOTES, "UTF-8"),
  214. 'member' => sprintf(($this->galaxyRow['ally_members'] == 1) ? $LNG['gl_member_add'] : $LNG['gl_member'], $this->galaxyRow['ally_members']),
  215. 'web' => $this->galaxyRow['ally_web'],
  216. 'tag' => $this->galaxyRow['ally_tag'],
  217. 'rank' => $this->galaxyRow['ally_rank'],
  218. 'class' => $Class,
  219. );
  220. }
  221. }
  222. protected function getDebrisData()
  223. {
  224. $total = $this->galaxyRow['der_metal'] + $this->galaxyRow['der_crystal'];
  225. if($total == 0) {
  226. $this->galaxyData[$this->galaxyRow['planet']]['debris'] = false;
  227. } else {
  228. $this->galaxyData[$this->galaxyRow['planet']]['debris'] = array(
  229. 'metal' => $this->galaxyRow['der_metal'],
  230. 'crystal' => $this->galaxyRow['der_crystal'],
  231. );
  232. }
  233. }
  234. protected function getMoonData()
  235. {
  236. if(!isset($this->galaxyRow['m_id'])) {
  237. $this->galaxyData[$this->galaxyRow['planet']]['moon'] = false;
  238. } else {
  239. $this->galaxyData[$this->galaxyRow['planet']]['moon'] = array(
  240. 'id' => $this->galaxyRow['m_id'],
  241. 'name' => htmlspecialchars($this->galaxyRow['m_name'], ENT_QUOTES, "UTF-8"),
  242. 'temp_min' => $this->galaxyRow['m_temp_min'],
  243. 'diameter' => $this->galaxyRow['m_diameter'],
  244. );
  245. }
  246. }
  247. protected function getPlanetData()
  248. {
  249. $this->galaxyData[$this->galaxyRow['planet']]['planet'] = array(
  250. 'id' => $this->galaxyRow['id'],
  251. 'name' => htmlspecialchars($this->galaxyRow['name'], ENT_QUOTES, "UTF-8"),
  252. 'image' => $this->galaxyRow['image'],
  253. 'phalanx' => isModulAvalible(MODULE_PHALANX) && ShowPhalanxPage::allowPhalanx($this->galaxyRow['galaxy'], $this->galaxyRow['system']),
  254. );
  255. }
  256. }