diff --git a/lib/browse/BrowseColumns.inc.php b/lib/browse/BrowseColumns.inc.php index d9fd176..257b32d 100644 --- a/lib/browse/BrowseColumns.inc.php +++ b/lib/browse/BrowseColumns.inc.php @@ -13,7 +13,7 @@ */ require_once(KT_LIB_DIR . "/database/dbutil.inc"); - +require_once(KT_LIB_DIR . '/users/User.inc'); class BrowseColumn { var $label = null; var $sort_on = false; @@ -173,6 +173,50 @@ class DateColumn extends BrowseColumn { } } + +class UserColumn extends BrowseColumn { + var $field_function; + + // $sDocumentFieldFunction is _called_ on the document. + function UserColumn($sLabel, $sName, $sDocumentFieldFunction) { + $this->field_function = $sDocumentFieldFunction; + parent::BrowseColumn($sLabel, $sName); + + } + + function renderHeader($sReturnURL) { + $text = $this->label; + $href = $sReturnURL . "&sort_on=" . $this->name . "&sort_order="; + $href .= $this->sort_direction == "asc"? "desc" : "asc" ; + + return ''.$text.''; + + } + + // use inline, since its just too heavy to even _think_ about using smarty. + function renderData($aDataRow) { + $outStr = ''; + $fn = $this->field_function; + $iUserId = null; + if ($aDataRow["type"] == "folder") { + if (method_exists($aDataRow['folder'], $fn)) { + $iUserId = $aDataRow['folder']->$fn(); // FIXME this should check if the function exists first. + } + } else { + if (true) {//(method_exists($aDataRow['document'], $fn)) { + $iUserId = $aDataRow['document']->$fn(); // FIXME this should check if the function exists first. + } + } + $oUser = User::get($iUserId); + if (PEAR::isError($oUser) || $oUser == false) { + $outStr = ' '; + } else { + $outStr = $oUser->getName(); + } + return $outStr; + } +} + // use the _name_ parameter + _f_ + id to create a non-clashing checkbox. class SelectionColumn extends BrowseColumn { diff --git a/presentation/lookAndFeel/knowledgeTree/browse.php b/presentation/lookAndFeel/knowledgeTree/browse.php index 26653c1..a9a2488 100644 --- a/presentation/lookAndFeel/knowledgeTree/browse.php +++ b/presentation/lookAndFeel/knowledgeTree/browse.php @@ -79,8 +79,7 @@ class BrowseDispatcher extends KTStandardDispatcher { $collection->addColumn(new TitleColumn("Test 1 (title)","title")); $collection->addColumn(new DateColumn("Created","created", "getCreatedDateTime")); $collection->addColumn(new DateColumn("Last Modified","modified", "getLastModifiedDate")); - $collection->addColumn(new BrowseColumn("Test 3","test3")); - $collection->addColumn(new BrowseColumn("Test 4","test4")); + $collection->addColumn(new UserColumn('Creator','creator_id','getCreatorID')); $this->aBreadcrumbs = array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForFolder($this->oFolder));