PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/demos/WoWGuildAndCharacter.php

https://github.com/bforchhammer/bnetlib
PHP | 237 lines | 222 code | 11 blank | 4 comment | 3 complexity | 67d2906eed6f351303c3265567746ce5 MD5 | raw file
  1. <?php
  2. include dirname(__DIR__) . '/autoload_register.php';
  3. ?>
  4. <!doctype html>
  5. <html>
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Character and Guild Demo</title>
  9. </head>
  10. <style type="text/css" media="screen">
  11. body{color:#444;background:#ddd;font:normal 14px/20px 'Helvetica Neue',Helvetica,Arial,sans-serif}
  12. a{color:#82bd1a;text-decoration:none}
  13. a:hover{text-decoration:underline}
  14. article a{font-weight:bold}
  15. p,dl{margin:0 0 15px}
  16. h1,h2,h3{color:#555;margin:0 0 30px}
  17. h1{font-size:28px}
  18. h2{font-size:21px}
  19. h3{font-size:17px}
  20. hgroup h1{margin:0 0 15px}
  21. p:last-child,dl:last-child{margin:0}
  22. #main{width:800px;margin:75px auto}
  23. #lib{font-size:40px}
  24. #lib a{color:#444}
  25. #lib a:hover,#lib a:focus{color:#82bd1a;text-decoration:none}
  26. footer{clear:both;color:#999;font-size:11px}
  27. section>section{margin:0;width:800px}
  28. article{background:#fff;margin-bottom:25px;-webkit-box-shadow:0 0 3px rgba(0,0,0,.25);-moz-box-shadow:0 0 3px rgba(0,0,0,.25);-o-box-shadow:0 0 3px rgba(0,0,0,.25);box-shadow:0 0 3px rgba(0,0,0,.25);-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}
  29. section>ul{margin:0;padding:0;list-style:none;font-weight:bold}
  30. header>section{top:0;right:2px;float:right;position:relative}
  31. section>ul>li{font-size:13px;margin-left:5px;display:inline-block}
  32. .nav-space{margin-left:25px}
  33. nav a,section>ul>li>a{color:#eee;line-height:1;background:#888;padding:4px 7px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}
  34. .inner{padding:30px}
  35. section>ul>li>a:hover,section>ul>li>a:focus{color:#eee;background:#82bd1a;text-decoration:none}
  36. table{width:100%;border-spacing:0;border-collapse:collapse;margin-bottom:25px}
  37. table:last-of-type{margin:0}
  38. th{font-weight:bold}
  39. th,td{padding:4px 7px;text-align:right}
  40. td{border-top:1px solid #d0d0d0}
  41. th:last-child,td:last-child{text-align:left}
  42. tr:hover{background:#f5f5f5}
  43. tr tr:hover{background:#e9e9e9}
  44. table.center th,table.center td,th.center,td.center{text-align:center}
  45. img{left:0;top:-2px;float:left;position:relative;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;margin-right:10px}
  46. </style>
  47. <body>
  48. <div id="main">
  49. <header>
  50. <section>
  51. <ul>
  52. <li>Docs:</li>
  53. <li><a href="http://coss.github.com/bnetlib/api" title="API Documentation">API</a></li>
  54. <li><a href="http://coss.github.com/bnetlib" title="End User Documentation">End-User</a></li>
  55. <li class="nav-space">Downlaod:</li>
  56. <li><a href="https://github.com/coss/bnetlib/zipball/master" title="Download as .zip">Zip</a></li>
  57. <li><a href="https://github.com/coss/bnetlib/tarball/master" title="Download as .tar.gz">Tar</a></li>
  58. <li class="nav-space">Actions:</li>
  59. <li><a href="https://github.com/coss/bnetlib" title="Fork bnetlib on GitHub">Fork</a></li>
  60. <li><a href="https://github.com/coss/bnetlib/toggle_watch" title="Watch bnetlib on GitHub">Watch</a></li>
  61. <li><a href="https://github.com/coss/bnetlib/issues" title="Report an Issue">Issues</a></li>
  62. </ul>
  63. </section>
  64. <h1 id="lib"><a href="http://coss.github.com/bnetlib" title="End User Documentation">bnetlib</a></h1>
  65. </header>
  66. <section>
  67. <section>
  68. <article>
  69. <div class="inner">
  70. <h1>Character and Guild Demo</h1>
  71. <?php
  72. use bnetlib\Locale\Locale;
  73. use bnetlib\Connection\Stub;
  74. use bnetlib\WorldOfWarcraft;
  75. use bnetlib\Resource\Entity\Wow\Guild\News;
  76. $locale = new Locale(Stub::LOCALE_GB, WorldOfWarcraft::SHORT_NAME);
  77. $wow = new WorldOfWarcraft(new Stub());
  78. $wow->getConnection()->setOptions(array(
  79. 'defaults' => array(
  80. 'region' => Stub::REGION_EU
  81. )
  82. ));
  83. $wow->getServiceLocator()->setLocale($locale);
  84. $guild = $wow->getGuild(array(
  85. 'realm' => 'Blackrock',
  86. 'name' => 'Roots of Dragonmaw'
  87. ));
  88. $char = $wow->getCharacter(array(
  89. 'realm' => 'Blackrock',
  90. 'name' => 'Coss',
  91. 'fields' => array(
  92. 'guild',
  93. 'talents',
  94. 'reputation',
  95. 'titles',
  96. 'professions',
  97. ),
  98. ));
  99. $tbn = $wow->getThumbnail($char);
  100. printf(
  101. '<h2><img src="data:image/jpeg;base64,%s" height="26" wight="26"> %s</h2>',
  102. base64_encode($tbn->getData()),
  103. $char->getFullName()
  104. );
  105. echo '<table><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>';
  106. echo '<tr>';
  107. echo '<td>Name</td>';
  108. printf('<td>%s</td>',$char->getName());
  109. echo '</tr><tr>';
  110. echo '<td>Realm</td>';
  111. printf('<td>%s</td>', $char->getRealm());
  112. echo '</tr><tr>';
  113. echo '<td>Level</td>';
  114. printf('<td>%d</td>', $char->getLevel());
  115. echo '</tr><tr>';
  116. echo '<td>Race</td>';
  117. printf('<td>%s</td>', $char->getRaceLocale());
  118. echo '</tr><tr>';
  119. echo '<td>Class</td>';
  120. printf('<td>%s</td>', $char->getClassLocale());
  121. echo '</tr><tr>';
  122. echo '<td>Gender</td>';
  123. printf('<td>%s</td>', $char->getGenderLocale());
  124. echo '</tr><tr>';
  125. echo '<td>Faction</td>';
  126. printf('<td>%s</td>', $char->getFactionLocale());
  127. echo '</tr><tr>';
  128. echo '<td>Talent Specialization</td>';
  129. printf(
  130. '<td>%s (%s)</td>',
  131. $char->getTalents()->getSelectedSpec()->getName(),
  132. $char->getTalents()->getSelectedSpec()->getSimpleBuild()
  133. );
  134. echo '</tr><tr>';
  135. echo '<td>Professions</td><td>';
  136. $profs = array();
  137. foreach ($char->getProfessions() as $prof) {
  138. $profs[] = sprintf('%s (%d/%d)', $prof->getName(), $prof->getRank(), $prof->getMaxRank());
  139. }
  140. echo implode('<br>', $profs);
  141. echo '</td></tr><tr>';
  142. echo '<td>Reputation</td><td>';
  143. $reps = array();
  144. foreach ($char->getReputation() as $faction) {
  145. if (!isset($reps[$faction->getStandingLocale()])) {
  146. $reps[$faction->getStandingLocale()] = 0;
  147. }
  148. $reps[$faction->getStandingLocale()] += 1;
  149. }
  150. $output = array();
  151. foreach ($reps as $key => $value) {
  152. $output[] = $key . ': ' . $value;
  153. }
  154. echo implode('<br>', $output);
  155. echo '</td></tr><tr>';
  156. echo '<td>Achievement Points</td>';
  157. printf('<td>%s</td>', $char->getAchievementPoints());
  158. echo '</tr><tr>';
  159. echo '<td>Last Modified</td>';
  160. printf('<td>%s</td>', $char->getDate()->format('l, d F Y H:i:s'));
  161. echo '</tr>';
  162. echo '</tbody></table>';
  163. printf('<h2>%s</h2>', $guild->getName());
  164. echo '<table><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>';
  165. echo '<tr>';
  166. echo '<td>Realm</td>';
  167. printf('<td>%s</td>', $guild->getRealm());
  168. echo '</tr><tr>';
  169. echo '<td>Level</td>';
  170. printf('<td>%d</td>', $guild->getLevel());
  171. echo '</tr><tr>';
  172. echo '<td>Faction</td>';
  173. printf('<td>%s</td>', $guild->getFactionLocale());
  174. echo '</tr><tr>';
  175. echo '<td>Achievement Points</td>';
  176. printf('<td>%s</td>', $guild->getAchievementPoints());
  177. echo '</tr><tr>';
  178. echo '<td>Members</td>';
  179. printf('<td>%s</td>', count($guild->getMembers()));
  180. echo '</tr><tr>';
  181. echo '<td>Last Modified</td>';
  182. printf('<td>%s</td>', $guild->getDate()->format('l, d F Y H:i:s'));
  183. echo '</tr>';
  184. echo '</tbody></table>';
  185. echo '<h3>Members</h3>';
  186. echo '<table><thead><tr><th class="center">Rank</th><th>Character</th></tr></thead><tbody>';
  187. foreach ($guild->getMembers() as $member) {
  188. echo '<tr>';
  189. printf('<td class="center">%d</td>', $member->getRank());
  190. printf(
  191. '<td>%s, Level %d %s %s with %d Achievement Points</td>',
  192. $member->getCharacter()->getName(),
  193. $member->getCharacter()->getLevel(),
  194. $member->getCharacter()->getRaceLocale(),
  195. $member->getCharacter()->getClassLocale(),
  196. $member->getCharacter()->getAchievementPoints()
  197. );
  198. echo '</tr>';
  199. }
  200. echo '</tbody></table>';
  201. echo '<h3>News</h3>';
  202. $news = $guild->getNews()->getByType(News::TYPE_ITEM_PURCHASE);
  203. if ($news === null) {
  204. echo '<p>No News with the type of ' . News::TYPE_ITEM_PURCHASE . '</p>';
  205. } else {
  206. echo '<table class="center"><thead><tr><th>Character</th>';
  207. echo '<th>Id</th><th>Date</th></tr></thead><tbody>';
  208. foreach ($news as $entry) {
  209. echo '<tr>';
  210. printf('<td>%s</td>', $entry->getCharacter());
  211. printf('<td>%d</td>', $entry->getItemId());
  212. printf('<td>%s</td>', $entry->getDate()->format('l, d F Y H:i:s'));
  213. echo '</tr>';
  214. }
  215. echo '</tbody></table>';
  216. }
  217. ?>
  218. </div>
  219. </article>
  220. </section>
  221. <footer>
  222. Š 2012 Eric Boh. All rights reserved.
  223. </footer>
  224. </div>
  225. </body>
  226. </html>