KanbanStatisticService.php in Content Planner 8
File
modules/content_kanban/src/KanbanStatisticService.php
View source
<?php
namespace Drupal\content_kanban;
use Drupal\Core\Database\Driver\mysql\Connection;
use Drupal\workflows\Entity\Workflow;
class KanbanStatisticService {
protected $database;
public function __construct(Connection $database) {
$this->database = $database;
}
public function getWorkflowStateContentCounts(Workflow $workflow) {
$workflow_states = KanbanWorkflowService::getWorkflowStates($workflow);
$data = [];
foreach ($workflow_states as $state_id => $state_label) {
$count = $this
->getWorkflowStateContentCount($workflow
->id(), $state_id);
$data[$state_id] = [
'id' => $state_id,
'label' => $state_label,
'count' => $count,
];
}
return $data;
}
public function getWorkflowStateContentCount($workflow_id, $state_id) {
$query = $this->database
->select('content_moderation_state_field_data', 'c');
$query
->addField('c', 'id');
$query
->condition('c.workflow', $workflow_id);
$query
->condition('c.moderation_state', $state_id);
$count_query = $query
->countQuery();
$result = $count_query
->execute()
->fetchObject();
return $result->expression;
}
}