Commit 53e99e4500b7eb244b9736c7e61e34fa09c51f30

Authored by bryndivey
1 parent 21f1a780

Moved criteria into namespace oriented registry


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5797 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/browse/Criteria.inc
1 1 <?php
2   -require_once(KT_LIB_DIR . '/security/Permission.inc');
3   -require_once(KT_LIB_DIR . '/users/User.inc');
4   -require_once(KT_LIB_DIR . '/documentmanagement/Document.inc');
5   -require_once(KT_LIB_DIR . '/documentmanagement/DocumentField.inc');
6   -require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc');
7   -require_once(KT_LIB_DIR . '/documentmanagement/MetaData.inc');
8   -require_once(KT_LIB_DIR . '/foldermanagement/Folder.inc');
9   -
10   -require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php');
11   -require_once(KT_LIB_DIR . '/workflow/workflow.inc.php');
12   -
13 2 /**
14 3 * $Id$
15 4 *
... ... @@ -40,6 +29,20 @@ require_once(KT_LIB_DIR . &#39;/workflow/workflow.inc.php&#39;);
40 29 * @package lib.browse
41 30 */
42 31  
  32 +require_once(KT_LIB_DIR . '/security/Permission.inc');
  33 +require_once(KT_LIB_DIR . '/users/User.inc');
  34 +require_once(KT_LIB_DIR . '/documentmanagement/Document.inc');
  35 +require_once(KT_LIB_DIR . '/documentmanagement/DocumentField.inc');
  36 +require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc');
  37 +require_once(KT_LIB_DIR . '/documentmanagement/MetaData.inc');
  38 +require_once(KT_LIB_DIR . '/foldermanagement/Folder.inc');
  39 +
  40 +require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php');
  41 +require_once(KT_LIB_DIR . '/workflow/workflow.inc.php');
  42 +
  43 +require_once(KT_LIB_DIR . '/browse/criteriaregistry.php');
  44 +
  45 +
43 46 $RESTRICTING_SEARCH = true;
44 47  
45 48 class BrowseCriterion {
... ... @@ -56,18 +59,21 @@ class BrowseCriterion {
56 59 var $bContains = false;
57 60 var $bHandleNot = true;
58 61  
59   - function BrowseCriterion ($sDisplay, $sDocumentField, $sSortField, $iID) {
60   - $this->sDisplay =& $sDisplay;
61   - $this->sDocumentField =& $sDocumentField;
62   - $this->sSortField =& $sSortField;
63   - $this->iID = $iID;
  62 + var $sDocumentField = null;
  63 + var $sSortField = null;
  64 + var $sNamespace = null;
  65 +
  66 + function BrowseCriterion() {
  67 + $this->sDisplay = '';
64 68 }
65 69  
  70 +
66 71 function headerDisplay () {
67 72 return $this->sDisplay;
68 73 }
69 74  
70   - // dummy function
  75 +
  76 + // for final display
71 77 function documentDisplay ($oDocument) {
72 78 return $this->sDisplay;
73 79 }
... ... @@ -157,6 +163,10 @@ class BrowseCriterion {
157 163 function getID() {
158 164 return $this->iID;
159 165 }
  166 +
  167 + function getNameSpace() {
  168 + return $this->sNamespace;
  169 + }
160 170  
161 171 function setOptions($aOptions) {
162 172 $this->aOptions = $aOptions;
... ... @@ -171,7 +181,10 @@ class BrowseCriterion {
171 181 // !#@&)*( (*&!@# *(&@NOT (*&!@#
172 182 $k = array_keys($aPreValue);
173 183 $k = $this->getWidgetBase();
174   - $preval = $aPreValue[$k];
  184 +
  185 + if(array_key_exists($k, $aPreValue)) {
  186 + $preval = $aPreValue[$k];
  187 + }
175 188 return $this->getNotWidget($aPreValue) . "<input type=\"text\" size=\"50\" name=\"" . $this->getWidgetBase() . "\" value=\"" . $preval . "\"/>";
176 189 } else {
177 190 return $this->getNotWidget($aPreValue) . "<input type=\"text\" size=\"50\" name=\"" . $this->getWidgetBase() . "\" />";
... ... @@ -188,8 +201,10 @@ class BrowseCriterion {
188 201 if (is_null($aPreValue)) {
189 202 $is_positive = true;
190 203 } else {
191   - $preval = KTUtil::arrayGet($aPreValue, $form_name, "0"); // by default, use "is" not "is not"
192   - $is_positive = ($preval == "0"); // 0 or empty or similar.
  204 + if(array_key_exists($form_name, $aPreValue)) {
  205 + $preval = KTUtil::arrayGet($aPreValue, $form_name, "0"); // by default, use "is" not "is not"
  206 + }
  207 + $is_positive = ($preval == "0"); // 0 or empty or similar.
193 208 }
194 209 if ($is_positive) {
195 210 $pos_select = ' selected="true"';
... ... @@ -208,7 +223,7 @@ class BrowseCriterion {
208 223 }
209 224  
210 225 function getWidgetBase () {
211   - return "bmd" . strtr($this->getID(), '-', '_');
  226 + return strtr($this->getNamespace(), '-', '_');
212 227 }
213 228  
214 229 function getSearchTable() {
... ... @@ -242,12 +257,21 @@ class BrowseCriterion {
242 257 }
243 258 }
244 259  
  260 +
245 261 class NameCriterion extends BrowseCriterion {
246 262 var $bFolderCriterion = true;
247 263 var $bString = true;
248 264 var $sSearchTable = "DC";
249 265 var $bContains = true;
250 266  
  267 + var $sDocumentField = 'filename';
  268 + var $sSortField = 'filename';
  269 + var $sNamespace = 'ktcore.criteria.name';
  270 +
  271 + function NameCriterion() {
  272 + $this->sDisplay = _kt('Name');
  273 + }
  274 +
251 275 function documentDisplay ($oDocument) {
252 276 $aOptions = $this->aOptions;
253 277 if (array_key_exists('displayFullPath', $aOptions)) {
... ... @@ -279,6 +303,13 @@ class NameCriterion extends BrowseCriterion {
279 303  
280 304 class IDCriterion extends BrowseCriterion {
281 305 var $bFolderCriterion = true;
  306 + var $sDocumentField = 'id';
  307 + var $sSortField = 'id';
  308 + var $sNamespace = 'ktcore.criteria.id';
  309 +
  310 + function IDCriterion() {
  311 + $this->sDisplay = _kt('Document ID');
  312 + }
282 313 function documentDisplay ($oDocument) {
283 314 return $oDocument->getID();
284 315 }
... ... @@ -292,6 +323,13 @@ class TitleCriterion extends BrowseCriterion {
292 323 var $bString = true;
293 324 var $sSearchTable = "DM";
294 325 var $bContains = true;
  326 + var $sDocumentField = 'name';
  327 + var $sSortField = 'name';
  328 + var $sNamespace = 'ktcore.criteria.title';
  329 +
  330 + function TitleCriterion() {
  331 + $this->sDisplay = _kt('Title');
  332 + }
295 333  
296 334 function documentDisplay ($oDocument) {
297 335 return $oDocument->getName();
... ... @@ -312,6 +350,13 @@ class CreatorCriterion extends BrowseCriterion {
312 350 "table" => "users",
313 351 "field" => "name",
314 352 );
  353 + var $sDocumentField = 'creator_id';
  354 + var $sSortField = 'creator_id';
  355 + var $sNamespace = 'ktcore.criteria.creator';
  356 +
  357 + function CreatorCriterion() {
  358 + $this->sDisplay = _kt('Creator');
  359 + }
315 360  
316 361 function documentDisplay ($oDocument) {
317 362 $oCreator = User::get($oDocument->getCreatorID());
... ... @@ -346,6 +391,14 @@ class CreatorCriterion extends BrowseCriterion {
346 391  
347 392 class DateCreatedCriterion extends BrowseCriterion {
348 393 var $sSearchTable = "D";
  394 + var $sDocumentField = 'created';
  395 + var $sSortField = 'created';
  396 + var $sNamespace = 'ktcore.criteria.datecreated';
  397 +
  398 + function DateCreatedCriterion() {
  399 + $this->sDisplay = _kt('Date Created');
  400 + }
  401 +
349 402 function documentDisplay ($oDocument) {
350 403 return $oDocument->getCreatedDateTime();
351 404 }
... ... @@ -419,6 +472,13 @@ class DocumentTypeCriterion extends BrowseCriterion {
419 472 "table" => "document_types_lookup",
420 473 "field" => "name"
421 474 );
  475 + var $sDocumentField = 'document_type_id';
  476 + var $sSortField = 'document_type_id';
  477 + var $sNamespace = 'ktcore.criteria.documenttype';
  478 +
  479 + function DocumentTypeCriterion() {
  480 + $this->sDisplay = _kt('Document Type');
  481 + }
422 482  
423 483 function documentDisplay ($oDocument) {
424 484 $oDocumentType = DocumentType::get($oDocument->getDocumentTypeID());
... ... @@ -456,15 +516,25 @@ class GenericMetadataCriterion extends BrowseCriterion {
456 516 "joinColumn" => "document_id",
457 517 );
458 518 var $bString = true;
  519 + var $sDocumentField = null;
  520 + var $sSortField = null;
  521 + var $sNamespace = 'ktcore.criteria.generic';
  522 +
  523 + function initialize($sDisplay, $sDocumentField, $sSortField, $iID, $sNamespace) {
  524 + $this->sDisplay = $sDisplay;
  525 + $this->sDocumentField = $sDocumentField;
  526 + $this->sSortField = $sSortField;
459 527  
460   - function GenericMetadataCriterion ($sDisplay, $sDocumentField, $sSortField, $iID) {
461 528 $this->iID = $iID;
462   - $this->BrowseCriterion($sDisplay, $sDocumentField, $sSortField, $iID);
463 529 $this->aLookup['whereClause'] = 'document_field_id = ' . $iID;
464   - $this->oField =& DocumentField::get($iID);
  530 + $this->oField = DocumentField::get($iID);
  531 + $this->sNamespace = $sNamespace;
465 532 $this->sSearchTable = "DFL" . $iID;
466 533 }
467 534  
  535 + function getID() {
  536 + return $this->iID;
  537 + }
468 538 function documentDisplay ($oDocument) {
469 539 global $default;
470 540 $sQuery = "SELECT DFL.value as value " .
... ... @@ -499,6 +569,7 @@ class GenericMetadataCriterion extends BrowseCriterion {
499 569 $k = $this->getWidgetBase();
500 570 $preval = $aPreValue[$k];
501 571 }
  572 +
502 573 // If there's no lookup, just use the standard text input
503 574 if ($this->oField->getHasLookup() == false) {
504 575 $this->bContains = true; // contains
... ... @@ -542,24 +613,38 @@ class GenericMetadataCriterion extends BrowseCriterion {
542 613 }
543 614  
544 615 class DateModifiedCriterion extends DateCreatedCriterion {
545   - function documentDisplay ($oDocument) {
546   - return $oDocument->getLastModifiedDate();
  616 + var $sDocumentField = 'modified';
  617 + var $sSortField = 'modified';
  618 + var $sNamespace = 'ktcore.criteria.datemodified';
  619 +
  620 + function DateModifiedCriterion() {
  621 + $this->sDisplay = _kt('Date Modified');
547 622 }
  623 +
548 624 function getName() {
549   - return "datemodified";
  625 + return 'datemodified';
  626 + }
  627 +
  628 + function documentDisplay ($oDocument) {
  629 + return $oDocument->getLastModifiedDate();
550 630 }
551 631 }
552 632  
553 633 class SizeCriterion extends BrowseCriterion {
554 634 var $sSearchTable = "DC";
555 635 var $bVisible = false;
  636 + var $sDocumentField = 'size';
  637 + var $sSortField = 'size';
  638 + var $sNamespace = 'ktcore.criteria.size';
  639 +
  640 + function SizeCriterion() {
  641 + $this->sDisplay = _kt('File Size');
  642 + }
556 643  
557 644 function documentDisplay ($oDocument) {
558 645 return $oDocument->getFileSize();
559 646 }
560   - function getName() {
561   - return "size";
562   - }
  647 +
563 648 function searchDisplay($aRequest) {
564 649 return "";
565 650 }
... ... @@ -570,7 +655,13 @@ class ContentCriterion extends BrowseCriterion {
570 655 var $bHandleNot = false;
571 656 var $bString = true;
572 657 var $sSearchTable = "DT";
573   - var $sDocumentField = "document_text";
  658 + var $sDocumentField = 'document_text';
  659 + var $sSortField = 'content';
  660 + var $sNamespace = 'ktcore.criteria.content';
  661 +
  662 + function ContentCriterion() {
  663 + $this->sDisplay = _kt('Document Text');
  664 + }
574 665  
575 666 function documentDisplay ($oDocument) {
576 667 return "Document Text";
... ... @@ -635,6 +726,14 @@ class ContentCriterion extends BrowseCriterion {
635 726  
636 727 class WorkflowStateCriterion extends BrowseCriterion {
637 728 var $sSearchTable = "DM";
  729 + var $sDocumentField = 'state';
  730 + var $sSortField = 'state';
  731 + var $sNamespace = 'ktcore.criteria.workflowstate';
  732 +
  733 + function WorkflowStateCriterion() {
  734 + $this->sDisplay = _kt('Workflow State');
  735 + }
  736 +
638 737 function documentDisplay ($oDocument) {
639 738 $oState =& KTWorkflowState::getByDocument($oDocument);
640 739 if ($oState) {
... ... @@ -689,6 +788,14 @@ class WorkflowStateCriterion extends BrowseCriterion {
689 788 class DiscussionTextCriterion extends BrowseCriterion {
690 789 var $bContains = true;
691 790 var $bHandleNot = false;
  791 + var $sDocumentField = 'discussiontext';
  792 + var $sSortField = 'discussiontext';
  793 + var $sNamespace = 'ktcore.criteria.discussiontext';
  794 +
  795 + function DiscussionTextCriterion() {
  796 + $this->sDisplay = _kt('Discussion Threads');
  797 + }
  798 +
692 799  
693 800 function documentDisplay ($oDocument) {
694 801 return "Discussion Threads";
... ... @@ -750,6 +857,12 @@ class SearchableTextCriterion extends BrowseCriterion {
750 857 var $bString = true;
751 858 var $sSearchTable = "DST";
752 859 var $sDocumentField = "document_text";
  860 + var $sSortField = 'searchable_text';
  861 + var $sNamespace = 'ktcore.criteria.searchabletext';
  862 +
  863 + function SearchableTextCriterion() {
  864 + $this->sDisplay = _kt('Simple Search Text');
  865 + }
753 866  
754 867 function documentDisplay ($oDocument) {
755 868 return "Simple search text";
... ... @@ -817,6 +930,13 @@ class SearchableTextCriterion extends BrowseCriterion {
817 930 class TransactionTextCriterion extends BrowseCriterion {
818 931 var $bContains = true;
819 932 var $bHandleNot = false;
  933 + var $sDocumentField = 'transactiontext';
  934 + var $sSortField = 'transactiontext';
  935 + var $sNamespace = 'ktcore.criteria.transactiontext';
  936 +
  937 + function TransactionTextCriterion() {
  938 + $this->sDisplay = _kt('Transaction Text');
  939 + }
820 940  
821 941 function documentDisplay ($oDocument) {
822 942 return "Transaction text";
... ... @@ -871,121 +991,79 @@ class TransactionTextCriterion extends BrowseCriterion {
871 991 }
872 992 }
873 993  
874   -class Criteria {
  994 +
  995 +
  996 +class DateCreatedDeltaCriterion extends DateCreatedCriterion {
  997 + var $sDocumentField = 'created';
  998 + var $sSortField = 'created';
  999 + var $aTypes = array('MINUTE'=>'Minutes',
  1000 + 'HOUR'=>'Hours',
  1001 + 'DAY'=>'Days',
  1002 + 'MONTH'=>'Months',
  1003 + 'YEAR'=>'Years');
  1004 + var $sNamespace = 'ktcore.criteria.datecreateddelta';
  1005 +
  1006 + function DateCreatedDeltaCriterion() {
  1007 + $this->sDisplay = _kt('Date Created Delta');
  1008 + }
875 1009  
876   - function &_getBaseCriterionByNumber($iID) {
877   - global $default;
878   - switch ($iID) {
879   - case -1:
880   - $oCriterion =& new NameCriterion(_kt("Name"), 'filename', 'filename', -1);
881   - break;
882   - case -2:
883   - $oCriterion =& new TitleCriterion(_kt("Title"), 'name', 'name', -2);
884   - break;
885   - case -3:
886   - $oCriterion =& new CreatorCriterion(_kt("Creator"), 'creator_id', 'creator_id', -3);
887   - break;
888   - case -4:
889   - $oCriterion =& new DateCreatedCriterion(_kt("Date Created"), 'created', 'created', -4);
890   - break;
891   - case -5:
892   - $oCriterion =& new DocumentTypeCriterion(_kt("Document Type"), 'document_type_id', 'document_type_id', -5);
893   - break;
894   - case -6:
895   - $oCriterion =& new IDCriterion(_kt("Document ID"), 'id', 'id', -6);
896   - break;
897   - case -7:
898   - $oCriterion =& new DateModifiedCriterion(_kt("Date Modified"), 'modified', 'modified', -7);
899   - break;
900   - case -8:
901   - $oCriterion =& new SizeCriterion(_kt("File Size"), 'size', 'size', -8);
902   - break;
903   - case -9:
904   - $oCriterion =& new ContentCriterion(_kt("Document Text"), 'content', 'content', -9);
905   - break;
906   - case -10:
907   - $oCriterion =& new WorkflowStateCriterion(_kt("Workflow state"), 'state', 'state', -10);
908   - break;
909   - case -11:
910   - $oCriterion =& new TransactionTextCriterion(_kt("Transaction Text"), 'transactiontext', 'transactiontext', -11);
911   - break;
912   - case -12:
913   - $oCriterion =& new SearchableTextCriterion(_kt("Simple Search Text"), 'searchabletext', 'searchabletext', -12);
914   - break;
915   - case -13:
916   - $oCriterion =& new DiscussionTextCriterion(_kt("Discussion Threads"), 'discussiontext', 'discussiontext', -13);
917   - break;
918   - }
919   - return $oCriterion;
920   - }
921   -
922   - function initCriteria () {
923   - global $aBaseCriteria;
924   - if (isset($aBaseCriteria)) {
925   - return;
926   - }
927   - $aBaseCriteria = array();
928   - $aIDs = range(-1, -13);
929   - foreach ($aIDs as $iID) {
930   - $oCriterion =& Criteria::_getBaseCriterionByNumber($iID);
931   - $aBaseCriteria[$iID] =& $oCriterion;
932   - }
933   - }
934   -
935   - function &getBaseCriteria () {
936   - global $aBaseCriteria;
937   - Criteria::initCriteria();
938   - return $aBaseCriteria;
939   - }
940   -
941   - function &getGenericCriteria () {
942   - global $aGenericCriteria;
943   - global $default;
944   - $aQuery = array("SELECT id FROM $default->document_fields_table", array()); /*ok*/
945   - $aIDs = DBUtil::getResultArrayKey($aQuery, 'id');
946   - foreach ($aIDs as $iID) {
947   - $oCriterion =& Criteria::getCriterionByNumber($iID);
948   - $aGenericCriteria[$iID] =& $oCriterion;
949   - }
950   - return $aGenericCriteria;
  1010 + function searchWidget ($aRequest, $aPreValue = null) {
  1011 + $sNumWidget = $this->getWidgetBase() . '_num';
  1012 + $sTypeWidget = $this->getWidgetBase() . '_type';
  1013 +
  1014 + // build type selection widget
  1015 + $sSelect = '<select name="'.$sTypeWidget.'">';
  1016 + foreach($this->aTypes as $k=>$v) {
  1017 + $sSelect .= '<option value="'.$k.'"';
  1018 + $t = KTUtil::arrayGet($aPreValue, $sTypeWidget, 'DAY');
  1019 + if($k==$t) $sSelect .= ' selected="selected"';
  1020 + $sSelect .= '>'.$v.'</option>';
  1021 + }
  1022 + $sSelect .= '</select>';
  1023 +
  1024 + $sToRender = $this->getNotWidget($aPreValue);
  1025 +
  1026 + $sToRender .= '<input name="'.$sNumWidget.'" value="'.$aPreValue[$sNumWidget].'"/>'.$sSelect.' ago';
  1027 + return $sToRender;
951 1028 }
952 1029  
953   - function &getAllCriteria () {
954   - global $aAllCriteria;
955   - global $aBaseCriteria;
956   - global $default;
957   - Criteria::initCriteria();
958   - if (isset($aAllCriteria)) {
959   - return $aAllCriteria;
960   - }
961   - $aQuery = array("SELECT id FROM $default->document_fields_table", array()); /*ok*/
962   - $aIDs = DBUtil::getResultArrayKey($aQuery, 'id');
963   - $aAllCriteriaIDs = array_merge(array_keys($aBaseCriteria), $aIDs);
964   - foreach ($aAllCriteriaIDs as $iID) {
965   - $oCriterion =& Criteria::getCriterionByNumber($iID);
966   - $aAllCriteria[$iID] =& $oCriterion;
  1030 + function searchSQL ($aRequest) {
  1031 + $sNum = KTUtil::arrayGet($aRequest, $this->getWidgetBase() . '_num');
  1032 + $sType = KTUtil::arrayGet($aRequest, $this->getWidgetBase() . '_type');
  1033 +
  1034 + $val = array($this->getSearchTable() . "." . $this->getSearchField() . " > SUBDATE(NOW(), INTERVAL ? {$sType})", array($sNum));
  1035 +
  1036 + $want_invert = KTUtil::arrayGet($aRequest, $this->getWidgetBase() . '_not');
  1037 + if (is_null($want_invert) || ($want_invert == "0")) {
  1038 + return $val;
  1039 + } else {
  1040 + $val[0] = '(NOT (' . $val[0] . '))';
967 1041 }
968   - return $aAllCriteria;
  1042 + return $val;
969 1043 }
  1044 +}
970 1045  
971   - function &getCriterionByNumber($iID) {
972   - global $aBaseCriteria;
973   - global $default;
974   - Criteria::initCriteria();
975 1046  
976   - // array_key_exists 4.3.2 (at least, tested on RHEL3) returns
977   - // false if '-1' (the string) is the key given, and the real key
978   - // is -1 (the integer).
979   - $iID = (int)$iID;
  1047 +class DateModifiedDeltaCriterion extends DateCreatedDeltaCriterion {
  1048 + var $sDocumentField = 'modified';
  1049 + var $sSortField = 'modified';
  1050 + var $sNamespace = 'ktcore.criteria.datemodifieddelta';
980 1051  
981   - if (array_key_exists($iID, $aBaseCriteria)) {
982   - return $aBaseCriteria[$iID];
983   - } else {
984   - $aQuery = array("SELECT name FROM $default->document_fields_table WHERE id = ?", array($iID)); /*ok*/
985   - $sName = DBUtil::getOneResultKey($aQuery, 'name');
986   - return new GenericMetadataCriterion($sName, 'id', 'id', $iID);
987   - }
  1052 + function DateModifiedDeltaCriterion() {
  1053 + $this->sDisplay = _kt('Date Modified Delta');
  1054 + }
  1055 +
  1056 + function documentDisplay ($oDocument) {
  1057 + return $oDocument->getLastModifiedDate();
  1058 + }
  1059 + function getName() {
  1060 + return "datemodified";
988 1061 }
989 1062 }
990 1063  
  1064 +
  1065 +
  1066 +
  1067 +
  1068 +
991 1069 ?>
... ...
lib/browse/PartialQuery.inc.php
... ... @@ -326,7 +326,7 @@ class SimpleSearchQuery extends PartialQuery {
326 326 function getQuery($aOptions = null) {
327 327 $aSubgroup = array(
328 328 'values' => array(
329   - array('type' => '-12', 'data' => array('bmd_12' => $this->searchable_text)),
  329 + array('type' => 'ktcore.criteria.searchabletext', 'data' => array('ktcore.criteria.searchabletext' => $this->searchable_text)),
330 330 array('sql' => array('D.status_id = 1')),
331 331 ),
332 332 'join' => 'AND',
... ... @@ -388,7 +388,7 @@ class TypeBrowseQuery extends SimpleSearchQuery {
388 388 function getQuery($aOptions = null) {
389 389 $aSubgroup = array(
390 390 'values' => array(
391   - array('type' => '-5', 'data' => array('bmd_5' => $this->iDocType)),
  391 + array('type' => 'ktcore.criteria.documenttype', 'data' => array('ktcore.criteria.documenttype' => $this->iDocType)),
392 392 array('sql' => array('D.status_id = 1')),
393 393 ),
394 394 'join' => 'AND',
... ... @@ -407,18 +407,18 @@ class TypeBrowseQuery extends SimpleSearchQuery {
407 407 }
408 408  
409 409 class ValueBrowseQuery extends SimpleSearchQuery {
410   - var $iFieldId;
  410 + var $sFieldNamespace;
411 411 var $sValueName;
412 412  
413   - function ValueBrowseQuery($oField, $oValue) {
414   - $this->iFieldId = $oField->getId();
  413 + function ValueBrowseQuery($oField, $oValue) {
  414 + $this->sFieldNamespace = $oField->getNamespace();
415 415 $this->sValueName = $oValue->getName();
416 416 }
417 417  
418 418 function getQuery($aOptions = null) {
419 419 $aSubgroup = array(
420 420 'values' => array(
421   - array('type' => $this->iFieldId, 'data' => array('bmd' . $this->iFieldId => $this->sValueName)),
  421 + array('type' => $this->sFieldNamespace, 'data' => array($this->sFieldNamespace => $this->sValueName)),
422 422 array('sql' => array('D.status_id = 1')),
423 423 ),
424 424 'join' => 'AND',
... ...
lib/browse/criteriaregistry.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id: criteriaregistry.php 5492 2006-06-04 20:50:43Z bryndivey $
  5 + *
  6 + * Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com
  7 + *
  8 + * This program is free software; you can redistribute it and/or modify
  9 + * it under the terms of the GNU General Public License as published by
  10 + * the Free Software Foundation; using version 2 of the License.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20 + *
  21 + * -------------------------------------------------------------------------
  22 + *
  23 + * You can contact the copyright owner regarding licensing via the contact
  24 + * details that can be found on the KnowledgeTree web site:
  25 + *
  26 + * http://www.ktdms.com/
  27 + */
  28 +
  29 +class KTCriteriaRegistry {
  30 + var $_aCriteria = array();
  31 + var $_aCriteriaDetails = array();
  32 + var $_bGenericRegistered = false;
  33 +
  34 + function &getSingleton() {
  35 + if (!KTUtil::arrayGet($GLOBALS['_KT_CRITERIA'], 'oKTCriteriaRegistry')) {
  36 + $GLOBALS['_KT_CRITERIA']['oKTCriteriaRegistry'] = new KTCriteriaRegistry;
  37 + // $GLOBALS['_KT_CRITERIA']['oKTCriteriaRegistry']->_buildGenericCriteria();
  38 + }
  39 + return $GLOBALS['_KT_CRITERIA']['oKTCriteriaRegistry'];
  40 + }
  41 +
  42 + function _buildGenericCriteria() {
  43 + $aFields =& DocumentField::getList();
  44 + foreach($aFields as $oField) {
  45 + $sNamespace = $oField->getNamespace();
  46 + $aInitialize = array($oField->getName(), 'id', 'id', $oField->getId(), $sNamespace);
  47 + $this->registerCriterion('GenericMetadataCriterion', $sNamespace, null, $aInitialize);
  48 + }
  49 + $this->_bGenericRegistered = true;
  50 + }
  51 +
  52 + function registerCriterion($sClassName, $sNamespace = null, $sFilename = null, $aInitialize = null) {
  53 + $this->_aCriteriaDetails[$sNamespace] = array($sClassName, $sNamespace, $sFilename, $aInitialize);
  54 + }
  55 +
  56 + function &getCriterion($sNamespace) {
  57 + if(!$this->_bGenericRegistered) {
  58 + $this->_buildGenericCriteria();
  59 + }
  60 +
  61 + if (array_key_exists($sNamespace, $this->_aCriteria)) {
  62 + return $this->_aCriteria[$sNamespace];
  63 + }
  64 +
  65 + $aDetails = KTUtil::arrayGet($this->_aCriteriaDetails, $sNamespace);
  66 + if (empty($aDetails)) {
  67 + return null;
  68 + }
  69 + $sFilename = $aDetails[2];
  70 + if (!empty($sFilename)) {
  71 + require_once($sFilename);
  72 + }
  73 + $sClassName = $aDetails[0];
  74 + $oCriterion =& new $sClassName();
  75 +
  76 +
  77 + if(is_array($aDetails[3])) {
  78 + call_user_func_array(array(&$oCriterion, 'initialize'), $aDetails[3]);
  79 + }
  80 +
  81 +
  82 + $this->_aCriteria[$sNamespace] =& $oCriterion;
  83 + return $oCriterion;
  84 + }
  85 +
  86 + function &getCriteria() {
  87 + if(!$this->_bGenericRegistered) {
  88 + $this->_buildGenericCriteria();
  89 + }
  90 + $aRet = array();
  91 +
  92 + foreach (array_keys($this->_aCriteriaDetails) as $sCriteriaName) {
  93 + $aRet[$sCriteriaName] =& $this->getCriterion($sCriteriaName);
  94 + }
  95 + return $aRet;
  96 + }
  97 +
  98 +}
  99 +
... ...
lib/documentmanagement/DocumentField.inc
... ... @@ -35,21 +35,21 @@ require_once(KT_LIB_DIR . &#39;/documentmanagement/DocumentType.inc&#39;);
35 35  
36 36 class DocumentField extends KTEntity {
37 37  
38   - /** primary key value */
39   - var $iId = -1;
40   - var $sName;
41   - var $sDataType;
42   - var $sDescription;
43   - var $bIsGeneric;
44   - var $bHasLookup;
  38 + /** primary key value */
  39 + var $iId = -1;
  40 + var $sName;
  41 + var $sDataType;
  42 + var $sDescription;
  43 + var $bIsGeneric;
  44 + var $bHasLookup;
45 45 var $iParentFieldset;
46   - var $bHasLookupTree;
47   - var $bIsMandatory;
  46 + var $bHasLookupTree;
  47 + var $bIsMandatory;
48 48  
49 49 var $_aFieldToSelect = array(
50 50 'iId' => 'id',
51 51 'sName' => 'name',
52   - 'sDescription' => 'description',
  52 + 'sDescription' => 'description',
53 53 'sDataType' => 'data_type',
54 54 'bIsGeneric' => 'is_generic',
55 55 'bHasLookup' => 'has_lookup',
... ... @@ -93,7 +93,7 @@ class DocumentField extends KTEntity {
93 93 function _fieldValues () {
94 94 return array(
95 95 'name' => $this->sName,
96   - 'description' => $this->sDescription,
  96 + 'description' => $this->sDescription,
97 97 'data_type' => $this->sDataType,
98 98 'is_generic' => KTUtil::anyToBool($this->bIsGeneric),
99 99 'has_lookup' => KTUtil::anyToBool($this->bHasLookup),
... ... @@ -108,9 +108,9 @@ class DocumentField extends KTEntity {
108 108 return $default->document_fields_table;
109 109 }
110 110  
111   - function &getList($sWhereClause = null) {
112   - return KTEntityUtil::getList2('DocumentField', $sWhereClause);
113   - }
  111 + function &getList($sWhereClause = null) {
  112 + return KTEntityUtil::getList2('DocumentField', $sWhereClause);
  113 + }
114 114  
115 115 function &createFromArray($aOptions) {
116 116 return KTEntityUtil::createFromArray('DocumentField', $aOptions);
... ... @@ -206,6 +206,16 @@ class DocumentField extends KTEntity {
206 206  
207 207 return implode(', ', $aDescriptors);
208 208 }
  209 +
  210 + function getNamespace() {
  211 + $oFieldset = KTFieldset::get($this->getParentFieldsetId());
  212 + if(PEAR::isError($oFieldset)) {
  213 + $sFS = 'nofieldset';
  214 + } else {
  215 + $sFS = $oFieldset->getNamespace();
  216 + }
  217 + return $sFS . '.' . $this->getName();
  218 + }
209 219 }
210 220  
211 221 /**
... ...
lib/plugins/plugin.inc.php
... ... @@ -54,6 +54,7 @@ class KTPlugin {
54 54 var $_aViews = array();
55 55 var $_aNotificationHandlers = array();
56 56 var $_aTemplateLocations = array();
  57 + var $_aCriteria = array();
57 58  
58 59 function KTPlugin($sFilename = null) {
59 60 $this->sFilename = $sFilename;
... ... @@ -162,6 +163,11 @@ class KTPlugin {
162 163 $this->_aTemplateLocations[$sName] = array($sName, $sPath);
163 164 }
164 165  
  166 + function registerCriterion($sClassName, $sNamespace, $sFilename = null, $aInitialize = null) {
  167 + $this->_fixFilename($sFilename);
  168 + $this->_aCriteria[$sNamespace] = array($sClassName, $sNamespace, $sFilename, $aInitialize);
  169 + }
  170 +
165 171 function _fixFilename($sFilename) {
166 172 if (empty($sFilename)) {
167 173 $sFilename = $this->sFilename;
... ... @@ -220,6 +226,7 @@ class KTPlugin {
220 226 require_once(KT_LIB_DIR . "/help/help.inc.php");
221 227 require_once(KT_LIB_DIR . "/workflow/workflowutil.inc.php");
222 228 require_once(KT_LIB_DIR . "/browse/columnregistry.inc.php");
  229 + require_once(KT_LIB_DIR . "/browse/criteriaregistry.php");
223 230  
224 231 $oPRegistry =& KTPortletRegistry::getSingleton();
225 232 $oTRegistry =& KTTriggerRegistry::getSingleton();
... ... @@ -234,6 +241,7 @@ class KTPlugin {
234 241 $oColumnRegistry =& KTColumnRegistry::getSingleton();
235 242 $oNotificationHandlerRegistry =& KTNotificationRegistry::getSingleton();
236 243 $oTemplating =& KTTemplating::getSingleton();
  244 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
237 245  
238 246 foreach ($this->_aPortlets as $k => $v) {
239 247 call_user_func_array(array(&$oPRegistry, 'registerPortlet'), $v);
... ... @@ -302,6 +310,10 @@ class KTPlugin {
302 310 foreach ($this->_aTemplateLocations as $k => $v) {
303 311 call_user_func_array(array(&$oTemplating, 'addLocation'), $v);
304 312 }
  313 +
  314 + foreach ($this->_aCriteria as $k => $v) {
  315 + call_user_func_array(array(&$oCriteriaRegistry, 'registerCriterion'), $v);
  316 + }
305 317 }
306 318  
307 319 function setup() {
... ...
lib/search/searchutil.inc.php
... ... @@ -51,7 +51,8 @@ class KTSearchUtil {
51 51 $type = KTUtil::arrayGet($dataset, "type");
52 52 $sql = KTUtil::arrayGet($dataset, "sql");
53 53 if (!empty($type)) {
54   - $oCriterion = Criteria::getCriterionByNumber($dataset["type"]);
  54 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  55 + $oCriterion = $oCriteriaRegistry->getCriterion($dataset['type']);
55 56 if (PEAR::isError($oCriterion)) {
56 57 return PEAR::raiseError('Invalid criteria specified.');
57 58 }
... ...
lib/upgrades/UpgradeFunctions.inc.php
... ... @@ -39,6 +39,7 @@ class UpgradeFunctions {
39 39 "3.0.3.2" => array("createFolderDetailsPermission"),
40 40 "3.0.3.3" => array("generateWorkflowTriggers"),
41 41 "3.0.3.7" => array("rebuildAllPermissions"),
  42 + "3.1.5" => array("upgradeSavedSearches"),
42 43 );
43 44  
44 45 var $descriptions = array(
... ... @@ -56,6 +57,7 @@ class UpgradeFunctions {
56 57 'createFolderDetailsPermission' => 'Create the Core: Folder Details permission',
57 58 'generateWorkflowTriggers' => 'Migrate old in-transition guards to triggers',
58 59 'rebuildAllPermissions' => 'Rebuild all permissions to ensure correct functioning of permission-definitions.'
  60 + 'upgradeSavedSearches' => 'Upgrade saved searches to use namespaces instead of integer ids',
59 61 );
60 62 var $phases = array(
61 63 "setPermissionFolder" => 1,
... ... @@ -765,6 +767,57 @@ class UpgradeFunctions {
765 767 KTPermissionUtil::updatePermissionLookupRecursive($oRootFolder);
766 768 }
767 769  
  770 +
  771 + function _upgradeSavedSearch($aSearch) {
  772 + $aMapping = array('-1' => 'ktcore.criteria.name',
  773 + '-6' => 'ktcore.criteria.id',
  774 + '-2' => 'ktcore.criteria.title',
  775 + '-3' => 'ktcore.criteria.creator',
  776 + '-4' => 'ktcore.criteria.datecreated',
  777 + '-5' => 'ktcore.criteria.documenttype',
  778 + '-7' => 'ktcore.criteria.datemodified',
  779 + '-8' => 'ktcore.criteria.size',
  780 + '-9' => 'ktcore.criteria.content',
  781 + '-10' => 'ktcore.criteria.workflowstate',
  782 + '-13' => 'ktcore.criteria.discussiontext',
  783 + '-12' => 'ktcore.criteria.searchabletext',
  784 + '-11' => 'ktcore.criteria.transactiontext');
  785 +
  786 + $aFieldsets =& KTFieldset::getList();
  787 + foreach($aFieldsets as $oFieldset) {
  788 + $aFields =& DocumentField::getByFieldset($oFieldset);
  789 + foreach($aFields as $oField) {
  790 + $sNamespace = $oFieldset->getNamespace() . '.' . $oField->getName();
  791 + $sId = (string) $oField->getId();
  792 + $aMapping[$sId] = $sNamespace;
  793 + }
  794 + }
  795 +
  796 + foreach(array_keys($aSearch['subgroup']) as $sgkey) {
  797 + $sg =& $aSearch['subgroup'][$sgkey];
  798 + foreach(array_keys($sg['values']) as $vkey) {
  799 + $item =& $sg['values'][$vkey];
  800 + $type = $item['type'];
  801 + $toreplace = 'bmd' . ((int)$type < 0 ? '_' : '') . abs((int)$type);
  802 + $item['type'] = $aMapping[$type];
  803 + $nData = array();
  804 + foreach($item['data'] as $k=>$v) {
  805 + $k = str_replace($toreplace, $aMapping[$type], $k);
  806 + $nData[$k] = $v;
  807 + }
  808 + $item['data'] = $nData;
  809 + }
  810 + }
  811 + return $aSearch;
  812 + }
  813 +
  814 + function upgradeSavedSearches() {
  815 + foreach(KTSavedSearch::getSearches() as $oS) {
  816 + $aSearch = $this->_upgradeSavedSearch($oS->getSearch());
  817 + $oS->setSearch($aSearch);
  818 + $oS->update();
  819 + }
  820 + }
768 821 }
769 822  
770 823 ?>
... ...
plugins/ktcore/KTCorePlugin.php
... ... @@ -27,7 +27,6 @@
27 27 require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
28 28 require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
29 29  
30   -
31 30 class KTCorePlugin extends KTPlugin {
32 31 var $bAlwaysInclude = true;
33 32 var $sNamespace = "ktcore.plugin";
... ... @@ -119,7 +118,23 @@ class KTCorePlugin extends KTPlugin {
119 118 $this->registerWorkflowTrigger('ktcore.workflowtriggers.conditionguard', 'ConditionGuardTrigger', 'KTWorkflowTriggers.inc.php');
120 119  
121 120 $this->registerWorkflowTrigger('ktcore.workflowtriggers.copyaction', 'CopyActionTrigger', 'KTWorkflowTriggers.inc.php');
122   -
  121 +
  122 + // criterion
  123 + $this->registerCriterion('NameCriterion', 'ktcore.criteria.name', KT_LIB_DIR . '/browse/Criteria.inc');
  124 + $this->registerCriterion('IDCriterion', 'ktcore.criteria.id', KT_LIB_DIR . '/browse/Criteria.inc');
  125 + $this->registerCriterion('TitleCriterion', 'ktcore.criteria.title', KT_LIB_DIR . '/browse/Criteria.inc');
  126 + $this->registerCriterion('CreatorCriterion', 'ktcore.criteria.creator', KT_LIB_DIR . '/browse/Criteria.inc');
  127 + $this->registerCriterion('DateCreatedCriterion', 'ktcore.criteria.datecreated', KT_LIB_DIR . '/browse/Criteria.inc');
  128 + $this->registerCriterion('DocumentTypeCriterion', 'ktcore.criteria.documenttype', KT_LIB_DIR . '/browse/Criteria.inc');
  129 + $this->registerCriterion('DateModifiedCriterion', 'ktcore.criteria.datemodified', KT_LIB_DIR . '/browse/Criteria.inc');
  130 + $this->registerCriterion('SizeCriterion', 'ktcore.criteria.size', KT_LIB_DIR . '/browse/Criteria.inc');
  131 + $this->registerCriterion('ContentCriterion', 'ktcore.criteria.content', KT_LIB_DIR . '/browse/Criteria.inc');
  132 + $this->registerCriterion('WorkflowStateCriterion', 'ktcore.criteria.workflowstate', KT_LIB_DIR . '/browse/Criteria.inc');
  133 + $this->registerCriterion('DiscussionTextCriterion', 'ktcore.criteria.discussiontext', KT_LIB_DIR . '/browse/Criteria.inc');
  134 + $this->registerCriterion('SearchableTextCriterion', 'ktcore.criteria.searchabletext', KT_LIB_DIR . '/browse/Criteria.inc');
  135 + $this->registerCriterion('TransactionTextCriterion', 'ktcore.criteria.transactiontext', KT_LIB_DIR . '/browse/Criteria.inc');
  136 + $this->registerCriterion('DateCreatedDeltaCriterion', 'ktcore.criteria.datecreateddelta', KT_LIB_DIR . '/browse/Criteria.inc');
  137 + $this->registerCriterion('DateModifiedDeltaCriterion', 'ktcore.criteria.datemodifieddelta', KT_LIB_DIR . '/browse/Criteria.inc');
123 138  
124 139 $this->setupAdmin();
125 140 }
... ...
plugins/ktcore/admin/conditions.php
... ... @@ -78,7 +78,8 @@ class KTConditionDispatcher extends KTAdminDispatcher {
78 78 $oTemplating =& KTTemplating::getSingleton();
79 79 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search");
80 80  
81   - $aCriteria = Criteria::getAllCriteria();
  81 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  82 + $aCriteria =& $oCriteriaRegistry->getCriteria();
82 83  
83 84 $aTemplateData = array(
84 85 "title" => _kt("Create a new condition"),
... ... @@ -108,7 +109,8 @@ class KTConditionDispatcher extends KTAdminDispatcher {
108 109 $oTemplating =& KTTemplating::getSingleton();
109 110 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_edit");
110 111  
111   - $aCriteria = Criteria::getAllCriteria();
  112 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  113 + $aCriteria =& $oCriteriaRegistry->getCriteria();
112 114  
113 115 // we need to help out here, since it gets unpleasant inside the template.
114 116 foreach ($aSearch['subgroup'] as $isg => $as) {
... ... @@ -117,8 +119,9 @@ class KTConditionDispatcher extends KTAdminDispatcher {
117 119 if(count($aSubgroup['values'])) {
118 120 foreach ($aSubgroup['values'] as $iv => $t) {
119 121 $datavars =& $aSubgroup['values'][$iv];
120   - $datavars['typename'] = $aCriteria[$datavars['type']]->sDisplay;
121   - $datavars['widgetval'] = $aCriteria[$datavars['type']]->searchWidget(null, $datavars['data']);
  122 + $oCriterion = $oCriteriaRegistry->getCriterion($datavars['type']);
  123 + $datavars['typename'] = $oCriterion->sDisplay;
  124 + $datavars['widgetval'] = $oCriterion->searchWidget(null, $datavars['data']);
122 125 }
123 126 }
124 127 }
... ...
plugins/ktcore/admin/savedSearch.php
... ... @@ -55,7 +55,8 @@ class KTSavedSearchDispatcher extends KTAdminDispatcher {
55 55 $oTemplating =& KTTemplating::getSingleton();
56 56 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search");
57 57  
58   - $aCriteria = Criteria::getAllCriteria();
  58 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  59 + $aCriteria =& $oCriteriaRegistry->getCriteria();
59 60  
60 61 $aTemplateData = array(
61 62 "title" => _kt("Create a new saved search"),
... ... @@ -105,7 +106,8 @@ class KTSavedSearchDispatcher extends KTAdminDispatcher {
105 106 $oTemplating =& KTTemplating::getSingleton();
106 107 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_edit");
107 108  
108   - $aCriteria = Criteria::getAllCriteria();
  109 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  110 + $aCriteria =& $oCriteriaRegistry->getCriteria();
109 111  
110 112 // we need to help out here, since it gets unpleasant inside the template.
111 113  
... ... @@ -114,8 +116,9 @@ class KTSavedSearchDispatcher extends KTAdminDispatcher {
114 116 if (is_array($aSubgroup['values'])) {
115 117 foreach ($aSubgroup['values'] as $iv => $t) {
116 118 $datavars =& $aSubgroup['values'][$iv];
117   - $datavars['typename'] = $aCriteria[$datavars['type']]->sDisplay;
118   - $datavars['widgetval'] = $aCriteria[$datavars['type']]->searchWidget(null, $datavars['data']);
  119 + $oCriterion = $oCriteriaRegistry->getCriterion($datavars['type']);
  120 + $datavars['typename'] = $oCriterion->sDisplay;
  121 + $datavars['widgetval'] = $oCriterion->searchWidget(null, $datavars['data']);
119 122 }
120 123 }
121 124 }
... ... @@ -124,7 +127,7 @@ class KTSavedSearchDispatcher extends KTAdminDispatcher {
124 127 //$s .= print_r($aSearch, true);
125 128 //$s .= '</pre>';
126 129 //print $s;
127   -
  130 +
128 131 $aTemplateData = array(
129 132 "title" => _kt("Edit an existing condition"),
130 133 "aCriteria" => $aCriteria,
... ...
resources/js/constructed_search.js
... ... @@ -95,6 +95,7 @@ function addNewCriteria(add_button) {
95 95 var dest_cell = notify_message.parentNode;
96 96 var baseUrl = getElement('kt-core-baseurl').value;
97 97 var targeturl = baseUrl + '/search/ajaxBooleanSearch.php?action=getNewCriteria&type='+select.value+'&critId='+critId;
  98 +
98 99 simpleLog('DEBUG','addNewCriteria initiating request to: '+targeturl);
99 100  
100 101 var deferred = doSimpleXMLHttpRequest(targeturl);
... ...
search/ajaxBooleanSearch.php
... ... @@ -31,6 +31,7 @@ require_once(KT_LIB_DIR . &quot;/database/dbutil.inc&quot;);
31 31 require_once(KT_LIB_DIR . "/util/ktutil.inc");
32 32 require_once(KT_LIB_DIR . "/dispatcher.inc.php");
33 33 require_once(KT_LIB_DIR . "/browse/Criteria.inc");
  34 +require_once(KT_LIB_DIR . "/browse/criteriaregistry.php");
34 35  
35 36 /*
36 37 * example code - tests the frontend behaviour. remember to check ajaxConditional.php
... ... @@ -49,7 +50,9 @@ class AjaxBooleanSearchDispatcher extends KTDispatcher {
49 50 if (empty($criteriaType)) {
50 51 return 'AJAX Error: no criteria type specified.';
51 52 }
52   - $critObj = Criteria::getCriterionByNumber($criteriaType);
  53 +
  54 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  55 + $critObj = $oCriteriaRegistry->getCriterion($criteriaType);
53 56 if (PEAR::isError($critObj)) {
54 57 return 'AJAX Error: failed to initialise critiria of type "'.$type.'".';
55 58 }
... ...
search/booleanSearch.php
... ... @@ -56,7 +56,8 @@ class BooleanSearchDispatcher extends KTStandardDispatcher {
56 56 $oTemplating =& KTTemplating::getSingleton();
57 57 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search");
58 58  
59   - $aCriteria = Criteria::getAllCriteria();
  59 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  60 + $aCriteria = $oCriteriaRegistry->getCriteria();
60 61  
61 62 $aTemplateData = array(
62 63 "context" => &$this,
... ... @@ -193,8 +194,9 @@ class BooleanSearchDispatcher extends KTStandardDispatcher {
193 194  
194 195 $oTemplating =& KTTemplating::getSingleton();
195 196 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_change");
196   -
197   - $aCriteria = Criteria::getAllCriteria();
  197 +
  198 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  199 + $aCriteria = $oCriteriaRegistry->getCriteria();
198 200  
199 201 // we need to help out here, since it gets unpleasant inside the template.
200 202  
... ... @@ -203,8 +205,10 @@ class BooleanSearchDispatcher extends KTStandardDispatcher {
203 205 if (is_array($aSubgroup['values'])) {
204 206 foreach ($aSubgroup['values'] as $iv => $t) {
205 207 $datavars =& $aSubgroup['values'][$iv];
206   - $datavars['typename'] = $aCriteria[$datavars['type']]->sDisplay;
207   - $datavars['widgetval'] = $aCriteria[$datavars['type']]->searchWidget(null, $datavars['data']);
  208 +
  209 + $oCriterion = $oCriteriaRegistry->getCriterion($datavars['type']);
  210 + $datavars['typename'] = $oCriterion->sDisplay;
  211 + $datavars['widgetval'] = $oCriterion->searchWidget(null, $datavars['data']);
208 212 }
209 213 }
210 214 }
... ... @@ -224,7 +228,6 @@ class BooleanSearchDispatcher extends KTStandardDispatcher {
224 228  
225 229  
226 230 function handleCriteriaSet($aCriteriaSet, $iStartIndex, $sTitle=null) {
227   -
228 231 if ($sTitle == null) {
229 232 $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Advanced Search'));
230 233 $sTitle = _kt('Search Results');
... ... @@ -260,7 +263,6 @@ class BooleanSearchDispatcher extends KTStandardDispatcher {
260 263 $collection->setOptions($aOptions);
261 264 $collection->setQueryObject(new BooleanSearchQuery($aCriteriaSet));
262 265  
263   -
264 266 //$a = new BooleanSearchQuery($aCriteriaSet);
265 267 //var_dump($a->getDocumentCount()); exit(0);
266 268  
... ...
templates/ktcore/boolean_search.smarty
1   -{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/Base.js")}
2   -{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/DateTime.js")}
3   -{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/Iter.js")}
4   -{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/DOM.js")}
5   -{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/Async.js")}
6 1 {$context->oPage->requireJSResource("resources/js/taillog.js")}
7 2 {$context->oPage->requireJSResource("resources/js/constructed_search.js")}
8 3  
... ... @@ -45,7 +40,7 @@ legend { border: 1px dotted #999;}
45 40 <div style="display: none" id="search-criteria-container">
46 41 <select name="querytype">
47 42 {foreach item=oCriteria from=$aCriteria} {if ($oCriteria->bVisible == true)}
48   - <option value="{$oCriteria->getID()}">{$oCriteria->headerDisplay()}</option>
  43 + <option value="{$oCriteria->getNamespace()}">{$oCriteria->headerDisplay()}</option>
49 44 {/if}
50 45 {/foreach}
51 46 </select>
... ... @@ -86,7 +81,7 @@ legend { border: 1px dotted #999;}
86 81 <tr>
87 82 <td><select name="querytype">
88 83 {foreach item=oCriteria from=$aCriteria} {if ($oCriteria->bVisible == true)}
89   - <option value="{$oCriteria->getID()}">{$oCriteria->headerDisplay()}</option>
  84 + <option value="{$oCriteria->getNamespace()}">{$oCriteria->headerDisplay()}</option>
90 85 {/if}
91 86 {/foreach}
92 87 </select>
... ...
templates/ktcore/boolean_search_change.smarty
... ... @@ -47,7 +47,7 @@ legend { border: 1px dotted #999;}
47 47 <div style="display: none" id="search-criteria-container">
48 48 <select name="querytype">
49 49 {foreach item=oCriteria from=$aCriteria} {if ($oCriteria->bVisible == true)}
50   - <option value="{$oCriteria->getID()}">{$oCriteria->headerDisplay()}</option>
  50 + <option value="{$oCriteria->getNamespace()}">{$oCriteria->headerDisplay()}</option>
51 51 {/if}
52 52 {/foreach}
53 53 </select>
... ... @@ -106,7 +106,7 @@ legend { border: 1px dotted #999;}
106 106 <tr>
107 107 <td><select name="querytype">
108 108 {foreach item=oCriteria from=$aCriteria} {if ($oCriteria->bVisible == true)}
109   - <option value="{$oCriteria->getID()}">{$oCriteria->headerDisplay()}</option>
  109 + <option value="{$oCriteria->getNamespace()}">{$oCriteria->headerDisplay()}</option>
110 110 {/if}
111 111 {/foreach}
112 112 </select>
... ...
templates/ktcore/boolean_search_edit.smarty
... ... @@ -47,7 +47,7 @@ legend { border: 1px dotted #999;}
47 47 <div style="display: none" id="search-criteria-container">
48 48 <select name="querytype">
49 49 {foreach item=oCriteria from=$aCriteria} {if ($oCriteria->bVisible == true)}
50   - <option value="{$oCriteria->getID()}">{$oCriteria->headerDisplay()}</option>
  50 + <option value="{$oCriteria->getNamespace()}">{$oCriteria->headerDisplay()}</option>
51 51 {/if}
52 52 {/foreach}
53 53 </select>
... ... @@ -110,7 +110,7 @@ legend { border: 1px dotted #999;}
110 110 <tr>
111 111 <td><select name="querytype">
112 112 {foreach item=oCriteria from=$aCriteria} {if ($oCriteria->bVisible == true)}
113   - <option value="{$oCriteria->getID()}">{$oCriteria->headerDisplay()}</option>
  113 + <option value="{$oCriteria->getNamespace()}">{$oCriteria->headerDisplay()}</option>
114 114 {/if}
115 115 {/foreach}
116 116 </select>
... ...