本文整理汇总了PHP中comments::getCount方法的典型用法代码示例。如果您正苦于以下问题:PHP comments::getCount方法的具体用法?PHP comments::getCount怎么用?PHP comments::getCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comments
的用法示例。
在下文中一共展示了comments::getCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get a news post.
*
* @param string $id The news id.
* @param bool $idlib True if the Id library should be used (False for MongoIds)
* @param bool $justOne True if only one entry should be returned.
* @param bool $fixUTF8 True if UTF8 should be decoded.
*
* @return mixed The news post as an array, or an error string.
*/
protected function get($id, $idlib = true, $justOne = false, $fixUTF8 = true, $page = 1, $limit = self::PER_PAGE)
{
$query = array('ghosted' => false);
if ($idlib) {
$keys = Id::dissectKeys($id, 'news');
$query['date'] = array('$gte' => $keys['date'], '$lte' => $keys['date'] + $keys['ambiguity']);
} else {
$query['_id'] = $this->_toMongoId($id);
}
$results = $this->db->find($query)->skip(($page - 1) * self::PER_PAGE)->sort(array('date' => -1));
$total = $results->count();
$valid = array();
if ($limit != null) {
$results->limit($limit);
}
if ($idlib) {
foreach ($results as $result) {
if (!Id::validateHash($id, array('ambiguity' => $keys['ambiguity'], 'reportedDate' => $keys['date'], 'date' => $result['date'], 'title' => $result['title']), 'news')) {
continue;
}
array_push($valid, $result);
}
} else {
$valid = iterator_to_array($results);
}
if ($justOne) {
$valid = array(reset($valid));
}
if (empty($valid)) {
return array('Invalid id.', 0);
}
$comments = new comments(ConnectionFactory::get('mongo'));
foreach ($valid as $key => $entry) {
$this->resolveUser($valid[$key]['user']);
if ($fixUTF8) {
$this->resolveUTF8($valid[$key]);
}
$valid[$key]['comments'] = $comments->getCount($entry['_id']);
$valid[$key]['rating'] = $this->getScore($entry['_id']);
}
if ($justOne) {
return reset($valid);
}
return array($valid, $total);
}