mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 11:11:39 +09:00
This commit is contained in:
parent
941542b991
commit
6961155f9c
4 changed files with 123 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
21
modules/comment/queries/getCommentPage.xml
Normal file
21
modules/comment/queries/getCommentPage.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<query id="getCommentPage" action="select">
|
||||
<tables>
|
||||
<table name="comments" alias="comments" />
|
||||
<table name="comments_list" alias="comments_list" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="count(*)" alias="count" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="more" column="comments.status" var="status" pipe="and" />
|
||||
<condition operation="equal" column="comments_list.document_srl" var="document_srl" notnull="notnull" pipe="and" />
|
||||
<condition operation="equal" column="comments_list.comment_srl" var="comments.comment_srl" filter="number" pipe="and" />
|
||||
<group pipe="and">
|
||||
<condition operation="below" column="comments_list.head" var="head" filter="number" notnull="notnull" />
|
||||
<group pipe="or">
|
||||
<condition operation="equal" column="comments_list.head" var="head" filter="number" notnull="notnull" />
|
||||
<condition operation="less" column="comments_list.arrange" var="arrange" filter="number" notnull="notnull" pipe="and" />
|
||||
</group>
|
||||
</group>
|
||||
</conditions>
|
||||
</query>
|
||||
11
modules/comment/queries/getCommentPageItem.xml
Normal file
11
modules/comment/queries/getCommentPageItem.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<query id="getCommentPageItem" action="select">
|
||||
<tables>
|
||||
<table name="comments_list" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="*" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="equal" column="comment_srl" var="comment_srl" filter="number" notnull="notnull" />
|
||||
</conditions>
|
||||
</query>
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue