<?
/** classit.inc *
* iterator for classes created *
* by classgen.php requires *
* MySQL-XML */
/** @author Brandon Niemczyk */
class classit {
var $current_obj;
var $parent_id; // parent id number
var $object_type; // string storing the type of object
var $doc_id; // document id
var $obj_array = array(); // complete array of objects
var $nviewed_stack = array(); // stack of objects (not viewed)
var $viewed_stack = array(); // stack of objects (viewed)
/** generator requires type of object and *
* the document id **/
function classit($type, $document) {
$this->object_type = $type;
$this->doc_id = $document;
// become the doc in doc
$doc = new DOCUMENT();
$doc->become($this->doc_id);
// get obj_array from document
$this->obj_array = $doc->search_elements("xmlobjtype", $this->object_type);
// copy to nviewed stack (sort first)
sort ($this->obj_array);
// we reverse it so that we don't lose the correct order with pop/push
$this->nviewed_stack = array_reverse($this->obj_array);
}
/** get next object */
function next() {
// we can't go to next if there is nothing there!
if(count($this->nviewed_stack) < 1) return false;
// put current in viewed
if(isset($this->current_obj->id))
array_push($this->viewed_stack, $this->current_obj->id);
// create current this is where things get trick
// we have to generate the code (figure out obj type)
// and then run it
$code = "\$this->current_obj = new $this->object_type;";
eval($code);
$this->current_obj->become(array_pop($this->nviewed_stack));
// set the parent id number
if(isset($this->current_obj->parent))
$this->parent_id = $this->current_obj->parent;
// return current_obj
return $this->current_obj;
}
/** get previous object */
function previous() {
// we can't go to previous if there is nothing there
if(count($this->viewed_stack) < 1) return false;
// put current in nviewed, there should always be a current
array_push($this->nviewed_stack, $this->current_obj->id);
// create the current TRICKY AGAIN ;)
$code = "\$this->current_obj = new $this->object_type;";
eval($code);
$this->current_obj->become(array_pop($this_viewed_stack));
// set the parent
if(isset($this->current_obj->parent))
$this->parent_id = $this->current_obj->parent;
// return current_obj
return $current_obj;
}
/** this class is not complete I need to add some *
* search functions to it **/
}