Example #1
0
 final function getFromList($class, $name)
 {
     if (cse($class, "_a")) {
         return $this->{$class}[$name];
     }
     // A small hack.. If asked for the same object, return ourselves. This is the best way to do it.. I think this does not really break teh conceptual integrity. Every object must have itself as a virtual entity. Even if it is not there in the list, it should be gettable.... The only question is the uniqueness. BUt our model of unique nname makes sure of that too...
     if ($class === lget_class($this) && $name === $this->nname) {
         return $this;
     }
     // A virtual list concept only implemented and need in ffile. This allows us to get an object without initializing the whole list.
     $this->__list_list = array_push_unique($this->__list_list, $class);
     $ret = $this->getFromVirtualList($class, $name);
     if ($ret) {
         $ret->__parent_o = $this;
         return $ret;
     }
     $name = str_replace("'", "", $name);
     $list = "{$class}_l";
     if (!isset($this->{$list})) {
         $this->{$list} = null;
         //throw new lxexception ("The " . get_class($this) . ":$list is NULL ");
     }
     // Very important. If it is already set, then don't ever load it from the database.
     if (isset($this->{$list}[$name])) {
         $object = $this->{$list}[$name];
         return $object;
     }
     if (exec_class_method($class, 'canGetSingle')) {
         if (isset($this->{$list}[$name])) {
             return $this->{$list}[$name];
         }
         $rule = exec_class_method($class, 'initThisListRule', $this, $class);
         if ($rule) {
             $query = $this->getDefaultQuery($class, $rule);
             if ($query) {
                 $query .= " AND nname = '{$name}'";
             } else {
                 $query .= "where nname = '{$name}'";
             }
             $db = new Sqlite($this->__masterserver, $this->getTheTable($class));
             $res = $db->getRowsGeneric($query);
             if (!$res) {
                 throw new lxexception("The Element {$name} Doesnt Exist in. {$this->getClass()}:{$this->nname} {$list}");
             }
             $obj = new $class($this->__masterserver, $this->__readserver, $name);
             $obj->setFromArray($res[0]);
             $this->{$list}[$name] = $obj;
         } else {
             $this->{$list}[$name] = exec_class_method($class, 'initThisObject', $this, $class, $name);
         }
     } else {
         $this->initListIfUndef($class);
         if (!$this->{$list}) {
             $this->{$list} = null;
             //throw new lxexception ("The " . get_class($this) . ":$list is NULL ");
         }
     }
     if (isset($this->{$list}[$name])) {
         // The virtual objects already has a __parent_o, and so we shouldn't add our own __parent_o
         if (!$this->isVirtual($class)) {
             $this->{$list}[$name]->__parent_o = $this;
         }
         $this->{$list}[$name]->postRead();
         return $this->{$list}[$name];
     } else {
         throw new lxexception("The Element {$name} Doesnt Exist in. {$this->getClass()}:{$this->nname} {$list}");
     }
 }