Added PreorderStatusflag to Preorder/Index
This commit is contained in:
@@ -5,6 +5,7 @@ class Preorder extends mfBaseModel {
|
||||
private $in_after_save = 0;
|
||||
|
||||
private $status;
|
||||
private $statusflags;
|
||||
private $campaign;
|
||||
private $partner;
|
||||
private $discounts;
|
||||
@@ -658,6 +659,18 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
if($name == "statusflags") {
|
||||
$flags = [];
|
||||
foreach(PreorderStatusflagModel::getAll() as $flag) {
|
||||
$flag->preorder_id = $this->id;
|
||||
$flags[$flag->id] = $flag;
|
||||
}
|
||||
if(count($flags)) {
|
||||
$this->statusflags = $flags;
|
||||
}
|
||||
return $this->statusflags;
|
||||
}
|
||||
|
||||
if($name == "partner") {
|
||||
$this->partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->partner_id);
|
||||
|
||||
@@ -914,6 +914,9 @@ class PreorderController extends mfBaseController {
|
||||
case "savePatchposition":
|
||||
$return = $this->savePatchpositionApi();
|
||||
break;
|
||||
case "setStatusFlag":
|
||||
$return = $this->setStatusFlagAction();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
@@ -926,7 +929,38 @@ class PreorderController extends mfBaseController {
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
|
||||
private function setStatusFlagAction() {
|
||||
$preorder_id = $this->request->preorder_id;
|
||||
$flag_id = $this->request->flag_id;
|
||||
$value = $this->request->value;
|
||||
|
||||
if(!$preorder_id || !$flag_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$flag = new PreorderStatusflag($flag_id);
|
||||
if(!$flag->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$flagvalue = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder_id, "flag_id" => $flag_id]);
|
||||
if(!$flagvalue) {
|
||||
$flagvalue = PreorderStatusflagValueModel::create([
|
||||
"preorder_id" => $preorder_id,
|
||||
"flag_id" => $flag_id
|
||||
]);
|
||||
}
|
||||
|
||||
$flagvalue->value = ($value) ? 1 : 0;
|
||||
|
||||
if(!$flagvalue->save()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ["message" => "Statusflag saved successfully"];
|
||||
}
|
||||
|
||||
private function getFilteredPreordersApi() {
|
||||
$preorders = [];
|
||||
$filter = [];
|
||||
|
||||
@@ -1,5 +1,52 @@
|
||||
<?php
|
||||
|
||||
class PreorderStatusflag extends mfBaseModel {
|
||||
private $value;
|
||||
public $preorder_id;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "value") {
|
||||
if(!$this->preorder_id) return null;
|
||||
$value = PreorderStatusflagValueModel::getFirst(["preorder_id" => $this->preorder_id, "flag_id" => $this->id]);
|
||||
$this->value = $value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
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") {
|
||||
$this->editor = new User($this->edit_by);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ class PreorderStatusflagValueModel {
|
||||
public $preorder_id;
|
||||
public $flag_id;
|
||||
public $value;
|
||||
public $old_value;
|
||||
public $new_value;
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
@@ -42,7 +40,8 @@ class PreorderStatusflagValueModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("PreorderStatusflagValue", "*", "$where ORDER BY statusflag_id LIMIT 1");
|
||||
|
||||
$res = $db->select("PreorderStatusflagValue", "*", "$where ORDER BY flag_id LIMIT 1");
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderStatusflagValue($data);
|
||||
@@ -60,7 +59,7 @@ class PreorderStatusflagValueModel {
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreorderStatusflagValue", "*", "1=1 ORDER BY statusflag_id");
|
||||
$res = $db->select("PreorderStatusflagValue", "*", "1=1 ORDER BY flag_id");
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderStatusflagValue($data);
|
||||
@@ -92,7 +91,7 @@ class PreorderStatusflagValueModel {
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM PreorderStatusflagValue
|
||||
WHERE $where
|
||||
ORDER BY statusflag_id";
|
||||
ORDER BY flag_id";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if (is_array($limit) && count($limit)) {
|
||||
@@ -116,7 +115,6 @@ class PreorderStatusflagValueModel {
|
||||
$where = "1=1 ";
|
||||
|
||||
|
||||
|
||||
if (array_key_exists("preorder_id", $filter)) {
|
||||
$preorder_id = $filter['preorder_id'];
|
||||
if (is_numeric($preorder_id)) {
|
||||
|
||||
Reference in New Issue
Block a user