OpignoGroupContext.php in Opigno group manager 3.x
File
src/OpignoGroupContext.php
View source
<?php
namespace Drupal\opigno_group_manager;
use Drupal\Core\Cache\Cache;
final class OpignoGroupContext {
const GROUP_ID = 'group_id';
const CURRENT_CONTENT_ID = 'current_content_id';
const ACTIVITY_LINK_TYPE = 'activity_link_type';
protected static function ensureSession() {
if (\Drupal::currentUser()
->isAnonymous() && !isset($_SESSION['session_started'])) {
$_SESSION['session_started'] = TRUE;
\Drupal::service('session_manager')
->start();
}
}
public static function getCurrentGroupId() {
static::ensureSession();
$group = \Drupal::routeMatch()
->getParameter('group');
if (!empty($group)) {
if (is_object($group)) {
return $group
->id();
}
else {
return $group;
}
}
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
return $store
->get(self::GROUP_ID);
}
public static function getCurrentGroupContentId() {
static::ensureSession();
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
return $store
->get(self::CURRENT_CONTENT_ID);
}
public static function getActivityLinkType() {
static::ensureSession();
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
return $store
->get(self::ACTIVITY_LINK_TYPE);
}
public static function setGroupId($group_id) {
static::ensureSession();
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
$store
->set(self::GROUP_ID, $group_id);
}
public static function setCurrentContentId($current_content_id) {
static::ensureSession();
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
if ($store
->get(self::CURRENT_CONTENT_ID) != $current_content_id) {
$store
->set(self::CURRENT_CONTENT_ID, $current_content_id);
self::rebuildActions();
}
}
public static function setActivityLinkType($activity_link_type) {
static::ensureSession();
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
$store
->set(self::ACTIVITY_LINK_TYPE, $activity_link_type);
}
public static function removeContext() {
static::ensureSession();
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
$store
->delete(self::GROUP_ID);
$store
->delete(self::CURRENT_CONTENT_ID);
$store
->delete(self::ACTIVITY_LINK_TYPE);
self::rebuildActions();
}
public static function removeActivityLinkType() {
static::ensureSession();
$store = \Drupal::service('tempstore.private')
->get('opigno_group_manager');
$store
->delete(self::ACTIVITY_LINK_TYPE);
self::rebuildActions();
}
public static function rebuildActions() {
$bins = Cache::getBins();
$bins['render']
->invalidateAll();
}
}
Classes
Name |
Description |
OpignoGroupContext |
This class manage the context when a user enters or exits a Learning Path. |