92 lines
2.0 KiB
PHP
92 lines
2.0 KiB
PHP
<?php
|
|
|
|
class ContractconfigItem extends mfBaseModel {
|
|
private $value;
|
|
public $contract_id;
|
|
|
|
protected function beforeUpdate($data) {
|
|
if(!array_key_exists("edit_by", $data)) {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$data["edit_by"] = $me->id;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
public function setContractId($contract_id) {
|
|
if(!is_numeric($contract_id)) {
|
|
return false;
|
|
}
|
|
$this->contract_id = $contract_id;
|
|
return true;
|
|
}
|
|
|
|
public function getValue() {
|
|
$value = $this->getProperty("value");
|
|
if(!$value) {
|
|
return null;
|
|
}
|
|
|
|
if($this->multiple) {
|
|
return json_decode($value->json);
|
|
}
|
|
if($this->type == "int") {
|
|
return $value->int;
|
|
}
|
|
if($this->type == "decimal") {
|
|
return $value->number;
|
|
}
|
|
|
|
return $value->string;
|
|
}
|
|
|
|
public function getTypedataArray() {
|
|
if(!$this->typedata) {
|
|
return [];
|
|
}
|
|
|
|
return explode("\n", $this->typedata);
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if(!$this->id) {
|
|
return null;
|
|
}
|
|
|
|
if($name == "value") {
|
|
if(!$this->contract_id) {
|
|
return null;
|
|
}
|
|
$value = ContractconfigValueModel::getFirst(['item_id' => $this->id, "contract_id" => $this->contract_id]);
|
|
if(!$value) {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$value = new ContractconfigValue();
|
|
$value->item_id = $this->id;
|
|
$value->contract_id = $this->contract_id;
|
|
$value->create_by = $me->id;
|
|
$value->edit_by = $me->id;
|
|
}
|
|
|
|
$this->value = $value;
|
|
return $this->value;
|
|
}
|
|
|
|
$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;
|
|
}
|
|
} |