Commit 1d80be8a78e6b785cf428962deac690d3e127b0e

Authored by Megan Watson
1 parent 483ed264

KTC-286

"Welcome to knowledgeTree dashlet should always be on the top left corner of the dashlet container"
Fixed. Refactored the way the users state is refreshed. It now uses the plugin_helper table to get any new dashlets.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7816 c91229c3-7414-0410-bfa2-8a42b809f60b
dashboard.php
... ... @@ -3,38 +3,38 @@
3 3 * $Id$
4 4 *
5 5 * Main dashboard page -- This page is presented to the user after login.
6   - * It contains a high level overview of the users subscriptions, checked out
7   - * document, pending approval routing documents, etc.
  6 + * It contains a high level overview of the users subscriptions, checked out
  7 + * document, pending approval routing documents, etc.
8 8 *
9 9 * KnowledgeTree Open Source Edition
10 10 * Document Management Made Simple
11 11 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
12   - *
  12 + *
13 13 * This program is free software; you can redistribute it and/or modify it under
14 14 * the terms of the GNU General Public License version 3 as published by the
15 15 * Free Software Foundation.
16   - *
  16 + *
17 17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 20 * details.
21   - *
  21 + *
22 22 * You should have received a copy of the GNU General Public License
23 23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24   - *
  24 + *
25 25 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
26 26 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
27   - *
  27 + *
28 28 * The interactive user interfaces in modified source and object code versions
29 29 * of this program must display Appropriate Legal Notices, as required under
30 30 * Section 5 of the GNU General Public License version 3.
31   - *
  31 + *
32 32 * In accordance with Section 7(b) of the GNU General Public License version 3,
33 33 * these Appropriate Legal Notices must retain the display of the "Powered by
34   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  34 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
35 35 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
36   - * must display the words "Powered by KnowledgeTree" and retain the original
37   - * copyright notice.
  36 + * must display the words "Powered by KnowledgeTree" and retain the original
  37 + * copyright notice.
38 38 * Contributor( s): ______________________________________
39 39 */
40 40  
... ... @@ -53,9 +53,9 @@ require_once(KT_LIB_DIR . &#39;/dashboard/DashletDisables.inc.php&#39;);
53 53 $sectionName = 'dashboard';
54 54  
55 55 class DashboardDispatcher extends KTStandardDispatcher {
56   -
  56 +
57 57 var $notifications = array();
58   - var $sHelpPage = 'ktcore/dashboard.html';
  58 + var $sHelpPage = 'ktcore/dashboard.html';
59 59  
60 60 function DashboardDispatcher() {
61 61 $this->aBreadcrumbs = array(
... ... @@ -67,25 +67,29 @@ class DashboardDispatcher extends KTStandardDispatcher {
67 67 $this->oPage->setShowPortlets(false);
68 68 // retrieve action items for the user.
69 69 // FIXME what is the userid?
70   -
71   -
  70 +
  71 +
72 72 $oDashletRegistry =& KTDashletRegistry::getSingleton();
73 73 $aDashlets = $oDashletRegistry->getDashlets($this->oUser);
74   -
  74 +
75 75 $this->sSection = 'dashboard';
76 76 $this->oPage->setBreadcrumbDetails(_kt('Home'));
77 77 $this->oPage->title = _kt('Dashboard');
78   -
  78 +
79 79 // simplistic improvement over the standard rendering: float half left
80 80 // and half right. +Involves no JS -can leave lots of white-space at the bottom.
81 81  
82 82 $aDashletsLeft = array();
83   - $aDashletsRight = array();
  83 + $aDashletsRight = array();
84 84  
85 85 $i = 0;
86 86 foreach ($aDashlets as $oDashlet) {
87   - if ($i == 0) { $aDashletsLeft[] = $oDashlet; }
88   - else {$aDashletsRight[] = $oDashlet; }
  87 + if(strpos(strtolower($oDashlet->sTitle), 'welcome to knowledgetree') !== false && !empty($aDashletsLeft)){
  88 + array_unshift($aDashletsLeft, $oDashlet);
  89 + }else{
  90 + if ($i == 0) { $aDashletsLeft[] = $oDashlet; }
  91 + else {$aDashletsRight[] = $oDashlet; }
  92 + }
89 93 $i += 1;
90 94 $i %= 2;
91 95 }
... ... @@ -97,10 +101,10 @@ class DashboardDispatcher extends KTStandardDispatcher {
97 101 $this->oPage->requireJSResource('thirdpartyjs/yui/dom/dom.js');
98 102 $this->oPage->requireJSResource('thirdpartyjs/yui/dragdrop/dragdrop.js');
99 103 $this->oPage->requireJSResource('resources/js/DDList.js');
100   -
  104 +
101 105  
102 106 $this->oUser->refreshDashboadState();
103   -
  107 +
104 108 // dashboard
105 109 $sDashboardState = $this->oUser->getDashboardState();
106 110 $sDSJS = 'var savedState = ';
... ... @@ -114,7 +118,6 @@ class DashboardDispatcher extends KTStandardDispatcher {
114 118 $this->oPage->requireJSStandalone($sDSJS);
115 119 $this->oPage->requireJSResource('resources/js/dashboard.js');
116 120  
117   -
118 121 // render
119 122 $oTemplating =& KTTemplating::getSingleton();
120 123 $oTemplate = $oTemplating->loadTemplate('kt3/dashboard');
... ... @@ -125,33 +128,33 @@ class DashboardDispatcher extends KTStandardDispatcher {
125 128 );
126 129 return $oTemplate->render($aTemplateData);
127 130 }
128   -
  131 +
129 132 // return some kind of ID for each dashlet
130 133 // currently uses the class name
131 134 function _getDashletId($oDashlet) {
132 135 return get_class($oDashlet);
133 136 }
134 137  
135   - // disable a dashlet.
  138 + // disable a dashlet.
136 139 // FIXME this very slightly violates the separation of concerns, but its not that flagrant.
137 140 function do_disableDashlet() {
138 141 $sNamespace = KTUtil::arrayGet($_REQUEST, 'fNamespace');
139 142 $iUserId = $this->oUser->getId();
140   -
  143 +
141 144 if (empty($sNamespace)) {
142 145 $this->errorRedirectToMain('No dashlet specified.');
143 146 exit(0);
144 147 }
145   -
  148 +
146 149 // do the "delete"
147   -
  150 +
148 151 $this->startTransaction();
149 152 $aParams = array('sNamespace' => $sNamespace, 'iUserId' => $iUserId);
150 153 $oDD = KTDashletDisable::createFromArray($aParams);
151 154 if (PEAR::isError($oDD)) {
152 155 $this->errorRedirectToMain('Failed to disable the dashlet.');
153 156 }
154   -
  157 +
155 158 $this->commitTransaction();
156 159 $this->successRedirectToMain('Dashlet disabled.');
157 160 }
... ...
lib/dashboard/dashletregistry.inc.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -53,6 +53,55 @@ class KTDashletRegistry {
53 53 $this->nsnames[$nsname] = array($name, $filename, $nsname, $sPlugin);
54 54 }
55 55  
  56 + /**
  57 + * Get any dashlets added since the user's last login
  58 + *
  59 + * @param object $oUser
  60 + */
  61 + function getNewDashlets($oUser, $sCurrent) {
  62 + $new = array();
  63 + $inactive = array();
  64 +
  65 + static $sInactive = '';
  66 + $sIgnore = (!empty($sInactive)) ? $sCurrent.','.$sInactive : $sCurrent;
  67 +
  68 + // Get all dashlets that haven't already been displayed to the user and are active for the user
  69 + $query = "SELECT * FROM plugin_helper h
  70 + INNER JOIN plugins p ON (h.plugin = p.namespace)
  71 + WHERE p.disabled = 0 AND classtype = 'dashlet'
  72 + AND h.classname NOT IN ($sIgnore)";
  73 +
  74 + $res = DBUtil::getResultArray($query);
  75 +
  76 + // If the query is not empty, get the dashlets and return the new active ones
  77 + // Add the inactive ones the list.
  78 + if(!PEAR::isError($res) && !empty($res)){
  79 + $oRegistry =& KTPluginRegistry::getSingleton();
  80 + foreach ($res as $item){
  81 + $name = $item['classname'];
  82 + $filename = $item['pathname'];
  83 + $sPluginName = $item['plugin'];
  84 +
  85 + require_once($filename);
  86 + $oPlugin =& $oRegistry->getPlugin($sPluginName);
  87 +
  88 + $oDashlet = new $name;
  89 + $oDashlet->setPlugin($oPlugin);
  90 + if ($oDashlet->is_active($oUser)) {
  91 + $new[] = $name;
  92 + }else{
  93 + $inactive[] = "'$name'";
  94 + }
  95 + }
  96 + // Add new inactive dashlets
  97 + $sNewInactive = implode(',', $inactive);
  98 + $sInactive = (!empty($sInactive)) ? $sInactive.','.$sNewInactive : $sNewInactive;
  99 +
  100 + return $new;
  101 + }
  102 + return '';
  103 + }
  104 +
56 105 // FIXME we might want to do the pruning now, but I'm unsure how to handle the preconditions.
57 106 function getDashlets($oUser) {
58 107 $aDashlets = array();
... ...
lib/users/User.inc
... ... @@ -81,6 +81,12 @@ class User extends KTEntity {
81 81 var $dLastLogin = null;
82 82 var $bDisabled = false;
83 83  
  84 + /**
  85 + * The dashboard state for the current user
  86 + * @var string
  87 + */
  88 + var $sDashboardState = '';
  89 +
84 90 var $_aFieldToSelect = array(
85 91 'iId' => 'id',
86 92 'sUserName' => 'username',
... ... @@ -176,23 +182,26 @@ class User extends KTEntity {
176 182 }
177 183  
178 184 function getDashboardState() {
179   - return KTUtil::getSystemSetting($this->_getDashboardStateKey());
  185 + if(empty($this->sDashboardState)){
  186 + $this->sDashboardState = KTUtil::getSystemSetting($this->_getDashboardStateKey());
  187 + }
  188 + return $this->sDashboardState;
180 189 }
181 190  
182 191 function setDashboardState($mValue) {
  192 + $this->sDashboardState = $mValue;
183 193 KTUtil::setSystemSetting($this->_getDashboardStateKey(), $mValue);
184 194 }
185 195  
186 196 function refreshDashboadState()
187 197 {
188 198 require_once(KT_DIR . "/thirdparty/pear/JSON.php");
189   -
190 199 $dashletRegistry = & KTDashletRegistry::getSingleton();
191 200  
192   - $aDashlets = $dashletRegistry->getDashlets($this);
  201 + $update = false;
  202 + $knownlist = array();
193 203  
194 204 $oJSON = new Services_JSON();
195   -
196 205 $state = $this->getDashboardState();
197 206 $dashlets = $oJSON->decode($state);
198 207  
... ... @@ -200,34 +209,59 @@ class User extends KTEntity {
200 209 if (!isset($dashlets->right)) $dashlets->right = array();
201 210 $mergedlist = kt_array_merge($dashlets->left,$dashlets->right);
202 211  
203   -
204   - $knownlist = array();
205 212 foreach($mergedlist as $dashlet)
206 213 {
207   - array_push($knownlist,$dashlet->id);
  214 + array_push($knownlist,"'".$dashlet->id."'");
208 215 }
209   - $update=false;
210 216  
211   - //if (!isset($dashlets->left)) $dashlets->left=array();
212   - //if (!isset($dashlets->right)) $dashlets->right=array();
  217 + $sKnownlist = implode(',', $knownlist);
  218 + $aDashlets = $dashletRegistry->getNewDashlets($this, $sKnownlist);
  219 +
  220 + if(!empty($aDashlets)){
  221 + $column=1;
  222 + foreach($aDashlets as $class)
  223 + {
  224 + $column = ($column + 1) %2;
  225 + $obj = new stdClass();
  226 + $obj->id=$class;
  227 + $obj->state=0;
  228 +
  229 + if ($column == 0)
  230 + array_push($dashlets->left,$obj);
  231 + else
  232 + array_push($dashlets->right,$obj);
  233 + $update=true;
  234 + }
  235 + }
213 236  
214   - $column=1;
215   - foreach($aDashlets as $dashlet)
216   - {
217   - $class = get_class($dashlet);
218   - $column=($column + 1) %2;
219   - if (!in_array($class,$knownlist))
220   - {
221   - $obj = new stdClass();
222   - $obj->id=$class;
223   - $obj->state=0;
224   -
225   - if ($column == 0)
226   - array_push($dashlets->left,$obj);
227   - else
228   - array_push($dashlets->right,$obj);
229   - $update=true;
230   - }
  237 + // Check if the KT Info dashlet is being displayed
  238 + // If it's not in the top left corner, move it there.
  239 + if(!(strpos($sKnownlist, 'KTInfoDashlet') === false) && $knownlist[0] != "'KTInfoDashlet'"){
  240 + $left = $dashlets->left;
  241 + $right = $dashlets->right;
  242 +
  243 + $found = false;
  244 + $update = true;
  245 + foreach($left as $key => $item){
  246 + if($item->id == 'KTInfoDashlet'){
  247 + // found the dashlet
  248 + $found = 'true';
  249 + array_splice($dashlets->left, $key, 1);
  250 + array_unshift($dashlets->left, $item);
  251 + continue;
  252 + }
  253 + }
  254 + if(!$found){
  255 + foreach($right as $key => $item){
  256 + if($item->id == 'KTInfoDashlet'){
  257 + // found the dashlet
  258 + $found = 'true';
  259 + array_splice($dashlets->right, $key, 1);
  260 + array_unshift($dashlets->left, $item);
  261 + continue;
  262 + }
  263 + }
  264 + }
231 265 }
232 266  
233 267 if ($update)
... ...