48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
class PreorderinfrastructureApiController extends mfBaseApicontroller {
|
|
|
|
protected function init() {
|
|
$this->allowMissingOrigin = true;
|
|
}
|
|
|
|
protected function registerRoutes() {
|
|
$this->addRoute("/preorderinfrastructure/patchportAssignmentOrders", "getPatchportAssignmentOrders", "GET");
|
|
|
|
}
|
|
|
|
protected function authenticated() {
|
|
$this->registerRoutes();
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* GET /preorderinfrastructure/patchportAssignmentOrders
|
|
* Returns Homes in patching enabled campaigns with status 245
|
|
*
|
|
* @return array mfRequest
|
|
*/
|
|
protected function getPatchportAssignmentOrders() {
|
|
if($this->me->username != "system.preorder.infra.api.snopp") {
|
|
return mfResponse::Forbidden();
|
|
}
|
|
|
|
$campaigns = PreordercampaignModel::search(["create_external_patchports" => 1]);
|
|
if(!$campaigns) {
|
|
return mfResponse::Ok(["homes" => []]);
|
|
}
|
|
|
|
// get IDs of campaigns
|
|
$campaign_ids = array_map(fn($c): int => $c->id, $campaigns);
|
|
|
|
$homes = [];
|
|
foreach(PreorderModel::search(["preordercampaign_id" => $campaign_ids, "status_code" => 245]) as $preorder) {
|
|
if(!$preorder->adb_wohneinheit_id) continue;
|
|
$home = $preorder->adb_wohneinheit;
|
|
if(!$home->extref) continue;
|
|
$homes[] = $home->extref;
|
|
}
|
|
|
|
return mfResponse::Ok(["homes" => $homes]);
|
|
}
|
|
} |