diff --git a/src/EmailAlerter.php b/src/EmailAlerter.php index 17cfbd6..cda6b5d 100644 --- a/src/EmailAlerter.php +++ b/src/EmailAlerter.php @@ -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); diff --git a/src/TimeBasedFieldUpdater.php b/src/TimeBasedFieldUpdater.php index 2195946..ffe4794 100644 --- a/src/TimeBasedFieldUpdater.php +++ b/src/TimeBasedFieldUpdater.php @@ -4,28 +4,28 @@ namespace Drupal\opencase; use Drupal; final class TimeBasedFieldUpdater { - private string $date_field; + private string $date_field_to_compare; private string $entity_type; - private array $conditions; + private array $where; private string $date_format; - final public function __construct($entity_type, $date_field, $conditions = [], $date_format = 'Y-m-d') + final public function __construct($entity_type, $where = [], $date_field_to_compare, $date_format = 'Y-m-d') { - $this->date_field = $date_field; - $this->conditions = $conditions; + $this->date_field_to_compare = $date_field_to_compare; + $this->where = $where; $this->date_format = $date_format; $this->entity_type = $entity_type; } final public function update($time_elapsed, $old_values, $new_values): void { $query = Drupal::entityQuery($this->entity_type); - foreach($this->conditions as $cond_field=>$cond_value) { + foreach($this->where 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)), "<"); + $query->condition($this->date_field_to_compare, date($this->date_format, strtotime('-'.$time_elapsed)), "<"); foreach($query->execute() as $id) { $entity = Drupal::entityTypeManager()->getStorage($this->entity_type)->load($id); foreach($new_values as $new_field=>$new_value) {