You are here

class GroupStatistics in Open Social 10.2.x

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

Class GroupStatistics.

@package Drupal\social_group

Hierarchy

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_group
View 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

Namesort descending Modifiers Type Description Overrides
GroupStatistics::$database protected property The database connection object.
GroupStatistics::count protected function Get entity count by type for the group.
GroupStatistics::getGroupMemberCount public function Get group members count.
GroupStatistics::getGroupNodeCount public function Get group node count by type.
GroupStatistics::__construct public function Constructor for SocialGroupMembersCount.