diff --git a/modules/comment/comment.model.php b/modules/comment/comment.model.php
index d85eed7bb..4c308eea4 100644
--- a/modules/comment/comment.model.php
+++ b/modules/comment/comment.model.php
@@ -452,7 +452,7 @@ class commentModel extends comment
*/
function getCommentList($document_srl, $page = 0, $is_admin = FALSE, $count = 0)
{
- if(!isset($document_srl))
+ if(!$document_srl)
{
return;
}
@@ -460,7 +460,7 @@ class commentModel extends comment
// get the number of comments on the document module
$oDocumentModel = getModel('document');
$columnList = array('document_srl', 'module_srl', 'comment_count');
- $oDocument = $oDocumentModel->getDocument($document_srl, FALSE, TRUE, $columnList);
+ $oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
// return if no doc exists.
if(!$oDocument->isExists())
@@ -469,7 +469,8 @@ class commentModel extends comment
}
// return if no comment exists
- if($oDocument->getCommentCount() < 1)
+ $document_comment_count = $oDocument->getCommentCount();
+ if($document_comment_count < 1)
{
return;
}
@@ -489,9 +490,10 @@ class commentModel extends comment
}
// get a very last page if no page exists
- if(!$page)
+ $total_pages = max(1, ceil($document_comment_count / $comment_count));
+ if(!$page || $page > $total_pages)
{
- $page = (int) ( ($oDocument->getCommentCount() - 1) / $comment_count) + 1;
+ $page = $total_pages;
}
// get a list of comments
@@ -550,6 +552,80 @@ class commentModel extends comment
ModuleHandler::triggerCall('comment.getCommentList', 'after', $output);
return $output;
}
+
+ /**
+ * Find out which page a comment is on
+ * @param int $document_srl
+ * @param int $comment_srl
+ * @param int $count
+ * @return int
+ */
+ function getCommentPage($document_srl, $comment_srl, $count = 0)
+ {
+ // Check the document
+ $oDocumentModel = getModel('document');
+ $columnList = array('document_srl', 'module_srl', 'comment_count');
+ $oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
+ if(!$oDocument->isExists())
+ {
+ return 0;
+ }
+
+ // return if no comment exists
+ $document_comment_count = $oDocument->getCommentCount();
+ if($document_comment_count < 1)
+ {
+ return 0;
+ }
+
+ // Get the comment count per page
+ if(!$count)
+ {
+ $module_srl = $oDocument->get('module_srl');
+ $comment_config = $this->getCommentConfig($module_srl);
+ $comment_count = $comment_config->comment_count;
+ }
+ else
+ {
+ $comment_count = $count;
+ }
+
+ // Get the number of pages
+ $total_pages = max(1, ceil($document_comment_count / $comment_count));
+ if ($total_pages == 1)
+ {
+ return 1;
+ }
+
+ // Find out which page the comment is on
+ $args = new stdClass();
+ $args->document_srl = $document_srl;
+ $args->comment_srl = $comment_srl;
+ $output = executeQuery('comment.getCommentPageItem', $args);
+ if (is_object($output->data))
+ {
+ $item = $output->data;
+ $args->head = $item->head;
+ $args->arrange = $item->arrange;
+ if (getController('comment')->isModuleUsingPublishValidation($module_srl))
+ {
+ $args->status = 1;
+ }
+ $output = executeQuery('comment.getCommentPage', $args);
+ if ($output->toBool() && $output->data->count)
+ {
+ return max(1, ceil($output->data->count / $comment_count));
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+ }
/**
* Update a list of comments in corresponding with document_srl
diff --git a/modules/comment/queries/getCommentPage.xml b/modules/comment/queries/getCommentPage.xml
new file mode 100644
index 000000000..ab51416ae
--- /dev/null
+++ b/modules/comment/queries/getCommentPage.xml
@@ -0,0 +1,21 @@
+
diff --git a/modules/comment/queries/getCommentPageItem.xml b/modules/comment/queries/getCommentPageItem.xml
new file mode 100644
index 000000000..3119856ed
--- /dev/null
+++ b/modules/comment/queries/getCommentPageItem.xml
@@ -0,0 +1,11 @@
+
diff --git a/modules/document/document.item.php b/modules/document/document.item.php
index 931bd7297..9fd27ec52 100644
--- a/modules/document/document.item.php
+++ b/modules/document/document.item.php
@@ -942,6 +942,8 @@ class documentItem extends BaseObject
return;
}
+ $oCommentModel = getModel('comment');
+
// cpage is a number of comment pages
$cpageStr = sprintf('%d_cpage', $this->document_srl);
$cpage = Context::get($cpageStr);
@@ -949,9 +951,16 @@ class documentItem extends BaseObject
{
$cpage = Context::get('cpage');
}
+ if(!$cpage && ($comment_srl = Context::get('comment_srl')))
+ {
+ $cpage = $oCommentModel->getCommentPage($this->document_srl, $comment_srl);
+ }
+ if(!$cpage && ($comment_srl = Context::get('_comment_srl')))
+ {
+ $cpage = $oCommentModel->getCommentPage($this->document_srl, $comment_srl);
+ }
// Get a list of comments
- $oCommentModel = getModel('comment');
$output = $oCommentModel->getCommentList($this->document_srl, $cpage, $is_admin);
if(!$output->toBool() || !count($output->data)) return;