2007-08-23 16:01:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2012-02-19 03:31:32 +00:00
|
|
|
* User page callbacks for tracker.module.
|
2007-08-23 16:01:01 +00:00
|
|
|
*/
|
|
|
|
|
2014-06-13 02:33:48 +00:00
|
|
|
use Drupal\Component\Utility\String;
|
2014-11-10 07:40:48 +00:00
|
|
|
use Drupal\node\Entity\Node;
|
2007-08-23 16:01:01 +00:00
|
|
|
|
|
|
|
/**
|
2012-02-19 03:31:32 +00:00
|
|
|
* Page callback: Generates a page of tracked nodes for the site.
|
|
|
|
*
|
|
|
|
* Queries the database for info, adds RDFa info if applicable, and generates
|
|
|
|
* the render array that will be used to render the page.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* A renderable array.
|
|
|
|
*
|
|
|
|
* @see tracker_menu()
|
2007-08-23 16:01:01 +00:00
|
|
|
*/
|
2013-12-18 04:48:02 +00:00
|
|
|
function tracker_page($account = NULL) {
|
2007-11-06 08:51:23 +00:00
|
|
|
if ($account) {
|
2012-06-05 05:42:19 +00:00
|
|
|
$query = db_select('tracker_user', 't')
|
2013-05-29 07:20:43 +00:00
|
|
|
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
|
|
|
->addMetaData('base_table', 'tracker_user')
|
2013-07-11 17:29:02 +00:00
|
|
|
->condition('t.uid', $account->id());
|
2007-08-23 16:01:01 +00:00
|
|
|
}
|
2009-08-31 06:52:50 +00:00
|
|
|
else {
|
2014-06-14 02:31:56 +00:00
|
|
|
$query = db_select('tracker_node', 't', array('target' => 'replica'))
|
2013-05-29 07:20:43 +00:00
|
|
|
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
|
|
|
->addMetaData('base_table', 'tracker_node');
|
2009-08-31 06:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This array acts as a placeholder for the data selected later
|
|
|
|
// while keeping the correct order.
|
2013-03-10 19:05:24 +00:00
|
|
|
$tracker_data = $query
|
2009-08-31 06:52:50 +00:00
|
|
|
->addTag('node_access')
|
|
|
|
->fields('t', array('nid', 'changed'))
|
|
|
|
->condition('t.published', 1)
|
|
|
|
->orderBy('t.changed', 'DESC')
|
|
|
|
->limit(25)
|
|
|
|
->execute()
|
|
|
|
->fetchAllAssoc('nid');
|
2007-08-23 16:01:01 +00:00
|
|
|
|
2009-12-02 14:56:32 +00:00
|
|
|
$rows = array();
|
2013-03-10 19:05:24 +00:00
|
|
|
if (!empty($tracker_data)) {
|
2014-08-13 00:40:09 +00:00
|
|
|
// Load nodes into an array with the same order as $tracker_data.
|
2014-11-10 07:40:48 +00:00
|
|
|
$nodes = Node::loadMultiple(array_keys($tracker_data));
|
2014-08-13 00:40:09 +00:00
|
|
|
|
|
|
|
// Enrich the node data.
|
|
|
|
$result = \Drupal::service('comment.statistics')->read($nodes, 'node', FALSE);
|
|
|
|
foreach ($result as $statistics) {
|
|
|
|
// The node ID may not be unique; there can be multiple comment fields.
|
|
|
|
// Make comment_count the total of all comments.
|
|
|
|
$nid = $statistics->entity_id;
|
|
|
|
if (empty($nodes[$nid]->comment_count)
|
|
|
|
|| !is_numeric($nodes[$nid]->comment_count)) {
|
|
|
|
$nodes[$nid]->comment_count = $statistics->comment_count;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$nodes[$nid]->comment_count += $statistics->comment_count;
|
|
|
|
}
|
|
|
|
|
2013-03-10 19:05:24 +00:00
|
|
|
$nodes[$nid]->last_activity = $tracker_data[$nid]->changed;
|
2009-08-31 06:52:50 +00:00
|
|
|
}
|
2009-04-05 12:26:12 +00:00
|
|
|
|
2012-02-19 03:31:32 +00:00
|
|
|
// Display the data.
|
2009-08-31 06:52:50 +00:00
|
|
|
foreach ($nodes as $node) {
|
2012-02-19 03:31:32 +00:00
|
|
|
// Determine the number of comments.
|
2009-08-31 06:52:50 +00:00
|
|
|
$comments = 0;
|
|
|
|
if ($node->comment_count) {
|
|
|
|
$comments = $node->comment_count;
|
2007-08-23 16:01:01 +00:00
|
|
|
|
2014-07-03 12:05:51 +00:00
|
|
|
if ($new = \Drupal::service('comment.manager')->getCountNewComments($node)) {
|
2014-11-19 12:51:19 +00:00
|
|
|
$comments = array(
|
|
|
|
'#type' => 'link',
|
|
|
|
'#url' => $node->urlInfo(),
|
|
|
|
'#title' => \Drupal::translation()->formatPlural($new, '1 new', '@count new'),
|
|
|
|
'#options' => array(
|
|
|
|
'fragment' => 'new',
|
|
|
|
),
|
|
|
|
'#prefix' => $node->comment_count . '<br />',
|
|
|
|
);
|
2009-08-31 06:52:50 +00:00
|
|
|
}
|
2007-08-23 16:01:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-09 17:03:07 +00:00
|
|
|
$mark_build = array(
|
|
|
|
'#theme' => 'mark',
|
2013-08-16 17:13:11 +00:00
|
|
|
'#status' => node_mark($node->id(), $node->getChangedTime()),
|
2013-06-09 17:03:07 +00:00
|
|
|
);
|
|
|
|
|
2010-01-14 06:23:40 +00:00
|
|
|
$row = array(
|
2014-06-13 02:33:48 +00:00
|
|
|
'type' => String::checkPlain(node_get_type_label($node)),
|
2014-11-19 12:51:19 +00:00
|
|
|
'title' => array(
|
|
|
|
'data' => array(
|
|
|
|
'#type' => 'link',
|
|
|
|
'#url' => $node->urlInfo(),
|
|
|
|
'#title' => $node->getTitle(),
|
|
|
|
'#suffix' => ' ' . drupal_render($mark_build),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'author' => array(
|
|
|
|
'data' => array(
|
|
|
|
'#theme' => 'username',
|
|
|
|
'#account' => $node->getOwner(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'replies' => array(
|
|
|
|
'class' => array('replies'),
|
|
|
|
'data' => $comments,
|
|
|
|
),
|
|
|
|
'last updated' => array(
|
|
|
|
'data' => t('!time ago', array(
|
|
|
|
'!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->last_activity),
|
|
|
|
)),
|
|
|
|
),
|
2009-08-31 06:52:50 +00:00
|
|
|
);
|
2010-01-14 06:23:40 +00:00
|
|
|
|
|
|
|
$rows[] = $row;
|
2009-08-31 06:52:50 +00:00
|
|
|
}
|
2007-08-23 16:01:01 +00:00
|
|
|
}
|
|
|
|
|
2009-07-02 04:27:23 +00:00
|
|
|
$page['tracker'] = array(
|
|
|
|
'#rows' => $rows,
|
2009-11-23 02:45:42 +00:00
|
|
|
'#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')),
|
2014-03-12 15:46:33 +00:00
|
|
|
'#type' => 'table',
|
2009-12-02 14:56:32 +00:00
|
|
|
'#empty' => t('No content available.'),
|
2009-07-02 04:27:23 +00:00
|
|
|
);
|
|
|
|
$page['pager'] = array(
|
|
|
|
'#theme' => 'pager',
|
|
|
|
'#weight' => 10,
|
|
|
|
);
|
|
|
|
$page['#sorted'] = TRUE;
|
2007-08-23 16:01:01 +00:00
|
|
|
|
2009-07-02 04:27:23 +00:00
|
|
|
return $page;
|
2007-08-23 16:01:01 +00:00
|
|
|
}
|