class Groups in Rocket.Chat 8.2
Hierarchy
- class \Drupal\rocket_chat_api\RocketChat\Collection\Groups implements CollectionInterface
Expanded class hierarchy of Groups
4 files declare their use of Groups
- Channel.php in modules/
rocket_chat_api/ src/ RocketChat/ Element/ Channel.php - GroupChannel.php in modules/
rocket_chat_group/ src/ Plugin/ Field/ FieldType/ GroupChannel.php - RocketChatGroupHelper.php in src/
Form/ RocketChatGroupHelper.php - RocketChatSettingsForm.php in src/
Form/ RocketChatSettingsForm.php - Contains \Drupal\rocket_chat\Form\RocketChatSettingsForm.
File
- modules/
rocket_chat_api/ src/ RocketChat/ Collection/ Groups.php, line 9
Namespace
Drupal\rocket_chat_api\RocketChat\CollectionView source
class Groups implements CollectionInterface {
/**
* @var \Drupal\rocket_chat_api\RocketChat\RocketChatStateinterface
*/
private $state;
/**
* @var \Drupal\rocket_chat_api\RocketChat\ApiClient
*/
private $apiClient;
/**
* Cache Names (or stub name).
*/
public const LIST = "rocket.chat.group.list";
public const UPDATE = "rocket.chat.group.lastUpdate";
public const GROUP = "rocket.chat.group.";
/**
* @var \Psr\Log\LoggerInterface
*/
protected $Logger;
public function __construct(StateInterface $state, ApiClient $apiClient) {
$this->state = $state;
$this->apiClient = $apiClient;
$this->Logger = Drupal::logger("Rocket Chat API: Groups");
}
public function getCache($forceReload = FALSE) {
$this
->refreshCache(FALSE);
$idList = $this->state
->get(self::LIST, []);
foreach ($idList as $index => $id) {
$idList[$index] = self::GROUP . $id;
}
$groups = $this->state
->getMultiple($idList);
if (empty($groups)) {
$groups = [];
}
return $groups;
}
public function refreshCache($forceReload = FALSE) {
$lastUpdate = $this->state
->get(self::UPDATE, 0);
$now = time();
if ($now - $lastUpdate >= 3600 * 24 * 7) {
$this->Logger
->info("Refreshing Groups Cache due to stale Cache (timeout)");
$forceReload = TRUE;
}
if ($forceReload) {
$groups = [];
$found = Channel::getAllGroupsBatched($this->apiClient, $groups);
$groupIds = [];
foreach ($groups as $group) {
$groupIds[] = $group['_id'];
$this->state
->set(self::GROUP . $group['_id'], $group);
}
$this->state
->set(self::LIST, $groupIds);
$this->state
->set(self::UPDATE, $now);
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Groups:: |
private | property | ||
Groups:: |
protected | property | ||
Groups:: |
private | property | ||
Groups:: |
public | function |
Overrides CollectionInterface:: |
|
Groups:: |
public | constant | ||
Groups:: |
public | constant | Cache Names (or stub name). | |
Groups:: |
public | function |
Overrides CollectionInterface:: |
|
Groups:: |
public | constant | ||
Groups:: |
public | function |