PageRenderTime 73ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/demos/WoWBattlegroupAndRealms.php

https://github.com/bforchhammer/bnetlib
PHP | 205 lines | 186 code | 15 blank | 4 comment | 1 complexity | 443d24fe40bb8e65a16927854b2ea6f2 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>Battlegroup and Realms 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:left}
  40. td{border-top:1px solid #d0d0d0}
  41. td.right{text-align:right}
  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. </style>
  46. <body>
  47. <div id="main">
  48. <header>
  49. <section>
  50. <ul>
  51. <li>Docs:</li>
  52. <li><a href="http://coss.github.com/bnetlib/api" title="API Documentation">API</a></li>
  53. <li><a href="http://coss.github.com/bnetlib" title="End User Documentation">End-User</a></li>
  54. <li class="nav-space">Downlaod:</li>
  55. <li><a href="https://github.com/coss/bnetlib/zipball/master" title="Download as .zip">Zip</a></li>
  56. <li><a href="https://github.com/coss/bnetlib/tarball/master" title="Download as .tar.gz">Tar</a></li>
  57. <li class="nav-space">Actions:</li>
  58. <li><a href="https://github.com/coss/bnetlib" title="Fork bnetlib on GitHub">Fork</a></li>
  59. <li><a href="https://github.com/coss/bnetlib/toggle_watch" title="Watch bnetlib on GitHub">Watch</a></li>
  60. <li><a href="https://github.com/coss/bnetlib/issues" title="Report an Issue">Issues</a></li>
  61. </ul>
  62. </section>
  63. <h1 id="lib"><a href="http://coss.github.com/bnetlib" title="End User Documentation">bnetlib</a></h1>
  64. </header>
  65. <section>
  66. <section>
  67. <article>
  68. <div class="inner">
  69. <h1>Battlegroup and Realms Demo</h1>
  70. <?php
  71. use bnetlib\Locale\Locale;
  72. use bnetlib\Connection\Stub;
  73. use bnetlib\WorldOfWarcraft;
  74. use bnetlib\Resource\Entity\Wow\Realms;
  75. $locale = new Locale(Stub::LOCALE_GB, WorldOfWarcraft::SHORT_NAME);
  76. $wow = new WorldOfWarcraft(new Stub());
  77. $wow->getConnection()->setOptions(array(
  78. 'defaults' => array(
  79. 'region' => Stub::REGION_EU
  80. )
  81. ));
  82. $wow->getServiceLocator()->setLocale($locale);
  83. $realms = $wow->getRealms();
  84. $battlegroups = $wow->getBattlegroups();
  85. echo '<h2>Battlegroups</h2>';
  86. echo '<table><thead><tr><th class="center">Realms</th><th>Name</th><th>Slug</th></tr></thead><tbody>';
  87. $bgList = array();
  88. foreach ($battlegroups as $battlegroup) {
  89. $realmCount = count($realms->getByBattlegroup($battlegroup->getName()));
  90. if ($realmCount > 0) {
  91. $bgList[] = $battlegroup;
  92. }
  93. echo '<tr>';
  94. printf('<td class="center">%d</td>', $realmCount);
  95. printf('<td>%s</td>', $battlegroup->getName());
  96. printf('<td>%s</td>', $battlegroup->getSlug());
  97. echo '</tr>';
  98. }
  99. echo '</tbody></table>';
  100. echo '<h2>Tol Barad Ratio</h2>';
  101. $realmTypes = array(
  102. 'pvp' => 'PvP',
  103. 'pve' => 'PvE',
  104. 'rp' => 'RP-PvE',
  105. 'rppvp' => 'RP-PvP',
  106. );
  107. $tolBaradRatio = array(
  108. 'Total' => array('a' => 0, 'h' => 0),
  109. 'PvP' => array('a' => 0, 'h' => 0),
  110. 'PvE' => array('a' => 0, 'h' => 0),
  111. 'RP-PvE' => array('a' => 0, 'h' => 0),
  112. 'RP-PvP' => array('a' => 0, 'h' => 0),
  113. );
  114. foreach ($realmTypes as $key => $value) {
  115. foreach ($realms->getByType($key) as $realm) {
  116. $tolBarad = $realm->getTolBarad();
  117. $faction = $tolBarad->isAllianceControlled() ? 'a' : 'h';
  118. $tolBaradRatio[$value][$faction] += 1;
  119. $tolBaradRatio['Total'][$faction] += 1;
  120. }
  121. }
  122. echo '<table><tbody>';
  123. foreach ($tolBaradRatio as $name => $ratio) {
  124. echo '<tr>';
  125. printf('<td class="right"><strong>%s</strong></td>', $name);
  126. echo '<td>';
  127. printf(
  128. '<table class="center"><thead><tr><th>%s</th><th>%s</th></tr></thead><tbody>',
  129. $locale->get('faction.0'),
  130. $locale->get('faction.1')
  131. );
  132. echo '<tr>';
  133. printf(
  134. '<td>%d (%.2f%%)</td>',
  135. $ratio['a'],
  136. ($ratio['a'] / ($ratio['a'] + $ratio['h'])) * 100
  137. );
  138. printf(
  139. '<td>%d (%.2f%%)</td>',
  140. $ratio['h'],
  141. ($ratio['h'] / ($ratio['a'] + $ratio['h'])) * 100
  142. );
  143. echo '</tr>';
  144. echo '</tbody></table>';
  145. echo '</td></tr>';
  146. }
  147. echo '</tbody></table>';
  148. $bg = array_rand($bgList);
  149. printf('<h2>Battlegroup: %s (%s)</h2>', $bgList[$bg]->getName(), $bgList[$bg]->getSlug());
  150. $bgRealms = $realms->getByBattlegroup($bgList[$bg]->getName());
  151. foreach ($bgRealms as $realm) {
  152. printf('<h3>%s</h3>', $realm->getName());
  153. echo '<table><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>';
  154. echo '<tr>';
  155. echo '<td>Online</td>';
  156. printf('<td>%s</td>', ($realm->isOnline()) ? 'Yes' : 'No');
  157. echo '</tr><tr>';
  158. echo '<td>Queue</td>';
  159. printf('<td>%s</td>', ($realm->hasQueue()) ? 'Yes' : 'No');
  160. echo '</tr><tr>';
  161. echo '<td>Type</td>';
  162. printf('<td>%s</td>', $realm->getType());
  163. echo '</tr><tr>';
  164. echo '<td>Population</td>';
  165. printf('<td>%s</td>', $realm->getPopulation());
  166. echo '</tr><tr>';
  167. echo '<td>Area</td>';
  168. printf('<td>Tol Barad (%d)</td>', $realm->getTolBarad()->getArea());
  169. echo '</tr><tr>';
  170. echo '<td>Controlling Faction</td>';
  171. printf('<td>%s</td>', $realm->getTolBarad()->getControllingFactionLocale());
  172. echo '</tr><tr>';
  173. echo '<td>PvP Area Status</td>';
  174. printf('<td>%s</td>', $realm->getTolBarad()->getStatusLocale());
  175. echo '</tr><tr>';
  176. echo '<td>Next Match</td>';
  177. printf('<td>%s</td>', $realm->getTolBarad()->getDate()->format('l, d F Y H:i:s'));
  178. echo '</tr>';
  179. echo '</tbody></table>';
  180. }
  181. ?>
  182. </div>
  183. </article>
  184. </section>
  185. <footer>
  186. Š 2012 Eric Boh. All rights reserved.
  187. </footer>
  188. </div>
  189. </body>
  190. </html>