Added Preorder API EP getCifData; added cifcableurl to preorder
This commit is contained in:
35
application/Api/v1/Modules/ApiControllerModule.php
Normal file
35
application/Api/v1/Modules/ApiControllerModule.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace thetool\Api\Modules;
|
||||
|
||||
class ApiControllerModule {
|
||||
protected $log;
|
||||
private $dependencies = [];
|
||||
|
||||
public function __construct($dependencies = null) {
|
||||
$this->log = \mfLoghandler::singleton();
|
||||
|
||||
if(is_array($dependencies) && count($dependencies)) {
|
||||
foreach($dependencies as $name => $dep) {
|
||||
$this->$name = $dep;
|
||||
}
|
||||
}
|
||||
|
||||
if(method_exists($this, "init")) {
|
||||
$this->init();
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
if(array_key_exists($name, $this->dependencies)) {
|
||||
return $this->dependencies[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function __set($name, $value) {
|
||||
$this->dependencies[$name] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
54
application/Api/v1/Modules/Preorder/Cif.php
Normal file
54
application/Api/v1/Modules/Preorder/Cif.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace thetool\Api\Modules\Preorder;
|
||||
use thetool\Api\Modules;
|
||||
|
||||
require_once(APPDIR."/Api/v1/Modules/ApiControllerModule.php");
|
||||
|
||||
/*
|
||||
* API Endpoints for Preorder Client Installation Feedback
|
||||
*/
|
||||
class Cif extends Modules\ApiControllerModule {
|
||||
|
||||
public function init() {
|
||||
|
||||
}
|
||||
|
||||
public function providerSetCif($code) {
|
||||
return \mfResponse::InternalServerError();
|
||||
//return \mfResponse::Ok(["message" => "in providerSetCif($code)"]);
|
||||
}
|
||||
|
||||
public function getCifData() {
|
||||
|
||||
if(!array_key_exists("ciftoken", $this->get) || !$this->get['ciftoken']) {
|
||||
return \mfResponse::BadRequest(["message" => "ciftoken missing"]);
|
||||
}
|
||||
|
||||
$preorder = \PreorderModel::getFirst(["ciftoken" => $this->get["ciftoken"], "partner_id" => $this->me->address_id]);
|
||||
if(!$preorder) {
|
||||
return \mfResponse::NotFound(["message" => "Invalid ciftoken"]);
|
||||
}
|
||||
|
||||
$return = $preorder->getCifdataApiArray();
|
||||
|
||||
return \mfResponse::Ok($return);
|
||||
}
|
||||
|
||||
public function userSetCif() {
|
||||
return \mfResponse::InternalServerError();
|
||||
|
||||
if(!array_key_exists("ciftoken", $this->get) || !$this->get['ciftoken']) {
|
||||
return \mfResponse::BadRequest(["message" => "ciftoken missing"]);
|
||||
}
|
||||
|
||||
$preorder = \PreorderModel::getFirst(["ciftoken" => $this->get["ciftoken"], "partner_id" => $this->me->address_id]);
|
||||
if(!$preorder) {
|
||||
return \mfResponse::NotFound(["message" => "Invalid ciftoken"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Preorder_Cif {
|
||||
|
||||
public function providerSetCif($code) {
|
||||
return mfResponse::Ok(["message" => "in providerSetCif($code)"]);
|
||||
}
|
||||
|
||||
public function getCifData() {
|
||||
return mfResponse::Ok(["message" => "in getCifData()"]);
|
||||
}
|
||||
|
||||
public function userSetCif() {
|
||||
return mfResponse::Ok(["message" => "in userSetCif()"]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
require_once(APPDIR."/Api/v1/Preorder/Preorder_Cif.php");
|
||||
require_once(APPDIR."/Api/v1/Modules/Preorder/Cif.php");
|
||||
|
||||
use thetool\Api\Modules;
|
||||
|
||||
class PreorderApicontroller extends mfBaseApicontroller {
|
||||
//private $filter_gemeinde_ids = [];
|
||||
@@ -20,23 +22,33 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
|
||||
protected function init() {
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$cifObject = new Preorder_Cif();
|
||||
|
||||
$this->addRoute("/preorder", "submitPreorder", "POST");
|
||||
$this->addRoute("/preorder/open", "getOpenPreorders", "GET");
|
||||
$this->addRoute("/preorder/customerInstallationFeedback", [$cifObject, "getCifData"], "GET");
|
||||
$this->addRoute("/preorder/customerInstallationFeedback", [$cifObject, "userSetCif"], "POST");
|
||||
|
||||
$this->addRoute("/preorder/:code", "getPreorder", "GET");
|
||||
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
|
||||
$this->addRoute("/preorder/:code/clientInstallationFinished", [$cifObject, "providerSetCif"], "GET");
|
||||
$this->addRoute("/preorder/:code/serviceActivated", "setServiceActive", "POST");
|
||||
|
||||
$this->allowMissingOrigin = true;
|
||||
}
|
||||
|
||||
protected function registerRoutes() {
|
||||
$moduleCif = new Modules\Preorder\Cif([
|
||||
"get" => $this->get,
|
||||
"post" => $this->post,
|
||||
"db" => $this->db(),
|
||||
"me" => $this->me
|
||||
]);
|
||||
|
||||
$this->addRoute("/preorder", "submitPreorder", "POST");
|
||||
$this->addRoute("/preorder/open", "getOpenPreorders", "GET");
|
||||
$this->addRoute("/preorder/customerInstallationFeedback", [$moduleCif, "getCifData"], "GET");
|
||||
$this->addRoute("/preorder/customerInstallationFeedback", [$moduleCif, "userSetCif"], "POST");
|
||||
|
||||
$this->addRoute("/preorder/:code", "getPreorder", "GET");
|
||||
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
|
||||
$this->addRoute("/preorder/:code/clientInstallationFinished", [$moduleCif, "providerSetCif"], "GET");
|
||||
$this->addRoute("/preorder/:code/serviceActivated", "setServiceActive", "POST");
|
||||
}
|
||||
|
||||
/*
|
||||
* is called after User is authenticated by API Key
|
||||
*/
|
||||
protected function authenticated() {
|
||||
$this->registerRoutes();
|
||||
|
||||
if($this->me->is("preorderaddressreporting")) {
|
||||
return mfResponse::Forbidden();
|
||||
@@ -92,8 +104,6 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$this->allowed_preordertypes = array_unique($this->allowed_preordertypes);
|
||||
|
||||
//var_dump($campaign, $this->allowed_origins);exit;
|
||||
}
|
||||
|
||||
protected function getOpenPreorders() {
|
||||
|
||||
@@ -370,6 +370,45 @@ class Preorder extends mfBaseModel {
|
||||
return $ciftoken;
|
||||
}
|
||||
|
||||
public function getCifdataApiArray() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hausnummer = $this->getProperty("adb_hausnummer");
|
||||
$wohneinheit = $this->getProperty("adb_wohneinheit");
|
||||
|
||||
$a = [];
|
||||
$a["ciftoken"] = $this->ciftoken;
|
||||
$a["code"] = $this->ucode;
|
||||
$a['oaid'] = $this->oaid;
|
||||
|
||||
$a['company'] = ($this->company) ? $this->company : null;
|
||||
$a['uid'] = ($this->uid) ? $this->uid : null;
|
||||
$a['firstnam'] = ($this->firstname) ? $this->firstname : null;
|
||||
$a['lastname'] = ($this->lastname) ? $this->lastname : null;
|
||||
|
||||
$a['street'] = $hausnummer->strasse->name;
|
||||
$a['housenumber'] = $hausnummer->hausnummer;
|
||||
$a['zip'] = $hausnummer->plz->plz;
|
||||
$a['city'] = $hausnummer->strasse->gemeinde->name;
|
||||
$a['municipality'] = "";
|
||||
$a['district'] = $hausnummer->ortschaft->name;
|
||||
$a['block'] = ($wohneinheit->block) ? $wohneinheit->block : null;
|
||||
$a['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null;
|
||||
$a['stiege'] = ($wohneinheit->stiege) ? $wohneinheit->stiege : null;
|
||||
$a['tuer'] = ($wohneinheit->tuer) ? $wohneinheit->tuer : null;
|
||||
|
||||
if($campaign->district_is_city) {
|
||||
$a['city'] = $hausnummer->ortschaft->name;
|
||||
$a['municipality'] = $hausnummer->strasse->gemeinde->name;
|
||||
} else {
|
||||
unset($a['municipality']);
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
public function getApiArray() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
@@ -388,6 +427,7 @@ class Preorder extends mfBaseModel {
|
||||
$a['status'] = $this->getProperty("status")->getApiArray();
|
||||
$a['ciftoken'] = ($this->ciftoken) ? $this->ciftoken : null;
|
||||
$a['cifurl'] = ($this->cifurl) ? $this->cifurl : null;
|
||||
$a['cifcableurl'] = ($this->cifcableurl) ? $this->cifcableurl : null;
|
||||
$a['installationDate'] = ($this->installation_date) ? date("c", $this->installation_date) : null;
|
||||
$a['connectionType'] = $this->connection_type;
|
||||
$a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1;
|
||||
|
||||
@@ -202,6 +202,11 @@ class PreorderlogisticsController extends mfBaseController {
|
||||
$preorder->save();
|
||||
}
|
||||
|
||||
if(!$preorder->cifcableurl) {
|
||||
$preorder->cifcableurl = "https://www.deineglasfaser.at/kundinnen/leerrohr-nachbestellung/";
|
||||
$preorder->save();
|
||||
}
|
||||
|
||||
|
||||
$plog = PreorderlogisticsModel::getFirst(["preorder_id" => $preorder->id]);
|
||||
if(!$plog) {
|
||||
|
||||
31
db/migrations/20231204100158_preorder_add_cifcableurl.php
Normal file
31
db/migrations/20231204100158_preorder_add_cifcableurl.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class PreorderAddCifcableurl extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Preorder");
|
||||
$table->addColumn("cifcableurl", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "cifurl"]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1442,6 +1442,10 @@ components:
|
||||
type: string
|
||||
description: Customer Installation Feedback Url
|
||||
example: "https://pro.ichwillglasfaser.at/ClientSubmit/finishedInstallationWork?c=XArjnWQXGq4a8JWF"
|
||||
cifcableurl:
|
||||
type: string
|
||||
description: Url to order various lengths of cable for Customer Installation
|
||||
example: "https://www.ichwillglasfaser.at/CableOrderForm"
|
||||
installationDate:
|
||||
type: string
|
||||
format: date-time
|
||||
|
||||
Reference in New Issue
Block a user