Commit 5ee725cd89865baf4e69fea2e0d1d201821e2807

Authored by Jonathan Byrne
1 parent 12398b72

KTS-2718

"Tags added to documents when the Tag Cloud add-in is disabled does not show in that Tag Cloud Dashlet once it has been enabled again."

Fixed. Moved tag cloud trigger into core so it isn't dependant on the plugin.

Committed By: Jonathan Byrne
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7772 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/KTCorePlugin.php
... ... @@ -158,6 +158,11 @@ class KTCorePlugin extends KTPlugin {
158 158 $this->registerTrigger('edit', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.edit', KT_DIR . '/plugins/search2/Search2Triggers.php');
159 159 $this->registerTrigger('add', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.add', KT_DIR . '/plugins/search2/Search2Triggers.php');
160 160 $this->registerTrigger('discussion', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.discussion', KT_DIR . '/plugins/search2/Search2Triggers.php');
  161 +
  162 + //Tag Cloud Triggers
  163 + $this->registerTrigger('add', 'postValidate', 'KTAddDocumentTrigger', 'ktcore.triggers.tagcloud.add', KT_DIR.'/plugins/tagcloud/TagCloudTriggers.php');
  164 + $this->registerTrigger('edit', 'postValidate', 'KTEditDocumentTrigger', 'ktcore.triggers.tagcloud.edit', KT_DIR.'/plugins/tagcloud/TagCloudTriggers.php');
  165 +
161 166  
162 167 // widgets
163 168 $this->registerWidget('KTCoreHiddenWidget', 'ktcore.widgets.hidden', 'KTWidgets.php');
... ...
plugins/tagcloud/TagCloudPlugin.php
1 1 <?php
2 2  
3 3 /*
4   - * $Id:$
  4 + * $Id$
5 5 *
6 6 * KnowledgeTree Open Source Edition
7 7 * Document Management Made Simple
... ... @@ -70,10 +70,7 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
70 70 $this->registerCriterion('TagCloudCriterion', 'ktcore.criteria.tagcloud', KT_LIB_DIR . '/browse/Criteria.inc');
71 71 $this->registerDashlet('TagCloudDashlet', 'ktcore.tagcloud.feed.dashlet', 'TagCloudDashlet.php');
72 72 $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__);
73   - $this->registerTrigger('add', 'postValidate', 'KTAddDocumentTrigger',
74   - 'ktcore.triggers.tagcloud.add');
75   - $this->registerTrigger('edit', 'postValidate', 'KTEditDocumentTrigger',
76   - 'ktcore.triggers.tagcloud.edit');
  73 +
77 74  
78 75 // Check if the tagcloud fielset entry exists, if not, create it
79 76 if(!TagCloudPlugin::tagFieldsetExists()){
... ... @@ -192,213 +189,4 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
192 189 $oPluginRegistry =& KTPluginRegistry::getSingleton();
193 190 $oPluginRegistry->registerPlugin('TagCloudPlugin', 'ktcore.tagcloud.plugin', __FILE__);
194 191  
195   -/**
196   - * Trigger for document add (postValidate)
197   - *
198   - */
199   -class KTAddDocumentTrigger {
200   - var $aInfo = null;
201   - /**
202   - * function to set the info for the trigger
203   - *
204   - * @param array $aInfo
205   - */
206   - function setInfo(&$aInfo) {
207   - $this->aInfo =& $aInfo;
208   - }
209   -
210   - /**
211   - * postValidate method for trigger
212   - *
213   - * @return unknown
214   - */
215   - function postValidate() {
216   - global $default;
217   - $oDocument =& $this->aInfo['document'];
218   - $aMeta = & $this->aInfo['aOptions'];
219   -
220   - $iDocId = $oDocument->getID();
221   -
222   - // get tag id from document_fields table where name = Tag
223   - $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
224   - 'WHERE df.name = \'Tag\'';
225   -
226   - $sTags = DBUtil::getOneResultKey(array($sQuery), 'id');
227   - if (PEAR::isError($sTags)) {
228   - // XXX: log error
229   - return false;
230   - }
231   - $tagString = '';
232   - // add tags
233   - if ($sTags) {
234   - if (count($aMeta['metadata']) > 0)
235   - {
236   - foreach($aMeta['metadata'] as $aMetaData)
237   - {
238   -
239   - $oProxy = $aMetaData[0];
240   - if($oProxy->iId == $sTags)
241   - {
242   - $tagString = $aMetaData[1];
243   - }
244   - }
245   - }
246   - if($tagString != ''){
247   - $words_table = KTUtil::getTableName('tag_words');
248   - $tagString = str_replace(' ', '', $tagString);
249   - $tags = explode(',',$tagString);
250   -
251   - $aTagIds = array();
252   -
253   - foreach($tags as $sTag)
254   - {
255   - $sTag=strtolower(trim($sTag));
256   -
257   - $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
258   -
259   - if (PEAR::isError($res)) {
260   - return $res;
261   - }
262   -
263   - if (is_null($res))
264   - {
265   - $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
266   - $aTagIds[$sTag] = $id;
267   - }
268   - else
269   - {
270   - $aTagIds[$sTag] = $res['id'];
271   - }
272   - }
273   -
274   - $doc_tags = KTUtil::getTableName('document_tags');
275   -
276   - foreach($aTagIds as $sTag=>$tagid)
277   - {
278   - DBUtil::autoInsert($doc_tags, array(
279   -
280   - 'document_id'=>$iDocId,
281   - 'tag_id'=>$tagid),
282   - array('noid'=>true));
283   - }
284   - }
285   - }
286   - }
287   -}
288   -
289   -/**
290   - * Trigger for document edit (postValidate)
291   - *
292   - */
293   -class KTEditDocumentTrigger {
294   - var $aInfo = null;
295   - /**
296   - * function to set the info for the trigger
297   - *
298   - * @param array $aInfo
299   - */
300   - function setInfo(&$aInfo) {
301   - $this->aInfo =& $aInfo;
302   - }
303   -
304   - /**
305   - * postValidate method for trigger
306   - *
307   - * @return unknown
308   - */
309   - function postValidate() {
310   - global $default;
311   - $oDocument =& $this->aInfo['document'];
312   - $aMeta = & $this->aInfo['aOptions'];
313   - // get document id
314   - $iDocId = $oDocument->getID();
315   -
316   - // get all tags that are linked to the document
317   - $sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' .
318   - 'WHERE dt.tag_id = tw.id ' .
319   - 'AND dt.document_id = d.id ' .
320   - 'AND d.id = ?';
321   - $aParams = array($iDocId);
322   - $aTagId = DBUtil::getResultArray(array($sQuery, $aParams));
323   - if (PEAR::isError($aTagId)) {
324   - // XXX: log error
325   - return false;
326   - }
327   - // if there are any related tags proceed
328   - if ($aTagId) {
329   - // delete all entries from document_tags table for the document
330   - $sQuery = 'DELETE FROM document_tags ' .
331   - 'WHERE document_id = ?';
332   - $aParams = array($iDocId);
333   - $removed = DBUtil::runQuery(array($sQuery, $aParams));
334   - if (PEAR::isError($removed)) {
335   - // XXX: log error
336   - return false;
337   - }
338   - }
339   - // proceed to add the tags as per normaly
340   - $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
341   - 'WHERE df.name = \'Tag\'';
342   -
343   - $sTags = DBUtil::getOneResultKey(array($sQuery), 'id');
344   - if (PEAR::isError($sTags)) {
345   - // XXX: log error
346   - return false;
347   - }
348   - $tagString = '';
349   - if ($sTags) {
350   - // it is actually correct using $aMeta. It is different to the add trigger above...
351   - if (count($aMeta) > 0)
352   - {
353   - foreach($aMeta as $aMetaData)
354   - {
355   - $oProxy = $aMetaData[0];
356   - if($oProxy->iId == $sTags)
357   - {
358   - $tagString = $aMetaData[1];
359   - break;
360   - }
361   - }
362   - }
363   - if($tagString != ''){
364   - $words_table = KTUtil::getTableName('tag_words');
365   - $tagString = str_replace(' ', ' ', $tagString);
366   - $tags = explode(',',$tagString);
367   -
368   - $aTagIds = array();
369   -
370   - foreach($tags as $sTag)
371   - {
372   - $sTag=strtolower(trim($sTag));
373   -
374   - $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
375   -
376   - if (PEAR::isError($res)) {
377   - return $res;
378   - }
379   -
380   - if (is_null($res))
381   - {
382   - $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
383   - $aTagIds[$sTag] = $id;
384   - }
385   - else
386   - {
387   - $aTagIds[$sTag] = $res['id'];
388   - }
389   - }
390   -
391   - $doc_tags = KTUtil::getTableName('document_tags');
392   -
393   - foreach($aTagIds as $sTag=>$tagid)
394   - {
395   - DBUtil::autoInsert($doc_tags, array(
396   - 'document_id'=>$iDocId,
397   - 'tag_id'=>$tagid),
398   - array('noid'=>true));
399   - }
400   - }
401   - }
402   - }
403   -}
404 192 ?>
... ...
plugins/tagcloud/TagCloudTriggers.php 0 โ†’ 100644
  1 +<?php
  2 +/*
  3 + * $Id: $
  4 + *
  5 + * KnowledgeTree Open Source Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
  8 + *
  9 + * This program is free software; you can redistribute it and/or modify it under
  10 + * the terms of the GNU General Public License version 3 as published by the
  11 + * Free Software Foundation.
  12 + *
  13 + * This program is distributed in the hope that it will be useful, but WITHOUT
  14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16 + * details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20 + *
  21 + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
  22 + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
  23 + *
  24 + * The interactive user interfaces in modified source and object code versions
  25 + * of this program must display Appropriate Legal Notices, as required under
  26 + * Section 5 of the GNU General Public License version 3.
  27 + *
  28 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  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
  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.
  34 + * Contributor( s): ______________________________________
  35 + *
  36 + */
  37 +/**
  38 + * Trigger for document add (postValidate)
  39 + *
  40 + */
  41 +class KTAddDocumentTrigger {
  42 + var $aInfo = null;
  43 + /**
  44 + * function to set the info for the trigger
  45 + *
  46 + * @param array $aInfo
  47 + */
  48 + function setInfo(&$aInfo) {
  49 + $this->aInfo =& $aInfo;
  50 + }
  51 +
  52 + /**
  53 + * postValidate method for trigger
  54 + *
  55 + * @return unknown
  56 + */
  57 + function postValidate() {
  58 + global $default;
  59 + $oDocument =& $this->aInfo['document'];
  60 + $aMeta = & $this->aInfo['aOptions'];
  61 +
  62 + $iDocId = $oDocument->getID();
  63 +
  64 + // get tag id from document_fields table where name = Tag
  65 + $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
  66 + 'WHERE df.name = \'Tag\'';
  67 +
  68 + $sTags = DBUtil::getOneResultKey(array($sQuery), 'id');
  69 + if (PEAR::isError($sTags)) {
  70 + // XXX: log error
  71 + return false;
  72 + }
  73 + $tagString = '';
  74 + // add tags
  75 + if ($sTags) {
  76 + if (count($aMeta['metadata']) > 0)
  77 + {
  78 + foreach($aMeta['metadata'] as $aMetaData)
  79 + {
  80 +
  81 + $oProxy = $aMetaData[0];
  82 + if($oProxy->iId == $sTags)
  83 + {
  84 + $tagString = $aMetaData[1];
  85 + }
  86 + }
  87 + }
  88 + if($tagString != ''){
  89 + $words_table = KTUtil::getTableName('tag_words');
  90 + $tagString = str_replace(' ', '', $tagString);
  91 + $tags = explode(',',$tagString);
  92 +
  93 + $aTagIds = array();
  94 +
  95 + foreach($tags as $sTag)
  96 + {
  97 + $sTag=strtolower(trim($sTag));
  98 +
  99 + $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
  100 +
  101 + if (PEAR::isError($res)) {
  102 + return $res;
  103 + }
  104 +
  105 + if (is_null($res))
  106 + {
  107 + $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
  108 + $aTagIds[$sTag] = $id;
  109 + }
  110 + else
  111 + {
  112 + $aTagIds[$sTag] = $res['id'];
  113 + }
  114 + }
  115 +
  116 + $doc_tags = KTUtil::getTableName('document_tags');
  117 +
  118 + foreach($aTagIds as $sTag=>$tagid)
  119 + {
  120 + DBUtil::autoInsert($doc_tags, array(
  121 +
  122 + 'document_id'=>$iDocId,
  123 + 'tag_id'=>$tagid),
  124 + array('noid'=>true));
  125 + }
  126 + }
  127 + }
  128 + }
  129 +}
  130 +
  131 +
  132 +/**
  133 + * Trigger for document edit (postValidate)
  134 + *
  135 + */
  136 +class KTEditDocumentTrigger {
  137 + var $aInfo = null;
  138 + /**
  139 + * function to set the info for the trigger
  140 + *
  141 + * @param array $aInfo
  142 + */
  143 + function setInfo(&$aInfo) {
  144 + $this->aInfo =& $aInfo;
  145 + }
  146 +
  147 + /**
  148 + * postValidate method for trigger
  149 + *
  150 + * @return unknown
  151 + */
  152 + function postValidate() {
  153 + global $default;
  154 + $oDocument =& $this->aInfo['document'];
  155 + $aMeta = & $this->aInfo['aOptions'];
  156 + // get document id
  157 + $iDocId = $oDocument->getID();
  158 +
  159 + // get all tags that are linked to the document
  160 + $sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' .
  161 + 'WHERE dt.tag_id = tw.id ' .
  162 + 'AND dt.document_id = d.id ' .
  163 + 'AND d.id = ?';
  164 + $aParams = array($iDocId);
  165 + $aTagId = DBUtil::getResultArray(array($sQuery, $aParams));
  166 + if (PEAR::isError($aTagId)) {
  167 + // XXX: log error
  168 + return false;
  169 + }
  170 + // if there are any related tags proceed
  171 + if ($aTagId) {
  172 + // delete all entries from document_tags table for the document
  173 + $sQuery = 'DELETE FROM document_tags ' .
  174 + 'WHERE document_id = ?';
  175 + $aParams = array($iDocId);
  176 + $removed = DBUtil::runQuery(array($sQuery, $aParams));
  177 + if (PEAR::isError($removed)) {
  178 + // XXX: log error
  179 + return false;
  180 + }
  181 + }
  182 + // proceed to add the tags as per normaly
  183 + $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
  184 + 'WHERE df.name = \'Tag\'';
  185 +
  186 + $sTags = DBUtil::getOneResultKey(array($sQuery), 'id');
  187 + if (PEAR::isError($sTags)) {
  188 + // XXX: log error
  189 + return false;
  190 + }
  191 + $tagString = '';
  192 + if ($sTags) {
  193 + // it is actually correct using $aMeta. It is different to the add trigger above...
  194 + if (count($aMeta) > 0)
  195 + {
  196 + foreach($aMeta as $aMetaData)
  197 + {
  198 + $oProxy = $aMetaData[0];
  199 + if($oProxy->iId == $sTags)
  200 + {
  201 + $tagString = $aMetaData[1];
  202 + break;
  203 + }
  204 + }
  205 + }
  206 + if($tagString != ''){
  207 + $words_table = KTUtil::getTableName('tag_words');
  208 + $tagString = str_replace(' ', ' ', $tagString);
  209 + $tags = explode(',',$tagString);
  210 +
  211 + $aTagIds = array();
  212 +
  213 + foreach($tags as $sTag)
  214 + {
  215 + $sTag=strtolower(trim($sTag));
  216 +
  217 + $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
  218 +
  219 + if (PEAR::isError($res)) {
  220 + return $res;
  221 + }
  222 +
  223 + if (is_null($res))
  224 + {
  225 + $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
  226 + $aTagIds[$sTag] = $id;
  227 + }
  228 + else
  229 + {
  230 + $aTagIds[$sTag] = $res['id'];
  231 + }
  232 + }
  233 +
  234 + $doc_tags = KTUtil::getTableName('document_tags');
  235 +
  236 + foreach($aTagIds as $sTag=>$tagid)
  237 + {
  238 + DBUtil::autoInsert($doc_tags, array(
  239 + 'document_id'=>$iDocId,
  240 + 'tag_id'=>$tagid),
  241 + array('noid'=>true));
  242 + }
  243 + }
  244 + }
  245 + }
  246 +}
  247 +?>
0 248 \ No newline at end of file
... ...