You are here

class UserStatistics in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
  2. 10.3.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
  3. 10.0.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
  4. 10.1.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
  5. 10.2.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics

Class UserStatistics.

@package Drupal\social_profile

Hierarchy

Expanded class hierarchy of UserStatistics

1 string reference to 'UserStatistics'
social_profile.services.yml in modules/social_features/social_profile/social_profile.services.yml
modules/social_features/social_profile/social_profile.services.yml
1 service uses UserStatistics
social_profile.user_statistics in modules/social_features/social_profile/social_profile.services.yml
Drupal\social_profile\UserStatistics

File

modules/social_features/social_profile/src/UserStatistics.php, line 12

Namespace

Drupal\social_profile
View source
class UserStatistics {

  /**
   * The database connection object.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * Constructor for UserStatistics.
   *
   * @param \Drupal\Core\Database\Connection $connection
   *   The database connection.
   */
  public function __construct(Connection $connection) {
    $this->database = $connection;
  }

  /**
   * Get node count by type.
   *
   * @param int $user_id
   *   The user ID.
   * @param string $type
   *   Node type id.
   *
   * @return int
   *   The number of nodes.
   */
  public function nodeCount($user_id, $type) {
    return $this
      ->count($user_id, $type);
  }

  /**
   * Get entity count by type for the profile.
   *
   * @param int $user_id
   *   The user ID.
   * @param string $type
   *   Entity type.
   *
   * @return int
   *   The number of entities.
   */
  protected function count($user_id, $type) {
    $query = $this->database
      ->select('node_field_data', 'nfd');
    $query
      ->addField('nfd', 'nid');
    $query
      ->condition('nfd.uid', $user_id);
    $query
      ->condition('nfd.type', $type, 'LIKE');
    return $query
      ->countQuery()
      ->execute()
      ->fetchField();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UserStatistics::$database protected property The database connection object.
UserStatistics::count protected function Get entity count by type for the profile.
UserStatistics::nodeCount public function Get node count by type.
UserStatistics::__construct public function Constructor for UserStatistics.