Commit cc8c54e7663461f30b47b6a54d257b248a909547
1 parent
fe2a0eea
Centralise browser logic into per-criterion objects, making the
interface respond to which criteria are set up in the browser. Also support generic metadata in the browser - as evidenced by the Category criterion added to the browser now. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3073 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
284 additions
and
91 deletions
lib/browse/Browser.inc
| @@ -28,6 +28,215 @@ require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | @@ -28,6 +28,215 @@ require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 28 | * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | 28 | * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa |
| 29 | * @package lib.browse | 29 | * @package lib.browse |
| 30 | */ | 30 | */ |
| 31 | + | ||
| 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->sSortField " . $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->sSortField " . $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 getLookup () { | ||
| 122 | + return $this->aLookup; | ||
| 123 | + } | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +class NameCriterion extends BrowseCriterion { | ||
| 127 | + var $bFolderCriterion = true; | ||
| 128 | + function documentDisplay ($oDocument) { | ||
| 129 | + $aOptions =& $this->oBrowser->getOptions(); | ||
| 130 | + if (array_key_exists('displayFullPath', $aOptions)) { | ||
| 131 | + $bDisplayFullPath = $aOptions['displayFullPath']; | ||
| 132 | + } else { | ||
| 133 | + $bDisplayFullPath = false; | ||
| 134 | + } | ||
| 135 | + if (array_key_exists('templateBrowsing', $aOptions)) { | ||
| 136 | + $bTemplateBrowsing = $aOptions['templateBrowsing']; | ||
| 137 | + } else { | ||
| 138 | + $bTemplateBrowsing = false; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + if ($bTemplateBrowsing) { | ||
| 142 | + return displayDocumentLinkForTemplateBrowsing($oDocument, $bDisplayFullPath); | ||
| 143 | + } else { | ||
| 144 | + return displayDocumentLink($oDocument, $bDisplayFullPath); | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + function folderDisplay($oFolder) { | ||
| 149 | + return displayFolderLink($oFolder); | ||
| 150 | + } | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +class TitleCriterion extends BrowseCriterion { | ||
| 154 | + function documentDisplay ($oDocument) { | ||
| 155 | + return $oDocument->getName(); | ||
| 156 | + } | ||
| 157 | + function folderDisplay($oFolder) { | ||
| 158 | + return $oFolder->getDescription(); | ||
| 159 | + } | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +class CreatorCriterion extends BrowseCriterion { | ||
| 163 | + var $bFolderCriterion = true; | ||
| 164 | + var $aLookup = array( | ||
| 165 | + "table" => "users", | ||
| 166 | + "field" => "name", | ||
| 167 | + ); | ||
| 168 | + function documentDisplay ($oDocument) { | ||
| 169 | + $oCreator = User::get($oDocument->getCreatorID()); | ||
| 170 | + if ($oCreator) { | ||
| 171 | + return $oCreator->getName(); | ||
| 172 | + } | ||
| 173 | + return " "; | ||
| 174 | + } | ||
| 175 | + function folderDisplay($oFolder) { | ||
| 176 | + return $this->documentDisplay($oFolder); | ||
| 177 | + } | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +class DateCreatedCriterion extends BrowseCriterion { | ||
| 181 | + var $aLookup = array( | ||
| 182 | + "table" => "document_transactions", | ||
| 183 | + "field" => "datetime", | ||
| 184 | + "joinColumn" => "document_id", | ||
| 185 | + "whereClause" => "transaction_id=1", | ||
| 186 | + ); | ||
| 187 | + | ||
| 188 | + function documentDisplay ($oDocument) { | ||
| 189 | + $aDocumentTransaction = DocumentTransaction::getList("transaction_id=1 AND document_id=" . $oDocument->getID()); | ||
| 190 | + return $aDocumentTransaction[0]->dDateTime; | ||
| 191 | + } | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +class DocumentTypeCriterion extends BrowseCriterion { | ||
| 195 | + var $aLookup = array( | ||
| 196 | + "table" => "document_types_lookup", | ||
| 197 | + "field" => "name" | ||
| 198 | + ); | ||
| 199 | + | ||
| 200 | + function documentDisplay ($oDocument) { | ||
| 201 | + $oDocumentType = DocumentType::get($oDocument->getDocumentTypeID()); | ||
| 202 | + if ($oDocumentType) { | ||
| 203 | + return $oDocumentType->getName(); | ||
| 204 | + } | ||
| 205 | + return " "; | ||
| 206 | + } | ||
| 207 | +} | ||
| 208 | + | ||
| 209 | +class GenericMetadataCriterion extends BrowseCriterion { | ||
| 210 | + var $aLookup = array( | ||
| 211 | + "table" => "document_fields_link", | ||
| 212 | + "field" => "value", | ||
| 213 | + "joinColumn" => "document_id", | ||
| 214 | + ); | ||
| 215 | + var $iFieldID; | ||
| 216 | + | ||
| 217 | + function GenericMetadataCriterion ($sDisplay, $sDocumentField, $sSortField, &$oBrowser, $iFieldID) { | ||
| 218 | + $this->iFieldID = $iFieldID; | ||
| 219 | + $this->BrowseCriterion($sDisplay, $sDocumentField, $sSortField, $oBrowser); | ||
| 220 | + $this->aLookup['whereClause'] = 'document_field_id = ' . $iFieldID; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + function documentDisplay ($oDocument) { | ||
| 224 | + global $default; | ||
| 225 | + $sQuery = "SELECT DFL.value as value " . | ||
| 226 | + "FROM $default->document_fields_link_table AS DFL " . | ||
| 227 | + "WHERE DFL.document_id = ? " . | ||
| 228 | + "AND DFL.document_field_id = ?"; | ||
| 229 | + $aParams = array($oDocument->getID(), $this->iFieldID); | ||
| 230 | + | ||
| 231 | + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'value'); | ||
| 232 | + if (PEAR::isError($res)) { | ||
| 233 | + // WARN: Add log warning | ||
| 234 | + return " "; | ||
| 235 | + } | ||
| 236 | + return $res; | ||
| 237 | + } | ||
| 238 | +} | ||
| 239 | + | ||
| 31 | class Browser { | 240 | class Browser { |
| 32 | 241 | ||
| 33 | /** | 242 | /** |
| @@ -48,6 +257,8 @@ class Browser { | @@ -48,6 +257,8 @@ class Browser { | ||
| 48 | * The direction to sort the results in | 257 | * The direction to sort the results in |
| 49 | */ | 258 | */ |
| 50 | var $sSortDirection; | 259 | var $sSortDirection; |
| 260 | + | ||
| 261 | + var $aOptions; | ||
| 51 | 262 | ||
| 52 | /** | 263 | /** |
| 53 | * Constructs a new Browser instance | 264 | * Constructs a new Browser instance |
| @@ -60,35 +271,12 @@ class Browser { | @@ -60,35 +271,12 @@ class Browser { | ||
| 60 | // default sort criteria | 271 | // default sort criteria |
| 61 | if (count($aNewSortCriteria) == 0) { | 272 | if (count($aNewSortCriteria) == 0) { |
| 62 | $aNewSortCriteria = array ( | 273 | $aNewSortCriteria = array ( |
| 63 | - "name" => array( | ||
| 64 | - "display" => _("Title"), | ||
| 65 | - ), | ||
| 66 | - "filename" => array( | ||
| 67 | - "display" => _("Description"), | ||
| 68 | - ), | ||
| 69 | - "creator_id" => array( | ||
| 70 | - "display" => _("Creator"), | ||
| 71 | - "lookup" => array( | ||
| 72 | - "table" => "users", | ||
| 73 | - "field" => "name", | ||
| 74 | - ), | ||
| 75 | - ), | ||
| 76 | - "id" => array( | ||
| 77 | - "display" => _("Date Created"), | ||
| 78 | - "lookup" => array( | ||
| 79 | - "table" => "document_transactions", | ||
| 80 | - "field" => "datetime", | ||
| 81 | - "joinColumn" => "document_id", | ||
| 82 | - "whereClause" => "transaction_id=1", | ||
| 83 | - ), | ||
| 84 | - ), | ||
| 85 | - "document_type_id" => array( | ||
| 86 | - "display" => _("Document Type"), | ||
| 87 | - "lookup" => array( | ||
| 88 | - "table" => "document_types_lookup", | ||
| 89 | - "field" => "name" | ||
| 90 | - ), | ||
| 91 | - ), | 274 | + "name" => new NameCriterion(_("Title"), 'name', 'name', $this), |
| 275 | + "filename" => new TitleCriterion(_("Description"), 'filename', 'filename', $this), | ||
| 276 | + "creator_id" => new CreatorCriterion(_("Creator"), 'creator_id', 'creator_id', $this), | ||
| 277 | + "id" => new DateCreatedCriterion(_("Date Created"), 'id', 'id', $this), | ||
| 278 | + "document_type_id" => new DocumentTypeCriterion(_("Document Type"), 'document_type_id', 'document_type_id', $this), | ||
| 279 | + "category" => new GenericMetadataCriterion("Category", 'id', 'id', $this, 1), | ||
| 92 | ); | 280 | ); |
| 93 | } | 281 | } |
| 94 | 282 | ||
| @@ -153,6 +341,15 @@ class Browser { | @@ -153,6 +341,15 @@ class Browser { | ||
| 153 | $this->sSortDirection = $sNewSortDirection; | 341 | $this->sSortDirection = $sNewSortDirection; |
| 154 | } | 342 | } |
| 155 | 343 | ||
| 344 | + | ||
| 345 | + function setOptions($aOptions) { | ||
| 346 | + $this->aOptions = array_merge($this->aOptions, $aOptions); | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | + function getOptions() { | ||
| 350 | + return $this->aOptions; | ||
| 351 | + } | ||
| 352 | + | ||
| 156 | /** | 353 | /** |
| 157 | * [Abstract] Browse the documents | 354 | * [Abstract] Browse the documents |
| 158 | * | 355 | * |
| @@ -161,4 +358,5 @@ class Browser { | @@ -161,4 +358,5 @@ class Browser { | ||
| 161 | function browse() { | 358 | function browse() { |
| 162 | } | 359 | } |
| 163 | 360 | ||
| 361 | + | ||
| 164 | } | 362 | } |
lib/browse/BrowserFactory.inc
| @@ -39,7 +39,7 @@ class BrowserFactory { | @@ -39,7 +39,7 @@ class BrowserFactory { | ||
| 39 | * @param string the direction to sort in | 39 | * @param string the direction to sort in |
| 40 | * @return Browser the correct Browser implementation class | 40 | * @return Browser the correct Browser implementation class |
| 41 | */ | 41 | */ |
| 42 | - function create($sBrowseBy, $sSortField, $sSortDirection) { | 42 | + function &create($sBrowseBy, $sSortField, $sSortDirection) { |
| 43 | 43 | ||
| 44 | switch ($sBrowseBy) { | 44 | switch ($sBrowseBy) { |
| 45 | case "folder" : // retrieve folderID if present | 45 | case "folder" : // retrieve folderID if present |
| @@ -59,4 +59,4 @@ class BrowserFactory { | @@ -59,4 +59,4 @@ class BrowserFactory { | ||
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | -} | ||
| 63 | \ No newline at end of file | 62 | \ No newline at end of file |
| 63 | +} |
lib/browse/FolderBrowser.inc
| @@ -114,36 +114,28 @@ class FolderBrowser extends Browser { | @@ -114,36 +114,28 @@ class FolderBrowser extends Browser { | ||
| 114 | // now find all the child folders relative to this one | 114 | // now find all the child folders relative to this one |
| 115 | // FIXME: in the same unit? | 115 | // FIXME: in the same unit? |
| 116 | 116 | ||
| 117 | - $aLookupCriteria = $this->aSortCriteria[$this->sSortField]["lookup"]; | 117 | + $oSortCriterion = $this->aSortCriteria[$this->sSortField]; |
| 118 | + $aLookupCriteria = $oSortCriterion->getLookup(); | ||
| 118 | 119 | ||
| 119 | - // if we're sorting by name or creator_id then sort folders in the appropriate direction | 120 | + $aQuery = $oSortCriterion->folderQuery($iFolderID); |
| 120 | 121 | ||
| 121 | - $aParams = array(); | ||
| 122 | - $sFolderQuery = "SELECT f.id FROM $default->folders_table AS f ";/*ok*/ | ||
| 123 | - if (in_array($this->sSortField, array("name", "creator_id"))) { | ||
| 124 | - if (isset($aLookupCriteria)) { | ||
| 125 | - $sFolderQuery .= "INNER JOIN " . $aLookupCriteria["table"] . " lt ON f.$this->sSortField=lt.id WHERE parent_id = ?"; | ||
| 126 | - $sFolderQuery .= " ORDER BY lt." . $aLookupCriteria["field"] . " $this->sSortDirection"; | ||
| 127 | - } else { | ||
| 128 | - $sFolderQuery .= "WHERE parent_id = ? ORDER BY $this->sSortField $this->sSortDirection"; | ||
| 129 | - } | ||
| 130 | - } else { | ||
| 131 | - $sFolderQuery .= "WHERE parent_id = ? ORDER BY f.name asc"; | 122 | + $oResult = DBUtil::runQuery($aQuery); |
| 123 | + if (PEAR::isError($oResult)) { | ||
| 124 | + var_dump($oResult); | ||
| 125 | + exit(0); | ||
| 132 | } | 126 | } |
| 133 | - $aParams[] = $iFolderID; | ||
| 134 | - $default->log->debug("Ordering folderQuery = $sFolderQuery"); | ||
| 135 | 127 | ||
| 136 | - if ($sql->query(array($sFolderQuery, $aParams))) { | ||
| 137 | - while ($sql->next_record()) { | ||
| 138 | - $default->log->debug("In folder iteration while, with folder_id " . $sql->f("id")); | 128 | + if ($oResult->numRows()) { |
| 129 | + while ($aRow = $oResult->fetchRow()) { | ||
| 130 | + $default->log->debug("In folder iteration while, with folder_id " . $aRow["id"]); | ||
| 139 | // check whether to display folders which are not readable and display/hide these accordingly | 131 | // check whether to display folders which are not readable and display/hide these accordingly |
| 140 | - $oFolder = Folder::get($sql->f("id")); | 132 | + $oFolder = Folder::get($aRow["id"]); |
| 141 | if ($default->folderHidingFlag) { | 133 | if ($default->folderHidingFlag) { |
| 142 | if (Permission::userHasFolderReadPermission($oFolder)) { | 134 | if (Permission::userHasFolderReadPermission($oFolder)) { |
| 143 | - $default->log->debug("FOLDER PERMISSIONS: Does have permission for folder " . $oFolder->getID() . ":" . $sql->f("id") ); | 135 | + $default->log->debug("FOLDER PERMISSIONS: Does have permission for folder " . $oFolder->getID() . ":" . $aRow["id"]); |
| 144 | $results["folders"][] = $oFolder; | 136 | $results["folders"][] = $oFolder; |
| 145 | } else { | 137 | } else { |
| 146 | - $default->log->debug("FOLDER PERMISSIONS: Does NOT have permission for folder " . $sql->f("id") ); | 138 | + $default->log->debug("FOLDER PERMISSIONS: Does NOT have permission for folder " . $aRow["id"] ); |
| 147 | } | 139 | } |
| 148 | } else{ | 140 | } else{ |
| 149 | $results["folders"][] = $oFolder; | 141 | $results["folders"][] = $oFolder; |
| @@ -153,29 +145,21 @@ class FolderBrowser extends Browser { | @@ -153,29 +145,21 @@ class FolderBrowser extends Browser { | ||
| 153 | 145 | ||
| 154 | $default->log->debug("Going on to document checking"); | 146 | $default->log->debug("Going on to document checking"); |
| 155 | 147 | ||
| 156 | - // create query to retrieve documents in this folder | ||
| 157 | - $documentQuery = "SELECT d.id as id FROM $default->documents_table AS d ";/*wc*/ | ||
| 158 | - if (isset($aLookupCriteria)) { | ||
| 159 | - $documentQuery .= "INNER JOIN " . $aLookupCriteria["table"] . " lt ON "; | ||
| 160 | - $documentQuery .= "d.$this->sSortField" . "=lt." . (isset($aLookupCriteria["joinColumn"]) ? $aLookupCriteria["joinColumn"] : "id"); | 148 | + $aQuery = $oSortCriterion->documentQuery($iFolderID); |
| 149 | + $oResult = DBUtil::runQuery($aQuery); | ||
| 150 | + if (PEAR::isError($oResult)) { | ||
| 151 | + var_dump($oResult); | ||
| 152 | + exit(0); | ||
| 161 | } | 153 | } |
| 162 | - $documentQuery .= " WHERE d.folder_id=$iFolderID " . (isset($aLookupCriteria["whereClause"]) ? "AND lt." . $aLookupCriteria["whereClause"] : "") . " "; | ||
| 163 | - if (isset($aLookupCriteria)) { | ||
| 164 | - $documentQuery .= "ORDER BY lt." . $aLookupCriteria["field"] . " $this->sSortDirection"; | ||
| 165 | - } else { | ||
| 166 | - $documentQuery .= "ORDER BY $this->sSortField $this->sSortDirection"; | ||
| 167 | - } | ||
| 168 | - $default->log->debug("docQuery=$documentQuery"); | ||
| 169 | 154 | ||
| 170 | // initialise access flag; | 155 | // initialise access flag; |
| 171 | $results["accessDenied"] = false; | 156 | $results["accessDenied"] = false; |
| 172 | - if ($sql->query($documentQuery)) { | ||
| 173 | - | 157 | + if ($oResult->numRows()) { |
| 174 | // do the check for whether this documents have folder read permission, if they do, it's all good. | 158 | // do the check for whether this documents have folder read permission, if they do, it's all good. |
| 175 | $hasFolderRead = Permission::userHasFolderReadPermission($rootFolder); | 159 | $hasFolderRead = Permission::userHasFolderReadPermission($rootFolder); |
| 176 | 160 | ||
| 177 | - while ($sql->next_record()) { | ||
| 178 | - $oDocument = & Document::get($sql->f("id")); | 161 | + while ($aRow = $oResult->fetchRow()) { |
| 162 | + $oDocument = &Document::get($aRow["id"]); | ||
| 179 | // proceed if the document is live | 163 | // proceed if the document is live |
| 180 | if ($oDocument->isLive()) { | 164 | if ($oDocument->isLive()) { |
| 181 | // check permissions | 165 | // check permissions |
presentation/lookAndFeel/knowledgeTree/documentmanagement/browseBL.php
| @@ -95,7 +95,7 @@ if (!$fSortDirection) { | @@ -95,7 +95,7 @@ if (!$fSortDirection) { | ||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | // fire up the document browser | 97 | // fire up the document browser |
| 98 | -$oBrowser = BrowserFactory::create($fBrowseType, $fSortBy, $fSortDirection); | 98 | +$oBrowser =& BrowserFactory::create($fBrowseType, $fSortBy, $fSortDirection); |
| 99 | $sectionName = $oBrowser->getSectionName(); | 99 | $sectionName = $oBrowser->getSectionName(); |
| 100 | 100 | ||
| 101 | // instantiate my content pattern | 101 | // instantiate my content pattern |
presentation/lookAndFeel/knowledgeTree/documentmanagement/browseUI.inc
| @@ -199,27 +199,24 @@ function renderDocumentTypeResults($aResults) { | @@ -199,27 +199,24 @@ function renderDocumentTypeResults($aResults) { | ||
| 199 | */ | 199 | */ |
| 200 | function renderFolderResults($aResults, $bTemplateBrowsing = false) { | 200 | function renderFolderResults($aResults, $bTemplateBrowsing = false) { |
| 201 | global $default; | 201 | global $default; |
| 202 | + global $oBrowser; | ||
| 202 | $sToRender = ""; | 203 | $sToRender = ""; |
| 203 | 204 | ||
| 204 | // now loop through the rest of the folders and display links | 205 | // now loop through the rest of the folders and display links |
| 205 | if (count($aResults["folders"]) > 1) { | 206 | if (count($aResults["folders"]) > 1) { |
| 206 | for ($i=1; $i<count($aResults["folders"]); $i++) { | 207 | for ($i=1; $i<count($aResults["folders"]); $i++) { |
| 208 | + $oFolder = $aResults["folders"][$i]; | ||
| 209 | + | ||
| 207 | $sFolderLink = displayFolderLink($aResults["folders"][$i]); | 210 | $sFolderLink = displayFolderLink($aResults["folders"][$i]); |
| 208 | $oCreator = User::get($aResults["folders"][$i]->getCreatorID()); | 211 | $oCreator = User::get($aResults["folders"][$i]->getCreatorID()); |
| 209 | 212 | ||
| 210 | // the first element of the array contains the current folder name | 213 | // the first element of the array contains the current folder name |
| 211 | $sToRender .= "<tr bgcolor=\"" . getColour($i-1) . "\">\n"; | 214 | $sToRender .= "<tr bgcolor=\"" . getColour($i-1) . "\">\n"; |
| 212 | $sToRender .= "<td width=\"10\"> </td>\n"; // for the checkboxes | 215 | $sToRender .= "<td width=\"10\"> </td>\n"; // for the checkboxes |
| 213 | - // folder name | ||
| 214 | - $sToRender .= "<td valign=\"bottom\">" . $sFolderLink . "</td>\n"; | ||
| 215 | - // blank filename (folder description?) | ||
| 216 | - $sToRender .= "<td valign=\"bottom\">" . $aResults["folders"][$i]->getDescription() . "</td>\n"; | ||
| 217 | - // creator name | ||
| 218 | - $sToRender .= "<td valign=\"bottom\">" . ($oCreator ? $oCreator->getName() : " ") . "</td>\n"; | ||
| 219 | - // modified date (TODO: add to db) | ||
| 220 | - $sToRender .= "<td valign=\"bottom\"> </td>\n"; | ||
| 221 | - // document type (??: display one of the mapped document types? which one?) | ||
| 222 | - $sToRender .= "<td valign=\"bottom\"> </td>\n"; | 216 | + |
| 217 | + foreach (array_values($oBrowser->getSortCriteria()) as $oCriterion) { | ||
| 218 | + $sToRender .= "<td valign=\"bottom\">" . $oCriterion->folderDisplay($oFolder) . "</td>\n"; | ||
| 219 | + } | ||
| 223 | $sToRender .= "</tr>\n"; | 220 | $sToRender .= "</tr>\n"; |
| 224 | } | 221 | } |
| 225 | } else { | 222 | } else { |
| @@ -254,7 +251,11 @@ function renderSortHeadings($sSortBy, $sSortDirection) { | @@ -254,7 +251,11 @@ function renderSortHeadings($sSortBy, $sSortDirection) { | ||
| 254 | $sToRender .= "<td width=\"10\"> </td>\n"; // For the checkboxes | 251 | $sToRender .= "<td width=\"10\"> </td>\n"; // For the checkboxes |
| 255 | while (list($key, $value) = each ($aSortCriteria)) { | 252 | while (list($key, $value) = each ($aSortCriteria)) { |
| 256 | $sCurrentSortDirection = "asc"; | 253 | $sCurrentSortDirection = "asc"; |
| 257 | - $displayText = $value["display"]; | 254 | + if (is_array($value)) { |
| 255 | + $displayText = $value["display"]; | ||
| 256 | + } else { | ||
| 257 | + $displayText = $value->headerDisplay(); | ||
| 258 | + } | ||
| 258 | // if the current heading is being sorted then flip the sort direction | 259 | // if the current heading is being sorted then flip the sort direction |
| 259 | if ($sSortBy == $key) { | 260 | if ($sSortBy == $key) { |
| 260 | $sCurrentSortDirection = ($sSortDirection == "asc" ? "desc" : "asc"); | 261 | $sCurrentSortDirection = ($sSortDirection == "asc" ? "desc" : "asc"); |
| @@ -288,6 +289,14 @@ function renderSortHeadings($sSortBy, $sSortDirection) { | @@ -288,6 +289,14 @@ function renderSortHeadings($sSortBy, $sSortDirection) { | ||
| 288 | */ | 289 | */ |
| 289 | function renderDocumentList($aResults, $sNoDocumentsMessage, $sNoPermissionMessage, $bDisplayFullPath = false, $bTemplateBrowsing = false) { | 290 | function renderDocumentList($aResults, $sNoDocumentsMessage, $sNoPermissionMessage, $bDisplayFullPath = false, $bTemplateBrowsing = false) { |
| 290 | global $default; | 291 | global $default; |
| 292 | + global $oBrowser; | ||
| 293 | + | ||
| 294 | + $oBrowser->setOptions(array( | ||
| 295 | + 'displayFullPath' => $bDisplayFullPath, | ||
| 296 | + 'templateBrowsing' => $bTemplateBrowsing, | ||
| 297 | + )); | ||
| 298 | + | ||
| 299 | + $aSortCriteria = $oBrowser->getSortCriteria(); | ||
| 291 | 300 | ||
| 292 | $iFolderCount = count($aResults["folders"]) - 1; | 301 | $iFolderCount = count($aResults["folders"]) - 1; |
| 293 | // loop through the files and display links | 302 | // loop through the files and display links |
| @@ -295,21 +304,23 @@ function renderDocumentList($aResults, $sNoDocumentsMessage, $sNoPermissionMessa | @@ -295,21 +304,23 @@ function renderDocumentList($aResults, $sNoDocumentsMessage, $sNoPermissionMessa | ||
| 295 | for ($i=0; $i<count($aResults["documents"]); $i++) { | 304 | for ($i=0; $i<count($aResults["documents"]); $i++) { |
| 296 | // in order for candy striping to work we need to take the number of folders | 305 | // in order for candy striping to work we need to take the number of folders |
| 297 | // into account when alternating | 306 | // into account when alternating |
| 307 | + $oDocument = $aResults["documents"][$i]; | ||
| 308 | + | ||
| 298 | $sToRender .= "<tr bgcolor=\"" . getColour($i+$iFolderCount) . "\" width=\"100%\">\n"; | 309 | $sToRender .= "<tr bgcolor=\"" . getColour($i+$iFolderCount) . "\" width=\"100%\">\n"; |
| 299 | $sToRender .= "<td valign=\"bottom\" width=\"10\">" . | 310 | $sToRender .= "<td valign=\"bottom\" width=\"10\">" . |
| 300 | "<input type=\"checkbox\" name=\"fDocumentIDs[]\" value=\"" . $aResults["documents"][$i]->getID() . "\"/></td>\n"; | 311 | "<input type=\"checkbox\" name=\"fDocumentIDs[]\" value=\"" . $aResults["documents"][$i]->getID() . "\"/></td>\n"; |
| 301 | - $sToRender .= "<td>" . ($bTemplateBrowsing ? displayDocumentLinkForTemplateBrowsing($aResults["documents"][$i], $bDisplayFullPath) : | ||
| 302 | - displayDocumentLink($aResults["documents"][$i], $bDisplayFullPath)) . "</td>"; | ||
| 303 | - // #3425 the title is now the filename, and the description is the title | ||
| 304 | - $sToRender .= "<td valign=\"bottom\">" . $aResults["documents"][$i]->getName() . "</td>"; | ||
| 305 | - $oCreator = User::get($aResults["documents"][$i]->getCreatorID()); | ||
| 306 | - $sToRender .= "<td valign=\"bottom\">" . ($oCreator ? $oCreator->getName() : "") . "</td>"; | ||
| 307 | - $aDocumentTransaction = DocumentTransaction::getList("transaction_id=1 AND document_id=" . $aResults["documents"][$i]->getID()); | ||
| 308 | - $sToRender .= "<td valign=\"bottom\">" . $aDocumentTransaction[0]->dDateTime . "</td>"; | ||
| 309 | - $oDocumentType = DocumentType::get($aResults["documents"][$i]->getDocumentTypeID()); | ||
| 310 | - if ($oDocumentType) { | ||
| 311 | - $sToRender .= "<td valign=\"bottom\">" . $oDocumentType->getName() . "</td>"; | 312 | + |
| 313 | + /*$sToRender .= "<td valign=\"bottom\">" . $aSortCriteria["name"]->documentDisplay($oDocument) . "</td>"; | ||
| 314 | + $sToRender .= "<td valign=\"bottom\">" . $aSortCriteria["filename"]->documentDisplay($oDocument) . "</td>"; | ||
| 315 | + $sToRender .= "<td valign=\"bottom\">" . $aSortCriteria["creator_id"]->documentDisplay($oDocument) . "</td>"; | ||
| 316 | + $sToRender .= "<td valign=\"bottom\">" . $aSortCriteria['id']->documentDisplay($oDocument) . "</td>"; | ||
| 317 | + $sToRender .= "<td valign=\"bottom\">" . $aSortCriteria['document_type_id']->documentDisplay($oDocument) . "</td>"; | ||
| 318 | + $sToRender .= "<td valign=\"bottom\">" . $aSortCriteria['category']->documentDisplay($oDocument) . "</td>"; | ||
| 319 | + */ | ||
| 320 | + foreach (array_values($aSortCriteria) as $oCriterion) { | ||
| 321 | + $sToRender .= "<td valign=\"bottom\">" . $oCriterion->documentDisplay($oDocument) . "</td>"; | ||
| 312 | } | 322 | } |
| 323 | + | ||
| 313 | $sToRender .= "</tr>\n"; | 324 | $sToRender .= "</tr>\n"; |
| 314 | } | 325 | } |
| 315 | 326 |