components = array(); $this->url = new URL(); } /** * Vajadusel võivad järglased siin teostada mingeid tegevusi, * kui on näiteks mingi inf vaja parentile edasi anda, * või ennast kohandada kuidagi parentiga. */ function set_parent(&$parent) { //var_dump($this->name); parent::set_parent($parent); if (isset($parent)) { $this->def_logic($parent->get_logic()); $this->url->add_url($parent->url); } } /** * Siin saab kasut reference'i, siis kasutame, muidu ei saa, siis ei kasuta :P * * @return */ function set_logic(&$logic) { //var_dump($logic); //var_dump($this); if (isset($logic)) $this->logic =& $logic; } function def_logic(&$logic) { //var_dump($logic); //var_dump($this); if (!isset($this->logic)) $this->logic =& $logic; } function &get_logic() { return $this->logic; } function get_url() { return $this->url; } function set_name($name) { //$this->url->remove($this->name); $this->name = $name; //$this->url->add($name) } function get_link($command = NULL) { $url = $this->url->get_copy(); //var_dump($this->url); $url->add($this->name, $command); return $url->render(); } /* function Component(&$logic, $template_file_name = NULL) { //$template_file_name = (isset($template_name) ? "$template_name.tpl.php" : NULL) ; $template_path = './templates/'; parent::Template($template_file_name);//, $template_path); $this->set_logic($locic); //$this->set_parent($parent); } */ function &add_component(&$c, $container_place = NULL, $unique_exemplar_name = NULL, $template_name = NULL) { //echo "add_component"; $c->set_parent($this); //$c->compose(); if (!isset($unique_exemplar_name)) $unique_exemplar_name = $c->get_unique_name(get_class($c)); $c->set_name($unique_exemplar_name); //nimi muutub iga päringuga.. ebasoovitav variant //c annab ise endale nime.. juba parem parem //echo $unique_exemplar_name; //var_dump($unique_exemplar_name); $this->components[$c->name] =& $c; if (isset($container_place)) $this->add_template($container_place, $c); //NB?? else $this->set_over_template($c); return $c; } function &add_comp($class_name, $container_place = NULL, &$logic, $unique_exemplar_name = NULL, $template_name = NULL) { if (!$c = $this->get_comp($class_name, $template_name)) { echo 'tundmatu klass '.$class_name; return FALSE; } //var_dump($logic); //var_dump($c->logic); //composes kasutatakse $c-name, mille saab alles add_component-is //$c->name = $unique_exemplar_name; //väärtustame siis enne.. //echo($c->name); //add_component kustsub välja add_template, mis teeb set_parent(), mis võtab parent'i logicu. //ja seda ma ei taha kui mul on logic siit sisse antud. $c->set_logic($logic); $c2 =& $this->add_component($c, $container_place, $unique_exemplar_name, $template_name); $c->compose();//? //die(); return $c2; //return $this->add_component($c, $container_place, $unique_exemplar_name, $template_name); /* $c->compose(); if (!isset($unique_exemplar_name)) $unique_exemplar_name = $c->get_unique_name($class_name); //nimi muutub iga päringuga.. ebasoovitav variant //c annab ise endale nime.. juba parem parem $this->components[$unique_exemplar_name] =& $c; return $c; */ } function &get_comp($class_name, $template_name = NULL) { $path = './preslogic/'; if (is_string($class_name) and file_exists($path."$class_name.comp.php")) { include_once $path."$class_name.comp.php"; }else return NULL; $c =& new $class_name($template_name); return $c; } function compose() { //siin additakse alamkomponendid, ja antakse väärtused. //$this->add_comp('relationviewbox', 'topical', $relation, 'suhtekuva','relview'); } function get_unique_name($base_name) { $name = $base_name.'_'.substr(md5((string)rand()), 0, 5); return $name; } function fetch($file_name) { //valmista ette midagi komponendi puus.. näiteks renderda lingid.. //komponentide omavaheline info vahetus //üks variant on, et see tehakse samal hetkel kui komponente liidetakse-lahutatakse //kuid see teeb asja väga keeruliseks. lihtsam on teha puu valmis, ning alles siis //lasta komponentidel suhted klaarida. return parent::fetch($file_name); } } ?>