total cases field is working.

This commit is contained in:
naomi 2022-05-18 13:27:14 +01:00
parent cfec9be05c
commit 13fb920e69
2 changed files with 17 additions and 4 deletions

View File

@ -208,15 +208,17 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
}
public function getCountOfCaseProvisions(array $conditions = []): int {
public function getCountOfCaseProvisions(array $conditionsToApplyToCaseProvisionQuery = []): int {
$query = \Drupal::entityQuery('oc_case_provision');
$query->condition('oc_provider', $this->id());
// foreach($conditions as $condition) {
// $query->condition($condition);
// }
return count($query->execute());
}
public function calculateTotalCases(): void {
$this->set('total_cases', $this->getCountOfCaseProvisions());
$this->save();
}
/**
* {@inheritdoc}
*/

View File

@ -7,6 +7,7 @@
use Drupal\Core\Render\Element;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\opencase_cases\Entity\OCCaseProvision;
/**
* Implements hook_element_info_alter().
@ -44,6 +45,16 @@ function opencase_process_element($element) {
$element['time']['#attributes']['step'] = 60;
return $element;
}
function opencase_oc_case_provision_insert(OCCaseProvision $case_provision): void {
$case_provision->oc_provider->entity->calculateTotalCases();
}
function opencase_oc_case_provision_delete(OCCaseProvision $case_provision): void {
$case_provision->oc_provider->entity->calculateTotalCases();
}
function opencase_oc_case_provision_update(OCCaseProvision $case_provision): void {
$case_provision->oc_provider->entity->calculateTotalCases();
$case_provision->original->oc_provider->entity->calculateTotalCases();
}
/**
* Implements hook_page_attachments