Fix 0 quantity not displayed
[order_line_extra.git] / hincludes / lib / QueryIterator.class.php
1 <?php
2
3 class QueryIterator {
4         public function __construct($result) {
5                 if(!php_Boot::$skip_constructor) {
6                 $this->result = $result;
7                 $this->fetch();
8         }}
9         public function next() {
10                 $»t = ($this->nextValue);
11                 switch($»t->index) {
12                 case 0:
13                 {
14                         throw new HException("Iterator exhausted");
15                 }break;
16                 case 1:
17                 $v = $»t->params[0];
18                 {
19                         $this->fetch();
20                         return $v;
21                 }break;
22                 }
23         }
24         public function hasNext() {
25                 return $this->nextValue != Maybe::$Nothing;
26         }
27         public function fetch() {
28                 $next = db_fetch($this->result);
29                 $this->nextValue = (($next) ? Maybe::Just($next) : Maybe::$Nothing);
30         }
31         public $nextValue;
32         public $result;
33         public function __call($m, $a) {
34                 if(isset($this->$m) && is_callable($this->$m))
35                         return call_user_func_array($this->$m, $a);
36                 else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
37                         return call_user_func_array($this->»dynamics[$m], $a);
38                 else if('toString' == $m)
39                         return $this->__toString();
40                 else
41                         throw new HException('Unable to call «'.$m.'»');
42         }
43         function __toString() { return 'QueryIterator'; }
44 }