diff --git a/plugins/ktstandard/KTDiscussion.php b/plugins/ktstandard/KTDiscussion.php
index ae47385..cd3e82b 100644
--- a/plugins/ktstandard/KTDiscussion.php
+++ b/plugins/ktstandard/KTDiscussion.php
@@ -1,13 +1,194 @@
oThread = $oThread;
+ $oTemplate = $context->oValidator->validateTemplate('ktstandard/action/discussion_thread_list_item');
+ $oFirstComment = DiscussionComment::get($oThread->getFirstCommentId());
+ if (PEAR::isError($oFirstComment)) {
+ return null;
+ }
+ $oLastComment = DiscussionComment::get($oThread->getLastCommentId());
+ if (PEAR::isError($oLastComment)) {
+ return null;
+ }
+ $oCreator = User::get($oThread->getCreatorId());
+ $oTemplate->setData(array(
+ 'thread' => $this->oThread,
+ 'first_comment' => $oFirstComment,
+ 'last_comment' => $oLastComment,
+ 'creator' => $oCreator,
+ 'context' => $context,
+ ));
+ return $oTemplate->render();
+ }
+}
+
+class KTCommentListRenderer {
+ function render($context, $oComment) {
+ $this->oComment = $oComment;
+ $oTemplate = $context->oValidator->validateTemplate('ktstandard/action/discussion_comment_list_item');
+ $oCreator = User::get($oComment->getUserId());
+ $oTemplate->setData(array(
+ 'comment' => $oComment,
+ 'creator' => $oCreator,
+ 'context' => $context,
+ ));
+ return $oTemplate->render();
+ }
+}
+
+class KTDocumentDiscussionAction extends KTDocumentAction {
var $sBuiltInAction = 'viewDiscussion';
var $sDisplayName = 'Discussion';
var $sName = 'ktcore.actions.document.discussion';
+
+ function do_main() {
+ $this->oPage->setBreadcrumbDetails("discussion");
+ $oTemplate =& $this->oValidator->validateTemplate('ktstandard/action/discussion');
+
+ // Fields for new thread creation
+ $fields = array();
+ $fields[] = new KTStringWidget("Subject", "The topic of discussion in this thread", "subject", "", $this->oPage, true);
+ $fields[] = new KTTextWidget("Body", "Your contribution to the discussion in this thread", "body", "", $this->oPage, true, null, null, array("cols" => 50, "rows" => 10));
+
+ $threads = DiscussionThread::getList();
+
+ $aTemplateData = array(
+ 'context' => &$this,
+ 'fields' => $fields,
+ 'threads' => $threads,
+ 'threadrenderer' => new KTDiscussionThreadListRenderer(),
+ );
+ return $oTemplate->render($aTemplateData);
+ }
+
+ function do_newthread() {
+ $aErrorOptions = array(
+ 'redirect_to' => array('main', sprintf('fDocumentId=%d', $this->oDocument->getId())),
+ );
+
+ $aErrorOptions['message'] = "No subject provided";
+ $sSubject = KTUtil::arrayGet($_REQUEST, 'subject');
+ $sSubject = $this->oValidator->validateString($sSubject, $aErrorOptions);
+
+ $aErrorOptions['message'] = "No body provided";
+ $sBody = KTUtil::arrayGet($_REQUEST, 'body');
+ $sBody = $this->oValidator->validateString($sBody, $aErrorOptions);
+
+ // Start the transaction around thread and comment creation
+ $this->startTransaction();
+
+ $oThread = DiscussionThread::createFromArray(array(
+ 'documentid' => $this->oDocument->getId(),
+ 'creatorid' => $this->oUser->getId(),
+ ));
+ $aErrorOptions['message'] = "There was an error creating a new thread";
+ $this->oValidator->notError($oThread);
+
+ $oComment = DiscussionComment::createFromArray(array(
+ 'threadid' => $oThread->getId(),
+ 'userid' => $this->oUser->getId(),
+ 'subject' => $sSubject,
+ 'body' => $sBody,
+ ));
+ $aErrorOptions['message'] = "There was an error adding the comment to the thread";
+ $this->oValidator->notError($oComment);
+
+ $oThread->setFirstCommentId($oComment->getId());
+ $oThread->setLastCommentId($oComment->getId());
+ $res = $oThread->update();
+ $aErrorOptions['message'] = "There was an error updating the thread with the new comment";
+ $this->oValidator->notError($res);
+
+ // Thread and comment created correctly, commit to database
+ $this->commitTransaction();
+
+ $this->successRedirectToMain("New thread created", sprintf('fDocumentId=%d', $this->oDocument->getId()));
+ exit(0);
+ }
+
+ function do_viewthread() {
+ $iThreadId = KTUtil::arrayGet($_REQUEST, 'fThreadId');
+ $oThread = DiscussionThread::get($iThreadId);
+
+ $iCommentId = $oThread->getFirstCommentId();
+ $oComment = DiscussionComment::get($iCommentId);
+
+ $this->aBreadcrumbs[] = array(
+ 'name' => 'discussion',
+ 'url' => $_SERVER['PHP_SELF'] . sprintf('?fDocumentId=%d', $this->oDocument->getId()),
+ );
+ $this->aBreadcrumbs[] = array(
+ 'name' => $oComment->getSubject(),
+ );
+ $this->oPage->setBreadcrumbDetails("viewing comments");
+ $oTemplate =& $this->oValidator->validateTemplate('ktstandard/action/discussion_thread');
+ // Fields for new thread creation
+ $fields = array();
+ $fields[] = new KTStringWidget("Subject", "The topic of discussion in this thread", "subject", "", $this->oPage, true);
+ $fields[] = new KTTextWidget("Body", "Your contribution to the discussion in this thread", "body", "", $this->oPage, true, null, null, array("cols" => 50, "rows" => 10));
+
+ $aTemplateData = array(
+ 'context' => &$this,
+ 'fields' => $fields,
+ 'thread' => $oThread,
+ 'commentrenderer' => new KTCommentListRenderer(),
+ );
+ return $oTemplate->render($aTemplateData);
+ }
+
+ function do_postreply() {
+ $aErrorOptions = array(
+ 'redirect_to' => array('main', sprintf('fDocumentId=%d', $this->oDocument->getId())),
+ );
+ $iThreadId = KTUtil::arrayGet($_REQUEST, 'fThreadId');
+ $oThread = DiscussionThread::get($iThreadId);
+
+ $this->oValidator->notError($oThread, $aErrorOptions);
+
+ $aErrorOptions = array(
+ 'redirect_to' => array('viewthread', sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId())),
+ );
+
+
+ $aErrorOptions['message'] = "No subject provided";
+ $sSubject = KTUtil::arrayGet($_REQUEST, 'subject');
+ $sSubject = $this->oValidator->validateString($sSubject, $aErrorOptions);
+
+ $aErrorOptions['message'] = "No body provided";
+ $sBody = KTUtil::arrayGet($_REQUEST, 'body');
+ $sBody = $this->oValidator->validateString($sBody, $aErrorOptions);
+
+ // Start the transaction comment creation
+ $this->startTransaction();
+
+ $oComment = DiscussionComment::createFromArray(array(
+ 'threadid' => $oThread->getId(),
+ 'userid' => $this->oUser->getId(),
+ 'subject' => $sSubject,
+ 'body' => $sBody,
+ ));
+ $aErrorOptions['message'] = "There was an error adding the comment to the thread";
+ $this->oValidator->notError($oComment, $aErrorOptions);
+
+ $oThread->setLastCommentId($oComment->getId());
+ $res = $oThread->update();
+ $aErrorOptions['message'] = "There was an error updating the thread with the new comment";
+ $this->oValidator->notError($res, $aErrorOptions);
+
+ // Thread and comment created correctly, commit to database
+ $this->commitTransaction();
+
+ $this->successRedirectTo('viewThread', "Reply posted", sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId()));
+ exit(0);
+ }
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentDiscussionAction', 'ktcore.actions.document.discussion');
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
deleted file mode 100644
index a5b1702..0000000
--- a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php
+++ /dev/null
@@ -1,141 +0,0 @@
-fileSystemRoot/lib/visualpatterns/PatternCreate.inc");
-require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");
-require_once("addCommentUI.inc"); //###
-require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
-require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
-require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
-require_once("$default->fileSystemRoot/lib/users/User.inc");
-require_once("$default->fileSystemRoot/lib/security/Permission.inc");
-require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
-require_once("$default->fileSystemRoot/lib/discussions/DiscussionThread.inc"); //###
-require_once("$default->fileSystemRoot/lib/discussions/DiscussionComment.inc"); //###
-require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/documentUI.inc");
-require_once("$default->fileSystemRoot/presentation/Html.inc");
-
-if(checkSession()) {
- $oPatternCustom = & new PatternCustom();
- require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
- if (isset($fAddCommentSubmit)) {
- $default->log->info("adding comment: subject=$fSubject; comment=$fComment");
- if ( (strlen($fSubject) > 0) && (strlen($fComment) > 0) ) {
- // create a new thread, unless we're replying
- if (isset($fNewThread)) {
- $oThread = & new DiscussionThread(-1, $fDocumentID, $_SESSION["userID"]);
- $oThread->create();
- $iThreadID = $oThread->getID();
- // if this is a new thread, then set inReplyTo to -1
- $fInReplyTo = -1;
- } else {
- // replying
- // retrieve the thread id
- //$iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID);
- $default->log->info("adding comment: SEtting thread id: " . $fThreadID);
- $iThreadID = $fThreadID;
- }
- if ($iThreadID) {
- $default->log->info("addComment fInReplyTo=$fInReplyTo, threadID=$iThreadID");
- // Create the new comment
- $oComment = & new DiscussionComment($fComment, $fSubject, $_SESSION["userID"], $iThreadID, $fInReplyTo);
- $oComment->setThreadID($iThreadID);
- $oComment->create();
-
- if($oComment->getID() > 0) {
- $oThread = DiscussionThread::get($iThreadID);
- $oThread->setLastCommentID($oComment->getID());
- if ($oThread->getFirstCommentID() == -1){ // if it is a new Thread
- $oThread->setFirstCommentID($oComment->getID());
- }
- // Session variable is set to true if user views the thread
- if ($_SESSION['Discussion' . $fDocumentID][0]->bViews != true ){
- $oThread->incrementNumberOfViews();
- $_SESSION['Discussion' . $fDocumentID][0]->bViews = true;
- }
- $oThread->incrementNumberOfReplies();
-
- if ($oThread->Update()) { //
- controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$fDocumentID");
- //$oPatternCustom->addHtml(getSubmitSuccessPage($fDocumentID));
- } else {
- $main->setErrorMessage(_("Thread Object failed to update"));
- }
- } else {
- $main->setErrorMessage(_("Comment Object failed in creation"));
- }
- } else {
- $main->setErrorMessage(_("Could not create a new discussion thread."));
- }
- } else { // the user has not entered BOTH a subject and a text body
- $main->setErrorMessage(_("The subject line and/or body should not be empty."));
- $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&fDocumentID=$fDocumentID");
- $oPatternCustom->addHtml(getAddComment($fDocumentID, $fSubject, $fComment, $fCommentID, 1, $fThreadID));
- } // end of IF for Subject and Body test
- } else if (isset($fReplyComment)) { // if user is replying to existing comment
- $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&fDocumentID=$fDocumentID");
-
- $oComment = DiscussionComment::get($fCommentID);
- $oUser = User::get($oComment->getUserID());
-
- $sReplyBody = $oComment->getBody();
-
- $sReplyBodyHeader .= "\n\n> ------ Original Message ------";
- $sReplyBodyHeader .= "\n> User: " . $oUser->getName();
- $sReplyBodyHeader .= "\n> Date: " . $oComment->getDate();
- $sReplyBodyHeader .= "\n> Subject: " . $oComment->getSubject();
- $sReplyBodyHeader .= "\n> ---------------------------------------";
- $default->log->info("replyBody before=$sReplyBody; replyBodyAfter=" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody));
- $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace(">" ,"> >", $sReplyBody); // Put in ">" as indentation for the reply
- //$sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply
-
- if (strpos($oComment->getSubject(), "Re:") != " "){
- $sReply = "Re: ";
- } else { $sReply = ""; }
-
- $oPatternCustom->addHtml(getAddComment($fDocumentID, $sReply . $oComment->getSubject() , urldecode($sReplyBody), $fCommentID, "-1" , $fThreadID));
-
- } else if (isset($fNewThread)){ // Start adding a new Thread
- $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&fDocumentID=$fDocumentID&fNewThread=1");
- $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject ,$Comment, $fCommentID, "1", $fThreadID));
- } else {
- // input validation
- if (isset($fDocumentID)) {
- $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&fDocumentID=$fDocumentID");
- $oPatternCustom->setHtml(getAddComment($fDocumentID,$sSubject,$sBody, $fCommentID, 1, $fThreadID));
- } else {
- $main->setErrorMessage(_("You did not specify a document to add a comment to."));
- }
- }
- $main->setCentralPayload($oPatternCustom);
- $main->render();
-}
-?>
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
deleted file mode 100644
index a27e0d8..0000000
--- a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc
+++ /dev/null
@@ -1,99 +0,0 @@
- a valid Document ID
- */
-function getSubmitSuccessPage($iDocumentID){
- global $default;
- $sMessage = _("Your submission has been successful.");
- $sToRender .= "$sMessage
";
-
- return $sToRender;
-}
-
-/**
- * Display the ADD COMMENT page
- *
- * @param $iDocumentID -> a valid Document ID
- * @param $sSubject -> a Subject text
- * @param $sBody -> a Body text
- */
-function getAddComment($iDocumentID, $sSubject, $sBody, $iCommentID, $iNewComment = null, $iThreadID) {
- global $default;
-
- $sHeading = _("Add a Comment");
- $sToRender .= renderHeading($sHeading);
- $sToRender .= displayDocumentPath($iDocumentID);
- $sToRender .= "
\n";
- return $sToRender;
-}
-
-/**
- * Display the comment: Body text included
- * Prints out 1 comment
- * User needs to call this function many times to list all comments
- *
- * @param $sCommentBody -> Some body text
- * @param $iComment Subject -> Some subject text
- * @param $dDate -> Date comment was created
- * @param $iDocumentID -> a valid document ID
- * @param $sUserName -> Name of creator of comment
- */
-function getCommentBody($sCommentBody, $sCommentSubject,$dDate,$iDocumentID, $sUserName) {
- global $default;
-
- $sHeading = _("Document Comment");
-
- $sToRender .= renderHeading($sHeading);
- $sToRender .= displayDocumentPath($iDocumentID);
- $sToRender .= "
Author: $sUserName";
- $sToRender .= "";
- $sToRender .= "| " . _("Subject") . ": | $sCommentSubject | ";
- $sToRender .= "" . _("Date") . ": $dDate |
$sCommentBody | ";
- $sToRender .= "
";
- return $sToRender;
-}
-
-?>
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewCommentBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/viewCommentBL.php
deleted file mode 100644
index f749e0e..0000000
--- a/presentation/lookAndFeel/knowledgeTree/discussions/viewCommentBL.php
+++ /dev/null
@@ -1,57 +0,0 @@
-fileSystemRoot/lib/users/User.inc");
-require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
-require_once("$default->fileSystemRoot/lib/security/Permission.inc");
-require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
-require_once("$default->fileSystemRoot/lib/discussions/DiscussionThread.inc");
-require_once("$default->fileSystemRoot/lib/discussions/DiscussionComment.inc");
-require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/documentUI.inc");
-require_once("$default->fileSystemRoot/presentation/Html.inc");
-
-KTUtil::extractGPC('fCommentID', 'fDocumentID', 'fThreadID');
-
-if (checkSession()) {
- require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
- $oPatternCustom = & new PatternCustom();
-
- // validate input parameters
- if (isset($fCommentID) && isset($fDocumentID)) {
- $oComment = DiscussionComment::get($fCommentID);
- $oUser = User::get($oComment->getUserID());
- $main->setFormAction("$default->rootUrl/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php?fDocumentID=$iDocumentID&fCommentID=$iCommentID&fReplyComment=1");
- $oPatternCustom->setHtml(getCommentBody($oComment,$fDocumentID,$oUser,$fThreadID));
- } else {
- $main->setErrorMessage(_("You didn't specify a comment to view"));
- }
- $main->setCentralPayload($oPatternCustom);
- $main->render();
-}
-?>
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewCommentUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/viewCommentUI.inc
deleted file mode 100644
index 60f081e..0000000
--- a/presentation/lookAndFeel/knowledgeTree/discussions/viewCommentUI.inc
+++ /dev/null
@@ -1,79 +0,0 @@
- a valid Document ID
- * @param $oComment -> a valid Comment Object
- * @param $oUser -> a valid User Object (Logged in user)
- * @param $iThreadID -> the ThreadID passed through
- */
-function getCommentBody($oComment, $iDocumentID, $oUser, $iThreadID) {
- global $default;
-
- $sHeading = _("Document Comment");
-
- $sToRender .= renderHeading($sHeading);
- $sToRender .= displayDocumentPath($iDocumentID);
- $aBody = explode("\n",$oComment->getBody());
- $sBody = "";
- $numChars = 160; // number of chars in a line
-
- // Used for wrapping text that may be too long on one any line
- for ($i=0; $i <= sizeof($aBody) ;$i++) {
- if (strlen($aBody[$i]) >$numChars){
- $loop = (strlen($aBody[$i]) - (strlen($aBody[$i])) % $numChars)/$numChars +1;
-
- $j=$numChars;
- for($j=0; $j < $loop; $j++ ) {
- $sBody .= "
" . substr($aBody[$i],($j*$numChars), $numChars) . "";
- }
- } else { $sBody .= "
" . $aBody[$i]; }
- }
-
-// $sToRender .= "Views: " . $oThread->getNumberOfViews() . " | ";
-// $sToRender .= " | ";
-// $sToRender .= "Replies: " . $oThread->getNumberOfReplies() . " | ";
-
- $sToRender .= "
| Author: " . $oUser->getUserName() . " | \n";
- $sToRender .= "\n";
- $sToRender .= "getID()) . "&fThreadID=" . $iThreadID . "\"> ";
- $sToRender .= " |  |
\n";
- $sToRender .= "| " . _("Subject") . ": | ";
- $sToRender .= $oComment->getSubject();
- $sToRender .= " | " . _("Date") . ": " . $oComment->getDate() . " |
";
- $sToRender .= "| ";
- $sToRender .= $sBody;
- $sToRender .= " | ";
- $sToRender .= " | \n";
-
- $sToRender .= "
";
-
- return $sToRender;
-}
-?>
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php
deleted file mode 100644
index ef77b43..0000000
--- a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php
+++ /dev/null
@@ -1,68 +0,0 @@
-fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
-require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
-require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
-require_once("$default->fileSystemRoot/lib/users/User.inc");
-require_once("$default->fileSystemRoot/lib/security/Permission.inc");
-require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
-require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
-require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListFromQuery.inc");
-require_once("$default->fileSystemRoot/lib/discussions/DiscussionThread.inc");
-require_once("$default->fileSystemRoot/lib/discussions/DiscussionComment.inc");
-require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/documentUI.inc");
-require_once("$default->fileSystemRoot/presentation/Html.inc");
-
-if (checkSession()) {
- require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
- $oPatternCustom = & new PatternCustom();
- if (isset($fForDiscussion)) {
- if (isset($fDocumentID)) {
- $aDocumentThreads = DiscussionThread::getList(array("document_id = ? ORDER BY id", $fDocumentID));/*ok*/
- if (count($aDocumentThreads) > 0) {
- // call the ui function to display the comments
- $oPatternCustom->setHtml(getPage($fDocumentID, $aDocumentThreads));
- } else { // No current thread, option to create one
- $main->setErrorMessage(_("No discussion thread is currently available"));
- $oPatternCustom->addHtml(getNewThreadOption($fDocumentID));
- }
- } else { // Doument id is negative
- $main->setErrorMessage(_("You did not specify a document."));
- }
- } else { // If no discussion exists
- $main->setErrorMessage(_("Invalid function. No such functionality exists for this page."));
- }
- $main->setCentralPayload($oPatternCustom);
- $main->render();
-}
-?>
diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc
deleted file mode 100644
index 964e762..0000000
--- a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc
+++ /dev/null
@@ -1,162 +0,0 @@
-\n";
- $sToRender .= " | \n";
- $sToRender .= " | \n";
- $sToRender .= "
\n";
- return $sToRender;
-}
-
-// If there are no threads to view for a document
-function getViewFailPage($sMessage) {
- global $default;
- if ( strlen($sMessage)>0 ) {
- $sToRender = $sMessage;
- } else {
- $sToRender = _("Current document has no discussion. Press the ADD button to start a discussion.");
- }
- return $sToRender;
-}
-
-/**
- * Page to create a new thread
- *
- * @param $iDocumentID -> a valid document ID
- */
-function getNewThreadOption($iDocumentID) {
- global $default;
- $sToRender .= _("Would you like to create a new Discussion thread for this document?");
- $sToRender .= " ";
- $sToRender .= "
";
- $sToRender .= "
";
- return $sToRender;
-}
-
-/**
- * Views the list of comments for a document
- * Prints out 1 comment
- * User needs to call this function many times to list all comments
- *
- * @param $iNum -> its the iterative index of the current comment
- * @param $iThread -> a valid Thread Object
- * @param $oComment -> a valid Comment Object
- */
-function getViewComment($iNum, $oThread, $oComment, $sIndent) {
- global $default;
-
- $iSubjectChars = 59;
- // If iNum is odd then highlight it
- if (($iNum%2) == 1) $BGcolor = "#F5F6EE";
- if (($iNum%2) == 0) $UserBGcolor = "#F5F6EE";
-
- $sUserName = "";
- $oUser = User::get($oComment->getUserID());
- if ($oUser) {
- $sUserName = $oUser->getName();
- }
- // If the Subject string is too long
- if (strlen($oComment->getSubject())>$iSubjectChars ) $dotdot = " ...";
-
- $sToRender .= "\n";
- $sToRender .= "\t| \n";
- $sToRender .= "\t\t$sIndentgetID() . "&fDocumentID=" . $oThread->getDocumentID() . "&fThreadID=" . $oThread->getID()) . "\" title=\"" . $oComment->getSubject() . "\">\n";
- $sToRender .= substr($oComment->getSubject(),0,$iSubjectChars ) . $dotdot . " | \n";
- $sToRender .= "\t\n";
- $sToRender .= "\t\t$sUserName | \n";
- $sToRender .= "\t" . $oComment->getDate() . " | |
\n";
-
- return $sToRender;
-}
-
-/**
- * Prints out the list of discussion comments
- */
-function getPage($iDocumentID, $aDocumentThreads) {
- global $default;
-
- $sToRender .= renderHeading(_("Document Discussion Comments"));
- $sToRender .= displayDocumentPath($iDocumentID);
- $sToRender .= getPageButtons($iDocumentID);
- $sToRender .= "\n";
- $sToRender .= "\n";
- $sToRender .= "| " . _("Subject") . " | \n";
- $sToRender .= "" . _("Author") . " | \n";
- $sToRender .= "" . _("Date") . " | \n";
- $sToRender .= "
\n";
-
- $iCount = 0;
- // for each thread, retrieve all comments
- for ($i=0; $igetID(), -1);
- // now loop through the comments, and indent comments that have the same reply_to at the same level .... ??
- for ($j=0; $jlog->info("commentTree[$j][comment]=" . arrayToString($aCommentTree[$j]["comment"]));
- $sToRender .= getViewComment($iCount++, $aDocumentThreads[$i], $aCommentTree[$j]["comment"], getIndent($aCommentTree[$j]["level"]));
- }
- }
- }
- $sToRender .= "\n
\n\n";
- return $sToRender;
-}
-/**
- * Returns the comments for a particular thread
- */
-function getCommentTree($iThreadID, $iReplyTo, $iLevel = 0) {
- global $default;
- // find all comments for the specified thread and reply
- $aWhereClause = array("thread_id = ? AND in_reply_to = ? ORDER BY id", array($iThreadID, $iReplyTo));
- $aComments = DiscussionComment::getList($aWhereClause);/*ok*/
- // loop through these and find their children
- for ($i=0; $i $aComments[$i], "level" => $iLevel);
- $aChildren = getCommentTree($iThreadID, $aComments[$i]->getID(), $iLevel+1);
- if (count($aChildren) > 0) {
- $aTree = array_merge($aTree, $aChildren);
- }
- }
- $default->log->debug("getCommentTree($iThreadID, $iReplyTo, $iLevel), returning " . arrayToString($aTree));
- return $aTree;
-}
-
-/**
- * Returns an indent string of appropriate length for the specified comment level
- */
-function getIndent($iLevel) {
- global $default;
- $sToRender = "";
- for ($i=0; $i<$iLevel; $i++) {
- $sToRender .= " ";
- }
- $default->log->info("indent($iLevel) = " . $sToRender);
- return $sToRender;
-}
-?>
diff --git a/templates/ktstandard/action/discussion.smarty b/templates/ktstandard/action/discussion.smarty
new file mode 100644
index 0000000..e7de77c
--- /dev/null
+++ b/templates/ktstandard/action/discussion.smarty
@@ -0,0 +1,35 @@
+{if $threads}
+Existing threads
+
+
+
+ | Subject |
+ Creator |
+ Views |
+ Replies |
+ Last activity |
+
+
+
+ {foreach from=$threads item=thread}
+ {$threadrenderer->render($context, $thread)}
+ {/foreach}
+
+
+{else}
+ There are no existing threads for this document
+{/if}
+
+
diff --git a/templates/ktstandard/action/discussion_comment_list_item.smarty b/templates/ktstandard/action/discussion_comment_list_item.smarty
new file mode 100644
index 0000000..000e44a
--- /dev/null
+++ b/templates/ktstandard/action/discussion_comment_list_item.smarty
@@ -0,0 +1,22 @@
+{capture assign=sCSS}{literal}
+dl.kt-discussion-comment > dt {
+ font-weight: bold;
+}
+
+.kt-discussion-post-link {
+ font-size: smaller;
+}
+{/literal}{/capture}
+{$context->oPage->requireCSSStandalone($sCSS)}
+
+
+
+Post a reply
diff --git a/templates/ktstandard/action/discussion_thread.smarty b/templates/ktstandard/action/discussion_thread.smarty
new file mode 100644
index 0000000..7fadd48
--- /dev/null
+++ b/templates/ktstandard/action/discussion_thread.smarty
@@ -0,0 +1,19 @@
+{foreach from=$thread->getCommentsSortedByDate() item=oComment}
+ {$commentrenderer->render($context, $oComment)}
+{/foreach}
+
+
diff --git a/templates/ktstandard/action/discussion_thread_list_item.smarty b/templates/ktstandard/action/discussion_thread_list_item.smarty
new file mode 100644
index 0000000..1f4426c
--- /dev/null
+++ b/templates/ktstandard/action/discussion_thread_list_item.smarty
@@ -0,0 +1,7 @@
+
+ | {$first_comment->getSubject()} |
+ {$creator->getName()} |
+ {$thread->getNumberOfViews()} |
+ {$thread->getNumberOfReplies()} |
+ {$last_comment->getDate()} |
+