WIP Contract / IVT Import2024-05-23
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
|
||||
class ContractconfigValue extends mfBaseModel {
|
||||
private $item;
|
||||
|
||||
|
||||
protected function afterSave() {
|
||||
$this->runAfterSaveHooks();
|
||||
}
|
||||
|
||||
public function set($new_value) {
|
||||
// explicitly load item, because we might not have an id yet
|
||||
$item = new ContractconfigItem($this->item_id);
|
||||
@@ -21,7 +25,7 @@ class ContractconfigValue extends mfBaseModel {
|
||||
|
||||
if($item->multiple) {
|
||||
if(!is_array($new_value)) {
|
||||
$new_value = [$new_vale];
|
||||
$new_value = [$new_value];
|
||||
}
|
||||
|
||||
$json_array = [];
|
||||
@@ -31,7 +35,7 @@ class ContractconfigValue extends mfBaseModel {
|
||||
$json_array[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->json = json_encode($json_array);
|
||||
} elseif($item->type == "int") {
|
||||
if(!is_numeric($new_value)) return false;
|
||||
@@ -47,7 +51,46 @@ class ContractconfigValue extends mfBaseModel {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function runAfterSaveHooks() {
|
||||
$contract = $this->getProperty("item")->contract;
|
||||
|
||||
if(!$contract || !$contract->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$folderpath = APPDIR."/Contractconfig/hooks/";
|
||||
$dir = opendir($folderpath);
|
||||
while($filename = readdir($dir)) {
|
||||
if(substr($filename, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
if($filename == "Contractconfig_Hook.php") continue;
|
||||
if(substr($filename, -4) != ".php") continue;
|
||||
|
||||
$hook_type = basename($filename, ".php");
|
||||
$classname = "Contractconfig_Hook_$hook_type";
|
||||
$hook_class_filename = $folderpath.$filename;
|
||||
require_once $hook_class_filename;
|
||||
|
||||
if(!class_exists($classname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hook = new $classname($contract);
|
||||
if($hook->isResponsible()) {
|
||||
$this->log->debug("Running {$classname}->afterSave() for Contract id ".$contract->id);
|
||||
$hook->afterSave();
|
||||
if($hook->errors) {
|
||||
$this->hook_errors = $hook->errors;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user