| 1 |
<?php |
| 2 |
defined('ABSPATH') || die('Restricted Access'); |
| 3 |
|
| 4 |
use AcyMailing\Core\AcymPlugin; |
| 5 |
use AcyMailing\Classes\FieldClass; |
| 6 |
|
| 7 |
require_once __DIR__.DIRECTORY_SEPARATOR.'BirthdayAutomationTriggers.php'; |
| 8 |
require_once __DIR__.DIRECTORY_SEPARATOR.'BirthdayCampaignType.php'; |
| 9 |
require_once __DIR__.DIRECTORY_SEPARATOR.'BirthdayFollowup.php'; |
| 10 |
|
| 11 |
class plgAcymBirthday extends AcymPlugin |
| 12 |
{ |
| 13 |
use BirthdayAutomationTriggers; |
| 14 |
use BirthdayCampaignType; |
| 15 |
use BirthdayFollowup; |
| 16 |
|
| 17 |
public function onAcymProcessFilter_birthday(&$query, $options, $num = null) |
| 18 |
{ |
| 19 |
if ($options['plugin'] !== get_class($this)) return; |
| 20 |
|
| 21 |
$dateToCheck = $this->processDateToCheck($options); |
| 22 |
|
| 23 |
$fieldClass = new FieldClass(); |
| 24 |
$birthdayField = $fieldClass->getOneById((int)$options['field']); |
| 25 |
if (empty($birthdayField)) { |
| 26 |
// Prevent the campaign from being sent to everyone |
| 27 |
$query->where[] = '0 = 1'; |
| 28 |
|
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$query->join['birthday_field'.$num] = '#__acym_user_has_field AS uf'.$num.' ON uf'.$num.'.user_id = user.id'; |
| 33 |
$query->where[] = 'uf'.$num.'.field_id = '.intval($birthdayField->id); |
| 34 |
$query->where[] = 'uf'.$num.'.value LIKE '.acym_escapeDB('%'.date_format($dateToCheck, '-m-d')); |
| 35 |
} |
| 36 |
|
| 37 |
public function getBirthdayField(&$availableFields) |
| 38 |
{ |
| 39 |
$fieldClass = new FieldClass(); |
| 40 |
$dateFields = $fieldClass->getFieldsByType(['date']); |
| 41 |
foreach ($dateFields as $oneField) { |
| 42 |
$availableFields[$oneField->id] = acym_translation($oneField->name); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
public function getJsonBirthdayField() |
| 47 |
{ |
| 48 |
$availableFields = []; |
| 49 |
$this->getBirthdayField($availableFields); |
| 50 |
echo json_encode(['fields' => $availableFields]); |
| 51 |
exit; |
| 52 |
} |
| 53 |
} |
| 54 |
|