Commit a8dcdcf819061443163374f8b4ec78855af88e1d

Authored by Megan Watson
1 parent ad03a8c2

KTS-3602

"Tag Cloud creates 2 fieldset entries"
Fixed. Added logging. Return a pear error if the check on the existing fieldset fails.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9127 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/widgets/FieldsetDisplayRegistry.inc.php
... ... @@ -6,31 +6,31 @@
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2008 KnowledgeTree Inc.
8 8 * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 23 * California 94120-7775, or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 *
... ... @@ -43,9 +43,9 @@ require_once(KT_LIB_DIR . &#39;/widgets/widgetfactory.inc.php&#39;);
43 43 require_once(KT_LIB_DIR . '/validation/validatorfactory.inc.php');
44 44  
45 45 class KTFieldsetDisplayRegistry {
46   -
  46 +
47 47 var $fieldset_types = array();
48   -
  48 +
49 49 // {{{ getSingleton
50 50 function &getSingleton () {
51 51 if (!KTUtil::arrayGet($GLOBALS, 'oKTFieldsetDisplayRegistry')) {
... ... @@ -63,14 +63,26 @@ class KTFieldsetDisplayRegistry {
63 63 function registerFieldsetDisplay($nsname, $className) {
64 64 $this->fieldset_types[$nsname] = $className;
65 65 }
66   -
  66 +
67 67 function getHandler($nsname) {
68 68 if (!array_key_exists($nsname, $this->fieldset_types)) {
69   - // unfortunately, we need to do a bit more spelunking here.
  69 + // unfortunately, we need to do a bit more spelunking here.
70 70 // if its conditional, we use a different item. ns is unsufficient.
71   - //
  71 + //
72 72 // FIXME this is slightly wasteful from a performance POV, though DB caching should make it OK.
73 73 $oFieldset =& KTFieldset::getByNamespace ($nsname);
  74 + if (PEAR::isError($oFieldset))
  75 + {
  76 + global $default;
  77 + $default->log->error('Could not resolve Fieldset by namespace: ' . $nsname . '. Error: ' . $oFieldset->getMessage());
  78 + return 'SimpleFieldsetDisplay';
  79 + }
  80 + if (is_a($oFieldset, 'KTEntityNoObjects'))
  81 + {
  82 + global $default;
  83 + $default->log->error('Could not resolve Fieldset by namespace: ' . $nsname . '. Error: KTEntityNoObjects returned.');
  84 + return 'SimpleFieldsetDisplay';
  85 + }
74 86 if ($oFieldset->getIsConditional() && KTMetadataUtil::validateCompleteness($oFieldset)) {
75 87 return 'ConditionalFieldsetDisplay';
76 88 } else {
... ... @@ -80,7 +92,7 @@ class KTFieldsetDisplayRegistry {
80 92 return $this->fieldset_types[$nsname];
81 93 }
82 94 }
83   -
  95 +
84 96 // simple function to adapt a fieldset to a form
85 97 // passing in $oDocument will set the initial default
86 98 // values to those attached to the document.
... ... @@ -89,10 +101,10 @@ class KTFieldsetDisplayRegistry {
89 101 function formAdaptor($oFieldset, $oDocument = null) {
90 102 $widgets = array();
91 103 $validators = array();
92   -
  104 +
93 105 $oVF =& KTValidationFactory::getSingleton();
94   - $oWF =& KTWidgetFactory::getSingleton();
95   -
  106 + $oWF =& KTWidgetFactory::getSingleton();
  107 +
96 108 $fields =& $oFieldset->getFields();
97 109 foreach ($fields as $oField) {
98 110 // FIXME we probably want to use some form of factory here.
... ... @@ -100,7 +112,7 @@ class KTFieldsetDisplayRegistry {
100 112 if ($field->getHasLookup()) {
101 113 // lookups
102 114 if ($field->getHasLookupTree()) {
103   - // tree
  115 + // tree
104 116 // FIXME we don't handle trees yet
105 117 continue;
106 118 /*
... ... @@ -108,13 +120,13 @@ class KTFieldsetDisplayRegistry {
108 120 $fieldTree = new MDTree();
109 121 $fieldTree->buildForField($field->getId());
110 122 $fieldTree->setActiveItem($current_value);
111   - $fieldOptions['tree'] = $fieldTree->_evilTreeRenderer($fieldTree, $fieldName);
112   - $oField = new KTTreeWidget($fieldLabel, $fieldDescription, $fieldName, $fieldValue, $page, $fieldRequired, null, $fieldErrors, $fieldOptions);
113   -
  123 + $fieldOptions['tree'] = $fieldTree->_evilTreeRenderer($fieldTree, $fieldName);
  124 + $oField = new KTTreeWidget($fieldLabel, $fieldDescription, $fieldName, $fieldValue, $page, $fieldRequired, null, $fieldErrors, $fieldOptions);
  125 +
114 126 */
115 127 } else {
116 128 // normal
117   -
  129 +
118 130 $widgets[] = $oWF->get('ktcore.widgets.entityselection', array(
119 131 'label' => $oField->getName(),
120 132 'name' => 'metadata_' . $oField->getId(),
... ... @@ -124,14 +136,14 @@ class KTFieldsetDisplayRegistry {
124 136 'label_method' => 'getName',
125 137 'required' => $oField->getIsMandatory(),
126 138 ));
127   -
  139 +
128 140 if ($oField->getIsMandatory()) {
129 141 $validators[] = $oVF->get('ktcore.validators.required', array(
130 142 'test' => $field_name,
131 143 'basename' => 'metadata_',
132 144 ));
133 145 }
134   -
  146 +
135 147 $validators[] = $oVF->get('ktcore.validators.membership', array(
136 148 'test' => $field_name,
137 149 'output' => $field_name,
... ... @@ -150,10 +162,10 @@ class KTFieldsetDisplayRegistry {
150 162 'test' => $field_name,
151 163 'basename' => $field_name,
152 164 ));
153   - }
154   - }
  165 + }
  166 + }
155 167 }
156   -
  168 +
157 169 return array(
158 170 'widgets' => $widgets,
159 171 'validators' => $validators,
... ...
plugins/tagcloud/TagCloudPlugin.php
... ... @@ -7,31 +7,31 @@
7 7 * Document Management Made Simple
8 8 * Copyright (C) 2008 KnowledgeTree Inc.
9 9 * Portions copyright The Jam Warehouse Software (Pty) Limited
10   - *
  10 + *
11 11 * This program is free software; you can redistribute it and/or modify it under
12 12 * the terms of the GNU General Public License version 3 as published by the
13 13 * Free Software Foundation.
14   - *
  14 + *
15 15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 18 * details.
19   - *
  19 + *
20 20 * You should have received a copy of the GNU General Public License
21 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - *
23   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  22 + *
  23 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
24 24 * California 94120-7775, or email info@knowledgetree.com.
25   - *
  25 + *
26 26 * The interactive user interfaces in modified source and object code versions
27 27 * of this program must display Appropriate Legal Notices, as required under
28 28 * Section 5 of the GNU General Public License version 3.
29   - *
  29 + *
30 30 * In accordance with Section 7(b) of the GNU General Public License version 3,
31 31 * these Appropriate Legal Notices must retain the display of the "Powered by
32   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
33 33 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
34   - * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * must display the words "Powered by KnowledgeTree" and retain the original
35 35 * copyright notice.
36 36 * Contributor( s): ______________________________________
37 37 *
... ... @@ -76,23 +76,27 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
76 76  
77 77  
78 78 // Check if the tagcloud fielset entry exists, if not, create it
79   - if(!TagCloudPlugin::tagFieldsetExists()){
  79 + $iFieldsetId = TagCloudPlugin::tagFieldsetExists();
  80 + if(PEAR::isError($iFieldsetId)){
  81 + return false;
  82 + }
  83 + if($iFieldsetId !== false){
80 84 $oFieldset = TagCloudPlugin::createFieldset();
81   - if (PEAR::isError($oFieldset)) {
  85 + if (PEAR::isError($oFieldset) || is_null($oFieldset)) {
82 86 return false;
83 87 }
84   - if($oFieldset){
85   - // make the fieldset id viewable
86   - $iFieldsetId = $oFieldset->iId;
87   - }
88   - }else{ // if the entry exists, make the fieldset id viewable anyway
89   - $iFieldsetId = TagCloudPlugin::tagFieldsetExists();
  88 + // make the fieldset id viewable
  89 + $iFieldsetId = $oFieldset->iId;
90 90 }
91 91  
92 92 // Check if the tagcloud document field entry exists, if not, create it
93   - if(!TagCloudPlugin::tagFieldExists()){
  93 + $fExists = TagCloudPlugin::tagFieldExists();
  94 + if(PEAR::isError($fExists)){
  95 + return false;
  96 + }
  97 + if($fExists !== false){
94 98 $oField = TagCloudPlugin::createDocumentField($iFieldsetId);
95   - if (PEAR::isError($oField)) {
  99 + if (PEAR::isError($oField) || is_null($oField)) {
96 100 return false;
97 101 }
98 102 }
... ... @@ -156,8 +160,9 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
156 160 $sTag = DBUtil::getOneResultKey(array($sQuery), 'id');
157 161  
158 162 if (PEAR::isError($sTag)) {
159   - // XXX: log error
160   - return false;
  163 + global $default;
  164 + $default->log->error('Error resolving Tag Cloud field: '. $sTag->getMessage());
  165 + return $sTag;
161 166  
162 167 }
163 168 if(!is_null($sTag)){
... ... @@ -178,8 +183,9 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
178 183 $iFieldset = DBUtil::getOneResultKey(array($sQuery), 'id');
179 184  
180 185 if (PEAR::isError($iFieldset)) {
181   - // XXX: log error
182   - return false;
  186 + global $default;
  187 + $default->log->error('Error resolving Tag Cloud fieldset: '. $iFieldset->getMessage());
  188 + return $iFieldset;
183 189  
184 190 }
185 191 if(!is_null($iFieldset)){
... ...