🔖 Version 1.0.0-beta
This commit is contained in:
parent
c93a06972b
commit
460a811554
26 changed files with 2480 additions and 771 deletions
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Civi\Mailinglistsync;
|
||||
|
||||
use Civi\Api4\Contact;
|
||||
use Civi\Mailinglistsync\Exceptions\MailinglistException;
|
||||
use CRM_Mailinglistsync_ExtensionUtil as E;
|
||||
use Civi\Api4\Event;
|
||||
|
||||
|
@ -22,7 +25,7 @@ class EventMailingList extends BaseMailingList {
|
|||
* @return array
|
||||
*/
|
||||
protected function getEntity(): array {
|
||||
return $this->event;
|
||||
return $this->event ?? NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,20 +40,53 @@ class EventMailingList extends BaseMailingList {
|
|||
}
|
||||
|
||||
public function getRecipients(): array {
|
||||
// TODO: Implement getRecipients() method.
|
||||
try {
|
||||
$recipientData = Contact::get()
|
||||
->addSelect('id', 'first_name', 'last_name', 'email.email', 'Active_Directory.SID')
|
||||
->addJoin('Email AS email', 'LEFT', ['id', '=', 'email.contact_id'])
|
||||
->addJoin('Participant AS participant', 'INNER',
|
||||
['id', '=', 'participant.contact_id'],
|
||||
['participant.event_id', '=', $this->event['id']],
|
||||
['participant.status', 'IN', self::getEnabledParticipantStatus()],
|
||||
)
|
||||
->addGroupBy('id')
|
||||
->execute()
|
||||
->getArrayCopy();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
throw new MailinglistException(
|
||||
"Could not get recipients for event with id '{$this->event['id']}': {$e->getMessage()}",
|
||||
MailinglistException::ERROR_CODE_GET_RECIPIENTS_FAILED
|
||||
);
|
||||
}
|
||||
|
||||
$recipients = [];
|
||||
foreach ($recipientData as $recipient) {
|
||||
try {
|
||||
$recipients[$recipient['email.email']] = new MailingListRecipient(
|
||||
sid: $recipient['Active_Directory.SID'],
|
||||
contact_id: $recipient['id'],
|
||||
first_name: $recipient['first_name'],
|
||||
last_name: $recipient['last_name'],
|
||||
email: $recipient['email.email'],
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw new MailinglistException(
|
||||
"Could not create recipient object for contact with id '{$recipient['id']}'\n$e",
|
||||
MailinglistException::ERROR_CODE_GET_RECIPIENTS_FAILED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of participants status that are enabled for the mailing list.
|
||||
*
|
||||
* @return array
|
||||
* @return ?array
|
||||
*/
|
||||
public static function getEnabledParticipantStatus(): array {
|
||||
public static function getEnabledParticipantStatus(): ?array {
|
||||
return MailingListSettings::get(E::SHORT_NAME . '_participant_status');
|
||||
}
|
||||
|
||||
public static function create(array $values): BaseMailingList {
|
||||
// TODO: Implement create() method.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue