KanbanLogService.php in Content Planner 8
File
modules/content_kanban/src/KanbanLogService.php
View source
<?php
namespace Drupal\content_kanban;
use Drupal\content_kanban\Entity\KanbanLog;
use Drupal\Core\Database\Driver\mysql\Connection;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeManager;
class KanbanLogService {
protected $database;
protected $entityTypeManager;
public function __construct(Connection $database, EntityTypeManager $entityTypeManager) {
$this->database = $database;
$this->entityTypeManager = $entityTypeManager;
}
public function createLogEntity($name, $user_id, $entity_id, $entity_type, $workflow_id, $state_from = NULL, $state_to = NULL) {
$entity_build = [
'name' => $name,
'user_id' => $user_id,
'entity_id' => $entity_id,
'entity_type' => $entity_type,
'workflow_id' => $workflow_id,
'state_from' => $state_from,
'state_to' => $state_to,
];
$entity = KanbanLog::create($entity_build);
try {
return $entity
->save();
} catch (EntityStorageException $e) {
watchdog_exception('content_kanban', $e);
}
return 0;
}
public function getRecentLogs($limit = 10, array $filter = []) {
$query = $this->entityTypeManager
->getStorage('content_kanban_log')
->getQuery();
$query
->sort('created', 'DESC');
$query
->range(0, $limit);
if (isset($filter['exclude_anonymous_users']) && $filter['exclude_anonymous_users'] == TRUE) {
$query
->condition('user_id', 0, '<>');
}
$result = $query
->execute();
if ($result) {
return KanbanLog::loadMultiple($result);
}
return [];
}
}