phpOpenTracker/phpOpenTracker/API Result.php,1.10,1.11
Sebastian Bergmann <[email protected]> Mon, 01 Mar 2004 15:55:34 +0000
| Newsgroups | gmane.comp.web.phpopentracker.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/phpopencounter/phpOpenTracker/phpOpenTracker/API
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31908
Modified Files:
Result.php
Log Message:
Add getAsNumber() method.
Index: Result.php
===================================================================
RCS file: /cvsroot/phpopencounter/phpOpenTracker/phpOpenTracker/API/Result.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Result.php 1 Mar 2004 08:56:57 -0000 1.10
--- Result.php 1 Mar 2004 15:55:30 -0000 1.11
***************
*** 24,27 ****
--- 24,28 ----
class phpOpenTracker_API_Result implements IteratorAggregate {
protected $result;
+ protected $resultKeys;
protected $parameters;
protected $supportedFormats;
***************
*** 29,32 ****
--- 30,34 ----
public function __construct($result, $parameters, $supportedFormats = array()) {
$this->result = $result;
+ $this->resultKeys = array_keys($result[0]);
$this->parameters = $parameters;
$this->supportedFormats = $supportedFormats;
***************
*** 45,49 ****
public function getAsCSV() {
if ($this->supportedFormats['csv']) {
! $csv = implode(';', array_keys($this->result[0])) . "\n";
foreach ($this->result as $row) {
--- 47,51 ----
public function getAsCSV() {
if ($this->supportedFormats['csv']) {
! $csv = implode(';', $this->resultKeys) . "\n";
foreach ($this->result as $row) {
***************
*** 59,62 ****
--- 61,76 ----
}
+ public function getAsNumber() {
+ if (sizeof($this->result) == 1 &&
+ sizeof($this->resultKeys) == 1 &&
+ is_numeric($this->result[0][$this->resultKeys[0]])) {
+ return $this->result[0][$this->resultKeys[0]];
+ } else {
+ throw new phpOpenTracker_API_Exception(
+ 'Unsupported result format "Number" requested.'
+ );
+ }
+ }
+
public function getAsXML() {
if ($this->supportedFormats['xml']) {
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click