Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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