Merge branch 'fronkdev' into 'master'
Preorderadmin & Superexpert mode See merge request fronk/thetool!284
This commit is contained in:
@@ -480,7 +480,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
}
|
||||
|
||||
protected function updateUnitOAIDs() {
|
||||
protected function updateUnitOAIDsAction() {
|
||||
$this->layout()->setTemplate("Preordercampaign/Admin");
|
||||
|
||||
$id = $this->request->id;
|
||||
@@ -513,7 +513,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function assignOpenAccessIdsToPreorders() {
|
||||
protected function assignOpenAccessIdsToPreordersAction() {
|
||||
$this->layout()->setTemplate("Preordercampaign/Admin");
|
||||
|
||||
$id = $this->request->id;
|
||||
@@ -735,7 +735,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function exportOaidsToRimo() {
|
||||
protected function exportOaidsToRimoAction() {
|
||||
|
||||
$this->layout()->setTemplate("Preordercampaign/Admin");
|
||||
|
||||
@@ -802,7 +802,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function updateOaidFromUnit() {
|
||||
protected function updateOaidFromUnitAction() {
|
||||
$this->layout()->setTemplate("Preordercampaign/Admin");
|
||||
|
||||
$id = $this->request->id;
|
||||
@@ -895,4 +895,192 @@ class PreordercampaignController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function splitMultipleConnectionsAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$campaign = new Preordercampaign($id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$orders_split = 0;
|
||||
$orders_new = 0;
|
||||
$missing_units = 0;
|
||||
|
||||
foreach(PreorderModel::searchActive(["preordercampaign_id" => $campaign->id, "connection_count" => 2]) as $preorder) {
|
||||
// check if we have enough units with extref
|
||||
$wohneinheiten = ADBWohneinheitModel::search(["hausnummer_id" => $preorder->adb_hausnummer_id]);
|
||||
$unit_count = count($wohneinheiten);
|
||||
if($unit_count < $preorder->connection_count) {
|
||||
$missing_units++;
|
||||
/*$mu = [];
|
||||
$mu['preorder'] = $preorder;
|
||||
$mu['unit_count'] = $unit_count;
|
||||
$missing_units[] = $mu;*/
|
||||
//echo "Nicht genug Wohneinheiten - Preorder id ".$preorder->id.": ".count($wohneinheiten)." - need ".$preorder->connection_count."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$available_units = [];
|
||||
$additional_units = []; // to sort non-specific units last
|
||||
foreach($wohneinheiten as $unit) {
|
||||
if($preorder->adb_wohneinheit_id == $unit->id || !PreorderModel::getFirstActive(["adb_wohneinheit_id" => $unit->id])) {
|
||||
if($unit->tuer || preg_match('/^(Top|Tuer|Tür)\s+\d+$/i', $unit->zusatz)) {
|
||||
$available_units[] = $unit;
|
||||
} else {
|
||||
$additional_units[] = $unit;
|
||||
}
|
||||
} else {
|
||||
//echo $preorder->id." balh\n";
|
||||
}
|
||||
}
|
||||
|
||||
if(count($additional_units)) $available_units = array_merge($available_units, $additional_units);
|
||||
|
||||
if($preorder->connection_count > count($available_units)) {
|
||||
$missing_units++;
|
||||
/*$md = [];
|
||||
$md["unit_count"] = $unit_count;
|
||||
$md["door_count"] = count($available_units);
|
||||
$md["preorder"] = $preorder;
|
||||
$missing_doors[] = $md;*/
|
||||
//echo "Not enough units with tuer (hausnummer id ".$preorder->adb_hausnummer_id.") units total: ".count($wohneinheiten)."; units with tuer: ".count($available_units)."; preorder connection count: ".$preorder->connection_count."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// create new Preorders with available units
|
||||
// then set original Preorder deleted
|
||||
//echo "Creating ".$preorder->connection_count." new preorders\n";
|
||||
|
||||
for($c = 0; $c < $preorder->connection_count; $c++) {
|
||||
if(!$available_units[$c]->oaid) {
|
||||
$available_units[$c]->oaid = $available_units[$c]->getNewOAID();
|
||||
$available_units[$c]->save();
|
||||
}
|
||||
|
||||
/*
|
||||
echo "unit id: ".$available_units[$c]->id."\n";
|
||||
echo "hausnummer ".$available_units[$c]->hausnummer_id." \n";
|
||||
echo $available_units[$c]->extref."\n\n";
|
||||
*/
|
||||
|
||||
$new_preorder = clone($preorder);
|
||||
$new_preorder->ucode = $preorder->ucode.".".($c+1);
|
||||
$new_preorder->connection_count = 1;
|
||||
$new_preorder->adb_wohneinheit_id = $available_units[$c]->id;
|
||||
$new_preorder->oaid = $available_units[$c]->oaid;
|
||||
|
||||
//var_dump($new_preorder);
|
||||
|
||||
$new_preorder->save();
|
||||
}
|
||||
//exit;
|
||||
$preorder->deleted = date("U");
|
||||
$preorder->delete_reason = "connection_split";
|
||||
$preorder->save();
|
||||
}
|
||||
|
||||
if($missing_units) {
|
||||
$this->layout()->setFlash("$missing_units Bestellungen konnten nicht geteilt werden, da nicht genug Wohneinheiten verfügbar sind.", "warning");
|
||||
}
|
||||
|
||||
if($orders_new) {
|
||||
$this->layout()->setFlash("$orders_split Bestellungen in $orders_new Bestellungen aufgeteilt.", "success");
|
||||
}
|
||||
$this->redirect("Preordercampaign", "Admin", ["id" => $id]);
|
||||
}
|
||||
|
||||
protected function addUnitsAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$campaign = new Preordercampaign($id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$units_added = 0;
|
||||
$missing_units = 0;
|
||||
|
||||
foreach(PreorderModel::searchActive(['preordercampaign_id' => $campaign->id, 'adb_wohneinheit_id' => null, 'connection_count' => 1, "connection_type" => "single-dwelling"]) as $preorder) {
|
||||
if($preorder->adb_wohneinheit_id) {
|
||||
continue;
|
||||
}
|
||||
if(!$preorder->adb_hausnummer_id) {
|
||||
echo "missing hausnummer Preorder ".$preorder->id."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$wohneinheiten = ADBWohneinheitModel::search(['hausnummer_id' => $preorder->adb_hausnummer_id]);
|
||||
if(!count($wohneinheiten)) {
|
||||
$missing_units++;
|
||||
continue;
|
||||
}
|
||||
$unit_count = count($wohneinheiten);
|
||||
//echo "$unit_count\n";
|
||||
if($unit_count === 1) {
|
||||
$same_unit_count++;
|
||||
$unit = $wohneinheiten[0];
|
||||
$preorder->adb_wohneinheit_id = $unit->id;
|
||||
$preorder->save();
|
||||
|
||||
$units_added++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if($unit_count > 1) {
|
||||
// legacy comment: assume its single-dwelling with erroneously high door count
|
||||
// current comment: Just use any unit
|
||||
$unit_candidates = [];
|
||||
|
||||
foreach($wohneinheiten as $unit) {
|
||||
if(!$unit->tuer) continue;
|
||||
if($unit->tuer > 1) {
|
||||
$unit_candidates[$unit->tuer] = $unit;
|
||||
}
|
||||
}
|
||||
|
||||
// no candidates with door number -> use any
|
||||
|
||||
if(!count($unit_candidates)) {
|
||||
foreach($wohneinheiten as $unit) {
|
||||
$unit_candidates[] = $unit;
|
||||
}
|
||||
}
|
||||
|
||||
if(count($unit_candidates)) {
|
||||
ksort($unit_candidates, SORT_NUMERIC);
|
||||
$new_unit = array_shift($unit_candidates);
|
||||
$preorder->adb_wohneinheit_id = $new_unit->id;
|
||||
$preorder->save();
|
||||
|
||||
$units_added++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if($missing_units) {
|
||||
$this->layout()->setFlash("Für $missing_units Bestellungen wurde keine Wohneinheit gefunden.", "warning");
|
||||
}
|
||||
|
||||
if($units_added) {
|
||||
$this->layout()->setFlash("$units_added Wohneinheiten eingetragen.", "success");
|
||||
}
|
||||
$this->redirect("Preordercampaign", "Admin", ["id" => $id]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -144,6 +144,62 @@ class User extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertStart($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(date("U") + $duration);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertStop($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(0);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertExtend($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(date("U") + $duration);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertEnabled() {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$tsFlag = $this->getFlag("superexpert_lock_date");
|
||||
$ts = $tsFlag->value();
|
||||
|
||||
if(!is_numeric($ts) || !$ts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = date("U");
|
||||
|
||||
// if superexpert is longer than 60 minutes -> disable
|
||||
if($ts > $now + 3601) {
|
||||
$tsFlag->value(null);
|
||||
$tsFlag->save();
|
||||
return false;
|
||||
}
|
||||
|
||||
if($ts > $now) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFlag($name) {
|
||||
return new WorkerFlag($this->id, $name);
|
||||
}
|
||||
|
||||
@@ -109,8 +109,7 @@ class UserController extends mfBaseController
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
@@ -342,4 +341,75 @@ class UserController extends mfBaseController
|
||||
|
||||
return $me->isAdmin();
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "sse":
|
||||
$return = $this->startSuperexpertApi();
|
||||
break;
|
||||
case "ese":
|
||||
$return = $this->extendSuperexpertApi();
|
||||
break;
|
||||
case "endse":
|
||||
$return = $this->endSuperexpertApi();
|
||||
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 startSuperexpertApi() {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($me->superexpertEnabled() ) {
|
||||
// superexpert mode started already
|
||||
return false;
|
||||
}
|
||||
|
||||
$me->superexpertStart(1800);
|
||||
|
||||
return ["valid_to" => $me->getFlag("superexpert_lock_date")->value()];
|
||||
}
|
||||
|
||||
private function extendSuperexpertApi() {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if(!$me->superexpertEnabled() ) {
|
||||
// superexpert mode must be started already
|
||||
$this->log->debug("se not started");
|
||||
return false;
|
||||
}
|
||||
$this->log->debug("ese");
|
||||
$me->superexpertExtend(1800);
|
||||
|
||||
return ["valid_to" => $me->getFlag("superexpert_lock_date")->value()];
|
||||
}
|
||||
|
||||
private function endSuperexpertApi() {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($me->superexpertEnabled() ) {
|
||||
$me->superexpertStop();
|
||||
}
|
||||
|
||||
|
||||
return ["valid_to" => null];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user