Home_Page.php 9.1 KB

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