Added GET /preorder api endpoint
This commit is contained in:
@@ -18,6 +18,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$this->addRoute("/preorder", "submitPreorder", "POST");
|
||||
$this->addRoute("/preorder/:code", "getPreorder", "GET");
|
||||
|
||||
$this->allowMissingOrigin = true;
|
||||
}
|
||||
@@ -69,6 +70,31 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
//var_dump($campaign, $this->allowed_origins);exit;
|
||||
}
|
||||
|
||||
protected function getPreorder($code) {
|
||||
$code = trim(strtoupper($code));
|
||||
if(!$code) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirst(['ucode' => $code]);
|
||||
if(!$preorder) {
|
||||
// try oan id
|
||||
$preorder = PreorderModel::getFirst(['oaid' => $code]);
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
}
|
||||
|
||||
$return = $preorder->getApiArray();
|
||||
if(!$return) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
|
||||
return mfResponse::Ok($return);
|
||||
|
||||
}
|
||||
|
||||
protected function submitPreorder() {
|
||||
//var_dump($this->post);exit;
|
||||
if(!$this->campaigns) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
class Preorder extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','email','note'];
|
||||
private $status;
|
||||
private $campaign;
|
||||
private $partner;
|
||||
private $building;
|
||||
@@ -33,7 +34,78 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
return $ucode;
|
||||
}
|
||||
|
||||
public function getApiArray() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hausnummer = $this->getProperty("adb_hausnummer");
|
||||
$wohneinheit = $this->getProperty("adb_wohneinheit");
|
||||
|
||||
$a = [];
|
||||
$a['ucode'] = strtoupper($this->ucode);
|
||||
$a['oaid'] = $this->oaid;
|
||||
$a['status'] = $this->getProperty("status")->getApiArray();
|
||||
$a['connectionType'] = $this->connection_type;
|
||||
$a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1;
|
||||
$a['preorderType'] = $this->type;
|
||||
$a['acceptMarketing'] = ($this->accept_marketing) ? true : false;
|
||||
$a['acceptAgb'] = ($this->accept_agb) ? true : false;
|
||||
$a['acceptDsgvo'] = ($this->accept_dsgvo) ? true : false;
|
||||
$a['acceptWithdrawal'] = ($this->accept_withdrawal) ? true : false;
|
||||
$a['address_info'] = ($this->address_info) ? $this->address_info : null;
|
||||
|
||||
$address = [];
|
||||
$address['street'] = $hausnummer->strasse->name;
|
||||
$address['housenumber'] = $hausnummer->hausnummer;
|
||||
$address['zip'] = $hausnummer->plz->plz;
|
||||
$address['city'] = $hausnummer->strasse->gemeinde->name;
|
||||
$address['district'] = $hausnummer->ortschaft->name;
|
||||
$address['bock'] = ($wohneinheit->block) ? $wohneinheit->block : null;
|
||||
$address['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null;
|
||||
$address['stiege'] = ($wohneinheit->stiege) ? $wohneinheit->stiege : null;
|
||||
$address['tuer'] = ($wohneinheit->tuer) ? $wohneinheit->tuer : null;
|
||||
|
||||
$customer = [];
|
||||
$customer['company'] = ($this->company) ? $this->company : null;
|
||||
$customer['uid'] = ($this->uid) ? $this->uid : null;
|
||||
$customer['firstnam'] = ($this->firstname) ? $this->firstname : null;
|
||||
$customer['lastname'] = ($this->lastname) ? $this->lastname : null;
|
||||
$customer['street'] = ($this->street) ? $this->street : null;
|
||||
$customer['housenumber'] = ($this->hausnummer) ? $this->hausnummer : null;
|
||||
$customer['zip'] = ($this->plz) ? $this->plz : null;
|
||||
$customer['city'] = ($this->city) ? $this->city : null;
|
||||
$customer['bock'] = ($this->block) ? $this->block : null;
|
||||
$customer['stock'] = ($this->stock) ? $this->stock : null;
|
||||
$customer['stiege'] = ($this->stiege) ? $this->stiege : null;
|
||||
$customer['tuer'] = ($this->tuer) ? $this->tuer : null;
|
||||
$customer['phone'] = ($this->phone) ? $this->phone : null;
|
||||
$customer['email'] = ($this->email) ? $this->email : null;
|
||||
|
||||
$a['address'] = $address;
|
||||
$a['customer'] = $customer;
|
||||
|
||||
$a['addonServices'] = null;
|
||||
if($this->addon_services) {
|
||||
$addon_services = json_decode($this->addon_services);
|
||||
if(json_last_error() === JSON_ERROR_NONE) {
|
||||
$a['addonServices'] = $addon_services;
|
||||
}
|
||||
}
|
||||
|
||||
$a['additionalData'] = null;
|
||||
if($this->addon_data) {
|
||||
$addon_data = json_decode($this->addon_data);
|
||||
if(json_last_error() === JSON_ERROR_NONE) {
|
||||
$a['additionalData'] = $addon_data;
|
||||
}
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -42,6 +114,17 @@ class Preorder extends mfBaseModel {
|
||||
return $this->campaign;
|
||||
}
|
||||
|
||||
if($name == "status") {
|
||||
$this->status = mfValuecache::singleton()->get("mfObjectmodel-Preorderstatus-".$this->status_id);
|
||||
if(!$this->status) {
|
||||
$this->status = new Preorderstatus($this->status_id);
|
||||
if($this->status->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Preorderstatus-".$this->status_id, $this->status);
|
||||
}
|
||||
}
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
if($name == "partner") {
|
||||
$this->partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->partner_id);
|
||||
if(!$this->partner) {
|
||||
|
||||
16
application/Preorderstatus/Preorderstatus.php
Normal file
16
application/Preorderstatus/Preorderstatus.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class Preorderstatus extends mfBaseModel {
|
||||
|
||||
public function getApiArray() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$a = [];
|
||||
$a['code'] = (int)$this->code;
|
||||
$a['text'] = $this->name;
|
||||
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
140
application/Preorderstatus/PreorderstatusModel.php
Normal file
140
application/Preorderstatus/PreorderstatusModel.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
class PreorderstatusModel {
|
||||
public $code;
|
||||
public $name;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Preorderstatus();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
if(substr($field, 0, 5) == "vlan_" && !$value) {
|
||||
$model->$field = null;
|
||||
continue;
|
||||
}
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = mfValuecache::singleton()->get("me");
|
||||
if(!$me) {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
mfValuecache::singleton()->set("me", $me);
|
||||
}
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Preorderstatus", "*");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preorderstatus($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = false) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Preorderstatus", "*", "$where ORDER BY code, name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Preorderstatus($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM Preorderstatus
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT * FROM Preorderstatus
|
||||
WHERE $where
|
||||
ORDER BY code, name
|
||||
";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preorderstatus($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
|
||||
if(array_key_exists("code", $filter)) {
|
||||
$code = $filter['code'];
|
||||
if(is_numeric($code)) {
|
||||
$where .= " AND code=$code";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user