🎉 initial commit
This commit is contained in:
commit
c93a06972b
27 changed files with 4189 additions and 0 deletions
49
Civi/Mailinglistsync/Utils.php
Normal file
49
Civi/Mailinglistsync/Utils.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Civi\Mailinglistsync;
|
||||
|
||||
use Civi\Api4\LocationType;
|
||||
use Civi\Mailinglistsync\Exceptions\MailinglistException;
|
||||
use CRM_Mailinglistsync_ExtensionUtil as E;
|
||||
|
||||
/**
|
||||
* Gets the location type IDs for mailing list email-addresses either from
|
||||
* the database or from the cache.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Civi\Mailinglistsync\Exceptions\MailinglistException
|
||||
*/
|
||||
function getLocationTypes(): array {
|
||||
// Try to get location types from cache
|
||||
$locationTypes = \Civi::cache()->get(E::SHORT_NAME . '_location_types');
|
||||
|
||||
// Get location types from database if not in cache
|
||||
if ($locationTypes === NULL) {
|
||||
$locationTypeNames = [
|
||||
GroupMailingList::getLocationTypeName(),
|
||||
ADGroupMailingList::getLocationTypeName(),
|
||||
EventMailingList::getLocationTypeName(),
|
||||
];
|
||||
try {
|
||||
$result = LocationType::get()
|
||||
->addSelect('id', 'name')
|
||||
->addWhere('name', 'IN', $locationTypeNames)
|
||||
->execute()
|
||||
->getArrayCopy();
|
||||
$locationTypes = [];
|
||||
foreach ($result as $locationType) {
|
||||
$locationTypes[$locationType['id']] = $locationType['name'];
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
throw new MailinglistException(
|
||||
E::ts('Could not get location types'),
|
||||
MailinglistException::ERROR_CODE_GET_LOCATION_TYPES_FAILED,
|
||||
);
|
||||
}
|
||||
// Cache location types
|
||||
\Civi::cache()->set(E::SHORT_NAME . '_location_types', $locationTypes);
|
||||
}
|
||||
|
||||
return $locationTypes;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue