function _node_resource_load_node_comments in Services 7.3
Same name and namespace in other branches
- 6.3 resources/node_resource.inc \_node_resource_load_node_comments()
Returns the comments of a specified node.
Parameters
$nid: Unique identifier for the node.
$count: Number of comments to return.
$start: Which comment to start with. If present, $start and $count are used together to create a LIMIT clause for selecting comments. This could be used to do paging.
Return value
An array of comment objects.
2 string references to '_node_resource_load_node_comments'
- hook_services_resources in docs/
services.services.api.php - Defines function signatures for resources available to services.
- _node_resource_definition in resources/
node_resource.inc
File
- resources/
node_resource.inc, line 610
Code
function _node_resource_load_node_comments($nid, $count = 0, $start = 0) {
$query = db_select('comment', 'c');
$query
->innerJoin('node', 'n', 'n.nid = c.nid');
$query
->addTag('node_access');
$query
->fields('c', array(
'cid',
))
->condition('c.nid', $nid);
if ($count) {
$query
->range($start, $count);
}
$result = $query
->execute()
->fetchAll();
foreach ($result as $record) {
$cids[] = $record->cid;
}
!empty($cids) ? $comments = comment_load_multiple($cids) : array();
$return_comments = array();
foreach ($comments as $comment) {
$return_comments[] = services_field_permissions_clean('view', 'comment', $comment);
}
return $return_comments;
}