Home_Page.php 9.2 KB

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