class GroupStatistics in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/GroupStatistics.php \Drupal\social_group\GroupStatistics
- 8.8 modules/social_features/social_group/src/GroupStatistics.php \Drupal\social_group\GroupStatistics
- 10.0.x modules/social_features/social_group/src/GroupStatistics.php \Drupal\social_group\GroupStatistics
- 10.1.x modules/social_features/social_group/src/GroupStatistics.php \Drupal\social_group\GroupStatistics
- 10.2.x modules/social_features/social_group/src/GroupStatistics.php \Drupal\social_group\GroupStatistics
Class GroupStatistics.
@package Drupal\social_group
Hierarchy
- class \Drupal\social_group\GroupStatistics
Expanded class hierarchy of GroupStatistics
1 file declares its use of GroupStatistics
- SocialGroupListBuilder.php in modules/
social_features/ social_group/ src/ Controller/ SocialGroupListBuilder.php
1 string reference to 'GroupStatistics'
- social_group.services.yml in modules/
social_features/ social_group/ social_group.services.yml - modules/social_features/social_group/social_group.services.yml
2 services use GroupStatistics
- social_group.group_members_count in modules/
social_features/ social_group/ social_group.services.yml - Drupal\social_group\GroupStatistics
- social_group.group_statistics in modules/
social_features/ social_group/ social_group.services.yml - Drupal\social_group\GroupStatistics
File
- modules/
social_features/ social_group/ src/ GroupStatistics.php, line 13
Namespace
Drupal\social_groupView source
class GroupStatistics {
/**
* The database connection object.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Constructor for SocialGroupMembersCount.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(Connection $connection) {
$this->database = $connection;
}
/**
* Get group members count.
*
* @param \Drupal\group\Entity\GroupInterface $group
* The group entity.
*
* @return int
* The number of members.
*/
public function getGroupMemberCount(GroupInterface $group) {
return $this
->count($group, 'group_membership');
}
/**
* Get group node count by type.
*
* @param \Drupal\group\Entity\GroupInterface $group
* The group entity.
* @param string $type
* Node type id.
*
* @return int
* The number of nodes.
*/
public function getGroupNodeCount(GroupInterface $group, $type) {
return $this
->count($group, 'group_node-' . $type);
}
/**
* Get entity count by type for the group.
*
* @param \Drupal\group\Entity\GroupInterface $group
* The group entity.
* @param string $type
* Entity type in group.
*
* @return int
* The number of entities.
*/
protected function count(GroupInterface $group, $type) {
// Additional caching not required since views does this for us.
$query = $this->database
->select('group_content_field_data', 'gcfd');
$query
->addField('gcfd', 'gid');
$query
->condition('gcfd.gid', $group
->id());
$query
->condition('gcfd.type', $group
->getGroupType()
->id() . '-' . $type, 'LIKE');
return $query
->countQuery()
->execute()
->fetchField();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupStatistics:: |
protected | property | The database connection object. | |
GroupStatistics:: |
protected | function | Get entity count by type for the group. | |
GroupStatistics:: |
public | function | Get group members count. | |
GroupStatistics:: |
public | function | Get group node count by type. | |
GroupStatistics:: |
public | function | Constructor for SocialGroupMembersCount. |