/www/api/v2/xmlrpc/TrackerXmlRpcService.php

https://bitbucket.org/blackriver/openx · PHP · 174 lines · 98 code · 23 blank · 53 comment · 15 complexity · 772c24888b0a13f75be050b6a18c22a5 MD5 · raw file

  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: TrackerXmlRpcService.php 81772 2012-09-11 00:07:29Z chris.nutting $
  25. */
  26. require_once '../../../../init.php';
  27. require_once MAX_PATH . '/lib/pear/XML/RPC/Server.php';
  28. require_once MAX_PATH . '/www/api/v2/common/BaseTrackerService.php';
  29. require_once MAX_PATH . '/www/api/v2/common/XmlRpcUtils.php';
  30. require_once MAX_PATH . '/lib/OA/Dll/Tracker.php';
  31. /**
  32. * Description of TrackerXmlRpcService
  33. *
  34. * @author David Keen <david.keen@openx.org>
  35. */
  36. class TrackerXmlRpcService extends BaseTrackerService
  37. {
  38. /**
  39. * Adds a tracker.
  40. *
  41. * @param XML_RPC_Message &$oParams
  42. * @return generated result (data or error)
  43. */
  44. public function addTracker(&$oParams)
  45. {
  46. $sessionId = null;
  47. $oTrackerInfo = new OA_Dll_TrackerInfo();
  48. $oResponseWithError = null;
  49. if (!XmlRpcUtils::getRequiredScalarValue($sessionId, $oParams, 0,
  50. $oResponseWithError) ||
  51. !XmlRpcUtils::getStructureScalarFields($oTrackerInfo, $oParams, 1,
  52. array('clientId', 'trackerName', 'description', 'status',
  53. 'type', 'linkCampaigns', 'variableMethod'),
  54. $oResponseWithError)) {
  55. return $oResponseWithError;
  56. }
  57. if ($this->oTrackerServiceImpl->addTracker($sessionId, $oTrackerInfo)) {
  58. return XmlRpcUtils::integerTypeResponse($oTrackerInfo->trackerId);
  59. } else {
  60. return XmlRpcUtils::generateError($this->oTrackerServiceImpl->getLastError());
  61. }
  62. }
  63. /**
  64. * Changes the details for an existing tracker.
  65. *
  66. * @param XML_RPC_Message &$oParams
  67. *
  68. * @return generated result (data or error)
  69. */
  70. public function modifyTracker(&$oParams)
  71. {
  72. $sessionId = null;
  73. $oTrackerInfo = new OA_Dll_TrackerInfo();
  74. $oResponseWithError = null;
  75. if (!XmlRpcUtils::getRequiredScalarValue($sessionId, $oParams, 0,
  76. $oResponseWithError) ||
  77. !XmlRpcUtils::getStructureScalarFields($oTrackerInfo, $oParams, 1,
  78. array('trackerId', 'trackerName', 'description', 'status',
  79. 'type', 'linkCampaigns', 'variableMethod'),
  80. $oResponseWithError)) {
  81. return $oResponseWithError;
  82. }
  83. if ($this->oTrackerServiceImpl->modifyTracker($sessionId, $oTrackerInfo)) {
  84. return XmlRpcUtils::booleanTypeResponse(true);
  85. } else {
  86. return XmlRpcUtils::generateError($this->oTrackerServiceImpl->getLastError());
  87. }
  88. }
  89. /**
  90. *
  91. * @param XML_RPC_Message &$oParams
  92. *
  93. * @return generated result (data or error)
  94. */
  95. public function deleteTracker(&$oParams)
  96. {
  97. $sessionId = null;
  98. $trackerId = null;
  99. $oResponseWithError = null;
  100. if (!XmlRpcUtils::getScalarValues(array(&$sessionId, &$trackerId),
  101. array(true, true), $oParams, $oResponseWithError )) {
  102. return $oResponseWithError;
  103. }
  104. if ($this->oTrackerServiceImpl->deleteTracker($sessionId, $trackerId)) {
  105. return XmlRpcUtils::booleanTypeResponse(true);
  106. } else {
  107. return XmlRpcUtils::generateError($this->oTrackerServiceImpl->getLastError());
  108. }
  109. }
  110. /**
  111. *
  112. * @param XML_RPC_Message $oParams
  113. * @return generated result (data or error)
  114. */
  115. function linkTrackerToCampaign($oParams)
  116. {
  117. $sessionId = null;
  118. $trackerId = null;
  119. $status = null;
  120. $oResponseWithError = null;
  121. if (!XmlRpcUtils::getScalarValues(
  122. array(&$sessionId, &$trackerId, &$campaignId, &$status),
  123. array(true, true, true, false), $oParams, $oResponseWithError)) {
  124. return $oResponseWithError;
  125. }
  126. if ($this->oTrackerServiceImpl->linkTrackerToCampaign($sessionId, $trackerId, $campaignId, $status)) {
  127. return XmlRpcUtils::booleanTypeResponse(true);
  128. } else {
  129. return XmlRpcUtils::generateError($this->oTrackerServiceImpl->getLastError());
  130. }
  131. }
  132. public function getTracker(&$oParams)
  133. {
  134. $sessionId = null;
  135. $trackerId = null;
  136. $oTrackerInfo = new OA_Dll_TrackerInfo();
  137. $oResponseWithError = null;
  138. if (!XmlRpcUtils::getScalarValues(
  139. array(&$sessionId, &$trackerId),
  140. array(true, true), $oParams, $oResponseWithError)) {
  141. return $oResponseWithError;
  142. }
  143. if ($this->oTrackerServiceImpl->getTracker($sessionId,
  144. $trackerId, $oTrackerInfo)) {
  145. return XmlRpcUtils::getEntityResponse($oTrackerInfo);
  146. } else {
  147. return XmlRpcUtils::generateError($this->oTrackerServiceImpl->getLastError());
  148. }
  149. }
  150. }
  151. ?>