[icinga-checkins] icinga.org: icinga-api/mhein/default: * optimized and commented code for livestatus' array results

git at icinga.org git at icinga.org
Tue Jan 12 14:21:31 CET 2010


Module: icinga-api
Branch: mhein/default
Commit: 148bf0ffd9e99b4273507edb5cfee65ea7e71619
URL:    https://git.icinga.org/?p=icinga-api.git;a=commit;h=148bf0ffd9e99b4273507edb5cfee65ea7e71619

Author: Christian Doebler <christian.doebler at netways.de>
Date:   Wed Dec 23 11:26:01 2009 +0100

* optimized and commented code for livestatus' array results

---

 objects/result/IcingaApiResult.php           |    2 +-
 objects/result/IcingaApiResultLivestatus.php |   36 ++++++++++++++++++-------
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/objects/result/IcingaApiResult.php b/objects/result/IcingaApiResult.php
index 826bb17..9b75ee3 100644
--- a/objects/result/IcingaApiResult.php
+++ b/objects/result/IcingaApiResult.php
@@ -46,7 +46,7 @@ abstract class IcingaApiResult
 			case self::RESULT_OBJECT:
 				if ($this->resultRow->{$name} === null) {
 					throw new IcingaApiResultException('Search field "' . $name . '" not available!');
-				} else{
+				} else {
 					$returnValue = $this->resultRow->{$name};
 				}
 				break;
diff --git a/objects/result/IcingaApiResultLivestatus.php b/objects/result/IcingaApiResultLivestatus.php
index a86004f..36b77fe 100644
--- a/objects/result/IcingaApiResultLivestatus.php
+++ b/objects/result/IcingaApiResultLivestatus.php
@@ -86,34 +86,50 @@ class IcingaApiResultLivestatus
 					$this->offset = false;
 				}
 				break;
+
  			case self::RESULT_ARRAY:
-				if ($this->offset === false) {
-					$this->offset = 0;
-				} else {
-					$this->offset++;
-				}
-				if ($this->offset >= $this->numResults) {
-					$this->offset = false;
-				}
-				if ($this->offset !== false) {
+ 				if ($this->offset < $this->numResults) {
+
+ 					// set row offset
+					if ($this->offset === false) {
+						$this->offset = 0;
+					} else {
+						$this->offset++;
+					}
+
 					if ($this->lastRowCombined !== false) {
+
 						if ($this->offset > $this->lastRowCombined) {
+
+							// current row not converted to associative array -> convert
 							$this->resultArray[$this->offset] = array_combine(
 								$this->searchColumns,
 								$this->resultArray[$this->offset]
 							);
 							$this->lastRowCombined = $this->offset;
+
 						}
+
 					} else {
+
+						// first row -> convert to associative array
 						$this->resultArray[$this->offset] = array_combine(
 							$this->searchColumns,
 							$this->resultArray[$this->offset]
 						);
 						$this->lastRowCombined = 0;
+
 					}
+
+					// set row
 					$this->resultRow = $this->resultArray[$this->offset];
-				} else {
+
+ 				} else {
+
+ 					// no rows left -> reset
+					$this->offset = false;
 					$this->resultRow = false;
+
 				}
  				break;
  		}





More information about the icinga-checkins mailing list