82 lines
1.8 KiB
PHP
82 lines
1.8 KiB
PHP
<?php
|
|
|
|
class Order extends mfBaseModel {
|
|
private $owner;
|
|
private $billingaddress;
|
|
private $products;
|
|
private $files;
|
|
private $creator;
|
|
private $editor;
|
|
|
|
|
|
public function getNewPos() {
|
|
if(!$this->id) {
|
|
return 0;
|
|
}
|
|
|
|
$products = $this->getProperty("products");
|
|
if(!is_array($products) || !count($products)) {
|
|
return 1;
|
|
}
|
|
|
|
$p = end($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;
|
|
}
|
|
|
|
} |