1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
<?php
/**
*
* @author Christian Doebler <christian.doebler@netways.de>
*
*/
class IcingaApiResultIdo
extends IcingaApiResult {
/*
* VARIABLES
*/
/*
* METHODS
*/
/**
* class constructor
*
* @param void
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function __construct () {}
/**
* sets the search object
*
* @param PDOStatement $object search object for further processing
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function setSearchObject (&$object) {
$this->searchObject = $object;
$this->numResults = $this->searchObject->rowCount();
}
/**
* sets next result row
*
* @param void
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function next () {
switch ($this->resultType) {
case self::RESULT_OBJECT:
$this->resultRow = $this->searchObject->fetchObject();
if ($this->resultRow !== false) {
if ($this->offset === false) {
$this->offset = 0;
} else {
$this->offset++;
}
} else {
$this->offset = false;
}
break;
case self::RESULT_ARRAY:
if ($this->resultArray === false) {
$this->resultArray = $this->searchObject->fetchAll(PDO::FETCH_ASSOC);
if ($this->resultType == self::RESULT_ARRAY && $this->dbType == 'oci') {
$this->resultArray = array_change_key_case($this->resultArray, CASE_LOWER);
}
}
if ($this->offset === false) {
$this->offset = 0;
} else {
$this->offset++;
}
if ($this->offset >= $this->numResults) {
$this->offset = false;
}
if ($this->offset !== false) {
$this->resultRow = $this->resultArray[$this->offset];
} else {
$this->resultRow = false;
}
break;
}
}
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResult#rewind()
*/
public function rewind () {
switch ($this->resultType) {
case self::RESULT_OBJECT:
// TODO: implement rewind for objects
// throw new IcingaApiResultException('rewind() not supported by target type!');
break;
case self::RESULT_ARRAY:
$this->offset = false;
$this->next();
break;
}
}
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResult#getAll()
*/
public function getAll () {
$returnData = false;
switch ($this->resultType) {
case self::RESULT_OBJECT:
// TODO: implement getting complete result set for objects
throw new IcingaApiResultException('getAll() not supported by target type!');
break;
case self::RESULT_ARRAY:
$returnData = $this->resultArray;
break;
}
return $returnData;
}
}
?>
|