Home_Page.php 8.5 KB

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