Commit e2adcb3e3c897c7e70aa010345c747dcc74cc52e
1 parent
bc01295a
Untie Criteria from Browser, so it can be used by others easily.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3082 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
326 additions
and
284 deletions
lib/browse/Browser.inc
| 1 | 1 | <?php |
| 2 | -require_once("$default->fileSystemRoot/lib/security/Permission.inc"); | |
| 3 | -require_once("$default->fileSystemRoot/lib/users/User.inc"); | |
| 4 | -require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | |
| 5 | -require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | |
| 6 | 2 | /** |
| 7 | 3 | * $Id$ |
| 8 | 4 | * |
| ... | ... | @@ -29,283 +25,13 @@ require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); |
| 29 | 25 | * @package lib.browse |
| 30 | 26 | */ |
| 31 | 27 | |
| 32 | -class BrowseCriterion { | |
| 33 | - var $sDisplay; | |
| 34 | - var $sDocumentField; | |
| 35 | - var $sSortField; | |
| 36 | - var $aLookup = null; | |
| 37 | - var $oBrowser; | |
| 38 | - var $bFolderCriterion = false; | |
| 39 | - | |
| 40 | - function BrowseCriterion ($sDisplay, $sDocumentField, $sSortField, &$oBrowser) { | |
| 41 | - $this->sDisplay =& $sDisplay; | |
| 42 | - $this->sDocumentField =& $sDocumentField; | |
| 43 | - $this->sSortField =& $sSortField; | |
| 44 | - $this->oBrowser =& $oBrowser; | |
| 45 | - } | |
| 46 | - | |
| 47 | - function headerDisplay () { | |
| 48 | - return $this->sDisplay; | |
| 49 | - } | |
| 50 | - | |
| 51 | - // dummy function | |
| 52 | - function documentDisplay ($oDocument) { | |
| 53 | - return $this->sDisplay; | |
| 54 | - } | |
| 55 | - | |
| 56 | - function folderDisplay ($oDocument) { | |
| 57 | - return " "; | |
| 58 | - } | |
| 59 | - | |
| 60 | - function folderQuery ($iParentID) { | |
| 61 | - global $default; | |
| 62 | - $sFolderQuery = "SELECT f.id FROM $default->folders_table AS f ";/*ok*/ | |
| 63 | - if (!$this->bFolderCriterion) { | |
| 64 | - $sFolderQuery .= "WHERE parent_id = ? ORDER BY f.name asc"; | |
| 65 | - $aParams = array($iParentID); | |
| 66 | - return array($sFolderQuery, $aParams); | |
| 67 | - } | |
| 68 | - | |
| 69 | - if (!is_null($this->aLookup)) { | |
| 70 | - $sFolderQuery .= "INNER JOIN " . $this->aLookup["table"] . " lt ON f.$this->sDocumentField = lt.id WHERE parent_id = ?"; | |
| 71 | - $sFolderQuery .= " ORDER BY lt." . $this->aLookup["field"] . " " . $this->oBrowser->sSortDirection; | |
| 72 | - $aParams = array($iParentID); | |
| 73 | - return array($sFolderQuery, $aParams); | |
| 74 | - } | |
| 75 | - | |
| 76 | - $sFolderQuery .= "WHERE parent_id = ? ORDER BY " . $this->getFolderSortField() . " " . $this->oBrowser->sSortDirection; | |
| 77 | - $aParams = array($iParentID); | |
| 78 | - return array($sFolderQuery, $aParams); | |
| 79 | - } | |
| 80 | - | |
| 81 | - function documentQuery ($iFolderID) { | |
| 82 | - global $default; | |
| 83 | - // create query to retrieve documents in this folder | |
| 84 | - $documentQuery = "SELECT d.id as id FROM $default->documents_table AS d ";/*wc*/ | |
| 85 | - | |
| 86 | - if (!is_null($this->aLookup)) { | |
| 87 | - $sDocumentJoinField = $this->getDocumentField(); | |
| 88 | - $documentQuery .= "INNER JOIN " . $this->aLookup["table"] . " lt ON "; | |
| 89 | - if (array_key_exists('joinColumn', $this->aLookup)) { | |
| 90 | - $documentQuery .= "d.$sDocumentJoinField" . " = lt." . $this->aLookup["joinColumn"]; | |
| 91 | - } else { | |
| 92 | - $documentQuery .= "d.$sDocumentJoinField" . " = lt.id"; | |
| 93 | - } | |
| 94 | - } | |
| 95 | - | |
| 96 | - $documentQuery .= " WHERE d.folder_id = ? "; | |
| 97 | - $aParams = array($iFolderID); | |
| 98 | - if (!is_null($this->aLookup)) { | |
| 99 | - if (array_key_exists("whereClause", $this->aLookup)) { | |
| 100 | - $documentQuery .= "AND lt." . $this->aLookup["whereClause"] . " "; | |
| 101 | - } | |
| 102 | - | |
| 103 | - $documentQuery .= "ORDER BY lt." . $this->aLookup["field"] . " " . $this->oBrowser->sSortDirection; | |
| 104 | - } else { | |
| 105 | - $sDocumentJoinField = $this->getDocumentField(); | |
| 106 | - // $sSortField = $this->getSortField(); | |
| 107 | - $documentQuery .= "ORDER BY " . $this->getSortField() . " " . $this->oBrowser->sSortDirection; | |
| 108 | - } | |
| 109 | - | |
| 110 | - return array($documentQuery, $aParams); | |
| 111 | - } | |
| 112 | - | |
| 113 | - function getDocumentField () { | |
| 114 | - return $this->sDocumentField; | |
| 115 | - } | |
| 116 | - | |
| 117 | - function getSortField () { | |
| 118 | - return $this->sSortField; | |
| 119 | - } | |
| 120 | - | |
| 121 | - function getFolderSortField () { | |
| 122 | - return $this->sSortField; | |
| 123 | - } | |
| 124 | - | |
| 125 | - function getLookup () { | |
| 126 | - return $this->aLookup; | |
| 127 | - } | |
| 128 | - | |
| 129 | - function getName() { | |
| 130 | - return $this->sDocumentField; | |
| 131 | - } | |
| 132 | -} | |
| 133 | - | |
| 134 | -class NameCriterion extends BrowseCriterion { | |
| 135 | - var $bFolderCriterion = true; | |
| 136 | - function documentDisplay ($oDocument) { | |
| 137 | - $aOptions =& $this->oBrowser->getOptions(); | |
| 138 | - if (array_key_exists('displayFullPath', $aOptions)) { | |
| 139 | - $bDisplayFullPath = $aOptions['displayFullPath']; | |
| 140 | - } else { | |
| 141 | - $bDisplayFullPath = false; | |
| 142 | - } | |
| 143 | - if (array_key_exists('templateBrowsing', $aOptions)) { | |
| 144 | - $bTemplateBrowsing = $aOptions['templateBrowsing']; | |
| 145 | - } else { | |
| 146 | - $bTemplateBrowsing = false; | |
| 147 | - } | |
| 148 | - | |
| 149 | - if ($bTemplateBrowsing) { | |
| 150 | - return displayDocumentLinkForTemplateBrowsing($oDocument, $bDisplayFullPath); | |
| 151 | - } else { | |
| 152 | - return displayDocumentLink($oDocument, $bDisplayFullPath); | |
| 153 | - } | |
| 154 | - } | |
| 155 | - | |
| 156 | - function folderDisplay($oFolder) { | |
| 157 | - return displayFolderLink($oFolder); | |
| 158 | - } | |
| 159 | - | |
| 160 | - function getFolderSortField() { | |
| 161 | - return 'name'; | |
| 162 | - } | |
| 163 | -} | |
| 164 | - | |
| 165 | -class IDCriterion extends BrowseCriterion { | |
| 166 | - var $bFolderCriterion = true; | |
| 167 | - function documentDisplay ($oDocument) { | |
| 168 | - return $oDocument->getID(); | |
| 169 | - } | |
| 170 | - function folderDisplay($oFolder) { | |
| 171 | - return $oFolder->getID(); | |
| 172 | - } | |
| 173 | -} | |
| 174 | - | |
| 175 | -class TitleCriterion extends BrowseCriterion { | |
| 176 | - var $bFolderCriterion = true; | |
| 177 | - function documentDisplay ($oDocument) { | |
| 178 | - return $oDocument->getName(); | |
| 179 | - } | |
| 180 | - function folderDisplay($oFolder) { | |
| 181 | - return $oFolder->getDescription(); | |
| 182 | - } | |
| 183 | - | |
| 184 | - function getFolderSortField() { | |
| 185 | - return 'description'; | |
| 186 | - } | |
| 187 | -} | |
| 188 | - | |
| 189 | -class CreatorCriterion extends BrowseCriterion { | |
| 190 | - var $bFolderCriterion = true; | |
| 191 | - var $aLookup = array( | |
| 192 | - "table" => "users", | |
| 193 | - "field" => "name", | |
| 194 | - ); | |
| 195 | - function documentDisplay ($oDocument) { | |
| 196 | - $oCreator = User::get($oDocument->getCreatorID()); | |
| 197 | - if ($oCreator) { | |
| 198 | - return $oCreator->getName(); | |
| 199 | - } | |
| 200 | - return " "; | |
| 201 | - } | |
| 202 | - function folderDisplay($oFolder) { | |
| 203 | - return $this->documentDisplay($oFolder); | |
| 204 | - } | |
| 205 | -} | |
| 206 | - | |
| 207 | -class DateCreatedCriterion extends BrowseCriterion { | |
| 208 | - var $aLookup = array( | |
| 209 | - "table" => "document_transactions", | |
| 210 | - "field" => "datetime", | |
| 211 | - "joinColumn" => "document_id", | |
| 212 | - "whereClause" => "transaction_id=1", | |
| 213 | - ); | |
| 214 | - | |
| 215 | - function documentDisplay ($oDocument) { | |
| 216 | - $aDocumentTransaction = DocumentTransaction::getList("transaction_id=1 AND document_id=" . $oDocument->getID()); | |
| 217 | - return $aDocumentTransaction[0]->dDateTime; | |
| 218 | - } | |
| 219 | - function getName() { | |
| 220 | - return "datecreated"; | |
| 221 | - } | |
| 222 | -} | |
| 223 | - | |
| 224 | -class DocumentTypeCriterion extends BrowseCriterion { | |
| 225 | - var $aLookup = array( | |
| 226 | - "table" => "document_types_lookup", | |
| 227 | - "field" => "name" | |
| 228 | - ); | |
| 229 | - | |
| 230 | - function documentDisplay ($oDocument) { | |
| 231 | - $oDocumentType = DocumentType::get($oDocument->getDocumentTypeID()); | |
| 232 | - if ($oDocumentType) { | |
| 233 | - return $oDocumentType->getName(); | |
| 234 | - } | |
| 235 | - return " "; | |
| 236 | - } | |
| 237 | -} | |
| 238 | - | |
| 239 | -class GenericMetadataCriterion extends BrowseCriterion { | |
| 240 | - var $aLookup = array( | |
| 241 | - "table" => "document_fields_link", | |
| 242 | - "field" => "value", | |
| 243 | - "joinColumn" => "document_id", | |
| 244 | - ); | |
| 245 | - var $iFieldID; | |
| 246 | - | |
| 247 | - function GenericMetadataCriterion ($sDisplay, $sDocumentField, $sSortField, &$oBrowser, $iFieldID) { | |
| 248 | - $this->iFieldID = $iFieldID; | |
| 249 | - $this->BrowseCriterion($sDisplay, $sDocumentField, $sSortField, $oBrowser); | |
| 250 | - $this->aLookup['whereClause'] = 'document_field_id = ' . $iFieldID; | |
| 251 | - } | |
| 252 | - | |
| 253 | - function documentDisplay ($oDocument) { | |
| 254 | - global $default; | |
| 255 | - $sQuery = "SELECT DFL.value as value " . | |
| 256 | - "FROM $default->document_fields_link_table AS DFL " . | |
| 257 | - "WHERE DFL.document_id = ? " . | |
| 258 | - "AND DFL.document_field_id = ?"; | |
| 259 | - $aParams = array($oDocument->getID(), $this->iFieldID); | |
| 260 | - | |
| 261 | - $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'value'); | |
| 262 | - if (PEAR::isError($res)) { | |
| 263 | - // WARN: Add log warning | |
| 264 | - return " "; | |
| 265 | - } | |
| 266 | - return $res; | |
| 267 | - } | |
| 268 | - | |
| 269 | - function getName() { | |
| 270 | - global $default; | |
| 271 | - $aQuery = array("SELECT name FROM $default->document_fields_table WHERE id = ?", array($this->iFieldID)); /*ok*/ | |
| 272 | - return "gmd_" . DBUtil::getOneResultKey($aQuery, 'name'); | |
| 273 | - } | |
| 274 | -} | |
| 275 | - | |
| 276 | -function &getCriterionByNumber(&$aSortCriteria, &$oBrowser, $iID) { | |
| 277 | - global $default; | |
| 278 | - switch ($iID) { | |
| 279 | - case -1: | |
| 280 | - $oCriterion =& new NameCriterion(_("Name"), 'filename', 'filename', $oBrowser); | |
| 281 | - break; | |
| 282 | - case -2: | |
| 283 | - $oCriterion =& new TitleCriterion(_("Title"), 'name', 'name', $oBrowser); | |
| 284 | - break; | |
| 285 | - case -3: | |
| 286 | - $oCriterion =& new CreatorCriterion(_("Creator"), 'creator_id', 'creator_id', $oBrowser); | |
| 287 | - break; | |
| 288 | - case -4: | |
| 289 | - $oCriterion =& new DateCreatedCriterion(_("Date Created"), 'id', 'id', $oBrowser); | |
| 290 | - break; | |
| 291 | - case -5: | |
| 292 | - $oCriterion =& new DocumentTypeCriterion(_("Document Type"), 'document_type_id', 'document_type_id', $oBrowser); | |
| 293 | - break; | |
| 294 | - case -6: | |
| 295 | - $oCriterion =& new IDCriterion(_("ID"), 'id', 'id', $oBrowser); | |
| 296 | - break; | |
| 297 | - default: | |
| 298 | - $aQuery = array("SELECT name FROM $default->document_fields_table WHERE id = ?", array($iID)); /*ok*/ | |
| 299 | - $sName = DBUtil::getOneResultKey($aQuery, 'name'); | |
| 300 | - $oCriterion =& new GenericMetadataCriterion($sName, 'id', 'id', $oBrowser, $iID); | |
| 301 | - break; | |
| 28 | +require_once("$default->fileSystemRoot/lib/security/Permission.inc"); | |
| 29 | +require_once("$default->fileSystemRoot/lib/users/User.inc"); | |
| 30 | +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | |
| 31 | +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | |
| 32 | +require_once("Criteria.inc"); | |
| 302 | 33 | |
| 303 | - } | |
| 304 | - return $oCriterion; | |
| 305 | -} | |
| 306 | - | |
| 307 | 34 | class Browser { |
| 308 | - | |
| 309 | 35 | /** |
| 310 | 36 | * The point we're browsing from |
| 311 | 37 | */ |
| ... | ... | @@ -341,7 +67,7 @@ class Browser { |
| 341 | 67 | $aQuery = array("SELECT criteria_id FROM browse_criteria ORDER BY precedence", array()); /*ok*/ |
| 342 | 68 | $aSelectedCriteriaIDs = DBUtil::getResultArrayKey($aQuery, 'criteria_id'); |
| 343 | 69 | foreach ($aSelectedCriteriaIDs as $iID) { |
| 344 | - $oCriterion =& getCriterionByNumber($aNewSortCriteria, $this, $iID); | |
| 70 | + $oCriterion =& Criteria::getCriterionByNumber($iID); | |
| 345 | 71 | $aNewSortCriteria[$oCriterion->getName()] =& $oCriterion; |
| 346 | 72 | } |
| 347 | 73 | } |
| ... | ... | @@ -410,6 +136,9 @@ class Browser { |
| 410 | 136 | |
| 411 | 137 | function setOptions($aOptions) { |
| 412 | 138 | $this->aOptions = array_merge($this->aOptions, $aOptions); |
| 139 | + foreach (array_values($this->aSortCriteria) as $oCriteria) { | |
| 140 | + $oCriteria->setOptions($aOptions); | |
| 141 | + } | |
| 413 | 142 | } |
| 414 | 143 | |
| 415 | 144 | function getOptions() { |
| ... | ... | @@ -427,6 +156,5 @@ class Browser { |
| 427 | 156 | */ |
| 428 | 157 | function browse() { |
| 429 | 158 | } |
| 430 | - | |
| 431 | - | |
| 432 | 159 | } |
| 160 | +?> | ... | ... |
lib/browse/Criteria.inc
0 โ 100644
| 1 | +<?php | |
| 2 | +require_once("$default->fileSystemRoot/lib/security/Permission.inc"); | |
| 3 | +require_once("$default->fileSystemRoot/lib/users/User.inc"); | |
| 4 | +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | |
| 5 | +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | |
| 6 | +/** | |
| 7 | + * $Id$ | |
| 8 | + * | |
| 9 | + * Contains document browsing business logic. | |
| 10 | + * | |
| 11 | + * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com | |
| 12 | + * | |
| 13 | + * This program is free software; you can redistribute it and/or modify | |
| 14 | + * it under the terms of the GNU General Public License as published by | |
| 15 | + * the Free Software Foundation; either version 2 of the License, or | |
| 16 | + * (at your option) any later version. | |
| 17 | + * | |
| 18 | + * This program is distributed in the hope that it will be useful, | |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | + * GNU General Public License for more details. | |
| 22 | + * | |
| 23 | + * You should have received a copy of the GNU General Public License | |
| 24 | + * along with this program; if not, write to the Free Software | |
| 25 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 26 | + * | |
| 27 | + * @version $Revision$ | |
| 28 | + * @author Neil Blakey-Milner <nbm@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | |
| 29 | + * @package lib.browse | |
| 30 | + */ | |
| 31 | + | |
| 32 | +class BrowseCriterion { | |
| 33 | + var $sDisplay; | |
| 34 | + var $sDocumentField; | |
| 35 | + var $sSortField; | |
| 36 | + var $aLookup = null; | |
| 37 | + var $bFolderCriterion = false; | |
| 38 | + var $aOptions = array(); | |
| 39 | + | |
| 40 | + function BrowseCriterion ($sDisplay, $sDocumentField, $sSortField) { | |
| 41 | + $this->sDisplay =& $sDisplay; | |
| 42 | + $this->sDocumentField =& $sDocumentField; | |
| 43 | + $this->sSortField =& $sSortField; | |
| 44 | + } | |
| 45 | + | |
| 46 | + function headerDisplay () { | |
| 47 | + return $this->sDisplay; | |
| 48 | + } | |
| 49 | + | |
| 50 | + // dummy function | |
| 51 | + function documentDisplay ($oDocument) { | |
| 52 | + return $this->sDisplay; | |
| 53 | + } | |
| 54 | + | |
| 55 | + function folderDisplay ($oDocument) { | |
| 56 | + return " "; | |
| 57 | + } | |
| 58 | + | |
| 59 | + function folderQuery ($iParentID, $sSortDirection) { | |
| 60 | + global $default; | |
| 61 | + $sFolderQuery = "SELECT f.id FROM $default->folders_table AS f ";/*ok*/ | |
| 62 | + if (!$this->bFolderCriterion) { | |
| 63 | + $sFolderQuery .= "WHERE parent_id = ? ORDER BY f.name asc"; | |
| 64 | + $aParams = array($iParentID); | |
| 65 | + return array($sFolderQuery, $aParams); | |
| 66 | + } | |
| 67 | + | |
| 68 | + if (!is_null($this->aLookup)) { | |
| 69 | + $sFolderQuery .= "INNER JOIN " . $this->aLookup["table"] . " lt ON f.$this->sDocumentField = lt.id WHERE parent_id = ?"; | |
| 70 | + $sFolderQuery .= " ORDER BY lt." . $this->aLookup["field"] . " " . $sSortDirection; | |
| 71 | + $aParams = array($iParentID); | |
| 72 | + return array($sFolderQuery, $aParams); | |
| 73 | + } | |
| 74 | + | |
| 75 | + $sFolderQuery .= "WHERE parent_id = ? ORDER BY " . $this->getFolderSortField() . " " . $sSortDirection; | |
| 76 | + $aParams = array($iParentID); | |
| 77 | + return array($sFolderQuery, $aParams); | |
| 78 | + } | |
| 79 | + | |
| 80 | + function documentQuery ($iFolderID, $sSortDirection) { | |
| 81 | + global $default; | |
| 82 | + // create query to retrieve documents in this folder | |
| 83 | + $documentQuery = "SELECT d.id as id FROM $default->documents_table AS d ";/*wc*/ | |
| 84 | + | |
| 85 | + if (!is_null($this->aLookup)) { | |
| 86 | + $sDocumentJoinField = $this->getDocumentField(); | |
| 87 | + $documentQuery .= "INNER JOIN " . $this->aLookup["table"] . " lt ON "; | |
| 88 | + if (array_key_exists('joinColumn', $this->aLookup)) { | |
| 89 | + $documentQuery .= "d.$sDocumentJoinField" . " = lt." . $this->aLookup["joinColumn"]; | |
| 90 | + } else { | |
| 91 | + $documentQuery .= "d.$sDocumentJoinField" . " = lt.id"; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + | |
| 95 | + $documentQuery .= " WHERE d.folder_id = ? "; | |
| 96 | + $aParams = array($iFolderID); | |
| 97 | + if (!is_null($this->aLookup)) { | |
| 98 | + if (array_key_exists("whereClause", $this->aLookup)) { | |
| 99 | + $documentQuery .= "AND lt." . $this->aLookup["whereClause"] . " "; | |
| 100 | + } | |
| 101 | + | |
| 102 | + $documentQuery .= "ORDER BY lt." . $this->aLookup["field"] . " " . $sSortDirection; | |
| 103 | + } else { | |
| 104 | + $sDocumentJoinField = $this->getDocumentField(); | |
| 105 | + // $sSortField = $this->getSortField(); | |
| 106 | + $documentQuery .= "ORDER BY " . $this->getSortField() . " " . $sSortDirection; | |
| 107 | + } | |
| 108 | + | |
| 109 | + return array($documentQuery, $aParams); | |
| 110 | + } | |
| 111 | + | |
| 112 | + function getDocumentField () { | |
| 113 | + return $this->sDocumentField; | |
| 114 | + } | |
| 115 | + | |
| 116 | + function getSortField () { | |
| 117 | + return $this->sSortField; | |
| 118 | + } | |
| 119 | + | |
| 120 | + function getFolderSortField () { | |
| 121 | + return $this->sSortField; | |
| 122 | + } | |
| 123 | + | |
| 124 | + function getLookup () { | |
| 125 | + return $this->aLookup; | |
| 126 | + } | |
| 127 | + | |
| 128 | + function getName() { | |
| 129 | + return $this->sDocumentField; | |
| 130 | + } | |
| 131 | + | |
| 132 | + function setOptions($aOptions) { | |
| 133 | + $this->aOptions = $aOptions; | |
| 134 | + } | |
| 135 | +} | |
| 136 | + | |
| 137 | +class NameCriterion extends BrowseCriterion { | |
| 138 | + var $bFolderCriterion = true; | |
| 139 | + function documentDisplay ($oDocument) { | |
| 140 | + $aOptions = $this->aOptions; | |
| 141 | + if (array_key_exists('displayFullPath', $aOptions)) { | |
| 142 | + $bDisplayFullPath = $aOptions['displayFullPath']; | |
| 143 | + } else { | |
| 144 | + $bDisplayFullPath = false; | |
| 145 | + } | |
| 146 | + if (array_key_exists('templateBrowsing', $aOptions)) { | |
| 147 | + $bTemplateBrowsing = $aOptions['templateBrowsing']; | |
| 148 | + } else { | |
| 149 | + $bTemplateBrowsing = false; | |
| 150 | + } | |
| 151 | + | |
| 152 | + if ($bTemplateBrowsing) { | |
| 153 | + return displayDocumentLinkForTemplateBrowsing($oDocument, $bDisplayFullPath); | |
| 154 | + } else { | |
| 155 | + return displayDocumentLink($oDocument, $bDisplayFullPath); | |
| 156 | + } | |
| 157 | + } | |
| 158 | + | |
| 159 | + function folderDisplay($oFolder) { | |
| 160 | + return displayFolderLink($oFolder); | |
| 161 | + } | |
| 162 | + | |
| 163 | + function getFolderSortField() { | |
| 164 | + return 'name'; | |
| 165 | + } | |
| 166 | +} | |
| 167 | + | |
| 168 | +class IDCriterion extends BrowseCriterion { | |
| 169 | + var $bFolderCriterion = true; | |
| 170 | + function documentDisplay ($oDocument) { | |
| 171 | + return $oDocument->getID(); | |
| 172 | + } | |
| 173 | + function folderDisplay($oFolder) { | |
| 174 | + return $oFolder->getID(); | |
| 175 | + } | |
| 176 | +} | |
| 177 | + | |
| 178 | +class TitleCriterion extends BrowseCriterion { | |
| 179 | + var $bFolderCriterion = true; | |
| 180 | + function documentDisplay ($oDocument) { | |
| 181 | + return $oDocument->getName(); | |
| 182 | + } | |
| 183 | + function folderDisplay($oFolder) { | |
| 184 | + return $oFolder->getDescription(); | |
| 185 | + } | |
| 186 | + | |
| 187 | + function getFolderSortField() { | |
| 188 | + return 'description'; | |
| 189 | + } | |
| 190 | +} | |
| 191 | + | |
| 192 | +class CreatorCriterion extends BrowseCriterion { | |
| 193 | + var $bFolderCriterion = true; | |
| 194 | + var $aLookup = array( | |
| 195 | + "table" => "users", | |
| 196 | + "field" => "name", | |
| 197 | + ); | |
| 198 | + function documentDisplay ($oDocument) { | |
| 199 | + $oCreator = User::get($oDocument->getCreatorID()); | |
| 200 | + if ($oCreator) { | |
| 201 | + return $oCreator->getName(); | |
| 202 | + } | |
| 203 | + return " "; | |
| 204 | + } | |
| 205 | + function folderDisplay($oFolder) { | |
| 206 | + return $this->documentDisplay($oFolder); | |
| 207 | + } | |
| 208 | +} | |
| 209 | + | |
| 210 | +class DateCreatedCriterion extends BrowseCriterion { | |
| 211 | + var $aLookup = array( | |
| 212 | + "table" => "document_transactions", | |
| 213 | + "field" => "datetime", | |
| 214 | + "joinColumn" => "document_id", | |
| 215 | + "whereClause" => "transaction_id=1", | |
| 216 | + ); | |
| 217 | + | |
| 218 | + function documentDisplay ($oDocument) { | |
| 219 | + $aDocumentTransaction = DocumentTransaction::getList("transaction_id=1 AND document_id=" . $oDocument->getID()); | |
| 220 | + return $aDocumentTransaction[0]->dDateTime; | |
| 221 | + } | |
| 222 | + function getName() { | |
| 223 | + return "datecreated"; | |
| 224 | + } | |
| 225 | +} | |
| 226 | + | |
| 227 | +class DocumentTypeCriterion extends BrowseCriterion { | |
| 228 | + var $aLookup = array( | |
| 229 | + "table" => "document_types_lookup", | |
| 230 | + "field" => "name" | |
| 231 | + ); | |
| 232 | + | |
| 233 | + function documentDisplay ($oDocument) { | |
| 234 | + $oDocumentType = DocumentType::get($oDocument->getDocumentTypeID()); | |
| 235 | + if ($oDocumentType) { | |
| 236 | + return $oDocumentType->getName(); | |
| 237 | + } | |
| 238 | + return " "; | |
| 239 | + } | |
| 240 | +} | |
| 241 | + | |
| 242 | +class GenericMetadataCriterion extends BrowseCriterion { | |
| 243 | + var $aLookup = array( | |
| 244 | + "table" => "document_fields_link", | |
| 245 | + "field" => "value", | |
| 246 | + "joinColumn" => "document_id", | |
| 247 | + ); | |
| 248 | + var $iFieldID; | |
| 249 | + | |
| 250 | + function GenericMetadataCriterion ($sDisplay, $sDocumentField, $sSortField, $iFieldID) { | |
| 251 | + $this->iFieldID = $iFieldID; | |
| 252 | + $this->BrowseCriterion($sDisplay, $sDocumentField, $sSortField); | |
| 253 | + $this->aLookup['whereClause'] = 'document_field_id = ' . $iFieldID; | |
| 254 | + } | |
| 255 | + | |
| 256 | + function documentDisplay ($oDocument) { | |
| 257 | + global $default; | |
| 258 | + $sQuery = "SELECT DFL.value as value " . | |
| 259 | + "FROM $default->document_fields_link_table AS DFL " . | |
| 260 | + "WHERE DFL.document_id = ? " . | |
| 261 | + "AND DFL.document_field_id = ?"; | |
| 262 | + $aParams = array($oDocument->getID(), $this->iFieldID); | |
| 263 | + | |
| 264 | + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'value'); | |
| 265 | + if (PEAR::isError($res)) { | |
| 266 | + // WARN: Add log warning | |
| 267 | + return " "; | |
| 268 | + } | |
| 269 | + return $res; | |
| 270 | + } | |
| 271 | + | |
| 272 | + function getName() { | |
| 273 | + global $default; | |
| 274 | + $aQuery = array("SELECT name FROM $default->document_fields_table WHERE id = ?", array($this->iFieldID)); /*ok*/ | |
| 275 | + return "gmd_" . DBUtil::getOneResultKey($aQuery, 'name'); | |
| 276 | + } | |
| 277 | +} | |
| 278 | + | |
| 279 | +class Criteria { | |
| 280 | + function &getCriterionByNumber($iID) { | |
| 281 | + global $default; | |
| 282 | + switch ($iID) { | |
| 283 | + case -1: | |
| 284 | + $oCriterion =& new NameCriterion(_("Name"), 'filename', 'filename'); | |
| 285 | + break; | |
| 286 | + case -2: | |
| 287 | + $oCriterion =& new TitleCriterion(_("Title"), 'name', 'name'); | |
| 288 | + break; | |
| 289 | + case -3: | |
| 290 | + $oCriterion =& new CreatorCriterion(_("Creator"), 'creator_id', 'creator_id'); | |
| 291 | + break; | |
| 292 | + case -4: | |
| 293 | + $oCriterion =& new DateCreatedCriterion(_("Date Created"), 'id', 'id'); | |
| 294 | + break; | |
| 295 | + case -5: | |
| 296 | + $oCriterion =& new DocumentTypeCriterion(_("Document Type"), 'document_type_id', 'document_type_id'); | |
| 297 | + break; | |
| 298 | + case -6: | |
| 299 | + $oCriterion =& new IDCriterion(_("ID"), 'id', 'id'); | |
| 300 | + break; | |
| 301 | + default: | |
| 302 | + $aQuery = array("SELECT name FROM $default->document_fields_table WHERE id = ?", array($iID)); /*ok*/ | |
| 303 | + $sName = DBUtil::getOneResultKey($aQuery, 'name'); | |
| 304 | + $oCriterion =& new GenericMetadataCriterion($sName, 'id', 'id', $iID); | |
| 305 | + break; | |
| 306 | + } | |
| 307 | + return $oCriterion; | |
| 308 | + } | |
| 309 | + | |
| 310 | + function initCriteria () { | |
| 311 | + } | |
| 312 | +} | |
| 313 | + | |
| 314 | +?> | ... | ... |
lib/browse/FolderBrowser.inc
| ... | ... | @@ -117,7 +117,7 @@ class FolderBrowser extends Browser { |
| 117 | 117 | $oSortCriterion = $this->aSortCriteria[$this->sSortField]; |
| 118 | 118 | $aLookupCriteria = $oSortCriterion->getLookup(); |
| 119 | 119 | |
| 120 | - $aQuery = $oSortCriterion->folderQuery($iFolderID); | |
| 120 | + $aQuery = $oSortCriterion->folderQuery($iFolderID, $this->sSortDirection); | |
| 121 | 121 | |
| 122 | 122 | $oResult = DBUtil::runQuery($aQuery); |
| 123 | 123 | if (PEAR::isError($oResult)) { |
| ... | ... | @@ -145,7 +145,7 @@ class FolderBrowser extends Browser { |
| 145 | 145 | |
| 146 | 146 | $default->log->debug("Going on to document checking"); |
| 147 | 147 | |
| 148 | - $aQuery = $oSortCriterion->documentQuery($iFolderID); | |
| 148 | + $aQuery = $oSortCriterion->documentQuery($iFolderID, $this->sSortDirection); | |
| 149 | 149 | $oResult = DBUtil::runQuery($aQuery); |
| 150 | 150 | if (PEAR::isError($oResult)) { |
| 151 | 151 | var_dump($oResult); | ... | ... |