Home_Page.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. * @param resource $db Connection to the database.
  104. * @global int Player ID.
  105. */
  106. public function __construct($db){
  107. global $INVENTORY_TYPE;
  108. global $UID;
  109. parent::__construct($db);
  110. $this->view = PATH::VIEW . "home.php";
  111. $s = "
  112. SELECT
  113. uid,
  114. name,
  115. level,
  116. country,
  117. experience,
  118. rep,
  119. mana,
  120. crystal,
  121. energy,
  122. energy_max,
  123. arena_energy,
  124. arena_energy_max,
  125. darkportal_energy,
  126. darkportal_energy_max,
  127. dimension_energy,
  128. dimension_energy_max,
  129. honor_point,
  130. guild_point,
  131. honor_medal,
  132. honor_mark,
  133. event_coin,
  134. social_point,
  135. costume_point
  136. FROM player
  137. WHERE uid = '$UID';
  138. ";
  139. $q = $this->db->query($s);
  140. $r = $q->fetchArray(SQLITE3_ASSOC);
  141. if ($r){
  142. $this->uid = $r["uid"];
  143. $this->name = $r["name"];
  144. $this->level = $r["level"];
  145. $this->country = $r["country"];
  146. $this->experience = $r["experience"];
  147. if (strlen($r["rep"]) > 0){
  148. $this->rep = new Unit($this->db, $r["rep"]);
  149. }
  150. $this->currency["mana"] = $r["mana"];
  151. $this->currency["crystal"] = $r["crystal"];
  152. $this->currency["energy"] = $r["energy"];
  153. $this->currency["energy_max"] = $r["energy_max"];
  154. $this->currency["arena_energy"] = $r["arena_energy"];
  155. $this->currency["arena_energy_max"] = $r["arena_energy_max"];
  156. $this->currency["darkportal_energy"] = $r["darkportal_energy"];
  157. $this->currency["darkportal_energy_max"] = $r["darkportal_energy_max"];
  158. $this->currency["dimension_energy"] = $r["dimension_energy"];
  159. $this->currency["dimension_energy_max"] = $r["dimension_energy_max"];
  160. $this->currency["honor_point"] = $r["honor_point"];
  161. $this->currency["guild_point"] = $r["guild_point"];
  162. $this->currency["honor_medal"] = $r["honor_medal"];
  163. $this->currency["honor_mark"] = $r["honor_mark"];
  164. $this->currency["event_coin"] = $r["event_coin"];
  165. $this->currency["social_point"] = $r["social_point"];
  166. $this->currency["costume_point"] = $r["costume_point"];
  167. }
  168. $s = "
  169. SELECT unit
  170. FROM defense
  171. WHERE uid = '$UID'
  172. ORDER BY position;
  173. ";
  174. $q = $this->db->query($s);
  175. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  176. array_push($this->defense, new Unit($db, $r["unit"], false));
  177. }
  178. $s = "
  179. SELECT DISTINCT building
  180. FROM building
  181. WHERE uid = '$UID';
  182. ";
  183. $q = $this->db->query($s);
  184. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  185. array_push($this->building, new Building($db, $r["building"]));
  186. }
  187. $s = "
  188. SELECT decoration
  189. FROM decoration
  190. WHERE uid = '$UID';
  191. ";
  192. $q = $this->db->query($s);
  193. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  194. array_push($this->decoration, new Decoration($db, $r["decoration"]));
  195. }
  196. $s = "
  197. SELECT
  198. id,
  199. type
  200. FROM inventory
  201. WHERE
  202. uid = '$UID' AND
  203. type = " . INVENTORY_TYPE_ID::SCROLL . " AND
  204. amount > 0
  205. ORDER BY inventory.type;
  206. ";
  207. $q = $this->db->query($s);
  208. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  209. array_push($this->inventory_scroll, new Inventory($db, $r["id"], $r["type"]));
  210. }
  211. // Rune crafting items are marked as generic crafting.
  212. $s = "
  213. SELECT
  214. inventory.id AS id,
  215. inventory.type AS type
  216. FROM
  217. inventory
  218. WHERE
  219. inventory.uid = '$UID' AND
  220. inventory.type = " . INVENTORY_TYPE_ID::RUNE_CRAFT . " AND
  221. amount > 0
  222. ORDER BY inventory.id;
  223. ";
  224. $q = $this->db->query($s);
  225. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  226. array_push($this->inventory_craft_rune, new Inventory($db, $r["id"], $r["type"]));
  227. }
  228. $s = "
  229. SELECT
  230. inventory.id AS id,
  231. inventory.type AS type
  232. FROM
  233. inventory
  234. WHERE
  235. inventory.uid = '$UID' AND
  236. inventory.type = " . INVENTORY_TYPE_ID::CRAFT_STUFF . " AND
  237. amount > 0
  238. ORDER BY inventory.id;
  239. ";
  240. $q = $this->db->query($s);
  241. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  242. array_push($this->inventory_craft, new Inventory($db, $r["id"], $r["type"]));
  243. }
  244. $s = "
  245. SELECT
  246. inventory.id AS id,
  247. inventory.type AS type
  248. FROM
  249. inventory,
  250. k_inventory
  251. WHERE
  252. inventory.id = k_inventory.id AND
  253. inventory.type = k_inventory.type AND
  254. inventory.uid = '$UID' AND
  255. inventory.type = " . INVENTORY_TYPE_ID::ESSENCES . " AND
  256. amount > 0
  257. ORDER BY
  258. upper(name) NOT LIKE '%MAGIC%',
  259. upper(name) NOT LIKE '%FIRE%',
  260. upper(name) NOT LIKE '%WATER%',
  261. upper(name) NOT LIKE '%WIND%',
  262. upper(name) NOT LIKE '%LIGHT%',
  263. upper(name) NOT LIKE '%DARK%',
  264. upper(name) NOT LIKE '%LOW%',
  265. upper(name) NOT LIKE '%MID%',
  266. upper(name) NOT LIKE '%HIGH%'
  267. ;
  268. ";
  269. $q = $this->db->query($s);
  270. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  271. array_push($this->inventory_essence, new Inventory($db, $r["id"], $r["type"]));
  272. }
  273. $this->title = "SWDB";
  274. $this->description = "Summoners War DataBase";
  275. $this->canonical = URL::BASE;
  276. }
  277. }
  278. ?>