/includes/types.php

https://github.com/milek/GamesRepository · PHP · 201 lines · 132 code · 32 blank · 37 comment · 9 complexity · 9f40803e7eaad3eced8065dca3669ae7 MD5 · raw file

  1. <?php
  2. class Group
  3. {
  4. // name of group
  5. public $name;
  6. // array of games
  7. public $games = array();
  8. /**
  9. * Adds game
  10. */
  11. function addGame($name, $renter)
  12. {
  13. $id = '';
  14. $cdnumber = '1';
  15. if (!(strpos($name, "{") === false))
  16. {
  17. $metadata = substr($name, strpos($name, "{") + 1, -1);
  18. $name = substr($name, 0, strpos($name, "{") - 1);
  19. $metarray = split(';', $metadata);
  20. foreach ($metarray as $m)
  21. {
  22. list($key, $value) = split(':', $m);
  23. if ($key == 'cd')
  24. {
  25. $cdnumber = $value;
  26. }
  27. else if ($key == 'id')
  28. {
  29. $id = $value;
  30. }
  31. }
  32. }
  33. $game = new Game;
  34. $game->name = $name;
  35. $game->id = $id;
  36. $game->renter = $renter;
  37. $game->released = null;
  38. $game->cdnumber = $cdnumber;
  39. $game->checkForAchievements();
  40. $this->games[] = $game;
  41. }
  42. /**
  43. * Adds game with release date
  44. */
  45. function addGameWithReleaseDate($name, $renter, $releaseDate)
  46. {
  47. $game = new Game;
  48. $game->name = $name;
  49. $game->renter = $renter;
  50. $game->released = $releaseDate;
  51. $game->checkForAchievements();
  52. $this->games[] = $game;
  53. }
  54. }
  55. class Game
  56. {
  57. // id
  58. public $id;
  59. // name
  60. public $name;
  61. // box art id
  62. public $boxArtId;
  63. // renter
  64. public $renter;
  65. // achievements points
  66. public $achPoints;
  67. // achivements count
  68. public $achCount;
  69. // released
  70. public $released;
  71. /**
  72. * Constructor
  73. */
  74. function __construct()
  75. {
  76. $this->achPoints = new Points;
  77. $this->achCount = new Points;
  78. $this->released = true;
  79. }
  80. /**
  81. * Check game for XBox Live Achievements
  82. */
  83. function checkForAchievements()
  84. {
  85. }
  86. /**
  87. * Checks if box art for game exists, either on server
  88. * or through id
  89. */
  90. function boxArtExists()
  91. {
  92. $local = "covers/".strtolower($this->normalize($this->name)).".jpg";
  93. if (file_exists($local))
  94. {
  95. return true;
  96. }
  97. return $this->boxArtId != null;
  98. }
  99. /**
  100. * Returns box art for game. Either local file or remote
  101. * from XBox Live servers. It's always better to have
  102. * local file.
  103. */
  104. function getBoxArt()
  105. {
  106. $local = "covers/".strtolower($this->normalize($this->name)).".jpg";
  107. if (file_exists($local))
  108. {
  109. return $local;
  110. }
  111. $remote = "http://tiles.xbox.com:80/consoleAssets/".$this->boxArtId."/en-GB/largeboxart.jpg";
  112. return $remote;
  113. }
  114. /**
  115. * Returns update game name, use only for display purposes
  116. */
  117. function getGameName()
  118. {
  119. $gameName = $this->name;
  120. // LEGO games looks better with ®
  121. $gameName = str_replace("LEGO", "LEGO&reg;", $gameName);
  122. return $gameName;
  123. }
  124. /**
  125. * Normalize game name for use with box art
  126. */
  127. function normalize($gamename)
  128. {
  129. $gamename = str_replace(" ", "_", $gamename);
  130. $gamename = str_replace(".", "_", $gamename);
  131. $gamename = str_replace(":", "", $gamename);
  132. $gamename = str_replace("'", "", $gamename);
  133. $gamename = str_replace("&#252;", "u", $gamename);
  134. $gamename = str_replace("&", "_", $gamename);
  135. $gamename = str_replace("__", "_", $gamename);
  136. $gamename = str_replace("__", "_", $gamename);
  137. return $gamename;
  138. }
  139. }
  140. class Points
  141. {
  142. // current value
  143. public $value = 0;
  144. // out of
  145. public $outOf = 0;
  146. }
  147. class Category
  148. {
  149. // id
  150. public $id = "";
  151. // name
  152. public $name = "";
  153. // active
  154. public $active = false;
  155. }
  156. ?>