From 821155c99635a8d14677fbfe00aa6d096a9b13be Mon Sep 17 00:00:00 2001
From: Brad Shuttleworth
Date: Mon, 12 Dec 2005 10:22:32 +0000
Subject: [PATCH] very simple dashlet disabling.
---
config/tableMappings.inc | 1 +
lib/dashboard/DashletDisables.inc.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
plugins/ktcore/assistance/KTUserAssistance.php | 30 +++++++++++++++++++++++++-----
presentation/lookAndFeel/knowledgeTree/dashboard.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++---------------------
sql/mysql/install/structure.sql | 28 ++++++++++++++++++++++++++++
templates/ktcore/dashlets/admintutorial.smarty | 2 +-
templates/ktcore/dashlets/usertutorial.smarty | 2 +-
7 files changed, 154 insertions(+), 28 deletions(-)
create mode 100644 lib/dashboard/DashletDisables.inc.php
diff --git a/config/tableMappings.inc b/config/tableMappings.inc
index ae1a748..516d4b3 100644
--- a/config/tableMappings.inc
+++ b/config/tableMappings.inc
@@ -141,4 +141,5 @@ $default->permission_dynamic_conditions_table = 'permission_dynamic_conditions';
$default->permission_dynamic_assignments_table = 'permission_dynamic_assignments';
$default->notifications_table = "notifications";
$default->authentication_sources_table = "authentication_sources";
+$default->dashlet_disable_table = "dashlet_disables";
?>
diff --git a/lib/dashboard/DashletDisables.inc.php b/lib/dashboard/DashletDisables.inc.php
new file mode 100644
index 0000000..ab23232
--- /dev/null
+++ b/lib/dashboard/DashletDisables.inc.php
@@ -0,0 +1,51 @@
+iId; }
+ function getUserId() { return $this->iUserId; }
+ function setUserId($iNewValue) { $this->iUserId = $iNewValue; }
+ function getNamespace() { return $this->sNamespace; }
+ function setNamespace($sNewValue) { $this->sNamespace = $sNewValue; }
+
+ var $_aFieldToSelect = array(
+ "iId" => "id",
+ "iUserId" => "user_id",
+ "sNamespace" => "dashlet_namespace",
+ );
+
+ function _table () {
+ return KTUtil::getTableName('dashlet_disable');
+ }
+
+ // Static function
+ function &get($iId) { return KTEntityUtil::get('KTDashletDisable', $iId); }
+ function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTDashletDisable', $sWhereClause); }
+ function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('KTDashletDisable', $aOptions); }
+
+ function &getForUserAndDashlet($iUserId, $sNamespace) {
+ $sWhereClause = 'WHERE user_id = ? AND dashlet_namespace = ?';
+ $aParams = array($iUserId, $sNamespace);
+
+ return KTDashletDisable::getList(array($sWhereClause, $aParams));
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/plugins/ktcore/assistance/KTUserAssistance.php b/plugins/ktcore/assistance/KTUserAssistance.php
index e5ae3e6..424ee41 100644
--- a/plugins/ktcore/assistance/KTUserAssistance.php
+++ b/plugins/ktcore/assistance/KTUserAssistance.php
@@ -5,6 +5,7 @@
require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
require_once(KT_LIB_DIR . '/dashboard/dashlet.inc.php');
+require_once(KT_LIB_DIR . '/dashboard/DashletDisables.inc.php');
require_once(KT_LIB_DIR . "/templating/templating.inc.php");
require_once(KT_LIB_DIR . "/dashboard/Notification.inc.php");
require_once(KT_LIB_DIR . "/security/Permission.inc");
@@ -25,10 +26,17 @@ $oRegistry->registerPlugin('KTUserAssistance', 'ktcore.userassistance', __FILE__
$oPlugin =& $oRegistry->getPlugin('ktcore.userassistance');
// ultra simple skeleton for the user tutorial
+// FIXME do we want to store the namespace inside the dashlet?
class KTUserTutorialDashlet extends KTBaseDashlet {
function is_active($oUser) {
- // FIXME check if the user has "turned this off" for themselves.
- return true;
+ $namespace = 'ktcore.dashlet.usertutorial';
+ $disables = KTDashletDisable::getForUserAndDashlet($oUser->getId(), $namespace);
+
+ if (!empty($disables)) {
+ return false;
+ } else {
+ return true;
+ }
}
function render() {
@@ -45,9 +53,19 @@ $oPlugin->registerDashlet('KTUserTutorialDashlet', 'ktcore.dashlet.usertutorial'
// ultra simple skeleton for the admin tutorial
class KTAdminTutorialDashlet extends KTBaseDashlet {
function is_active($oUser) {
- // FIXME check if the user has "turned this off" for themselves.
- return Permission::userIsSystemAdministrator($oUser->getId());
- return true;
+
+ $namespace = 'ktcore.dashlet.admintutorial';
+
+ if (!Permission::userIsSystemAdministrator($oUser->getId())) {
+ return false; // quickest disable.
+ }
+
+ $disables = KTDashletDisable::getForUserAndDashlet($oUser->getId(), $namespace);
+ if (!empty($disables)) {
+ return false;
+ } else {
+ return true;
+ }
}
function render() {
@@ -78,6 +96,8 @@ class KTUserAssistBasePage extends KTStandardDispatcher {
$this->oPage->setShowPortlets(false);
return $contents;
}
+
+ // hide the dashlet from the user (e.g. don't show it again) and redirect back to the dashboard.
}
class KTUserAssistB1WhatIs extends KTUserAssistBasePage { var $pagefile = 'kt3b1-what-is-a-beta'; var $title = 'What is a Beta?'; }
diff --git a/presentation/lookAndFeel/knowledgeTree/dashboard.php b/presentation/lookAndFeel/knowledgeTree/dashboard.php
index c90ca70..2cd5b4e 100644
--- a/presentation/lookAndFeel/knowledgeTree/dashboard.php
+++ b/presentation/lookAndFeel/knowledgeTree/dashboard.php
@@ -37,11 +37,13 @@ require_once(KT_LIB_DIR . "/templating/templating.inc.php");
require_once(KT_LIB_DIR . "/templating/kt3template.inc.php");
require_once(KT_LIB_DIR . "/dispatcher.inc.php");
+require_once(KT_LIB_DIR . "/dashboard/DashletDisables.inc.php");
+
$sectionName = "dashboard";
class DashboardDispatcher extends KTStandardDispatcher {
-
- var $notifications = array();
+
+ var $notifications = array();
function DashboardDispatcher() {
$this->aBreadcrumbs = array(
@@ -50,26 +52,50 @@ class DashboardDispatcher extends KTStandardDispatcher {
return parent::KTStandardDispatcher();
}
function do_main() {
- $this->oPage->setShowPortlets(false);
- // retrieve action items for the user.
- // FIXME what is the userid?
-
-
- $oDashletRegistry =& KTDashletRegistry::getSingleton();
- $aDashlets = $oDashletRegistry->getDashlets($this->oUser);
-
- $this->sSection = "dashboard";
- $this->oPage->setBreadcrumbDetails(_("Home"));
- $this->oPage->title = _("Dashboard");
-
- $oTemplating = new KTTemplating;
- $oTemplate = $oTemplating->loadTemplate("kt3/dashboard");
- $aTemplateData = array(
+ $this->oPage->setShowPortlets(false);
+ // retrieve action items for the user.
+ // FIXME what is the userid?
+
+
+ $oDashletRegistry =& KTDashletRegistry::getSingleton();
+ $aDashlets = $oDashletRegistry->getDashlets($this->oUser);
+
+ $this->sSection = "dashboard";
+ $this->oPage->setBreadcrumbDetails(_("Home"));
+ $this->oPage->title = _("Dashboard");
+
+ $oTemplating = new KTTemplating;
+ $oTemplate = $oTemplating->loadTemplate("kt3/dashboard");
+ $aTemplateData = array(
"context" => $this,
- "dashlets" => $aDashlets,
- );
- return $oTemplate->render($aTemplateData);
- }
+ "dashlets" => $aDashlets,
+ );
+ return $oTemplate->render($aTemplateData);
+ }
+
+ // disable a dashlet.
+ // FIXME this very slightly violates the separation of concerns, but its not that flagrant.
+ function do_disableDashlet() {
+ $sNamespace = KTUtil::arrayGet($_REQUEST, 'fNamespace');
+ $iUserId = $this->oUser->getId();
+
+ if (empty($sNamespace)) {
+ $this->errorRedirectToMain('No dashlet specified.');
+ exit(0);
+ }
+
+ // do the "delete"
+
+ $this->startTransaction();
+ $aParams = array('sNamespace' => $sNamespace, 'iUserId' => $iUserId);
+ $oDD = KTDashletDisable::createFromArray($aParams);
+ if (PEAR::isError($oDD)) {
+ $this->errorRedirectToMain('Failed to disable the dashlet.');
+ }
+
+ $this->commitTransaction();
+ $this->successRedirectToMain('Dashlet disabled.');
+ }
}
$oDispatcher = new DashboardDispatcher();
diff --git a/sql/mysql/install/structure.sql b/sql/mysql/install/structure.sql
index d68b279..2b083fa 100644
--- a/sql/mysql/install/structure.sql
+++ b/sql/mysql/install/structure.sql
@@ -118,6 +118,22 @@ CREATE TABLE `data_types` (
-- --------------------------------------------------------
--
+-- Table structure for table `dashlet_disables`
+--
+
+CREATE TABLE `dashlet_disables` (
+ `id` int(11) NOT NULL default '0',
+ `user_id` int(11) NOT NULL default '',
+ `dashlet_namespace` varchar(255) NOT NULL default '',
+ UNIQUE KEY `id` (`id`),
+ INDEX (`user_id`),
+ INDEX (`dashlet_namespace`)
+) ENGINE=InnoDB ;
+
+-- --------------------------------------------------------
+
+
+--
-- Table structure for table `dependant_document_instance`
--
@@ -2084,6 +2100,18 @@ CREATE TABLE `zseq_workflows` (
PRIMARY KEY (`id`)
) ENGINE=MyISAM ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `zseq_dashlet_disables`
+--
+
+CREATE TABLE `zseq_dashlet_disables` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM ;
+
--
-- Constraints for dumped tables
--
diff --git a/templates/ktcore/dashlets/admintutorial.smarty b/templates/ktcore/dashlets/admintutorial.smarty
index ed038e7..405f61d 100644
--- a/templates/ktcore/dashlets/admintutorial.smarty
+++ b/templates/ktcore/dashlets/admintutorial.smarty
@@ -9,4 +9,4 @@ which might help you get to grips with the new system.{/i18n}
href="{$rootUrl}/plugin.php/ktcore.userassistance/admin-quickguide">{i18n}Read the admin introduction.{/i18n} |
{i18n}Find out what's different in KT 3.{/i18n} |
-{i18n}Don't show me this again.{/i18n}
+{i18n}Don't show me this again.{/i18n}
diff --git a/templates/ktcore/dashlets/usertutorial.smarty b/templates/ktcore/dashlets/usertutorial.smarty
index bad1281..d04323d 100644
--- a/templates/ktcore/dashlets/usertutorial.smarty
+++ b/templates/ktcore/dashlets/usertutorial.smarty
@@ -6,4 +6,4 @@ KnowledgeTree™ 3? We've written some quick documentation{/i18n}
Take the crash course. |
Learn about KnowledgeTree 3. |
-Don't show me this again.
+{i18n}Don't show me this again.{/i18n}
--
libgit2 0.21.4