105 lines
2.9 KiB
PHP
105 lines
2.9 KiB
PHP
<?php
|
|
|
|
class Preordercampaign extends mfBaseModel {
|
|
private $network;
|
|
private $preorders;
|
|
private $types;
|
|
|
|
|
|
public function addTypes(Array $types) {
|
|
$allowd_types = ["interest","provision","order"];
|
|
|
|
$new_types = [];
|
|
|
|
foreach($types as $type) {
|
|
if(!in_array($type, $allowd_types)) {
|
|
$this->log->debug("$type not in allowed_types");
|
|
continue;
|
|
}
|
|
$new_types[] = $type;
|
|
}
|
|
//var_dump($new_types);
|
|
foreach($allowd_types as $atype) {
|
|
$existing = PreordercampaignTypeModel::getFirst(['preordercampaign_id' => $this->id, "type" => $atype]);
|
|
//var_dump($existing);exit;
|
|
if($existing) {
|
|
if(!in_array($atype,$new_types)) {
|
|
$existing->delete();
|
|
}
|
|
} else {
|
|
if(in_array($atype, $new_types)) {
|
|
$data = [];
|
|
|
|
$data['preordercampaign_id'] = $this->id;
|
|
$data['type'] = $atype;
|
|
$nt = PreordercampaignTypeModel::create($data);
|
|
$nt->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "preorders") {
|
|
$this->preorders = PreorderModel::search(['preordercampaign_id' => $this->id]);
|
|
return $this->preorders;
|
|
}
|
|
|
|
if($name == "types") {
|
|
$types = PreordercampaignTypeModel::search(['preordercampaign_id' => $this->id]);
|
|
foreach($types as $type) {
|
|
$this->types[$type->type] = $type;
|
|
}
|
|
return $this->types;
|
|
}
|
|
|
|
if($name == "creator") {
|
|
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
|
if($user) {
|
|
$this->creator = $user;
|
|
return $this->creator;
|
|
}
|
|
$this->creator = new User($this->create_by);
|
|
if($this->creator->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
|
}
|
|
return $this->creator;
|
|
}
|
|
|
|
if($name == "editor") {
|
|
$user = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
|
if($user) {
|
|
$this->editor = $user;
|
|
return $this->editor;
|
|
}
|
|
$this->editor = new User($this->edit_by);
|
|
if($this->editor->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
|
}
|
|
return $this->editor;
|
|
}
|
|
|
|
$classname = ucfirst($name);
|
|
$idfield = $name."_id";
|
|
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
|
if(!$this->$name) {
|
|
$this->$name = new $classname($this->$idfield);
|
|
}
|
|
|
|
if($this->$name->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
|
|
} |