PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/betfairDemoView.class.php

https://github.com/sangau001/bflib
PHP | 166 lines | 102 code | 13 blank | 51 comment | 4 complexity | f665811e090f5cc2041f98fe9f75550a MD5 | raw file
  1. <?php
  2. /**
  3. Copyright Christopher Lacy-Hulbert 2009
  4. This file is part of Bflib.
  5. Bflib is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Bflib is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Bflib. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /**
  17. * 'View' class with display methods for rendering data received by the bflib Demo application controller
  18. * This code will likely be rewritten for any site/product which implements this library, so that
  19. * data can be rendered appropriately. However, the data flow back to the controller will likely
  20. * remain intact whatever your end implementation.
  21. *
  22. * @author Chris Lacy-Hulbert <chris@spiration.co.uk>
  23. */
  24. class betfairDemoView {
  25. private $context;
  26. private $soapResponse;
  27. /**
  28. * constructor
  29. *
  30. */
  31. public function __construct(){ }
  32. /**
  33. * register the current context
  34. *
  35. * @param string $val context name
  36. */
  37. public function setContext( $val ){
  38. $this->context = $val;
  39. }
  40. /**
  41. * store the soapResponse data
  42. * @param array $val
  43. */
  44. public function setSoapResponse( $val ){
  45. $this->soapResponse = $val;
  46. $this->soapResponse->Result->header->sessionToken='concealed';
  47. }
  48. /**
  49. * construct markup to return to controller, rendering the soapResponse data
  50. *
  51. */
  52. public function render( ){
  53. $chunk = '';
  54. $displayUnit='';
  55. $hostname = betfairDemoConstants::HOSTNAME;
  56. switch( $this->context ){
  57. case 'getAllEventTypes':
  58. foreach($this->soapResponse->Result->eventTypeItems->EventType as $eventType){
  59. $displayUnit.="<li><p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getEvents/{$eventType->id}'>{$eventType->name}</a></li>";
  60. }
  61. break;
  62. case 'getEvents':
  63. /* either this is another list of event nodes, or it is a market summary */
  64. if(isset($this->soapResponse->Result->marketItems->MarketSummary)){
  65. if(is_array($this->soapResponse->Result->marketItems->MarketSummary)){
  66. foreach($this->soapResponse->Result->marketItems->MarketSummary as $market){
  67. $displayUnit.="<li><p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getMarket/{$market->marketId}'>{$market->marketName}</a></p></li>";
  68. }
  69. }else{
  70. $market = $this->soapResponse->Result->marketItems->MarketSummary;
  71. $displayUnit.="<li><p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getMarket/{$market->marketId}'>{$market->marketName}</a></p></li>";
  72. }
  73. }if(isset($this->soapResponse->Result->eventItems->BFEvent)){
  74. /*
  75. * if it's an array, there are more than one events, otherwise there is just one
  76. * this is somewhat broken in that the datatype switches from an object to an object array depending on
  77. * the number of items. Probably it would be better if BF just served up an array with a
  78. * single object in it in cases where there is only one eventItem under an eventParent
  79. *
  80. */
  81. if(is_array($this->soapResponse->Result->eventItems->BFEvent)){
  82. foreach($this->soapResponse->Result->eventItems->BFEvent as $event){
  83. $displayUnit.="<li><p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getEvents/{$event->eventId}'>{$event->eventName}</a></p></li>";
  84. }
  85. }else{
  86. $event = $this->soapResponse->Result->eventItems->BFEvent;
  87. $displayUnit.="<li><p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getEvents/{$event->eventId}'>{$event->eventName}</a></p></li>";
  88. }
  89. }
  90. break;
  91. case 'getAllMarkets':
  92. $markets = explode(":",$this->soapResponse->Result->marketData);
  93. array_shift($markets);
  94. foreach($markets as $market){
  95. $marketData = explode('~',$market);
  96. $displayUnit.="<li> {$marketData[1]}
  97. <a href='http://".betfairDemoConstants::HOSTNAME."/v1/getCompleteMarketPricesCompressed/{$marketData[0]}'>get compressed</a> |
  98. <a href='http://".betfairDemoConstants::HOSTNAME."/v1/getMarketPriceCompressed/{$marketData[0]}'>get market</a> |
  99. <a href='http://".betfairDemoConstants::HOSTNAME."/v1/getBFMarketPrices/{$marketData[0]}'>get BF market prices</a> |
  100. </li>";
  101. }
  102. break;
  103. case 'getInPlayMarkets':
  104. $markets = explode(":",$this->soapResponse->Result->marketData);
  105. array_shift($markets);
  106. foreach($markets as $market){
  107. $marketData = explode('~',$market);
  108. $displayUnit.="<li><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getCompleteMarketPricesCompressed/{$marketData[0]}'>{$marketData[1]}</a></li>";
  109. }
  110. break;
  111. case 'getMarket':
  112. if(betfairConstants::ERROR_OK === $this->soapResponse->Result->header->errorCode){
  113. $marketDescription = $this->soapResponse->Result->market->marketDescription;
  114. include('templates/marketData.tpl.php');
  115. $displayUnit=betfairHelper::returnVar($this->soapResponse);
  116. }else{
  117. }
  118. break;
  119. case 'getCompleteMarketPricesCompressed':
  120. $displayUnit=betfairHelper::returnVar($this->soapResponse);
  121. break;
  122. case 'getBFMarketPrices':
  123. $displayUnit='<table>';
  124. foreach($this->soapResponse->allRunnerData as &$runner){
  125. $displayUnit.='<tr>';
  126. foreach($runner->prices as $priceDetails){
  127. $displayUnit.='<p>odds:'.$priceDetails->odds.'- back: '.$priceDetails->backAmountAvailable.'- lay: '.$priceDetails->layAmountAvailable;
  128. $displayUnit.='</p>';
  129. }
  130. $displayUnit.='</tr>';
  131. }
  132. $displayUnit.='</table>';
  133. break;
  134. default:
  135. $displayUnit.="<p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getAllEventTypes/'>get all event types</a></p>";
  136. $displayUnit.="<p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getAccountFunds/'>get account funds</a></p>";
  137. $displayUnit.="<p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getAllCurrencies/'>get all currencies</a></p>";
  138. $displayUnit.="<p><a href='http://".betfairDemoConstants::HOSTNAME."/v1/getPaymentCard/'>get payment card</a></p>";
  139. break;
  140. }
  141. include('templates/header.tpl.php');
  142. include('templates/body.tpl.php');
  143. $chunk .= <<<EOT
  144. </div>
  145. EOT;
  146. return($chunk);
  147. }
  148. }
  149. ?>