id) { return 0; } $p = end($this->getProperty("products")); return ++$p->pos; } public function getProperty($name) { if($this->$name == null) { if(!$this->id) { return null; } if($name == "owner") { $this->owner = new Address($this->owner_id); return $this->owner; } if($name == "contact") { $this->contact = new Address($this->contact_id); return $this->contact; } if($name == "billingaddress") { $this->billingaddress = new Address($this->billingaddress_id); return $this->billingaddress; } if($name == "products") { $this->products = OrderProductModel::search(["order_id" => $this->id]); return $this->products; } if($name == "files") { $this->files = OrderFileModel::search(['order_id' => $this->id]); return $this->files; } if($name == "creator") { $this->creator = new User($this->create_by); return $this->creator; } if($name == "editor") { $this->editor = new User($this->edit_by); return $this->editor; } $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = new $classname($this->$idfield); if($this->$name->id) { return $this->$name; } else { return null; } } return $this->$name; } }