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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
<?php
/**
*
* @author Christian Doebler <christian.doebler@netways.de>
*
*/
abstract class IcingaApiResult
extends IcingaApi
implements Iterator, IcingaApiResultInterface {
/*
* VARIABLES
*/
protected $searchObject = false;
protected $resultType = self::RESULT_OBJECT;
protected $resultArray = false;
protected $resultRow = false;
protected $numResults = false;
protected $offset = false;
protected $dbType = false;
/*
* METHODS
*/
/**
* class constructor
*
* @param void
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function __construct () {}
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResultInterface#__get()
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function __get ($name) {
$returnValue = false;
switch ($this->resultType) {
case self::RESULT_OBJECT:
if ($this->resultRow->{$name} === null) {
throw new IcingaApiResultException('Search field "' . $name . '" not available!');
} else {
$returnValue = $this->resultRow->{$name};
}
break;
case self::RESULT_ARRAY:
if ($this->resultRow !== false) {
if (!array_key_exists($name, $this->resultRow)) {
throw new IcingaApiResultException('Search field "' . $name . '" not available!');
} else {
$returnValue = $this->resultRow[$name];
}
}
break;
}
return $returnValue;
}
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResultInterface#__call()
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function __call ($name, $arguments = array()) {
return $this->__get($name);
}
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResultInterface#get()
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function get ($searchField = false) {
$returnData = false;
if ($searchField === false) {
throw new IcingaApiResultException('get(): No search field defined!');
return false;
}
if ($this->resultRow !== false) {
$returnData = $this->__get($searchField);
}
return $returnData;
}
/**
* returns complete result set
* @param void
* @return mixed complete result set
* @author Christian Doebler <christian.doebler@netways.de>
*/
abstract public function getAll ();
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResultInterface#get()
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function getRow () {
return $this->resultRow;
}
/**
* sets the search object
*
* @param mixed $object search object for further processing
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
abstract public function setSearchObject (&$object);
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResultInterface#setResultType()
*/
public function setResultType ($type) {
$this->resultType = $type;
}
/**
* returns current result object
*
* @param void
* @return mixed
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function current () {
return $this;
}
/**
* returns current offset
*
* @param void
* @return scalar
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function key () {
return $this->offset;
}
/**
* checks whether there's a result row left
*
* @param void
* @return boolean
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function valid () {
return ($this->offset !== false) ? true : false;
}
/**
* (non-PHPdoc)
* @see objects/result/IcingaApiResultInterface#getResultCount()
*/
public function getResultCount () {
return $this->numResults;
}
/**
* sets the database type (mysql, oci, etc.)
* @param string $type type of database
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function setDbType ($type) {
$this->dbType = $type;
}
}
// extend exceptions
class IcingaApiResultException extends IcingaApiException {}
?>
|