Updated Dashboard and made it live
This commit is contained in:
@@ -22,9 +22,8 @@ class DashboardController extends mfBaseController {
|
||||
$this->layout()->set("newss", $newss);
|
||||
|
||||
if($this->me->can("Statistics") && $this->me->is(["Admin", "netowner", "salespartner"])) {
|
||||
return $this->dashboardAction();
|
||||
$this->redirect("DashboardNew");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function dashboardAction() {
|
||||
|
||||
@@ -5,6 +5,7 @@ class DashboardNewController extends mfBaseController {
|
||||
private User $me;
|
||||
|
||||
protected function init(): void {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->layout()->set("me", $me);
|
||||
@@ -12,19 +13,24 @@ class DashboardNewController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
if (!$this->me->can("Statistics") || !$this->me->is(["Admin", "netowner", "salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
$this->layout()->set('additionalJS', ["plugins/chart.js/chart.4.4.6.js", "plugins/chart.js/chartjs-adapter-moment.min.js"]);
|
||||
Helper::renderVue($this, "DashboardNew", $this->mod, []);
|
||||
Helper::renderVue($this, $this->mod, "Dashboard", ["IS_ADMIN" => $this->me->is("Admin") ? "true" : "false"]);
|
||||
}
|
||||
|
||||
|
||||
protected function getNetOwnerFilterOptionsAction() {
|
||||
if (!$this->me->is("Admin")) return; // TODO: enable for RML and Energie Steiermark
|
||||
|
||||
$allPreorderCampaigns = PreordercampaignModel::getAll();
|
||||
$netowners = [];
|
||||
|
||||
foreach ($allPreorderCampaigns as $campaign) {
|
||||
$network = new Network($campaign->network_id);
|
||||
|
||||
if (!$this->me->is("Admin") && $network->owner_id != $this->me->address_id) continue;
|
||||
|
||||
$networkOwner = new Address($network->owner_id);
|
||||
$ownerName = $networkOwner->getCompanyOrName();
|
||||
|
||||
@@ -37,12 +43,11 @@ class DashboardNewController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function getCampaignFilterOptionsAction() {
|
||||
if (!$this->me->is("Admin")) return; // TODO: enable for RML and Energie Steiermark
|
||||
$post = json_decode(file_get_contents('php://input'), true);
|
||||
$netowner_ids = isset($post['netOwners']) ? [$post['netOwners']] : [];
|
||||
$campaigns = [];
|
||||
|
||||
$all_campaigns = PreordercampaignModel::getAll();
|
||||
$all_campaigns = $this->me->is("Admin") ? PreordercampaignModel::getAll() : PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
|
||||
|
||||
if (!empty($netowner_ids)) {
|
||||
foreach ($all_campaigns as $campaign) {
|
||||
@@ -64,13 +69,12 @@ class DashboardNewController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function getCampaignGemeindeFilterOptionsAction() {
|
||||
if (!$this->me->is("Admin")) return; // TODO: enable for RML and Energie Steiermark
|
||||
$post = json_decode(file_get_contents('php://input'), true);
|
||||
$netowner_ids = isset($post['netOwners']) ? [$post['netOwners']] : [];
|
||||
$campaign_ids = isset($post['campaigns']) ? [$post['campaigns']] : [];
|
||||
$campaigns = [];
|
||||
|
||||
$all_campaigns = PreordercampaignModel::getAll();
|
||||
$all_campaigns = $this->me->is("Admin") ? PreordercampaignModel::getAll() : PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
|
||||
|
||||
if (!empty($netowner_ids)) {
|
||||
foreach ($all_campaigns as $campaign) {
|
||||
@@ -94,6 +98,30 @@ class DashboardNewController extends mfBaseController {
|
||||
self::returnJson($this->getGemeindenFromCampaigns($campaigns));
|
||||
}
|
||||
|
||||
private function checkParameterAuthorization($campaign_ids = []) {
|
||||
// $campaigns = PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
|
||||
// $campaign_filter = ["preordercampaign_id" => $campaign_ids];
|
||||
// if(!$campaign_ids) {
|
||||
// foreach(PreordercampaignModel::search(["owner_id" => $this->me->address_id]) as $campaign) {
|
||||
// $campaign_ids[] = $campaign->id;
|
||||
// }
|
||||
// }
|
||||
// we need to use this if the user is not a admin to only show his campaigns
|
||||
// we will pass the campaign_ids to the function and check if the user is allowed to see the data
|
||||
// if the user is not allowed to see the data we will return an empty array
|
||||
|
||||
$campaigns = PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
|
||||
// loop through the campaigns and check if the user is allowed to see the data
|
||||
foreach ($campaigns as $campaign) {
|
||||
if (!in_array($campaign->id, $campaign_ids)) {
|
||||
$key = array_search($campaign->id, $campaign_ids);
|
||||
unset($campaign_ids[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $campaign_ids;
|
||||
}
|
||||
|
||||
private function getGemeindenFromCampaigns($campaignids = []) {
|
||||
$gemeinden = [];
|
||||
|
||||
@@ -138,24 +166,11 @@ class DashboardNewController extends mfBaseController {
|
||||
$mph_connection_types = ["apartment-building", "apartment", "multi-dwelling"];
|
||||
|
||||
$countFunction = function($params, $statusFlag = null) use ($campaign_ids, $gemeinde_ids) {
|
||||
$baseParams = ["preordercampaign_id" => $campaign_ids];
|
||||
if (!empty($gemeinde_ids)) {
|
||||
// as the count only supports 1 gemeinde id as filter we need to use a foreach to get the count for multiple gemeinde ids
|
||||
|
||||
$count = 0;
|
||||
foreach ($gemeinde_ids as $gemeinde_id) {
|
||||
$baseParams["gemeinde_id"] = $gemeinde_id;
|
||||
$count += $statusFlag ?
|
||||
PreorderModel::countStatusFlagsActive($baseParams, $statusFlag) :
|
||||
PreorderModel::countActive($baseParams);
|
||||
}
|
||||
return $count;
|
||||
} else {
|
||||
$params = array_merge($baseParams, $params);
|
||||
return $statusFlag ?
|
||||
PreorderModel::countStatusFlagsActive($params, $statusFlag) :
|
||||
PreorderModel::countActive($params);
|
||||
}
|
||||
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
|
||||
$params = array_merge($baseParams, $params);
|
||||
return $statusFlag ?
|
||||
PreorderModel::countStatusFlagsActive($params, $statusFlag) :
|
||||
PreorderModel::countActive($params);
|
||||
};
|
||||
|
||||
|
||||
@@ -205,16 +220,8 @@ class DashboardNewController extends mfBaseController {
|
||||
|
||||
private function getTimeline($type, $campaign_ids, $gemeinde_ids) { //TODO: fix gemeinde
|
||||
$timeline = [];
|
||||
$baseParams = ["preordercampaign_id" => $campaign_ids];
|
||||
if (!empty($gemeinde_ids)) {
|
||||
foreach ($gemeinde_ids as $gemeinde_id) {
|
||||
$baseParams["gemeinde_id"] = $gemeinde_id;
|
||||
$timeline[] = $this->getTimelineData($type, $baseParams);
|
||||
}
|
||||
} else {
|
||||
$timeline[] = $this->getTimelineData($type, $baseParams);
|
||||
}
|
||||
|
||||
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
|
||||
$timeline[] = $this->getTimelineData($type, $baseParams);
|
||||
return $timeline;
|
||||
}
|
||||
|
||||
@@ -240,7 +247,7 @@ class DashboardNewController extends mfBaseController {
|
||||
}
|
||||
|
||||
// Load cached data if it exists
|
||||
if (file_exists($cacheFile)) {
|
||||
if (file_exists($cacheFile) && false) {
|
||||
$cachedData = json_decode(file_get_contents($cacheFile), true);
|
||||
$lastCachedDate = end($cachedData)['date'];
|
||||
$lastCachedTimestamp = strtotime($lastCachedDate);
|
||||
|
||||
@@ -748,9 +748,12 @@ class PreorderModel {
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde_id", $filter)) {
|
||||
$gemeinde_id = FronkDB::singleton()->escape($filter['gemeinde_id']);
|
||||
if($gemeinde_id) {
|
||||
if(!is_array($filter['gemeinde_id'])) {
|
||||
$gemeinde_id = FronkDB::singleton()->escape($filter['gemeinde_id']);
|
||||
$where .= " AND `".ADDRESSDB_DBNAME."`.adb_hausnummer.gemeinde_id = $gemeinde_id";
|
||||
} elseif(count($filter['gemeinde_id'])) {
|
||||
$gemeinde_id = $filter['gemeinde_id'];
|
||||
$where .= " AND `".ADDRESSDB_DBNAME."`.adb_hausnummer.gemeinde_id IN (".implode(",",$gemeinde_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user