Commit f58e00a84eac8a0b675979cb4f44a943c8cf2a7e

Authored by Brad Shuttleworth
1 parent d56c5ac8

- add very simple document_type browsing into the system

- considering adding all lookup fields, though that might get a little too "busy".
- does not incorporate the category version yet, since it will need to have an upgrade from
  freetext to lookup.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4417 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/browse/PartialQuery.inc.php
... ... @@ -253,6 +253,30 @@ class SimpleSearchQuery extends PartialQuery {
253 253 }
254 254 }
255 255  
  256 +class TypeBrowseQuery extends SimpleSearchQuery {
  257 + var $iDocType;
  258 +
  259 + function TypeBrowseQuery($oDocType) {
  260 + $this->iDocType = $oDocType->getId();
  261 + }
  262 +
  263 + function getQuery($aOptions = null) {
  264 + $aSubgroup = array(
  265 + 'values' => array(
  266 + array('type' => '-5', 'data' => array('bmd_5' => $this->iDocType)),
  267 + array('sql' => array('D.status_id = 1')),
  268 + ),
  269 + 'join' => 'AND',
  270 + );
  271 + $aCriteriaSet = array(
  272 + 'subgroup' => array($aSubgroup),
  273 + 'join' => 'AND',
  274 + );
  275 + $oUser = User::get($_SESSION['userID']);
  276 + return KTSearchUtil::criteriaToQuery($aCriteriaSet, $oUser, 'ktcore.permissions.read', $aOptions);
  277 + }
  278 +}
  279 +
256 280 class BooleanSearchQuery extends PartialQuery {
257 281 // FIXME cache permission lookups, etc.
258 282 var $datavars;
... ...
plugins/ktcore/KTPortlets.php
... ... @@ -23,3 +23,37 @@ class KTSearchPortlet extends KTPortlet {
23 23  
24 24 $oPRegistry->registerPortlet(array('browse', 'dashboard'), 'KTSearchPortlet', 'ktcore.portlets.search', '/plugins/ktcore/KTPortlets.php');
25 25  
  26 +
  27 +class KTBrowseModePortlet extends KTPortlet {
  28 +
  29 + function KTBrowseModePortlet($sTitle = null) {
  30 + // match empty, false.
  31 + if ($sTitle == null) {
  32 + $sTitle = _('Browse Documents By');
  33 + }
  34 + parent::KTPortlet($sTitle);
  35 + }
  36 +
  37 + function render() {
  38 + // this is unfortunate, but such is life.
  39 + $current_action = KTUtil::arrayGet($_REQUEST, 'fBrowseMode', 'folder');
  40 + $modes = array(
  41 + 'folder' => array('name' => _('Folder')),
  42 +
  43 + 'document_type' => array('name' => _('Document Type'), 'target' => 'selectType'),
  44 + );
  45 +
  46 + $oTemplating = new KTTemplating;
  47 + $oTemplate = $oTemplating->loadTemplate("kt3/portlets/browsemodes_portlet");
  48 + $aTemplateData = array(
  49 + "context" => $this,
  50 + "current_action" => $current_action,
  51 + "modes" => $modes,
  52 + );
  53 +
  54 + return $oTemplate->render($aTemplateData);
  55 + }
  56 +}
  57 +$oPRegistry->registerPortlet(array('browse'), 'KTBrowseModePortlet', 'ktcore.portlets.browsemodes', '/plugins/ktcore/KTPortlets.php');
  58 +
  59 +
... ...
presentation/lookAndFeel/knowledgeTree/browse.php
... ... @@ -35,6 +35,7 @@ require_once(KT_LIB_DIR . "/browse/PartialQuery.inc.php");
35 35 require_once(KT_LIB_DIR . "/browse/browseutil.inc.php");
36 36  
37 37 require_once(KT_LIB_DIR . "/foldermanagement/Folder.inc");
  38 +require_once(KT_LIB_DIR . "/documentmanagement/DocumentType.inc");
38 39  
39 40 require_once(KT_LIB_DIR . "/widgets/portlet.inc.php");
40 41 require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
... ... @@ -46,8 +47,10 @@ $sectionName = "browse";
46 47 class BrowseDispatcher extends KTStandardDispatcher {
47 48  
48 49  
49   - var $sSection = "browse";
50   - var $browseType;
  50 + var $sSection = "browse";
  51 + var $browse_mode = null;
  52 + var $query = null;
  53 + var $resultURL;
51 54  
52 55 function BrowseDispatcher() {
53 56 $this->aBreadcrumbs = array(
... ... @@ -55,81 +58,148 @@ class BrowseDispatcher extends KTStandardDispatcher {
55 58 );
56 59 return parent::KTStandardDispatcher();
57 60 }
58   -
  61 +
59 62 function check() {
60   - // which folder.
61   - $in_folder_id = KTUtil::arrayGet($_REQUEST, "fFolderId", 1);
62   - $folder_id = (int) $in_folder_id; // conveniently, will be 0 if not possible.
63   - if ($folder_id == 0) {
64   - $folder_id = 1;
65   - }
  63 + $this->browse_mode = KTUtil::arrayGet($_REQUEST, 'fBrowseMode', "folder");
  64 + $action = KTUtil::arrayGet($_REQUEST, $this->event_var, 'main');
  65 +
  66 + // catch the alternative actions.
  67 + if ($action != 'main') {
  68 + return true;
  69 + }
  70 +
  71 + // if we're going to main ...
  72 + if ($this->browse_mode == 'folder') {
  73 + // which folder.
  74 + $in_folder_id = KTUtil::arrayGet($_REQUEST, "fFolderId", 1);
  75 + $folder_id = (int) $in_folder_id; // conveniently, will be 0 if not possible.
  76 + if ($folder_id == 0) {
  77 + $folder_id = 1;
  78 + }
66 79  
67   - // here we need the folder object to do the breadcrumbs.
68   - $this->oFolder =& Folder::get($folder_id);
69   - if (PEAR::isError($this->oFolder)) {
70   - $this->oPage->addError(_("invalid folder"));
71   - $folder_id = 1;
72   - $this->oFolder =& Folder::get($folder_id);
  80 + // here we need the folder object to do the breadcrumbs.
  81 + $oFolder =& Folder::get($folder_id);
  82 + if (PEAR::isError($oFolder)) {
  83 + $this->oPage->addError(_("invalid folder"));
  84 + $folder_id = 1;
  85 + $oFolder =& Folder::get($folder_id);
  86 + }
  87 +
  88 + // we now have a folder, and need to create the query.
  89 + $this->oQuery = new BrowseQuery($oFolder->getId());
  90 +
  91 + $this->aBreadcrumbs = array_merge($this->aBreadcrumbs,
  92 + KTBrowseUtil::breadcrumbsForFolder($oFolder));
  93 +
  94 + $portlet = new KTActionPortlet(_("Folder Actions"));
  95 + $aActions = KTFolderActionUtil::getFolderActionsForFolder($oFolder, $this->oUser);
  96 + $portlet->setActions($aActions,null);
  97 + $this->oPage->addPortlet($portlet);
  98 + $this->resultURL = "?fFolderId=" . $oFolder->getId();
  99 +
  100 + } else if ($this->browse_mode == 'category') {
  101 + return false;
  102 + } else if ($this->browse_mode == 'document_type') {
  103 + // FIXME implement document_type browsing.
  104 + $doctype = KTUtil::arrayGet($_REQUEST, 'fType',null);
  105 + $oDocType = DocumentType::get($doctype);
  106 + if (PEAR::isError($oDocType) || ($oDocType == false)) {
  107 + $this->errorRedirectToMain('No Document Type selected.');
  108 + exit(0);
  109 + }
  110 +
  111 + $this->oQuery = new TypeBrowseQuery($oDocType);
  112 +
  113 + // FIXME probably want to redirect to self + action=selectType
  114 + $this->aBreadcrumbs[] = array('name' => _('Document Types'));
  115 +
  116 + $this->resultURL = "?fType=" . $doctype . "&fBrowseMode=document_type";
  117 +
  118 +
  119 +
  120 + } else {
  121 + // FIXME what should we do if we can't initiate the browse? we "pretend" to have no perms.
  122 + return false;
73 123 }
  124 +
74 125 return true;
75 126 }
76 127  
77 128 function do_main() {
78   - $collection = new DocumentCollection;
79   - $this->browseType = "Folder";
80   -
81   - $collection->addColumn(new SelectionColumn("Browse Selection","selection"));
82   - $collection->addColumn(new TitleColumn("Test 1 (title)","title"));
83   - $collection->addColumn(new DateColumn(_("Created"),"created", "getCreatedDateTime"));
84   - $collection->addColumn(new DateColumn(_("Last Modified"),"modified", "getLastModifiedDate"));
85   - $collection->addColumn(new UserColumn(_('Creator'),'creator_id','getCreatorID'));
86   -
87   - $this->aBreadcrumbs = array_merge($this->aBreadcrumbs,
88   - KTBrowseUtil::breadcrumbsForFolder($this->oFolder));
89   - // setup the folderside add actions
90   - // FIXME do we want to use folder actions?
91   - $portlet = new KTActionPortlet(_("Folder Actions"));
92   -
93   -
94   - // FIXME make a FolderActionUtil ... is it necessary?
95   -
96   - $aActions = KTFolderActionUtil::getFolderActionsForFolder($this->oFolder, $this->oUser);
97   -
98   - $portlet->setActions($aActions,null);
99   -
100   - $this->oPage->addPortlet($portlet);
101   -
102   - $batchPage = (int) KTUtil::arrayGet($_REQUEST, "page", 0);
103   - $batchSize = 20;
104   -
105   - $resultURL = "?fFolderId=" . $this->oFolder->getId();
106   - $collection->setBatching($resultURL, $batchPage, $batchSize);
107   -
108   -
109   - // ordering. (direction and column)
110   - $displayOrder = KTUtil::arrayGet($_REQUEST, 'sort_order', "asc");
111   - if ($displayOrder !== "asc") { $displayOrder = "desc"; }
112   - $displayControl = KTUtil::arrayGet($_REQUEST, 'sort_on', "title");
113   -
114   -
115   - $collection->setSorting($displayControl, $displayOrder);
116   -
117   - // add in the query object.
118   - $qObj = new BrowseQuery($this->oFolder->getId());
119   - $collection->setQueryObject($qObj);
120   -
121   - // breadcrumbs
122   - // FIXME handle breadcrumbs
123   - $collection->getResults();
124   -
125   - $oTemplating = new KTTemplating;
126   - $oTemplate = $oTemplating->loadTemplate("kt3/browse");
127   - $aTemplateData = array(
  129 + $collection = new DocumentCollection;
  130 +
  131 +
  132 + $collection->addColumn(new SelectionColumn("Browse Selection","selection"));
  133 + $collection->addColumn(new TitleColumn("Test 1 (title)","title"));
  134 + $collection->addColumn(new DateColumn(_("Created"),"created", "getCreatedDateTime"));
  135 + $collection->addColumn(new DateColumn(_("Last Modified"),"modified", "getLastModifiedDate"));
  136 + $collection->addColumn(new UserColumn(_('Creator'),'creator_id','getCreatorID'));
  137 +
  138 +
  139 + // setup the folderside add actions
  140 + // FIXME do we want to use folder actions?
  141 +
  142 + $batchPage = (int) KTUtil::arrayGet($_REQUEST, "page", 0);
  143 + $batchSize = 20;
  144 +
  145 +
  146 + $collection->setBatching($resultURL, $batchPage, $batchSize);
  147 +
  148 +
  149 + // ordering. (direction and column)
  150 + $displayOrder = KTUtil::arrayGet($_REQUEST, 'sort_order', "asc");
  151 + if ($displayOrder !== "asc") { $displayOrder = "desc"; }
  152 + $displayControl = KTUtil::arrayGet($_REQUEST, 'sort_on', "title");
  153 +
  154 +
  155 + $collection->setSorting($displayControl, $displayOrder);
  156 +
  157 + // add in the query object.
  158 + $qObj = $this->oQuery;
  159 + $collection->setQueryObject($qObj);
  160 +
  161 + // breadcrumbs
  162 + // FIXME handle breadcrumbs
  163 + $collection->getResults();
  164 +
  165 + $oTemplating = new KTTemplating;
  166 + $oTemplate = $oTemplating->loadTemplate("kt3/browse");
  167 + $aTemplateData = array(
  168 + "context" => $this,
  169 + "collection" => $collection,
  170 + 'browse_mode' => $this->browse_mode,
  171 + );
  172 + return $oTemplate->render($aTemplateData);
  173 + }
  174 +
  175 + function do_selectCategory() {
  176 + $this->errorRedirectToMain('category browsing is not yet implemented.');
  177 +
  178 + $oTemplating = new KTTemplating;
  179 + $oTemplate = $oTemplating->loadTemplate("kt3/browse_category");
  180 + $aTemplateData = array(
128 181 "context" => $this,
129   - "collection" => $collection,
130   - );
131   - return $oTemplate->render($aTemplateData);
132   - }
  182 + );
  183 + return $oTemplate->render($aTemplateData);
  184 + }
  185 +
  186 + function do_selectType() {
  187 + $aTypes = DocumentType::getList();
  188 + // FIXME what is the error message?
  189 +
  190 + if (empty($aTypes)) {
  191 + $this->errorRedirectToMain('No document types available.');
  192 + exit(0);
  193 + }
  194 +
  195 + $oTemplating = new KTTemplating;
  196 + $oTemplate = $oTemplating->loadTemplate("kt3/browse_types");
  197 + $aTemplateData = array(
  198 + "context" => $this,
  199 + "document_types" => $aTypes,
  200 + );
  201 + return $oTemplate->render($aTemplateData);
  202 + }
133 203 }
134 204  
135 205 $oDispatcher = new BrowseDispatcher();
... ...
templates/kt3/browse.smarty
1   -{$collection->render()}
2 1 \ No newline at end of file
  2 +{$collection->render()}
... ...
templates/kt3/browse_types.smarty 0 → 100644
  1 +<h2>Select a document type</h2>
  2 +
  3 +<p class="descriptiveText">{i18n}In some circumstances it is useful to view all
  4 +the different documents of a given <strong>document type</strong>. Select a type
  5 +to view all documents of that type.{/i18n}</p>
  6 +
  7 +<ul>
  8 +{foreach item=oType from=$document_types}
  9 + <li><a href="{$smarty.server.PHP_SELF}?action=main&fType={$oType->getId()}&fBrowseMode=document_type">{$oType->getName()}</a></li>
  10 +{/foreach}
  11 +</ul>
0 12 \ No newline at end of file
... ...
templates/kt3/portlets/browsemodes_portlet.smarty 0 → 100644
  1 +<ul>
  2 +{foreach item=sModeName key=sModeKey from=$modes}
  3 + <li>{if ($sModeKey == $current_action)}
  4 + <strong>{$sModeName.name}</strong>
  5 + {else}
  6 + <a href="{$smarty.server.PHP_SELF}{if ($sModeName.target != null)}?action={$sModeName.target}{/if}">{$sModeName.name}</a>
  7 + {/if}
  8 +{/foreach}
  9 +</ul>
0 10 \ No newline at end of file
... ...