File: 0.00.1a/core/entity/EntityList.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeDESK 4: 5: FreeDESK is (C) Copyright 2012 David Cutting 6: 7: FreeDESK is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeDESK is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeDESK. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freedesk/ 21: -------------------------------------------------------------- */ 22: 23: /** 24: * Entity List Iterator - iterate through the contents of an EntityList 25: **/ 26: class EntityListIterator 27: { 28: /** 29: * Current list 30: **/ 31: private $list = null; 32: 33: /** 34: * Current/last index 35: **/ 36: private $index = -1; 37: 38: /** 39: * Constructor 40: * @param $list The Entity List to iterate through 41: **/ 42: function EntityListIterator(&$list) 43: { 44: $this->list = &$list; 45: $this->index = -1; 46: } 47: 48: /** 49: * Fetch next 50: * @return mixed Entity object or bool null on failure 51: **/ 52: function FetchNext() 53: { 54: return $this->list->Fetch[++$this->index]; 55: } 56: } 57: 58: /** 59: * Entity List - list of Entity objects found e.g. in a search 60: **/ 61: class EntityList 62: { 63: /** 64: * Data Items 65: **/ 66: private $items = array(); 67: 68: /** 69: * Count of Items 70: **/ 71: private $count = 0; 72: 73: /** 74: * Add an item 75: * @param mixed $item Entity object to add to list 76: **/ 77: function Add(&$item) 78: { 79: $this->items[]=&$item; 80: $this->count++; 81: } 82: 83: /** 84: * Fetch an item by index 85: * @param int $item Item Index 86: * @return mixed Entity object if found or bool null if not found 87: **/ 88: function Fetch($item) 89: { 90: if (isset($this->items[$item])) 91: return $this->items[$item]; 92: else 93: return false; 94: } 95: } 96: 97: ?> 98: 99: