From c11f9074b96d45f98e8a02a0230f79175ec72449 Mon Sep 17 00:00:00 2001 From: Michael Joseph Date: Mon, 15 Dec 2003 13:45:53 +0000 Subject: [PATCH] #3497 changes to support listing comments by thread and indenting appropriately --- presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------ presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc | 14 ++++++++------ presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php | 83 +++++++++++++++++++++++++++++++++++------------------------------------------------ presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------- 4 files changed, 199 insertions(+), 220 deletions(-) diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php index 2453920..92fc931 100644 --- a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php +++ b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentBL.php @@ -43,105 +43,98 @@ require_once("$default->fileSystemRoot/presentation/Html.inc"); if(checkSession()) { $oPatternCustom = & new PatternCustom(); require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - if (isset($fAddComment)) { // User wishes to add a comment - if ($fDocumentID > 0) { // The document ID is positive + // input validation + if (isset($fAddComment)) { + if (isset($fDocumentID)) { $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID"); $oPatternCustom->setHtml(getAddComment($fDocumentID,$sSubject,$sBody, $fCommentID, 1)); + } else { + $main->setErrorMessage("You did not specify a document to add a comment to."); } - else { // And invalid Document ID was sent - $main->setErrorMessage("The Document id cannot be lss than 0. ID is invalid."); - } - - } else if (isset($fViewComment)){ // User wishes to view a comment - + // User wishes to view a comment + } else if (isset($fViewComment)) { if (isset($iCommentID)) { $oComment = DiscussionComment::get($iCommentID); $oUser = User::get($oComment->getUserID()); - - $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(),$oComment->getDate(),$iDocumentID,$oUser->getUserName())) ; + $oPatternCustom->setHtml(getCommentBody($oComment->getBody(), $oComment->getSubject(), $oComment->getDate(), $iDocumentID,$oUser->getUserName())) ; } - - } else if (isset($fAddCommentSubmit)) { - if ($_POST["NewComment"] != "" && $_POST["NewCommentSubject"] != "") { - - if (isset($fNewThread)){ // Create a New Thread for this document as it doesn't exist - - // Create the thread Object - $oThread = & new DiscussionThread(-1,$iDocumentID, $_SESSION["userID"]); - $oThread->create(); - $iThreadID = $oThread->getID(); - } - else { // Update the existing thread - $iThreadID = DiscussionThread::getThreadIDforDoc($iDocumentID); - } - - if ($iThreadID > 0){ - // Create the new comment - $oComment = & new DiscussionComment($_POST["NewComment"], $_POST["NewCommentSubject"],$_SESSION["userID"],$iDocumentID); - $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()); - } - if($_SESSION['Discussion' . $iDocumentID][0]->bViews != true ){ // Session variable is set to true if user views the thread - - $oThread->setNumberOfViews(); - $_SESSION['Discussion' . $iDocumentID][0]->bViews = true; - } - $oThread->setNumberOfReplies(); - - if ($oThread->Update()) { // - controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID"); - //$oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID)); - }else { - $main->setErrorMessage("Thread Object failed to update"); - } + } else 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($fNewComment)) { + $oThread = & new DiscussionThread(-1, $iDocumentID, $_SESSION["userID"]); + $oThread->create(); + $iThreadID = $oThread->getID(); + // if this is a new thread, then set inReplyTo to -1 + $fInReplyTo = -1; + } else { + // retrieve the thread id + $iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID); + } + if ($iThreadID) { + $default->log->info("addComment fInReplyTo=$fInReplyTo"); + // 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' . $iDocumentID][0]->bViews != true ){ + $oThread->incrementNumberOfViews(); + $_SESSION['Discussion' . $iDocumentID][0]->bViews = true; + } + $oThread->incrementNumberOfReplies(); - }else { - $main->setErrorMessage("Comment Object failed in creation"); + if ($oThread->Update()) { // + controllerRedirect("viewDiscussion", "fForDiscussion=1&fDocumentID=$iDocumentID"); + //$oPatternCustom->addHtml(getSubmitSuccessPage($iDocumentID)); + } else { + $main->setErrorMessage("Thread Object failed to update"); } - - }else{ // There is no thread id for this document - $main->setErrorMessage("No threadID($iThreadID) exists for this document"); - }// End Of if for THREAD ID test - - }else { // the user has not entered BOTH a subject and a text body + } 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&iDocumentID=$fDocumentID"); - $oPatternCustom->addHtml(getAddComment($fDocumentID,$_POST["NewCommentSubject"],$_POST["NewComment"], $fCommentID, 1)); + $oPatternCustom->addHtml(getAddComment($fDocumentID, $fSubject, $fComment, $fCommentID, 1)); } // 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&iDocumentID=$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>---------------------------------------"; + $sReplyBody = $oComment->getBody(); - $sReplyBody = $sReplyBodyHeader . "\n>" . str_replace("%0D%0A" ,"%0D%0A>", $sReplyBody); // Put in ">" as indentation for the reply + $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 = ""; } + } else { $sReply = ""; } $oPatternCustom->addHtml(getAddComment($fDocumentID, $sReply . $oComment->getSubject() , urldecode($sReplyBody), $fCommentID, "-1" )); } else if (isset($fNewThread)){ // Start adding a new Thread $main->setFormAction($_SERVER['PHP_SELF'] . "?fAddCommentSubmit=1&iDocumentID=$fDocumentID&fNewThread=1"); - $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject , $Comment, $fCommentID, "1")); + $oPatternCustom->addHtml(getAddComment($fDocumentID, $CommentSubject ,$Comment, $fCommentID, "1")); } else { // If no discussion exists $main->setErrorMessage("Error: No discussion thread available"); diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc index bd46d7c..404f5be 100644 --- a/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/discussions/addCommentUI.inc @@ -48,7 +48,7 @@ function getSubmitSuccessPage($iDocumentID){ function getAddComment($fDocumentID, $sSubject, $sBody, $iCommentID, $fNewComment = null) { global $default; - $sHeading = "Add a Comment"; + $sHeading = "Add a Comment"; $sToRender .= renderHeading($sHeading); $sToRender .= displayDocumentPath($fDocumentID); $sToRender .= "\n"; @@ -56,14 +56,16 @@ function getAddComment($fDocumentID, $sSubject, $sBody, $iCommentID, $fNewCommen $sToRender .= "               "; $sToRender .= "               "; $sToRender .= "graphicsUrl/widgets/submit.gif\" border=0>"; - if($fNewComment>0){ // If user is creating a new comment + if ($fNewComment>0) { // If user is creating a new comment $sToRender .= "\n"; - }else { // If the user is replying to a comment - $sToRender .= "\n"; + $sToRender .= ""; + } else { // If the user is replying to a comment + $sToRender .= ""; + $sToRender .= "\n"; } $sToRender .= "
\n"; - $sToRender .= "
graphicsUrl/widgets/cancel.gif\" border=0 >
graphicsUrl/widgets/cancel.gif\" border=0 >
graphicsUrl/widgets/cancel.gif\" border=0 >
Subject\n"; - $sToRender .= "
Body
\n"; + $sToRender .= "\n"; + $sToRender .= "Body\n"; return $sToRender; } diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php index b0a7de2..fd088a4 100644 --- a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php +++ b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionBL.php @@ -44,61 +44,48 @@ if (checkSession()) { require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); if (isset($fForDiscussion)) { - if ($fDocumentID > 0) { - $iThreadID = DiscussionThread::getThreadIDforDoc($fDocumentID); - if ($iThreadID) {// if thread ID does exist - $oThread = DiscussionThread::get($iThreadID); - if($oThread) { // if thread object exists - // Iterate through the number of comments - $sAllCommentID = $oThread->getAllCommentID(); - $arrAllCommentID = explode(",", $sAllCommentID); - $iNumMax = $oThread->getNumberOfReplies(); - - $sQuery = "SELECT 1 as ForView, subject, username, date, discussion_comments.id as com_id, discussion_threads.document_id as doc_id " . - "FROM (discussion_comments INNER JOIN users ON discussion_comments.user_id = users.id) " . - "INNER JOIN discussion_threads ON discussion_threads.id = discussion_comments.thread_id " . - "WHERE discussion_threads.id = " . $iThreadID . - " ORDER BY discussion_comments.thread_id ASC"; - - $aColumns = array("subject", "username", "date"); - $aColumnNames = array("Subject ", "User", "Date"); - $aColumnTypes = array(3,1,1); - $aQueryStringVars = array("fViewComment", "iCommentID", "iDocumentID"); - $aQueryStringCols = array("ForView", "com_id", "doc_id"); - - for ($i = 0; $i < $iNumMax; $i++) { - $aHyperLinkURL[$i] = $_SERVER['PHP_SELF'] ; - } - - $oSearchResults = & new PatternTableSqlQuery ($sQuery, $aColumns, $aColumnTypes, $aColumnNames, "100%", $aHyperLinkURL, $aQueryStringCols, $aQueryStringVars); - $sToRender .= renderHeading("Document Discussion Thread"); - $sToRender .= displayDocumentPath($oThread->getDocumentID()); - $oPatternCustom->addHtml($sToRender); - $oPatternCustom->addHtml(getPageButtons($oThread)); - $oPatternCustom->addHtml($oSearchResults->render()); + if (isset($fDocumentID)) { + $aDocumentThreads = DiscussionThread::getList("document_id=$fDocumentID ORDER BY id"); + if (count($aDocumentThreads) > 0) { + // call the ui function to display the comments + $oPatternCustom->setHtml(getPage($fDocumentID, $aDocumentThreads)); +// $sQuery = "SELECT 1 as ForView, dc.subject AS subject, username, date, dc.id AS commentID, dt.document_id AS documentID " . +// "FROM discussion_comments AS dc " . +// "INNER JOIN users AS u ON dc.user_id = u.id " . +// "INNER JOIN discussion_threads AS dt ON dt.id = dc.thread_id " . +// "WHERE dt.id in ( " . implode(",", $aDocumentThreads) . ") " . +// "ORDER BY dc.thread_id, dc.id, date ASC"; +// +// $aColumns = array("subject", "username", "date"); +// $aColumnNames = array("Subject ", "User", "Date"); +// $aColumnTypes = array(3,1,1); +// $aQueryStringVars = array("fViewComment", "iCommentID", "iDocumentID"); +// $aQueryStringCols = array("ForView", "commentID", "documentID"); +// +// for ($i = 0; $i < $iNumMax; $i++) { +// $aHyperLinkURL[$i] = $_SERVER['PHP_SELF'] ; +// } +// +// $oSearchResults = & new PatternTableSqlQuery ($sQuery, $aColumns, $aColumnTypes, $aColumnNames, "100%", $aHyperLinkURL, $aQueryStringCols, $aQueryStringVars); +// $sToRender .= renderHeading("Document Discussion Thread"); +// $sToRender .= displayDocumentPath($fDocumentID); +// $oPatternCustom->addHtml($sToRender); +// $oPatternCustom->addHtml(getPageButtons($fDocumentID)); +// $oPatternCustom->addHtml($oSearchResults->render()); +// // On opening, increment the number of views of current thread & update database - if($_SESSION['Discussion' . $fDocumentID][0]->bViews !=true ){ - $oThread->setNumberOfViews(); - if($oThread->Update() == false) $oPatternCustom->addHtml("Failed to update. Please Contact Database Administrator in this regard") ; - $_SESSION['Discussion' . $fDocumentID][0]->bViews = true; - } - } else { - $main->setErrorMessage("Error creating discussion thread object"); - } +// if($_SESSION['Discussion' . $fDocumentID][0]->bViews !=true ){ +// $oThread->incrementNumberOfViews(); +// if($oThread->Update() == false) $oPatternCustom->addHtml("Failed to update. Please Contact Database Administrator in this regard") ; +// $_SESSION['Discussion' . $fDocumentID][0]->bViews = true; +// } } 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("Invalid Document ID. ID may not be negative."); - } - } else if (isset($fViewComment)){ // User wants to view a comment - if (isset($iCommentID)) { // Check if a comment ID exists - $oComment = DiscussionComment::get($iCommentID); - $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,$iDocumentID,$oUser)) ; + $main->setErrorMessage("You did not specify a document."); } } else { // If no discussion exists $main->setErrorMessage("Invalid function. No such functionality exists for this page."); diff --git a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc index ce9d0c3..cff5e79 100644 --- a/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/discussions/viewDiscussionUI.inc @@ -25,28 +25,23 @@ * @package discussions */ -function getPageButtons($oThread){ +function getPageButtons($iDocumentID){ global $default; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - + $sToRender .= "\n"; + $sToRender .= "\n"; $sToRender .= "
graphicsUrl/widgets/addcomment.gif\" border=\"0\" />graphicsUrl/widgets/back.gif\" border=\"0\" />graphicsUrl/widgets/addcomment.gif\" border=\"0\" />graphicsUrl/widgets/back.gif\" border=\"0\" />
\n"; - - return $sToRender ; + return $sToRender; } // If there are no threads to view for a document -function getViewFailPage($sMessage) -{ +function getViewFailPage($sMessage) { global $default; - - if (strlen($sMessage)>0){ + if ( strlen($sMessage)>0 ) { $sToRender = $sMessage; + } else { + $sToRender = "Current document has no discussion. Press the ADD button to start a discussion."; } - else $sToRender = "Current document has no discussion. Press the ADD button to start a discussion."; - return $sToRender; } @@ -56,14 +51,12 @@ function getViewFailPage($sMessage) * @param $fDocumentID -> a valid document ID */ function getNewThreadOption($fDocumentID) { - global $default; - - $sToRender .= "Would you like to create a new Discussion thread for this document?"; - $sToRender .= "   "; - $sToRender .= "graphicsUrl/widgets/new.gif\" border=\"0\">"; - $sToRender .= "graphicsUrl/widgets/cancel.gif\" border=\"0\">"; - - return $sToRender; + global $default; + $sToRender .= "Would you like to create a new Discussion thread for this document?"; + $sToRender .= "   "; + $sToRender .= "graphicsUrl/widgets/new.gif\" border=\"0\">"; + $sToRender .= "graphicsUrl/widgets/cancel.gif\" border=\"0\">"; + return $sToRender; } /** @@ -74,9 +67,8 @@ function getNewThreadOption($fDocumentID) { * @param $iNum -> its the iterative index of the current comment * @param $iThread -> a valid Thread Object * @param $oComment -> a valid Comment Object - * @param $oUser -> a valid User Object (Logged in user) */ -function getViewComment($iNum,$oThread,$oComment,$oUser) { +function getViewComment($iNum, $oThread, $oComment, $sIndent) { global $default; $iSubjectChars = 59; @@ -84,85 +76,90 @@ function getViewComment($iNum,$oThread,$oComment,$oUser) { if (($iNum%2) == 1) $BGcolor = "#F5F6EE"; if (($iNum%2) == 0) $UserBGcolor = "#F5F6EE"; - // If the Subject string is too long - if (strlen($oComment->getSubject())>$iSubjectChars ) $dotdot = " ..."; - if (strlen($oUser->getUserName())> 13 ) $Userdotdot = " ..."; - - // If this is the first Subject line then create a table - if ($iNum == 1) { - $sHeading = "Document Discussion Comments"; - - $sToRender .= renderHeading($sHeading ); - $sToRender .= displayDocumentPath($oThread->getDocumentID()); - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= "
Views: " . $oThread->getNumberOfViews() . "Replies: " . $oThread->getNumberOfReplies() . "getID()) . "\">graphicsUrl/widgets/addcomment.gif\" border=\"0\" />"; - $sToRender .= "graphicsUrl/widgets/back.gif\" onmouseover=\"this.style.cursor='hand'\" onclick=\"javascript: history.go(-1);\" >

\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; + $sUserName = ""; + $oUser = User::get($oComment->getUserID()); + if ($oUser) { + $sUserName = $oUser->getName(); } - - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - - // If this is the last subject line then close the table - if ($iNum == ($oThread->getNumberOfReplies())) { $sToRender .= "\n
SubjectAuthorDate
$iNum getID() . "&iDocumentID=" . $oThread->getDocumentID() . "\" title=\"" . $oComment->getSubject() . "\">" . substr($oComment->getSubject(),0,$iSubjectChars ) . $dotdot . "getUserName()\">" . substr($oUser->getUserName(),0,10) . $Userdotdot . "" . $oComment->getDate() . "
\n\n";} + // If the Subject string is too long + if (strlen($oComment->getSubject())>$iSubjectChars ) $dotdot = " ..."; + + $sToRender .= "\n"; + $sToRender .= "\t\n"; + $sToRender .= "\t\t$sIndentgetSubject() . "\">\n"; + $sToRender .= substr($oComment->getSubject(),0,$iSubjectChars ) . $dotdot . "\n"; + $sToRender .= "\t\n"; + $sToRender .= "\t\t$sUserName\n"; + $sToRender .= "\t" . $oComment->getDate() . "\n"; + return $sToRender; } -/** - * Views a single thread comment with its text body - * - * @param $iDocumentID -> a valid Document ID - * @param $oComment -> a valid Comment Object - * @param $oUser -> a valid User Object (Logged in user) +/** + * Prints out the list of discussion comments */ -function getCommentBody($oComment, $iDocumentID, $oUser) { +function getPage($iDocumentID, $aDocumentThreads) { 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 + $sToRender .= renderHeading("Document Discussion Comments"); + $sToRender .= displayDocumentPath($iDocumentID); + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= "
\n"; + $sToRender .= "graphicsUrl/widgets/addcomment.gif\" border=\"0\" />\n"; + $sToRender .= "graphicsUrl/widgets/back.gif\" onmouseover=\"this.style.cursor='hand'\" onclick=\"javascript: history.go(-1);\">\n

\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; - // 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 .= "
SubjectAuthorDate
\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - - $sToRender .= "
Author: " . $oUser->getUserName() . "\n"; - $sToRender .= "getID()) . "\">graphicsUrl/widgets/reply.gif\" border=\"0\" />"; - $sToRender .= "graphicsUrl/widgets/back.gif\" border=0 >
Subject: "; - $sToRender .= $oComment->getSubject(); - $sToRender .= "Date: " . $oComment->getDate() . "   
"; - $sToRender .= "
"; - $sToRender .= $sBody; - $sToRender .= "
"; - $sToRender .= "
"; - - return $sToRender; + $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]=" . $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 + $aComments = DiscussionComment::getList("thread_id = $iThreadID AND in_reply_to = $iReplyTo ORDER BY id"); + // 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; +} ?> \ No newline at end of file -- libgit2 0.21.4