Merge branch 'master' of ssh://git.autonomic.zone:2222/autonomic-cooperative/opencase
This commit is contained in:
@ -4,9 +4,8 @@ namespace Drupal\opencase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
class EmailAlerter {
|
||||
public function send_email_to_users_with_role(array $params, string $key, string $role): void {
|
||||
public function send_email_to_users_with_role(array $params, string $key, string $role, string $module): void {
|
||||
$mailManager = \Drupal::service('plugin.manager.mail');
|
||||
$module = 'goodnightout_opencase';
|
||||
$to = implode(',', $this->get_email_addresses_of_users_with_role($role));
|
||||
$send = true;
|
||||
$result = $mailManager->mail($module, $key, $to, NULL, $params, NULL, $send);
|
||||
|
52
src/Plugin/Block/AddActivity.php
Normal file
52
src/Plugin/Block/AddActivity.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\opencase\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
||||
/**
|
||||
* Provides a Block with some help text about actor type fields
|
||||
*
|
||||
* @Block(
|
||||
* id = "add_activity",
|
||||
* admin_label = @Translation("Add Activity"),
|
||||
* category = @Translation("Opencase"),
|
||||
* )
|
||||
*/
|
||||
class AddActivity extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build():array {
|
||||
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
|
||||
$target_id = $actor->id();
|
||||
$actorType = $actor->bundle();
|
||||
$markup = "<ul>";
|
||||
$activity_types = $this->getActivityTypesToDisplay($actorType);
|
||||
foreach($activity_types as $id => $info) {
|
||||
$label = $info['label'];
|
||||
$markup .= "<li><a href='/opencase/oc_activity/add/$id?target_id=$target_id&destination=/opencase/oc_actor/$target_id'>$label</a></li>";
|
||||
}
|
||||
$markup .= "</ul>";
|
||||
return array('#markup' => $markup);
|
||||
}
|
||||
|
||||
public function getCacheMaxAge():int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getActivityTypesToDisplay(string $actorType): array {
|
||||
// Client modules will provide a list of what activity types (bundles) are relevant for each actor type.
|
||||
// Check if they are implemented, and if so display them.
|
||||
$implemented_activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||
$relevant_activity_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_activity_type_ids', [$actorType]);
|
||||
$activity_types_to_display = [];
|
||||
foreach ($relevant_activity_type_ids as $type_id) {
|
||||
if (array_key_exists($type_id, $implemented_activity_types)) {
|
||||
$activity_types_to_display[$type_id] = $implemented_activity_types[$type_id];
|
||||
}
|
||||
}
|
||||
return $activity_types_to_display;
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ class AddEventsMenuLink extends DeriverBase implements ContainerDeriverInterface
|
||||
$eventTypes = $this->entityTypeManager->getStorage('oc_event_type')->loadMultiple();
|
||||
foreach ($eventTypes as $id => $eventType) {
|
||||
$links[$id] = [
|
||||
'title' => $eventType->label() . " Event",
|
||||
'title' => $eventType->label(),
|
||||
'route_name' => "entity.oc_event.add_form",
|
||||
'route_parameters' => ['oc_event_type' => $eventType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
@ -45,7 +45,7 @@ class SeeAllActorsMenuLink extends DeriverBase implements ContainerDeriverInterf
|
||||
$actorTypes = $this->entityTypeManager->getStorage('oc_actor_type')->loadMultiple();
|
||||
foreach ($actorTypes as $id => $actorType) {
|
||||
$links[$id] = [
|
||||
'title' => $actorType->label(),
|
||||
'title' => \Drupal\opencase\Pluraliser::pluralise($actorType->label()),
|
||||
'route_name' => "view.actors.page_1",
|
||||
'route_parameters' => ['type' => $actorType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
@ -50,7 +50,7 @@ class SeeAllEventsMenuLink extends DeriverBase implements ContainerDeriverInterf
|
||||
$eventTypes = $this->entityTypeManager->getStorage('oc_event_type')->loadMultiple();
|
||||
foreach ($eventTypes as $id => $eventType) {
|
||||
$links[$id] = [
|
||||
'title' => $eventType->label(),
|
||||
'title' => \Drupal\opencase\Pluraliser::pluralise($eventType->label()),
|
||||
'route_name' => "view.events.page_1",
|
||||
'route_parameters' => ['type' => $eventType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
@ -45,7 +45,7 @@ class SeeAllOrganisationsMenuLink extends DeriverBase implements ContainerDerive
|
||||
$organisationTypes = $this->entityTypeManager->getStorage('oc_organisation_type')->loadMultiple();
|
||||
foreach ($organisationTypes as $id => $organisationType) {
|
||||
$links[$id] = [
|
||||
'title' => $organisationType->label(),
|
||||
'title' => \Drupal\opencase\Pluraliser::pluralise($organisationType->label()),
|
||||
'route_name' => "view.organisations.page_1",
|
||||
'route_parameters' => ['type' => $organisationType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
9
src/Pluraliser.php
Normal file
9
src/Pluraliser.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opencase;
|
||||
|
||||
class Pluraliser {
|
||||
public static function pluralise($text) {
|
||||
return $text . "s";
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace Drupal\opencase;
|
||||
use Drupal;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\opencase\Utils;
|
||||
|
||||
final class TimeBasedFieldUpdater {
|
||||
|
||||
@ -12,24 +13,25 @@ final class TimeBasedFieldUpdater {
|
||||
private array $conditions;
|
||||
private string $date_format;
|
||||
|
||||
final public function __construct(EntityTypeManagerInterface $entityTypeManager, string $entity_type, string $date_field, array $conditions = [], string $date_format = 'Y-m-d')
|
||||
final public function __construct(
|
||||
EntityTypeManagerInterface $entityTypeManager,
|
||||
Utils $utils,
|
||||
string $entity_type, string $bundle, string $date_field, string $date_format = 'Y-m-d'
|
||||
)
|
||||
{
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
$this->utils = $utils;
|
||||
$this->date_field = $date_field;
|
||||
$this->conditions = $conditions;
|
||||
$this->date_format = $date_format;
|
||||
$this->entity_type = $entity_type;
|
||||
$this->bundle = $bundle;
|
||||
}
|
||||
|
||||
final public function update(string $time_elapsed, array $old_values, array $new_values): void {
|
||||
final public function update(array $conditions, string $time_elapsed, array $new_values): void {
|
||||
$query = $this->entityTypeManager->getStorage($this->entity_type)->getQuery();
|
||||
foreach($this->conditions as $cond_field=>$cond_value) {
|
||||
$query->condition($cond_field, $cond_value);
|
||||
}
|
||||
foreach($old_values as $old_field=>$old_value) {
|
||||
$query->condition($old_field, $old_value);
|
||||
}
|
||||
$query->condition($this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<");
|
||||
$conditions[] = [$this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<"];
|
||||
$conditions[] = ['type', $this->bundle, '='];
|
||||
$this->utils->addConditionsToQuery($query, $conditions);
|
||||
foreach($query->execute() as $id) {
|
||||
$entity = $this->entityTypeManager->getStorage($this->entity_type)->load($id);
|
||||
foreach($new_values as $new_field=>$new_value) {
|
||||
|
52
src/Utils.php
Normal file
52
src/Utils.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php declare(strict_types =1);
|
||||
|
||||
namespace Drupal\opencase;
|
||||
|
||||
use \Drupal;
|
||||
use Drupal\Core\Entity\EntityTypeManager;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
class Utils {
|
||||
|
||||
public function __construct(
|
||||
EntityTypeManager $entityTypeManager = null
|
||||
) {
|
||||
if ($entityTypeManager == null) {
|
||||
$entityTypeManager = Drupal::entityTypeManager();
|
||||
}
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
}
|
||||
|
||||
public function addConditionsToQuery(QueryInterface $query, array $conditions): void {
|
||||
foreach($conditions as $condition) {
|
||||
$field = $condition[0];
|
||||
$value = $condition[1];
|
||||
$operator = $condition[2];
|
||||
$query->condition($field, $value, $operator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility: find term by name and vid.
|
||||
*
|
||||
* @param string $name
|
||||
* Term name.
|
||||
* @param string $vid
|
||||
* Term vid.
|
||||
* @return int
|
||||
* Term id, or 0 if none.
|
||||
*/
|
||||
public function getTidByName(string $name, string $vid):int {
|
||||
if (empty($name) || empty($vid)) {
|
||||
return 0;
|
||||
}
|
||||
$properties = [
|
||||
'name' => $name,
|
||||
'vid' => $vid,
|
||||
];
|
||||
$terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadByProperties($properties);
|
||||
$term = reset($terms);
|
||||
return (int)(!empty($term) ? $term->id() : 0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user