object */ public $items = array(); /* Classe des objets de la collection */ public $class; /* $CACHE = true : l'objet est instancié une fois et conserver mémoire $CACHE = false : l'objet est instancié à la demande à chaque parcours du tableau */ public static $CACHE = true; public function __construct($class, $values = null) { $this->class = $class; if (is_array($values)) { foreach ($values as $k => $v) { $this->add((int) $v); } } } public function rewind() { reset($this->items); } public function current() { $var = current($this->items); if (!is_object($var) && $var !== false) { if (self::$CACHE) { $this->items[$this->key()] = Object_Factory::Build($this->class, $this->key()); $var = current($this->items); } else { $var = Object_Factory::Build($this->class, $this->key()); } } return $var; } public function key() { $var = key($this->items); return $var; } public function next() { $var = next($this->items); if (!is_object($var) && $var !== false) { if (self::$CACHE) { $this->items[$this->key()] = Object_Factory::Build($this->class, $this->key()); $var = $this->items[$this->key()]; } else { $var = Object_Factory::Build($this->class, $this->key()); } } return $var; } public function valid() { $var = $this->current() !== false; return $var; } public function add($Object) { if (is_object($Object)) { if (is_subclass_of($Object, 'DB_Object')) { $this->items[$Object->Id] = $Object; } else if(get_class($Object) == 'DB_Object_Collection' && $this->class == $Object->class) { $this->add($Object->get_keys()); } } else if ((int) $Object > 0) { $this->items[(int) $Object] = null; } else if (is_array($Object)) { foreach ($Object as $k => $v) { $this->items[(int) $k] = null; } } } public function get_keys() { return array_keys($this->items); } public function key_exists($k) { if (is_object($k)) { $k = (int) $k->Id; } return array_key_exists((int) $k, $this->items); } public function delete($k) { if (is_object($k)) { $k = intval($k->Id); } unset($this->items[(int) $k]); } public function size() { return sizeof($this->items); } } ?>