Commit f4d46d7388325786d31b60670c0232aab6af8e1e

Authored by Brad Shuttleworth
1 parent ac8057ba

brought browse.php to near-parity: all the basic columns are now in place.

- sorting appears to still have a few glitches.
- metadata columns are _not_ available, though they shouldn't be too difficult.
- the columns are hardcoded:  we require at least title and selector, the rest should
  be moved into the db.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4230 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/browse/BrowseColumns.inc.php
... ... @@ -13,7 +13,7 @@
13 13 */
14 14  
15 15 require_once(KT_LIB_DIR . "/database/dbutil.inc");
16   -
  16 +require_once(KT_LIB_DIR . '/users/User.inc');
17 17 class BrowseColumn {
18 18 var $label = null;
19 19 var $sort_on = false;
... ... @@ -173,6 +173,50 @@ class DateColumn extends BrowseColumn {
173 173 }
174 174 }
175 175  
  176 +
  177 +class UserColumn extends BrowseColumn {
  178 + var $field_function;
  179 +
  180 + // $sDocumentFieldFunction is _called_ on the document.
  181 + function UserColumn($sLabel, $sName, $sDocumentFieldFunction) {
  182 + $this->field_function = $sDocumentFieldFunction;
  183 + parent::BrowseColumn($sLabel, $sName);
  184 +
  185 + }
  186 +
  187 + function renderHeader($sReturnURL) {
  188 + $text = $this->label;
  189 + $href = $sReturnURL . "&sort_on=" . $this->name . "&sort_order=";
  190 + $href .= $this->sort_direction == "asc"? "desc" : "asc" ;
  191 +
  192 + return '<a href="' . $href . '">'.$text.'</a>';
  193 +
  194 + }
  195 +
  196 + // use inline, since its just too heavy to even _think_ about using smarty.
  197 + function renderData($aDataRow) {
  198 + $outStr = '';
  199 + $fn = $this->field_function;
  200 + $iUserId = null;
  201 + if ($aDataRow["type"] == "folder") {
  202 + if (method_exists($aDataRow['folder'], $fn)) {
  203 + $iUserId = $aDataRow['folder']->$fn(); // FIXME this should check if the function exists first.
  204 + }
  205 + } else {
  206 + if (true) {//(method_exists($aDataRow['document'], $fn)) {
  207 + $iUserId = $aDataRow['document']->$fn(); // FIXME this should check if the function exists first.
  208 + }
  209 + }
  210 + $oUser = User::get($iUserId);
  211 + if (PEAR::isError($oUser) || $oUser == false) {
  212 + $outStr = '&nbsp;';
  213 + } else {
  214 + $outStr = $oUser->getName();
  215 + }
  216 + return $outStr;
  217 + }
  218 +}
  219 +
176 220 // use the _name_ parameter + _f_ + id to create a non-clashing checkbox.
177 221  
178 222 class SelectionColumn extends BrowseColumn {
... ...
presentation/lookAndFeel/knowledgeTree/browse.php
... ... @@ -79,8 +79,7 @@ class BrowseDispatcher extends KTStandardDispatcher {
79 79 $collection->addColumn(new TitleColumn("Test 1 (title)","title"));
80 80 $collection->addColumn(new DateColumn("Created","created", "getCreatedDateTime"));
81 81 $collection->addColumn(new DateColumn("Last Modified","modified", "getLastModifiedDate"));
82   - $collection->addColumn(new BrowseColumn("Test 3","test3"));
83   - $collection->addColumn(new BrowseColumn("Test 4","test4"));
  82 + $collection->addColumn(new UserColumn('Creator','creator_id','getCreatorID'));
84 83  
85 84 $this->aBreadcrumbs = array_merge($this->aBreadcrumbs,
86 85 KTBrowseUtil::breadcrumbsForFolder($this->oFolder));
... ...