Home_Page.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. global $UID;
  95. parent::__construct($db);
  96. $this->view = $path["view"] . "home.php";
  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. WHERE uid = '$UID';
  123. ";
  124. $q = $this->db->query($s);
  125. $r = $q->fetchArray(SQLITE3_ASSOC);
  126. if ($r){
  127. $this->uid = $r["uid"];
  128. $this->name = $r["name"];
  129. $this->country = $r["country"];
  130. $this->experience = $r["experience"];
  131. if (strlen($r["rep"]) > 0){
  132. $this->rep = new Unit($this->db, $r["rep"]);
  133. }
  134. $this->currency["mana"] = $r["mana"];
  135. $this->currency["crystal"] = $r["crystal"];
  136. $this->currency["energy"] = $r["energy"];
  137. $this->currency["energy_max"] = $r["energy_max"];
  138. $this->currency["arena_energy"] = $r["arena_energy"];
  139. $this->currency["arena_energy_max"] = $r["arena_energy_max"];
  140. $this->currency["darkportal_energy"] = $r["darkportal_energy"];
  141. $this->currency["darkportal_energy_max"] = $r["darkportal_energy_max"];
  142. $this->currency["dimension_energy"] = $r["dimension_energy"];
  143. $this->currency["dimension_energy_max"] = $r["dimension_energy_max"];
  144. $this->currency["honor_point"] = $r["honor_point"];
  145. $this->currency["guild_point"] = $r["guild_point"];
  146. $this->currency["honor_medal"] = $r["honor_medal"];
  147. $this->currency["honor_mark"] = $r["honor_mark"];
  148. $this->currency["event_coin"] = $r["event_coin"];
  149. $this->currency["social_point"] = $r["social_point"];
  150. $this->currency["costume_point"] = $r["costume_point"];
  151. }
  152. $s = "
  153. SELECT unit
  154. FROM defense
  155. WHERE uid = '$UID'
  156. ORDER BY position;
  157. ";
  158. $q = $this->db->query($s);
  159. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  160. array_push($this->defense, new Unit($db, $r["unit"], false));
  161. }
  162. $s = "
  163. SELECT DISTINCT building
  164. FROM building
  165. WHERE uid = '$UID';
  166. ";
  167. $q = $this->db->query($s);
  168. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  169. array_push($this->building, new Building($db, $r["building"]));
  170. }
  171. $s = "
  172. SELECT decoration
  173. FROM decoration
  174. WHERE uid = '$UID';
  175. ";
  176. $q = $this->db->query($s);
  177. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  178. array_push($this->decoration, new Decoration($db, $r["decoration"]));
  179. }
  180. $s = "
  181. SELECT id
  182. FROM inventory
  183. WHERE
  184. uid = '$UID' AND
  185. type = " . $INVENTORY_TYPE["SCROLL"] . " AND
  186. amount > 0;
  187. ";
  188. $q = $this->db->query($s);
  189. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  190. array_push($this->inventory_scroll, new Inventory($db, $r["id"]));
  191. }
  192. // Rune crafting items are marked as generic crafting.
  193. $s = "
  194. SELECT inventory.id
  195. FROM
  196. inventory,
  197. k_inventory
  198. WHERE
  199. inventory.uid = '$UID' AND
  200. inventory.id = k_inventory.id AND
  201. k_inventory.type = " . $INVENTORY_TYPE["RUNE_CRAFT"] . " AND
  202. amount > 0;
  203. ";
  204. $q = $this->db->query($s);
  205. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  206. array_push($this->inventory_craft_rune, new Inventory($db, $r["id"]));
  207. }
  208. $s = "
  209. SELECT inventory.id
  210. FROM
  211. inventory,
  212. k_inventory
  213. WHERE
  214. inventory.uid = '$UID' AND
  215. inventory.id = k_inventory.id AND
  216. k_inventory.type = " . $INVENTORY_TYPE["CRAFT_STUFF"] . " AND
  217. amount > 0;
  218. ";
  219. $q = $this->db->query($s);
  220. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  221. array_push($this->inventory_craft, new Inventory($db, $r["id"]));
  222. }
  223. $s = "
  224. SELECT inventory.id AS id
  225. FROM
  226. inventory,
  227. k_inventory
  228. WHERE
  229. inventory.uid = '$UID' AND
  230. k_inventory.id = inventory.id AND
  231. k_inventory.type = " . $INVENTORY_TYPE["ESSENCES"] . "
  232. ORDER BY
  233. upper(name) NOT LIKE '%MAGIC%',
  234. upper(name) NOT LIKE '%FIRE%',
  235. upper(name) NOT LIKE '%WATER%',
  236. upper(name) NOT LIKE '%WIND%',
  237. upper(name) NOT LIKE '%LIGHT%',
  238. upper(name) NOT LIKE '%DARK%',
  239. upper(name) NOT LIKE '%LOW%',
  240. upper(name) NOT LIKE '%MID%',
  241. upper(name) NOT LIKE '%HIGH%'
  242. ;
  243. ";
  244. $q = $this->db->query($s);
  245. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  246. array_push($this->inventory_essence, new Inventory($db, $r["id"]));
  247. }
  248. $this->title = "SWDB";
  249. $this->description = "Summoners War DataBase";
  250. $this->canonical = $root;
  251. }
  252. }
  253. ?>