StreamTestController.php in Heartbeat 8
File
src/Controller/StreamTestController.php
View source
<?php
namespace Drupal\heartbeat\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\heartbeat\HeartbeatService;
use Drupal\heartbeat\HeartbeatStreamServices;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManager;
class StreamTestController extends ControllerBase {
protected $entityQuery;
protected $entityTypeManager;
protected $heartbeatStreamService;
protected $heartbeatService;
public function __construct(QueryFactory $entity_query, EntityTypeManager $entity_type_manager, HeartbeatStreamServices $heartbeatStreamService, HeartbeatService $heartbeatService) {
$this->entityQuery = $entity_query;
$this->entityTypeManager = $entity_type_manager;
$this->heartbeatStreamService = $heartbeatStreamService;
$this->heartbeatService = $heartbeatService;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.query'), $container
->get('entity_type.manager'), $container
->get('heartbeatstream'), $container
->get('heartbeat'));
}
public function stream() {
$messages = array();
$types = $this->heartbeatStreamService
->getTypesById(1);
foreach ($types as $type) {
if ($type != null) {
$heartbeatType = $type
->getValue();
$heartbeats = $this->heartbeatService
->loadByType($heartbeatType);
foreach ($heartbeats as $heartbeat) {
$messages[] = $heartbeat
->getMessage()
->getValue()[0]['value'];
}
}
}
return [
'#theme' => 'heartbeat_stream',
'#messages' => array_reverse($messages),
'#attached' => array(
'library' => 'heartbeat/heartbeat',
),
];
}
public function friendstream() {
$messages = array();
$types = $this->heartbeatStreamService
->getTypesById(2);
foreach ($types as $type) {
if ($type != null) {
$heartbeatType = $type
->getValue();
$heartbeats = $this->heartbeatService
->loadByType($heartbeatType);
foreach ($heartbeats as $heartbeat) {
$messages[] = $heartbeat
->getMessage()
->getValue()[0]['value'];
}
}
}
return [
'#theme' => 'heartbeat_stream',
'#messages' => array_reverse($messages),
'#attached' => array(
'library' => 'heartbeat/heartbeat',
),
];
}
public function tweetstream() {
$messages = array();
$types = $this->heartbeatStreamService
->getTypesById(3);
foreach ($types as $type) {
if ($type != null) {
$heartbeatType = $type
->getValue();
$heartbeats = $this->heartbeatService
->loadByType($heartbeatType);
foreach ($heartbeats as $heartbeat) {
$messages[] = $heartbeat
->getMessage()
->getValue()[0]['value'];
}
}
}
return [
'#theme' => 'heartbeat_stream',
'#messages' => array_reverse($messages),
'#attached' => array(
'library' => 'heartbeat/heartbeat',
),
];
}
public function superherostream() {
$messages = array();
$types = $this->heartbeatStreamService
->getTypesById(4);
foreach ($types as $type) {
if ($type != null) {
$heartbeatType = $type
->getValue();
$heartbeats = $this->heartbeatService
->loadByType($heartbeatType);
foreach ($heartbeats as $heartbeat) {
$messages[] = $heartbeat
->getMessage()
->getValue()[0]['value'];
}
}
}
return [
'#theme' => 'heartbeat_stream',
'#messages' => array_reverse($messages),
'#attached' => array(
'library' => 'heartbeat/heartbeat',
),
];
}
}