You are here

protected function UserBlock::getUserContentCount in Content Planner 8

Get content count for a given user.

Parameters

int $user_id: The user id to load the content count for.

Return value

int The content count for the given user id.

1 call to UserBlock::getUserContentCount()
UserBlock::build in src/Plugin/DashboardBlock/UserBlock.php
Builds the render array for a dashboard block.

File

src/Plugin/DashboardBlock/UserBlock.php, line 104

Class

UserBlock
Provides a user block for Content Planner Dashboard.

Namespace

Drupal\content_planner\Plugin\DashboardBlock

Code

protected function getUserContentCount($user_id) {
  $query = \Drupal::database()
    ->select('node_field_data', 'nfd');
  $query
    ->fields('nfd', [
    'nid',
  ]);
  $query
    ->condition('nfd.uid', $user_id);
  $query
    ->countQuery();
  $result = $query
    ->execute();
  $result->allowRowCount = TRUE;
  $count = $result
    ->rowCount();
  if ($count) {
    return $count;
  }
  return 0;
}