Home_Page.php 8.7 KB

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