From c5b571a95c6ee157936f61d457a51802182a77fe Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Thu, 20 Sep 2018 18:44:46 -0400 Subject: [PATCH] Ordering widget components based on their order attribute, using uasort --- models/admin/newDashboard/index.php | 15 ++++++++------- views/admin/members/header.html | 2 +- .../newDashboard/components/entityAmount.html | 1 + views/admin/newDashboard/summaryWidget.html | 17 +++++++++-------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/models/admin/newDashboard/index.php b/models/admin/newDashboard/index.php index 4c164041..ba8459e8 100644 --- a/models/admin/newDashboard/index.php +++ b/models/admin/newDashboard/index.php @@ -198,6 +198,9 @@ class GlmMembersAdmin_newDashboard_index extends GlmDataMembers $haveInfoRecords = true; } + // Not sure how to make the 'callback' use $this-> or this could get pulled out + function orderSort ($a, $b) { return (strcmp ($a['order'],$b['order'])); } + // In case we want to treat the widget data before sending it to the viewfile. // May be able to avoid sending the (huge) Config array to the view foreach ( $this->config[ 'addOns' ] as $a ) { @@ -207,19 +210,15 @@ class GlmMembersAdmin_newDashboard_index extends GlmDataMembers $addons[$a['slug']]['slug'] = $a['slug']; $addons[$a['slug']]['index'] = $a['index']; $addons[$a['slug']]['widgetData'] = apply_filters($a['slug'] . "-dashboard-widget", ""); - $addons[$a['slug']]['widgetData'] = $this->queryWidgetLists($addons[$a['slug']]['widgetData']); - + + // Sort the component list based on the 'order' + uasort($addons[$a['slug']]['widgetData']['components'], 'orderSort'); } else { echo "
" . $a['slug'] . " has no filter called " . $a['slug'] . "-dashboard-widget"; - //$widgetData[] = $a['slug']; } - } - - - // Compile template data. $templateData = array( 'lockedToMember' => $lockedToMember, @@ -247,6 +246,8 @@ class GlmMembersAdmin_newDashboard_index extends GlmDataMembers } + // public function orderSort ($a, $b) { return (strcmp ($a['order'],$b['order'])); } + public function queryWidgetLists( &$widgetData = false ) { foreach ( $widgetData['components'] as &$widgetComponent ) { diff --git a/views/admin/members/header.html b/views/admin/members/header.html index 31ca525e..3140666a 100644 --- a/views/admin/members/header.html +++ b/views/admin/members/header.html @@ -11,5 +11,5 @@ {else}

Dashboard

{/if} -
+
diff --git a/views/admin/newDashboard/components/entityAmount.html b/views/admin/newDashboard/components/entityAmount.html index e69de29b..d980c078 100644 --- a/views/admin/newDashboard/components/entityAmount.html +++ b/views/admin/newDashboard/components/entityAmount.html @@ -0,0 +1 @@ +entityAmount \ No newline at end of file diff --git a/views/admin/newDashboard/summaryWidget.html b/views/admin/newDashboard/summaryWidget.html index 26998ac9..d600d8c2 100644 --- a/views/admin/newDashboard/summaryWidget.html +++ b/views/admin/newDashboard/summaryWidget.html @@ -2,20 +2,21 @@
  •  {$addon.widgetData.title}
    - {$addon.widgetData|@count} - - - {foreach $addon.widgetData.components as $component} - Order: {$component.order} + {if isset($component.template)} - {*if file_exists("./components/$component.component.html") // wouldn't it be great if this worked?*} + {**if file_exists("./components/$component.component.html") // wouldn't it be great if this worked?**} - {* This will throw a serious error if the file does not exist *} + {** This will throw a serious error if the file does not exist **} + {if isset($component['order']) && $component['order'] !== ''} +
    ====Throwing this component '{$component.template}'' in position {$component.order}====
    + {else} +
    ====No order for this component '{$component.template}', thrown to the top====
    + {/if} {include file="./components/{$component.template}.html"} - {*/if*} + {**/if**} {/if} {/foreach}
    -- 2.17.1