Ordering widget components based on their order attribute, using uasort
authorLaury GvR <laury@gaslightmedia.com>
Thu, 20 Sep 2018 22:44:46 +0000 (18:44 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 20 Sep 2018 22:44:46 +0000 (18:44 -0400)
models/admin/newDashboard/index.php
views/admin/members/header.html
views/admin/newDashboard/components/entityAmount.html
views/admin/newDashboard/summaryWidget.html

index 4c16404..ba8459e 100644 (file)
@@ -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 "<br>" . $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 ) {
index 31ca525..3140666 100644 (file)
@@ -11,5 +11,5 @@
 {else}
     <h2>Dashboard</h2>
 {/if}
-    <div id="glm-admin-content-container">
+<div id="glm-admin-content-container">
 
index 26998ac..d600d8c 100644 (file)
@@ -2,20 +2,21 @@
     <li>
         <div class="summary-widget-handle collapsible-header"><pre> {$addon.widgetData.title}</pre></div>
         <div class="summary-widget-body collapsible-body">
-            {$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'] !== ''}
+                        <br>====<span>Throwing this component '{$component.template}'' in position {$component.order}</span>====<br>
+                        {else}
+                        <br>====<span>No order for this component '{$component.template}', thrown to the top</span>====<br>
+                        {/if}
                         {include file="./components/{$component.template}.html"}
 
-                    {*/if*}
+                    {**/if**}
                 {/if}
             {/foreach}
             <div class="results-number">