class UserStatistics in Open Social 8.9
Same name and namespace in other branches
- 8.8 modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
- 10.3.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
- 10.0.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
- 10.1.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
- 10.2.x modules/social_features/social_profile/src/UserStatistics.php \Drupal\social_profile\UserStatistics
Class UserStatistics.
@package Drupal\social_profile
Hierarchy
- class \Drupal\social_profile\UserStatistics
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_profileView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserStatistics:: |
protected | property | The database connection object. | |
UserStatistics:: |
protected | function | Get entity count by type for the profile. | |
UserStatistics:: |
public | function | Get node count by type. | |
UserStatistics:: |
public | function | Constructor for UserStatistics. |