PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 10.3.0 10.4.0 All 60 releases
acymailing / back / dynamics / birthday / plugin.php

plugin.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at back/dynamics/birthday/plugin.php

54 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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