PageRenderTime 26ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/ebay/ebatns/EbatNs_Result.php

https://gitlab.com/endomorphosis/KindSupply
PHP | 564 lines | 244 code | 1 blank | 319 comment | 18 complexity | 6d59544f6440b8731bdb68b474702939 MD5 | raw file
  1. <?php
  2. // $Id: EbatNs_Result.php,v 1.1 2007/05/31 11:38:00 michael Exp $
  3. /* $Log: EbatNs_Result.php,v $
  4. /* Revision 1.1 2007/05/31 11:38:00 michael
  5. /* - initial checkin
  6. /* - version < 513
  7. /*
  8. *
  9. * 3 3.02.06 10:44 Mcoslar
  10. *
  11. * 2 30.01.06 16:44 Mcoslar
  12. * �nderungen eingef�gt
  13. */
  14. require_once 'EbatNs_Defines.php';
  15. /**
  16. * DEFINE("EBAY_ERR_SUCCESS", "0");
  17. * DEFINE("EBAY_ERR_ERROR", "1");
  18. * DEFINE("EBAY_ERR_WARNING", "2");
  19. */
  20. class EbatNs_Result {
  21. // this array holds all attribute data of the object
  22. var $_props = array();
  23. /**
  24. * sets a property by name and value
  25. */
  26. function _setProp($key, $value)
  27. {
  28. $this->_props[$key] = $value;
  29. }
  30. /**
  31. * gets a property by name
  32. */
  33. function _getProp($key)
  34. {
  35. return $this->_props[$key];
  36. }
  37. /**
  38. *
  39. * @access private
  40. * @var array
  41. */
  42. var $_errors = array();
  43. /**
  44. *
  45. * @access private
  46. * @var define
  47. */
  48. var $_errorSeverity = EBAY_ERR_SUCCESS;
  49. /**
  50. *
  51. * @access private
  52. * @var number
  53. */
  54. var $_actualPage = 0;
  55. /**
  56. *
  57. * @access private
  58. * @var number
  59. */
  60. var $_numberPages = 1;
  61. /**
  62. *
  63. * @access private
  64. * @var boolean
  65. */
  66. var $_userBreak = false;
  67. /**
  68. *
  69. * @access private
  70. * @var array
  71. */
  72. var $_xmlValues = null;
  73. /**
  74. *
  75. * @access private
  76. * @var array
  77. */
  78. var $_xmlTags = null;
  79. /**
  80. * Read accessor to the ResultMessages.
  81. * Holds any additional message from the eBay system (e.g. Item->Add() will return a message, or Item->End() will return the end-time here)
  82. *
  83. * @access public
  84. * @param integer $index The index of the value to return
  85. * @return string Value of the ResultMessages property
  86. */
  87. function getResultMessages($index)
  88. {
  89. return $this->_props['ResultMessages'][$index];
  90. }
  91. /**
  92. * Return the amount of ResultMessages actually declared
  93. *
  94. * @access public
  95. * @return string Value of the ResultMessages property
  96. */
  97. function getResultMessagesCount()
  98. {
  99. return count($this->_props['ResultMessages']);
  100. }
  101. /**
  102. * Returns a copy of the ResultMessages array
  103. *
  104. * @access public
  105. * @return array of string
  106. */
  107. function getResultMessagesArray()
  108. {
  109. return $this->_props['ResultMessages'];
  110. }
  111. /**
  112. * Write accessor to the ResultMessages.
  113. * Holds any additional message from the eBay system (e.g. Item->Add() will return a message, or Item->End() will return the end-time here)
  114. *
  115. * @access public
  116. * @param string $value The new value for the ResultMessages property
  117. * @param integer $index The index of the value to update. if $index = -1, the value is added to the end of list.
  118. * @return void
  119. */
  120. function setResultMessages($value, $index = -1)
  121. {
  122. if (-1 == $index) {
  123. $index = count($this->_props['ResultMessages']);
  124. }
  125. $this->_props['ResultMessages'][$index] = $value;
  126. }
  127. /**
  128. * Read accessor of ResultStatus.
  129. * Could be used to return various status information codes about success or failure of the calls.
  130. *
  131. * @access public
  132. * @return string Value of the ResultStatus property
  133. */
  134. function getResultStatus()
  135. {
  136. return $this->_props['ResultStatus'];
  137. }
  138. /**
  139. * Write accessor of ResultStatus.
  140. * Could be used to return various status information codes about success or failure of the calls.
  141. *
  142. * @access public
  143. * @param string $value The new value for the ResultStatus property
  144. * @return void
  145. */
  146. function setResultStatus($value)
  147. {
  148. $this->_props['ResultStatus'] = $value;
  149. }
  150. /**
  151. * Read accessor of HasRefreshedToken.
  152. *
  153. * @access public
  154. * @return boolean Value of the HasRefreshedToken property
  155. */
  156. function getHasRefreshedToken()
  157. {
  158. return $this->_props['HasRefreshedToken'];
  159. }
  160. /**
  161. * Write accessor of HasRefreshedToken.
  162. *
  163. * @access public
  164. * @param boolean $value The new value for the HasRefreshedToken property
  165. * @return void
  166. */
  167. function setHasRefreshedToken($value)
  168. {
  169. $this->_props['HasRefreshedToken'] = $value;
  170. }
  171. /**
  172. * Read accessor of HasNewTokenHardExpirationDate.
  173. *
  174. * @access public
  175. * @return boolean Value of the HasNewTokenHardExpirationDate property
  176. */
  177. function getHasNewTokenHardExpirationDate()
  178. {
  179. return $this->_props['HasNewTokenHardExpirationDate'];
  180. }
  181. /**
  182. * Write accessor of HasNewTokenHardExpirationDate.
  183. *
  184. * @access public
  185. * @param boolean $value The new value for the HasNewTokenHardExpirationDate property
  186. * @return void
  187. */
  188. function setHasNewTokenHardExpirationDate($value)
  189. {
  190. $this->_props['HasNewTokenHardExpirationDate'] = $value;
  191. }
  192. /**
  193. * Read accessor of RefreshedToken.
  194. *
  195. * @access public
  196. * @return string Value of the RefreshedToken property
  197. */
  198. function getRefreshedToken()
  199. {
  200. return $this->_props['RefreshedToken'];
  201. }
  202. /**
  203. * Write accessor of RefreshedToken.
  204. *
  205. * @access public
  206. * @param string $value The new value for the RefreshedToken property
  207. * @return void
  208. */
  209. function setRefreshedToken($value)
  210. {
  211. $this->_props['RefreshedToken'] = $value;
  212. }
  213. /**
  214. * Read accessor of HardExpirationDateToken.
  215. *
  216. * @access public
  217. * @return datetime Value of the HardExpirationDateToken property
  218. */
  219. function getHardExpirationDateToken()
  220. {
  221. return $this->_props['HardExpirationDateToken'];
  222. }
  223. /**
  224. * Write accessor of HardExpirationDateToken.
  225. *
  226. * @access public
  227. * @param datetime $value The new value for the HardExpirationDateToken property
  228. * @return void
  229. */
  230. function setHardExpirationDateToken($value)
  231. {
  232. $this->_props['HardExpirationDateToken'] = $value;
  233. }
  234. /**
  235. * Read accessor of SingleValue.
  236. * Various API Methods might return data as a single (scalar) value. All method will return an Ebay_Result, if a method needs to return a single value beside, it should set the value to the result object.
  237. *
  238. * @access public
  239. * @return <unspecified> Value of the SingleValue property
  240. */
  241. function getSingleValue()
  242. {
  243. return $this->_props['SingleValue'];
  244. }
  245. /**
  246. * Write accessor of SingleValue.
  247. * Various API Methods might return data as a single (scalar) value. All method will return an Ebay_Result, if a method needs to return a single value beside, it should set the value to the result object.
  248. *
  249. * @access public
  250. * @param $ <unspecified> $value The new value for the SingleValue property
  251. * @return void
  252. */
  253. function setSingleValue($value)
  254. {
  255. $this->_props['SingleValue'] = $value;
  256. }
  257. /**
  258. * Read accessor of RawLogSeq.
  259. * return the final SeqNo when RawLogMode is used
  260. *
  261. * @access public
  262. * @return number Value of the RawLogSeq property
  263. */
  264. function getRawLogSeq()
  265. {
  266. return $this->_props['RawLogSeq'];
  267. }
  268. /**
  269. * Write accessor of RawLogSeq.
  270. * return the final SeqNo when RawLogMode is used
  271. *
  272. * @access public
  273. * @param number $value The new value for the RawLogSeq property
  274. * @return void
  275. */
  276. function setRawLogSeq($value)
  277. {
  278. $this->_props['RawLogSeq'] = $value;
  279. }
  280. /**
  281. * Read accessor of RawResult.
  282. * holds the rawResult (XML) data. Only set if specified to the call method in the apiCaller
  283. *
  284. * @access public
  285. * @return string Value of the RawResult property
  286. */
  287. function getRawResult()
  288. {
  289. return $this->_props['RawResult'];
  290. }
  291. /**
  292. * Write accessor of RawResult.
  293. * holds the rawResult (XML) data. Only set if specified to the call method in the apiCaller
  294. *
  295. * @access public
  296. * @param string $value The new value for the RawResult property
  297. * @return void
  298. */
  299. function setRawResult($value)
  300. {
  301. $this->_props['RawResult'] = $value;
  302. }
  303. /**
  304. * Standard init function, should be called from the constructor(s)
  305. */
  306. function _init()
  307. {
  308. $this->_props['ResultMessages'] = array();
  309. $this->_props['ResultStatus'] = '';
  310. $this->_props['HasRefreshedToken'] = false;
  311. $this->_props['HasNewTokenHardExpirationDate'] = false;
  312. $this->_props['RefreshedToken'] = EBAY_NOTHING;
  313. $this->_props['HardExpirationDateToken'] = EBAY_NOTHING;
  314. $this->_props['SingleValue'] = EBAY_NOTHING;
  315. $this->_props['RawLogSeq'] = 0;
  316. $this->_props['RawResult'] = EBAY_NOTHING;
  317. }
  318. /**
  319. *
  320. * @access public
  321. * @return boolean
  322. */
  323. function anyErrors()
  324. {
  325. return ($this->_errorSeverity == EBAY_ERR_ERROR) && (count($this->_errors) > 0);
  326. }
  327. /**
  328. *
  329. * @access public
  330. * @param number $index
  331. * @return string
  332. */
  333. function getErrorMessage($index)
  334. {
  335. if (count($this->_errors) >= $index) {
  336. // only returning short-message here for now
  337. if (array_key_exists('LongMessage', $this->_errors[$index])) {
  338. return htmlentities($this->_errors[$index]['LongMessage']);
  339. }else {
  340. if (array_key_exists('ShortMessage', $this->_errors[$index])) {
  341. return htmlentities($this->_errors[$index]['ShortMessage']);
  342. }else {
  343. return "msg not found";
  344. }
  345. }
  346. }else {
  347. return "no error or wrong index";
  348. }
  349. }
  350. /**
  351. *
  352. * @access public
  353. * @param number $index
  354. * @return string
  355. */
  356. function getErrorCode($index)
  357. {
  358. if (count($this->_errors) >= $index) {
  359. return $this->_errors[$index]['Code'];
  360. }else {
  361. return "no error or wrong index";
  362. }
  363. }
  364. /**
  365. * return the error severity as a numeric value. You can use to test on one of following defines:
  366. * EBAY_ERR_SUCCESS (equal to EBAY _ERR_OK)
  367. * EBAY_ERR_WARNING
  368. * EBAY_ERR_ERROR
  369. *
  370. * @access public
  371. * @return define
  372. */
  373. function getErrorSeverity()
  374. {
  375. return $this->_errorSeverity;
  376. }
  377. /**
  378. *
  379. * @access public
  380. * @return number
  381. */
  382. function getActualPage()
  383. {
  384. return $this->_actualPage;
  385. }
  386. /**
  387. *
  388. * @access public
  389. * @return number
  390. */
  391. function getNumberOfPages()
  392. {
  393. return $this->_numberPages;
  394. }
  395. /**
  396. *
  397. * @access public
  398. * @return boolean
  399. */
  400. function isGood()
  401. {
  402. return !$this->anyErrors();
  403. }
  404. /**
  405. *
  406. * @access public
  407. * @return boolean
  408. */
  409. function anyWarnings()
  410. {
  411. return $this->_errorSeverity == EBAY_ERR_WARNING;
  412. }
  413. /**
  414. * Severity is set to the highest level
  415. * so if the Result Object has the warning-Level and
  416. * you set the severity to error, the Results severity will become also error-level
  417. * If the Result-Object is on error-level you can backchange to the warning-level
  418. * please call first with level = 0 to reset the severity and then set to warning-level
  419. *
  420. * @access public
  421. * @param number $level
  422. * @return void
  423. */
  424. function setSeverity($level)
  425. {
  426. switch ($level) {
  427. case EBAY_ERR_SUCCESS:
  428. // resetting the severity
  429. $this->_errorSeverity = EBAY_ERR_SUCCESS;
  430. break;
  431. case EBAY_ERR_ERROR:
  432. $this->_errorSeverity = EBAY_ERR_ERROR;
  433. break;
  434. case EBAY_ERR_WARNING:
  435. if ($this->_errorSeverity != EBAY_ERR_ERROR) {
  436. $this->_errorSeverity = EBAY_ERR_WARNING;
  437. };
  438. break;
  439. }
  440. }
  441. /**
  442. *
  443. * @access public
  444. * @param number $errCode
  445. * @param string $errMessage
  446. * @param define $errSeverity
  447. * @return void
  448. */
  449. function addError($errCode, $errMessage, $errSeverity)
  450. {
  451. $this->setSeverity($errSeverity);
  452. $this->_errors[] = array('LongMessage' => "$errMessage", 'Code' => "$errCode");
  453. }
  454. /**
  455. *
  456. * @access public
  457. * @return void
  458. */
  459. function debugPrintErrors()
  460. {
  461. $c = count($this->_errors);
  462. for ($i = 0; $i < $c; $i++) {
  463. print_r("#" . $this->getErrorCode($i) . " : " . $this->getErrorMessage($i) . "<br>\r\n");
  464. }
  465. }
  466. /**
  467. * signals a break condition, so the retrieval process is aborted
  468. *
  469. * @access public
  470. * @return void
  471. */
  472. function setUserBreak()
  473. {
  474. $this->_userBreak = true;
  475. }
  476. /**
  477. * returns true, if a break has to be handled
  478. *
  479. * @access public
  480. * @return void
  481. */
  482. function hasUserBreak()
  483. {
  484. return $this->_userBreak;
  485. }
  486. /**
  487. *
  488. * @access public
  489. * @return number
  490. */
  491. function getErrorCount()
  492. {
  493. return count($this->_errors);
  494. }
  495. /**
  496. *
  497. * @access public
  498. * @param string $tagName
  499. * @return string
  500. */
  501. function getXmlStructTagContent($tagName)
  502. {
  503. if (isset($this->_xmlTags[$tagName])) {
  504. return $this->_xmlValues[$this->_xmlTags[$tagName][0]]['value'];
  505. }else {
  506. return null;
  507. }
  508. }
  509. /**
  510. *
  511. * @access public
  512. * @param string $tagName
  513. * @param boolean $includeSearchTag if set to true the data returned will include the tag which was search, normally you would just get the inner elements so pass false (which is the default).
  514. * @param $ <unspecified> $searchBackward
  515. * @return array
  516. */
  517. function getXmlStructResultFragment($tagName, $includeSearchTag = false, $searchBackward = false)
  518. {
  519. if ($searchBackward) {
  520. $max = count($this->_xmlTags[$tagName]);
  521. if ($max) {
  522. if ($includeSearchTag) {
  523. $offset = $this->_xmlTags[$tagName][$max - 2];
  524. $len = $this->_xmlTags[$tagName][$max -1] - $this->_xmlTags[$tagName][$max - 2] + 1;
  525. }else {
  526. $offset = $this->_xmlTags[$tagName][$max - 2] + 1;
  527. $len = $this->_xmlTags[$tagName][$max -1] - $this->_xmlTags[$tagName][$max - 2] - 1;
  528. }
  529. }
  530. }else {
  531. if ($includeSearchTag) {
  532. $offset = $this->_xmlTags[$tagName][0];
  533. $len = $this->_xmlTags[$tagName][1] - $this->_xmlTags[$tagName][0] + 1;
  534. }else {
  535. $offset = $this->_xmlTags[$tagName][0] + 1;
  536. $len = $this->_xmlTags[$tagName][1] - $this->_xmlTags[$tagName][0] - 1;
  537. }
  538. }
  539. return array_slice($this->_xmlValues, $offset, $len);
  540. }
  541. /**
  542. *
  543. * @access public
  544. * @return string
  545. */
  546. function getToolkitVersion()
  547. {
  548. return "1.0.403.0";
  549. }
  550. /**
  551. *
  552. * @access public
  553. * @return void
  554. */
  555. function EbatNs_Result()
  556. {
  557. // call to initialisation
  558. // (be sure to call this always on the actual class and prevent any overwriting)
  559. EbatNs_Result::_init();
  560. // insert code here...
  561. }
  562. }
  563. ?>