Home_Page.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. /**
  3. * Home page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  6. *
  7. * @category Page
  8. */
  9. /**
  10. * Require dependent files if not present.
  11. */
  12. require_once(PATH::PAGE . "Page.php");
  13. require_once(PATH::ENTITY . "Unit.php");
  14. require_once(PATH::ENTITY . "Building.php");
  15. require_once(PATH::ENTITY . "Decoration.php");
  16. require_once(PATH::ENTITY . "Inventory.php");
  17. /**
  18. * Home page model.
  19. *
  20. * @category Page
  21. */
  22. class Home_Page extends Page{
  23. /**
  24. * @var int Player ID.
  25. */
  26. public $uid;
  27. /**
  28. * @var int Player level.
  29. */
  30. public $level;
  31. /**
  32. * @var string Player name.
  33. */
  34. public $name;
  35. /**
  36. * @var string Player country (XX).
  37. */
  38. public $country;
  39. /**
  40. * @var int Total experience.
  41. */
  42. public $experience;
  43. /**
  44. * @var Unit Representative Unit.
  45. */
  46. public $rep;
  47. /**
  48. * @var \Unit[] Unitss in Arena defense.
  49. */
  50. public $defense = [];
  51. /**
  52. * @var int[] Currency.
  53. */
  54. public $currency = [
  55. "mana" => 0,
  56. "crystal" => 0,
  57. "energy" => 0,
  58. "energy_max" => 0,
  59. "arena_energy" => 0,
  60. "arena_energy_max" => 0,
  61. "darkportal_energy" => 0,
  62. "darkportal_energy_max" => 0,
  63. "dimension_energy" => 0,
  64. "dimension_energy_max" => 0,
  65. "honor_point" => 0,
  66. "guild_point" => 0,
  67. "honor_medal" => 0,
  68. "honor_mark" => 0,
  69. "event_coin" => 0,
  70. "social_point" => 0,
  71. "ancient_stone" => 0,
  72. "costume_point" => 0,
  73. ];
  74. /**
  75. * @var \Building[] List of Buildings.
  76. */
  77. public $building = [];
  78. /**
  79. * @var \Decoration[] List of Decorations.
  80. */
  81. public $decoration = [];
  82. /**
  83. * @var \Inventory[] List of Scrolls in Inventory.
  84. */
  85. public $inventory_scroll = [];
  86. /**
  87. * @var \Inventory[] List of rune crafting items in Inventory.
  88. */
  89. public $inventory_craft_rune = [];
  90. /**
  91. * @var \Inventory[] List of rune crafting items in Inventory.
  92. */
  93. public $inventory_craft = [];
  94. /**
  95. * @var \Inventory[] List of rune crafting items in Inventory.
  96. */
  97. public $inventory_essence = [];
  98. /**
  99. * Constructor.
  100. *
  101. * Retrieves the data and initializes the variables.
  102. *
  103. * @global int Player ID.
  104. * @global resource Connection to the database.
  105. */
  106. public function __construct(){
  107. global $UID;
  108. global $db;
  109. $this->view = PATH::VIEW . "home.php";
  110. $s = "
  111. SELECT
  112. uid,
  113. name,
  114. level,
  115. country,
  116. experience,
  117. rep,
  118. mana,
  119. crystal,
  120. energy,
  121. energy_max,
  122. arena_energy,
  123. arena_energy_max,
  124. darkportal_energy,
  125. darkportal_energy_max,
  126. dimension_energy,
  127. dimension_energy_max,
  128. honor_point,
  129. guild_point,
  130. honor_medal,
  131. honor_mark,
  132. event_coin,
  133. social_point,
  134. costume_point
  135. FROM player
  136. WHERE uid = '$UID';
  137. ";
  138. $q = $db->query($s);
  139. $r = $q->fetchArray(SQLITE3_ASSOC);
  140. if ($r){
  141. $this->uid = $r["uid"];
  142. $this->name = $r["name"];
  143. $this->level = $r["level"];
  144. $this->country = $r["country"];
  145. $this->experience = $r["experience"];
  146. if (strlen($r["rep"]) > 0){
  147. $this->rep = new Unit($r["rep"]);
  148. }
  149. $this->currency["mana"] = $r["mana"];
  150. $this->currency["crystal"] = $r["crystal"];
  151. $this->currency["energy"] = $r["energy"];
  152. $this->currency["energy_max"] = $r["energy_max"];
  153. $this->currency["arena_energy"] = $r["arena_energy"];
  154. $this->currency["arena_energy_max"] = $r["arena_energy_max"];
  155. $this->currency["darkportal_energy"] = $r["darkportal_energy"];
  156. $this->currency["darkportal_energy_max"] = $r["darkportal_energy_max"];
  157. $this->currency["dimension_energy"] = $r["dimension_energy"];
  158. $this->currency["dimension_energy_max"] = $r["dimension_energy_max"];
  159. $this->currency["honor_point"] = $r["honor_point"];
  160. $this->currency["guild_point"] = $r["guild_point"];
  161. $this->currency["honor_medal"] = $r["honor_medal"];
  162. $this->currency["honor_mark"] = $r["honor_mark"];
  163. $this->currency["event_coin"] = $r["event_coin"];
  164. $this->currency["social_point"] = $r["social_point"];
  165. $this->currency["costume_point"] = $r["costume_point"];
  166. }
  167. $s = "
  168. SELECT unit
  169. FROM defense
  170. WHERE uid = '$UID'
  171. ORDER BY position;
  172. ";
  173. $q = $db->query($s);
  174. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  175. array_push($this->defense, new Unit($r["unit"], false));
  176. }
  177. $s = "
  178. SELECT
  179. building.id,
  180. min(building)
  181. FROM
  182. building,
  183. k_building
  184. WHERE
  185. uid = '$UID' AND
  186. building.building = k_building.id
  187. GROUP BY building.building;
  188. ";
  189. $q = $db->query($s);
  190. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  191. array_push($this->building, new Building($r["id"]));
  192. }
  193. $s = "
  194. SELECT id
  195. FROM decoration
  196. WHERE uid = '$UID';
  197. ";
  198. $q = $db->query($s);
  199. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  200. array_push($this->decoration, new Decoration($r["id"]));
  201. }
  202. $s = "
  203. SELECT
  204. id,
  205. type
  206. FROM inventory
  207. WHERE
  208. uid = '$UID' AND
  209. type = " . INVENTORY_TYPE_ID::SCROLL . " AND
  210. amount > 0
  211. ORDER BY inventory.type;
  212. ";
  213. $q = $db->query($s);
  214. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  215. array_push($this->inventory_scroll, new Inventory($r["id"], $r["type"]));
  216. }
  217. // Rune crafting items are marked as generic crafting.
  218. $s = "
  219. SELECT
  220. inventory.id AS id,
  221. inventory.type AS type
  222. FROM
  223. inventory
  224. WHERE
  225. inventory.uid = '$UID' AND
  226. inventory.type = " . INVENTORY_TYPE_ID::RUNE_CRAFT . " AND
  227. amount > 0
  228. ORDER BY inventory.id;
  229. ";
  230. $q = $db->query($s);
  231. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  232. array_push($this->inventory_craft_rune, new Inventory($r["id"], $r["type"]));
  233. }
  234. $s = "
  235. SELECT
  236. inventory.id AS id,
  237. inventory.type AS type
  238. FROM
  239. inventory
  240. WHERE
  241. inventory.uid = '$UID' AND
  242. inventory.type = " . INVENTORY_TYPE_ID::CRAFT_STUFF . " AND
  243. amount > 0
  244. ORDER BY inventory.id;
  245. ";
  246. $q = $db->query($s);
  247. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  248. array_push($this->inventory_craft, new Inventory($r["id"], $r["type"]));
  249. }
  250. $s = "
  251. SELECT
  252. inventory.id AS id,
  253. inventory.type AS type
  254. FROM
  255. inventory,
  256. k_inventory
  257. WHERE
  258. inventory.id = k_inventory.id AND
  259. inventory.type = k_inventory.type AND
  260. inventory.uid = '$UID' AND
  261. inventory.type = " . INVENTORY_TYPE_ID::ESSENCES . " AND
  262. amount > 0
  263. ORDER BY
  264. upper(name) NOT LIKE '%MAGIC%',
  265. upper(name) NOT LIKE '%FIRE%',
  266. upper(name) NOT LIKE '%WATER%',
  267. upper(name) NOT LIKE '%WIND%',
  268. upper(name) NOT LIKE '%LIGHT%',
  269. upper(name) NOT LIKE '%DARK%',
  270. upper(name) NOT LIKE '%LOW%',
  271. upper(name) NOT LIKE '%MID%',
  272. upper(name) NOT LIKE '%HIGH%'
  273. ;
  274. ";
  275. $q = $db->query($s);
  276. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  277. array_push($this->inventory_essence, new Inventory($r["id"], $r["type"]));
  278. }
  279. $this->title = "SWDB";
  280. $this->description = "Summoners War DataBase";
  281. $this->canonical = URL::BASE;
  282. }
  283. }
  284. ?>