class KanbanLogService in Content Planner 8
Class KanbanLogService.
Hierarchy
- class \Drupal\content_kanban\KanbanLogService
Expanded class hierarchy of KanbanLogService
1 string reference to 'KanbanLogService'
- content_kanban.services.yml in modules/
content_kanban/ content_kanban.services.yml - modules/content_kanban/content_kanban.services.yml
1 service uses KanbanLogService
- content_kanban.kanban_log_service in modules/
content_kanban/ content_kanban.services.yml - Drupal\content_kanban\KanbanLogService
File
- modules/
content_kanban/ src/ KanbanLogService.php, line 13
Namespace
Drupal\content_kanbanView source
class KanbanLogService {
/**
* Drupal\Core\Database\Driver\mysql\Connection definition.
*
* @var \Drupal\Core\Database\Driver\mysql\Connection
*/
protected $database;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new KanbanLogService object.
*/
public function __construct(Connection $database, EntityTypeManager $entityTypeManager) {
$this->database = $database;
$this->entityTypeManager = $entityTypeManager;
}
/**
* Creates a new log entry.
*
* @param string $name
* The name of the entry.
* @param int $user_id
* The user id.
* @param int $entity_id
* The entity id.
* @param string $entity_type
* The entity type.
* @param string $workflow_id
* The workflow id.
* @param null|string $state_from
* The state_from value if it exists, NULL by default.
* @param null|string $state_to
* The state_to value if it exists, NULL by default.
*
* @return int
* Returns the entity save response code for save action.
*/
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;
}
/**
* Get recent Logs.
*
* @param int $limit
* The limit of the queried logs.
* @param array $filter
* An array containing filters if any.
*
* @return \Drupal\content_kanban\Entity\KanbanLog[]
* Returns an array of Kanban logs.
*/
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 [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KanbanLogService:: |
protected | property | Drupal\Core\Database\Driver\mysql\Connection definition. | |
KanbanLogService:: |
protected | property | The entity type manager. | |
KanbanLogService:: |
public | function | Creates a new log entry. | |
KanbanLogService:: |
public | function | Get recent Logs. | |
KanbanLogService:: |
public | function | Constructs a new KanbanLogService object. |