Merge branch 'master' of ssh://git.autonomic.zone:2222/autonomic-cooperative/opencase

This commit is contained in:
Nick 2022-04-22 10:34:09 +02:00
commit 952dc2ccf6
6 changed files with 77 additions and 23 deletions

View File

@ -96,36 +96,19 @@ function opencase_cases_get_activities(Drupal\opencase_cases\entity\OCCase $case
return $activities; return $activities;
} }
function opencase_cases_get_amount(Drupal\opencase_cases\entity\OCCaseFee $case_fee): string {
if (!isEmpty($case_fee->amount)) return $case_fee->amount->first()->value;
else return '0';
}
function opencase_cases_get_case(Drupal\opencase_cases\entity\OCCaseFee $case_fee): Drupal\opencase_cases\entity\OCCase {
return $case_fee->oc_case->referencedEntities()[0];
}
function opencase_cases_update_total_fee_for_case_belonging_to_case_fee(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
$total = 0;
$case = opencase_cases_get_case($case_fee);
$case_fees = opencase_cases_get_case_fees($case);
foreach($case_fees as $case_fee) {
$total += opencase_cases_get_amount($case_fee);
}
$case->set('total_fee', $total);
$case->save();
}
function opencase_cases_oc_case_fee_update(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void { function opencase_cases_oc_case_fee_update(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
opencase_cases_update_total_fee_for_case_belonging_to_case_fee($case_fee); $case = $case_fee->getCase();
$case->addToTotalFee($case_fee->amount->value - $case_fee->original->amount->value);
} }
function opencase_cases_oc_case_fee_insert(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void { function opencase_cases_oc_case_fee_insert(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
opencase_cases_update_total_fee_for_case_belonging_to_case_fee($case_fee); $case = $case_fee->getCase();
$case->addToTotalFee($case_fee->amount->value);
} }
function opencase_cases_oc_case_fee_delete(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void { function opencase_cases_oc_case_fee_delete(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
opencase_cases_update_total_fee_for_case_belonging_to_case_fee($case_fee); $case = $case_fee->getCase();
$case->addToTotalFee(0 - $case_fee->amount->value);
} }
function opencase_cases_entity_base_field_info($entity_type) { function opencase_cases_entity_base_field_info($entity_type) {

View File

@ -222,6 +222,10 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
return $this; return $this;
} }
public function addToTotalFee(float $amountToAdd): void {
$this->set('total_fee', $this->total_fee->value + $amountToAdd);
$this->save();
}
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -190,6 +190,10 @@ class OCCaseFee extends EditorialContentEntityBase implements OCCaseFeeInterface
return $this; return $this;
} }
public function getCase():\Drupal\opencase_cases\Entity\OCCase {
return \Drupal\opencase_cases\Entity\OCCase::load($this->oc_case->target_id);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -50,6 +50,11 @@ opencase.opencase_admin_menu:
route_name: opencase.opencase_admin_menu route_name: opencase.opencase_admin_menu
menu_name: opencase menu_name: opencase
weight: 100 weight: 100
opencase.manage_taxonomy_links:
class: Drupal\opencase\Plugin\Menu\ManageTaxonomyMenuLink
deriver: Drupal\opencase\Plugin\Derivative\ManageTaxonomyMenuLink
menu_name: opencase
parent: opencase.opencase_admin_menu
opencase.manage_user_logins: opencase.manage_user_logins:
title: 'Manage user logins' title: 'Manage user logins'
description: 'Manage who can access the system' description: 'Manage who can access the system'

View File

@ -0,0 +1,52 @@
<?php
namespace Drupal\opencase\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ManageTaxonomyMenuLink extends DeriverBase implements ContainerDeriverInterface {
/**
   * @var EntityTypeManagerInterface $entityTypeManager.
   */
protected $entityTypeManager;
/**
   * Creates a AddEventsMenuLink instance.
   *
   * @param $base_plugin_id
   * @param EntityTypeManagerInterface $entity_type_manager
   */
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
   * {@inheritdoc}
   */
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$base_plugin_id,
$container->get('entity_type.manager')
);
}
/**
   * {@inheritdoc}
   */
public function getDerivativeDefinitions($base_plugin_definition) {
$links = [];
$vocabs = $this->entityTypeManager->getStorage('taxonomy_vocabulary')->loadMultiple();
foreach ($vocabs as $id => $vocab) {
$links[$id] = [
'title' => 'Manage ' . $vocab->label(),
'route_name' => "entity.taxonomy_vocabulary.overview_form",
'route_parameters' => ['taxonomy_vocabulary' => $vocab->id()]
] + $base_plugin_definition;
}
return $links;
}
}

View File

@ -0,0 +1,6 @@
<?php
namespace Drupal\opencase\Plugin\Menu;
use Drupal\Core\Menu\MenuLinkDefault;
class ManageTaxonomyMenuLink extends MenuLinkDefault {}