PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/demos/WowAuction.php

https://github.com/bforchhammer/bnetlib
PHP | 157 lines | 135 code | 16 blank | 6 comment | 4 complexity | e3486bff989f6d8b57ba2e604b6b9abc MD5 | raw file
  1. <?php
  2. include dirname(__DIR__) . '/autoload_register.php';
  3. $goldIntToString = function ($int) {
  4. $currency = array(
  5. 'g' => round($int / 10000, 0),
  6. 's' => round(($int % 10000) / 100, 0),
  7. 'c' => round(($int % 10000) % 100, 0),
  8. );
  9. $return = array();
  10. foreach ($currency as $symbol => $value) {
  11. if ($value > 0) {
  12. $return[] = $value . $symbol;
  13. }
  14. }
  15. return implode(' ', $return);
  16. };
  17. ?>
  18. <!doctype html>
  19. <html>
  20. <head>
  21. <meta charset="utf-8">
  22. <title>Auction Demo</title>
  23. </head>
  24. <style type="text/css" media="screen">
  25. body{color:#444;background:#ddd;font:normal 14px/20px 'Helvetica Neue',Helvetica,Arial,sans-serif}
  26. a{color:#82bd1a;text-decoration:none}
  27. a:hover{text-decoration:underline}
  28. article a{font-weight:bold}
  29. p,dl{margin:0 0 15px}
  30. h1,h2,h3{color:#555;margin:0 0 30px}
  31. h1{font-size:28px}
  32. h2{font-size:21px}
  33. h3{font-size:17px}
  34. hgroup h1{margin:0 0 15px}
  35. p:last-child,dl:last-child{margin:0}
  36. #main{width:800px;margin:75px auto}
  37. #lib{font-size:40px}
  38. #lib a{color:#444}
  39. #lib a:hover,#lib a:focus{color:#82bd1a;text-decoration:none}
  40. footer{clear:both;color:#999;font-size:11px}
  41. section>section{margin:0;width:800px}
  42. 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}
  43. section>ul{margin:0;padding:0;list-style:none;font-weight:bold}
  44. header>section{top:0;right:2px;float:right;position:relative}
  45. section>ul>li{font-size:13px;margin-left:5px;display:inline-block}
  46. .nav-space{margin-left:25px}
  47. 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}
  48. .inner{padding:30px}
  49. section>ul>li>a:hover,section>ul>li>a:focus{color:#eee;background:#82bd1a;text-decoration:none}
  50. table{width:100%;border-spacing:0;border-collapse:collapse;margin-bottom:25px}
  51. table:last-of-type{margin:0}
  52. th{font-weight:bold}
  53. th,td{padding:4px 7px;text-align:center}
  54. td{border-top:1px solid #d0d0d0}
  55. tr:hover{background:#f5f5f5}
  56. tr tr:hover{background:#e9e9e9}
  57. </style>
  58. <body>
  59. <div id="main">
  60. <header>
  61. <section>
  62. <ul>
  63. <li>Docs:</li>
  64. <li><a href="http://coss.github.com/bnetlib/api" title="API Documentation">API</a></li>
  65. <li><a href="http://coss.github.com/bnetlib" title="End User Documentation">End-User</a></li>
  66. <li class="nav-space">Downlaod:</li>
  67. <li><a href="https://github.com/coss/bnetlib/zipball/master" title="Download as .zip">Zip</a></li>
  68. <li><a href="https://github.com/coss/bnetlib/tarball/master" title="Download as .tar.gz">Tar</a></li>
  69. <li class="nav-space">Actions:</li>
  70. <li><a href="https://github.com/coss/bnetlib" title="Fork bnetlib on GitHub">Fork</a></li>
  71. <li><a href="https://github.com/coss/bnetlib/toggle_watch" title="Watch bnetlib on GitHub">Watch</a></li>
  72. <li><a href="https://github.com/coss/bnetlib/issues" title="Report an Issue">Issues</a></li>
  73. </ul>
  74. </section>
  75. <h1 id="lib"><a href="http://coss.github.com/bnetlib" title="End User Documentation">bnetlib</a></h1>
  76. </header>
  77. <section>
  78. <section>
  79. <article>
  80. <div class="inner">
  81. <h1>Auction Demo</h1>
  82. <?php
  83. use bnetlib\Locale\Locale;
  84. use bnetlib\Connection\Stub;
  85. use bnetlib\WorldOfWarcraft;
  86. use bnetlib\Resource\Entity\Wow\Auction\Faction;
  87. $locale = new Locale(Stub::LOCALE_GB, WorldOfWarcraft::SHORT_NAME);
  88. $wow = new WorldOfWarcraft(new Stub());
  89. $wow->getConnection()->setOptions(array(
  90. 'defaults' => array(
  91. 'region' => Stub::REGION_EU
  92. )
  93. ));
  94. $wow->getServiceLocator()->setLocale($locale);
  95. $auction = $wow->getAuction(array('realm' => 'Die ewige Wacht'));
  96. $auctionData = $wow->getAuctionData($auction);
  97. foreach (array(0 => 'getAlliance', 1 => 'getHorde') as $id => $method) {
  98. printf('<h2>%s</h2>', $locale->get('faction.' . $id));
  99. /* @var $faction Faction */
  100. $faction = call_user_func(array($auctionData, $method));
  101. $ruby = $faction->getByItem(52986);
  102. if (empty($ruby)) {
  103. echo '<p>No "Heartblossom" listed.</p>';
  104. } else {
  105. printf(
  106. '<p>Found <strong>%d</strong> entries for "Heartblossom". '
  107. . 'The duration for <strong>%d</strong> auctions is "Short".</p>',
  108. count($ruby),
  109. /* $faction->getItemAndTimeIntersection(52177, 'SHORT') works too */
  110. count($faction->getItemAndTimeIntersection(52177, Faction::TIME_SHORT))
  111. );
  112. echo '<table><thead><tr><th>Auction Id</th><th>Quantity</th><th>Owner</th>';
  113. echo '<th>Bid</th><th>Buyout</th><th>Duration</th></tr></thead><tbody>';
  114. foreach ($ruby as $key => $auction) {
  115. $marked = ($auction->isShort()) ? ' style="background: #FBE7E7;"' : '';
  116. $marked = ($auction->isVeryLong()) ? ' style="background: #E7F9D6;"' : $marked;
  117. echo '<tr' . $marked . '>';
  118. printf('<td>%d</td>', $auction->getId());
  119. printf('<td>%d</td>', $auction->getQuantity());
  120. printf('<td>%s</td>', $auction->getOwner());
  121. printf('<td>%s</td>', $goldIntToString($auction->getBid()));
  122. printf('<td>%s</td>', $goldIntToString($auction->getBuyout()));
  123. printf('<td>%s</td>', $auction->getTimeLeftLocale());
  124. echo '</tr>';
  125. }
  126. echo '</tbody></table>';
  127. }
  128. if ($id === 0) {
  129. echo '<br><br>';
  130. }
  131. }
  132. ?>
  133. </div>
  134. </article>
  135. </section>
  136. <footer>
  137. Š 2012 Eric Boh. All rights reserved.
  138. </footer>
  139. </div>
  140. </body>
  141. </html>