Mailigen_Synchronizer - Version 1.1.0

Version Notes

- One-way Magento customers synchronization. All customer information (customer address, last login date, items in cart, orders information) from Magento store will be synced with selected Mailigen contact list.
- Automatic synchronization between your Magento customer list and one of your Mailigen email lists. When customer registers in Magento, they will be added to the selected Mailigen contact list.

Download this release

Release Info

Developer Thomas Nelson
Extension Mailigen_Synchronizer
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.1 to 1.1.0

Files changed (25) hide show
  1. app/code/community/Mailigen/Synchronizer/Block/Adminhtml/Sync/Information.php +268 -0
  2. app/code/community/Mailigen/Synchronizer/Block/Newsletter/Subscriber/Grid.php +8 -9
  3. app/code/community/Mailigen/Synchronizer/Helper/Customer.php +166 -0
  4. app/code/community/Mailigen/Synchronizer/Helper/Data.php +183 -1
  5. app/code/community/Mailigen/Synchronizer/Helper/Log.php +30 -0
  6. app/code/community/Mailigen/Synchronizer/Model/Customer.php +229 -0
  7. app/code/community/Mailigen/Synchronizer/Model/Customer/Merge/Field.php +220 -0
  8. app/code/community/Mailigen/Synchronizer/Model/List.php +103 -32
  9. app/code/community/Mailigen/Synchronizer/Model/Mailigen.php +421 -77
  10. app/code/community/Mailigen/Synchronizer/Model/Newsletter/Subscriber.php +37 -31
  11. app/code/community/Mailigen/Synchronizer/Model/Observer.php +256 -147
  12. app/code/community/Mailigen/Synchronizer/Model/Resource/Customer.php +16 -0
  13. app/code/community/Mailigen/Synchronizer/Model/Resource/Customer/Collection.php +42 -0
  14. app/code/community/Mailigen/Synchronizer/Model/Resource/Iterator/Batched.php +56 -0
  15. app/code/community/Mailigen/Synchronizer/Model/Schedule.php +88 -0
  16. app/code/community/Mailigen/Synchronizer/Model/System/Config/Backend/Customer/List.php +43 -0
  17. app/code/community/Mailigen/Synchronizer/Model/System/Config/Backend/Newsletter/List.php +34 -0
  18. app/code/community/Mailigen/Synchronizer/controllers/Adminhtml/MailigenController.php +58 -12
  19. app/code/community/Mailigen/Synchronizer/data/mailigen_synchronizer_setup/data-install-1.1.0.php +30 -0
  20. app/code/community/Mailigen/Synchronizer/etc/config.xml +121 -24
  21. app/code/community/Mailigen/Synchronizer/etc/system.xml +166 -89
  22. app/code/community/Mailigen/Synchronizer/sql/mailigen_synchronizer_setup/install-1.1.0.php +44 -0
  23. app/etc/modules/Mailigen_Synchronizer.xml +0 -9
  24. {app/code/community/Mailigen/Synchronizer/api → lib/mailigen}/MGAPI.class.php +1651 -1626
  25. package.xml +10 -8
app/code/community/Mailigen/Synchronizer/Block/Adminhtml/Sync/Information.php ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Block_Adminhtml_Sync_Information
11
+ extends Mage_Adminhtml_Block_Abstract
12
+ implements Varien_Data_Form_Element_Renderer_Interface
13
+ {
14
+ /**
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ public function render(Varien_Data_Form_Element_Abstract $element)
19
+ {
20
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
21
+ $helper = Mage::helper('mailigen_synchronizer');
22
+
23
+ $lastSyncedText = $this->_getLastSyncedText();
24
+ $syncedCustomersProgress = $this->_getSyncedCustomersProgress();
25
+ $syncStatusText = $this->_getSyncStatusText();
26
+
27
+ $html = '<style type="text/css">
28
+ .progress {
29
+ padding: 2px;
30
+ background: rgba(0, 0, 0, 0.25);
31
+ border-radius: 6px;
32
+ -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
33
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
34
+ }
35
+ .progress-bar {
36
+ font-size: 12px;
37
+ color: #111;
38
+ text-align: left;
39
+ text-indent: 6px;
40
+ position: relative;
41
+ height: 16px;
42
+ border-radius: 4px;
43
+ background-color: #86e01e;
44
+ -webkit-transition: 0.4s linear;
45
+ -moz-transition: 0.4s linear;
46
+ -ms-transition: 0.4s linear;
47
+ -o-transition: 0.4s linear;
48
+ transition: 0.4s linear;
49
+ -webkit-transition-property: width, background-color;
50
+ -moz-transition-property: width, background-color;
51
+ -ms-transition-property: width, background-color;
52
+ -o-transition-property: width, background-color;
53
+ transition-property: width, background-color;
54
+ -webkit-box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1);
55
+ box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1);
56
+
57
+ }
58
+ .progress-bar:before, .progress-bar:after {
59
+ content: "";
60
+ top: 0;
61
+ right: 0;
62
+ left: 0;
63
+ position: absolute;
64
+ }
65
+ .progress-bar:before {
66
+ bottom: 0;
67
+ z-index: 2;
68
+ border-radius: 4px 4px 0 0;
69
+ }
70
+ .progress-bar:after {
71
+ bottom: 45%;
72
+ z-index: 3;
73
+ border-radius: 4px;
74
+ background-color: transparent;
75
+ background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(255, 255, 255, 0.3)), color-stop(100%, rgba(255, 255, 255, 0.05)));
76
+ background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
77
+ background-image: -moz-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
78
+ background-image: -ms-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
79
+ background-image: -o-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
80
+ background-image: linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
81
+ }
82
+ </style>
83
+ <table cellspacing="0" class="form-list">
84
+ <tr>
85
+ <td class="label">' . $helper->__('Last Synced') . '</td>
86
+ <td class="value">' . $lastSyncedText . '</td>
87
+ <td class="scope-label"></td>
88
+ <td></td>
89
+ </tr>
90
+ <tr>
91
+ <td class="label">' . $helper->__('Synced Customers') . '</td>
92
+ <td class="value">
93
+ <div class="progress">
94
+ <div class="progress-bar" style="width:' . $syncedCustomersProgress['percent'] . '%;">
95
+ ' . $syncedCustomersProgress['text'] . '
96
+ </div>
97
+ </div>
98
+ </td>
99
+ <td class="scope-label"></td>
100
+ <td></td>
101
+ </tr>
102
+ <tr>
103
+ <td class="label">' . $helper->__('Sync Status') . '</td>
104
+ <td class="value">' . $syncStatusText . '</td>
105
+ <td class="scope-label"></td>
106
+ <td></td>
107
+ </tr>
108
+ </table>';
109
+
110
+ return $html;
111
+ }
112
+
113
+ /**
114
+ * Get last synced datetime
115
+ *
116
+ * @return string
117
+ */
118
+ protected function _getLastSyncedText()
119
+ {
120
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
121
+ $helper = Mage::helper('mailigen_synchronizer');
122
+
123
+ $lastSynced = Mage::getModel('mailigen_synchronizer/customer')->getCollection()
124
+ ->setPageSize(1)
125
+ ->setCurPage(1)
126
+ ->setOrder('synced_at')
127
+ ->load();
128
+ if ($lastSynced && $lastSynced->getFirstItem()) {
129
+ $lastSynced = $lastSynced->getFirstItem()->getSyncedAt();
130
+ // $lastSyncedText = $helper->time_elapsed_string($lastSynced, true);
131
+ $lastSyncedText = Mage::helper('core')->formatDate($lastSynced, 'medium', true);
132
+ } else {
133
+ $lastSyncedText = $helper->__('Not synced yet');
134
+ }
135
+
136
+ return $lastSyncedText;
137
+ }
138
+
139
+ /**
140
+ * Get synced customers progress
141
+ *
142
+ * @return array
143
+ */
144
+ protected function _getSyncedCustomersProgress()
145
+ {
146
+ $totalCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCollection()->getSize();
147
+ $syncedCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCollection()
148
+ ->addFieldToFilter('is_synced', 1)
149
+ ->getSize();
150
+ $syncedCustomersPercent = round($syncedCustomers / $totalCustomers * 100);
151
+ $syncedCustomersText = "$syncedCustomersPercent% ($syncedCustomers/$totalCustomers)";
152
+
153
+ return array('percent' => $syncedCustomersPercent, 'text' => $syncedCustomersText);
154
+ }
155
+
156
+ /**
157
+ * Get Sync status and show stop button
158
+ *
159
+ * @return string
160
+ */
161
+ protected function _getSyncStatusText()
162
+ {
163
+ /** @var $mailigenSchedule Mailigen_Synchronizer_Model_Schedule */
164
+ $mailigenSchedule = Mage::getModel('mailigen_synchronizer/schedule');
165
+ $runningJob = $mailigenSchedule->getLastRunningJob();
166
+ $pendingJob = $mailigenSchedule->getLastPendingJob();
167
+
168
+ if ($runningJob) {
169
+ $html = "Running";
170
+ if (strlen($runningJob->getExecutedAt())) {
171
+ $html .= ' (Started at: ';
172
+ $html .= Mage::helper('core')->formatDate($runningJob->getExecutedAt(), 'medium', true);
173
+ $html .= ') ';
174
+
175
+ /**
176
+ * Show stop sync customers button
177
+ */
178
+ $html .= $this->_getStopCustomersSyncButton();
179
+ }
180
+ }
181
+ elseif ($pendingJob) {
182
+ $html = "Pending";
183
+ if (strlen($pendingJob->getScheduledAt())) {
184
+ $html .= ' (Scheduled at: ';
185
+ $html .= Mage::helper('core')->formatDate($pendingJob->getScheduledAt(), 'medium', true);
186
+ $html .= ')';
187
+ }
188
+ }
189
+ else {
190
+ $html = "Not scheduled";
191
+ /**
192
+ * Show reset sync customers button
193
+ */
194
+ $html .= ' '.$this->_getResetCustomersSyncButton();
195
+ }
196
+
197
+ return $html;
198
+ }
199
+
200
+ /**
201
+ * Get Stop customers sync button html
202
+ *
203
+ * @return string
204
+ */
205
+ protected function _getStopCustomersSyncButton()
206
+ {
207
+ $stopSyncUrl = Mage::helper('adminhtml')->getUrl('*/mailigen/stopSyncCustomers');
208
+ $buttonJs = '<script type="text/javascript">
209
+ //<![CDATA[
210
+ function stopMailigenSynchronizer() {
211
+ new Ajax.Request("' . $stopSyncUrl . '", {
212
+ method: "get",
213
+ onSuccess: function(transport){
214
+ if (transport.responseText){
215
+ alert(transport.responseText);
216
+ }
217
+ }
218
+ });
219
+ }
220
+ //]]>
221
+ </script>';
222
+
223
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
224
+ ->setData(array(
225
+ 'id' => 'stop_mailigen_synchronizer_button',
226
+ 'label' => $this->helper('adminhtml')->__('Stop sync'),
227
+ 'onclick' => 'javascript:stopMailigenSynchronizer(); return false;'
228
+ ));
229
+
230
+ return $buttonJs . $button->toHtml();
231
+ }
232
+
233
+ /**
234
+ * Get Reset customers sync button html
235
+ *
236
+ * @return string
237
+ */
238
+ protected function _getResetCustomersSyncButton()
239
+ {
240
+ $resetSyncUrl = Mage::helper('adminhtml')->getUrl('*/mailigen/resetSyncCustomers');
241
+ $buttonJs = '<script type="text/javascript">
242
+ //<![CDATA[
243
+ function resetMailigenSynchronizer() {
244
+ new Ajax.Request("' . $resetSyncUrl . '", {
245
+ method: "get",
246
+ onSuccess: function(transport){
247
+ if (transport.responseText == "1"){
248
+ window.location.reload();
249
+ }
250
+ else {
251
+ alert(transport.responseText);
252
+ }
253
+ }
254
+ });
255
+ }
256
+ //]]>
257
+ </script>';
258
+
259
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
260
+ ->setData(array(
261
+ 'id' => 'reset_mailigen_synchronizer_button',
262
+ 'label' => $this->helper('adminhtml')->__('Reset sync'),
263
+ 'onclick' => 'javascript:resetMailigenSynchronizer(); return false;'
264
+ ));
265
+
266
+ return $buttonJs . $button->toHtml();
267
+ }
268
+ }
app/code/community/Mailigen/Synchronizer/Block/Newsletter/Subscriber/Grid.php CHANGED
@@ -1,16 +1,15 @@
1
- <?php
2
 
3
  class Mailigen_Synchronizer_Block_Newsletter_Subscriber_Grid extends Mage_Adminhtml_Block_Newsletter_Subscriber_Grid
4
  {
5
- protected function _prepareLayout()
6
  {
7
-
8
  $this->setChild('sync_button',
9
  $this->getLayout()->createBlock('adminhtml/widget_button')
10
  ->setData(array(
11
- 'label' => Mage::helper('adminhtml')->__('Bulk synchronize with Mailigen'),
12
- 'onclick' => "setLocation('{$this->getUrl('*/mailigen/sync')}')",
13
- 'class' => 'task'
14
  ))
15
  );
16
 
@@ -26,10 +25,10 @@ class Mailigen_Synchronizer_Block_Newsletter_Subscriber_Grid extends Mage_Adminh
26
  {
27
  $html = parent::getMainButtonsHtml();
28
 
29
- $enabled = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_status');
30
 
31
- if( $enabled ) {
32
- $html.= $this->getSyncButtonHtml();
33
  }
34
 
35
  return $html;
1
+ <?php
2
 
3
  class Mailigen_Synchronizer_Block_Newsletter_Subscriber_Grid extends Mage_Adminhtml_Block_Newsletter_Subscriber_Grid
4
  {
5
+ protected function _prepareLayout()
6
  {
 
7
  $this->setChild('sync_button',
8
  $this->getLayout()->createBlock('adminhtml/widget_button')
9
  ->setData(array(
10
+ 'label' => Mage::helper('adminhtml')->__('Bulk synchronize with Mailigen'),
11
+ 'onclick' => "setLocation('{$this->getUrl('*/mailigen/syncNewsletter')}')",
12
+ 'class' => 'task'
13
  ))
14
  );
15
 
25
  {
26
  $html = parent::getMainButtonsHtml();
27
 
28
+ $enabled = $this->helper('mailigen_synchronizer')->isEnabled();
29
 
30
+ if ($enabled) {
31
+ $html .= $this->getSyncButtonHtml();
32
  }
33
 
34
  return $html;
app/code/community/Mailigen/Synchronizer/Helper/Customer.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Helper_Customer extends Mage_Core_Helper_Abstract
11
+ {
12
+ /**
13
+ * @var array
14
+ */
15
+ protected $_storeLang = array();
16
+
17
+ /**
18
+ * @var null|array
19
+ */
20
+ protected $_customerGroup = null;
21
+
22
+ /**
23
+ * @var null
24
+ */
25
+ protected $_website = null;
26
+
27
+
28
+ /**
29
+ * @var null
30
+ */
31
+ protected $_customerGender = null;
32
+
33
+ /**
34
+ * @var null
35
+ */
36
+ protected $_countries = null;
37
+
38
+ /**
39
+ * @var array
40
+ */
41
+ public $customerStatus = array(0 => 'Inactive', 1 => 'Active');
42
+
43
+ /**
44
+ * @param $date
45
+ * @return bool|string
46
+ */
47
+ public function getFormattedDate($date)
48
+ {
49
+ if (is_numeric($date)) {
50
+ $date = date('d/m/Y', $date);
51
+ } elseif (is_string($date) && !empty($date)) {
52
+ $date = date('d/m/Y', strtotime($date));
53
+ } else {
54
+ $date = '';
55
+ }
56
+ return $date;
57
+ }
58
+
59
+ /**
60
+ * @return array
61
+ */
62
+ public function getGenders()
63
+ {
64
+ if (is_null($this->_customerGender)) {
65
+ $genders = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions(false);
66
+ foreach ($genders as $gender) {
67
+ $this->_customerGender[$gender['value']] = $gender['label'];
68
+ }
69
+ }
70
+ return $this->_customerGender;
71
+ }
72
+ /**
73
+ * @param $gender
74
+ * @return string
75
+ */
76
+ public function getFormattedGender($gender)
77
+ {
78
+ $genders = $this->getGenders();
79
+ return (!is_null($gender) && isset($genders[$gender])) ? $genders[$gender] : '';
80
+ }
81
+
82
+ /**
83
+ * @return array|null
84
+ */
85
+ public function getCustomerGroups()
86
+ {
87
+ if (is_null($this->_customerGroup)) {
88
+ $this->_customerGroup = array();
89
+ /** @var $groups Mage_Customer_Model_Resource_Group_Collection */
90
+ $groups = Mage::getModel('customer/group')->getCollection();
91
+ foreach ($groups as $group) {
92
+ $this->_customerGroup[$group->getCustomerGroupId()] = $group->getCustomerGroupCode();
93
+ }
94
+ }
95
+ return $this->_customerGroup;
96
+ }
97
+
98
+ /**
99
+ * @param $groupId
100
+ * @return string
101
+ */
102
+ public function getCustomerGroup($groupId)
103
+ {
104
+ $groups = $this->getCustomerGroups();
105
+ return isset($groups[$groupId]) ? $groups[$groupId] : '';
106
+ }
107
+
108
+ /**
109
+ * @param $status
110
+ * @return string
111
+ */
112
+ public function getFormattedCustomerStatus($status)
113
+ {
114
+ return $status ? $this->customerStatus[1] : $this->customerStatus[0];
115
+ }
116
+
117
+ /**
118
+ * @param $storeId
119
+ * @return mixed
120
+ */
121
+ public function getStoreLanguage($storeId)
122
+ {
123
+ if (!isset($this->_storeLang[$storeId])) {
124
+ $this->_storeLang[$storeId] = substr(Mage::getStoreConfig('general/locale/code', $storeId), 0, 2);
125
+ }
126
+ return $this->_storeLang[$storeId];
127
+ }
128
+
129
+ /**
130
+ * @param $storeId
131
+ * @return mixed
132
+ */
133
+ public function getWebsite($storeId)
134
+ {
135
+ if (!isset($this->_website[$storeId])) {
136
+ /** @var $store Mage_Core_Model_Store */
137
+ $store = Mage::getModel('core/store')->load($storeId);
138
+ $this->_website[$storeId] = $store->getWebsite();
139
+ }
140
+ return $this->_website[$storeId];
141
+ }
142
+
143
+ /**
144
+ * @return array
145
+ */
146
+ public function getCountries()
147
+ {
148
+ if (is_null($this->_countries)) {
149
+ $countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false);
150
+ foreach ($countries as $country) {
151
+ $this->_countries[$country['value']] = $country['label'];
152
+ }
153
+ }
154
+ return $this->_countries;
155
+ }
156
+
157
+ /**
158
+ * @param $country
159
+ * @return string
160
+ */
161
+ public function getFormattedCountry($country)
162
+ {
163
+ $countries = $this->getCountries();
164
+ return isset($countries[$country]) ? $countries[$country] : '';
165
+ }
166
+ }
app/code/community/Mailigen/Synchronizer/Helper/Data.php CHANGED
@@ -1,3 +1,185 @@
1
  <?php
2
 
3
- class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
11
+ {
12
+ const XML_PATH_ENABLED = 'mailigen_synchronizer/general/enabled';
13
+ const XML_PATH_API_KEY = 'mailigen_synchronizer/general/api_key';
14
+ const XML_PATH_NEWSLETTER_CONTACT_LIST = 'mailigen_synchronizer/newsletter/contact_list';
15
+ const XML_PATH_NEWSLETTER_NEW_LIST_TITLE = 'mailigen_synchronizer/newsletter/new_list_title';
16
+ const XML_PATH_NEWSLETTER_AUTOSYNC = 'mailigen_synchronizer/newsletter/autosync';
17
+ const XML_PATH_NEWSLETTER_HANDLE_DEFAULT_EMAILS = 'mailigen_synchronizer/newsletter/handle_default_emails';
18
+ const XML_PATH_CUSTOMERS_CONTACT_LIST = 'mailigen_synchronizer/customers/contact_list';
19
+ const XML_PATH_CUSTOMERS_NEW_LIST_TITLE = 'mailigen_synchronizer/customers/new_list_title';
20
+ const XML_PATH_CUSTOMERS_AUTOSYNC = 'mailigen_synchronizer/customers/autosync';
21
+ const XML_PATH_CUSTOMERS_MANUAL_SYNC = 'mailigen_synchronizer/customers/manual_sync';
22
+ const XML_PATH_CUSTOMERS_STOP_SYNC = 'mailigen_synchronizer/customers/stop_sync';
23
+
24
+ protected $_mgapi = null;
25
+
26
+ /**
27
+ * @param null $storeId
28
+ * @return bool
29
+ */
30
+ public function isEnabled($storeId = null)
31
+ {
32
+ return Mage::getStoreConfigFlag(self::XML_PATH_ENABLED, $storeId);
33
+ }
34
+
35
+ /**
36
+ * @param null $storeId
37
+ * @return mixed
38
+ */
39
+ public function getApiKey($storeId = null)
40
+ {
41
+ return Mage::getStoreConfig(self::XML_PATH_API_KEY, $storeId);
42
+ }
43
+
44
+ /**
45
+ * @param null $storeId
46
+ * @return mixed
47
+ */
48
+ public function getNewsletterContactList($storeId = null)
49
+ {
50
+ return Mage::getStoreConfig(self::XML_PATH_NEWSLETTER_CONTACT_LIST, $storeId);
51
+ }
52
+
53
+ /**
54
+ * @param null $storeId
55
+ * @return bool
56
+ */
57
+ public function canAutoSyncNewsletter($storeId = null)
58
+ {
59
+ return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_AUTOSYNC, $storeId);
60
+ }
61
+
62
+ /**
63
+ * @param null $storeId
64
+ * @return bool
65
+ */
66
+ public function canNewsletterHandleDefaultEmails($storeId = null)
67
+ {
68
+ return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_HANDLE_DEFAULT_EMAILS, $storeId);
69
+ }
70
+
71
+ /**
72
+ * @param null $storeId
73
+ * @return mixed
74
+ */
75
+ public function getCustomersContactList($storeId = null)
76
+ {
77
+ return Mage::getStoreConfig(self::XML_PATH_CUSTOMERS_CONTACT_LIST, $storeId);
78
+ }
79
+
80
+ /**
81
+ * @param null $storeId
82
+ * @return bool
83
+ */
84
+ public function canAutoSyncCustomers($storeId = null)
85
+ {
86
+ return Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMERS_AUTOSYNC, $storeId);
87
+ }
88
+
89
+ /**
90
+ * @return MGAPI|null
91
+ */
92
+ public function getMailigenApi()
93
+ {
94
+ if (is_null($this->_mgapi)) {
95
+ require_once Mage::getBaseDir('lib') . '/mailigen/MGAPI.class.php';
96
+ $this->_mgapi = new MGAPI($this->getApiKey());
97
+ }
98
+
99
+ return $this->_mgapi;
100
+ }
101
+
102
+ /**
103
+ * @param int $start
104
+ */
105
+ public function setManualSync($start = 1)
106
+ {
107
+ $config = new Mage_Core_Model_Config();
108
+ $config->saveConfig(self::XML_PATH_CUSTOMERS_MANUAL_SYNC, $start);
109
+ $config->cleanCache();
110
+ }
111
+
112
+ /**
113
+ * @return bool
114
+ */
115
+ public function getManualSync()
116
+ {
117
+ return Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMERS_MANUAL_SYNC);
118
+ }
119
+
120
+ /**
121
+ * @param int $stop
122
+ */
123
+ public function setStopSync($stop = 1)
124
+ {
125
+ $config = new Mage_Core_Model_Config();
126
+ $config->saveConfig(self::XML_PATH_CUSTOMERS_STOP_SYNC, $stop);
127
+ }
128
+
129
+ /**
130
+ * Get stop sync value directly from DB
131
+ *
132
+ * @return bool
133
+ */
134
+ public function getStopSync()
135
+ {
136
+ /** @var $stopSyncConfigCollection Mage_Core_Model_Resource_Config_Data_Collection */
137
+ $stopSyncConfigCollection = Mage::getModel('core/config_data')->getCollection()
138
+ ->addFieldToFilter('path', self::XML_PATH_CUSTOMERS_STOP_SYNC);
139
+
140
+ if ($stopSyncConfigCollection->getSize()) {
141
+ /** @var $stopSyncConfig Mage_Core_Model_Config_Data */
142
+ $stopSyncConfig = $stopSyncConfigCollection->getFirstItem();
143
+ $result = ($stopSyncConfig->getValue() == '1');
144
+ }
145
+ else {
146
+ $result = false;
147
+ }
148
+
149
+ return $result;
150
+ }
151
+
152
+ /**
153
+ * @param $datetime
154
+ * @param bool $full
155
+ * @return string
156
+ */
157
+ function time_elapsed_string($datetime, $full = false) {
158
+ $now = new DateTime;
159
+ $ago = new DateTime($datetime);
160
+ $diff = $now->diff($ago);
161
+
162
+ $diff->w = floor($diff->d / 7);
163
+ $diff->d -= $diff->w * 7;
164
+
165
+ $string = array(
166
+ 'y' => 'year',
167
+ 'm' => 'month',
168
+ 'w' => 'week',
169
+ 'd' => 'day',
170
+ 'h' => 'hour',
171
+ 'i' => 'minute',
172
+ 's' => 'second',
173
+ );
174
+ foreach ($string as $k => &$v) {
175
+ if ($diff->$k) {
176
+ $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
177
+ } else {
178
+ unset($string[$k]);
179
+ }
180
+ }
181
+
182
+ if (!$full) $string = array_slice($string, 0, 1);
183
+ return $string ? implode(', ', $string) . ' ago' : 'just now';
184
+ }
185
+ }
app/code/community/Mailigen/Synchronizer/Helper/Log.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Helper_Log extends Mage_Core_Helper_Abstract
11
+ {
12
+ const LOG_FILE = 'mailigen_synchronizer.log';
13
+
14
+ /**
15
+ * @param $message
16
+ * @param null $level
17
+ */
18
+ public static function log($message, $level = null)
19
+ {
20
+ Mage::log($message, $level, self::LOG_FILE);
21
+ }
22
+
23
+ /**
24
+ * @param Exception $e
25
+ */
26
+ public static function logException(Exception $e)
27
+ {
28
+ self::log("\n" . $e->__toString(), Zend_Log::ERR);
29
+ }
30
+ }
app/code/community/Mailigen/Synchronizer/Model/Customer.php ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Customer extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @var array
14
+ */
15
+ protected $_newCustomersOrderInfoData = array();
16
+
17
+ protected function _construct()
18
+ {
19
+ $this->_init('mailigen_synchronizer/customer');
20
+ }
21
+
22
+ /**
23
+ * @return int
24
+ */
25
+ public function updateCustomersOrderInfo(){
26
+ $customerIds = Mage::getModel('customer/customer')->getCollection()->getAllIds();
27
+ $customerFlatIds = $this->getCollection()->getAllIds();
28
+ $newCustomerFlatIds = array_diff($customerIds, $customerFlatIds);
29
+
30
+ if (count($newCustomerFlatIds) > 0) {
31
+ $customers = Mage::getModel('customer/customer')->getCollection()
32
+ ->addAttributeToFilter('entity_id', array('in' => $newCustomerFlatIds))
33
+ ->addAttributeToSelect(array('store_id', 'email'));
34
+
35
+ Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
36
+ $customers,
37
+ array($this, '_prepareCustomerOrderInfoData'),
38
+ array($this, '_saveBatchedCustomersOrderInfo')
39
+ );
40
+ }
41
+
42
+ return count($newCustomerFlatIds);
43
+ }
44
+
45
+ /**
46
+ * @param $customer
47
+ */
48
+ public function _prepareCustomerOrderInfoData($customer)
49
+ {
50
+ /** @var $helper Mailigen_Synchronizer_Helper_Customer */
51
+ $helper = Mage::helper('mailigen_synchronizer/customer');
52
+ /** @var $orders Mage_Sales_Model_Resource_Order_Collection */
53
+ $orders = Mage::getModel('sales/order')->getCollection()
54
+ ->addFieldToFilter('customer_id', $customer->getId())
55
+ ->addFieldToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
56
+ ->addAttributeToSort('created_at', 'desc')
57
+ ->addAttributeToSelect('*');
58
+ $lastOrder = $orders->getFirstItem();
59
+
60
+ /**
61
+ * Sum all orders grand total
62
+ */
63
+ $totalGrandTotal = 0;
64
+ if ($orders->count() > 0) {
65
+ foreach ($orders as $_order) {
66
+ $totalGrandTotal += $_order->getGrandTotal();
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Get customer cart info
72
+ */
73
+ $website = $helper->getWebsite($customer->getStoreId());
74
+ /** @var $quote Mage_Sales_Model_Quote */
75
+ $quote = Mage::getModel('sales/quote')->setWebsite($website);
76
+ $quote->loadByCustomer($customer);
77
+
78
+ $this->_newCustomersOrderInfoData[] = array(
79
+ 'id' => $customer->getId(),
80
+ 'email' => $customer->getEmail(),
81
+ 'lastorderdate' => $orders && $lastOrder ? $helper->getFormattedDate($lastOrder->getCreatedAt()) : '',
82
+ 'valueoflastorder' => $orders && $lastOrder ? (float)$lastOrder->getGrandTotal() : '',
83
+ 'totalvalueoforders' => (float)$totalGrandTotal,
84
+ 'totalnumberoforders' => (int)$orders->count(),
85
+ 'numberofitemsincart' => $quote ? (int)$quote->getItemsQty() : '',
86
+ 'valueofcurrentcart' => $quote ? (float)$quote->getGrandTotal() : '',
87
+ 'lastitemincartaddingdate' => $quote ? $helper->getFormattedDate($quote->getUpdatedAt()) : '',
88
+ 'is_removed' => 0,
89
+ 'is_synced' => 0,
90
+ 'synced_at' => null
91
+ );
92
+ }
93
+
94
+ public function _saveBatchedCustomersOrderInfo()
95
+ {
96
+ $tableName = $this->getResource()->getMainTable();
97
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
98
+ $inserted = $write->insertMultiple($tableName, $this->_newCustomersOrderInfoData);
99
+ if ($inserted < count($this->_newCustomersOrderInfoData)) {
100
+ Mage::throwException("Saved $inserted customers of " . count($this->_newCustomersOrderInfoData));
101
+ }
102
+ $this->_newCustomersOrderInfoData = array();
103
+ }
104
+
105
+ /**
106
+ * @param $customerIds
107
+ * @return Mage_Customer_Model_Resource_Customer_Collection
108
+ */
109
+ public function getCustomerCollection($customerIds)
110
+ {
111
+ /** @var $customers Mage_Customer_Model_Resource_Customer_Collection */
112
+ $customers = Mage::getModel('customer/customer')->getCollection()
113
+ ->addAttributeToSelect(array(
114
+ 'email',
115
+ 'firstname',
116
+ 'lastname',
117
+ 'prefix',
118
+ 'middlename',
119
+ 'suffix',
120
+ 'store_id',
121
+ 'group_id',
122
+ 'created_at',
123
+ 'dob',
124
+ 'gender',
125
+ 'is_active'
126
+ ))
127
+ ->addAttributeToFilter('entity_id', array('in' => $customerIds));
128
+
129
+ /**
130
+ * Join Customer default billing address info
131
+ */
132
+ $customers->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
133
+ ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
134
+ ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
135
+
136
+ /**
137
+ * Join Customer last login at
138
+ */
139
+ $logCustomerTableName = $this->getResource()->getTable('log/customer');
140
+ $customers->getSelect()->columns(array('last_login_at' => new Zend_Db_Expr("(SELECT login_at FROM $logCustomerTableName WHERE customer_id = e.entity_id ORDER BY log_id DESC LIMIT 1)")));
141
+
142
+ /**
143
+ * Join Customer order info
144
+ */
145
+ $customers->joinTable('mailigen_synchronizer/customer', "id = entity_id", array(
146
+ 'lastorderdate',
147
+ 'valueoflastorder',
148
+ 'totalvalueoforders',
149
+ 'totalnumberoforders',
150
+ 'numberofitemsincart',
151
+ 'valueofcurrentcart',
152
+ 'lastitemincartaddingdate'
153
+ ));
154
+
155
+ return $customers;
156
+ }
157
+
158
+ /**
159
+ * @param $customerIds
160
+ * @return int
161
+ */
162
+ public function updateSyncedCustomers($customerIds)
163
+ {
164
+ $tableName = $this->getResource()->getMainTable();
165
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
166
+ $updated = $write->update(
167
+ $tableName,
168
+ array('is_synced' => 1, 'synced_at' => Varien_Date::now()),
169
+ array('id IN (?)' => $customerIds)
170
+ );
171
+
172
+ if ($updated < count($customerIds)) {
173
+ Mage::throwException("Updated $updated customers of " . count($customerIds));
174
+ }
175
+
176
+ return $updated;
177
+ }
178
+
179
+ /**
180
+ * @return int
181
+ */
182
+ public function removeSyncedAndRemovedCustomers()
183
+ {
184
+ $tableName = $this->getResource()->getMainTable();
185
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
186
+ $deleted = $write->delete($tableName, array('is_removed = ?' => 1, 'is_synced = ?' => 1));
187
+
188
+ return $deleted;
189
+ }
190
+
191
+ /**
192
+ * @param $customerId
193
+ * @param bool $is_removed
194
+ * @return int
195
+ */
196
+ public function setCustomerNotSynced($customerId, $is_removed = false)
197
+ {
198
+ $tableName = $this->getResource()->getMainTable();
199
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
200
+
201
+ $bind = array();
202
+ $bind['is_synced'] = 0;
203
+ if (is_int($is_removed)) {
204
+ $bind['is_removed'] = $is_removed;
205
+ }
206
+ $updated = $write->update($tableName, $bind, array('id = ?' => $customerId));
207
+
208
+ return $updated;
209
+ }
210
+
211
+ /**
212
+ * @param bool $is_removed
213
+ * @return int
214
+ */
215
+ public function setCustomersNotSynced($is_removed = false)
216
+ {
217
+ $tableName = $this->getResource()->getMainTable();
218
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
219
+
220
+ $bind = array();
221
+ $bind['is_synced'] = 0;
222
+ if (is_int($is_removed)) {
223
+ $bind['is_removed'] = $is_removed;
224
+ }
225
+ $updated = $write->update($tableName, $bind);
226
+
227
+ return $updated;
228
+ }
229
+ }
app/code/community/Mailigen/Synchronizer/Model/Customer/Merge/Field.php ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Customer_Merge_Field extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @param $values
14
+ * @return string
15
+ */
16
+ protected function _getFormattedPredefinedValues($values)
17
+ {
18
+ if (is_array($values)) {
19
+ return implode("||", $values);
20
+ }
21
+ return '';
22
+ }
23
+
24
+ /**
25
+ * @return array
26
+ */
27
+ protected function _getMergeFieldsConfig()
28
+ {
29
+ /** @var $helper Mailigen_Synchronizer_Helper_Customer */
30
+ $helper = Mage::helper('mailigen_synchronizer/customer');
31
+
32
+ return array(
33
+ /**
34
+ * Customer fields
35
+ */
36
+ 'PREFIX' => array(
37
+ 'title' => 'Prefix',
38
+ 'field_type' => 'text',
39
+ 'req' => false
40
+ ),
41
+ 'MIDDLENAME' => array(
42
+ 'title' => 'Middle name',
43
+ 'field_type' => 'text',
44
+ 'req' => false
45
+ ),
46
+ 'SUFFIX' => array(
47
+ 'title' => 'Suffix',
48
+ 'field_type' => 'text',
49
+ 'req' => false
50
+ ),
51
+ 'STOREID' => array(
52
+ 'title' => 'Store id',
53
+ 'field_type' => 'text',
54
+ 'req' => true
55
+ ),
56
+ 'STORELANGUAGE' => array(
57
+ 'title' => 'Store language',
58
+ 'field_type' => 'text',
59
+ 'req' => true
60
+ ),
61
+ 'CUSTOMERGROUP' => array(
62
+ 'title' => 'Customer group',
63
+ 'field_type' => 'dropdown',
64
+ 'req' => true,
65
+ 'predefined_values' => $this->_getFormattedPredefinedValues($helper->getCustomerGroups())
66
+ ),
67
+ 'PHONE' => array(
68
+ 'title' => 'Phone',
69
+ 'field_type' => 'sms',
70
+ 'req' => false
71
+ ),
72
+ 'REGISTRATIONDATE' => array(
73
+ 'title' => 'Registration date',
74
+ 'field_type' => 'date',
75
+ 'req' => true
76
+ ),
77
+ 'COUNTRY' => array(
78
+ 'title' => 'Country',
79
+ 'field_type' => 'dropdown',
80
+ 'req' => false,
81
+ 'predefined_values' => $this->_getFormattedPredefinedValues($helper->getCountries()),
82
+ ),
83
+ 'CITY' => array(
84
+ 'title' => 'City',
85
+ 'field_type' => 'text',
86
+ 'req' => false
87
+ ),
88
+ 'DATEOFBIRTH' => array(
89
+ 'title' => 'Date of birth',
90
+ 'field_type' => 'date',
91
+ 'req' => false
92
+ ),
93
+ 'GENDER' => array(
94
+ 'title' => 'Gender',
95
+ 'field_type' => 'dropdown',
96
+ 'req' => false,
97
+ 'predefined_values' => $this->_getFormattedPredefinedValues($helper->getGenders())
98
+ ),
99
+ 'LASTLOGIN' => array(
100
+ 'title' => 'Last login',
101
+ 'field_type' => 'date',
102
+ 'req' => false
103
+ ),
104
+ 'CLIENTID' => array(
105
+ 'title' => 'Client id',
106
+ 'field_type' => 'number',
107
+ 'req' => true
108
+ ),
109
+ 'STATUSOFUSER' => array(
110
+ 'title' => 'Status of user',
111
+ 'field_type' => 'dropdown',
112
+ 'req' => true,
113
+ 'predefined_values' => $this->_getFormattedPredefinedValues($helper->customerStatus)
114
+ ),
115
+ /**
116
+ * Customer orders info
117
+ */
118
+ 'LASTORDERDATE' => array(
119
+ 'title' => 'Last order date',
120
+ 'field_type' => 'date',
121
+ 'req' => false
122
+ ),
123
+ 'VALUEOFLASTORDER' => array(
124
+ 'title' => 'Value of last order',
125
+ 'field_type' => 'number',
126
+ 'req' => false
127
+ ),
128
+ 'TOTALVALUEOFORDERS' => array(
129
+ 'title' => 'Total value of orders',
130
+ 'field_type' => 'number',
131
+ 'req' => false
132
+ ),
133
+ 'TOTALNUMBEROFORDERS' => array(
134
+ 'title' => 'Total number of orders',
135
+ 'field_type' => 'number',
136
+ 'req' => false
137
+ ),
138
+ 'NUMBEROFITEMSINCART' => array(
139
+ 'title' => 'Number of items in cart',
140
+ 'field_type' => 'number',
141
+ 'req' => false
142
+ ),
143
+ 'VALUEOFCURRENTCART' => array(
144
+ 'title' => 'Value of current cart',
145
+ 'field_type' => 'number',
146
+ 'req' => false
147
+ ),
148
+ 'LASTITEMINCARTADDINGDATE' => array(
149
+ 'title' => 'Last item in cart adding date',
150
+ 'field_type' => 'date',
151
+ 'req' => false
152
+ ),
153
+ /**
154
+ * @todo Add Discount coupon fields
155
+ */
156
+ );
157
+ }
158
+
159
+ public function createMergeFields()
160
+ {
161
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
162
+ $helper = Mage::helper('mailigen_synchronizer');
163
+ $api = $helper->getMailigenApi();
164
+ $listId = $helper->getCustomersContactList();
165
+ if (empty($listId)) {
166
+ Mage::throwException("Customer contact list isn't selected");
167
+ }
168
+
169
+ $createdFields = $this->_getCreatedMergeFields();
170
+ $newFields = $this->_getMergeFieldsConfig();
171
+
172
+ foreach ($newFields as $tag => $options) {
173
+ if (isset($createdFields[$tag])) {
174
+ /**
175
+ * Merge Field already created
176
+ * Update only 'CUSTOMERGROUP' field
177
+ */
178
+ if ($tag == 'CUSTOMERGROUP') {
179
+ $api->listMergeVarUpdate($listId, $tag, $options);
180
+ if ($api->errorCode) {
181
+ Mage::throwException("Unable to update merge var. $api->errorCode: $api->errorMessage");
182
+ }
183
+ }
184
+ }
185
+ else {
186
+ /**
187
+ * Create new merge field
188
+ */
189
+ $name = $options['title'];
190
+ $api->listMergeVarAdd($listId, $tag, $name, $options);
191
+ if ($api->errorCode) {
192
+ Mage::throwException("Unable to add merge var. $api->errorCode: $api->errorMessage");
193
+ }
194
+ }
195
+ }
196
+ }
197
+
198
+ /**
199
+ * @return array
200
+ */
201
+ protected function _getCreatedMergeFields()
202
+ {
203
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
204
+ $helper = Mage::helper('mailigen_synchronizer');
205
+ $api = $helper->getMailigenApi();
206
+ $listId = $helper->getCustomersContactList();
207
+
208
+ $createdMergeFields = array();
209
+ $tmpCreatedMergeFields = $api->listMergeVars($listId);
210
+ if ($api->errorCode) {
211
+ Mage::throwException("Unable to load merge vars. $api->errorCode: $api->errorMessage");
212
+ }
213
+
214
+ foreach ($tmpCreatedMergeFields as $mergeField) {
215
+ $createdMergeFields[$mergeField['tag']] = $mergeField;
216
+ }
217
+
218
+ return $createdMergeFields;
219
+ }
220
+ }
app/code/community/Mailigen/Synchronizer/Model/List.php CHANGED
@@ -1,34 +1,105 @@
1
  <?php
2
- class Mailigen_Synchronizer_Model_List extends Mage_Core_Model_Abstract {
3
-
4
- public function _construct()
5
- {
6
- parent::_construct();
7
- $this->_init('mailigen_synchronizer/list');
8
- }
9
-
10
- public function toOptionArray()
11
- {
12
-
13
- $mgapi = Mage::getModuleDir('','Mailigen_Synchronizer') . DS . 'api' . DS . 'MGAPI.class.php';
14
- $apikey = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_api_key');
15
- require_once( $mgapi );
16
-
17
- $api = new MGAPI($apikey);
18
-
19
- $lists = $api->lists();
20
-
21
- //print_r($lists);
22
-
23
- if( !$api->errorCode && $lists){
24
- $array[] = array('label' => '--Create a new list--','value'=>'');
25
- foreach($lists as $list){
26
- $array[] = array('label'=>$list['name'],'value'=>$list['id']);
27
- }
28
- return $array;
29
-
30
- }
31
-
32
-
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
1
  <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_List extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @var null
14
+ */
15
+ protected $_lists = null;
16
+
17
+ public function _construct()
18
+ {
19
+ parent::_construct();
20
+ $this->_init('mailigen_synchronizer/list');
21
+ }
22
+
23
+ /**
24
+ * @param bool $load
25
+ * @return array|null
26
+ */
27
+ public function getLists($load = false)
28
+ {
29
+ if (is_null($this->_lists) || $load) {
30
+ $api = Mage::helper('mailigen_synchronizer')->getMailigenApi();
31
+ $this->_lists = $api->lists();
32
+ }
33
+ return $this->_lists;
34
+ }
35
+
36
+ /**
37
+ * @param bool $load
38
+ * @return array
39
+ */
40
+ public function toOptionArray($load = false)
41
+ {
42
+ $lists = $this->getLists($load);
43
+
44
+ if (is_array($lists) && !empty($lists)) {
45
+ $array[] = array('label' => '--Create a new list--', 'value' => '');
46
+ foreach ($lists as $list) {
47
+ $array[] = array('label' => $list['name'], 'value' => $list['id']);
48
+ }
49
+ return $array;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * @param $newListName
55
+ * @return bool|string
56
+ */
57
+ public function createNewList($newListName)
58
+ {
59
+ //Get the list with current lists
60
+ $lists = $this->toOptionArray();
61
+
62
+ //Check if a similar list name doesn't exists already.
63
+ $continue = true;
64
+ foreach ($lists as $list) {
65
+ if ($list['label'] == $newListName) {
66
+ $continue = false;
67
+ Mage::getSingleton('adminhtml/session')->addError("A list with name '$newListName' already exists");
68
+ break;
69
+ }
70
+ }
71
+
72
+ //Only if a list with a similar name is not doesn't exists we move further.
73
+ if ($continue) {
74
+
75
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
76
+ $logger = Mage::helper('mailigen_synchronizer/log');
77
+
78
+ $options = array(
79
+ 'permission_reminder' => ' ',
80
+ 'notify_to' => Mage::getStoreConfig('trans_email/ident_general/email'),
81
+ 'subscription_notify' => true,
82
+ 'unsubscription_notify' => true,
83
+ 'has_email_type_option' => true
84
+ );
85
+
86
+ $api = Mage::helper('mailigen_synchronizer')->getMailigenApi();
87
+ $retval = $api->listCreate($newListName, $options);
88
+
89
+ if ($api->errorCode) {
90
+ $logger->log("Unable to create list. $api->errorCode: $api->errorMessage");
91
+ }
92
+
93
+ //We grab the list one more time
94
+ $lists = $this->toOptionArray(true);
95
+ foreach ($lists as $list) {
96
+ if ($list['label'] == $newListName) {
97
+ //We make the new submitted list default
98
+ return $list['value'];
99
+ }
100
+ }
101
+ }
102
+
103
+ return false;
104
+ }
105
  }
app/code/community/Mailigen/Synchronizer/Model/Mailigen.php CHANGED
@@ -1,78 +1,422 @@
1
- <?php
2
-
3
- class Mailigen_Synchronizer_Model_Mailigen extends Mage_Core_Model_Abstract {
4
-
5
- public function sync(){
6
- $mgapi = Mage::getModuleDir('','Mailigen_Synchronizer') . DS . 'api' . DS . 'MGAPI.class.php';
7
- $apikey = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_api_key');
8
- $listid = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_list');
9
-
10
- require_once( $mgapi );
11
- $api = new MGAPI($apikey);
12
-
13
- //First we pull all unsubscribers from Mailigen
14
- $unsubscribers = $api->listMembers($listid, "unsubscribed", 0, 500);
15
-
16
- foreach ($unsubscribers as $unsubscriber) {
17
-
18
- $email = $unsubscriber['email'];
19
-
20
-
21
- // create new subscriber without send an confirmation email
22
- Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe( $email );
23
-
24
- // get just generated subscriber
25
- $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
26
-
27
- // change status to "unsubscribed" and save
28
- $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
29
- $subscriber->save();
30
- }
31
-
32
- //Second we pull all subscribers from Mailigen
33
- $subscribers = $api->listMembers($listid, "subscribed", 0, 500);
34
-
35
- foreach ($subscribers as $subscriber) {
36
-
37
- $email = $subscriber['email'];
38
-
39
-
40
- // create new subscriber without send an confirmation email
41
- Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe( $email );
42
-
43
- // get just generated subscriber
44
- $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
45
-
46
- // change status to "unsubscribed" and save
47
- $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
48
- $subscriber->save();
49
- }
50
-
51
- //and finally we push our list to mailigen
52
- $collection = Mage::getResourceSingleton('newsletter/subscriber_collection');
53
- $collection->showCustomerInfo(true)->addSubscriberTypeField()->showStoreInfo();
54
-
55
- $batch = array();
56
- foreach($collection as $subscriber){
57
-
58
- $batch[] = array(
59
- 'EMAIL'=>$subscriber->getSubscriberEmail(),
60
- 'FNAME'=>$subscriber->getCustomerFirstname(),
61
- 'LNAME'=>$subscriber->getCustomerLastname()
62
- );
63
- }
64
-
65
- $double_optin = false;
66
- $update_existing = true;
67
- $retval = $api->listBatchSubscribe($listid, $batch, $double_optin, $update_existing);
68
-
69
- if ($api->errorCode){
70
- Mage::getSingleton('adminhtml/session')->addError( "Something went wrong" );
71
- Mage::log( "Mailigen API Error: " . "Code=".$api->errorCode. " Msg=".$api->errorMessage );
72
- } else{
73
- Mage::getSingleton('adminhtml/session')->addSuccess( "Your contacts have been syncronized" );
74
- Mage::log("Returned: ".$retval);
75
- }
76
- }
77
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Mailigen extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @var null
14
+ */
15
+ protected $_customersListId = null;
16
+
17
+ /**
18
+ * @var array
19
+ */
20
+ protected $_batchedCustomersData = array();
21
+
22
+ /**
23
+ * @var array
24
+ */
25
+ protected $_customersLog = array(
26
+ 'update_success_count' => 0,
27
+ 'update_error_count' => 0,
28
+ 'update_errors' => array(),
29
+ 'update_count' => 0,
30
+ 'remove_success_count' => 0,
31
+ 'remove_error_count' => 0,
32
+ 'remove_errors' => array(),
33
+ 'remove_count' => 0,
34
+ );
35
+
36
+ public function syncNewsletter()
37
+ {
38
+ $api = Mage::helper('mailigen_synchronizer')->getMailigenApi();
39
+ $listid = Mage::helper('mailigen_synchronizer')->getNewsletterContactList();
40
+ if (!$listid) {
41
+ return;
42
+ }
43
+
44
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
45
+ $logger = Mage::helper('mailigen_synchronizer/log');
46
+
47
+ //First we pull all unsubscribers from Mailigen
48
+ $unsubscribers = $api->listMembers($listid, "unsubscribed", 0, 500);
49
+
50
+ foreach ($unsubscribers as $unsubscriber) {
51
+
52
+ $email = $unsubscriber['email'];
53
+
54
+ // create new subscriber without send an confirmation email
55
+ Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
56
+
57
+ // get just generated subscriber
58
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
59
+
60
+ // change status to "unsubscribed" and save
61
+ $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
62
+ $subscriber->save();
63
+ }
64
+
65
+ //Second we pull all subscribers from Mailigen
66
+ $subscribers = $api->listMembers($listid, "subscribed", 0, 500);
67
+
68
+ foreach ($subscribers as $subscriber) {
69
+
70
+ $email = $subscriber['email'];
71
+
72
+
73
+ // create new subscriber without send an confirmation email
74
+ Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
75
+
76
+ // get just generated subscriber
77
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
78
+
79
+ // change status to "unsubscribed" and save
80
+ $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
81
+ $subscriber->save();
82
+ }
83
+
84
+ //and finally we push our list to mailigen
85
+ $collection = Mage::getResourceSingleton('newsletter/subscriber_collection');
86
+ $collection->showCustomerInfo(true)->addSubscriberTypeField()->showStoreInfo();
87
+
88
+ $batch = array();
89
+ foreach ($collection as $subscriber) {
90
+
91
+ $batch[] = array(
92
+ 'EMAIL' => $subscriber->getSubscriberEmail(),
93
+ 'FNAME' => $subscriber->getCustomerFirstname(),
94
+ 'LNAME' => $subscriber->getCustomerLastname()
95
+ );
96
+ }
97
+
98
+ $double_optin = false;
99
+ $update_existing = true;
100
+ $retval = $api->listBatchSubscribe($listid, $batch, $double_optin, $update_existing);
101
+
102
+ if ($api->errorCode) {
103
+ Mage::getSingleton('adminhtml/session')->addError("Something went wrong");
104
+ $logger->log("Sync newsletter error: Code={$api->errorCode} Msg={$api->errorMessage}");
105
+ } else {
106
+ Mage::getSingleton('adminhtml/session')->addSuccess("Your contacts have been syncronized");
107
+ $logger->log("Sync newsletter success: " . var_export($retval, true));
108
+ }
109
+ }
110
+
111
+ public function syncCustomers()
112
+ {
113
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
114
+ $logger = Mage::helper('mailigen_synchronizer/log');
115
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
116
+ $helper = Mage::helper('mailigen_synchronizer');
117
+ $logger->log('Customers synchronization started');
118
+ $this->_customersListId = $helper->getCustomersContactList();
119
+ if (!$this->_customersListId) {
120
+ Mage::throwException("Customer contact list isn't selected");
121
+ }
122
+
123
+
124
+ /**
125
+ * Create or update Merge fields
126
+ */
127
+ Mage::getModel('mailigen_synchronizer/customer_merge_field')->createMergeFields();
128
+ $logger->log('Merge fields created and updated');
129
+
130
+
131
+ /**
132
+ * Update customers order info
133
+ */
134
+ $updatedCustomers = Mage::getModel('mailigen_synchronizer/customer')->updateCustomersOrderInfo();
135
+ $logger->log("Updated $updatedCustomers customers in flat table");
136
+
137
+
138
+ /**
139
+ * Update Customers in Mailigen
140
+ */
141
+ $updateCustomerIds = Mage::getModel('mailigen_synchronizer/customer')->getCollection()->getAllIds(0, 0);
142
+ /** @var $updateCustomers Mage_Customer_Model_Resource_Customer_Collection */
143
+ $updateCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCustomerCollection($updateCustomerIds);
144
+ if (count($updateCustomerIds) > 0 && $updateCustomers) {
145
+ $logger->log("Started updating customers in Mailigen");
146
+ $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
147
+ $updateCustomers,
148
+ array($this, '_prepareCustomerDataForUpdate'),
149
+ array($this, '_updateCustomersInMailigen'),
150
+ 100,
151
+ 10000
152
+ );
153
+ /**
154
+ * Reschedule task, to run after 2 min
155
+ */
156
+ if ($iterator == 0) {
157
+ Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
158
+ $this->_writeResultLogs();
159
+ $logger->log("Reschedule task, to update customers in Mailigen after 2 min");
160
+ return;
161
+ }
162
+ $logger->log("Finished updating customers in Mailigen");
163
+ }
164
+ unset($updateCustomerIds, $updateCustomers);
165
+
166
+ /**
167
+ * Log update info
168
+ */
169
+ $this->_writeResultLogs();
170
+
171
+
172
+ /**
173
+ * Remove Customers from Mailigen
174
+ */
175
+ /** @var $removeCustomer Mailigen_Synchronizer_Model_Resource_Customer_Collection */
176
+ $removeCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCollection()
177
+ ->addFieldToFilter('is_removed', 1)
178
+ ->addFieldToFilter('is_synced', 0)
179
+ ->addFieldToSelect(array('id', 'email'));
180
+ if ($removeCustomers && count($removeCustomers) > 0) {
181
+ $logger->log("Started removing customers from Mailigen");
182
+ $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
183
+ $removeCustomers,
184
+ array($this, '_prepareCustomerDataForRemove'),
185
+ array($this, '_removeCustomersFromMailigen'),
186
+ 100,
187
+ 10000
188
+ );
189
+ /**
190
+ * Reschedule task, to run after 2 min
191
+ */
192
+ if ($iterator == 0) {
193
+ Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
194
+ $this->_writeResultLogs();
195
+ $logger->log("Reschedule task to remove customers in Mailigen after 2 min");
196
+ return;
197
+ }
198
+ $logger->log("Finished removing customers from Mailigen");
199
+ }
200
+ unset($removeCustomers);
201
+
202
+ /**
203
+ * Remove synced and removed customers from Flat table
204
+ */
205
+ Mage::getModel('mailigen_synchronizer/customer')->removeSyncedAndRemovedCustomers();
206
+
207
+ /**
208
+ * Log remove info
209
+ */
210
+ $this->_writeResultLogs();
211
+
212
+ $logger->log('Customers synchronization finished');
213
+ }
214
+
215
+ /**
216
+ * @param Mage_Customer_Model_Customer $customer
217
+ */
218
+ public function _prepareCustomerDataForUpdate($customer)
219
+ {
220
+ /** @var $helper Mailigen_Synchronizer_Helper_Customer */
221
+ $helper = Mage::helper('mailigen_synchronizer/customer');
222
+
223
+ $this->_batchedCustomersData[$customer->getId()] = array(
224
+ /**
225
+ * Customer info
226
+ */
227
+ 'EMAIL' => $customer->getEmail(),
228
+ 'FNAME' => $customer->getFirstname(),
229
+ 'LNAME' => $customer->getLastname(),
230
+ 'PREFIX' => $customer->getPrefix(),
231
+ 'MIDDLENAME' => $customer->getMiddlename(),
232
+ 'SUFFIX' => $customer->getSuffix(),
233
+ 'STOREID' => $customer->getStoreId(),
234
+ 'STORELANGUAGE' => $helper->getStoreLanguage($customer->getStoreId()),
235
+ 'CUSTOMERGROUP' => $helper->getCustomerGroup($customer->getGroupId()),
236
+ 'PHONE' => $customer->getBillingTelephone(),
237
+ 'REGISTRATIONDATE' => $helper->getFormattedDate($customer->getCreatedAtTimestamp()),
238
+ 'COUNTRY' => $helper->getFormattedCountry($customer->getBillingCountryId()),
239
+ 'CITY' => $customer->getBillingCity(),
240
+ 'DATEOFBIRTH' => $helper->getFormattedDate($customer->getDob()),
241
+ 'GENDER' => $helper->getFormattedGender($customer->getGender()),
242
+ 'LASTLOGIN' => $helper->getFormattedDate($customer->getLastLoginAt()),
243
+ 'CLIENTID' => $customer->getId(),
244
+ 'STATUSOFUSER' => $helper->getFormattedCustomerStatus($customer->getIsActive()),
245
+ /**
246
+ * Customer orders info
247
+ */
248
+ 'LASTORDERDATE' => $customer->getData('lastorderdate'),
249
+ 'VALUEOFLASTORDER' => $customer->getData('valueoflastorder'),
250
+ 'TOTALVALUEOFORDERS' => $customer->getData('totalvalueoforders'),
251
+ 'TOTALNUMBEROFORDERS' => $customer->getData('totalnumberoforders'),
252
+ 'NUMBEROFITEMSINCART' => $customer->getData('numberofitemsincart'),
253
+ 'VALUEOFCURRENTCART' => $customer->getData('valueofcurrentcart'),
254
+ 'LASTITEMINCARTADDINGDATE' => $customer->getData('lastitemincartaddingdate')
255
+ );
256
+ }
257
+
258
+ /**
259
+ * @param $collectionInfo
260
+ */
261
+ public function _updateCustomersInMailigen($collectionInfo)
262
+ {
263
+ /**
264
+ * Send API request to Mailigen
265
+ */
266
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
267
+ $helper = Mage::helper('mailigen_synchronizer');
268
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
269
+ $logger = Mage::helper('mailigen_synchronizer/log');
270
+ $api = $helper->getMailigenApi();
271
+ $apiResponse = $api->listBatchSubscribe($this->_customersListId, $this->_batchedCustomersData, false, true);
272
+
273
+ /**
274
+ * Log results
275
+ */
276
+ if (isset($collectionInfo['currentPage']) && isset($collectionInfo['pageSize']) && isset($collectionInfo['pages'])) {
277
+ $curr = $collectionInfo['currentPage'] * $collectionInfo['pageSize'];
278
+ $total = $collectionInfo['pages'] * $collectionInfo['pageSize'];
279
+ $logger->log("Updated $curr/$total customers in Mailigen");
280
+ }
281
+ $this->_customersLog['update_count'] += count($this->_batchedCustomersData);
282
+
283
+ if ($api->errorCode) {
284
+ /**
285
+ * Reschedule job to run after 5 min
286
+ */
287
+ Mage::getModel('mailigen_synchronizer/schedule')->createJob(5);
288
+ $this->_writeResultLogs();
289
+ $errorInfo = array(
290
+ 'errorCode' => $api->errorCode,
291
+ 'errorMessage' => $api->errorMessage,
292
+ 'apiResponse' => $apiResponse
293
+ );
294
+ Mage::throwException('Unable to batch unsubscribe. ' . var_export($errorInfo, true));
295
+ } else {
296
+ /**
297
+ * Update Customer flat table
298
+ */
299
+ Mage::getModel('mailigen_synchronizer/customer')->updateSyncedCustomers(array_keys($this->_batchedCustomersData));
300
+
301
+ $this->_customersLog['update_success_count'] += $apiResponse['success_count'];
302
+ $this->_customersLog['update_error_count'] += $apiResponse['error_count'];
303
+ if (count($apiResponse['errors']) > 0) {
304
+ $this->_customersLog['update_errors'] = array_merge_recursive($this->_customersLog['update_errors'], $apiResponse['errors']);
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Check if sync should be stopped
310
+ */
311
+ $this->_checkSyncStop();
312
+
313
+ $this->_batchedCustomersData = array();
314
+ }
315
+
316
+ /**
317
+ * @param Mage_Customer_Model_Customer $customer
318
+ */
319
+ public function _prepareCustomerDataForRemove($customer)
320
+ {
321
+ $this->_batchedCustomersData[$customer->getId()] = $customer->getEmail();
322
+ }
323
+
324
+ /**
325
+ * @param $collectionInfo
326
+ */
327
+ public function _removeCustomersFromMailigen($collectionInfo)
328
+ {
329
+ /**
330
+ * Send API request to Mailigen
331
+ */
332
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
333
+ $helper = Mage::helper('mailigen_synchronizer');
334
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
335
+ $logger = Mage::helper('mailigen_synchronizer/log');
336
+ $api = $helper->getMailigenApi();
337
+ $apiResponse = $api->listBatchUnsubscribe($this->_customersListId, $this->_batchedCustomersData, true, false, false);
338
+
339
+ /**
340
+ * Log results
341
+ */
342
+ if (isset($collectionInfo['currentPage']) && isset($collectionInfo['pageSize']) && isset($collectionInfo['pages'])) {
343
+ $curr = $collectionInfo['currentPage'] * $collectionInfo['pageSize'];
344
+ $total = $collectionInfo['pages'] * $collectionInfo['pageSize'];
345
+ $logger->log("Removed $curr/$total customers from Mailigen");
346
+ }
347
+ $this->_customersLog['remove_count'] = count($this->_batchedCustomersData);
348
+
349
+ if ($api->errorCode) {
350
+ /**
351
+ * Reschedule job to run after 5 min
352
+ */
353
+ Mage::getModel('mailigen_synchronizer/schedule')->createJob(5);
354
+ $this->_writeResultLogs();
355
+ $errorInfo = array(
356
+ 'errorCode' => $api->errorCode,
357
+ 'errorMessage' => $api->errorMessage,
358
+ 'apiResponse' => $apiResponse
359
+ );
360
+ Mage::throwException('Unable to batch unsubscribe. ' . var_export($errorInfo, true));
361
+ } else {
362
+ /**
363
+ * Update Customer flat table
364
+ */
365
+ Mage::getModel('mailigen_synchronizer/customer')->updateSyncedCustomers(array_keys($this->_batchedCustomersData));
366
+
367
+ $this->_customersLog['remove_success_count'] += $apiResponse['success_count'];
368
+ $this->_customersLog['remove_error_count'] += $apiResponse['error_count'];
369
+ if (count($apiResponse['errors']) > 0) {
370
+ $this->_customersLog['remove_errors'] = array_merge_recursive($this->_customersLog['remove_errors'], $apiResponse['errors']);
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Check if sync should be stopped
376
+ */
377
+ $this->_checkSyncStop();
378
+
379
+ $this->_batchedCustomersData = array();
380
+ }
381
+
382
+ /**
383
+ * Stop sync, if force sync stop is enabled
384
+ */
385
+ public function _checkSyncStop()
386
+ {
387
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
388
+ $helper = Mage::helper('mailigen_synchronizer');
389
+ if ($helper->getStopSync()) {
390
+ $helper->setStopSync(0);
391
+
392
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
393
+ $logger = Mage::helper('mailigen_synchronizer/log');
394
+ $logger->log('Sync has been stopped manually');
395
+ die('Sync has been stopped manually');
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Write update, remove result logs
401
+ */
402
+ protected function _writeResultLogs()
403
+ {
404
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
405
+ $logger = Mage::helper('mailigen_synchronizer/log');
406
+
407
+ if ($this->_customersLog['update_count'] > 0) {
408
+ $logger->log("Successfully updated {$this->_customersLog['update_success_count']}/{$this->_customersLog['update_count']} customers");
409
+ if (!empty($this->_customersLog['update_errors'])) {
410
+ $logger->log("Update errors: " . var_export($this->_customersLog['update_errors'], true));
411
+ }
412
+ }
413
+
414
+ if ($this->_customersLog['remove_count'] > 0) {
415
+ $logger->log("Successfully removed {$this->_customersLog['remove_success_count']}/{$this->_customersLog['remove_count']} customers");
416
+ $logger->log("Removed with error {$this->_customersLog['remove_error_count']}/{$this->_customersLog['remove_count']} customers");
417
+ if (!empty($this->_customersLog['remove_errors'])) {
418
+ $logger->log("Remove errors: " . var_export($this->_customersLog['remove_errors'], true));
419
+ }
420
+ }
421
+ }
422
  }
app/code/community/Mailigen/Synchronizer/Model/Newsletter/Subscriber.php CHANGED
@@ -1,16 +1,22 @@
1
  <?php
2
 
3
- class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_Subscriber {
4
-
5
- public function subscribe($email) {
 
 
 
 
 
 
6
  $this->loadByEmail($email);
7
  $customerSession = Mage::getSingleton('customer/session');
8
 
9
- if(!$this->getId()) {
10
  $this->setSubscriberConfirmCode($this->randomSequence());
11
  }
12
 
13
- $isConfirmNeed = (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1) ? true : false;
14
  $isOwnSubscribes = false;
15
  $ownerId = Mage::getModel('customer/customer')
16
  ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
@@ -24,7 +30,7 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
24
  if ($isConfirmNeed === true) {
25
  // if user subscribes own login email - confirmation is not needed
26
  $isOwnSubscribes = $isSubscribeOwnEmail;
27
- if ($isOwnSubscribes == true){
28
  $this->setStatus(self::STATUS_SUBSCRIBED);
29
  } else {
30
  $this->setStatus(self::STATUS_NOT_ACTIVE);
@@ -47,10 +53,9 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
47
 
48
  try {
49
  $this->save();
50
-
51
-
52
- $send_flag = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_default_emails');
53
- if ( !$send_flag ) {
54
  if ($isConfirmNeed === true
55
  && $isOwnSubscribes === false
56
  ) {
@@ -58,7 +63,7 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
58
  } else {
59
  $this->sendConfirmationSuccessEmail();
60
  }
61
-
62
  }
63
 
64
  return $this->getStatus();
@@ -66,10 +71,11 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
66
  throw new Exception($e->getMessage());
67
  }
68
  }
69
-
 
70
  /**
71
  * Unsubscribes loaded subscription
72
- *
73
  */
74
  public function unsubscribe()
75
  {
@@ -79,15 +85,15 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
79
 
80
  $this->setSubscriberStatus(self::STATUS_UNSUBSCRIBED)
81
  ->save();
82
-
83
- $send_flag = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_default_emails');
84
- if ( !$send_flag ) {
85
  $this->sendUnsubscriptionEmail();
86
  }
87
-
88
  return $this;
89
  }
90
-
91
  /**
92
  * Saving customer subscription status
93
  *
@@ -108,17 +114,17 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
108
  return $this;
109
  }
110
 
111
- if(!$this->getId()) {
112
  $this->setSubscriberConfirmCode($this->randomSequence());
113
  }
114
 
115
- /*
116
- * Logical mismatch between customer registration confirmation code and customer password confirmation
117
- */
118
- $confirmation = null;
119
- if ($customer->isConfirmationRequired() && ($customer->getConfirmation() != $customer->getPassword())) {
120
- $confirmation = $customer->getConfirmation();
121
- }
122
 
123
  $sendInformationEmail = false;
124
  if ($customer->hasIsSubscribed()) {
@@ -138,13 +144,13 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
138
  $status = ($this->getStatus() == self::STATUS_NOT_ACTIVE ? self::STATUS_UNSUBSCRIBED : $this->getStatus());
139
  }
140
 
141
- if($status != $this->getStatus()) {
142
  $this->setIsStatusChanged(true);
143
  }
144
 
145
  $this->setStatus($status);
146
 
147
- if(!$this->getId()) {
148
  $storeId = $customer->getStoreId();
149
  if ($customer->getStoreId() == 0) {
150
  $storeId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
@@ -160,9 +166,9 @@ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter
160
  $this->save();
161
  $sendSubscription = $customer->getData('sendSubscription') || $sendInformationEmail;
162
  if (is_null($sendSubscription) xor $sendSubscription) {
163
-
164
- $send_flag = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_default_emails');
165
- if ( !$send_flag ) {
166
  if ($this->getIsStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
167
  $this->sendUnsubscriptionEmail();
168
  } elseif ($this->getIsStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
1
  <?php
2
 
3
+ class Mailigen_Synchronizer_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_Subscriber
4
+ {
5
+ /**
6
+ * @param $email
7
+ * @return mixed
8
+ * @throws Exception
9
+ */
10
+ public function subscribe($email)
11
+ {
12
  $this->loadByEmail($email);
13
  $customerSession = Mage::getSingleton('customer/session');
14
 
15
+ if (!$this->getId()) {
16
  $this->setSubscriberConfirmCode($this->randomSequence());
17
  }
18
 
19
+ $isConfirmNeed = (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1) ? true : false;
20
  $isOwnSubscribes = false;
21
  $ownerId = Mage::getModel('customer/customer')
22
  ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
30
  if ($isConfirmNeed === true) {
31
  // if user subscribes own login email - confirmation is not needed
32
  $isOwnSubscribes = $isSubscribeOwnEmail;
33
+ if ($isOwnSubscribes == true) {
34
  $this->setStatus(self::STATUS_SUBSCRIBED);
35
  } else {
36
  $this->setStatus(self::STATUS_NOT_ACTIVE);
53
 
54
  try {
55
  $this->save();
56
+
57
+ $send_flag = Mage::helper('mailigen_synchronizer')->canNewsletterHandleDefaultEmails();
58
+ if (!$send_flag) {
 
59
  if ($isConfirmNeed === true
60
  && $isOwnSubscribes === false
61
  ) {
63
  } else {
64
  $this->sendConfirmationSuccessEmail();
65
  }
66
+
67
  }
68
 
69
  return $this->getStatus();
71
  throw new Exception($e->getMessage());
72
  }
73
  }
74
+
75
+
76
  /**
77
  * Unsubscribes loaded subscription
78
+ * @return $this
79
  */
80
  public function unsubscribe()
81
  {
85
 
86
  $this->setSubscriberStatus(self::STATUS_UNSUBSCRIBED)
87
  ->save();
88
+
89
+ $send_flag = Mage::helper('mailigen_synchronizer')->canNewsletterHandleDefaultEmails();
90
+ if (!$send_flag) {
91
  $this->sendUnsubscriptionEmail();
92
  }
93
+
94
  return $this;
95
  }
96
+
97
  /**
98
  * Saving customer subscription status
99
  *
114
  return $this;
115
  }
116
 
117
+ if (!$this->getId()) {
118
  $this->setSubscriberConfirmCode($this->randomSequence());
119
  }
120
 
121
+ /*
122
+ * Logical mismatch between customer registration confirmation code and customer password confirmation
123
+ */
124
+ $confirmation = null;
125
+ if ($customer->isConfirmationRequired() && ($customer->getConfirmation() != $customer->getPassword())) {
126
+ $confirmation = $customer->getConfirmation();
127
+ }
128
 
129
  $sendInformationEmail = false;
130
  if ($customer->hasIsSubscribed()) {
144
  $status = ($this->getStatus() == self::STATUS_NOT_ACTIVE ? self::STATUS_UNSUBSCRIBED : $this->getStatus());
145
  }
146
 
147
+ if ($status != $this->getStatus()) {
148
  $this->setIsStatusChanged(true);
149
  }
150
 
151
  $this->setStatus($status);
152
 
153
+ if (!$this->getId()) {
154
  $storeId = $customer->getStoreId();
155
  if ($customer->getStoreId() == 0) {
156
  $storeId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
166
  $this->save();
167
  $sendSubscription = $customer->getData('sendSubscription') || $sendInformationEmail;
168
  if (is_null($sendSubscription) xor $sendSubscription) {
169
+
170
+ $send_flag = Mage::helper('mailigen_synchronizer')->canNewsletterHandleDefaultEmails();
171
+ if (!$send_flag) {
172
  if ($this->getIsStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
173
  $this->sendUnsubscriptionEmail();
174
  } elseif ($this->getIsStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
app/code/community/Mailigen/Synchronizer/Model/Observer.php CHANGED
@@ -1,148 +1,257 @@
1
- <?php
2
-
3
- class Mailigen_Synchronizer_Model_Observer {
4
-
5
- public function newsletter_subscriber_create_after( Varien_Event_Observer $observer ){
6
-
7
- $enabled = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_status');
8
- $delete_on_unsubscribe = Mage::getStoreConfig('mailigen_settings/mailigen_unsubscribe_group/mailigen_unsubscribe_delete');
9
-
10
-
11
-
12
- $subscriber = $observer->getDataObject();
13
- $data = $subscriber->getData();
14
- $statusChange = $subscriber->getIsStatusChanged();
15
-
16
- if( $enabled && $statusChange == true ) {
17
-
18
- $mgapi = Mage::getModuleDir('','Mailigen_Synchronizer') . DS . 'api' . DS . 'MGAPI.class.php';
19
- $apikey = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_api_key');
20
- $listid = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_list');
21
-
22
- require_once( $mgapi );
23
- $api = new MGAPI($apikey);
24
-
25
- $email_address = $observer['subscriber']->getSubscriberEmail();
26
- $merge_vars = array('EMAIL'=>$email_address); // or $merge_vars = array();
27
- $email_type = 'html';
28
- $double_optin = false;
29
- $update_existing = true;
30
-
31
-
32
- //If mailigen transational emails are set from admin.
33
- $send_flag = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_default_emails');
34
-
35
- if( $send_flag ){
36
- $send_welcome = true;
37
- $send_goodbye = true;
38
- }else{
39
- $send_welcome = false;
40
- $send_goodbye = false;
41
- }
42
-
43
- //if is a customer we also grab firstname and lastname
44
- if( $observer['subscriber']->getCustomerId() ){
45
- $customer = Mage::getModel("customer/customer");
46
- $customer->load( $observer['subscriber']->getCustomerId() );
47
-
48
- $merge_vars['FNAME'] = $customer->getFirstname();
49
- $merge_vars['LNAME'] = $customer->getLastname();
50
-
51
- }
52
-
53
- Mage::log( "Subscribe: " . $send_flag );
54
-
55
- if ($data['subscriber_status'] === 1) {
56
- $retval = $api->listSubscribe($listid, $email_address, $merge_vars, $email_type, $double_optin, $update_existing, $send_welcome);
57
- }else{
58
- $retval = $api->listUnsubscribe($listid, $email_address, $delete_member, $send_goodbye, $send_notify);
59
- }
60
-
61
-
62
-
63
- if ($api->errorCode){
64
- Mage::log( "Mailigen API Error: " . "Code=".$api->errorCode. " Msg=".$api->errorMessage );
65
- } else{
66
- Mage::log("Returned: ".$retval);
67
- }
68
- }
69
-
70
- return $observer;
71
- }
72
-
73
- public function daily_sync( Varien_Event_Observer $observer ){
74
- $autosync = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_default_emails');
75
- if( $autosync == 'yes' ) {
76
- $mailigen = Mage::getModel('mailigen_synchronizer/mailigen');
77
- $mailigen->sync();
78
- }
79
- }
80
-
81
- public function admin_system_config_changed_section_mailigen_settings ( Varien_Event_Observer $observer ){
82
-
83
- $new_list_name = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_new_list');
84
- $notify_to = Mage::getStoreConfig('trans_email/ident_general/email');
85
-
86
- if( $new_list_name ) {
87
-
88
- //Get the list with current lists
89
- $lists = Mage::getModel('mailigen_synchronizer/list')->toOptionArray();
90
-
91
- //We need this later on
92
- $config_model = new Mage_Core_Model_Config();
93
-
94
- //Check if a similar list name doesn't exists already.
95
- $continue = true;
96
- foreach($lists as $list){
97
- if($list['label'] == $new_list_name){
98
- $continue = false;
99
- Mage::getSingleton('adminhtml/session')->addError( "A list with a simiar name already exists" );
100
- break;
101
- }
102
- }
103
-
104
- //Only if a list with a similar name is not doesn't exists we move further.
105
- if( $continue ) {
106
-
107
- $options = array(
108
- 'permission_reminder' => ' ',
109
- 'notify_to' => $notify_to,
110
- 'subscription_notify' => true,
111
- 'unsubscription_notify' => true,
112
- 'has_email_type_option' => true
113
- );
114
-
115
- $mgapi = Mage::getModuleDir('','Mailigen_Synchronizer') . DS . 'api' . DS . 'MGAPI.class.php';
116
- $apikey = Mage::getStoreConfig('mailigen_settings/mailigen_general_group/mailigen_general_api_key');
117
- require_once( $mgapi );
118
- $api = new MGAPI($apikey);
119
-
120
- $retval = $api->listCreate($new_list_name, $options);
121
-
122
- if ($api->errorCode){
123
- Mage::log( "Mailigen API Error: " . "Code=".$api->errorCode. " Msg=".$api->errorMessage );
124
- } else{
125
- Mage::log("Returned: ".$retval);
126
- }
127
-
128
- //We grab the list one more time
129
- $lists = Mage::getModel('mailigen_synchronizer/list')->toOptionArray();
130
- foreach($lists as $list){
131
- if($list['label'] == $new_list_name){
132
- //We make the new submitted list default
133
- $config_model ->saveConfig('mailigen_settings/mailigen_general_group/mailigen_general_list', $list['value'], 'default', 0);
134
- continue;
135
- }
136
- }
137
- }
138
-
139
- $config_model ->saveConfig('mailigen_settings/mailigen_general_group/mailigen_general_new_list', "", 'default', 0);
140
-
141
-
142
- }
143
-
144
-
145
-
146
- }
147
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Observer
11
+ {
12
+ /**
13
+ * @param Varien_Event_Observer $observer
14
+ * @return Varien_Event_Observer
15
+ */
16
+ public function newsletterSubscriberSaveCommitAfter(Varien_Event_Observer $observer)
17
+ {
18
+ $enabled = Mage::helper('mailigen_synchronizer')->isEnabled();
19
+ $subscriber = $observer->getDataObject();
20
+ $data = $subscriber->getData();
21
+ $statusChange = $subscriber->getIsStatusChanged();
22
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
23
+ $logger = Mage::helper('mailigen_synchronizer/log');
24
+
25
+ if ($enabled && $statusChange == true) {
26
+
27
+ $api = Mage::helper('mailigen_synchronizer')->getMailigenApi();
28
+ $listid = Mage::helper('mailigen_synchronizer')->getNewsletterContactList();
29
+
30
+ $email_address = $observer['subscriber']->getSubscriberEmail();
31
+ $merge_vars = array('EMAIL' => $email_address); // or $merge_vars = array();
32
+ $email_type = 'html';
33
+ $double_optin = false;
34
+ $update_existing = true;
35
+ $delete_member = false;
36
+ $send_notify = true;
37
+
38
+ //If mailigen transational emails are set from admin.
39
+ $send_flag = Mage::helper('mailigen_synchronizer')->canNewsletterHandleDefaultEmails();
40
+
41
+ if ($send_flag) {
42
+ $send_welcome = true;
43
+ $send_goodbye = true;
44
+ } else {
45
+ $send_welcome = false;
46
+ $send_goodbye = false;
47
+ }
48
+
49
+ //if is a customer we also grab firstname and lastname
50
+ if ($observer['subscriber']->getCustomerId()) {
51
+ $customer = Mage::getModel("customer/customer");
52
+ $customer->load($observer['subscriber']->getCustomerId());
53
+
54
+ $merge_vars['FNAME'] = $customer->getFirstname();
55
+ $merge_vars['LNAME'] = $customer->getLastname();
56
+
57
+ }
58
+
59
+ if ($data['subscriber_status'] === 1) {
60
+ $logger->log('Subscribe newsletter');
61
+ $retval = $api->listSubscribe($listid, $email_address, $merge_vars, $email_type, $double_optin, $update_existing, $send_welcome);
62
+ } else {
63
+ $logger->log('Unsubscribe newsletter');
64
+ $retval = $api->listUnsubscribe($listid, $email_address, $delete_member, $send_goodbye, $send_notify);
65
+ }
66
+
67
+
68
+ if ($api->errorCode) {
69
+ $logger->log("Unable to (un)subscribe newsletter. $api->errorCode: $api->errorMessage");
70
+ }
71
+ }
72
+
73
+ return $observer;
74
+ }
75
+
76
+ /**
77
+ * Sync newsletter and customers by cron job
78
+ */
79
+ public function daily_sync()
80
+ {
81
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
82
+ $helper = Mage::helper('mailigen_synchronizer');
83
+ if (!$helper->isEnabled()) {
84
+ return "Module is disabled";
85
+ }
86
+
87
+ /**
88
+ * Synchronize Newsletter
89
+ */
90
+ try {
91
+ if ($helper->canAutoSyncNewsletter()) {
92
+ /** @var $mailigen Mailigen_Synchronizer_Model_Mailigen */
93
+ $mailigen = Mage::getModel('mailigen_synchronizer/mailigen');
94
+ $mailigen->syncNewsletter();
95
+ }
96
+ } catch (Exception $e) {
97
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
98
+ }
99
+
100
+ /**
101
+ * Synchronize Customers
102
+ */
103
+ try {
104
+ if ($helper->canAutoSyncCustomers() || $helper->getManualSync()) {
105
+ if ($helper->getManualSync()) {
106
+ $helper->setManualSync(0);
107
+ }
108
+
109
+ /** @var $mailigen Mailigen_Synchronizer_Model_Mailigen */
110
+ $mailigen = Mage::getModel('mailigen_synchronizer/mailigen');
111
+ $mailigen->syncCustomers();
112
+ }
113
+ } catch (Exception $e) {
114
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * @param Varien_Event_Observer $observer
120
+ */
121
+ public function adminSystemConfigChangedSectionMailigenSettings(Varien_Event_Observer $observer)
122
+ {
123
+ /** @var $list Mailigen_Synchronizer_Model_List */
124
+ $list = Mage::getModel('mailigen_synchronizer/list');
125
+ /** @var $config Mage_Core_Model_Config */
126
+ $config = new Mage_Core_Model_Config();
127
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
128
+ $helper = Mage::helper('mailigen_synchronizer');
129
+ /** @var $mailigenSchedule Mailigen_Synchronizer_Model_Schedule */
130
+ $mailigenSchedule = Mage::getModel('mailigen_synchronizer/schedule');
131
+ $removeCache = false;
132
+
133
+ /**
134
+ * Create new newsletter list
135
+ */
136
+ $newsletterNewListName = Mage::getStoreConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_NEW_LIST_TITLE);
137
+ if ($newsletterNewListName) {
138
+ if ($mailigenSchedule->countPendingOrRunningJobs() == 0) {
139
+ $newListValue = $list->createNewList($newsletterNewListName);
140
+ if ($newListValue) {
141
+ $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_CONTACT_LIST, $newListValue, 'default', 0);
142
+ $removeCache = true;
143
+ }
144
+ }
145
+ $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_NEW_LIST_TITLE, '', 'default', 0);
146
+ }
147
+
148
+ /**
149
+ * Create new customers list
150
+ */
151
+ $customersNewListName = Mage::getStoreConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_NEW_LIST_TITLE);
152
+ if ($customersNewListName) {
153
+ if ($mailigenSchedule->countPendingOrRunningJobs() == 0) {
154
+ $newListValue = $list->createNewList($customersNewListName);
155
+ if ($newListValue) {
156
+ $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_CONTACT_LIST, $newListValue, 'default', 0);
157
+ $removeCache = true;
158
+
159
+ /**
160
+ * Set customers not synced on contact list change
161
+ */
162
+ /** @var $customer Mailigen_Synchronizer_Model_Customer */
163
+ $customer = Mage::getModel('mailigen_synchronizer/customer');
164
+ $customer->setCustomersNotSynced();
165
+ }
166
+ }
167
+ $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_NEW_LIST_TITLE, '', 'default', 0);
168
+ }
169
+
170
+ /**
171
+ * Check if user selected the same contact lists for newsletter and customers
172
+ */
173
+ if ($helper->getNewsletterContactList() == $helper->getCustomersContactList() && $helper->getNewsletterContactList() != '') {
174
+ Mage::getSingleton('adminhtml/session')->addError("Please select different contact lists for newsletter and customers");
175
+ $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_CONTACT_LIST, '', 'default', 0);
176
+ $removeCache = true;
177
+ }
178
+
179
+ if ($removeCache) {
180
+ $config->removeCache();
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Add "Bulk synchronize with Mailigen" button "Manage Customers" page in BE
186
+ *
187
+ * @param Varien_Event_Observer $observer
188
+ */
189
+ public function adminhtmlWidgetContainerHtmlBefore(Varien_Event_Observer $observer)
190
+ {
191
+ $block = $observer->getBlock();
192
+
193
+ if ($block instanceof Mage_Adminhtml_Block_Customer && Mage::helper('mailigen_synchronizer')->isEnabled()) {
194
+ $url = Mage::helper('adminhtml')->getUrl('*/mailigen/syncCustomers');
195
+ $block->addButton('synchronize', array(
196
+ 'label' => Mage::helper('adminhtml')->__('Bulk synchronize with Mailigen'),
197
+ 'onclick' => "setLocation('{$url}')",
198
+ 'class' => 'task'
199
+ ));
200
+ }
201
+ }
202
+
203
+ /**
204
+ * @param Varien_Event_Observer $observer
205
+ */
206
+ public function customerDeleteAfter(Varien_Event_Observer $observer)
207
+ {
208
+ $customer = $observer->getDataObject();
209
+ if ($customer && $customer->getId()) {
210
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId(), 1);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * @param Varien_Event_Observer $observer
216
+ */
217
+ public function customerSaveAfter(Varien_Event_Observer $observer)
218
+ {
219
+ $customer = $observer->getDataObject();
220
+ if ($customer && $customer->getId()) {
221
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
222
+ }
223
+ }
224
+ /**
225
+ * @param Varien_Event_Observer $observer
226
+ */
227
+ public function customerAddressSaveAfter(Varien_Event_Observer $observer)
228
+ {
229
+ $customerAddress = $observer->getDataObject();
230
+ $customer = $customerAddress->getCustomer();
231
+ if ($customer && $customer->getId()) {
232
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
233
+ }
234
+ }
235
+
236
+ /**
237
+ * @param Varien_Event_Observer $observer
238
+ */
239
+ public function customerLogin(Varien_Event_Observer $observer)
240
+ {
241
+ $customer = $observer->getCustomer();
242
+ if ($customer && $customer->getId()) {
243
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
244
+ }
245
+ }
246
+
247
+ /**
248
+ * @param Varien_Event_Observer $observer
249
+ */
250
+ public function salesOrderSaveAfter(Varien_Event_Observer $observer)
251
+ {
252
+ $order = $observer->getOrder();
253
+ if ($order && $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE && $order->getCustomerId()) {
254
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($order->getCustomerId());
255
+ }
256
+ }
257
  }
app/code/community/Mailigen/Synchronizer/Model/Resource/Customer.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Resource_Customer extends Mage_Core_Model_Resource_Db_Abstract
11
+ {
12
+ protected function _construct()
13
+ {
14
+ $this->_init('mailigen_synchronizer/customer', 'id');
15
+ }
16
+ }
app/code/community/Mailigen/Synchronizer/Model/Resource/Customer/Collection.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Resource_Customer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
11
+ {
12
+ protected function _construct()
13
+ {
14
+ $this->_init('mailigen_synchronizer/customer');
15
+ }
16
+
17
+ /**
18
+ * Retrieve all ids for collection
19
+ *
20
+ * @param bool $is_synced
21
+ * @param bool $is_removed
22
+ * @return array
23
+ */
24
+ public function getAllIds($is_synced = false, $is_removed = false)
25
+ {
26
+ $idsSelect = clone $this->getSelect();
27
+ $idsSelect->reset(Zend_Db_Select::ORDER);
28
+ $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
29
+ $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
30
+ $idsSelect->reset(Zend_Db_Select::COLUMNS);
31
+
32
+ if (is_int($is_synced)) {
33
+ $idsSelect->where('is_synced = ?', $is_synced);
34
+ }
35
+ if (is_int($is_removed)) {
36
+ $idsSelect->where('is_removed = ?', $is_removed);
37
+ }
38
+
39
+ $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');
40
+ return $this->getConnection()->fetchCol($idsSelect);
41
+ }
42
+ }
app/code/community/Mailigen/Synchronizer/Model/Resource/Iterator/Batched.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Resource_Iterator_Batched extends Varien_Object
11
+ {
12
+ const DEFAULT_BATCH_SIZE = 250;
13
+
14
+ /**
15
+ * @param $collection
16
+ * @param array $callbackForIndividual
17
+ * @param array $callbackAfterBatch
18
+ * @param null $batchSize
19
+ * @param null $batchLimit
20
+ * @return int
21
+ */
22
+ public function walk($collection, array $callbackForIndividual, array $callbackAfterBatch, $batchSize = null, $batchLimit = null)
23
+ {
24
+ if (!$batchSize) {
25
+ $batchSize = self::DEFAULT_BATCH_SIZE;
26
+ }
27
+
28
+ $collection->setPageSize($batchSize);
29
+
30
+ $currentPage = 1;
31
+ $pages = $collection->getLastPageNumber();
32
+
33
+ do {
34
+ $collection->setCurPage($currentPage);
35
+ $collection->load();
36
+
37
+ foreach ($collection as $item) {
38
+ call_user_func($callbackForIndividual, $item);
39
+ }
40
+
41
+ if (!empty($callbackAfterBatch)) {
42
+ $collectionInfo = array('currentPage' => $currentPage, 'pages' => $pages, 'pageSize' => $batchSize);
43
+ call_user_func($callbackAfterBatch, $collectionInfo);
44
+ }
45
+
46
+ if (is_int($batchLimit) && $currentPage * $batchSize >= $batchLimit) {
47
+ return 0;
48
+ }
49
+
50
+ $currentPage++;
51
+ $collection->clear();
52
+ } while ($currentPage <= $pages);
53
+
54
+ return 1;
55
+ }
56
+ }
app/code/community/Mailigen/Synchronizer/Model/Schedule.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_Schedule extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @var string
14
+ */
15
+ protected $_jobCode = 'mailigen_synchronizer';
16
+
17
+ /**
18
+ * @var null
19
+ */
20
+ protected $_countPendingOrRunningJobs = null;
21
+
22
+ /**
23
+ * @return int|null
24
+ */
25
+ public function countPendingOrRunningJobs()
26
+ {
27
+ if (is_null($this->_countPendingOrRunningJobs)) {
28
+ $pendingOrRunningJobs = Mage::getModel('cron/schedule')->getCollection()
29
+ ->addFieldToFilter('job_code', $this->_jobCode)
30
+ ->addFieldToFilter('status', array(
31
+ 'in' => array(
32
+ Mage_Cron_Model_Schedule::STATUS_RUNNING,
33
+ Mage_Cron_Model_Schedule::STATUS_PENDING
34
+ )
35
+ ));
36
+ $this->_countPendingOrRunningJobs = $pendingOrRunningJobs->getSize();
37
+ }
38
+
39
+ return $this->_countPendingOrRunningJobs;
40
+ }
41
+
42
+ /**
43
+ * @return null|Mage_Cron_Model_Schedule
44
+ */
45
+ public function getLastRunningJob()
46
+ {
47
+ /** @var $runningJobs Mage_Cron_Model_Resource_Schedule_Collection */
48
+ $runningJobs = Mage::getModel('cron/schedule')->getCollection()
49
+ ->addFieldToFilter('job_code', $this->_jobCode)
50
+ ->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_RUNNING)
51
+ ->setOrder('executed_at')
52
+ ->setPageSize(1)->setCurPage(1);
53
+
54
+ return $runningJobs->getSize() ? $runningJobs->getFirstItem() : null;
55
+ }
56
+
57
+ /**
58
+ * @return null|Mage_Cron_Model_Schedule
59
+ */
60
+ public function getLastPendingJob()
61
+ {
62
+ /** @var $runningJobs Mage_Cron_Model_Resource_Schedule_Collection */
63
+ $pendingJobs = Mage::getModel('cron/schedule')->getCollection()
64
+ ->addFieldToFilter('job_code', $this->_jobCode)
65
+ ->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_PENDING)
66
+ ->setOrder('executed_at')
67
+ ->setPageSize(1)->setCurPage(1);
68
+
69
+ return $pendingJobs->getSize() ? $pendingJobs->getFirstItem() : null;
70
+ }
71
+
72
+ /**
73
+ * @param int $delay Schedule job, to run after delay (in minutes)
74
+ * @return Mage_Cron_Model_Schedule
75
+ */
76
+ public function createJob($delay = 0)
77
+ {
78
+ /** @var $cronScheduler Mage_Cron_Model_Schedule */
79
+ $cronScheduler = Mage::getModel('cron/schedule');
80
+ $time = time() + 60 * $delay;
81
+ $cronScheduler->setJobCode($this->_jobCode)
82
+ ->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING)
83
+ ->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $time))
84
+ ->setScheduledAt(strftime('%Y-%m-%d %H:%M:00', $time));
85
+
86
+ return $cronScheduler->save();
87
+ }
88
+ }
app/code/community/Mailigen/Synchronizer/Model/System/Config/Backend/Customer/List.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_System_Config_Backend_Customer_List extends Mage_Core_Model_Config_Data
11
+ {
12
+ /**
13
+ * Processing object before save data
14
+ *
15
+ * @return Mage_Core_Model_Abstract
16
+ */
17
+ protected function _beforeSave()
18
+ {
19
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
20
+ $helper = Mage::helper('mailigen_synchronizer');
21
+ $oldValue = $helper->getCustomersContactList();
22
+ $newValue = $this->getValue();
23
+
24
+ if ($oldValue != $newValue) {
25
+ /** @var $mailigenSchedule Mailigen_Synchronizer_Model_Schedule */
26
+ $mailigenSchedule = Mage::getModel('mailigen_synchronizer/schedule');
27
+ if ($mailigenSchedule->countPendingOrRunningJobs() > 0) {
28
+ /**
29
+ * Deny config modification, until synchronization will not be finished
30
+ */
31
+ $this->_dataSaveAllowed = false;
32
+ Mage::getSingleton('adminhtml/session')->addNotice($helper->__("You can't change customer list until synchronization will not be finished."));
33
+ } else {
34
+ /**
35
+ * Set customers not synced on contact list change
36
+ */
37
+ /** @var $customer Mailigen_Synchronizer_Model_Customer */
38
+ $customer = Mage::getModel('mailigen_synchronizer/customer');
39
+ $customer->setCustomersNotSynced();
40
+ }
41
+ }
42
+ }
43
+ }
app/code/community/Mailigen/Synchronizer/Model/System/Config/Backend/Newsletter/List.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Model_System_Config_Backend_Newsletter_List extends Mage_Core_Model_Config_Data
11
+ {
12
+ /**
13
+ * Processing object before save data
14
+ *
15
+ * @return Mage_Core_Model_Abstract
16
+ */
17
+ protected function _beforeSave()
18
+ {
19
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
20
+ $helper = Mage::helper('mailigen_synchronizer');
21
+ /** @var $mailigenSchedule Mailigen_Synchronizer_Model_Schedule */
22
+ $mailigenSchedule = Mage::getModel('mailigen_synchronizer/schedule');
23
+ $oldValue = $helper->getNewsletterContactList();
24
+ $newValue = $this->getValue();
25
+
26
+ /**
27
+ * Deny config modification, until synchronization will not be finished
28
+ */
29
+ if ($oldValue != $newValue && $mailigenSchedule->countPendingOrRunningJobs() > 0) {
30
+ $this->_dataSaveAllowed = false;
31
+ Mage::getSingleton('adminhtml/session')->addNotice($helper->__("You can't change newsletter list until synchronization will not be finished."));
32
+ }
33
+ }
34
+ }
app/code/community/Mailigen/Synchronizer/controllers/Adminhtml/MailigenController.php CHANGED
@@ -1,13 +1,59 @@
1
- <?php
2
-
3
- class Mailigen_Synchronizer_Adminhtml_MailigenController extends Mage_Adminhtml_Controller_Action {
4
-
5
- public function syncAction(){
6
-
7
- $mailigen = Mage::getModel('mailigen_synchronizer/mailigen');
8
- $mailigen->sync();
9
-
10
- $this->_redirect('*/newsletter_subscriber/index');
11
- }
12
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  }
1
+ <?php
2
+
3
+ class Mailigen_Synchronizer_Adminhtml_MailigenController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function syncNewsletterAction()
6
+ {
7
+ /** @var $mailigen Mailigen_Synchronizer_Model_Mailigen */
8
+ $mailigen = Mage::getModel('mailigen_synchronizer/mailigen');
9
+ $mailigen->syncNewsletter();
10
+
11
+ $this->_redirect('*/newsletter_subscriber/index');
12
+ }
13
+
14
+ public function syncCustomersAction()
15
+ {
16
+ try {
17
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
18
+ $helper = Mage::helper('mailigen_synchronizer');
19
+ /** @var $mailigenSchedule Mailigen_Synchronizer_Model_Schedule */
20
+ $mailigenSchedule = Mage::getModel('mailigen_synchronizer/schedule');
21
+
22
+ if ($mailigenSchedule->countPendingOrRunningJobs() == 0) {
23
+ $mailigenSchedule->createJob();
24
+ $helper->setManualSync(1);
25
+ }
26
+
27
+ $this->_getSession()->addSuccess($this->__('Mailigen customer synchronization task will start shortly.'));
28
+ } catch (Exception $e) {
29
+ $this->_getSession()->addError($e->getMessage());
30
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
31
+ }
32
+
33
+ $this->_redirect('*/customer/index');
34
+ }
35
+
36
+ /**
37
+ * Force stop customer sync
38
+ */
39
+ public function stopSyncCustomersAction()
40
+ {
41
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
42
+ $helper = Mage::helper('mailigen_synchronizer');
43
+ $helper->setStopSync(1);
44
+
45
+ $this->getResponse()->setBody($this->__('Customer sync will be stopped within a minute'));
46
+ }
47
+
48
+ /**
49
+ * Force set customers not synced, to allow sync again
50
+ */
51
+ public function resetSyncCustomersAction()
52
+ {
53
+ /** @var $customer Mailigen_Synchronizer_Model_Customer */
54
+ $customer = Mage::getModel('mailigen_synchronizer/customer');
55
+ $customer->setCustomersNotSynced();
56
+
57
+ $this->getResponse()->setBody('1');
58
+ }
59
  }
app/code/community/Mailigen/Synchronizer/data/mailigen_synchronizer_setup/data-install-1.1.0.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mailigen_Synchronizer
4
+ *
5
+ * @category Mailigen
6
+ * @package Mailigen_Synchronizer
7
+ * @author Maksim Soldatjonok <maksold@gmail.com>
8
+ */
9
+ /* @var $installer Mage_Core_Model_Resource_Setup */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $configModel = new Mage_Core_Model_Config();
14
+ $configMapping = array(
15
+ 'mailigen_settings/mailigen_general_group/mailigen_general_status' => Mailigen_Synchronizer_Helper_Data::XML_PATH_ENABLED,
16
+ 'mailigen_settings/mailigen_general_group/mailigen_general_api_key' => Mailigen_Synchronizer_Helper_Data::XML_PATH_API_KEY,
17
+ 'mailigen_settings/mailigen_general_group/mailigen_general_new_list' => Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_NEW_LIST_TITLE,
18
+ 'mailigen_settings/mailigen_general_group/mailigen_autosync_list' => Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_AUTOSYNC,
19
+ 'mailigen_settings/mailigen_general_group/mailigen_default_emails' => Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_HANDLE_DEFAULT_EMAILS,
20
+ 'mailigen_settings/mailigen_general_group/mailigen_general_list' => Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_CONTACT_LIST,
21
+ );
22
+
23
+ foreach ($configMapping as $oldConfig => $newConfig) {
24
+ $oldConfigValue = Mage::getStoreConfig($oldConfig);
25
+
26
+ $configModel->saveConfig($newConfig, $oldConfigValue);
27
+ $configModel->deleteConfig($oldConfig);
28
+ }
29
+
30
+ $installer->endSetup();
app/code/community/Mailigen/Synchronizer/etc/config.xml CHANGED
@@ -2,52 +2,129 @@
2
  <config>
3
  <modules>
4
  <Mailigen_Synchronizer>
5
- <version>1.0.1</version>
6
  </Mailigen_Synchronizer>
7
  </modules>
8
  <global>
9
  <helpers>
10
- <Mailigen_Synchronizer>
11
  <class>Mailigen_Synchronizer_Helper</class>
12
- </Mailigen_Synchronizer>
13
  </helpers>
14
- <models>
 
 
 
 
 
 
 
 
 
 
15
  <mailigen_synchronizer>
16
  <class>Mailigen_Synchronizer_Model</class>
 
17
  </mailigen_synchronizer>
18
- <!-- we rewrite Newsletter Module -->
 
 
 
 
 
 
 
19
  <newsletter>
20
  <rewrite>
21
  <subscriber>Mailigen_Synchronizer_Model_Newsletter_Subscriber</subscriber>
22
  </rewrite>
23
  </newsletter>
24
  </models>
25
- <blocks>
26
- <adminhtml>
27
- <rewrite>
28
- <newsletter_subscriber_grid>Mailigen_Synchronizer_Block_Newsletter_Subscriber_Grid</newsletter_subscriber_grid>
29
- </rewrite>
30
- </adminhtml>
31
- </blocks>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  <events>
33
  <newsletter_subscriber_save_commit_after>
34
  <observers>
35
  <newsletter_subscriber_newsletter_subscriber_create_after>
36
  <type>singleton</type>
37
  <class>Mailigen_Synchronizer_Model_Observer</class>
38
- <method>newsletter_subscriber_create_after</method>
39
  </newsletter_subscriber_newsletter_subscriber_create_after>
40
  </observers>
41
  </newsletter_subscriber_save_commit_after>
42
- <admin_system_config_changed_section_mailigen_settings>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  <observers>
44
- <newsletter_subscriber_admin_system_config_changed_section_mailigen_settings>
45
  <type>singleton</type>
46
  <class>Mailigen_Synchronizer_Model_Observer</class>
47
- <method>admin_system_config_changed_section_mailigen_settings</method>
48
- </newsletter_subscriber_admin_system_config_changed_section_mailigen_settings>
49
  </observers>
50
- </admin_system_config_changed_section_mailigen_settings>
 
 
 
 
 
 
 
 
 
51
  </events>
52
  </global>
53
  <admin>
@@ -73,9 +150,9 @@
73
  <children>
74
  <config>
75
  <children>
76
- <mailigen_settings>
77
  <title>Mailigen - Settings</title>
78
- </mailigen_settings>
79
  </children>
80
  </config>
81
  </children>
@@ -84,13 +161,33 @@
84
  </admin>
85
  </resources>
86
  </acl>
 
 
 
 
 
 
 
 
 
 
 
87
  </adminhtml>
 
 
 
 
 
 
 
88
  <crontab>
89
  <jobs>
90
- <Mailigen_Synchronizer>
91
- <schedule><cron_expr>*/5 * * * *</cron_expr></schedule>
92
- <run><model>newsletter_subscriber/observer::daily_sync</model></run>
93
- </Mailigen_Synchronizer>
 
 
94
  </jobs>
95
  </crontab>
96
  </config>
2
  <config>
3
  <modules>
4
  <Mailigen_Synchronizer>
5
+ <version>1.1.0</version>
6
  </Mailigen_Synchronizer>
7
  </modules>
8
  <global>
9
  <helpers>
10
+ <mailigen_synchronizer>
11
  <class>Mailigen_Synchronizer_Helper</class>
12
+ </mailigen_synchronizer>
13
  </helpers>
14
+ <blocks>
15
+ <mailigen_synchronizer>
16
+ <class>Mailigen_Synchronizer_Block</class>
17
+ </mailigen_synchronizer>
18
+ <adminhtml>
19
+ <rewrite>
20
+ <newsletter_subscriber_grid>Mailigen_Synchronizer_Block_Newsletter_Subscriber_Grid</newsletter_subscriber_grid>
21
+ </rewrite>
22
+ </adminhtml>
23
+ </blocks>
24
+ <models>
25
  <mailigen_synchronizer>
26
  <class>Mailigen_Synchronizer_Model</class>
27
+ <resourceModel>mailigen_synchronizer_resource</resourceModel>
28
  </mailigen_synchronizer>
29
+ <mailigen_synchronizer_resource>
30
+ <class>Mailigen_Synchronizer_Model_Resource</class>
31
+ <entities>
32
+ <customer>
33
+ <table>mailigen_synchronizer_customer</table>
34
+ </customer>
35
+ </entities>
36
+ </mailigen_synchronizer_resource>
37
  <newsletter>
38
  <rewrite>
39
  <subscriber>Mailigen_Synchronizer_Model_Newsletter_Subscriber</subscriber>
40
  </rewrite>
41
  </newsletter>
42
  </models>
43
+ <resources>
44
+ <mailigen_synchronizer_setup>
45
+ <setup>
46
+ <module>Mailigen_Synchronizer</module>
47
+ <class>Mage_Core_Model_Resource_Setup</class>
48
+ </setup>
49
+ <connection>
50
+ <use>core_setup</use>
51
+ </connection>
52
+ </mailigen_synchronizer_setup>
53
+ <mailigen_synchronizer_write>
54
+ <connection>
55
+ <use>core_write</use>
56
+ </connection>
57
+ </mailigen_synchronizer_write>
58
+ <mailigen_synchronizer_read>
59
+ <connection>
60
+ <use>core_read</use>
61
+ </connection>
62
+ </mailigen_synchronizer_read>
63
+ </resources>
64
  <events>
65
  <newsletter_subscriber_save_commit_after>
66
  <observers>
67
  <newsletter_subscriber_newsletter_subscriber_create_after>
68
  <type>singleton</type>
69
  <class>Mailigen_Synchronizer_Model_Observer</class>
70
+ <method>newsletterSubscriberSaveCommitAfter</method>
71
  </newsletter_subscriber_newsletter_subscriber_create_after>
72
  </observers>
73
  </newsletter_subscriber_save_commit_after>
74
+ <admin_system_config_changed_section_mailigen_synchronizer>
75
+ <observers>
76
+ <newsletter_subscriber_admin_system_config_changed_section_mailigen_synchronizer>
77
+ <type>singleton</type>
78
+ <class>Mailigen_Synchronizer_Model_Observer</class>
79
+ <method>adminSystemConfigChangedSectionMailigenSettings</method>
80
+ </newsletter_subscriber_admin_system_config_changed_section_mailigen_synchronizer>
81
+ </observers>
82
+ </admin_system_config_changed_section_mailigen_synchronizer>
83
+ <customer_delete_after>
84
+ <observers>
85
+ <mailigen_synchronizer_customer_delete_after>
86
+ <type>singleton</type>
87
+ <class>Mailigen_Synchronizer_Model_Observer</class>
88
+ <method>customerDeleteAfter</method>
89
+ </mailigen_synchronizer_customer_delete_after>
90
+ </observers>
91
+ </customer_delete_after>
92
+ <customer_save_after>
93
+ <observers>
94
+ <mailigen_synchronizer_customer_save_after>
95
+ <type>singleton</type>
96
+ <class>Mailigen_Synchronizer_Model_Observer</class>
97
+ <method>customerSaveAfter</method>
98
+ </mailigen_synchronizer_customer_save_after>
99
+ </observers>
100
+ </customer_save_after>
101
+ <customer_address_save_after>
102
+ <observers>
103
+ <mailigen_synchronizer_customer_address_save_after>
104
+ <type>singleton</type>
105
+ <class>Mailigen_Synchronizer_Model_Observer</class>
106
+ <method>customerAddressSaveAfter</method>
107
+ </mailigen_synchronizer_customer_address_save_after>
108
+ </observers>
109
+ </customer_address_save_after>
110
+ <customer_login>
111
  <observers>
112
+ <mailigen_synchronizer_customer_login>
113
  <type>singleton</type>
114
  <class>Mailigen_Synchronizer_Model_Observer</class>
115
+ <method>customerLogin</method>
116
+ </mailigen_synchronizer_customer_login>
117
  </observers>
118
+ </customer_login>
119
+ <sales_order_save_after>
120
+ <observers>
121
+ <mailigen_synchronizer_sales_order_save_after>
122
+ <type>singleton</type>
123
+ <class>Mailigen_Synchronizer_Model_Observer</class>
124
+ <method>salesOrderSaveAfter</method>
125
+ </mailigen_synchronizer_sales_order_save_after>
126
+ </observers>
127
+ </sales_order_save_after>
128
  </events>
129
  </global>
130
  <admin>
150
  <children>
151
  <config>
152
  <children>
153
+ <mailigen_synchronizer>
154
  <title>Mailigen - Settings</title>
155
+ </mailigen_synchronizer>
156
  </children>
157
  </config>
158
  </children>
161
  </admin>
162
  </resources>
163
  </acl>
164
+ <events>
165
+ <adminhtml_widget_container_html_before>
166
+ <observers>
167
+ <mailigen_synchronizer_adminhtml_widget_container_html_before>
168
+ <type>singleton</type>
169
+ <class>Mailigen_Synchronizer_Model_Observer</class>
170
+ <method>adminhtmlWidgetContainerHtmlBefore</method>
171
+ </mailigen_synchronizer_adminhtml_widget_container_html_before>
172
+ </observers>
173
+ </adminhtml_widget_container_html_before>
174
+ </events>
175
  </adminhtml>
176
+ <default>
177
+ <mailigen_synchronizer>
178
+ <general>
179
+ <cron_string>0 1 * * *</cron_string>
180
+ </general>
181
+ </mailigen_synchronizer>
182
+ </default>
183
  <crontab>
184
  <jobs>
185
+ <mailigen_synchronizer>
186
+ <schedule>
187
+ <config_path>mailigen_synchronizer/general/cron_string</config_path>
188
+ </schedule>
189
+ <run><model>mailigen_synchronizer/observer::daily_sync</model></run>
190
+ </mailigen_synchronizer>
191
  </jobs>
192
  </crontab>
193
  </config>
app/code/community/Mailigen/Synchronizer/etc/system.xml CHANGED
@@ -1,90 +1,167 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <config>
3
- <sections>
4
- <mailigen_settings translate="label" module="Mailigen_Synchronizer">
5
- <label>Mailigen Configuration</label>
6
- <tab>customer</tab>
7
- <sort_order>1000</sort_order>
8
- <show_in_default>1</show_in_default>
9
- <show_in_website>1</show_in_website>
10
- <show_in_store>1</show_in_store>
11
- <groups>
12
- <mailigen_general_group translate="label" module="Mailigen_Synchronizer">
13
- <label>General</label>
14
- <frontend_type>text</frontend_type>
15
- <sort_order>1000</sort_order>
16
- <show_in_default>1</show_in_default>
17
- <show_in_website>1</show_in_website>
18
- <show_in_store>1</show_in_store>
19
- <fields>
20
- <mailigen_general_status translate="label">
21
- <label>Enabled</label>
22
- <frontend_type>select</frontend_type>
23
- <source_model>adminhtml/system_config_source_yesno</source_model>
24
- <sort_order>1</sort_order>
25
- <show_in_default>1</show_in_default>
26
- <show_in_website>1</show_in_website>
27
- <show_in_store>1</show_in_store>
28
- </mailigen_general_status>
29
- <mailigen_general_api_key translate="label">
30
- <label>Api Key: </label>
31
- <comment>API Key - see http://admin.mailigen.com/settings/api</comment>
32
- <frontend_type>text</frontend_type>
33
- <sort_order>2</sort_order>
34
- <show_in_default>1</show_in_default>
35
- <show_in_website>1</show_in_website>
36
- <show_in_store>1</show_in_store>
37
- </mailigen_general_api_key>
38
- <mailigen_general_list translate="label">
39
- <label>Contact List</label>
40
- <frontend_type>select</frontend_type>
41
- <source_model>mailigen_synchronizer/list</source_model>
42
- <sort_order>3</sort_order>
43
- <show_in_default>1</show_in_default>
44
- <show_in_website>1</show_in_website>
45
- <show_in_store>1</show_in_store>
46
- <comment>By selecting a new list option you'll be able to create a new Mailigen list directly from this panel.</comment>
47
- <!--
48
- <depends>
49
- <mailigen_general_api_key></mailigen_general_api_key>
50
- </depends>
51
- -->
52
- </mailigen_general_list>
53
- <mailigen_general_new_list translate="label">
54
- <label>New List Title</label>
55
- <frontend_type>text</frontend_type>
56
- <sort_order>4</sort_order>
57
- <show_in_default>1</show_in_default>
58
- <show_in_website>1</show_in_website>
59
- <show_in_store>1</show_in_store>
60
- <comment>Type the title of your new list. During the save, the list will be created and it will become the current contact list.</comment>
61
- <depends>
62
- <mailigen_general_list></mailigen_general_list>
63
- </depends>
64
- </mailigen_general_new_list>
65
- <mailigen_autosync_list translate="label">
66
- <label>Auto Sync List</label>
67
- <frontend_type>select</frontend_type>
68
- <source_model>adminhtml/system_config_source_yesno</source_model>
69
- <sort_order>5</sort_order>
70
- <show_in_default>1</show_in_default>
71
- <show_in_website>1</show_in_website>
72
- <show_in_store>1</show_in_store>
73
- <comment>If set to yes, this will perform batch syncronization of your list at 1:00 AM every night. You must have CRON setup on your store for this feature to work.</comment>
74
- </mailigen_autosync_list>
75
- <mailigen_default_emails translate="label">
76
- <label>Enable Mailigen Emails</label>
77
- <frontend_type>select</frontend_type>
78
- <source_model>adminhtml/system_config_source_yesno</source_model>
79
- <sort_order>6</sort_order>
80
- <show_in_default>1</show_in_default>
81
- <show_in_website>1</show_in_website>
82
- <show_in_store>1</show_in_store>
83
- <comment>If set to yes, this will disable the Magento "Subscription Success","Subscription Confirmation" and the "Unsubscription Confirmation" emails. Mailigen will send these emails for you</comment>
84
- </mailigen_default_emails>
85
- </fields>
86
- </mailigen_general_group>
87
- </groups>
88
- </mailigen_settings>
89
- </sections>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  </config>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <mailigen_synchronizer translate="label" module="mailigen_synchronizer">
5
+ <label>Mailigen</label>
6
+ <tab>customer</tab>
7
+ <sort_order>1000</sort_order>
8
+ <show_in_default>1</show_in_default>
9
+ <show_in_website>1</show_in_website>
10
+ <show_in_store>1</show_in_store>
11
+ <groups>
12
+ <general translate="label" module="mailigen_synchronizer">
13
+ <label>General</label>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>10</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <fields>
20
+ <enabled translate="label">
21
+ <label>Enabled</label>
22
+ <frontend_type>select</frontend_type>
23
+ <source_model>adminhtml/system_config_source_yesno</source_model>
24
+ <sort_order>10</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ </enabled>
29
+ <api_key translate="label">
30
+ <label>Api Key:</label>
31
+ <comment>API Key - see http://admin.mailigen.com/settings/api</comment>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>20</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ </api_key>
38
+ <cron_string translate="label">
39
+ <label>Sync schedule (cron syntax)</label>
40
+ <frontend_type>text</frontend_type>
41
+ <sort_order>30</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>0</show_in_website>
44
+ <show_in_store>0</show_in_store>
45
+ <comment>If set "0 1 * * *", then sync once a day at 1:00 AM</comment>
46
+ </cron_string>
47
+ </fields>
48
+ </general>
49
+ <newsletter translate="label" module="mailigen_synchronizer">
50
+ <label>Newsletter</label>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>20</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ <fields>
57
+ <contact_list translate="label">
58
+ <label>Newsletter Contact List</label>
59
+ <frontend_type>select</frontend_type>
60
+ <source_model>mailigen_synchronizer/list</source_model>
61
+ <backend_model>mailigen_synchronizer/system_config_backend_newsletter_list</backend_model>
62
+ <sort_order>10</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ <comment>By selecting a new list option you'll be able to create a new Mailigen list directly from this panel. Attention! Please do not confuse Newsletter and Customer lists!</comment>
67
+ </contact_list>
68
+ <new_list_title translate="label">
69
+ <label>New Contact List Title</label>
70
+ <frontend_type>text</frontend_type>
71
+ <sort_order>20</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ <comment>Type the title of your new list. During the save, the list will be created and it will become the current contact list.</comment>
76
+ <depends>
77
+ <contact_list></contact_list>
78
+ </depends>
79
+ </new_list_title>
80
+ <autosync translate="label">
81
+ <label>Auto Sync Newsletter</label>
82
+ <frontend_type>select</frontend_type>
83
+ <source_model>adminhtml/system_config_source_yesno</source_model>
84
+ <sort_order>30</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>1</show_in_store>
88
+ <comment>If set to yes, this will perform batch synchronization of your list. You must have CRON setup on your store for this feature to work.</comment>
89
+ </autosync>
90
+ <handle_default_emails translate="label">
91
+ <label>Enable Mailigen Emails</label>
92
+ <frontend_type>select</frontend_type>
93
+ <source_model>adminhtml/system_config_source_yesno</source_model>
94
+ <sort_order>40</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <comment>If set to yes, this will disable the Magento "Subscription Success","Subscription Confirmation" and the "Unsubscription Confirmation" emails. Mailigen will send these emails for you</comment>
99
+ </handle_default_emails>
100
+ </fields>
101
+ </newsletter>
102
+ <customers translate="label" module="mailigen_synchronizer">
103
+ <label>Customers</label>
104
+ <frontend_type>text</frontend_type>
105
+ <sort_order>30</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ <fields>
110
+ <contact_list translate="label">
111
+ <label>Customers Contact List</label>
112
+ <frontend_type>select</frontend_type>
113
+ <source_model>mailigen_synchronizer/list</source_model>
114
+ <backend_model>mailigen_synchronizer/system_config_backend_customer_list</backend_model>
115
+ <sort_order>10</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>1</show_in_store>
119
+ <comment>By selecting a new list option you'll be able to create a new Mailigen list directly from this panel. Attention! Please do not confuse Newsletter and Customer lists!</comment>
120
+ </contact_list>
121
+ <new_list_title translate="label">
122
+ <label>New Contact List Title</label>
123
+ <frontend_type>text</frontend_type>
124
+ <sort_order>20</sort_order>
125
+ <show_in_default>1</show_in_default>
126
+ <show_in_website>1</show_in_website>
127
+ <show_in_store>1</show_in_store>
128
+ <comment>Type the title of your new list. During the save, the list will be created and it will become the current contact list.</comment>
129
+ <depends>
130
+ <contact_list></contact_list>
131
+ </depends>
132
+ </new_list_title>
133
+ <autosync translate="label">
134
+ <label>Auto Sync Customers</label>
135
+ <frontend_type>select</frontend_type>
136
+ <source_model>adminhtml/system_config_source_yesno</source_model>
137
+ <sort_order>30</sort_order>
138
+ <show_in_default>1</show_in_default>
139
+ <show_in_website>1</show_in_website>
140
+ <show_in_store>1</show_in_store>
141
+ <comment>If set to yes, this will perform batch synchronization of your list. You must have CRON setup on your store for this feature to work.</comment>
142
+ </autosync>
143
+ <sycn_information>
144
+ <frontend_model>mailigen_synchronizer/adminhtml_sync_information</frontend_model>
145
+ <sort_order>40</sort_order>
146
+ <show_in_default>1</show_in_default>
147
+ <show_in_website>1</show_in_website>
148
+ <show_in_store>1</show_in_store>
149
+ </sycn_information>
150
+ <manual_sync>
151
+ <frontend_type>hidden</frontend_type>
152
+ <show_in_default>0</show_in_default>
153
+ <show_in_website>0</show_in_website>
154
+ <show_in_store>0</show_in_store>
155
+ </manual_sync>
156
+ <stop_sync>
157
+ <frontend_type>hidden</frontend_type>
158
+ <show_in_default>0</show_in_default>
159
+ <show_in_website>0</show_in_website>
160
+ <show_in_store>0</show_in_store>
161
+ </stop_sync>
162
+ </fields>
163
+ </customers>
164
+ </groups>
165
+ </mailigen_synchronizer>
166
+ </sections>
167
  </config>
app/code/community/Mailigen/Synchronizer/sql/mailigen_synchronizer_setup/install-1.1.0.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mailigen_Synchronizer
4
+ *
5
+ * @category Mailigen
6
+ * @package Mailigen_Synchronizer
7
+ * @author Maksim Soldatjonok <maksold@gmail.com>
8
+ */
9
+ /* @var $installer Mage_Core_Model_Resource_Setup */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ /**
14
+ * Drop table 'mailigen_synchronizer/customer' if it exists
15
+ */
16
+ $installer->getConnection()->dropTable($installer->getTable('mailigen_synchronizer/customer'));
17
+
18
+ /**
19
+ * Create table 'mailigen_synchronizer/customer'
20
+ */
21
+ $table = $installer->getConnection()
22
+ ->newTable($installer->getTable('mailigen_synchronizer/customer'))
23
+ // Customer info fields
24
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
25
+ array('unsigned' => true, 'nullable' => false, 'primary' => true,), 'Customer Id'
26
+ )
27
+ ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
28
+ // Customer order fields
29
+ ->addColumn('lastorderdate', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
30
+ ->addColumn('valueoflastorder', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
31
+ ->addColumn('totalvalueoforders', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
32
+ ->addColumn('totalnumberoforders', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
33
+ ->addColumn('numberofitemsincart', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
34
+ ->addColumn('valueofcurrentcart', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
35
+ ->addColumn('lastitemincartaddingdate', Varien_Db_Ddl_Table::TYPE_TEXT, 255)
36
+ // Special fields
37
+ ->addColumn('is_removed', Varien_Db_Ddl_Table::TYPE_TINYINT, 1, array('default' => '0'))
38
+ ->addColumn('is_synced', Varien_Db_Ddl_Table::TYPE_TINYINT, 1, array('default' => '0'))
39
+ ->addColumn('synced_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP)
40
+ ->setComment('Mailigen Synchronizer Customers');
41
+
42
+ $installer->getConnection()->createTable($table);
43
+
44
+ $installer->endSetup();
app/etc/modules/Mailigen_Synchronizer.xml DELETED
@@ -1,9 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Mailigen_Synchronizer>
5
- <active>true</active>
6
- <codePool>community</codePool>
7
- </Mailigen_Synchronizer>
8
- </modules>
9
- </config>
 
 
 
 
 
 
 
 
 
{app/code/community/Mailigen/Synchronizer/api → lib/mailigen}/MGAPI.class.php RENAMED
@@ -1,1627 +1,1652 @@
1
- <?php
2
-
3
- class MGAPI {
4
- var $version = "1.5";
5
- var $errorMessage;
6
- var $errorCode;
7
-
8
- /**
9
- * API server adrese
10
- */
11
- var $apiUrl;
12
-
13
- /**
14
- * Default to a 300 second timeout on server calls
15
- */
16
- var $timeout = 300;
17
-
18
- /**
19
- * Default to a 8K chunk size
20
- */
21
- var $chunkSize = 8192;
22
-
23
- /**
24
- * Lietotaja API atslega
25
- */
26
- var $api_key;
27
-
28
- /**
29
- * Izmantot ssl: false - ne, true - ja
30
- */
31
- var $secure = false;
32
-
33
- /**
34
- * Pieslegties pie MailiGen API
35
- *
36
- * @param string $apikey Jusu MailiGen API atslega
37
- * @param string $secure Izmantot vai neizmantot ssl pieslegšanos
38
- */
39
- function MGAPI($apikey, $secure = false) {
40
- $this->secure = $secure;
41
- $this->apiUrl = parse_url("http://api.mailigen.com/" . $this->version . "/?output=php");
42
- if ( isset($GLOBALS["mg_api_key"]) && $GLOBALS["mg_api_key"]!="" ){
43
- $this->api_key = $GLOBALS["mg_api_key"];
44
- } else {
45
- $this->api_key = $GLOBALS["mg_api_key"] = $apikey;
46
- }
47
- }
48
- function setTimeout($seconds){
49
- if (is_int($seconds)){
50
- $this->timeout = $seconds;
51
- return true;
52
- }
53
- }
54
- function getTimeout(){
55
- return $this->timeout;
56
- }
57
- function useSecure($val){
58
- if ($val === true){
59
- $this->secure = true;
60
- } else {
61
- $this->secure = false;
62
- }
63
- }
64
-
65
- /**
66
- * Noņemam nost statusu, kas lika kampaņu izsūtīt kaut kad nākotnē
67
- *
68
- * @example mgapi_campaignUnschedule.php
69
- * @example xml-rpc_campaignUnschedule.php
70
- *
71
- * @param string $cid Kampaņas, kurai vajag noņemt izsūtīšanas laiku kaut kad nākotnē, ID
72
- * @return boolean true ja ir veiksmīgi
73
- */
74
- function campaignUnschedule($cid) {
75
- $params = array();
76
- $params["cid"] = $cid;
77
- return $this->callServer("campaignUnschedule", $params);
78
- }
79
-
80
- /**
81
- * Iestādam laiku, kad izsūtīt kampaņu
82
- *
83
- * @example mgapi_campaignSchedule.php
84
- * @example xml-rpc_campaignSchedule.php
85
- *
86
- * @param string $cid Kampaņas, kurai vajag iestādīt izsūtīšanas laiku, ID
87
- * @param string $schedule_time Laiks, kad izsūtīt. Laiku jānorāda šādā formātā YYYY-MM-DD HH:II:SS pēc <strong>GMT</strong>
88
- * @return boolean true ja ir veiksmīgi
89
- */
90
- function campaignSchedule($cid, $schedule_time) {
91
- $params = array();
92
- $params["cid"] = $cid;
93
- $params["schedule_time"] = $schedule_time;
94
- return $this->callServer("campaignSchedule", $params);
95
- }
96
-
97
- /**
98
- * Atjaunojam auto atbildētāja izsūtīšanu
99
- *
100
- * @example mgapi_campaignResume.php
101
- * @example xml-rpc_campaignResume.php
102
- *
103
- * @param string $cid Kampaņas, kuru vajag atsākt, ID
104
- * @return boolean true ja ir veiksmīgi
105
- */
106
- function campaignResume($cid) {
107
- $params = array();
108
- $params["cid"] = $cid;
109
- return $this->callServer("campaignResume", $params);
110
- }
111
-
112
- /**
113
- * Apstādinam uz laiku autoatbildētāju
114
- *
115
- * @example mgapi_campaignPause.php
116
- * @example xml-rpc_campaignPause.php
117
- *
118
- * @param string $cid Kampaņas, kuru vajag apstādināt, ID
119
- * @return boolean true ja ir veiksmīgi
120
- */
121
- function campaignPause($cid) {
122
- $params = array();
123
- $params["cid"] = $cid;
124
- return $this->callServer("campaignPause", $params);
125
- }
126
-
127
- /**
128
- * Nosūtīt kampaņu nekavējoties
129
- *
130
- * @example mgapi_campaignSendNow.php
131
- * @example xml-rpc_campaignSendNow.php
132
- *
133
- * @param string $cid Kampaņas, kuru vajag nosūtīt, ID
134
- * @return boolean true ja ir veiksmīgi
135
- */
136
- function campaignSendNow($cid) {
137
- $params = array();
138
- $params["cid"] = $cid;
139
- return $this->callServer("campaignSendNow", $params);
140
- }
141
-
142
- /**
143
- * Nosūtam testa vēstuli uz norādītajiem epastiem
144
- *
145
- * @example mgapi_campaignSendTest.php
146
- * @example xml-rpc_campaignSendTest.php
147
- *
148
- * @param string $cid Kampaņas, kur vēlamies notestēt, ID
149
- * @param array $test_emails Masīvs, kas satur epastus, uz kuriem nosūtīt vēstuli
150
- * @param string $send_type Nav obligāts. Ja vēlaties nosūtīt abus formātus, norādiet "html", ja tikai teksta, tad "plain"
151
- * @return boolean true ja veiksmīgi
152
- */
153
- function campaignSendTest($cid, $test_emails = array(), $send_type = NULL) {
154
- $params = array();
155
- $params["cid"] = $cid;
156
- $params["test_emails"] = $test_emails;
157
- $params["send_type"] = $send_type;
158
- return $this->callServer("campaignSendTest", $params);
159
- }
160
-
161
- /**
162
- * Atrodam visus lietotāja šablonus
163
- *
164
- * @example mgapi_campaignTemplates.php
165
- * @example xml-rpc_campaignTemplates.php
166
- *
167
- * @return array Masīvs, kas satur šablonus
168
- * @returnf integer id Šablona ID
169
- * @returnf string name Šablona nosaukums
170
- * @returnf string layout Šablona izkārtojums - "basic", "left_column", "right_column" vai "postcard"
171
- * @returnf string preview_image URL adrese līdz priekšskatījuma attēlam
172
- * @returnf array source Šablona HTML kods
173
- */
174
- function campaignTemplates() {
175
- $params = array();
176
- return $this->callServer("campaignTemplates", $params);
177
- }
178
-
179
- /**
180
- * Izveidojam jaunu kampaņu
181
- *
182
- * @example mgapi_campaignCreate.php
183
- * @example xml-rpc_campaignCreate.php
184
- *
185
- * @param string $type Kampaņas veids: "html", "plain", "auto"
186
- * @param array $options Masīvs ar kampaņas parametriem
187
- string/array list_id Saraksta id, to var atrast r lists()
188
- string subject Vēstules virsraksts
189
- string from_email Epasts, uz kuru varēs nosūtīt atbildes epastu
190
- string from_name Vārds, kas parādīsies pie nosūtītāja
191
- string to_email Merge vērtība, kas parādīsies pie To: lauka (tas nav epasts)
192
- array tracking Nav obligāts. Statistikas parametru masīvs, tiek izmantotas šādas atslēgas: "opens", "html_clicks" un "text_clicks". Pēc noklusējuma tiek skaitīta atvēršana un HTML klikšķi
193
- string title Nav obligāts. Kampaņas nosaukums. Pēc noklusējuma tiek izmantots vēstules virsraksts
194
- array analytics Nav obligāts. Masīvs ar skaitītāju informāciju. Google gadījumā ir šāds pielietojums "google"=>"jūsu_google_analytics_atslēga". "jūsu_google_analytics_atslēga" tiks pievienota visiem linkiem, statistiku varēs apskatīties klienta Google Analytics kontā
195
- boolean generate_text Nav obligāts. Ja nav norādīts plain teksts, tiks ģenerēts tekst no HTML. Pēc noklusējuma ir false
196
- boolean auto_footer Nav obligāts. Iekļaut vai neiekļaut automātisko kājeni vēstules saturā. Šis ir pieejams lietotājie ar Pro paku. Pēc noklusējuma ir false
197
- boolean authenticate Nav obligāts. Ieslēgt epastu autentifikāciju. Šis strādās, ja ir pievienoti un aktivizēti autentificēti domēni sistēmā. Pēc noklusējuma ir false
198
- string sender Nav obligāts. Epasta adrese. Tiek izmantots, lai norādītu citu sūtītāja informāciju. Ir pieejams lietotājiem ar Pro paku.
199
- integer/array segment_id Nav obligāts. Satur segmenta ID, kuriem izsūtīt kampaņu
200
- boolean inline_img Nav obligāts. Izmantot vai nē inline bildes. Šis ir pieejams ar atbilstošu addonu. Pēc noklusējuma ir false
201
- string ln Nav obligāts. Nosaka, kādā valodā būs kājene un galvene. Iespējamās vērtības: cn, dk, en, ee, fi, fr, de, it, jp, lv, lt, no, pl, pt, ru, es, se
202
-
203
- * @param array $content Masīvs, kas satur vēstules saturu. Struktūra:
204
- "html" HTML saturs
205
- "plain" saturs plain vēstulei
206
- "url" Adrese, no kuras importēt HTML tekstu. Ja netiek norādīts plain teksts, tad vajag ieslēgt generate_text, lai tiktu ģenerēts plain teksta vēstules saturs. Ja tiek norādīta šī vērtība, tad tiek pārrakstītas augstāk minētās vērtības
207
- "archive" Ar Base64 kodēts arhīva fails. Ja tiek norādīta šī vērtība, tad tiek pārrakstītas augstāk minētās vērtības
208
- "archive_type" Nav obligāts. Pieļaujamie arhīva formāti: zip, tar.gz, tar.bz2, tar, tgz, tbz . Ja nav norādīts, tad pēc noklusējuma tiks izmantots zip
209
- integer template_id Nav obligāts. Lietotāja šablona id, nu kura tiks ģenerēts HTML saturs
210
-
211
- * @param array $type_opts Nav obligāts -
212
-
213
- Autoatbildētāja kampaņa, šis masīvs satur šādu informāciju:
214
- string offset-units Kāda vērtība no "day", "week", "month", "year". Obligāti jānorāda
215
- string offset-time Vērtība, kas ir lielāka par 0. Obligāti jānorāda
216
- string offset-dir Viena vērtība no "before" vai "after". Pēc noklusējuma "after"
217
- string event Nav obligāts. Izsūtīt pēc "signup" (parakstīšanās, pēc noklusējuma), "date" (datuma) vai "annual" (ikgadējs)
218
- string event-datemerge Nav obligāts. Merge lauks, kurš tiek ņemts vērā, kad izsūtīt. Šis ir nepieciešams, ja event ir norādīt "date" vai "annual"
219
-
220
- *
221
- * @return string Atgriež jaunās kampaņas ID
222
- */
223
- function campaignCreate($type, $options, $content, $type_opts = NULL) {
224
- $params = array();
225
- $params["type"] = $type;
226
- $params["options"] = $options;
227
- $params["content"] = $content;
228
- $params["type_opts"] = $type_opts;
229
- return $this->callServer("campaignCreate", $params);
230
- }
231
-
232
- /**
233
- * Atjaunojam kampaņas, kura vēl nav nosūtīta, parametrus
234
- *
235
- *
236
- * Uzmanību:<br/><ul>
237
- * <li>Ja Jūs izmantojat list_id, visi iepriekšējie saraksti tiks izdzēsti.</li>
238
- * <li>Ja Jūs izmantojat template_id, tiks pārrakstīts HTML saturs ar šablona saturu</li>
239
- *
240
- * @example mgapi_campaignUpdate.php
241
- * @example xml-rpc_campaignUpdate.php
242
- *
243
- * @param string $cid Kampaņas, kuru vajag labot, ID
244
- * @param string $name Parametra nosaukums (skatīties pie campaignCreate() options lauku ). Iespējamie parametri: subject, from_email, utt. Papildus parametri ir content. Gadījumā, ja vajag mainīt "type_opts", kā "name" vajag norādīt, piemēram, "auto".
245
- * @param mixed $value Iespējamās vērtības parametram ( skatīties campaignCreate() options lauku )
246
- * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
247
- */
248
- function campaignUpdate($cid, $name, $value) {
249
- $params = array();
250
- $params["cid"] = $cid;
251
- $params["name"] = $name;
252
- $params["value"] = $value;
253
- return $this->callServer("campaignUpdate", $params);
254
- }
255
-
256
- /**
257
- * Kopējam kampaņu
258
- *
259
- * @example mgapi_campaignReplicate.php
260
- * @example xml-rpc_campaignReplicate.php
261
- *
262
- * @param string $cid Kampaņas, kuru vajag kopēt, ID
263
- * @return string Atgriežam jaunās kampaņas ID
264
- */
265
- function campaignReplicate($cid) {
266
- $params = array();
267
- $params["cid"] = $cid;
268
- return $this->callServer("campaignReplicate", $params);
269
- }
270
-
271
- /**
272
- * Tiek dzēsta neatgriezensiki kampaņa. Esiet uzmanīgi!
273
- *
274
- * @example mgapi_campaignDelete.php
275
- * @example xml-rpc_campaignDelete.php
276
- *
277
- * @param string $cid Kampaņas, kuru vajag dzēst, ID
278
- * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
279
- */
280
- function campaignDelete($cid) {
281
- $params = array();
282
- $params["cid"] = $cid;
283
- return $this->callServer("campaignDelete", $params);
284
- }
285
-
286
- /**
287
- * Atgriežam kampaņu sarakstu. Var pielietot filtru, lai detalizēt atlasītu
288
- *
289
- * @example mgapi_campaigns.php
290
- * @example xml-rpc_campaigns.php
291
- *
292
- * @param array $filters Nav obligāts. Masīvs ar parametriem:
293
- string campaign_id Nav obligāts, kampaņas id
294
- string list_id Nav obligāts, saraksta id. To var atrast ar lists()
295
- string status Nav obligāts. Var atrast kampaņu pēc statusa: sent, draft, paused, sending
296
- string type Nav obligāts. Kampaņas tips: plain, html
297
- string from_name Nav obligāts. Atlasa kampānu pēc nosūtītāja vārda
298
- string from_email Nav obligāts. Atlasa kampaņas pēc "Reply-to" epasta
299
- string title Nav obligāts. Atlasa pēc kampaņas nosaukuma
300
- string subject Nav obligāts. Atlasa pēc vēstules virsraksta ("Subject")
301
- string sendtime_start Nav obligāts. Atlasa vēstules, kas izsūtītas pēc šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
302
- string sendtime_end Nav obligāts. Atlasa vēstules, kas izsūtītas pirms šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
303
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
304
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 1000
305
- * @return array Agriež masīvu ar kampaņu sarakstu
306
- * @returnf string id Kampaņas id. To izmanto pārējām funkcijām
307
- * @returnf integer web_id Kampaņas id, kas tiek izmanots web versijā
308
- * @returnf string title Kampaņas virsraksts
309
- * @returnf string type Kampaņas tips (html,plain,auto)
310
- * @returnf date create_time Kampaņas izveidošanas datums
311
- * @returnf date send_time Kampānas nosūtīšanas datums
312
- * @returnf integer emails_sent Epastu skaits, uz kuriem nosūtīta kampaņa
313
- * @returnf string status Kampaņas statuss (sent, draft, paused, sending)
314
- * @returnf string from_name Vārds, kas parādās From laukā
315
- * @returnf string from_email E-pasts, uz kuru saņēmējs var nosūtīt atbildi
316
- * @returnf string subject Vēstules virsraksts
317
- * @returnf boolean to_email Personalizēt "To:" lauku
318
- * @returnf string archive_url Arhīva saite uz kampaņu
319
- * @returnf boolean analytics Integrēt vai neitegrēt Google Analytics
320
- * @returnf string analytcs_tag Google Analytics nosaukums kampaņai
321
- * @returnf boolean track_clicks_text Skaitīt vai neskaitīt klikšķus plain vēstulē
322
- * @returnf boolean track_clicks_html Skaitīt vai neskaitīt klikšķus HTML vēstulē
323
- * @returnf boolean track_opens Skaitīt vai neskaitīt atvēršanu
324
- */
325
- function campaigns($filters = array(), $start = 0, $limit = 25) {
326
- $params = array();
327
- $params["filters"] = $filters;
328
- $params["start"] = $start;
329
- $params["limit"] = $limit;
330
- return $this->callServer("campaigns", $params);
331
- }
332
-
333
- /**
334
- * Given a list and a campaign, get all the relevant campaign statistics (opens, bounces, clicks, etc.)
335
- *
336
- * @example mgapi_campaignStats.php
337
- * @example xml-rpc_campaignStats.php
338
- *
339
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
340
- * @return array Masīvs, kas satur kampaņas statistiku
341
- * @returnf integer hard_bounces Nepiegādāto/nepareizo epastu skaits
342
- * @returnf integer soft_bounces Pagaidu nepiegādāto
343
- * @returnf integer blocked_bounces Bloķēto skaits
344
- * @returnf integer temporary_bounces Īslaicīgi atgriezto skaits
345
- * @returnf integer generic_bounces Nepareizo epastu skaits
346
- * @returnf integer unsubscribes Epastu skaits, kas atrakstījās no kampaņas
347
- * @returnf integer forwards Skaits, cik reizes vēstule ir pārsūtīta
348
- * @returnf integer opens Skaits, cik reizes atvērts
349
- * @returnf date last_open Datums, kad pēdējo reizi atvērts
350
- * @returnf integer unique_opens Unikālo atvēršanu skait
351
- * @returnf integer clicks Skaits, cik daudz ir spiests uz linkiem
352
- * @returnf integer unique_clicks Unikālie klikšķi uz saitēm
353
- * @returnf date last_click Datums, kad pēdējo reizi spiests uz linkiem
354
- * @returnf integer users_who_clicked Lietotāju skaits, kas spieduši uz saitēm
355
- * @returnf integer emails_sent Kopējais skaits, cik vēstules ir izsūtītas
356
- */
357
- function campaignStats($cid) {
358
- $params = array();
359
- $params["cid"] = $cid;
360
- return $this->callServer("campaignStats", $params);
361
- }
362
-
363
- /**
364
- * Atrodam kampaņas visus linkus
365
- *
366
- * @example mgapi_campaignClickStats.php
367
- * @example xml-rpc_campaignClickStats.php
368
- *
369
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
370
- * @return struct urls Saišu masīvs, kur atslēga ir saite
371
- * @returnf integer clicks Kopējais klikšķu skaits
372
- * @returnf integer unique Unikālo klikšķu skaits
373
- */
374
- function campaignClickStats($cid) {
375
- $params = array();
376
- $params["cid"] = $cid;
377
- return $this->callServer("campaignClickStats", $params);
378
- }
379
-
380
- /**
381
- * Atrodam šīs kampaņas epastu domēnu statistiku
382
- *
383
- * @example mgapi_campaignEmailDomainPerformance.php
384
- * @example xml-rpc_campaignEmailDomainPerformance.php
385
- *
386
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
387
- * @return array Masīvs ar epasta domēniem
388
- * @returnf string domain Domēna vārds
389
- * @returnf integer total_sent Kopā nosūtīto epastu skaits kampaņai (visi epasti)
390
- * @returnf integer emails Uz šo domēnu nosūtīto epstu skaits
391
- * @returnf integer bounces Neaizgājušo epastu skaits
392
- * @returnf integer opens Unikālo atvēršanu skaits
393
- * @returnf integer clicks Unikālo klikšķu skaits
394
- * @returnf integer unsubs Skaits, cik atrakstījušies
395
- * @returnf integer delivered Piegādāto vēstuļu skaits
396
- * @returnf integer emails_pct Skaits, cik epastu procentuāli ir ar šo domēnu
397
- * @returnf integer bounces_pct Skaits, cik procentuāli no kopēja skaita nav piegādāts ar šo domēnu
398
- * @returnf integer opens_pct Skaits, cik procentuāli ir atvērts ar šo domēnu
399
- * @returnf integer clicks_pct Skaits, cik procentuāli no šī domēna ir spieduši
400
- * @returnf integer unsubs_pct Procentuāli, cik daudz no šī domēna ir atrakstījušies
401
- */
402
- function campaignEmailDomainPerformance($cid) {
403
- $params = array();
404
- $params["cid"] = $cid;
405
- return $this->callServer("campaignEmailDomainPerformance", $params);
406
- }
407
-
408
- /**
409
- * Atrodam neeksistējošos/nepareizos epastus (hard bounces)
410
- *
411
- * @example mgapi_campaignHardBounces.php
412
- * @example xml-rpc_campaignHardBounces.php
413
- *
414
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
415
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
416
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
417
- * @return array Epastu saraksts
418
- */
419
- function campaignHardBounces($cid, $start = 0, $limit = 1000) {
420
- $params = array();
421
- $params["cid"] = $cid;
422
- $params["start"] = $start;
423
- $params["limit"] = $limit;
424
- return $this->callServer("campaignHardBounces", $params);
425
- }
426
-
427
- /**
428
- * Atrodam pagaidu atgrieztos epastus (soft bounces)
429
- *
430
- * @example mgapi_campaignSoftBounces.php
431
- * @example xml-rpc_campaignSoftBounces.php
432
- *
433
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
434
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
435
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
436
- * @return array Epastu saraksts
437
- */
438
- function campaignSoftBounces($cid, $start = 0, $limit = 1000) {
439
- $params = array();
440
- $params["cid"] = $cid;
441
- $params["start"] = $start;
442
- $params["limit"] = $limit;
443
- return $this->callServer("campaignSoftBounces", $params);
444
- }
445
-
446
- /**
447
- * Atrodam atgrieztos epastus (blocked bounces)
448
- *
449
- * @example mgapi_campaignBlockedBounces.php
450
- * @example xml-rpc_campaignBlockedBounces.php
451
- *
452
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
453
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
454
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
455
- * @return array Epastu saraksts
456
- */
457
- function campaignBlockedBounces($cid, $start = 0, $limit = 1000) {
458
- $params = array();
459
- $params["cid"] = $cid;
460
- $params["start"] = $start;
461
- $params["limit"] = $limit;
462
- return $this->callServer("campaignBlockedBounces", $params);
463
- }
464
-
465
- /**
466
- * Atrodam atgrieztos epastus (temporary bounces)
467
- *
468
- * @example mgapi_campaignTemporaryBounces.php
469
- * @example xml-rpc_campaignTemporaryBounces.php
470
- *
471
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
472
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
473
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
474
- * @return array Epastu saraksts
475
- */
476
- function campaignTemporaryBounces($cid, $start = 0, $limit = 1000) {
477
- $params = array();
478
- $params["cid"] = $cid;
479
- $params["start"] = $start;
480
- $params["limit"] = $limit;
481
- return $this->callServer("campaignTemporaryBounces", $params);
482
- }
483
-
484
- /**
485
- * Atrodam atgrieztos epastus (generic bounces)
486
- *
487
- * @example mgapi_campaignGenericBounces.php
488
- * @example xml-rpc_campaignGenericBounces.php
489
- *
490
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
491
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
492
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
493
- * @return array Epastu saraksts
494
- */
495
- function campaignGenericBounces($cid, $start = 0, $limit = 1000) {
496
- $params = array();
497
- $params["cid"] = $cid;
498
- $params["start"] = $start;
499
- $params["limit"] = $limit;
500
- return $this->callServer("campaignGenericBounces", $params);
501
- }
502
-
503
- /**
504
- * Atrodam visus e-pastus, kas ir atrakstījušies no šīs kampaņas
505
- *
506
- * @example mgapi_campaignUnsubscribes.php
507
- * @example xml-rpc_campaignUnsubscribes.php
508
- *
509
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
510
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
511
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
512
- * @return array Epastu saraksts
513
- */
514
- function campaignUnsubscribes($cid, $start = 0, $limit = 1000) {
515
- $params = array();
516
- $params["cid"] = $cid;
517
- $params["start"] = $start;
518
- $params["limit"] = $limit;
519
- return $this->callServer("campaignUnsubscribes", $params);
520
- }
521
-
522
- /**
523
- * Atgriež valstu sarakstu, no kurām ir atvērtas vēstules un cik daudz
524
- *
525
- * @example mgapi_campaignGeoOpens.php
526
- * @example xml-rpc_campaignGeoOpens.php
527
- *
528
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
529
- * @return array countries Masīvs ar valstu sarakstu
530
- * @returnf string code Valsts kods ISO3166 formātā, satur 2 simbolus
531
- * @returnf string name Valsts nosaukums
532
- * @returnf int opens Skaits, cik daudz atvērts
533
- */
534
- function campaignGeoOpens($cid) {
535
- $params = array();
536
- $params["cid"] = $cid;
537
- return $this->callServer("campaignGeoOpens", $params);
538
- }
539
-
540
- /**
541
- * Atrodam pārsūtīšanas statistiku
542
- *
543
- * @example mgapi_campaignForwardStats.php
544
- * @example xml-rpc_campaignForwardStats.php
545
- *
546
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
547
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
548
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
549
- * @return array Epastu saraksts
550
- */
551
- function campaignForwardStats($cid, $start = 0, $limit = 1000) {
552
- $params = array();
553
- $params["cid"] = $cid;
554
- $params["start"] = $start;
555
- $params["limit"] = $limit;
556
- return $this->callServer("campaignForwardStats", $params);
557
- }
558
-
559
- /**
560
- * Atgriež kampaņas atmesto vēstuļu tekstus, kuras nav vecākas par 30 dienām
561
- *
562
- * @example mgapi_campaignBounceMessages.php
563
- * @example xml-rpc_campaignBounceMessages.php
564
- *
565
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
566
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
567
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
568
- * @return array bounces Masīvs, kas satur atsviesto epastu saturu
569
- * @returnf string date Laiks, kad vēstule saņemta
570
- * @returnf string email Epasta arese, uz kuru neizdevās nosūtīt
571
- * @returnf string message Atsviestēs vēstules saturs
572
- */
573
- function campaignBounceMessages($cid, $start = 0, $limit = 25) {
574
- $params = array();
575
- $params["cid"] = $cid;
576
- $params["start"] = $start;
577
- $params["limit"] = $limit;
578
- return $this->callServer("campaignBounceMessages", $params);
579
- }
580
-
581
- /**
582
- * Atgriež epastu sarakstu, kas atvēruši kampaņu
583
- *
584
- * @example mgapi_campaignOpened.php
585
- *
586
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
587
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
588
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
589
- * @return struct Masīvs, kas satur datus
590
- * @returnf integer total Kopējais skaits
591
- * @returnf array data Saraksts ar datiem
592
- struct data
593
- string email Epasta adrese
594
- integer count Cik reizes atvēra
595
- */
596
- function campaignOpened($cid, $start = 0, $limit = 25) {
597
- $params = array();
598
- $params["cid"] = $cid;
599
- $params["start"] = $start;
600
- $params["limit"] = $limit;
601
- return $this->callServer("campaignOpened", $params);
602
- }
603
-
604
- /**
605
- * Atgriež epastu sarakstu, kas nav atvēruši kampaņu
606
- *
607
- * @example mgapi_campaignNotOpened.php
608
- *
609
- * @param string $cid Kampaņas id. To var atrast ar campaigns()
610
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
611
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
612
- * @return struct Masīvs, kas satur datus
613
- * @returnf integer total Kopējais skaits
614
- * @returnf array data Epastu saraksts
615
- string email Epasta adrese
616
- */
617
- function campaignNotOpened($cid, $start = 0, $limit = 25) {
618
- $params = array();
619
- $params["cid"] = $cid;
620
- $params["start"] = $start;
621
- $params["limit"] = $limit;
622
- return $this->callServer("campaignNotOpened", $params);
623
- }
624
-
625
- /**
626
- * Izveidojam jaunu sarakstu
627
- *
628
- * @example mgapi_listCreate.php
629
- * @example xml-rpc_listCreate.php
630
- *
631
- * @param string $title Saraksta nosaukums
632
- * @param array $options Masīvs ar kampaņas parametriem
633
- string permission_reminder Atgādinājums lietotājiem, kā tie nokļuva sarakstā
634
- string notify_to Epasta adrese, uz kuru sūtīt paziņojumus
635
- bool subscription_notify Sūtīt paziņojumus par to, ka ir jauns lietotājs pierakstījies
636
- bool unsubscription_notify Sūtīt paziņojumus par to, ka ir jauns lietotājs atrakstījies
637
- bool has_email_type_option Ļaut izvēlēties epasta formātu
638
-
639
- *
640
- * @return string Atgriež jaunā saraksta ID
641
- */
642
- function listCreate($title, $options = NULL) {
643
- $params = array();
644
- $params["title"] = $title;
645
- $params["options"] = $options;
646
- return $this->callServer("listCreate", $params);
647
- }
648
-
649
- /**
650
- * Atjaunojam saraksta parametrus
651
- *
652
- * @example mgapi_listUpdate.php
653
- * @example xml-rpc_listUpdate.php
654
- *
655
- * @param string $id Saraksta, kuru vajag labot, ID
656
- * @param string $name Parametra nosaukums (skatīties pie listCreate() options lauku ). Iespējamie parametri: title, permission_reminder, notify_to, utt.
657
- * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
658
- */
659
- function listUpdate($id, $name, $value) {
660
- $params = array();
661
- $params["id"] = $id;
662
- $params["name"] = $name;
663
- $params["value"] = $value;
664
- return $this->callServer("listUpdate", $params);
665
- }
666
-
667
- /**
668
- * Tiek dzēsts neatgriezensiki saraksts. Esiet uzmanīgi!
669
- *
670
- * @example mgapi_listDelete.php
671
- * @example xml-rpc_listDelete.php
672
- *
673
- * @param string $id Saraksta, kuru vajag labot, ID
674
- * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
675
- */
676
- function listDelete($id) {
677
- $params = array();
678
- $params["id"] = $id;
679
- return $this->callServer("listDelete", $params);
680
- }
681
-
682
- /**
683
- * Atrodam visus sarakstus
684
- *
685
- * @example mgapi_lists.php
686
- * @example xml-rpc_lists.php
687
- *
688
- * @return array Masīvs ar sarakstiem
689
- * @returnf string id Saraksta id. Šī vērtība tiek izmantota cītās funkcijās, kas strādā ar sarakstiem.
690
- * @returnf integer web_id Saraksta id, kas tiek izmantots web administrācijas lapā
691
- * @returnf string name Saraksta nosaukums
692
- * @returnf date date_created Saraksta izveidošanas datums.
693
- * @returnf integer member_count Lietotāju skaits sarakstā
694
- * @returnf integer unsubscribe_count Lietotāju skaits, cik atrakstījušies no saraksta
695
- * @returnf string default_from_name Noklusējuma vērtība From Name priekš kampaņām, kas izmanto šo sarakstu
696
- * @returnf string default_from_email Noklusējuma vērtība From Email priekš kampaņām, kas izmanto šo sarakstu
697
- * @returnf string default_subject Noklusējuma vērtība Subject priekš kampaņām, kas izmanto šo sarakstu
698
- * @returnf string default_language Noklusēja valoda saraksta formām
699
- */
700
- function lists($start = 0, $limit = 1000) {
701
- $params = array();
702
- $params["start"] = $start;
703
- $params["limit"] = $limit;
704
- return $this->callServer("lists", $params);
705
- }
706
-
707
- /**
708
- * Atrodam merge tagus sarakstam
709
- *
710
- * @example mgapi_listMergeVarUpdate.php
711
- * @example xml-rpc_listMergeVars.php
712
- *
713
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
714
- * @return array Merge tagu saraksts
715
- * @returnf string name Merge taga nosaukums
716
- * @returnf bool req Vai šis lauks ir obligāti aizpildāms (true) vai nē (false)
717
- * @returnf string field_type Merge tada datu tips. Ir pieļaujamas šādas vērtības: email, text, number, date, address, phone, website, image
718
- * @returnf bool show Norāda, vai rādīt šo lauku lietotāju sarakstā.
719
- * @returnf string order Kārtas numurs
720
- * @returnf string default Vērtība pēc noklusējuma
721
- * @returnf string tag Merge tags, kas tiek izmantots formās, listSubscribe() un listUpdateMember()
722
- */
723
- function listMergeVars($id) {
724
- $params = array();
725
- $params["id"] = $id;
726
- return $this->callServer("listMergeVars", $params);
727
- }
728
-
729
- /**
730
- * Pievienojam jaunu merge tagu sarakstam
731
- *
732
- * @example mgapi_listMergeVarUpdate.php
733
- * @example xml-rpc_listMergeVarAdd.php
734
- *
735
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
736
- * @param string $tag Merge tags, kuru vajag pievienot, piemēram, FNAME
737
- * @param string $name Garāks nosaukum, kas tiks rādīts lietotājiem
738
- * @param array $options Nav obligāts. Dažādi parametri merge tagam.
739
- string field_type Nav obligāts. Kāda vērtība no: text, number, date, address, phone, website, image. Pēc noklusējuma ir text
740
- boolean req Nav obligāts. Norāda, vai lauks ir obligāti aizpildāms. Pēc noklusējuma, false
741
- boolean show Nav obligāts. Norāda, vai rādīt šo lauku lietotāju sarakstā. Pēc noklusējuma, true
742
- string default_value Nav obligāts. Vērtība pēc noklusējuma
743
-
744
- * @return boolean true ja ir izdevies, false ja nav izdevies
745
- */
746
- function listMergeVarAdd($id, $tag, $name, $options = array()) {
747
- $params = array();
748
- $params["id"] = $id;
749
- $params["tag"] = $tag;
750
- $params["name"] = $name;
751
- $params["options"] = $options;
752
- return $this->callServer("listMergeVarAdd", $params);
753
- }
754
-
755
- /**
756
- * Atjaunojam merge taga parametrus sarakstā. Merge taga tipu nevar nomainīt
757
- *
758
- * @example mgapi_listMergeVarUpdate.php
759
- * @example xml-rpc_listMergeVarUpdate.php
760
- *
761
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
762
- * @param string $tag Merge tags, kuru vajag atjaunot
763
- * @param array $options Parametri merge taga atjaunošanai. Pareizus parametrus skatīties pie metodes listMergeVarAdd()
764
- * @return boolean true ja ir izdevies, false ja nav izdevies
765
- */
766
- function listMergeVarUpdate($id, $tag, $options) {
767
- $params = array();
768
- $params["id"] = $id;
769
- $params["tag"] = $tag;
770
- $params["options"] = $options;
771
- return $this->callServer("listMergeVarUpdate", $params);
772
- }
773
-
774
- /**
775
- * Tiek izdzēsts merge tags no saraksta un vērtība visiem saraksta lietotājiem. Dati tie izdzēsti neatgriezeniski
776
- *
777
- * @example mgapi_listMergeVarDel.php
778
- * @example xml-rpc_listMergeVarDel.php
779
- *
780
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
781
- * @param string $tag Merge tags, kuru vajag izdzēst
782
- * @return boolean true ja ir izdevies, false ja nav izdevies
783
- */
784
- function listMergeVarDel($id, $tag) {
785
- $params = array();
786
- $params["id"] = $id;
787
- $params["tag"] = $tag;
788
- return $this->callServer("listMergeVarDel", $params);
789
- }
790
-
791
- /**
792
- * Pievienojam sarakstam jaunu lietotaju
793
- *
794
- * @example mgapi_listSubscribe.php
795
- * @example xml-rpc_listSubscribe.php
796
- *
797
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
798
- * @param string $email_address Epasta adrese, ko japievieno sarakstam
799
- * @param array $merge_vars Masivs, kas satur MERGE lauku vertibas (FNAME, LNAME, etc.) Maksimalais izmers 255
800
- * @param string $email_type Nav obligats. Epasta tips: html vai plain. Pec noklusejuma html
801
- * @param boolean $double_optin Vai sutit apstiprinajuma vestuli. Pec noklusejuma true
802
- * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
803
- * @param boolean $send_welcome - Nav obligats. Sutit vai nesutit paldies vestuli. Pec noklusejuma false
804
-
805
- * @return boolean true ja ir izdevies, false ja nav izdevies
806
- */
807
- function listSubscribe($id, $email_address, $merge_vars, $email_type = 'html', $double_optin = true, $update_existing = false, $send_welcome = false) {
808
- $params = array();
809
- $params["id"] = $id;
810
- $params["email_address"] = $email_address;
811
- $params["merge_vars"] = $merge_vars;
812
- $params["email_type"] = $email_type;
813
- $params["double_optin"] = $double_optin;
814
- $params["update_existing"] = $update_existing;
815
- $params["send_welcome"] = $send_welcome;
816
- return $this->callServer("listSubscribe", $params);
817
- }
818
-
819
- /**
820
- * Pievienojam sarakstam jaunu lietotaju
821
- *
822
- * @example mgapi_listSubscribe.php
823
- * @example xml-rpc_listSubscribe.php
824
- *
825
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
826
- * @param string $phone Tālrunis, ko japievieno sarakstam
827
- * @param array $merge_vars Masivs, kas satur MERGE lauku vertibas (FNAME, LNAME, etc.) Maksimalais izmers 255
828
- * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
829
-
830
- * @return boolean true ja ir izdevies, false ja nav izdevies
831
- */
832
- function listSubscribeSMS($id, $phone, $merge_vars, $update_existing = false) {
833
- $params = array();
834
- $params["id"] = $id;
835
- $params["phone"] = $phone;
836
- $params["merge_vars"] = $merge_vars;
837
- $params["update_existing"] = $update_existing;
838
- return $this->callServer("listSubscribeSMS", $params);
839
- }
840
-
841
- /**
842
- * Iznemam no saraksta epasta adresi
843
- *
844
- * @example mgapi_listUnsubscribe.php
845
- * @example xml-rpc_listUnsubscribe.php
846
- *
847
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
848
- * @param string $email_address Epasta adrese vai "id", ko var atrast ar "listMemberInfo" metodi
849
- * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
850
- * @param boolean $send_goodbye Nosutit vai nesutit pazinojumu epasta lietotajam. Pec noklusejuma true
851
- * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
852
- * @return boolean true ja ir izdevies, false ja nav izdevies
853
- */
854
- function listUnsubscribe($id, $email_address, $delete_member = false, $send_goodbye = true, $send_notify = true) {
855
- $params = array();
856
- $params["id"] = $id;
857
- $params["email_address"] = $email_address;
858
- $params["delete_member"] = $delete_member;
859
- $params["send_goodbye"] = $send_goodbye;
860
- $params["send_notify"] = $send_notify;
861
- return $this->callServer("listUnsubscribe", $params);
862
- }
863
-
864
- /**
865
- * Iznemam no saraksta epasta adresi
866
- *
867
- * @example mgapi_listUnsubscribe.php
868
- * @example xml-rpc_listUnsubscribe.php
869
- *
870
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
871
- * @param string $phone Phone vai "id", ko var atrast ar "listMemberInfo" metodi
872
- * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
873
- * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
874
- * @return boolean true ja ir izdevies, false ja nav izdevies
875
- */
876
- function listUnsubscribeSMS($id, $phone, $delete_member = false, $send_notify = true) {
877
- $params = array();
878
- $params["id"] = $id;
879
- $params["phone"] = $phone;
880
- $params["delete_member"] = $delete_member;
881
- $params["send_notify"] = $send_notify;
882
- return $this->callServer("listUnsubscribeSMS", $params);
883
- }
884
-
885
- /**
886
- * Labo epasta adresi, MERGE laukus saraksta lietotajam
887
- *
888
- * @example mgapi_listUpdateMember.php
889
- * @example xml-rpc_listUpdateMember.php
890
- *
891
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
892
- * @param string $email_address Epasta adrese vai "id", ko var atrast ar "listMemberInfo" metodi
893
- * @param array $merge_vars Masivs ar MERGE laukiem. MERGE laukus var apskatities pie metodes "listSubscribe"
894
- * @param string $email_type Epasta tips: "html" vai "plain". Nav obligats
895
- * @return boolean true ja ir izdevies, false ja nav izdevies
896
- */
897
- function listUpdateMember($id, $email_address, $merge_vars, $email_type = '') {
898
- $params = array();
899
- $params["id"] = $id;
900
- $params["email_address"] = $email_address;
901
- $params["merge_vars"] = $merge_vars;
902
- $params["email_type"] = $email_type;
903
- return $this->callServer("listUpdateMember", $params);
904
- }
905
-
906
- /**
907
- * Pievienojam sarakstam vairakus epastus
908
- *
909
- * @example mgapi_listBatchSubscribe.php
910
- * @example xml-rpc_listBatchSubscribe.php
911
- *
912
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
913
- * @param array $batch Masivs, kas satur epastu datus. Epasta dati ir masivs ar šada atslegam: "EMAIL" epasta adresei, "EMAIL_TYPE" epasta tips (html vai plain)
914
- * @param boolean $double_optin Vai sutit apstiprinajuma vestuli. Pec noklusejuma true
915
- * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
916
- * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
917
- * @returnf integer success_count Skaits, cik izdevas
918
- * @returnf integer error_count Skaits, cik neizdevas
919
- * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "email"
920
- */
921
- function listBatchSubscribe($id, $batch, $double_optin = true, $update_existing = false) {
922
- $params = array();
923
- $params["id"] = $id;
924
- $params["batch"] = $batch;
925
- $params["double_optin"] = $double_optin;
926
- $params["update_existing"] = $update_existing;
927
- return $this->callServer("listBatchSubscribe", $params);
928
- }
929
-
930
- /**
931
- * Pievienojam sarakstam vairakus epastus
932
- *
933
- * @example mgapi_listBatchSubscribe.php
934
- * @example xml-rpc_listBatchSubscribe.php
935
- *
936
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
937
- * @param array $batch Masivs, kas satur epastu datus. Epasta dati ir masivs ar šada atslegam: "SMS" epasta adresei
938
- * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
939
- * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
940
- * @returnf integer success_count Skaits, cik izdevas
941
- * @returnf integer error_count Skaits, cik neizdevas
942
- * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "phone"
943
- */
944
- function listBatchSubscribeSMS($id, $batch, $update_existing = false) {
945
- $params = array();
946
- $params["id"] = $id;
947
- $params["batch"] = $batch;
948
- $params["double_optin"] = $double_optin;
949
- $params["update_existing"] = $update_existing;
950
- return $this->callServer("listBatchSubscribeSMS", $params);
951
- }
952
-
953
- /**
954
- * Iznemam no saraksta vairakus epastus
955
- *
956
- * @example mgapi_listBatchUnsubscribe.php
957
- * @example xml-rpc_listBatchUnsubscribe.php
958
- *
959
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
960
- * @param array $emails Epastu masivs
961
- * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
962
- * @param boolean $send_goodbye Nosutit vai nesutit pazinojumu epasta lietotajam. Pec noklusejuma true
963
- * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
964
- * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
965
- * @returnf integer success_count Skaits, cik izdevas
966
- * @returnf integer error_count Skaits, cik neizdevas
967
- * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "email"
968
- */
969
- function listBatchUnsubscribe($id, $emails, $delete_member = false, $send_goodbye = true, $send_notify = false) {
970
- $params = array();
971
- $params["id"] = $id;
972
- $params["emails"] = $emails;
973
- $params["delete_member"] = $delete_member;
974
- $params["send_goodbye"] = $send_goodbye;
975
- $params["send_notify"] = $send_notify;
976
- return $this->callServer("listBatchUnsubscribe", $params);
977
- }
978
-
979
- /**
980
- * Iznemam no saraksta vairakus epastus
981
- *
982
- * @example mgapi_listBatchUnsubscribe.php
983
- * @example xml-rpc_listBatchUnsubscribe.php
984
- *
985
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
986
- * @param array $phones Tālruņu masivs
987
- * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
988
- * @param boolean $send_goodbye Nosutit vai nesutit pazinojumu epasta lietotajam. Pec noklusejuma true
989
- * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
990
- * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
991
- * @returnf integer success_count Skaits, cik izdevas
992
- * @returnf integer error_count Skaits, cik neizdevas
993
- * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "email"
994
- */
995
- function listBatchUnsubscribeSMS($id, $phones, $delete_member = false, $send_notify = false) {
996
- $params = array();
997
- $params["id"] = $id;
998
- $params["phones"] = $phones;
999
- $params["delete_member"] = $delete_member;
1000
- $params["send_notify"] = $send_notify;
1001
- return $this->callServer("listBatchUnsubscribeSMS", $params);
1002
- }
1003
-
1004
- /**
1005
- * Atrodam epasta info sarkaksta
1006
- *
1007
- * @example mgapi_listMembers.php
1008
- * @example xml-rpc_listMembers.php
1009
- *
1010
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
1011
- * @param string $status Epasta statuss (subscribed, unsubscribed, inactive, bounced), pec noklusejuma subscribed
1012
- * @param integer $start Nav obligats. Nepieciešams lielam sarakstam. Lapas numurs, no kuras sakt. Pirmajai lapai atbilst numurs 0
1013
- * @param integer $limit Nav obligats. Nepieciešams lielam sarakstam. Skaits, cik daudz atgriezt epastus. Pec noklusejuma 100, maksimalais ir 15000
1014
- * @return array Masivs ar lietotaju sarakstu
1015
- * @returnf string email Lietotaja epasts
1016
- * @returnf date timestamp Peivienošanas datums
1017
- */
1018
- function listMembers($id, $status = 'subscribed', $start = 0, $limit = 100) {
1019
- $params = array();
1020
- $params["id"] = $id;
1021
- $params["status"] = $status;
1022
- $params["start"] = $start;
1023
- $params["limit"] = $limit;
1024
- return $this->callServer("listMembers", $params);
1025
- }
1026
-
1027
- /**
1028
- * Atrodam epasta info sarkaksta
1029
- *
1030
- * @example mgapi_listMemberInfo.php
1031
- * @example xml-rpc_listMemberInfo.php
1032
- *
1033
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
1034
- * @param string $email_address Epasta adrese vai epasta ID saraksta
1035
- * @return array Masivs, kas satur epasta informaciju
1036
- * @returnf string id Unikals epasta id
1037
- * @returnf string email Epasta adrese
1038
- * @returnf string email_type Epasta tips: html vai plain
1039
- * @returnf array merges Masivs ar papildus laukiem
1040
- * @returnf string status Epasta status: inactive, subscribed, unsubscribed, bounced
1041
- * @returnf string ip_opt IP adrese, no kuras tika apstiprinats epasts
1042
- * @returnf string ip_signup IP adrese, no kuras tika aizpildita forma
1043
- * @returnf date timestamp Laiks, kad tika pievienots sarakstam
1044
- */
1045
- function listMemberInfo($id, $email_address) {
1046
- $params = array();
1047
- $params["id"] = $id;
1048
- $params["email_address"] = $email_address;
1049
- return $this->callServer("listMemberInfo", $params);
1050
- }
1051
-
1052
- /**
1053
- * Saraksta pieauguma informacija pa menešiem
1054
- *
1055
- * @example mgapi_listGrowthHistory.php
1056
- * @example xml-rpc_listGrowthHistory.php
1057
- *
1058
- * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
1059
- * @return array Masivs pa menešiem
1060
- * @returnf string month Gads un menesis YYYY-MM formata
1061
- * @returnf integer existing Skaits, cik bija lietotaju meneša sakuma
1062
- * @returnf integer imports Skaits, cik daudz tekošaja menesi tika pievienoti lietotaji
1063
- */
1064
- function listGrowthHistory($id) {
1065
- $params = array();
1066
- $params["id"] = $id;
1067
- return $this->callServer("listGrowthHistory", $params);
1068
- }
1069
-
1070
- /**
1071
- * Atrodam visus saraksta segmentus
1072
- *
1073
- * @example mgapi_listSegments.php
1074
- * @example xml-rpc_listSegments.php
1075
- *
1076
- * @return array Masīvs ar saraksta segmentiem
1077
- * @returnf string id Saraksta segmenta id.
1078
- * @returnf integer web_id Saraksta segmenta id, kas tiek izmantots web administrācijas lapā
1079
- * @returnf string name Saraksta segmenta nosaukums
1080
- * @returnf date date_created Saraksta izveidošanas datums.
1081
- * @returnf integer member_count Lietotāju skaits sarakstā
1082
- */
1083
- function listSegments($id) {
1084
- $params = array();
1085
- $params["id"] = $id;
1086
- return $this->callServer("listSegments", $params);
1087
- }
1088
-
1089
- /**
1090
- * Izveidojam jaunu segmentu
1091
- *
1092
- * @example mgapi_listSegmentCreate.php
1093
- *
1094
- * @param string $list Saraksta ID
1095
- * @param string $title Segmenta nosaukums
1096
- * @param string $match Sakritības tips
1097
- * @param array $filter Masīvs ar nosacījumu masīviem
1098
- string field Merge lauks
1099
- string condition Nosacījumi: is, not, isany, contains, notcontain, starts, ends, greater, less
1100
- string value Vērtība, priekš condition
1101
-
1102
- *
1103
- * @return string Atgriež jaunā segmenta ID
1104
- */
1105
- function listSegmentCreate($list, $title, $match, $filter) {
1106
- $params = array();
1107
- $params["list"] = $list;
1108
- $params["title"] = $title;
1109
- $params["match"] = $match;
1110
- $params["filter"] = $filter;
1111
- return $this->callServer("listSegmentCreate", $params);
1112
- }
1113
-
1114
- /**
1115
- * Atjaunojam segmenta parametrus
1116
- *
1117
- * @example mgapi_listSegmentUpdate.php
1118
- *
1119
- * @param string $sid Segmenta, kuru vajag labot, ID
1120
- * @param string $name Parametra nosaukums (skatīties pie listSegmentCreate() options lauku ). Iespējamie parametri: title, match, filter
1121
- * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1122
- */
1123
- function listSegmentUpdate($sid, $name, $value) {
1124
- $params = array();
1125
- $params["sid"] = $sid;
1126
- $params["name"] = $name;
1127
- $params["value"] = $value;
1128
- return $this->callServer("listSegmentUpdate", $params);
1129
- }
1130
-
1131
- /**
1132
- * Tiek dzēsts neatgriezensiki segments. Esiet uzmanīgi!
1133
- *
1134
- * @example mgapi_listSegmentDelete.php
1135
- *
1136
- * @param string $sid Segmenta, kuru vajag dzēst, ID
1137
- * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1138
- */
1139
- function listSegmentDelete($sid) {
1140
- $params = array();
1141
- $params["sid"] = $sid;
1142
- return $this->callServer("listSegmentDelete", $params);
1143
- }
1144
-
1145
- /**
1146
- * Noņemam nost statusu, kas lika SMS kampaņu izsūtīt kaut kad nākotnē
1147
- *
1148
- * @example mgapi_smsCampaignUnschedule.php
1149
- *
1150
- * @param string $cid SMS kampaņa, kurai vajag noņemt izsūtīšanas laiku kaut kad nākotnē, ID
1151
- * @return boolean true ja ir veiksmīgi
1152
- */
1153
- function smsCampaignUnschedule($cid) {
1154
- $params = array();
1155
- $params["cid"] = $cid;
1156
- return $this->callServer("smsCampaignUnschedule", $params);
1157
- }
1158
-
1159
- /**
1160
- * Iestādam laiku, kad izsūtīt SMS kampaņu
1161
- *
1162
- * @example mgapi_smsCampaignSchedule.php
1163
- *
1164
- * @param string $cid SMS kampaņa, kurai vajag iestādīt izsūtīšanas laiku, ID
1165
- * @param string $schedule_time Laiks, kad izsūtīt. Laiku jānorāda šādā formātā YYYY-MM-DD HH:II:SS pēc <strong>GMT</strong>
1166
- * @return boolean true ja ir veiksmīgi
1167
- */
1168
- function smsCampaignSchedule($cid, $schedule_time) {
1169
- $params = array();
1170
- $params["cid"] = $cid;
1171
- $params["schedule_time"] = $schedule_time;
1172
- return $this->callServer("smsCampaignSchedule", $params);
1173
- }
1174
-
1175
- /**
1176
- * Nosūtīt SMS kampaņu nekavējoties
1177
- *
1178
- * @example mgapi_smsCampaignSendNow.php
1179
- *
1180
- * @param string $cid SMS kampaņa, kuru vajag nosūtīt, ID
1181
- * @return boolean true ja ir veiksmīgi
1182
- */
1183
- function smsCampaignSendNow($cid) {
1184
- $params = array();
1185
- $params["cid"] = $cid;
1186
- return $this->callServer("smsCampaignSendNow", $params);
1187
- }
1188
-
1189
- /**
1190
- * Atrodam visus lietotāja SMS šablonus
1191
- *
1192
- * @example mgapi_smsCampaignTemplates.php
1193
- *
1194
- * @return array Masīvs, kas satur SMS šablonus
1195
- * @returnf integer id Šablona ID
1196
- * @returnf string source Šablona teksts
1197
- */
1198
- function smsCampaignTemplates() {
1199
- $params = array();
1200
- return $this->callServer("smsCampaignTemplates", $params);
1201
- }
1202
-
1203
- /**
1204
- * Izveidojam jaunu SMS kampaņu
1205
- *
1206
- * @example mgapi_smsCampaignCreate.php
1207
- *
1208
- * @param array $options Masīvs ar SMS kampaņas parametriem
1209
- string sender Vārds, no kā tiks nosūtīta SMS. To nepieciešams piereģistrēt ar funkciju smsSenderIdRegister()
1210
- struct recipients
1211
- string list_id Saraksta id, to var atrast ar lists()
1212
- integer segment_id Nav obligāts. Segmenta ID, to var atrast ar segments()
1213
- string merge SMS lauka nosaukums, piemēram, MERGE10, SMS
1214
- array tracking Nav obligāts. Statistikas parametru masīvs, tiek izmantotas šādas atslēgas: "clicks".
1215
- string title Nav obligāts. Kampaņas nosaukums.
1216
- array analytics Nav obligāts. Masīvs ar skaitītāju informāciju. Google gadījumā ir šāds pielietojums "google"=>"jūsu_google_analytics_atslēga". "jūsu_google_analytics_atslēga" tiks pievienota visiem linkiem, statistiku varēs apskatīties klienta Google Analytics kontā
1217
- boolean unicode Nav obligāts. Nosaka, vai izsūtīt kampaņu unikodā. Lai speciālie simboli un burit rādītos SMS kampaņa, šim ir jābūt true. Pēc noklusējuma ir false
1218
- boolean concatenate Nav obligāts. Nosaka, vai izsūtīt vairākas īsziņas, ja teksts ir par garu. Pēc noklusējuma ir false
1219
-
1220
- * @param array $content Masīvs, kas satur vēstules saturu. Struktūra:
1221
- text saturs Nav obligāts, ja ir norādīts template_id. SMS kampaņas saturs
1222
- integer template_id Nav obligāts. Lietotāja SMS šablona id, nu kura tiks paņemts SMS saturs. Var atrast ar smsCampaignTemplates()
1223
-
1224
- *
1225
- * @return string Atgriež jaunās SMS kampaņas ID
1226
- */
1227
- function smsCampaignCreate($options, $content) {
1228
- $params = array();
1229
- $params["options"] = $options;
1230
- $params["content"] = $content;
1231
- return $this->callServer("smsCampaignCreate", $params);
1232
- }
1233
-
1234
- /**
1235
- * Atjaunojam kampaņas, kura vēl nav nosūtīta, parametrus
1236
- *
1237
- *
1238
- * Uzmanību:<br/><ul>
1239
- * <li>Ja Jūs izmantojat list_id, visi iepriekšējie saraksti tiks izdzēsti.</li>
1240
- * <li>Ja Jūs izmantojat template_id, tiks pārrakstīts saturs ar šablona saturu</li>
1241
- *
1242
- * @example mgapi_smsCampaignUpdate.php
1243
- *
1244
- * @param string $cid Kampaņas, kuru vajag labot, ID
1245
- * @param string $name Parametra nosaukums (skatīties pie smsCampaignCreate() options lauku ). Iespējamie parametri: sender, recipients, utt. Papildus parametri ir content.
1246
- * @param mixed $value Iespējamās vērtības parametram ( skatīties campaignCreate() options lauku )
1247
- * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1248
- */
1249
- function smsCampaignUpdate($cid, $name, $value) {
1250
- $params = array();
1251
- $params["cid"] = $cid;
1252
- $params["name"] = $name;
1253
- $params["value"] = $value;
1254
- return $this->callServer("smsCampaignUpdate", $params);
1255
- }
1256
-
1257
- /**
1258
- * Kopējam kampaņu
1259
- *
1260
- * @example mgapi_smsCampaignReplicate.php
1261
- *
1262
- * @param string $cid SMS kampaņa, kuru vajag kopēt, ID
1263
- * @return string Atgriežam jaunās SMS kampaņas ID
1264
- */
1265
- function smsCampaignReplicate($cid) {
1266
- $params = array();
1267
- $params["cid"] = $cid;
1268
- return $this->callServer("smsCampaignReplicate", $params);
1269
- }
1270
-
1271
- /**
1272
- * Tiek dzēsta neatgriezensiki SMS kampaņa. Esiet uzmanīgi!
1273
- *
1274
- * @example mgapi_smsCampaignDelete.php
1275
- *
1276
- * @param string $cid SMS kampaņa, kuru vajag dzēst, ID
1277
- * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1278
- */
1279
- function smsCampaignDelete($cid) {
1280
- $params = array();
1281
- $params["cid"] = $cid;
1282
- return $this->callServer("smsCampaignDelete", $params);
1283
- }
1284
-
1285
- /**
1286
- * Atgriežam SMS kampaņu sarakstu. Var pielietot filtru, lai detalizēt atlasītu
1287
- *
1288
- * @example mgapi_smsCampaigns.php
1289
- *
1290
- * @param array $filters Nav obligāts. Masīvs ar parametriem:
1291
- string campaign_id Nav obligāts, kampaņas id
1292
- string recipients Nav obligāts, saraksta id. To var atrast ar lists()
1293
- string status Nav obligāts. Var atrast kampaņu pēc statusa: sent, draft, sending
1294
- string sender Nav obligāts. Atlasa kampānu pēc sūtītāja vārda
1295
- string title Nav obligāts. Atlasa pēc kampaņas nosaukuma
1296
- string sendtime_start Nav obligāts. Atlasa vēstules, kas izsūtītas pēc šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
1297
- string sendtime_end Nav obligāts. Atlasa vēstules, kas izsūtītas pirms šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
1298
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
1299
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 1000
1300
- * @return array Agriež masīvu ar SMS kampaņu sarakstu
1301
- * @returnf string id SMS kampaņas id. To izmanto pārējām funkcijām
1302
- * @returnf integer web_id SMS kampaņas id, kas tiek izmanots web versijā
1303
- * @returnf string title SMS kampaņas virsraksts
1304
- * @returnf date create_time SMS kampaņas izveidošanas datums
1305
- * @returnf date send_time SMS kampānas nosūtīšanas datums
1306
- * @returnf integer sms_sent Nosūtīto SMS skaits
1307
- * @returnf string status Kampaņas statuss (sent, draft, paused, sending)
1308
- * @returnf string sender SMS sūtītāja vārds
1309
- * @returnf boolean analytics Integrēt vai neitegrēt Google Analytics
1310
- * @returnf string analytcs_tag Google Analytics nosaukums kampaņai
1311
- * @returnf boolean track_clicks Skaitīt vai neskaitīt klikšķus
1312
- * @returnf boolean unicode Izmantot vai neizmantot unikodu
1313
- * @returnf boolean concatenate Sadalīt vai nesadalīt vairākās īsziņās garāku īsziņu
1314
- */
1315
- function smsCampaigns($filters = array(), $start = 0, $limit = 25) {
1316
- $params = array();
1317
- $params["filters"] = $filters;
1318
- $params["start"] = $start;
1319
- $params["limit"] = $limit;
1320
- return $this->callServer("smsCampaigns", $params);
1321
- }
1322
-
1323
- /**
1324
- * Atgriež SMS kampaņas statistiku
1325
- *
1326
- * @example mgapi_smsCampaignStats.php
1327
- *
1328
- * @param string $cid SMS kampaņas id. To var atrast ar smsCampaigns()
1329
- * @return array Masīvs, kas satur SMS kampaņas statistiku
1330
- * @returnf integer delivered Piegādāto SMS skaits
1331
- * @returnf integer sent Nosūtīto SMS skaits. Vēl nav saņemts gala apstiprinājums par veiksmi vai neveiksmi
1332
- * @returnf integer queued SMS skats, kas stāv vēl izsūtīšanas rindā
1333
- * @returnf integer undelivered Nepiegādāto SMS skaits
1334
- * @returnf integer error Nepiegādāto SMS skaits, kuriem ir bijusi kāda tehniska kļūda piegādes procesā
1335
- * @returnf integer other SMS ar citu piegādes statusu
1336
- * @returnf integer clicks Skaits, cik daudz ir spiests uz linkiem
1337
- * @returnf integer unique_clicks Unikālie klikšķi uz saitēm
1338
- * @returnf date last_click Datums, kad pēdējo reizi spiests uz linkiem
1339
- * @returnf integer users_who_clicked Lietotāju skaits, kas spieduši uz saitēm
1340
- * @returnf integer sms_sent Kopējais skaits, cik vēstules ir izsūtītas
1341
- */
1342
- function smsCampaignStats($cid) {
1343
- $params = array();
1344
- $params["cid"] = $cid;
1345
- return $this->callServer("smsCampaignStats", $params);
1346
- }
1347
-
1348
- /**
1349
- * Atrodam SMS kampaņas visus linkus
1350
- *
1351
- * @example mgapi_smsCampaignClickStats.php
1352
- *
1353
- * @param string $cid SMS kampaņas id. To var atrast ar smsCampaigns()
1354
- * @return struct urls Saišu masīvs, kur atslēga ir saite
1355
- * @returnf integer clicks Kopējais klikšķu skaits
1356
- * @returnf integer unique Unikālo klikšķu skaits
1357
- */
1358
- function smsCampaignClickStats($cid) {
1359
- $params = array();
1360
- $params["cid"] = $cid;
1361
- return $this->callServer("smsCampaignClickStats", $params);
1362
- }
1363
-
1364
- /**
1365
- * Atgriež SMS kampaņas nepiegādāto īsziņu statusus
1366
- *
1367
- * @example mgapi_smsCampaignBounces.php
1368
- *
1369
- * @param string $cid SMS kampaņas id. To var atrast ar smsCampaigns()
1370
- * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
1371
- * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
1372
- * @return array bounces Masīvs, kas satur nepiegādātās SMS
1373
- * @returnf string phone Tālruņa numurs, uz kuru neizdevās nosūtīt
1374
- * @returnf string reason Iemesls, kāpēc netika piegādāts
1375
- */
1376
- function smsCampaignBounces($cid, $start = 0, $limit = 25) {
1377
- $params = array();
1378
- $params["cid"] = $cid;
1379
- $params["start"] = $start;
1380
- $params["limit"] = $limit;
1381
- return $this->callServer("smsCampaignBounces", $params);
1382
- }
1383
-
1384
- /**
1385
- * Nosūtam pieprasījumu reģistrēt SMS sūtītāja vārdu
1386
- *
1387
- * @example mgapi_smsSenderIdRegister.php
1388
- *
1389
- * @param string $sender Vēlamais SMS sūtītāja vārds
1390
- * @param string $phone Rezerves mobilā tālr. numurs
1391
- * @param string $company Uzņēmuma nosaukums
1392
- * @param string $fullname Kontaktpersonas vārds, uzvārds
1393
- * @param string $companyposition Pozīcija uzņēmumā
1394
- * @param string $comments Papildus komentāri
1395
- * @returnf boolean Vai ir pieņemts izskatīšanai
1396
- */
1397
- function smsSenderIdRegister($sender, $phone, $company, $fullname, $companyposition, $comments = '') {
1398
- $params = array();
1399
- $params["sender"] = $sender;
1400
- $params["phone"] = $phone;
1401
- $params["company"] = $company;
1402
- $params["fullname"] = $fullname;
1403
- $params["companyposition"] = $companyposition;
1404
- $params["comments"] = $comments;
1405
- return $this->callServer("smsSenderIdRegister", $params);
1406
- }
1407
-
1408
- /**
1409
- * Atgriež dažādu informaciju par lietotaju kontu
1410
- *
1411
- * @example mgapi_getAccountDetails.php
1412
- * @example xml-rpc_getAccountDetails.php
1413
- *
1414
- * @return array Masivs, kas satur da˛adu informaciju par šis API atlsegas lietotaja kontu
1415
- * @returnf string user_id Lietotaja unikalais ID, tas tiek izmantots buvejot da˛adas saites
1416
- * @returnf string username Lietotaja lietotajvards
1417
- * @returnf bool is_trial Vai lietotajs ir trial
1418
- * @returnf int emails_left Skaits, cik daudz epastus var nosutit
1419
- * @returnf datetime first_payment Pirma maksajuma datums
1420
- * @returnf datetime last_payment Pedeja maksajuma datums
1421
- * @returnf int times_logged_in Skaits, cik daudz reizes lietotajs caur web ir ielogojies
1422
- * @returnf datetime last_login Datums, kad pedejo reizi bija ielogojies caur web
1423
- * @returnf array contact Masivs, kas satur kontkatinformaciju: Vards, uzvards, epasts, uznemuma nosaukums, adrese, majas lapas adrese, telefons, fakss
1424
- * @returnf array orders Masivs, kas satur informaciju par samaksatajiem rekiniem: rekina numurs, plans, cena, valuta, izrakstišanas datums, pakas deriguma terminš
1425
- */
1426
- function getAccountDetails() {
1427
- $params = array();
1428
- return $this->callServer("getAccountDetails", $params);
1429
- }
1430
-
1431
- /**
1432
- * Atrodam visu sarakstu ID, kuros ir ššis epasts
1433
- *
1434
- * @example mgapi_listsForEmail.php
1435
- * @example xml-rpc_listsForEmail.php
1436
- *
1437
- * @param string $email_address epasta adrese
1438
- * @return array an array Masivs, kas satur sarakstu ID
1439
- */
1440
- function listsForEmail($email_address) {
1441
- $params = array();
1442
- $params["email_address"] = $email_address;
1443
- return $this->callServer("listsForEmail", $params);
1444
- }
1445
-
1446
- /**
1447
- * Atrodam visas API atslegas
1448
- *
1449
- * @example mgapi_apikeys.php
1450
- * @example xml-rpc_apikeys.php
1451
- *
1452
- * @param string $username lietotaja vards
1453
- * @param string $password lietotaja parole
1454
- * @param boolean $expired nav obligats - radit vai neradit atslegas, kuras vairs nav derigas. Pec noklusejuma ir false
1455
- * @return array API atslegu masivs, kas satur:
1456
- * @returnf string apikey Šo atslegu var izmantot, lai pieslegtos API
1457
- * @returnf string created_at Datums, kad atslega ir izveidota
1458
- * @returnf string expired_at Datums, kad ta tika atzimeta, ka neaktiva
1459
- */
1460
- function apikeys($username, $password, $expired = false) {
1461
- $params = array();
1462
- $params["username"] = $username;
1463
- $params["password"] = $password;
1464
- $params["expired"] = $expired;
1465
- return $this->callServer("apikeys", $params);
1466
- }
1467
-
1468
- /**
1469
- * Izveidojam jaunu API atslegu
1470
- *
1471
- * @example mgapi_apikeyAdd.php
1472
- * @example xml-rpc_apikeyAdd.php
1473
- *
1474
- * @param string $username lietotaja vards
1475
- * @param string $password lietotaja parole
1476
- * @return string atgrie˛ jaunu API atslegu
1477
- */
1478
- function apikeyAdd($username, $password) {
1479
- $params = array();
1480
- $params["username"] = $username;
1481
- $params["password"] = $password;
1482
- return $this->callServer("apikeyAdd", $params);
1483
- }
1484
-
1485
- /**
1486
- * Atzimejam ka neaktivu API atslegu
1487
- *
1488
- * @example mgapi_apikeyExpire.php
1489
- * @example xml-rpc_apikeyExpire.php
1490
- *
1491
- * @param string $username lietotaja vards
1492
- * @param string $password lietotaja parole
1493
- * @return boolean true, ja izdevas nomainit statusu
1494
- */
1495
- function apikeyExpire($username, $password) {
1496
- $params = array();
1497
- $params["username"] = $username;
1498
- $params["password"] = $password;
1499
- return $this->callServer("apikeyExpire", $params);
1500
- }
1501
-
1502
- /**
1503
- * Atrodam API atslegu
1504
- *
1505
- * @example mgapi_login.php
1506
- * @example xml-rpc_login.php
1507
- *
1508
- * @param string $username lietotaja vards
1509
- * @param string $password lietotaja parole
1510
- * @return string tiek atgriezta API atslega, ja tadas vel nav, tad tiek izveidota
1511
- */
1512
- function login($username, $password) {
1513
- $params = array();
1514
- $params["username"] = $username;
1515
- $params["password"] = $password;
1516
- return $this->callServer("login", $params);
1517
- }
1518
-
1519
- /**
1520
- * "ping" - vienkarš veids, ka parbaudit, vai viss ir kartiba. Ja ir kadas problemas, tiks atgriezts par to pazinojums.
1521
- *
1522
- * @example mgapi_ping.php
1523
- * @example xml-rpc_ping.php
1524
- *
1525
- * @return string tiek atgriezts teksts "Everything's Ok!", ja viss ir kartiba, ja nav, tad atgrie˛ kludas pazinojumu
1526
- */
1527
- function ping() {
1528
- $params = array();
1529
- return $this->callServer("ping", $params);
1530
- }
1531
-
1532
- /**
1533
- * Piesledzas pie servera uz izsauc nepieciešamo metodi un atgrie˛ rezultatu
1534
- * Šo funkciju nav nepieciešams izsaukt manuali
1535
- */
1536
- function callServer($method, $params) {
1537
- $host = $this->apiUrl["host"];
1538
- $params["apikey"] = $this->api_key;
1539
-
1540
- $this->errorMessage = "";
1541
- $this->errorCode = "";
1542
- $post_vars = $this->httpBuildQuery($params);
1543
-
1544
- $payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
1545
- $payload .= "Host: " . $host . "\r\n";
1546
- $payload .= "User-Agent: MGAPI/" . $this->version ."\r\n";
1547
- $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
1548
- $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
1549
- $payload .= "Connection: close \r\n\r\n";
1550
- $payload .= $post_vars;
1551
-
1552
- ob_start();
1553
- if ($this->secure){
1554
- $sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
1555
- } else {
1556
- $sock = fsockopen($host, 80, $errno, $errstr, 30);
1557
- }
1558
- if(!$sock) {
1559
- $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
1560
- $this->errorCode = "-99";
1561
- ob_end_clean();
1562
- return false;
1563
- }
1564
-
1565
- $response = "";
1566
- fwrite($sock, $payload);
1567
- stream_set_timeout($sock, $this->timeout);
1568
- $info = stream_get_meta_data($sock);
1569
- while ((!feof($sock)) && (!$info["timed_out"])) {
1570
- $response .= fread($sock, $this->chunkSize);
1571
- $info = stream_get_meta_data($sock);
1572
- }
1573
- if ($info["timed_out"]) {
1574
- $this->errorMessage = "Could not read response (timed out)";
1575
- $this->errorCode = -98;
1576
- }
1577
- fclose($sock);
1578
- ob_end_clean();
1579
- if ($info["timed_out"]) return false;
1580
-
1581
- list($throw, $response) = explode("\r\n\r\n", $response, 2);
1582
-
1583
- if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
1584
-
1585
- $serial = unserialize($response);
1586
- if($response && $serial === false) {
1587
- $response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
1588
- } else {
1589
- $response = $serial;
1590
- }
1591
- if(is_array($response) && isset($response["error"])) {
1592
- $this->errorMessage = $response["error"];
1593
- $this->errorCode = $response["code"];
1594
- return false;
1595
- }
1596
-
1597
- return $response;
1598
- }
1599
-
1600
- /**
1601
- * Definejam funkciju, kas aizstaj http_build_query sistemam, kuras tas nav
1602
- */
1603
- function httpBuildQuery($params, $key = NULL) {
1604
- if(!function_exists('http_build_query')) {
1605
- $ret = array();
1606
-
1607
- foreach((array) $params as $name => $val) {
1608
- $name = urlencode($name);
1609
- if($key !== null) {
1610
- $name = $key . "[" . $name . "]";
1611
- }
1612
-
1613
- if(is_array($val) || is_object($val)) {
1614
- $ret[] = $this->httpBuildQuery($val, $name);
1615
- } elseif($val !== null) {
1616
- $ret[] = $name . "=" . urlencode($val);
1617
- }
1618
- }
1619
-
1620
- return implode("&", $ret);
1621
- } else {
1622
- return http_build_query((array)$params, $key);
1623
- }
1624
- }
1625
- }
1626
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1627
  ?>
1
+ <?php
2
+
3
+ class MGAPI {
4
+ var $version = "1.5";
5
+ var $errorMessage;
6
+ var $errorCode;
7
+
8
+ /**
9
+ * API server adrese
10
+ */
11
+ var $apiUrl;
12
+
13
+ /**
14
+ * Default to a 300 second timeout on server calls
15
+ */
16
+ var $timeout = 300;
17
+
18
+ /**
19
+ * Default to a 8K chunk size
20
+ */
21
+ var $chunkSize = 8192;
22
+
23
+ /**
24
+ * Lietotaja API atslega
25
+ */
26
+ var $api_key;
27
+
28
+ /**
29
+ * Izmantot ssl: false - ne, true - ja
30
+ */
31
+ var $secure = false;
32
+
33
+ /**
34
+ * Pieslegties pie MailiGen API
35
+ *
36
+ * @param string $apikey Jusu MailiGen API atslega
37
+ * @param string $secure Izmantot vai neizmantot ssl pieslegšanos
38
+ */
39
+ function MGAPI($apikey, $secure = false) {
40
+ $this->secure = $secure;
41
+ $this->apiUrl = parse_url("http://api.mailigen.com/" . $this->version . "/?output=php");
42
+ if ( isset($GLOBALS["mg_api_key"]) && $GLOBALS["mg_api_key"]!="" ){
43
+ $this->api_key = $GLOBALS["mg_api_key"];
44
+ } else {
45
+ $this->api_key = $GLOBALS["mg_api_key"] = $apikey;
46
+ }
47
+ }
48
+ function setTimeout($seconds){
49
+ if (is_int($seconds)){
50
+ $this->timeout = $seconds;
51
+ return true;
52
+ }
53
+ }
54
+ function getTimeout(){
55
+ return $this->timeout;
56
+ }
57
+ function useSecure($val){
58
+ if ($val === true){
59
+ $this->secure = true;
60
+ } else {
61
+ $this->secure = false;
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Noņemam nost statusu, kas lika kampaņu izsūtīt kaut kad nākotnē
67
+ *
68
+ * @example mgapi_campaignUnschedule.php
69
+ * @example xml-rpc_campaignUnschedule.php
70
+ *
71
+ * @param string $cid Kampaņas, kurai vajag noņemt izsūtīšanas laiku kaut kad nākotnē, ID
72
+ * @return boolean true ja ir veiksmīgi
73
+ */
74
+ function campaignUnschedule($cid) {
75
+ $params = array();
76
+ $params["cid"] = $cid;
77
+ return $this->callServer("campaignUnschedule", $params);
78
+ }
79
+
80
+ /**
81
+ * Iestādam laiku, kad izsūtīt kampaņu
82
+ *
83
+ * @example mgapi_campaignSchedule.php
84
+ * @example xml-rpc_campaignSchedule.php
85
+ *
86
+ * @param string $cid Kampaņas, kurai vajag iestādīt izsūtīšanas laiku, ID
87
+ * @param string $schedule_time Laiks, kad izsūtīt. Laiku jānorāda šādā formātā YYYY-MM-DD HH:II:SS pēc <strong>GMT</strong>
88
+ * @return boolean true ja ir veiksmīgi
89
+ */
90
+ function campaignSchedule($cid, $schedule_time) {
91
+ $params = array();
92
+ $params["cid"] = $cid;
93
+ $params["schedule_time"] = $schedule_time;
94
+ return $this->callServer("campaignSchedule", $params);
95
+ }
96
+
97
+ /**
98
+ * Atjaunojam auto atbildētāja izsūtīšanu
99
+ *
100
+ * @example mgapi_campaignResume.php
101
+ * @example xml-rpc_campaignResume.php
102
+ *
103
+ * @param string $cid Kampaņas, kuru vajag atsākt, ID
104
+ * @return boolean true ja ir veiksmīgi
105
+ */
106
+ function campaignResume($cid) {
107
+ $params = array();
108
+ $params["cid"] = $cid;
109
+ return $this->callServer("campaignResume", $params);
110
+ }
111
+
112
+ /**
113
+ * Apstādinam uz laiku autoatbildētāju
114
+ *
115
+ * @example mgapi_campaignPause.php
116
+ * @example xml-rpc_campaignPause.php
117
+ *
118
+ * @param string $cid Kampaņas, kuru vajag apstādināt, ID
119
+ * @return boolean true ja ir veiksmīgi
120
+ */
121
+ function campaignPause($cid) {
122
+ $params = array();
123
+ $params["cid"] = $cid;
124
+ return $this->callServer("campaignPause", $params);
125
+ }
126
+
127
+ /**
128
+ * Nosūtīt kampaņu nekavējoties
129
+ *
130
+ * @example mgapi_campaignSendNow.php
131
+ * @example xml-rpc_campaignSendNow.php
132
+ *
133
+ * @param string $cid Kampaņas, kuru vajag nosūtīt, ID
134
+ * @return boolean true ja ir veiksmīgi
135
+ */
136
+ function campaignSendNow($cid) {
137
+ $params = array();
138
+ $params["cid"] = $cid;
139
+ return $this->callServer("campaignSendNow", $params);
140
+ }
141
+
142
+ /**
143
+ * Nosūtam testa vēstuli uz norādītajiem epastiem
144
+ *
145
+ * @example mgapi_campaignSendTest.php
146
+ * @example xml-rpc_campaignSendTest.php
147
+ *
148
+ * @param string $cid Kampaņas, kur vēlamies notestēt, ID
149
+ * @param array $test_emails Masīvs, kas satur epastus, uz kuriem nosūtīt vēstuli
150
+ * @param string $send_type Nav obligāts. Ja vēlaties nosūtīt abus formātus, norādiet "html", ja tikai teksta, tad "plain"
151
+ * @return boolean true ja veiksmīgi
152
+ */
153
+ function campaignSendTest($cid, $test_emails = array(), $send_type = NULL) {
154
+ $params = array();
155
+ $params["cid"] = $cid;
156
+ $params["test_emails"] = $test_emails;
157
+ $params["send_type"] = $send_type;
158
+ return $this->callServer("campaignSendTest", $params);
159
+ }
160
+
161
+ /**
162
+ * Atrodam visus lietotāja šablonus
163
+ *
164
+ * @example mgapi_campaignTemplates.php
165
+ * @example xml-rpc_campaignTemplates.php
166
+ *
167
+ * @return array Masīvs, kas satur šablonus
168
+ * @returnf integer id Šablona ID
169
+ * @returnf string name Šablona nosaukums
170
+ * @returnf string layout Šablona izkārtojums - "basic", "left_column", "right_column" vai "postcard"
171
+ * @returnf string preview_image URL adrese līdz priekšskatījuma attēlam
172
+ * @returnf array source Šablona HTML kods
173
+ */
174
+ function campaignTemplates() {
175
+ $params = array();
176
+ return $this->callServer("campaignTemplates", $params);
177
+ }
178
+
179
+ /**
180
+ * Izveidojam jaunu kampaņu
181
+ *
182
+ * @example mgapi_campaignCreate.php
183
+ * @example xml-rpc_campaignCreate.php
184
+ *
185
+ * @param string $type Kampaņas veids: "html", "plain", "auto"
186
+ * @param array $options Masīvs ar kampaņas parametriem
187
+ string/array list_id Saraksta id, to var atrast r lists()
188
+ string subject Vēstules virsraksts
189
+ string from_email Epasts, uz kuru varēs nosūtīt atbildes epastu
190
+ string from_name Vārds, kas parādīsies pie nosūtītāja
191
+ string to_email Merge vērtība, kas parādīsies pie To: lauka (tas nav epasts)
192
+ array tracking Nav obligāts. Statistikas parametru masīvs, tiek izmantotas šādas atslēgas: "opens", "html_clicks" un "text_clicks". Pēc noklusējuma tiek skaitīta atvēršana un HTML klikšķi
193
+ string title Nav obligāts. Kampaņas nosaukums. Pēc noklusējuma tiek izmantots vēstules virsraksts
194
+ array analytics Nav obligāts. Masīvs ar skaitītāju informāciju. Google gadījumā ir šāds pielietojums "google"=>"jūsu_google_analytics_atslēga". "jūsu_google_analytics_atslēga" tiks pievienota visiem linkiem, statistiku varēs apskatīties klienta Google Analytics kontā
195
+ boolean generate_text Nav obligāts. Ja nav norādīts plain teksts, tiks ģenerēts tekst no HTML. Pēc noklusējuma ir false
196
+ boolean auto_footer Nav obligāts. Iekļaut vai neiekļaut automātisko kājeni vēstules saturā. Šis ir pieejams lietotājie ar Pro paku. Pēc noklusējuma ir false
197
+ boolean authenticate Nav obligāts. Ieslēgt epastu autentifikāciju. Šis strādās, ja ir pievienoti un aktivizēti autentificēti domēni sistēmā. Pēc noklusējuma ir false
198
+ string sender Nav obligāts. Epasta adrese. Tiek izmantots, lai norādītu citu sūtītāja informāciju. Ir pieejams lietotājiem ar Pro paku.
199
+ integer/array segment_id Nav obligāts. Satur segmenta ID, kuriem izsūtīt kampaņu
200
+ boolean inline_img Nav obligāts. Izmantot vai nē inline bildes. Šis ir pieejams ar atbilstošu addonu. Pēc noklusējuma ir false
201
+ string ln Nav obligāts. Nosaka, kādā valodā būs kājene un galvene. Iespējamās vērtības: cn, dk, en, ee, fi, fr, de, it, jp, lv, lt, no, pl, pt, ru, es, se
202
+
203
+ * @param array $content Masīvs, kas satur vēstules saturu. Struktūra:
204
+ "html" HTML saturs
205
+ "plain" saturs plain vēstulei
206
+ "url" Adrese, no kuras importēt HTML tekstu. Ja netiek norādīts plain teksts, tad vajag ieslēgt generate_text, lai tiktu ģenerēts plain teksta vēstules saturs. Ja tiek norādīta šī vērtība, tad tiek pārrakstītas augstāk minētās vērtības
207
+ "archive" Ar Base64 kodēts arhīva fails. Ja tiek norādīta šī vērtība, tad tiek pārrakstītas augstāk minētās vērtības
208
+ "archive_type" Nav obligāts. Pieļaujamie arhīva formāti: zip, tar.gz, tar.bz2, tar, tgz, tbz . Ja nav norādīts, tad pēc noklusējuma tiks izmantots zip
209
+ integer template_id Nav obligāts. Lietotāja šablona id, nu kura tiks ģenerēts HTML saturs
210
+
211
+ * @param array $type_opts Nav obligāts -
212
+
213
+ Autoatbildētāja kampaņa, šis masīvs satur šādu informāciju:
214
+ string offset-units Kāda vērtība no "day", "week", "month", "year". Obligāti jānorāda
215
+ string offset-time Vērtība, kas ir lielāka par 0. Obligāti jānorāda
216
+ string offset-dir Viena vērtība no "before" vai "after". Pēc noklusējuma "after"
217
+ string event Nav obligāts. Izsūtīt pēc "signup" (parakstīšanās, pēc noklusējuma), "date" (datuma) vai "annual" (ikgadējs)
218
+ string event-datemerge Nav obligāts. Merge lauks, kurš tiek ņemts vērā, kad izsūtīt. Šis ir nepieciešams, ja event ir norādīt "date" vai "annual"
219
+
220
+ *
221
+ * @return string Atgriež jaunās kampaņas ID
222
+ */
223
+ function campaignCreate($type, $options, $content, $type_opts = NULL) {
224
+ $params = array();
225
+ $params["type"] = $type;
226
+ $params["options"] = $options;
227
+ $params["content"] = $content;
228
+ $params["type_opts"] = $type_opts;
229
+ return $this->callServer("campaignCreate", $params);
230
+ }
231
+
232
+ /**
233
+ * Atjaunojam kampaņas, kura vēl nav nosūtīta, parametrus
234
+ *
235
+ *
236
+ * Uzmanību:<br/><ul>
237
+ * <li>Ja Jūs izmantojat list_id, visi iepriekšējie saraksti tiks izdzēsti.</li>
238
+ * <li>Ja Jūs izmantojat template_id, tiks pārrakstīts HTML saturs ar šablona saturu</li>
239
+ *
240
+ * @example mgapi_campaignUpdate.php
241
+ * @example xml-rpc_campaignUpdate.php
242
+ *
243
+ * @param string $cid Kampaņas, kuru vajag labot, ID
244
+ * @param string $name Parametra nosaukums (skatīties pie campaignCreate() options lauku ). Iespējamie parametri: subject, from_email, utt. Papildus parametri ir content. Gadījumā, ja vajag mainīt "type_opts", kā "name" vajag norādīt, piemēram, "auto".
245
+ * @param mixed $value Iespējamās vērtības parametram ( skatīties campaignCreate() options lauku )
246
+ * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
247
+ */
248
+ function campaignUpdate($cid, $name, $value) {
249
+ $params = array();
250
+ $params["cid"] = $cid;
251
+ $params["name"] = $name;
252
+ $params["value"] = $value;
253
+ return $this->callServer("campaignUpdate", $params);
254
+ }
255
+
256
+ /**
257
+ * Kopējam kampaņu
258
+ *
259
+ * @example mgapi_campaignReplicate.php
260
+ * @example xml-rpc_campaignReplicate.php
261
+ *
262
+ * @param string $cid Kampaņas, kuru vajag kopēt, ID
263
+ * @return string Atgriežam jaunās kampaņas ID
264
+ */
265
+ function campaignReplicate($cid) {
266
+ $params = array();
267
+ $params["cid"] = $cid;
268
+ return $this->callServer("campaignReplicate", $params);
269
+ }
270
+
271
+ /**
272
+ * Tiek dzēsta neatgriezensiki kampaņa. Esiet uzmanīgi!
273
+ *
274
+ * @example mgapi_campaignDelete.php
275
+ * @example xml-rpc_campaignDelete.php
276
+ *
277
+ * @param string $cid Kampaņas, kuru vajag dzēst, ID
278
+ * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
279
+ */
280
+ function campaignDelete($cid) {
281
+ $params = array();
282
+ $params["cid"] = $cid;
283
+ return $this->callServer("campaignDelete", $params);
284
+ }
285
+
286
+ /**
287
+ * Atgriežam kampaņu sarakstu. Var pielietot filtru, lai detalizēt atlasītu
288
+ *
289
+ * @example mgapi_campaigns.php
290
+ * @example xml-rpc_campaigns.php
291
+ *
292
+ * @param array $filters Nav obligāts. Masīvs ar parametriem:
293
+ string campaign_id Nav obligāts, kampaņas id
294
+ string list_id Nav obligāts, saraksta id. To var atrast ar lists()
295
+ string status Nav obligāts. Var atrast kampaņu pēc statusa: sent, draft, paused, sending
296
+ string type Nav obligāts. Kampaņas tips: plain, html
297
+ string from_name Nav obligāts. Atlasa kampānu pēc nosūtītāja vārda
298
+ string from_email Nav obligāts. Atlasa kampaņas pēc "Reply-to" epasta
299
+ string title Nav obligāts. Atlasa pēc kampaņas nosaukuma
300
+ string subject Nav obligāts. Atlasa pēc vēstules virsraksta ("Subject")
301
+ string sendtime_start Nav obligāts. Atlasa vēstules, kas izsūtītas pēc šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
302
+ string sendtime_end Nav obligāts. Atlasa vēstules, kas izsūtītas pirms šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
303
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
304
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 1000
305
+ * @return array Agriež masīvu ar kampaņu sarakstu
306
+ * @returnf string id Kampaņas id. To izmanto pārējām funkcijām
307
+ * @returnf integer web_id Kampaņas id, kas tiek izmanots web versijā
308
+ * @returnf string title Kampaņas virsraksts
309
+ * @returnf string type Kampaņas tips (html,plain,auto)
310
+ * @returnf date create_time Kampaņas izveidošanas datums
311
+ * @returnf date send_time Kampānas nosūtīšanas datums
312
+ * @returnf integer emails_sent Epastu skaits, uz kuriem nosūtīta kampaņa
313
+ * @returnf string status Kampaņas statuss (sent, draft, paused, sending)
314
+ * @returnf string from_name Vārds, kas parādās From laukā
315
+ * @returnf string from_email E-pasts, uz kuru saņēmējs var nosūtīt atbildi
316
+ * @returnf string subject Vēstules virsraksts
317
+ * @returnf boolean to_email Personalizēt "To:" lauku
318
+ * @returnf string archive_url Arhīva saite uz kampaņu
319
+ * @returnf boolean analytics Integrēt vai neitegrēt Google Analytics
320
+ * @returnf string analytcs_tag Google Analytics nosaukums kampaņai
321
+ * @returnf boolean track_clicks_text Skaitīt vai neskaitīt klikšķus plain vēstulē
322
+ * @returnf boolean track_clicks_html Skaitīt vai neskaitīt klikšķus HTML vēstulē
323
+ * @returnf boolean track_opens Skaitīt vai neskaitīt atvēršanu
324
+ */
325
+ function campaigns($filters = array(), $start = 0, $limit = 25) {
326
+ $params = array();
327
+ $params["filters"] = $filters;
328
+ $params["start"] = $start;
329
+ $params["limit"] = $limit;
330
+ return $this->callServer("campaigns", $params);
331
+ }
332
+
333
+ /**
334
+ * Given a list and a campaign, get all the relevant campaign statistics (opens, bounces, clicks, etc.)
335
+ *
336
+ * @example mgapi_campaignStats.php
337
+ * @example xml-rpc_campaignStats.php
338
+ *
339
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
340
+ * @return array Masīvs, kas satur kampaņas statistiku
341
+ * @returnf integer hard_bounces Nepiegādāto/nepareizo epastu skaits
342
+ * @returnf integer soft_bounces Pagaidu nepiegādāto
343
+ * @returnf integer blocked_bounces Bloķēto skaits
344
+ * @returnf integer temporary_bounces Īslaicīgi atgriezto skaits
345
+ * @returnf integer generic_bounces Nepareizo epastu skaits
346
+ * @returnf integer unsubscribes Epastu skaits, kas atrakstījās no kampaņas
347
+ * @returnf integer forwards Skaits, cik reizes vēstule ir pārsūtīta
348
+ * @returnf integer opens Skaits, cik reizes atvērts
349
+ * @returnf date last_open Datums, kad pēdējo reizi atvērts
350
+ * @returnf integer unique_opens Unikālo atvēršanu skait
351
+ * @returnf integer clicks Skaits, cik daudz ir spiests uz linkiem
352
+ * @returnf integer unique_clicks Unikālie klikšķi uz saitēm
353
+ * @returnf date last_click Datums, kad pēdējo reizi spiests uz linkiem
354
+ * @returnf integer users_who_clicked Lietotāju skaits, kas spieduši uz saitēm
355
+ * @returnf integer emails_sent Kopējais skaits, cik vēstules ir izsūtītas
356
+ */
357
+ function campaignStats($cid) {
358
+ $params = array();
359
+ $params["cid"] = $cid;
360
+ return $this->callServer("campaignStats", $params);
361
+ }
362
+
363
+ /**
364
+ * Atrodam kampaņas visus linkus
365
+ *
366
+ * @example mgapi_campaignClickStats.php
367
+ * @example xml-rpc_campaignClickStats.php
368
+ *
369
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
370
+ * @return struct urls Saišu masīvs, kur atslēga ir saite
371
+ * @returnf integer clicks Kopējais klikšķu skaits
372
+ * @returnf integer unique Unikālo klikšķu skaits
373
+ */
374
+ function campaignClickStats($cid) {
375
+ $params = array();
376
+ $params["cid"] = $cid;
377
+ return $this->callServer("campaignClickStats", $params);
378
+ }
379
+
380
+ /**
381
+ * Atrodam šīs kampaņas epastu domēnu statistiku
382
+ *
383
+ * @example mgapi_campaignEmailDomainPerformance.php
384
+ * @example xml-rpc_campaignEmailDomainPerformance.php
385
+ *
386
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
387
+ * @return array Masīvs ar epasta domēniem
388
+ * @returnf string domain Domēna vārds
389
+ * @returnf integer total_sent Kopā nosūtīto epastu skaits kampaņai (visi epasti)
390
+ * @returnf integer emails Uz šo domēnu nosūtīto epstu skaits
391
+ * @returnf integer bounces Neaizgājušo epastu skaits
392
+ * @returnf integer opens Unikālo atvēršanu skaits
393
+ * @returnf integer clicks Unikālo klikšķu skaits
394
+ * @returnf integer unsubs Skaits, cik atrakstījušies
395
+ * @returnf integer delivered Piegādāto vēstuļu skaits
396
+ * @returnf integer emails_pct Skaits, cik epastu procentuāli ir ar šo domēnu
397
+ * @returnf integer bounces_pct Skaits, cik procentuāli no kopēja skaita nav piegādāts ar šo domēnu
398
+ * @returnf integer opens_pct Skaits, cik procentuāli ir atvērts ar šo domēnu
399
+ * @returnf integer clicks_pct Skaits, cik procentuāli no šī domēna ir spieduši
400
+ * @returnf integer unsubs_pct Procentuāli, cik daudz no šī domēna ir atrakstījušies
401
+ */
402
+ function campaignEmailDomainPerformance($cid) {
403
+ $params = array();
404
+ $params["cid"] = $cid;
405
+ return $this->callServer("campaignEmailDomainPerformance", $params);
406
+ }
407
+
408
+ /**
409
+ * Atrodam neeksistējošos/nepareizos epastus (hard bounces)
410
+ *
411
+ * @example mgapi_campaignHardBounces.php
412
+ * @example xml-rpc_campaignHardBounces.php
413
+ *
414
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
415
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
416
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
417
+ * @return array Epastu saraksts
418
+ */
419
+ function campaignHardBounces($cid, $start = 0, $limit = 1000) {
420
+ $params = array();
421
+ $params["cid"] = $cid;
422
+ $params["start"] = $start;
423
+ $params["limit"] = $limit;
424
+ return $this->callServer("campaignHardBounces", $params);
425
+ }
426
+
427
+ /**
428
+ * Atrodam pagaidu atgrieztos epastus (soft bounces)
429
+ *
430
+ * @example mgapi_campaignSoftBounces.php
431
+ * @example xml-rpc_campaignSoftBounces.php
432
+ *
433
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
434
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
435
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
436
+ * @return array Epastu saraksts
437
+ */
438
+ function campaignSoftBounces($cid, $start = 0, $limit = 1000) {
439
+ $params = array();
440
+ $params["cid"] = $cid;
441
+ $params["start"] = $start;
442
+ $params["limit"] = $limit;
443
+ return $this->callServer("campaignSoftBounces", $params);
444
+ }
445
+
446
+ /**
447
+ * Atrodam atgrieztos epastus (blocked bounces)
448
+ *
449
+ * @example mgapi_campaignBlockedBounces.php
450
+ * @example xml-rpc_campaignBlockedBounces.php
451
+ *
452
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
453
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
454
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
455
+ * @return array Epastu saraksts
456
+ */
457
+ function campaignBlockedBounces($cid, $start = 0, $limit = 1000) {
458
+ $params = array();
459
+ $params["cid"] = $cid;
460
+ $params["start"] = $start;
461
+ $params["limit"] = $limit;
462
+ return $this->callServer("campaignBlockedBounces", $params);
463
+ }
464
+
465
+ /**
466
+ * Atrodam atgrieztos epastus (temporary bounces)
467
+ *
468
+ * @example mgapi_campaignTemporaryBounces.php
469
+ * @example xml-rpc_campaignTemporaryBounces.php
470
+ *
471
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
472
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
473
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
474
+ * @return array Epastu saraksts
475
+ */
476
+ function campaignTemporaryBounces($cid, $start = 0, $limit = 1000) {
477
+ $params = array();
478
+ $params["cid"] = $cid;
479
+ $params["start"] = $start;
480
+ $params["limit"] = $limit;
481
+ return $this->callServer("campaignTemporaryBounces", $params);
482
+ }
483
+
484
+ /**
485
+ * Atrodam atgrieztos epastus (generic bounces)
486
+ *
487
+ * @example mgapi_campaignGenericBounces.php
488
+ * @example xml-rpc_campaignGenericBounces.php
489
+ *
490
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
491
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
492
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
493
+ * @return array Epastu saraksts
494
+ */
495
+ function campaignGenericBounces($cid, $start = 0, $limit = 1000) {
496
+ $params = array();
497
+ $params["cid"] = $cid;
498
+ $params["start"] = $start;
499
+ $params["limit"] = $limit;
500
+ return $this->callServer("campaignGenericBounces", $params);
501
+ }
502
+
503
+ /**
504
+ * Atrodam visus e-pastus, kas ir atrakstījušies no šīs kampaņas
505
+ *
506
+ * @example mgapi_campaignUnsubscribes.php
507
+ * @example xml-rpc_campaignUnsubscribes.php
508
+ *
509
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
510
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
511
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
512
+ * @return array Epastu saraksts
513
+ */
514
+ function campaignUnsubscribes($cid, $start = 0, $limit = 1000) {
515
+ $params = array();
516
+ $params["cid"] = $cid;
517
+ $params["start"] = $start;
518
+ $params["limit"] = $limit;
519
+ return $this->callServer("campaignUnsubscribes", $params);
520
+ }
521
+
522
+ /**
523
+ * Atgriež valstu sarakstu, no kurām ir atvērtas vēstules un cik daudz
524
+ *
525
+ * @example mgapi_campaignGeoOpens.php
526
+ * @example xml-rpc_campaignGeoOpens.php
527
+ *
528
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
529
+ * @return array countries Masīvs ar valstu sarakstu
530
+ * @returnf string code Valsts kods ISO3166 formātā, satur 2 simbolus
531
+ * @returnf string name Valsts nosaukums
532
+ * @returnf int opens Skaits, cik daudz atvērts
533
+ */
534
+ function campaignGeoOpens($cid) {
535
+ $params = array();
536
+ $params["cid"] = $cid;
537
+ return $this->callServer("campaignGeoOpens", $params);
538
+ }
539
+
540
+ /**
541
+ * Atrodam pārsūtīšanas statistiku
542
+ *
543
+ * @example mgapi_campaignForwardStats.php
544
+ * @example xml-rpc_campaignForwardStats.php
545
+ *
546
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
547
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
548
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 1000. Maksimālā vērtība ir 15000
549
+ * @return array Epastu saraksts
550
+ */
551
+ function campaignForwardStats($cid, $start = 0, $limit = 1000) {
552
+ $params = array();
553
+ $params["cid"] = $cid;
554
+ $params["start"] = $start;
555
+ $params["limit"] = $limit;
556
+ return $this->callServer("campaignForwardStats", $params);
557
+ }
558
+
559
+ /**
560
+ * Atgriež kampaņas atmesto vēstuļu tekstus, kuras nav vecākas par 30 dienām
561
+ *
562
+ * @example mgapi_campaignBounceMessages.php
563
+ * @example xml-rpc_campaignBounceMessages.php
564
+ *
565
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
566
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
567
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
568
+ * @return array bounces Masīvs, kas satur atsviesto epastu saturu
569
+ * @returnf string date Laiks, kad vēstule saņemta
570
+ * @returnf string email Epasta arese, uz kuru neizdevās nosūtīt
571
+ * @returnf string message Atsviestēs vēstules saturs
572
+ */
573
+ function campaignBounceMessages($cid, $start = 0, $limit = 25) {
574
+ $params = array();
575
+ $params["cid"] = $cid;
576
+ $params["start"] = $start;
577
+ $params["limit"] = $limit;
578
+ return $this->callServer("campaignBounceMessages", $params);
579
+ }
580
+
581
+ /**
582
+ * Atgriež epastu sarakstu, kas atvēruši kampaņu
583
+ *
584
+ * @example mgapi_campaignOpened.php
585
+ *
586
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
587
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
588
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
589
+ * @return struct Masīvs, kas satur datus
590
+ * @returnf integer total Kopējais skaits
591
+ * @returnf array data Saraksts ar datiem
592
+ struct data
593
+ string email Epasta adrese
594
+ integer count Cik reizes atvēra
595
+ */
596
+ function campaignOpened($cid, $start = 0, $limit = 25) {
597
+ $params = array();
598
+ $params["cid"] = $cid;
599
+ $params["start"] = $start;
600
+ $params["limit"] = $limit;
601
+ return $this->callServer("campaignOpened", $params);
602
+ }
603
+
604
+ /**
605
+ * Atgriež epastu sarakstu, kas nav atvēruši kampaņu
606
+ *
607
+ * @example mgapi_campaignNotOpened.php
608
+ *
609
+ * @param string $cid Kampaņas id. To var atrast ar campaigns()
610
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
611
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
612
+ * @return struct Masīvs, kas satur datus
613
+ * @returnf integer total Kopējais skaits
614
+ * @returnf array data Epastu saraksts
615
+ string email Epasta adrese
616
+ */
617
+ function campaignNotOpened($cid, $start = 0, $limit = 25) {
618
+ $params = array();
619
+ $params["cid"] = $cid;
620
+ $params["start"] = $start;
621
+ $params["limit"] = $limit;
622
+ return $this->callServer("campaignNotOpened", $params);
623
+ }
624
+
625
+ /**
626
+ * Izveidojam jaunu sarakstu
627
+ *
628
+ * @example mgapi_listCreate.php
629
+ * @example xml-rpc_listCreate.php
630
+ *
631
+ * @param string $title Saraksta nosaukums
632
+ * @param array $options Masīvs ar kampaņas parametriem
633
+ string permission_reminder Atgādinājums lietotājiem, kā tie nokļuva sarakstā
634
+ string notify_to Epasta adrese, uz kuru sūtīt paziņojumus
635
+ bool subscription_notify Sūtīt paziņojumus par to, ka ir jauns lietotājs pierakstījies
636
+ bool unsubscription_notify Sūtīt paziņojumus par to, ka ir jauns lietotājs atrakstījies
637
+ bool has_email_type_option Ļaut izvēlēties epasta formātu
638
+
639
+ *
640
+ * @return string Atgriež jaunā saraksta ID
641
+ */
642
+ function listCreate($title, $options = NULL) {
643
+ $params = array();
644
+ $params["title"] = $title;
645
+ $params["options"] = $options;
646
+ return $this->callServer("listCreate", $params);
647
+ }
648
+
649
+ /**
650
+ * Atjaunojam saraksta parametrus
651
+ *
652
+ * @example mgapi_listUpdate.php
653
+ * @example xml-rpc_listUpdate.php
654
+ *
655
+ * @param string $id Saraksta, kuru vajag labot, ID
656
+ * @param string $name Parametra nosaukums (skatīties pie listCreate() options lauku ). Iespējamie parametri: title, permission_reminder, notify_to, utt.
657
+ * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
658
+ */
659
+ function listUpdate($id, $name, $value) {
660
+ $params = array();
661
+ $params["id"] = $id;
662
+ $params["name"] = $name;
663
+ $params["value"] = $value;
664
+ return $this->callServer("listUpdate", $params);
665
+ }
666
+
667
+ /**
668
+ * Tiek dzēsts neatgriezensiki saraksts. Esiet uzmanīgi!
669
+ *
670
+ * @example mgapi_listDelete.php
671
+ * @example xml-rpc_listDelete.php
672
+ *
673
+ * @param string $id Saraksta, kuru vajag labot, ID
674
+ * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
675
+ */
676
+ function listDelete($id) {
677
+ $params = array();
678
+ $params["id"] = $id;
679
+ return $this->callServer("listDelete", $params);
680
+ }
681
+
682
+ /**
683
+ * Atrodam visus sarakstus
684
+ *
685
+ * @example mgapi_lists.php
686
+ * @example xml-rpc_lists.php
687
+ *
688
+ * @return array Masīvs ar sarakstiem
689
+ * @returnf string id Saraksta id. Šī vērtība tiek izmantota cītās funkcijās, kas strādā ar sarakstiem.
690
+ * @returnf integer web_id Saraksta id, kas tiek izmantots web administrācijas lapā
691
+ * @returnf string name Saraksta nosaukums
692
+ * @returnf date date_created Saraksta izveidošanas datums.
693
+ * @returnf integer member_count Lietotāju skaits sarakstā
694
+ * @returnf integer unsubscribe_count Lietotāju skaits, cik atrakstījušies no saraksta
695
+ * @returnf string default_from_name Noklusējuma vērtība From Name priekš kampaņām, kas izmanto šo sarakstu
696
+ * @returnf string default_from_email Noklusējuma vērtība From Email priekš kampaņām, kas izmanto šo sarakstu
697
+ * @returnf string default_subject Noklusējuma vērtība Subject priekš kampaņām, kas izmanto šo sarakstu
698
+ * @returnf string default_language Noklusēja valoda saraksta formām
699
+ */
700
+ function lists($start = 0, $limit = 1000) {
701
+ $params = array();
702
+ $params["start"] = $start;
703
+ $params["limit"] = $limit;
704
+ return $this->callServer("lists", $params);
705
+ }
706
+
707
+ /**
708
+ * Atrodam merge tagus sarakstam
709
+ *
710
+ * @example mgapi_listMergeVarUpdate.php
711
+ * @example xml-rpc_listMergeVars.php
712
+ *
713
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
714
+ * @return array Merge tagu saraksts
715
+ * @returnf string name Merge taga nosaukums
716
+ * @returnf bool req Vai šis lauks ir obligāti aizpildāms (true) vai nē (false)
717
+ * @returnf string field_type Merge tada datu tips. Ir pieļaujamas šādas vērtības: email, text, number, date, address, phone, website, image
718
+ * @returnf bool show Norāda, vai rādīt šo lauku lietotāju sarakstā.
719
+ * @returnf string order Kārtas numurs
720
+ * @returnf string default Vērtība pēc noklusējuma
721
+ * @returnf string tag Merge tags, kas tiek izmantots formās, listSubscribe() un listUpdateMember()
722
+ */
723
+ function listMergeVars($id) {
724
+ $params = array();
725
+ $params["id"] = $id;
726
+ return $this->callServer("listMergeVars", $params);
727
+ }
728
+
729
+ /**
730
+ * Pievienojam jaunu merge tagu sarakstam
731
+ *
732
+ * @example mgapi_listMergeVarUpdate.php
733
+ * @example xml-rpc_listMergeVarAdd.php
734
+ *
735
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
736
+ * @param string $tag Merge tags, kuru vajag pievienot, piemēram, FNAME
737
+ * @param string $name Garāks nosaukum, kas tiks rādīts lietotājiem
738
+ * @param array $options Nav obligāts. Dažādi parametri merge tagam.
739
+ string field_type Nav obligāts. Kāda vērtība no: text, number, date, address, phone, website, image. Pēc noklusējuma ir text
740
+ boolean req Nav obligāts. Norāda, vai lauks ir obligāti aizpildāms. Pēc noklusējuma, false
741
+ boolean show Nav obligāts. Norāda, vai rādīt šo lauku lietotāju sarakstā. Pēc noklusējuma, true
742
+ string default_value Nav obligāts. Vērtība pēc noklusējuma
743
+
744
+ * @return boolean true ja ir izdevies, false ja nav izdevies
745
+ */
746
+ function listMergeVarAdd($id, $tag, $name, $options = array()) {
747
+ $params = array();
748
+ $params["id"] = $id;
749
+ $params["tag"] = $tag;
750
+ $params["name"] = $name;
751
+ $params["options"] = $options;
752
+ return $this->callServer("listMergeVarAdd", $params);
753
+ }
754
+
755
+ /**
756
+ * Atjaunojam merge taga parametrus sarakstā. Merge taga tipu nevar nomainīt
757
+ *
758
+ * @example mgapi_listMergeVarUpdate.php
759
+ * @example xml-rpc_listMergeVarUpdate.php
760
+ *
761
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
762
+ * @param string $tag Merge tags, kuru vajag atjaunot
763
+ * @param array $options Parametri merge taga atjaunošanai. Pareizus parametrus skatīties pie metodes listMergeVarAdd()
764
+ * @return boolean true ja ir izdevies, false ja nav izdevies
765
+ */
766
+ function listMergeVarUpdate($id, $tag, $options) {
767
+ $params = array();
768
+ $params["id"] = $id;
769
+ $params["tag"] = $tag;
770
+ $params["options"] = $options;
771
+ return $this->callServer("listMergeVarUpdate", $params);
772
+ }
773
+
774
+ /**
775
+ * Tiek izdzēsts merge tags no saraksta un vērtība visiem saraksta lietotājiem. Dati tie izdzēsti neatgriezeniski
776
+ *
777
+ * @example mgapi_listMergeVarDel.php
778
+ * @example xml-rpc_listMergeVarDel.php
779
+ *
780
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
781
+ * @param string $tag Merge tags, kuru vajag izdzēst
782
+ * @return boolean true ja ir izdevies, false ja nav izdevies
783
+ */
784
+ function listMergeVarDel($id, $tag) {
785
+ $params = array();
786
+ $params["id"] = $id;
787
+ $params["tag"] = $tag;
788
+ return $this->callServer("listMergeVarDel", $params);
789
+ }
790
+
791
+ /**
792
+ * Pievienojam sarakstam jaunu lietotaju
793
+ *
794
+ * @example mgapi_listSubscribe.php
795
+ * @example xml-rpc_listSubscribe.php
796
+ *
797
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
798
+ * @param string $email_address Epasta adrese, ko japievieno sarakstam
799
+ * @param array $merge_vars Masivs, kas satur MERGE lauku vertibas (FNAME, LNAME, etc.) Maksimalais izmers 255
800
+ * @param string $email_type Nav obligats. Epasta tips: html vai plain. Pec noklusejuma html
801
+ * @param boolean $double_optin Vai sutit apstiprinajuma vestuli. Pec noklusejuma true
802
+ * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
803
+ * @param boolean $send_welcome - Nav obligats. Sutit vai nesutit paldies vestuli. Pec noklusejuma false
804
+
805
+ * @return boolean true ja ir izdevies, false ja nav izdevies
806
+ */
807
+ function listSubscribe($id, $email_address, $merge_vars, $email_type = 'html', $double_optin = true, $update_existing = false, $send_welcome = false) {
808
+ $params = array();
809
+ $params["id"] = $id;
810
+ $params["email_address"] = $email_address;
811
+ $params["merge_vars"] = $merge_vars;
812
+ $params["email_type"] = $email_type;
813
+ $params["double_optin"] = $double_optin;
814
+ $params["update_existing"] = $update_existing;
815
+ $params["send_welcome"] = $send_welcome;
816
+ return $this->callServer("listSubscribe", $params);
817
+ }
818
+
819
+ /**
820
+ * Pievienojam sarakstam jaunu lietotaju
821
+ *
822
+ * @example mgapi_listSubscribe.php
823
+ * @example xml-rpc_listSubscribe.php
824
+ *
825
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
826
+ * @param string $phone Tālrunis, ko japievieno sarakstam
827
+ * @param array $merge_vars Masivs, kas satur MERGE lauku vertibas (FNAME, LNAME, etc.) Maksimalais izmers 255
828
+ * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
829
+
830
+ * @return boolean true ja ir izdevies, false ja nav izdevies
831
+ */
832
+ function listSubscribeSMS($id, $phone, $merge_vars, $update_existing = false) {
833
+ $params = array();
834
+ $params["id"] = $id;
835
+ $params["phone"] = $phone;
836
+ $params["merge_vars"] = $merge_vars;
837
+ $params["update_existing"] = $update_existing;
838
+ return $this->callServer("listSubscribeSMS", $params);
839
+ }
840
+
841
+ /**
842
+ * Iznemam no saraksta epasta adresi
843
+ *
844
+ * @example mgapi_listUnsubscribe.php
845
+ * @example xml-rpc_listUnsubscribe.php
846
+ *
847
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
848
+ * @param string $email_address Epasta adrese vai "id", ko var atrast ar "listMemberInfo" metodi
849
+ * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
850
+ * @param boolean $send_goodbye Nosutit vai nesutit pazinojumu epasta lietotajam. Pec noklusejuma true
851
+ * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
852
+ * @return boolean true ja ir izdevies, false ja nav izdevies
853
+ */
854
+ function listUnsubscribe($id, $email_address, $delete_member = false, $send_goodbye = true, $send_notify = true) {
855
+ $params = array();
856
+ $params["id"] = $id;
857
+ $params["email_address"] = $email_address;
858
+ $params["delete_member"] = $delete_member;
859
+ $params["send_goodbye"] = $send_goodbye;
860
+ $params["send_notify"] = $send_notify;
861
+ return $this->callServer("listUnsubscribe", $params);
862
+ }
863
+
864
+ /**
865
+ * Iznemam no saraksta epasta adresi
866
+ *
867
+ * @example mgapi_listUnsubscribe.php
868
+ * @example xml-rpc_listUnsubscribe.php
869
+ *
870
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
871
+ * @param string $phone Phone vai "id", ko var atrast ar "listMemberInfo" metodi
872
+ * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
873
+ * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
874
+ * @return boolean true ja ir izdevies, false ja nav izdevies
875
+ */
876
+ function listUnsubscribeSMS($id, $phone, $delete_member = false, $send_notify = true) {
877
+ $params = array();
878
+ $params["id"] = $id;
879
+ $params["phone"] = $phone;
880
+ $params["delete_member"] = $delete_member;
881
+ $params["send_notify"] = $send_notify;
882
+ return $this->callServer("listUnsubscribeSMS", $params);
883
+ }
884
+
885
+ /**
886
+ * Labo epasta adresi, MERGE laukus saraksta lietotajam
887
+ *
888
+ * @example mgapi_listUpdateMember.php
889
+ * @example xml-rpc_listUpdateMember.php
890
+ *
891
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
892
+ * @param string $email_address Epasta adrese vai "id", ko var atrast ar "listMemberInfo" metodi
893
+ * @param array $merge_vars Masivs ar MERGE laukiem. MERGE laukus var apskatities pie metodes "listSubscribe"
894
+ * @param string $email_type Epasta tips: "html" vai "plain". Nav obligats
895
+ * @return boolean true ja ir izdevies, false ja nav izdevies
896
+ */
897
+ function listUpdateMember($id, $email_address, $merge_vars, $email_type = '') {
898
+ $params = array();
899
+ $params["id"] = $id;
900
+ $params["email_address"] = $email_address;
901
+ $params["merge_vars"] = $merge_vars;
902
+ $params["email_type"] = $email_type;
903
+ return $this->callServer("listUpdateMember", $params);
904
+ }
905
+
906
+ /**
907
+ * Pievienojam sarakstam vairakus epastus
908
+ *
909
+ * @example mgapi_listBatchSubscribe.php
910
+ * @example xml-rpc_listBatchSubscribe.php
911
+ *
912
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
913
+ * @param array $batch Masivs, kas satur epastu datus. Epasta dati ir masivs ar šada atslegam: "EMAIL" epasta adresei, "EMAIL_TYPE" epasta tips (html vai plain)
914
+ * @param boolean $double_optin Vai sutit apstiprinajuma vestuli. Pec noklusejuma true
915
+ * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
916
+ * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
917
+ * @returnf integer success_count Skaits, cik izdevas
918
+ * @returnf integer error_count Skaits, cik neizdevas
919
+ * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "email"
920
+ */
921
+ function listBatchSubscribe($id, $batch, $double_optin = true, $update_existing = false) {
922
+ $params = array();
923
+ $params["id"] = $id;
924
+ $params["batch"] = $batch;
925
+ $params["double_optin"] = $double_optin;
926
+ $params["update_existing"] = $update_existing;
927
+ return $this->callServer("listBatchSubscribe", $params);
928
+ }
929
+
930
+ /**
931
+ * Pievienojam sarakstam vairakus epastus
932
+ *
933
+ * @example mgapi_listBatchSubscribe.php
934
+ * @example xml-rpc_listBatchSubscribe.php
935
+ *
936
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
937
+ * @param array $batch Masivs, kas satur epastu datus. Epasta dati ir masivs ar šada atslegam: "SMS" epasta adresei
938
+ * @param boolean $update_existing Vai atjaunot eksistejošos epastus. Pec noklusejuma false (atgriezis kludas pazinojumu)
939
+ * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
940
+ * @returnf integer success_count Skaits, cik izdevas
941
+ * @returnf integer error_count Skaits, cik neizdevas
942
+ * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "phone"
943
+ */
944
+ function listBatchSubscribeSMS($id, $batch, $update_existing = false) {
945
+ $params = array();
946
+ $params["id"] = $id;
947
+ $params["batch"] = $batch;
948
+ $params["double_optin"] = $double_optin;
949
+ $params["update_existing"] = $update_existing;
950
+ return $this->callServer("listBatchSubscribeSMS", $params);
951
+ }
952
+
953
+ /**
954
+ * Iznemam no saraksta vairakus epastus
955
+ *
956
+ * @example mgapi_listBatchUnsubscribe.php
957
+ * @example xml-rpc_listBatchUnsubscribe.php
958
+ *
959
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
960
+ * @param array $emails Epastu masivs
961
+ * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
962
+ * @param boolean $send_goodbye Nosutit vai nesutit pazinojumu epasta lietotajam. Pec noklusejuma true
963
+ * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
964
+ * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
965
+ * @returnf integer success_count Skaits, cik izdevas
966
+ * @returnf integer error_count Skaits, cik neizdevas
967
+ * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "email"
968
+ */
969
+ function listBatchUnsubscribe($id, $emails, $delete_member = false, $send_goodbye = true, $send_notify = false) {
970
+ $params = array();
971
+ $params["id"] = $id;
972
+ $params["emails"] = $emails;
973
+ $params["delete_member"] = $delete_member;
974
+ $params["send_goodbye"] = $send_goodbye;
975
+ $params["send_notify"] = $send_notify;
976
+ return $this->callServer("listBatchUnsubscribe", $params);
977
+ }
978
+
979
+ /**
980
+ * Iznemam no saraksta vairakus epastus
981
+ *
982
+ * @example mgapi_listBatchUnsubscribe.php
983
+ * @example xml-rpc_listBatchUnsubscribe.php
984
+ *
985
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
986
+ * @param array $phones Tālruņu masivs
987
+ * @param boolean $delete_member Dzest vai nedzest lietotaju no saraksta. Pec noklusejuma false
988
+ * @param boolean $send_goodbye Nosutit vai nesutit pazinojumu epasta lietotajam. Pec noklusejuma true
989
+ * @param boolean $send_notify Nosutit vai nesutit pazinojumu uz epastu, kas noradits saraksta opcijas. Pec noklusejuma false
990
+ * @return struct Masivs, kas satur skaitu, cik izevies iznemt un kludu pazinojumus
991
+ * @returnf integer success_count Skaits, cik izdevas
992
+ * @returnf integer error_count Skaits, cik neizdevas
993
+ * @returnf array errors Masivs ar kludas pazinojumiem. Satur "code", "message", un "email"
994
+ */
995
+ function listBatchUnsubscribeSMS($id, $phones, $delete_member = false, $send_notify = false) {
996
+ $params = array();
997
+ $params["id"] = $id;
998
+ $params["phones"] = $phones;
999
+ $params["delete_member"] = $delete_member;
1000
+ $params["send_notify"] = $send_notify;
1001
+ return $this->callServer("listBatchUnsubscribeSMS", $params);
1002
+ }
1003
+
1004
+ /**
1005
+ * Atrodam epasta info sarkaksta
1006
+ *
1007
+ * @example mgapi_listMembers.php
1008
+ * @example xml-rpc_listMembers.php
1009
+ *
1010
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
1011
+ * @param string $status Epasta statuss (subscribed, unsubscribed, inactive, bounced), pec noklusejuma subscribed
1012
+ * @param integer $start Nav obligats. Nepieciešams lielam sarakstam. Lapas numurs, no kuras sakt. Pirmajai lapai atbilst numurs 0
1013
+ * @param integer $limit Nav obligats. Nepieciešams lielam sarakstam. Skaits, cik daudz atgriezt epastus. Pec noklusejuma 100, maksimalais ir 15000
1014
+ * @return array Masivs ar lietotaju sarakstu
1015
+ * @returnf string email Lietotaja epasts
1016
+ * @returnf date timestamp Peivienošanas datums
1017
+ */
1018
+ function listMembers($id, $status = 'subscribed', $start = 0, $limit = 100) {
1019
+ $params = array();
1020
+ $params["id"] = $id;
1021
+ $params["status"] = $status;
1022
+ $params["start"] = $start;
1023
+ $params["limit"] = $limit;
1024
+ return $this->callServer("listMembers", $params);
1025
+ }
1026
+
1027
+ /**
1028
+ * Atrodam epasta info sarkaksta
1029
+ *
1030
+ * @example mgapi_listMemberInfo.php
1031
+ * @example xml-rpc_listMemberInfo.php
1032
+ *
1033
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
1034
+ * @param string $email_address Epasta adrese vai epasta ID saraksta
1035
+ * @return array Masivs, kas satur epasta informaciju
1036
+ * @returnf string id Unikals epasta id
1037
+ * @returnf string email Epasta adrese
1038
+ * @returnf string email_type Epasta tips: html vai plain
1039
+ * @returnf array merges Masivs ar papildus laukiem
1040
+ * @returnf string status Epasta status: inactive, subscribed, unsubscribed, bounced
1041
+ * @returnf string ip_opt IP adrese, no kuras tika apstiprinats epasts
1042
+ * @returnf string ip_signup IP adrese, no kuras tika aizpildita forma
1043
+ * @returnf date timestamp Laiks, kad tika pievienots sarakstam
1044
+ */
1045
+ function listMemberInfo($id, $email_address) {
1046
+ $params = array();
1047
+ $params["id"] = $id;
1048
+ $params["email_address"] = $email_address;
1049
+ return $this->callServer("listMemberInfo", $params);
1050
+ }
1051
+
1052
+ /**
1053
+ * Saraksta pieauguma informacija pa menešiem
1054
+ *
1055
+ * @example mgapi_listGrowthHistory.php
1056
+ * @example xml-rpc_listGrowthHistory.php
1057
+ *
1058
+ * @param string $id Saraksta ID. Saraksta ID var atrast ar lists() metodi
1059
+ * @return array Masivs pa menešiem
1060
+ * @returnf string month Gads un menesis YYYY-MM formata
1061
+ * @returnf integer existing Skaits, cik bija lietotaju meneša sakuma
1062
+ * @returnf integer imports Skaits, cik daudz tekošaja menesi tika pievienoti lietotaji
1063
+ */
1064
+ function listGrowthHistory($id) {
1065
+ $params = array();
1066
+ $params["id"] = $id;
1067
+ return $this->callServer("listGrowthHistory", $params);
1068
+ }
1069
+
1070
+ /**
1071
+ * Atrodam visus saraksta segmentus
1072
+ *
1073
+ * @example mgapi_listSegments.php
1074
+ * @example xml-rpc_listSegments.php
1075
+ *
1076
+ * @return array Masīvs ar saraksta segmentiem
1077
+ * @returnf string id Saraksta segmenta id.
1078
+ * @returnf integer web_id Saraksta segmenta id, kas tiek izmantots web administrācijas lapā
1079
+ * @returnf string name Saraksta segmenta nosaukums
1080
+ * @returnf date date_created Saraksta izveidošanas datums.
1081
+ * @returnf integer member_count Lietotāju skaits sarakstā
1082
+ */
1083
+ function listSegments($id) {
1084
+ $params = array();
1085
+ $params["id"] = $id;
1086
+ return $this->callServer("listSegments", $params);
1087
+ }
1088
+
1089
+ /**
1090
+ * Izveidojam jaunu segmentu
1091
+ *
1092
+ * @example mgapi_listSegmentCreate.php
1093
+ *
1094
+ * @param string $list Saraksta ID
1095
+ * @param string $title Segmenta nosaukums
1096
+ * @param string $match Sakritības tips
1097
+ * @param array $filter Masīvs ar nosacījumu masīviem
1098
+ string field Merge lauks
1099
+ string condition Nosacījumi: is, not, isany, contains, notcontain, starts, ends, greater, less
1100
+ string value Vērtība, priekš condition
1101
+
1102
+ *
1103
+ * @return string Atgriež jaunā segmenta ID
1104
+ */
1105
+ function listSegmentCreate($list, $title, $match, $filter) {
1106
+ $params = array();
1107
+ $params["list"] = $list;
1108
+ $params["title"] = $title;
1109
+ $params["match"] = $match;
1110
+ $params["filter"] = $filter;
1111
+ return $this->callServer("listSegmentCreate", $params);
1112
+ }
1113
+
1114
+ /**
1115
+ * Atjaunojam segmenta parametrus
1116
+ *
1117
+ * @example mgapi_listSegmentUpdate.php
1118
+ *
1119
+ * @param string $sid Segmenta, kuru vajag labot, ID
1120
+ * @param string $name Parametra nosaukums (skatīties pie listSegmentCreate() options lauku ). Iespējamie parametri: title, match, filter
1121
+ * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1122
+ */
1123
+ function listSegmentUpdate($sid, $name, $value) {
1124
+ $params = array();
1125
+ $params["sid"] = $sid;
1126
+ $params["name"] = $name;
1127
+ $params["value"] = $value;
1128
+ return $this->callServer("listSegmentUpdate", $params);
1129
+ }
1130
+
1131
+ /**
1132
+ * Tiek dzēsts neatgriezensiki segments. Esiet uzmanīgi!
1133
+ *
1134
+ * @example mgapi_listSegmentDelete.php
1135
+ *
1136
+ * @param string $sid Segmenta, kuru vajag dzēst, ID
1137
+ * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1138
+ */
1139
+ function listSegmentDelete($sid) {
1140
+ $params = array();
1141
+ $params["sid"] = $sid;
1142
+ return $this->callServer("listSegmentDelete", $params);
1143
+ }
1144
+
1145
+ /**
1146
+ * Atrodam epastus
1147
+ *
1148
+ * @example mgapi_listSegmentMembers.php
1149
+ * @example xml-rpc_listSegmentMembers.php
1150
+ *
1151
+ * @param string $id Segmenta ID. Saraksta ID var atrast ar listSegments() metodi
1152
+ * @param string $status Epasta statuss (subscribed, unsubscribed, inactive, bounced), pec noklusejuma subscribed
1153
+ * @param integer $start Nav obligats. Nepieciešams lielam sarakstam. Lapas numurs, no kuras sakt. Pirmajai lapai atbilst numurs 0
1154
+ * @param integer $limit Nav obligats. Nepieciešams lielam sarakstam. Skaits, cik daudz atgriezt epastus. Pec noklusejuma 100, maksimalais ir 15000
1155
+ * @return array Masivs ar lietotaju sarakstu
1156
+ * @returnf string email Lietotaja epasts
1157
+ * @returnf string id Lietotaja ID
1158
+ * @returnf string list Saraksta ID
1159
+ * @returnf date timestamp Peivienošanas datums
1160
+ */
1161
+ function listSegmentMembers($id, $status = 'subscribed', $start = 0, $limit = 100) {
1162
+ $params = array();
1163
+ $params["id"] = $id;
1164
+ $params["status"] = $status;
1165
+ $params["start"] = $start;
1166
+ $params["limit"] = $limit;
1167
+ return $this->callServer("listSegmentMembers", $params);
1168
+ }
1169
+
1170
+ /**
1171
+ * Noņemam nost statusu, kas lika SMS kampaņu izsūtīt kaut kad nākotnē
1172
+ *
1173
+ * @example mgapi_smsCampaignUnschedule.php
1174
+ *
1175
+ * @param string $cid SMS kampaņa, kurai vajag noņemt izsūtīšanas laiku kaut kad nākotnē, ID
1176
+ * @return boolean true ja ir veiksmīgi
1177
+ */
1178
+ function smsCampaignUnschedule($cid) {
1179
+ $params = array();
1180
+ $params["cid"] = $cid;
1181
+ return $this->callServer("smsCampaignUnschedule", $params);
1182
+ }
1183
+
1184
+ /**
1185
+ * Iestādam laiku, kad izsūtīt SMS kampaņu
1186
+ *
1187
+ * @example mgapi_smsCampaignSchedule.php
1188
+ *
1189
+ * @param string $cid SMS kampaņa, kurai vajag iestādīt izsūtīšanas laiku, ID
1190
+ * @param string $schedule_time Laiks, kad izsūtīt. Laiku jānorāda šādā formātā YYYY-MM-DD HH:II:SS pēc <strong>GMT</strong>
1191
+ * @return boolean true ja ir veiksmīgi
1192
+ */
1193
+ function smsCampaignSchedule($cid, $schedule_time) {
1194
+ $params = array();
1195
+ $params["cid"] = $cid;
1196
+ $params["schedule_time"] = $schedule_time;
1197
+ return $this->callServer("smsCampaignSchedule", $params);
1198
+ }
1199
+
1200
+ /**
1201
+ * Nosūtīt SMS kampaņu nekavējoties
1202
+ *
1203
+ * @example mgapi_smsCampaignSendNow.php
1204
+ *
1205
+ * @param string $cid SMS kampaņa, kuru vajag nosūtīt, ID
1206
+ * @return boolean true ja ir veiksmīgi
1207
+ */
1208
+ function smsCampaignSendNow($cid) {
1209
+ $params = array();
1210
+ $params["cid"] = $cid;
1211
+ return $this->callServer("smsCampaignSendNow", $params);
1212
+ }
1213
+
1214
+ /**
1215
+ * Atrodam visus lietotāja SMS šablonus
1216
+ *
1217
+ * @example mgapi_smsCampaignTemplates.php
1218
+ *
1219
+ * @return array Masīvs, kas satur SMS šablonus
1220
+ * @returnf integer id Šablona ID
1221
+ * @returnf string source Šablona teksts
1222
+ */
1223
+ function smsCampaignTemplates() {
1224
+ $params = array();
1225
+ return $this->callServer("smsCampaignTemplates", $params);
1226
+ }
1227
+
1228
+ /**
1229
+ * Izveidojam jaunu SMS kampaņu
1230
+ *
1231
+ * @example mgapi_smsCampaignCreate.php
1232
+ *
1233
+ * @param array $options Masīvs ar SMS kampaņas parametriem
1234
+ string sender Vārds, no kā tiks nosūtīta SMS. To nepieciešams piereģistrēt ar funkciju smsSenderIdRegister()
1235
+ struct recipients
1236
+ string list_id Saraksta id, to var atrast ar lists()
1237
+ integer segment_id Nav obligāts. Segmenta ID, to var atrast ar segments()
1238
+ string merge SMS lauka nosaukums, piemēram, MERGE10, SMS
1239
+ array tracking Nav obligāts. Statistikas parametru masīvs, tiek izmantotas šādas atslēgas: "clicks".
1240
+ string title Nav obligāts. Kampaņas nosaukums.
1241
+ array analytics Nav obligāts. Masīvs ar skaitītāju informāciju. Google gadījumā ir šāds pielietojums "google"=>"jūsu_google_analytics_atslēga". "jūsu_google_analytics_atslēga" tiks pievienota visiem linkiem, statistiku varēs apskatīties klienta Google Analytics kontā
1242
+ boolean unicode Nav obligāts. Nosaka, vai izsūtīt kampaņu unikodā. Lai speciālie simboli un burit rādītos SMS kampaņa, šim ir jābūt true. Pēc noklusējuma ir false
1243
+ boolean concatenate Nav obligāts. Nosaka, vai izsūtīt vairākas īsziņas, ja teksts ir par garu. Pēc noklusējuma ir false
1244
+
1245
+ * @param array $content Masīvs, kas satur vēstules saturu. Struktūra:
1246
+ text saturs Nav obligāts, ja ir norādīts template_id. SMS kampaņas saturs
1247
+ integer template_id Nav obligāts. Lietotāja SMS šablona id, nu kura tiks paņemts SMS saturs. Var atrast ar smsCampaignTemplates()
1248
+
1249
+ *
1250
+ * @return string Atgriež jaunās SMS kampaņas ID
1251
+ */
1252
+ function smsCampaignCreate($options, $content) {
1253
+ $params = array();
1254
+ $params["options"] = $options;
1255
+ $params["content"] = $content;
1256
+ return $this->callServer("smsCampaignCreate", $params);
1257
+ }
1258
+
1259
+ /**
1260
+ * Atjaunojam kampaņas, kura vēl nav nosūtīta, parametrus
1261
+ *
1262
+ *
1263
+ * Uzmanību:<br/><ul>
1264
+ * <li>Ja Jūs izmantojat list_id, visi iepriekšējie saraksti tiks izdzēsti.</li>
1265
+ * <li>Ja Jūs izmantojat template_id, tiks pārrakstīts saturs ar šablona saturu</li>
1266
+ *
1267
+ * @example mgapi_smsCampaignUpdate.php
1268
+ *
1269
+ * @param string $cid Kampaņas, kuru vajag labot, ID
1270
+ * @param string $name Parametra nosaukums (skatīties pie smsCampaignCreate() options lauku ). Iespējamie parametri: sender, recipients, utt. Papildus parametri ir content.
1271
+ * @param mixed $value Iespējamās vērtības parametram ( skatīties campaignCreate() options lauku )
1272
+ * @return boolean true, ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1273
+ */
1274
+ function smsCampaignUpdate($cid, $name, $value) {
1275
+ $params = array();
1276
+ $params["cid"] = $cid;
1277
+ $params["name"] = $name;
1278
+ $params["value"] = $value;
1279
+ return $this->callServer("smsCampaignUpdate", $params);
1280
+ }
1281
+
1282
+ /**
1283
+ * Kopējam kampaņu
1284
+ *
1285
+ * @example mgapi_smsCampaignReplicate.php
1286
+ *
1287
+ * @param string $cid SMS kampaņa, kuru vajag kopēt, ID
1288
+ * @return string Atgriežam jaunās SMS kampaņas ID
1289
+ */
1290
+ function smsCampaignReplicate($cid) {
1291
+ $params = array();
1292
+ $params["cid"] = $cid;
1293
+ return $this->callServer("smsCampaignReplicate", $params);
1294
+ }
1295
+
1296
+ /**
1297
+ * Tiek dzēsta neatgriezensiki SMS kampaņa. Esiet uzmanīgi!
1298
+ *
1299
+ * @example mgapi_smsCampaignDelete.php
1300
+ *
1301
+ * @param string $cid SMS kampaņa, kuru vajag dzēst, ID
1302
+ * @return boolean true ja ir veiksmīgi, pretējā gadījumā atgriež kļūdas paziņojumu
1303
+ */
1304
+ function smsCampaignDelete($cid) {
1305
+ $params = array();
1306
+ $params["cid"] = $cid;
1307
+ return $this->callServer("smsCampaignDelete", $params);
1308
+ }
1309
+
1310
+ /**
1311
+ * Atgriežam SMS kampaņu sarakstu. Var pielietot filtru, lai detalizēt atlasītu
1312
+ *
1313
+ * @example mgapi_smsCampaigns.php
1314
+ *
1315
+ * @param array $filters Nav obligāts. Masīvs ar parametriem:
1316
+ string campaign_id Nav obligāts, kampaņas id
1317
+ string recipients Nav obligāts, saraksta id. To var atrast ar lists()
1318
+ string status Nav obligāts. Var atrast kampaņu pēc statusa: sent, draft, sending
1319
+ string sender Nav obligāts. Atlasa kampānu pēc sūtītāja vārda
1320
+ string title Nav obligāts. Atlasa pēc kampaņas nosaukuma
1321
+ string sendtime_start Nav obligāts. Atlasa vēstules, kas izsūtītas pēc šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
1322
+ string sendtime_end Nav obligāts. Atlasa vēstules, kas izsūtītas pirms šī datuma/laika. Formāts - YYYY-MM-DD HH:mm:ss (24hr)
1323
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
1324
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 1000
1325
+ * @return array Agriež masīvu ar SMS kampaņu sarakstu
1326
+ * @returnf string id SMS kampaņas id. To izmanto pārējām funkcijām
1327
+ * @returnf integer web_id SMS kampaņas id, kas tiek izmanots web versijā
1328
+ * @returnf string title SMS kampaņas virsraksts
1329
+ * @returnf date create_time SMS kampaņas izveidošanas datums
1330
+ * @returnf date send_time SMS kampānas nosūtīšanas datums
1331
+ * @returnf integer sms_sent Nosūtīto SMS skaits
1332
+ * @returnf string status Kampaņas statuss (sent, draft, paused, sending)
1333
+ * @returnf string sender SMS sūtītāja vārds
1334
+ * @returnf boolean analytics Integrēt vai neitegrēt Google Analytics
1335
+ * @returnf string analytcs_tag Google Analytics nosaukums kampaņai
1336
+ * @returnf boolean track_clicks Skaitīt vai neskaitīt klikšķus
1337
+ * @returnf boolean unicode Izmantot vai neizmantot unikodu
1338
+ * @returnf boolean concatenate Sadalīt vai nesadalīt vairākās īsziņās garāku īsziņu
1339
+ */
1340
+ function smsCampaigns($filters = array(), $start = 0, $limit = 25) {
1341
+ $params = array();
1342
+ $params["filters"] = $filters;
1343
+ $params["start"] = $start;
1344
+ $params["limit"] = $limit;
1345
+ return $this->callServer("smsCampaigns", $params);
1346
+ }
1347
+
1348
+ /**
1349
+ * Atgriež SMS kampaņas statistiku
1350
+ *
1351
+ * @example mgapi_smsCampaignStats.php
1352
+ *
1353
+ * @param string $cid SMS kampaņas id. To var atrast ar smsCampaigns()
1354
+ * @return array Masīvs, kas satur SMS kampaņas statistiku
1355
+ * @returnf integer delivered Piegādāto SMS skaits
1356
+ * @returnf integer sent Nosūtīto SMS skaits. Vēl nav saņemts gala apstiprinājums par veiksmi vai neveiksmi
1357
+ * @returnf integer queued SMS skats, kas stāv vēl izsūtīšanas rindā
1358
+ * @returnf integer undelivered Nepiegādāto SMS skaits
1359
+ * @returnf integer error Nepiegādāto SMS skaits, kuriem ir bijusi kāda tehniska kļūda piegādes procesā
1360
+ * @returnf integer other SMS ar citu piegādes statusu
1361
+ * @returnf integer clicks Skaits, cik daudz ir spiests uz linkiem
1362
+ * @returnf integer unique_clicks Unikālie klikšķi uz saitēm
1363
+ * @returnf date last_click Datums, kad pēdējo reizi spiests uz linkiem
1364
+ * @returnf integer users_who_clicked Lietotāju skaits, kas spieduši uz saitēm
1365
+ * @returnf integer sms_sent Kopējais skaits, cik vēstules ir izsūtītas
1366
+ */
1367
+ function smsCampaignStats($cid) {
1368
+ $params = array();
1369
+ $params["cid"] = $cid;
1370
+ return $this->callServer("smsCampaignStats", $params);
1371
+ }
1372
+
1373
+ /**
1374
+ * Atrodam SMS kampaņas visus linkus
1375
+ *
1376
+ * @example mgapi_smsCampaignClickStats.php
1377
+ *
1378
+ * @param string $cid SMS kampaņas id. To var atrast ar smsCampaigns()
1379
+ * @return struct urls Saišu masīvs, kur atslēga ir saite
1380
+ * @returnf integer clicks Kopējais klikšķu skaits
1381
+ * @returnf integer unique Unikālo klikšķu skaits
1382
+ */
1383
+ function smsCampaignClickStats($cid) {
1384
+ $params = array();
1385
+ $params["cid"] = $cid;
1386
+ return $this->callServer("smsCampaignClickStats", $params);
1387
+ }
1388
+
1389
+ /**
1390
+ * Atgriež SMS kampaņas nepiegādāto īsziņu statusus
1391
+ *
1392
+ * @example mgapi_smsCampaignBounces.php
1393
+ *
1394
+ * @param string $cid SMS kampaņas id. To var atrast ar smsCampaigns()
1395
+ * @param integer $start Nav obligāts. Lapa, no kuras izvadīt datus. Pēc noklusējuma ir 0, kas atbilst pirmajai lapai
1396
+ * @param integer $limit Nav obligāts. Rezultātu skaits lapā. Pēc noklusējuma 25. Maksimālā vērtība ir 50
1397
+ * @return array bounces Masīvs, kas satur nepiegādātās SMS
1398
+ * @returnf string phone Tālruņa numurs, uz kuru neizdevās nosūtīt
1399
+ * @returnf string reason Iemesls, kāpēc netika piegādāts
1400
+ */
1401
+ function smsCampaignBounces($cid, $start = 0, $limit = 25) {
1402
+ $params = array();
1403
+ $params["cid"] = $cid;
1404
+ $params["start"] = $start;
1405
+ $params["limit"] = $limit;
1406
+ return $this->callServer("smsCampaignBounces", $params);
1407
+ }
1408
+
1409
+ /**
1410
+ * Nosūtam pieprasījumu reģistrēt SMS sūtītāja vārdu
1411
+ *
1412
+ * @example mgapi_smsSenderIdRegister.php
1413
+ *
1414
+ * @param string $sender Vēlamais SMS sūtītāja vārds
1415
+ * @param string $phone Rezerves mobilā tālr. numurs
1416
+ * @param string $company Uzņēmuma nosaukums
1417
+ * @param string $fullname Kontaktpersonas vārds, uzvārds
1418
+ * @param string $companyposition Pozīcija uzņēmumā
1419
+ * @param string $comments Papildus komentāri
1420
+ * @returnf boolean Vai ir pieņemts izskatīšanai
1421
+ */
1422
+ function smsSenderIdRegister($sender, $phone, $company, $fullname, $companyposition, $comments = '') {
1423
+ $params = array();
1424
+ $params["sender"] = $sender;
1425
+ $params["phone"] = $phone;
1426
+ $params["company"] = $company;
1427
+ $params["fullname"] = $fullname;
1428
+ $params["companyposition"] = $companyposition;
1429
+ $params["comments"] = $comments;
1430
+ return $this->callServer("smsSenderIdRegister", $params);
1431
+ }
1432
+
1433
+ /**
1434
+ * Atgriež dažādu informaciju par lietotaju kontu
1435
+ *
1436
+ * @example mgapi_getAccountDetails.php
1437
+ * @example xml-rpc_getAccountDetails.php
1438
+ *
1439
+ * @return array Masivs, kas satur da˛adu informaciju par šis API atlsegas lietotaja kontu
1440
+ * @returnf string user_id Lietotaja unikalais ID, tas tiek izmantots buvejot da˛adas saites
1441
+ * @returnf string username Lietotaja lietotajvards
1442
+ * @returnf bool is_trial Vai lietotajs ir trial
1443
+ * @returnf int emails_left Skaits, cik daudz epastus var nosutit
1444
+ * @returnf datetime first_payment Pirma maksajuma datums
1445
+ * @returnf datetime last_payment Pedeja maksajuma datums
1446
+ * @returnf int times_logged_in Skaits, cik daudz reizes lietotajs caur web ir ielogojies
1447
+ * @returnf datetime last_login Datums, kad pedejo reizi bija ielogojies caur web
1448
+ * @returnf array contact Masivs, kas satur kontkatinformaciju: Vards, uzvards, epasts, uznemuma nosaukums, adrese, majas lapas adrese, telefons, fakss
1449
+ * @returnf array orders Masivs, kas satur informaciju par samaksatajiem rekiniem: rekina numurs, plans, cena, valuta, izrakstišanas datums, pakas deriguma terminš
1450
+ */
1451
+ function getAccountDetails() {
1452
+ $params = array();
1453
+ return $this->callServer("getAccountDetails", $params);
1454
+ }
1455
+
1456
+ /**
1457
+ * Atrodam visu sarakstu ID, kuros ir ššis epasts
1458
+ *
1459
+ * @example mgapi_listsForEmail.php
1460
+ * @example xml-rpc_listsForEmail.php
1461
+ *
1462
+ * @param string $email_address epasta adrese
1463
+ * @return array an array Masivs, kas satur sarakstu ID
1464
+ */
1465
+ function listsForEmail($email_address) {
1466
+ $params = array();
1467
+ $params["email_address"] = $email_address;
1468
+ return $this->callServer("listsForEmail", $params);
1469
+ }
1470
+
1471
+ /**
1472
+ * Atrodam visas API atslegas
1473
+ *
1474
+ * @example mgapi_apikeys.php
1475
+ * @example xml-rpc_apikeys.php
1476
+ *
1477
+ * @param string $username lietotaja vards
1478
+ * @param string $password lietotaja parole
1479
+ * @param boolean $expired nav obligats - radit vai neradit atslegas, kuras vairs nav derigas. Pec noklusejuma ir false
1480
+ * @return array API atslegu masivs, kas satur:
1481
+ * @returnf string apikey Šo atslegu var izmantot, lai pieslegtos API
1482
+ * @returnf string created_at Datums, kad atslega ir izveidota
1483
+ * @returnf string expired_at Datums, kad ta tika atzimeta, ka neaktiva
1484
+ */
1485
+ function apikeys($username, $password, $expired = false) {
1486
+ $params = array();
1487
+ $params["username"] = $username;
1488
+ $params["password"] = $password;
1489
+ $params["expired"] = $expired;
1490
+ return $this->callServer("apikeys", $params);
1491
+ }
1492
+
1493
+ /**
1494
+ * Izveidojam jaunu API atslegu
1495
+ *
1496
+ * @example mgapi_apikeyAdd.php
1497
+ * @example xml-rpc_apikeyAdd.php
1498
+ *
1499
+ * @param string $username lietotaja vards
1500
+ * @param string $password lietotaja parole
1501
+ * @return string atgrie˛ jaunu API atslegu
1502
+ */
1503
+ function apikeyAdd($username, $password) {
1504
+ $params = array();
1505
+ $params["username"] = $username;
1506
+ $params["password"] = $password;
1507
+ return $this->callServer("apikeyAdd", $params);
1508
+ }
1509
+
1510
+ /**
1511
+ * Atzimejam ka neaktivu API atslegu
1512
+ *
1513
+ * @example mgapi_apikeyExpire.php
1514
+ * @example xml-rpc_apikeyExpire.php
1515
+ *
1516
+ * @param string $username lietotaja vards
1517
+ * @param string $password lietotaja parole
1518
+ * @return boolean true, ja izdevas nomainit statusu
1519
+ */
1520
+ function apikeyExpire($username, $password) {
1521
+ $params = array();
1522
+ $params["username"] = $username;
1523
+ $params["password"] = $password;
1524
+ return $this->callServer("apikeyExpire", $params);
1525
+ }
1526
+
1527
+ /**
1528
+ * Atrodam API atslegu
1529
+ *
1530
+ * @example mgapi_login.php
1531
+ * @example xml-rpc_login.php
1532
+ *
1533
+ * @param string $username lietotaja vards
1534
+ * @param string $password lietotaja parole
1535
+ * @return string tiek atgriezta API atslega, ja tadas vel nav, tad tiek izveidota
1536
+ */
1537
+ function login($username, $password) {
1538
+ $params = array();
1539
+ $params["username"] = $username;
1540
+ $params["password"] = $password;
1541
+ return $this->callServer("login", $params);
1542
+ }
1543
+
1544
+ /**
1545
+ * "ping" - vienkarš veids, ka parbaudit, vai viss ir kartiba. Ja ir kadas problemas, tiks atgriezts par to pazinojums.
1546
+ *
1547
+ * @example mgapi_ping.php
1548
+ * @example xml-rpc_ping.php
1549
+ *
1550
+ * @return string tiek atgriezts teksts "Everything's Ok!", ja viss ir kartiba, ja nav, tad atgrie˛ kludas pazinojumu
1551
+ */
1552
+ function ping() {
1553
+ $params = array();
1554
+ return $this->callServer("ping", $params);
1555
+ }
1556
+
1557
+ /**
1558
+ * Piesledzas pie servera uz izsauc nepieciešamo metodi un atgrie˛ rezultatu
1559
+ * Šo funkciju nav nepieciešams izsaukt manuali
1560
+ */
1561
+ function callServer($method, $params) {
1562
+ $host = $this->apiUrl["host"];
1563
+ $params["apikey"] = $this->api_key;
1564
+
1565
+ $this->errorMessage = "";
1566
+ $this->errorCode = "";
1567
+ $post_vars = $this->httpBuildQuery($params);
1568
+
1569
+ $payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
1570
+ $payload .= "Host: " . $host . "\r\n";
1571
+ $payload .= "User-Agent: MGAPI/" . $this->version ."\r\n";
1572
+ $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
1573
+ $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
1574
+ $payload .= "Connection: close \r\n\r\n";
1575
+ $payload .= $post_vars;
1576
+
1577
+ ob_start();
1578
+ if ($this->secure){
1579
+ $sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
1580
+ } else {
1581
+ $sock = fsockopen($host, 80, $errno, $errstr, 30);
1582
+ }
1583
+ if(!$sock) {
1584
+ $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
1585
+ $this->errorCode = "-99";
1586
+ ob_end_clean();
1587
+ return false;
1588
+ }
1589
+
1590
+ $response = "";
1591
+ fwrite($sock, $payload);
1592
+ stream_set_timeout($sock, $this->timeout);
1593
+ $info = stream_get_meta_data($sock);
1594
+ while ((!feof($sock)) && (!$info["timed_out"])) {
1595
+ $response .= fread($sock, $this->chunkSize);
1596
+ $info = stream_get_meta_data($sock);
1597
+ }
1598
+ if ($info["timed_out"]) {
1599
+ $this->errorMessage = "Could not read response (timed out)";
1600
+ $this->errorCode = -98;
1601
+ }
1602
+ fclose($sock);
1603
+ ob_end_clean();
1604
+ if ($info["timed_out"]) return false;
1605
+
1606
+ list($throw, $response) = explode("\r\n\r\n", $response, 2);
1607
+
1608
+ if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
1609
+
1610
+ $serial = unserialize($response);
1611
+ if($response && $serial === false) {
1612
+ $response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
1613
+ } else {
1614
+ $response = $serial;
1615
+ }
1616
+ if(is_array($response) && isset($response["error"])) {
1617
+ $this->errorMessage = $response["error"];
1618
+ $this->errorCode = $response["code"];
1619
+ return false;
1620
+ }
1621
+
1622
+ return $response;
1623
+ }
1624
+
1625
+ /**
1626
+ * Definejam funkciju, kas aizstaj http_build_query sistemam, kuras tas nav
1627
+ */
1628
+ function httpBuildQuery($params, $key = NULL) {
1629
+ if(!function_exists('http_build_query')) {
1630
+ $ret = array();
1631
+
1632
+ foreach((array) $params as $name => $val) {
1633
+ $name = urlencode($name);
1634
+ if($key !== null) {
1635
+ $name = $key . "[" . $name . "]";
1636
+ }
1637
+
1638
+ if(is_array($val) || is_object($val)) {
1639
+ $ret[] = $this->httpBuildQuery($val, $name);
1640
+ } elseif($val !== null) {
1641
+ $ret[] = $name . "=" . urlencode($val);
1642
+ }
1643
+ }
1644
+
1645
+ return implode("&", $ret);
1646
+ } else {
1647
+ return http_build_query((array)$params, $key);
1648
+ }
1649
+ }
1650
+ }
1651
+
1652
  ?>
package.xml CHANGED
@@ -1,28 +1,30 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mailigen_Synchronizer</name>
4
- <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Two-way sync between Magento email newsletter subscriber list and Mailigen email list</summary>
10
- <description>This extension enables a two-way synchronization between your Magento email newsletter subscriber list and your Mailigen email list. It is easy and quick to install and configure, no complex actions or knowledge of programming needed.&#xD;
11
  &#xD;
12
  Feature-rich synchronization&#xD;
13
  &#xD;
14
  - Automatic synchronization between your Magento email subscriber list and one of your Mailigen email lists. When users subscribe to the newsletter in Magento, they will be added to the selected Mailigen contact list.&#xD;
15
  - Two-way synchronization when it comes to subscriber status change. When users unsubscribe from your Magento list, they will be removed also from your Mailigen list. And vice versa, users will be removed from your Magento list when unsubscribed from your Mailigen list.&#xD;
 
 
16
  &#xD;
17
  For more detailed information, instructions and usage of this extension, please visit Mailigen Integrations page or contact our support team.&#xD;
18
  &#xD;
19
  Mailigen provides email and integrated marketing services covering full email automation. See a full integration list in Mailigen Integrations page.</description>
20
- <notes>- Automatic synchronization between your Magento email subscriber list and one of your Mailigen email lists. When users subscribe to the newsletter in Magento, they will be added to the selected Mailigen contact list.&#xD;
21
- - Two-way synchronization when it comes to subscriber status change. When users unsubscribe from your Magento list, they will be removed also from your Mailigen list. And vice versa, users will be removed from your Magento list when unsubscribed from your Mailigen list.</notes>
22
  <authors><author><name>Thomas Nelson</name><user>mailigen</user><email>info@mailigen.com</email></author></authors>
23
- <date>2014-11-27</date>
24
- <time>19:21:24</time>
25
- <contents><target name="magecommunity"><dir name="Mailigen"><dir name="Synchronizer"><dir name="Block"><dir name="Newsletter"><dir name="Subscriber"><file name="Grid.php" hash="0806d62b81980578a09e5c6210530337"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="45ff744e45e50f035bfcc81534f96dad"/></dir><dir name="Model"><file name="List.php" hash="1f17c0f455adc4024140f22ebe5d6554"/><file name="Mailigen.php" hash="56b6c239c2863384756fc41e3617f804"/><dir name="Newsletter"><file name="Subscriber.php" hash="31cd322f6d00250b672b3e4929559e75"/></dir><file name="Observer.php" hash="fdeaaf4e3a6af3b632de65968e077a41"/></dir><dir name="api"><file name="MGAPI.class.php" hash="904de870b0896a4ffd5c5c144b76d6bb"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="MailigenController.php" hash="2ecc61ae8c037d48a810cc9802b5a507"/></dir></dir><dir name="etc"><file name="config.xml" hash="a90af7455f1c48dc07e53f7be2e5ceee"/><file name="system.xml" hash="ba6c34ba2c4256e9cad3f34fe483beff"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mailigen_Synchronizer.xml" hash="6a07537f8d139cba241548e9e11c3e8b"/></dir></target></contents>
26
  <compatible/>
27
  <dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
28
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mailigen_Synchronizer</name>
4
+ <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Two-way sync for Magneto newsletter subscribers and one-way sync for Magnento customers</summary>
10
+ <description>This extension enables a two-way synchronization between your Magento email newsletter subscriber list and your Mailigen email list, and one-way synchronization between your Magento customer list and your Mailigen email list. It is easy and quick to install and configure, no complex actions or knowledge of programming needed.&#xD;
11
  &#xD;
12
  Feature-rich synchronization&#xD;
13
  &#xD;
14
  - Automatic synchronization between your Magento email subscriber list and one of your Mailigen email lists. When users subscribe to the newsletter in Magento, they will be added to the selected Mailigen contact list.&#xD;
15
  - Two-way synchronization when it comes to subscriber status change. When users unsubscribe from your Magento list, they will be removed also from your Mailigen list. And vice versa, users will be removed from your Magento list when unsubscribed from your Mailigen list.&#xD;
16
+ - Automatic synchronization between your Magento customer list and one of your Mailigen email lists. When customer registers in Magento, they will be added to the selected Mailigen contact list.&#xD;
17
+ - One-way Magento customers synchronization. All customer information (customer address, last login date, items in cart, orders information) from Magento store will be synced with selected Mailigen contact list.&#xD;
18
  &#xD;
19
  For more detailed information, instructions and usage of this extension, please visit Mailigen Integrations page or contact our support team.&#xD;
20
  &#xD;
21
  Mailigen provides email and integrated marketing services covering full email automation. See a full integration list in Mailigen Integrations page.</description>
22
+ <notes>- One-way Magento customers synchronization. All customer information (customer address, last login date, items in cart, orders information) from Magento store will be synced with selected Mailigen contact list.&#xD;
23
+ - Automatic synchronization between your Magento customer list and one of your Mailigen email lists. When customer registers in Magento, they will be added to the selected Mailigen contact list.</notes>
24
  <authors><author><name>Thomas Nelson</name><user>mailigen</user><email>info@mailigen.com</email></author></authors>
25
+ <date>2015-05-13</date>
26
+ <time>05:38:01</time>
27
+ <contents><target name="magecommunity"><dir name="Mailigen"><dir name="Synchronizer"><dir name="Block"><dir name="Adminhtml"><dir name="Sync"><file name="Information.php" hash="0ab1c0f348bebc09b8d4463aa915b0ba"/></dir></dir><dir name="Newsletter"><dir name="Subscriber"><file name="Grid.php" hash="31ab69f735a6e1d4382ffa88c223bbf3"/></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="91b9c056767eb2de5e7d86d98038e984"/><file name="Data.php" hash="3907873d61c689b8899a8fbe03f39008"/><file name="Log.php" hash="e4ae795b78f4aed8b24f2a73a6e5a9ff"/></dir><dir name="Model"><dir name="Customer"><dir name="Merge"><file name="Field.php" hash="61c16630b368bff6a38096e29160b9b2"/></dir></dir><file name="Customer.php" hash="947ac735ca21d6edc4b47e93a80c7a9c"/><file name="List.php" hash="824b44c8d118cd0eb2aa7a62233b024f"/><file name="Mailigen.php" hash="16db407dc7953abb448de5c523833575"/><dir name="Newsletter"><file name="Subscriber.php" hash="31d0caec2f0eff537c39c6b584afc198"/></dir><file name="Observer.php" hash="e6046431c97e6672f2157c799e7fa429"/><dir name="Resource"><dir name="Customer"><file name="Collection.php" hash="8d8bf178493201cf2de8b734f0a4d931"/></dir><file name="Customer.php" hash="4fa61ed2e22202c87e0d6b06c8ed8e9d"/><dir name="Iterator"><file name="Batched.php" hash="d2b0ec0268773422de00cb6766083753"/></dir></dir><file name="Schedule.php" hash="e1c494dce9652566ae679a2032c86769"/><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Customer"><file name="List.php" hash="5370ca37cb8d4f0a268e3ef2e9f4c673"/></dir><dir name="Newsletter"><file name="List.php" hash="05f2ce9cb0954a35cc87f7899164beaa"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="MailigenController.php" hash="772672a78be5385faa660bded0157ddc"/></dir></dir><dir name="data"><dir name="mailigen_synchronizer_setup"><file name="data-install-1.1.0.php" hash="30f1fdb649862fcbbd943aeb7ce65c7f"/></dir></dir><dir name="etc"><file name="config.xml" hash="003723c7c2cc94866d58790ce7d6df7d"/><file name="system.xml" hash="52ba369f2ae3d11a0b5c71e101ec743a"/></dir><dir name="sql"><dir name="mailigen_synchronizer_setup"><file name="install-1.1.0.php" hash="57d4d1b139ec03084f758906803dd28f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="."><file name="Mailigen_Synchronizer.xml" hash=""/></dir></target><target name="magelib"><dir name="mailigen"><file name="MGAPI.class.php" hash="16b7712206e95bf61c2cf6f92ef71583"/></dir></target></contents>
28
  <compatible/>
29
  <dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
30
  </package>