本文整理汇总了PHP中comment::get_replies方法的典型用法代码示例。如果您正苦于以下问题:PHP comment::get_replies方法的具体用法?PHP comment::get_replies怎么用?PHP comment::get_replies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comment
的用法示例。
在下文中一共展示了comment::get_replies方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_replies
public function get_replies($recursive = true)
{
global $DB;
$out = array();
// replies are always ordered by ascending date creation
$DB->query('
SELECT nvc.*, nvwu.username, nvwu.avatar
FROM nv_comments nvc
LEFT OUTER JOIN nv_webusers nvwu
ON nvwu.id = nvc.user
WHERE nvc.reply_to = ' . $this->id . ' AND
nvc.website = ' . $this->website . ' AND
nvc.status = 0
ORDER BY nvc.date_created ASC');
$rs = $DB->result();
if ($recursive) {
for ($r = 0; $r < count($rs); $r++) {
$c = new comment();
$c->load_from_resultset(array($rs[$r]));
$replies = $c->get_replies();
$out[] = $rs[$r];
if (!empty($replies)) {
foreach ($replies as $reply) {
$out[] = $reply;
}
}
}
} else {
$out = $rs;
}
return $out;
}
示例2: nvweb_comments_list
function nvweb_comments_list($offset = 0, $limit = NULL, $permission = NULL, $order = 'oldest')
{
global $DB;
global $website;
global $current;
$limit = value_or_default($limit, 2147483647);
if ($order == 'newest' || $order == 'hierarchy_newest') {
$orderby = "nvc.date_created DESC";
} else {
$orderby = "nvc.date_created ASC";
}
$element = $current['object'];
if ($current['type'] == 'structure') {
if (empty($current['structure_elements'])) {
$current['structure_elements'] = $element->elements();
}
$element = $current['structure_elements'][0];
} else {
if ($current['type'] == 'item') {
$element = new item();
$element->load($current['id']);
}
}
if (strpos($order, 'hierarchy') !== false) {
// list comments keeping hierarchy
// MySQL (still) does not have recursive queries, meanwhile we apply the following procedure:
// find all comments of 0-depth (root level) and calculate if they have any reply
// then, in PHP, parse the results and load (recursively) all replies and subreplies
// in the result array, INSERT the additional results in the position where they must be respecting the order requested (oldest/newest)
// note 1: this procedure allows optimization, for now we've made it work
// note 2: the only drawback is that offset/limit it's only taken into account for the root level comments, so the
// number of results is variable on each request; we found that an acceptable drawback
$DB->query('
SELECT SQL_CALC_FOUND_ROWS nvc.*, nvwu.username, nvwu.avatar,
(SELECT COUNT(nvcr.id)
FROM nv_comments nvcr
WHERE nvcr.reply_to = nvc.id
AND nvcr.status = 0
) AS replies
FROM nv_comments nvc
LEFT OUTER JOIN nv_webusers nvwu
ON nvwu.id = nvc.user
WHERE nvc.website = ' . protect($website->id) . '
AND nvc.item = ' . protect($element->id) . '
AND nvc.status = 0
AND nvc.reply_to = 0
ORDER BY ' . $orderby . '
LIMIT ' . $limit . '
OFFSET ' . $offset);
$rs = $DB->result();
$out = array();
for ($r = 0; $r < count($rs); $r++) {
$rows_to_add = array();
if ($rs[$r]->replies > 0) {
$c = new comment();
$c->load_from_resultset(array($rs[$r]));
$rows_to_add = $c->get_replies();
}
$out[] = $rs[$r];
if (!empty($rows_to_add)) {
foreach ($rows_to_add as $rta) {
$out[] = $rta;
}
}
}
$rs = $out;
$total = count($rs);
} else {
$DB->query('
SELECT SQL_CALC_FOUND_ROWS nvc.*, nvwu.username, nvwu.avatar
FROM nv_comments nvc
LEFT OUTER JOIN nv_webusers nvwu
ON nvwu.id = nvc.user
WHERE nvc.website = ' . protect($website->id) . '
AND nvc.item = ' . protect($element->id) . '
AND nvc.status = 0
ORDER BY ' . $orderby . '
LIMIT ' . $limit . '
OFFSET ' . $offset);
$rs = $DB->result();
$total = $DB->foundRows();
}
return array($rs, $total);
}