Merge branch 'fronkdev' into 'master'
Added Preorderselfservice API See merge request fronk/thetool!806
This commit is contained in:
73
application/Api/v1/PreorderselfserviceApicontroller.php
Normal file
73
application/Api/v1/PreorderselfserviceApicontroller.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
class PreorderselfserviceApicontroller extends mfBaseApicontroller {
|
||||
|
||||
public function init() {
|
||||
$this->addRoute("/preorderselfservice/preorder", "getPreorder", "GET");
|
||||
}
|
||||
|
||||
protected function authenticated() {
|
||||
if($this->me->username != "preorder-selfservice-gui-api") {
|
||||
return \mfResponse::Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
private function authUser() {
|
||||
return true;
|
||||
//return false;
|
||||
}
|
||||
protected function getPreorder() {
|
||||
if(!$this->authUser()) {
|
||||
return mfResponse::Forbidden(["status" => "403", "message" => "User authentication failed"]);
|
||||
}
|
||||
|
||||
$auth_email = trim($this->get["auth_email"]);
|
||||
$auth_phone = trim($this->get["auth_phone"]);
|
||||
|
||||
$search = [];
|
||||
if($auth_email) {
|
||||
$search = ["email" => $auth_email];
|
||||
} elseif($auth_phone) {
|
||||
$phone_search = [];
|
||||
$auth_phone = preg_replace('/[^0-9]+/', '', $auth_phone);
|
||||
$phone_search[] = $auth_phone;
|
||||
|
||||
if(substr($auth_phone, 0, 2) == "43") {
|
||||
$phone_search[] = "+$auth_phone";
|
||||
$auth_phone = preg_replace('/^43/', '0', $auth_phone);
|
||||
$phone_search[] = $auth_phone;
|
||||
}
|
||||
|
||||
if(substr($auth_phone, 0, 1) != "0") {
|
||||
$phone_search[] = "0$auth_phone";
|
||||
}
|
||||
$search = ["phone" => $phone_search];
|
||||
}
|
||||
|
||||
if(!count($search)) {
|
||||
return mfResponse::BadRequest(["message" => "auth method missing"]);
|
||||
}
|
||||
|
||||
$preorders = PreorderModel::searchActive($search);
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach($preorders as $preorder) {
|
||||
if(!$preorder->adb_hausnummer || !$preorder->adb_wohneinheit) continue;
|
||||
|
||||
//$hausnummer = $preorder->adb_hausnummer;
|
||||
//$wohneinheit = $preorder->adb_wohneinheit;
|
||||
|
||||
$item = [];
|
||||
|
||||
$item["preorder"] = $preorder->getApiArray(["full_home", "full_address"]);
|
||||
//$item["building"] = $hausnummer->getApiArray();
|
||||
//$item["unit"] = $wohneinheit->getApiArray();
|
||||
|
||||
$result[] = $item;
|
||||
}
|
||||
|
||||
return mfResponse::Ok($result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -959,11 +959,14 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
|
||||
$include_full_home = false;
|
||||
$include_full_address = false;
|
||||
|
||||
if(in_array("full_home", $options)) {
|
||||
$include_full_home = true;
|
||||
}
|
||||
|
||||
if(in_array("full_address", $options)) {
|
||||
$include_full_address = true;
|
||||
}
|
||||
|
||||
$hausnummer = $this->getProperty("adb_hausnummer");
|
||||
$wohneinheit = $this->getProperty("adb_wohneinheit");
|
||||
@@ -1020,6 +1023,22 @@ class Preorder extends mfBaseModel {
|
||||
unset($address['municipality']);
|
||||
}
|
||||
|
||||
if($include_full_address) {
|
||||
$address['gps_lat'] = $hausnummer->gps_lat;
|
||||
$address['gps_long'] = $hausnummer->gps_long;
|
||||
$address["borderpoint_lat"] = $hausnummer->borderpoint_lat;
|
||||
$address["borderpoint_long"] = $hausnummer->borderpoint_long;
|
||||
|
||||
$address["trenches"] = [];
|
||||
$address["home_trench"] = [];
|
||||
if($hausnummer->trenches) {
|
||||
$address["trenches"] = json_decode($hausnummer->trenches);
|
||||
}
|
||||
if($hausnummer->home_trench) {
|
||||
$address["home_trench"] = json_decode($hausnummer->home_trench);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$include_full_home) {
|
||||
$address['block'] = ($wohneinheit->block) ? $wohneinheit->block : null;
|
||||
$address['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null;
|
||||
|
||||
@@ -670,6 +670,25 @@ class PreorderModel {
|
||||
$where .= " AND tt_preorder.extref = '$extref'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("email", $filter)) {
|
||||
$email = FronkDB::singleton()->escape($filter['email']);
|
||||
if($email) {
|
||||
$where .= " AND tt_preorder.email = '$email'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("phone", $filter)) {
|
||||
$phone = $filter["phone"];
|
||||
if(is_array($phone)) {
|
||||
$where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') IN ('".implode("','", $phone)."')";
|
||||
} else {
|
||||
$phone = FronkDB::singleton()->escape($filter['phone']);
|
||||
if($phone) {
|
||||
$where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') = '$phone'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("workorder_export_date", $filter)) {
|
||||
$workorder_export_date = $filter['workorder_export_date'];
|
||||
|
||||
Reference in New Issue
Block a user