Added Preorder attributes and checkboxes in list
This commit is contained in:
@@ -8,6 +8,7 @@ class Preorder extends mfBaseModel {
|
||||
private $building;
|
||||
private $adb_hausnummer;
|
||||
private $adb_wohneinheit;
|
||||
private $attribute = [];
|
||||
|
||||
|
||||
public function afterLoad() {
|
||||
@@ -184,6 +185,14 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
}
|
||||
|
||||
if($name == "attribute") {
|
||||
if(!$this->attributes) {
|
||||
return null;
|
||||
}
|
||||
$this->attribute = json_decode($this->attributes, true);
|
||||
return $this->attribute;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($user) {
|
||||
|
||||
@@ -126,6 +126,9 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
|
||||
|
||||
}
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
@@ -586,4 +589,60 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin","netowner","salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "saveAttribute":
|
||||
$return = $this->saveAttributeApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function saveAttributeApi() {
|
||||
$preorder_id = $this->request->id;
|
||||
if(!is_numeric($preorder_id) || $preorder_id < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$attribute = $this->request->attribute;
|
||||
if(!$attribute) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$value = $this->request->value;
|
||||
$attribs = $preorder->attribute;
|
||||
if(!$attribs) {
|
||||
$attribs = [];
|
||||
}
|
||||
|
||||
$attribs[$attribute] = $value ? 1 : 0;
|
||||
$preorder->attributes = json_encode($attribs);
|
||||
if($preorder->save()) {
|
||||
return ["id" => $preorder_id, "attribute" => $attribute];
|
||||
} else {
|
||||
$this->returnJson(["status" => "error", "result" => ["id" => $preorder_id, "attribute" => $attribute]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +51,7 @@ class PreorderModel {
|
||||
public $shipping_address;
|
||||
public $addon_services;
|
||||
public $addon_data;
|
||||
public $attributes;
|
||||
public $submit_type;
|
||||
public $submit_request;
|
||||
|
||||
@@ -442,6 +443,22 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("attributes", $filter)) {
|
||||
$attributes = FronkDB::singleton()->escape($filter['attributes']);
|
||||
if(is_array($attributes) && count($attributes)) {
|
||||
if(array_key_exists("bep_specified", $attributes)) {
|
||||
if($attributes['bep_specified']) {
|
||||
$where .= " AND JSON_EXTRACT(attributes, \"$.bep_specified\") = 1";
|
||||
}
|
||||
}
|
||||
if(array_key_exists("inhouse_cabling_supplied", $attributes)) {
|
||||
if($attributes['inhouse_cabling_supplied']) {
|
||||
$where .= " AND JSON_EXTRACT(attributes, \"$.inhouse_cabling_supplied\") = 1";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// custom where clause
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
|
||||
Reference in New Issue
Block a user