Mzax_Emarketing - Version 0.2.5

Version Notes

Please note, this extension is currently under development and it is still in beta.

Download this release

Release Info

Developer Jacob Siefer
Extension Mzax_Emarketing
Version 0.2.5
Comparing to
See all releases


Version 0.2.5

Files changed (219) hide show
  1. LICENSE +48 -0
  2. app/code/community/Mzax/Emarketing/Block/Campaign/Edit.php +136 -0
  3. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Form.php +44 -0
  4. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Abstract.php +72 -0
  5. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email.php +257 -0
  6. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Inbox.php +79 -0
  7. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Outbox.php +88 -0
  8. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content.php +200 -0
  9. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Original.php +76 -0
  10. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Variation.php +107 -0
  11. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Errors.php +120 -0
  12. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Filters.php +76 -0
  13. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Inbox.php +60 -0
  14. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Medium.php +83 -0
  15. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients.php +102 -0
  16. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients/Grid.php +105 -0
  17. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Report.php +767 -0
  18. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Settings.php +303 -0
  19. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Tasks.php +58 -0
  20. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Test.php +72 -0
  21. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tabs.php +134 -0
  22. app/code/community/Mzax/Emarketing/Block/Campaign/Grid.php +175 -0
  23. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Filter/Filter.php +54 -0
  24. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Action.php +47 -0
  25. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Filter.php +65 -0
  26. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/SendMail.php +35 -0
  27. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Sender.php +42 -0
  28. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Stats.php +57 -0
  29. app/code/community/Mzax/Emarketing/Block/Campaign/New.php +69 -0
  30. app/code/community/Mzax/Emarketing/Block/Campaign/Preview.php +219 -0
  31. app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail.php +72 -0
  32. app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail/Form.php +85 -0
  33. app/code/community/Mzax/Emarketing/Block/Campaign/Test.php +83 -0
  34. app/code/community/Mzax/Emarketing/Block/Campaign/Test/Emulate.php +174 -0
  35. app/code/community/Mzax/Emarketing/Block/Campaign/View.php +40 -0
  36. app/code/community/Mzax/Emarketing/Block/Chart/Abstract.php +211 -0
  37. app/code/community/Mzax/Emarketing/Block/Chart/Area.php +32 -0
  38. app/code/community/Mzax/Emarketing/Block/Chart/Bar.php +32 -0
  39. app/code/community/Mzax/Emarketing/Block/Chart/Column.php +32 -0
  40. app/code/community/Mzax/Emarketing/Block/Chart/Geo.php +32 -0
  41. app/code/community/Mzax/Emarketing/Block/Chart/Line.php +32 -0
  42. app/code/community/Mzax/Emarketing/Block/Chart/Pie.php +32 -0
  43. app/code/community/Mzax/Emarketing/Block/Chart/Scatter.php +32 -0
  44. app/code/community/Mzax/Emarketing/Block/Chart/SteppedArea.php +32 -0
  45. app/code/community/Mzax/Emarketing/Block/Chart/Widget/Container.php +68 -0
  46. app/code/community/Mzax/Emarketing/Block/Chart/Widget/Geo.php +103 -0
  47. app/code/community/Mzax/Emarketing/Block/Chart/Widget/Tab.php +274 -0
  48. app/code/community/Mzax/Emarketing/Block/Conditions.php +46 -0
  49. app/code/community/Mzax/Emarketing/Block/Editable.php +73 -0
  50. app/code/community/Mzax/Emarketing/Block/Filter/Object/Grid.php +187 -0
  51. app/code/community/Mzax/Emarketing/Block/Filter/Test/Recursive.php +106 -0
  52. app/code/community/Mzax/Emarketing/Block/Filter/Test/Single.php +229 -0
  53. app/code/community/Mzax/Emarketing/Block/Filters.php +47 -0
  54. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Action.php +73 -0
  55. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Campaign.php +57 -0
  56. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Recipient.php +62 -0
  57. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Size.php +74 -0
  58. app/code/community/Mzax/Emarketing/Block/Inbox/Email.php +103 -0
  59. app/code/community/Mzax/Emarketing/Block/Inbox/Email/Form.php +187 -0
  60. app/code/community/Mzax/Emarketing/Block/Inbox/Grid.php +259 -0
  61. app/code/community/Mzax/Emarketing/Block/Inbox/View.php +47 -0
  62. app/code/community/Mzax/Emarketing/Block/Outbox/Email.php +108 -0
  63. app/code/community/Mzax/Emarketing/Block/Outbox/Email/Form.php +188 -0
  64. app/code/community/Mzax/Emarketing/Block/Outbox/Grid.php +251 -0
  65. app/code/community/Mzax/Emarketing/Block/Outbox/View.php +47 -0
  66. app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Attribute.php +72 -0
  67. app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Object.php +62 -0
  68. app/code/community/Mzax/Emarketing/Block/Recipients/Grid.php +158 -0
  69. app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/DomainThreshold.php +59 -0
  70. app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/MailStorage.php +69 -0
  71. app/code/community/Mzax/Emarketing/Block/Template/Edit.php +101 -0
  72. app/code/community/Mzax/Emarketing/Block/Template/Edit/Form.php +118 -0
  73. app/code/community/Mzax/Emarketing/Block/Template/Grid.php +87 -0
  74. app/code/community/Mzax/Emarketing/Block/Template/Upload.php +62 -0
  75. app/code/community/Mzax/Emarketing/Block/Template/Upload/Form.php +52 -0
  76. app/code/community/Mzax/Emarketing/Block/Template/View.php +45 -0
  77. app/code/community/Mzax/Emarketing/Block/Tracker/Edit.php +119 -0
  78. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Form.php +44 -0
  79. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Conditions.php +65 -0
  80. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/GoalType.php +106 -0
  81. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Settings.php +170 -0
  82. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Tasks.php +69 -0
  83. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Test.php +73 -0
  84. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tabs.php +95 -0
  85. app/code/community/Mzax/Emarketing/Block/Tracker/Grid.php +143 -0
  86. app/code/community/Mzax/Emarketing/Block/Tracker/New.php +70 -0
  87. app/code/community/Mzax/Emarketing/Block/Tracker/Test.php +83 -0
  88. app/code/community/Mzax/Emarketing/Block/Tracker/Test/Emulate.php +173 -0
  89. app/code/community/Mzax/Emarketing/Block/Tracker/Upload.php +69 -0
  90. app/code/community/Mzax/Emarketing/Block/Tracker/Upload/Form.php +75 -0
  91. app/code/community/Mzax/Emarketing/Block/Tracker/View.php +46 -0
  92. app/code/community/Mzax/Emarketing/Block/Unsubscribe.php +78 -0
  93. app/code/community/Mzax/Emarketing/Db/Select.php +325 -0
  94. app/code/community/Mzax/Emarketing/Helper/Campaign.php +193 -0
  95. app/code/community/Mzax/Emarketing/Helper/Data.php +315 -0
  96. app/code/community/Mzax/Emarketing/Helper/Newsletter.php +78 -0
  97. app/code/community/Mzax/Emarketing/Helper/Request.php +187 -0
  98. app/code/community/Mzax/Emarketing/Helper/SqlFormatter.php +1107 -0
  99. app/code/community/Mzax/Emarketing/LICENSE +48 -0
  100. app/code/community/Mzax/Emarketing/Model/Campaign.php +1034 -0
  101. app/code/community/Mzax/Emarketing/Model/Campaign/Content.php +46 -0
  102. app/code/community/Mzax/Emarketing/Model/Campaign/Variation.php +227 -0
  103. app/code/community/Mzax/Emarketing/Model/Conversion/Goal.php +147 -0
  104. app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Abstract.php +151 -0
  105. app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Orders.php +184 -0
  106. app/code/community/Mzax/Emarketing/Model/Conversion/Select.php +90 -0
  107. app/code/community/Mzax/Emarketing/Model/Conversion/Tracker.php +344 -0
  108. app/code/community/Mzax/Emarketing/Model/DomainThrottle.php +268 -0
  109. app/code/community/Mzax/Emarketing/Model/Email.php +170 -0
  110. app/code/community/Mzax/Emarketing/Model/Form/Element/Ace.php +402 -0
  111. app/code/community/Mzax/Emarketing/Model/Form/Element/Credits.php +37 -0
  112. app/code/community/Mzax/Emarketing/Model/Form/Element/EmailEditor.php +171 -0
  113. app/code/community/Mzax/Emarketing/Model/Form/Element/Info.php +32 -0
  114. app/code/community/Mzax/Emarketing/Model/Form/Element/TemplateEditor.php +130 -0
  115. app/code/community/Mzax/Emarketing/Model/Form/Element/Textarea.php +42 -0
  116. app/code/community/Mzax/Emarketing/Model/Form/Element/Wildselect.php +69 -0
  117. app/code/community/Mzax/Emarketing/Model/Goal.php +84 -0
  118. app/code/community/Mzax/Emarketing/Model/Inbox.php +96 -0
  119. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Abstract.php +35 -0
  120. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Recipient.php +237 -0
  121. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Store.php +94 -0
  122. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Unsubscribe.php +74 -0
  123. app/code/community/Mzax/Emarketing/Model/Inbox/Email.php +473 -0
  124. app/code/community/Mzax/Emarketing/Model/Inbox/Email/Collector.php +103 -0
  125. app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Abstract.php +42 -0
  126. app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Storage.php +209 -0
  127. app/code/community/Mzax/Emarketing/Model/Link.php +112 -0
  128. app/code/community/Mzax/Emarketing/Model/Link/Reference.php +425 -0
  129. app/code/community/Mzax/Emarketing/Model/Medium.php +163 -0
  130. app/code/community/Mzax/Emarketing/Model/Medium/Abstract.php +125 -0
  131. app/code/community/Mzax/Emarketing/Model/Medium/Email.php +333 -0
  132. app/code/community/Mzax/Emarketing/Model/Medium/Email/Composer.php +578 -0
  133. app/code/community/Mzax/Emarketing/Model/Medium/Email/Filter.php +89 -0
  134. app/code/community/Mzax/Emarketing/Model/Medium/Email/Processor.php +274 -0
  135. app/code/community/Mzax/Emarketing/Model/Medium/Email/Snippets.php +89 -0
  136. app/code/community/Mzax/Emarketing/Model/Object/Abstract.php +335 -0
  137. app/code/community/Mzax/Emarketing/Model/Object/Address.php +101 -0
  138. app/code/community/Mzax/Emarketing/Model/Object/Collection.php +234 -0
  139. app/code/community/Mzax/Emarketing/Model/Object/Collection/Item.php +67 -0
  140. app/code/community/Mzax/Emarketing/Model/Object/Customer.php +153 -0
  141. app/code/community/Mzax/Emarketing/Model/Object/Customer/Address.php +126 -0
  142. app/code/community/Mzax/Emarketing/Model/Object/Filter.php +148 -0
  143. app/code/community/Mzax/Emarketing/Model/Object/Filter/Abstract.php +1366 -0
  144. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/City.php +58 -0
  145. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Country.php +82 -0
  146. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Postcode.php +58 -0
  147. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Region.php +58 -0
  148. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Street.php +58 -0
  149. app/code/community/Mzax/Emarketing/Model/Object/Filter/Attribute.php +521 -0
  150. app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Goal.php +150 -0
  151. app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Abstract.php +40 -0
  152. app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Interact.php +41 -0
  153. app/code/community/Mzax/Emarketing/Model/Object/Filter/Column.php +267 -0
  154. app/code/community/Mzax/Emarketing/Model/Object/Filter/Combine.php +152 -0
  155. app/code/community/Mzax/Emarketing/Model/Object/Filter/Component.php +804 -0
  156. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Abstract.php +40 -0
  157. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address.php +191 -0
  158. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address/Attribute.php +58 -0
  159. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Attribute.php +57 -0
  160. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Lastlogin.php +93 -0
  161. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Name.php +63 -0
  162. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Order.php +165 -0
  163. app/code/community/Mzax/Emarketing/Model/Object/Filter/Main.php +173 -0
  164. app/code/community/Mzax/Emarketing/Model/Object/Filter/Newsletter.php +181 -0
  165. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Abstract.php +44 -0
  166. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Address.php +148 -0
  167. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Campaign.php +261 -0
  168. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Abstract.php +45 -0
  169. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Table.php +133 -0
  170. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Items.php +179 -0
  171. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Previous.php +210 -0
  172. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Table.php +101 -0
  173. app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Abstract.php +42 -0
  174. app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Attribute.php +81 -0
  175. app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Category.php +133 -0
  176. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Abstract.php +44 -0
  177. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Address.php +149 -0
  178. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Item/Table.php +127 -0
  179. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Items.php +173 -0
  180. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Table.php +99 -0
  181. app/code/community/Mzax/Emarketing/Model/Object/Filter/Table.php +615 -0
  182. app/code/community/Mzax/Emarketing/Model/Object/Order.php +130 -0
  183. app/code/community/Mzax/Emarketing/Model/Object/OrderAddress.php +60 -0
  184. app/code/community/Mzax/Emarketing/Model/Object/OrderItem.php +118 -0
  185. app/code/community/Mzax/Emarketing/Model/Object/Product.php +76 -0
  186. app/code/community/Mzax/Emarketing/Model/Object/Quote.php +128 -0
  187. app/code/community/Mzax/Emarketing/Model/Object/QuoteAddress.php +65 -0
  188. app/code/community/Mzax/Emarketing/Model/Object/Recipient.php +105 -0
  189. app/code/community/Mzax/Emarketing/Model/Object/Subscriber.php +179 -0
  190. app/code/community/Mzax/Emarketing/Model/Observer.php +81 -0
  191. app/code/community/Mzax/Emarketing/Model/Observer/Abstract.php +46 -0
  192. app/code/community/Mzax/Emarketing/Model/Observer/Cron.php +272 -0
  193. app/code/community/Mzax/Emarketing/Model/Observer/Customer.php +39 -0
  194. app/code/community/Mzax/Emarketing/Model/Observer/Goal.php +178 -0
  195. app/code/community/Mzax/Emarketing/Model/Observer/Order.php +39 -0
  196. app/code/community/Mzax/Emarketing/Model/Outbox.php +232 -0
  197. app/code/community/Mzax/Emarketing/Model/Outbox/Email.php +615 -0
  198. app/code/community/Mzax/Emarketing/Model/Outbox/Transporter.php +112 -0
  199. app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/File.php +52 -0
  200. app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/Interface.php +31 -0
  201. app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/Sendmail.php +60 -0
  202. app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/Smtp.php +66 -0
  203. app/code/community/Mzax/Emarketing/Model/Premailer.php +163 -0
  204. app/code/community/Mzax/Emarketing/Model/Recipient.php +610 -0
  205. app/code/community/Mzax/Emarketing/Model/Recipient/Error.php +113 -0
  206. app/code/community/Mzax/Emarketing/Model/Recipient/Provider.php +182 -0
  207. app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Abstract.php +126 -0
  208. app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Customer.php +116 -0
  209. app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Newsletter.php +141 -0
  210. app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Order.php +137 -0
  211. app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Quote.php +137 -0
  212. app/code/community/Mzax/Emarketing/Model/Report.php +203 -0
  213. app/code/community/Mzax/Emarketing/Model/Report/Aggregator.php +114 -0
  214. app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Abstract.php +475 -0
  215. app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Campaign.php +135 -0
  216. app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension.php +83 -0
  217. app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension/Abstract.php +571 -0
  218. app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension/Country.php +122 -0
  219. app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension/Dayofweek.php +71 -0
LICENSE ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Open Software License ("OSL") v. 3.0
3
+
4
+ This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
5
+
6
+ Licensed under the Open Software License version 3.0
7
+
8
+ 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
9
+
10
+ 1. to reproduce the Original Work in copies, either alone or as part of a collective work;
11
+
12
+ 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
13
+
14
+ 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
15
+
16
+ 4. to perform the Original Work publicly; and
17
+
18
+ 5. to display the Original Work publicly.
19
+
20
+ 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
21
+
22
+ 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
23
+
24
+ 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
25
+
26
+ 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
27
+
28
+ 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
29
+
30
+ 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
31
+
32
+ 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
33
+
34
+ 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
35
+
36
+ 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
37
+
38
+ 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
39
+
40
+ 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
41
+
42
+ 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
43
+
44
+ 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
45
+
46
+ 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
47
+
48
+ 16. Modification of This License. This License is Copyright � 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
app/code/community/Mzax/Emarketing/Block/Campaign/Edit.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+ public function __construct()
27
+ {
28
+ $this->_objectId = 'id';
29
+
30
+ $this->_blockGroup = 'mzax_emarketing';
31
+ $this->_controller = 'campaign';
32
+
33
+ parent::__construct();
34
+
35
+ $this->_updateButton('save', 'label', $this->__('Save Campaign'));
36
+ $this->_updateButton('delete', 'label', $this->__('Delete Campaign'));
37
+
38
+ }
39
+
40
+
41
+ public function getHeaderCssClass()
42
+ {
43
+ return 'head-' . strtr($this->_controller, '_', '-');
44
+ }
45
+
46
+ public function getHeaderText()
47
+ {
48
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
49
+ $campaign = Mage::registry('current_campaign');
50
+ if ($campaign->getId()) {
51
+ $text = $this->htmlEscape($campaign->getName());
52
+ if($campaign->isRunning()) {
53
+ return '<span class="mzax-running"></span>' . $text;
54
+ }
55
+ return $text;
56
+ }
57
+ else {
58
+ return $this->__('New %s Campaign', Mage::getSingleton('mzax_emarketing/medium')->getOptionText($campaign->getData('medium')));
59
+ }
60
+ }
61
+
62
+ public function getValidationUrl()
63
+ {
64
+ return $this->getUrl('*/*/validate', array('_current'=>true));
65
+ }
66
+
67
+ protected function _prepareLayout()
68
+ {
69
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
70
+ $campaign = Mage::registry('current_campaign');
71
+
72
+ $this->_addButton('save_and_continue', array(
73
+ 'label' => $this->__('Save And Continue Edit'),
74
+ 'onclick' => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
75
+ 'class' => 'save'
76
+ ), 10);
77
+
78
+
79
+ if($campaign->getId() && !$campaign->isArchived()) {
80
+
81
+ if($campaign->isRunning()) {
82
+
83
+ $this->_removeButton('save');
84
+ $this->removeButton('delete');
85
+
86
+ $this->_addButton('stop', array(
87
+ 'label' => $this->__('STOP'),
88
+ 'onclick' => "confirmSetLocation('{$this->__('Are you sure you want to stop this campaign?')}', '{$this->getUrl('*/*/stop', array('_current' => true))}')",
89
+ 'class' => 'mzax-stop'
90
+ ), 100, 0);
91
+
92
+
93
+ $this->_addButton('save_and_continue', array(
94
+ 'label' => $this->__('Save Changes'),
95
+ 'onclick' => "saveAndContinueEdit('{$this->_getSaveAndContinueUrl()}', '{$this->__('Are you sure you want to apply those changes to this running campaign?')}')",
96
+ 'class' => 'save'
97
+ ), 10);
98
+ }
99
+ else {
100
+ $this->_addButton('start', array(
101
+ 'label' => $this->__('Start'),
102
+ 'onclick' => "confirmSetLocation('{$this->__('Are you sure you want to start this campaign?')}', '{$this->getUrl('*/*/start', array('_current' => true))}')",
103
+ 'class' => 'mzax-start'
104
+ ), 100, 0);
105
+ }
106
+ }
107
+
108
+ return parent::_prepareLayout();
109
+ }
110
+
111
+
112
+ /**
113
+ * Get form action URL
114
+ *
115
+ * @return string
116
+ */
117
+ public function getFormActionUrl()
118
+ {
119
+ if ($this->hasFormActionUrl()) {
120
+ return $this->getData('form_action_url');
121
+ }
122
+
123
+
124
+ return $this->getUrl('*/*/save');
125
+ }
126
+
127
+
128
+ protected function _getSaveAndContinueUrl()
129
+ {
130
+ return $this->getUrl('*/*/save', array(
131
+ '_current' => true,
132
+ 'back' => 'edit',
133
+ 'tab' => '{{tab_id}}'
134
+ ));
135
+ }
136
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Form.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
30
+
31
+ $campaign = Mage::registry('current_campaign');
32
+
33
+ if ($campaign->getId()) {
34
+ $form->addField('campaign_id', 'hidden', array(
35
+ 'name' => 'campaign_id',
36
+ 'value' => $campaign->getId()
37
+ ));
38
+ }
39
+
40
+ $form->setUseContainer(true);
41
+ $this->setForm($form);
42
+ return parent::_prepareForm();
43
+ }
44
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Abstract.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract extends Mage_Adminhtml_Block_Widget_Form
24
+ {
25
+
26
+ protected function _prepareLayout()
27
+ {
28
+ parent::_prepareLayout();
29
+ }
30
+
31
+
32
+ /**
33
+ * Retrieve current campaign
34
+ *
35
+ * @return Mzax_Emarketing_Model_Campaign
36
+ */
37
+ public function getCampaign()
38
+ {
39
+ return Mage::registry('current_campaign');
40
+ }
41
+
42
+
43
+ /**
44
+ * Retrieve campaign content
45
+ * Usally the campaign it self or a variation object
46
+ *
47
+ * @return Mzax_Emarketing_Model_Campaign_Content
48
+ */
49
+ public function getContent()
50
+ {
51
+ return $this->getData('content');
52
+ }
53
+
54
+
55
+ /**
56
+ *
57
+ * @param Varien_Data_Form $form
58
+ * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
59
+ */
60
+ public function initForm(Varien_Data_Form $form)
61
+ {
62
+ $this->setForm($form);
63
+ $this->_prepareForm();
64
+ return $this;
65
+ }
66
+
67
+
68
+
69
+
70
+
71
+
72
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email.php ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
24
+ {
25
+
26
+ protected function _prepareLayout()
27
+ {
28
+ parent::_prepareLayout();
29
+ }
30
+
31
+
32
+
33
+ protected function getTemplateOptions()
34
+ {
35
+ $templates = Mage::getResourceSingleton('mzax_emarketing/template_collection')->toOptionArray();
36
+ array_unshift($templates, array(
37
+ 'value' => '',
38
+ 'label' => $this->__('Choose a Template...')
39
+ ));
40
+
41
+ return $templates;
42
+ }
43
+
44
+
45
+
46
+ /**
47
+ * Prepare form before rendering HTML
48
+ *
49
+ * @return Mage_Adminhtml_Block_Widget_Form
50
+ */
51
+ protected function _prepareForm()
52
+ {
53
+ $form = $this->getForm();
54
+ $campaign = $this->getCampaign();
55
+ $content = $this->getContent();
56
+ $data = $content->getMediumData();
57
+
58
+
59
+
60
+ $fieldset = $form->addFieldset('email_fieldset', array(
61
+ 'legend' => $this->__('Email'),
62
+ 'class' => 'fieldset-wide',
63
+ ));
64
+
65
+ $fieldset->addType('editor', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_emailEditor'));
66
+
67
+
68
+ $templateOptions = $this->getTemplateOptions();
69
+
70
+
71
+ /* Stop if no template exist */
72
+ if(count($templateOptions) === 1) {
73
+
74
+ $fieldset->addField('template_note', 'note', array(
75
+ 'label' => $this->__('Template'),
76
+ 'class' => 'mzax-template-select',
77
+ 'text' => $this->__("Before you can create an email campaign, you need to setup at least one email template."),
78
+ 'after_element_html' => $this->__(' <a href="%s" target="_blank">Edit Templates</a>', $this->getUrl('*/admin_template')),
79
+ ));
80
+ return;
81
+ }
82
+
83
+
84
+ $fieldset->addField('designmode', 'select', array(
85
+ 'label' => $this->__('Design Mode'),
86
+ 'note' => $this->__("If design mode is disabled the WYSIWYG editor will be disabled and will not mess with your html code."),
87
+ 'name' => 'designmode',
88
+ 'options' => array(
89
+ '1' => $this->__('Enabled'),
90
+ '0' => $this->__('Disabled'),
91
+ ),
92
+ 'value' => '1'
93
+ ));
94
+
95
+ $template = $fieldset->addField('template_id', 'select', array(
96
+ 'name' => 'template_id',
97
+ 'required' => true,
98
+ 'label' => $this->__('Template'),
99
+ 'title' => $this->__('Template'),
100
+ 'values' => $templateOptions,
101
+ 'class' => 'mzax-template-select',
102
+ 'note' => $this->__("A template is required for sending out emails"),
103
+ 'after_element_html' => $this->__(' <a href="%s" target="_blank">Edit Templates</a>', $this->getUrl('*/admin_template')),
104
+ ));
105
+
106
+
107
+ $subject = $fieldset->addField('subject', 'text', array(
108
+ 'name' => 'subject',
109
+ 'required' => true,
110
+ 'label' => $this->__('Email Subject'),
111
+ 'title' => $this->__('Email Subject'),
112
+ ));
113
+
114
+
115
+
116
+
117
+ $urlParams = array('id' => $campaign->getId());
118
+ if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
119
+ $contentName = $content->getName();
120
+ $urlParams['variation'] = $content->getId();
121
+ }
122
+ else {
123
+ $contentName = $this->__('Original');
124
+ }
125
+
126
+ $quickSaveUrl = $this->getUrl('*/*/quicksave', $urlParams);
127
+ $previewUrl = $this->getUrl('*/*/preview', $urlParams);
128
+
129
+
130
+
131
+ $editorConfig = new Varien_Object();
132
+ $editorConfig->setTranslator($this);
133
+ $editorConfig->setFilesBrowserWindowUrl($this->getUrl('adminhtml/cms_wysiwyg_images/index'));
134
+ $editorConfig->setWidgetWindowUrl($this->getUrl('adminhtml/widget/index'));
135
+ $editorConfig->setTemplateLoadUrl($this->getUrl('*/*/templateHtml'));
136
+ $editorConfig->setQuicksaveUrl($quickSaveUrl);
137
+ $editorConfig->setQuicksaveFields(array($subject, $template));
138
+ $editorConfig->setTemplateField($template);
139
+ $editorConfig->setEnableCkeditor($data->getDataSetDefault('designmode', 1));
140
+
141
+
142
+ if($campaign->getId()) {
143
+ $editorConfig->setButtons(array(
144
+ array(
145
+ 'title' => $this->__('Quick Save'),
146
+ 'onclick' => "{editor}.quicksave(); return false;",
147
+ 'class' => 'mzax-quicksave',
148
+ 'style' => 'margin-left: 20px; float: right;'
149
+ ),
150
+ array(
151
+ 'title' => $this->__('Preview'),
152
+ 'onclick' => "popWin('$previewUrl', '_blank', 'width=800,height=700,resizable=1,scrollbars=1'); return false;",
153
+ 'class' => '',
154
+ 'style' => 'margin-left: 10px; float: right;'
155
+ ),
156
+ ));
157
+ }
158
+
159
+
160
+ $editorConfig->setSnippets($campaign->getSnippets());
161
+
162
+
163
+ $editor = $fieldset->addField('body', 'editor', array(
164
+ 'name' => 'body',
165
+ 'label' => $this->__('Email Body'),
166
+ 'title' => $this->__('Email Body'),
167
+ 'style' => 'height:36em',
168
+ 'required' => true,
169
+ 'logo' => $this->getSkinUrl('images/logo.gif'),
170
+ 'fullscreen_title' => $this->__('Email Campaign %s / %s', $campaign->getName(), $contentName),
171
+ 'config' => $editorConfig,
172
+ 'template' => Mage::getModel('mzax_emarketing/template')->load($data->getTemplateId())
173
+ ));
174
+
175
+
176
+ // Setting custom renderer for content field to remove label column
177
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
178
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
179
+ $editor->setRenderer($renderer);
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+ $fieldset = $form->addFieldset('email_delay', array(
188
+ 'legend' => $this->__('Only send out emails at certain times'),
189
+ 'class' => 'fieldset-wide mzax-checkboxes',
190
+ ));
191
+ $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
192
+
193
+ $hourOptions = array();
194
+ for($i = 0; $i < 24; $i++) {
195
+ $hourOptions[$i] = $this->__("%'.02d:00h", $i);
196
+ }
197
+
198
+ $fieldset->addField('info', 'info', array(
199
+ 'text' => $this->__('Keep in mind that this option can significantly delay an email from getting send out. Depending on your campaign this may not be a problem, but sometimes it can. You may want to double check the expire time under "Settings" and make sure it is high enough.')
200
+ ))->setRenderer($renderer);
201
+
202
+
203
+ $fieldset->addField('day_filter', 'checkboxes', array(
204
+ 'name' => 'day_filter[]',
205
+ 'label' => $this->__('Send only on selected weekdays'),
206
+ 'values' => Mage::app()->getLocale()->getOptionWeekdays(),
207
+ 'note' => $this->__("If nothing select, this filter is disabled.")
208
+ ));
209
+
210
+ $fieldset->addField('time_filter', 'checkboxes', array(
211
+ 'name' => 'time_filter[]',
212
+ 'label' => $this->__('Send only at selected hours'),
213
+ 'options' => $hourOptions,
214
+ 'note' => $this->__("If nothing select, this filter is disabled.")
215
+ ));
216
+
217
+
218
+
219
+
220
+
221
+ /*
222
+
223
+
224
+ $fieldset = $form->addFieldset('email_advanced', array(
225
+ 'legend' => $this->__('Advanced Options'),
226
+ 'class' => 'fieldset-wide',
227
+ ));
228
+
229
+ $fieldset->addField('prerender', 'select', array(
230
+ 'label' => $this->__('Pre-Render'),
231
+ 'note' => $this->__("If enabled, email will get pre rendered, cached and then only the basic {{var}} expressions will get parsed. If your content is static or only uses var expressions. Enabling this can increase the render performance by a factor of 10."),
232
+ 'name' => 'prerender',
233
+ 'options' => array(
234
+ '0' => $this->__('Disabled'),
235
+ '1' => $this->__('Enabled'),
236
+ ),
237
+ 'value' => '0'
238
+ ));
239
+
240
+
241
+ if($campaign === $content) {
242
+ $subject = $fieldset->addField('forward_emails', 'text', array(
243
+ 'name' => 'forward_emails',
244
+ 'label' => $this->__('Forward Email'),
245
+ 'note' => $this->__("All non-auto email replies will get forward to this email address."),
246
+ ));
247
+ }
248
+
249
+ */
250
+ $form->addValues($data->getData());
251
+
252
+ return $this;
253
+
254
+
255
+ }
256
+
257
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Inbox.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox extends Mzax_Emarketing_Block_Inbox_Grid
25
+ {
26
+
27
+
28
+ /**
29
+ *
30
+ * @var Mzax_Emarketing_Model_Campaign
31
+ */
32
+ protected $_campaign;
33
+
34
+
35
+
36
+ /**
37
+ *
38
+ * @return Mzax_Emarketing_Model_Campaign
39
+ */
40
+ public function getCampaign()
41
+ {
42
+ if(!$this->_campaign) {
43
+ $campaignId = (int) $this->getRequest()->getParam('id');
44
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign')->load($campaignId);
45
+ }
46
+ return $this->_campaign;
47
+ }
48
+
49
+
50
+
51
+ protected function _prepareCollection()
52
+ {
53
+ $this->getCollection()->addFieldToFilter('campaign_id', $this->getCampaign()->getId());
54
+ parent::_prepareCollection();
55
+ }
56
+
57
+
58
+
59
+
60
+ protected function _prepareColumns()
61
+ {
62
+ parent::_prepareColumns();
63
+ $this->removeColumn('campaign');
64
+
65
+ }
66
+
67
+
68
+
69
+ public function getGridUrl()
70
+ {
71
+ return $this->getUrl('*/*/bounces', array('_current'=> true));
72
+ }
73
+
74
+ public function getRowUrl($row)
75
+ {
76
+ return $this->getUrl('*/admin_inbox/email', array('id'=>$row->getId()));
77
+ }
78
+
79
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Outbox.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Outbox extends Mzax_Emarketing_Block_Outbox_Grid
25
+ {
26
+
27
+
28
+ /**
29
+ *
30
+ * @var Mzax_Emarketing_Model_Campaign
31
+ */
32
+ protected $_campaign;
33
+
34
+
35
+
36
+ /**
37
+ *
38
+ * @return Mzax_Emarketing_Model_Campaign
39
+ */
40
+ public function getCampaign()
41
+ {
42
+ if(!$this->_campaign) {
43
+ $campaignId = (int) $this->getRequest()->getParam('id');
44
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign')->load($campaignId);
45
+ }
46
+ return $this->_campaign;
47
+ }
48
+
49
+
50
+
51
+ protected function _prepareCollection()
52
+ {
53
+ $this->getCollection()->addFieldToFilter('campaign_id', $this->getCampaign()->getId());
54
+ parent::_prepareCollection();
55
+ }
56
+
57
+
58
+
59
+
60
+ protected function _prepareColumns()
61
+ {
62
+ parent::_prepareColumns();
63
+ $this->removeColumn('campaign');
64
+ }
65
+
66
+
67
+
68
+ public function getGridUrl()
69
+ {
70
+ return $this->getUrl('*/*/campaignGrid', array('grid_ajax' => 1, '_current'=> true));
71
+ }
72
+
73
+ public function getRowUrl($row)
74
+ {
75
+ return $this->getUrl('*/admin_outbox/email', array('id'=>$row->getId()));
76
+ }
77
+
78
+
79
+
80
+ public function canDisplayContainer()
81
+ {
82
+ if($this->getRequest()->getParam('grid_ajax')) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+
88
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content extends Mage_Adminhtml_Block_Widget_Tabs
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var string
30
+ */
31
+ const TAB_BLOCK_CAMPAIGN = 'mzax_emarketing/campaign_edit_tab_content_original';
32
+
33
+ /**
34
+ *
35
+ * @var string
36
+ */
37
+ const TAB_BLOCK_VARIATION = 'mzax_emarketing/campaign_edit_tab_content_variation';
38
+
39
+
40
+ /**
41
+ * Initialize Tabs
42
+ *
43
+ */
44
+ public function __construct()
45
+ {
46
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
47
+ $campaign = Mage::registry('current_campaign');
48
+
49
+ parent::__construct();
50
+ $this->setId('campaign_email_tab');
51
+ $this->setDestElementId('mzax_emarketing_info_tabs_content_content');
52
+ $this->setTemplate('mzax/emarketing/campaign/content-tabs.phtml');
53
+ $this->setCurrentTabId('mzax_emarketing_info_tabs_content');
54
+ }
55
+
56
+
57
+
58
+ /**
59
+ * Prepare Layout Content
60
+ *
61
+ * @return Mage_Adminhtml_Block_Catalog_Category_Tabs
62
+ */
63
+ protected function _prepareLayout()
64
+ {
65
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
66
+ $campaign = Mage::registry('current_campaign');
67
+
68
+ $tabId = 'mzax_emarketing_info_tabs_content';
69
+
70
+
71
+ $this->addTab('original', array(
72
+ 'label' => Mage::helper('mzax_emarketing')->__('Orignal'),
73
+ 'content' => $campaign,
74
+ 'active' => true,
75
+ ));
76
+
77
+
78
+ if(!$campaign->getId()) {
79
+ $this->setDisabled(true);
80
+ return;
81
+ }
82
+
83
+ $activeTab = (int) $this->getRequest()->getParam('variation');
84
+
85
+ /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
86
+ foreach($campaign->getVariations() as $variation)
87
+ {
88
+ $this->addTab('variation_' . $variation->getId(), array(
89
+ 'label' => $variation->getName(),
90
+ 'content' => $variation,
91
+ 'active' => $activeTab == $variation->getId(),
92
+ 'remove_url' => $this->getRemoveUrl($variation)
93
+ ));
94
+ }
95
+ }
96
+
97
+
98
+
99
+
100
+ /**
101
+ * Retrieve add variation url
102
+ *
103
+ * @return string
104
+ */
105
+ public function getAddUrl()
106
+ {
107
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
108
+ $campaign = Mage::registry('current_campaign');
109
+
110
+ return $this->getUrl('*/*/addVariation', array(
111
+ 'id' => $campaign->getId(),
112
+ 'tab' => $this->getCurrentTabId()
113
+ ));
114
+ }
115
+
116
+
117
+ /**
118
+ * Retrieve delete variation url
119
+ *
120
+ * @param Mzax_Emarketing_Model_Campaign_Variation $variation
121
+ * @return string
122
+ */
123
+ public function getRemoveUrl(Mzax_Emarketing_Model_Campaign_Variation $variation = null)
124
+ {
125
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
126
+ $campaign = Mage::registry('current_campaign');
127
+
128
+ $params = array('id' => $campaign->getId(), 'tab' => $this->getCurrentTabId());
129
+
130
+ if($variation) {
131
+ $params['variation'] = $variation->getId();
132
+ }
133
+ else {
134
+ $params['variation'] = 'all';
135
+ }
136
+
137
+ return $this->getUrl('*/*/deleteVariation', $params);
138
+ }
139
+
140
+
141
+
142
+
143
+ /**
144
+ * (non-PHPdoc)
145
+ * @see Mage_Adminhtml_Block_Widget_Tabs::getTabContent()
146
+ */
147
+ public function getTabContent($tab)
148
+ {
149
+ $content = $tab->getContent();
150
+
151
+ if($content instanceof Mzax_Emarketing_Model_Campaign) {
152
+ $content = $this->getLayout()
153
+ ->createBlock(self::TAB_BLOCK_CAMPAIGN)
154
+ ->setContent($content)
155
+ ->initForm();
156
+ }
157
+ else if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
158
+ $content = $this->getLayout()
159
+ ->createBlock(self::TAB_BLOCK_VARIATION)
160
+ ->setContent($content)
161
+ ->initForm();
162
+ }
163
+
164
+ if($content instanceof Mage_Core_Block_Abstract) {
165
+ $content = $content->toHtml();
166
+ }
167
+
168
+ return $content;
169
+ }
170
+
171
+
172
+
173
+
174
+ /**
175
+ *
176
+ *
177
+ * @see Mage_Adminhtml_Block_Widget_Tabs::getTabClass()
178
+ * @return string
179
+ */
180
+ public function getTabClass($tab)
181
+ {
182
+ $classes[] = parent::getTabClass($tab);
183
+
184
+ $content = $tab->getContent();
185
+ if($content instanceof Mzax_Emarketing_Model_Campaign) {
186
+ $classes[] = "original";
187
+ }
188
+ if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
189
+ $classes[] = "variation";
190
+ if(!$content->getIsActive()) {
191
+ $classes[] = "inactive";
192
+ }
193
+ }
194
+ return implode(' ', $classes);
195
+ }
196
+
197
+
198
+
199
+
200
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Original.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original extends Mage_Adminhtml_Block_Widget_Form
24
+ {
25
+
26
+ protected function _prepareLayout()
27
+ {
28
+ parent::_prepareLayout();
29
+ }
30
+
31
+
32
+
33
+ public function initForm()
34
+ {
35
+ $form = new Varien_Data_Form();
36
+ $form->setHtmlIdPrefix('campaign_');
37
+ $form->setFieldNameSuffix('campaign');
38
+
39
+ $this->setForm($form);
40
+
41
+ return $this;
42
+ }
43
+
44
+
45
+
46
+ /**
47
+ *
48
+ * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
49
+ */
50
+ public function getContentForm()
51
+ {
52
+ $form = new Varien_Data_Form();
53
+ $form->setHtmlIdPrefix('campaign_mediumdata_');
54
+ $form->setFieldNameSuffix('campaign[medium_data]');
55
+
56
+ /* @var $mediumForm Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract */
57
+ $mediumForm = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_medium_email');
58
+ $mediumForm->setContent($this->getContent());
59
+ $mediumForm->initForm($form);
60
+
61
+ return $mediumForm;
62
+ }
63
+
64
+
65
+
66
+
67
+ public function getFormHtml()
68
+ {
69
+ $html = $this->getContentForm()->getFormHtml();
70
+ $html.= parent::getFormHtml();
71
+
72
+ return $html;
73
+ }
74
+
75
+
76
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Variation.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Variation
25
+ extends Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original
26
+ {
27
+
28
+ protected function _prepareLayout()
29
+ {
30
+ parent::_prepareLayout();
31
+ }
32
+
33
+
34
+ /**
35
+ *
36
+ * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
37
+ */
38
+ public function getContentForm()
39
+ {
40
+ $variation = $this->getContent();
41
+
42
+
43
+ $form = new Varien_Data_Form();
44
+ $form->setHtmlIdPrefix("variation_medium_{$variation->getId()}_");
45
+ $form->setFieldNameSuffix("variation[{$variation->getId()}][medium_data]");
46
+
47
+ /* @var $mediumForm Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract */
48
+ $mediumForm = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_medium_email');
49
+ $mediumForm->setContent($this->getContent());
50
+ $mediumForm->initForm($form);
51
+
52
+ return $mediumForm;
53
+ }
54
+
55
+
56
+
57
+
58
+ public function initForm()
59
+ {
60
+ parent::initForm();
61
+
62
+ $form = $this->getForm();
63
+
64
+ /* @var $content Mzax_Emarketing_Model_Campaign_Content */
65
+ $variation = $this->getContent();
66
+
67
+ $form->setHtmlIdPrefix("variation_{$variation->getId()}_");
68
+ $form->setFieldNameSuffix("variation[{$variation->getId()}]");
69
+
70
+
71
+
72
+ /*
73
+ * Variation
74
+ */
75
+ $fieldset = $form->addFieldset('variation_fieldset', array(
76
+ 'legend' => $this->__('Settings'),
77
+ 'class' => 'fieldset-wide',
78
+ ));
79
+
80
+
81
+ $fieldset->addField('is_active', 'select', array(
82
+ 'label' => $this->__('Is Active'),
83
+ 'title' => $this->__('Is Active'),
84
+ 'name' => 'is_active',
85
+ 'required' => true,
86
+ 'options' => array(
87
+ '1' => $this->__('Enabled'),
88
+ '0' => $this->__('Disabled'),
89
+ ),
90
+ 'value' => '1'
91
+ ));
92
+
93
+
94
+ $fieldset->addField('name', 'text', array(
95
+ 'name' => 'name',
96
+ 'required' => true,
97
+ 'label' => $this->__('Name'),
98
+ 'title' => $this->__('Name'),
99
+ ));
100
+
101
+ $form->addValues($variation->getData());
102
+
103
+ return $this;
104
+
105
+
106
+ }
107
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Errors.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Errors extends Mage_Adminhtml_Block_Widget_Grid
32
+ {
33
+
34
+ public function __construct()
35
+ {
36
+ parent::__construct();
37
+ $this->setId('recipient_error_grid');
38
+ $this->setUseAjax(true);
39
+ $this->setDefaultSort('created_at');
40
+ $this->setDefaultDir('desc');
41
+ }
42
+
43
+
44
+
45
+
46
+
47
+ protected function _prepareCollection()
48
+ {
49
+ /* @var $collection Mzax_Emarketing_Model_Resource_Recipient_Error_Collection */
50
+ $collection = Mage::getResourceModel('mzax_emarketing/recipient_error_collection');
51
+
52
+ if($campaign = Mage::registry('current_campaign')) {
53
+ $collection->addFieldToFilter('campaign_id', $campaign->getId());
54
+ }
55
+
56
+ $this->setCollection($collection);
57
+
58
+ return parent::_prepareCollection();
59
+ }
60
+
61
+
62
+
63
+
64
+ protected function _prepareColumns()
65
+ {
66
+ $this->addColumn('created_at', array(
67
+ 'header' => $this->__('Created At'),
68
+ 'index' => 'created_at',
69
+ 'gmtoffset' => true,
70
+ 'type' =>'datetime'
71
+ ));
72
+
73
+
74
+
75
+ $this->addColumn('recipient', array(
76
+ 'header' => $this->__('Recipient'),
77
+ 'index' => 'recipient_id'
78
+ ));
79
+
80
+
81
+ $this->addColumn('message', array(
82
+ 'header' => $this->__('Message'),
83
+ 'index' => 'message',
84
+ 'type' => 'text',
85
+ 'getter' => function($row) {
86
+ return nl2br($row->getMessage());
87
+ },
88
+ 'truncate' => 500
89
+ ));
90
+
91
+
92
+
93
+ return parent::_prepareColumns();
94
+ }
95
+
96
+
97
+
98
+
99
+
100
+
101
+ public function getGridUrl()
102
+ {
103
+ return $this->getUrl('*/*/errorGrid', array('grid_ajax' => 1, '_current'=> true));
104
+ }
105
+
106
+ public function getRowUrl($row)
107
+ {
108
+ return null;
109
+ //return $this->getUrl('*/admin_outbox/email', array('id'=>$row->getId()));
110
+ }
111
+
112
+
113
+ public function canDisplayContainer()
114
+ {
115
+ if($this->getRequest()->getParam('grid_ajax')) {
116
+ return false;
117
+ }
118
+ return true;
119
+ }
120
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Filters.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+
28
+ public function initForm()
29
+ {
30
+ $form = new Varien_Data_Form();
31
+ $form->setHtmlIdPrefix('_mzax_emarketing');
32
+ $form->setFieldNameSuffix('mzax_emarketing');
33
+
34
+
35
+ $campaign = Mage::registry('current_campaign');
36
+
37
+
38
+ $form->setHtmlIdPrefix('filter_');
39
+
40
+ $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
41
+ ->setTemplate('mzax/emarketing/fieldset.phtml')
42
+ ->setTestUrl($this->getUrl('*/*/testFilters', array('_current' => true)))
43
+ ->setNewFilterUrl($this->getUrl('*/*/newFilterHtml', array('campaign' => $campaign->getId())));
44
+
45
+ $fieldset = $form->addFieldset('conditions_fieldset', array(
46
+ 'legend'=>Mage::helper('salesrule')->__('Only send email to people matching the filters below')
47
+ ))->setRenderer($renderer);
48
+
49
+
50
+
51
+ $fieldset->addField('filters', 'text', array(
52
+ 'name' => 'filters',
53
+ 'label' => $this->__('Filters'),
54
+ 'title' => $this->__('Filters'),
55
+ ))->setCampaign($campaign)
56
+ ->setRenderer(Mage::getBlockSingleton('mzax_emarketing/filters'));
57
+
58
+ $this->setForm($form);
59
+
60
+ return $this;
61
+
62
+
63
+ }
64
+
65
+ /**
66
+ * This method is called before rendering HTML
67
+ *
68
+ * @return Mage_Adminhtml_Block_Widget_Form
69
+ */
70
+ protected function _beforeToHtml()
71
+ {
72
+ return parent::_beforeToHtml();
73
+ }
74
+
75
+
76
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Inbox.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Inbox extends Mzax_Emarketing_Block_Inbox_Grid
25
+ {
26
+
27
+
28
+
29
+ protected function _prepareCollection()
30
+ {
31
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
32
+ $campaign = Mage::registry('current_campaign');
33
+
34
+ $this->getCollection()->addFieldToFilter('campaign_id', $campaign->getId());
35
+ parent::_prepareCollection();
36
+ }
37
+
38
+
39
+
40
+
41
+ protected function _prepareColumns()
42
+ {
43
+ parent::_prepareColumns();
44
+ $this->removeColumn('campaign');
45
+
46
+ }
47
+
48
+
49
+
50
+ public function getGridUrl()
51
+ {
52
+ return $this->getUrl('*/*/bounces', array('_current'=> true));
53
+ }
54
+
55
+ public function getRowUrl($row)
56
+ {
57
+ return $this->getUrl('*/admin_inbox/email', array('id'=>$row->getId()));
58
+ }
59
+
60
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Medium.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Medium extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareLayout()
28
+ {
29
+ parent::_prepareLayout();
30
+ }
31
+
32
+
33
+
34
+ public function initForm()
35
+ {
36
+ $form = new Varien_Data_Form();
37
+ $form->setHtmlIdPrefix('campaign_');
38
+ $form->setFieldNameSuffix('campaign');
39
+
40
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
41
+ $campaign = Mage::registry('current_campaign');
42
+
43
+
44
+
45
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
46
+ ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
47
+
48
+
49
+ /**
50
+ * Campaign
51
+ */
52
+ $fieldset = $form->addFieldset('base_fieldset', array(
53
+ 'legend' => $this->__('Campaign'),
54
+ 'offer' => $this->__('Would you like to send out campaigns using different mediums? <a href="%s" target="_blank">Contact me</a>!', 'http://www.mzax.de/emarketing/mediums.html?utm_source=extension&utm_medium=link&utm_content=choose-medium-footer&utm_campaign=needmore')
55
+ ))->setRenderer($renderer);
56
+
57
+
58
+ $fieldset->addField('name','text', array(
59
+ 'name' => 'name',
60
+ 'required' => true,
61
+ 'label' => $this->__('Campaign Name'),
62
+ 'title' => $this->__('Campaign Name'),
63
+ ));
64
+
65
+
66
+ $fieldset->addField('medium','select', array(
67
+ 'name' => 'medium',
68
+ 'label' => $this->__('Send Medium'),
69
+ 'title' => $this->__('Send Medium'),
70
+ 'values' => Mage::getSingleton('mzax_emarketing/medium')->getAllOptions(false),
71
+ 'note' => $this->__('Which medium would you like to use to send out this campaign?'),
72
+ 'required' => true,
73
+ ));
74
+
75
+
76
+ $form->addValues($campaign->getData());
77
+ $this->setForm($form);
78
+
79
+ return $this;
80
+
81
+
82
+ }
83
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients extends Mage_Adminhtml_Block_Template
25
+ {
26
+
27
+ /**
28
+ * @var Mzax_Emarketing_Model_Campaign
29
+ */
30
+ protected $_campaign;
31
+
32
+
33
+ /**
34
+ * @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid
35
+ */
36
+ protected $_grid;
37
+
38
+
39
+
40
+ public function _construct()
41
+ {
42
+ parent::_construct();
43
+ $this->setTemplate('mzax/emarketing/campaign/recipients.phtml');
44
+ }
45
+
46
+
47
+
48
+ protected function _prepareLayout()
49
+ {
50
+ $emulate = $this->getLayout()->createBlock('mzax_emarketing/campaign_test_emulate');
51
+ $emulate->setTemplate('mzax/emarketing/campaign/filters/emulate.phtml');
52
+
53
+ $grid = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_recipients_grid');
54
+
55
+ $this->setChild('emulate', $emulate);
56
+ $this->setChild('grid', $grid);
57
+ }
58
+
59
+
60
+
61
+
62
+ public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
63
+ {
64
+ $child = $this->getChild('emulate');
65
+ if($child && method_exists($child, 'prepareEmulation')) {
66
+ $child->prepareEmulation($filter);
67
+ }
68
+ }
69
+
70
+
71
+
72
+ /**
73
+ * Retrieve grid
74
+ *
75
+ * @return Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid
76
+ */
77
+ public function getGrid()
78
+ {
79
+ return $this->getChild('grid');
80
+ }
81
+
82
+
83
+
84
+
85
+
86
+ /**
87
+ *
88
+ * @return Mzax_Emarketing_Model_Campaign
89
+ */
90
+ public function getCampaign()
91
+ {
92
+ if(!$this->_campaign) {
93
+ $this->_campaign = Mage::registry('current_campaign');
94
+ }
95
+ return $this->_campaign;
96
+ }
97
+
98
+
99
+
100
+
101
+
102
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients/Grid.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid extends Mzax_Emarketing_Block_Filter_Object_Grid
25
+ {
26
+
27
+ /**
28
+ * @var Mzax_Emarketing_Model_Campaign
29
+ */
30
+ protected $_campaign;
31
+
32
+
33
+
34
+ public function __construct()
35
+ {
36
+ parent::__construct();
37
+ $this->setId('recipients_grid');
38
+ $this->setUseAjax(true);
39
+
40
+ $this->addExportType('*/*/exportRecipients', 'CSV');
41
+ }
42
+
43
+
44
+
45
+ /**
46
+ * @return Mzax_Emarketing_Model_Campaign
47
+ */
48
+ public function getCampaign()
49
+ {
50
+ if(!$this->_campaign) {
51
+ $this->_campaign = Mage::registry('current_campaign');
52
+ }
53
+ return $this->_campaign;
54
+ }
55
+
56
+
57
+
58
+
59
+ public function getFilter()
60
+ {
61
+ $filter = $this->getCampaign()->getRecipientProvider();
62
+ $this->prepareEmulation($filter);
63
+
64
+ return $filter;
65
+ }
66
+
67
+
68
+
69
+ public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
70
+ {
71
+ $parent = $this->getParentBlock();
72
+ if($parent && method_exists($parent, 'prepareEmulation')) {
73
+ $parent->prepareEmulation($filter);
74
+ }
75
+ }
76
+
77
+
78
+
79
+ /**
80
+ * Prepare grid columns
81
+ *
82
+ * This is done by the email provider. The grid
83
+ * does not know what type of objects it is loading
84
+ *
85
+ */
86
+ protected function _prepareColumns()
87
+ {
88
+ parent::_prepareColumns();
89
+
90
+ $this->removeColumn('matches');
91
+ $this->getCampaign()->getMedium()->prepareRecipientGrid($this);
92
+
93
+ return $this;
94
+ }
95
+
96
+
97
+
98
+ public function getGridUrl()
99
+ {
100
+ return $this->getUrl('*/*/*', array('_current' => true));
101
+ }
102
+
103
+
104
+
105
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Report.php ADDED
@@ -0,0 +1,767 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Block_Widget
34
+ {
35
+
36
+
37
+ /**
38
+ *
39
+ * @var Mzax_Emarketing_Model_Campaign
40
+ */
41
+ protected $_campaign;
42
+
43
+
44
+ protected $_dateRange;
45
+
46
+
47
+
48
+
49
+ protected function _construct()
50
+ {
51
+ parent::_construct();
52
+
53
+ $this->setId('campaign_report_tab');
54
+ $this->setTemplate('mzax/emarketing/campaign/report.phtml');
55
+ }
56
+
57
+
58
+
59
+ /**
60
+ * Retrieve campaign
61
+ *
62
+ * @return Mzax_Emarketing_Model_Campaign
63
+ */
64
+ public function getCampaign()
65
+ {
66
+ if(!$this->_campaign) {
67
+ $this->_campaign = Mage::registry('current_campaign');
68
+ }
69
+ return $this->_campaign;
70
+ }
71
+
72
+
73
+ /**
74
+ * Set campaign
75
+ *
76
+ * @param Mzax_Emarketing_Model_Campaign $campaign
77
+ * @return Mzax_Emarketing_Block_Campaign_Edit_Tab_Report
78
+ */
79
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
80
+ {
81
+ $this->_campaign = $campaign;
82
+ return $this;
83
+ }
84
+
85
+
86
+
87
+ /**
88
+ * Has campaign any trackers
89
+ *
90
+ * @return boolean
91
+ */
92
+ public function hasTracker()
93
+ {
94
+ return (bool) count($this->getCampaign()->getTrackers());
95
+ }
96
+
97
+
98
+
99
+
100
+ /**
101
+ * Query report data tables
102
+ *
103
+ * @param string $dimension
104
+ * @param array $metrics
105
+ * @param boolean $variation
106
+ * @return Mzax_Emarketing_Model_Report_Query
107
+ */
108
+ public function queryReport($dimension, $metrics, $variations, $order = null)
109
+ {
110
+ $query = $this->getCampaign()->queryReport($dimension, $metrics, $variations, $order);
111
+ $query->setParam('date_range', $this->getDateRange());
112
+
113
+ return $query;
114
+ }
115
+
116
+
117
+
118
+ /**
119
+ * Retrieve date range from request
120
+ *
121
+ * @return boolean|array
122
+ */
123
+ public function getDateRange()
124
+ {
125
+ if($this->_dateRange === null) {
126
+ $validator = new Zend_Validate_Date;
127
+
128
+ $from = $this->getRequest()->getParam('from');
129
+ $to = $this->getRequest()->getParam('to');
130
+
131
+ if($validator->isValid($from) && $validator->isValid($to)) {
132
+ $this->_dateRange = array($from, $to);
133
+ }
134
+ else {
135
+ $this->_dateRange = false;
136
+ }
137
+ }
138
+ return $this->_dateRange;
139
+ }
140
+
141
+
142
+
143
+ /**
144
+ * Retreive query from local cache or create new
145
+ *
146
+ * @param string $key
147
+ * @param string $dimension
148
+ * @param array $metrics
149
+ * @param boolean $variation
150
+ * @return Mzax_Emarketing_Model_Report_Query
151
+ */
152
+ public function getCachedQuery($key, $dimension, $metrics, $variations, $order = null)
153
+ {
154
+ $query = $this->getData('query_' . $key);
155
+ if(!$query) {
156
+ $query = $this->queryReport($dimension, $metrics, $variations, $order);
157
+ $this->setData('query_' . $key, $query);
158
+ }
159
+ return $query;
160
+ }
161
+
162
+
163
+
164
+
165
+
166
+ /**
167
+ *
168
+ * @return Mzax_Emarketing_Model_Report_Query
169
+ */
170
+ public function getTotals()
171
+ {
172
+ return $this->getCachedQuery('totals', 'campaign', array('sendings', 'views', 'clicks', 'bounces', 'optouts', 'conversion' => '#?'), false);
173
+ }
174
+
175
+
176
+
177
+
178
+
179
+
180
+ public function getTotal()
181
+ {
182
+ return (int) $this->getTotals()->getCell('sendings');
183
+ }
184
+
185
+
186
+ const COLOR_BLANK = 'E7EFEF';
187
+ const COLOR_SENDINGS = '899DA8';
188
+ const COLOR_VIEWS = '159FC4';
189
+ const COLOR_CLICKS = 'D7D020';
190
+ const COLOR_ORDERS = 'A9C200';
191
+ const COLOR_CONVERSIONS = 'A9C200';
192
+ const COLOR_OPTOUT = 'BF3A3A';
193
+ const COLOR_BOUNDS = '712B2B';
194
+
195
+
196
+
197
+
198
+
199
+ /**
200
+ * Prepare chart data table by providing correct
201
+ * column lables and colors
202
+ *
203
+ * @param Mzax_Chart_Table $table
204
+ */
205
+ public function prepareTable(Mzax_Chart_Table $table)
206
+ {
207
+ $variations = $table->getTableProperty('variations');
208
+ $dimension = $table->getTableProperty('dimension');
209
+
210
+ foreach($table->getColumns() as $column) {
211
+ if(isset($column->p->metric)) {
212
+ switch($column->p->metric) {
213
+ case 'sendings':
214
+ $column->label = $this->__('Recipients');
215
+ $column->p->color = self::COLOR_SENDINGS;
216
+ break;
217
+ case 'views':
218
+ case 'view_rate':
219
+ $column->label = $this->__('Views');
220
+ $column->p->color = self::COLOR_VIEWS;
221
+ break;
222
+ case 'clicks':
223
+ case 'click_rate':
224
+ $column->label = $this->__('Clicks');
225
+ $column->p->color = self::COLOR_CLICKS;
226
+ break;
227
+ case 'bounces':
228
+ case 'bounce_rate':
229
+ $column->label = $this->__('Bounces');
230
+ $column->p->color = self::COLOR_BOUNDS;
231
+ break;
232
+ case 'optouts':
233
+ case 'optout_rate':
234
+ $column->label = $this->__('Optouts');
235
+ $column->p->color = self::COLOR_OPTOUT;
236
+ break;
237
+ }
238
+ }
239
+ if(isset($column->p->tracker_id)) {
240
+ $tracker = $this->getCampaign()->getTracker($column->p->tracker_id);
241
+ if($tracker) {
242
+ $column->label = $tracker->getTitle();
243
+ }
244
+ else {
245
+ $column->label = $this->__('Tracker (%s)', $column->p->tracker_id);
246
+ }
247
+ $column->p->color = self::COLOR_CLICKS;
248
+ }
249
+
250
+ if(isset($column->p->color)) {
251
+ $column->p->color_axis = array($this->brightness($column->p->color, 80), $this->brightness($column->p->color, -80));
252
+ }
253
+
254
+ if(isset($column->p->variation_id)) {
255
+ $vid = $column->p->variation_id;
256
+
257
+ $index = array_search($vid, $variations);
258
+
259
+ $gradient = $this->gradient(
260
+ $this->brightness($column->p->color, -100),
261
+ $this->brightness($column->p->color, 20),
262
+ count($variations));
263
+
264
+ $column->p->color = $gradient[$index];
265
+
266
+ $variation = $this->getCampaign()->getVariation($vid);
267
+ if($variation) {
268
+ $column->label = $variation->getName();
269
+ }
270
+ else {
271
+ $column->label = $this->__('Variation (%s)', $vid);
272
+ }
273
+ }
274
+ }
275
+
276
+ if($dimension !== 'date') {
277
+ $colors = array('627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277','627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277','627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277','627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277');
278
+
279
+ //$table->addColumn('style', Mzax_Chart_Table::TYPE_STRING, 'style', array('role' => 'style'));
280
+ foreach($colors as $row => $color) {
281
+ $table->setRowProperty($row, 'color', $color);
282
+ }
283
+ $table->setTableProperty('dye', true);
284
+ }
285
+
286
+
287
+ switch(strtolower($dimension)) {
288
+ case 'hour':
289
+ $table->setColumnType(0, Mzax_Chart_Table::TYPE_TIME);
290
+ $table->setTableProperty('stacked', true);
291
+ $table->setTableProperty('dye', false);
292
+ break;
293
+ case 'dayofweek':
294
+ $table->setTableProperty('stacked', false);
295
+ $table->setTableProperty('dye', false);
296
+ break;
297
+ }
298
+
299
+
300
+ }
301
+
302
+ protected function gradient($start, $end, $steps)
303
+ {
304
+ $steps = max($steps, 2);
305
+ $start = array_map('hexdec', str_split($start, 2));
306
+ $end = array_map('hexdec', str_split($end, 2));
307
+
308
+ foreach($start as $j => $v) {
309
+ $step[$j] = ($v - $end[$j]) / ($steps-1);
310
+ }
311
+
312
+ $colors = array();
313
+ for($i = 0; $i <= $steps; $i++) {
314
+ $rgb = array();
315
+ foreach($step as $j => $v) {
316
+ $rgb[$j] = sprintf('%02x', floor($start[$j] - $v * $i));
317
+ }
318
+ $colors[] = implode('', $rgb);
319
+ }
320
+ return $colors;
321
+ }
322
+
323
+
324
+
325
+ protected function brightness($color, $adjust)
326
+ {
327
+ $rgb = array_map('hexdec', str_split($color, 2));
328
+ foreach($rgb as &$v) {
329
+ $v = sprintf('%02x', max(0,min(255,$v + $adjust)));
330
+ }
331
+ return implode('', $rgb);
332
+ }
333
+
334
+
335
+
336
+
337
+
338
+
339
+ protected function getGoogleJs()
340
+ {
341
+ $locale = Mage::app()->getLocale()->getLocaleCode();
342
+
343
+ $js = <<<JS
344
+ <script type="text/javascript" src="https://www.google.com/jsapi"></script>
345
+ <script type="text/javascript">
346
+ google.load("visualization", "1", {packages:["corechart"], language:'$locale'});
347
+ </script>
348
+ JS;
349
+ return $this->getLayout()
350
+ ->createBlock('core/text')->setText($js);
351
+ }
352
+
353
+
354
+
355
+
356
+ protected function _beforeToHtml()
357
+ {
358
+ parent::_beforeToHtml();
359
+
360
+
361
+ $views = $this->createCircle('viewes', $this->getTotals()->getCell('views'), self::COLOR_VIEWS);
362
+ $clicks = $this->createCircle('clicks', $this->getTotals()->getCell('clicks'), self::COLOR_CLICKS);
363
+ $orders = $this->createCircle('orders', $this->getTotals()->getCell('conversion'), self::COLOR_CONVERSIONS);
364
+
365
+ $optout = $this->createCircle('orders', $this->getTotals()->getSum('bounces', 'optouts'));
366
+ $optout->setColors(array(self::COLOR_OPTOUT, self::COLOR_BOUNDS, self::COLOR_BLANK));
367
+ $optout->clearRows();
368
+ $optout->addRow(array('optout', $this->getTotals()->getCell('optouts')));
369
+ $optout->addRow(array('bounce', $this->getTotals()->getCell('bounces')));
370
+ $optout->addRow(array('', $this->getTotal() - $this->getTotals()->getSum('bounces', 'optouts')));
371
+
372
+ $this->setViewsCircle($views);
373
+ $this->setClicksCircle($clicks);
374
+ $this->setOrdersCircle($orders);
375
+ $this->setOptoutCircle($optout);
376
+
377
+
378
+ }
379
+
380
+
381
+
382
+
383
+ protected function _prepareLayout()
384
+ {
385
+ /* @var $content Mage_Core_Block_Text_List */
386
+ $content = $this->getLayout()->getBlock('content');
387
+ if($content) {
388
+ $content->append($this->getGoogleJs());
389
+ }
390
+ }
391
+
392
+
393
+
394
+
395
+
396
+ public function getConversionBlock()
397
+ {
398
+ $query = $this->getCachedQuery('conversion', 'date', 'view_rate', false);
399
+
400
+ /* @var $block Mzax_Emarketing_Block_Chart_Widget_Tab */
401
+ $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_tab');
402
+ $block->setType('line');
403
+ $block->getChart()->setCurveType('function');
404
+ $block->setQuery($query);
405
+
406
+ $this->prepareTabs($block, '%s_rate', array('views', 'clicks', 'trackers', 'outputs', 'bounces'));
407
+ $this->prepareTable($block->getTable());
408
+
409
+ return $block;
410
+ }
411
+
412
+
413
+
414
+
415
+ /**
416
+ *
417
+ * @return Mzax_Emarketing_Block_Chart_Widget_Tab
418
+ */
419
+ public function getActivityBlock()
420
+ {
421
+ $query = $this->getCachedQuery('activity', 'date', 'sendings', false);
422
+
423
+ /* @var $block Mzax_Emarketing_Block_Chart_Widget_Tab */
424
+ $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_tab');
425
+ $block->setType('column');
426
+ $block->setQuery($query);
427
+
428
+
429
+ $this->prepareTabs($block, '%ss', null);
430
+ $this->prepareTable($block->getTable());
431
+ return $block;
432
+ }
433
+
434
+
435
+
436
+
437
+
438
+ /**
439
+ *
440
+ * @return Mzax_Emarketing_Block_Chart_Widget_Tab
441
+ */
442
+ public function getDimensionPie($dimension, $tabs = array('views', 'clicks'))
443
+ {
444
+ $query = $this->getCachedQuery('dimension_'.$dimension, $dimension, 'views', false , 1);
445
+
446
+
447
+ /* @var $block Mzax_Emarketing_Block_Chart_Widget_Tab */
448
+ $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_tab');
449
+ $block->setCampaign($this->getCampaign());
450
+ $block->setType('pie');
451
+ $block->setQuery($query);
452
+ $block->getChart()->setChartArea(array(
453
+ 'top' => '5%',
454
+ 'right' => '5%',
455
+ 'bottom' => '5%',
456
+ 'left' => '5%',
457
+ 'width' => '90%',
458
+ 'height' => '90%'
459
+ ));
460
+ $block->getChart()->setPieHole(0.25);
461
+
462
+
463
+ $block->getChart()->setLegend(array(
464
+ 'position' => 'left',
465
+ 'alignment' => 'center'
466
+ ));
467
+
468
+ $this->prepareTabs($block, '%ss', $tabs);
469
+ $this->prepareTable($block->getTable());
470
+ return $block;
471
+ }
472
+
473
+
474
+
475
+ /**
476
+ *
477
+ * @return Mzax_Emarketing_Block_Chart_Widget_Tab
478
+ */
479
+ public function getDimensionChart($dimension, $charType = 'column', $tabs = null)
480
+ {
481
+ $query = $this->getCachedQuery('dimension_'.$dimension, $dimension, 'views', false);
482
+
483
+ /* @var $block Mzax_Emarketing_Block_Chart_Widget_Tab */
484
+ $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_tab');
485
+ $block->setCampaign($this->getCampaign());
486
+ $block->setType($charType);
487
+ $block->setQuery($query);
488
+ $block->getChart()->setChartArea(array(
489
+ 'top' => '0%',
490
+ 'right' => '0%',
491
+ 'bottom' => '0%',
492
+ 'left' => '0%',
493
+ 'width' => '100%',
494
+ 'height' => '100%'
495
+ ));
496
+
497
+ if($charType === 'geo') {
498
+ $block->getChart()->setHeight(400);
499
+ }
500
+
501
+ $this->prepareTabs($block, '%ss', $tabs);
502
+ $this->prepareTable($block->getTable());
503
+ return $block;
504
+ }
505
+
506
+
507
+
508
+ protected function prepareTabs(Mzax_Emarketing_Block_Chart_Widget_Tab $block, $metric = "%ss", $tabs = null)
509
+ {
510
+ if(!$tabs || in_array('sendings', $tabs)) {
511
+ $block->addTab('sendings', array(
512
+ 'label' => $this->__('Sendings'),
513
+ 'metric' => sprintf($metric, 'sending')
514
+ ));
515
+ }
516
+
517
+ if(!$tabs || in_array('views', $tabs)) {
518
+ $block->addTab('views', array(
519
+ 'label' => $this->__('Views'),
520
+ 'metric' => sprintf($metric, 'view')
521
+ ));
522
+ }
523
+
524
+ if(!$tabs || in_array('clicks', $tabs)) {
525
+ $block->addTab('clicks', array(
526
+ 'label' => $this->__('Clicks'),
527
+ 'metric' => sprintf($metric, 'click')
528
+ ));
529
+ }
530
+
531
+ if($this->hasTracker()) {
532
+ if(!$tabs || in_array('trackers', $tabs)) {
533
+ $trackers = array();
534
+ foreach($this->getCampaign()->getTrackers() as $tracker) {
535
+ $trackers[sprintf($metric, '#'.$tracker->getId())] = $tracker->getTitle();
536
+ }
537
+ if($tracker = $this->getCampaign()->getDefaultTracker()) {
538
+ $block->addTab('trackers', array(
539
+ 'label' => $tracker->getTitle(),
540
+ 'default' => sprintf($metric, '#'.$tracker->getId()),
541
+ 'metric' => $trackers
542
+ ));
543
+ }
544
+ }
545
+ }
546
+
547
+ if($tabs && in_array('optouts/bounces', $tabs)) {
548
+ $block->addTab('optouts', array(
549
+ 'label' => $this->__('Optouts'),
550
+ 'default' => 'optouts',
551
+ 'metric' => array(
552
+ sprintf($metric, 'optout') => $this->__('Optouts'),
553
+ sprintf($metric, 'bounce') => $this->__('Bounces'),
554
+ )
555
+ ));
556
+ }
557
+
558
+ if(!$tabs || in_array('optouts', $tabs)) {
559
+ $block->addTab('optouts', array(
560
+ 'label' => $this->__('Optouts'),
561
+ 'metric' => sprintf($metric, 'optout')
562
+ ));
563
+ }
564
+
565
+ if(!$tabs || in_array('bounces', $tabs)) {
566
+ $block->addTab('bounces', array(
567
+ 'label' => $this->__('Bounces'),
568
+ 'metric' => sprintf($metric, 'bounce')
569
+ ));
570
+ }
571
+ }
572
+
573
+
574
+
575
+
576
+
577
+
578
+ /**
579
+ *
580
+ * @return Mzax_Emarketing_Block_Chart_Widget_Tab
581
+ */
582
+ public function getGeoChart()
583
+ {
584
+ $query = $this->getCachedQuery('dimension_country', 'country', 'views', false);
585
+
586
+ /* @var $block Mzax_Emarketing_Block_Chart_Widget_Geo */
587
+ $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_geo');
588
+ $block->setQuery($query);
589
+
590
+ $this->prepareTabs($block, '%ss', array('views', 'clicks'));
591
+ $this->prepareTable($block->getTable());
592
+ return $block;
593
+ }
594
+
595
+
596
+
597
+
598
+ /**
599
+ *
600
+ * @return Mzax_Emarketing_Block_Chart_Widget_Tab
601
+ */
602
+ public function getRevenueChart($type = '', $chartType = 'area')
603
+ {
604
+ $type = $type ? '_revenue_'.$type : '_revenue';
605
+
606
+ $tracker = $this->getCampaign()->getDefaultTracker();
607
+
608
+ $query = $this->getCachedQuery($type, 'date', '#'.$tracker->getId(). $type, false);
609
+
610
+ /* @var $block Mzax_Emarketing_Block_Chart_Widget_Tab */
611
+ $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_tab');
612
+ $block->setType($chartType);
613
+ $block->setQuery($query);
614
+
615
+ foreach($this->getCampaign()->getTrackers() as $tracker) {
616
+ $block->addTab('tracker_'.$tracker->getId(), array(
617
+ 'class' => 'trackers',
618
+ 'label' => $tracker->getTitle(),
619
+ 'metric' => '#'.$tracker->getId(). $type
620
+ ));
621
+ }
622
+
623
+ $this->prepareTable($block->getTable());
624
+ return $block;
625
+ }
626
+
627
+
628
+
629
+
630
+
631
+
632
+ public function createCircle($label = '', $value = 0, $color = 'EA7601')
633
+ {
634
+ $total = $this->getTotal();
635
+
636
+ $percentage = $total ? round(($value/$total)*100,1) : 0;
637
+
638
+ $chart = $this->createChart('pie');
639
+ $chart->setColors(array($color, 'E7EFEF'));
640
+ $chart->setPieHole(0.8);
641
+ $chart->setChartArea(array(
642
+ 'top' => '10%',
643
+ 'right' => '10%',
644
+ 'bottom' => '10%',
645
+ 'left' => '10%',
646
+ 'width' => '80%',
647
+ 'height' => '80%'
648
+ ));
649
+
650
+ $chart->setEnableInteractivity(false);
651
+ $chart->setPieSliceText('none');
652
+ $chart->setLegend('none');
653
+ $chart->setWidth(80);
654
+ $chart->setHeight(80);
655
+ $chart->setTitle($label);
656
+ $chart->setAutoRedraw(false);
657
+ $chart->setAutoRedraw(false);
658
+ $chart->addOverlay('percentage', "{$percentage}%");
659
+ $chart->addColumn('Label', 'string');
660
+ $chart->addColumn('Values', 'number');
661
+
662
+ $chart->addRow(array($label, $value));
663
+ $chart->addRow(array('', max(0,$total-$value)));
664
+
665
+ $chart->setValue($value);
666
+ $chart->setLabel($label);
667
+
668
+ return $chart;
669
+ }
670
+
671
+
672
+
673
+ /**
674
+ * Create chart type
675
+ *
676
+ * @param string $type
677
+ * @return Mzax_Emarketing_Block_Chart_Abstract
678
+ */
679
+ public function createChart($type)
680
+ {
681
+ $block = 'mzax_emarketing/chart_' . $type;
682
+
683
+ /* @var $chart Mzax_Emarketing_Block_Chart_Abstract */
684
+ $chart = $this->getLayout()->createBlock($block);
685
+
686
+ return $chart;
687
+
688
+ }
689
+
690
+
691
+
692
+ /**
693
+ * Retrieve GeoIP credits
694
+ *
695
+ * @return array
696
+ */
697
+ public function getGeoIpCredits()
698
+ {
699
+ $adapters = Mage::getSingleton('mzax_emarketing/system_config_source_geoIp')->getSelectedAdapters();
700
+ $credits = array();
701
+
702
+ $geoLiteCredit = 'GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.';
703
+ $geoLite = false;
704
+ /* @var $adapter Mzax_GeoIp_Adapter_Abstract */
705
+ foreach($adapters as $adapter) {
706
+ $credit = $adapter->getCredits();
707
+ if($credit) {
708
+ if(strpos($credit, $geoLiteCredit)) {
709
+ $geoLite = true;
710
+ $credit = str_replace($geoLiteCredit, 'GeoLite*', $credit);
711
+ }
712
+ $credits[] = $credit;
713
+ }
714
+ }
715
+
716
+ if($geoLite) {
717
+ $credits[] = '*' . $geoLiteCredit;
718
+ }
719
+
720
+ return $credits;
721
+ }
722
+
723
+
724
+
725
+ /**
726
+ * Retrieve Varien Data Form
727
+ *
728
+ * @return Varien_Data_Form
729
+ */
730
+ public function getForm()
731
+ {
732
+ $elementRenderer = Mage::getBlockSingleton('mzax_emarketing/editable');
733
+ $elementRenderer->setFormat('form');
734
+
735
+ $form = new Varien_Data_Form();
736
+ $form->setElementRenderer($elementRenderer);
737
+ return $form;
738
+ }
739
+
740
+
741
+
742
+ /**
743
+ * Helper for simple select element
744
+ *
745
+ * @param string $key
746
+ * @param array $options
747
+ * @return Varien_Data_Form_Element_Abstract
748
+ */
749
+ public function getDateElement($key, $default = null)
750
+ {
751
+ $format = Varien_Date::DATE_INTERNAL_FORMAT;
752
+ $value = $this->getRequest()->getParam($key, '');
753
+
754
+ return $this->getForm()->addField($key, 'date',array(
755
+ 'name' => $key,
756
+ 'value_name' => $value,
757
+ 'value' => $value,
758
+ 'explicit_apply' => true,
759
+ 'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
760
+ 'input_format' => $format,
761
+ 'format' => $format
762
+ ))->setId('report_'.$key);
763
+ }
764
+
765
+
766
+
767
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Settings.php ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareLayout()
28
+ {
29
+ parent::_prepareLayout();
30
+ }
31
+
32
+
33
+
34
+ public function initForm()
35
+ {
36
+ $form = new Varien_Data_Form();
37
+ $form->setHtmlIdPrefix('campaign_');
38
+ $form->setFieldNameSuffix('campaign');
39
+
40
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
41
+ $campaign = Mage::registry('current_campaign');
42
+
43
+ $outputFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
44
+
45
+ /**
46
+ * Campaign
47
+ */
48
+ $fieldset = $form->addFieldset('base_fieldset', array(
49
+ 'legend' => $this->__('Campaign'),
50
+ 'offer' => $this->__('Would you like to send to different recipients? <a href="%s" target="_blank">Contact me</a>!', 'http://www.mzax.de/emarketing/recipients.html?utm_source=extension&utm_medium=link&utm_content=campaign-settings&utm_campaign=needmore'),
51
+ 'continue' => false
52
+ ));
53
+
54
+ if(!$campaign->getId()) {
55
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
56
+ ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
57
+ $fieldset->setRenderer($renderer);
58
+ }
59
+
60
+
61
+
62
+ $fieldset->addField('name','text', array(
63
+ 'name' => 'name',
64
+ 'required' => true,
65
+ 'label' => $this->__('Campaign Name'),
66
+ 'title' => $this->__('Campaign Name'),
67
+ ));
68
+
69
+
70
+ $fieldset->addField('medium','hidden', array(
71
+ 'name' => 'medium'
72
+ ));
73
+
74
+
75
+
76
+ // @todo disable if it has reci
77
+ $fieldset->addField('provider','select', array(
78
+ 'name' => 'provider',
79
+ 'label' => $this->__('Campaign Recipient'),
80
+ 'title' => $this->__('Campaign Recipient'),
81
+ 'values' => $campaign->getAvailableProviders(false),
82
+ 'note' => $this->__("Who are the recipients of this campaign"),
83
+ 'disabled' => (bool) $campaign->getId(),
84
+ 'required' => true,
85
+ ));
86
+
87
+
88
+ $fieldset->addField('store_id', 'select', array(
89
+ 'name' => 'store_id',
90
+ 'label' => $this->__('Sender Store'),
91
+ 'title' => $this->__('Sender Store'),
92
+ 'values' => Mage::getModel('adminhtml/system_config_source_store')->toOptionArray(),
93
+ 'required' => true,
94
+ ));
95
+
96
+
97
+ $fieldset->addField('start_at','date',array(
98
+ 'name' => 'start_at',
99
+ 'time' => true,
100
+ 'style' => 'width:60%;',
101
+ 'format' => $outputFormat,
102
+ 'label' => $this->__('Date Start'),
103
+ 'image' => $this->getSkinUrl('images/grid-cal.gif')
104
+ ));
105
+ $fieldset->addField('end_at','date',array(
106
+ 'name' => 'end_at',
107
+ 'time' => true,
108
+ 'style' => 'width:60%;',
109
+ 'format' => $outputFormat,
110
+ 'label' => $this->__('Date End'),
111
+ 'image' => $this->getSkinUrl('images/grid-cal.gif')
112
+ ));
113
+
114
+
115
+
116
+ if($campaign->getId()) {
117
+ /*
118
+ $fieldset->addField('running', 'select', array(
119
+ 'label' => $this->__('Running'),
120
+ 'title' => $this->__('Running'),
121
+ 'name' => 'running',
122
+ 'required' => true,
123
+ 'options' => array(
124
+ '1' => $this->__('Yes'),
125
+ '0' => $this->__('No'),
126
+ ),
127
+ 'value' => '1'
128
+ ));
129
+ */
130
+
131
+
132
+ /**
133
+ * Ab Test
134
+ */
135
+ $abtestFieldset = $form->addFieldset('abtest', array(
136
+ 'note' => "If enabled, the user will be logged in if possible.",
137
+ 'legend' => $this->__('AB Testing'),
138
+ ));
139
+
140
+
141
+ $abtestFieldset->addField('abtest_enable', 'select', array(
142
+ 'label' => $this->__('Enabled'),
143
+ 'title' => $this->__('Enabled'),
144
+ 'name' => 'abtest_enable',
145
+ 'required' => true,
146
+ 'options' => array(
147
+ '0' => $this->__('No'),
148
+ '1' => $this->__('Yes')
149
+ ),
150
+ 'value' => '0'
151
+ ));
152
+
153
+ $abtestFieldset->addField('abtest_traffic', 'text', array(
154
+ 'name' => 'abtest_traffic',
155
+ 'label' => $this->__('Traffic Percentage'),
156
+ 'title' => $this->__('Traffic Percentage'),
157
+ 'required' => true,
158
+ 'value' => '100'
159
+ ));
160
+
161
+
162
+
163
+
164
+ /**
165
+ * Campaign
166
+ */
167
+ $advanced = $form->addFieldset('advanced_fieldset',
168
+ array('legend'=>$this->__('Advanced Settings'))
169
+ );
170
+
171
+
172
+ $advanced->addField('autologin', 'select', array(
173
+ 'label' => $this->__('Autologin'),
174
+ 'title' => $this->__('Autologin'),
175
+ 'note' => $this->__("If enabled, the user will be logged in if possible."),
176
+ 'name' => 'autologin',
177
+ 'required' => true,
178
+ 'options' => array(
179
+ '1' => $this->__('Enabled'),
180
+ '0' => $this->__('Disabled'),
181
+ ),
182
+ 'value' => '1'
183
+ ));
184
+
185
+
186
+
187
+
188
+ $advanced->addField('check_frequency', 'select', array(
189
+ 'label' => $this->__('Check Frequency'),
190
+ 'title' => $this->__('Check Frequency'),
191
+ 'name' => 'check_frequency',
192
+ 'required' => true,
193
+ 'options' => array(
194
+ '1440' => $this->__('Once a day'),
195
+ '720' => $this->__('Twice a day'),
196
+ '360' => $this->__('Every 6 hours'),
197
+ '180' => $this->__('Every 3 hours'),
198
+ '60' => $this->__('Every hour'),
199
+ '30' => $this->__('Every 30 minutes'),
200
+ '1' => $this->__('Every time'),
201
+ '0' => $this->__('Never automatically'),
202
+ ),
203
+ 'value' => '720',
204
+ 'note' => $this->__("How often to check for new recipients, e.g. Birthdays will do once a day, while abandon carts need to check all the time."),
205
+ ));
206
+
207
+
208
+
209
+ $advanced->addField('min_resend_interval', 'select', array(
210
+ 'label' => $this->__('Minimum Resend Interval'),
211
+ 'title' => $this->__('Minimum Resend Interval'),
212
+ 'name' => 'min_resend_interval',
213
+ 'required' => true,
214
+ 'options' => array(
215
+ '0' => $this->__('[Only send once]'),
216
+ '1' => $this->__('One day'),
217
+ '2' => $this->__('Two days'),
218
+ '7' => $this->__('One week'),
219
+ '14' => $this->__('Two weeks'),
220
+ '31' => $this->__('1 month'),
221
+ '62' => $this->__('2 months'),
222
+ '91' => $this->__('3 months'),
223
+ '122' => $this->__('4 months'),
224
+ '152' => $this->__('5 months'),
225
+ '183' => $this->__('6 months'),
226
+ '274' => $this->__('9 months'),
227
+ '364' => $this->__('12 months')
228
+ ),
229
+ 'value' => '0',
230
+ 'note' => $this->__("The minimum time before a recipient can recieve this campaign again."),
231
+ ));
232
+
233
+
234
+
235
+ $advanced->addField('expire_time', 'select', array(
236
+ 'name' => 'expire_time',
237
+ 'label' => $this->__('Expire Time'),
238
+ 'options' => array(
239
+ '15' => $this->__('15 minutes'),
240
+ '30' => $this->__('Half an hour'),
241
+ '60' => $this->__('One hour'),
242
+ '120' => $this->__('Two hours'),
243
+ '180' => $this->__('Three hours'),
244
+ '720' => $this->__('6 hours'),
245
+ '1440' => $this->__('12 hours'),
246
+ '1440' => $this->__('One day'),
247
+ '2880' => $this->__('Two days'),
248
+ '7200' => $this->__('5 days'),
249
+ '10080' => $this->__('One week'),
250
+ '20160' => $this->__('Two weeks'),
251
+ '87658' => $this->__('One month'),
252
+ '0' => $this->__('Never expire')
253
+ ),
254
+ 'required' => true,
255
+ 'value' => '120',
256
+ 'note' => $this->__("When an recipient is queued things can get delayed do to technical issue, domain throttling or other things. You can define an expire time so that if the message has not been sent in the given time frame, don’t send it anymore."),
257
+ ));
258
+
259
+
260
+
261
+
262
+ $advanced->addField('identity','select', array(
263
+ 'name' => 'identity',
264
+ 'label' => $this->__('Email Sender'),
265
+ 'title' => $this->__('Email Sender'),
266
+ 'values' => Mage::getModel('adminhtml/system_config_source_email_identity')->toOptionArray(),
267
+ 'required' => true,
268
+ 'note' => $this->__("The sender identity to use when sending out the emails. Keep in mind that email bounces will get send back to that email address in case you have defined an inbox to check.")
269
+ ));
270
+
271
+
272
+
273
+ $trackers = Mage::getResourceSingleton('mzax_emarketing/conversion_tracker_collection')->toOptionArray();
274
+
275
+ array_unshift($trackers, array('value' => '0', 'label' => $this->__("Use Config Default Tracker")));
276
+
277
+
278
+ $advanced->addField('default_tracker_id','select', array(
279
+ 'name' => 'default_tracker_id',
280
+ 'label' => $this->__('Default Conversion Tracker'),
281
+ 'title' => $this->__('Default Conversion Tracker'),
282
+ 'values' => $trackers,
283
+ 'required' => true,
284
+ ));
285
+
286
+ } // has id
287
+
288
+
289
+ if($medium = $campaign->getMedium()) {
290
+ $medium->initSettingsForm($form, $campaign);
291
+ $form->addValues($campaign->getMediumData()->getData());
292
+ }
293
+
294
+
295
+
296
+ $form->addValues($campaign->getData());
297
+ $this->setForm($form);
298
+
299
+ return $this;
300
+
301
+
302
+ }
303
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Tasks.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Tasks extends Mage_Adminhtml_Block_Template
25
+ {
26
+
27
+ protected function _prepareLayout()
28
+ {
29
+ parent::_prepareLayout();
30
+ $this->setTemplate('mzax/emarketing/campaign/tasks.phtml');
31
+ }
32
+
33
+
34
+ /**
35
+ *
36
+ * @return Mzax_Emarketing_Model_Campaign
37
+ */
38
+ public function getCampaign()
39
+ {
40
+ return Mage::registry('current_campaign');
41
+ }
42
+
43
+
44
+
45
+ /**
46
+ * Retrieve action url
47
+ *
48
+ * @return string
49
+ */
50
+ public function getActionUrl($action)
51
+ {
52
+ return $this->getUrl('*/*/' . $action, array(
53
+ 'id' => $this->getCampaign()->getId()
54
+ ));
55
+ }
56
+
57
+
58
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Test.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
25
+ {
26
+
27
+
28
+ /**
29
+ * Retrieve filter
30
+ *
31
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
32
+ */
33
+ public function getFilter()
34
+ {
35
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
36
+ $campaign = Mage::registry('current_campaign');
37
+ return $campaign->getRecipientProvider()->getFilter();
38
+ }
39
+
40
+
41
+
42
+
43
+
44
+
45
+ /**
46
+ * Generate url by route and parameters
47
+ *
48
+ * @param string $route
49
+ * @param array $params
50
+ * @return string
51
+ */
52
+ public function getUrl($route = '', $params = array())
53
+ {
54
+ $params['campaign'] = $this->getCampaign()->getId();
55
+ return parent::getUrl($route, $params);
56
+ }
57
+
58
+
59
+
60
+
61
+ /**
62
+ * Retrieve current campaign
63
+ *
64
+ * @return Mzax_Emarketing_Model_Campaign
65
+ */
66
+ public function getCampaign()
67
+ {
68
+ return Mage::registry('current_campaign');
69
+ }
70
+
71
+
72
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tabs.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setId('mzax_emarketing_info_tabs');
31
+ $this->setDestElementId('edit_form');
32
+ $this->setTitle($this->__('Setup Campaign'));
33
+ }
34
+
35
+ protected function _beforeToHtml()
36
+ {
37
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
38
+ $campaign = Mage::registry('current_campaign');
39
+
40
+
41
+
42
+ if(!$campaign->getMedium()) {
43
+ $this->addTab('medium', array(
44
+ 'label' => $this->__('Choose Medium'),
45
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_medium')->initForm()->toHtml(),
46
+ 'active' => true
47
+ ));
48
+ }
49
+ else {
50
+
51
+ $mediumTitle = Mage::getSingleton('mzax_emarketing/medium')->getOptionText($campaign->getData('medium'));
52
+ if($campaign->getId()) {
53
+ $this->setTitle($this->__('%s Campaign', $mediumTitle));
54
+ }
55
+ else {
56
+ $this->setTitle($this->__('New %s Campaign', $mediumTitle));
57
+ }
58
+
59
+
60
+ $this->addTab('settings', array(
61
+ 'label' => $this->__('Settings'),
62
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_settings')->initForm()->toHtml(),
63
+ 'active' => true
64
+ ));
65
+
66
+
67
+ $this->addTab('content', array(
68
+ 'label' => $this->__('Content'),
69
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_content')->toHtml(),
70
+ 'active' => false
71
+ ));
72
+
73
+ // only available if saved
74
+ if($campaign->getId())
75
+ {
76
+
77
+ $this->addTab('filters', array(
78
+ 'label' => $this->__('Filters'),
79
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_filters')->initForm()->toHtml(),
80
+ 'active' => false
81
+ ));
82
+ $this->addTab('recipients', array(
83
+ 'label' => $this->__('Find Recipients'),
84
+ 'class' => 'ajax',
85
+ 'url' => $this->getUrl('*/*/recipients', array('_current' => true)),
86
+ ));
87
+
88
+ if(!$campaign->isArchived()) {
89
+ // we want to initalize it
90
+ $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_report');
91
+ $this->addTab('report', array(
92
+ 'label' => $this->__('Report'),
93
+ 'class' => 'ajax',
94
+ 'url' => $this->getUrl('*/*/report', array('_current' => true)),
95
+ ));
96
+ }
97
+
98
+
99
+ $this->addTab('tasks', array(
100
+ 'label' => $this->__('Tasks'),
101
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_tasks')->toHtml(),
102
+ 'active' => false
103
+ ));
104
+
105
+ $campaign->getMedium()->prepareCampaignTabs($this);
106
+
107
+ if($count = $campaign->countRecipientErrors()) {
108
+ $this->addTab('errors', array(
109
+ 'label' => $this->__('Recipient Errors (%s)', $count),
110
+ 'class' => 'ajax',
111
+ 'url' => $this->getUrl('*/*/errorGrid', array('_current' => true))
112
+ ));
113
+ }
114
+
115
+
116
+ }
117
+ }
118
+
119
+
120
+ $this->_updateActiveTab();
121
+ return parent::_beforeToHtml();
122
+ }
123
+
124
+ protected function _updateActiveTab()
125
+ {
126
+ $tabId = $this->getRequest()->getParam('tab');
127
+ if( $tabId ) {
128
+ $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
129
+ if($tabId) {
130
+ $this->setActiveTab($tabId);
131
+ }
132
+ }
133
+ }
134
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Campaign Grid
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Grid
34
+ {
35
+
36
+ public function __construct()
37
+ {
38
+ parent::__construct();
39
+ $this->setId('campaign_grid');
40
+ $this->setUseAjax(true);
41
+ $this->setSaveParametersInSession(true);
42
+ $this->setDefaultSort('campaign_id');
43
+ }
44
+
45
+
46
+
47
+ protected function _prepareCollection()
48
+ {
49
+ /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
50
+ $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
51
+
52
+ if(!$this->getRequest()->getParam('archive')) {
53
+ $collection->addArchiveFilter(false);
54
+ }
55
+
56
+ $this->setCollection($collection);
57
+
58
+ return parent::_prepareCollection();
59
+ }
60
+
61
+
62
+
63
+ protected function _prepareLayout()
64
+ {
65
+ if( $this->getRequest()->getParam('archive') ) {
66
+ $this->setChild('archive_button',
67
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
68
+ 'label' => $this->__('Hide Archived'),
69
+ 'onclick' => "{$this->getJsObjectName()}.addVarToUrl('archive', 0); {$this->getJsObjectName()}.reload();",
70
+ 'class' => 'task'
71
+ ))
72
+ );
73
+ }
74
+ else {
75
+ $this->setChild('archive_button',
76
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
77
+ 'label' => $this->__('Show Archived'),
78
+ 'onclick' => "{$this->getJsObjectName()}.addVarToUrl('archive', 1); {$this->getJsObjectName()}.reload();",
79
+ 'class' => 'task'
80
+ ))
81
+ );
82
+ }
83
+
84
+ return parent::_prepareLayout();
85
+ }
86
+
87
+
88
+
89
+
90
+ public function getMainButtonsHtml()
91
+ {
92
+ $html = parent::getMainButtonsHtml();
93
+ $html = $this->getChildHtml('archive_button') . $html;
94
+
95
+ return $html;
96
+ }
97
+
98
+
99
+
100
+
101
+ protected function _prepareColumns()
102
+ {
103
+ $this->addColumn('added_at', array(
104
+ 'header' => Mage::helper('mzax_emarketing')->__('Date Added'),
105
+ 'index' => 'created_at',
106
+ 'gmtoffset' => true,
107
+ 'type' => 'datetime'
108
+ ));
109
+
110
+ $this->addColumn('modified_at', array(
111
+ 'header' => $this->__('Last Change'),
112
+ 'index' => 'updated_at',
113
+ 'gmtoffset' => true,
114
+ 'type' => 'datetime'
115
+ ));
116
+
117
+ $this->addColumn('name', array(
118
+ 'header' => $this->__('Name'),
119
+ 'index' => 'name'
120
+ ));
121
+
122
+
123
+ $this->addColumn('recipients', array(
124
+ 'header' => $this->__('Recipients'),
125
+ 'index' => 'provider',
126
+ 'type' => 'options',
127
+ 'width' => 120,
128
+ 'options' => Mage::getSingleton('mzax_emarketing/recipient_provider')->getOptionHash()
129
+ ));
130
+
131
+ $this->addColumn('medium', array(
132
+ 'header' => $this->__('Medium'),
133
+ 'index' => 'medium',
134
+ 'type' => 'options',
135
+ 'width' => 120,
136
+ 'options' => Mage::getSingleton('mzax_emarketing/medium')->getMediums()
137
+ ));
138
+
139
+ $this->addColumn('running', array(
140
+ 'header' => $this->__('Is running'),
141
+ 'index' => 'running',
142
+ 'type' => 'options',
143
+ 'width' => 120,
144
+ 'options' => array(
145
+ 0 => $this->__('No'),
146
+ 1 => $this->__('Yes')
147
+ )
148
+ ));
149
+
150
+ $this->addColumn('stats', array(
151
+ 'header' => Mage::helper('mzax_emarketing')->__('Stats'),
152
+ 'filter' => false,
153
+ 'renderer' => 'mzax_emarketing/campaign_grid_renderer_stats'
154
+ ));
155
+
156
+
157
+
158
+ return parent::_prepareColumns();
159
+ }
160
+
161
+ protected function _prepareMassaction()
162
+ {
163
+ return $this;
164
+ }
165
+
166
+ public function getGridUrl()
167
+ {
168
+ return $this->getUrl('*/*/grid', array('_current'=> true));
169
+ }
170
+
171
+ public function getRowUrl($row)
172
+ {
173
+ return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
174
+ }
175
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Filter/Filter.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Grid_Filter_Filter extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Select
25
+ {
26
+
27
+
28
+ protected function _getOptions()
29
+ {
30
+ return Mage::getModel('mzax_emarketing/object_filter')->getAllOptions();
31
+ }
32
+
33
+
34
+ /**
35
+ * Retrieve condition
36
+ *
37
+ * @return array
38
+ */
39
+ public function getCondition()
40
+ {
41
+ $id = $this->getValue();
42
+ $length = strlen($id);
43
+
44
+ $search = "{s:4:\"type\";s:{$length}:\"{$id}\"";
45
+
46
+ $helper = Mage::getResourceHelper('core');
47
+ $likeExpression = $helper->addLikeEscape($search, array('position' => 'any'));
48
+ return array('like' => $likeExpression);
49
+ }
50
+
51
+
52
+
53
+
54
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Action.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
25
+ {
26
+ public function render(Varien_Object $row)
27
+ {
28
+ if($row->isValidForSend()) {
29
+ $actions[] = array(
30
+ 'url' => $this->getUrl('*/admin_queue/edit', array('campaign_id' => $row->getId())),
31
+ 'caption' => Mage::helper('mzax_emarketing')->__('Queue Campaign...')
32
+ );
33
+ }
34
+
35
+
36
+ $actions[] = array(
37
+ 'url' => $this->getUrl('*/*/preview', array('campaign'=>$row->getId())),
38
+ 'popup' => true,
39
+ 'caption' => Mage::helper('mzax_emarketing')->__('Preview')
40
+ );
41
+
42
+
43
+ $this->getColumn()->setActions($actions);
44
+
45
+ return parent::render($row);
46
+ }
47
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Filter.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Filter extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ public function render(Varien_Object $row)
27
+ {
28
+ if($row instanceof Mzax_Emarketing_Model_Campaign) {
29
+ return $this->renderFilters($row);
30
+ }
31
+ return '';
32
+
33
+ }
34
+
35
+
36
+
37
+ public function renderFilters(Mzax_Emarketing_Model_Campaign $campagin)
38
+ {
39
+ $html = array();
40
+
41
+ $columnFilter = $this->getColumn()->getFilter();
42
+ if( $columnFilter ) {
43
+ $columnFilter = $columnFilter->getValue();
44
+ }
45
+
46
+
47
+ /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
48
+ foreach($campagin->getFilters() as $filter) {
49
+ $style = '';
50
+ if($filter->getType() == $columnFilter) {
51
+ $style = 'background:#FFFFDD; color:#222';
52
+ }
53
+
54
+ $html[] = "<li style=\"{$style}\">{$filter->getQueryString()}</li>";
55
+ }
56
+
57
+ $html = implode("\n", $html);
58
+ $html = "<ul style=\"list-style: inside disc; font-size: 0.8em; color: #666;\">$html</ul>";
59
+
60
+ return $html;
61
+ }
62
+
63
+
64
+
65
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/SendMail.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_SendMail extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
25
+ {
26
+ public function render(Varien_Object $row)
27
+ {
28
+ $url = $this->getUrl('*/*/sendTestMail', array(
29
+ 'campaign' => $this->getColumn()->getCampaign()->getId(),
30
+ 'recipient' => $row->getId(),
31
+ ));
32
+
33
+ return "<a href=\"{$url}\">{$this->__('Send Mail')}</span>";
34
+ }
35
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Sender.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Sender extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ public function render(Varien_Object $row)
27
+ {
28
+ $sender = $row->getSender();
29
+
30
+ $str = '';
31
+ if(isset($sender['name'])) {
32
+ $str .= htmlspecialchars($sender['name']) . ' ';
33
+ }
34
+ if($sender['email']) {
35
+ $str .= '[' . $sender['email'] . ']';
36
+ }
37
+ if($str == '') {
38
+ $str .= '---';
39
+ }
40
+ return $str;
41
+ }
42
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Stats.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Stats extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ public function render(Varien_Object $row)
27
+ {
28
+ if($row instanceof Mzax_Emarketing_Model_Campaign && $row->getSendingStats() > 0) {
29
+ return $this->renderStats($row);
30
+ }
31
+ return '';
32
+
33
+ }
34
+
35
+
36
+
37
+ public function renderStats(Mzax_Emarketing_Model_Campaign $campagin)
38
+ {
39
+ $html = array();
40
+
41
+ $sendings = $campagin->getSendingStats();
42
+ $interactions = $campagin->getInteractionStats();
43
+ $conversions = $campagin->getConversionStats();
44
+ $fails = $campagin->getFailStats();
45
+
46
+ $html[] = sprintf('<div class="mzax-grid-stats" title="%s">', $this->__('%s Sendings', $sendings));
47
+ $html[] = sprintf('<div class="mzax-grid-stat interactions" style="width:%01.3f%%" title="%s"></div>', (($interactions)/$sendings)*100, $this->__('%s Interactions', $interactions));
48
+ $html[] = sprintf('<div class="mzax-grid-stat conversions" style="width:%01.3f%%" title="%s"></div>', (($conversions)/$sendings)*100, $this->__('%s Conversions', $conversions));
49
+ $html[] = sprintf('<div class="mzax-grid-stat fails" style="width:%01.3f%%" title="%s"></div>', (($fails)/$sendings)*100, $this->__('%s Bounces and Optouts', $fails));
50
+ $html[] = '</div>';
51
+
52
+ return implode("\n", $html);
53
+ }
54
+
55
+
56
+
57
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/New.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ *
26
+ * @author Jacob Siefer
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @version 0.2.5
29
+ */
30
+ class Mzax_Emarketing_Block_Campaign_New extends Mzax_Emarketing_Block_Campaign_Edit
31
+ {
32
+
33
+
34
+ public function getHeaderText()
35
+ {
36
+ return $this->__('New Campaign');
37
+ }
38
+
39
+
40
+ public function getValidationUrl()
41
+ {
42
+ return null;
43
+ }
44
+
45
+
46
+ protected function _prepareLayout()
47
+ {
48
+ parent::_prepareLayout();
49
+
50
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
51
+ $campaign = Mage::registry('current_campaign');
52
+
53
+ $this->_removeButton('reset');
54
+ $this->_removeButton('save');
55
+ $this->_removeButton('save_and_continue');
56
+ }
57
+
58
+
59
+ /**
60
+ * Get form action URL
61
+ *
62
+ * @return string
63
+ */
64
+ public function getFormActionUrl()
65
+ {
66
+ return $this->getUrl('*/*/new');
67
+ }
68
+
69
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Preview.php ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Campaign_Preview extends Mage_Adminhtml_Block_Widget
24
+ {
25
+
26
+ protected $_campaign;
27
+
28
+
29
+ protected $_recipient;
30
+
31
+
32
+
33
+ /**
34
+ *
35
+ * @var Mzax_Emarketing_Model_Outbox_Email
36
+ */
37
+ protected $_email;
38
+
39
+
40
+ protected function _preparePreview()
41
+ {
42
+ $campaign = $this->getCampaign();
43
+
44
+ $this->setTemplate("mzax/emarketing/campaign/medium/{$campaign->getMedium()->getMediumId()}/preview.phtml");
45
+
46
+ $head = $this->getLayout()->getBlock('head');
47
+ if($head) {
48
+ $content = $this->getRecipient()->getContent();
49
+
50
+ if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
51
+ $head->setTitle($this->__('Preview - %s / %s', $campaign->getName(), $content->getName()));
52
+ }
53
+ else {
54
+ $head->setTitle($this->__('Preview - %s / Original', $campaign->getName(), $content->getName()));
55
+ }
56
+ }
57
+ }
58
+
59
+
60
+ public function setCampaign($campaign)
61
+ {
62
+ $this->_campaign = $campaign;
63
+ $this->_recipient = null;
64
+ $this->_preparePreview();
65
+ return $this;
66
+ }
67
+
68
+
69
+
70
+ /**
71
+ *
72
+ * @throws Exception
73
+ * @return Mzax_Emarketing_Model_Campaign
74
+ */
75
+ public function getCampaign()
76
+ {
77
+ if(!$this->_campaign) {
78
+
79
+ $id = (int) $this->getRequest()->getParam('campaign');
80
+
81
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
82
+ $campaign = Mage::getModel('mzax_emarketing/campaign');
83
+ $campaign->load($id);
84
+
85
+ if(!$campaign->getId()) {
86
+ throw new Exception("No campaign found");
87
+ }
88
+
89
+ $this->_campaign = $campaign;
90
+ }
91
+ return $this->_campaign;
92
+ }
93
+
94
+
95
+
96
+
97
+ /**
98
+ * Retrieve recipient model
99
+ *
100
+ * @return Mzax_Emarketing_Model_Recipient
101
+ */
102
+ public function getRecipient()
103
+ {
104
+ if(!$this->_recipient) {
105
+ $objectId = $this->getRequest()->getParam('entity');
106
+
107
+ $content = $this->getCampaign();
108
+ // check if we want to preview a certain variation
109
+ if($variationId = $this->getRequest()->getParam('variation')) {
110
+ $content = $this->getCampaign()->getVariation($variationId);
111
+ $this->setEditorId('variation_'.$content->getId().'_body');
112
+ }
113
+ else {
114
+ $this->setEditorId('campaign_body');
115
+ }
116
+
117
+ $this->_recipient = $this->getCampaign()->createMockRecipient($objectId);
118
+ $this->_recipient->setContent($content);
119
+
120
+ }
121
+ return $this->_recipient;
122
+ }
123
+
124
+
125
+
126
+ /**
127
+ * Retrieve email body
128
+ *
129
+ * @return string
130
+ */
131
+ public function getSubject()
132
+ {
133
+ return $this->getEmail()->getSubject();
134
+ }
135
+
136
+
137
+ /**
138
+ * Retrieve email body
139
+ *
140
+ * @return string
141
+ */
142
+ public function getBodyHtml()
143
+ {
144
+ return $this->getEmail()->getBodyHtml();
145
+ }
146
+
147
+
148
+ /**
149
+ * Retrieve email body
150
+ *
151
+ * @return string
152
+ */
153
+ public function getBodyText()
154
+ {
155
+ return $this->getEmail()->getBodyText();
156
+ }
157
+
158
+
159
+
160
+ /**
161
+ *
162
+ * @return array
163
+ */
164
+ public function getLinkReferences()
165
+ {
166
+ return $this->getEmail()->getLinkReferences();
167
+ }
168
+
169
+
170
+
171
+ /**
172
+ *
173
+ * @return Mzax_Emarketing_Model_Outbox_Email
174
+ */
175
+ public function getEmail()
176
+ {
177
+ if(!$this->_email) {
178
+ $recipient = $this->getRecipient();
179
+ $recipient->prepare();
180
+
181
+ /* @var $email Mzax_Emarketing_Model_Outbox_Email */
182
+ $this->_email = Mage::getModel('mzax_emarketing/outbox_email');
183
+ $this->_email->setTo($recipient->getAddress());
184
+ $this->_email->setRecipient($recipient);
185
+ $this->_email->render();
186
+ }
187
+ return $this->_email;
188
+ }
189
+
190
+
191
+
192
+ public function getRenderTime()
193
+ {
194
+ if($this->_email) {
195
+ return (float) $this->_email->getRenderTime();
196
+ }
197
+ return 0;
198
+ }
199
+
200
+
201
+
202
+
203
+ /**
204
+ * Is ACE editor enabled
205
+ *
206
+ * @return boolean
207
+ */
208
+ public function aceEnabled()
209
+ {
210
+ $enabled = Mage::getStoreConfigFlag('mzax_emarketing/content_management/enable_ace');
211
+ if(!$enabled) {
212
+ return 0;
213
+ }
214
+ return (int) $this->getConfig('enable_ace', 1);
215
+ }
216
+
217
+
218
+
219
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_SendTestMail extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+ public function __construct()
27
+ {
28
+ $this->_objectId = 'id';
29
+
30
+ $this->_blockGroup = 'mzax_emarketing';
31
+ $this->_controller = 'campaign';
32
+ $this->_mode = 'sendTestMail';
33
+
34
+ parent::__construct();
35
+
36
+ $this->_updateButton('save', 'label', $this->__('Send Email'));
37
+ $this->_removeButton('delete');
38
+ $this->_removeButton('reset');
39
+ $this->_removeButton('back');
40
+ }
41
+
42
+
43
+
44
+
45
+ public function getHeaderText()
46
+ {
47
+ return $this->__('Send Test Mail');
48
+ }
49
+
50
+ public function getValidationUrl()
51
+ {
52
+ return $this->getUrl('*/*/validateTestMail', array('_current'=>true));
53
+ }
54
+
55
+
56
+
57
+
58
+ /**
59
+ * Get form action URL
60
+ *
61
+ * @return string
62
+ */
63
+ public function getFormActionUrl()
64
+ {
65
+ if ($this->hasFormActionUrl()) {
66
+ return $this->getData('form_action_url');
67
+ }
68
+ return $this->getUrl('*/*/sendTestMailPost', array('_current' => true));
69
+ }
70
+
71
+
72
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail/Form.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_SendTestMail_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
30
+
31
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
32
+ $campaign = Mage::registry('current_campaign');
33
+
34
+ /* @var $recipient Mzax_Emarketing_Model_Recipient */
35
+ $recipient = Mage::registry('current_recipient');
36
+
37
+ $form->addField('id', 'hidden', array(
38
+ 'name' => 'id',
39
+ 'value' => $campaign->getId()
40
+ ));
41
+
42
+ $form->addField('object_id', 'hidden', array(
43
+ 'name' => 'object_id',
44
+ 'value' => $recipient->getObjectId()
45
+ ));
46
+
47
+ $form->addField('recipient_name', 'text', array(
48
+ 'name' => 'recipient_name',
49
+ 'label' => $this->__("Recipient Name"),
50
+ 'value' => $recipient->getName()
51
+ ));
52
+
53
+
54
+ $user = Mage::getSingleton('admin/session')->getUser();
55
+
56
+ $form->addField('recipient_email', 'text', array(
57
+ 'name' => 'recipient_email',
58
+ 'label' => $this->__("Recipient Email"),
59
+ 'value' => $user->getEmail()
60
+ ));
61
+
62
+
63
+ if($campaign->hasVariations()) {
64
+
65
+ $options = $campaign->getVariations()->toOptionArray();
66
+
67
+ array_unshift($options, array('value' => '0', 'label' => $this->__('[Orignal]')));
68
+
69
+ $form->addField('variation', 'select', array(
70
+ 'name' => 'variation',
71
+ 'label' => $this->__("Variation"),
72
+ 'value' => $this->getRequest()->getParam('variation', '0'),
73
+ 'values' => $options
74
+ ));
75
+
76
+
77
+
78
+ }
79
+
80
+
81
+ $form->setUseContainer(true);
82
+ $this->setForm($form);
83
+ return parent::_prepareForm();
84
+ }
85
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Test.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
25
+ {
26
+
27
+
28
+ /**
29
+ * Retrieve filter
30
+ *
31
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
32
+ */
33
+ public function getFilter()
34
+ {
35
+ $filter = $this->getCampaign()->getRecipientProvider();
36
+ $this->prepareEmulation($filter);
37
+ return $filter;
38
+ }
39
+
40
+
41
+
42
+ public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
43
+ {
44
+ $child = $this->getChild('emulate');
45
+ if($child && method_exists($child, 'prepareEmulation')) {
46
+ $child->prepareEmulation($filter);
47
+ }
48
+ }
49
+
50
+
51
+
52
+
53
+
54
+
55
+ /**
56
+ * Generate url by route and parameters
57
+ *
58
+ * @param string $route
59
+ * @param array $params
60
+ * @return string
61
+ */
62
+ public function getUrl($route = '', $params = array())
63
+ {
64
+ $params['id'] = $this->getCampaign()->getId();
65
+ return parent::getUrl($route, $params);
66
+ }
67
+
68
+
69
+
70
+
71
+ /**
72
+ * Retrieve current campaign
73
+ *
74
+ * @return Mzax_Emarketing_Model_Campaign
75
+ */
76
+ public function getCampaign()
77
+ {
78
+ return Mage::registry('current_campaign');
79
+ }
80
+
81
+
82
+
83
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Test/Emulate.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_Test_Emulate extends Mage_Adminhtml_Block_Template
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var Varien_Data_Form
30
+ */
31
+ protected $_form;
32
+
33
+
34
+
35
+ /**
36
+ * Retrieve Varien Data Form
37
+ *
38
+ * @return Varien_Data_Form
39
+ */
40
+ public function getForm()
41
+ {
42
+ if(!$this->_form) {
43
+ $this->_form = new Varien_Data_Form();
44
+ $this->_form->setElementRenderer(Mage::getBlockSingleton('mzax_emarketing/editable')->setFormat('form'));
45
+ $this->_form->setHtmlIdPrefix("emulate_");
46
+ $this->_form->setFieldNameSuffix("emulate");
47
+ }
48
+ return $this->_form;
49
+ }
50
+
51
+
52
+ /**
53
+ * Prepare filter
54
+ *
55
+ * Usally called by parent block class
56
+ *
57
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
58
+ */
59
+ public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
60
+ {
61
+ $emulate = $this->getRequest()->getParam('emulate');
62
+
63
+ if($this->emulate('time')) {
64
+ if(isset($emulate['from']) && isset($emulate['to'])) {
65
+ $filter->setParam('current_time', array($emulate['from'], $emulate['to']));
66
+ $filter->setParam('is_local_time', true);
67
+
68
+ }
69
+ }
70
+
71
+ if($this->emulate('campaign')) {
72
+ /* @var $campagin Mzax_Emarketing_Model_Campaign */
73
+ $campagin = Mage::getModel('mzax_emarketing/campaign');
74
+ $campagin->load($emulate['campaign_id']);
75
+
76
+ if($campagin->getId()) {
77
+ $filter->setParam('campaign', $campagin);
78
+ }
79
+ }
80
+ }
81
+
82
+
83
+
84
+ /**
85
+ * Check if we should emulate the specified key
86
+ *
87
+ * @param string $key
88
+ * @return boolean
89
+ */
90
+ public function emulate($key)
91
+ {
92
+ $emulate = $this->getRequest()->getParam('emulate');
93
+
94
+ if(isset($emulate[$key])) {
95
+ return ($emulate[$key] == 1);
96
+ }
97
+ return false;
98
+ }
99
+
100
+
101
+
102
+
103
+
104
+ /**
105
+ *
106
+ *
107
+ * @return Varien_Data_Form_Element_Abstract
108
+ */
109
+ public function getCampaignSelect()
110
+ {
111
+ $params = $this->getRequest()->getParam('emulate');
112
+
113
+ /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
114
+ $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
115
+ $collection->addArchiveFilter(false);
116
+
117
+ $options = array();
118
+ if($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
119
+ $options['current'] = $this->__('beeing tracked');
120
+ }
121
+ $options += $collection->toOptionHash();
122
+
123
+ /* @var $campagin Mzax_Emarketing_Model_Campaign */
124
+ $campagin = Mage::getModel('mzax_emarketing/campaign');
125
+
126
+ if(isset($params['campaign_id'])) {
127
+ $campagin->load($params['campaign_id']);
128
+ }
129
+
130
+ return $this->getForm()->addField('campaign_id', 'select', array(
131
+ 'name' => 'campaign_id',
132
+ 'value_name' => (string) $campagin->getName(),
133
+ 'value' => $campagin->getId(),
134
+ 'options' => $options,
135
+ ));
136
+
137
+ }
138
+
139
+
140
+
141
+
142
+ /**
143
+ * Helper for simple select element
144
+ *
145
+ * @param string $key
146
+ * @param array $options
147
+ * @return Varien_Data_Form_Element_Abstract
148
+ */
149
+ public function getDateElement($key)
150
+ {
151
+ $format = Varien_Date::DATE_INTERNAL_FORMAT;
152
+
153
+ $params = $this->getRequest()->getParam('emulate');
154
+
155
+ if(isset($params[$key])) {
156
+ $value = $params[$key];
157
+ }
158
+ else {
159
+ $value = Zend_Date::now()->toString($format);
160
+ }
161
+
162
+ return $this->getForm()->addField($key, 'date',array(
163
+ 'name' => $key,
164
+ 'value_name' => $value,
165
+ 'value' => $value,
166
+ 'explicit_apply' => true,
167
+ 'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
168
+ 'input_format' => $format,
169
+ 'format' => $format
170
+ ));
171
+ }
172
+
173
+
174
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/View.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Campaign_View extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'mzax_emarketing';
30
+ $this->_controller = 'campaign';
31
+ $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Campaigns');
32
+ $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Campaign');
33
+
34
+
35
+ parent::__construct();
36
+ }
37
+
38
+
39
+
40
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Abstract.php ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Abstract extends Mage_Core_Block_Template
24
+ {
25
+
26
+
27
+ protected $_chartClass = '';
28
+
29
+ protected function _construct()
30
+ {
31
+ parent::_construct();
32
+ $this->setElementId('gchart_'.rand(0, 100000));
33
+ }
34
+
35
+ public function getChartClass()
36
+ {
37
+ return "google.visualization.{$this->_chartClass}";
38
+ }
39
+
40
+
41
+
42
+
43
+
44
+ protected $_columns = array();
45
+
46
+
47
+ protected $_rows = array();
48
+
49
+
50
+ protected $_overlays = array();
51
+
52
+
53
+ public function addOverlay($name, $overlay)
54
+ {
55
+ $this->_overlays[$name] = $overlay;
56
+ return $this;
57
+ }
58
+
59
+
60
+ public function addColumn($label, $type = 'number', $p = null)
61
+ {
62
+ $this->_columns[] = array($label, $type, $p);
63
+ return $this;
64
+ }
65
+
66
+
67
+ public function clearRows()
68
+ {
69
+ $this->_rows = array();
70
+ return $this;
71
+ }
72
+
73
+ public function addRow(array $row, $offset = null)
74
+ {
75
+ if($offset === null) {
76
+ $this->_rows[] = $row;
77
+ }
78
+ else {
79
+ array_splice($this->_rows, $offset, 0, array($row));
80
+ }
81
+ return $this;
82
+ }
83
+
84
+
85
+ public function getOptionJs()
86
+ {
87
+ $ignore = array('type', 'module_name', 'auto_redraw');
88
+ $options = array();
89
+ foreach($this->_data as $key => $value) {
90
+ if(in_array($key, $ignore)) {
91
+ continue;
92
+ }
93
+ $name = lcfirst($this->_camelize($key));
94
+ $options[$name] = $value;
95
+ }
96
+
97
+ return Zend_Json::encode($options);
98
+ }
99
+
100
+
101
+
102
+
103
+
104
+ protected function _getDataJson()
105
+ {
106
+ $json = array();
107
+ foreach($this->_rows as $row) {
108
+ $data = array();
109
+ foreach($this->_columns as $i => $column) {
110
+ list($label, $type, $p) = $column;
111
+ $value = $row[$i];
112
+ if($value === null) {
113
+ $value = 'null';
114
+ }
115
+ else {
116
+ switch($type) {
117
+ case 'tooltip':
118
+ case 'string':
119
+ $value = "'".$this->jsQuoteEscape($value)."'";
120
+ break;
121
+
122
+ case 'date':
123
+ if($value instanceof DateTime) {
124
+ $value = "new Date({$value->format('Y, n-1, j')})";
125
+ }
126
+ break;
127
+
128
+ default:
129
+ $value = (float) $value;
130
+ break;
131
+ }
132
+ }
133
+ $data[] = $value;
134
+ }
135
+
136
+ $json[] = "[" . implode(', ', $data) . "]";
137
+ }
138
+ return "[" . implode(",\n", $json) . "]";
139
+ }
140
+
141
+
142
+
143
+ protected function _getDataTableJs($name = 'data')
144
+ {
145
+ $html = "var {$name} = new google.visualization.DataTable();\n";
146
+
147
+ foreach($this->_columns as $column) {
148
+ list($label, $type, $p) = $column;
149
+
150
+ $json = array('type' => $type, 'label' => $label);
151
+ if($p) {
152
+ $json['p'] = $p;
153
+ }
154
+ $json = Zend_Json::encode($json);
155
+
156
+ $html .= "{$name}.addColumn($json);\n";
157
+ }
158
+
159
+ $html .= "{$name}.addRows({$this->_getDataJson()});";
160
+
161
+ return $html;
162
+ }
163
+
164
+
165
+
166
+
167
+
168
+ public function _toHtml()
169
+ {
170
+ $autoredraw = (int) $this->getDataSetDefault('auto_redraw', true);
171
+
172
+ $overlayHtml = '';
173
+ foreach($this->_overlays as $name => $overlay) {
174
+ if($overlay instanceof Mage_Core_Block_Abstract) {
175
+ $overlay = $overlay->toHtml();
176
+ }
177
+ $overlayHtml .= "<div class=\"overlay $name\">$overlay</div>";
178
+ }
179
+
180
+
181
+ return <<<HTML
182
+ <div id="{$this->getElementId()}-wrapper" class="chart-wrapper">
183
+ <div id="{$this->getElementId()}"></div>
184
+ {$overlayHtml}
185
+ </div>
186
+ <script type="text/javascript">
187
+ (function() {
188
+ {$this->_getDataTableJs('data')}
189
+ var chart = new {$this->getChartClass()}(document.getElementById('{$this->getElementId()}'));
190
+ chart.draw(data, {$this->getOptionJs()});
191
+ if($autoredraw) {
192
+ Event.observe(window, "resize", function() {
193
+ chart.draw(data, options);
194
+ });
195
+ }
196
+ }());
197
+ </script>
198
+ HTML;
199
+ }
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Area.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Area extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+
26
+ protected $_chartClass = 'AreaChart';
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Bar.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Bar extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+ protected $_chartClass = 'BarChart';
26
+
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Column.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Column extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+ protected $_chartClass = 'ColumnChart';
26
+
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Geo.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Geo extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+ protected $_chartClass = 'GeoChart';
26
+
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Line.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Line extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+
26
+ protected $_chartClass = 'LineChart';
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Pie.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Pie extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+
26
+ protected $_chartClass = 'PieChart';
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Scatter.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_Scatter extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+ protected $_chartClass = 'ScatterChart';
26
+
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/SteppedArea.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Block_Chart_SteppedArea extends Mzax_Emarketing_Block_Chart_Abstract
24
+ {
25
+ protected $_chartClass = 'SteppedAreaChart';
26
+
27
+
28
+
29
+
30
+
31
+
32
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Widget/Container.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Block_Chart_Widget_Container extends Mage_Adminhtml_Block_Abstract
26
+ {
27
+
28
+ /**
29
+ *
30
+ * @var Mzax_Emarketing_Block_Chart_Abstract
31
+ */
32
+ protected $_chart;
33
+
34
+
35
+ /**
36
+ *
37
+ * @param Mzax_Emarketing_Block_Chart_Abstract $chart
38
+ * @return Mzax_Emarketing_Block_Chart_Widget_Container
39
+ */
40
+ public function setChart(Mzax_Emarketing_Block_Chart_Abstract $chart)
41
+ {
42
+ $this->_chart = $chart;
43
+ return $this;
44
+ }
45
+
46
+
47
+ /**
48
+ *
49
+ * @return Mzax_Emarketing_Block_Chart_Abstract
50
+ */
51
+ public function getChart()
52
+ {
53
+ return $this->_chart;
54
+ }
55
+
56
+
57
+
58
+ protected function _toHtml()
59
+ {
60
+ if($this->_chart) {
61
+ return $this->_chart->toHtml();
62
+ }
63
+ return '';
64
+ }
65
+
66
+
67
+
68
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Widget/Geo.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Block_Chart_Widget_Geo extends Mzax_Emarketing_Block_Chart_Widget_Tab
26
+ {
27
+
28
+
29
+
30
+
31
+
32
+ protected function _construct()
33
+ {
34
+ parent::_construct();
35
+ $this->setTemplate('mzax/emarketing/widget/chart-geo.phtml');
36
+ }
37
+
38
+
39
+
40
+ public function getType()
41
+ {
42
+ return 'geo';
43
+ }
44
+
45
+
46
+
47
+
48
+ /**
49
+ *
50
+ * @return Mzax_Emarketing_Block_Chart_Abstract
51
+ */
52
+ public function getChart()
53
+ {
54
+ if(!$this->_chart) {
55
+
56
+
57
+ $block = 'mzax_emarketing/chart_' . $this->getType();
58
+
59
+ /* @var $chart Mzax_Emarketing_Block_Chart_Abstract */
60
+ $chart = $this->_chart = $this->getLayout()->createBlock($block);
61
+ $chart->setBackgroundColor('#f5f5f5');
62
+ $chart->setHAxis(array(
63
+ 'baselineColor' => 'white',
64
+ 'gridlines' => array(
65
+ 'color' => '#DDD'
66
+ ),
67
+ 'textPosition'=> 'in',
68
+ 'textStyle' => array(
69
+ 'fontSize' => 11,
70
+ 'color' => '#333'
71
+ )
72
+ ));
73
+ $chart->setVAxis(array(
74
+ 'baselineColor' => 'white',
75
+ 'gridlines' => array(
76
+ 'color' => '#DDD'
77
+ ),
78
+ 'textPosition'=> 'in',
79
+ 'textStyle' => array(
80
+ 'fontSize' => 11,
81
+ 'color' => '#333'
82
+ )
83
+ ));
84
+ $chart->setBar(array(
85
+ 'groupWidth' => '80%'
86
+ ));
87
+ $chart->setChartArea(array(
88
+ 'top' => '5%',
89
+ 'right' => '0',
90
+ 'bottom' => '0',
91
+ 'left' => '0',
92
+ 'width' => '100%',
93
+ 'height' => '100%'
94
+ ));
95
+ $chart->setLegend('none');
96
+ $chart->setHeight(400);
97
+
98
+ }
99
+ return $this->_chart;
100
+ }
101
+
102
+
103
+ }
app/code/community/Mzax/Emarketing/Block/Chart/Widget/Tab.php ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @method Mzax_Emarketing_Model_Campaign getCampaign()
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Block_Chart_Widget_Tab extends Mage_Adminhtml_Block_Abstract
33
+ {
34
+
35
+ /**
36
+ *
37
+ * @var Mzax_Emarketing_Block_Chart_Abstract
38
+ */
39
+ protected $_chart;
40
+
41
+
42
+ /**
43
+ *
44
+ * @var Mzax_Emarketing_Model_Report_Query
45
+ */
46
+ protected $_query;
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ protected $_tabs = array();
55
+
56
+
57
+ protected static $_uid = 1;
58
+
59
+
60
+
61
+
62
+ public function getHtmlId()
63
+ {
64
+ $id = $this->getData('html_id');
65
+ if(!$id) {
66
+ $id = 'charttab_' . (self::$_uid++);
67
+ $this->setData('html_id', $id);
68
+ }
69
+ return $id;
70
+ }
71
+
72
+
73
+
74
+
75
+ protected function _construct()
76
+ {
77
+ parent::_construct();
78
+ $this->setTemplate('mzax/emarketing/widget/chart-tab.phtml');
79
+ }
80
+
81
+
82
+
83
+ public function addTab($id, $params)
84
+ {
85
+ $this->_tabs[$id] = $params;
86
+ return $this;
87
+ }
88
+
89
+ public function getTabs()
90
+ {
91
+ return $this->_tabs;
92
+ }
93
+
94
+
95
+
96
+ /**
97
+ * Retrieve query
98
+ *
99
+ * @return Mzax_Emarketing_Model_Report_Query
100
+ */
101
+ public function getQuery()
102
+ {
103
+ return $this->_query;
104
+ }
105
+
106
+
107
+ /**
108
+ * Set query
109
+ *
110
+ * @param Mzax_Emarketing_Model_Report_Query $query
111
+ * @return Mzax_Emarketing_Block_Chart_Widget_Tab
112
+ */
113
+ public function setQuery(Mzax_Emarketing_Model_Report_Query $query)
114
+ {
115
+ $this->_query = $query;
116
+ return $this;
117
+ }
118
+
119
+
120
+
121
+ public function getType()
122
+ {
123
+ return $this->getDataSetDefault('type', 'line');
124
+ }
125
+
126
+
127
+
128
+
129
+ /**
130
+ *
131
+ * @return Mzax_Emarketing_Block_Chart_Abstract
132
+ */
133
+ public function getChart()
134
+ {
135
+ if(!$this->_chart) {
136
+
137
+
138
+ $block = 'mzax_emarketing/chart_' . $this->getType();
139
+
140
+ /* @var $chart Mzax_Emarketing_Block_Chart_Abstract */
141
+ $chart = $this->_chart = $this->getLayout()->createBlock($block);
142
+ $chart->setBackgroundColor('#f5f5f5');
143
+ $chart->setHAxis(array(
144
+ 'baselineColor' => 'white',
145
+ 'gridlines' => array(
146
+ 'color' => '#DDD'
147
+ ),
148
+ 'textPosition'=> 'in',
149
+ 'textStyle' => array(
150
+ 'fontSize' => 11,
151
+ 'color' => '#333'
152
+ )
153
+ ));
154
+ $chart->setVAxis(array(
155
+ 'baselineColor' => 'white',
156
+ 'gridlines' => array(
157
+ 'color' => '#DDD'
158
+ ),
159
+ 'textPosition'=> 'in',
160
+ 'textStyle' => array(
161
+ 'fontSize' => 11,
162
+ 'color' => '#333'
163
+ )
164
+ ));
165
+ $chart->setBar(array(
166
+ 'groupWidth' => '80%'
167
+ ));
168
+ $chart->setChartArea(array(
169
+ 'top' => '5%',
170
+ 'right' => '0',
171
+ 'bottom' => '0',
172
+ 'left' => '0',
173
+ 'width' => '100%',
174
+ 'height' => '100%'
175
+ ));
176
+ $chart->setLegend('none');
177
+ $chart->setHeight(200);
178
+
179
+ }
180
+ return $this->_chart;
181
+ }
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+ /**
190
+ *
191
+ * @return Mzax_Chart_Table
192
+ */
193
+ public function getTable()
194
+ {
195
+ return $this->getQuery()->getDataTable();
196
+ }
197
+
198
+
199
+
200
+
201
+ /**
202
+ * Retrieve query params as JSON
203
+ *
204
+ * @return string
205
+ */
206
+ public function getQueryParams()
207
+ {
208
+ return Zend_Json::encode($this->getQuery()->getParams());
209
+ }
210
+
211
+
212
+
213
+ public function getQueryUrl()
214
+ {
215
+ $url = $this->getData('query_url');
216
+ if(!$url) {
217
+ $url = $this->getUrl('*/*/queryReport', array(
218
+ '_current' => true,
219
+ 'form_key' => Mage::getSingleton('core/session')->getFormKey()
220
+ ));
221
+ }
222
+ return $url;
223
+ }
224
+
225
+
226
+
227
+
228
+
229
+
230
+ public function getTabMetric(array $tab)
231
+ {
232
+ if(isset($tab['metric'])) {
233
+ if(is_array($tab['metric'])) {
234
+ if(isset($tab['default'])) {
235
+ return $tab['default'];
236
+ }
237
+ return reset(array_keys($tab['metric']));
238
+ }
239
+ return $tab['metric'];
240
+ }
241
+ return '';
242
+ }
243
+
244
+
245
+ public function getTabLabel(array $tab)
246
+ {
247
+ if(isset($tab['label'])) {
248
+ return $tab['label'];
249
+ }
250
+ return '';
251
+ }
252
+
253
+
254
+ public function getTabClass(array $tab)
255
+ {
256
+ $class = array();
257
+ if(isset($tab['id'])) {
258
+ $class[] = $tab['id'];
259
+ }
260
+ if(isset($tab['class'])) {
261
+ $class[] = $tab['class'];
262
+ }
263
+ if(isset($tab['metric'])) {
264
+ $class[] = is_string($tab['metric']) ? $tab['metric'] : 'dropdown';
265
+ }
266
+
267
+
268
+ return implode(' ', array_unique($class));
269
+ }
270
+
271
+
272
+
273
+
274
+ }
app/code/community/Mzax/Emarketing/Block/Conditions.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Block_Conditions implements Varien_Data_Form_Element_Renderer_Interface
33
+ {
34
+ public function render(Varien_Data_Form_Element_Abstract $element)
35
+ {
36
+ $goal = $element->getTracker()->getGoal();
37
+
38
+ if($goal) {
39
+ $html = '<div class="filters">';
40
+ $html .= $goal->getFilter()->asHtml();
41
+ $html .= '</div>';
42
+ return $html;
43
+ }
44
+ return '';
45
+ }
46
+ }
app/code/community/Mzax/Emarketing/Block/Editable.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Block_Editable extends Mage_Core_Block_Abstract
33
+ implements Varien_Data_Form_Element_Renderer_Interface
34
+ {
35
+ public function render(Varien_Data_Form_Element_Abstract $element)
36
+ {
37
+ $element->addClass('element-value-changer');
38
+
39
+ $valueName = $element->getValueName();
40
+ if ($valueName==='') {
41
+ $valueName = '...';
42
+ }
43
+
44
+ $valueLabel = htmlspecialchars(Mage::helper('core/string')->truncate($valueName, 150, '...'));
45
+
46
+ switch($this->getFormat())
47
+ {
48
+ case 'text':
49
+ $html = $valueLabel;
50
+ break;
51
+
52
+ case 'html':
53
+ $html = '<strong>' . $valueLabel . '</strong>' ;
54
+ break;
55
+
56
+ default:
57
+ if ($element->getIsMeta()) {
58
+ $html = '<input type="hidden" class="hidden" id="'.$element->getHtmlId().'" name="'.$element->getName().'" value="'.$element->getValue().'"/>';
59
+ $html.= htmlspecialchars($valueName);
60
+ } else {
61
+ $html = '<span class="rule-param"' . ($element->getParamId() ? ' id="' . $element->getParamId() . '"' : '') . '>';
62
+ $html.= '<a href="javascript:void(0)" class="label">' . $valueLabel . '</a>';
63
+ $html.= '<span class="element">';
64
+ $html.= $element->getElementHtml();
65
+ if ($element->getExplicitApply()) {
66
+ $html.= '<a href="javascript:void(0)" class="rule-param-apply"><img src="'.$this->getSkinUrl('images/rule_component_apply.gif').'" class="v-middle" alt="'.$this->__('Apply').'" title="'.$this->__('Apply').'" /></a>';
67
+ }
68
+ $html.= '</span></span>';
69
+ }
70
+ }
71
+ return $html;
72
+ }
73
+ }
app/code/community/Mzax/Emarketing/Block/Filter/Object/Grid.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ *
28
+ * @method Mzax_Emarketing_Model_Object_Collection getCollection()
29
+ *
30
+ * @author Jacob Siefer
31
+ *
32
+ */
33
+ class Mzax_Emarketing_Block_Filter_Object_Grid extends Mage_Adminhtml_Block_Widget_Grid
34
+ {
35
+
36
+ /**
37
+ * @var Mzax_Emarketing_Model_Object_Filter_Component
38
+ */
39
+ protected $_filter;
40
+
41
+
42
+
43
+ public function __construct($attributes = array())
44
+ {
45
+ if(isset($attributes['filter'])) {
46
+ $this->setFilter($attributes['filter']);
47
+ unset($attributes['filter']);
48
+ }
49
+ parent::__construct($attributes);
50
+ }
51
+
52
+
53
+
54
+ protected function _prepareLayout()
55
+ {
56
+ $this->setChild('hide_button',
57
+ $this->getLayout()->createBlock('adminhtml/widget_button')
58
+ ->setData(array(
59
+ 'label' => Mage::helper('adminhtml')->__('&times;'),
60
+ 'class' => 'close-grid'
61
+ ))
62
+ );
63
+ return parent::_prepareLayout();
64
+ }
65
+
66
+
67
+
68
+ public function getMainButtonsHtml()
69
+ {
70
+ $html = parent::getMainButtonsHtml();
71
+ $html.= $this->getChildHtml('hide_button');
72
+ return $html;
73
+ }
74
+
75
+
76
+
77
+
78
+ /**
79
+ *
80
+ *
81
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
82
+ */
83
+ public function getFilter()
84
+ {
85
+ return $this->_filter;
86
+ }
87
+
88
+
89
+ /**
90
+ *
91
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $source
92
+ * @return Mzax_Emarketing_Block_Filter_Object_Grid
93
+ */
94
+ public function setFilter(Mzax_Emarketing_Model_Object_Filter_Component $filter)
95
+ {
96
+ $this->_filter = $filter;
97
+ return $this;
98
+ }
99
+
100
+
101
+
102
+ /**
103
+ *
104
+ * @return Mzax_Emarketing_Model_Object_Abstract
105
+ */
106
+ public function getObject()
107
+ {
108
+ return $this->getFilter()->getObject();
109
+ }
110
+
111
+
112
+ /**
113
+ * (non-PHPdoc)
114
+ * @see Mage_Adminhtml_Block_Widget_Grid::getCollection()
115
+ * @return Mzax_Emarketing_Model_Object_Collection
116
+ */
117
+ public function getCollection()
118
+ {
119
+ return $this->getFilter()->getCollection();
120
+ }
121
+
122
+
123
+
124
+ /**
125
+ * Allow provider and filters to alter the grid
126
+ *
127
+ */
128
+ protected function _afterLoadCollection()
129
+ {
130
+ parent::_afterLoadCollection();
131
+ $this->getFilter()->afterGridLoadCollection($this);
132
+
133
+ return $this;
134
+ }
135
+
136
+
137
+
138
+
139
+
140
+ /**
141
+ * Prepare grid columns
142
+ *
143
+ * This is done by the email provider. The grid
144
+ * does not know what type of objects it is loading
145
+ *
146
+ */
147
+ protected function _prepareColumns()
148
+ {
149
+ $object = $this->getObject();
150
+
151
+ $this->setFilterVisibility(true);
152
+ $this->setPagerVisibility(true);
153
+
154
+ $this->addColumn('main_object_id', array(
155
+ 'header' => $this->__($object->getName() .' ID'),
156
+ 'index' => 'id',
157
+ 'is_system' => true,
158
+ 'width' => '50px',
159
+ 'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
160
+ 'object' => $object,
161
+ ));
162
+
163
+ $this->setDefaultSort('main_object_id');
164
+ $this->setDefaultDir('DESC');
165
+
166
+ $this->getFilter()->prepareGridColumns($this);
167
+ return parent::_prepareColumns();
168
+ }
169
+
170
+
171
+
172
+ public function getGridUrl()
173
+ {
174
+ return $this->getData('grid_url');
175
+ }
176
+
177
+
178
+
179
+ public function getRowUrl($row)
180
+ {
181
+ return null;
182
+ }
183
+
184
+
185
+
186
+
187
+ }
app/code/community/Mzax/Emarketing/Block/Filter/Test/Recursive.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Filter_Test_Recursive extends Mzax_Emarketing_Block_Filter_Test_Single
25
+ {
26
+
27
+
28
+ /**
29
+ *
30
+ * @var Mzax_Emarketing_Block_Filter_Test_Single
31
+ */
32
+ protected $_filterBlock;
33
+
34
+
35
+
36
+ protected function _construct()
37
+ {
38
+ parent::_construct();
39
+ $this->setTemplate('mzax/emarketing/filter/test/recursive.phtml');
40
+ }
41
+
42
+
43
+
44
+ /**
45
+ * Retrieve filter
46
+ *
47
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
48
+ */
49
+ public function getFilter()
50
+ {
51
+ return Mage::registry('current_filter');
52
+ }
53
+
54
+
55
+
56
+
57
+
58
+ protected function _beforeToHtml()
59
+ {
60
+ $time = microtime(true);
61
+ $html = $this->_toHtmlRecursive($this->getFilter());
62
+ $time = microtime(true) - $time;
63
+
64
+ $this->setTime($time);
65
+ $this->setFilterHtml($html);
66
+ }
67
+
68
+
69
+
70
+
71
+ protected function _toHtmlRecursive(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
72
+ {
73
+ $block = $this->getFilterBlock();
74
+ $block->setFilter($filter);
75
+
76
+ $subfilters = '';
77
+ $filters = $filter->getFilters();
78
+ if(count($filters)) {
79
+ foreach($filters as $f) {
80
+ $subfilters .= $this->_toHtmlRecursive($f);
81
+ }
82
+ }
83
+ $block->setSubfilters($subfilters);
84
+
85
+ return $block->toHtml();
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ *
92
+ * @return Mzax_Emarketing_Block_Filter_Test_Single
93
+ */
94
+ public function getFilterBlock()
95
+ {
96
+ $block = $this->getLayout()->createBlock('mzax_emarketing/filter_test_single');
97
+ $block->setTemplate('mzax/emarketing/filter/test/filter.phtml');
98
+
99
+ return $block;
100
+ }
101
+
102
+
103
+
104
+
105
+
106
+ }
app/code/community/Mzax/Emarketing/Block/Filter/Test/Single.php ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @method Mzax_Emarketing_Model_Object_Filter_Abstract getFilter()
30
+ * @method boolean getError()
31
+ * @method string getSelect()
32
+ * @method Mzax_Emarketing_Block_Filter_Object_Grid getGrid()
33
+ * @method string getGridHtml()
34
+ *
35
+ * @author Jacob Siefer
36
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
37
+ * @version 0.2.5
38
+ */
39
+ class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Template
40
+ {
41
+
42
+ protected function _construct()
43
+ {
44
+ parent::_construct();
45
+ $this->setTemplate('mzax/emarketing/filter/test/single.phtml');
46
+ }
47
+
48
+
49
+ protected function _toHtml()
50
+ {
51
+ $filter = $this->getFilter();
52
+ if(!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
53
+ return 'NO FILTER :(';
54
+ }
55
+ return parent::_toHtml();
56
+ }
57
+
58
+
59
+ protected function _beforeToHtml()
60
+ {
61
+ $filter = $this->getFilter();
62
+ if(!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
63
+ return;
64
+ }
65
+
66
+ $error = false;
67
+ $select = false;
68
+ $grid = null;
69
+
70
+ $time = microtime(true);
71
+
72
+ try {
73
+ $select = $filter->getSelect()->assembleAll();
74
+ $grid = $this->getFilterGrid($filter);
75
+ $total = $grid->getCollection()->getSize();
76
+ $gridHtml = $grid->getHtml();
77
+ if($this->isDebugMode()) {
78
+ $queryTime = microtime(true);
79
+ $filter->runFilterQuery();
80
+ $this->setQueryTime(microtime(true) - $queryTime);
81
+ }
82
+ $this->setGridSelect($grid->getCollection()->getSelect());
83
+ $this->setTotal($total);
84
+
85
+ $result = $filter->checkIndexes(false);
86
+ if(is_string($result)) {
87
+ $this->setIndexCheckResult($result);
88
+ }
89
+ }
90
+ catch(Exception $e) {
91
+ $gridHtml = "<p>{$e->getMessage()}</p>";
92
+ $gridHtml.= "<pre>{$e->getTraceAsString()}</pre>";
93
+ $error = true;
94
+ }
95
+
96
+ $time = microtime(true) - $time;
97
+
98
+ $this->setError($error);
99
+ $this->setGrid($grid);
100
+ $this->setGridHtml($gridHtml);
101
+ $this->setSelect($select);
102
+ $this->setTime($time);
103
+ }
104
+
105
+
106
+
107
+
108
+
109
+
110
+ /**
111
+ * Is debug mode?
112
+ *
113
+ * @return boolean
114
+ */
115
+ public function isDebugMode()
116
+ {
117
+ if(Mage::getIsDeveloperMode()) {
118
+ return true;
119
+ }
120
+ return true;
121
+ }
122
+
123
+
124
+ public function getObjectName()
125
+ {
126
+ return $this->getFilter()->getParentObject()->getName();
127
+ }
128
+
129
+
130
+
131
+ public function getStatusMessage()
132
+ {
133
+ $name = $this->getObjectName();
134
+ $total = $this->getTotal();
135
+
136
+ if($this->getError()) {
137
+ return $this->__("Error retrieving {$name}s");
138
+ }
139
+ if($total == 0) {
140
+ return $this->__("No {$name}s found");
141
+ }
142
+
143
+ return $this->__("%s {$name}s found", $total);
144
+ }
145
+
146
+
147
+
148
+ public function getStatusIcon()
149
+ {
150
+ $total = $this->getTotal();
151
+
152
+ if($this->getError()) {
153
+ return $this->getSkinUrl('images/error_msg_icon.gif');
154
+ }
155
+ if($total == 0) {
156
+ return $this->getSkinUrl('images/warning_msg_icon.gif');
157
+ }
158
+
159
+ return $this->getSkinUrl('images/success_msg_icon.gif');
160
+ }
161
+
162
+
163
+
164
+ public function getPreviewUrl()
165
+ {
166
+ return $this->getUrl('*/*/filterPreview', array('_current' => true, '_filter' => $this->getFilter()));
167
+ }
168
+
169
+
170
+
171
+
172
+ /**
173
+ *
174
+ *
175
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
176
+ * @return Mzax_Emarketing_Block_Filter_Object_Grid
177
+ */
178
+ public function getFilterGrid(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
179
+ {
180
+ /* @var $grid Mzax_Emarketing_Block_Filter_Object_Grid */
181
+ $grid = $this->getLayout()->createBlock('mzax_emarketing/filter_object_grid', '', array(
182
+ 'filter' => $filter,
183
+ 'id' => 'filterGrid_' . str_replace('--', '_', $filter->getId())
184
+ ));
185
+ $grid->setFilter($filter);
186
+ $grid->setDefaultLimit(5);
187
+ $grid->setGridUrl($this->getUrl('*/*/filterGrid', array('_filter' => $filter, '_current' => true)));
188
+ $grid->setUseAjax(true);
189
+
190
+ return $grid;
191
+ }
192
+
193
+
194
+
195
+
196
+
197
+ /**
198
+ *
199
+ * @return Mzax_Emarketing_Helper_SqlFormatter
200
+ */
201
+ public function getSqlFormatter()
202
+ {
203
+ return $this->helper('mzax_emarketing/sqlFormatter');
204
+ }
205
+
206
+
207
+
208
+
209
+
210
+ /**
211
+ * Generate url by route and parameters
212
+ *
213
+ * @param string $route
214
+ * @param array $params
215
+ * @return string
216
+ */
217
+ public function getUrl($route = '', $params = array())
218
+ {
219
+ if(isset($params['_filter'])) {
220
+ $params['filter_id'] = $params['_filter']->getId();
221
+ unset($params['_filter']);
222
+ }
223
+ return parent::getUrl($route, $params);
224
+ }
225
+
226
+
227
+
228
+
229
+ }
app/code/community/Mzax/Emarketing/Block/Filters.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Block_Filters implements Varien_Data_Form_Element_Renderer_Interface
34
+ {
35
+ public function render(Varien_Data_Form_Element_Abstract $element)
36
+ {
37
+ $provider = $element->getCampaign()->getRecipientProvider();
38
+
39
+ if($provider) {
40
+ $html = '<div class="filters">';
41
+ $html .= $provider->getFilter()->asHtml();
42
+ $html .= '</div>';
43
+ return $html;
44
+ }
45
+ return '';
46
+ }
47
+ }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Action.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Action render that allows option groups
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Block_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
33
+ {
34
+
35
+ /**
36
+ * Renders column
37
+ *
38
+ * @param Varien_Object $row
39
+ * @return string
40
+ */
41
+ public function render(Varien_Object $row)
42
+ {
43
+ $actions = $this->getColumn()->getActions();
44
+ if ( empty($actions) || !is_array($actions) ) {
45
+ return '&nbsp;';
46
+ }
47
+
48
+ $out = '<select class="action-select" onchange="varienGridAction.execute(this);">'
49
+ . '<option value=""></option>';
50
+
51
+ foreach ($actions as $action){
52
+ if ( !is_array($action) ) {
53
+ continue;
54
+ }
55
+ if(isset($action['actions']) && is_array($action['actions'])) {
56
+ $out .='<optgroup label="' . $action['caption'] . '">';
57
+ foreach($action['actions'] as $subaction) {
58
+ $out .= $this->_toOptionHtml($subaction, $row);
59
+ }
60
+ $out .='</optgroup>';
61
+ }
62
+ else if ( is_array($action) ) {
63
+ $out .= $this->_toOptionHtml($action, $row);
64
+ }
65
+ }
66
+ $out .= '</select>';
67
+ return $out;
68
+ }
69
+
70
+
71
+
72
+
73
+ }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Campaign.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Renderer for campaigns
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Block_Grid_Column_Renderer_Campaign
32
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Options
33
+ {
34
+
35
+
36
+ /**
37
+ * Render a grid cell as options
38
+ *
39
+ * @param Varien_Object $row
40
+ * @return string
41
+ */
42
+ public function render(Varien_Object $row)
43
+ {
44
+ $html = parent::render($row);
45
+
46
+ $id = $row->getCampaignId();
47
+ if($id) {
48
+ $url = $this->getUrl('*/campaign/edit', array('id' => $id));
49
+ return sprintf('<a href="%s">%s</a>', $url, $html);
50
+ }
51
+ return $html;
52
+ }
53
+
54
+
55
+
56
+
57
+ }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Recipient.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Recipient renderer
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Block_Grid_Column_Renderer_Recipient
34
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
35
+ {
36
+
37
+
38
+ /**
39
+ * Renders grid column
40
+ *
41
+ * @param Varien_Object $row
42
+ * @return mixed
43
+ */
44
+ public function _getValue(Varien_Object $row)
45
+ {
46
+ $value = parent::_getValue($row);
47
+ $recipient = $row->getRecipient();
48
+
49
+ if($recipient instanceof Mzax_Emarketing_Model_Recipient)
50
+ {
51
+ $campaign = $recipient->getCampaign();
52
+ $subject = $campaign->getRecipientProvider()->getSubject();
53
+
54
+ if($subject) {
55
+ $url = $subject->getAdminUrl($recipient->getObjectId());
56
+ return sprintf('<a href="%s">%s</a>', $url, $value);
57
+ }
58
+
59
+ }
60
+ return $value;
61
+ }
62
+ }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Size.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Size renderer
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Block_Grid_Column_Renderer_Size
34
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
35
+ {
36
+
37
+
38
+ /**
39
+ * Renders grid column
40
+ *
41
+ * @param Varien_Object $row
42
+ * @return mixed
43
+ */
44
+ public function render(Varien_Object $row)
45
+ {
46
+ $bytes = (int) $this::_getValue($row);
47
+
48
+ $html = $this->formatSize($bytes);
49
+
50
+ $html = "<div style=\"text-align:right;\">$html</div>";
51
+
52
+ return $html;
53
+
54
+
55
+ }
56
+
57
+
58
+
59
+ public function formatSize($bytes)
60
+ {
61
+ if($bytes > 0) {
62
+ $unit = intval(log($bytes, 1024));
63
+ $units = array('B', 'KB', 'MB', 'GB');
64
+ if (array_key_exists($unit, $units)) {
65
+ return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]);
66
+ }
67
+ }
68
+ return '';
69
+
70
+
71
+ }
72
+
73
+
74
+ }
app/code/community/Mzax/Emarketing/Block/Inbox/Email.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Inbox_Email extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+ public function __construct()
27
+ {
28
+ $this->_objectId = 'id';
29
+
30
+ $this->_blockGroup = 'mzax_emarketing';
31
+ $this->_controller = 'inbox';
32
+ $this->_mode = 'email';
33
+
34
+ parent::__construct();
35
+
36
+ $this->_updateButton('save', 'label', $this->__('Save'));
37
+ $this->_updateButton('delete', 'label', $this->__('Delete'));
38
+
39
+ }
40
+
41
+
42
+ public function getHeaderText()
43
+ {
44
+ $message = Mage::registry('current_email');
45
+ if ($message->getId()) {
46
+ return $this->htmlEscape($message->getSubject());
47
+ }
48
+ else {
49
+ return $this->__('New Email');
50
+ }
51
+ }
52
+
53
+
54
+
55
+ public function getValidationUrl()
56
+ {
57
+ return $this->getUrl('*/*/validate', array('_current'=>true));
58
+ }
59
+
60
+
61
+
62
+ protected function _prepareLayout()
63
+ {
64
+ // return false;
65
+ $this->_addButton('save_and_continue', array(
66
+ 'label' => $this->__('Save And Continue Edit'),
67
+ 'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
68
+ 'class' => 'save'
69
+ ), 10);
70
+
71
+
72
+ $this->_addButton('parse', array(
73
+ 'label' => $this->__('Parse'),
74
+ 'onclick' => "setLocation('{$this->getUrl('*/*/parse', array('_current' => true))}')"
75
+ ), 10);
76
+
77
+
78
+ return parent::_prepareLayout();
79
+ }
80
+
81
+
82
+ /**
83
+ * Get form action URL
84
+ *
85
+ * @return string
86
+ */
87
+ public function getFormActionUrl()
88
+ {
89
+ if ($this->hasFormActionUrl()) {
90
+ return $this->getData('form_action_url');
91
+ }
92
+ return $this->getUrl('*/*/save');
93
+ }
94
+
95
+
96
+ protected function _getSaveAndContinueUrl()
97
+ {
98
+ return $this->getUrl('*/*/save', array(
99
+ '_current' => true,
100
+ 'back' => 'edit'
101
+ ));
102
+ }
103
+ }
app/code/community/Mzax/Emarketing/Block/Inbox/Email/Form.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget_Form
33
+ {
34
+
35
+ protected function _prepareForm()
36
+ {
37
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
38
+ $form->setHtmlIdPrefix("email");
39
+ $form->setFieldNameSuffix("email");
40
+
41
+
42
+ /* @var $email Mzax_Emarketing_Model_Inbox_Email */
43
+ $email = Mage::registry('current_email');
44
+
45
+
46
+
47
+ // Setting custom renderer for content field to remove label column
48
+ $rendererWide = $this->getLayout()
49
+ ->createBlock('adminhtml/widget_form_renderer_fieldset_element')
50
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
51
+
52
+ $aceType = Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_ace');
53
+
54
+
55
+ if($email->getId()) {
56
+ $form->addField('message_id', 'hidden', array(
57
+ 'name' => 'message_id',
58
+ 'value' => $email->getId()
59
+ ));
60
+ }
61
+
62
+ $fieldset = $form->addFieldset('base_fieldset', array(
63
+ 'legend' => $this->__('Bounce Message'),
64
+ 'class' => 'fieldset-wide',
65
+ ))->addType('ace', $aceType);
66
+
67
+
68
+
69
+
70
+ $fieldset->addField('type', 'select', array(
71
+ 'name' => 'type',
72
+ 'required' => true,
73
+ 'label' => Mage::helper('mzax_emarketing')->__('Bounce Type'),
74
+ 'title' => Mage::helper('mzax_emarketing')->__('Bounce Type'),
75
+ 'options' => array(
76
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_SOFT => $this->__('Soft'),
77
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_HARD => $this->__('Hard'),
78
+ Mzax_Emarketing_Model_Inbox_Email::AUTOREPLY => $this->__('Autoreply'),
79
+ Mzax_Emarketing_Model_Inbox_Email::NO_BOUNCE => $this->__('No Bounce'),
80
+ ),
81
+ 'note' => "Email Bounce Type",
82
+ ));
83
+
84
+
85
+ $fieldset->addField('email', 'text', array(
86
+ 'name' => 'email',
87
+ 'label' => $this->__('Email (From)'),
88
+ 'title' => $this->__('Email (From)'),
89
+ 'note' => $this->__('The recipient we detected after parsing, may not be correct'),
90
+ 'readonly' => true
91
+ ));
92
+
93
+
94
+ $fieldset->addField('subject', 'text', array(
95
+ 'name' => 'subject',
96
+ 'label' => $this->__('Email Subject'),
97
+ 'title' => $this->__('Email Subject'),
98
+ 'readonly' => true
99
+ ));
100
+
101
+
102
+ if($campaign = $email->getCampaign()) {
103
+
104
+ $fieldset->addField('campaign_name', 'link', array(
105
+ 'label' => $this->__('Campagin'),
106
+ 'value' => $campaign->getName(),
107
+ 'href' => $this->getUrl('*/admin_campaign/edit', array('id' => $campaign->getId()))
108
+ ));
109
+
110
+ }
111
+
112
+ if($recipient = $email->getRecipient()) {
113
+ if($campaign) {
114
+ $href = $campaign->getRecipientProvider()->getObject()->getAdminUrl($recipient->getId());
115
+ $recipient->prepare();
116
+
117
+ $fieldset->addField('recipient_email', 'link', array(
118
+ 'label' => $this->__('Recipient'),
119
+ 'value' => sprintf('%s <%s>', $recipient->getName(), $recipient->getEmail()),
120
+ 'href' => $href
121
+ ));
122
+ }
123
+ }
124
+
125
+
126
+ $editor = $fieldset->addField('message', 'ace', array(
127
+ 'name' => 'message',
128
+ 'label' => $this->__('Message'),
129
+ 'title' => $this->__('Message'),
130
+ 'allow_fullscreen' => false,
131
+ 'mode' => 'ace/mode/text',
132
+ 'readonly' => true,
133
+ 'autosize' => true
134
+ ));
135
+
136
+
137
+
138
+
139
+
140
+
141
+ $fieldset = $form->addFieldset('headers_fieldset', array(
142
+ 'legend' => $this->__('Email Headers'),
143
+ 'class' => 'fieldset-wide',
144
+ ))->addType('ace', $aceType);
145
+
146
+ $editor = $fieldset->addField('headers', 'ace', array(
147
+ 'name' => 'headers',
148
+ 'label' => $this->__('Headers'),
149
+ 'title' => $this->__('Email Headers'),
150
+ 'style' => 'height:12em',
151
+ 'required' => true,
152
+ 'logo' => $this->getSkinUrl('images/logo.gif'),
153
+ 'fullscreen_title' => $this->__('Bounce Header'),
154
+ 'mode' => 'ace/mode/praat',
155
+ 'readonly' => true,
156
+ 'autosize' => true
157
+ ))->setRenderer($rendererWide);
158
+
159
+
160
+
161
+ $fieldset = $form->addFieldset('content_fieldset', array(
162
+ 'legend' => $this->__('Email Content'),
163
+ 'class' => 'fieldset-wide',
164
+ ))->addType('ace', $aceType);
165
+
166
+ $editor = $fieldset->addField('content', 'ace', array(
167
+ 'name' => 'content',
168
+ 'label' => $this->__('Content'),
169
+ 'title' => $this->__('Email Content'),
170
+ 'style' => 'height:36em',
171
+ 'required' => true,
172
+ 'logo' => $this->getSkinUrl('images/logo.gif'),
173
+ 'fullscreen_title' => $this->__('Bounce Body'),
174
+ 'mode' => 'ace/mode/text',
175
+ 'readonly' => true,
176
+ 'value' => $email->getContent()
177
+ ))->setRenderer($rendererWide);
178
+
179
+
180
+
181
+
182
+ $form->addValues($email->getData());
183
+ $this->setForm($form);
184
+ $form->setUseContainer(true);
185
+ return parent::_prepareForm();
186
+ }
187
+ }
app/code/community/Mzax/Emarketing/Block/Inbox/Grid.php ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setId('inbox_grid');
31
+ $this->setUseAjax(true);
32
+ $this->setSaveParametersInSession(true);
33
+ $this->setDefaultSort('email_id');
34
+ }
35
+
36
+
37
+ public function getCollection()
38
+ {
39
+ if(!$this->_collection) {
40
+ /* Mzax_Emarketing_Model_Resource_Inbox_Email_Collection */
41
+ $this->_collection = Mage::getResourceModel('mzax_emarketing/inbox_email_collection');
42
+ $this->_collection->assignRecipients();
43
+ $this->_collection->assignCampaigns();
44
+ }
45
+ return $this->_collection;
46
+ }
47
+
48
+
49
+ protected function _prepareColumns()
50
+ {
51
+ $this->addColumn('created_at', array(
52
+ 'header' => $this->__('Created At'),
53
+ 'index' => 'created_at',
54
+ 'gmtoffset' => true,
55
+ 'type' =>'datetime'
56
+ ));
57
+
58
+ $this->addColumn('recipient', array(
59
+ 'header' => $this->__('Recipient'),
60
+ 'index' => 'email',
61
+ 'frame_callback' => array($this, 'addCampaignLink'),
62
+ ));
63
+
64
+ $this->addColumn('subject', array(
65
+ 'header' => $this->__('Subject'),
66
+ 'index' => 'subject',
67
+ 'type' => 'text',
68
+ 'truncate' => 50
69
+ ));
70
+ $this->addColumn('message', array(
71
+ 'header' => $this->__('Message'),
72
+ 'index' => 'message',
73
+ 'type' => 'text',
74
+ 'truncate' => 100
75
+ ));
76
+ $this->addColumn('type', array(
77
+ 'header' => $this->__('Type'),
78
+ 'index' => 'type',
79
+ 'type' => 'options',
80
+ 'options' => array(
81
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_SOFT => $this->__('Soft'),
82
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_HARD => $this->__('Hard'),
83
+ Mzax_Emarketing_Model_Inbox_Email::AUTOREPLY => $this->__('Autoreply'),
84
+ Mzax_Emarketing_Model_Inbox_Email::UNSUBSCRIBE => $this->__('Unsubscribe'),
85
+ Mzax_Emarketing_Model_Inbox_Email::NO_BOUNCE => $this->__('No Bounce'),
86
+ ),
87
+ 'width' => '100px',
88
+ ));
89
+
90
+
91
+ /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
92
+ $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
93
+
94
+ $this->addColumn('campaign', array(
95
+ 'header' => $this->__('Campaign'),
96
+ 'index' => 'campaign_id',
97
+ 'type' => 'options',
98
+ 'options' => $campaigns->toOptionHash(),
99
+ 'frame_callback' => array($this, 'addCampaignLink'),
100
+ 'width' => '100px',
101
+ ));
102
+
103
+
104
+ if (!Mage::app()->isSingleStoreMode()) {
105
+ $this->addColumn('store_id', array(
106
+ 'header' => $this->__('Store'),
107
+ 'index' => 'store_id',
108
+ 'type' => 'store',
109
+ 'store_view' => false,
110
+ 'display_deleted' => true,
111
+ ));
112
+ }
113
+
114
+ $this->addColumn('status_code', array(
115
+ 'header' => $this->__('Status'),
116
+ 'index' =>'status_code'
117
+ ));
118
+
119
+ $this->addColumn('size', array(
120
+ 'header' => $this->__('Size'),
121
+ 'index' =>'size',
122
+ 'filter' => false,
123
+ 'renderer' => 'mzax_emarketing/grid_column_renderer_size',
124
+ 'width' => '50px',
125
+ ));
126
+
127
+ return parent::_prepareColumns();
128
+ }
129
+
130
+
131
+
132
+
133
+ /**
134
+ * Frame Callback
135
+ *
136
+ * Add link to admin for subject if available
137
+ *
138
+ *
139
+ * @param string $value
140
+ * @param Varien_Object $row
141
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
142
+ * @param boolean $export
143
+ * @return string
144
+ */
145
+ public function addSubjectLink($value, $row, $column, $export)
146
+ {
147
+ $recipient = $row->getRecipient();
148
+
149
+ if($recipient instanceof Mzax_Emarketing_Model_Recipient && !$export)
150
+ {
151
+ $campaign = $recipient->getCampaign();
152
+ $subject = $campaign->getRecipientProvider()->getSubject();
153
+
154
+ if($subject) {
155
+ $url = $subject->getAdminUrl($recipient->getObjectId());
156
+ return sprintf('<a href="%s">%s</a>', $url, $value);
157
+ }
158
+
159
+ }
160
+ }
161
+
162
+
163
+
164
+ /**
165
+ * Frame Callback
166
+ *
167
+ * Add link to campaign if available
168
+ *
169
+ * @param string $value
170
+ * @param Varien_Object $row
171
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
172
+ * @param boolean $export
173
+ * @return string
174
+ */
175
+ public function addCampaignLink($value, $row, $column, $export)
176
+ {
177
+ $id = $row->getCampaignId();
178
+ if($id && !$export) {
179
+ $url = $this->getUrl('*/admin_campaign/edit', array('id' => $id));
180
+ return sprintf('<a href="%s">%s</a>', $url, $value);
181
+ }
182
+ return $value;
183
+ }
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+ protected function _prepareMassaction()
193
+ {
194
+ $this->setMassactionIdField('email_id');
195
+ $this->getMassactionBlock()->setFormFieldName('messages');
196
+
197
+ $this->getMassactionBlock()->addItem('delete', array(
198
+ 'label' => $this->__('Delete Emails'),
199
+ 'url' => $this->getUrl('*/*/massDelete'),
200
+ 'confirm' => $this->__('Are you sure?')
201
+ ));
202
+
203
+ $this->getMassactionBlock()->addItem('reparse', array(
204
+ 'label' => $this->__('Re-parse Emails'),
205
+ 'url' => $this->getUrl('*/*/massParse')
206
+ ));
207
+
208
+ $this->getMassactionBlock()->addItem('flag_as', array(
209
+ 'label'=> $this->__('Flag as...'),
210
+ 'url' => $this->getUrl('*/*/massFlag', array('_current'=>true)),
211
+ 'additional' => array(
212
+ 'visibility' => array(
213
+ 'name' => 'type',
214
+ 'type' => 'select',
215
+ 'class' => 'required-entry',
216
+ 'label' => $this->__('Type'),
217
+ 'options' => array(
218
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_SOFT => $this->__('Soft'),
219
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_HARD => $this->__('Hard'),
220
+ Mzax_Emarketing_Model_Inbox_Email::AUTOREPLY => $this->__('Autoreply'),
221
+ Mzax_Emarketing_Model_Inbox_Email::NO_BOUNCE => $this->__('No Bounce'),
222
+ ),
223
+ )
224
+ )
225
+ ));
226
+
227
+ $this->getMassactionBlock()->addItem('forward', array(
228
+ 'label' => $this->__('Forward emails'),
229
+ 'url' => $this->getUrl('*/*/massForward')
230
+ ));
231
+
232
+
233
+ // enable disable
234
+ $this->getMassactionBlock()->addItem('report', array(
235
+ 'label' => $this->__('Report as bounce'),
236
+ 'url' => $this->getUrl('*/*/massReport'),
237
+ 'confirm' => $this->__('Thank you for your help! This will forward the email to me (Jacob Siefer) and I will use it to test it against the bounce filter. I will not share or publish any of the orignal content.')
238
+ ));
239
+
240
+ return $this;
241
+ }
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+ public function getGridUrl()
251
+ {
252
+ return $this->getUrl('*/*/grid', array('_current'=> true));
253
+ }
254
+
255
+ public function getRowUrl($row)
256
+ {
257
+ return $this->getUrl('*/*/email', array('id'=>$row->getId()));
258
+ }
259
+ }
app/code/community/Mzax/Emarketing/Block/Inbox/View.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Inbox_View extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'mzax_emarketing';
30
+ $this->_controller = 'inbox';
31
+ $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Inbox');
32
+
33
+ parent::__construct();
34
+
35
+ $this->removeButton('add');
36
+
37
+ $this->_addButton('fetch', array(
38
+ 'label' => $this->__('Get new messages'),
39
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/fetch') .'\')',
40
+ 'class' => '',
41
+ ));
42
+
43
+ }
44
+
45
+
46
+
47
+ }
app/code/community/Mzax/Emarketing/Block/Outbox/Email.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Outbox_Email extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+ public function __construct()
27
+ {
28
+ $this->_objectId = 'id';
29
+
30
+ $this->_blockGroup = 'mzax_emarketing';
31
+ $this->_controller = 'outbox';
32
+ $this->_mode = 'email';
33
+
34
+ parent::__construct();
35
+ $email = Mage::registry('current_email');
36
+
37
+
38
+ $this->_updateButton('save', 'label', $this->__('Save'));
39
+ $this->_updateButton('delete', 'label', $this->__('Delete'));
40
+
41
+ if($email->getId() && $email->getStatus() == Mzax_Emarketing_Model_Outbox_Email::STATUS_NOT_SEND) {
42
+ $this->_addButton('discard', array(
43
+ 'label' => $this->__('Discard'),
44
+ 'class' => 'delete',
45
+ 'onclick' => 'deleteConfirm(\''. $this->__('Are you sure you want to do this?')
46
+ .'\', \'' . $this->getUrl('*/*/*', array('_current' => true)) . '\')',
47
+ ));
48
+ $this->_addButton('render', array(
49
+ 'label' => $this->__('re-Render'),
50
+ 'class' => 'save',
51
+ 'onclick' => "setLocation('{$this->getUrl('*/*/render', array('_current' => true))}')",
52
+ ));
53
+ }
54
+
55
+ $this->_addButton('download', array(
56
+ 'label' => Mage::helper('adminhtml')->__('Download'),
57
+ 'class' => 'download',
58
+ 'onclick' => "setLocation('{$this->getUrl('*/*/download', array('_current' => true))}')",
59
+ ));
60
+
61
+
62
+ $this->_removeButton('save');
63
+ $this->_removeButton('reset');
64
+
65
+ }
66
+
67
+
68
+ public function getHeaderText()
69
+ {
70
+ $message = Mage::registry('current_email');
71
+ if ($message->getId()) {
72
+ return $this->htmlEscape($message->getSubject());
73
+ }
74
+ else {
75
+ return $this->__('New Email');
76
+ }
77
+ }
78
+
79
+
80
+
81
+ public function getValidationUrl()
82
+ {
83
+ return $this->getUrl('*/*/validate', array('_current'=>true));
84
+ }
85
+
86
+
87
+
88
+ protected function _prepareLayout()
89
+ {
90
+ return parent::_prepareLayout();
91
+ }
92
+
93
+
94
+ /**
95
+ * Get form action URL
96
+ *
97
+ * @return string
98
+ */
99
+ public function getFormActionUrl()
100
+ {
101
+ if ($this->hasFormActionUrl()) {
102
+ return $this->getData('form_action_url');
103
+ }
104
+ return $this->getUrl('*/*/save');
105
+ }
106
+
107
+
108
+ }
app/code/community/Mzax/Emarketing/Block/Outbox/Email/Form.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
30
+ $form->setHtmlIdPrefix("email");
31
+ $form->setFieldNameSuffix("email");
32
+
33
+
34
+ /* @var $email Mzax_Emarketing_Model_Outbox_Email */
35
+ $email = Mage::registry('current_email');
36
+
37
+
38
+
39
+ // Setting custom renderer for content field to remove label column
40
+ $rendererWide = $this->getLayout()
41
+ ->createBlock('adminhtml/widget_form_renderer_fieldset_element')
42
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
43
+
44
+ $aceType = Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_ace');
45
+
46
+
47
+ if($email->getId()) {
48
+ $form->addField('message_id', 'hidden', array(
49
+ 'name' => 'message_id',
50
+ 'value' => $email->getId()
51
+ ));
52
+ }
53
+
54
+ $fieldset = $form->addFieldset('base_fieldset', array(
55
+ 'legend' => $this->__('Details'),
56
+ 'class' => 'fieldset-wide',
57
+ ))->addType('ace', $aceType);
58
+
59
+
60
+
61
+
62
+ $fieldset->addField('email', 'text', array(
63
+ 'name' => 'email',
64
+ 'label' => $this->__('Email (From)'),
65
+ 'title' => $this->__('Email (From)'),
66
+ 'readonly' => true
67
+ ));
68
+
69
+
70
+ $fieldset->addField('subject', 'text', array(
71
+ 'name' => 'subject',
72
+ 'label' => $this->__('Email Subject'),
73
+ 'title' => $this->__('Email Subject'),
74
+ 'value' => $email->getSubject(),
75
+ 'readonly' => true
76
+ ));
77
+
78
+
79
+ if($campaign = $email->getCampaign()) {
80
+
81
+ $fieldset->addField('campaign_name', 'link', array(
82
+ 'label' => $this->__('Campagin'),
83
+ 'value' => $campaign->getName(),
84
+ 'href' => $this->getUrl('*/admin_campaign/edit', array('id' => $campaign->getId()))
85
+ ));
86
+
87
+ }
88
+
89
+ if($recipient = $email->getRecipient()) {
90
+ if($campaign) {
91
+ $href = $campaign->getRecipientProvider()->getObject()->getAdminUrl($recipient->getId());
92
+ $recipient->prepare();
93
+
94
+ $fieldset->addField('recipient_email', 'link', array(
95
+ 'label' => $this->__('Recipient'),
96
+ 'value' => sprintf('%s <%s>', $recipient->getName(), $recipient->getEmail()),
97
+ 'href' => $href
98
+ ));
99
+ }
100
+ }
101
+
102
+
103
+ $editor = $fieldset->addField('message', 'ace', array(
104
+ 'name' => 'message',
105
+ 'label' => $this->__('Message'),
106
+ 'title' => $this->__('Message'),
107
+ 'allow_fullscreen' => false,
108
+ 'mode' => 'ace/mode/text',
109
+ 'style' => 'min-height:5em',
110
+ 'readonly' => true,
111
+ 'autosize' => true,
112
+ 'value' => $email->getMessage(),
113
+ 'note' => $this->__('The plain text version of this email'),
114
+ ));
115
+
116
+
117
+
118
+
119
+
120
+
121
+ $fieldset = $form->addFieldset('headers_fieldset', array(
122
+ 'legend' => $this->__('Email Headers'),
123
+ 'class' => 'fieldset-wide',
124
+ ))->addType('ace', $aceType);
125
+
126
+ $editor = $fieldset->addField('headers', 'ace', array(
127
+ 'name' => 'headers',
128
+ 'label' => $this->__('Headers'),
129
+ 'title' => $this->__('Email Headers'),
130
+ 'style' => 'min-height:5em',
131
+ 'required' => true,
132
+ 'logo' => $this->getSkinUrl('images/logo.gif'),
133
+ 'fullscreen_title' => $this->__('Email Headers'),
134
+ 'mode' => 'ace/mode/praat',
135
+ 'readonly' => true,
136
+ 'autosize' => true,
137
+ 'value' => $email->getHeaders()
138
+ ))->setRenderer($rendererWide);
139
+
140
+
141
+
142
+ $fieldset = $form->addFieldset('html_fieldset', array(
143
+ 'legend' => $this->__('HTML Code'),
144
+ 'class' => 'fieldset-wide',
145
+ ))->addType('ace', $aceType);
146
+
147
+ $editor = $fieldset->addField('html_body', 'ace', array(
148
+ 'name' => 'html_body',
149
+ 'label' => $this->__('HTML Code'),
150
+ 'title' => $this->__('HTML Code'),
151
+ 'style' => 'height:36em',
152
+ 'required' => true,
153
+ 'logo' => $this->getSkinUrl('images/logo.gif'),
154
+ 'fullscreen_title' => $this->__('HTML Body'),
155
+ 'mode' => 'ace/mode/html',
156
+ 'readonly' => true,
157
+ 'value' => $email->getBodyHtml()
158
+ ))->setRenderer($rendererWide);
159
+
160
+
161
+
162
+
163
+
164
+ $fieldset = $form->addFieldset('content_fieldset', array(
165
+ 'legend' => $this->__('Raw Content'),
166
+ 'class' => 'fieldset-wide',
167
+ ))->addType('ace', $aceType);
168
+
169
+ $editor = $fieldset->addField('content', 'ace', array(
170
+ 'name' => 'content',
171
+ 'label' => $this->__('Content'),
172
+ 'title' => $this->__('Email Content'),
173
+ 'style' => 'height:36em',
174
+ 'required' => true,
175
+ 'logo' => $this->getSkinUrl('images/logo.gif'),
176
+ 'fullscreen_title' => $this->__('Raw Email Content'),
177
+ 'mode' => 'ace/mode/text',
178
+ 'readonly' => true,
179
+ 'value' => $email->getContent()
180
+ ))->setRenderer($rendererWide);
181
+
182
+
183
+ $form->addValues($email->getData());
184
+ $this->setForm($form);
185
+ $form->setUseContainer(true);
186
+ return parent::_prepareForm();
187
+ }
188
+ }
app/code/community/Mzax/Emarketing/Block/Outbox/Grid.php ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setId('outbox_grid');
31
+ $this->setUseAjax(true);
32
+ $this->setSaveParametersInSession(true);
33
+ $this->setDefaultSort('created_at');
34
+ $this->setDefaultDir('desc');
35
+ }
36
+
37
+
38
+ protected function _beforeToHtml()
39
+ {
40
+ $this->setId('outbox_grid');
41
+ parent::_beforeToHtml();
42
+ }
43
+
44
+
45
+
46
+ public function getCollection()
47
+ {
48
+ if(!$this->_collection) {
49
+ /* Mzax_Emarketing_Model_Resource_Outbox_Email_Collection */
50
+ $this->_collection = Mage::getResourceModel('mzax_emarketing/outbox_email_collection');
51
+ $this->_collection->assignRecipients();
52
+ $this->_collection->assignCampaigns();
53
+ }
54
+ return $this->_collection;
55
+ }
56
+
57
+
58
+ protected function _prepareColumns()
59
+ {
60
+ $this->addColumn('created_at', array(
61
+ 'header' => $this->__('Created at'),
62
+ 'index' => 'created_at',
63
+ 'gmtoffset' => true,
64
+ 'type' =>'datetime'
65
+ ));
66
+
67
+ $this->addColumn('recipient', array(
68
+ 'header' => $this->__('Recipient'),
69
+ 'index' => 'to',
70
+ 'frame_callback' => array($this, 'addObjectLink'),
71
+ ));
72
+
73
+
74
+ $this->addColumn('sent_at', array(
75
+ 'header' => $this->__('Sent at'),
76
+ 'index' => 'sent_at',
77
+ 'gmtoffset' => true,
78
+ 'type' =>'datetime'
79
+ ));
80
+ $this->addColumn('expire_at', array(
81
+ 'header' => $this->__('Expire at'),
82
+ 'index' => 'expire_at',
83
+ 'gmtoffset' => true,
84
+ 'type' =>'datetime'
85
+ ));
86
+
87
+
88
+ /*
89
+ $this->addColumn('subject', array(
90
+ 'header' => $this->__('Subject'),
91
+ 'index' => 'subject',
92
+ 'type' => 'text',
93
+ 'getter' => function($row) {
94
+ return $row->getSubject();
95
+ },
96
+ 'truncate' => 50
97
+ ));
98
+ $this->addColumn('message', array(
99
+ 'header' => $this->__('Message'),
100
+ 'index' => 'message',
101
+ 'type' => 'text',
102
+ 'getter' => function($row) {
103
+ return $row->getMessage();
104
+ },
105
+ 'truncate' => 100
106
+ ));
107
+ */
108
+
109
+ /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
110
+ $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
111
+
112
+ $this->addColumn('campaign', array(
113
+ 'header' => $this->__('Campaign'),
114
+ 'index' => 'campaign_id',
115
+ 'type' => 'options',
116
+ 'options' => $campaigns->toOptionHash(),
117
+ 'frame_callback' => array($this, 'addCampaignLink'),
118
+ 'width' => '100px',
119
+ ));
120
+
121
+
122
+ $this->addColumn('status', array(
123
+ 'header' => $this->__('Status'),
124
+ 'index' => 'status',
125
+ 'type' => 'options',
126
+ 'options' => array(
127
+ Mzax_Emarketing_Model_Outbox_Email::STATUS_NOT_SEND => $this->__('Not yet sent'),
128
+ Mzax_Emarketing_Model_Outbox_Email::STATUS_EXPIRED => $this->__('Expired'),
129
+ Mzax_Emarketing_Model_Outbox_Email::STATUS_FAILED => $this->__('Failed'),
130
+ Mzax_Emarketing_Model_Outbox_Email::STATUS_SENT => $this->__('Sent'),
131
+ Mzax_Emarketing_Model_Outbox_Email::STATUS_DISCARDED => $this->__('Discarded'),
132
+ ),
133
+ 'frame_callback' => function($value, $row, $column, $export){
134
+ $status = $row->getData($column->getIndex());
135
+ return "<span class=\"outbox-status-{$status}\">!!$value!!</span>";
136
+ },
137
+ 'width' => '100px',
138
+ ));
139
+
140
+ return parent::_prepareColumns();
141
+ }
142
+
143
+
144
+
145
+
146
+ /**
147
+ * Frame Callback
148
+ *
149
+ * Add link to admin for subject if available
150
+ *
151
+ *
152
+ * @param string $value
153
+ * @param Varien_Object $row
154
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
155
+ * @param boolean $export
156
+ * @return string
157
+ */
158
+ public function addObjectLink($value, $row, $column, $export)
159
+ {
160
+ $recipient = $row->getRecipient();
161
+
162
+ if($recipient instanceof Mzax_Emarketing_Model_Recipient && !$export)
163
+ {
164
+ $campaign = $recipient->getCampaign();
165
+ if($campaign->getRecipientProvider()) {
166
+ $object = $campaign->getRecipientProvider()->getObject();
167
+
168
+ if($object) {
169
+ $url = $object->getAdminUrl($recipient->getObjectId());
170
+ return sprintf('<a href="%s">%s</a>', $url, $value);
171
+ }
172
+ }
173
+ }
174
+ return $value;
175
+ }
176
+
177
+
178
+
179
+ /**
180
+ * Frame Callback
181
+ *
182
+ * Add link to campaign if available
183
+ *
184
+ * @param string $value
185
+ * @param Varien_Object $row
186
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
187
+ * @param boolean $export
188
+ * @return string
189
+ */
190
+ public function addCampaignLink($value, $row, $column, $export)
191
+ {
192
+ $id = $row->getCampaignId();
193
+ if($id && !$export) {
194
+ $url = $this->getUrl('*/admin_campaign/edit', array('id' => $id));
195
+ return sprintf('<a href="%s">%s</a>', $url, $value);
196
+ }
197
+ return $value;
198
+ }
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+ protected function _prepareMassaction()
208
+ {
209
+ $this->setMassactionIdField('email_id');
210
+ $this->getMassactionBlock()->setFormFieldName('messages');
211
+
212
+
213
+ $this->getMassactionBlock()->addItem('send', array(
214
+ 'label' => $this->__('Send'),
215
+ 'url' => $this->getUrl('*/admin_outbox/massSend'),
216
+ 'confirm' => $this->__('Are you sure you want to send those emails now?')
217
+ ));
218
+
219
+ $this->getMassactionBlock()->addItem('delete', array(
220
+ 'label' => $this->__('Delete'),
221
+ 'url' => $this->getUrl('*/admin_outbox/massDelete'),
222
+ 'confirm' => $this->__('Are you sure?')
223
+ ));
224
+
225
+ $this->getMassactionBlock()->addItem('discard', array(
226
+ 'label' => $this->__('Discard'),
227
+ 'url' => $this->getUrl('*/admin_outbox/massDiscard'),
228
+ 'confirm' => $this->__('Are you sure?')
229
+ ));
230
+
231
+
232
+ return $this;
233
+ }
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+ public function getGridUrl()
243
+ {
244
+ return $this->getUrl('*/*/grid', array('_current'=> true));
245
+ }
246
+
247
+ public function getRowUrl($row)
248
+ {
249
+ return $this->getUrl('*/*/email', array('id'=>$row->getId()));
250
+ }
251
+ }
app/code/community/Mzax/Emarketing/Block/Outbox/View.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Outbox_View extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'mzax_emarketing';
30
+ $this->_controller = 'outbox';
31
+ $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Outbox');
32
+
33
+ parent::__construct();
34
+
35
+
36
+ $this->_removeButton('add');
37
+
38
+ $this->_addButton('send', array(
39
+ 'label' => $this->__('Send Pending'),
40
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/send') .'\')',
41
+ 'class' => '',
42
+ ));
43
+ }
44
+
45
+
46
+
47
+ }
app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Attribute.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Recipients_Column_Renderer_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
25
+ {
26
+
27
+ /**
28
+ * Retrieve attribute
29
+ *
30
+ * @return Mage_Catalog_Model_Resource_Eav_Attribute
31
+ */
32
+ public function getAttribute()
33
+ {
34
+ return $this->getColumn()->getAttribute();
35
+ }
36
+
37
+
38
+
39
+
40
+ public function render(Varien_Object $row)
41
+ {
42
+ $attribute = $this->getAttribute();
43
+
44
+
45
+ $data = $row->getData($attribute->getAttributeCode());
46
+
47
+ if($attribute->getFrontendInput() === 'multiselect') {
48
+
49
+ $searchValue = (array) $this->getColumn()->getSearchValue();
50
+
51
+ $result = array();
52
+ foreach(explode(',', $data) as $value) {
53
+ $valueText = $attribute->getSource()->getOptionText($value);
54
+ if(in_array($value, $searchValue)) {
55
+ $valueText = "<strong>$valueText</strong>";
56
+ }
57
+ $result[] = $valueText;
58
+ }
59
+
60
+ $data = implode(', ', $result);
61
+ }
62
+
63
+
64
+
65
+ return $data;
66
+ }
67
+
68
+
69
+
70
+
71
+
72
+ }
app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Object.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Recipients_Column_Renderer_Object extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
25
+ {
26
+
27
+ /**
28
+ * Retrieve current object
29
+ *
30
+ * @return Mzax_Emarketing_Model_Object_Abstract
31
+ */
32
+ public function getObject()
33
+ {
34
+ return $this->getColumn()->getObject();
35
+ }
36
+
37
+
38
+
39
+
40
+ public function render(Varien_Object $row)
41
+ {
42
+ $idField = $this->getColumn()->getIdField();
43
+ if(!$idField) {
44
+ $idField = $row->getIdFieldName();
45
+ }
46
+
47
+ $labelField = $this->getColumn()->getLabelField();
48
+ if($labelField) {
49
+ $label = $row->getData($labelField);
50
+ }
51
+ else {
52
+ $label = $this->getObject()->getRowId($row);
53
+ }
54
+
55
+
56
+ $url = $this->getObject()->getAdminUrl($row->getData($idField));
57
+ if($url) {
58
+ return "<a href=\"{$url}\">$label</a>";
59
+ }
60
+ return $label;
61
+ }
62
+ }
app/code/community/Mzax/Emarketing/Block/Recipients/Grid.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ *
28
+ * @method Mzax_Emarketing_Model_Object_Collection getCollection()
29
+ *
30
+ * @author Jacob Siefer
31
+ *
32
+ */
33
+ class Mzax_Emarketing_Block_Recipients_Grid extends Mage_Adminhtml_Block_Widget_Grid
34
+ {
35
+
36
+ /**
37
+ * @var Mzax_Emarketing_Model_Object_Filter_Component
38
+ */
39
+ protected $_source;
40
+
41
+
42
+
43
+ public function __construct()
44
+ {
45
+ parent::__construct();
46
+ }
47
+
48
+
49
+ /**
50
+ *
51
+ *
52
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
53
+ */
54
+ public function getSource()
55
+ {
56
+ return $this->_source;
57
+ }
58
+
59
+
60
+ /**
61
+ *
62
+ * @return Mzax_Emarketing_Model_Object_Abstract
63
+ */
64
+ public function getObject()
65
+ {
66
+ return $this->getCollection()->getObject();
67
+ }
68
+
69
+
70
+ /**
71
+ *
72
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $source
73
+ * @return Mzax_Emarketing_Block_Recipients_Grid
74
+ */
75
+ public function setSource(Mzax_Emarketing_Model_Object_Filter_Component $source)
76
+ {
77
+ $this->_source = $source;
78
+ return $this;
79
+ }
80
+
81
+
82
+
83
+ /**
84
+ * (non-PHPdoc)
85
+ * @see Mage_Adminhtml_Block_Widget_Grid::getCollection()
86
+ * @return Mzax_Emarketing_Model_Object_Collection
87
+ */
88
+ public function getCollection()
89
+ {
90
+ return $this->getSource()->getCollection();
91
+ }
92
+
93
+
94
+
95
+ /**
96
+ * Allow provider and filters to alter the grid
97
+ *
98
+ */
99
+ protected function _afterLoadCollection()
100
+ {
101
+ parent::_afterLoadCollection();
102
+ $this->getSource()->afterGridLoadCollection($this);
103
+
104
+ return $this;
105
+ }
106
+
107
+
108
+
109
+
110
+
111
+ /**
112
+ * Prepare grid columns
113
+ *
114
+ * This is done by the email provider. The grid
115
+ * does not know what type of objects it is loading
116
+ *
117
+ */
118
+ protected function _prepareColumns()
119
+ {
120
+ $object = $this->getObject();
121
+
122
+ $this->setFilterVisibility(true);
123
+ $this->setPagerVisibility(true);
124
+
125
+ $this->addColumn('main_object_id', array(
126
+ 'header' => $this->__($object->getName() .' ID'),
127
+ 'index' => 'id',
128
+ 'is_system' => true,
129
+ 'width' => '50px',
130
+ 'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
131
+ 'object' => $object,
132
+ ));
133
+
134
+ $this->setDefaultSort('main_object_id');
135
+ $this->setDefaultDir('DESC');
136
+
137
+ $this->getSource()->prepareGridColumns($this);
138
+ return parent::_prepareColumns();
139
+ }
140
+
141
+
142
+
143
+ public function getGridUrl()
144
+ {
145
+ return $this->getData('grid_url');
146
+ }
147
+
148
+
149
+
150
+ public function getRowUrl($row)
151
+ {
152
+ return null;
153
+ }
154
+
155
+
156
+
157
+
158
+ }
app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/DomainThreshold.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @author Jacob Siefer
27
+ *
28
+ */
29
+ class Mzax_Emarketing_Block_System_Config_Form_Field_DomainThreshold
30
+ extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
31
+ {
32
+ public function __construct()
33
+ {
34
+ $this->addColumn('domain', array(
35
+ 'label' => $this->__('Domain'),
36
+ 'style' => 'width:150px',
37
+ 'class' => 'required-entry'
38
+ ));
39
+ $this->addColumn('time_threshold', array(
40
+ 'label' => $this->__('[T]'),
41
+ 'style' => 'width:30px',
42
+ 'class' => 'required-entry validate-zero-or-greater'
43
+ ));
44
+ $this->addColumn('send_threshold', array(
45
+ 'label' => $this->__('[S]'),
46
+ 'style' => 'width:30px',
47
+ 'class' => 'required-entry validate-zero-or-greater'
48
+ ));
49
+ $this->addColumn('rest_time', array(
50
+ 'label' => $this->__('[R]'),
51
+ 'style' => 'width:30px',
52
+ 'class' => 'required-entry validate-zero-or-greater'
53
+ ));
54
+
55
+ $this->_addAfter = false;
56
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add Domain');
57
+ parent::__construct();
58
+ }
59
+ }
app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/MailStorage.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @author Jacob Siefer
27
+ *
28
+ */
29
+ class Mzax_Emarketing_Block_System_Config_Form_Field_MailStorage
30
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
31
+ {
32
+
33
+
34
+
35
+ protected function _getHtml()
36
+ {
37
+ /* @var $inbox Mzax_Emarketing_Model_Inbox_Email_Collector */
38
+ $collector = Mage::getSingleton('mzax_emarketing/inbox_email_collector');
39
+ $result = $collector->test();
40
+
41
+ if($result) {
42
+ $message = Mage::helper('mzax_emarketing')->__('Successfully conntected to inbox');
43
+ $class = 'inbox-success';
44
+ }
45
+ else {
46
+ $message = Mage::helper('mzax_emarketing')->__('Failed to conntected to inbox');
47
+ $class = 'inbox-failure';
48
+ }
49
+
50
+ return '<div class="inbox-status '.$class.'">' . $message . '</div>';
51
+ }
52
+
53
+
54
+
55
+ public function render(Varien_Data_Form_Element_Abstract $element)
56
+ {
57
+ $id = $element->getHtmlId();
58
+
59
+ if(!Mage::getStoreConfigFlag('mzax_emarketing/inbox/enable')) {
60
+ return '';
61
+ }
62
+
63
+ $useContainerId = $element->getData('use_container_id');
64
+ $html = '<tr id="row_' . $id . '">'
65
+ . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
66
+ . '</tr>';
67
+ return $html;
68
+ }
69
+ }
app/code/community/Mzax/Emarketing/Block/Template/Edit.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Template_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+ public function __construct()
27
+ {
28
+ $this->_objectId = 'id';
29
+
30
+ $this->_blockGroup = 'mzax_emarketing';
31
+ $this->_controller = 'template';
32
+
33
+
34
+ parent::__construct();
35
+
36
+ $this->_updateButton('save', 'label', $this->__('Save Template'));
37
+ $this->_updateButton('delete', 'label', $this->__('Delete Template'));
38
+
39
+ if(Mage::registry('current_template')->getId()) {
40
+ $this->_addButton('download', array(
41
+ 'label' => $this->__('Download'),
42
+ 'class' => 'download',
43
+ 'onclick' => "setLocation('{$this->getUrl('*/*/download', array('_current' => true))}')",
44
+ ));
45
+ }
46
+
47
+ }
48
+
49
+
50
+
51
+
52
+ public function getHeaderText()
53
+ {
54
+ $template = Mage::registry('current_template');
55
+ if ($template->getId()) {
56
+ return $this->htmlEscape($template->getName());
57
+ }
58
+ else {
59
+ return $this->__('New Template');
60
+ }
61
+ }
62
+
63
+ public function getValidationUrl()
64
+ {
65
+ return $this->getUrl('*/*/validate', array('_current'=>true));
66
+ }
67
+
68
+ protected function _prepareLayout()
69
+ {
70
+ $this->_addButton('save_and_continue', array(
71
+ 'label' => $this->__('Save And Continue Edit'),
72
+ 'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
73
+ 'class' => 'save'
74
+ ), 10);
75
+
76
+ return parent::_prepareLayout();
77
+ }
78
+
79
+
80
+ /**
81
+ * Get form action URL
82
+ *
83
+ * @return string
84
+ */
85
+ public function getFormActionUrl()
86
+ {
87
+ if ($this->hasFormActionUrl()) {
88
+ return $this->getData('form_action_url');
89
+ }
90
+ return $this->getUrl('*/*/save');
91
+ }
92
+
93
+
94
+ protected function _getSaveAndContinueUrl()
95
+ {
96
+ return $this->getUrl('*/*/save', array(
97
+ '_current' => true,
98
+ 'back' => 'edit'
99
+ ));
100
+ }
101
+ }
app/code/community/Mzax/Emarketing/Block/Template/Edit/Form.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Template_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
30
+ $form->setHtmlIdPrefix("template");
31
+ $form->setFieldNameSuffix("template");
32
+
33
+
34
+
35
+
36
+
37
+ /* @var $template Mzax_Emarketing_Model_Template */
38
+ $template = Mage::registry('current_template');
39
+
40
+
41
+ if($template->getId()) {
42
+ $form->addField('template_id', 'hidden', array(
43
+ 'name' => 'template_id',
44
+ 'value' => $template->getId()
45
+ ));
46
+ }
47
+
48
+
49
+ $fieldset = $form->addFieldset('base_fieldset', array(
50
+ 'legend' => $this->__('Template Option'),
51
+ 'class' => 'fieldset-wide',
52
+ ))
53
+ ->addType('editor', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_templateEditor'))
54
+ ->addType('credits', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_credits'));
55
+
56
+
57
+
58
+ $fieldset->addField('credits', 'credits', array(
59
+ 'name' => 'credits',
60
+ 'required' => true
61
+ ));
62
+
63
+
64
+ $fieldset->addField('name', 'text', array(
65
+ 'name' => 'name',
66
+ 'required' => true,
67
+ 'label' => $this->__('Template Name'),
68
+ 'title' => $this->__('Template Name'),
69
+ ));
70
+
71
+ $fieldset->addField('description', 'textarea', array(
72
+ 'name' => 'description',
73
+ 'required' => true,
74
+ 'label' => $this->__('Description'),
75
+ 'title' => $this->__('Description'),
76
+ 'style' => 'height:4em;',
77
+ 'note' => "For internal use only",
78
+ ));
79
+
80
+
81
+
82
+ $snippets = new Mzax_Emarketing_Model_Medium_Email_Snippets;
83
+ Mage::getSingleton('mzax_emarketing/medium_email')->prepareSnippets($snippets);
84
+
85
+
86
+ $editorConfig = new Varien_Object();
87
+ $editorConfig->setFilesBrowserWindowUrl($this->getUrl('adminhtml/cms_wysiwyg_images/index'));
88
+ $editorConfig->setWidgetWindowUrl($this->getUrl('adminhtml/widget/index'));
89
+ $editorConfig->setSnippets($snippets);
90
+
91
+
92
+
93
+ $editor = $fieldset->addField('body', 'editor', array(
94
+ 'name' => 'body',
95
+ 'required' => true,
96
+ 'label' => $this->__('Template HTML'),
97
+ 'title' => $this->__('Template HTML'),
98
+ 'logo' => $this->getSkinUrl('images/logo.gif'),
99
+ 'fullscreen_title' => $this->__('Template %s', $template->getName()),
100
+ 'style' => 'height:50em;',
101
+ 'value' => '',
102
+ 'config' => $editorConfig
103
+ ));
104
+
105
+ // Setting custom renderer for content field to remove label column
106
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
107
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
108
+ $editor->setRenderer($renderer);
109
+
110
+
111
+
112
+
113
+ $form->addValues($template->getData());
114
+ $this->setForm($form);
115
+ $form->setUseContainer(true);
116
+ return parent::_prepareForm();
117
+ }
118
+ }
app/code/community/Mzax/Emarketing/Block/Template/Grid.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Template_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setId('template_grid');
31
+ $this->setUseAjax(true);
32
+ $this->setSaveParametersInSession(true);
33
+ $this->setDefaultSort('template_id');
34
+ }
35
+
36
+
37
+ protected function _prepareCollection()
38
+ {
39
+ /* @var $collection Mzax_Emarketing_Model_Resource_Template_Collection */
40
+ $collection = Mage::getResourceModel('mzax_emarketing/template_collection');
41
+ $this->setCollection($collection);
42
+
43
+ return parent::_prepareCollection();
44
+ }
45
+
46
+
47
+ protected function _prepareColumns()
48
+ {
49
+ $this->addColumn('created_at', array(
50
+ 'header' => $this->__('Created At'),
51
+ 'index' => 'created_at',
52
+ 'gmtoffset' => true,
53
+ 'type' =>'datetime'
54
+ ));
55
+
56
+ $this->addColumn('updated_at', array(
57
+ 'header' => $this->__('Updated At'),
58
+ 'index' =>'created_at',
59
+ 'gmtoffset' => true,
60
+ 'type' =>'datetime'
61
+ ));
62
+
63
+ $this->addColumn('name', array(
64
+ 'header' => $this->__('Name'),
65
+ 'index' => 'name',
66
+ ));
67
+
68
+
69
+ return parent::_prepareColumns();
70
+ }
71
+
72
+
73
+ protected function _prepareMassaction()
74
+ {
75
+ return $this;
76
+ }
77
+
78
+ public function getGridUrl()
79
+ {
80
+ return $this->getUrl('*/*/grid', array('_current'=> true));
81
+ }
82
+
83
+ public function getRowUrl($row)
84
+ {
85
+ return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
86
+ }
87
+ }
app/code/community/Mzax/Emarketing/Block/Template/Upload.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Template_Upload extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+ public function __construct()
27
+ {
28
+ $this->_objectId = 'id';
29
+
30
+ $this->_blockGroup = 'mzax_emarketing';
31
+ $this->_controller = 'template';
32
+ $this->_mode = 'upload';
33
+
34
+ parent::__construct();
35
+
36
+ $this->_updateButton('save', 'label', $this->__('Upload Template'));
37
+ $this->removeButton('delete');
38
+
39
+ }
40
+
41
+
42
+
43
+
44
+ public function getHeaderText()
45
+ {
46
+ return $this->__('Upload New Template');
47
+ }
48
+
49
+
50
+
51
+ /**
52
+ * Get form action URL
53
+ *
54
+ * @return string
55
+ */
56
+ public function getFormActionUrl()
57
+ {
58
+ return $this->getUrl('*/*/uploadPost');
59
+ }
60
+
61
+
62
+ }
app/code/community/Mzax/Emarketing/Block/Template/Upload/Form.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Template_Upload_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data'));
30
+ $form->setHtmlIdPrefix("template");
31
+ $form->setFieldNameSuffix("template");
32
+
33
+
34
+ $fieldset = $form->addFieldset('base_fieldset', array(
35
+ 'legend' => $this->__('Template'),
36
+ 'class' => 'fieldset-wide',
37
+ ));
38
+
39
+
40
+ $fieldset->addField('template', 'file', array(
41
+ 'name' => 'file',
42
+ 'required' => true,
43
+ 'label' => $this->__('Template File'),
44
+ 'title' => $this->__('Template File'),
45
+ ));
46
+
47
+
48
+ $this->setForm($form);
49
+ $form->setUseContainer(true);
50
+ return parent::_prepareForm();
51
+ }
52
+ }
app/code/community/Mzax/Emarketing/Block/Template/View.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Template_View extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'mzax_emarketing';
30
+ $this->_controller = 'template';
31
+ $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Templates');
32
+ $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Template');
33
+
34
+ $this->_addButton('upload', array(
35
+ 'label' => $this->__('Upload'),
36
+ 'class' => 'upload',
37
+ 'onclick' => "setLocation('{$this->getUrl('*/*/upload')}')",
38
+ ));
39
+
40
+ parent::__construct();
41
+ }
42
+
43
+
44
+
45
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Block_Tracker_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
32
+ {
33
+ public function __construct()
34
+ {
35
+ $this->_objectId = 'id';
36
+
37
+ $this->_blockGroup = 'mzax_emarketing';
38
+ $this->_controller = 'tracker';
39
+
40
+
41
+ parent::__construct();
42
+
43
+ $this->_updateButton('save', 'label', $this->__('Save Tracker'));
44
+ $this->_updateButton('delete', 'label', $this->__('Delete Tracker'));
45
+ }
46
+
47
+
48
+
49
+ public function getHeaderText()
50
+ {
51
+ $tracker = Mage::registry('current_tracker');
52
+ if ($tracker->getId()) {
53
+ $title = $this->htmlEscape($tracker->getTitle());
54
+ if($tracker->isDefault()) {
55
+ return $title . ' <sup>' . $this->__('[Default]') . '</sup>';
56
+ }
57
+ return $title;
58
+ }
59
+ else {
60
+ return $this->__('New Conversion Tracker');
61
+ }
62
+ }
63
+
64
+ public function getValidationUrl()
65
+ {
66
+ return $this->getUrl('*/*/validate', array('_current'=>true));
67
+ }
68
+
69
+
70
+
71
+
72
+ protected function _prepareLayout()
73
+ {
74
+ $tracker = Mage::registry('current_tracker');
75
+ if ($tracker->getId()) {
76
+ $this->_addButton('save_and_continue', array(
77
+ 'label' => $this->__('Save And Continue Edit'),
78
+ 'onclick' => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
79
+ 'class' => 'save'
80
+ ), 10);
81
+
82
+ if($tracker->isDefault()) {
83
+ $this->_removeButton('delete');
84
+ }
85
+ }
86
+ else {
87
+ $this->_removeButton('save');
88
+ $this->_removeButton('reset');
89
+ }
90
+
91
+ return parent::_prepareLayout();
92
+ }
93
+
94
+
95
+ /**
96
+ * Get form action URL
97
+ *
98
+ * @return string
99
+ */
100
+ public function getFormActionUrl()
101
+ {
102
+ if ($this->hasFormActionUrl()) {
103
+ return $this->getData('form_action_url');
104
+ }
105
+ return $this->getUrl('*/*/save');
106
+ }
107
+
108
+
109
+
110
+
111
+ protected function _getSaveAndContinueUrl()
112
+ {
113
+ return $this->getUrl('*/*/save', array(
114
+ '_current' => true,
115
+ 'back' => 'edit',
116
+ 'tab' => '{{tab_id}}'
117
+ ));
118
+ }
119
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Form.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Tracker_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
30
+
31
+ $tracker = Mage::registry('current_tracker');
32
+
33
+ if ($tracker->getId()) {
34
+ $form->addField('tracker_id', 'hidden', array(
35
+ 'name' => 'tracker_id',
36
+ 'value' => $tracker->getId()
37
+ ));
38
+ }
39
+
40
+ $form->setUseContainer(true);
41
+ $this->setForm($form);
42
+ return parent::_prepareForm();
43
+ }
44
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Conditions.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Conditions extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+
28
+ public function initForm()
29
+ {
30
+ $form = new Varien_Data_Form();
31
+ $form->setHtmlIdPrefix('_mzax_emarketing');
32
+ $form->setFieldNameSuffix('mzax_emarketing');
33
+
34
+
35
+ $tracker = Mage::registry('current_tracker');
36
+
37
+
38
+ $form->setHtmlIdPrefix('conditions_');
39
+
40
+ $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
41
+ ->setTemplate('mzax/emarketing/fieldset.phtml')
42
+ ->setTestUrl($this->getUrl('*/*/testConditions', array('_current' => true)))
43
+ ->setNewFilterUrl($this->getUrl('*/*/newConditionHtml', array('tracker' => $tracker->getId())));
44
+
45
+ $fieldset = $form->addFieldset('conditions_fieldset', array(
46
+ 'legend'=>Mage::helper('salesrule')->__('Only track conversion goals matching the conditions below')
47
+ ))->setRenderer($renderer);
48
+
49
+
50
+
51
+ $fieldset->addField('conditions', 'text', array(
52
+ 'name' => 'conditions',
53
+ 'label' => $this->__('Conditions'),
54
+ 'title' => $this->__('Conditions'),
55
+ ))->setTracker($tracker)
56
+ ->setRenderer(Mage::getBlockSingleton('mzax_emarketing/conditions'));
57
+
58
+ $this->setForm($form);
59
+
60
+ return $this;
61
+ }
62
+
63
+
64
+
65
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/GoalType.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Block_Tracker_Edit_Tab_GoalType extends Mage_Adminhtml_Block_Widget_Form
32
+ {
33
+
34
+ protected function _prepareLayout()
35
+ {
36
+ parent::_prepareLayout();
37
+ }
38
+
39
+
40
+
41
+ public function initForm()
42
+ {
43
+ $form = new Varien_Data_Form();
44
+ $form->setHtmlIdPrefix('tracker_');
45
+ $form->setFieldNameSuffix('tracker');
46
+
47
+ /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
48
+ $tracker = Mage::registry('current_tracker');
49
+
50
+
51
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
52
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
53
+
54
+ /**
55
+ * Tracker
56
+ */
57
+ $fieldset = $form->addFieldset('base_fieldset', array(
58
+ 'legend' => $this->__('Setup a new conversion goal tracker'),
59
+ 'class' => 'fieldset-wide',
60
+ 'offer' => $this->__('Would you like to track different goals or have any suggestions? <a href="%s" target="_blank">Contact me</a>!', 'http://www.mzax.de/emarketing/goals.html?utm_source=extension&utm_medium=link&utm_content=setup-tracker&utm_campaign=needmore'),
61
+ 'continue' => !$tracker->getId()
62
+ ));
63
+
64
+ $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
65
+ $fieldset->addType('wildselect', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_wildselect'));
66
+
67
+
68
+
69
+ $offerRenderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
70
+ ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
71
+ $fieldset->setRenderer($offerRenderer);
72
+
73
+
74
+ $fieldset->addField('info', 'info', array(
75
+ 'text' => $this->__('First you must decide what conversion goals this tracker should use as this will drive what filters are available.')
76
+ ))->setRenderer($renderer);
77
+
78
+
79
+
80
+ $fieldset->addField('title','text', array(
81
+ 'name' => 'title',
82
+ 'required' => true,
83
+ 'label' => $this->__('Title'),
84
+ 'title' => $this->__('Title'),
85
+ ));
86
+
87
+
88
+ // @todo disable if it has reci
89
+ $fieldset->addField('goal_type','select', array(
90
+ 'name' => 'goal_type',
91
+ 'label' => $this->__('What goals to track?'),
92
+ 'values' => Mage::getSingleton('mzax_emarketing/conversion_goal')->getAllOptions(false),
93
+ 'note' => $this->__("What conversion goal would you like to track"),
94
+ 'required' => true
95
+ ));
96
+
97
+
98
+
99
+ $form->addValues($tracker->getData());
100
+ $this->setForm($form);
101
+
102
+ return $this;
103
+
104
+
105
+ }
106
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Settings.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Default tracker settings tab
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
32
+ {
33
+
34
+
35
+ protected function _prepareLayout()
36
+ {
37
+ parent::_prepareLayout();
38
+ }
39
+
40
+
41
+
42
+ public function initForm()
43
+ {
44
+ $form = new Varien_Data_Form();
45
+ $form->setHtmlIdPrefix('tracker_');
46
+ $form->setFieldNameSuffix('tracker');
47
+
48
+ /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
49
+ $tracker = Mage::registry('current_tracker');
50
+
51
+
52
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
53
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
54
+
55
+ /**
56
+ * Tracker
57
+ */
58
+ $fieldset = $form->addFieldset('base_fieldset', array(
59
+ 'legend' => $this->__('Tracker'),
60
+ 'class' => 'fieldset-wide',
61
+ 'offer' => $this->__('Would you like to track different goals or have any suggestions? <a href="%s" target="_blank">Contact me</a>!', 'http://www.mzax.de/emarketing/goals.html?utm_source=extension&utm_medium=link&utm_content=tracker-settings&utm_campaign=needmore'),
62
+ 'continue' => !$tracker->getId()
63
+ ));
64
+
65
+ $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
66
+ $fieldset->addType('wildselect', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_wildselect'));
67
+ $fieldset->addType('textarea', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_textarea'));
68
+
69
+
70
+ $offerRenderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
71
+ ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
72
+ $fieldset->setRenderer($offerRenderer);
73
+
74
+
75
+
76
+
77
+ $fieldset->addField('info', 'info', array(
78
+ 'text' => $this->__('A tracker allows you to define what conversion goals you want to track for all or certain campaigns.<br />Don’t worry if you are not yet sure what to track yet, your data is there, here you just define how to aggregate that data so it will be visible in your reports. So if you do changes or create a new tracker later then your data will be re-aggregated and you have your full reports.')
79
+ ))->setRenderer($renderer);
80
+
81
+
82
+
83
+
84
+ $fieldset->addField('title','text', array(
85
+ 'name' => 'title',
86
+ 'required' => true,
87
+ 'label' => $this->__('Title'),
88
+ 'title' => $this->__('Title')
89
+ ));
90
+
91
+
92
+ if(!$tracker->getId()) {
93
+ $fieldset->addField('goal_type','hidden', array(
94
+ 'name' => 'goal_type'
95
+ ));
96
+ }
97
+ else {
98
+ $fieldset->addField('goal_type','select', array(
99
+ 'name' => 'goal_type',
100
+ 'label' => $this->__('Goals'),
101
+ 'values' => Mage::getSingleton('mzax_emarketing/conversion_goal')->getAllOptions(false),
102
+ 'note' => $tracker->hasFilters()
103
+ ? $this->__("You can not change this value if you have any filters defined")
104
+ : false,
105
+ 'required' => true,
106
+ 'disabled' => $tracker->hasFilters()
107
+ ));
108
+ }
109
+
110
+
111
+ $fieldset->addField('is_active', 'select', array(
112
+ 'label' => $this->__('Enabled'),
113
+ 'title' => $this->__('Enabled'),
114
+ 'name' => 'is_active',
115
+ 'required' => true,
116
+ 'disabled' => $tracker->isDefault(),
117
+ 'note' => $tracker->isDefault()
118
+ ? $this->__('You can not disable the default tracker.')
119
+ : '',
120
+ 'options' => array(
121
+ '1' => $this->__('Yes'),
122
+ '0' => $this->__('No'),
123
+ ),
124
+ 'value' => '1'
125
+ ));
126
+
127
+
128
+ $fieldset->addField('description', 'textarea', array(
129
+ 'label' => $this->__('Description'),
130
+ 'title' => $this->__('Description'),
131
+ 'placeholder' => $this->__('Add a simple description that is used internally only for your own records.'),
132
+ 'name' => 'description',
133
+ 'style' => 'height:4em;',
134
+ ));
135
+
136
+
137
+ /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
138
+ $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
139
+ $campaigns->addArchiveFilter(false);
140
+
141
+
142
+ if($tracker->isDefault()) {
143
+ $fieldset->addField('is_default', 'checkbox', array(
144
+ 'label' => $this->__('Track Campaigns'),
145
+ 'title' => $this->__('Track Campaigns'),
146
+ 'disabled' => true,
147
+ 'checked' => true,
148
+ 'note' => $this->__('The default tracker must always track all campaigns'),
149
+ 'name' => 'is_default',
150
+ 'after_element_html' => '<label>'.$this->__('Always track all campaigns').'</label>'
151
+ ));
152
+ }
153
+ else {
154
+ $campaignOptions = $campaigns->toOptionArray();
155
+
156
+ $fieldset->addField('campaign_ids', 'wildselect', array(
157
+ 'label' => $this->__('Track Campaigns'),
158
+ 'title' => $this->__('Track Campaigns'),
159
+ 'wildcard_label' => $this->__('Always track all campaigns'),
160
+ 'name' => 'campaign_ids[]',
161
+ 'values' => $campaignOptions
162
+ ));
163
+ }
164
+
165
+ $form->addValues($tracker->getData());
166
+ $this->setForm($form);
167
+
168
+ return $this;
169
+ }
170
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Tasks.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Tasks extends Mage_Adminhtml_Block_Template
33
+ {
34
+
35
+ protected function _prepareLayout()
36
+ {
37
+ parent::_prepareLayout();
38
+ $this->setTemplate('mzax/emarketing/tracker/tasks.phtml');
39
+ }
40
+
41
+
42
+ /**
43
+ * Retrieve Current Tracker
44
+ *
45
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
46
+ */
47
+ public function getTracker()
48
+ {
49
+ return Mage::registry('current_tracker');
50
+ }
51
+
52
+
53
+
54
+ /**
55
+ * (non-PHPdoc)
56
+ * @see Mage_Core_Block_Abstract::getUrl()
57
+ */
58
+ public function getUrl($route = '', $params = array())
59
+ {
60
+ if(!isset($params['_tracker'])) {
61
+ $params['id'] = $this->getTracker()->getId();
62
+ }
63
+ return parent::getUrl($route, $params);
64
+ }
65
+
66
+
67
+
68
+
69
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Test.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
25
+ {
26
+
27
+
28
+ /**
29
+ * Retrieve filter
30
+ *
31
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
32
+ */
33
+ public function getFilter()
34
+ {
35
+ /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
36
+ $tracker = Mage::registry('current_tracker');
37
+ return $tracker->getGoal();
38
+ }
39
+
40
+
41
+
42
+
43
+
44
+ /**
45
+ * Generate url by route and parameters
46
+ *
47
+ * @param string $route
48
+ * @param array $params
49
+ * @return string
50
+ */
51
+ public function getUrl($route = '', $params = array())
52
+ {
53
+ $params['tracker'] = $this->getCampaign()->getId();
54
+ return parent::getUrl($route, $params);
55
+ }
56
+
57
+
58
+
59
+
60
+ /**
61
+ * Retrieve current campaign
62
+ *
63
+ * @return Mzax_Emarketing_Model_Campaign
64
+ */
65
+ public function getCampaign()
66
+ {
67
+ return Mage::registry('current_tracker');
68
+ }
69
+
70
+
71
+
72
+
73
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tabs.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Block_Tracker_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
32
+ {
33
+
34
+ public function __construct()
35
+ {
36
+ parent::__construct();
37
+ $this->setId('mzax_emarketing_info_tabs');
38
+ $this->setDestElementId('edit_form');
39
+ $this->setTitle($this->__('Conversion Tracker'));
40
+ }
41
+
42
+ protected function _beforeToHtml()
43
+ {
44
+ /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
45
+ $tracker = Mage::registry('current_tracker');
46
+
47
+ if(!$tracker->getGoalType())
48
+ {
49
+ $this->addTab('goaltype', array(
50
+ 'label' => $this->__('Choose a goal type'),
51
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_goalType')->initForm()->toHtml(),
52
+ 'active' => true
53
+ ));
54
+ }
55
+ else
56
+ {
57
+ $this->addTab('settings', array(
58
+ 'label' => $this->__('Settings'),
59
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_settings')->initForm()->toHtml(),
60
+ 'active' => true
61
+ ));
62
+
63
+ $this->addTab('conditions', array(
64
+ 'label' => $this->__('Conditions'),
65
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_conditions')->initForm()->toHtml(),
66
+ 'active' => false
67
+ ));
68
+
69
+ if($tracker->getId()) {
70
+ $this->addTab('task', array(
71
+ 'label' => $this->__('Tasks'),
72
+ 'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_tasks')->toHtml(),
73
+ 'active' => false
74
+ ));
75
+ }
76
+ }
77
+
78
+
79
+ $this->_updateActiveTab();
80
+ return parent::_beforeToHtml();
81
+ }
82
+
83
+
84
+
85
+ protected function _updateActiveTab()
86
+ {
87
+ $tabId = $this->getRequest()->getParam('tab');
88
+ if( $tabId ) {
89
+ $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
90
+ if($tabId) {
91
+ $this->setActiveTab($tabId);
92
+ }
93
+ }
94
+ }
95
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Grid.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setId('tracker_grid');
31
+ $this->setUseAjax(true);
32
+ $this->setSaveParametersInSession(true);
33
+ $this->setDefaultSort('tracker_id');
34
+ }
35
+
36
+
37
+ protected function _prepareCollection()
38
+ {
39
+ /* @var $collection Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection */
40
+ $collection = Mage::getResourceModel('mzax_emarketing/conversion_tracker_collection');
41
+ $this->setCollection($collection);
42
+
43
+ return parent::_prepareCollection();
44
+ }
45
+
46
+
47
+ protected function _prepareColumns()
48
+ {
49
+ $this->addColumn('updated_at', array(
50
+ 'header' => $this->__('Last change'),
51
+ 'index' =>'created_at',
52
+ 'gmtoffset' => true,
53
+ 'type' =>'datetime'
54
+ ));
55
+
56
+ $this->addColumn('title', array(
57
+ 'header' => $this->__('Title'),
58
+ 'index' => 'title',
59
+ ));
60
+
61
+ $this->addColumn('description', array(
62
+ 'header' => $this->__('Description'),
63
+ 'index' => 'description',
64
+ ));
65
+
66
+ $this->addColumn('is_active', array(
67
+ 'header' => Mage::helper('cms')->__('Active'),
68
+ 'index' => 'is_active',
69
+ 'filter_index' => 'is_active',
70
+ 'type' => 'options',
71
+ 'options' => array(
72
+ 0 => $this->__('Disabled'),
73
+ 1 => $this->__('Enabled')
74
+ ),
75
+ ));
76
+
77
+ $this->addColumn('is_aggregated', array(
78
+ 'header' => Mage::helper('cms')->__('Is Aggregated'),
79
+ 'index' => 'is_aggregated',
80
+ 'filter_index' => 'is_aggregated',
81
+ 'type' => 'options',
82
+ 'options' => array(
83
+ 0 => $this->__('No'),
84
+ 1 => $this->__('Yes')
85
+ ),
86
+ ));
87
+
88
+
89
+
90
+ return parent::_prepareColumns();
91
+ }
92
+
93
+
94
+ protected function _prepareMassaction()
95
+ {
96
+ $this->setMassactionIdField('tracker_id');
97
+ $this->getMassactionBlock()->setFormFieldName('trackers');
98
+
99
+ $this->getMassactionBlock()->addItem('delete', array(
100
+ 'label' => $this->__('Delete'),
101
+ 'url' => $this->getUrl('*/*/massDelete'),
102
+ 'confirm' => $this->__('Are you sure?')
103
+ ));
104
+
105
+ $this->getMassactionBlock()->addItem('is_active', array(
106
+ 'label'=> $this->__('Enable/Disable'),
107
+ 'url' => $this->getUrl('*/*/massEnable', array('_current'=>true)),
108
+ 'additional' => array(
109
+ 'visibility' => array(
110
+ 'name' => 'status',
111
+ 'type' => 'select',
112
+ 'class' => 'required-entry',
113
+ 'label' => $this->__('Status'),
114
+ 'options' => array(
115
+ 0 => $this->__('Disable'),
116
+ 1 => $this->__('Enable'),
117
+ ),
118
+ )
119
+ )
120
+ ));
121
+ $this->getMassactionBlock()->addItem('aggregate', array(
122
+ 'label' => $this->__('Aggregate'),
123
+ 'confirm' => $this->__('This may take some time depending on the size of your data, would you like to continue?'),
124
+ 'url' => $this->getUrl('*/*/massAggregate')
125
+ ));
126
+
127
+
128
+
129
+ return $this;
130
+ }
131
+
132
+
133
+
134
+ public function getGridUrl()
135
+ {
136
+ return $this->getUrl('*/*/grid', array('_current'=> true));
137
+ }
138
+
139
+ public function getRowUrl($row)
140
+ {
141
+ return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
142
+ }
143
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/New.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ *
26
+ * @author Jacob Siefer
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @version 0.2.5
29
+ */
30
+ class Mzax_Emarketing_Block_Tracker_New extends Mzax_Emarketing_Block_Tracker_Edit
31
+ {
32
+
33
+
34
+ public function getHeaderText()
35
+ {
36
+ return $this->__('New Conversion Goal Tracker');
37
+ }
38
+
39
+
40
+ public function getValidationUrl()
41
+ {
42
+ return null;
43
+ }
44
+
45
+
46
+ protected function _prepareLayout()
47
+ {
48
+ parent::_prepareLayout();
49
+
50
+ /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
51
+ $tracker = Mage::registry('current_tracker');
52
+
53
+ $this->_removeButton('reset');
54
+ $this->_removeButton('save');
55
+ $this->_removeButton('save_and_continue');
56
+ }
57
+
58
+
59
+ /**
60
+ * Get form action URL
61
+ *
62
+ * @return string
63
+ */
64
+ public function getFormActionUrl()
65
+ {
66
+ return $this->getUrl('*/*/new');
67
+ }
68
+
69
+
70
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Test.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Tracker_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
25
+ {
26
+
27
+
28
+ /**
29
+ * Retrieve filter
30
+ *
31
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
32
+ */
33
+ public function getFilter()
34
+ {
35
+ $filter = $this->getTracker()->getGoal();
36
+ $this->prepareEmulation($filter);
37
+ return $filter;
38
+ }
39
+
40
+
41
+
42
+ public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
43
+ {
44
+ $child = $this->getChild('emulate');
45
+ if($child && method_exists($child, 'prepareEmulation')) {
46
+ $child->prepareEmulation($filter);
47
+ }
48
+ }
49
+
50
+
51
+
52
+
53
+
54
+ /**
55
+ * Generate url by route and parameters
56
+ *
57
+ * @param string $route
58
+ * @param array $params
59
+ * @return string
60
+ */
61
+ public function getUrl($route = '', $params = array())
62
+ {
63
+ $params['id'] = $this->getTracker()->getId();
64
+ return parent::getUrl($route, $params);
65
+ }
66
+
67
+
68
+
69
+
70
+ /**
71
+ * Retrieve current tracker
72
+ *
73
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
74
+ */
75
+ public function getTracker()
76
+ {
77
+ return Mage::registry('current_tracker');
78
+ }
79
+
80
+
81
+
82
+
83
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Test/Emulate.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Tracker_Test_Emulate extends Mage_Adminhtml_Block_Template
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var Varien_Data_Form
30
+ */
31
+ protected $_form;
32
+
33
+
34
+
35
+ /**
36
+ * Retrieve Varien Data Form
37
+ *
38
+ * @return Varien_Data_Form
39
+ */
40
+ public function getForm()
41
+ {
42
+ if(!$this->_form) {
43
+ $this->_form = new Varien_Data_Form();
44
+ $this->_form->setElementRenderer(Mage::getBlockSingleton('mzax_emarketing/editable')->setFormat('form'));
45
+ $this->_form->setHtmlIdPrefix("emulate_");
46
+ $this->_form->setFieldNameSuffix("emulate");
47
+ }
48
+ return $this->_form;
49
+ }
50
+
51
+
52
+ /**
53
+ * Prepare filter
54
+ *
55
+ * Usally called by parent block class
56
+ *
57
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
58
+ */
59
+ public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
60
+ {
61
+ $emulate = $this->getRequest()->getParam('emulate');
62
+
63
+ if($this->emulate('time')) {
64
+ if(isset($emulate['from']) && isset($emulate['to'])) {
65
+ $filter->setParam('current_time', array($emulate['from'], $emulate['to']));
66
+ $filter->setParam('is_local_time', true);
67
+ }
68
+ }
69
+
70
+ if($this->emulate('campaign')) {
71
+ /* @var $campagin Mzax_Emarketing_Model_Campaign */
72
+ $campagin = Mage::getModel('mzax_emarketing/campaign');
73
+ $campagin->load($emulate['campaign_id']);
74
+
75
+ if($campagin->getId()) {
76
+ $filter->setParam('campaign', $campagin);
77
+ }
78
+ }
79
+ }
80
+
81
+
82
+
83
+ /**
84
+ * Check if we should emulate the specified key
85
+ *
86
+ * @param string $key
87
+ * @return boolean
88
+ */
89
+ public function emulate($key)
90
+ {
91
+ $emulate = $this->getRequest()->getParam('emulate');
92
+
93
+ if(isset($emulate[$key])) {
94
+ return ($emulate[$key] == 1);
95
+ }
96
+ return false;
97
+ }
98
+
99
+
100
+
101
+
102
+
103
+ /**
104
+ *
105
+ *
106
+ * @return Varien_Data_Form_Element_Abstract
107
+ */
108
+ public function getCampaignSelect()
109
+ {
110
+ $params = $this->getRequest()->getParam('emulate');
111
+
112
+ /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
113
+ $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
114
+ $collection->addArchiveFilter(false);
115
+
116
+ $options = array();
117
+ if($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
118
+ $options['current'] = $this->__('beeing tracked');
119
+ }
120
+ $options += $collection->toOptionHash();
121
+
122
+ /* @var $campagin Mzax_Emarketing_Model_Campaign */
123
+ $campagin = Mage::getModel('mzax_emarketing/campaign');
124
+
125
+ if(isset($params['campaign_id'])) {
126
+ $campagin->load($params['campaign_id']);
127
+ }
128
+
129
+ return $this->getForm()->addField('campaign_id', 'select', array(
130
+ 'name' => 'campaign_id',
131
+ 'value_name' => (string) $campagin->getName(),
132
+ 'value' => $campagin->getId(),
133
+ 'options' => $options,
134
+ ));
135
+
136
+ }
137
+
138
+
139
+
140
+
141
+ /**
142
+ * Helper for simple select element
143
+ *
144
+ * @param string $key
145
+ * @param array $options
146
+ * @return Varien_Data_Form_Element_Abstract
147
+ */
148
+ public function getDateElement($key)
149
+ {
150
+ $format = Varien_Date::DATE_INTERNAL_FORMAT;
151
+
152
+ $params = $this->getRequest()->getParam('emulate');
153
+
154
+ if(isset($params[$key])) {
155
+ $value = $params[$key];
156
+ }
157
+ else {
158
+ $value = Zend_Date::now()->toString($format);
159
+ }
160
+
161
+ return $this->getForm()->addField($key, 'date',array(
162
+ 'name' => $key,
163
+ 'value_name' => $value,
164
+ 'value' => $value,
165
+ 'explicit_apply' => true,
166
+ 'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
167
+ 'input_format' => $format,
168
+ 'format' => $format
169
+ ));
170
+ }
171
+
172
+
173
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Upload.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Block_Tracker_Upload extends Mage_Adminhtml_Block_Widget_Form_Container
33
+ {
34
+ public function __construct()
35
+ {
36
+ $this->_objectId = 'id';
37
+
38
+ $this->_blockGroup = 'mzax_emarketing';
39
+ $this->_controller = 'tracker';
40
+ $this->_mode = 'upload';
41
+
42
+ parent::__construct();
43
+
44
+ $this->_updateButton('save', 'label', $this->__('Upload Tracker'));
45
+ $this->removeButton('delete');
46
+
47
+ }
48
+
49
+
50
+
51
+ public function getHeaderText()
52
+ {
53
+ return $this->__('Upload New Tracker');
54
+ }
55
+
56
+
57
+
58
+ /**
59
+ * Get form action URL
60
+ *
61
+ * @return string
62
+ */
63
+ public function getFormActionUrl()
64
+ {
65
+ return $this->getUrl('*/*/uploadPost');
66
+ }
67
+
68
+
69
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Upload/Form.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Block_Tracker_Upload_Form extends Mage_Adminhtml_Block_Widget_Form
34
+ {
35
+
36
+ protected function _prepareForm()
37
+ {
38
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data'));
39
+ $form->setHtmlIdPrefix("tracker");
40
+ $form->setFieldNameSuffix("tracker");
41
+
42
+
43
+ $fieldset = $form->addFieldset('base_fieldset', array(
44
+ 'legend' => $this->__('Upload new conversion tracker'),
45
+ 'class' => 'fieldset-wide',
46
+ ));
47
+
48
+ $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
49
+
50
+
51
+ $noLabel = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
52
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
53
+
54
+
55
+ $fieldset->addField('info', 'info', array(
56
+ 'text' => $this->__('You can download and upload trackers. This makes it easy if you want to share or backup any custom configuration. Trackers should always be backwards compatible however if you load a tracker from a newer version than you have installed a warning will appear. If thats the case, test the filter and make sure it works as expected.')
57
+ ))->setRenderer($noLabel);
58
+
59
+
60
+
61
+
62
+ $fieldset->addField('template', 'file', array(
63
+ 'name' => 'file',
64
+ 'required' => true,
65
+ 'label' => $this->__('Conversion Tracker File'),
66
+ 'title' => $this->__('Conversion Tracker File'),
67
+ 'note' => $this->__('Select the tracker file that you want to upload (*.mzax.tracker).'),
68
+ ));
69
+
70
+
71
+ $this->setForm($form);
72
+ $form->setUseContainer(true);
73
+ return parent::_prepareForm();
74
+ }
75
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/View.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Block_Tracker_View extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'mzax_emarketing';
30
+ $this->_controller = 'tracker';
31
+ $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Trackers');
32
+ $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Tracker');
33
+
34
+ $this->_addButton('upload', array(
35
+ 'label' => $this->__('Upload'),
36
+ 'class' => 'upload',
37
+ 'onclick' => "setLocation('{$this->getUrl('*/*/upload')}')",
38
+ ));
39
+
40
+
41
+ parent::__construct();
42
+ }
43
+
44
+
45
+
46
+ }
app/code/community/Mzax/Emarketing/Block/Unsubscribe.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Block_Unsubscribe extends Mage_Core_Block_Template
34
+ {
35
+
36
+
37
+
38
+ /**
39
+ * Retrieve session model
40
+ *
41
+ * @return Mzax_Emarketing_Model_Session
42
+ */
43
+ public function getSession()
44
+ {
45
+ return Mage::getSingleton('mzax_emarketing/session');
46
+ }
47
+
48
+
49
+
50
+ /**
51
+ * Retrieve address
52
+ *
53
+ * @return string
54
+ */
55
+ public function getAddress()
56
+ {
57
+ return $this->getSession()->getLastAddress();
58
+ }
59
+
60
+
61
+
62
+ public function getFormKey()
63
+ {
64
+ return $this->getSession()->getFormKey();
65
+ }
66
+
67
+
68
+
69
+ public function getYesUrl()
70
+ {
71
+ return $this->getUrl('*/*/do');
72
+ }
73
+
74
+ public function getNoUrl()
75
+ {
76
+ return $this->getUrl('/');
77
+ }
78
+ }
app/code/community/Mzax/Emarketing/Db/Select.php ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
26
+ {
27
+
28
+
29
+ static protected $_assambleAll = false;
30
+
31
+ static protected $_tempTables = array();
32
+
33
+ protected $_temporaryTable = false;
34
+
35
+
36
+ /**
37
+ * If select uses temproary table use table join instead
38
+ *
39
+ * @param string $bind
40
+ * @param Zend_Db_Select $select
41
+ * @param string $alias
42
+ * @param string $selectColumn
43
+ * @return Mzax_Emarketing_Db_Select
44
+ */
45
+ public function joinSelect($bind, Zend_Db_Select $select, $alias)
46
+ {
47
+ if($select instanceof Mzax_Emarketing_Db_Select && ($table = $select->getTemporaryTable())) {
48
+ if($select->createTemporaryTable()) {
49
+ return $this->joinTable($bind, new Zend_Db_Expr($table), $alias);
50
+ }
51
+ }
52
+ return parent::joinSelect($bind, $select, $alias);
53
+ }
54
+
55
+
56
+ /**
57
+ * If select uses temproary table use table join instead
58
+ *
59
+ * @param string $bind
60
+ * @param Zend_Db_Select $select
61
+ * @param string $alias
62
+ * @param string $selectColumn
63
+ * @return Mzax_Emarketing_Db_Select
64
+ */
65
+ public function joinSelectLeft($bind, Zend_Db_Select $select, $alias)
66
+ {
67
+ if($select instanceof Mzax_Emarketing_Db_Select && ($table = $select->getTemporaryTable())) {
68
+ if($select->createTemporaryTable()) {
69
+ return $this->joinTableLeft($bind, new Zend_Db_Expr($table), $alias);
70
+ }
71
+ }
72
+ return parent::joinSelectLeft($bind, $select, $alias);
73
+ }
74
+
75
+
76
+ /**
77
+ * Use temporary table for this select object
78
+ *
79
+ * @param string $tableName
80
+ * @return Mzax_Emarketing_Db_Select
81
+ */
82
+ public function useTemporaryTable($tableName)
83
+ {
84
+ $this->_temporaryTable = $tableName ? $tableName : false;
85
+ return $this;
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Retrieve temporary table if available
92
+ *
93
+ * @return boolean|string
94
+ */
95
+ public function getTemporaryTable()
96
+ {
97
+ if($this->_temporaryTable) {
98
+ return $this->_temporaryTable;
99
+ }
100
+ return false;
101
+ }
102
+
103
+
104
+
105
+ /**
106
+ * Create temporary table with this select object
107
+ *
108
+ * @return boolean|multitype:|string
109
+ */
110
+ public function createTemporaryTable()
111
+ {
112
+ $name = $this->getTemporaryTable();
113
+ if(!$name) {
114
+ return false;
115
+ }
116
+
117
+ $adapter = $this->getResourceHelper()->getAdapter();
118
+
119
+ if(isset(self::$_tempTables[$name])) {
120
+ return self::$_tempTables[$name];
121
+ }
122
+
123
+
124
+ $sql[] = "CREATE TEMPORARY TABLE IF NOT EXISTS `$name`";
125
+ $sql[] = "ENGINE = MEMORY";
126
+ $sql[] = parent::assemble();
127
+
128
+ try {
129
+ $adapter->query(implode("\n", $sql));
130
+ }
131
+ catch(Exception $e) {
132
+ Mage::logException($e);
133
+ if(Mage::getIsDeveloperMode()) {
134
+ die($e->getMessage() . "<br />\n<br />\n<br />\n" . implode("\n", $sql));
135
+ }
136
+ return self::$_tempTables[$name] = false;
137
+ }
138
+
139
+ return self::$_tempTables[$name] = "SELECT * FROM `$name`";
140
+ }
141
+
142
+
143
+
144
+ /**
145
+ * Assamble the select object without using temporary
146
+ * tables
147
+ *
148
+ * @return string
149
+ */
150
+ public function assembleAll()
151
+ {
152
+ self::$_assambleAll = true;
153
+ try {
154
+ $sql = parent::assemble();
155
+ self::$_assambleAll = false;
156
+ return $sql;
157
+ }
158
+ catch(Exception $e) {
159
+ self::$_assambleAll = false;
160
+ throw $e;
161
+ }
162
+ }
163
+
164
+
165
+
166
+ /**
167
+ * Allow to use temporary tabes for this filter
168
+ * result
169
+ *
170
+ * @return string
171
+ */
172
+ public function assemble()
173
+ {
174
+ if(!self::$_assambleAll && $sql = $this->createTemporaryTable()) {
175
+ return $sql;
176
+ }
177
+ else {
178
+ return parent::assemble();
179
+ }
180
+ }
181
+
182
+
183
+
184
+
185
+
186
+
187
+ /**
188
+ * Join attribute to current query
189
+ *
190
+ * Will return an expression that points to the value column
191
+ *
192
+ * @param string $attribute
193
+ * @param string $binding Optional binding column
194
+ * @return Zend_Db_Expr Expression that points to the value column
195
+ */
196
+ public function joinAttribute($bind, $attribute)
197
+ {
198
+ if($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) {
199
+ $joinKey = "{$attribute->getEntityType()->getEntityTypeCode()}/{$attribute->getAttributeCode()}";
200
+ }
201
+ else {
202
+ $joinKey = $attribute;
203
+ }
204
+
205
+ if($this->getJoin($joinKey)) {
206
+ return $this->getJoin($joinKey);
207
+ }
208
+
209
+ $this->_joins[$joinKey] = $this->getResourceHelper()->joinAttribute($this, $attribute, $this->_getBindExpr($bind));
210
+ return $this->_joins[$joinKey];
211
+ }
212
+
213
+
214
+
215
+
216
+
217
+ /**
218
+ * Preform a right table join using the binder
219
+ *
220
+ * @param string|array $bind
221
+ * @param string $table
222
+ * @param string $tableAlias
223
+ * @return Mzax_Emarketing_Db_Select
224
+ */
225
+ public function joinTableRight($bind, $table, $tableAlias = null)
226
+ {
227
+ return $this->_joinTable('Right', $bind, $table, $tableAlias);
228
+ }
229
+
230
+
231
+
232
+ /**
233
+ * Preform a left table join using the binder
234
+ *
235
+ * @param string|array $binding
236
+ * @param string $table
237
+ * @param string $tableAlias
238
+ * @return Mzax_Emarketing_Db_Select
239
+ */
240
+ public function joinTableLeft($bind, $table, $tableAlias = null)
241
+ {
242
+ return $this->_joinTable('Left', $bind, $table, $tableAlias);
243
+ }
244
+
245
+
246
+
247
+ /**
248
+ * Preform a inner table join using the binder
249
+ *
250
+ * @param string|array $binding
251
+ * @param string $table
252
+ * @param string $tableAlias
253
+ * @return Mzax_Emarketing_Db_Select
254
+ */
255
+ public function joinTable($bind, $table, $tableAlias = null)
256
+ {
257
+ return $this->_joinTable('Inner', $bind, $table, $tableAlias);
258
+ }
259
+
260
+
261
+
262
+ /**
263
+ * Preform a table join using the binder
264
+ *
265
+ * @param string $joinType
266
+ * @param string|array $binding
267
+ * @param string $table
268
+ * @param string $tableAlias
269
+ * @return Mzax_Emarketing_Db_Select
270
+ */
271
+ protected function _joinTable($joinType, $bind, $table, $tableAlias = null)
272
+ {
273
+ if(!$tableAlias) {
274
+ $tableAlias = $table;
275
+ }
276
+ if(isset($this->_joins[$tableAlias])) {
277
+ return $this;
278
+ }
279
+
280
+ $joinFunc = "join{$joinType}";
281
+
282
+ // assume that same name for binding and column
283
+ if(is_string($bind)) {
284
+ //$bind = array($bind => '{' . $bind . '}');
285
+ }
286
+
287
+ $tableName = $this->getTable($table);
288
+ $cond = $this->_getJoinCondition($tableAlias, $bind);
289
+ $this->$joinFunc(array($tableAlias => $tableName), $cond, null);
290
+ $this->_joins[$tableAlias] = $tableName;
291
+ return $this;
292
+ }
293
+
294
+
295
+
296
+
297
+
298
+ /**
299
+ * Retrieve table name
300
+ *
301
+ * @param string $table
302
+ * @return string
303
+ */
304
+ public function getTable($table)
305
+ {
306
+ return $this->getResourceHelper()->getTable($table);
307
+ }
308
+
309
+
310
+
311
+
312
+
313
+ /**
314
+ * Retrieve resource helper
315
+ *
316
+ * @return Mzax_Emarketing_Model_Resource_Helper
317
+ */
318
+ protected function getResourceHelper()
319
+ {
320
+ return Mage::getResourceSingleton('mzax_emarketing/helper');
321
+ }
322
+
323
+
324
+
325
+ }
app/code/community/Mzax/Emarketing/Helper/Campaign.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Helper class for campaign related tasks
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Helper_Campaign extends Mage_Core_Helper_Abstract
33
+ {
34
+
35
+
36
+ /**
37
+ * Check all campaigns for new recipients
38
+ *
39
+ * This will look for new recipients that match the current filters
40
+ * and should recieve the campaign
41
+ *
42
+ * @return integer The number of new recipients
43
+ */
44
+ public function fetchNewRecipients(array $options)
45
+ {
46
+ $lock = Mage::helper('mzax_emarketing')->lock('fetch_new_recipients');
47
+ if(!$lock) {
48
+ return false;
49
+ }
50
+
51
+ /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
52
+ $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
53
+ $campaigns->addCheckFilter();
54
+ $campaigns->addRunningFilter();
55
+
56
+ // do the once that get checked more often at the end
57
+ $campaigns->setOrder('check_frequency', 'DESC');
58
+ // then go for a random sort to make sure they all get a chance
59
+ $campaigns->setOrder('RAND()', 'ASC');
60
+
61
+
62
+ $options = new Varien_Object($options);
63
+ $options->getDataSetDefault('timeout', 150);
64
+ $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
65
+
66
+ if($options->getVerbose()) {
67
+ echo "\n\n{$campaigns->getSelect()}\n\n";
68
+ }
69
+
70
+ $start = time();
71
+ $timeout = (int) $options->getTimeout();
72
+
73
+ $count = 0;
74
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
75
+ foreach($campaigns as $campaign) {
76
+ try {
77
+ if($options->getVerbose()) {
78
+ echo sprintf("Find Recipients for '%s' (#%s)...", $campaign->getName(), $campaign->getId());
79
+ }
80
+
81
+ $count += $found = $campaign->findRecipients();
82
+
83
+ if($options->getVerbose()) {
84
+ echo sprintf(" \tfound %s\n", $found);
85
+ }
86
+
87
+ $lock->touch();
88
+ }
89
+ catch(Exception $e) {
90
+ if($options->getBreakOnError()) {
91
+ $lock->unlock();
92
+ throw $e;
93
+ }
94
+ Mage::logException($e);
95
+
96
+ if($options->getVerbose()) {
97
+ echo "\n{$e->getMessage()}\n{$e->getTraceAsString()}\n\n";
98
+ }
99
+ }
100
+ // make sure we don't exceed the timeout
101
+ if($timeout && time()-$start > $timeout) {
102
+ break;
103
+ }
104
+ }
105
+ $lock->unlock();
106
+ return $count;
107
+ }
108
+
109
+
110
+
111
+
112
+ /**
113
+ * Send recipients
114
+ *
115
+ * @param array $options
116
+ * @throws Exception
117
+ * @return number
118
+ */
119
+ public function sendRecipients(array $options)
120
+ {
121
+ $lock = Mage::helper('mzax_emarketing')->lock('send_recipients');
122
+ if(!$lock) {
123
+ return false;
124
+ }
125
+
126
+
127
+ /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
128
+ $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
129
+ $campaigns->addRunningFilter();
130
+ //$campaigns->setOrder('last_check', 'DESC');
131
+ $campaigns->setOrder('RAND()', 'ASC');
132
+
133
+ $options = new Varien_Object($options);
134
+ $options->getDataSetDefault('timeout', 100);
135
+ $options->getDataSetDefault('maximum', 500);
136
+ $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
137
+
138
+
139
+ if($options->getVerbose()) {
140
+ echo "\n\n{$campaigns->getSelect()}\n\n";
141
+ }
142
+
143
+ $start = time();
144
+
145
+ $timeout = (int) $options->getTimeout();
146
+ $maximum = (int) $options->getMaximum();
147
+
148
+ $count = 0;
149
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
150
+ foreach($campaigns as $campaign) {
151
+ try {
152
+ if($options->getVerbose()) {
153
+ echo sprintf("Send Recipients for '%s' (#%s)...", $campaign->getName(), $campaign->getId());
154
+ }
155
+
156
+ $count += $sent = $campaign->sendRecipients(array(
157
+ 'timeout' => $timeout - (time()-$start),
158
+ 'maximum' => $maximum - $count,
159
+ 'break_on_error' => $options->getBreakOnError()
160
+ ));
161
+
162
+ if($options->getVerbose()) {
163
+ echo sprintf(" \tsent %s\n", $sent);
164
+ }
165
+ }
166
+ catch(Exception $e) {
167
+ if($options->getBreakOnError()) {
168
+ $lock->unlock();
169
+ throw $e;
170
+ }
171
+ Mage::logException($e);
172
+ if($options->getVerbose()) {
173
+ echo "\n{$e->getMessage()}\n{$e->getTraceAsString()}\n\n";
174
+ }
175
+ }
176
+ // make sure we don't exceed the timeout
177
+ if($timeout && time()-$start > $timeout) {
178
+ break;
179
+ }
180
+ // don't send more then max at once
181
+ if($maximum && $maximum <= $count) {
182
+ break;
183
+ }
184
+ $lock->touch();
185
+ }
186
+ $lock->unlock();
187
+ return $count;
188
+ }
189
+
190
+
191
+
192
+
193
+ }
app/code/community/Mzax/Emarketing/Helper/Data.php ADDED
@@ -0,0 +1,315 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Mzax_Emarketing_Helper_Data extends Mage_Core_Helper_Abstract
24
+ {
25
+
26
+
27
+
28
+ /**
29
+ * Retreive version
30
+ *
31
+ * @return string
32
+ */
33
+ public function getVersion()
34
+ {
35
+ return (string) Mage::getConfig()->getModuleConfig('Mzax_Emarketing')->version;
36
+ }
37
+
38
+
39
+
40
+
41
+ /**
42
+ * Create a lock with the given name
43
+ *
44
+ * @param string $name
45
+ * @param number $timeout
46
+ * @param number $maxRunTime
47
+ * @return Ambigous <boolean, Mzax_Once>|boolean
48
+ */
49
+ public function lock($name, $timeout = 5, $maxRunTime = 3600)
50
+ {
51
+ $filename = Mage::getBaseDir('tmp') . DS . 'mzax_emarketing_' . $name . '.lock';
52
+
53
+ if($lock = Mzax_Once::lock($filename, $timeout, $maxRunTime)) {
54
+ return $lock;
55
+ }
56
+ return false;
57
+ }
58
+
59
+
60
+
61
+ /**
62
+ * Compress a 32 char hex hash to a 16 char accii hash
63
+ * without loosing to much of uniqueness
64
+ *
65
+ * @param string $hash
66
+ * @return string
67
+ */
68
+ public function compressHash($hash)
69
+ {
70
+ $parts = str_split($hash, 2);
71
+
72
+ $base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXQZ';
73
+ $baseLength = strlen($base);
74
+ $compress = '';
75
+ foreach($parts as $part) {
76
+ $compress .= $base{hexdec($part)%$baseLength};
77
+ }
78
+ return $compress;
79
+ }
80
+
81
+
82
+
83
+
84
+ /**
85
+ * Encode magento expressions
86
+ *
87
+ * Magento expressions {{var xzt}} don't work well
88
+ * with HTML as they are not encoded in attributes for instance.
89
+ *
90
+ * We can encode them and decode them later
91
+ *
92
+ * @param unknown $html
93
+ * @return string
94
+ */
95
+ public function encodeMageExpr(&$html)
96
+ {
97
+ $html = preg_replace_callback('/\{\{(.*?)\}\}/', function($match) {
98
+ return '#MAGE_EXPR(' . base64_encode($match[0]) . ')';
99
+ },$html);
100
+ }
101
+
102
+
103
+ /**
104
+ * Decode magento expressions that have been encoded
105
+ *
106
+ * @param string $html
107
+ * @return string
108
+ */
109
+ public function decodeMageExpr(&$html)
110
+ {
111
+ $html = preg_replace_callback('/#MAGE_EXPR\((.*?)\)/', function($match) {
112
+ return base64_decode($match[1]);
113
+ },$html);
114
+ }
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ protected $_operatorsByType = array(
124
+ 'string' => array('==', '!=', '>=', '>', '<=', '<', '{}', '!{}', '()', '!()'),
125
+ 'numeric' => array('==', '!=', '>=', '>', '<=', '<', '()', '!()'),
126
+ 'date' => array('==', '>=', '<='),
127
+ 'select' => array('==', '!=', '()', '!()'),
128
+ 'boolean' => array('==', '!='),
129
+ 'multiselect' => array('()', '!()'),
130
+ 'grid' => array('()', '!()'),
131
+ );
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+ /**
141
+ * Retrieve Store Options
142
+ *
143
+ * @return array
144
+ */
145
+ public function getStoreOptions()
146
+ {
147
+ /* Mage_Adminhtml_Model_System_Config_Source_Store */
148
+ return Mage::getModel('adminhtml/system_config_source_store')->toOptionArray();
149
+ }
150
+
151
+
152
+
153
+ /**
154
+ * Retrieve Website Options
155
+ *
156
+ * @return array
157
+ */
158
+ public function getWebsitesOptions()
159
+ {
160
+ /* Mage_Adminhtml_Model_System_Config_Source_Website */
161
+ returnMage::getModel('adminhtml/system_config_source_website')->toOptionArray();
162
+ }
163
+
164
+
165
+
166
+
167
+
168
+ public function getDefaultValueByType($type)
169
+ {
170
+ switch($type) {
171
+ case 'numeric': return '1';
172
+ }
173
+ return '';
174
+ }
175
+
176
+
177
+
178
+
179
+ public function getDefaultOperatorByType($type)
180
+ {
181
+ switch($type) {
182
+ case 'boolean':
183
+ case 'numeric':
184
+ case 'select':
185
+ case 'date':
186
+ return '==';
187
+ case 'multiselect':
188
+ return '()';
189
+ }
190
+ return '{}';
191
+ }
192
+
193
+
194
+
195
+ /**
196
+ * Retrieve operators by type
197
+ *
198
+ * @param string $type
199
+ * @return array
200
+ */
201
+ public function getOperatorOptionsByType($type)
202
+ {
203
+ $operators = $this->getOperatorOptions();
204
+
205
+ if(isset($this->_operatorsByType[$type])) {
206
+ return $this->getOperatorOptions($this->_operatorsByType[$type]);
207
+ }
208
+ return $operators;
209
+ }
210
+
211
+
212
+
213
+
214
+ /**
215
+ * Retrieve operator options
216
+ *
217
+ * @return array
218
+ */
219
+ public function getOperatorOptions($filter = null)
220
+ {
221
+ $options = array(
222
+ '==' => $this->__('is'),
223
+ '!=' => $this->__('is not'),
224
+ '>=' => $this->__('equals or greater than'),
225
+ '<=' => $this->__('equals or less than'),
226
+ '>' => $this->__('greater than'),
227
+ '<' => $this->__('less than'),
228
+ '{}' => $this->__('contains'),
229
+ '!{}' => $this->__('does not contain'),
230
+ '()' => $this->__('is one of'),
231
+ '!()' => $this->__('is not one of')
232
+ );
233
+
234
+ if(is_array($filter)) {
235
+ $result = array();
236
+ foreach($options as $key => $label) {
237
+ if(in_array($key, $filter)) {
238
+ $result[$key] = $label;
239
+ }
240
+ }
241
+ return $result;
242
+ }
243
+ return $options;
244
+ }
245
+
246
+
247
+
248
+
249
+
250
+
251
+ /**
252
+ * Retrieve time unit options
253
+ *
254
+ * @param string $value
255
+ * @return array
256
+ */
257
+ public function getTimeUnitOptions()
258
+ {
259
+ return array(
260
+ 'hours' => $this->__('hour(s)'),
261
+ 'days' => $this->__('day(s)'),
262
+ 'weeks' => $this->__('week(s)'),
263
+ 'months' => $this->__('month(s)'),
264
+ 'years' => $this->__('year(s)')
265
+ );
266
+ }
267
+
268
+
269
+
270
+
271
+ /**
272
+ * Calculate date
273
+ *
274
+ * @param number $value
275
+ * @param string $unit
276
+ * @param number $roundDate
277
+ * @return Zend_Date
278
+ */
279
+ public function calcDate($value, $unit, $roundDate = null, $sign = '-')
280
+ {
281
+ // validate unit
282
+ if(!key_exists($unit, $this->getTimeUnitOptions())) {
283
+ return null;
284
+ }
285
+
286
+ $timestamp = strtotime("{$sign}{$value} {$unit}");
287
+ if($timestamp) {
288
+ // don't calculate with extrem high numbers (preformance)
289
+ $timestamp = min(max($timestamp, 0), 10000000000);
290
+ $date = new Zend_Date;
291
+ $date->setTimestamp($timestamp);
292
+
293
+ if($roundDate === self::DAY_START) {
294
+ $date->setHour(0);
295
+ $date->setMinute(0);
296
+ $date->setSecond(0);
297
+ }
298
+ else if($roundDate === self::DAY_END) {
299
+ $date->setHour(23);
300
+ $date->setMinute(59);
301
+ $date->setSecond(59);
302
+ }
303
+
304
+ return $date;
305
+ }
306
+
307
+ return null;
308
+ }
309
+
310
+
311
+
312
+
313
+
314
+
315
+ }
app/code/community/Mzax/Emarketing/Helper/Newsletter.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Helper_Newsletter extends Mage_Core_Helper_Abstract
34
+ {
35
+
36
+
37
+
38
+ /**
39
+ * Unsubscribe email from newsletter
40
+ *
41
+ * @param string $email
42
+ * @param integer $storeId
43
+ * @param boolean $sendUnsubscriptionEmail
44
+ * @return Mage_Newsletter_Model_Subscriber
45
+ */
46
+ public function unsubscribe($email, $storeId, $sendUnsubscriptionEmail = false)
47
+ {
48
+ if(!$storeId) {
49
+ $storeId = Mage::app()->getStore()->getId();
50
+ }
51
+
52
+ /* @var $subscriber Mage_Newsletter_Model_Subscriber */
53
+ $subscriber = Mage::getModel('newsletter/subscriber');
54
+ $subscriber->setStoreId($storeId);
55
+ $subscriber->loadByEmail($email);
56
+
57
+ if(!$subscriber->getId()) {
58
+ $subscriber->setEmail($email);
59
+ $subscriber->setSubscriberConfirmCode($subscriber->randomSequence());
60
+ }
61
+
62
+ if($subscriber->getStatus() != $subscriber::STATUS_UNSUBSCRIBED) {
63
+ $subscriber->setIsStatusChanged(true);
64
+ $subscriber->setChangeStatusAt(now());
65
+ $subscriber->setSubscriberStatus($subscriber::STATUS_UNSUBSCRIBED)->save();
66
+
67
+ if($sendUnsubscriptionEmail) {
68
+ $subscriber->sendUnsubscriptionEmail();
69
+ }
70
+ }
71
+
72
+ return $subscriber;
73
+ }
74
+
75
+
76
+
77
+
78
+ }
app/code/community/Mzax/Emarketing/Helper/Request.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Helper_Request extends Mage_Core_Helper_Abstract
34
+ {
35
+ /**
36
+ *
37
+ * @var string
38
+ */
39
+ const CACHE_ID = 'mzax_emarketing_bad_requests';
40
+
41
+
42
+ /**
43
+ *
44
+ * @var integer
45
+ */
46
+ const MAX_BAD_REQUESTS = 25;
47
+
48
+
49
+ /**
50
+ *
51
+ * @var integer
52
+ */
53
+ const RESET_TIME = 3600;
54
+
55
+
56
+ /**
57
+ *
58
+ * @var array
59
+ */
60
+ protected $_data;
61
+
62
+
63
+
64
+ /**
65
+ * Check if we can "trust" the request
66
+ *
67
+ * @param string $request
68
+ * @return boolean
69
+ */
70
+ public function isTrustable($request = null)
71
+ {
72
+ $data = $this->getData($request);
73
+ return ($data[0] < self::MAX_BAD_REQUESTS);
74
+ }
75
+
76
+
77
+
78
+ /**
79
+ * Flag current connection
80
+ *
81
+ * if a connection (IP) has to many bad requests
82
+ * then we should not trust them anymore with
83
+ * any sensetive data
84
+ *
85
+ * @param string $request
86
+ * @return number
87
+ */
88
+ public function bad($request = null)
89
+ {
90
+ $data = $this->getData($request);
91
+
92
+ // reset counter if last bad request is a while ago
93
+ if(time() - $data[1] >= self::RESET_TIME) {
94
+ $data[0] = 0;
95
+ }
96
+
97
+ // increase
98
+ $data[0]++;
99
+ $data[1] = time();
100
+
101
+ $this->setData($data, $request);
102
+ return $data[0];
103
+ }
104
+
105
+
106
+
107
+
108
+ /**
109
+ * Retrieve data for request
110
+ *
111
+ * @param string $request
112
+ * @return array
113
+ */
114
+ public function getData($request = null)
115
+ {
116
+ if(!$request) {
117
+ $request = Mage::app()->getRequest();
118
+ }
119
+ $ip = $request->getServer('REMOTE_ADDR');
120
+
121
+ $data = $this->loadData();
122
+
123
+ if( isset($data[$ip]) ) {
124
+ return $data[$ip];
125
+ }
126
+
127
+ // no request yet made by this ip yet
128
+ return array(0, time());
129
+ }
130
+
131
+
132
+
133
+ /**
134
+ * Set dat for request
135
+ *
136
+ * @param array $data
137
+ * @param string $request
138
+ */
139
+ public function setData(array $data, $request = null)
140
+ {
141
+ if(!$request) {
142
+ $request = Mage::app()->getRequest();
143
+ }
144
+ $ip = $request->getServer('REMOTE_ADDR');
145
+
146
+ $cacheData = $this->loadData();
147
+ $cacheData[$ip] = $data;
148
+ $this->saveData($cacheData);
149
+ }
150
+
151
+
152
+
153
+ /**
154
+ * Load dat from cache
155
+ *
156
+ * @return array
157
+ */
158
+ public function loadData()
159
+ {
160
+ if(!$this->_data) {
161
+ $this->_data = Mage::app()->loadCache(self::CACHE_ID);
162
+ if($this->_data) {
163
+ $this->_data = unserialize($this->_data);
164
+ }
165
+ else {
166
+ $this->_data = array();
167
+ }
168
+ }
169
+ return $this->_data;
170
+ }
171
+
172
+
173
+
174
+ /**
175
+ * save data to cache
176
+ *
177
+ * @param array $data
178
+ */
179
+ public function saveData(array $data)
180
+ {
181
+ $this->_data = $data;
182
+ Mage::app()->saveCache(serialize($data), self::CACHE_ID);
183
+ }
184
+
185
+
186
+
187
+ }
app/code/community/Mzax/Emarketing/Helper/SqlFormatter.php ADDED
@@ -0,0 +1,1107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * SQL Formatter is a collection of utilities for debugging SQL queries.
26
+ * It includes methods for formatting, syntax highlighting, removing comments, etc.
27
+ *
28
+ * @package SqlFormatter
29
+ * @author Jeremy Dorn <jeremy@jeremydorn.com>
30
+ * @author Florin Patan <florinpatan@gmail.com>
31
+ * @copyright 2013 Jeremy Dorn
32
+ * @license http://opensource.org/licenses/MIT
33
+ * @link http://github.com/jdorn/sql-formatter
34
+ * @version 1.2.18
35
+ */
36
+ class Mzax_Emarketing_Helper_SqlFormatter extends Mage_Core_Helper_Abstract
37
+ {
38
+ // Constants for token types
39
+ const TOKEN_TYPE_WHITESPACE = 0;
40
+ const TOKEN_TYPE_WORD = 1;
41
+ const TOKEN_TYPE_QUOTE = 2;
42
+ const TOKEN_TYPE_BACKTICK_QUOTE = 3;
43
+ const TOKEN_TYPE_RESERVED = 4;
44
+ const TOKEN_TYPE_RESERVED_TOPLEVEL = 5;
45
+ const TOKEN_TYPE_RESERVED_NEWLINE = 6;
46
+ const TOKEN_TYPE_BOUNDARY = 7;
47
+ const TOKEN_TYPE_COMMENT = 8;
48
+ const TOKEN_TYPE_BLOCK_COMMENT = 9;
49
+ const TOKEN_TYPE_NUMBER = 10;
50
+ const TOKEN_TYPE_ERROR = 11;
51
+ const TOKEN_TYPE_VARIABLE = 12;
52
+
53
+ // Constants for different components of a token
54
+ const TOKEN_TYPE = 0;
55
+ const TOKEN_VALUE = 1;
56
+
57
+ // Reserved words (for syntax highlighting)
58
+ protected static $reserved = array(
59
+ 'ACCESSIBLE', 'ACTION', 'AGAINST', 'AGGREGATE', 'ALGORITHM', 'ALL', 'ALTER', 'ANALYSE', 'ANALYZE', 'AS', 'ASC',
60
+ 'AUTOCOMMIT', 'AUTO_INCREMENT', 'BACKUP', 'BEGIN', 'BETWEEN', 'BINLOG', 'BOTH', 'CASCADE', 'CASE', 'CHANGE', 'CHANGED', 'CHARACTER SET',
61
+ 'CHARSET', 'CHECK', 'CHECKSUM', 'COLLATE', 'COLLATION', 'COLUMN', 'COLUMNS', 'COMMENT', 'COMMIT', 'COMMITTED', 'COMPRESSED', 'CONCURRENT',
62
+ 'CONSTRAINT', 'CONTAINS', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_TIMESTAMP', 'DATABASE', 'DATABASES', 'DAY', 'DAY_HOUR', 'DAY_MINUTE',
63
+ 'DAY_SECOND', 'DEFAULT', 'DEFINER', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DIV',
64
+ 'DO', 'DUMPFILE', 'DUPLICATE', 'DYNAMIC', 'ELSE', 'ENCLOSED', 'END', 'ENGINE', 'ENGINE_TYPE', 'ENGINES', 'ESCAPE', 'ESCAPED', 'EVENTS', 'EXEC',
65
+ 'EXECUTE', 'EXISTS', 'EXPLAIN', 'EXTENDED', 'FAST', 'FIELDS', 'FILE', 'FIRST', 'FIXED', 'FLUSH', 'FOR', 'FORCE', 'FOREIGN', 'FULL', 'FULLTEXT',
66
+ 'FUNCTION', 'GLOBAL', 'GRANT', 'GRANTS', 'GROUP_CONCAT', 'HEAP', 'HIGH_PRIORITY', 'HOSTS', 'HOUR', 'HOUR_MINUTE',
67
+ 'HOUR_SECOND', 'IDENTIFIED', 'IF', 'IFNULL', 'IGNORE', 'IN', 'INDEX', 'INDEXES', 'INFILE', 'INSERT', 'INSERT_ID', 'INSERT_METHOD', 'INTERVAL',
68
+ 'INTO', 'INVOKER', 'IS', 'ISOLATION', 'KEY', 'KEYS', 'KILL', 'LAST_INSERT_ID', 'LEADING', 'LEVEL', 'LIKE', 'LINEAR',
69
+ 'LINES', 'LOAD', 'LOCAL', 'LOCK', 'LOCKS', 'LOGS', 'LOW_PRIORITY', 'MARIA', 'MASTER', 'MASTER_CONNECT_RETRY', 'MASTER_HOST', 'MASTER_LOG_FILE',
70
+ 'MATCH','MAX_CONNECTIONS_PER_HOUR', 'MAX_QUERIES_PER_HOUR', 'MAX_ROWS', 'MAX_UPDATES_PER_HOUR', 'MAX_USER_CONNECTIONS',
71
+ 'MEDIUM', 'MERGE', 'MINUTE', 'MINUTE_SECOND', 'MIN_ROWS', 'MODE', 'MODIFY',
72
+ 'MONTH', 'MRG_MYISAM', 'MYISAM', 'NAMES', 'NATURAL', 'NOT', 'NOW()','NULL', 'OFFSET', 'ON', 'OPEN', 'OPTIMIZE', 'OPTION', 'OPTIONALLY',
73
+ 'ON UPDATE', 'ON DELETE', 'OUTFILE', 'PACK_KEYS', 'PAGE', 'PARTIAL', 'PARTITION', 'PARTITIONS', 'PASSWORD', 'PRIMARY', 'PRIVILEGES', 'PROCEDURE',
74
+ 'PROCESS', 'PROCESSLIST', 'PURGE', 'QUICK', 'RANGE', 'RAID0', 'RAID_CHUNKS', 'RAID_CHUNKSIZE','RAID_TYPE', 'READ', 'READ_ONLY',
75
+ 'READ_WRITE', 'REFERENCES', 'REGEXP', 'RELOAD', 'RENAME', 'REPAIR', 'REPEATABLE', 'REPLACE', 'REPLICATION', 'RESET', 'RESTORE', 'RESTRICT',
76
+ 'RETURN', 'RETURNS', 'REVOKE', 'RLIKE', 'ROLLBACK', 'ROW', 'ROWS', 'ROW_FORMAT', 'SECOND', 'SECURITY', 'SEPARATOR',
77
+ 'SERIALIZABLE', 'SESSION', 'SHARE', 'SHOW', 'SHUTDOWN', 'SLAVE', 'SONAME', 'SOUNDS', 'SQL', 'SQL_AUTO_IS_NULL', 'SQL_BIG_RESULT',
78
+ 'SQL_BIG_SELECTS', 'SQL_BIG_TABLES', 'SQL_BUFFER_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_LOG_BIN', 'SQL_LOG_OFF', 'SQL_LOG_UPDATE',
79
+ 'SQL_LOW_PRIORITY_UPDATES', 'SQL_MAX_JOIN_SIZE', 'SQL_QUOTE_SHOW_CREATE', 'SQL_SAFE_UPDATES', 'SQL_SELECT_LIMIT', 'SQL_SLAVE_SKIP_COUNTER',
80
+ 'SQL_SMALL_RESULT', 'SQL_WARNINGS', 'SQL_CACHE', 'SQL_NO_CACHE', 'START', 'STARTING', 'STATUS', 'STOP', 'STORAGE',
81
+ 'STRAIGHT_JOIN', 'STRING', 'STRIPED', 'SUPER', 'TABLE', 'TABLES', 'TEMPORARY', 'TERMINATED', 'THEN', 'TO', 'TRAILING', 'TRANSACTIONAL', 'TRUE',
82
+ 'TRUNCATE', 'TYPE', 'TYPES', 'UNCOMMITTED', 'UNIQUE', 'UNLOCK', 'UNSIGNED', 'USAGE', 'USE', 'USING', 'VARIABLES',
83
+ 'VIEW', 'WHEN', 'WITH', 'WORK', 'WRITE', 'YEAR_MONTH'
84
+ );
85
+
86
+ // For SQL formatting
87
+ // These keywords will all be on their own line
88
+ protected static $reserved_toplevel = array(
89
+ 'SELECT', 'FROM', 'WHERE', 'SET', 'ORDER BY', 'GROUP BY', 'LIMIT', 'DROP',
90
+ 'VALUES', 'UPDATE', 'HAVING', 'ADD', 'AFTER', 'ALTER TABLE', 'DELETE FROM', 'UNION ALL', 'UNION', 'EXCEPT', 'INTERSECT'
91
+ );
92
+
93
+ protected static $reserved_newline = array(
94
+ 'LEFT OUTER JOIN', 'RIGHT OUTER JOIN', 'LEFT JOIN', 'RIGHT JOIN', 'OUTER JOIN', 'INNER JOIN', 'JOIN', 'XOR', 'OR', 'AND'
95
+ );
96
+
97
+ protected static $functions = array (
98
+ 'ABS', 'ACOS', 'ADDDATE', 'ADDTIME', 'AES_DECRYPT', 'AES_ENCRYPT', 'AREA', 'ASBINARY', 'ASCII', 'ASIN', 'ASTEXT', 'ATAN', 'ATAN2',
99
+ 'AVG', 'BDMPOLYFROMTEXT', 'BDMPOLYFROMWKB', 'BDPOLYFROMTEXT', 'BDPOLYFROMWKB', 'BENCHMARK', 'BIN', 'BIT_AND', 'BIT_COUNT', 'BIT_LENGTH',
100
+ 'BIT_OR', 'BIT_XOR', 'BOUNDARY', 'BUFFER', 'CAST', 'CEIL', 'CEILING', 'CENTROID', 'CHAR', 'CHARACTER_LENGTH', 'CHARSET', 'CHAR_LENGTH',
101
+ 'COALESCE', 'COERCIBILITY', 'COLLATION', 'COMPRESS', 'CONCAT', 'CONCAT_WS', 'CONNECTION_ID', 'CONTAINS', 'CONV', 'CONVERT', 'CONVERT_TZ',
102
+ 'CONVEXHULL', 'COS', 'COT', 'COUNT', 'CRC32', 'CROSSES', 'CURDATE', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER',
103
+ 'CURTIME', 'DATABASE', 'DATE', 'DATEDIFF', 'DATE_ADD', 'DATE_DIFF', 'DATE_FORMAT', 'DATE_SUB', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK',
104
+ 'DAYOFYEAR', 'DECODE', 'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT', 'DIFFERENCE', 'DIMENSION', 'DISJOINT', 'DISTANCE', 'ELT', 'ENCODE',
105
+ 'ENCRYPT', 'ENDPOINT', 'ENVELOPE', 'EQUALS', 'EXP', 'EXPORT_SET', 'EXTERIORRING', 'EXTRACT', 'EXTRACTVALUE', 'FIELD', 'FIND_IN_SET', 'FLOOR',
106
+ 'FORMAT', 'FOUND_ROWS', 'FROM_DAYS', 'FROM_UNIXTIME', 'GEOMCOLLFROMTEXT', 'GEOMCOLLFROMWKB', 'GEOMETRYCOLLECTION', 'GEOMETRYCOLLECTIONFROMTEXT',
107
+ 'GEOMETRYCOLLECTIONFROMWKB', 'GEOMETRYFROMTEXT', 'GEOMETRYFROMWKB', 'GEOMETRYN', 'GEOMETRYTYPE', 'GEOMFROMTEXT', 'GEOMFROMWKB', 'GET_FORMAT',
108
+ 'GET_LOCK', 'GLENGTH', 'GREATEST', 'GROUP_CONCAT', 'GROUP_UNIQUE_USERS', 'HEX', 'HOUR', 'IF', 'IFNULL', 'INET_ATON', 'INET_NTOA', 'INSERT', 'INSTR',
109
+ 'INTERIORRINGN', 'INTERSECTION', 'INTERSECTS', 'INTERVAL', 'ISCLOSED', 'ISEMPTY', 'ISNULL', 'ISRING', 'ISSIMPLE', 'IS_FREE_LOCK', 'IS_USED_LOCK',
110
+ 'LAST_DAY', 'LAST_INSERT_ID', 'LCASE', 'LEAST', 'LEFT', 'LENGTH', 'LINEFROMTEXT', 'LINEFROMWKB', 'LINESTRING', 'LINESTRINGFROMTEXT', 'LINESTRINGFROMWKB',
111
+ 'LN', 'LOAD_FILE', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCATE', 'LOG', 'LOG10', 'LOG2', 'LOWER', 'LPAD', 'LTRIM', 'MAKEDATE', 'MAKETIME', 'MAKE_SET',
112
+ 'MASTER_POS_WAIT', 'MAX', 'MBRCONTAINS', 'MBRDISJOINT', 'MBREQUAL', 'MBRINTERSECTS', 'MBROVERLAPS', 'MBRTOUCHES', 'MBRWITHIN', 'MD5', 'MICROSECOND',
113
+ 'MID', 'MIN', 'MINUTE', 'MLINEFROMTEXT', 'MLINEFROMWKB', 'MOD', 'MONTH', 'MONTHNAME', 'MPOINTFROMTEXT', 'MPOINTFROMWKB', 'MPOLYFROMTEXT', 'MPOLYFROMWKB',
114
+ 'MULTILINESTRING', 'MULTILINESTRINGFROMTEXT', 'MULTILINESTRINGFROMWKB', 'MULTIPOINT', 'MULTIPOINTFROMTEXT', 'MULTIPOINTFROMWKB', 'MULTIPOLYGON',
115
+ 'MULTIPOLYGONFROMTEXT', 'MULTIPOLYGONFROMWKB', 'NAME_CONST', 'NULLIF', 'NUMGEOMETRIES', 'NUMINTERIORRINGS', 'NUMPOINTS', 'OCT', 'OCTET_LENGTH',
116
+ 'OLD_PASSWORD', 'ORD', 'OVERLAPS', 'PASSWORD', 'PERIOD_ADD', 'PERIOD_DIFF', 'PI', 'POINT', 'POINTFROMTEXT', 'POINTFROMWKB', 'POINTN', 'POINTONSURFACE',
117
+ 'POLYFROMTEXT', 'POLYFROMWKB', 'POLYGON', 'POLYGONFROMTEXT', 'POLYGONFROMWKB', 'POSITION', 'POW', 'POWER', 'QUARTER', 'QUOTE', 'RADIANS', 'RAND',
118
+ 'RELATED', 'RELEASE_LOCK', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'ROUND', 'ROW_COUNT', 'RPAD', 'RTRIM', 'SCHEMA', 'SECOND', 'SEC_TO_TIME',
119
+ 'SESSION_USER', 'SHA', 'SHA1', 'SIGN', 'SIN', 'SLEEP', 'SOUNDEX', 'SPACE', 'SQRT', 'SRID', 'STARTPOINT', 'STD', 'STDDEV', 'STDDEV_POP', 'STDDEV_SAMP',
120
+ 'STRCMP', 'STR_TO_DATE', 'SUBDATE', 'SUBSTR', 'SUBSTRING', 'SUBSTRING_INDEX', 'SUBTIME', 'SUM', 'SYMDIFFERENCE', 'SYSDATE', 'SYSTEM_USER', 'TAN',
121
+ 'TIME', 'TIMEDIFF', 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TIME_FORMAT', 'TIME_TO_SEC', 'TOUCHES', 'TO_DAYS', 'TRIM', 'TRUNCATE', 'UCASE',
122
+ 'UNCOMPRESS', 'UNCOMPRESSED_LENGTH', 'UNHEX', 'UNIQUE_USERS', 'UNIX_TIMESTAMP', 'UPDATEXML', 'UPPER', 'USER', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP',
123
+ 'UUID', 'VARIANCE', 'VAR_POP', 'VAR_SAMP', 'VERSION', 'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'WITHIN', 'X', 'Y', 'YEAR', 'YEARWEEK'
124
+ );
125
+
126
+ // Punctuation that can be used as a boundary between other tokens
127
+ protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
128
+
129
+ // For HTML syntax highlighting
130
+ // Styles applied to different token types
131
+ public static $quote_attributes = 'style="color: blue;"';
132
+ public static $backtick_quote_attributes = 'style="color: purple;"';
133
+ public static $reserved_attributes = 'style="font-weight:bold;"';
134
+ public static $boundary_attributes = '';
135
+ public static $number_attributes = 'style="color: green;"';
136
+ public static $word_attributes = 'style="color: #333;"';
137
+ public static $error_attributes = 'style="background-color: red;"';
138
+ public static $comment_attributes = 'style="color: #aaa;"';
139
+ public static $variable_attributes = 'style="color: orange;"';
140
+ public static $pre_attributes = 'style="color: black;"';
141
+
142
+ // Boolean - whether or not the current environment is the CLI
143
+ // This affects the type of syntax highlighting
144
+ // If not defined, it will be determined automatically
145
+ public static $cli;
146
+
147
+ // For CLI syntax highlighting
148
+ public static $cli_quote = "\x1b[34;1m";
149
+ public static $cli_backtick_quote = "\x1b[35;1m";
150
+ public static $cli_reserved = "\x1b[37m";
151
+ public static $cli_boundary = "";
152
+ public static $cli_number = "\x1b[32;1m";
153
+ public static $cli_word = "";
154
+ public static $cli_error = "\x1b[31;1;7m";
155
+ public static $cli_comment = "\x1b[30;1m";
156
+ public static $cli_functions = "\x1b[37m";
157
+ public static $cli_variable = "\x1b[36;1m";
158
+
159
+ // The tab character to use when formatting SQL
160
+ public static $tab = ' ';
161
+
162
+ // This flag tells us if queries need to be enclosed in <pre> tags
163
+ public static $use_pre = true;
164
+
165
+ // This flag tells us if SqlFormatted has been initialized
166
+ protected static $init;
167
+
168
+ // Regular expressions for tokenizing
169
+ protected static $regex_boundaries;
170
+ protected static $regex_reserved;
171
+ protected static $regex_reserved_newline;
172
+ protected static $regex_reserved_toplevel;
173
+ protected static $regex_function;
174
+
175
+ // Cache variables
176
+ // Only tokens shorter than this size will be cached. Somewhere between 10 and 20 seems to work well for most cases.
177
+ public static $max_cachekey_size = 15;
178
+ protected static $token_cache = array();
179
+ protected static $cache_hits = 0;
180
+ protected static $cache_misses = 0;
181
+
182
+ /**
183
+ * Get stats about the token cache
184
+ * @return Array An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes
185
+ */
186
+ public static function getCacheStats()
187
+ {
188
+ return array(
189
+ 'hits'=>self::$cache_hits,
190
+ 'misses'=>self::$cache_misses,
191
+ 'entries'=>count(self::$token_cache),
192
+ 'size'=>strlen(serialize(self::$token_cache))
193
+ );
194
+ }
195
+
196
+ /**
197
+ * Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words.
198
+ */
199
+ protected static function init()
200
+ {
201
+ if (self::$init) return;
202
+
203
+ // Sort reserved word list from longest word to shortest, 3x faster than usort
204
+ $reservedMap = array_combine(self::$reserved, array_map('strlen', self::$reserved));
205
+ arsort($reservedMap);
206
+ self::$reserved = array_keys($reservedMap);
207
+
208
+ // Set up regular expressions
209
+ self::$regex_boundaries = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$boundaries)).')';
210
+ self::$regex_reserved = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved)).')';
211
+ self::$regex_reserved_toplevel = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_toplevel)).')');
212
+ self::$regex_reserved_newline = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_newline)).')');
213
+
214
+ self::$regex_function = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$functions)).')';
215
+
216
+ self::$init = true;
217
+ }
218
+
219
+ /**
220
+ * Return the next token and token type in a SQL string.
221
+ * Quoted strings, comments, reserved words, whitespace, and punctuation are all their own tokens.
222
+ *
223
+ * @param String $string The SQL string
224
+ * @param array $previous The result of the previous getNextToken() call
225
+ *
226
+ * @return Array An associative array containing the type and value of the token.
227
+ */
228
+ protected static function getNextToken($string, $previous = null)
229
+ {
230
+ // Whitespace
231
+ if (preg_match('/^\s+/',$string,$matches)) {
232
+ return array(
233
+ self::TOKEN_VALUE => $matches[0],
234
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_WHITESPACE
235
+ );
236
+ }
237
+
238
+ // Comment
239
+ if ($string[0] === '#' || (isset($string[1])&&($string[0]==='-'&&$string[1]==='-') || ($string[0]==='/'&&$string[1]==='*'))) {
240
+ // Comment until end of line
241
+ if ($string[0] === '-' || $string[0] === '#') {
242
+ $last = strpos($string, "\n");
243
+ $type = self::TOKEN_TYPE_COMMENT;
244
+ } else { // Comment until closing comment tag
245
+ $last = strpos($string, "*/", 2) + 2;
246
+ $type = self::TOKEN_TYPE_BLOCK_COMMENT;
247
+ }
248
+
249
+ if ($last === false) {
250
+ $last = strlen($string);
251
+ }
252
+
253
+ return array(
254
+ self::TOKEN_VALUE => substr($string, 0, $last),
255
+ self::TOKEN_TYPE => $type
256
+ );
257
+ }
258
+
259
+ // Quoted String
260
+ if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`' || $string[0]==='[') {
261
+ $return = array(
262
+ self::TOKEN_TYPE => (($string[0]==='`' || $string[0]==='[')? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
263
+ self::TOKEN_VALUE => self::getQuotedString($string)
264
+ );
265
+
266
+ return $return;
267
+ }
268
+
269
+ // User-defined Variable
270
+ if ($string[0] === '@' && isset($string[1])) {
271
+ $ret = array(
272
+ self::TOKEN_VALUE => null,
273
+ self::TOKEN_TYPE => self::TOKEN_TYPE_VARIABLE
274
+ );
275
+
276
+ // If the variable name is quoted
277
+ if ($string[1]==='"' || $string[1]==='\'' || $string[1]==='`') {
278
+ $ret[self::TOKEN_VALUE] = '@'.self::getQuotedString(substr($string,1));
279
+ }
280
+ // Non-quoted variable name
281
+ else {
282
+ preg_match('/^(@[a-zA-Z0-9\._\$]+)/',$string,$matches);
283
+ if ($matches) {
284
+ $ret[self::TOKEN_VALUE] = $matches[1];
285
+ }
286
+ }
287
+
288
+ if($ret[self::TOKEN_VALUE] !== null) return $ret;
289
+ }
290
+
291
+ // Number (decimal, binary, or hex)
292
+ if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|'.self::$regex_boundaries.')/',$string,$matches)) {
293
+ return array(
294
+ self::TOKEN_VALUE => $matches[1],
295
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_NUMBER
296
+ );
297
+ }
298
+
299
+ // Boundary Character (punctuation and symbols)
300
+ if (preg_match('/^('.self::$regex_boundaries.')/',$string,$matches)) {
301
+ return array(
302
+ self::TOKEN_VALUE => $matches[1],
303
+ self::TOKEN_TYPE => self::TOKEN_TYPE_BOUNDARY
304
+ );
305
+ }
306
+
307
+ // A reserved word cannot be preceded by a '.'
308
+ // this makes it so in "mytable.from", "from" is not considered a reserved word
309
+ if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
310
+ $upper = strtoupper($string);
311
+ // Top Level Reserved Word
312
+ if (preg_match('/^('.self::$regex_reserved_toplevel.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) {
313
+ return array(
314
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED_TOPLEVEL,
315
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1]))
316
+ );
317
+ }
318
+ // Newline Reserved Word
319
+ if (preg_match('/^('.self::$regex_reserved_newline.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) {
320
+ return array(
321
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED_NEWLINE,
322
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1]))
323
+ );
324
+ }
325
+ // Other Reserved Word
326
+ if (preg_match('/^('.self::$regex_reserved.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) {
327
+ return array(
328
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED,
329
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1]))
330
+ );
331
+ }
332
+ }
333
+
334
+ // A function must be suceeded by '('
335
+ // this makes it so "count(" is considered a function, but "count" alone is not
336
+ $upper = strtoupper($string);
337
+ // function
338
+ if (preg_match('/^('.self::$regex_function.'[(]|\s|[)])/', $upper,$matches)) {
339
+ return array(
340
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED,
341
+ self::TOKEN_VALUE=>substr($string,0,strlen($matches[1])-1)
342
+ );
343
+ }
344
+
345
+ // Non reserved word
346
+ preg_match('/^(.*?)($|\s|["\'`]|'.self::$regex_boundaries.')/',$string,$matches);
347
+
348
+ return array(
349
+ self::TOKEN_VALUE => $matches[1],
350
+ self::TOKEN_TYPE => self::TOKEN_TYPE_WORD
351
+ );
352
+ }
353
+
354
+ protected static function getQuotedString($string)
355
+ {
356
+ $ret = null;
357
+
358
+ // This checks for the following patterns:
359
+ // 1. backtick quoted string using `` to escape
360
+ // 2. square bracket quoted string (SQL Server) using ]] to escape
361
+ // 3. double quoted string using "" or \" to escape
362
+ // 4. single quoted string using '' or \' to escape
363
+ if ( preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) {
364
+ $ret = $matches[1];
365
+ }
366
+
367
+ return $ret;
368
+ }
369
+
370
+ /**
371
+ * Takes a SQL string and breaks it into tokens.
372
+ * Each token is an associative array with type and value.
373
+ *
374
+ * @param String $string The SQL string
375
+ *
376
+ * @return Array An array of tokens.
377
+ */
378
+ protected static function tokenize($string)
379
+ {
380
+ self::init();
381
+
382
+ $tokens = array();
383
+
384
+ // Used for debugging if there is an error while tokenizing the string
385
+ $original_length = strlen($string);
386
+
387
+ // Used to make sure the string keeps shrinking on each iteration
388
+ $old_string_len = strlen($string) + 1;
389
+
390
+ $token = null;
391
+
392
+ $current_length = strlen($string);
393
+
394
+ // Keep processing the string until it is empty
395
+ while ($current_length) {
396
+ // If the string stopped shrinking, there was a problem
397
+ if ($old_string_len <= $current_length) {
398
+ $tokens[] = array(
399
+ self::TOKEN_VALUE=>$string,
400
+ self::TOKEN_TYPE=>self::TOKEN_TYPE_ERROR
401
+ );
402
+
403
+ return $tokens;
404
+ }
405
+ $old_string_len = $current_length;
406
+
407
+ // Determine if we can use caching
408
+ if ($current_length >= self::$max_cachekey_size) {
409
+ $cacheKey = substr($string,0,self::$max_cachekey_size);
410
+ } else {
411
+ $cacheKey = false;
412
+ }
413
+
414
+ // See if the token is already cached
415
+ if ($cacheKey && isset(self::$token_cache[$cacheKey])) {
416
+ // Retrieve from cache
417
+ $token = self::$token_cache[$cacheKey];
418
+ $token_length = strlen($token[self::TOKEN_VALUE]);
419
+ self::$cache_hits++;
420
+ } else {
421
+ // Get the next token and the token type
422
+ $token = self::getNextToken($string, $token);
423
+ $token_length = strlen($token[self::TOKEN_VALUE]);
424
+ self::$cache_misses++;
425
+
426
+ // If the token is shorter than the max length, store it in cache
427
+ if ($cacheKey && $token_length < self::$max_cachekey_size) {
428
+ self::$token_cache[$cacheKey] = $token;
429
+ }
430
+ }
431
+
432
+ $tokens[] = $token;
433
+
434
+ // Advance the string
435
+ $string = substr($string, $token_length);
436
+
437
+ $current_length -= $token_length;
438
+ }
439
+
440
+ return $tokens;
441
+ }
442
+
443
+ /**
444
+ * Format the whitespace in a SQL string to make it easier to read.
445
+ *
446
+ * @param String $string The SQL string
447
+ * @param boolean $highlight If true, syntax highlighting will also be performed
448
+ *
449
+ * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag
450
+ */
451
+ public static function format($string, $highlight=true)
452
+ {
453
+ // This variable will be populated with formatted html
454
+ $return = '';
455
+
456
+ // Use an actual tab while formatting and then switch out with self::$tab at the end
457
+ $tab = "\t";
458
+
459
+ $indent_level = 0;
460
+ $newline = false;
461
+ $inline_parentheses = false;
462
+ $increase_special_indent = false;
463
+ $increase_block_indent = false;
464
+ $indent_types = array();
465
+ $added_newline = false;
466
+ $inline_count = 0;
467
+ $inline_indented = false;
468
+ $clause_limit = false;
469
+
470
+ // Tokenize String
471
+ $original_tokens = self::tokenize($string);
472
+
473
+ // Remove existing whitespace
474
+ $tokens = array();
475
+ foreach ($original_tokens as $i=>$token) {
476
+ if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
477
+ $token['i'] = $i;
478
+ $tokens[] = $token;
479
+ }
480
+ }
481
+
482
+ // Format token by token
483
+ foreach ($tokens as $i=>$token) {
484
+ // Get highlighted token if doing syntax highlighting
485
+ if ($highlight) {
486
+ $highlighted = self::highlightToken($token);
487
+ } else { // If returning raw text
488
+ $highlighted = $token[self::TOKEN_VALUE];
489
+ }
490
+
491
+ // If we are increasing the special indent level now
492
+ if ($increase_special_indent) {
493
+ $indent_level++;
494
+ $increase_special_indent = false;
495
+ array_unshift($indent_types,'special');
496
+ }
497
+ // If we are increasing the block indent level now
498
+ if ($increase_block_indent) {
499
+ $indent_level++;
500
+ $increase_block_indent = false;
501
+ array_unshift($indent_types,'block');
502
+ }
503
+
504
+ // If we need a new line before the token
505
+ if ($newline) {
506
+ $return .= "\n" . str_repeat($tab, $indent_level);
507
+ $newline = false;
508
+ $added_newline = true;
509
+ } else {
510
+ $added_newline = false;
511
+ }
512
+
513
+ // Display comments directly where they appear in the source
514
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
515
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
516
+ $indent = str_repeat($tab,$indent_level);
517
+ $return .= "\n" . $indent;
518
+ $highlighted = str_replace("\n","\n".$indent,$highlighted);
519
+ }
520
+
521
+ $return .= $highlighted;
522
+ $newline = true;
523
+ continue;
524
+ }
525
+
526
+ if ($inline_parentheses) {
527
+ // End of inline parentheses
528
+ if ($token[self::TOKEN_VALUE] === ')') {
529
+ $return = rtrim($return,' ');
530
+
531
+ if ($inline_indented) {
532
+ array_shift($indent_types);
533
+ $indent_level --;
534
+ $return .= "\n" . str_repeat($tab, $indent_level);
535
+ }
536
+
537
+ $inline_parentheses = false;
538
+
539
+ $return .= $highlighted . ' ';
540
+ continue;
541
+ }
542
+
543
+ if ($token[self::TOKEN_VALUE] === ',') {
544
+ if ($inline_count >= 30) {
545
+ $inline_count = 0;
546
+ $newline = true;
547
+ }
548
+ }
549
+
550
+ $inline_count += strlen($token[self::TOKEN_VALUE]);
551
+ }
552
+
553
+ // Opening parentheses increase the block indent level and start a new line
554
+ if ($token[self::TOKEN_VALUE] === '(') {
555
+ // First check if this should be an inline parentheses block
556
+ // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2)
557
+ // Allow up to 3 non-whitespace tokens inside inline parentheses
558
+ $length = 0;
559
+ for ($j=1;$j<=250;$j++) {
560
+ // Reached end of string
561
+ if (!isset($tokens[$i+$j])) break;
562
+
563
+ $next = $tokens[$i+$j];
564
+
565
+ // Reached closing parentheses, able to inline it
566
+ if ($next[self::TOKEN_VALUE] === ')') {
567
+ $inline_parentheses = true;
568
+ $inline_count = 0;
569
+ $inline_indented = false;
570
+ break;
571
+ }
572
+
573
+ // Reached an invalid token for inline parentheses
574
+ if ($next[self::TOKEN_VALUE]===';' || $next[self::TOKEN_VALUE]==='(') {
575
+ break;
576
+ }
577
+
578
+ // Reached an invalid token type for inline parentheses
579
+ if ($next[self::TOKEN_TYPE]===self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE]===self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE]===self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE]===self::TOKEN_TYPE_BLOCK_COMMENT) {
580
+ break;
581
+ }
582
+
583
+ $length += strlen($next[self::TOKEN_VALUE]);
584
+ }
585
+
586
+ if ($inline_parentheses && $length > 30) {
587
+ $increase_block_indent = true;
588
+ $inline_indented = true;
589
+ $newline = true;
590
+ }
591
+
592
+ // Take out the preceding space unless there was whitespace there in the original query
593
+ if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
594
+ $return = rtrim($return,' ');
595
+ }
596
+
597
+ if (!$inline_parentheses) {
598
+ $increase_block_indent = true;
599
+ // Add a newline after the parentheses
600
+ $newline = true;
601
+ }
602
+
603
+ }
604
+
605
+ // Closing parentheses decrease the block indent level
606
+ elseif ($token[self::TOKEN_VALUE] === ')') {
607
+ // Remove whitespace before the closing parentheses
608
+ $return = rtrim($return,' ');
609
+
610
+ $indent_level--;
611
+
612
+ // Reset indent level
613
+ while ($j=array_shift($indent_types)) {
614
+ if ($j==='special') {
615
+ $indent_level--;
616
+ } else {
617
+ break;
618
+ }
619
+ }
620
+
621
+ if ($indent_level < 0) {
622
+ // This is an error
623
+ $indent_level = 0;
624
+
625
+ if ($highlight) {
626
+ $return .= "\n".self::highlightError($token[self::TOKEN_VALUE]);
627
+ continue;
628
+ }
629
+ }
630
+
631
+ // Add a newline before the closing parentheses (if not already added)
632
+ if (!$added_newline) {
633
+ $return .= "\n" . str_repeat($tab, $indent_level);
634
+ }
635
+ }
636
+
637
+ // Top level reserved words start a new line and increase the special indent level
638
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
639
+ $increase_special_indent = true;
640
+
641
+ // If the last indent type was 'special', decrease the special indent for this round
642
+ reset($indent_types);
643
+ if (current($indent_types)==='special') {
644
+ $indent_level--;
645
+ array_shift($indent_types);
646
+ }
647
+
648
+ // Add a newline after the top level reserved word
649
+ $newline = true;
650
+ // Add a newline before the top level reserved word (if not already added)
651
+ if (!$added_newline) {
652
+ $return .= "\n" . str_repeat($tab, $indent_level);
653
+ }
654
+ // If we already added a newline, redo the indentation since it may be different now
655
+ else {
656
+ $return = rtrim($return,$tab).str_repeat($tab, $indent_level);
657
+ }
658
+
659
+ // If the token may have extra whitespace
660
+ if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) {
661
+ $highlighted = preg_replace('/\s+/',' ',$highlighted);
662
+ }
663
+ //if SQL 'LIMIT' clause, start variable to reset newline
664
+ if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
665
+ $clause_limit = true;
666
+ }
667
+ }
668
+
669
+ // Checks if we are out of the limit clause
670
+ elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
671
+ $clause_limit = false;
672
+ }
673
+
674
+ // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause)
675
+ elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
676
+ //If the previous TOKEN_VALUE is 'LIMIT', resets new line
677
+ if ($clause_limit === true) {
678
+ $newline = false;
679
+ $clause_limit = false;
680
+ }
681
+ // All other cases of commas
682
+ else {
683
+ $newline = true;
684
+ }
685
+ }
686
+
687
+ // Newline reserved words start a new line
688
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
689
+ // Add a newline before the reserved word (if not already added)
690
+ if (!$added_newline) {
691
+ $return .= "\n" . str_repeat($tab, $indent_level);
692
+ }
693
+
694
+ // If the token may have extra whitespace
695
+ if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) {
696
+ $highlighted = preg_replace('/\s+/',' ',$highlighted);
697
+ }
698
+ }
699
+
700
+ // Multiple boundary characters in a row should not have spaces between them (not including parentheses)
701
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
702
+ if (isset($tokens[$i-1]) && $tokens[$i-1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
703
+ if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
704
+ $return = rtrim($return,' ');
705
+ }
706
+ }
707
+ }
708
+
709
+ // If the token shouldn't have a space before it
710
+ if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') {
711
+ $return = rtrim($return, ' ');
712
+ }
713
+
714
+ $return .= $highlighted.' ';
715
+
716
+ // If the token shouldn't have a space after it
717
+ if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
718
+ $return = rtrim($return,' ');
719
+ }
720
+
721
+ // If this is the "-" of a negative number, it shouldn't have a space after it
722
+ if($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i+1]) && $tokens[$i+1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i-1])) {
723
+ $prev = $tokens[$i-1][self::TOKEN_TYPE];
724
+ if($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
725
+ $return = rtrim($return,' ');
726
+ }
727
+ }
728
+ }
729
+
730
+ // If there are unmatched parentheses
731
+ if ($highlight && array_search('block',$indent_types) !== false) {
732
+ $return .= "\n".self::highlightError("WARNING: unclosed parentheses or section");
733
+ }
734
+
735
+ // Replace tab characters with the configuration tab character
736
+ $return = trim(str_replace("\t",self::$tab,$return));
737
+
738
+ if ($highlight) {
739
+ $return = self::output($return);
740
+ }
741
+
742
+ return $return;
743
+ }
744
+
745
+ /**
746
+ * Add syntax highlighting to a SQL string
747
+ *
748
+ * @param String $string The SQL string
749
+ *
750
+ * @return String The SQL string with HTML styles applied
751
+ */
752
+ public static function highlight($string)
753
+ {
754
+ $tokens = self::tokenize($string);
755
+
756
+ $return = '';
757
+
758
+ foreach ($tokens as $token) {
759
+ $return .= self::highlightToken($token);
760
+ }
761
+
762
+ return self::output($return);
763
+ }
764
+
765
+ /**
766
+ * Split a SQL string into multiple queries.
767
+ * Uses ";" as a query delimiter.
768
+ *
769
+ * @param String $string The SQL string
770
+ *
771
+ * @return Array An array of individual query strings without trailing semicolons
772
+ */
773
+ public static function splitQuery($string)
774
+ {
775
+ $queries = array();
776
+ $current_query = '';
777
+ $empty = true;
778
+
779
+ $tokens = self::tokenize($string);
780
+
781
+ foreach ($tokens as $token) {
782
+ // If this is a query separator
783
+ if ($token[self::TOKEN_VALUE] === ';') {
784
+ if (!$empty) {
785
+ $queries[] = $current_query.';';
786
+ }
787
+ $current_query = '';
788
+ $empty = true;
789
+ continue;
790
+ }
791
+
792
+ // If this is a non-empty character
793
+ if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
794
+ $empty = false;
795
+ }
796
+
797
+ $current_query .= $token[self::TOKEN_VALUE];
798
+ }
799
+
800
+ if (!$empty) {
801
+ $queries[] = trim($current_query);
802
+ }
803
+
804
+ return $queries;
805
+ }
806
+
807
+ /**
808
+ * Remove all comments from a SQL string
809
+ *
810
+ * @param String $string The SQL string
811
+ *
812
+ * @return String The SQL string without comments
813
+ */
814
+ public static function removeComments($string)
815
+ {
816
+ $result = '';
817
+
818
+ $tokens = self::tokenize($string);
819
+
820
+ foreach ($tokens as $token) {
821
+ // Skip comment tokens
822
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
823
+ continue;
824
+ }
825
+
826
+ $result .= $token[self::TOKEN_VALUE];
827
+ }
828
+ $result = self::format( $result,false);
829
+
830
+ return $result;
831
+ }
832
+
833
+ /**
834
+ * Compress a query by collapsing white space and removing comments
835
+ *
836
+ * @param String $string The SQL string
837
+ *
838
+ * @return String The SQL string without comments
839
+ */
840
+ public static function compress($string)
841
+ {
842
+ $result = '';
843
+
844
+ $tokens = self::tokenize($string);
845
+
846
+ $whitespace = true;
847
+ foreach ($tokens as $token) {
848
+ // Skip comment tokens
849
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
850
+ continue;
851
+ }
852
+ // Remove extra whitespace in reserved words (e.g "OUTER JOIN" becomes "OUTER JOIN")
853
+ elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
854
+ $token[self::TOKEN_VALUE] = preg_replace('/\s+/',' ',$token[self::TOKEN_VALUE]);
855
+ }
856
+
857
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
858
+ // If the last token was whitespace, don't add another one
859
+ if ($whitespace) {
860
+ continue;
861
+ } else {
862
+ $whitespace = true;
863
+ // Convert all whitespace to a single space
864
+ $token[self::TOKEN_VALUE] = ' ';
865
+ }
866
+ } else {
867
+ $whitespace = false;
868
+ }
869
+
870
+ $result .= $token[self::TOKEN_VALUE];
871
+ }
872
+
873
+ return rtrim($result);
874
+ }
875
+
876
+ /**
877
+ * Highlights a token depending on its type.
878
+ *
879
+ * @param Array $token An associative array containing type and value.
880
+ *
881
+ * @return String HTML code of the highlighted token.
882
+ */
883
+ protected static function highlightToken($token)
884
+ {
885
+ $type = $token[self::TOKEN_TYPE];
886
+
887
+ if (self::is_cli()) {
888
+ $token = $token[self::TOKEN_VALUE];
889
+ } else {
890
+ if (defined('ENT_IGNORE')) {
891
+ $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT | ENT_IGNORE ,'UTF-8');
892
+ } else {
893
+ $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8');
894
+ }
895
+ }
896
+
897
+ if ($type===self::TOKEN_TYPE_BOUNDARY) {
898
+ return self::highlightBoundary($token);
899
+ } elseif ($type===self::TOKEN_TYPE_WORD) {
900
+ return self::highlightWord($token);
901
+ } elseif ($type===self::TOKEN_TYPE_BACKTICK_QUOTE) {
902
+ return self::highlightBacktickQuote($token);
903
+ } elseif ($type===self::TOKEN_TYPE_QUOTE) {
904
+ return self::highlightQuote($token);
905
+ } elseif ($type===self::TOKEN_TYPE_RESERVED) {
906
+ return self::highlightReservedWord($token);
907
+ } elseif ($type===self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
908
+ return self::highlightReservedWord($token);
909
+ } elseif ($type===self::TOKEN_TYPE_RESERVED_NEWLINE) {
910
+ return self::highlightReservedWord($token);
911
+ } elseif ($type===self::TOKEN_TYPE_NUMBER) {
912
+ return self::highlightNumber($token);
913
+ } elseif ($type===self::TOKEN_TYPE_VARIABLE) {
914
+ return self::highlightVariable($token);
915
+ } elseif ($type===self::TOKEN_TYPE_COMMENT || $type===self::TOKEN_TYPE_BLOCK_COMMENT) {
916
+ return self::highlightComment($token);
917
+ }
918
+
919
+ return $token;
920
+ }
921
+
922
+ /**
923
+ * Highlights a quoted string
924
+ *
925
+ * @param String $value The token's value
926
+ *
927
+ * @return String HTML code of the highlighted token.
928
+ */
929
+ protected static function highlightQuote($value)
930
+ {
931
+ if (self::is_cli()) {
932
+ return self::$cli_quote . $value . "\x1b[0m";
933
+ } else {
934
+ return '<span ' . self::$quote_attributes . '>' . $value . '</span>';
935
+ }
936
+ }
937
+
938
+ /**
939
+ * Highlights a backtick quoted string
940
+ *
941
+ * @param String $value The token's value
942
+ *
943
+ * @return String HTML code of the highlighted token.
944
+ */
945
+ protected static function highlightBacktickQuote($value)
946
+ {
947
+ if (self::is_cli()) {
948
+ return self::$cli_backtick_quote . $value . "\x1b[0m";
949
+ } else {
950
+ return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>';
951
+ }
952
+ }
953
+
954
+ /**
955
+ * Highlights a reserved word
956
+ *
957
+ * @param String $value The token's value
958
+ *
959
+ * @return String HTML code of the highlighted token.
960
+ */
961
+ protected static function highlightReservedWord($value)
962
+ {
963
+ if (self::is_cli()) {
964
+ return self::$cli_reserved . $value . "\x1b[0m";
965
+ } else {
966
+ return '<span ' . self::$reserved_attributes . '>' . $value . '</span>';
967
+ }
968
+ }
969
+
970
+ /**
971
+ * Highlights a boundary token
972
+ *
973
+ * @param String $value The token's value
974
+ *
975
+ * @return String HTML code of the highlighted token.
976
+ */
977
+ protected static function highlightBoundary($value)
978
+ {
979
+ if ($value==='(' || $value===')') return $value;
980
+
981
+ if (self::is_cli()) {
982
+ return self::$cli_boundary . $value . "\x1b[0m";
983
+ } else {
984
+ return '<span ' . self::$boundary_attributes . '>' . $value . '</span>';
985
+ }
986
+ }
987
+
988
+ /**
989
+ * Highlights a number
990
+ *
991
+ * @param String $value The token's value
992
+ *
993
+ * @return String HTML code of the highlighted token.
994
+ */
995
+ protected static function highlightNumber($value)
996
+ {
997
+ if (self::is_cli()) {
998
+ return self::$cli_number . $value . "\x1b[0m";
999
+ } else {
1000
+ return '<span ' . self::$number_attributes . '>' . $value . '</span>';
1001
+ }
1002
+ }
1003
+
1004
+ /**
1005
+ * Highlights an error
1006
+ *
1007
+ * @param String $value The token's value
1008
+ *
1009
+ * @return String HTML code of the highlighted token.
1010
+ */
1011
+ protected static function highlightError($value)
1012
+ {
1013
+ if (self::is_cli()) {
1014
+ return self::$cli_error . $value . "\x1b[0m";
1015
+ } else {
1016
+ return '<span ' . self::$error_attributes . '>' . $value . '</span>';
1017
+ }
1018
+ }
1019
+
1020
+ /**
1021
+ * Highlights a comment
1022
+ *
1023
+ * @param String $value The token's value
1024
+ *
1025
+ * @return String HTML code of the highlighted token.
1026
+ */
1027
+ protected static function highlightComment($value)
1028
+ {
1029
+ if (self::is_cli()) {
1030
+ return self::$cli_comment . $value . "\x1b[0m";
1031
+ } else {
1032
+ return '<span ' . self::$comment_attributes . '>' . $value . '</span>';
1033
+ }
1034
+ }
1035
+
1036
+ /**
1037
+ * Highlights a word token
1038
+ *
1039
+ * @param String $value The token's value
1040
+ *
1041
+ * @return String HTML code of the highlighted token.
1042
+ */
1043
+ protected static function highlightWord($value)
1044
+ {
1045
+ if (self::is_cli()) {
1046
+ return self::$cli_word . $value . "\x1b[0m";
1047
+ } else {
1048
+ return '<span ' . self::$word_attributes . '>' . $value . '</span>';
1049
+ }
1050
+ }
1051
+
1052
+ /**
1053
+ * Highlights a variable token
1054
+ *
1055
+ * @param String $value The token's value
1056
+ *
1057
+ * @return String HTML code of the highlighted token.
1058
+ */
1059
+ protected static function highlightVariable($value)
1060
+ {
1061
+ if (self::is_cli()) {
1062
+ return self::$cli_variable . $value . "\x1b[0m";
1063
+ } else {
1064
+ return '<span ' . self::$variable_attributes . '>' . $value . '</span>';
1065
+ }
1066
+ }
1067
+
1068
+ /**
1069
+ * Helper function for building regular expressions for reserved words and boundary characters
1070
+ *
1071
+ * @param String $a The string to be quoted
1072
+ *
1073
+ * @return String The quoted string
1074
+ */
1075
+ private static function quote_regex($a)
1076
+ {
1077
+ return preg_quote($a,'/');
1078
+ }
1079
+
1080
+ /**
1081
+ * Helper function for building string output
1082
+ *
1083
+ * @param String $string The string to be quoted
1084
+ *
1085
+ * @return String The quoted string
1086
+ */
1087
+ private static function output($string)
1088
+ {
1089
+ if (self::is_cli()) {
1090
+ return $string."\n";
1091
+ } else {
1092
+ $string=trim($string);
1093
+ if (!self::$use_pre) {
1094
+ return $string;
1095
+ }
1096
+
1097
+ return '<pre '.self::$pre_attributes.'>' . $string . '</pre>';
1098
+ }
1099
+ }
1100
+
1101
+ private static function is_cli()
1102
+ {
1103
+ if (isset(self::$cli)) return self::$cli;
1104
+ else return php_sapi_name() === 'cli';
1105
+ }
1106
+
1107
+ }
app/code/community/Mzax/Emarketing/LICENSE ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Open Software License ("OSL") v. 3.0
3
+
4
+ This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
5
+
6
+ Licensed under the Open Software License version 3.0
7
+
8
+ 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
9
+
10
+ 1. to reproduce the Original Work in copies, either alone or as part of a collective work;
11
+
12
+ 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
13
+
14
+ 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
15
+
16
+ 4. to perform the Original Work publicly; and
17
+
18
+ 5. to display the Original Work publicly.
19
+
20
+ 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
21
+
22
+ 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
23
+
24
+ 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
25
+
26
+ 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
27
+
28
+ 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
29
+
30
+ 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
31
+
32
+ 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
33
+
34
+ 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
35
+
36
+ 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
37
+
38
+ 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
39
+
40
+ 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
41
+
42
+ 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
43
+
44
+ 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
45
+
46
+ 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
47
+
48
+ 16. Modification of This License. This License is Copyright � 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
app/code/community/Mzax/Emarketing/Model/Campaign.php ADDED
@@ -0,0 +1,1034 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Campaign
27
+ *
28
+ * @method Mzax_Emarketing_Model_Campaign setCreatedAt(string $value)
29
+ * @method Mzax_Emarketing_Model_Campaign setUpdatedAt(string $value)
30
+ * @method Mzax_Emarketing_Model_Campaign setStartAt(string $value)
31
+ * @method Mzax_Emarketing_Model_Campaign setEndAt(string $value)
32
+ * @method Mzax_Emarketing_Model_Campaign setRunning(string $value)
33
+ * @method Mzax_Emarketing_Model_Campaign setAutologin(string $value)
34
+ * @method Mzax_Emarketing_Model_Campaign setCheckFrequency(string $value)
35
+ * @method Mzax_Emarketing_Model_Campaign setLastCheck(string $value)
36
+ * @method Mzax_Emarketing_Model_Campaign setMinResendInterval(string $value)
37
+ * @method Mzax_Emarketing_Model_Campaign setAbtestEnable(string $value)
38
+ * @method Mzax_Emarketing_Model_Campaign setAbtestTraffic(string $value)
39
+ * @method Mzax_Emarketing_Model_Campaign setStoreId(string $value)
40
+ * @method Mzax_Emarketing_Model_Campaign setTemplateId(string $value)
41
+ * @method Mzax_Emarketing_Model_Campaign setDefaultTrackerId(string $value)
42
+ * @method Mzax_Emarketing_Model_Campaign setName(string $value)
43
+ * @method Mzax_Emarketing_Model_Campaign setIdentity(string $value)
44
+ * @method Mzax_Emarketing_Model_Campaign setProvider(string $value)
45
+ * @method Mzax_Emarketing_Model_Campaign setFilterData(string $value)
46
+ * @method Mzax_Emarketing_Model_Campaign setMediumJson(string $value)
47
+ *
48
+ * @method Mzax_Emarketing_Model_Resource_Campaign getResource()
49
+ *
50
+ * @method string getCreatedAt()
51
+ * @method string getUpdatedAt()
52
+ * @method string getStartAt()
53
+ * @method string getEndAt()
54
+ * @method string getRunning()
55
+ * @method string getAutologin()
56
+ * @method string getCheckFrequency()
57
+ * @method string getLastCheck()
58
+ * @method string getMinResendInterval()
59
+ * @method string getAbtestEnable()
60
+ * @method string getAbtestTraffic()
61
+ * @method string getStoreId()
62
+ * @method string getTemplateId()
63
+ * @method string getDefaultTrackerId()
64
+ * @method string getName()
65
+ * @method string getIdentity()
66
+ * @method string getProvider()
67
+ * @method string getFilterData()
68
+ * @method string getMediumJson()
69
+ * @method string getSendingStats()
70
+ * @method string getInteractionStats()
71
+ * @method string getConversionStats()
72
+ * @method string getFailStats()
73
+ * @method string getRevenueStats()
74
+ *
75
+ *
76
+ * @author Jacob Siefer
77
+ *
78
+ */
79
+ class Mzax_Emarketing_Model_Campaign
80
+ extends Mage_Core_Model_Abstract
81
+ implements Mzax_Emarketing_Model_Campaign_Content
82
+ {
83
+
84
+
85
+
86
+ const DEFAULT_EMAIL_PROVIDER = 'customers';
87
+
88
+
89
+ const CACHE_TAG = 'MZAX_EMARKETING_CAMPAIGN';
90
+
91
+
92
+ //protected $_cacheTag = self::CACHE_TAG;
93
+
94
+
95
+ /**
96
+ * Recipient provider
97
+ *
98
+ * @var Mzax_Emarketing_Model_Recipient_Provider_Abstract
99
+ */
100
+ protected $_provider;
101
+
102
+
103
+
104
+ /**
105
+ * Medium provider
106
+ *
107
+ * @var Mzax_Emarketing_Model_Medium_Abstract
108
+ */
109
+ protected $_medium;
110
+
111
+
112
+ /**
113
+ *
114
+ * @var Varien_Object
115
+ */
116
+ protected $_mediumData;
117
+
118
+
119
+ /**
120
+ * Available variations
121
+ *
122
+ * @var Mzax_Emarketing_Model_Resource_Campaign_Variation_Collection
123
+ */
124
+ protected $_variations;
125
+
126
+
127
+ /**
128
+ * Prefix of model events names
129
+ *
130
+ * @var string
131
+ */
132
+ protected $_eventPrefix = 'mzax_emarketing_campaign';
133
+
134
+ /**
135
+ * Parameter name in event
136
+ *
137
+ * In observe method you can use $observer->getEvent()->getObject() in this case
138
+ *
139
+ * @var string
140
+ */
141
+ protected $_eventObject = 'campaign';
142
+
143
+
144
+
145
+ /**
146
+ *
147
+ * @var Mzax_Emarketing_Model_Resource_Recipient_Collection
148
+ */
149
+ protected $_recipients;
150
+
151
+
152
+
153
+ /**
154
+ *
155
+ * @var Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection
156
+ */
157
+ protected $_trackers;
158
+
159
+
160
+ /**
161
+ *
162
+ * @var Mzax_Emarketing_Model_Conversion_Tracker
163
+ */
164
+ protected $_defaultTracker;
165
+
166
+
167
+
168
+ /**
169
+ * Store url model
170
+ *
171
+ * @var Mage_Core_Model_Url
172
+ */
173
+ protected $_urlModel;
174
+
175
+
176
+
177
+
178
+
179
+ protected function _construct()
180
+ {
181
+ $this->_init('mzax_emarketing/campaign');
182
+ }
183
+
184
+
185
+
186
+
187
+
188
+ /**
189
+ *
190
+ * @return string
191
+ */
192
+ public function getContentCacheId()
193
+ {
194
+ return $this->_eventObject . '_' . $this->getId();
195
+ }
196
+
197
+
198
+
199
+
200
+ protected function _beforeSave()
201
+ {
202
+
203
+ parent::_beforeSave();
204
+
205
+ if($this->_mediumData) {
206
+ $this->setData('medium_json', $this->_mediumData->toJson());
207
+ }
208
+
209
+ if($this->_provider) {
210
+ $this->setProvider($this->_provider->getType());
211
+ $this->setFilterData($this->_provider->getFilter()->asJson());
212
+ }
213
+
214
+ if(!$this->getData('medium')) {
215
+ throw new Exception("Campaign must define a medium");
216
+ }
217
+ if(!$this->getData('provider')) {
218
+ throw new Exception("Campaign must define a recipient provider");
219
+ }
220
+
221
+ }
222
+
223
+
224
+
225
+ protected function _afterSave()
226
+ {
227
+ parent::_afterSave();
228
+
229
+ // save all variations if loaded
230
+ if( $this->_variations ) {
231
+ $this->_variations->save();
232
+ }
233
+ }
234
+
235
+
236
+ /**
237
+ * Processing object after load data
238
+ *
239
+ * @return Mage_Core_Model_Abstract
240
+ */
241
+ protected function _afterLoad()
242
+ {
243
+ if($filters = $this->getData('filters')) {
244
+ $this->setFilters($filters);
245
+ }
246
+ }
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+ /**
255
+ * Retrieve store object
256
+ *
257
+ * @return Mage_Core_Model_Store
258
+ */
259
+ public function getStore()
260
+ {
261
+ return Mage::app()->getStore($this->getStoreId());
262
+ }
263
+
264
+
265
+
266
+ /**
267
+ * Retrieve URL model
268
+ *
269
+ * @return Mage_Core_Model_Url
270
+ */
271
+ public function getUrlModel()
272
+ {
273
+ if(!$this->_urlModel) {
274
+ $this->_urlModel = Mage::getModel('core/url')->setStore($this->getStore());
275
+ }
276
+ return $this->_urlModel;
277
+ }
278
+
279
+
280
+
281
+
282
+
283
+ /**
284
+ * Is campaign archived
285
+ *
286
+ * @return boolean
287
+ */
288
+ public function isArchived($flag = null)
289
+ {
290
+ if(is_bool($flag)) {
291
+ $this->setData('archived', $flag ? 1 : 0);
292
+ }
293
+ return (boolean) $this->getData('archived');
294
+ }
295
+
296
+
297
+
298
+
299
+ /**
300
+ * Is campaign currently running
301
+ *
302
+ * @return boolean
303
+ */
304
+ public function isRunning($flag = null)
305
+ {
306
+ if(is_bool($flag)) {
307
+ $this->setData('running', $flag ? 1 : 0);
308
+ }
309
+ return (boolean) $this->getData('running');
310
+ }
311
+
312
+
313
+
314
+
315
+ public function start()
316
+ {
317
+ $this->isRunning(true);
318
+ return $this;
319
+ }
320
+
321
+
322
+ /**
323
+ * Will not just stop but also remove any
324
+ * already queued recipients
325
+ *
326
+ * @return Mzax_Emarketing_Model_Campaign
327
+ */
328
+ public function stop()
329
+ {
330
+ $this->isRunning(false);
331
+
332
+ /* @see Mzax_Emarketing_Model_Resource_Recipient */
333
+ Mage::getResourceSingleton('mzax_emarketing/recipient')->removePending($this->getId());
334
+
335
+ return $this;
336
+ }
337
+
338
+
339
+
340
+
341
+ /**
342
+ * check if the campaign is valid for sending
343
+ *
344
+ * @deprecated
345
+ * @return boolean
346
+ */
347
+ public function isValidForSend()
348
+ {
349
+ return true;
350
+ }
351
+
352
+
353
+
354
+ /**
355
+ * Is a plain text email campaign
356
+ *
357
+ * @deprecated
358
+ * @return boolean
359
+ */
360
+ public function isPlain()
361
+ {
362
+ return false;
363
+ }
364
+
365
+
366
+
367
+
368
+ //--------------------------------------------------------------------------
369
+ //
370
+ // Medium
371
+ //
372
+ //--------------------------------------------------------------------------
373
+
374
+
375
+
376
+
377
+ /**
378
+ * Retrieve medium
379
+ *
380
+ * @return Mzax_Emarketing_Model_Medium_Abstract
381
+ */
382
+ public function getMedium()
383
+ {
384
+ if(!$this->_medium && $this->getData('medium')) {
385
+ $this->_medium = Mage::getSingleton('mzax_emarketing/medium')->factory($this->getData('medium'));
386
+ }
387
+ return $this->_medium;
388
+ }
389
+
390
+
391
+
392
+
393
+ /**
394
+ * Retrieve content data
395
+ *
396
+ * @return Varien_Object
397
+ */
398
+ public function getMediumData()
399
+ {
400
+ if(!$this->_mediumData) {
401
+ if($data = $this->getMediumJson()) {
402
+ $data = Zend_Json::decode($data);
403
+ $this->_mediumData = new Varien_Object($data);
404
+ }
405
+ else {
406
+ $this->_mediumData = new Varien_Object;
407
+ }
408
+ $this->setDataChanges(true);
409
+ }
410
+ return $this->_mediumData;
411
+ }
412
+
413
+
414
+
415
+
416
+ //--------------------------------------------------------------------------
417
+ //
418
+ // Provider
419
+ //
420
+ //--------------------------------------------------------------------------
421
+
422
+
423
+
424
+ /**
425
+ * Retrieve all available recipient provider options
426
+ *
427
+ * @return array
428
+ */
429
+ public function getAvailableProviders()
430
+ {
431
+ return self::getProviderFactory()->getAllOptions(false);
432
+ }
433
+
434
+
435
+
436
+
437
+ /**
438
+ * Retrieve recipient provider for this campaign
439
+ *
440
+ * @return Mzax_Emarketing_Model_Recipient_Provider_Abstract
441
+ */
442
+ public function getRecipientProvider()
443
+ {
444
+ if(!$this->_provider && $this->getData('provider')) {
445
+ $type = $this->getData('provider');
446
+ $this->_provider = self::getProviderFactory()
447
+ ->factory($this->getData('provider'))
448
+ ->setCampaign($this);
449
+ }
450
+ return $this->_provider;
451
+ }
452
+
453
+
454
+
455
+
456
+ /**
457
+ * Retrieve provider factory
458
+ *
459
+ * @return Mzax_Emarketing_Model_Recipient_Provider
460
+ */
461
+ public static function getProviderFactory()
462
+ {
463
+ return Mage::getSingleton('mzax_emarketing/recipient_provider');
464
+ }
465
+
466
+
467
+
468
+
469
+
470
+ /**
471
+ * Retrieve filter by id
472
+ *
473
+ * @param string $id e.g. 1-1-2-3-1-2
474
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
475
+ */
476
+ public function getFilterById($id)
477
+ {
478
+ return $this->getRecipientProvider()->getFilterById($id);
479
+ }
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+ //--------------------------------------------------------------------------
489
+ //
490
+ // Email
491
+ //
492
+ //--------------------------------------------------------------------------
493
+
494
+
495
+
496
+
497
+ /**
498
+ * Retrieve magento email sender
499
+ *
500
+ * @return array
501
+ */
502
+ public function getSender()
503
+ {
504
+ $sender = $this->getData('sender');
505
+ if(empty($sender)) {
506
+ $sender = $this->getIdentity();
507
+ }
508
+
509
+ if (!is_array($sender)) {
510
+ $sender = array(
511
+ 'name' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/name', $this->getStore()),
512
+ 'email' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/email', $this->getStore()),
513
+ );
514
+ }
515
+ $this->setSender($sender);
516
+ return $sender;
517
+ }
518
+
519
+
520
+
521
+
522
+
523
+
524
+ /**
525
+ * Create a mock recipient instance
526
+ *
527
+ * @param string $entityId Target entity id
528
+ * @return Mzax_Emarketing_Model_Recipient
529
+ */
530
+ public function createMockRecipient($objectId = null)
531
+ {
532
+ /* @var $recipient Mzax_Emarketing_Model_Recipient */
533
+ $recipient = Mage::getModel('mzax_emarketing/recipient');
534
+ $recipient->setCampaign($this);
535
+ $recipient->setObjectId($objectId);
536
+ $recipient->isMock(true);
537
+
538
+ return $recipient;
539
+ }
540
+
541
+
542
+
543
+
544
+ /**
545
+ * Prepare recipient
546
+ *
547
+ * before we send out an email and prepare the template
548
+ * we will give the email provider and the filters a chance to prepare the recipient
549
+ * to add any data usefull information
550
+ *
551
+ * @param Mzax_Emarketing_Model_Recipient $recipient
552
+ * @return Mzax_Emarketing_Model_Campaign
553
+ */
554
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
555
+ {
556
+ $this->getRecipientProvider()->prepareRecipient($recipient);
557
+ $this->getMedium()->prepareRecipient($recipient);
558
+ return $this;
559
+ }
560
+
561
+
562
+
563
+
564
+ /**
565
+ * Retrieve campaign content
566
+ *
567
+ * If ab-testing is enabled we need to retrieve
568
+ * a random variation
569
+ *
570
+ * @return Mzax_Emarketing_Model_Campaign_Content
571
+ */
572
+ public function getContent($variationId = null)
573
+ {
574
+ if($variationId !== null) {
575
+ // if zero, use orginal campaign
576
+ if($variationId == Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL) {
577
+ return $this;
578
+ }
579
+
580
+ $variation = $this->getVariation($variationId);
581
+ if(!$variation) {
582
+ return $this;
583
+ }
584
+ return $variation;
585
+ }
586
+
587
+ $this->setVariationId(Mzax_Emarketing_Model_Campaign_Variation::NONE);
588
+
589
+ // check if ab-testing is enabled
590
+ if(!$this->getAbtestEnable() && $this->getAbtestTraffic() > 0) {
591
+ return $this;
592
+ }
593
+
594
+ // include include in test?
595
+ if(mt_rand(0,999)/10 >= $this->getAbtestTraffic()) {
596
+ return $this;
597
+ }
598
+
599
+ $this->setVariationId(Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL);
600
+ $active = array($this);
601
+
602
+ /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
603
+ foreach($this->getVariations() as $variation) {
604
+ if($variation->getIsActive()) {
605
+ $active[] = $variation;
606
+ }
607
+ }
608
+
609
+ // pick randrom content
610
+ return $active[array_rand($active)];
611
+ }
612
+
613
+
614
+
615
+
616
+
617
+ /**
618
+ * Retrieve available snippets for the content manager
619
+ *
620
+ * @return Mzax_Emarketing_Model_Medium_Email_Snippets
621
+ */
622
+ public function getSnippets()
623
+ {
624
+ /* @var $snippets Mzax_Emarketing_Model_Medium_Email_Snippets */
625
+ $snippets = Mage::getModel('mzax_emarketing/medium_email_snippets');
626
+
627
+ if($this->getRecipientProvider()) {
628
+ $this->getRecipientProvider()->prepareSnippets($snippets);
629
+ }
630
+ if($this->getMedium()) {
631
+ $this->getMedium()->prepareSnippets($snippets);
632
+ }
633
+ $this->getMedium()->prepareSnippets($snippets);
634
+
635
+ return $snippets;
636
+ }
637
+
638
+
639
+
640
+
641
+ //--------------------------------------------------------------------------
642
+ //
643
+ // Variations
644
+ //
645
+ //--------------------------------------------------------------------------
646
+
647
+
648
+
649
+ /**
650
+ * Check if campagin has any variations
651
+ *
652
+ * @return int
653
+ */
654
+ public function hasVariations()
655
+ {
656
+ return count($this->getVariations());
657
+ }
658
+
659
+
660
+
661
+
662
+
663
+
664
+ /**
665
+ * Retrieve all variations
666
+ *
667
+ * @return Mzax_Emarketing_Model_Resource_Campaign_Variation_Collection
668
+ */
669
+ public function getVariations()
670
+ {
671
+ if(!$this->_variations) {
672
+ $this->_variations = Mage::getResourceModel('mzax_emarketing/campaign_variation_collection');
673
+ $this->_variations->addCampaignFilter($this);
674
+ }
675
+ return $this->_variations;
676
+ }
677
+
678
+
679
+
680
+
681
+
682
+ /**
683
+ * Retrieve variation by id
684
+ *
685
+ * @param string $id
686
+ * @return Mzax_Emarketing_Model_Campaign_Variation
687
+ */
688
+ public function getVariation($id)
689
+ {
690
+ return $this->getVariations()->getItemById($id);
691
+ }
692
+
693
+
694
+
695
+
696
+ /**
697
+ * Create new variation
698
+ *
699
+ * @param bool $save
700
+ * @return Mzax_Emarketing_Model_Campaign_Variation
701
+ */
702
+ public function createVariation()
703
+ {
704
+ $variations = $this->getVariations();
705
+
706
+ /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
707
+ $variation = Mage::getModel('mzax_emarketing/campaign_variation');
708
+ $variation->setCampaign($this);
709
+ $variation->setName('Variation ' . (count($variations)+1));
710
+ $variation->setMediumJson($this->getMediumJson());
711
+
712
+ return $variation;
713
+ }
714
+
715
+
716
+ //--------------------------------------------------------------------------
717
+ //
718
+ // Trackers
719
+ //
720
+ //--------------------------------------------------------------------------
721
+
722
+
723
+
724
+
725
+ /**
726
+ * Retrieve all conversion trackers
727
+ *
728
+ * @return Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection
729
+ */
730
+ public function getTrackers()
731
+ {
732
+ if(!$this->_trackers) {
733
+ $this->_trackers = Mage::getResourceModel('mzax_emarketing/conversion_tracker_collection');
734
+ $this->_trackers->addCampaignFilter($this);
735
+ $this->_trackers->addActiveFilter();
736
+ }
737
+ return $this->_trackers;
738
+ }
739
+
740
+
741
+ /**
742
+ * Retrieve tracker by id
743
+ *
744
+ * @param string $id
745
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
746
+ */
747
+ public function getTracker($id)
748
+ {
749
+ return $this->getTrackers()->getItemById($id);
750
+ }
751
+
752
+
753
+
754
+ /**
755
+ * Retrieve default tracker for this campaign
756
+ *
757
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
758
+ */
759
+ public function getDefaultTracker()
760
+ {
761
+ if(!$this->_defaultTracker) {
762
+ $tracker = $this->getTracker($this->getDefaultTrackerId());
763
+ if(!$tracker) {
764
+ foreach($this->getTrackers() as $tracker) {
765
+ if($tracker->isDefault()) {
766
+ break;
767
+ }
768
+ }
769
+ }
770
+ $this->_defaultTracker = $tracker;
771
+ }
772
+ return $this->_defaultTracker;
773
+ }
774
+
775
+
776
+
777
+
778
+
779
+ //--------------------------------------------------------------------------
780
+ //
781
+ // Recipients
782
+ //
783
+ //--------------------------------------------------------------------------
784
+
785
+
786
+ /**
787
+ * Try to bind recipients to goals
788
+ *
789
+ * The recipient provider has to do that
790
+ *
791
+ * @param Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder
792
+ * @return Mzax_Emarketing_Model_Campaign
793
+ */
794
+ public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
795
+ {
796
+ if($provider = $this->getRecipientProvider()) {
797
+ $provider->bindRecipients($binder);
798
+ }
799
+ return $this;
800
+ }
801
+
802
+
803
+
804
+
805
+ /**
806
+ * Find and queue new recipients for this campaign that
807
+ * match the current filters
808
+ *
809
+ * @return integer the number of recipients found
810
+ */
811
+ public function findRecipients($force = false)
812
+ {
813
+ if($force || $this->getRunning()) {
814
+ $this->setCurrentTime(null);
815
+ return $this->getResource()->findRecipients($this);
816
+ }
817
+ return 0;
818
+ }
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+ /**
827
+ * Retrieve all recipients for this campaign
828
+ *
829
+ * @return Mzax_Emarketing_Model_Resource_Recipient_Collection
830
+ */
831
+ public function getRecipients()
832
+ {
833
+ if($this->_recipients) {
834
+ $this->_recipients = Mage::getResourceModel('mzax_emarketing/recipient_collection');
835
+ $this->_recipients->setCampaign($this);
836
+ }
837
+ return $this->_recipients;
838
+ }
839
+
840
+
841
+
842
+
843
+
844
+ /**
845
+ * Retrieve all recipients that have not yet been send
846
+ *
847
+ * @return Mzax_Emarketing_Model_Resource_Recipient_Collection
848
+ */
849
+ public function getPendingRecipients()
850
+ {
851
+ /* @var $recipients Mzax_Emarketing_Model_Resource_Recipient_Collection */
852
+ $recipients = Mage::getResourceModel('mzax_emarketing/recipient_collection');
853
+ $recipients->setCampaign($this);
854
+ $recipients->addPrepareFilter(false);
855
+
856
+ return $recipients;
857
+ }
858
+
859
+
860
+
861
+
862
+ /**
863
+ * Prepare pending recipients and move them to
864
+ * the email outbox
865
+ * This will render all emails and makes them ready
866
+ * to get send
867
+ *
868
+ * @see Mzax_Emarketing_Model_Outbox
869
+ * @return integer Number of prepared recipients
870
+ */
871
+ public function sendRecipients($options = array())
872
+ {
873
+ $options = new Varien_Object($options);
874
+ $options->getDataSetDefault('timeout', 300);
875
+ $options->getDataSetDefault('maximum', 500);
876
+ $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
877
+
878
+ if($this->getId() && $this->getRecipientProvider() && $this->getMedium()) {
879
+ return $this->getMedium()->sendRecipients($this, $options);
880
+ }
881
+ return 0;
882
+ }
883
+
884
+
885
+
886
+
887
+
888
+ /**
889
+ * Retrieve number of recipient errors
890
+ *
891
+ * @return integer
892
+ */
893
+ public function countRecipientErrors()
894
+ {
895
+ $count = $this->getData('recipient_errors_count');
896
+ if($count === null) {
897
+ $count = $this->getResource()->countRecipientErrors($this);
898
+ $this->setData('recipient_errors_count', $count);
899
+ }
900
+ return $count;
901
+ }
902
+
903
+
904
+
905
+
906
+ //--------------------------------------------------------------------------
907
+ //
908
+ // Inbox/Outbox
909
+ //
910
+ //--------------------------------------------------------------------------
911
+
912
+ /**
913
+ * Check number of messages in inbox
914
+ *
915
+ * @return integer
916
+ */
917
+ public function countInbox()
918
+ {
919
+ $count = $this->getData('inbox_count');
920
+ if($count === null) {
921
+ $count = $this->getResource()->countInbox($this);
922
+ $this->setData('inbox_count', $count);
923
+ }
924
+ return $count;
925
+ }
926
+
927
+
928
+
929
+ /**
930
+ * Check number of messages in outbox
931
+ *
932
+ * @return integer
933
+ */
934
+ public function countOutbox()
935
+ {
936
+ $count = $this->getData('outbox_count');
937
+ if($count === null) {
938
+ $count = $this->getResource()->countOutbox($this);
939
+ $this->setData('outbox_count', $count);
940
+ }
941
+ return $count;
942
+ }
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+ //--------------------------------------------------------------------------
951
+ //
952
+ // Report
953
+ //
954
+ //--------------------------------------------------------------------------
955
+
956
+
957
+
958
+ /**
959
+ * Aggregate data for this campaign
960
+ *
961
+ * @param integer $incremental
962
+ * @return Mzax_Emarketing_Model_Campaign
963
+ */
964
+ public function aggregate($incremental = null)
965
+ {
966
+ $options = new Varien_Object(array(
967
+ 'campaign_id' => $this->getId(),
968
+ 'verbose' => false
969
+ ));
970
+
971
+ Mage::dispatchEvent($this->_eventPrefix . '_aggregate',
972
+ array('options' => $options, 'campaign' => $this));
973
+
974
+ if($incremental) {
975
+ $options->setIncremental((int) $incremental);
976
+ }
977
+
978
+ /* @var $report Mzax_Emarketing_Model_Report */
979
+ $report = Mage::getSingleton('mzax_emarketing/report');
980
+ $report->aggregate($options->toArray());
981
+
982
+ return $this;
983
+ }
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+ /**
992
+ * Retrieve a new report query instance
993
+ *
994
+ * @param string $dimension
995
+ * @param array $metrics
996
+ * @param boolean $variation
997
+ * @return Mzax_Emarketing_Model_Report_Query
998
+ */
999
+ public function queryReport($dimension = 'campaign', $metrics = array('sendings', 'views', 'clicks'), $variations = false, $order = null)
1000
+ {
1001
+ $metrics = (array) $metrics;
1002
+
1003
+ // replace default tracker id
1004
+ foreach($metrics as $key => $metric) {
1005
+ if( strpos($metric,'#?') !== false) {
1006
+ if($tracker = $this->getDefaultTracker()) {
1007
+ $metrics[$key] = str_replace('#?', '#' . $tracker->getId(), $metric);
1008
+ }
1009
+ else {
1010
+ unset($metrics[$key]);
1011
+ }
1012
+ }
1013
+ if($metric instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
1014
+ $metrics[$key] = '#' . $metric->getId();
1015
+ }
1016
+ }
1017
+
1018
+ /* @var $query Mzax_Emarketing_Model_Report_Query */
1019
+ $query = Mage::getModel('mzax_emarketing/report_query');
1020
+ $query->setParam('campaign', $this->getId());
1021
+ $query->setParam('dimension', $dimension);
1022
+ $query->setParam('metrics', $metrics);
1023
+ $query->setParam('variations', $variations);
1024
+ $query->setParam('order', $order);
1025
+
1026
+
1027
+ return $query;
1028
+ }
1029
+
1030
+
1031
+
1032
+
1033
+
1034
+ }
app/code/community/Mzax/Emarketing/Model/Campaign/Content.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ * @author Jacob Siefer
28
+ *
29
+ */
30
+ interface Mzax_Emarketing_Model_Campaign_Content
31
+ {
32
+
33
+
34
+ public function getContentCacheId();
35
+
36
+
37
+ /**
38
+ * Retrieve content data
39
+ *
40
+ * @return Varien_Object
41
+ */
42
+ public function getMediumData();
43
+
44
+
45
+
46
+ }
app/code/community/Mzax/Emarketing/Model/Campaign/Variation.php ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @method string getCreatedAt()
26
+ * @method string getUpdatedAt()
27
+ * @method string getName()
28
+ * @method string getIsActive()
29
+ * @method string getIsRemoved()
30
+ * @method string getMediumJson()
31
+ *
32
+ * @method Mzax_Emarketing_Model_Campaign_Variation setCreatedAt()
33
+ * @method Mzax_Emarketing_Model_Campaign_Variation setUpdatedAt()
34
+ * @method Mzax_Emarketing_Model_Campaign_Variation setName()
35
+ * @method Mzax_Emarketing_Model_Campaign_Variation setIsActive()
36
+ * @method Mzax_Emarketing_Model_Campaign_Variation setIsRemoved()
37
+ * @method Mzax_Emarketing_Model_Campaign_Variation setMediumJson()
38
+ *
39
+ *
40
+ *
41
+ * @author Jacob Siefer
42
+ *
43
+ */
44
+ class Mzax_Emarketing_Model_Campaign_Variation
45
+ extends Mage_Core_Model_Abstract
46
+ implements Mzax_Emarketing_Model_Campaign_Content
47
+ {
48
+
49
+
50
+
51
+
52
+ const ORIGNAL = 0;
53
+ const NONE = -1;
54
+
55
+ /**
56
+ * Prefix of model events names
57
+ *
58
+ * @var string
59
+ */
60
+ protected $_eventPrefix = 'mzax_emarketing_campaign_variation';
61
+
62
+ /**
63
+ * Parameter name in event
64
+ *
65
+ * In observe method you can use $observer->getEvent()->getObject() in this case
66
+ *
67
+ * @var string
68
+ */
69
+ protected $_eventObject = 'variation';
70
+
71
+
72
+
73
+ /**
74
+ *
75
+ * @var Mzax_Emarketing_Model_Campaign
76
+ */
77
+ protected $_campaign;
78
+
79
+
80
+ /**
81
+ *
82
+ * @var Varien_Object
83
+ */
84
+ protected $_mediumData;
85
+
86
+
87
+
88
+
89
+ protected function _construct()
90
+ {
91
+ $this->_init('mzax_emarketing/campaign_variation');
92
+ }
93
+
94
+
95
+ /**
96
+ *
97
+ * @return string
98
+ */
99
+ public function getContentCacheId()
100
+ {
101
+ return $this->_eventObject . '_' . $this->getId();
102
+ }
103
+
104
+
105
+
106
+
107
+ protected function _beforeSave()
108
+ {
109
+ if($this->_mediumData) {
110
+ $this->setData('medium_json', $this->_mediumData->toJson());
111
+ }
112
+
113
+ parent::_beforeSave();
114
+ }
115
+
116
+
117
+
118
+
119
+ /**
120
+ * set campaign id
121
+ *
122
+ * @param string|integer $campaignId
123
+ * @return Mzax_Emarketing_Model_Campaign_Variation
124
+ */
125
+ public function setCampaignId($campaignId)
126
+ {
127
+ if($this->_campaign && $this->_campaign->getId() != $campaignId) {
128
+ $this->_campaign = null;
129
+ }
130
+
131
+ $this->setData('campaign_id', $campaignId);
132
+ return $this;
133
+ }
134
+
135
+
136
+
137
+
138
+ /**
139
+ * set campaign
140
+ *
141
+ * @param Varien_Object $campaign
142
+ * @return Mzax_Emarketing_Model_Campaign_Variation
143
+ */
144
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
145
+ {
146
+ $this->setCampaignId($campaign->getId());
147
+ $this->_campaign = $campaign;
148
+
149
+ return $this;
150
+ }
151
+
152
+
153
+
154
+
155
+ /**
156
+ *
157
+ *
158
+ * @return Mzax_Emarketing_Model_Campaign
159
+ */
160
+ public function getCampaign()
161
+ {
162
+ return $this->_campaign;
163
+ }
164
+
165
+
166
+
167
+
168
+ /**
169
+ * Is variation removed
170
+ *
171
+ * For statistical reference, variations should not get deleted
172
+ *
173
+ * @param string $flag
174
+ * @return boolean
175
+ */
176
+ public function isRemoved($flag = null)
177
+ {
178
+ if(is_bool($flag)) {
179
+ $this->setIsRemoved((int) $flag);
180
+ }
181
+ return (bool) $this->getIsRemoved();
182
+ }
183
+
184
+
185
+
186
+ /**
187
+ * Is variation active
188
+ *
189
+ * @param string $flag
190
+ * @return boolean
191
+ */
192
+ public function isActive($flag = null)
193
+ {
194
+ if(is_bool($flag)) {
195
+ $this->setIsActive((int) $flag);
196
+ }
197
+ return (bool) $this->getIsActive();
198
+ }
199
+
200
+
201
+
202
+
203
+
204
+
205
+ /**
206
+ * Retrieve content data
207
+ *
208
+ * @return Varien_Object
209
+ */
210
+ public function getMediumData()
211
+ {
212
+ if(!$this->_mediumData) {
213
+ if( $json = $this->getMediumJson() ) {
214
+ $json = Zend_Json::decode($json);
215
+ $this->_mediumData = new Varien_Object($json);
216
+ }
217
+ else {
218
+ $this->_mediumData = new Varien_Object;
219
+ }
220
+ }
221
+ return $this->_mediumData;
222
+ }
223
+
224
+
225
+
226
+
227
+ }
app/code/community/Mzax/Emarketing/Model/Conversion/Goal.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Conversion_Goal implements Mage_Eav_Model_Entity_Attribute_Source_Interface
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var Mage_Core_Model_Config_Element
30
+ */
31
+ protected $_config;
32
+
33
+
34
+
35
+ /**
36
+ *
37
+ * @var array
38
+ */
39
+ protected $_goals;
40
+
41
+
42
+ /**
43
+ *
44
+ * @param string $name
45
+ * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
46
+ */
47
+ public function factory($name)
48
+ {
49
+ $config = $this->getConfig();
50
+ if(!isset($config->$name)) {
51
+ return null;
52
+ }
53
+ $config = $config->$name;
54
+ $class = $config->getClassName();
55
+
56
+ $instance = new $class($config);
57
+
58
+ return $instance;
59
+ }
60
+
61
+
62
+
63
+
64
+
65
+
66
+ /**
67
+ * Retrieve All options
68
+ *
69
+ * @return array
70
+ */
71
+ public function getAllOptions($withEmpty = true, $defaultValues = false)
72
+ {
73
+ $options = array();
74
+
75
+ /* @var $goal Mzax_Emarketing_Model_Conversion_Goal_Abstract */
76
+ foreach($this->getGoals() as $name => $goal) {
77
+ $options[] = array(
78
+ 'value' => $name,
79
+ 'label' => $goal->getTitle()
80
+ );
81
+ }
82
+ if ($withEmpty) {
83
+ array_unshift($options, array('label'=>'', 'value'=>''));
84
+ }
85
+
86
+ return $options;
87
+ }
88
+
89
+
90
+
91
+
92
+
93
+
94
+ /**
95
+ * Retrieve all conversion goals
96
+ *
97
+ * @return array
98
+ */
99
+ public function getGoals()
100
+ {
101
+ if(!$this->_goals) {
102
+ $this->_goals = array();
103
+
104
+ foreach($this->getConfig()->children() as $name => $cfg) {
105
+ $this->_goals[$name] = self::factory($name);
106
+ }
107
+ }
108
+ return $this->_goals;
109
+ }
110
+
111
+
112
+
113
+
114
+
115
+ /**
116
+ * Retrieve Option value text
117
+ *
118
+ * @param string $value
119
+ * @return mixed
120
+ */
121
+ public function getOptionText($value)
122
+ {
123
+ $options = $this->getFilters();
124
+ if(isset($options[$value])) {
125
+ return $options[$value]->getTitle();
126
+ }
127
+ return false;
128
+ }
129
+
130
+
131
+
132
+ /**
133
+ * Retrieve config
134
+ *
135
+ * @return Mage_Core_Model_Config_Element
136
+ */
137
+ public function getConfig()
138
+ {
139
+ if(!$this->_config) {
140
+ $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/goal_types');
141
+ }
142
+ return $this->_config;
143
+ }
144
+
145
+
146
+
147
+ }
app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Abstract.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ abstract class Mzax_Emarketing_Model_Conversion_Goal_Abstract
26
+ extends Mzax_Emarketing_Model_Object_Filter_Main
27
+ {
28
+
29
+ protected $_type;
30
+
31
+
32
+ /**
33
+ *
34
+ * @var Mzax_Emarketing_Model_Conversion_Tracker
35
+ */
36
+ protected $_tracker;
37
+
38
+
39
+
40
+ abstract public function getAggregationSelect($campaign);
41
+
42
+
43
+ /**
44
+ * Set default filters when newly created
45
+ *
46
+ * @return void
47
+ */
48
+ public function setDefaultFilters()
49
+ {}
50
+
51
+
52
+ public function __construct($config)
53
+ {
54
+ parent::__construct();
55
+
56
+ if($config instanceof Mage_Core_Model_Config_Element) {
57
+ $this->_setup($config);
58
+ }
59
+ }
60
+
61
+
62
+ protected function _setup(Mage_Core_Model_Config_Element $config)
63
+ {
64
+ $this->_type = $config->getName();
65
+
66
+ Mage::dispatchEvent("mzax_emarketing_conversion_goal_setup", array('goal' => $this));
67
+ Mage::dispatchEvent("mzax_emarketing_conversion_goal_setup_" . $this->_type, array('goal' => $this));
68
+ }
69
+
70
+
71
+ public function getType()
72
+ {
73
+ return $this->_type;
74
+ }
75
+
76
+
77
+
78
+ /**
79
+ * Set Tracker
80
+ *
81
+ * @param Mzax_Emarketing_Model_Conversion_Tracker $tracker
82
+ * @param $validateFilters
83
+ * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
84
+ */
85
+ public function setTracker($tracker, $validateFilters = false)
86
+ {
87
+ $this->_tracker = $tracker;
88
+ $this->load($tracker->getFilterData(), !$validateFilters);
89
+ $this->setParam('tracker', $tracker);
90
+
91
+ return $this;
92
+ }
93
+
94
+
95
+
96
+ /**
97
+ * Retrieve Tracker
98
+ *
99
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
100
+ */
101
+ public function getTracker()
102
+ {
103
+ return $this->_tracker;
104
+ }
105
+
106
+
107
+ public function getFormPrefix()
108
+ {
109
+ return 'conditions';
110
+ }
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ public function getQuery()
119
+ {
120
+ $query = parent::getQuery();
121
+ $query->seek('recipient_id');
122
+
123
+ return $query;
124
+ }
125
+
126
+ /**
127
+ *
128
+ * @return Zend_Db_Select
129
+ */
130
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
131
+ {
132
+ parent::_prepareQuery($query);
133
+ $query->addBinding('recipient_id', new Zend_Db_Expr('MIN(`filter`.`recipient_id`)'));
134
+ $query->setColumn('recipient_id');
135
+ }
136
+
137
+
138
+
139
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
140
+ {
141
+ parent::prepareGridColumns($grid);
142
+ $grid->addColumn('recipient_id', array(
143
+ 'header' => $this->__('Recipient Id'),
144
+ 'width' => '100px',
145
+ 'index' => 'recipient_id'
146
+ ));
147
+ }
148
+
149
+
150
+
151
+ }
app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Orders.php ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Conversion_Goal_Orders
32
+ extends Mzax_Emarketing_Model_Conversion_Goal_Abstract
33
+ {
34
+
35
+
36
+
37
+ public function getTitle()
38
+ {
39
+ return "Magento Orders";
40
+ }
41
+
42
+
43
+
44
+ /**
45
+ * Set default filters when newly created
46
+ *
47
+ * @return void
48
+ */
49
+ public function setDefaultFilters()
50
+ {
51
+ /* @var $campaginFilter Mzax_Emarketing_Model_Object_Filter_Order_Campaign */
52
+ $campaginFilter = $this->addFilter('order_campaign');
53
+ if($campaginFilter) {
54
+ $campaginFilter->setCampaign($campaginFilter::DEFAULT_CAMPAIGN);
55
+ $campaginFilter->setJoin($campaginFilter::DEFAULT_JOIN);
56
+
57
+ /* @var $goalFilter Mzax_Emarketing_Model_Object_Filter_Campaign_Goal */
58
+ $goalFilter = $campaginFilter->addFilter('campaign_goal');
59
+ if($goalFilter) {
60
+ $goalFilter->setAction($goalFilter::ACTION_CLICKED);
61
+ $goalFilter->setOffsetValue(5);
62
+ $goalFilter->setOffsetUnit('days');
63
+ }
64
+
65
+ }
66
+
67
+ /* @var $tableFilter Mzax_Emarketing_Model_Object_Filter_Order_Table */
68
+ $tableFilter = $this->addFilter('order_table');
69
+ if($tableFilter) {
70
+ $tableFilter->setColumn('status');
71
+ $tableFilter->setOperator('()');
72
+ $tableFilter->setValue(Mage_Sales_Model_Order::STATE_COMPLETE);
73
+ }
74
+
75
+
76
+ }
77
+
78
+
79
+
80
+
81
+ /**
82
+ *
83
+ * @return Mzax_Emarketing_Model_Object_Order
84
+ */
85
+ public function getObject()
86
+ {
87
+ return Mage::getSingleton('mzax_emarketing/object_order');
88
+ }
89
+
90
+
91
+ /**
92
+ *
93
+ * @return Mzax_Emarketing_Db_Select
94
+ */
95
+ public function getAggregationSelect($campaign)
96
+ {
97
+ $this->setParam('campaign', $campaign);
98
+
99
+ $query = $this->getObject()->getQuery();
100
+ $query->addBinding('date_filter', 'created_at');
101
+ $query->joinSelect('id', $this->getSelect(), 'filter');
102
+ $query->joinSelectLeft('order_id', $this->getRecipientBinder($campaign, false)->getSelect(), 'recipients');
103
+ $query->group('order_id');
104
+ $query->reset(Zend_Db_Select::COLUMNS);
105
+ $query->setColumn('tracker_id', new Zend_Db_Expr($this->getTracker()->getId()));
106
+ $query->setColumn('campaign_id', new Zend_Db_Expr($campaign->getId()));
107
+ $query->setColumn('goal_id', 'order_id');
108
+ $query->setColumn('goal_time', 'ordered_at');
109
+ $query->setColumn('goal_value', 'base_grand_total');
110
+
111
+ $query->setColumn('recipient_id', 'IFNULL(MAX(`filter`.`recipient_id`), MAX(`recipients`.`recipient_id`))');
112
+
113
+ return $query;
114
+ }
115
+
116
+
117
+
118
+
119
+ /**
120
+ * Get goal <-> recipient binder
121
+ *
122
+ * @param Mzax_Emarketing_Model_Campaign $campaign
123
+ * @param boolean $direct
124
+ * @param integer|false $variation
125
+ * @return Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder
126
+ */
127
+ public function getRecipientBinder($campaign, $direct = false, $variation = false)
128
+ {
129
+ $select = $this->_select('sales/order', 'order');
130
+ $select->addBinding('order_id', 'entity_id');
131
+ $select->addBinding('order_time', 'created_at');
132
+ $select->addBinding('customer_id', 'customer_id');
133
+ $select->addBinding('email', 'customer_email');
134
+ $select->addBinding('quote_id', 'quote_id');
135
+ $select->addBinding('campaign', new Zend_Db_Expr($campaign->getId()));
136
+
137
+ $select->where('{campaign_id} = ?', $campaign->getId());
138
+ $select->where('{order_time} > ?', $campaign->getCreatedAt());
139
+ $select->where('{order_time} > {sent_at}');
140
+ $select->where('{is_mock} = 0');
141
+
142
+ $select->setColumn('order_id');
143
+ $select->setColumn('order_time');
144
+ $select->setColumn('recipient_id');
145
+
146
+ if($variation !== false) {
147
+ $select->where('{variation_id} = ?', $variation);
148
+ }
149
+
150
+
151
+ /* @var $binder Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder */
152
+ $binder = Mage::getResourceModel('mzax_emarketing/recipient_goal_binder');
153
+ $binder->setSelect($select);
154
+
155
+
156
+ // create a direct binding using the goal table
157
+ $binder->createBinding()
158
+ ->joinTable(array(
159
+ 'object_type' => Mzax_Emarketing_Model_Goal::TYPE_ORDER,
160
+ 'object_id' => '{order_id}'
161
+ ), 'goal')
162
+ ->joinTable(array('recipient_id' => '{recipient_id}'), 'recipient')
163
+ ->addBinding('recipient_id', 'goal.recipient_id')
164
+ ->addBinding('sent_at', 'recipient.sent_at')
165
+ ->addBinding('variation_id', 'recipient.variation_id')
166
+ ->addBinding('campaign_id', 'recipient.campaign_id')
167
+ ->addBinding('is_mock', 'recipient.is_mock');
168
+
169
+ if(!$direct) {
170
+ // see if we can get any indirect bindings via email etc
171
+ $campaign->bindRecipients($binder);
172
+ }
173
+
174
+ Mage::dispatchEvent('mzax_emarketing_order_recipient_binder', array(
175
+ 'binder' => $binder,
176
+ 'direct' => $direct,
177
+ 'campaign' => $campaign
178
+ ));
179
+
180
+ return $binder;
181
+ }
182
+
183
+
184
+ }
app/code/community/Mzax/Emarketing/Model/Conversion/Select.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Conversion_Select
25
+ {
26
+
27
+
28
+
29
+
30
+ protected $_bindings = array();
31
+
32
+
33
+ protected $_unionSelects = array();
34
+
35
+
36
+
37
+ /**
38
+ *
39
+ * @param string $name
40
+ * @param Zend_Db_Select $select
41
+ * @param string $field
42
+ * @return Mzax_Emarketing_Model_Conversion_Select
43
+ */
44
+ public function addIndirectBinding($name, Zend_Db_Select $select, $field)
45
+ {
46
+ $this->_bindings[$name] = array(
47
+ 'select' => $select,
48
+ 'field' => $field
49
+ );
50
+ return $this;
51
+ }
52
+
53
+
54
+
55
+ /**
56
+ * Check if we can bind
57
+ *
58
+ * @param string $name
59
+ * @return string
60
+ */
61
+ public function getBinding($name)
62
+ {
63
+ if(isset($this->_bindings[$name])) {
64
+ return $this->_bindings[$name]['field'];
65
+ }
66
+ return false;
67
+ }
68
+
69
+
70
+
71
+ /**
72
+ * Bind using binging select
73
+ *
74
+ * @param string $name
75
+ * @return Zend_Db_Select
76
+ */
77
+ public function bind($name)
78
+ {
79
+ $select = clone $this->_bindings[$name]['select'];
80
+ $this->_unionSelects[] = $select;
81
+
82
+ return $select;
83
+ }
84
+
85
+
86
+
87
+
88
+
89
+
90
+ }
app/code/community/Mzax/Emarketing/Model/Conversion/Tracker.php ADDED
@@ -0,0 +1,344 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @method string getCreatedAt()
26
+ * @method string getUpdatedAt()
27
+ * @method string getTitle()
28
+ * @method string getDescription()
29
+ * @method string getIsActive()
30
+ * @method string getIsDefault()
31
+ * @method string getIsAggregated()
32
+ * @method string getGoalType()
33
+ * @method string getFilters()
34
+ *
35
+ * @author Jacob Siefer
36
+ *
37
+ */
38
+ class Mzax_Emarketing_Model_Conversion_Tracker
39
+ extends Mage_Core_Model_Abstract
40
+ {
41
+
42
+
43
+
44
+ /**
45
+ * Prefix of model events names
46
+ *
47
+ * @var string
48
+ */
49
+ protected $_eventPrefix = 'mzax_emarketing_conversion_tracker';
50
+
51
+ /**
52
+ * Parameter name in event
53
+ *
54
+ * In observe method you can use $observer->getEvent()->getObject() in this case
55
+ *
56
+ * @var string
57
+ */
58
+ protected $_eventObject = 'tracker';
59
+
60
+
61
+ /**
62
+ *
63
+ * @var Mzax_Emarketing_Model_Conversion_Goal_Abstract
64
+ */
65
+ protected $_goal;
66
+
67
+
68
+
69
+ protected function _construct()
70
+ {
71
+ $this->_init('mzax_emarketing/conversion_tracker');
72
+ }
73
+
74
+
75
+
76
+ protected function _beforeSave()
77
+ {
78
+ if($this->_goal) {
79
+ $json = $this->_goal->getFilter()->asJson();
80
+ if($this->getFilterData() !== $json) {
81
+ $this->setFilterData($json);
82
+ $this->setIsAggregated(false);
83
+ }
84
+ }
85
+
86
+ $campaigns = $this->getData('campaign_ids');
87
+ if(is_array($campaigns)) {
88
+ $campaigns = array_filter($campaigns, function($id) {
89
+ return (bool) ($id === '*' || ((int) $id));
90
+ });
91
+ $this->setData('campaign_ids', implode(',', $campaigns));
92
+ }
93
+
94
+ parent::_beforeSave();
95
+ }
96
+
97
+
98
+
99
+ /**
100
+ *
101
+ *
102
+ * @return array
103
+ */
104
+ public function getCampaignIds()
105
+ {
106
+ $data = $this->getData('campaign_ids');
107
+ if(!is_array($data)) {
108
+ $data = $data ? explode(',', $data) : array();
109
+ $this->setData('campaign_ids', $data);
110
+ }
111
+ return $data;
112
+ }
113
+
114
+
115
+
116
+
117
+ /**
118
+ * Retreive goal model
119
+ *
120
+ * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
121
+ */
122
+ public function getGoal($validateFilters = false)
123
+ {
124
+ if(!$this->_goal && $this->getGoalType()) {
125
+ $this->_goal = Mage::getSingleton('mzax_emarketing/conversion_goal')->factory($this->getGoalType());
126
+ if(!$this->_goal) {
127
+ throw new Mage_Exception(Mage::helper('mzax_emarketing')->__('Failed to initialise goal type “%s”. This goal type might not be installed on your system.', $this->getGoalType()));
128
+ }
129
+ $this->_goal->setTracker($this, $validateFilters);
130
+ }
131
+ return $this->_goal;
132
+ }
133
+
134
+
135
+
136
+
137
+ /**
138
+ * Set this tracker as default tracker
139
+ *
140
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
141
+ */
142
+ public function setAsDefault()
143
+ {
144
+ $this->getResource()->setDefaultTracker($this->getId());
145
+ return $this;
146
+ }
147
+
148
+
149
+
150
+ /**
151
+ * Check if tracker has any filters defined
152
+ *
153
+ * @return boolean
154
+ */
155
+ public function hasFilters()
156
+ {
157
+ return $this->getGoal()->hasFilters();
158
+ }
159
+
160
+
161
+
162
+ /**
163
+ * Is current default tracker
164
+ *
165
+ * @return boolean
166
+ */
167
+ public function isDefault()
168
+ {
169
+ return (bool) $this->getIsDefault();
170
+ }
171
+
172
+
173
+ /**
174
+ * Is tracker aggregated
175
+ *
176
+ * @return boolean
177
+ */
178
+ public function isAggregated()
179
+ {
180
+ return (bool) $this->getIsAggregated();
181
+ }
182
+
183
+
184
+
185
+ /**
186
+ * Is tracker active
187
+ *
188
+ * @return boolean
189
+ */
190
+ public function isActive()
191
+ {
192
+ return (bool) $this->getIsActive();
193
+ }
194
+
195
+
196
+
197
+ /**
198
+ * Is tracking all campaigns
199
+ *
200
+ * @return boolean
201
+ */
202
+ public function isTrackingAllCampaigns()
203
+ {
204
+ return in_array('*', $this->getCampaignIds());
205
+ }
206
+
207
+
208
+
209
+ /**
210
+ *
211
+ * @return Mzax_Emarketing_Model_Resource_Campaign_Collection
212
+ */
213
+ public function getCampaigns()
214
+ {
215
+ /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
216
+ $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
217
+ $collection->addArchiveFilter(false);
218
+
219
+ if(!$this->isTrackingAllCampaigns()) {
220
+ $collection->addIdFilter($this->getCampaignIds());
221
+ }
222
+
223
+ return $collection;
224
+ }
225
+
226
+
227
+
228
+
229
+
230
+
231
+ /**
232
+ * Aggregate data for this tracker
233
+ *
234
+ * @param string $incremental
235
+ * @param Mzax_Emarketing_Model_Campaign $campaign
236
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
237
+ */
238
+ public function aggregate($incremental = null, Mzax_Emarketing_Model_Campaign $campaign = null)
239
+ {
240
+ $options = new Varien_Object(array(
241
+ 'aggregator' => array('goals', 'tracker', 'dimension'),
242
+ 'tracker_id' => $this->getId(),
243
+ 'verbose' => false
244
+ ));
245
+
246
+ Mage::dispatchEvent($this->_eventPrefix . '_aggregate',
247
+ array('options' => $options, 'campaign' => $campaign, 'tracker' => $this));
248
+
249
+ if($incremental) {
250
+ $options->setIncremental((int) $incremental);
251
+ }
252
+ if($campaign) {
253
+ if($campaign instanceof Mzax_Emarketing_Model_Campaign) {
254
+ $campaign = $campaign->getId();
255
+ }
256
+ $options->setCampaignId((int) $campaign);
257
+ }
258
+
259
+ /* @var $report Mzax_Emarketing_Model_Report */
260
+ $report = Mage::getSingleton('mzax_emarketing/report');
261
+ $report->aggregate($options->toArray());
262
+
263
+ return $this;
264
+ }
265
+
266
+
267
+
268
+ /**
269
+ * Load tracker data from file
270
+ *
271
+ * @param string $filename
272
+ * @throws Mage_Exception
273
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
274
+ */
275
+ public function loadFromFile($filename)
276
+ {
277
+ if(!file_exists($filename)) {
278
+ throw new Mage_Exception("File not found ($filename)");
279
+ }
280
+ return $this->import(file_get_contents($filename));
281
+ }
282
+
283
+
284
+
285
+
286
+
287
+
288
+ /**
289
+ * Load tracker data from encoded string
290
+ *
291
+ * @see export()
292
+ * @param string $str
293
+ * @throws Mage_Exception
294
+ * @return Mzax_Emarketing_Model_Conversion_Tracker
295
+ */
296
+ public function import($str)
297
+ {
298
+ try {
299
+ $data = Zend_Json::decode(base64_decode($str));
300
+ $this->addData($data);
301
+ $this->_goal = null;
302
+ // check and make sure goal and filters exist
303
+ $this->getGoal(true);
304
+ }
305
+ catch(Zend_Json_Exception $e) {
306
+ throw new Mage_Exception("Failed to decode template file");
307
+ }
308
+ return $this;
309
+ }
310
+
311
+
312
+
313
+ /**
314
+ * Convert to tracker to encoded string
315
+ *
316
+ * @return string
317
+ */
318
+ public function export()
319
+ {
320
+ // set current extension version
321
+ $this->setVersion(Mage::helper('mzax_emarketing')->getVersion());
322
+
323
+ $json = $this->toJson(array('version', 'title', 'description', 'goal_type', 'filter_data'));
324
+ return base64_encode($json);
325
+ }
326
+
327
+
328
+
329
+
330
+
331
+ public function __clone()
332
+ {
333
+ $this->setId(null);
334
+ $this->setIsDefault(false);
335
+ $this->setIsAggregated(true);
336
+ $this->setCreatedAt(null);
337
+ $this->setUpdatedAt(null);
338
+
339
+ return $this;
340
+ }
341
+
342
+
343
+
344
+ }
app/code/community/Mzax/Emarketing/Model/DomainThrottle.php ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Model_DomainThrottle
26
+ {
27
+
28
+
29
+ /**
30
+ *
31
+ * @var Mzax_Presist
32
+ */
33
+ protected $_presist;
34
+
35
+
36
+
37
+ /**
38
+ * The number of seconds for the threshold.
39
+ * Works togher with send threshold
40
+ *
41
+ * @var integer
42
+ */
43
+ protected $_defaultTimeThreshold = 300;
44
+
45
+
46
+
47
+ /**
48
+ * The number of emails that can be send within the
49
+ * threshold time before we rest the domain.
50
+ *
51
+ * @var integer
52
+ */
53
+ protected $_defaultSendThreshold = 50;
54
+
55
+
56
+ /**
57
+ * The number of seconds to wait before sending an email
58
+ * to this domain again after the send threshold exceeded
59
+ *
60
+ * @var integer
61
+ */
62
+ protected $_defaultRestTime = 600;
63
+
64
+
65
+ /**
66
+ * Domain specific options
67
+ *
68
+ * @var array
69
+ */
70
+ protected $_domainOptions = array();
71
+
72
+
73
+
74
+
75
+
76
+
77
+ public function __construct()
78
+ {
79
+ $this->_presist = new Mzax_Presist;
80
+ $this->_presist->open(Mage::getBaseDir('tmp') . DS . 'domain_throttle.data');
81
+
82
+ if(empty($this->_presist->data)) {
83
+ $this->_presist->data = array();
84
+ }
85
+ }
86
+
87
+
88
+
89
+ /**
90
+ * Is given domain resting
91
+ *
92
+ * 0 = no resting, send out emails
93
+ *
94
+ * @param string $domain
95
+ * @return integer
96
+ */
97
+ public function isResting($domain)
98
+ {
99
+ $domain = strtolower($domain);
100
+ $data = &$this->_presist->data;
101
+ if(!$domain || !isset($data[$domain])) {
102
+ return false;
103
+ }
104
+ list($restTill, $lastTime, $count) = $data[$domain];
105
+
106
+ return max(0, $restTill - time());
107
+ }
108
+
109
+
110
+
111
+
112
+ /**
113
+ * Calculate current counter value
114
+ *
115
+ * The counter value can slowly decrease if enough
116
+ * time passes without any send outs
117
+ *
118
+ * @param string $domain
119
+ * @param array $entry
120
+ * @return number
121
+ */
122
+ protected function _calcCounter($domain, $entry)
123
+ {
124
+ $timeThereshold = $this->getTimeThreshold($domain);
125
+
126
+ list($restTill, $lastTime, $count) = $entry;
127
+
128
+ // @todo maybe there is better formular
129
+ return $count - max(floor(($now - $lastTime)/$timeThereshold), $count);
130
+ }
131
+
132
+
133
+
134
+
135
+ /**
136
+ * Touch domain and increase the internal counter
137
+ * and check if we have reached the threshold and
138
+ * should wait with the next email
139
+ *
140
+ * @param string $domain
141
+ */
142
+ public function touchDomain($domain)
143
+ {
144
+ $domain = strtolower($domain);
145
+
146
+ $now = time();
147
+
148
+ $data = &$this->_presist->data;
149
+
150
+
151
+ if(!isset($data[$domain])) {
152
+ $restTill = false;
153
+ $lastTime = $now;
154
+ $count = 1;
155
+ }
156
+ else {
157
+ list($restTill, $lastTime, $count) = $data[$domain];
158
+ $count = $this->_calcCounter($domain, $data[$domain]);
159
+ $count++;
160
+ }
161
+
162
+ if($count >= $this->getSendThreshold($domain)) {
163
+ $restTill = $now + $this->getRestTime($domain);
164
+ }
165
+
166
+ $data[$domain] = array($restTill, $lastTime, $count);
167
+ }
168
+
169
+
170
+
171
+ /**
172
+ * Check all records and remove the unrelevant ones
173
+ *
174
+ * @return Mzax_Emarketing_Model_Domain
175
+ */
176
+ public function purge()
177
+ {
178
+ $data = &$this->_presist->data;
179
+ foreach($data as $domain => $entry) {
180
+ if(!$this->_calcCounter($domain, $data[$domain])) {
181
+ unset($data[$domain]);
182
+ }
183
+ }
184
+ return $this;
185
+ }
186
+
187
+
188
+
189
+ public function __destruct()
190
+ {
191
+ try {
192
+ $this->_presist->close();
193
+ }
194
+ catch(Exception $e) {
195
+ // ignore
196
+ }
197
+ }
198
+
199
+
200
+
201
+
202
+
203
+
204
+ public function addDomainOption($domain, $timeThreshold, $sendThreshold, $restTime)
205
+ {
206
+ $domain = strtolower($domain);
207
+ $this->_domainOptions[$domain] = array(
208
+ 'time_threshold' => (int) $timeThreshold,
209
+ 'send_threshold' => (int) $sendThreshold,
210
+ 'rest_time' => (int) $restTime
211
+ );
212
+ return $this;
213
+ }
214
+
215
+
216
+
217
+ public function setTimeThreshold($value)
218
+ {
219
+ $this->_defaultTimeThreshold = (int) $value;
220
+ return $this;
221
+ }
222
+
223
+
224
+ public function setSendThreshold($value)
225
+ {
226
+ $this->_defaultSendThreshold = (int) $value;
227
+ return $this;
228
+ }
229
+
230
+ public function setRestTime($value)
231
+ {
232
+ $this->_defaultRestTime = (int) $value;
233
+ return $this;
234
+ }
235
+
236
+
237
+
238
+ public function getTimeThreshold($domain)
239
+ {
240
+ if(isset($this->_domainOptions[$domain])) {
241
+ return $this->_domainOptions[$domain]['time_threshold'];
242
+ }
243
+ return $this->_defaultTimeThreshold;
244
+ }
245
+
246
+
247
+ public function getSendThreshold($domain)
248
+ {
249
+ if(isset($this->_domainOptions[$domain])) {
250
+ return $this->_domainOptions[$domain]['send_threshold'];
251
+ }
252
+ return $this->_defaultSendThreshold;
253
+ }
254
+
255
+ public function getRestTime($domain)
256
+ {
257
+ if(isset($this->_domainOptions[$domain])) {
258
+ return $this->_domainOptions[$domain]['rest_time'];
259
+ }
260
+ return $this->_defaultRestTime;
261
+ }
262
+
263
+
264
+
265
+
266
+
267
+
268
+ }
app/code/community/Mzax/Emarketing/Model/Email.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ * @method string getCreatedAt()
28
+ * @method string getMessageId()
29
+ * @method string getCampaignId()
30
+ * @method string getRecipientId()
31
+ *
32
+ * @author Jacob Siefer
33
+ *
34
+ */
35
+ abstract class Mzax_Emarketing_Model_Email
36
+ extends Mage_Core_Model_Abstract
37
+ {
38
+
39
+
40
+ /**
41
+ *
42
+ * @var Mzax_Emarketing_Model_Recipient
43
+ */
44
+ protected $_recipient;
45
+
46
+
47
+ /**
48
+ *
49
+ * @var Mzax_Emarketing_Model_Campaign
50
+ */
51
+ protected $_campaign;
52
+
53
+
54
+
55
+
56
+ protected function _beforeSave()
57
+ {
58
+ if($this->_campaign) {
59
+ $this->setCampaignId($this->_campaign->getId());
60
+ }
61
+ if($this->_recipient) {
62
+ $this->setRecipientId($this->_recipient->getId());
63
+ }
64
+
65
+ return parent::_beforeSave();
66
+ }
67
+
68
+
69
+
70
+ /**
71
+ * Set campaign
72
+ *
73
+ * @param Mzax_Emarketing_Model_Campaign $campaign
74
+ * @return Mzax_Emarketing_Model_Recipient_Bounce_Message
75
+ */
76
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
77
+ {
78
+ $this->_campaign = $campaign;
79
+ if( $this->_recipient ) {
80
+ $this->_recipient->setCampaign($campaign);
81
+ }
82
+ return $this;
83
+ }
84
+
85
+
86
+
87
+ /**
88
+ * Retrieve campaign if available
89
+ *
90
+ * @return Mzax_Emarketing_Model_Campaign
91
+ */
92
+ public function getCampaign()
93
+ {
94
+ if(!$this->_campaign && $this->getCampaignId()) {
95
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign')->load($this->getCampaignId());
96
+ }
97
+ return $this->_campaign;
98
+ }
99
+
100
+
101
+
102
+
103
+ /**
104
+ * Set recipient
105
+ *
106
+ * @param Mzax_Emarketing_Model_Recipient $recipient
107
+ * @return Mzax_Emarketing_Model_Recipient_Bounce_Message
108
+ */
109
+ public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
110
+ {
111
+ $this->_recipient = $recipient;
112
+ if( $this->_campaign ) {
113
+ $this->_recipient->setCampaign($this->_campaign);
114
+ }
115
+ else {
116
+ $this->_campaign = $recipient->getCampaign();
117
+ }
118
+ return $this;
119
+ }
120
+
121
+
122
+
123
+ /**
124
+ * Retrieve recipient if available
125
+ *
126
+ * @return Mzax_Emarketing_Model_Recipient
127
+ */
128
+ public function getRecipient()
129
+ {
130
+ if(!$this->_recipient && $this->getRecipientId()) {
131
+ $this->_recipient = Mage::getModel('mzax_emarketing/recipient')->load($this->getRecipientId());
132
+ }
133
+ return $this->_recipient;
134
+ }
135
+
136
+
137
+
138
+ /**
139
+ * Retrieve store
140
+ *
141
+ * @return Mage_Core_Model_Store|NULL
142
+ */
143
+ public function getStore()
144
+ {
145
+ if($this->_campaign) {
146
+ return $this->_campaign->getStore();
147
+ }
148
+ return Mage::app()->getStore($this->getStoreId());
149
+ }
150
+
151
+
152
+
153
+ /**
154
+ * Load email by message id
155
+ *
156
+ * @param string $messageId
157
+ * @return Mzax_Emarketing_Model_Email
158
+ */
159
+ public function loadByMessageId($messageId)
160
+ {
161
+ $this->getResource()->load($this, $messageId, 'message_id');
162
+ return $this;
163
+ }
164
+
165
+
166
+
167
+
168
+
169
+
170
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/Ace.php ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Form_Element_Ace extends Varien_Data_Form_Element_Abstract
25
+ {
26
+
27
+
28
+
29
+ public function getEditorClass()
30
+ {
31
+ return 'mzax.ui.TextEditor';
32
+ }
33
+
34
+
35
+
36
+ public function getTypeClass()
37
+ {
38
+ return 'mage-ace-editor';
39
+ }
40
+
41
+
42
+
43
+
44
+
45
+ /**
46
+ * Retrieve editor options
47
+ *
48
+ * @return array
49
+ */
50
+ public function getEditorOptions()
51
+ {
52
+ $options = array(
53
+ 'theme' => $this->getConfig('theme', 'ace/theme/mage'),
54
+ 'mode' => $this->getConfig('mode', 'ace/mode/mage'),
55
+ 'enableAce' => $this->aceEnabled(),
56
+ 'autosize' => $this->getConfig('autosize', false),
57
+ 'readOnly' => $this->getReadonly(),
58
+ 'snippets' => $this->getSnippets()
59
+ );
60
+
61
+ return $options;
62
+ }
63
+
64
+
65
+
66
+
67
+ public function getElementHtml()
68
+ {
69
+ $helper = Mage::helper('core');
70
+
71
+ $id = $this->getHtmlId();
72
+ $jsId = "editor{$id}";
73
+
74
+ $logo = $this->getLogo();
75
+ if($logo) {
76
+ $logo = '<img src="' . $logo . '" class="logo" />';
77
+ }
78
+
79
+ $buttonsHtml = $this->_getPluginButtonsHtml();
80
+
81
+
82
+ $toolbarHtml = <<<JS
83
+ <div id="control-buttons-$id" class="mzax-editor-toolbar">
84
+ $logo
85
+ <div class="ftitle">{$this->getFullscreenTitle()}</div>
86
+ <div class="buttons-set">
87
+ {$buttonsHtml}
88
+ </div>
89
+ </div>
90
+ JS;
91
+
92
+ $toolbarHtml = str_replace('{editor}', $jsId, $toolbarHtml);
93
+
94
+ $classes = array('mzax-editor');
95
+ $classes[] = $this->getClass();
96
+ $classes[] = $this->getTypeClass();
97
+ $classes[] = $buttonsHtml ? 'has-plugin-buttons' : 'no-plugin-buttons';
98
+
99
+ $classes = array_filter($classes);
100
+
101
+ $html = '<div title="' . $this->getTitle()
102
+ . '" id="' . $id . '"'
103
+ . ' class="mzax-editor mage-ace-editor ' . implode(' ', $classes) .'" '
104
+ . $this->serialize($this->getHtmlAttributes()) . ' >';
105
+
106
+ $html.= '<textarea id="' . $id . '_txt" name="' . $this->getName() . '" style="display:none;">'.$this->getEscapedValue().'</textarea>';
107
+ $html.= $toolbarHtml;
108
+ $html.= '<div class="editor-container"></div>';
109
+ $html.= '</div>';
110
+
111
+ $html.= '<script type="text/javascript">';
112
+ $html.= $this->getJavaScript($jsId);
113
+ $html.= '</script>';
114
+
115
+
116
+ return $html;
117
+ }
118
+
119
+
120
+ public function getJavaScript($jsId)
121
+ {
122
+ $options = Zend_Json::encode($this->getEditorOptions());
123
+ $options = str_replace('{editor}', $jsId, $options);
124
+
125
+ $cls = $this->getEditorClass();
126
+
127
+ return <<<JS
128
+ window.$jsId = (function() {
129
+
130
+ var div = $("{$this->getHtmlId()}"),
131
+ txt = div.down('textarea'),
132
+ editor = new {$cls}(div.down('.editor-container'), {$options});
133
+
134
+ editor.setValue(txt.value);
135
+ editor.htmlId = div.id;
136
+
137
+ editor.fullscreen = function() {
138
+ div.toggleClassName('fullscreen');
139
+ document.body.toggleClassName('mzax-fullscreen');
140
+ editor.refreshUi();
141
+ };
142
+
143
+ varienGlobalEvents.attachEventHandler('formSubmit', function(event) {
144
+ txt.value = editor.getValue();
145
+ });
146
+
147
+ {$this->getExtaScript()}
148
+
149
+ return editor;
150
+ })();
151
+ JS;
152
+ }
153
+
154
+
155
+
156
+ public function getExtaScript()
157
+ {
158
+ return '';
159
+ }
160
+
161
+
162
+
163
+
164
+ public function getSnippets()
165
+ {
166
+ $data = $this->getConfig('snippets');
167
+
168
+ /* @var $store Mage_Core_Model_Store */
169
+ $store = $this->getConfig('store', Mage::app()->getStore(true));
170
+
171
+ if(!$data instanceof Mzax_Emarketing_Model_Medium_Email_Snippets) {
172
+ $data = new Mzax_Emarketing_Model_Medium_Email_Snippets;
173
+ }
174
+
175
+
176
+ /* @var $variable Mage_Core_Model_Variable */
177
+ foreach (Mage::getResourceModel('core/variable_collection') as $variable) {
178
+ $data->add(array(
179
+ 'title' => $this->translate('%s', $variable['name']),
180
+ 'description' => $this->translate('A custom variable, see Magento Admin -> System -> Custom Variables'),
181
+ 'snippet' => '{{customVar code=' . $variable['code'] . '}}',
182
+ 'value' => 'mage.custom_var.' . $variable['code'],
183
+ 'text' => $variable->getValue($variable::TYPE_TEXT),
184
+ 'html' => $variable->getValue($variable::TYPE_HTML),
185
+ 'shortcut' => null
186
+ ));
187
+ }
188
+
189
+
190
+ $storeContactVariabls = Mage::getModel('core/source_email_variables')->toOptionArray(false);
191
+ foreach($storeContactVariabls as $var) {
192
+ $path = preg_replace('/\{\{config path="(.*)"\}\}/i', '$1', $var['value']);
193
+ $data->add(array(
194
+ 'title' => $var['label'],
195
+ 'description' => $var['label'],
196
+ 'snippet' => $var['value'],
197
+ 'value' => 'mage.config.' . str_replace('/', '.', $path),
198
+ 'text' => $store->getConfig($path),
199
+ 'shortcut' => null
200
+ ));
201
+ }
202
+
203
+
204
+ $data->add(array(
205
+ 'title' => $this->translate("Magento Template Block"),
206
+ 'description' => $this->translate('Insert html from a php block class'),
207
+ 'snippet' => '{{block type="${1:core/template}" area="${3:frontend}" template="${2}" }}',
208
+ 'value' => 'mage.block.insert',
209
+ 'shortcut' => 'block'
210
+ ));
211
+
212
+
213
+ if ($this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
214
+ $data->add(array(
215
+ 'title' => $this->translate('Magento Widget'),
216
+ 'description' => $this->translate('Start magento widget helper tool'),
217
+ 'snippet' => '{{js:insertWidget}}',
218
+ 'value' => 'mage.widget',
219
+ 'shortcut' => 'widget'
220
+ ));
221
+ }
222
+
223
+ if ($this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
224
+ $data->add(array(
225
+ 'title' => $this->translate('Magento Image'),
226
+ 'description' => $this->translate('Start magento image browser'),
227
+ 'snippet' => '{{js:browserMedia}}',
228
+ 'value' => 'mage.image',
229
+ 'shortcut' => 'image'
230
+ ));
231
+ }
232
+
233
+
234
+ return $data->toArray();
235
+ }
236
+
237
+
238
+
239
+
240
+ /**
241
+ * Prepare Html buttons for additional WYSIWYG features
242
+ *
243
+ * @param bool $visible Display button or not
244
+ * @return void
245
+ */
246
+ protected function _getPluginButtonsHtml()
247
+ {
248
+ $buttonsHtml = '';
249
+
250
+ if(!$this->getReadonly()) {
251
+ // Button to widget insertion window
252
+ $buttonsHtml .= $this->_getButtonHtml(array(
253
+ 'title' => $this->translate('Insert MageCode'),
254
+ 'onclick' => "{editor}.execCommand('mage', {source: 'mage'});",
255
+ 'class' => 'mzax-variable'
256
+ ));
257
+ }
258
+
259
+ // Button to widget insertion window
260
+ if (!$this->getReadonly() && $this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
261
+ $buttonsHtml .= $this->_getButtonHtml(array(
262
+ 'title' => $this->translate('Insert Widget'),
263
+ 'onclick' => "{editor}.openWidgetTools();",
264
+ 'class' => 'mzax-widget'
265
+ ));
266
+ }
267
+
268
+ // Button to media images insertion window
269
+ if (!$this->getReadonly() && $this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
270
+ $buttonsHtml .= $this->_getButtonHtml(array(
271
+ 'title' => $this->translate('Insert Image'),
272
+ 'onclick' => "{editor}.openMediabrowser();",
273
+ 'class' => 'mzax-image'
274
+ ));
275
+ }
276
+
277
+
278
+ if ($this->getConfig('allow_fullscreen', true)) {
279
+ $buttonsHtml .= $this->_getButtonHtml(array(
280
+ 'title' => $this->translate('Fullscreen'),
281
+ 'onclick' => "{editor}.fullscreen();",
282
+ 'class' => 'mzax-fullscreen'
283
+ ));
284
+ }
285
+
286
+ $buttons = $this->getConfig('buttons');
287
+ if(is_array($buttons)) {
288
+ foreach($buttons as $button) {
289
+ $buttonsHtml .= $this->_getButtonHtml($button);
290
+ }
291
+ }
292
+
293
+
294
+ return $buttonsHtml;
295
+ }
296
+
297
+
298
+
299
+
300
+ /**
301
+ * Return custom button HTML
302
+ *
303
+ * @param array $data Button params
304
+ * @return string
305
+ */
306
+ protected function _getButtonHtml($data)
307
+ {
308
+ $html = '<button type="button"';
309
+ $html.= ' class="scalable '.(isset($data['class']) ? $data['class'] : '').'"';
310
+ $html.= isset($data['onclick']) ? ' onclick="'.$data['onclick'].'"' : '';
311
+ $html.= isset($data['style']) ? ' style="'.$data['style'].'"' : '';
312
+ $html.= isset($data['id']) ? ' id="'.$data['id'].'"' : '';
313
+ $html.= '>';
314
+ $html.= isset($data['title']) ? '<span>'.$data['title'].'</span>' : '';
315
+ $html.= '</button>';
316
+
317
+ return $html;
318
+ }
319
+
320
+
321
+
322
+
323
+
324
+ /**
325
+ * Editor config retriever
326
+ *
327
+ * @param string $key Config var key
328
+ * @return mixed
329
+ */
330
+ public function getConfig($key = null, $default = null)
331
+ {
332
+ if ( !($this->_getData('config') instanceof Varien_Object) ) {
333
+ $config = new Varien_Object();
334
+ $this->setConfig($config);
335
+ }
336
+
337
+ if ($key !== null) {
338
+ $data = $this->_getData('config')->getData($key);
339
+ if($data !== null) {
340
+ return $data;
341
+ }
342
+ $data = $this->getData($key);
343
+ if($data !== null) {
344
+ return $data;
345
+ }
346
+ return $default;
347
+ }
348
+ return $this->_getData('config');
349
+ }
350
+
351
+
352
+
353
+ /**
354
+ * Is ACE editor enabled
355
+ *
356
+ * @return boolean
357
+ */
358
+ public function aceEnabled()
359
+ {
360
+ $enabled = Mage::getStoreConfigFlag('mzax_emarketing/content_management/enable_ace');
361
+ if(!$enabled) {
362
+ return 0;
363
+ }
364
+ return (int) $this->getConfig('enable_ace', 1);
365
+ }
366
+
367
+
368
+ /**
369
+ * Is CKEditor enabled
370
+ *
371
+ * @return boolean
372
+ */
373
+ public function ckeEnabled()
374
+ {
375
+ $enabled = Mage::getStoreConfigFlag('mzax_emarketing/content_management/enable_ckeditor');
376
+ if(!$enabled) {
377
+ return 0;
378
+ }
379
+ return (int) $this->getConfig('enable_ckeditor', 1);
380
+ }
381
+
382
+
383
+
384
+ /**
385
+ * Translate string using defined helper
386
+ *
387
+ * @param string $string String to be translated
388
+ * @return string
389
+ */
390
+ public function translate($string)
391
+ {
392
+ $translator = $this->getConfig('translator');
393
+ if (is_object($translator) && is_callable(array($translator, '__'))) {
394
+ $result = call_user_func_array(array($translator, '__'), func_get_args());
395
+ if (is_string($result)) {
396
+ return $result;
397
+ }
398
+ }
399
+
400
+ return $string;
401
+ }
402
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/Credits.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Form_Element_Credits extends Varien_Data_Form_Element_Abstract
25
+ {
26
+
27
+ public function getElementHtml()
28
+ {
29
+ $credits = $this->getEscapedValue();
30
+ $credits = preg_replace('/\[(.*?)\|(.*?)\]/', '<a href="$2" target="_blank">$1</a>', $credits);
31
+
32
+ $credits = nl2br($credits);
33
+
34
+ return '<div class="mzax-credits">' . $credits . '</div>';
35
+ }
36
+
37
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/EmailEditor.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Email Editor
26
+ *
27
+ * The email editor requires a template to work.
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Form_Element_EmailEditor
34
+ extends Mzax_Emarketing_Model_Form_Element_TemplateEditor
35
+ {
36
+
37
+
38
+ /**
39
+ * The JS editor class
40
+ *
41
+ * @return string
42
+ */
43
+ public function getEditorClass()
44
+ {
45
+ return 'mzax.ui.PreviewFrame';
46
+ }
47
+
48
+
49
+
50
+ /**
51
+ * CSS class for this editor
52
+ *
53
+ * @return string
54
+ */
55
+ public function getTypeClass()
56
+ {
57
+ return 'mage-email-editor';
58
+ }
59
+
60
+
61
+
62
+
63
+ /**
64
+ * Retrieve editor options
65
+ *
66
+ * @return array
67
+ */
68
+ public function getEditorOptions()
69
+ {
70
+ $storeId = $this->getConfig('store_id');
71
+ $storeParam = null !== $storeId ? 'store/' . $this->getConfig('store_id') . '/' : '';
72
+
73
+ $options = parent::getEditorOptions();
74
+
75
+ $options['quicksaveUrl'] = $this->getConfig('quicksave_url');
76
+ $options['quicksaveFields'] = $this->getQuicksaveFields();
77
+ $options['templateLoadUrl'] = $this->getConfig('template_load_url');
78
+ $options['html'] = $this->getTemplateHtml();
79
+ $options['fieldName'] = $this->getData('name');
80
+ $options['enableCKEditor'] = $this->ckeEnabled();
81
+ $options['startEdit'] = true;
82
+
83
+ return $options;
84
+ }
85
+
86
+
87
+
88
+
89
+
90
+ public function getExtaScript()
91
+ {
92
+ $templateField = $this->getConfig('template_field') ? $this->getConfig('template_field')->getHtmlId() : '';
93
+
94
+ if($templateField) {
95
+ return <<<JS
96
+ var templateField = $('$templateField');
97
+ if(templateField) {
98
+ templateField.on('change', function() {
99
+ editor.loadTemplate(this.value);
100
+ });
101
+ }
102
+ JS;
103
+ }
104
+ return '';
105
+ }
106
+
107
+
108
+
109
+ protected function getQuicksaveFields()
110
+ {
111
+ $fields = $this->getConfig('quicksave_fields');
112
+ $quicksaveFields = array();
113
+ if(is_array($fields)) {
114
+ foreach($fields as $field) {
115
+ if($field instanceof Varien_Data_Form_Element_Abstract) {
116
+ $quicksaveFields[$field->getData('name')] = $field->getHtmlId();
117
+ }
118
+ }
119
+ }
120
+ return $quicksaveFields;
121
+ }
122
+
123
+
124
+
125
+ public function getTemplateHtml()
126
+ {
127
+ if($this->getTemplate()) {
128
+ $html = (string) $this->getTemplate()->getBody();
129
+ }
130
+ else {
131
+ $html = '';
132
+ }
133
+ return $html;
134
+ }
135
+
136
+
137
+
138
+
139
+ /**
140
+ * Prepare Html buttons for additional WYSIWYG features
141
+ *
142
+ * @param bool $visible Display button or not
143
+ * @return void
144
+ */
145
+ protected function _getPluginButtonsHtml()
146
+ {
147
+ $buttonsHtml = '';
148
+
149
+ if ($this->getConfig('allow_fullscreen', true)) {
150
+ $buttonsHtml .= $this->_getButtonHtml(array(
151
+ 'title' => $this->translate('Fullscreen'),
152
+ 'onclick' => "{editor}.fullscreen();",
153
+ 'class' => 'mzax-fullscreen'
154
+ ));
155
+ }
156
+
157
+ $buttons = $this->getConfig('buttons');
158
+ if(is_array($buttons)) {
159
+ foreach($buttons as $button) {
160
+ $buttonsHtml .= $this->_getButtonHtml($button);
161
+ }
162
+ }
163
+
164
+
165
+ return $buttonsHtml;
166
+ }
167
+
168
+
169
+
170
+
171
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/Info.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Form_Element_Info extends Varien_Data_Form_Element_Abstract
25
+ {
26
+
27
+ public function getElementHtml()
28
+ {
29
+ return '<div class="mzax-info-element">' . $this->getText() . '</div>';
30
+ }
31
+
32
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/TemplateEditor.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_Model_Form_Element_Ace
25
+ {
26
+
27
+ public function getEditorClass()
28
+ {
29
+ return 'mzax.ui.TemplateEditor';
30
+ }
31
+
32
+
33
+ public function getTypeClass()
34
+ {
35
+ return 'mage-template-editor';
36
+ }
37
+
38
+
39
+
40
+
41
+ /**
42
+ * Retrieve editor options
43
+ *
44
+ * @return array
45
+ */
46
+ public function getEditorOptions()
47
+ {
48
+ $storeId = $this->getConfig('store_id');
49
+ $storeParam = null !== $storeId ? 'store/' . $this->getConfig('store_id') . '/' : '';
50
+
51
+ $options = parent::getEditorOptions();
52
+ $options['mediaBrowserUrl'] = "{$this->getConfig('files_browser_window_url')}target_element_id/{editor}/{$storeParam}";
53
+ $options['widgetToolsUrl'] = "{$this->getConfig('widget_window_url')}widget_target_id/{editor}";
54
+
55
+ return $options;
56
+ }
57
+
58
+
59
+
60
+
61
+
62
+
63
+ /**
64
+ * Prepare Html buttons for additional WYSIWYG features
65
+ *
66
+ * @param bool $visible Display button or not
67
+ * @return void
68
+ */
69
+ protected function _getPluginButtonsHtml()
70
+ {
71
+ $buttonsHtml = '';
72
+
73
+ if(!$this->getReadonly()) {
74
+ // Button to widget insertion window
75
+ $buttonsHtml .= $this->_getButtonHtml(array(
76
+ 'title' => $this->translate('Insert MageCode'),
77
+ 'onclick' => "{editor}.execCommand('mage');",
78
+ 'class' => 'mzax-variable'
79
+ ));
80
+ }
81
+
82
+ // Button to widget insertion window
83
+ if (!$this->getReadonly() && $this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
84
+ $buttonsHtml .= $this->_getButtonHtml(array(
85
+ 'title' => $this->translate('Insert Widget'),
86
+ 'onclick' => "{editor}.insertWidget();",
87
+ 'class' => 'mzax-widget'
88
+ ));
89
+ }
90
+
91
+ // Button to media images insertion window
92
+ if (!$this->getReadonly() && $this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
93
+ $buttonsHtml .= $this->_getButtonHtml(array(
94
+ 'title' => $this->translate('Insert Image'),
95
+ 'onclick' => "{editor}.browserMedia();",
96
+ 'class' => 'mzax-image'
97
+ ));
98
+ }
99
+
100
+
101
+ if ($this->getConfig('allow_fullscreen', true)) {
102
+ $buttonsHtml .= $this->_getButtonHtml(array(
103
+ 'title' => $this->translate('Fullscreen'),
104
+ 'onclick' => "{editor}.fullscreen();",
105
+ 'class' => 'mzax-fullscreen'
106
+ ));
107
+ }
108
+
109
+ $buttonsHtml .= $this->_getButtonHtml(array(
110
+ 'title' => $this->translate('Switch Vert/Horz'),
111
+ 'onclick' => "{editor}.switchLayout();",
112
+ 'class' => 'mzax-layout-mode'
113
+ ));
114
+
115
+
116
+ $buttons = $this->getConfig('buttons');
117
+ if(is_array($buttons)) {
118
+ foreach($buttons as $button) {
119
+ $buttonsHtml .= $this->_getButtonHtml($button);
120
+ }
121
+ }
122
+
123
+
124
+ return $buttonsHtml;
125
+ }
126
+
127
+
128
+
129
+
130
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/Textarea.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Textare with placeholder attribute
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Form_Element_Textarea
33
+ extends Varien_Data_Form_Element_Textarea
34
+ {
35
+ public function getHtmlAttributes()
36
+ {
37
+ $attributes = parent::getHtmlAttributes();
38
+ $attributes[] = 'placeholder';
39
+
40
+ return $attributes;
41
+ }
42
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/Wildselect.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Works like multislect but one can also select all options
26
+ * like a wildcard
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Form_Element_Wildselect
34
+ extends Varien_Data_Form_Element_Multiselect
35
+ {
36
+
37
+
38
+
39
+ /**
40
+ * Retrieve Element HTML fragment
41
+ *
42
+ * @return string
43
+ */
44
+ public function getElementHtml()
45
+ {
46
+ $disabled = false;
47
+ if ($this->getValue() === $this->getDataSetDefault('wildcard', '*')) {
48
+ $this->setData('disabled', 'disabled');
49
+ $disabled = true;
50
+ }
51
+ $html = parent::getElementHtml();
52
+ $htmlId = 'wildcard_' . $this->getHtmlId();
53
+ $html .= '<input id="'.$htmlId.'" name="wildcard[]" value="' . $this->getId() . '"';
54
+ $html .= ($disabled ? ' checked="checked"' : '');
55
+
56
+ if ($this->getReadonly()) {
57
+ $html .= ' disabled="disabled"';
58
+ }
59
+
60
+ $wildcardLabel = $this->getDataSetDefault('wildcard_label', Mage::helper('mzax_emarketing')->__('Use All'));
61
+
62
+ $html .= ' onclick="toggleValueElements(this, this.parentNode);" class="checkbox" type="checkbox" />';
63
+
64
+ $html .= ' <label for="'.$htmlId.'" class="normal">' . $wildcardLabel . '</label>';
65
+ $html .= '<script type="text/javascript">toggleValueElements($(\''.$htmlId.'\'), $(\''.$htmlId.'\').parentNode);</script>';
66
+
67
+ return $html;
68
+ }
69
+ }
app/code/community/Mzax/Emarketing/Model/Goal.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ *
28
+ * @method Mzax_Emarketing_Model_Link setObjectId(string)
29
+ * @method Mzax_Emarketing_Model_Link setObjectType(string)
30
+ * @method Mzax_Emarketing_Model_Link setRecipientId(string)
31
+ * @method Mzax_Emarketing_Model_Link setClickId(string)
32
+ *
33
+ * @method string getObjectId()
34
+ * @method string getObjectType()
35
+ * @method string getRecipientId()
36
+ * @method string getClickId()
37
+ *
38
+ * @method Mzax_Emarketing_Model_Resource_Goal getResource()
39
+ *
40
+ *
41
+ * If you plan on implmenting custom events, use a type id greater than 100
42
+ *
43
+ *
44
+ * @author Jacob Siefer
45
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
46
+ * @version 0.2.5
47
+ */
48
+ class Mzax_Emarketing_Model_Goal extends Mage_Core_Model_Abstract
49
+ {
50
+
51
+ const TYPE_ORDER = 1;
52
+ const TYPE_SIGNUP = 2;
53
+
54
+
55
+
56
+ /**
57
+ * Prefix of model events names
58
+ *
59
+ * @var string
60
+ */
61
+ protected $_eventPrefix = 'mzax_emarketing_goal';
62
+
63
+ /**
64
+ * Parameter name in event
65
+ *
66
+ * In observe method you can use $observer->getEvent()->getObject() in this case
67
+ *
68
+ * @var string
69
+ */
70
+ protected $_eventObject = 'goal';
71
+
72
+
73
+
74
+
75
+ protected function _construct()
76
+ {
77
+ $this->_init('mzax_emarketing/goal');
78
+ }
79
+
80
+
81
+
82
+
83
+
84
+ }
app/code/community/Mzax/Emarketing/Model/Inbox.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Email Inbox Facade
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Inbox
32
+ {
33
+
34
+
35
+
36
+ /**
37
+ * Retrieve new email messages
38
+ *
39
+ * @return Mzax_Emarketing_Model_Inbox
40
+ */
41
+ public function downloadEmails()
42
+ {
43
+ if(!Mage::getStoreConfigFlag('mzax_emarketing/inbox/enable')) {
44
+ return;
45
+ }
46
+
47
+ $lock = Mage::helper('mzax_emarketing')->lock('download_emails');
48
+ if(!$lock) {
49
+ return $this;
50
+ }
51
+
52
+
53
+
54
+ /* @var $collector Mzax_Emarketing_Model_Inbox_Email_Collector */
55
+ $collector = Mage::getModel('mzax_emarketing/inbox_email_collector');
56
+ $collector->collect();
57
+
58
+ $lock->unlock();
59
+
60
+ return $this;
61
+ }
62
+
63
+
64
+
65
+
66
+ /**
67
+ * Parse email messages
68
+ *
69
+ * @return Mzax_Emarketing_Model_Inbox
70
+ */
71
+ public function parseEmails()
72
+ {
73
+ $lock = Mage::helper('mzax_emarketing')->lock('parse_emails');
74
+ if(!$lock) {
75
+ return $this;
76
+ }
77
+
78
+ /* @var $collection Mzax_Emarketing_Model_Resource_Inbox_Email_Collection */
79
+ $collection = Mage::getResourceModel('mzax_emarketing/inbox_email_collection');
80
+ $collection->addFieldToFilter('is_parsed', 0);
81
+
82
+ /* @var $email Mzax_Emarketing_Model_Inbox_Email */
83
+ foreach($collection as $email) {
84
+ $email->parse();
85
+ $lock->touch();
86
+ }
87
+
88
+ $lock->unlock();
89
+ return $this;
90
+ }
91
+
92
+
93
+
94
+
95
+
96
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Abstract.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @author Jacob Siefer
27
+ *
28
+ */
29
+ abstract class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
30
+ extends Mzax_Bounce_Detector_Abstract
31
+ {
32
+
33
+
34
+
35
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Recipient.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Recipient
26
+ extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
27
+ {
28
+
29
+
30
+ /**
31
+ * try to find our beacon from mime boundary
32
+ *
33
+ * @see Mzax_Emarketing_Model_Recipient
34
+ * @var string
35
+ */
36
+ const BOUNDARY_REGEX = '!\=\_MZAX\_\=([a-zA-Z0-9]{30})\_\=!';
37
+
38
+
39
+ /**
40
+ *
41
+ * @see Mzax_Emarketing_Model_Recipient::getBeaconImage()
42
+ * @var string
43
+ */
44
+ const IMAGE_REGEX = '!emarketing-media/([a-zA-Z0-9]{30})/logo\.gif!i';
45
+
46
+
47
+
48
+ /**
49
+ *
50
+ * @var string
51
+ */
52
+ const LINK_REGEX = '!link-goto/([a-zA-Z0-9]{40})!';
53
+
54
+
55
+
56
+
57
+ /**
58
+ * Try to detect unique beacon hash
59
+ *
60
+ * @param Mzax_Bounce_Message $message
61
+ * @return Ambigous <string, boolean>|unknown|boolean
62
+ */
63
+ public function detectBeaconHash(Mzax_Bounce_Message $message)
64
+ {
65
+ $beacon = $message->header('x-campaign-ref');
66
+ if($beacon) {
67
+ return $beacon;
68
+ }
69
+
70
+
71
+ $content = $message->getContent();
72
+
73
+ if(preg_match(self::BOUNDARY_REGEX, $content, $matches)) {
74
+ return $matches[1];
75
+ }
76
+ if(preg_match(self::IMAGE_REGEX, $content, $matches)) {
77
+ return $matches[1];
78
+ }
79
+
80
+ return false;
81
+ }
82
+
83
+
84
+
85
+
86
+ /**
87
+ * Try to detect unique link hash
88
+ *
89
+ * @param Mzax_Bounce_Message $message
90
+ * @return unknown|boolean
91
+ */
92
+ public function detectLinkHash(Mzax_Bounce_Message $message)
93
+ {
94
+ $content = $message->getContent();
95
+
96
+ if(preg_match(self::LINK_REGEX, $content, $matches)) {
97
+ return $matches[1];
98
+ }
99
+ return false;
100
+ }
101
+
102
+
103
+
104
+ /**
105
+ * Detect original email by references headers
106
+ *
107
+ * @see http://th-h.de/faq/headerfaq.php#technisches
108
+ * @param Mzax_Bounce_Message $message
109
+ * @return Mzax_Emarketing_Model_Outbox_Email|NULL
110
+ */
111
+ public function detectReferenceEmail(Mzax_Bounce_Message $message)
112
+ {
113
+ /* @var $email Mzax_Emarketing_Model_Outbox_Email */
114
+ $email = Mage::getModel('mzax_emarketing/outbox_email');
115
+
116
+ // try to load original email by reference header
117
+ foreach(array_reverse($message->getReferences()) as $messageId) {
118
+ $email->loadByMessageId($messageId);
119
+ if($email->getId()) {
120
+ return $email;
121
+ }
122
+ }
123
+
124
+ // try using in reply header
125
+ $inReplyTo = $message->getHeader('in-reply-to');
126
+ if(preg_match('/<(.+)>/', $inReplyTo, $match)) {
127
+ $email->loadByMessageId($match[1]);
128
+ if($email->getId()) {
129
+ return $email;
130
+ }
131
+ }
132
+ return null;
133
+ }
134
+
135
+
136
+
137
+ /**
138
+ * Try to find an email that has been recently sent
139
+ * to the sender address within the past 60 minutes
140
+ *
141
+ * This might not be fail proof, but lets see how we go
142
+ *
143
+ * @param Mzax_Bounce_Message $message
144
+ * @return Mzax_Emarketing_Model_Outbox_Email|NULL
145
+ */
146
+ public function detectRecientlySentEmail(Mzax_Bounce_Message $message)
147
+ {
148
+ $date = $message->getDate();
149
+ $email = $message->getFrom();
150
+
151
+ $emailId = Mage::getResourceSingleton('mzax_emarketing/outbox_email')->findRecentlySent($email, $date, 60);
152
+ if($emailId) {
153
+ return Mage::getModel('mzax_emarketing/outbox_email')->load($emailId);
154
+ }
155
+ return null;
156
+ }
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+ /**
165
+ * Try to find orignal recipient
166
+ *
167
+ * @return Mzax_Emarketing_Model_Recipient|NULL
168
+ */
169
+ public function findRecipient(Mzax_Bounce_Message $message)
170
+ {
171
+ $email = $this->detectReferenceEmail($message);
172
+ if($email) {
173
+ return $email->getRecipient();
174
+ }
175
+
176
+ $hash = $this->detectBeaconHash($message);
177
+ if($hash) {
178
+ /* @var $recipient Mzax_Emarketing_Model_Recipient */
179
+ $recipient = Mage::getModel('mzax_emarketing/recipient');
180
+ $recipient = $recipient->load($hash, 'beacon_hash');
181
+ if($recipient->getId()) {
182
+ return $recipient;
183
+ }
184
+ }
185
+
186
+ $hash = $this->detectLinkHash($message);
187
+ if($hash) {
188
+ /* @var $linkRef Mzax_Emarketing_Model_Link_Reference */
189
+ $linkRef = Mage::getModel('mzax_emarketing/link_reference');
190
+ $linkRef->load($hash, 'public_id');
191
+
192
+ if($linkRef->getRecipientId()) {
193
+ return $linkRef->getRecipient();
194
+ }
195
+ }
196
+
197
+
198
+ // last try, check if we have send anything to the sender email recently
199
+ $email = $this->detectRecientlySentEmail($message);
200
+ if($email) {
201
+ return $email->getRecipient();
202
+ }
203
+
204
+
205
+ return null;
206
+ }
207
+
208
+
209
+
210
+
211
+ /**
212
+ * Try to detect the original recipiet id and campaign id
213
+ *
214
+ *
215
+ * (non-PHPdoc)
216
+ * @see Mzax_Bounce_Detector_Abstract::inspect()
217
+ */
218
+ public function inspect(Mzax_Bounce_Message $message)
219
+ {
220
+ $recipient = $this->findRecipient($message);
221
+ if($recipient) {
222
+ $recipient->prepare();
223
+ $message->info('recipient_id', $recipient->getId());
224
+ $message->info('campaign_id', $recipient->getCampaignId());
225
+ $message->info('recipient', $recipient->getEmail(), 100);
226
+
227
+ $storeId = Mage::getResourceSingleton('mzax_emarketing/recipient')->getStoreId($recipient->getId());
228
+ if($storeId) {
229
+ $message->info('store_id', $storeId, 100);
230
+ }
231
+
232
+ }
233
+ }
234
+
235
+
236
+
237
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Store.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Detector for store id
26
+ *
27
+ * if no recipient was found we may can still find the right
28
+ * store id by using the To email address
29
+ *
30
+ * @author Jacob Siefer
31
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
+ * @version 0.2.5
33
+ */
34
+ class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Store
35
+ extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
36
+ {
37
+
38
+
39
+
40
+ /**
41
+ * Try to detect the original recipiet id and campaign id
42
+ *
43
+ *
44
+ * (non-PHPdoc)
45
+ * @see Mzax_Bounce_Detector_Abstract::inspect()
46
+ */
47
+ public function inspect(Mzax_Bounce_Message $message)
48
+ {
49
+ $to = strtolower($this->findEmail($message->getHeader('to')));
50
+
51
+ if($store = $this->getStoreByEmail($to)) {
52
+ $message->info('store_id', $store->getId());
53
+ }
54
+ }
55
+
56
+
57
+
58
+ public function getStoreByEmail($email)
59
+ {
60
+ $email = strtolower($email);
61
+ /* @var $store Mage_Core_Model_Store */
62
+
63
+
64
+ /*
65
+ * try to retrieve store by using the email
66
+ */
67
+ foreach(Mage::app()->getStores() as $store) {
68
+ $config = $store->getConfig('trans_email');
69
+ foreach($config as $key => $data) {
70
+ if(isset($data['email']) && strtolower($data['email']) === $email) {
71
+ return $store;
72
+ }
73
+ }
74
+ }
75
+
76
+ /*
77
+ * try to retrieve the store by using the domain
78
+ */
79
+ $domain = trim(strstr($email, '@'), '@');
80
+ foreach(Mage::app()->getStores() as $store) {
81
+ $baseUrl = strtolower($store->getBaseUrl($store::URL_TYPE_WEB));
82
+ $baseUrl = preg_replace('/^(?:https?:\/\/)?(?:www\.)?([^\/]+)(.*)$/i', '$1', $baseUrl);
83
+
84
+ if($baseUrl === $domain) {
85
+ return $store;
86
+ }
87
+ }
88
+
89
+ return null;
90
+ }
91
+
92
+
93
+
94
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Unsubscribe.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Unsubscribe
32
+ extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
33
+ {
34
+
35
+
36
+ /**
37
+ *
38
+ * (non-PHPdoc)
39
+ * @see Mzax_Bounce_Detector_Abstract::inspect()
40
+ */
41
+ public function inspect(Mzax_Bounce_Message $message)
42
+ {
43
+ $subject = trim($message->getSubject());
44
+
45
+ if(preg_match('/^Unsubscribe ([^\s]+) \(([0-9A-Z]+)\)$/i', $subject, $matches)) {
46
+ $email = $matches[1];
47
+ $hash = $matches[2];
48
+
49
+ /* @var $recipient Mzax_Emarketing_Model_Recipient */
50
+ $recipient = Mage::getModel('mzax_emarketing/recipient')->loadByBeacon($hash);
51
+ if($recipient->getId()) {
52
+ $recipient->prepare();
53
+ if(strtolower($recipient->getAddress()) == strtolower($email)) {
54
+ $message->info('recipient_id', $recipient->getId(), 200);
55
+ $message->info('campaign_id', $recipient->getCampaignId(), 200);
56
+ $message->info('recipient', $email, 200);
57
+ $message->info(Mzax_Bounce::TYPE_UNSUBSCRIBE, true);
58
+ $message->info('type', Mzax_Bounce::TYPE_UNSUBSCRIBE);
59
+
60
+ $storeId = Mage::getResourceSingleton('mzax_emarketing/recipient')->getStoreId($recipient->getId());
61
+ if($storeId) {
62
+ $message->info('store_id', $storeId, 100);
63
+ }
64
+
65
+ return true; // stop
66
+ }
67
+ }
68
+
69
+ }
70
+ }
71
+
72
+
73
+
74
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Email.php ADDED
@@ -0,0 +1,473 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @method string getCreatedAt()
26
+ * @method string getHeaders()
27
+ * @method string getIsParsed()
28
+ * @method string getCampaignId()
29
+ * @method string getRecipientId()
30
+ * @method string getSubject()
31
+ * @method string getMessage()
32
+ * @method string getSentAt()
33
+ * @method string getEmail()
34
+ * @method string getType()
35
+ *
36
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setCreatedAt(string)
37
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setHeaders(string)
38
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setContent(string)
39
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setIsParsed(string)
40
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setRecipientId(string)
41
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setCampaignId(string)
42
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setSubject(string)
43
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setMessage(string)
44
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setSentAt(string)
45
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setEmail(string)
46
+ * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setType(string)
47
+ *
48
+ * @method Mzax_Emarketing_Model_Resource_Inbox_Email getResource()
49
+ *
50
+ * @author Jacob Siefer
51
+ *
52
+ */
53
+ class Mzax_Emarketing_Model_Inbox_Email
54
+ extends Mzax_Emarketing_Model_Email
55
+ {
56
+
57
+ const BOUNCE_SOFT = 'SB';
58
+ const BOUNCE_HARD = 'HB';
59
+ const AUTOREPLY = 'AR';
60
+ const NO_BOUNCE = 'NB';
61
+ const UNSUBSCRIBE = 'US';
62
+
63
+ /**
64
+ * Prefix of model events names
65
+ *
66
+ * @var string
67
+ */
68
+ protected $_eventPrefix = 'mzax_emarketing_inbox_email';
69
+
70
+ /**
71
+ * Parameter name in event
72
+ *
73
+ * In observe method you can use $observer->getEvent()->getObject() in this case
74
+ *
75
+ * @var string
76
+ */
77
+ protected $_eventObject = 'email';
78
+
79
+
80
+
81
+ /**
82
+ * Email content
83
+ *
84
+ * @var string
85
+ */
86
+ protected $_content;
87
+
88
+
89
+
90
+ /**
91
+ * Retrieve bounce decoder
92
+ *
93
+ * @return Mzax_Bounce_Detector
94
+ */
95
+ public static function getBounceDecoder()
96
+ {
97
+ static $bounceDecoder;
98
+ if(!$bounceDecoder) {
99
+ $bounceDecoder = new Mzax_Bounce_Detector;
100
+ $bounceDecoder->addDetector(Mage::getModel('mzax_emarketing/inbox_bounce_detector_unsubscribe'), 0);
101
+ $bounceDecoder->addDetector(Mage::getModel('mzax_emarketing/inbox_bounce_detector_recipient'), 1);
102
+ $bounceDecoder->addDetector(Mage::getModel('mzax_emarketing/inbox_bounce_detector_store'), 2);
103
+ }
104
+ return $bounceDecoder;
105
+ }
106
+
107
+
108
+
109
+
110
+
111
+ protected function _construct()
112
+ {
113
+ $this->_init('mzax_emarketing/inbox_email');
114
+ }
115
+
116
+
117
+
118
+ protected function _beforeSave()
119
+ {
120
+ if($this->_content !== null) {
121
+ $this->setSize(strlen($this->_content));
122
+ }
123
+
124
+ return parent::_beforeSave();
125
+ }
126
+
127
+
128
+
129
+
130
+
131
+
132
+ /**
133
+ * Parse the current message
134
+ *
135
+ * Return the parse time
136
+ *
137
+ * @return number
138
+ */
139
+ public function parse()
140
+ {
141
+ $start = microtime(true);
142
+
143
+ $this->getResource()->flagAsParsed($this);
144
+
145
+
146
+ try {
147
+ /* @var $message Mzax_Bounce_Message */
148
+ $message = new Mzax_Bounce_Message($this->getRawData());
149
+ $message->setHeader('created_at', $this->getCreatedAt());
150
+
151
+ $result = self::getBounceDecoder()->inspect($message);
152
+ $result = new Varien_Object($result);
153
+
154
+
155
+ $update = array(
156
+ 'is_parsed' => 1,
157
+ 'email' => $result->getRecipient(),
158
+ 'sent_at' => $result->getSentAt(),
159
+ 'status_code' => $result->getStatus(),
160
+ 'is_arf' => (int) $result->getArf(),
161
+ 'is_autoreply' => (int) $result->getAutoreply(),
162
+ 'arf_type' => $result->getFeedbackType(),
163
+ 'recipient_id' => $result->getRecipientId(),
164
+ 'store_id' => $result->getStoreId(),
165
+ 'campaign_id' => $result->getCampaignId(),
166
+ );
167
+
168
+ $status = $result->getStatus();
169
+ if($status) {
170
+ if(strpos($status, '4.') === 0) {
171
+ $update['type'] = self::BOUNCE_SOFT;
172
+ }
173
+ if(strpos($status, '5.') === 0) {
174
+ $update['type'] = self::BOUNCE_HARD;
175
+ }
176
+ }
177
+ else if($result->getAutoreply()) {
178
+ $update['type'] = self::AUTOREPLY;
179
+ }
180
+ else if($result->getUnsubscribe()) {
181
+ $update['type'] = self::UNSUBSCRIBE;
182
+ /* @see $subscriber Mzax_Emarketing_Helper_Newsletter */
183
+ Mage::helper('mzax_emarketing/newsletter')->unsubscribe($result->getRecipient(), $result->getStoreId(), false);
184
+ }
185
+ else {
186
+ $update['type'] = self::NO_BOUNCE;
187
+ }
188
+
189
+
190
+ if($part = $message->findMinePart(Zend_Mime::TYPE_TEXT)) {
191
+ $text = $part->getDecodedContent();
192
+ }
193
+ else {
194
+ $text = $message->getDecodedContent();
195
+ }
196
+ if($pos = strpos($text, '---')) {
197
+ $text = substr($text, 0, $pos);
198
+ }
199
+ $text = Mage::helper('core/string')->stripTags($text);
200
+ $text = Mage::helper('core/string')->truncate($text, 512);
201
+
202
+ $update['message'] = $text;
203
+ $update['subject'] = $message->getSubject();
204
+
205
+
206
+ $this->addData($update);
207
+ $this->save();
208
+
209
+ Mage::dispatchEvent('mzax_emarketing_inbox_email_parse', array(
210
+ 'email' => $this,
211
+ 'message' => $message,
212
+ 'result' => $result
213
+ ));
214
+
215
+ if($this->shouldForward()) {
216
+ $this->forward($message);
217
+ }
218
+
219
+
220
+ // unsubscribe hard bounces
221
+ if(!$this->getNoUnsubscribe() && $this->getType() == self::BOUNCE_HARD && Mage::getStoreConfigFlag('mzax_emarketing/inbox/unsubscribe_hard_bounce', $this->getStore())) {
222
+ $email = $this->getEmail();
223
+ if($this->getRecipient()) {
224
+ $email = $this->getRecipient()->getEmail();
225
+ }
226
+ Mage::getSingleton('mzax_emarketing/medium_email')->unsubscribe($email, sprintf('%s bounce, email %s', $status, $this->getId()));
227
+ }
228
+ }
229
+ catch(Exception $e) {
230
+ if(Mage::getIsDeveloperMode()) {
231
+ throw $e;
232
+ }
233
+ Mage::logException($e);
234
+ }
235
+
236
+ return microtime(true) - $start;
237
+ }
238
+
239
+
240
+
241
+
242
+
243
+
244
+ /**
245
+ * Forward email
246
+ *
247
+ * @param Mzax_Bounce_Message $message
248
+ * @return boolean
249
+ */
250
+ public function forward(Mzax_Bounce_Message $message = null)
251
+ {
252
+ if(!$message) {
253
+ $message = new Mzax_Bounce_Message($this->getRawData());
254
+ }
255
+
256
+ $mail = $message->forward();
257
+
258
+ $canSend = false;
259
+ foreach($this->getForwardToEmails() as $email) {
260
+ if(Zend_Validate::is($email, 'EmailAddress')) {
261
+ $mail->addTo($email);
262
+ $canSend = true;
263
+ }
264
+ }
265
+
266
+ if(!$canSend) {
267
+ return false;
268
+ }
269
+
270
+
271
+ $sender = $this->getSender();
272
+ $mail->setFrom($sender['email'], $sender['name']);
273
+ $mail->addHeader('X-Mailer', 'Mzax-Emarketing '.Mage::helper('mzax_emarketing')->getVersion());
274
+ $mail->addHeader('X-Originating-IP', Mage::app()->getRequest()->getServer('SERVER_ADDR'));
275
+
276
+
277
+ $this->setMailTransport(null);
278
+ Mage::dispatchEvent('mzax_emarketing_inbox_email_forward', array(
279
+ 'mail' => $mail,
280
+ 'email' => $this,
281
+ 'message' => $message
282
+ ));
283
+
284
+ // in case an event observer has set one
285
+ $transport = $this->getMailTransport();
286
+
287
+ $mail->send($transport);
288
+
289
+ return true;
290
+ }
291
+
292
+
293
+
294
+
295
+ public function report()
296
+ {
297
+ $mail = new Zend_Mail();
298
+
299
+ $sender = $this->getSender();
300
+ $mail->setFrom($sender['email'], $sender['name']);
301
+ $mail->setSubject(sprintf("Bounce Report (%s)", Mage::helper('mzax_emarketing')->getVersion()));
302
+ $mail->setBodyText("The following message appears to be a bounce.\nPlease verify.\n\n");
303
+ $mail->createAttachment($this->getRawData(),
304
+ 'message/rfc822',
305
+ Zend_Mime::DISPOSITION_ATTACHMENT,
306
+ Zend_Mime::ENCODING_BASE64,
307
+ sprintf('bounce.%s.%s.eml', Mage::app()->getRequest()->getServer('SERVER_ADDR'), time()));
308
+ $mail->addTo('mail@jacobsiefer.de');
309
+ $mail->addHeader('X-Mailer', 'Mzax-Emarketing '.Mage::helper('mzax_emarketing')->getVersion());
310
+ $mail->send();
311
+ }
312
+
313
+
314
+
315
+
316
+
317
+ /**
318
+ * Retrieve sender
319
+ *
320
+ * @return array
321
+ */
322
+ public function getSender()
323
+ {
324
+ if($campaign = $this->getCampaign()) {
325
+ return $campaign->getSender();
326
+ }
327
+ $sender = Mage::getStoreConfig('mzax_emarketing/inbox/forward_identity', $this->getStore());
328
+ return array(
329
+ 'name' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/name', $this->getStore()),
330
+ 'email' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/email', $this->getStore()),
331
+ );
332
+ }
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+ /**
341
+ * Retrieve email addresses to forward non-bonce messages
342
+ *
343
+ * @return array
344
+ */
345
+ public function getForwardToEmails()
346
+ {
347
+ $emails = Mage::getStoreConfig('mzax_emarketing/inbox/forward_emails', $this->getStore());
348
+ $emails = explode(',', $emails);
349
+ $emails = array_map('trim', $emails);
350
+
351
+ $campaign = $this->getCampaign();
352
+ if($campaign) {
353
+ $campaignEmails = $campaign->getMediumData()->getForwardEmails();
354
+ if(!empty($campaignEmails)) {
355
+ $campaignEmails = explode(',', $campaignEmails);
356
+ $emails = array_merge($emails, $campaignEmails);
357
+ }
358
+ }
359
+
360
+ $emails = array_map('trim', $emails);
361
+ $emails = array_map('strtolower', $emails);
362
+ $emails = array_filter($emails);
363
+ $emails = array_unique($emails);
364
+
365
+ return $emails;
366
+ }
367
+
368
+
369
+
370
+
371
+ /**
372
+ * Should this message get forwarded
373
+ *
374
+ * @return boolean
375
+ */
376
+ public function shouldForward()
377
+ {
378
+ if(!$this->getIsParsed() || $this->getNoForward()) {
379
+ return false;
380
+ }
381
+ if($this->isARF() || $this->isAutoreply() || $this->isBounce()) {
382
+ return false;
383
+ }
384
+ return true;
385
+ }
386
+
387
+
388
+
389
+
390
+ /**
391
+ * Load email content
392
+ *
393
+ * @return string
394
+ */
395
+ public function getContent()
396
+ {
397
+ if($this->_content === null && $this->getId()) {
398
+ $file = $this->getResource()->getContentFile($this->getId());
399
+ if(file_exists($file)) {
400
+ $this->_content = file_get_contents($file);
401
+ }
402
+ else {
403
+ $this->_content = (string) $this->getData('content');
404
+ }
405
+ }
406
+ return $this->_content;
407
+ }
408
+
409
+
410
+
411
+
412
+ /**
413
+ * Retrieve full raw email data
414
+ *
415
+ * @return string
416
+ */
417
+ public function getRawData()
418
+ {
419
+ return $this->getHeaders() . Zend_Mime::LINEEND . $this->getContent();
420
+ }
421
+
422
+
423
+ /**
424
+ * Is already parsed
425
+ *
426
+ * @return boolean
427
+ */
428
+ public function isParsed()
429
+ {
430
+ return (bool) $this->getData('is_parsed');
431
+ }
432
+
433
+
434
+ /**
435
+ * Is Bounce (soft or hard)
436
+ *
437
+ * @return boolean
438
+ */
439
+ public function isBounce()
440
+ {
441
+ switch($this->getData('type')) {
442
+ case self::BOUNCE_HARD:
443
+ case self::BOUNCE_SOFT:
444
+ return true;
445
+ }
446
+ return false;
447
+ }
448
+
449
+
450
+ /**
451
+ * Is ARF (aka Feedback Loop)
452
+ *
453
+ * @return boolean
454
+ */
455
+ public function isARF()
456
+ {
457
+ return (bool) $this->getData('is_arf');
458
+ }
459
+
460
+
461
+
462
+ /**
463
+ * Is autoreply
464
+ *
465
+ * @return boolean
466
+ */
467
+ public function isAutoreply()
468
+ {
469
+ return (bool) $this->getData('is_autoreply');
470
+ }
471
+
472
+
473
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Email/Collector.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Inbox_Email_Collector
33
+ {
34
+
35
+
36
+
37
+ /**
38
+ * Retrieve puller
39
+ *
40
+ * @return Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract
41
+ */
42
+ public function getPuller()
43
+ {
44
+ return Mage::getModel('mzax_emarketing/inbox_email_pull_storage');
45
+ }
46
+
47
+
48
+
49
+
50
+ /**
51
+ * Collect new messages from inbox
52
+ *
53
+ * Returns the number of new messages found
54
+ *
55
+ * @return integer
56
+ */
57
+ public function collect()
58
+ {
59
+ $puller = $this->getPuller();
60
+ $messages = $puller->pull($this);
61
+
62
+ return $messages;
63
+ }
64
+
65
+
66
+
67
+ /**
68
+ * Test current setup
69
+ *
70
+ * @return boolean
71
+ */
72
+ public function test()
73
+ {
74
+ $puller = $this->getPuller();
75
+ if($puller) {
76
+ return $puller->test();
77
+ }
78
+ return false;
79
+ }
80
+
81
+
82
+
83
+
84
+
85
+ /**
86
+ *
87
+ *
88
+ * @param string $header
89
+ * @param string $content
90
+ * @return Mzax_Emarketing_Model_Inbox_Bounce_Collector
91
+ */
92
+ public function add($header, $content)
93
+ {
94
+ /* @var $resource Mzax_Emarketing_Model_Resource_Inbox_Email */
95
+ $resource = Mage::getResourceModel('mzax_emarketing/inbox_email');
96
+ $resource->insertEmail($header, $content);
97
+ return true;
98
+ }
99
+
100
+
101
+
102
+
103
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Abstract.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ abstract class Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract extends Varien_Object
33
+ {
34
+
35
+
36
+ abstract function pull(Mzax_Emarketing_Model_Inbox_Email_Collector $collector);
37
+
38
+
39
+ abstract function test();
40
+
41
+
42
+ }
app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Storage.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Inbox_Email_Pull_Storage
33
+ extends Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract
34
+ {
35
+
36
+
37
+ protected $_storageAdapter = 'Zend_Mail_Storage_Pop3';
38
+
39
+
40
+
41
+
42
+ /**
43
+ *
44
+ * @var Zend_Mail_Storage_Abstract
45
+ */
46
+ protected $_storage;
47
+
48
+
49
+
50
+ /**
51
+ * Retrieve storage config settings
52
+ *
53
+ * @return array
54
+ */
55
+ public function getConfig()
56
+ {
57
+ $config = array();
58
+ $config['host'] = Mage::getStoreConfig('mzax_emarketing/inbox/hostname');
59
+ $config['user'] = Mage::getStoreConfig('mzax_emarketing/inbox/username');
60
+ $config['password'] = Mage::getStoreConfig('mzax_emarketing/inbox/password');
61
+ $config['port'] = Mage::getStoreConfig('mzax_emarketing/inbox/port');
62
+ $config['ssl'] = Mage::getStoreConfigFlag('mzax_emarketing/inbox/ssl');
63
+
64
+ return $config;
65
+ }
66
+
67
+
68
+
69
+ public function test()
70
+ {
71
+ try {
72
+ $adapter = $this->getStorage();
73
+ $adapter->countMessages();
74
+ return true;
75
+ }
76
+ catch(Exception $e) {
77
+ return false;
78
+ }
79
+ }
80
+
81
+
82
+
83
+
84
+
85
+ /**
86
+ * Set storage adapter class
87
+ *
88
+ * @param string $adapter
89
+ * @return Mzax_Emarketing_Model_Inbox_Bounce_Pull_Storage
90
+ */
91
+ public function setStorageAdapter($adapter)
92
+ {
93
+ if($this->_storageAdapter !== $adapter) {
94
+ $this->_storageAdapter = $adapter;
95
+ $this->_storage = null;
96
+ }
97
+ return $this;
98
+ }
99
+
100
+
101
+
102
+ /**
103
+ * Retrieve storage adapter
104
+ *
105
+ * @throws Exception
106
+ * @return Zend_Mail_Storage_Abstract
107
+ */
108
+ public function getStorage()
109
+ {
110
+ if(!$this->_storage) {
111
+
112
+ $adapter = Mage::getStoreConfig('mzax_emarketing/inbox/storage_type');
113
+ if(!$adapter) {
114
+ $adapter = $this->_storageAdapter;
115
+ }
116
+
117
+ if(empty($adapter) || !class_exists($adapter)) {
118
+ throw new Exception("No such email storage adapter ($adapter)");
119
+ }
120
+ $this->_storage = new $adapter($this->getConfig());
121
+ if(!$this->_storage instanceof Zend_Mail_Storage_Abstract) {
122
+ throw new Exception("Storage adapter '$adapter' does not extend from 'Zend_Mail_Storage_Abstract'");
123
+ }
124
+ }
125
+ return $this->_storage;
126
+ }
127
+
128
+
129
+
130
+ /**
131
+ * Maximum size of email for retrieving.
132
+ *
133
+ * Prevent large emails from crashing the php script
134
+ *
135
+ * @return number
136
+ */
137
+ public function getMaxMessageSize()
138
+ {
139
+ $size = (float) Mage::getStoreConfig('mzax_emarketing/inbox/max_download_size');
140
+ $size = max($size, 0.5);
141
+
142
+ return min(1024*1024 * $size, 16777000 /* db limit */);
143
+ }
144
+
145
+
146
+
147
+
148
+
149
+ /**
150
+ * Connect to storage and retrieve emails
151
+ *
152
+ */
153
+ public function pull(Mzax_Emarketing_Model_Inbox_Email_Collector $collector)
154
+ {
155
+ $adapter = $this->getStorage();
156
+ $maxSize = $this->getMaxMessageSize();
157
+
158
+ $messages = 0;
159
+
160
+ foreach($adapter->getUniqueId() as $uid) {
161
+ try {
162
+ $id = $adapter->getNumberByUniqueId($uid);
163
+
164
+ $size = $adapter->getSize($id);
165
+ $header = $adapter->getRawHeader($id);
166
+
167
+ if($size > $maxSize) {
168
+ $content = "Mzaz Emarketing: Email content size ($size) exceeded the maximum content size of $maxSize.";
169
+ Mage::log($content);
170
+ }
171
+ else {
172
+ $content = $adapter->getRawContent($id);
173
+ }
174
+
175
+ $messages++;
176
+ $collector->add($header, $content);
177
+ $adapter->removeMessage($adapter->getNumberByUniqueId($uid));
178
+ }
179
+ catch(Exception $e) {
180
+ if(Mage::getIsDeveloperMode()) {
181
+ throw $e;
182
+ }
183
+ Mage::logException($e);
184
+ }
185
+ }
186
+
187
+ return $messages;
188
+ }
189
+
190
+
191
+ }
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
app/code/community/Mzax/Emarketing/Model/Link.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ *
28
+ * @method Mzax_Emarketing_Model_Link setLinkGroupId(string)
29
+ * @method Mzax_Emarketing_Model_Link setLinkHash(string)
30
+ * @method Mzax_Emarketing_Model_Link setUrl(string)
31
+ * @method Mzax_Emarketing_Model_Link setAnchor(string)
32
+ * @method Mzax_Emarketing_Model_Link setOptout(boolean)
33
+ *
34
+ * @method string getLinkGroupId()
35
+ * @method string getLinkHash()
36
+ * @method string getUrl()
37
+ * @method string getAnchor()
38
+ * @method string getOptout()
39
+ *
40
+ *
41
+ * @method Mzax_Emarketing_Model_Resource_Link getResource()
42
+ *
43
+ * @author Jacob Siefer
44
+ *
45
+ */
46
+ class Mzax_Emarketing_Model_Link extends Mage_Core_Model_Abstract
47
+ {
48
+
49
+
50
+ /**
51
+ * Prefix of model events names
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_eventPrefix = 'mzax_emarketing_link';
56
+
57
+ /**
58
+ * Parameter name in event
59
+ *
60
+ * In observe method you can use $observer->getEvent()->getObject() in this case
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_eventObject = 'link';
65
+
66
+
67
+
68
+
69
+ protected function _construct()
70
+ {
71
+ $this->_init('mzax_emarketing/link');
72
+ }
73
+
74
+
75
+
76
+
77
+
78
+ /**
79
+ * Try loading url model by url
80
+ *
81
+ * @param string $url
82
+ * @param string $anchor
83
+ * @return Mzax_Emarketing_Model_Url
84
+ */
85
+ public function loadByUrl($url, $anchor)
86
+ {
87
+ $this->getResource()->loadByUrl($this, $url, $anchor);
88
+ return $this;
89
+ }
90
+
91
+
92
+ /**
93
+ * Load or initialize new link instance
94
+ *
95
+ * @param string $url
96
+ * @param string $anchor
97
+ */
98
+ public function init($url, $anchor)
99
+ {
100
+ $this->loadByUrl($url, $anchor);
101
+
102
+ if(!$this->getId()) {
103
+ if(preg_match('!unsubscribe!i', $url.$anchor)) {
104
+ $this->setOptout(true);
105
+ }
106
+ $this->save();
107
+ }
108
+ return $this;
109
+ }
110
+
111
+
112
+ }
app/code/community/Mzax/Emarketing/Model/Link/Reference.php ADDED
@@ -0,0 +1,425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ * @method Mzax_Emarketing_Model_Resource_Link_Reference getResource()
29
+ * @method string getLinkId()
30
+ * @method string getRecipientId()
31
+ * @method string getPublicId()
32
+ *
33
+ * @author Jacob Siefer
34
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
+ * @version 0.2.5
36
+ */
37
+ class Mzax_Emarketing_Model_Link_Reference extends Mage_Core_Model_Abstract
38
+ {
39
+
40
+
41
+ /**
42
+ * Prefix of model events names
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_eventPrefix = 'mzax_emarketing_link_reference';
47
+
48
+
49
+ /**
50
+ * Parameter name in event
51
+ *
52
+ * In observe method you can use $observer->getEvent()->getObject() in this case
53
+ *
54
+ * @var string
55
+ */
56
+ protected $_eventObject = 'reference';
57
+
58
+
59
+ /**
60
+ * url model
61
+ *
62
+ * @var Mzax_Emarketing_Model_Link
63
+ */
64
+ protected $_link;
65
+
66
+
67
+ /**
68
+ * recipient model
69
+ *
70
+ * @var Mzax_Emarketing_Model_Recipient
71
+ */
72
+ protected $_recipient;
73
+
74
+
75
+
76
+
77
+
78
+ protected function _construct()
79
+ {
80
+ $this->_init('mzax_emarketing/link_reference');
81
+ }
82
+
83
+
84
+
85
+
86
+ /**
87
+ * Load public id or create new if non available
88
+ *
89
+ * @return Mzax_Emarketing_Model_Link_Reference
90
+ */
91
+ public function loadPublicId()
92
+ {
93
+ if(!$this->getPublicId() && $this->getLinkId() && $this->getRecipientId()) {
94
+ $this->_getResource()->loadPublicId($this, $this->getLinkId(), $this->getRecipientId());
95
+ }
96
+ if(!$this->getPublicId()) {
97
+ $this->setPublicId( $this->makePublicKey($this->getLink()));
98
+ }
99
+ return $this;
100
+ }
101
+
102
+
103
+ /**
104
+ * Make random public key
105
+ *
106
+ * @param string $link
107
+ * @return string
108
+ */
109
+ public function makePublicKey($link)
110
+ {
111
+ $hash = md5($link->getId() .
112
+ $link->getLinkHash() .
113
+ mt_rand(0, 99999999) .
114
+ microtime());
115
+
116
+ return Mage::helper('mzax_emarketing')->compressHash($hash);
117
+ }
118
+
119
+
120
+
121
+ protected function _beforeSave()
122
+ {
123
+ // make sure the link is saved
124
+ if( $this->_link && !$this->_link->getId()) {
125
+ $this->_link->save();
126
+ }
127
+ if($this->_link) {
128
+ $this->setLinkId($this->_link->getId());
129
+ }
130
+ if($this->_recipient) {
131
+ $this->setRecipientId($this->_recipient->getId());
132
+ }
133
+
134
+ if(!$this->getLinkId()) {
135
+ throw new Exception("Unable to save link reference, no link id set");
136
+ }
137
+
138
+ $this->loadPublicId();
139
+
140
+ parent::_beforeSave();
141
+ }
142
+
143
+
144
+
145
+
146
+
147
+
148
+ /**
149
+ * Retrieve link model
150
+ *
151
+ * @return Mzax_Emarketing_Model_Link
152
+ */
153
+ public function getLink()
154
+ {
155
+ if(!$this->_link) {
156
+ $this->_link = Mage::getModel('mzax_emarketing/link');
157
+ $this->_link->load($this->getLinkId());
158
+ }
159
+ return $this->_link;
160
+ }
161
+
162
+
163
+
164
+ /**
165
+ *
166
+ * @param Mzax_Emarketing_Model_Link|string $url
167
+ * @param string $anchor
168
+ * @throws BadMethodCallException
169
+ * @return Mzax_Emarketing_Model_Link_Reference
170
+ */
171
+ public function setLink($link, $anchor)
172
+ {
173
+ if(is_string($link)) {
174
+ $this->_link = Mage::getModel('mzax_emarketing/link')->init($link, $anchor);
175
+ }
176
+ else if($link instanceof Mzax_Emarketing_Model_Link) {
177
+ $this->_link = $link;
178
+ }
179
+ else {
180
+ throw new BadMethodCallException("Invalid link argument");
181
+ }
182
+
183
+ $this->setLinkId($this->_link->getId());
184
+ $this->loadPublicId();
185
+
186
+ return $this;
187
+ }
188
+
189
+
190
+
191
+ /**
192
+ * Retrieve recipient
193
+ *
194
+ * @return Mzax_Emarketing_Model_Recipient
195
+ */
196
+ public function getRecipient()
197
+ {
198
+ if(!$this->_recipient) {
199
+ $this->_recipient = Mage::getModel('mzax_emarketing/recipient');
200
+ $this->_recipient->load($this->getRecipientId());
201
+ }
202
+ return $this->_recipient;
203
+ }
204
+
205
+
206
+
207
+ /**
208
+ * Set recipient model
209
+ *
210
+ * @param Mzax_Emarketing_Model_Recipient $recipient
211
+ * @return Mzax_Emarketing_Model_Link
212
+ */
213
+ public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
214
+ {
215
+ $this->_recipient = $recipient;
216
+ $this->setRecipientId($recipient->getId());
217
+
218
+ return $this;
219
+ }
220
+
221
+
222
+
223
+
224
+ /**
225
+ * Retrieve campaign
226
+ *
227
+ * @return Mzax_Emarketing_Model_Campaign
228
+ */
229
+ public function getCampagin()
230
+ {
231
+ return $this->getRecipient()->getCampaign();
232
+ }
233
+
234
+
235
+
236
+
237
+ /**
238
+ * Retrieve redirect URL used in emails
239
+ *
240
+ * @param array $params
241
+ * @return string
242
+ */
243
+ public function getRedirectUrl($params = array())
244
+ {
245
+ $store = $this->getCampagin()->getStore();
246
+
247
+ $url = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . "link-goto/".$this->getPublicId();
248
+
249
+ if(!empty($params)) {
250
+ $url .= '?' . http_build_query($params);
251
+ }
252
+ return $url;
253
+ }
254
+
255
+
256
+
257
+
258
+ /**
259
+ * Retreive target url
260
+ *
261
+ * @return string
262
+ */
263
+ public function getTargetUrl()
264
+ {
265
+ $storeId = $this->getCampagin()->getStoreId();
266
+
267
+ $url = $this->getLink()->getUrl();
268
+
269
+ if(Mage::getStoreConfigFlag('mzax_emarketing/google_analytics/enable', $storeId)) {
270
+
271
+ $utmParams = array();
272
+ $utmParams['utm_source'] = $this->getUtmSource();
273
+ $utmParams['utm_medium'] = $this->getUtmMedium();
274
+ $utmParams['utm_campaign'] = $this->getUtmCampaign();
275
+
276
+ if($content = $this->getUtmContent()) {
277
+ $utmParams['utm_content'] = $content;
278
+ }
279
+ if($term = $this->getUtmTerm()) {
280
+ $utmParams['utm_term'] = $term;
281
+ }
282
+
283
+ $url .= (strpos($url, '?') ? '&' : '?') . http_build_query($utmParams);
284
+ }
285
+
286
+ return $url;
287
+ }
288
+
289
+
290
+
291
+ /**
292
+ * Source is globaly set
293
+ *
294
+ * @return string
295
+ */
296
+ public function getUtmSource()
297
+ {
298
+ return Mage::getStoreConfig(
299
+ 'mzax_emarketing/google_analytics/utm_source',
300
+ $this->getCampagin()->getStoreId());
301
+ }
302
+
303
+
304
+ /**
305
+ * Medium is globaly set
306
+ *
307
+ * @todo should be defined by campaign medium?
308
+ * @return string
309
+ */
310
+ public function getUtmMedium()
311
+ {
312
+ return Mage::getStoreConfig(
313
+ 'mzax_emarketing/google_analytics/utm_medium',
314
+ $this->getCampagin()->getStoreId());
315
+ }
316
+
317
+
318
+
319
+ /**
320
+ * Retrieve the utm term
321
+ * Use variation name
322
+ *
323
+ * @return string
324
+ */
325
+ public function getUtmContent()
326
+ {
327
+ $variationId = $this->getRecipient()->getVariationId();
328
+
329
+ switch($variationId) {
330
+ case Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL:
331
+ return '[Original]';
332
+ case Mzax_Emarketing_Model_Campaign_Variation::NONE:
333
+ return '[None]';
334
+ }
335
+
336
+ $variation = $this->getCampagin()->getVariation($variationId);
337
+ if($variation) {
338
+ return $variation->getName();
339
+ }
340
+
341
+ return '[N/A]';
342
+ }
343
+
344
+
345
+
346
+ /**
347
+ * Use a stripped version of the link anchor text as term
348
+ *
349
+ * @return string
350
+ */
351
+ public function getUtmTerm()
352
+ {
353
+ $anchor = trim($this->getLink()->getAnchor());
354
+
355
+ if($this->getLink()->getUrl() === $anchor) {
356
+ return "DIRECT LINK";
357
+ }
358
+
359
+ // check for any image tag <img src="foo" alt="bar" />
360
+ $anchor = preg_replace_callback('/<img\s+(.*)\s*\/?>/i', function($matches) {
361
+
362
+ // if an alt tag is given, use it
363
+ if(preg_match('/alt=("|\')(.*?)(?:\1)/i',$matches[1], $m)) {
364
+ return "IMG[{$m[2]}]";
365
+ }
366
+
367
+ // otherwise use the image src but only the basename to keep it short
368
+ if(preg_match('/src=("|\')(.*?)(?:\1)/i',$matches[1], $m)) {
369
+ $src = basename($m[2]);
370
+ return "IMG[{$src}]";
371
+ }
372
+
373
+ return 'IMG';
374
+
375
+ }, $anchor);
376
+
377
+ return strip_tags($anchor);
378
+ }
379
+
380
+
381
+
382
+
383
+
384
+ /**
385
+ * Use the campaign name
386
+ *
387
+ * @todo Add extra field for GA name
388
+ * @return string
389
+ */
390
+ public function getUtmCampaign()
391
+ {
392
+ $name = $this->getCampagin()->getName();
393
+ return $name;
394
+ }
395
+
396
+
397
+
398
+
399
+
400
+ /**
401
+ * Log click for this link so we know that someone clicked
402
+ * on a link inside an email
403
+ *
404
+ * @param Zend_Controller_Request_Http $request
405
+ * @param mixed $clickId
406
+ * @param mixed $eventId
407
+ * @return Mzax_Emarketing_Model_Link_Reference
408
+ */
409
+ public function captureClick(Zend_Controller_Request_Http $request = null, &$clickId = null, &$eventId = null)
410
+ {
411
+ $eventId = $this->getRecipient()->captureClick($this->getRequest());
412
+ $clickId = $this->getResource()->captureClick($this, $eventId);
413
+ return $this;
414
+ }
415
+
416
+
417
+
418
+ public function __toString()
419
+ {
420
+ return $this->getRedirectUrl();
421
+ }
422
+
423
+
424
+
425
+ }
app/code/community/Mzax/Emarketing/Model/Medium.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Factory class for meidums
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Medium implements Mage_Eav_Model_Entity_Attribute_Source_Interface
34
+ {
35
+
36
+ /**
37
+ *
38
+ * @var Mage_Core_Model_Config_Element
39
+ */
40
+ protected $_config;
41
+
42
+
43
+
44
+ /**
45
+ *
46
+ * @var array
47
+ */
48
+ protected $_mediums;
49
+
50
+
51
+
52
+ /**
53
+ * Retrieve Medium
54
+ *
55
+ * @param string $name
56
+ * @throws Exception
57
+ * @return Mzax_Emarketing_Model_Medium_Abstract
58
+ */
59
+ public function factory($name)
60
+ {
61
+ $config = $this->getConfig();
62
+ if(!isset($config->$name)) {
63
+ throw new Exception("No such email provider ({$name}) found");
64
+ }
65
+ $config = $config->$name;
66
+
67
+
68
+ $mediumClass = $config->getClassName();
69
+
70
+ if(!class_exists($mediumClass)) {
71
+ throw new Exception("Meidum config found, but model ($mediumClass) was not found");
72
+ }
73
+
74
+ /* @var $medium Mzax_Emarketing_Model_Medium_Abstract */
75
+ $medium = new $mediumClass;
76
+
77
+ return $medium;
78
+ }
79
+
80
+
81
+
82
+ /**
83
+ * Retrieve All options
84
+ *
85
+ * @return array
86
+ */
87
+ public function getAllOptions($withEmpty = true, $defaultValues = false)
88
+ {
89
+ $options = array();
90
+
91
+ /* @var medium Mzax_Emarketing_Model_Medium_Abstract */
92
+ foreach($this->getMediums() as $medium => $title) {
93
+ $options[] = array(
94
+ 'value' => $medium,
95
+ 'label' => $title
96
+ );
97
+ }
98
+ if ($withEmpty) {
99
+ array_unshift($options, array('label'=>'', 'value'=>''));
100
+ }
101
+
102
+ return $options;
103
+ }
104
+
105
+
106
+
107
+
108
+ /**
109
+ * Retrieve all mediums
110
+ *
111
+ * @return array
112
+ */
113
+ public function getMediums()
114
+ {
115
+ if(!$this->_mediums) {
116
+ $this->_mediums = array();
117
+
118
+ foreach($this->getConfig()->children() as $name => $cfg) {
119
+ $this->_mediums[$name] = (string) $cfg->title;
120
+ }
121
+ }
122
+ return $this->_mediums;
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+
130
+ /**
131
+ * Retrieve Option value text
132
+ *
133
+ * @param string $value
134
+ * @return mixed
135
+ */
136
+ public function getOptionText($value)
137
+ {
138
+ $options = $this->getMediums();
139
+ if(isset($options[$value])) {
140
+ return $options[$value];
141
+ }
142
+ return false;
143
+ }
144
+
145
+
146
+
147
+
148
+ /**
149
+ * Retrieve email marketing collection config
150
+ *
151
+ * @return Mage_Core_Model_Config_Element
152
+ */
153
+ public function getConfig()
154
+ {
155
+ if(!$this->_config) {
156
+ $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/mediums');
157
+ }
158
+ return $this->_config;
159
+ }
160
+
161
+
162
+
163
+ }
app/code/community/Mzax/Emarketing/Model/Medium/Abstract.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ abstract class Mzax_Emarketing_Model_Medium_Abstract
34
+ {
35
+ /**
36
+ * Unique Medium ID
37
+ *
38
+ * @return string
39
+ */
40
+ abstract public function getMediumId();
41
+
42
+
43
+ /**
44
+ * Send a single recipient
45
+ *
46
+ * @param Mzax_Emarketing_Model_Recipient $recipient
47
+ */
48
+ abstract public function sendRecipient(Mzax_Emarketing_Model_Recipient $recipient);
49
+
50
+
51
+
52
+ public function prepareRecipientGrid(Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid)
53
+ {
54
+ }
55
+
56
+
57
+
58
+ public function prepareCampaignTabs(Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs)
59
+ {
60
+ }
61
+
62
+
63
+ public function initSettingsForm(Varien_Data_Form $form, Mzax_Emarketing_Model_Campaign $campaign)
64
+ {
65
+
66
+ }
67
+
68
+
69
+
70
+ /**
71
+ *
72
+ * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
73
+ */
74
+ public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
75
+ {
76
+ }
77
+
78
+
79
+
80
+
81
+
82
+
83
+ /**
84
+ * Send message to all pending recipients
85
+ *
86
+ * @param Mzax_Emarketing_Model_Campaign $campaign
87
+ * @param Varien_Object $options
88
+ * @throws Exception
89
+ * @return number
90
+ */
91
+ public function sendRecipients(Mzax_Emarketing_Model_Campaign $campaign, Varien_Object $options)
92
+ {
93
+ $recipients = $campaign->getPendingRecipients();
94
+ $recipients->setPageSize($options->getMaximum());
95
+
96
+ $start = time();
97
+
98
+ $prepared = 0;
99
+ $timeout = (int) $options->getTimeout();
100
+
101
+ /* @var $recipient Mzax_Emarketing_Model_Recipient */
102
+ foreach($recipients as $recipient) {
103
+ try {
104
+ $this->sendRecipient($recipient);
105
+ $prepared++;
106
+ }
107
+ catch(Exception $e) {
108
+ $recipient->logException($e);
109
+ if($options->getBreakOnError()) {
110
+ throw $e;
111
+ }
112
+ Mage::logException($e);
113
+ }
114
+ $recipient->isPrepared(true);
115
+ $recipient->save();
116
+
117
+ if($timeout && time()-$start > $timeout) {
118
+ break;
119
+ }
120
+ }
121
+ return $prepared;
122
+ }
123
+
124
+
125
+ }
app/code/community/Mzax/Emarketing/Model/Medium/Email.php ADDED
@@ -0,0 +1,333 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Abstract
33
+ {
34
+
35
+
36
+ /**
37
+ * Retrieve medium id
38
+ *
39
+ * @return string
40
+ */
41
+ public function getMediumId()
42
+ {
43
+ return 'email';
44
+ }
45
+
46
+
47
+
48
+
49
+
50
+ /**
51
+ *
52
+ * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
53
+ * @return void
54
+ */
55
+ public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
56
+ {
57
+ $hlp = Mage::helper('mzax_emarketing');
58
+
59
+ $snippets->addVar('urls.unsubscribe', $hlp->__('Unsubscribe link'));
60
+ $snippets->addVar('urls.broswer_view', $hlp->__('View in browser link'));
61
+ $snippets->addVar('subject', $hlp->__('Email Subject'));
62
+ $snippets->addVar('address', $hlp->__('Recipient Address'));
63
+ $snippets->addVar('email', $hlp->__('Recipient Email'));
64
+ }
65
+
66
+
67
+
68
+
69
+
70
+ /**
71
+ * Prepare recipient
72
+ *
73
+ * @param Mzax_Emarketing_Model_Recipient $recipient
74
+ */
75
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
76
+ {
77
+ $recipient->setAddress( $recipient->getEmail() );
78
+
79
+ $recipient->addUrl('unsubscribe', 'mzax_emarketing/unsubscribe');
80
+ $recipient->addUrl('browser_view', 'mzax_emarketing/email');
81
+ }
82
+
83
+
84
+
85
+ /**
86
+ *
87
+ *
88
+ * @see Mzax_Emarketing_Model_Medium_Abstract::prepareCampaignTabs()
89
+ * @param Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs
90
+ */
91
+ public function prepareCampaignTabs(Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs)
92
+ {
93
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
94
+ $campaign = Mage::registry('current_campaign');
95
+
96
+
97
+ if($count = $campaign->countInbox()) {
98
+ $tabs->addTab('inbox', array(
99
+ 'label' => $tabs->__('Inbox (%s)', $count),
100
+ 'class' => 'ajax',
101
+ 'url' => $tabs->getUrl('*/admin_inbox/campaignGrid', array('_current' => true)),
102
+ ));
103
+ }
104
+
105
+ if($count = $campaign->countOutbox()) {
106
+ $tabs->addTab('outbox', array(
107
+ 'label' => $tabs->__('Outbox (%s)', $count),
108
+ 'class' => 'ajax',
109
+ 'url' => $tabs->getUrl('*/admin_outbox/campaignGrid', array('_current' => true)),
110
+ ));
111
+ }
112
+ }
113
+
114
+
115
+
116
+ /**
117
+ * Init settings form
118
+ *
119
+ * @param Varien_Data_Form $form
120
+ * @param Mzax_Emarketing_Model_Campaign $campaign
121
+ */
122
+ public function initSettingsForm(Varien_Data_Form $form, Mzax_Emarketing_Model_Campaign $campaign)
123
+ {
124
+ $helper = Mage::helper('mzax_emarketing');
125
+
126
+
127
+ $fieldset = $form->addFieldset('email_options', array(
128
+ 'legend' => $helper->__('Email Specific Options')
129
+ ), 'base_fieldset');
130
+
131
+
132
+ $fieldset->addField('prerender', 'select', array(
133
+ 'label' => $helper->__('Pre-Render'),
134
+ 'note' => $helper->__("If enabled, email will get pre rendered, cached and then only the basic {{var}} expressions will get parsed. If your content is static or only uses var expressions. Enabling this can increase the render performance."),
135
+ 'name' => 'medium_data[prerender]',
136
+ 'options' => array(
137
+ '0' => $helper->__('Disabled'),
138
+ '1' => $helper->__('Enabled'),
139
+ ),
140
+ 'value' => 0
141
+ ));
142
+
143
+
144
+ $fieldset->addField('forward_emails', 'text', array(
145
+ 'name' => 'medium_data[forward_emails]',
146
+ 'label' => $helper->__('Forward Email'),
147
+ 'note' => $helper->__("All non-auto email replies will get forward to this email address.")
148
+ ));
149
+
150
+ }
151
+
152
+
153
+
154
+
155
+ /**
156
+ * Prepare Recipient Grid
157
+ *
158
+ * @param Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid
159
+ * @return void
160
+ */
161
+ public function prepareRecipientGrid(Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid)
162
+ {
163
+ $campaign = $grid->getCampaign();
164
+
165
+ $previewAction = array(
166
+ 'target' => "campaign_{$campaign->getId()}_{id}",
167
+ 'url' => array(
168
+ 'base' => '*/admin_campaign/preview',
169
+ 'params' => array(
170
+ 'id' => $grid->getCampaign()->getId()
171
+ ),
172
+ ),
173
+ 'field' => 'entity',
174
+ 'popup' => true,
175
+ 'caption' => $grid->__('Preview')
176
+ );
177
+ $sendAction = array(
178
+ 'target' => "campaign_{$campaign->getId()}_{id}",
179
+ 'url' => array(
180
+ 'base' => '*/admin_campaign/sendTestMail',
181
+ 'params' => array(
182
+ 'id' => $grid->getCampaign()->getId()
183
+ ),
184
+ ),
185
+ 'field' => 'recipient',
186
+ 'popup' => true,
187
+ 'caption' => $grid->__('Send Test Email')
188
+ );
189
+
190
+ if($campaign->hasVariations())
191
+ {
192
+ $sendAction['caption'] = $previewAction['caption'] = $grid->__('[Orignal]');
193
+
194
+ $previewAction = array(
195
+ 'caption' => $grid->__('Preview'),
196
+ 'actions' => array($previewAction)
197
+ );
198
+ $sendAction = array(
199
+ 'caption' => $grid->__('Send Test Email'),
200
+ 'actions' => array($sendAction)
201
+ );
202
+
203
+ /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
204
+ foreach($campaign->getVariations() as $variation)
205
+ {
206
+ $params = array(
207
+ 'id' => $campaign->getId(),
208
+ 'variation' => $variation->getId()
209
+ );
210
+
211
+ $previewAction['actions'][] = array(
212
+ 'target' => "campaign_{$campaign->getId()}_{$variation->getId()}_{id}",
213
+ 'url' => array(
214
+ 'base' => '*/admin_campaign/preview',
215
+ 'params' => $params,
216
+ ),
217
+ 'field' => 'entity',
218
+ 'popup' => true,
219
+ 'caption' => $variation->getName()
220
+ );
221
+ $sendAction['actions'][] = array(
222
+ 'url' => array(
223
+ 'base' => '*/admin_campaign/sendTestMail',
224
+ 'params' => $params,
225
+ ),
226
+ 'field' => 'recipient',
227
+ 'popup' => true,
228
+ 'caption' => $variation->getName()
229
+ );
230
+ }
231
+ }
232
+
233
+ $grid->addColumn('action', array(
234
+ 'header' => $grid->__('Action'),
235
+ 'index' =>'id',
236
+ 'getter' => 'getId',
237
+ 'renderer' => 'mzax_emarketing/grid_column_renderer_action',
238
+ 'type' => 'action',
239
+ 'sortable' => false,
240
+ 'filter' => false,
241
+ 'no_link' => true,
242
+ 'is_system' => true,
243
+ 'width' => '80px',
244
+ 'actions' => array($previewAction, $sendAction)
245
+ ));
246
+ }
247
+
248
+
249
+
250
+
251
+
252
+
253
+ /**
254
+ * Send email to recipient
255
+ *
256
+ * Note: The email medium is not responsible for sending out the email directly
257
+ * it will prepare the recipient and the email and push the email to the Outbox
258
+ * model, which then will send out the emails
259
+ *
260
+ * @param Mzax_Emarketing_Model_Recipient $recipient
261
+ * @throws Exception
262
+ */
263
+ public function sendRecipient(Mzax_Emarketing_Model_Recipient $recipient)
264
+ {
265
+ $recipient->prepare();
266
+
267
+ if(!$recipient->getAddress()) {
268
+ throw new Exception("No address set");
269
+ }
270
+
271
+ /* @var $email Mzax_Emarketing_Model_Outbox_Email */
272
+ $email = Mage::getModel('mzax_emarketing/outbox_email');
273
+ $email->setTo($recipient->getAddress());
274
+ $email->setRecipient($recipient);
275
+ $email->render();
276
+ $email->setExpireAt($recipient->getExpireAt());
277
+
278
+ if(!$recipient->isMock()) {
279
+ $data = $recipient->getContent()->getMediumData();
280
+ $dayFilter = $data->getDayFilter();
281
+ $timeFilter = $data->getTimeFilter();
282
+
283
+ // apply day filter
284
+ if(is_array($dayFilter) && count($dayFilter) && count($dayFilter) < 7) {
285
+ $email->setDayFilter(implode(',', $dayFilter));
286
+ }
287
+
288
+ // apply time filter
289
+ if(is_array($timeFilter) && count($timeFilter) && count($timeFilter) < 24) {
290
+ $email->setTimeFilter(implode(',', $timeFilter));
291
+ }
292
+ }
293
+
294
+ $email->save();
295
+
296
+ // if mock, send out email straight away
297
+ if($recipient->isMock() && !$recipient->getSkipSend()) {
298
+ $email->send();
299
+ }
300
+ }
301
+
302
+
303
+
304
+
305
+
306
+ /**
307
+ * Unsubscibe email from all stores for any given reason
308
+ *
309
+ *
310
+ * @todo Can be done better...
311
+ * @param string $email
312
+ * @param string $reason Reason for log purpose only
313
+ */
314
+ public function unsubscribe($email, $reason)
315
+ {
316
+ /* @var $helper Mzax_Emarketing_Helper_Newsletter */
317
+ $helper = Mage::helper('mzax_emarketing/newsletter');
318
+
319
+ /* @var $store Mage_Core_Model_Store */
320
+ foreach(Mage::app()->getStores() as $store) {
321
+ $subscriber = $helper->unsubscribe($email, $store->getId(), false);
322
+ if($subscriber->getIsStatusChanged()) {
323
+ Mage::log(sprintf("unsubscribe '%s' from store '%s': %s", $email, $store->getName(), $reason), null, 'mzax_email_unsubscribe.log');
324
+ }
325
+ }
326
+
327
+
328
+ }
329
+
330
+
331
+
332
+ }
333
+
app/code/community/Mzax/Emarketing/Model/Medium/Email/Composer.php ADDED
@@ -0,0 +1,578 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Medium_Email_Composer
33
+ extends Mage_Core_Model_Template
34
+ {
35
+
36
+ const PRERENDER_CACHE_PREFIX = 'MZAX_EMARKETING_PRERENDER_CACHE_';
37
+
38
+ const BEACON_PLACEHOLDER ='{BEACON}';
39
+
40
+ const LINK_A_TAG = "!<a [^>]*href=\"(.*?)\"[^>]*>(.*?)</a>!is";
41
+
42
+ const LINK_MAP_TAG = "!<map [^>]*name=\"(.*?)\"[^>]*>.*?</map>!is";
43
+
44
+ const LINK_AREA_TAG = "!<area [^>]*href=\"(.*?)\"[^>]*/>!i";
45
+
46
+
47
+
48
+ /**
49
+ *
50
+ * @var Mzax_Emarketing_Model_Recipient
51
+ */
52
+ protected $_recipient;
53
+
54
+
55
+ protected $_bodyText;
56
+
57
+ protected $_bodyHtml;
58
+
59
+ protected $_subject;
60
+
61
+
62
+ protected $_linkReferences;
63
+
64
+
65
+ protected $_prerender = true;
66
+
67
+ protected $_renderTime;
68
+
69
+
70
+
71
+
72
+ public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
73
+ {
74
+ $this->_recipient = $recipient;
75
+ $this->reset();
76
+ return $this;
77
+ }
78
+
79
+
80
+ public function reset()
81
+ {
82
+ $this->_linkReferences = array();
83
+ $this->_bodyHtml = null;
84
+ $this->_bodyText = null;
85
+ $this->_subject = null;
86
+ }
87
+
88
+
89
+
90
+ public function getType()
91
+ {
92
+ return self::TYPE_HTML;
93
+ }
94
+
95
+
96
+
97
+
98
+ /**
99
+ * Retrieve all created link references
100
+ *
101
+ * @return array
102
+ */
103
+ public function getLinkReferences()
104
+ {
105
+ return $this->_linkReferences;
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @return Mzax_Emarketing_Model_Recipient
111
+ */
112
+ public function getRecipient()
113
+ {
114
+ return $this->_recipient;
115
+ }
116
+
117
+
118
+ public function getBodyHtml()
119
+ {
120
+ return $this->_bodyHtml;
121
+ }
122
+
123
+
124
+ public function getBodyText()
125
+ {
126
+ return $this->_bodyText;
127
+ }
128
+
129
+
130
+ public function getSubject()
131
+ {
132
+ return $this->_subject;
133
+ }
134
+
135
+
136
+ public function getRenderTime()
137
+ {
138
+ return $this->_renderTime;
139
+ }
140
+
141
+
142
+ public function allowPrerender()
143
+ {
144
+ $data = $this->getRecipient()->getContent()->getMediumData();
145
+ if(isset($data['prerender']) && $data['prerender']) {
146
+ return true;
147
+ }
148
+ return false;
149
+ }
150
+
151
+
152
+ /**
153
+ *
154
+ * @return Mzax_Emarketing_Model_Medium_Email_Processor
155
+ */
156
+ public function getTemplateProcessor()
157
+ {
158
+ $store = $this->getRecipient()->getStore();
159
+
160
+ $recipient = $this->getRecipient();
161
+ $recipient->prepare();
162
+
163
+
164
+ /* @var $processor Mzax_Emarketing_Model_Medium_Email_Processor */
165
+ $processor = Mage::getModel('mzax_emarketing/medium_email_processor');
166
+ $processor->setStoreId($recipient->getStoreId());
167
+ $processor->setContent($this->getContent());
168
+ $processor->setVariables($recipient->getData());
169
+ $processor->setVariables(array(
170
+ 'current_year' => date('Y'),
171
+ 'date' => Mage::app()->getLocale()->storeDate($store),
172
+ 'store' => $recipient->getCampaign()->getStore(),
173
+ 'url' => $recipient->getUrls()
174
+ ));
175
+
176
+ return $processor;
177
+ }
178
+
179
+
180
+
181
+
182
+
183
+ public function getContent()
184
+ {
185
+ $content = $this->getRecipient()->getContent();
186
+ $store = $this->getRecipient()->getStore();
187
+
188
+ if($this->allowPrerender()) {
189
+ $cacheId = self::PRERENDER_CACHE_PREFIX . $content->getContentCacheId();
190
+
191
+ $data = Mage::app()->loadCache($cacheId);
192
+ if($data) {
193
+ $data = unserialize($data);
194
+ }
195
+ if(!$data) {
196
+
197
+ $storeId = $this->getRecipient()->getStoreId();
198
+
199
+ /* @var $processor Mzax_Emarketing_Model_Medium_Email_Processor */
200
+ $processor = Mage::getModel('mzax_emarketing/medium_email_processor');
201
+ $processor->disableVarDirective(true);
202
+ $processor->setStoreId($storeId);
203
+ $processor->setContent($content);
204
+ $processor->setVariables(array(
205
+ 'current_year' => date('Y'),
206
+ 'date' => Mage::app()->getLocale()->storeDate($store),
207
+ 'store' => $this->getRecipient()->getCampaign()->getStore()
208
+ ));
209
+
210
+ $this->emulateDesign($storeId);
211
+ $subject = $processor->getSubject();
212
+ $bodyHtml = $processor->getBodyHtml();
213
+ $bodyText = $processor->getBodyText();
214
+ $this->revertDesign();
215
+
216
+ if(Mage::getStoreConfigFlag('mzax_emarketing/email/css_inliner', $storeId)) {
217
+ $this->inlineCss($bodyHtml);
218
+ }
219
+
220
+ if(Mage::getStoreConfigFlag('mzax_emarketing/email/remove_comments', $storeId)) {
221
+ $this->removeComments($bodyHtml);
222
+ }
223
+
224
+ $data = new Varien_Object;
225
+ $data->setSubject($subject);
226
+ $data->setBodyHtml($bodyHtml);
227
+ $data->setBodyText($bodyText);
228
+
229
+ Mage::app()->saveCache(serialize($data), $cacheId, array(Mzax_Emarketing_Model_Campaign::CACHE_TAG));
230
+ }
231
+ /* @var $fullCache Mzax_Emarketing_Model_Medium_Email_FullCache */
232
+ $fullCache = Mage::getModel('mzax_emarketing/medium_email_fullCache');
233
+ $fullCache->setMediumData($data);
234
+
235
+ return $fullCache;
236
+ }
237
+
238
+ return $content;
239
+ }
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+ /**
250
+ * Compose Email
251
+ *
252
+ * Parse all mage expresions and prepare html for sending
253
+ *
254
+ * @throws Exception
255
+ * @return Mzax_Emarketing_Model_Medium_Email_Composer
256
+ */
257
+ public function compose()
258
+ {
259
+ if(!$this->_recipient) {
260
+ throw new Exception("Can not compose email without a recipient");
261
+ }
262
+ $this->reset();
263
+
264
+ $start = microtime(true);
265
+
266
+ $recipient = $this->getRecipient();
267
+ $storeId = $recipient->getStoreId();
268
+ $processor = $this->getTemplateProcessor();
269
+
270
+
271
+ if($this->allowPrerender()) {
272
+ $this->_subject = $processor->getSubject();
273
+ $processor->setVariables(array('subject' => $this->_subject));
274
+
275
+ $this->_bodyHtml = $processor->getBodyHtml();
276
+ $this->_bodyText = $processor->getBodyText();
277
+
278
+ // insert view tacking beacon
279
+ $this->insertBeacon($this->_bodyHtml);
280
+
281
+ // make links trackable
282
+ $this->parseLinks($this->_bodyHtml);
283
+ }
284
+ else {
285
+ $this->emulateDesign($recipient->getStoreId());
286
+ $this->_subject = $processor->getSubject();
287
+ $processor->setVariables(array('subject' => $this->_subject));
288
+
289
+ $this->_bodyHtml = $processor->getBodyHtml();
290
+ $this->_bodyText = $processor->getBodyText();
291
+ $this->revertDesign();
292
+
293
+ // insert view tacking beacon
294
+ $this->insertBeacon($this->_bodyHtml);
295
+
296
+ // make links trackable
297
+ $this->parseLinks($this->_bodyHtml);
298
+
299
+
300
+ if(Mage::getStoreConfigFlag('mzax_emarketing/email/css_inliner', $storeId)) {
301
+ $this->inlineCss($this->_bodyHtml);
302
+ }
303
+ if(Mage::getStoreConfigFlag('mzax_emarketing/email/remove_comments', $storeId)) {
304
+ $this->removeComments($this->_bodyHtml);
305
+ }
306
+ }
307
+
308
+ $this->_renderTime = microtime(true) - $start;
309
+
310
+ return $this;
311
+ }
312
+
313
+
314
+
315
+ protected function inlineCss(&$html)
316
+ {
317
+ Mage::helper('mzax_emarketing')->encodeMageExpr($html);
318
+
319
+ // @todo Maybe use Pelago_Emogrifier (but only available in later versionsof Magento)
320
+ $cssInliner = new TijsVerkoyen_CssToInlineStyles_CssToInlineStyles($html);
321
+ $cssInliner->setUseInlineStylesBlock(true);
322
+ $html = $cssInliner->convert();
323
+
324
+ Mage::helper('mzax_emarketing')->decodeMageExpr($html);
325
+ }
326
+
327
+
328
+ const STYLE_TAGS = '!<style\s+type="text/css">(.+?)</style>!is';
329
+
330
+ protected function removeComments(&$html)
331
+ {
332
+ // remove leading & trailing spaces
333
+ $html = preg_replace('/^\s+|\s+$/m', "", $html);
334
+
335
+ // remove html comments
336
+ $html = preg_replace('/<!--(.*)-->/Uis', '', $html);
337
+
338
+ // remove empty lines
339
+ $html = preg_replace("/([\n\r]+)/", "\n", $html);
340
+
341
+ // cleanup css tags
342
+ $html = preg_replace_callback(self::STYLE_TAGS, array($this, 'cleanUpCss'), $html);
343
+ }
344
+
345
+
346
+
347
+ protected function cleanUpCss($match)
348
+ {
349
+ $css = $match[1];
350
+
351
+ // replace double quotes by single quotes
352
+ $css = str_replace('"', '\'', $css);
353
+
354
+ // remove comments
355
+ $css = preg_replace('/\/\*.*?\*\//s', '', $css);
356
+
357
+ // remove leading & trailing spaces
358
+ $css = preg_replace('/^\s+|\s+$/m', '', $css);
359
+
360
+ // remove lines
361
+ $css = preg_replace("/([\n\r]+)/", "", $css);
362
+ $css = preg_replace("/}\s*/", "}\n", $css);
363
+
364
+ // allow extra line for @media queries
365
+ $css = preg_replace("/^@(.*?){/m", "\n@$1{\n", $css);
366
+
367
+
368
+
369
+ return "<style type=\"text/css\">\n$css</style>\n";
370
+
371
+ }
372
+
373
+
374
+
375
+
376
+
377
+ protected function parseLinks(&$html)
378
+ {
379
+ // replace all links with trackable links
380
+ $html = preg_replace_callback(self::LINK_A_TAG, array($this, '__replaceLinkCallback'), $html);
381
+ $html = preg_replace_callback(self::LINK_MAP_TAG, array($this, '__replaceMapCallback'), $html);
382
+ }
383
+
384
+
385
+ /**
386
+ * PregReplace callback for <a> tag links
387
+ *
388
+ * @param array $matches
389
+ * @return string
390
+ */
391
+ public function __replaceLinkCallback($matches)
392
+ {
393
+ list($linkHtml, $url, $anchor) = $matches;
394
+
395
+ if(strpos(strtolower($url), 'mailto:') === 0) {
396
+ return $linkHtml;
397
+ }
398
+
399
+ $link = $this->createLinkReference($url, $anchor);
400
+
401
+ $linkHtml = str_replace("href=\"{$url}\"", "href=\"{$link}\"", $linkHtml);
402
+ return preg_replace("!\s+!", ' ', $linkHtml);
403
+ }
404
+
405
+
406
+
407
+
408
+
409
+ /**
410
+ * Create new link reference
411
+ *
412
+ * @param string $url
413
+ * @param string $anchor
414
+ * @return Mzax_Emarketing_Model_Link_Reference
415
+ */
416
+ public function createLinkReference($url, $anchor)
417
+ {
418
+ // normalize anchor text
419
+ $anchor = trim(preg_replace("!\s+!s", ' ', $anchor));
420
+
421
+ // unqiue key
422
+ $key = md5(strtolower($url.$anchor));
423
+
424
+ // if not yet created, create new one
425
+ if(!isset($this->_linkReferences[$key])) {
426
+ /* @var $reference Mzax_Emarketing_Model_Link_Reference */
427
+ $reference = Mage::getModel('mzax_emarketing/link_reference');
428
+ $reference->setRecipient($this->_recipient);
429
+ $reference->setLink($url, $anchor);
430
+
431
+ $this->_linkReferences[$key] = $reference;
432
+ }
433
+ return $this->_linkReferences[$key];
434
+
435
+ }
436
+
437
+
438
+
439
+
440
+
441
+ /**
442
+ * Get url to beacon image
443
+ *
444
+ * @return string
445
+ */
446
+ public function getBeaconImage()
447
+ {
448
+ $baseUrl = $this->_recipient->getCampaign()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, false);
449
+ return $baseUrl . "emarketing-media/{$this->_recipient->getBeaconHash()}/logo.gif";
450
+ }
451
+
452
+
453
+
454
+
455
+
456
+ /**
457
+ * Insert tracking beacon
458
+ * allows to see if an email is viewed or not
459
+ *
460
+ * @return string
461
+ */
462
+ public function insertBeacon(&$html)
463
+ {
464
+ $beaconHtml = "<img alt=\"{$this->_recipient->getCampaign()->getStore()->getName()}\" src=\"{$this->getBeaconImage()}\" style=\"width:10px; height:5px;\" />";
465
+
466
+ // if beacon placeholder exist replace it
467
+ if(strpos($html, self::BEACON_PLACEHOLDER) !== false) {
468
+ $html = str_replace(self::BEACON_PLACEHOLDER, $beaconHtml, $html);
469
+ }
470
+ // if not try to append it just before the body tag closes
471
+ else if(strpos($html, "</body>") !== false) {
472
+ $html = str_replace("</body>", "{$beaconHtml}\n</body>", $html);
473
+ }
474
+ // if everything fails add it to the end
475
+ else {
476
+ $html .= $beaconHtml;
477
+ }
478
+
479
+ return $this;
480
+ }
481
+
482
+
483
+
484
+
485
+
486
+
487
+ protected $_currentMapName;
488
+
489
+
490
+
491
+
492
+ /**
493
+ * PregReplace callback for <map> tag links
494
+ *
495
+ * @param array $matches
496
+ * @return string
497
+ */
498
+ public function __replaceMapCallback($matches)
499
+ {
500
+ list($mapHtml, $name) = $matches;
501
+
502
+ $this->_currentMapName = array($name, $this->_getTagByUsemap($name));
503
+ $mapHtml = preg_replace_callback(self::LINK_AREA_TAG, array($this, '__replaceMapLinkCallback'), $mapHtml);
504
+ $this->_currentMapName = null;
505
+
506
+ return $mapHtml;
507
+ }
508
+
509
+
510
+
511
+
512
+ /**
513
+ * Retrieve orginal tag that binds to the given usemap
514
+ *
515
+ * Helpfull to retrieve the image that was used for a <area> tag
516
+ *
517
+ * @param string $usemap
518
+ * @return string
519
+ */
520
+ public function _getTagByUsemap($usemap)
521
+ {
522
+ if(preg_match("!<[^>]*usemap=\"#{$usemap}\"[^>]*>!is", $this->_bodyHtml, $matches)) {
523
+ return $matches[0];
524
+ }
525
+ return '';
526
+ }
527
+
528
+
529
+
530
+
531
+
532
+ public function __replaceMapLinkCallback($matches)
533
+ {
534
+ list($area, $url) = $matches;
535
+
536
+ if(strpos(strtolower($url), 'mailto:') === 0) {
537
+ return $linkHtml;
538
+ }
539
+
540
+ $label = array($this->_currentMapName[1]);
541
+
542
+ if($shape = $this->_extractAttribute($area, 'shape')) {
543
+ $label[] = $shape;
544
+ }
545
+ if($coords = $this->_extractAttribute($area, 'coords')) {
546
+ $label[] = $coords;
547
+ }
548
+
549
+ /* @var $link Mzax_Emarketing_Model_Link */
550
+ $link = $this->createLinkReference($url, implode(':', $label));
551
+
552
+ return str_replace("href=\"{$url}\"", "href=\"{$link}\"", $area);
553
+ }
554
+
555
+
556
+
557
+ /**
558
+ * Extract attribute from a html tag
559
+ *
560
+ * e.g. '<a href="http://example.com">...'
561
+ * _extractAttribute($tag, 'href');
562
+ *
563
+ * @param string $htmlTag
564
+ * @param string $attribute
565
+ * @return string|null
566
+ */
567
+ protected function _extractAttribute($htmlTag, $attribute)
568
+ {
569
+ if(preg_match("!{$attribute}=\"(.*?)\"!i", $htmlTag, $match)) {
570
+ return $match[1];
571
+ }
572
+ return null;
573
+ }
574
+
575
+
576
+
577
+
578
+ }
app/code/community/Mzax/Emarketing/Model/Medium/Email/Filter.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Medium_Email_Filter
33
+ extends Mage_Widget_Model_Template_Filter
34
+ {
35
+
36
+ /**
37
+ *
38
+ * @var boolean
39
+ */
40
+ protected $_enableVarDirective = true;
41
+
42
+
43
+
44
+ /**
45
+ * Disable var directive
46
+ *
47
+ * @param string $flag
48
+ * @return Mzax_Emarketing_Model_Medium_Email_Filter
49
+ */
50
+ public function disableVarDirective($flag = true)
51
+ {
52
+ $this->_enableVarDirective = !$flag;
53
+ return $this;
54
+ }
55
+
56
+
57
+
58
+
59
+ /**
60
+ * Var directive with modifiers support
61
+ *
62
+ * @param array $construction
63
+ * @return string
64
+ */
65
+ public function varDirective($construction)
66
+ {
67
+ if($this->_enableVarDirective) {
68
+ return parent::varDirective($construction);
69
+ }
70
+ return $construction[0];
71
+ }
72
+
73
+
74
+
75
+
76
+ /**
77
+ * Generate widget HTML if template variables are assigned
78
+ *
79
+ * @param array $construction
80
+ * @return string
81
+ */
82
+ public function widgetDirective($construction)
83
+ {
84
+ $construction[2] .= sprintf(' store_id ="%s"', $this->getStoreId());
85
+ return parent::widgetDirective($construction);
86
+ }
87
+
88
+
89
+ }
app/code/community/Mzax/Emarketing/Model/Medium/Email/Processor.php ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Medium_Email_Processor
33
+ {
34
+
35
+
36
+ /**
37
+ *
38
+ * @var Mzax_Emarketing_Model_Medium_Email_Filter
39
+ */
40
+ protected $filter;
41
+
42
+
43
+ /**
44
+ *
45
+ * @var Mzax_Emarketing_Model_Campaign_Content
46
+ */
47
+ protected $_content;
48
+
49
+
50
+ /**
51
+ *
52
+ * @var string
53
+ */
54
+ protected $_subject;
55
+
56
+
57
+ /**
58
+ *
59
+ * @var string
60
+ */
61
+ protected $_bodyHtml;
62
+
63
+
64
+ /**
65
+ *
66
+ * @var string
67
+ */
68
+ protected $_bodyText;
69
+
70
+
71
+ /**
72
+ *
73
+ * @var boolean
74
+ */
75
+ protected $_enableFullCache = false;
76
+
77
+
78
+ public function __construct()
79
+ {
80
+ $this->filter = Mage::getModel('mzax_emarketing/medium_email_filter');
81
+ $this->filter->setUseAbsoluteLinks(true);
82
+ }
83
+
84
+
85
+ /**
86
+ *
87
+ *
88
+ * @param string $flag
89
+ * @return Mzax_Emarketing_Model_Medium_Email_Processor
90
+ */
91
+ public function disableVarDirective($flag = true)
92
+ {
93
+ $this->filter->disableVarDirective($flag);
94
+ return $this;
95
+ }
96
+
97
+
98
+ /**
99
+ * Add content provider
100
+ *
101
+ * @param Mzax_Emarketing_Model_Campaign_Content $content
102
+ * @return Mzax_Emarketing_Model_Recipient_Processor
103
+ */
104
+ public function setContent(Mzax_Emarketing_Model_Campaign_Content $content)
105
+ {
106
+ $this->_content = $content;
107
+ return $this;
108
+ }
109
+
110
+
111
+ /**
112
+ *
113
+ * @param string $key
114
+ * @return mixed
115
+ */
116
+ public function getMediumData($key)
117
+ {
118
+ return $this->getContent()->getMediumData()->getData($key);
119
+ }
120
+
121
+
122
+
123
+ /**
124
+ * Retrieve content provider
125
+ *
126
+ * @throws Exception
127
+ * @return Mzax_Emarketing_Model_Campaign_Content
128
+ */
129
+ public function getContent()
130
+ {
131
+ if(!$this->_content) {
132
+ throw new Exception("No content provider added to processor");
133
+ }
134
+ return $this->_content;
135
+ }
136
+
137
+
138
+ /**
139
+ *
140
+ * @param array $variables
141
+ * @return Mzax_Emarketing_Model_Medium_Email_Processor
142
+ */
143
+ public function setVariables($variables)
144
+ {
145
+ $this->filter->setVariables($variables);
146
+ return $this;
147
+ }
148
+
149
+
150
+ /**
151
+ *
152
+ * @param mixed $storeId
153
+ * @return Mzax_Emarketing_Model_Medium_Email_Processor
154
+ */
155
+ public function setStoreId($storeId)
156
+ {
157
+ $this->filter->setStoreId($storeId);
158
+ return $this;
159
+ }
160
+
161
+
162
+
163
+
164
+ /**
165
+ * Retrieve processed email subject
166
+ *
167
+ * @return string
168
+ */
169
+ public function getSubject()
170
+ {
171
+ if(!$this->_subject) {
172
+ $subject = $this->getMediumData('subject');
173
+
174
+ // @TODO prepare template vars?
175
+ $this->_subject = $this->filter->filter($subject);
176
+ }
177
+ return $this->_subject;
178
+ }
179
+
180
+
181
+
182
+ /**
183
+ * Retrieve template used by content
184
+ *
185
+ * @throws Exception
186
+ * @return Mzax_Emarketing_Model_Template
187
+ */
188
+ public function getTemplate()
189
+ {
190
+ $templateId = $this->getMediumData('template_id');
191
+ $template = Mage::getModel('mzax_emarketing/template')->load($templateId);
192
+ if(!$template->getId()) {
193
+ throw new Exception("Template not found");
194
+ }
195
+ return $template;
196
+ }
197
+
198
+
199
+
200
+
201
+ /**
202
+ * Retrieve processed email body
203
+ *
204
+ * @return string
205
+ */
206
+ public function getBodyHtml()
207
+ {
208
+ if(!$this->_bodyHtml) {
209
+
210
+ $bodyHtml = $this->getMediumData('body_html');
211
+ // if no body html is set, render template
212
+ if(!$bodyHtml) {
213
+ $cacheKey = 'mzax_email_cache_' . $this->_content->getContentCacheId();
214
+ $bodyHtml = Mage::app()->loadCache($cacheKey);
215
+
216
+ if(!$bodyHtml) {
217
+ $template = $this->getTemplate();
218
+
219
+ $data = Zend_Json::decode($this->getMediumData('body'));
220
+ $bodyHtml = $template->render($data);
221
+
222
+ Mage::app()->saveCache($bodyHtml, $cacheKey, array(Mzax_Emarketing_Model_Campaign::CACHE_TAG));
223
+ }
224
+ }
225
+
226
+ // @TODO prepare template vars?
227
+ $this->_bodyHtml = $this->filter->filter($bodyHtml);
228
+ }
229
+ return $this->_bodyHtml;
230
+ }
231
+
232
+
233
+ /**
234
+ *
235
+ * @return string
236
+ */
237
+ public function getBodyText()
238
+ {
239
+ if(!$this->_bodyText) {
240
+
241
+ $bodyText = $this->getMediumData('body_text');
242
+
243
+ // if body text is defined, use it
244
+ if($bodyText) {
245
+ $this->_bodyText = $this->filter->filter($bodyText);
246
+ }
247
+ // create one using the html
248
+ else {
249
+ // @todo Allow custom body text
250
+ try {
251
+ libxml_use_internal_errors(true);
252
+ $this->_bodyText = Html2Text_Html2Text::convert($this->getBodyHtml());
253
+ }
254
+ catch(Exception $e) {
255
+ if(Mage::getIsDeveloperMode()) {
256
+ $this->_bodyText = $e->getMessage();
257
+ }
258
+ else {
259
+ $this->_bodyText = '';
260
+ }
261
+
262
+ }
263
+ }
264
+ }
265
+ return $this->_bodyText;
266
+ }
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+ }
app/code/community/Mzax/Emarketing/Model/Medium/Email/Snippets.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Medium_Email_Snippets
33
+ {
34
+
35
+ protected $_snippets = array();
36
+
37
+
38
+
39
+ public function add(array $snippet)
40
+ {
41
+ if(!isset($snippet['value'])) {
42
+ throw new Exception("No value property defined for snippet");
43
+ }
44
+ if(!isset($snippet['title'])) {
45
+ throw new Exception("No title property defined for snippet");
46
+ }
47
+ if(!isset($snippet['snippet'])) {
48
+ throw new Exception("No snippet property defined for snippet");
49
+ }
50
+
51
+ $this->_snippets[$snippet['value']] = $snippet;
52
+ return $this;
53
+ }
54
+
55
+
56
+
57
+ public function addSnippets($value, $snippet, $title, $description = null, $shortcut = null)
58
+ {
59
+ return $this->add(array(
60
+ 'title' => $title,
61
+ 'description' => $description,
62
+ 'snippet' => $snippet,
63
+ 'value' => $value,
64
+ 'shortcut' => $shortcut
65
+ ));
66
+ }
67
+
68
+
69
+
70
+ public function addVar($value, $title, $description = null, $shortcut = null)
71
+ {
72
+ return $this->addSnippets('mage.' . $value, '{{var ' . $value . '}}', $title, $description, $shortcut);
73
+ }
74
+
75
+
76
+
77
+
78
+
79
+ public function toArray()
80
+ {
81
+ $data = $this->_snippets;
82
+ ksort($data);
83
+
84
+ return array_values($data);
85
+ }
86
+
87
+
88
+
89
+ }
app/code/community/Mzax/Emarketing/Model/Object/Abstract.php ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ *
31
+ */
32
+ abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
33
+ {
34
+
35
+ /**
36
+ *
37
+ * @var Mage_Core_Model_Resource_Abstract
38
+ */
39
+ protected $_resource;
40
+
41
+
42
+
43
+ /**
44
+ *
45
+ * @var string
46
+ */
47
+ protected $_entityId;
48
+
49
+
50
+
51
+
52
+ /**
53
+ *
54
+ * @return string
55
+ */
56
+ abstract function getName();
57
+
58
+
59
+
60
+
61
+
62
+ protected function _init($entityId)
63
+ {
64
+ $this->_entityId = $entityId;
65
+ $this->_resource = Mage::getResourceSingleton($entityId);
66
+ }
67
+
68
+
69
+
70
+ /**
71
+ * Retreive resource model
72
+ *
73
+ * Mage_Core_Model_Resource_Db_Abstract
74
+ * Mage_Eav_Model_Entity_Abstract
75
+ * @return Mage_Core_Model_Resource_Abstract
76
+ */
77
+ public function getResource()
78
+ {
79
+ return $this->_resource;
80
+ }
81
+
82
+
83
+
84
+ /**
85
+ * Retrieve object table name
86
+ *
87
+ * @return string
88
+ */
89
+ public function getObjectTable()
90
+ {
91
+ $resource = $this->getResource();
92
+ if($resource instanceof Mage_Eav_Model_Entity_Abstract) {
93
+ return $resource->getEntityTable();
94
+ }
95
+ if($resource instanceof Mage_Core_Model_Resource_Db_Abstract) {
96
+ return $resource->getMainTable();
97
+ }
98
+ return null;
99
+ }
100
+
101
+
102
+ /**
103
+ * Retrieve object id field name
104
+ *
105
+ * @return string
106
+ */
107
+ public function getIdFieldName()
108
+ {
109
+ $resource = $this->getResource();
110
+ if($resource instanceof Mage_Eav_Model_Entity_Abstract) {
111
+ return $resource->getEntityIdField();
112
+ }
113
+ if($resource instanceof Mage_Core_Model_Resource_Db_Abstract) {
114
+ return $resource->getIdFieldName();
115
+ }
116
+ return null;
117
+ }
118
+
119
+
120
+
121
+
122
+ /**
123
+ * Retrieve collection instance from object model
124
+ *
125
+ * @return Mzax_Emarketing_Model_Object_Collection
126
+ */
127
+ public function getCollection()
128
+ {
129
+ /* @var $collection Mzax_Emarketing_Model_Object_Collection */
130
+ $collection = Mage::getModel('mzax_emarketing/object_collection');
131
+ $collection->setObject($this);
132
+
133
+ return $collection;
134
+ }
135
+
136
+
137
+
138
+
139
+ /**
140
+ * Retreive select object for this object
141
+ * This method should be extended to add custom bindings
142
+ *
143
+ * @return Mzax_Emarketing_Db_Select
144
+ */
145
+ public function getQuery()
146
+ {
147
+ $select = $this->getResourceHelper()->select();
148
+ $select->from($this->getObjectTable());
149
+ $select->addBinding('id', $this->getIdFieldName());
150
+ $select->setColumn('id');
151
+
152
+ return $select;
153
+ }
154
+
155
+
156
+
157
+
158
+
159
+ /**
160
+ * Retrieve direct admin url for this model
161
+ * use null of not available
162
+ *
163
+ * Used by filter test grid columns to add a link
164
+ * to the object when showing object ids (e.g. customer_id, order_id)
165
+ *
166
+ * @param string $id
167
+ * @return NULL|string
168
+ */
169
+ public function getAdminUrl($id)
170
+ {
171
+ return null;
172
+ }
173
+
174
+
175
+
176
+ /**
177
+ * Retrieve row id for an object
178
+ *
179
+ * @param Varien_Object $row
180
+ * @return mixed
181
+ */
182
+ public function getRowId(Varien_Object $row)
183
+ {
184
+ return $row->getId();
185
+ }
186
+
187
+
188
+
189
+ /**
190
+ * Retrieve form helper
191
+ *
192
+ * @return Mzax_Emarketing_Helper_Data
193
+ */
194
+ protected function helper()
195
+ {
196
+ return Mage::helper('mzax_emarketing');
197
+ }
198
+
199
+
200
+
201
+ /**
202
+ * Translate
203
+ *
204
+ * @param string $message
205
+ * @param string $args,...
206
+ * @return string
207
+ */
208
+ protected function __()
209
+ {
210
+ return call_user_func_array(array($this->helper(), '__'), func_get_args());
211
+ }
212
+
213
+
214
+
215
+
216
+ /**
217
+ * Get admin url
218
+ *
219
+ * @param string $routePath
220
+ * @param array $routeParams
221
+ * @return string
222
+ */
223
+ public function getUrl($routePath = null, $routeParams = null)
224
+ {
225
+ return $this->_getUrlModel()->getUrl($routePath, $routeParams);
226
+ }
227
+
228
+
229
+
230
+
231
+ /**
232
+ * Retrieve admin url model
233
+ *
234
+ * @see Mzax_Emarketing_Model_Object_Abstract::getUrl()
235
+ * @return Mage_Adminhtml_Model_Url
236
+ */
237
+ protected function _getUrlModel()
238
+ {
239
+ return Mage::getSingleton('adminhtml/url');
240
+ }
241
+
242
+
243
+
244
+
245
+ /**
246
+ * Retrieve resource helper
247
+ *
248
+ * @return Mzax_Emarketing_Model_Resource_Helper
249
+ */
250
+ protected function getResourceHelper()
251
+ {
252
+ return Mage::getResourceSingleton('mzax_emarketing/helper');
253
+ }
254
+
255
+
256
+ //--------------------------------------------------------------------------
257
+ //
258
+ // Recipient Grid Methods
259
+ //
260
+ //--------------------------------------------------------------------------
261
+
262
+
263
+ /**
264
+ * Prepare collection for use in object grid
265
+ *
266
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
267
+ * @see Mzax_Emarketing_Model_Object_Abstract::prepareGridColumns()
268
+ * @return void
269
+ */
270
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
271
+ {
272
+ $collection->setObject($this);
273
+ }
274
+
275
+
276
+
277
+ /**
278
+ * Prepare the magento grid for this object
279
+ * Can be overwritten to add default columns to a filter grid
280
+ * used for the filter testing.
281
+ *
282
+ * Use 'prepareCollection()' method to add all necesery data for
283
+ * the grid frist
284
+ *
285
+ * @see Mzax_Emarketing_Model_Object_Abstract::prepareCollection()
286
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
287
+ * @return void
288
+ */
289
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
290
+ {}
291
+
292
+
293
+ /**
294
+ *
295
+ * @deprecated
296
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
297
+ */
298
+ public function afterGridLoadCollection(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
299
+ {}
300
+
301
+
302
+
303
+ /**
304
+ *
305
+ * @deprecated
306
+ * @param unknown $collection
307
+ */
308
+ public function afterLoadCollection($collection)
309
+ {}
310
+
311
+
312
+
313
+
314
+ public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
315
+ {}
316
+
317
+
318
+ /**
319
+ * Prepare recipient for sending
320
+ * this should at least set email and name to the recipient
321
+ * but can also set any other data that later can be used
322
+ * inside the templates
323
+ *
324
+ * @param Mzax_Emarketing_Model_Recipient $recipient
325
+ */
326
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
327
+ {
328
+ $object = Mage::getModel($this->_entityId);
329
+ $object->load($recipient->getObjectId());
330
+
331
+ $recipient->setObject($object);
332
+ }
333
+
334
+
335
+ }
app/code/community/Mzax/Emarketing/Model/Object/Address.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ *
29
+ */
30
+ abstract class Mzax_Emarketing_Model_Object_Address extends Mzax_Emarketing_Model_Object_Abstract
31
+ {
32
+
33
+ public function getQuery()
34
+ {
35
+ $query = parent::getQuery();
36
+ $query->addBinding('region', 'region');
37
+ $query->addBinding('country_id', 'country_id');
38
+ $query->addBinding('postcode', 'postcode');
39
+ $query->addBinding('street', 'street');
40
+ $query->addBinding('city', 'city');
41
+ $query->addBinding('telephone', 'telephone');
42
+ $query->addBinding('company', 'company');
43
+ $query->addBinding('firstname', 'firstname');
44
+ $query->addBinding('lastname', 'lastname');
45
+ $query->addBinding('email', 'email');
46
+
47
+ return $query;
48
+ }
49
+
50
+
51
+
52
+ public function getAdminUrl($id)
53
+ {
54
+ return null;
55
+ }
56
+
57
+
58
+
59
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
60
+ {
61
+ parent::prepareCollection($collection);
62
+
63
+ $adapter = $this->getResourceHelper()->getAdapter();
64
+
65
+ $nameExpr[] = "LTRIM(RTRIM({firstname}))";
66
+ $nameExpr[] = "LTRIM(RTRIM({lastname}))";
67
+ $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
68
+
69
+ $collection->addField('name', $nameExpr);
70
+ $collection->addField('email', 'email');
71
+ $collection->addField('city', 'city');
72
+ $collection->addField('postcode', 'postcode');
73
+ }
74
+
75
+
76
+
77
+
78
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
79
+ {
80
+
81
+ $grid->addColumn('name', array(
82
+ 'header' => Mage::helper('mzax_emarketing')->__('Name'),
83
+ 'index' => 'name'
84
+ ));
85
+ $grid->addColumn('email', array(
86
+ 'header' => Mage::helper('mzax_emarketing')->__('Email'),
87
+ 'index' => 'email',
88
+ ));
89
+ $grid->addColumn('city', array(
90
+ 'header' => Mage::helper('mzax_emarketing')->__('City'),
91
+ 'index' => 'city',
92
+ ));
93
+ $grid->addColumn('postcode', array(
94
+ 'header' => Mage::helper('mzax_emarketing')->__('Postcode'),
95
+ 'index' => 'postcode',
96
+ ));
97
+ }
98
+
99
+
100
+
101
+ }
app/code/community/Mzax/Emarketing/Model/Object/Collection.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ *
31
+ */
32
+ class Mzax_Emarketing_Model_Object_Collection extends Varien_Data_Collection_Db
33
+ {
34
+
35
+ /**
36
+ *
37
+ * @var Mzax_Emarketing_Db_Select
38
+ */
39
+ protected $_query;
40
+
41
+
42
+ /**
43
+ *
44
+ * @var Mzax_Emarketing_Model_Object_Abstract
45
+ */
46
+ protected $_object;
47
+
48
+
49
+
50
+ public function __construct()
51
+ {
52
+ parent::__construct();
53
+ $this->setItemObjectClass('mzax_emarketing/object_collection_item');
54
+ }
55
+
56
+
57
+
58
+
59
+
60
+ /**
61
+ * Set Object
62
+ *
63
+ * @param Mzax_Emarketing_Model_Object_Abstract $object
64
+ * @return Mzax_Emarketing_Model_Object_Collection
65
+ */
66
+ public function setObject($object)
67
+ {
68
+ $this->_object = $object;
69
+ return $this;
70
+ }
71
+
72
+
73
+
74
+ /**
75
+ * Retrieve Object
76
+ *
77
+ * @return Mzax_Emarketing_Model_Object_Abstract
78
+ */
79
+ public function getObject()
80
+ {
81
+ return $this->_object;
82
+ }
83
+
84
+
85
+
86
+
87
+ /**
88
+ * Set Query
89
+ *
90
+ * @param Mzax_Emarketing_Db_Select $query
91
+ * @return Mzax_Emarketing_Model_Object_Collection
92
+ */
93
+ public function setQuery(Mzax_Emarketing_Db_Select $query)
94
+ {
95
+ $this->_conn = $query->getAdapter();
96
+ $this->_select = $query;
97
+ return $this;
98
+ }
99
+
100
+
101
+
102
+
103
+ /**
104
+ * Retrieve Query
105
+ *
106
+ * @return Mzax_Emarketing_Db_Select
107
+ */
108
+ public function getQuery()
109
+ {
110
+ return $this->_select;
111
+ }
112
+
113
+
114
+
115
+
116
+ /**
117
+ * (non-PHPdoc)
118
+ * @see Varien_Data_Collection_Db::getIdFieldName()
119
+ * @return string
120
+ */
121
+ public function getIdFieldName()
122
+ {
123
+ return 'id';
124
+ }
125
+
126
+
127
+
128
+
129
+ /**
130
+ * Retrieve collection empty item
131
+ *
132
+ * @return Varien_Object
133
+ */
134
+ public function getNewEmptyItem()
135
+ {
136
+ /* @var $item Mzax_Emarketing_Model_Object_Collection_Item */
137
+ $item = parent::getNewEmptyItem();
138
+ $item->setObject($this->getObject());
139
+
140
+ return $item;
141
+ }
142
+
143
+
144
+
145
+
146
+ public function applyFilter(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
147
+ {
148
+ if($this->getObject() !== $filter->getObject()) {
149
+ throw new Exception("You can not apply filters for different objects");
150
+ }
151
+ $this->getQuery()->joinSelect('id', $filter->getSelect(), 'filter');
152
+ return $this;
153
+ }
154
+
155
+
156
+
157
+
158
+ public function addField($alias, $expr = null)
159
+ {
160
+ if(!$expr) {
161
+ $expr = $alias;
162
+ }
163
+ if(is_string($expr)) {
164
+ if(!strpos($expr, '.')) {
165
+ $query = $this->getQuery();
166
+
167
+ // assume field in main table if binding does not exist
168
+ if(!$query->hasBinding($expr)) {
169
+ $query->addBinding($expr, $expr);
170
+ }
171
+ $expr = $query->getBinding($expr);
172
+ }
173
+ else {
174
+ $expr = new Zend_Db_Expr($expr);
175
+ }
176
+ }
177
+
178
+ $this->addFilterToMap($alias, $expr);
179
+ $this->getQuery()->setColumn($alias, $expr);
180
+ return $this;
181
+ }
182
+
183
+
184
+
185
+ public function joinAttribute($alias, $binding, $attribute)
186
+ {
187
+ $expr = $this->getQuery()->joinAttribute($binding, $attribute);
188
+ $this->getQuery()->addBinding($alias, $expr);
189
+ $this->addField($alias, $expr);
190
+
191
+ return $expr;
192
+ }
193
+
194
+
195
+
196
+ public function hasBinding($name)
197
+ {
198
+ return $this->getQuery()->hasBinding($name);
199
+ }
200
+
201
+
202
+
203
+
204
+ /**
205
+ * Get SQL for get record count
206
+ *
207
+ * @return Varien_Db_Select
208
+ */
209
+ public function getSelectCountSql()
210
+ {
211
+ $this->_renderFilters();
212
+
213
+ $countSelect = clone $this->getSelect();
214
+ $countSelect->reset(Zend_Db_Select::ORDER);
215
+ $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
216
+ $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
217
+
218
+ if($countSelect->getPart(Zend_Db_Select::GROUP)) {
219
+ $select = $this->getQuery()->getAdapter()->select();
220
+ $select->from(array('results' => $countSelect), null);
221
+ $select->columns('COUNT(*)');
222
+
223
+ return $select;
224
+ }
225
+ else {
226
+ $countSelect->reset(Zend_Db_Select::COLUMNS);
227
+ $countSelect->columns('COUNT(*)');
228
+ }
229
+ return $countSelect;
230
+
231
+
232
+ }
233
+
234
+ }
app/code/community/Mzax/Emarketing/Model/Object/Collection/Item.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Collection item
27
+ *
28
+ * @see Mzax_Emarketing_Model_Object_Collection::getNewEmptyItem()
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Object_Collection_Item extends Varien_Object
34
+ {
35
+
36
+ /**
37
+ *
38
+ * @var Mzax_Emarketing_Model_Object_Abstract
39
+ */
40
+ protected $_object;
41
+
42
+
43
+ /**
44
+ * Set Object
45
+ *
46
+ * @param Mzax_Emarketing_Model_Object_Abstract $object
47
+ * @return Mzax_Emarketing_Model_Recipient_Object
48
+ */
49
+ public function setObject($object)
50
+ {
51
+ $this->_object = $object;
52
+ return $this;
53
+ }
54
+
55
+
56
+
57
+ /**
58
+ * Retrieve Object
59
+ *
60
+ * @return Mzax_Emarketing_Model_Object_Abstract
61
+ */
62
+ public function getObject()
63
+ {
64
+ return $this->_object;
65
+ }
66
+
67
+ }
app/code/community/Mzax/Emarketing/Model/Object/Customer.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ *
29
+ */
30
+ class Mzax_Emarketing_Model_Object_Customer extends Mzax_Emarketing_Model_Object_Abstract
31
+ {
32
+
33
+
34
+ public function _construct()
35
+ {
36
+ $this->_init('customer/customer');
37
+ }
38
+
39
+
40
+
41
+ public function getName()
42
+ {
43
+ return $this->__('Customer');
44
+ }
45
+
46
+
47
+ public function getAdminUrl($id)
48
+ {
49
+ return $this->getUrl('adminhtml/customer/edit', array('id' => $id));
50
+ }
51
+
52
+
53
+ public function getQuery()
54
+ {
55
+ $query = parent::getQuery();
56
+ $query->addBinding('customer_id', 'entity_id');
57
+ $query->addBinding('email', 'email');
58
+
59
+ return $query;
60
+ }
61
+
62
+
63
+
64
+
65
+ /**
66
+ *
67
+ * @return Mzax_Emarketing_Model_Object_Collection
68
+ */
69
+ public function getCollection()
70
+ {
71
+ $collection = parent::getCollection();
72
+
73
+ $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
74
+ $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
75
+
76
+ $adapter = $this->getResourceHelper()->getAdapter();
77
+
78
+ $nameExpr[] = "LTRIM(RTRIM($firstname))";
79
+ $nameExpr[] = "LTRIM(RTRIM($lastname))";
80
+ $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
81
+
82
+ $collection->addField('name', $nameExpr);
83
+ $collection->addField('email', 'email');
84
+
85
+ return $collection;
86
+ }
87
+
88
+
89
+
90
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
91
+ {
92
+ parent::prepareCollection($collection);
93
+
94
+ $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
95
+ $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
96
+
97
+ $adapter = $this->getResourceHelper()->getAdapter();
98
+
99
+ $nameExpr[] = "LTRIM(RTRIM($firstname))";
100
+ $nameExpr[] = "LTRIM(RTRIM($lastname))";
101
+ $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
102
+
103
+ $collection->addField('name', $nameExpr);
104
+ $collection->addField('email', 'email');
105
+ }
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
114
+ {
115
+
116
+ $grid->addColumn('name', array(
117
+ 'header' => Mage::helper('mzax_emarketing')->__('Name'),
118
+ 'index' => 'name'
119
+ ));
120
+
121
+ $grid->addColumn('email', array(
122
+ 'header' => Mage::helper('mzax_emarketing')->__('Email'),
123
+ 'index' => 'email',
124
+ ));
125
+
126
+
127
+ }
128
+
129
+
130
+
131
+
132
+ public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
133
+ {
134
+ $snippets->addVar('customer.firstname', $this->__("Customers Firstname"));
135
+ $snippets->addVar('customer.lastname', $this->__("Customers Lastname"));
136
+
137
+ }
138
+
139
+ /**
140
+ * (non-PHPdoc)
141
+ * @see Mzax_Emarketing_Model_Object_Abstract::prepareRecipient()
142
+ */
143
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
144
+ {
145
+ parent::prepareRecipient($recipient);
146
+
147
+ /* @var $customer Mage_Customer_Model_Customer */
148
+ $customer = $recipient->getObject();
149
+ $recipient->setCustomer($customer);
150
+ $recipient->setEmail($customer->getEmail());
151
+ $recipient->setName($customer->getName());
152
+ }
153
+ }
app/code/community/Mzax/Emarketing/Model/Object/Customer/Address.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Object Model for customer address
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Object_Customer_Address extends Mzax_Emarketing_Model_Object_Abstract
33
+ {
34
+
35
+
36
+ /**
37
+ * (non-PHPdoc)
38
+ * @see Varien_Object::_construct()
39
+ */
40
+ public function _construct()
41
+ {
42
+ $this->_init('customer/address');
43
+ }
44
+
45
+
46
+
47
+ /**
48
+ * The title of this object
49
+ *
50
+ * @return string
51
+ */
52
+ public function getName()
53
+ {
54
+ return $this->__('Customer Address');
55
+ }
56
+
57
+
58
+
59
+ /**
60
+ * Retrieve query for customer address
61
+ *
62
+ * @return Mzax_Emarketing_Db_Select
63
+ */
64
+ public function getQuery()
65
+ {
66
+ $query = parent::getQuery();
67
+ $query->addBinding('customer_address_id', 'entity_id');
68
+
69
+ return $query;
70
+ }
71
+
72
+
73
+
74
+ /**
75
+ * Add name, city and postcode to collection as
76
+ * we use them to show in every grid
77
+ *
78
+ * @see Mzax_Emarketing_Model_Object_Customer_Address::prepareGridColumns()
79
+ */
80
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
81
+ {
82
+ parent::prepareCollection($collection);
83
+
84
+ $firstname = $collection->getQuery()->joinAttribute('{id}', 'customer_address/firstname');
85
+ $lastname = $collection->getQuery()->joinAttribute('{id}', 'customer_address/lastname');
86
+ $postcode = $collection->getQuery()->joinAttribute('{id}', 'customer_address/city');
87
+ $city = $collection->getQuery()->joinAttribute('{id}', 'customer_address/postcode');
88
+
89
+ $adapter = $this->getResourceHelper()->getAdapter();
90
+
91
+ $nameExpr[] = "LTRIM(RTRIM({$firstname}))";
92
+ $nameExpr[] = "LTRIM(RTRIM({$lastname}))";
93
+ $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
94
+
95
+ $collection->addField('name', $nameExpr);
96
+ $collection->addField('city', $city);
97
+ $collection->addField('postcode', $postcode);
98
+ }
99
+
100
+
101
+
102
+ /**
103
+ * Add name, city and postcode to grid
104
+ *
105
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
106
+ * @return void
107
+ */
108
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
109
+ {
110
+ $grid->addColumn('name', array(
111
+ 'header' => Mage::helper('mzax_emarketing')->__('Name'),
112
+ 'index' => 'name'
113
+ ));
114
+ $grid->addColumn('city', array(
115
+ 'header' => Mage::helper('mzax_emarketing')->__('City'),
116
+ 'index' => 'city',
117
+ ));
118
+ $grid->addColumn('postcode', array(
119
+ 'header' => Mage::helper('mzax_emarketing')->__('Postcode'),
120
+ 'index' => 'postcode',
121
+ ));
122
+ }
123
+
124
+
125
+
126
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Object_Filter implements Mage_Eav_Model_Entity_Attribute_Source_Interface
25
+ {
26
+
27
+ /**
28
+ *
29
+ * @var Mage_Core_Model_Config_Element
30
+ */
31
+ protected $_config;
32
+
33
+
34
+
35
+ /**
36
+ *
37
+ * @var array
38
+ */
39
+ protected $_filters;
40
+
41
+
42
+ /**
43
+ *
44
+ * @param string $name
45
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
46
+ */
47
+ public function factory($name)
48
+ {
49
+ $config = $this->getConfig();
50
+ if(!isset($config->$name)) {
51
+ return null;
52
+ //throw new Exception("No such filter ({$name}) found");
53
+ }
54
+ $config = $config->$name;
55
+ $class = $config->getClassName();
56
+
57
+ $instance = new $class($config);
58
+
59
+ return $instance;
60
+ }
61
+
62
+
63
+
64
+
65
+
66
+
67
+ /**
68
+ * Retrieve All options
69
+ *
70
+ * @return array
71
+ */
72
+ public function getAllOptions($withEmpty = true, $defaultValues = false)
73
+ {
74
+ $options = array();
75
+
76
+ /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
77
+ foreach($this->getFilters() as $name => $filter) {
78
+ $options[] = array(
79
+ 'value' => $name,
80
+ 'label' => $filter->getTitle()
81
+ );
82
+ }
83
+ if ($withEmpty) {
84
+ array_unshift($options, array('label'=>'', 'value'=>''));
85
+ }
86
+
87
+ return $options;
88
+ }
89
+
90
+
91
+
92
+
93
+
94
+
95
+ /**
96
+ * Retrieve all filters
97
+ *
98
+ * @return array
99
+ */
100
+ public function getFilters()
101
+ {
102
+ if(!$this->_filters) {
103
+ $this->_filters = array();
104
+
105
+ foreach($this->getConfig()->children() as $name => $cfg) {
106
+ $this->_filters[$name] = self::factory($name);
107
+ }
108
+ }
109
+ return $this->_filters;
110
+ }
111
+
112
+
113
+
114
+
115
+
116
+ /**
117
+ * Retrieve Option value text
118
+ *
119
+ * @param string $value
120
+ * @return mixed
121
+ */
122
+ public function getOptionText($value)
123
+ {
124
+ $options = $this->getFilters();
125
+ if(isset($options[$value])) {
126
+ return $options[$value]->getTitle();
127
+ }
128
+ return false;
129
+ }
130
+
131
+
132
+
133
+ /**
134
+ * Retrieve email marketing collection config
135
+ *
136
+ * @return Mage_Core_Model_Config_Element
137
+ */
138
+ public function getConfig()
139
+ {
140
+ if(!$this->_config) {
141
+ $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/filters');
142
+ }
143
+ return $this->_config;
144
+ }
145
+
146
+
147
+
148
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Abstract.php ADDED
@@ -0,0 +1,1366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarketing_Model_Object_Filter_Component
25
+ {
26
+
27
+
28
+
29
+ /**
30
+ * Child Filters
31
+ *
32
+ * @var array
33
+ */
34
+ protected $_filters = array();
35
+
36
+
37
+
38
+ /**
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_formHtml;
43
+
44
+
45
+
46
+ /**
47
+ * Unique filter type id
48
+ *
49
+ * @var string
50
+ */
51
+ protected $_type;
52
+
53
+
54
+
55
+
56
+
57
+ public function __construct($config = null)
58
+ {
59
+ $this->_construct();
60
+
61
+ if($config instanceof Mage_Core_Model_Config_Element) {
62
+ $this->_prepareFilter($config);
63
+ }
64
+ }
65
+
66
+
67
+
68
+ protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
69
+ {
70
+ $this->_type = $config->getName();
71
+
72
+ Mage::dispatchEvent("mzax_emarketing_email_filter_prepare", array('filter' => $this));
73
+ Mage::dispatchEvent("mzax_emarketing_email_filter_prepare_" . $this->_type, array('filter' => $this));
74
+ }
75
+
76
+
77
+ public function setType($type)
78
+ {
79
+ $this->_type = $type;
80
+ return $this;
81
+ }
82
+
83
+
84
+ public function getType()
85
+ {
86
+ return $this->_type;
87
+ }
88
+
89
+
90
+
91
+ /**
92
+ * Retrieve object
93
+ *
94
+ * @return Mzax_Emarketing_Model_Object_Abstract
95
+ */
96
+ public function getObject()
97
+ {
98
+ return $this->getParentObject();
99
+ }
100
+
101
+
102
+
103
+ /**
104
+ * Set ID
105
+ *
106
+ * @param string $id
107
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
108
+ */
109
+ public function setId($id)
110
+ {
111
+ $this->_id = $id;
112
+ if($this->_filters) {
113
+ foreach($this->_filters as $i => $filter) {
114
+ $filter->setId($this->_id . '--' . ($i+1));
115
+ }
116
+ }
117
+ return $this;
118
+ }
119
+
120
+
121
+ /**
122
+ * Add child filter
123
+ *
124
+ * @param mixed $filter
125
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
126
+ */
127
+ public function addFilter($filter, $quite = true)
128
+ {
129
+ if(is_string($filter)) {
130
+ $instance = self::getFilterFactory()->factory($filter);
131
+ if(!$instance) {
132
+ if(!$quite) {
133
+ throw new Mage_Exception(Mage::helper('mzax_emarketing')->__('Failed to initialise filter with type “%s”. This filter might not be installed on your system.', $filter['type']));
134
+ }
135
+ return null;
136
+ }
137
+ $filter = $instance;
138
+ }
139
+ else if(is_array($filter) && isset($filter['type'])) {
140
+ $instance = self::getFilterFactory()->factory($filter['type']);
141
+ if(!$instance) {
142
+ if(!$quite) {
143
+ throw new Mage_Exception(Mage::helper('mzax_emarketing')->__('Failed to initialise filter with type “%s”. This filter might not be installed on your system.', $filter['type']));
144
+ }
145
+ return null;
146
+ }
147
+ $instance->load($filter);
148
+ $filter = $instance;
149
+ }
150
+ if(!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
151
+ return null;
152
+ }
153
+ $this->_filters[] = $filter->setParent($this);
154
+ $filter->setId($this->getId() . '--' . count($this->_filters));
155
+ return $filter;
156
+ }
157
+
158
+
159
+
160
+ /**
161
+ * Retrieve all filters
162
+ *
163
+ * @return array
164
+ */
165
+ public function getFilters()
166
+ {
167
+ return $this->_filters;
168
+ }
169
+
170
+
171
+
172
+ /**
173
+ * Retrieve filter by index
174
+ *
175
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
176
+ */
177
+ public function getFilterByIndex($index)
178
+ {
179
+ if(isset($this->_filters[$index])) {
180
+ return $this->_filters[$index];
181
+ }
182
+ return null;
183
+ }
184
+
185
+
186
+
187
+ /**
188
+ * Retrieve all filter options for this filter
189
+ *
190
+ * @return array
191
+ */
192
+ public function getOptions()
193
+ {
194
+ return array($this->getType() => $this->getTitle());
195
+ }
196
+
197
+
198
+
199
+
200
+ /**
201
+ * Retrieve Varien Data Form
202
+ *
203
+ * @return Varien_Data_Form
204
+ */
205
+ public function getForm()
206
+ {
207
+ $elementRenderer = Mage::getBlockSingleton('mzax_emarketing/editable');
208
+
209
+ $prefix = $this->getRoot()->getFormPrefix();
210
+
211
+ $form = new Varien_Data_Form();
212
+ $form->setHtmlIdPrefix("{$prefix}__{$this->getId()}__");
213
+ $form->setFieldNameSuffix("{$prefix}[{$this->getId()}]");
214
+ $form->setElementRenderer($elementRenderer);
215
+ return $form;
216
+ }
217
+
218
+
219
+
220
+
221
+ public function reset()
222
+ {
223
+ $this->unsetData();
224
+ $this->_filters = array();
225
+ $this->_formHtml = null;
226
+ return $this;
227
+ }
228
+
229
+
230
+
231
+
232
+
233
+ /**
234
+ * Retrieve data
235
+ *
236
+ * @param string $key
237
+ * @param string $default
238
+ * @return string
239
+ */
240
+ public function getDataSetDefault($key, $default = null)
241
+ {
242
+ // check for default constant
243
+ if($default === null) {
244
+ $const = get_class($this) . '::DEFAULT_' . strtoupper($key);
245
+ if(defined($const)) {
246
+ $default = constant($const);
247
+ }
248
+ }
249
+ return parent::getDataSetDefault($key, $default);
250
+ }
251
+
252
+
253
+
254
+
255
+ public function prepareParams()
256
+ {}
257
+
258
+
259
+
260
+
261
+ /**
262
+ * Load filters from data
263
+ *
264
+ * @param mixed $data
265
+ * @param boolean $quite Throw en exception if a filter was not avaialble
266
+ * @throws Exception
267
+ * @throws Mage_Exception
268
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
269
+ */
270
+ public function load($data, $quite = true)
271
+ {
272
+ $this->reset();
273
+
274
+ if(empty($data)) {
275
+ return $this;
276
+ }
277
+
278
+ // string should be a JSON
279
+ if(is_string($data)) {
280
+ try {
281
+ $data = Zend_Json::decode($data);
282
+ }
283
+ catch(Zend_Json_Exception $e) {
284
+ throw new Exception("Failed to decode filter json: {$e->getMessage()}", 0, $e);
285
+ }
286
+ }
287
+
288
+ if(is_array($data)) {
289
+ if(isset($data['filters'])) {
290
+ foreach($data['filters'] as $filter) {
291
+ $this->addFilter($filter, $quite);
292
+ }
293
+ unset($data['filters']);
294
+ }
295
+ $this->setData($data);
296
+ $this->prepareParams();
297
+ $this->setDataChanges(false);
298
+ }
299
+ return $this;
300
+ }
301
+
302
+
303
+
304
+ /**
305
+ * Load data from flat post array
306
+ *
307
+ * e.g.
308
+ * array(4) {
309
+ * [1]=>
310
+ * array(4) {
311
+ * ["type"]=>
312
+ * string(7) "combine"
313
+ * ["binder"]=>
314
+ * string(3) "all"
315
+ * ["expectation"]=>
316
+ * string(4) "true"
317
+ * }
318
+ * ["1--1"]=>
319
+ * array(4) {
320
+ * ["type"]=>
321
+ * string(7) "combine"
322
+ * ["binder"]=>
323
+ * string(3) "any"
324
+ * ["expectation"]=>
325
+ * string(4) "true"
326
+ * }
327
+ * ["1--1--1"]=>
328
+ * array(2) {
329
+ * ["type"]=>
330
+ * string(10) "newsletter"
331
+ * ["subscripted"]=>
332
+ * string(9) "subscript"
333
+ * }
334
+ * ["1--1--2"]=>
335
+ * array(2) {
336
+ * ["type"]=>
337
+ * string(10) "newsletter"
338
+ * ["subscripted"]=>
339
+ * string(15) "not_unsubscript"
340
+ * }
341
+ * }
342
+ *
343
+ * @param array $data
344
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
345
+ */
346
+ public function loadFlatArray(array $data)
347
+ {
348
+ $filters = array();
349
+
350
+ foreach($data as $id => $filterData)
351
+ {
352
+ $path = explode('--', $id);
353
+ $list =& $filters;
354
+
355
+ while(count($path) > 1) {
356
+
357
+ $id = array_shift($path);
358
+ if(!isset($list[$id])) {
359
+ continue 2;
360
+ }
361
+ if(!isset($list[$id]['filters'])) {
362
+ $list[$id]['filters'] = array();
363
+ }
364
+ $list =& $list[$id]['filters'];
365
+ }
366
+
367
+ $id = array_shift($path);
368
+ $list[$id] = $filterData;
369
+ }
370
+
371
+ if(!empty($filters)) {
372
+ $this->load(array_shift($filters));
373
+ }
374
+ else {
375
+ $this->setData(array());
376
+ $this->prepareParams();
377
+ }
378
+
379
+ return $this;
380
+ }
381
+
382
+
383
+
384
+
385
+ /**
386
+ * Retrieve filter data as array
387
+ *
388
+ * @return array
389
+ */
390
+ public function asArray()
391
+ {
392
+ $data = $this->getData();
393
+ if($this->_filters) {
394
+ $data['filters'] = array();
395
+ foreach($this->_filters as $filter) {
396
+ $data['filters'][] = $filter->asArray();
397
+ }
398
+ }
399
+
400
+ // not required for save
401
+ unset($data['new_child']);
402
+ return $data;
403
+ }
404
+
405
+
406
+
407
+ /**
408
+ * Retrieve filter data as json
409
+ *
410
+ * @return array
411
+ */
412
+ public function asJson()
413
+ {
414
+ return Zend_Json::encode($this->asArray());
415
+ }
416
+
417
+
418
+
419
+
420
+ /**
421
+ * Retrieve human readable filter text
422
+ *
423
+ * @param format
424
+ * @return mixed
425
+ */
426
+ public function asString($format = 'html')
427
+ {
428
+ $form = $this->getForm();
429
+ $form->getElementRenderer()->setFormat($format);
430
+
431
+ $html = $this->_getFormHtml($form);
432
+
433
+ return $html;
434
+ }
435
+
436
+
437
+
438
+
439
+ /**
440
+ * Retrieve filter as html
441
+ *
442
+ * @return string
443
+ */
444
+ public function asHtml()
445
+ {
446
+ $html = $this->getFormHtml();
447
+
448
+ if ($this->getId() != '1') {
449
+ $html .= $this->getRemoveLinkHtml();
450
+ }
451
+
452
+ $result = $this->checkIndexes(false);
453
+ if(is_string($result)) {
454
+ $html .= '<div class="maax-index-check">' . $result . '</div>';
455
+ }
456
+
457
+ $html .= $this->getChooserContainerHtml();
458
+
459
+ $prefix = $this->getRoot()->getFormPrefix();
460
+
461
+ if(count($this->getAvailableFilters())) {
462
+ $html .= '<ul id="'.$prefix.'__'.$this->getId().'__children" class="rule-param-children">';
463
+ foreach ($this->_filters as $filter) {
464
+ $html .= '<li>'.$filter->asHtml().'</li>';
465
+ }
466
+ $html .= '<li>'.$this->getNewChildElement()->getHtml().'</li></ul>';
467
+ }
468
+
469
+ return $html;
470
+ }
471
+
472
+
473
+
474
+
475
+ public final function getFormHtml()
476
+ {
477
+ $form = $this->getForm();
478
+
479
+ $typeField = $form->addField('type', 'hidden', array(
480
+ 'name' => 'type',
481
+ 'class' => 'hidden',
482
+ 'no_span' => true,
483
+ 'is_meta' => true,
484
+ 'value' => $this->getType()
485
+ ));
486
+
487
+ $html = $typeField->toHtml();
488
+ $html .= $this->_getFormHtml($form);
489
+
490
+ return $html;
491
+ }
492
+
493
+
494
+
495
+ protected function _getFormHtml(Varien_Data_Form $form)
496
+ {
497
+ $this->_form = $form;
498
+ return $this->prepareForm();
499
+ }
500
+
501
+ protected function prepareForm()
502
+ {
503
+ return '';
504
+ }
505
+
506
+
507
+ public function getChooserContainerHtml()
508
+ {
509
+ $url = $this->getChooserUrl();
510
+ if ($url) {
511
+ $url = Mage::helper('adminhtml')->getUrl($url);
512
+ return '<div class="rule-chooser" url="' . $url . '"></div>';
513
+ }
514
+ return '';
515
+ }
516
+
517
+
518
+
519
+ abstract function getTitle();
520
+
521
+
522
+
523
+
524
+ /**
525
+ * Run filter query and return result
526
+ *
527
+ * This method should only used for testing
528
+ * and debugging
529
+ *
530
+ * @return array
531
+ */
532
+ public function runFilterQuery()
533
+ {
534
+ $select = $this->getSelect();
535
+ $result = $this->_getReadAdapter()->query($select->assembleAll());
536
+
537
+ return $result;
538
+ }
539
+
540
+
541
+
542
+ public function beforeLoad($provider)
543
+ {}
544
+
545
+
546
+
547
+ public function afterLoad($provider)
548
+ {}
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+ protected function getAddLinkHtml()
559
+ {
560
+ $src = Mage::getDesign()->getSkinUrl('mzax/images/add-tiny.png');
561
+ $html = '<img src="' . $src . '" class="rule-param-add v-middle" alt="" title="' . $this->__('Add Filter') . '"/>';
562
+ return $html;
563
+ }
564
+
565
+
566
+
567
+ protected function getRemoveLinkHtml()
568
+ {
569
+ $src = Mage::getDesign()->getSkinUrl('mzax/images/delete-tiny.png');
570
+ $html = ' <span class="rule-param"><a href="javascript:void(0)" class="rule-param-remove" title="'.$this->__('Remove Filter').'"><img src="'.$src.'" alt="" class="v-middle" /></a></span>';
571
+ return $html;
572
+ }
573
+
574
+
575
+
576
+ public function getChooserTriggerHtml()
577
+ {
578
+ $src = Mage::getDesign()->getSkinUrl('images/rule_chooser_trigger.gif');
579
+ $html = '<a href="javascript:void(0)" class="rule-chooser-trigger"><img src="' . $src . '" alt="" class="v-middle rule-chooser-trigger" title="' . $this->__('Open Chooser') . '" /></a>';
580
+ return $html;
581
+ }
582
+
583
+
584
+
585
+
586
+ /**
587
+ * Prepare recipient collection
588
+ *
589
+ * @return void
590
+ */
591
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
592
+ {
593
+ parent::_prepareCollection($collection);
594
+ //$collection->applyFilter($this);
595
+ }
596
+
597
+
598
+
599
+
600
+ //--------------------------------------------------------------------------
601
+ //
602
+ // Quick Helpers
603
+ //
604
+ //--------------------------------------------------------------------------
605
+
606
+
607
+
608
+
609
+ /**
610
+ * Helper for new child filter element
611
+ *
612
+ * @return Varien_Data_Form_Element_Abstract
613
+ */
614
+ protected function getNewChildElement()
615
+ {
616
+ $path = $this->getTypePath() . '-';
617
+
618
+
619
+ $filters = array();
620
+ foreach($this->getAvailableFilters() as $type => $title) {
621
+
622
+ $title = $this->_explode($title, '|');
623
+
624
+ $list =& $filters;
625
+
626
+ while(count($title) > 1) {
627
+ $n = array_shift($title);
628
+ if(!isset($list[$n])) {
629
+ $list[$n] = array('label' => $n, 'value' => array());
630
+ }
631
+ $list =& $list[$n]['value'];
632
+ }
633
+
634
+ $list[] = array('value' => $path . $type, 'label' => array_shift($title));
635
+ }
636
+
637
+ array_unshift($filters, array('value'=>'', 'label' => $this->__('Please choose a filter to add...')));
638
+
639
+ return $this->getForm()->addField('new_child', 'select', array(
640
+ 'name' => 'new_child',
641
+ 'values' => $filters,
642
+ 'value_name' => $this->getAddLinkHtml(),
643
+ ))->setRenderer(Mage::getBlockSingleton('rule/newchild'));
644
+ }
645
+
646
+
647
+
648
+ /**
649
+ * Helper for simple input element
650
+ *
651
+ * @param string $key
652
+ * @return Varien_Data_Form_Element_Abstract
653
+ */
654
+ protected function getInputElement($key, $default = null)
655
+ {
656
+ $value = (string) $this->getDataSetDefault($key, $default);
657
+
658
+ return $this->getForm()->addField($key, 'text',array(
659
+ 'name' => $key,
660
+ 'value_name' => $value,
661
+ 'value' => $value
662
+ ));
663
+ }
664
+
665
+
666
+
667
+
668
+ /**
669
+ * Helper for simple select element
670
+ *
671
+ * @param string $key
672
+ * @param array $options
673
+ * @return Varien_Data_Form_Element_Abstract
674
+ */
675
+ protected function getSelectElement($key, $default = null, $options = null)
676
+ {
677
+ if(empty($options)) {
678
+ $options = $this->getDataUsingMethod($key . '_options');
679
+ }
680
+
681
+ $value = $this->getDataSetDefault($key, $default);
682
+ if(is_array($value)) {
683
+ $value = $value[0];
684
+ }
685
+ $valueName = '';
686
+ if(isset($options[$value])) {
687
+ $valueName = $options[$value];
688
+ }
689
+
690
+ return $this->getForm()->addField($key, 'select',array(
691
+ 'name' => $key,
692
+ 'value_name' => ($valueName ? $valueName : '...'),
693
+ 'value' => $value,
694
+ 'values' => $options
695
+ ));
696
+ }
697
+
698
+
699
+
700
+
701
+ /**
702
+ * Helper for simple select element
703
+ *
704
+ * @param string $key
705
+ * @param array $options
706
+ * @return Varien_Data_Form_Element_Abstract
707
+ */
708
+ public function getDateElement($key, $default = null)
709
+ {
710
+ $format = Varien_Date::DATE_INTERNAL_FORMAT;
711
+ $value = (string) $this->getDataSetDefault($key, $default);
712
+
713
+ if(!$value) {
714
+ $value = Zend_Date::now()->toString($format);
715
+ }
716
+
717
+ $value = Mage::app()->getLocale()->date($value, $format, null, false)->toString($format);
718
+
719
+ return $this->getForm()->addField($key, 'date',array(
720
+ 'name' => $key,
721
+ 'value_name' => $value,
722
+ 'value' => $value,
723
+ 'explicit_apply' => true,
724
+ 'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
725
+ 'input_format' => $format,
726
+ 'format' => $format
727
+ ));
728
+ }
729
+
730
+
731
+ /**
732
+ * Helper for simple select element
733
+ *
734
+ * @param string $key
735
+ * @param array $options
736
+ * @return Varien_Data_Form_Element_Abstract
737
+ */
738
+ protected function getMultiSelectElement($key, $default = null, $options = null)
739
+ {
740
+ if(empty($options)) {
741
+ $optionHash = $this->getDataUsingMethod($key . '_options');
742
+ }
743
+
744
+ $values = $this->getDataSetDefault($key, $default);
745
+ if(is_string($values)) {
746
+ $values = $this->_explode($values);
747
+ }
748
+ if(empty($values)) {
749
+ $values = array();
750
+ }
751
+
752
+ $valueName = array();
753
+ $options = array();
754
+ foreach($optionHash as $value => $option) {
755
+ $options[] = array('value' => $value, 'label' => $option);
756
+ if(in_array($value, $values)) {
757
+ $valueName[] = $option;
758
+ }
759
+ }
760
+
761
+ return $this->getForm()->addField($key, 'multiselect',array(
762
+ 'name' => $key,
763
+ 'value_name' => implode(', ', $valueName),
764
+ 'value' => $values,
765
+ 'values' => $options
766
+ ));
767
+ }
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+ /**
776
+ * Helper for simple time html
777
+ *
778
+ * The time html consists of two form fields
779
+ * a select for the unit and the value (e.g. 5 days, 6 weeks)
780
+ *
781
+ * @return string
782
+ */
783
+ protected function getTimeHtml($key, $html = "%s %s")
784
+ {
785
+ $valueKey = "{$key}_value";
786
+ $unitKey = "{$key}_unit";
787
+
788
+ $unitElement = $this->getSelectElement($unitKey, 'days', $this->helper()->getTimeUnitOptions());
789
+ $valueElement = $this->getInputElement($valueKey);
790
+
791
+ return $this->__($html,
792
+ $valueElement->toHtml(),
793
+ $unitElement->toHtml()
794
+ );
795
+ }
796
+
797
+
798
+
799
+
800
+
801
+ /**
802
+ * Helper for simple time html
803
+ *
804
+ * The time html consists of two form fields
805
+ * a select for the unit and the value (e.g. 5 days, 6 weeks)
806
+ *
807
+ * @return string
808
+ */
809
+ protected function getTimeRangeHtml($key, $html = "%s to %s %s")
810
+ {
811
+ $fromKey = "{$key}_from";
812
+ $toKey = "{$key}_to";
813
+ $unitKey = "{$key}_unit";
814
+
815
+ $unitElement = $this->getSelectElement($unitKey, 'days', $this->helper()->getTimeUnitOptions());
816
+ $fromElement = $this->getInputElement($fromKey, 2);
817
+ $toElement = $this->getInputElement($toKey, 5);
818
+
819
+ return $this->__($html,
820
+ $fromElement->toHtml(),
821
+ $toElement->toHtml(),
822
+ $unitElement->toHtml()
823
+ );
824
+ }
825
+
826
+
827
+
828
+ /**
829
+ * Retrieve time direction as boolean value
830
+ * true => for future
831
+ * false => for past
832
+ *
833
+ * @param string $key
834
+ * @param string $default
835
+ * @return boolean
836
+ */
837
+ protected function getTimeDirection($key, $default = null)
838
+ {
839
+ $dir = (string) $this->getDataSetDefault("{$key}_dir", $default);
840
+ return ($dir === 'future');
841
+ }
842
+
843
+
844
+ protected function getTimeDirectionHtml($key)
845
+ {
846
+ $dirKey = "{$key}_dir";
847
+
848
+ $unitElement = $this->getSelectElement($dirKey, 'future', $this->getTimeDirectionOptions());
849
+ return $unitElement->getHtml();
850
+ }
851
+
852
+
853
+ protected function getTimeDirectionOptions()
854
+ {
855
+ return array(
856
+ 'future' => $this->__('is in'),
857
+ 'past' => $this->__('is past'),
858
+ );
859
+ }
860
+
861
+
862
+
863
+
864
+
865
+ /**
866
+ * Retrieve time range expresion from two time expr values
867
+ *
868
+ * value unit value unit
869
+ * | | | |
870
+ * Last login [5] [days|weeks|months] to [7] [days|weeks|months] ago
871
+ * \________FROM_________/ \_________TO__________/
872
+ *
873
+ *
874
+ * ...WHERE `field` BETWEEN `from` AND `to`...
875
+ *
876
+ * @param string|Zend_Db_Expr $field
877
+ * @param string $fromKey
878
+ * @param string $toKey
879
+ * @param boolean $future
880
+ * @return Zend_Db_Expr
881
+ */
882
+ protected function getTimeRangeExpr($field, $key, $future = null, $dateOnly = false, $useLocalTime = false)
883
+ {
884
+ $now = $this->getCurrentTime(!$useLocalTime);
885
+
886
+ $fromKey = "{$key}_from";
887
+ $toKey = "{$key}_to";
888
+ $unitKey = "{$key}_unit";
889
+
890
+ if($future === null) {
891
+ $future = $this->getTimeDirection($key);
892
+ }
893
+
894
+ $from = (int) $this->getData($fromKey);
895
+ $to = (int) $this->getData($toKey);
896
+ $unit = (string) $this->getData($unitKey);
897
+ // days => DAY, weeks => WEEK,...
898
+ $unit = substr(strtoupper($unit), 0, -1);
899
+
900
+ if(!preg_match('/^[A-Z]+$/', $unit)) {
901
+ throw new Exception("Invalid time unit ($unit)");
902
+ }
903
+
904
+ $func = $future ? 'DATE_ADD' : 'DATE_SUB';
905
+
906
+ $limits = array();
907
+ if(is_array($now)) {
908
+ foreach($now as $date) {
909
+ // $date = $gmtOffset ? $this->addGmtOffset($date) : $date;
910
+ $limits[] = "$func($date, INTERVAL $from $unit)";
911
+ $limits[] = "$func($date, INTERVAL $to $unit)";
912
+ }
913
+ }
914
+ else {
915
+ //$now = $gmtOffset ? $this->addGmtOffset($now) : $date;
916
+ $limits[] = "$func($now, INTERVAL $from $unit)";
917
+ $limits[] = "$func($now, INTERVAL $to $unit)";
918
+ }
919
+
920
+
921
+ $limits = implode(', ', $limits);
922
+
923
+ if($dateOnly) {
924
+ return new Zend_Db_Expr("$field BETWEEN DATE(LEAST($limits)) AND DATE(GREATEST($limits))");
925
+ }
926
+
927
+ return new Zend_Db_Expr("$field BETWEEN LEAST($limits) AND GREATEST($limits)");
928
+
929
+ }
930
+
931
+
932
+
933
+ /**
934
+ * Retrieve anniversary expression
935
+ *
936
+ * @param string $field
937
+ * @param string $key
938
+ * @param boolean $future
939
+ * @param boolean $applyGmtOffset
940
+ * @return Zend_Db_Expr
941
+ */
942
+ protected function getAnniversaryTimeExpr($field, $key, $future = false, $fieldIsLocalTime = false)
943
+ {
944
+ // if data field is in local time, don't do any conversion
945
+ if(!$fieldIsLocalTime) {
946
+ $localField = $this->toLocalTime($field);
947
+ }
948
+ else {
949
+ $localField = $field;
950
+ }
951
+
952
+ $currentTime = $this->getCurrentTimeExpr(false, '%s', !$future);
953
+
954
+ $age = "YEAR($currentTime) - YEAR($localField)";
955
+ // if we look into the future we need to add one year if the day of the year is already past
956
+ if($future) {
957
+ $age.= "+IF(DAYOFYEAR($currentTime) > DAYOFYEAR($localField),1,0)";
958
+ }
959
+ // if we look into the past we need to substract a year if the day of the year is in front
960
+ else {
961
+ $age.= "-IF(DAYOFYEAR($currentTime) < DAYOFYEAR($localField),1,0)";
962
+ }
963
+
964
+ $anniversary = "DATE_ADD($localField, INTERVAL $age YEAR)";
965
+ $anniversary = "DATE($anniversary)";
966
+
967
+ // it needs to be at least one year old
968
+ $lastYear = $this->getCurrentTimeExpr(!$fieldIsLocalTime, 'DATE_SUB(%s, INTERVAL 6 MONTH)', $future);
969
+
970
+
971
+ $expr[] = "$field <= DATE($lastYear)";
972
+ $expr[] = $this->getTimeRangeExpr($anniversary, $key, $future, true, true);
973
+
974
+ return new Zend_Db_Expr(implode(' AND ', $expr));
975
+ }
976
+
977
+
978
+
979
+
980
+
981
+
982
+ protected function getCurrentTimeExpr($gmt = true, $format = '%s', $max = false)
983
+ {
984
+ $results = array();
985
+ foreach($this->getCurrentTime($gmt) as $date) {
986
+ $results[] = sprintf($format, $date);
987
+ }
988
+ if($max) {
989
+ return $this->getGreatestSql($results);
990
+ }
991
+ return $this->getLeastSql($results);
992
+ }
993
+
994
+
995
+
996
+
997
+
998
+
999
+ protected function getLeastSql(array $data)
1000
+ {
1001
+ if(count($data) > 1) {
1002
+ return $this->_getReadAdapter()->getLeastSql($data);
1003
+ }
1004
+ return $data[0];
1005
+ }
1006
+
1007
+
1008
+ protected function getGreatestSql(array $data)
1009
+ {
1010
+ if(count($data) > 1) {
1011
+ return $this->_getReadAdapter()->getGreatestSql($data);
1012
+ }
1013
+ return $data[0];
1014
+ }
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+ /**
1022
+ * Add gmt offset if available
1023
+ *
1024
+ * @param string $dateExpr
1025
+ * @return string
1026
+ */
1027
+ protected function addGmtOffset($dateExpr)
1028
+ {
1029
+ $gmtOffset = (int) $this->getParam('gmt_offset', 0);
1030
+ if($gmtOffset) {
1031
+ $dateExpr = "DATE_SUB($dateExpr, INTERVAL $gmtOffset MINUTE)";
1032
+ }
1033
+ return $dateExpr;
1034
+ }
1035
+
1036
+
1037
+
1038
+
1039
+ /**
1040
+ * Converts local date expresion to gmt time
1041
+ * gmt offset
1042
+ *
1043
+ * @param string $dateExpr
1044
+ * @return string
1045
+ */
1046
+ protected function toGmtTime($localDateExpr)
1047
+ {
1048
+ $gmtOffset = (int) $this->getParam('gmt_offset', 0);
1049
+ if($gmtOffset) {
1050
+ $localDateExpr = "DATE_SUB($localDateExpr, INTERVAL $gmtOffset MINUTE)";
1051
+ }
1052
+ return $localDateExpr;
1053
+ }
1054
+
1055
+
1056
+
1057
+
1058
+ /**
1059
+ * Convert database field to local time by appling specified
1060
+ * gmt offset
1061
+ *
1062
+ * @param string $dateExpr
1063
+ * @return string
1064
+ */
1065
+ protected function toLocalTime($gmtDateExpr)
1066
+ {
1067
+ $gmtOffset = (int) $this->getParam('gmt_offset', 0);
1068
+ if($gmtOffset) {
1069
+ $gmtDateExpr = "DATE_SUB($gmtDateExpr, INTERVAL $gmtOffset MINUTE)";
1070
+ }
1071
+ return $gmtDateExpr;
1072
+ }
1073
+
1074
+
1075
+
1076
+
1077
+
1078
+ /**
1079
+ * Retrieve date value
1080
+ *
1081
+ * @param string $key
1082
+ * @param integer $roundDate
1083
+ * @return Zend_Date
1084
+ */
1085
+ protected function getTimeValue($key, $roundDate = false)
1086
+ {
1087
+ return $this->helper()->calcDate(
1088
+ (int) $this->getData("{$key}_value"),
1089
+ (string) $this->getData("{$key}_unit"),
1090
+ $roundDate);
1091
+ }
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+ protected function getTimeExpr($key, $field, $substract = false)
1100
+ {
1101
+ $value = (int) $this->getData("{$key}_value");
1102
+ $unit = (string) $this->getData("{$key}_unit");
1103
+
1104
+ $unit = substr(strtoupper($unit), 0, -1);
1105
+
1106
+ $func = $substract ? 'DATE_SUB' : 'DATE_ADD';
1107
+
1108
+ return new Zend_Db_Expr("$func($field, INTERVAL $value $unit)");
1109
+ }
1110
+
1111
+
1112
+
1113
+
1114
+
1115
+ protected function getInputHtml($key, $type = "string", $default = null, $html = null)
1116
+ {
1117
+ $operations = $this->helper()->getOperatorOptionsByType($type);
1118
+
1119
+ $defaultOpertator = '{}';
1120
+ if($type === 'numeric') {
1121
+ $defaultOpertator = '==';
1122
+ if($default === null) {
1123
+ $default = '1';
1124
+ }
1125
+ if($html === null) {
1126
+ $html = '%s %s';
1127
+ }
1128
+ }
1129
+
1130
+ if($html === null) {
1131
+ $html = '%s "%s"';
1132
+ }
1133
+
1134
+
1135
+ $operatorElment = $this->getSelectElement($key . '_operator', $defaultOpertator, $operations);
1136
+ $inputElement = $this->getInputElement($key, $default);
1137
+
1138
+ if($type === 'numeric') {
1139
+ //$inputElement->addClass(''); numeric validation?
1140
+ }
1141
+
1142
+ return $this->__($html,
1143
+ $operatorElment->toHtml(),
1144
+ $inputElement->toHtml()
1145
+ );
1146
+ }
1147
+
1148
+
1149
+
1150
+ protected function getWhereSql($key, $field, $quoteField = null)
1151
+ {
1152
+ $adapter = $this->_getReadAdapter();
1153
+
1154
+ if($quoteField) {
1155
+ $field = str_replace('?', $adapter->quoteIdentifier($quoteField), $field);
1156
+ }
1157
+
1158
+ $value = $this->getData($key);
1159
+ $operator = $this->getDataSetDefault($key . '_operator', '{}');
1160
+
1161
+ switch($operator) {
1162
+ case '!=':
1163
+ case '>=':
1164
+ case '<=':
1165
+ case '>':
1166
+ case '<': return $adapter->quoteInto("{$field} {$operator} ?", $value);
1167
+ case '{}': return $adapter->quoteInto("{$field} LIKE ?", "%$value%");
1168
+ case '!{}': return $adapter->quoteInto("{$field} NOT LIKE ?", "%$value%");
1169
+ case '()': return $adapter->quoteInto("{$field} IN (?)", $this->_explode($value));
1170
+ case '!()': return $adapter->quoteInto("{$field} NOT IN (?)", $this->_explode($value));
1171
+ default: return $adapter->quoteInto("{$field} = ?", $value);
1172
+ }
1173
+ }
1174
+
1175
+
1176
+ /**
1177
+ * Check if where select would match zero
1178
+ *
1179
+ * @param string $key
1180
+ * @return boolean
1181
+ */
1182
+ protected function checkIfMatchZero($key)
1183
+ {
1184
+ return (bool) $this->_getReadAdapter()->fetchOne("SELECT ".$this->getWhereSql($key, '0'));
1185
+ }
1186
+
1187
+
1188
+ protected function _explode($string, $delimiter = ',')
1189
+ {
1190
+ if(is_array($string)) {
1191
+ return $string;
1192
+ }
1193
+ return array_map('trim', explode($delimiter, $string));
1194
+ }
1195
+
1196
+
1197
+ protected function _implode($string, $glue = ',')
1198
+ {
1199
+ if(is_array($string)) {
1200
+ return implode($glue, $string);
1201
+ }
1202
+ return $string;
1203
+ }
1204
+
1205
+
1206
+
1207
+
1208
+ protected function getAggregatorOptions()
1209
+ {
1210
+ return array(
1211
+ 'any' => $this->__('ANY'),
1212
+ 'all' => $this->__('ALL'),
1213
+ );
1214
+ }
1215
+
1216
+
1217
+ protected function getExpectationOptions()
1218
+ {
1219
+ return array(
1220
+ 'true' => $this->__('TRUE'),
1221
+ 'false' => $this->__('FALSE'),
1222
+ );
1223
+ }
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+
1232
+ /**
1233
+ * Use SQL UNION to combine all conditions into one
1234
+ * Select SQL
1235
+ *
1236
+ * @param array $conditions
1237
+ * @param string $aggregator
1238
+ * @param string $expectation
1239
+ * @return Mzax_Emarketing_Db_Select
1240
+ */
1241
+ protected function _combineConditions($conditions, $aggregator, $expectation, $alias = 'combine')
1242
+ {
1243
+ if(empty($conditions)) {
1244
+ return $this->getQuery()
1245
+ ->setColumn('matches', new Zend_Db_Expr('0'));
1246
+ }
1247
+
1248
+ $negate = ($expectation === 'false');
1249
+
1250
+ // if negate, add all options to query
1251
+ if($negate) {
1252
+ $conditions[] = $this->getQuery();
1253
+ }
1254
+
1255
+ $conditionCount = count($conditions);
1256
+
1257
+ if($conditionCount === 1) {
1258
+ $select = $conditions[0];
1259
+ }
1260
+ else {
1261
+ $select = $this->_select()->union($conditions, Zend_Db_Select::SQL_UNION_ALL);
1262
+ }
1263
+
1264
+ $select = $this->_select($select, 'combine_union', $select::SQL_WILDCARD);
1265
+ $select->group();
1266
+
1267
+ if($negate) {
1268
+ $select->columns(array('matches' => "$conditionCount - COUNT(*)"));
1269
+ }
1270
+ else {
1271
+ $select->columns(array('matches' => 'COUNT(*)'));
1272
+ }
1273
+
1274
+ if($aggregator === 'all') {
1275
+
1276
+ if($negate) { // ALL ARE FALSE
1277
+ $select->having("COUNT(*) = ?", 1);
1278
+ }
1279
+ else {// ALL ARE TRUE
1280
+ $select->having("COUNT(*) = ?", $conditionCount);
1281
+ }
1282
+ }
1283
+ else {
1284
+ if($negate) { // ANY ARE FALSE
1285
+ $select->having("COUNT(*) < ?", $conditionCount);
1286
+ }
1287
+ else { // ANY ARE TRUE
1288
+ //$select->having("COUNT(*) > ?", 0);
1289
+ }
1290
+ }
1291
+
1292
+ return $select;
1293
+ }
1294
+
1295
+
1296
+
1297
+
1298
+
1299
+
1300
+ /**
1301
+ * Retrieve all filter selects from
1302
+ * all children
1303
+ *
1304
+ * @return array
1305
+ */
1306
+ protected function _getConditions()
1307
+ {
1308
+ $conditions = array();
1309
+
1310
+ /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
1311
+ foreach($this->_filters as $filter) {
1312
+ if($select = $filter->getSelect()) {
1313
+ $conditions[] = $select;
1314
+ }
1315
+ }
1316
+ return $conditions;
1317
+ }
1318
+
1319
+
1320
+
1321
+ /**
1322
+ * Negate select
1323
+ *
1324
+ * Return query that selects all ids but the ones from
1325
+ * the given select
1326
+ *
1327
+ * @deprecated
1328
+ * @param Zend_Db_Select $select
1329
+ * @return Zend_Db_Select
1330
+ *//*
1331
+ protected function _negateSql($select)
1332
+ {
1333
+ return $this->getQuery()->where("NOT EXISTS ($select)")->getSelect();
1334
+ }
1335
+ */
1336
+
1337
+
1338
+ /**
1339
+ * Check database for indexes that the filter requires and
1340
+ * if possible create any missing indexes if
1341
+ * canCreateIndex() allows to do so.
1342
+ *
1343
+ * @param boolean $create Wheather to try to create an index or not
1344
+ * @return true|string
1345
+ */
1346
+ public function checkIndexes($create = false)
1347
+ {
1348
+ return true;
1349
+ }
1350
+
1351
+
1352
+
1353
+ /**
1354
+ * Check if filter can create indexes
1355
+ *
1356
+ * @return boolean
1357
+ */
1358
+ public function canCreateIndex()
1359
+ {
1360
+ return Mage::getStoreConfigFlag('mzax_emarketing/general/can_create_indexes');
1361
+ }
1362
+
1363
+
1364
+
1365
+
1366
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/City.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Address_City
29
+ extends Mzax_Emarketing_Model_Object_Filter_Column
30
+ {
31
+
32
+
33
+ protected $_formText = '%s %s %s.';
34
+
35
+
36
+ /**
37
+ *
38
+ * @var string
39
+ */
40
+ protected $_requireBinding = 'city';
41
+
42
+
43
+
44
+ protected $_label = 'City';
45
+
46
+
47
+
48
+
49
+
50
+ public function getTitle()
51
+ {
52
+ return "Address | City";
53
+ }
54
+
55
+
56
+
57
+
58
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Country.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Address_Country
29
+ extends Mzax_Emarketing_Model_Object_Filter_Column
30
+ {
31
+
32
+
33
+ protected $_formText = '%s %s %s.';
34
+
35
+
36
+ /**
37
+ *
38
+ * @var string
39
+ */
40
+ protected $_requireBinding = 'country_id';
41
+
42
+
43
+
44
+ protected $_label = 'Country';
45
+
46
+
47
+ protected $_inputType = 'multiselect';
48
+
49
+
50
+
51
+ public function getTitle()
52
+ {
53
+ return "Address | Country";
54
+ }
55
+
56
+
57
+
58
+
59
+ /**
60
+ * Retrieve all value options as hash
61
+ *
62
+ * array(value => label,...)
63
+ *
64
+ * @return array
65
+ */
66
+ public function getValueOptions()
67
+ {
68
+ $array = Mage::getResourceSingleton('directory/country_collection')->toOptionArray(false);
69
+
70
+ $options = array();
71
+ foreach($array as $option) {
72
+ $options[$option['value']] = $option['label'];
73
+ }
74
+
75
+ return $options;
76
+ }
77
+
78
+
79
+
80
+
81
+
82
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Postcode.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Address_Postcode
29
+ extends Mzax_Emarketing_Model_Object_Filter_Column
30
+ {
31
+
32
+
33
+ protected $_formText = '%s %s %s.';
34
+
35
+
36
+ /**
37
+ *
38
+ * @var string
39
+ */
40
+ protected $_requireBinding = 'postcode';
41
+
42
+
43
+
44
+ protected $_label = 'Postcode';
45
+
46
+
47
+
48
+
49
+
50
+ public function getTitle()
51
+ {
52
+ return "Address | Postcode";
53
+ }
54
+
55
+
56
+
57
+
58
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Region.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Address_Region
29
+ extends Mzax_Emarketing_Model_Object_Filter_Column
30
+ {
31
+
32
+
33
+ protected $_formText = '%s %s %s.';
34
+
35
+
36
+ /**
37
+ *
38
+ * @var string
39
+ */
40
+ protected $_requireBinding = 'region';
41
+
42
+
43
+
44
+ protected $_label = 'Region';
45
+
46
+
47
+
48
+
49
+
50
+ public function getTitle()
51
+ {
52
+ return "Address | Region";
53
+ }
54
+
55
+
56
+
57
+
58
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Street.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Address_Street
29
+ extends Mzax_Emarketing_Model_Object_Filter_Column
30
+ {
31
+
32
+
33
+ protected $_formText = '%s %s %s.';
34
+
35
+
36
+ /**
37
+ *
38
+ * @var string
39
+ */
40
+ protected $_requireBinding = 'street';
41
+
42
+
43
+
44
+ protected $_label = 'Street';
45
+
46
+
47
+
48
+
49
+
50
+ public function getTitle()
51
+ {
52
+ return "Address | Street";
53
+ }
54
+
55
+
56
+
57
+
58
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Attribute.php ADDED
@@ -0,0 +1,521 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ * Abstract Attribute filter
28
+ *
29
+ * Define the entity type code and the required binding
30
+ * and it will generate filters for all attributes
31
+ *
32
+ * use method isAttributeAllowed() for fine tuning
33
+ *
34
+ *
35
+ * @author Jacob Siefer
36
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
37
+ * @version 0.2.5
38
+ */
39
+ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
40
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
41
+ {
42
+
43
+ const VALUE_KEY = 'value';
44
+
45
+
46
+
47
+ /**
48
+ *
49
+ * @var Mage_Catalog_Model_Resource_Eav_Attribute
50
+ */
51
+ protected $_attribute;
52
+
53
+
54
+
55
+ /**
56
+ *
57
+ * @var string
58
+ */
59
+ protected $_entity;
60
+
61
+
62
+ /**
63
+ *
64
+ * @var string
65
+ */
66
+ protected $_requireBinding;
67
+
68
+
69
+
70
+ protected $_attributeConfigs = array();
71
+
72
+
73
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
74
+ {
75
+ return $this->_acceptParent($parent, $this->_requireBinding);
76
+ }
77
+
78
+
79
+
80
+ protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
81
+ {
82
+ if(isset($config->attributes)) {
83
+ /* @var $attrCfg Mage_Core_Model_Config_Element */
84
+ foreach($config->attributes->children() as $code => $cfg) {
85
+ $this->_attributeConfigs[$code] = $cfg->asCanonicalArray();
86
+ }
87
+ }
88
+ parent::_prepareFilter($config);
89
+ }
90
+
91
+
92
+
93
+ /**
94
+ * Retrieve attribute config value
95
+ *
96
+ * @param string $attribute
97
+ * @param string $key
98
+ * @param mixed $default
99
+ * @return mixed
100
+ */
101
+ protected function getAttributeConfig($attribute, $key, $default = null)
102
+ {
103
+ if($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) {
104
+ $attribute = $attribute->getAttributeCode();
105
+ }
106
+ if(isset($this->_attributeConfigs[$attribute][$key])) {
107
+ return $this->_attributeConfigs[$attribute][$key];
108
+ }
109
+ return $default;
110
+ }
111
+
112
+
113
+
114
+
115
+
116
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
117
+ {
118
+ $attribute = $this->getAttribute();
119
+ $adapter = $query->getAdapter();
120
+ $field = $query->joinAttribute($this->_requireBinding, $attribute);
121
+
122
+ $query->addBinding('attribute_value', $field);
123
+
124
+ $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
125
+ $value = $this->getData(self::VALUE_KEY);
126
+
127
+
128
+
129
+ /*
130
+ * Relative data attributes
131
+ */
132
+ if($this->getData('relative')) {
133
+
134
+ $future = $this->getDirection() == 'future';
135
+ $usesLocalTime = (bool) $this->getAttributeConfig($attribute, 'uses_local_time', false);
136
+
137
+ if($this->getAnniversary()) {
138
+ $query->where($this->getAnniversaryTimeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
139
+ }
140
+ else {
141
+ $query->where($this->getTimeRangeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
142
+ }
143
+ return;
144
+ }
145
+
146
+
147
+
148
+ /*
149
+ * Multi select attributes are saved as list in varchar
150
+ * (e.g. 123,1457,124,21)
151
+ *
152
+ * @todo can we use an index?
153
+ */
154
+ if($attribute->getFrontendInput() === 'multiselect')
155
+ {
156
+ $value = (array) $value;
157
+ $where = array();
158
+ foreach($value as $v) {
159
+ $where[] = $adapter->quoteInto("FIND_IN_SET(?, {attribute_value})", $v);
160
+ }
161
+ if(strpos($operator, '()') !== false) {
162
+ $where = implode(' OR ', $where);
163
+ }
164
+ else {
165
+ $where = implode(' AND ', $where);
166
+ }
167
+
168
+ if(strpos($operator, '!') === 0) {
169
+ $where = "!($where)";
170
+ }
171
+
172
+ $query->where($where);
173
+ return;
174
+ }
175
+
176
+ switch($operator) {
177
+ case '!=':
178
+ case '>=':
179
+ case '<=':
180
+ case '>':
181
+ case '<': return $query->where("{attribute_value} {$operator} ?", $this->_implode($value)); break;
182
+ case '{}': return $query->where("{attribute_value} LIKE ?", "%$value%"); break;
183
+ case '!{}': return $query->where("{attribute_value} NOT LIKE ?", "%$value%"); break;
184
+ case '()': return $query->where("{attribute_value} IN (?)", $this->_explode($value)); break;
185
+ case '!()': return $query->where("{attribute_value} NOT IN (?)", $this->_explode($value)); break;
186
+ default: return $query->where("{attribute_value} = ?", $this->_implode($value)); break;
187
+ }
188
+
189
+ }
190
+
191
+
192
+ /**
193
+ * Add attribute value to collection
194
+ *
195
+ * @return void
196
+ */
197
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
198
+ {
199
+ parent::_prepareCollection($collection);
200
+ $collection->addField('attribute_value');
201
+ }
202
+
203
+
204
+ /**
205
+ * Add attribute value to grid
206
+ *
207
+ * @return void
208
+ */
209
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
210
+ {
211
+ parent::prepareGridColumns($grid);
212
+
213
+ $grid->addColumn('attribute_value', array(
214
+ 'header' => $this->getFrontendLabel(),
215
+ 'index' => 'attribute_value',
216
+ 'type' => $this->getColumnType(),
217
+ 'options' => $this->getGridValueOptions(),
218
+ ));
219
+ }
220
+
221
+
222
+
223
+
224
+ /**
225
+ * Retrieve grid column type
226
+ *
227
+ * @return string
228
+ */
229
+ public function getColumnType()
230
+ {
231
+ switch($this->getInputType()) {
232
+ case 'multiselect':
233
+ case 'select':
234
+ case 'boolean':
235
+ return 'options';
236
+ }
237
+ return $this->getInputType();
238
+ }
239
+
240
+
241
+
242
+ /**
243
+ * Retrieve value options for the grid
244
+ *
245
+ * @return array
246
+ */
247
+ public function getGridValueOptions()
248
+ {
249
+ return $this->getValueOptions();
250
+ }
251
+
252
+
253
+
254
+
255
+
256
+ /**
257
+ * Retrieve attribute instance
258
+ *
259
+ * @return Mage_Catalog_Model_Resource_Eav_Attribute
260
+ */
261
+ public function getAttribute()
262
+ {
263
+ if(!$this->_attribute) {
264
+ $code = $this->getData('attribute');
265
+ $this->_attribute = $this->_getAttribute($this->_entity . '/' . $code);
266
+ }
267
+ return $this->_attribute;
268
+ }
269
+
270
+
271
+ public function getFrontendLabel($attribute = null)
272
+ {
273
+ if(!$attribute) {
274
+ $attribute = $this->getAttribute();
275
+ }
276
+ $label = $this->getAttributeConfig($attribute, 'label');
277
+ if(!$label) {
278
+ return $attribute->getFrontendLabel();
279
+ }
280
+ return$this->__($label);
281
+ }
282
+
283
+
284
+
285
+ /**
286
+ * html for settings in option form
287
+ *
288
+ * @return string
289
+ */
290
+ protected function prepareForm()
291
+ {
292
+ $attribute = $this->getAttribute();
293
+ if(!$attribute) {
294
+ return "**ERROR** NO ATTRIBUTE SELECTED.";
295
+ }
296
+
297
+ $html = $this->getHiddenField('attribute', $attribute->getAttributeCode())->toHtml();
298
+
299
+ if(!$this->getData('relative')) {
300
+ $operatorElement = $this->getOperatorElement();
301
+ $valueElement = $this->getValueElement();
302
+
303
+ return $html. $this->__('%s %s %s.',
304
+ $this->getFrontendLabel(),
305
+ $operatorElement->toHtml(),
306
+ $valueElement->toHtml()
307
+ );
308
+ }
309
+ // relative date
310
+ else {
311
+ $html .= $this->getHiddenField('relative', 1)->toHtml();
312
+ $html .= $this->getHiddenField('anniversary', $this->getAnniversary())->toHtml();
313
+ $html .= $this->getHiddenField('direction', $this->getDirection())->toHtml();
314
+
315
+ $timeRangeHtml = $this->getTimeRangeHtml(self::VALUE_KEY);
316
+
317
+ if($this->getAnniversary()) {
318
+ $text = $this->getDirection() == 'future'
319
+ ? '%s anniversary is in %s.'
320
+ : '%s anniversary was %s ago.';
321
+ }
322
+ else {
323
+ $text = $this->getDirection() == 'future'
324
+ ? '%s is in %s.'
325
+ : '%s was %s ago.';
326
+ }
327
+
328
+ return $html. $this->__($text,
329
+ $this->getFrontendLabel(),
330
+ $timeRangeHtml
331
+ );
332
+
333
+ }
334
+ }
335
+
336
+
337
+
338
+
339
+
340
+ /**
341
+ * Retrieve operator select element
342
+ *
343
+ * @return Varien_Data_Form_Element_Abstract
344
+ */
345
+ public function getOperatorElement()
346
+ {
347
+ $type = $this->getInputType();
348
+ $default = $this->helper()->getDefaultOperatorByType($type);
349
+ $options = $this->helper()->getOperatorOptionsByType($type);
350
+
351
+ return $this->getSelectElement('operator', $default, $options);
352
+ }
353
+
354
+
355
+
356
+ /**
357
+ * Retroeve value form element
358
+ *
359
+ * @return Varien_Data_Form_Element_Abstract
360
+ */
361
+ public function getValueElement()
362
+ {
363
+ $type = $this->getInputType();
364
+
365
+ switch($type) {
366
+
367
+ case 'date':
368
+ $element = $this->getDateElement(self::VALUE_KEY);
369
+ break;
370
+
371
+ case 'select':
372
+ if(count($this->getValueOptions()) <= 2) {
373
+ $element = $this->getSelectElement(self::VALUE_KEY);
374
+ break;
375
+ }
376
+
377
+ case 'multiselect':
378
+ $element = $this->getMultiSelectElement(self::VALUE_KEY);
379
+ break;
380
+
381
+ default:
382
+ $element = $this->getInputElement(self::VALUE_KEY);
383
+ break;
384
+ }
385
+
386
+ if($this->getChooserUrl()) {
387
+ $element->setExplicitApply(true);
388
+ $element->setAfterElementHtml($this->getChooserTriggerHtml());
389
+ }
390
+
391
+ return $element;
392
+ }
393
+
394
+
395
+
396
+
397
+
398
+
399
+ /**
400
+ * Retrieve all value options as hash
401
+ *
402
+ * array(value => label,...)
403
+ *
404
+ * @return array
405
+ */
406
+ public function getValueOptions()
407
+ {
408
+ $attribute = $this->getAttribute();
409
+ if($attribute->usesSource()) {
410
+ if ($attribute->getFrontendInput() == 'multiselect') {
411
+ $addEmptyOption = false;
412
+ } else {
413
+ $addEmptyOption = true;
414
+ }
415
+ $options = $attribute->getSource()->getAllOptions(false);
416
+ $hash = array();
417
+ foreach ($options as $o) {
418
+ if (is_array($o['value'])) {
419
+ continue;
420
+ }
421
+ $hash[$o['value']] = $o['label'];
422
+ }
423
+ return $hash;
424
+ }
425
+ return array();
426
+ }
427
+
428
+
429
+
430
+
431
+ /**
432
+ * Add hidden input field
433
+ *
434
+ * @param string $name
435
+ * @param string $value
436
+ * @return Varien_Data_Form_Element_Abstract
437
+ */
438
+ protected function getHiddenField($name, $value)
439
+ {
440
+ return $this->getForm()->addField($name, 'hidden', array(
441
+ 'name' => $name,
442
+ 'class' => 'hidden',
443
+ 'no_span' => true,
444
+ 'is_meta' => true,
445
+ 'value' => $value
446
+ ));
447
+ }
448
+
449
+
450
+
451
+
452
+ /**
453
+ * Retrieve input type
454
+ *
455
+ * @return string
456
+ */
457
+ public function getInputType()
458
+ {
459
+ switch ($this->getAttribute()->getFrontendInput()) {
460
+ case 'select': return 'select';
461
+ case 'multiselect': return 'multiselect';
462
+ case 'date': return 'date';
463
+ case 'boolean': return 'boolean';
464
+ case 'price': return 'numeric';
465
+ }
466
+ return 'string';
467
+ }
468
+
469
+
470
+
471
+
472
+
473
+ public function getOptions()
474
+ {
475
+ $title = $this->getTitle();
476
+ $type = $this->getType();
477
+ $options = array();
478
+
479
+ $attributes = $this->getResourceHelper()->getEntity($this->_entity)
480
+ ->loadAllAttributes()
481
+ ->getAttributesByCode();
482
+
483
+ /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
484
+ foreach($attributes as $attribute) {
485
+ if($this->isAttributeAllowed($attribute)) {
486
+
487
+ $label = $this->getFrontendLabel($attribute);
488
+
489
+ $options[$type.'?attribute='.$attribute->getAttributeCode()] = "{$title} | {$label}";
490
+
491
+ // dates can be filterd by a fixed date or relative to the time when checked
492
+ if($attribute->getFrontendInput() === 'date') {
493
+ $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?direction=future'] = $title . ' | ' . $this->__('%s is in...', $label);
494
+ $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?direction=past'] = $title . ' | ' . $this->__('%s was ... ago', $label);
495
+
496
+ $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?anniversary=1?direction=future'] = $title . ' | ' . $this->__('%s anniversary is in...', $label);
497
+ $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?anniversary=1?direction=past'] = $title . ' | ' . $this->__('%s anniversary was ... ago', $label);
498
+ }
499
+ }
500
+ }
501
+
502
+ asort($options);
503
+ return $options;
504
+ }
505
+
506
+
507
+ protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
508
+ {
509
+ if($this->getAttributeConfig($attribute, 'disable', false)) {
510
+ return false;
511
+ }
512
+ if($attribute->getFrontendLabel()) {
513
+ return true;
514
+ }
515
+
516
+
517
+ return false;
518
+ }
519
+
520
+
521
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Goal.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @method Mzax_Emarketing_Model_Object_Filter_Campaign_Goal setAction()
26
+ * @method Mzax_Emarketing_Model_Object_Filter_Campaign_Goal setOffsetValue()
27
+ * @method Mzax_Emarketing_Model_Object_Filter_Campaign_Goal setOffsetUnit()
28
+ *
29
+ *
30
+ * @author Jacob Siefer
31
+ *
32
+ */
33
+ class Mzax_Emarketing_Model_Object_Filter_Campaign_Goal
34
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
35
+ {
36
+
37
+
38
+ const ACTION_CLICKED = 'clicked';
39
+ const ACTION_VIEWED = 'viewed';
40
+ const ACTION_RECIEVED = 'recieved';
41
+
42
+
43
+
44
+
45
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
46
+ {
47
+ return $parent->getQuery()->hasAllBindings('recipient_id', 'goal_time', 'recipient_sent_at');
48
+ }
49
+
50
+
51
+
52
+ public function getTitle()
53
+ {
54
+ return "Goal | Occurred after recipient sent/viewed/click campaign";
55
+ }
56
+
57
+
58
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
59
+ {
60
+ $action = $this->getDataSetDefault('action');
61
+
62
+ switch($action) {
63
+ case self::ACTION_CLICKED:
64
+ case self::ACTION_VIEWED:
65
+ switch($action) {
66
+ case self::ACTION_CLICKED:
67
+ $eventType = Mzax_Emarketing_Model_Recipient::EVENT_TYPE_CLICK;
68
+ break;
69
+ case self::ACTION_VIEWED:
70
+ $eventType = Mzax_Emarketing_Model_Recipient::EVENT_TYPE_VIEW;
71
+ break;
72
+ }
73
+
74
+ $query->joinTable(array('recipient_id', 'event_type' => $eventType), 'recipient_event', 'event')->group();
75
+
76
+ //$select->join($this->_getTable('recipient_event', 'event'), "`event`.`recipient_id` = $recipientId AND `event`.`event_type` = $eventType", null);
77
+
78
+ $eventTime = '`event`.`captured_at`';
79
+ $timeLimit = $this->getTimeExpr('offset', $eventTime);
80
+
81
+ $query->where("{goal_time} < $timeLimit");
82
+ $query->where("{goal_time} > $eventTime");
83
+ break;
84
+
85
+ default:
86
+ $timeLimit = $this->getTimeExpr('offset', '{recipient_sent_at}');
87
+ $query->where("{goal_time} < $timeLimit");
88
+ break;
89
+
90
+ }
91
+ $query->group();
92
+ //die($query);
93
+ }
94
+
95
+
96
+
97
+
98
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
99
+ {
100
+ parent::_prepareCollection($collection);
101
+ $collection->addField('goal_time');
102
+ }
103
+
104
+
105
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
106
+ {
107
+ parent::prepareGridColumns($grid);
108
+
109
+ $grid->addColumn('goal_time', array(
110
+ 'header' => $this->__('Goal Time'),
111
+ 'type' => 'datetime',
112
+ 'index' => 'goal_time'
113
+ ));
114
+ }
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ /**
124
+ * html for settings in option form
125
+ *
126
+ * @return string
127
+ */
128
+ protected function prepareForm()
129
+ {
130
+ return $this->__("If goal occurred no later then %s after recipient %s the campaign.",
131
+ $this->getTimeHtml('offset'),
132
+ $this->getSelectElement('action')->toHtml()
133
+ );
134
+ }
135
+
136
+
137
+
138
+ public function getActionOptions()
139
+ {
140
+ return array(
141
+ self::ACTION_VIEWED => $this->__('viewed'),
142
+ self::ACTION_CLICKED => $this->__('clicked'),
143
+ self::ACTION_RECIEVED => $this->__('recieved'),
144
+ );
145
+ }
146
+
147
+
148
+
149
+
150
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Abstract.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ abstract class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Abstract
29
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
30
+ {
31
+
32
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
33
+ {
34
+ return $parent->hasInterface('recipient_id');
35
+ }
36
+
37
+
38
+
39
+
40
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Interact.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Interact
29
+ extends Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Abstract
30
+ {
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Column.php ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ abstract class Mzax_Emarketing_Model_Object_Filter_Column
29
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
30
+ {
31
+
32
+ const VALUE_KEY = 'value';
33
+
34
+
35
+
36
+ protected $_formText = '%s %s %s.';
37
+
38
+
39
+ /**
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_requireBinding;
44
+
45
+ protected $_label;
46
+
47
+
48
+ protected $_inputType = 'string';
49
+
50
+
51
+
52
+
53
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
54
+ {
55
+ return $this->_acceptParent($parent, $this->_requireBinding);
56
+ }
57
+
58
+
59
+
60
+
61
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
62
+ {
63
+ /* @var $adapter Zend_Db_Adapter_Abstract */
64
+ $adapter = $query->getAdapter();
65
+
66
+ $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->_inputType));
67
+ $value = $this->getData(self::VALUE_KEY);
68
+
69
+ if($this->_inputType === 'boolean') {
70
+ $value = '1';
71
+ }
72
+
73
+ switch($operator) {
74
+ case '!=':
75
+ case '>=':
76
+ case '<=':
77
+ case '>':
78
+ case '<': return $query->where("{{$this->_requireBinding}} {$operator} ?", $value); break;
79
+ case '{}': return $query->where("{{$this->_requireBinding}} LIKE ?", "%$value%"); break;
80
+ case '!{}': return $query->where("{{$this->_requireBinding}} NOT LIKE ?", "%$value%"); break;
81
+ case '()': return $query->where("{{$this->_requireBinding}} IN (?)", $this->_explode($value)); break;
82
+ case '!()': return $query->where("{{$this->_requireBinding}} NOT IN (?)", $this->_explode($value)); break;
83
+ default: return $query->where("{{$this->_requireBinding}} = ?", $value); break;
84
+ }
85
+ }
86
+
87
+
88
+
89
+
90
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
91
+ {
92
+ parent::_prepareCollection($collection);
93
+ $collection->addField($this->_requireBinding);
94
+ }
95
+
96
+
97
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
98
+ {
99
+ parent::prepareGridColumns($grid);
100
+
101
+
102
+ if(!$grid->getColumn($this->_requireBinding))
103
+ {
104
+ $grid->addColumn($this->_requireBinding, array(
105
+ 'header' => $this->_label,
106
+ 'type' => $this->getColumnType(),
107
+ 'options' => $this->getGridValueOptions(),
108
+ 'index' => $this->_requireBinding
109
+ ));
110
+ }
111
+ }
112
+
113
+
114
+
115
+
116
+
117
+
118
+ /**
119
+ * html for settings in option form
120
+ *
121
+ * @return string
122
+ */
123
+ protected function prepareForm()
124
+ {
125
+ $operatorElement = $this->getOperatorElement();
126
+ $valueElement = $this->getValueElement();
127
+
128
+ switch($this->_inputType) {
129
+ case 'boolean':
130
+ return $html . $this->__($this->_formText,
131
+ $operatorElement->toHtml(),
132
+ $this->_label
133
+ );
134
+ }
135
+
136
+ return $this->__($this->_formText,
137
+ $this->_label,
138
+ $operatorElement->toHtml(),
139
+ $valueElement->toHtml()
140
+ );
141
+ }
142
+
143
+
144
+
145
+
146
+
147
+ /**
148
+ * Retrieve operator select element
149
+ *
150
+ * @return Varien_Data_Form_Element_Abstract
151
+ */
152
+ public function getOperatorElement()
153
+ {
154
+ $default = $this->helper()->getDefaultOperatorByType($this->_inputType);
155
+ $options = $this->helper()->getOperatorOptionsByType($this->_inputType);
156
+
157
+ return $this->getSelectElement('operator', $default, $options);
158
+ }
159
+
160
+
161
+
162
+ /**
163
+ * Retroeve value form element
164
+ *
165
+ * @return Varien_Data_Form_Element_Abstract
166
+ */
167
+ public function getValueElement()
168
+ {
169
+ switch($this->_inputType) {
170
+
171
+ case 'date':
172
+ $element = $this->getDateElement(self::VALUE_KEY);
173
+ break;
174
+
175
+ case 'select':
176
+ case 'boolean':
177
+ $element = $this->getSelectElement(self::VALUE_KEY);
178
+ break;
179
+
180
+ case 'multiselect':
181
+ $element = $this->getMultiSelectElement(self::VALUE_KEY);
182
+ break;
183
+
184
+ default:
185
+ $element = $this->getInputElement(self::VALUE_KEY);
186
+ break;
187
+ }
188
+
189
+ if($this->getChooserUrl()) {
190
+ $element->setExplicitApply(true);
191
+ $element->setAfterElementHtml($this->getChooserTriggerHtml());
192
+ }
193
+
194
+ return $element;
195
+ }
196
+
197
+
198
+
199
+
200
+
201
+
202
+ /**
203
+ * Retrieve all value options as hash
204
+ *
205
+ * array(value => label,...)
206
+ *
207
+ * @return array
208
+ */
209
+ public function getValueOptions()
210
+ {
211
+ switch($this->_inputType) {
212
+ case 'boolean':
213
+ return array(
214
+ '1' => $this->__('is'),
215
+ '0' => $this->__('is not')
216
+ );
217
+ }
218
+ return array();
219
+ }
220
+
221
+
222
+
223
+ /**
224
+ * Retrieve value options for the grid
225
+ *
226
+ * @return array
227
+ */
228
+ public function getGridValueOptions()
229
+ {
230
+ switch($this->_inputType) {
231
+ case 'boolean':
232
+ return array(
233
+ '1' => $this->__('Yes'),
234
+ '0' => $this->__('No')
235
+ );
236
+ }
237
+ return $this->getValueOptions();
238
+ }
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+ /**
248
+ * Retrieve input type
249
+ *
250
+ * @return string
251
+ */
252
+ public function getColumnType()
253
+ {
254
+ switch($this->_inputType) {
255
+ case 'multiselect':
256
+ case 'select':
257
+ case 'boolean':
258
+ return 'options';
259
+ }
260
+ return 'text';
261
+ }
262
+
263
+
264
+
265
+
266
+
267
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Combine.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Object_Filter_Combine
25
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
26
+ {
27
+
28
+ const DEFAULT_AGGREGATOR = 'all';
29
+
30
+ const DEFAULT_EXPECTATION = 'true';
31
+
32
+
33
+ protected $_type = 'combine';
34
+
35
+
36
+ protected $_allowChildren = true;
37
+
38
+
39
+
40
+ /**
41
+ * This filter does not provide its own object
42
+ * instead it always uses its parents one
43
+ *
44
+ * @return boolean
45
+ */
46
+ public function hasOwnObject()
47
+ {
48
+ return false;
49
+ }
50
+
51
+
52
+
53
+
54
+ /**
55
+ * Works with all parents
56
+ *
57
+ * @see Mzax_Emarketing_Model_Object_Filter_Component::acceptParent()
58
+ * @return boolean Always true
59
+ */
60
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
61
+ {
62
+ return true;
63
+ }
64
+
65
+
66
+
67
+
68
+ /**
69
+ * Retrieve final filter query that unites all id filter queries
70
+ * and retrieve only those id's that exist in all filters
71
+ *
72
+ * @return string
73
+ */
74
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
75
+ {
76
+ $conditions = $this->_getConditions();
77
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
78
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
79
+
80
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
81
+ $select->useTemporaryTable($this->getTempTableName());
82
+
83
+ $query->joinSelect('id', $select, 'filter');
84
+ $query->group();
85
+ }
86
+
87
+
88
+
89
+
90
+
91
+ /**
92
+ * Prepare recipient collection
93
+ *
94
+ * @return void
95
+ */
96
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
97
+ {
98
+ parent::_prepareCollection($collection);
99
+ $collection->addField('matches', 'filter.matches');
100
+ }
101
+
102
+
103
+
104
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
105
+ {
106
+ parent::prepareGridColumns($grid);
107
+ $grid->addColumn('matches', array(
108
+ 'header' => $this->__('Matches'),
109
+ 'width' => '100px',
110
+ 'index' => 'matches'
111
+ ));
112
+ }
113
+
114
+
115
+
116
+ public function getAvailableFilters()
117
+ {
118
+ return $this->_parent->getAvailableFilters();
119
+ }
120
+
121
+
122
+
123
+
124
+ public function getTitle()
125
+ {
126
+ return "Combinations of conditions";
127
+ }
128
+
129
+
130
+ /**
131
+ * html for settings in option form
132
+ *
133
+ * @return string
134
+ */
135
+ protected function prepareForm()
136
+ {
137
+ $aggregatorElment = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
138
+ $expectationElment = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
139
+
140
+ return $this->__('If %s of these conditions are %s:',
141
+ $aggregatorElment->toHtml(), $expectationElment->toHtml());
142
+ }
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Component.php ADDED
@@ -0,0 +1,804 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Object
25
+ {
26
+
27
+ const ID_ALIAS = 'object_id';
28
+
29
+
30
+
31
+ protected $_id;
32
+
33
+
34
+ /**
35
+ * Parent Filter
36
+ *
37
+ * @var Mzax_Emarketing_Model_Object_Filter_Component
38
+ */
39
+ protected $_parent;
40
+
41
+
42
+
43
+
44
+
45
+
46
+ /**
47
+ *
48
+ * @var Mzax_Emarketing_Model_Object_Collection
49
+ */
50
+ protected $_collection;
51
+
52
+
53
+
54
+
55
+
56
+ /**
57
+ * Can have children
58
+ *
59
+ * @var boolean
60
+ */
61
+ protected $_allowChildren = false;
62
+
63
+
64
+
65
+
66
+
67
+
68
+ /**
69
+ * The subject provides generic information for the email provider/filter object.
70
+ * So for instance, the email provider customer
71
+ *
72
+ *
73
+ * @return Mzax_Emarketing_Model_Object_Abstract
74
+ */
75
+ abstract function getObject();
76
+
77
+
78
+
79
+ /**
80
+ *
81
+ * @return Mzax_Emarketing_Model_Object_Abstract
82
+ */
83
+ public function getParentObject()
84
+ {
85
+ return $this->getParentOrSelf()->getObject();
86
+ }
87
+
88
+
89
+ /**
90
+ * Wheather the filter has own object
91
+ * or uses the parents object only
92
+ *
93
+ * @return boolean
94
+ */
95
+ public function hasOwnObject()
96
+ {
97
+ return $this->_allowChildren;
98
+ }
99
+
100
+
101
+ /**
102
+ * Allow children to reuse bindings even if this
103
+ * filter already uses them
104
+ *
105
+ * Be default never
106
+ *
107
+ * @param string $binding
108
+ * @return boolean
109
+ */
110
+ public function allowChildBinding($binding)
111
+ {
112
+ return false;
113
+ }
114
+
115
+
116
+
117
+
118
+ /**
119
+ * Retrieve Expresion used for current time
120
+ *
121
+ * By default the function should return the
122
+ * mysql expression NOW() but we want to be able
123
+ * to change the current time in order to test
124
+ * filters etc for different times
125
+ *
126
+ * Also some filters may require the local time
127
+ * not the gmt time
128
+ *
129
+ * @param boolean $gmt get as gmt time
130
+ * @return array
131
+ */
132
+ public function getCurrentTime($gmt = true)
133
+ {
134
+ $adapter = $this->_getReadAdapter();
135
+
136
+ // is current specfied time is the local time or not
137
+ $isLocal = (bool) $this->getParam('is_local_time');
138
+
139
+ // check if we emulate current itme
140
+ $now = (array) $this->getParam('current_time');
141
+ $now = array_filter($now);
142
+ foreach($now as &$time) {
143
+ if(!$time instanceof Zend_Db_Expr) {
144
+ $time = $adapter->quote($time);
145
+ }
146
+ }
147
+ if(empty($now)) {
148
+ $now[] = $adapter->quote(now());
149
+ }
150
+
151
+ $result = array();
152
+ foreach($now as $date) {
153
+ if($gmt && $isLocal) {
154
+ $result[] = $this->toGmtTime($date);
155
+ }
156
+ else if(!$gmt && !$isLocal) {
157
+ $result[] = $this->toLocalTime($date);
158
+ }
159
+ else {
160
+ $result[] = $date;
161
+ }
162
+ }
163
+ return $result;
164
+ }
165
+
166
+
167
+
168
+ /**
169
+ * Retrieve filter select
170
+ *
171
+ * @return Mzax_Emarketing_Db_Select
172
+ */
173
+ public function getSelect()
174
+ {
175
+ return $this->getPreparedQuery();
176
+ }
177
+
178
+
179
+
180
+ /**
181
+ * Retrieve prepared query
182
+ *
183
+ * @return Mzax_Emarketing_Db_Select
184
+ */
185
+ final public function getPreparedQuery()
186
+ {
187
+ $query = $this->getParentOrSelf()->getQuery();
188
+ $this->_prepareQuery($query->lock());
189
+ return $query->lock(false);
190
+ }
191
+
192
+
193
+
194
+ /**
195
+ * Takes the query provided by the parent and modifies it
196
+ * to match the filter settings
197
+ *
198
+ * @param Mzax_Emarketing_Db_Select $query
199
+ */
200
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
201
+ {
202
+ }
203
+
204
+
205
+
206
+
207
+ /**
208
+ * Retrieve objects id field name
209
+ *
210
+ * @return string
211
+ */
212
+ public function getIdFieldName()
213
+ {
214
+ throw new Exception("getid field???");
215
+ return $this->getObject()->getIdFieldName();
216
+ }
217
+
218
+
219
+
220
+
221
+ /**
222
+ * Get filter select that this object will
223
+ * pass down to all sub filter
224
+ *
225
+ * By default it is the parents or the objects filter
226
+ * This method can be overwritten
227
+ *
228
+ * @return Mzax_Emarketing_Db_Select
229
+ */
230
+ public function getQuery()
231
+ {
232
+ if(!$this->_allowChildren && $this->_parent) {
233
+ return $this->_parent->getQuery();
234
+ }
235
+ return $this->getObject()->getQuery();
236
+ }
237
+
238
+
239
+
240
+
241
+
242
+
243
+ /**
244
+ * Retrieve collection instance from object model
245
+ *
246
+ * @return Mzax_Emarketing_Model_Object_Collection
247
+ */
248
+ public function getCollection()
249
+ {
250
+ if(!$this->_collection) {
251
+ /* @var $collection Mzax_Emarketing_Model_Object_Collection */
252
+ $this->_collection = Mage::getModel('mzax_emarketing/object_collection');
253
+ $this->_collection->setObject($this->getParentObject());
254
+ $this->_collection->setQuery($this->getPreparedQuery());
255
+
256
+ $this->_prepareCollection($this->_collection);
257
+ }
258
+ return $this->_collection;
259
+ }
260
+
261
+
262
+
263
+
264
+ /**
265
+ *
266
+ * @return Mzax_Emarketing_Model_Object_Collection
267
+ *//*
268
+ public function getCollection()
269
+ {
270
+ if(!$this->_collection) {
271
+ $this->_collection = $this->getParentObject()->getCollection();
272
+ $this->_prepareCollection($this->_collection);
273
+ }
274
+ return $this->_collection;
275
+ }
276
+ */
277
+
278
+
279
+
280
+
281
+ /**
282
+ * Prepare recipient collection
283
+ *
284
+ * @return void
285
+ */
286
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
287
+ {
288
+ $this->getParentObject()->prepareCollection($collection);
289
+ }
290
+
291
+
292
+
293
+
294
+ /**
295
+ * Set ID
296
+ *
297
+ * @param string $id
298
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
299
+ */
300
+ public function setId($id)
301
+ {
302
+ $this->_id = $id;
303
+ return $this;
304
+ }
305
+
306
+
307
+ /**
308
+ *
309
+ *
310
+ * @return string
311
+ */
312
+ public function getId()
313
+ {
314
+ if(!$this->_id) {
315
+ $this->_id = '1';
316
+ }
317
+ return $this->_id;
318
+ }
319
+
320
+
321
+
322
+
323
+
324
+ /**
325
+ * Set parent
326
+ *
327
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
328
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
329
+ */
330
+ public function setParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
331
+ {
332
+ $this->_parent = $parent;
333
+ return $this;
334
+ }
335
+
336
+
337
+ /**
338
+ * Retrieve parent object
339
+ *
340
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
341
+ */
342
+ public function getParent()
343
+ {
344
+ return $this->_parent;
345
+ }
346
+
347
+
348
+ /**
349
+ * Retrieve parent object
350
+ *
351
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
352
+ */
353
+ public function getParentOrSelf()
354
+ {
355
+ if(!$this->_parent) {
356
+ return $this;
357
+ }
358
+ return $this->_parent;
359
+ }
360
+
361
+
362
+
363
+ /**
364
+ * Return all ancestors
365
+ *
366
+ * @return array
367
+ */
368
+ public function getAncestors()
369
+ {
370
+ $ancestors = array();
371
+ $parent = $this;
372
+ while($parent = $parent->getParent()) {
373
+ $ancestors[] = $parent;
374
+ }
375
+ return $ancestors;
376
+ }
377
+
378
+
379
+
380
+
381
+
382
+ /**
383
+ *
384
+ *
385
+ * @return boolean
386
+ */
387
+ public function hasBinding()
388
+ {
389
+ $func = array($this->getQuery(), 'hasBinding');
390
+ return call_user_func_array($func, func_get_args());
391
+ }
392
+
393
+
394
+
395
+
396
+
397
+ /**
398
+ * Retrieve top most object
399
+ *
400
+ * @return Mzax_Emarketing_Model_Object_Filter_Component
401
+ */
402
+ public function getRoot()
403
+ {
404
+ /* @var $object Mzax_Emarketing_Model_Object_Filter_Component */
405
+ $object = $this;
406
+
407
+ while($object->getParent()) {
408
+ $object = $object->getParent();
409
+ }
410
+
411
+ return $object;
412
+ }
413
+
414
+
415
+
416
+
417
+
418
+ /**
419
+ * Retrieve full type path
420
+ *
421
+ * @return $string
422
+ */
423
+ public function getTypePath($delimiter = '-')
424
+ {
425
+ $paths = array();
426
+
427
+ /* @var $object Mzax_Emarketing_Model_Object_Filter_Component */
428
+ $object = $this;
429
+ do {
430
+ if($object instanceof Mzax_Emarketing_Model_Object_Filter_Container) {
431
+ break;
432
+ }
433
+ $paths[] = $object->getType();
434
+ } while($object = $object->getParent());
435
+
436
+ $paths = array_reverse($paths);
437
+
438
+ return implode($delimiter, $paths);
439
+ }
440
+
441
+
442
+
443
+
444
+
445
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
446
+ {
447
+ return false;
448
+ }
449
+
450
+
451
+ /**
452
+ * Helper method to if filter can accept parent using bindings
453
+ *
454
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
455
+ * @param string $binding
456
+ * @return boolean|Ambigous <boolean, mixed>
457
+ */
458
+ protected function _acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent, $binding)
459
+ {
460
+ $bindngs = func_get_args();
461
+ array_shift($bindngs);
462
+
463
+ foreach($bindngs as $binding) {
464
+ // parent may allow to reuse filters for certain bindings
465
+ if(!$parent->allowChildBinding($binding))
466
+ {
467
+ /* @var $ancestor Mzax_Emarketing_Model_Object_Filter_Component */
468
+ foreach($parent->getAncestors() as $ancestor) {
469
+ // skip all filtes that only pass down objects
470
+ if(!$ancestor->hasOwnObject()) {
471
+ continue;
472
+ }
473
+ // stop if ancestor filter already has binding
474
+ if($ancestor->hasBinding($binding)) {
475
+ continue 2;
476
+ }
477
+ break;
478
+ }
479
+ }
480
+ if($parent->hasBinding($binding)) {
481
+ return true;
482
+ }
483
+ }
484
+ return false;
485
+ }
486
+
487
+
488
+ /**
489
+ * Retrieve id filter name
490
+ *
491
+ * The name of the id field that we use
492
+ * to filter.
493
+ *
494
+ * Usally it is the same name as the id field name
495
+ * however some filter almost act as an adapter,
496
+ * they allow to retrieve customer_ids, but use
497
+ * the order_id as filter
498
+ *
499
+ * @return string
500
+ */
501
+ public function getIdFilterName()
502
+ {
503
+ throw new Exception("getIdFilterName!!!");
504
+ return $this->getObject()->getIdFieldName();
505
+ }
506
+
507
+
508
+
509
+
510
+
511
+
512
+ /**
513
+ * Retrieve available child filters
514
+ *
515
+ * @return array
516
+ */
517
+ public function getAvailableFilters()
518
+ {
519
+ if(!$this->_allowChildren) {
520
+ return array();
521
+ }
522
+
523
+ $filters = self::getFilterFactory()->getFilters();
524
+ $result = array();
525
+
526
+ /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
527
+ foreach($filters as $name => $filter) {
528
+ if($filter->acceptParent($this)) {
529
+ foreach($filter->getOptions() as $key => $title) {
530
+ $result[$key] = $title;
531
+ }
532
+ }
533
+ }
534
+
535
+ return $result;
536
+ }
537
+
538
+
539
+
540
+
541
+
542
+
543
+ //--------------------------------------------------------------------------
544
+ //
545
+ // Recipient Grid Methods
546
+ //
547
+ //--------------------------------------------------------------------------
548
+
549
+
550
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
551
+ {
552
+ $this->getParentObject()->prepareGridColumns($grid);
553
+ }
554
+
555
+
556
+ public function afterGridLoadCollection(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
557
+ {
558
+ $this->getParentObject()->afterGridLoadCollection($grid);
559
+ }
560
+
561
+
562
+ public function afterLoadCollection($collection)
563
+ {
564
+ $this->getParentObject()->afterLoadCollection($grid);
565
+ }
566
+
567
+
568
+
569
+
570
+ public function getFormPrefix()
571
+ {
572
+ return 'filter';
573
+ }
574
+
575
+
576
+
577
+
578
+
579
+ //--------------------------------------------------------------------------
580
+ //
581
+ // Helper Methods
582
+ //
583
+ //--------------------------------------------------------------------------
584
+
585
+ const TEMP_TABLE_PREFIX = 'MZAX_TMP_FILTER_';
586
+
587
+ /**
588
+ * Retreive parameter set on the root object
589
+ *
590
+ * @param string $key
591
+ * @param mixed $default
592
+ * @return mixed
593
+ */
594
+ public function getParam($key, $default = null)
595
+ {
596
+ $value = $this->getRoot()->getData('param_' . $key);
597
+ if($value === null) {
598
+ return $default;
599
+ }
600
+ return $value;
601
+ }
602
+
603
+ public function setParam($key, $value)
604
+ {
605
+ $this->getRoot()->setData('param_' . $key, $value);
606
+ return $this;
607
+ }
608
+
609
+
610
+
611
+
612
+ /**
613
+ * Retrieve a uniqe temporary table name that is valid for the livetime of this
614
+ * filter instance.
615
+ *
616
+ * @param string $sufix
617
+ * @return string
618
+ */
619
+ public function getTempTableName($sufix = 'default')
620
+ {
621
+ // can be globaly disabled
622
+ if(!Mage::getStoreConfigFlag('mzax_emarketing/general/use_temp_tables')) {
623
+ return false;
624
+ }
625
+
626
+ // can be disabled by param
627
+ if($this->getParam('disable_temp_tables')) {
628
+ return false;
629
+ }
630
+
631
+ // only works if we have the rights
632
+ if(!$this->getResourceHelper()->hasTemporaryTablePrivilege()) {
633
+ return false;
634
+ }
635
+
636
+ //return false;
637
+ $hash = $this->getParam('unique_filter_hash', microtime().mt_rand(0, 1000));
638
+ return strtoupper(self::TEMP_TABLE_PREFIX . md5($hash . '__' . $this->getId()) . '_' . $sufix);
639
+ }
640
+
641
+
642
+
643
+
644
+
645
+ /**
646
+ * Retrieve id column name
647
+ *
648
+ * @return Zend_Db_Expr
649
+ */
650
+ public function getIdColumn()
651
+ {
652
+ return new Zend_Db_Expr("`e`.`{$this->_idFieldName}`");
653
+ }
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+ /**
662
+ * Retrieve session model
663
+ *
664
+ * @return Mzax_Emarketing_Model_Session
665
+ */
666
+ public function getSession()
667
+ {
668
+ return Mage::getSingleton('mzax_emarketing/session');
669
+ }
670
+
671
+
672
+
673
+
674
+ /**
675
+ * Retrieve provider factory
676
+ *
677
+ * @return Mzax_Emarketing_Model_Object_Filter
678
+ */
679
+ public static function getFilterFactory()
680
+ {
681
+ return Mage::getSingleton('mzax_emarketing/object_filter');
682
+ }
683
+
684
+
685
+
686
+
687
+ /**
688
+ *
689
+ * @return Mzax_Emarketing_Model_Resource_Helper
690
+ */
691
+ protected function getResourceHelper()
692
+ {
693
+ return Mage::getResourceSingleton('mzax_emarketing/helper');
694
+ }
695
+
696
+
697
+
698
+ /**
699
+ * Retrieve connection for read data
700
+ *
701
+ * @return Varien_Db_Adapter_Interface
702
+ */
703
+ protected function _getReadAdapter()
704
+ {
705
+ return $this->getResourceHelper()->getReadAdapter();
706
+ }
707
+
708
+
709
+
710
+ /**
711
+ * Retrieve connection for write data
712
+ *
713
+ * @return Varien_Db_Adapter_Interface
714
+ */
715
+ protected function _getWriteAdapter()
716
+ {
717
+ return $this->getResourceHelper()->getWriteAdapter();
718
+ }
719
+
720
+
721
+
722
+
723
+ /**
724
+ *
725
+ * @param string $table
726
+ * @param string $alias
727
+ * @param string $cols
728
+ * @return Mzax_Emarketing_Db_Select
729
+ */
730
+ protected function _select($table = null, $alias = null, $cols = null)
731
+ {
732
+ $select = $this->getResourceHelper()->select();
733
+ if($table) {
734
+ $select->from($this->_getTable($table, $alias), $cols);
735
+ }
736
+ return $select;
737
+ }
738
+
739
+
740
+ /**
741
+ * Retrieve table name
742
+ *
743
+ * @param string $table
744
+ * @param string $alias
745
+ * @return string
746
+ */
747
+ protected function _getTable($table, $alias = null)
748
+ {
749
+ $table = $this->getResourceHelper()->getTable($table);
750
+ if($alias) {
751
+ return array($alias => $table);
752
+ }
753
+ return $table;
754
+ }
755
+
756
+
757
+
758
+ /**
759
+ * Retrieve an attribute by entityname/attributename
760
+ *
761
+ * getAttribute(entity/attribute);
762
+ * getAttribute(customer/signupdate);
763
+ *
764
+ * @param string $attribute
765
+ * @throws Exception
766
+ *
767
+ * @return Mage_Catalog_Model_Resource_Eav_Attribute
768
+ */
769
+ protected function _getAttribute($attribute)
770
+ {
771
+ return $this->getResourceHelper()->getAttribute($attribute);
772
+ }
773
+
774
+
775
+
776
+
777
+
778
+
779
+ /**
780
+ * Retrieve form helper
781
+ *
782
+ * @return Mzax_Emarketing_Helper_Data
783
+ */
784
+ protected function helper()
785
+ {
786
+ return Mage::helper('mzax_emarketing');
787
+ }
788
+
789
+
790
+
791
+ /**
792
+ * Translate
793
+ *
794
+ * @param string $message
795
+ * @param string $args,...
796
+ * @return string
797
+ */
798
+ protected function __()
799
+ {
800
+ return call_user_func_array(array($this->helper(), '__'), func_get_args());
801
+ }
802
+
803
+
804
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Abstract.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ abstract class Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
29
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
30
+ {
31
+
32
+
33
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
34
+ {
35
+ return $this->_acceptParent($parent, 'customer_id');
36
+ }
37
+
38
+
39
+
40
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address.php ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @author Jacob Siefer
27
+ *
28
+ */
29
+ class Mzax_Emarketing_Model_Object_Filter_Customer_Address
30
+ extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
31
+ {
32
+ const DEFAULT_AGGREGATOR = 'all';
33
+
34
+ const DEFAULT_EXPECTATION = 'true';
35
+
36
+ const TYPE_BILLING = 'billing';
37
+ const TYPE_SHIPPING = 'shipping';
38
+
39
+
40
+
41
+ protected $_allowChildren = true;
42
+
43
+
44
+
45
+ /**
46
+ * (non-PHPdoc)
47
+ * @see Mzax_Emarketing_Model_Object_Filter_Abstract::getTitle()
48
+ */
49
+ public function getTitle()
50
+ {
51
+ return "Customer | Default Billing/Shippin Address...";
52
+ }
53
+
54
+
55
+
56
+
57
+ /**
58
+ *
59
+ * @return Mzax_Emarketing_Model_Object_Customer_Address
60
+ */
61
+ public function getObject()
62
+ {
63
+ return Mage::getSingleton('mzax_emarketing/object_customer_address');
64
+ }
65
+
66
+
67
+
68
+ /**
69
+ *
70
+ * @return Zend_Db_Select
71
+ */
72
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
73
+ {
74
+ $this->checkIndexes(true);
75
+
76
+ $conditions = $this->_getConditions();
77
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
78
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
79
+
80
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
81
+ $select->useTemporaryTable($this->getTempTableName());
82
+
83
+ $addressId = $query->joinAttribute('customer_id', 'customer/default_billing');
84
+
85
+ $query->joinSelect(array('id' => $addressId), $select, 'filter');
86
+ $query->group();
87
+ }
88
+
89
+
90
+
91
+
92
+
93
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
94
+ {
95
+ parent::_prepareCollection($collection);
96
+ }
97
+
98
+
99
+
100
+
101
+
102
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
103
+ {
104
+ parent::prepareGridColumns($grid);
105
+
106
+
107
+ }
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ /**
118
+ * (non-PHPdoc)
119
+ * @see Mzax_Emarketing_Model_Object_Filter_Abstract::prepareForm()
120
+ */
121
+ protected function prepareForm()
122
+ {
123
+ $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
124
+
125
+ return $this->__('If default billing address matches %s of these conditions:',
126
+ $aggregatorElement->toHtml()
127
+ );
128
+ }
129
+
130
+
131
+
132
+
133
+ /**
134
+ * The customer etnity int table does not have an index for value
135
+ * which is sort of required by this index
136
+ *
137
+ */
138
+ public function checkIndexes($create = false)
139
+ {
140
+ $adapter = $this->_getWriteAdapter();
141
+
142
+ $table = $this->_getAttribute('customer/default_billing')->getBackendTable();
143
+
144
+ $indexList = $adapter->getIndexList($table);
145
+
146
+ // check if we already created an index
147
+ if(isset($indexList['MZAX_IDX_VALUE_ID'])) {
148
+ return true;
149
+ }
150
+
151
+ // check for other indexes that can work
152
+ foreach($indexList as $index) {
153
+ switch(count($index['fields'])) {
154
+ case 1:
155
+ if($index['fields'][0] === 'value') {
156
+ return true;
157
+ }
158
+ break;
159
+ case 2:
160
+ if($index['fields'][0] === 'attribute_id' && $index['fields'][1] === 'value') {
161
+ return true;
162
+ }
163
+ break;
164
+ }
165
+ }
166
+
167
+
168
+ if($create && $this->canCreateIndex()) {
169
+ try {
170
+ $adapter->addIndex($table, 'MZAX_IDX_VALUE_ID', array('attribute_id', 'value'));
171
+ return true;
172
+ }
173
+ catch(Exception $e) {
174
+ if(Mage::getIsDeveloperMode()) {
175
+ throw $e;
176
+ }
177
+ Mage::logException($e);
178
+ return $this->__('Failed to create an index for the table "%s". Please check logs.', $table);
179
+ }
180
+ }
181
+ else if($this->canCreateIndex()) {
182
+ return true;
183
+ }
184
+
185
+ return $this->__('It is recommended to set an index on "value" for the table "%s" before using this filter.', $table);
186
+ }
187
+
188
+
189
+
190
+
191
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address/Attribute.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Filter for customer address attributes
27
+ *
28
+ * @author Jacob Siefer
29
+ */
30
+ class Mzax_Emarketing_Model_Object_Filter_Customer_Address_Attribute
31
+ extends Mzax_Emarketing_Model_Object_Filter_Attribute
32
+ {
33
+
34
+ /**
35
+ * Entity type code
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_entity = 'customer_address';
40
+
41
+
42
+ /**
43
+ * Binding required
44
+ *
45
+ * @var string
46
+ */
47
+ protected $_requireBinding = 'customer_address_id';
48
+
49
+
50
+
51
+ public function getTitle()
52
+ {
53
+ return "Customer Adddress";
54
+ }
55
+
56
+
57
+
58
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Attribute.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Customer_Attribute
29
+ extends Mzax_Emarketing_Model_Object_Filter_Attribute
30
+ {
31
+
32
+
33
+ protected $_entity = 'customer';
34
+
35
+
36
+ protected $_requireBinding = 'customer_id';
37
+
38
+
39
+
40
+ public function getTitle()
41
+ {
42
+ return "Customer Attributes";
43
+ }
44
+
45
+
46
+
47
+ protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
48
+ {
49
+ if($attribute->getFrontendLabel()) {
50
+ return true;
51
+ }
52
+ return false;
53
+ }
54
+
55
+
56
+
57
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Lastlogin.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @author Jacob Siefer
27
+ *
28
+ */
29
+ class Mzax_Emarketing_Model_Object_Filter_Customer_Lastlogin
30
+ extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
31
+ {
32
+
33
+
34
+ public function getTitle()
35
+ {
36
+ return "Customer | Last login";
37
+ }
38
+
39
+
40
+
41
+
42
+
43
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
44
+ {
45
+ $query->joinTable('customer_id', 'log/customer', 'log');
46
+
47
+ if($storeId = $this->getParam('store_id')) {
48
+ $query->where('`log`.`store_id` = ?', $storeId);
49
+ }
50
+
51
+ $query->group();
52
+ $query->having($this->getTimeRangeExpr('MAX(`log`.`login_at`)', 'login', false));
53
+ }
54
+
55
+
56
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
57
+ {
58
+ parent::_prepareCollection($collection);
59
+ $collection->addField('last_login', new Zend_Db_Expr('MAX(`log`.`login_at`)'));
60
+ }
61
+
62
+
63
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
64
+ {
65
+ parent::prepareGridColumns($grid);
66
+
67
+ $grid->addColumn('last_login', array(
68
+ 'header' => $this->__('Last Login'),
69
+ 'width' => '180px',
70
+ 'index' => 'last_login',
71
+ 'gmtoffset' => true,
72
+ 'type' =>'datetime'
73
+ ));
74
+ }
75
+
76
+
77
+
78
+
79
+
80
+ /**
81
+ * html for settings in option form
82
+ *
83
+ * @return string
84
+ */
85
+ protected function prepareForm()
86
+ {
87
+ return $this->__('Customers last login was %s ago.',
88
+ $this->getTimeRangeHtml('login')
89
+ );
90
+ }
91
+
92
+
93
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Name.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @author Jacob Siefer
27
+ *
28
+ */
29
+ class Mzax_Emarketing_Model_Object_Filter_Customer_Name
30
+ extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
31
+ {
32
+
33
+ public function getTitle()
34
+ {
35
+ return "Customer | Full Name";
36
+ }
37
+
38
+
39
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
40
+ {
41
+ $firstname = $query->joinAttribute('customer_id', 'customer/firstname');
42
+ $lastname = $query->joinAttribute('customer_id', 'customer/lastname');
43
+
44
+ $query->where($this->getWhereSql('name', "CONCAT_WS(' ', $firstname, $lastname)"));
45
+ }
46
+
47
+
48
+
49
+
50
+ /**
51
+ * html for settings in option form
52
+ *
53
+ * @return string
54
+ */
55
+ protected function prepareForm()
56
+ {
57
+ return $this->__('Customer name %s.',
58
+ $this->getInputHtml('name')
59
+ );
60
+ }
61
+
62
+
63
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Order.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ * @author Jacob Siefer
27
+ *
28
+ */
29
+ class Mzax_Emarketing_Model_Object_Filter_Customer_Order
30
+ extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
31
+ {
32
+ const DEFAULT_AGGREGATOR = 'all';
33
+
34
+ const DEFAULT_EXPECTATION = 'true';
35
+
36
+
37
+
38
+ protected $_allowChildren = true;
39
+
40
+
41
+
42
+ /**
43
+ * (non-PHPdoc)
44
+ * @see Mzax_Emarketing_Model_Object_Filter_Abstract::getTitle()
45
+ */
46
+ public function getTitle()
47
+ {
48
+ return "Customer | Has order(s)...";
49
+ }
50
+
51
+
52
+
53
+ public function getQuery()
54
+ {
55
+ $query = $this->getObject()->getQuery();
56
+ $query->setColumn('customer_id');
57
+ $query->setColumn('order_id');
58
+
59
+ return $query;
60
+ }
61
+
62
+
63
+ /**
64
+ *
65
+ * @return Mzax_Emarketing_Model_Object_Order
66
+ */
67
+ public function getObject()
68
+ {
69
+ return Mage::getSingleton('mzax_emarketing/object_order');
70
+ }
71
+
72
+
73
+
74
+ /**
75
+ *
76
+ * @return Zend_Db_Select
77
+ */
78
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
79
+ {
80
+ $conditions = $this->_getConditions();
81
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
82
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
83
+
84
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
85
+
86
+ /* Check if we are looking for customer with no orders,
87
+ * Use current query object and alter it without breaking the query structure as
88
+ * we need to union the result with the sub filters
89
+ */
90
+ if($this->checkIfMatchZero('orders')) {
91
+
92
+ $customerId = new Zend_Db_Expr('`customer`.`entity_id`');
93
+ $zeroOrderQuery = $this->getQuery();
94
+ $zeroOrderQuery->joinRight(array('entity_id' => '{customer_id}'), 'customer/entity', 'customer');
95
+ $zeroOrderQuery->where('{order_id} IS NULL');
96
+ $zeroOrderQuery->addColumn('customer_id', $customerId);
97
+ $zeroOrderQuery->group($customerId);
98
+ $select = $this->_select()->union(array($zeroOrderQuery->getSelect(), $select));
99
+ }
100
+
101
+ $select->useTemporaryTable($this->getTempTableName());
102
+
103
+ $query->joinSelect('customer_id', $select, 'filter', 'customer_id');
104
+ $query->having($this->getWhereSql('orders', 'COUNT(`order_id`)'));
105
+ $query->group();
106
+ }
107
+
108
+
109
+
110
+
111
+
112
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
113
+ {
114
+ parent::_prepareCollection($collection);
115
+ $collection->addField('customer_id');
116
+ $collection->addField('orders', new Zend_Db_Expr('COUNT(`order_id`)'));
117
+ }
118
+
119
+
120
+
121
+
122
+
123
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
124
+ {
125
+ parent::prepareGridColumns($grid);
126
+
127
+ $grid->addColumn('orders', array(
128
+ 'header' => $this->__('Matching Orders'),
129
+ 'index' => 'orders',
130
+ ));
131
+
132
+ $grid->setDefaultSort('count_orders');
133
+ $grid->setDefaultDir('DESC');
134
+
135
+ }
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ /**
146
+ * (non-PHPdoc)
147
+ * @see Mzax_Emarketing_Model_Object_Filter_Abstract::prepareForm()
148
+ */
149
+ protected function prepareForm()
150
+ {
151
+ $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
152
+ $expectationElement = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
153
+
154
+ return $this->__('If number of orders, with %s of these conditions %s, %s:',
155
+ $aggregatorElement->toHtml(),
156
+ $expectationElement->toHtml(),
157
+ $this->getInputHtml('orders', 'numeric')
158
+ );
159
+ }
160
+
161
+
162
+
163
+
164
+
165
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Main.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ abstract class Mzax_Emarketing_Model_Object_Filter_Main extends Mzax_Emarketing_Model_Object_Filter_Combine
25
+ {
26
+
27
+
28
+ public function getId()
29
+ {
30
+ return '1';
31
+ }
32
+
33
+
34
+
35
+ /**
36
+ * A main filter object should always provide
37
+ * its own object
38
+ *
39
+ * @return boolean
40
+ */
41
+ public function hasOwnObject()
42
+ {
43
+ return true;
44
+ }
45
+
46
+
47
+ /**
48
+ * Has any filters been added?
49
+ *
50
+ * @return boolean
51
+ */
52
+ public function hasFilters()
53
+ {
54
+ return !empty($this->_filters);
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+ public function getAvailableFilters()
64
+ {
65
+ return Mzax_Emarketing_Model_Object_Filter_Component::getAvailableFilters();
66
+ }
67
+
68
+
69
+
70
+
71
+ /**
72
+ * Retrieve filter using type path
73
+ *
74
+ * Filters depend on their parent and ancestor, therefor we need
75
+ * to retrieve a new filter using its full type path.
76
+ *
77
+ * @param array $path
78
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
79
+ */
80
+ public function createFilterFromTypePath($path)
81
+ {
82
+ $params = array();
83
+
84
+ if(is_string($path)) {
85
+ if(strpos($path, '?')) {
86
+ $parts = explode('?', $path);
87
+ $path = array_shift($parts);
88
+ foreach($parts as $part) {
89
+ $var = explode('=', $part, 2);
90
+ if(count($var) === 2) {
91
+ $params[$var[0]] = urldecode($var[1]);
92
+ }
93
+ }
94
+ }
95
+ $path = explode('-', $path);
96
+ }
97
+ // ignore self
98
+ array_shift($path);
99
+
100
+ $filter = null;
101
+ $parent = $this;
102
+ while(count($path)) {
103
+ $filterName = array_shift($path);
104
+ $filter = $this->getFilterFactory()->factory($filterName);
105
+ if(!$filter) {
106
+ throw new Exception("No filter found by name: $filterName");
107
+ }
108
+ $filter->setParent($parent);
109
+ $parent = $filter;
110
+ }
111
+ $filter->addData($params);
112
+ return $filter;
113
+ }
114
+
115
+
116
+
117
+
118
+ /**
119
+ * Retrieve filter by id
120
+ *
121
+ * @param string $id e.g. 1--1--2--3--1--2
122
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract
123
+ */
124
+ public function getFilterById($id)
125
+ {
126
+ $path = explode('--', $id);
127
+ array_shift($path);
128
+ $filter = $this->getFilter();
129
+
130
+ /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
131
+ while($filter && $i = (int) array_shift($path)) {
132
+ $filter = $filter->getFilterByIndex($i-1);
133
+ }
134
+ return $filter;
135
+ }
136
+
137
+
138
+
139
+
140
+
141
+ /**
142
+ * (non-PHPdoc)
143
+ * @see Mzax_Emarketing_Model_Object_Filter_Component::getQuery()
144
+ */
145
+ public function getQuery()
146
+ {
147
+ $query = $this->getObject()->getQuery();
148
+ return $query;
149
+ }
150
+
151
+
152
+
153
+
154
+ /**
155
+ * The default filter instance
156
+ *
157
+ * @return Mzax_Emarketing_Model_Object_Filter_Combine
158
+ */
159
+ public function getFilter()
160
+ {
161
+ return $this;
162
+ if(!$this->_filter) {
163
+ $this->_filter = Mage::getModel('mzax_emarketing/object_filter_combine')
164
+ ->load($this->getFilterData())
165
+ ->setId('1')
166
+ ->setParent($this);
167
+ }
168
+ return $this->_filter;
169
+ }
170
+
171
+
172
+
173
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Newsletter.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Object_Filter_Newsletter
25
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
26
+ {
27
+
28
+ const DEFAULT_STATUS = 1;
29
+ const DEFAULT_CONDITION = 'is';
30
+
31
+
32
+
33
+
34
+ public function getTitle()
35
+ {
36
+ return "Newsletter | Subscription Status";
37
+ }
38
+
39
+
40
+
41
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
42
+ {
43
+ return $this->_acceptParent($parent, 'customer_id', 'subscriber_id', 'subscriber_status');
44
+ return $parent->hasBinding('customer_id', 'subscriber_id', 'subscriber_status');
45
+ }
46
+
47
+
48
+
49
+
50
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
51
+ {
52
+ $condition = $this->getDataSetDefault('condition', self::DEFAULT_CONDITION);
53
+ $status = $this->getDataSetDefault('status', self::DEFAULT_STATUS);
54
+
55
+ if(!$query->hasBinding('subscriber_status'))
56
+ {
57
+ if($query->hasBinding('subscriber_id')) {
58
+ $query->joinTableLeft('subscriber_id', 'newsletter/subscriber', 'subscriber');
59
+ }
60
+ else if($query->hasBinding('customer_id')) {
61
+ $query->joinTableLeft('customer_id', 'newsletter/subscriber', 'subscriber');
62
+ }
63
+ $query->addBinding('subscriber_status', 'subscriber.subscriber_status');
64
+ }
65
+
66
+ $condition = $condition === 'is' ? '=' : '!=';
67
+
68
+ $query->where("{subscriber_status} $condition ?", $status);
69
+ }
70
+
71
+
72
+
73
+
74
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
75
+ {
76
+ parent::_prepareCollection($collection);
77
+ $collection->addField('newsletter_status', 'subscriber_status');
78
+ }
79
+
80
+
81
+
82
+
83
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
84
+ {
85
+ parent::prepareGridColumns($grid);
86
+
87
+ $grid->addColumn('newsletter_status', array(
88
+ 'header' => $this->__('Newsletter'),
89
+ 'width' => '80px',
90
+ 'index' => 'newsletter_status',
91
+ 'align' => 'center',
92
+ 'type' => 'options',
93
+ 'options' => array_map('ucwords', $this->getStatusOptions())
94
+ ));
95
+
96
+ }
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ /**
106
+ * html for settings in option form
107
+ *
108
+ * @return string
109
+ */
110
+ protected function prepareForm()
111
+ {
112
+ $conditionElment = $this->getSelectElement('condition', self::DEFAULT_CONDITION);
113
+ $subscribeElment = $this->getSelectElement('status', self::DEFAULT_STATUS);
114
+
115
+ return $this->__('Newsletter subscription status %s %s.',
116
+ $conditionElment->toHtml(),
117
+ $subscribeElment->toHtml()
118
+ );
119
+ }
120
+
121
+
122
+
123
+
124
+
125
+ protected function getStatusOptions()
126
+ {
127
+ return array(
128
+ Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED => $this->__('subscribed'),
129
+ Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED => $this->__('unsubscribed'),
130
+ Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE => $this->__('not activated'),
131
+ Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => $this->__('unconfirmed')
132
+ );
133
+ }
134
+
135
+
136
+
137
+ protected function getConditionOptions()
138
+ {
139
+ return array(
140
+ 'is' => $this->__('is'),
141
+ 'is_not' => $this->__('is not')
142
+ );
143
+ }
144
+
145
+
146
+
147
+
148
+
149
+
150
+ /*
151
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
152
+ {
153
+ parent::_prepareCollection($collection);
154
+
155
+ if(!$collection->hasBinding('subscriber_status'))
156
+ {
157
+ if($collection->hasBinding('subscriber_id')) {
158
+ $collection->getQuery()->joinLeft('subscriber_id', 'newsletter/subscriber', 'subscriber');
159
+ }
160
+ else if($collection->hasBinding('customer_id')) {
161
+ $collection->getQuery()->joinLeft('customer_id', 'newsletter/subscriber', 'subscriber');
162
+ }
163
+ $collection->addField('newsletter_status', 'subscriber.subscriber_status');
164
+ }
165
+ else {
166
+ $collection->addField('newsletter_status', 'subscriber_status');
167
+ }
168
+
169
+ return $collection;
170
+ }
171
+
172
+ */
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Abstract.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ abstract class Mzax_Emarketing_Model_Object_Filter_Order_Abstract
33
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
34
+ {
35
+
36
+
37
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
38
+ {
39
+ return $this->_acceptParent($parent, 'order_id');
40
+ }
41
+
42
+
43
+
44
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Address.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Object_Filter_Order_Address
32
+ extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
33
+ {
34
+
35
+ const DEFAULT_AGGREGATOR = 'all';
36
+
37
+ const DEFAULT_EXPECTATION = 'true';
38
+
39
+
40
+ const TYPE_BILLING = 'billing';
41
+ const TYPE_SHIPPING = 'shipping';
42
+
43
+
44
+ protected $_allowChildren = true;
45
+
46
+
47
+
48
+
49
+ public function getTitle()
50
+ {
51
+ return "Order | Billing/Shipping Address matches...";
52
+ }
53
+
54
+
55
+
56
+
57
+
58
+ /**
59
+ *
60
+ * @return Mzax_Emarketing_Model_Object_OrderItem
61
+ */
62
+ public function getObject()
63
+ {
64
+ return Mage::getSingleton('mzax_emarketing/object_orderAddress');
65
+ }
66
+
67
+
68
+ public function getQuery()
69
+ {
70
+ $query = $this->getObject()->getQuery();
71
+ $query->setColumn('order_id');
72
+
73
+ $query->where('address_type = ?', $this->getDataSetDefault('address_type', self::TYPE_BILLING));
74
+
75
+ return $query;
76
+ }
77
+
78
+
79
+
80
+
81
+
82
+ /**
83
+ *
84
+ * @return Zend_Db_Select
85
+ */
86
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
87
+ {
88
+ $conditions = $this->_getConditions();
89
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
90
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
91
+
92
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
93
+ $select->useTemporaryTable($this->getTempTableName());
94
+
95
+ $query->joinSelect('order_id', $select, 'filter');
96
+ $query->group();
97
+ }
98
+
99
+
100
+
101
+
102
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
103
+ {
104
+ parent::_prepareCollection($collection);
105
+ }
106
+
107
+
108
+
109
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
110
+ {
111
+ parent::prepareGridColumns($grid);
112
+
113
+
114
+
115
+ }
116
+
117
+
118
+
119
+ /**
120
+ * html for settings in option form
121
+ *
122
+ * @return string
123
+ */
124
+ protected function prepareForm()
125
+ {
126
+ return $this->__('If %s address matches %s of these conditions:',
127
+ $this->getSelectElement('address_type', self::TYPE_BILLING)->toHtml(),
128
+ $this->getSelectElement('aggregator', 'all')->toHtml()
129
+ );
130
+ }
131
+
132
+
133
+
134
+ protected function getAddressTypeOptions()
135
+ {
136
+ return array(
137
+ self::TYPE_BILLING => $this->__('billing'),
138
+ self::TYPE_SHIPPING => $this->__('shipping'),
139
+ );
140
+ }
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Campaign.php ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @method Mzax_Emarketing_Model_Object_Filter_Order_Campaign setJoin()
26
+ * @method Mzax_Emarketing_Model_Object_Filter_Order_Campaign setCampaign()
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
33
+ extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
34
+ {
35
+
36
+ const DEFAULT_JOIN = 'direct';
37
+
38
+ const DEFAULT_CAMPAIGN = 'current';
39
+
40
+ const DEFAULT_AGGREGATOR = 'all';
41
+
42
+ const DEFAULT_EXPECTATION = 'true';
43
+
44
+
45
+ protected $_allowChildren = true;
46
+
47
+
48
+ /**
49
+ *
50
+ * @var Mzax_Emarketing_Model_Campaign
51
+ */
52
+ protected $_campaign;
53
+
54
+
55
+ public function getTitle()
56
+ {
57
+ return "Order | Link directly/indirectly to emarketing campaign";
58
+ }
59
+
60
+
61
+
62
+ /**
63
+ *
64
+ * @return Mzax_Emarketing_Model_Object_Recipient
65
+ */
66
+ public function getObject()
67
+ {
68
+ return Mage::getSingleton('mzax_emarketing/object_recipient');
69
+ }
70
+
71
+
72
+
73
+
74
+ public function getQuery()
75
+ {
76
+ $campaign = $this->getCampaign();
77
+
78
+ $query = $this->getObject()->getQuery();
79
+ if($campaign) {
80
+ $query->joinSelect('recipient_id', $this->getRecipientsByOrder(), 'recipient_order');
81
+ $query->where('{campaign_id} = ?', $campaign->getId());
82
+ }
83
+ $query->addBinding('goal_id', 'order_id', 'recipient_order');
84
+ $query->addBinding('goal_time', 'order_time', 'recipient_order');
85
+ $query->setColumn('recipient_id');
86
+ $query->setColumn('goal_id');
87
+
88
+ if(($variationId = $this->getVariation()) !== null) {
89
+ $query->where('{variation_id} = ?', $variationId);
90
+ }
91
+
92
+ return $query;
93
+
94
+ }
95
+
96
+
97
+
98
+
99
+ /**
100
+ *
101
+ * @return Zend_Db_Select
102
+ */
103
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
104
+ {
105
+ $conditions = $this->_getConditions();
106
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
107
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
108
+
109
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
110
+
111
+ $query->joinSelect(array('goal_id' => '{order_id}'), $select, 'recipients');
112
+ $query->group();
113
+
114
+ $query->provide('recipient_id', new Zend_Db_Expr('MAX(`recipients`.`id`)'));
115
+ }
116
+
117
+
118
+
119
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
120
+ {
121
+ parent::_prepareCollection($collection);
122
+ $collection->addField('recipient_ids', new Zend_Db_Expr('GROUP_CONCAT(`recipients`.`id` SEPARATOR ", ")'));
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
130
+ {
131
+ parent::prepareGridColumns($grid);
132
+
133
+ $grid->addColumn('recipient_ids', array(
134
+ 'header' => $this->__('Link Recipients'),
135
+ 'index' => 'recipient_ids',
136
+ ));
137
+ }
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+ /**
148
+ * Retrieve recipients by order select
149
+ *
150
+ * @return Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder
151
+ */
152
+ public function getRecipientsByOrder()
153
+ {
154
+ $campaign = $this->getCampaign();
155
+ $type = $this->getDataSetDefault('join');
156
+
157
+ $binder = Mage::getSingleton('mzax_emarketing/conversion_goal_orders')->getRecipientBinder($campaign, $type === 'direct');
158
+
159
+ return $binder->getSelect();
160
+ }
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+ /**
170
+ * html for settings in option form
171
+ *
172
+ * @return string
173
+ */
174
+ protected function prepareForm()
175
+ {
176
+ return $this->__('Order is linked %s to emarketing campaign %s',
177
+ $this->getSelectElement('join')->toHtml(),
178
+ $this->getSelectElement('campaign')->toHtml()
179
+ );
180
+ }
181
+
182
+
183
+
184
+
185
+ public function getJoinOptions()
186
+ {
187
+ return array(
188
+ 'direct' => $this->__('directly'),
189
+ 'indirect' => $this->__('indirectly'),
190
+ );
191
+ }
192
+
193
+
194
+
195
+ public function getCampaignOptions()
196
+ {
197
+ /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
198
+ $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
199
+ $collection->addArchiveFilter(false);
200
+
201
+ $options = array();
202
+ if($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
203
+ $options['current'] = $this->__('beeing tracked');
204
+ }
205
+ $options += $collection->toOptionHash();
206
+
207
+ return $options;
208
+ }
209
+
210
+
211
+
212
+
213
+
214
+ /**
215
+ * Retreive current campaign
216
+ *
217
+ * We must always return a campaign object!
218
+ * getQuery() needs to work with no data set
219
+ *
220
+ * @return Mzax_Emarketing_Model_Campaign
221
+ */
222
+ public function getCampaign()
223
+ {
224
+ if(!$this->_campaign) {
225
+
226
+ $id = $this->getDataSetDefault('campaign');
227
+
228
+ if($id === 'current') {
229
+ $this->_campaign = $this->getParam('campaign');
230
+ }
231
+ if(!$this->_campaign instanceof Mzax_Emarketing_Model_Campaign) {
232
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign');
233
+ if($id > 0) {
234
+ $this->_campaign->load($id);
235
+ }
236
+ }
237
+ }
238
+ return $this->_campaign;
239
+ }
240
+
241
+
242
+ /**
243
+ * Retreive current campaign variation which we aggregate
244
+ *
245
+ * @return null|integer
246
+ */
247
+ public function getVariation()
248
+ {
249
+ $id = Mage::registry('mzax_aggregate_variation');
250
+ if($id !== null && $id > -1) {
251
+ return (int) $id;
252
+ }
253
+ return null;
254
+ }
255
+
256
+
257
+
258
+
259
+
260
+
261
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Abstract.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ abstract class Mzax_Emarketing_Model_Object_Filter_Order_Item_Abstract
33
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
34
+ {
35
+
36
+
37
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
38
+ {
39
+ return $this->_acceptParent($parent, 'order_item_id');
40
+ }
41
+
42
+
43
+
44
+
45
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Table.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ * Setup filters for the order item table
28
+ *
29
+ *
30
+ * Missing something?
31
+ * use event "mzax_emarketing_email_filter_prepare_table_sales_order_item"
32
+ * to register any custom columns
33
+ *
34
+ *
35
+ *
36
+ * @author Jacob Siefer
37
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
38
+ * @version 0.2.5
39
+ */
40
+ class Mzax_Emarketing_Model_Object_Filter_Order_Item_Table
41
+ extends Mzax_Emarketing_Model_Object_Filter_Table
42
+ {
43
+
44
+ /**
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_table = 'sales/order_item';
49
+
50
+
51
+ protected $_tableAlias = 'sales_order_item';
52
+
53
+
54
+
55
+ protected $_tableIdFieldName = 'item_id';
56
+
57
+ /**
58
+ *
59
+ * @var string
60
+ */
61
+ protected $_requireBinding = 'order_item_id';
62
+
63
+
64
+
65
+ protected $_formText = 'Order Item `%s` %s %s.';
66
+
67
+
68
+ protected $_boolFormText = 'Order Item %s `%s`.';
69
+
70
+
71
+
72
+ /**
73
+ * Group title
74
+ *
75
+ * @return string
76
+ */
77
+ public function getTitle()
78
+ {
79
+ return "Order Item";
80
+ }
81
+
82
+
83
+
84
+ /**
85
+ * Register column filters
86
+ *
87
+ * Use mzax_emarketing_email_filter_prepare_table_sales_order_item event to register more
88
+ *
89
+ * @return void
90
+ */
91
+ protected function _registerColumns()
92
+ {
93
+ $this->addColumn('product_type', 'Product Type', 'multiselect', Mage::getSingleton('catalog/product_type')->getOptionArray());
94
+
95
+ $this->addColumn('sku', 'SKU', 'string');
96
+
97
+
98
+ $this->addColumn('base_price', 'Price', 'price');
99
+ $this->addColumn('base_price_incl_tax', 'Price (inc. tax)', 'price');
100
+
101
+ $this->addColumn('base_discount_amount', 'Discount Amount', 'price');
102
+ $this->addColumn('base_tax_amount', 'Tax Amount', 'price');
103
+
104
+
105
+ $this->addColumn('qty_ordered', 'Quantity Ordered', 'numeric');
106
+ $this->addColumn('qty_invoiced', 'Quantity Invoiced', 'numeric');
107
+ $this->addColumn('qty_refunded', 'Quantity Refunded', 'numeric');
108
+ $this->addColumn('qty_canceled', 'Quantity Canceled', 'numeric');
109
+ $this->addColumn('qty_shipped', 'Quantity Shipped', 'numeric');
110
+ $this->addColumn('qty_backordered', 'Quantity Backordered', 'numeric');
111
+
112
+ $this->addColumn('row_weight', 'Row Weight', 'numeric');
113
+
114
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
115
+ $this->addColumn('free_shipping', 'Free Shipping', 'boolean');
116
+ }
117
+
118
+
119
+
120
+
121
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
122
+ {
123
+ parent::_prepareCollection($collection);
124
+
125
+ // add currency code for price columns
126
+ $collection->getQuery()->joinTable(array('entity_id' => '{order_id}'), 'sales/order', 'order');
127
+ $collection->addField('currency_code', "`order`.`base_currency_code`");
128
+ }
129
+
130
+
131
+
132
+
133
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Items.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Object_Filter_Order_Items
32
+ extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
33
+ {
34
+
35
+ const DEFAULT_AGGREGATOR = 'all';
36
+
37
+ const DEFAULT_EXPECTATION = 'true';
38
+
39
+ const DEFAULT_SUM = 'qty_ordered';
40
+
41
+
42
+
43
+ protected $_allowChildren = true;
44
+
45
+
46
+
47
+
48
+ public function getTitle()
49
+ {
50
+ return "Order | Items subselection matches...";
51
+ }
52
+
53
+
54
+
55
+ /**
56
+ * Use order item object
57
+ *
58
+ * @return Mzax_Emarketing_Model_Object_OrderItem
59
+ */
60
+ public function getObject()
61
+ {
62
+ return Mage::getSingleton('mzax_emarketing/object_orderItem');
63
+ }
64
+
65
+
66
+
67
+ /**
68
+ * Setup query for child filters
69
+ * we need the order id and the sum_field
70
+ *
71
+ * @return Mzax_Emarketing_Db_Select
72
+ */
73
+ public function getQuery()
74
+ {
75
+ $sumField = $this->getDataSetDefault('sum');
76
+
77
+ $query = $this->getObject()->getQuery();
78
+ $query->addBinding('sum_field', $sumField);
79
+ $query->setColumn('order_id');
80
+ $query->setColumn('sum_field');
81
+
82
+ return $query;
83
+ }
84
+
85
+
86
+
87
+
88
+
89
+ /**
90
+ *
91
+ * @return Zend_Db_Select
92
+ */
93
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
94
+ {
95
+ $conditions = $this->_getConditions();
96
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
97
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
98
+
99
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
100
+ $select->useTemporaryTable($this->getTempTableName());
101
+
102
+ $query->joinSelect('order_id', $select, 'filter');
103
+ $query->addBinding('value', new Zend_Db_Expr('SUM(`filter`.`sum_field`)'));
104
+ $query->having($this->getWhereSql('value', 'SUM(`filter`.`sum_field`)'));
105
+ $query->group();
106
+ }
107
+
108
+
109
+
110
+
111
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
112
+ {
113
+ parent::_prepareCollection($collection);
114
+ $collection->addField('value');
115
+ }
116
+
117
+
118
+
119
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
120
+ {
121
+ parent::prepareGridColumns($grid);
122
+
123
+ $grid->addColumn('value', array(
124
+ 'header' => $this->__('Total'),
125
+ 'index' => 'value',
126
+ 'type' => 'number'
127
+ ));
128
+
129
+
130
+ $grid->setDefaultSort('increment_id');
131
+ $grid->setDefaultDir('DESC');
132
+
133
+ }
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+ /**
142
+ * html for settings in option form
143
+ *
144
+ * @return string
145
+ */
146
+ protected function prepareForm()
147
+ {
148
+ return $this->__('If total %s %s for subselection of items matching %s of these conditions:',
149
+ $this->getSelectElement('sum')->toHtml(),
150
+ $this->getInputHtml('value', 'numeric'),
151
+ $this->getSelectElement('aggregator', 'all')->toHtml()
152
+ );
153
+ }
154
+
155
+
156
+
157
+ /**
158
+ * List of fields to sum up and check against
159
+ *
160
+ * @return return array
161
+ */
162
+ protected function getSumOptions()
163
+ {
164
+ return array(
165
+ 'qty_ordered' => $this->__('quanity ordered'),
166
+ 'qty_invoiced' => $this->__('quanity invoiced'),
167
+ 'qty_shipped' => $this->__('quanity shipped'),
168
+ 'qty_canceled' => $this->__('quanity canceled'),
169
+ 'base_row_total' => $this->__('amount'),
170
+ 'base_discount_amount' => $this->__('discount amount'),
171
+ 'base_row_invoiced' => $this->__('invoice amount'),
172
+ 'base_amount_refunded' => $this->__('refund amount'),
173
+ 'base_tax_amount' => $this->__('tax amount'),
174
+ 'row_weight' => $this->__('weight'),
175
+ 'base_cost' => $this->__('cost'),
176
+ );
177
+ }
178
+
179
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Previous.php ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Object_Filter_Order_Previous
33
+ extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
34
+ {
35
+
36
+ const DEFAULT_AGGREGATOR = 'all';
37
+
38
+ const DEFAULT_EXPECTATION = 'true';
39
+
40
+ const DEFAULT_DIRECTION = 'preceded';
41
+
42
+
43
+
44
+ /**
45
+ * Can have children
46
+ *
47
+ * @var boolean
48
+ */
49
+ protected $_allowChildren = true;
50
+
51
+
52
+
53
+ /**
54
+ * Only works if parent object is the order object
55
+ *
56
+ * @return boolean
57
+ */
58
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
59
+ {
60
+ return $parent->getObject() === Mage::getSingleton('mzax_emarketing/object_order');
61
+ }
62
+
63
+
64
+
65
+
66
+
67
+ public function getTitle()
68
+ {
69
+ return "Order | Has preceded or followed orders matching...";
70
+ }
71
+
72
+
73
+
74
+
75
+ /**
76
+ * The child filter will use order_id binding again which is ok
77
+ *
78
+ * @return boolean
79
+ */
80
+ public function allowChildBinding($binding)
81
+ {
82
+ return $binding === 'order_id';
83
+ }
84
+
85
+
86
+
87
+
88
+ /**
89
+ *
90
+ * @return Mzax_Emarketing_Model_Object_Order
91
+ */
92
+ public function getObject()
93
+ {
94
+ return Mage::getSingleton('mzax_emarketing/object_order');
95
+ }
96
+
97
+
98
+
99
+
100
+ /**
101
+ * (non-PHPdoc)
102
+ * @see Mzax_Emarketing_Model_Object_Filter_Component::getQuery()
103
+ */
104
+ public function getQuery()
105
+ {
106
+ $query = $this->getObject()->getQuery();
107
+ $query->where('{customer_id} IS NOT NULL');
108
+ $query->addBinding('order_increment_id', 'increment_id');
109
+ $query->setColumn('customer_id');
110
+ $query->setColumn('ordered_at');
111
+ $query->setColumn('order_increment_id');
112
+ return $query;
113
+ }
114
+
115
+
116
+
117
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
118
+ {
119
+ $conditions = $this->_getConditions();
120
+ $aggregator = $this->getDataSetDefault('aggregator');
121
+ $expectation = $this->getDataSetDefault('expectation');
122
+
123
+ $subFilterSelect = $this->_combineConditions($conditions, $aggregator, $expectation);
124
+ $subFilterSelect->useTemporaryTable($this->getTempTableName());
125
+
126
+ $type = $this->getDataSetDefault('direction');
127
+ $cond['customer_id'] = '{customer_id}';
128
+
129
+
130
+ if($type === 'preceded') {
131
+ $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` < ' . '{ordered_at}');
132
+ $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` > ' . $this->getTimeExpr('offset', '{ordered_at}', true));
133
+ }
134
+ else {
135
+ $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` > ' . '{ordered_at}');
136
+ $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` < ' . $this->getTimeExpr('offset', '{ordered_at}', true));
137
+ }
138
+
139
+
140
+
141
+ $query->joinSelect($cond, $subFilterSelect, 'prev_orders');
142
+ $query->having($this->getWhereSql('orders', 'COUNT(`order_increment_id`)'));
143
+ $query->group();
144
+ }
145
+
146
+
147
+
148
+
149
+
150
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
151
+ {
152
+ parent::_prepareCollection($collection);
153
+ $collection->addField('prev_orders', new Zend_Db_Expr('GROUP_CONCAT(`prev_orders`.`order_increment_id` SEPARATOR ", ")'));
154
+ }
155
+
156
+
157
+
158
+
159
+
160
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
161
+ {
162
+ parent::prepareGridColumns($grid);
163
+
164
+ $grid->addColumn('prev_orders', array(
165
+ 'header' => $this->__('Previous Orders'),
166
+ 'width' => '180px',
167
+ 'index' => 'prev_orders',
168
+ ));
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ /**
180
+ * html for settings in option form
181
+ *
182
+ * @return string
183
+ */
184
+ protected function prepareForm()
185
+ {
186
+ $aggregatorElement = $this->getSelectElement('aggregator');
187
+ $expectationElement = $this->getSelectElement('expectation');
188
+
189
+ return $this->__('If number of %s orders, within %s and with %s of these conditions %s, %s:',
190
+ $this->getSelectElement('direction')->toHtml(),
191
+ $this->getTimeHtml('offset'),
192
+ $aggregatorElement->toHtml(),
193
+ $expectationElement->toHtml(),
194
+ $this->getInputHtml('orders', 'numeric')
195
+ );
196
+ }
197
+
198
+
199
+
200
+ protected function getDirectionOptions()
201
+ {
202
+ return array(
203
+ 'preceded' => $this->__('preceded'),
204
+ 'followed' => $this->__('followed'),
205
+ );
206
+ }
207
+
208
+
209
+
210
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Table.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Order table filters
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Object_Filter_Order_Table
32
+ extends Mzax_Emarketing_Model_Object_Filter_Table
33
+ {
34
+
35
+ /**
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_table = 'sales/order';
40
+
41
+
42
+ protected $_tableAlias = 'sales_order';
43
+
44
+
45
+
46
+ protected $_tableIdFieldName = 'entity_id';
47
+
48
+ /**
49
+ *
50
+ * @var string
51
+ */
52
+ protected $_requireBinding = 'order_id';
53
+
54
+
55
+
56
+ protected $_formText = 'Order `%s` %s %s.';
57
+
58
+
59
+ protected $_boolFormText = 'Order %s `%s`.';
60
+
61
+
62
+
63
+
64
+ public function getTitle()
65
+ {
66
+ return "Order";
67
+ }
68
+
69
+
70
+ protected function _registerColumns()
71
+ {
72
+ $column = $this->addColumn('created_at', 'Order Date', 'date');
73
+ $column->allowFuture = false;
74
+
75
+ $this->addColumn('base_grand_total', 'Grand Total', 'currency');
76
+ $this->addColumn('base_subtotal', 'Subtotal', 'currency');
77
+ $this->addColumn('base_shipping_amount', 'Shipping Amount', 'currency');
78
+ $this->addColumn('base_tax_amount', 'Tax Total', 'currency');
79
+ $this->addColumn('base_discount_amount', 'Discount Amount', 'currency');
80
+ $this->addColumn('base_total_refunded', 'Total Refunded', 'currency');
81
+ $this->addColumn('weight', 'Total Weight', 'numeric');
82
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
83
+ $this->addColumn('customer_is_guest', 'Guest Checkout', 'boolean');
84
+ $this->addColumn('status', 'Status', 'multiselect', Mage::getSingleton('sales/order_config')->getStatuses());
85
+ }
86
+
87
+
88
+
89
+
90
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
91
+ {
92
+ parent::_prepareCollection($collection);
93
+
94
+ // add currency code for price columns
95
+ $collection->addField('currency_code', "`$this->_tableAlias`.`base_currency_code`");
96
+ }
97
+
98
+
99
+
100
+
101
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Abstract.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ abstract class Mzax_Emarketing_Model_Object_Filter_Product_Abstract
29
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
30
+ {
31
+
32
+
33
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
34
+ {
35
+ return $this->_acceptParent($parent, 'product_id');
36
+ }
37
+
38
+
39
+
40
+
41
+
42
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Attribute.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Product_Attribute
29
+ extends Mzax_Emarketing_Model_Object_Filter_Attribute
30
+ {
31
+
32
+
33
+
34
+ /**
35
+ * Attribute data key that indicates whether it should be used for rules
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_isUsedForRuleProperty = 'is_used_for_promo_rules';
40
+
41
+
42
+ protected $_entity = Mage_Catalog_Model_Product::ENTITY;
43
+
44
+
45
+ protected $_requireBinding = 'product_id';
46
+
47
+
48
+
49
+ public function getTitle()
50
+ {
51
+ return "Product Attributes";
52
+ }
53
+
54
+
55
+
56
+ protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
57
+ {
58
+ if($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute) {
59
+ if($attribute->isAllowedForRuleCondition() && $attribute->getDataUsingMethod($this->_isUsedForRuleProperty)) {
60
+ return true;
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+
66
+
67
+
68
+
69
+
70
+
71
+ public function getChooserUrl()
72
+ {
73
+ if($this->getAttribute()->getAttributeCode() === 'sku') {
74
+ return 'adminhtml/promo_widget/chooser/attribute/sku/form/filter_conditions_fieldset';
75
+ }
76
+ }
77
+
78
+
79
+
80
+
81
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Category.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @author Jacob Siefer
26
+ *
27
+ */
28
+ class Mzax_Emarketing_Model_Object_Filter_Product_Category
29
+ extends Mzax_Emarketing_Model_Object_Filter_Product_Abstract
30
+ {
31
+
32
+
33
+
34
+ public function getTitle()
35
+ {
36
+ return "Product | Category";
37
+ }
38
+
39
+
40
+
41
+ public function getChooserUrl()
42
+ {
43
+ return 'adminhtml/promo_widget/chooser/attribute/category_ids/form/filter_conditions_fieldset';
44
+ }
45
+
46
+
47
+
48
+
49
+
50
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
51
+ {
52
+ $categoryIds = $this->getData('value');
53
+ if(empty($categoryIds)) {
54
+ $query->where('FALSE = TRUE');
55
+ return;
56
+ }
57
+
58
+ $categoryIds = $this->_explode($categoryIds);
59
+ $operator = $this->getDataSetDefault('operator', '()');
60
+
61
+ $query->joinTable('product_id', 'catalog/category_product', 'link')->group();
62
+ $query->addBinding('category_id', 'category_id', 'link');
63
+
64
+ if($operator === '()') {
65
+ $query->where('`link`.`category_id` IN(?)', $categoryIds);
66
+ }
67
+ else {
68
+ $query->where('`link`.`category_id` NOT IN(?)', $categoryIds);
69
+ }
70
+ }
71
+
72
+
73
+
74
+
75
+
76
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
77
+ {
78
+ parent::_prepareCollection($collection);
79
+
80
+ $expr = $collection->joinAttribute('catname', 'category_id', 'catalog_category/name');
81
+
82
+ $collection->addField('categories', new Zend_Db_Expr("GROUP_CONCAT($expr SEPARATOR ', ')"));
83
+
84
+ }
85
+
86
+
87
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
88
+ {
89
+ parent::prepareGridColumns($grid);
90
+
91
+ $grid->addColumn('categories', array(
92
+ 'header' => $this->__('Categories'),
93
+ 'index' => 'categories',
94
+ ));
95
+ }
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+ /**
105
+ * html for settings in option form
106
+ *
107
+ * @return string
108
+ */
109
+ protected function prepareForm()
110
+ {
111
+
112
+ $operations = $this->helper()->getOperatorOptions(array('()', '!()'));
113
+
114
+ $operatorElment = $this->getSelectElement('operator', '()', $operations);
115
+ $valueElement = $this->getInputElement('value');
116
+ $valueElement->setExplicitApply(true);
117
+ $valueElement->setAfterElementHtml($this->getChooserTriggerHtml());
118
+
119
+ return $this->__('Product category %s %s',
120
+ $operatorElment->toHtml(),
121
+ $valueElement->toHtml()
122
+ );
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Abstract.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ abstract class Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
33
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
34
+ {
35
+
36
+
37
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
38
+ {
39
+ return $this->_acceptParent($parent, 'quote_id');
40
+ }
41
+
42
+
43
+
44
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Address.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Object_Filter_Quote_Address
33
+ extends Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
34
+ {
35
+
36
+ const DEFAULT_AGGREGATOR = 'all';
37
+
38
+ const DEFAULT_EXPECTATION = 'true';
39
+
40
+
41
+ const TYPE_BILLING = 'billing';
42
+ const TYPE_SHIPPING = 'shipping';
43
+
44
+
45
+ protected $_allowChildren = true;
46
+
47
+
48
+
49
+
50
+ public function getTitle()
51
+ {
52
+ return "Shopping Cart / Quote | Billing/Shipping Address matches...";
53
+ }
54
+
55
+
56
+
57
+
58
+
59
+ /**
60
+ *
61
+ * @return Mzax_Emarketing_Model_Object_OrderItem
62
+ */
63
+ public function getObject()
64
+ {
65
+ return Mage::getSingleton('mzax_emarketing/object_quoteAddress');
66
+ }
67
+
68
+
69
+ public function getQuery()
70
+ {
71
+ $query = $this->getObject()->getQuery();
72
+ $query->setColumn('quote_id');
73
+
74
+ $query->where('address_type = ?', $this->getDataSetDefault('address_type', self::TYPE_BILLING));
75
+
76
+ return $query;
77
+ }
78
+
79
+
80
+
81
+
82
+
83
+ /**
84
+ *
85
+ * @return Zend_Db_Select
86
+ */
87
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
88
+ {
89
+ $conditions = $this->_getConditions();
90
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
91
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
92
+
93
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
94
+ $select->useTemporaryTable($this->getTempTableName());
95
+
96
+ $query->joinSelect('quote_id', $select, 'filter');
97
+ $query->group();
98
+ }
99
+
100
+
101
+
102
+
103
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
104
+ {
105
+ parent::_prepareCollection($collection);
106
+ }
107
+
108
+
109
+
110
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
111
+ {
112
+ parent::prepareGridColumns($grid);
113
+
114
+
115
+
116
+ }
117
+
118
+
119
+
120
+ /**
121
+ * html for settings in option form
122
+ *
123
+ * @return string
124
+ */
125
+ protected function prepareForm()
126
+ {
127
+ return $this->__('If %s address matches %s of these conditions:',
128
+ $this->getSelectElement('address_type', self::TYPE_BILLING)->toHtml(),
129
+ $this->getSelectElement('aggregator', 'all')->toHtml()
130
+ );
131
+ }
132
+
133
+
134
+
135
+ protected function getAddressTypeOptions()
136
+ {
137
+ return array(
138
+ self::TYPE_BILLING => $this->__('billing'),
139
+ self::TYPE_SHIPPING => $this->__('shipping'),
140
+ );
141
+ }
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Item/Table.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+ /**
27
+ * Setup filters for the quote item table
28
+ *
29
+ *
30
+ * Missing something?
31
+ * use event "mzax_emarketing_email_filter_prepare_table_sales_quote_item"
32
+ * to register any custom columns
33
+ *
34
+ *
35
+ *
36
+ * @author Jacob Siefer
37
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
38
+ * @version 0.2.5
39
+ */
40
+ class Mzax_Emarketing_Model_Object_Filter_Quote_Item_Table
41
+ extends Mzax_Emarketing_Model_Object_Filter_Table
42
+ {
43
+
44
+ /**
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_table = 'sales/quote_item';
49
+
50
+
51
+ protected $_tableAlias = 'sales_quote_item';
52
+
53
+
54
+
55
+ protected $_tableIdFieldName = 'item_id';
56
+
57
+ /**
58
+ *
59
+ * @var string
60
+ */
61
+ protected $_requireBinding = 'quote_item_id';
62
+
63
+
64
+
65
+ protected $_formText = 'Quote Item `%s` %s %s.';
66
+
67
+
68
+ protected $_boolFormText = 'Quote Item %s `%s`.';
69
+
70
+
71
+
72
+ /**
73
+ * Group title
74
+ *
75
+ * @return string
76
+ */
77
+ public function getTitle()
78
+ {
79
+ return "Quote Item";
80
+ }
81
+
82
+
83
+
84
+ /**
85
+ * Register column filters
86
+ *
87
+ * Use mzax_emarketing_email_filter_prepare_table_sales_order_item event to register more
88
+ *
89
+ * @return void
90
+ */
91
+ protected function _registerColumns()
92
+ {
93
+ $this->addColumn('product_type', 'Product Type', 'multiselect', Mage::getSingleton('catalog/product_type')->getOptionArray());
94
+
95
+ $this->addColumn('sku', 'SKU', 'string');
96
+
97
+ $this->addColumn('base_price', 'Price', 'price');
98
+ $this->addColumn('custom_price', 'Custom Price', 'price');
99
+
100
+ $this->addColumn('base_row_total', 'Row Total', 'price');
101
+ $this->addColumn('base_discount_amount', 'Discount Amount', 'price');
102
+ $this->addColumn('base_tax_amount', 'Tax Amount', 'price');
103
+
104
+ $this->addColumn('qty', 'Quantity', 'numeric');
105
+
106
+ $this->addColumn('row_weight', 'Row Weight', 'numeric');
107
+
108
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
109
+ $this->addColumn('free_shipping', 'Free Shipping', 'boolean');
110
+ }
111
+
112
+
113
+
114
+
115
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
116
+ {
117
+ parent::_prepareCollection($collection);
118
+
119
+ // add currency code for price columns
120
+ $collection->getQuery()->joinTable(array('entity_id' => '{quote_id}'), 'sales/quote', 'quote');
121
+ $collection->addField('currency_code', "`quote`.`base_currency_code`");
122
+ }
123
+
124
+
125
+
126
+
127
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Items.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Object_Filter_Quote_Items
32
+ extends Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
33
+ {
34
+
35
+ const DEFAULT_AGGREGATOR = 'all';
36
+
37
+ const DEFAULT_EXPECTATION = 'true';
38
+
39
+ const DEFAULT_SUM = 'qty';
40
+
41
+
42
+
43
+ protected $_allowChildren = true;
44
+
45
+
46
+
47
+
48
+ public function getTitle()
49
+ {
50
+ return "Shopping Cart / Quote | Items subselection matches...";
51
+ }
52
+
53
+
54
+
55
+ /**
56
+ * Use order item object
57
+ *
58
+ * @return Mzax_Emarketing_Model_Object_OrderItem
59
+ */
60
+ public function getObject()
61
+ {
62
+ return Mage::getSingleton('mzax_emarketing/object_quoteItem');
63
+ }
64
+
65
+
66
+
67
+ /**
68
+ * Setup query for child filters
69
+ * we need the order id and the sum_field
70
+ *
71
+ * @return Mzax_Emarketing_Db_Select
72
+ */
73
+ public function getQuery()
74
+ {
75
+ $sumField = $this->getDataSetDefault('sum');
76
+
77
+ $query = $this->getObject()->getQuery();
78
+ $query->addBinding('sum_field', $sumField);
79
+ $query->setColumn('quote_id');
80
+ $query->setColumn('sum_field');
81
+
82
+ return $query;
83
+ }
84
+
85
+
86
+
87
+
88
+
89
+ /**
90
+ *
91
+ * @return Zend_Db_Select
92
+ */
93
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
94
+ {
95
+ $conditions = $this->_getConditions();
96
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
97
+ $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
98
+
99
+ $select = $this->_combineConditions($conditions, $aggregator, $expectation);
100
+ $select->useTemporaryTable($this->getTempTableName());
101
+
102
+ $query->joinSelect('quote_id', $select, 'filter');
103
+ $query->addBinding('value', new Zend_Db_Expr('SUM(`filter`.`sum_field`)'));
104
+ $query->having($this->getWhereSql('value', 'SUM(`filter`.`sum_field`)'));
105
+ $query->group();
106
+ }
107
+
108
+
109
+
110
+
111
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
112
+ {
113
+ parent::_prepareCollection($collection);
114
+ $collection->addField('value');
115
+ }
116
+
117
+
118
+
119
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
120
+ {
121
+ parent::prepareGridColumns($grid);
122
+
123
+ $grid->addColumn('value', array(
124
+ 'header' => $this->__('Total'),
125
+ 'index' => 'value',
126
+ 'type' => 'number'
127
+ ));
128
+
129
+ $grid->setDefaultSort('quote_id');
130
+ $grid->setDefaultDir('DESC');
131
+
132
+ }
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+ /**
141
+ * html for settings in option form
142
+ *
143
+ * @return string
144
+ */
145
+ protected function prepareForm()
146
+ {
147
+ return $this->__('If total %s %s for subselection of items matching %s of these conditions:',
148
+ $this->getSelectElement('sum')->toHtml(),
149
+ $this->getInputHtml('value', 'numeric'),
150
+ $this->getSelectElement('aggregator', 'all')->toHtml()
151
+ );
152
+ }
153
+
154
+
155
+
156
+ /**
157
+ * List of fields to sum up and check against
158
+ *
159
+ * @return return array
160
+ */
161
+ protected function getSumOptions()
162
+ {
163
+ return array(
164
+ 'qty' => $this->__('quanity ordered'),
165
+ 'base_row_total' => $this->__('amount'),
166
+ 'base_discount_amount' => $this->__('discount amount'),
167
+ 'base_tax_amount' => $this->__('tax amount'),
168
+ 'row_weight' => $this->__('weight'),
169
+ 'base_cost' => $this->__('cost'),
170
+ );
171
+ }
172
+
173
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Table.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Quote table filters
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Object_Filter_Quote_Table
32
+ extends Mzax_Emarketing_Model_Object_Filter_Table
33
+ {
34
+
35
+ /**
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_table = 'sales/quote';
40
+
41
+
42
+ protected $_tableAlias = 'sales_quote';
43
+
44
+
45
+
46
+ protected $_tableIdFieldName = 'entity_id';
47
+
48
+ /**
49
+ *
50
+ * @var string
51
+ */
52
+ protected $_requireBinding = 'quote_id';
53
+
54
+
55
+
56
+ protected $_formText = 'Quote `%s` %s %s.';
57
+
58
+
59
+ protected $_boolFormText = 'Quote %s `%s`.';
60
+
61
+
62
+
63
+
64
+ public function getTitle()
65
+ {
66
+ return "Shopping Cart / Quote";
67
+ }
68
+
69
+
70
+ protected function _registerColumns()
71
+ {
72
+ $column = $this->addColumn('created_at', 'Created Date', 'date');
73
+ $column->allowFuture = false;
74
+
75
+ $column = $this->addColumn('updated_at', 'Last Update', 'date');
76
+ $column->allowFuture = false;
77
+
78
+ $this->addColumn('base_grand_total', 'Grand Total', 'currency');
79
+ $this->addColumn('base_subtotal', 'Subtotal', 'currency');
80
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
81
+ $this->addColumn('customer_is_guest', 'Guest Checkout', 'boolean');
82
+ $this->addColumn('base_subtotal_with_discount', 'Subtotal with Discount', 'currency');
83
+ }
84
+
85
+
86
+
87
+
88
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
89
+ {
90
+ parent::_prepareCollection($collection);
91
+
92
+ // add currency code for price columns
93
+ $collection->addField('currency_code', "`$this->_tableAlias`.`base_currency_code`");
94
+ }
95
+
96
+
97
+
98
+
99
+ }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Table.php ADDED
@@ -0,0 +1,615 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ * @method Mzax_Emarketing_Model_Object_Filter_Table setColumn(string $name)
28
+ * @method Mzax_Emarketing_Model_Object_Filter_Table setRelative(boolean $flag)
29
+ * @method Mzax_Emarketing_Model_Object_Filter_Table setValue(mixed $value)
30
+ * @method Mzax_Emarketing_Model_Object_Filter_Table setOperator(string $value)
31
+ *
32
+ * @author Jacob Siefer
33
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
+ * @version 0.2.5
35
+ */
36
+ abstract class Mzax_Emarketing_Model_Object_Filter_Table
37
+ extends Mzax_Emarketing_Model_Object_Filter_Abstract
38
+ {
39
+
40
+ const VALUE_KEY = 'value';
41
+
42
+
43
+ /**
44
+ * Name of table e.g. sales/order
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_table;
49
+
50
+
51
+ /**
52
+ * Query alias
53
+ *
54
+ * @var string
55
+ */
56
+ protected $_tableAlias;
57
+
58
+
59
+ /**
60
+ * Id field/column name
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_tableIdFieldName = 'entity_id';
65
+
66
+
67
+
68
+ /**
69
+ * Form text
70
+ *
71
+ * 1. Column Name
72
+ * 2. Operator (is, is not, contains,...)
73
+ * 3. Value
74
+ *
75
+ * @var string
76
+ */
77
+ protected $_formText = '%s %s %s.';
78
+
79
+
80
+
81
+ /**
82
+ * Form text for boolean checks
83
+ *
84
+ * 1. Column Name
85
+ * 2. Value (Yes, No)
86
+ *
87
+ * e.g
88
+ * Quote %s %s. => Quote [is|is not] "Virtual".
89
+ *
90
+ * @var string
91
+ */
92
+ protected $_boolFormText = '%s %s.';
93
+
94
+
95
+
96
+ /**
97
+ * The binding that is required to show this filter.
98
+ * Usally this is the table id field (order_id, quote_id, customer_id,...)
99
+ *
100
+ * @var string
101
+ */
102
+ protected $_requireBinding;
103
+
104
+
105
+
106
+ /**
107
+ * Use _registerColumns() and addColumn()
108
+ *
109
+ * @internal
110
+ * @see Mzax_Emarketing_Model_Object_Filter_Table::_registerColumns()
111
+ * @see Mzax_Emarketing_Model_Object_Filter_Table::addColumn()
112
+ * @var array
113
+ */
114
+ protected $_columnOptions = array();
115
+
116
+
117
+
118
+ /**
119
+ * Reference to the selected table column
120
+ *
121
+ * @internal
122
+ * @see Mzax_Emarketing_Model_Object_Filter_Table::getTableColumn()
123
+ * @var array
124
+ */
125
+ protected $_tableColumn;
126
+
127
+
128
+
129
+ /**
130
+ * Abstract method to register all columns
131
+ *
132
+ * @return void
133
+ */
134
+ abstract protected function _registerColumns();
135
+
136
+
137
+
138
+ /**
139
+ *
140
+ * (non-PHPdoc)
141
+ * @see Mzax_Emarketing_Model_Object_Filter_Component::acceptParent()
142
+ */
143
+ public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
144
+ {
145
+ return $this->_acceptParent($parent, $this->_requireBinding);
146
+ }
147
+
148
+
149
+
150
+ /**
151
+ *
152
+ * (non-PHPdoc)
153
+ * @see Mzax_Emarketing_Model_Object_Filter_Abstract::_prepareFilter($config)
154
+ */
155
+ protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
156
+ {
157
+ parent::_prepareFilter($config);
158
+ $this->_registerColumns();
159
+ Mage::dispatchEvent("mzax_emarketing_email_filter_prepare_table_" . $this->_tableAlias, array('filter' => $this));
160
+ }
161
+
162
+
163
+
164
+
165
+ /**
166
+ *
167
+ * (non-PHPdoc)
168
+ * @see Mzax_Emarketing_Model_Object_Filter_Component::_prepareQuery()
169
+ */
170
+ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
171
+ {
172
+ /* @var $adapter Zend_Db_Adapter_Abstract */
173
+ $column = $this->getTableColumn();
174
+ $adapter = $query->getAdapter();
175
+
176
+ if(!$column) {
177
+ throw new Exception("No valid table column defined");
178
+ }
179
+
180
+ if($this->_tableIdFieldName) {
181
+ $bind = array($this->_tableIdFieldName => $this->_requireBinding);
182
+ }
183
+ else {
184
+ $bind = $this->_requireBinding;
185
+ }
186
+
187
+ $query->joinTable($bind, $this->_table, $this->_tableAlias);
188
+ $query->addBinding('column_value', $column->name, $this->_tableAlias);
189
+
190
+ $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
191
+ $value = $this->getData(self::VALUE_KEY);
192
+
193
+
194
+
195
+ // relative date
196
+ if($this->getData('relative')) {
197
+ $future = $this->getDirection() == 'future';
198
+
199
+ if($this->getAnniversary()) {
200
+ $query->where($this->getAnniversaryTimeExpr('{column_value}', self::VALUE_KEY, $future, $column->applyGmtOffset));
201
+ }
202
+ else {
203
+ $query->where($this->getTimeRangeExpr('{column_value}', self::VALUE_KEY, $future));
204
+ }
205
+ return;
206
+ }
207
+
208
+ if($column->type === 'boolean') {
209
+ $value = '1';
210
+ }
211
+
212
+ switch($operator) {
213
+ case '!=':
214
+ case '>=':
215
+ case '<=':
216
+ case '>':
217
+ case '<': return $query->where("{column_value} {$operator} ?", $value); break;
218
+ case '{}': return $query->where("{column_value} LIKE ?", "%$value%"); break;
219
+ case '!{}': return $query->where("{column_value} NOT LIKE ?", "%$value%"); break;
220
+ case '()': return $query->where("{column_value} IN (?)", $this->_explode($value)); break;
221
+ case '!()': return $query->where("{column_value} NOT IN (?)", $this->_explode($value)); break;
222
+ default: return $query->where("{column_value} = ?", $value); break;
223
+ }
224
+ }
225
+
226
+
227
+
228
+
229
+ /**
230
+ *
231
+ * (non-PHPdoc)
232
+ * @see Mzax_Emarketing_Model_Object_Filter_Abstract::_prepareCollection($collection)
233
+ */
234
+ protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
235
+ {
236
+ parent::_prepareCollection($collection);
237
+ $collection->addField('column_value');
238
+ }
239
+
240
+
241
+
242
+ /**
243
+ *
244
+ * (non-PHPdoc)
245
+ * @see Mzax_Emarketing_Model_Object_Filter_Component::prepareGridColumns()
246
+ */
247
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
248
+ {
249
+ parent::prepareGridColumns($grid);
250
+
251
+ if($column = $this->getTableColumn())
252
+ {
253
+ $grid->addColumn('column_value', array(
254
+ 'header' => ucfirst($column->label),
255
+ 'type' => $this->getColumnType(),
256
+ 'options' => $this->getGridValueOptions(),
257
+ 'index' => 'column_value',
258
+ 'currency' => 'currency_code',
259
+ 'gmtoffset' => true
260
+ ));
261
+ }
262
+
263
+ }
264
+
265
+
266
+
267
+
268
+ /**
269
+ * Retrieve table column name
270
+ *
271
+ * @return array
272
+ */
273
+ public function getTableColumn()
274
+ {
275
+ if( $this->_tableColumn === null) {
276
+ $column = $this->getData('column');
277
+ if(isset($this->_columnOptions[$column])) {
278
+ $this->_tableColumn = $this->_columnOptions[$column];
279
+ }
280
+ else {
281
+ $this->_tableColumn = false;
282
+ }
283
+
284
+ }
285
+ return $this->_tableColumn;
286
+ }
287
+
288
+
289
+
290
+
291
+
292
+ /**
293
+ * html for settings in option form
294
+ *
295
+ * @return string
296
+ */
297
+ protected function prepareForm()
298
+ {
299
+ $column = $this->getTableColumn();
300
+ if(!$column) {
301
+ return "**ERROR** NO COLUMN SELECTED.";
302
+ }
303
+
304
+ $html = $this->getHiddenField('column', $column->name)->toHtml();
305
+
306
+ $operatorElement = $this->getOperatorElement();
307
+ $valueElement = $this->getValueElement();
308
+
309
+
310
+ if($this->getData('relative')) {
311
+
312
+ $timeRangeHtml = $this->getTimeRangeHtml(self::VALUE_KEY);
313
+
314
+ $html .= $this->getHiddenField('relative', 1)->toHtml();
315
+ $html .= $this->getHiddenField('anniversary', $this->getAnniversary())->toHtml();
316
+ $html .= $this->getHiddenField('direction', $this->getDirection())->toHtml();
317
+
318
+ $timeRangeHtml = $this->getTimeRangeHtml(self::VALUE_KEY);
319
+ $timeDirHtml = $this->getTimeDirectionHtml(self::VALUE_KEY);
320
+
321
+ if($this->getAnniversary()) {
322
+ $text = $this->getDirection() == 'future'
323
+ ? '%s anniversary is in %s.'
324
+ : '%s anniversary was %s ago.';
325
+ }
326
+ else {
327
+ $text = $this->getDirection() == 'future'
328
+ ? '%s is in %s.'
329
+ : '%s was %s ago.';
330
+ }
331
+
332
+ return $html. $this->__($text,
333
+ $column->label,
334
+ $timeRangeHtml
335
+ );
336
+ }
337
+
338
+
339
+ switch($column->type) {
340
+ case 'boolean':
341
+ return $html . $this->__($this->_boolFormText,
342
+ $operatorElement->toHtml(),
343
+ $column->label
344
+ );
345
+ }
346
+
347
+ return $html . $this->__($this->_formText,
348
+ $column->label,
349
+ $operatorElement->toHtml(),
350
+ $valueElement->toHtml()
351
+ );
352
+ }
353
+
354
+
355
+
356
+
357
+
358
+ /**
359
+ * Retrieve operator select element
360
+ *
361
+ * @return Varien_Data_Form_Element_Abstract
362
+ */
363
+ public function getOperatorElement()
364
+ {
365
+ $type = $this->getInputType();
366
+ $default = $this->helper()->getDefaultOperatorByType($type);
367
+ $options = $this->helper()->getOperatorOptionsByType($type);
368
+
369
+ return $this->getSelectElement('operator', $default, $options);
370
+ }
371
+
372
+
373
+
374
+ /**
375
+ * Retroeve value form element
376
+ *
377
+ * @return Varien_Data_Form_Element_Abstract
378
+ */
379
+ public function getValueElement()
380
+ {
381
+ $type = $this->getInputType();
382
+
383
+ switch($type) {
384
+
385
+ case 'date':
386
+ $element = $this->getDateElement(self::VALUE_KEY);
387
+ break;
388
+
389
+ case 'select':
390
+ case 'boolean':
391
+ $element = $this->getSelectElement(self::VALUE_KEY);
392
+ break;
393
+
394
+ case 'multiselect':
395
+ $element = $this->getMultiSelectElement(self::VALUE_KEY);
396
+ break;
397
+
398
+ default:
399
+ $element = $this->getInputElement(self::VALUE_KEY);
400
+ break;
401
+ }
402
+
403
+ if($this->getChooserUrl()) {
404
+ $element->setExplicitApply(true);
405
+ $element->setAfterElementHtml($this->getChooserTriggerHtml());
406
+ }
407
+
408
+ return $element;
409
+ }
410
+
411
+
412
+
413
+
414
+
415
+
416
+ /**
417
+ * Retrieve all value options as hash
418
+ *
419
+ * array(value => label,...)
420
+ *
421
+ * @return array
422
+ */
423
+ public function getValueOptions()
424
+ {
425
+ if($column = $this->getTableColumn()) {
426
+ switch($column->type) {
427
+ case 'boolean':
428
+ return array(
429
+ '1' => $this->__('is'),
430
+ '0' => $this->__('is not')
431
+ );
432
+ }
433
+ return $column->options;
434
+ }
435
+ return array();
436
+ }
437
+
438
+
439
+
440
+ /**
441
+ * Retrieve value options for the grid
442
+ *
443
+ * @return array
444
+ */
445
+ public function getGridValueOptions()
446
+ {
447
+ if($column = $this->getTableColumn()) {
448
+ switch($column->type) {
449
+ case 'boolean':
450
+ return array(
451
+ '1' => $this->__('Yes'),
452
+ '0' => $this->__('No')
453
+ );
454
+ }
455
+ if(isset($column->gridOptions)) {
456
+ return $column->gridOptions;
457
+ }
458
+ }
459
+ return $this->getValueOptions();
460
+ }
461
+
462
+
463
+
464
+ /**
465
+ * Add hidden input field
466
+ *
467
+ * @param string $name
468
+ * @param string $value
469
+ * @return Varien_Data_Form_Element_Abstract
470
+ */
471
+ protected function getHiddenField($name, $value)
472
+ {
473
+ return $this->getForm()->addField($name, 'hidden', array(
474
+ 'name' => $name,
475
+ 'class' => 'hidden',
476
+ 'no_span' => true,
477
+ 'is_meta' => true,
478
+ 'value' => $value
479
+ ));
480
+ }
481
+
482
+
483
+
484
+
485
+ /**
486
+ * Retrieve input type
487
+ *
488
+ * @return string
489
+ */
490
+ public function getInputType()
491
+ {
492
+ if($column = $this->getTableColumn()) {
493
+ switch($column->type) {
494
+ case 'price':
495
+ return 'numeric';
496
+ }
497
+
498
+ return $column->type;
499
+ }
500
+ return 'string';
501
+ }
502
+
503
+
504
+
505
+
506
+
507
+ /**
508
+ * Retrieve input type
509
+ *
510
+ * @return string
511
+ */
512
+ public function getColumnType()
513
+ {
514
+ if($column = $this->getTableColumn())
515
+ {
516
+ switch($column->type) {
517
+ case 'multiselect':
518
+ case 'select':
519
+ case 'boolean':
520
+ return 'options';
521
+ }
522
+ return $column->type;
523
+ }
524
+ return 'string';
525
+ }
526
+
527
+
528
+
529
+
530
+
531
+ /**
532
+ * Register column to this table filter
533
+ *
534
+ * @param string $name
535
+ * @param string $label
536
+ * @param string $type
537
+ * @param array $options
538
+ * @return stdClass
539
+ */
540
+ public function addColumn($name, $label, $type = 'numeric', $options = array())
541
+ {
542
+ // assume config source model
543
+ if(is_string($options)) {
544
+ $source = Mage::getSingleton($options);
545
+ $options = array();
546
+ if(method_exists($source, 'toOptionArray')) {
547
+ // we need a hash, not an array
548
+ foreach($source->toOptionArray() as $option) {
549
+ $options[$option['value']] = $option['label'];
550
+ }
551
+ }
552
+ }
553
+
554
+ $column = (object) array(
555
+ 'name' => $name,
556
+ 'label' => $this->__($label),
557
+ 'type' => $type,
558
+ 'options' => $options,
559
+ 'allowFuture' => true,
560
+ 'allowPast' => true,
561
+ 'allowAnniversary' => true,
562
+ 'applyGmtOffset' => false
563
+ );
564
+
565
+ $this->_columnOptions[$name] = $column;
566
+ return $column;
567
+ }
568
+
569
+
570
+
571
+
572
+ /**
573
+ * Retrieve all column options available
574
+ *
575
+ * @return array
576
+ */
577
+ public function getColumnOptions()
578
+ {
579
+ return $this->_columnOptions;
580
+ }
581
+
582
+
583
+
584
+
585
+
586
+ public function getOptions()
587
+ {
588
+ $title = $this->getTitle();
589
+ $type = $this->getType();
590
+ $options = array();
591
+
592
+ foreach($this->getColumnOptions() as $column)
593
+ {
594
+ $options[$type.'?column=' . $column->name] = "{$title} | {$column->label}";
595
+ if($column->type === 'date') {
596
+
597
+ if($column->allowFuture) {
598
+ $options[$type.'?column='.$column->name.'?relative=1?direction=future'] = $title . ' | ' . $this->__('%s is in...', $column->label);
599
+ }
600
+ if($column->allowPast) {
601
+ $options[$type.'?column='.$column->name.'?relative=1?direction=past'] = $title . ' | ' . $this->__('%s was ... ago', $column->label);
602
+ }
603
+ if($column->allowAnniversary) {
604
+ $options[$type.'?column='.$column->name.'?relative=1?anniversary=1?direction=future'] = $title . ' | ' . $this->__('%s anniversary is in...', $column->label);
605
+ $options[$type.'?column='.$column->name.'?relative=1?anniversary=1?direction=past'] = $title . ' | ' . $this->__('%s anniversary was ... ago', $column->label);
606
+ }
607
+ }
608
+ }
609
+
610
+ asort($options);
611
+ return $options;
612
+ }
613
+
614
+
615
+ }
app/code/community/Mzax/Emarketing/Model/Object/Order.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ *
29
+ */
30
+ class Mzax_Emarketing_Model_Object_Order extends Mzax_Emarketing_Model_Object_Abstract
31
+ {
32
+
33
+ public function _construct()
34
+ {
35
+ $this->_init('sales/order');
36
+ }
37
+
38
+
39
+
40
+
41
+ public function getName()
42
+ {
43
+ return $this->__('Order');
44
+ }
45
+
46
+
47
+ public function getAdminUrl($id)
48
+ {
49
+ return $this->getUrl('adminhtml/sales_order/view', array('order_id' => $id));
50
+ }
51
+
52
+
53
+
54
+ public function getRowId(Varien_Object $row)
55
+ {
56
+ return $row->getIncrementId();
57
+ }
58
+
59
+
60
+
61
+ public function getQuery()
62
+ {
63
+ $query = parent::getQuery();
64
+ $query->addBinding('store_id', 'store_id');
65
+ $query->addBinding('order_id', 'entity_id');
66
+ $query->addBinding('quote_id', 'quote_id');
67
+ $query->addBinding('ordered_at', 'created_at');
68
+ $query->addBinding('goal_time', 'created_at');
69
+ $query->addBinding('customer_id', 'customer_id');
70
+ $query->addBinding('email', 'customer_email');
71
+
72
+ return $query;
73
+ }
74
+
75
+
76
+
77
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
78
+ {
79
+ parent::prepareCollection($collection);
80
+
81
+ $collection->addField('store_id');
82
+ $collection->addField('created_at');
83
+ $collection->addField('status');
84
+ $collection->addField('increment_id');
85
+ }
86
+
87
+
88
+
89
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
90
+ {
91
+
92
+ if (!Mage::app()->isSingleStoreMode()) {
93
+ $grid->addColumn('store_id', array(
94
+ 'header' => Mage::helper('sales')->__('Purchased From (Store)'),
95
+ 'index' => 'store_id',
96
+ 'type' => 'store',
97
+ 'store_view'=> true,
98
+ 'display_deleted' => true,
99
+ 'width' => '20%',
100
+ ));
101
+ }
102
+
103
+ $grid->addColumn('customer_id', array(
104
+ 'header' => $this->__('Customer ID'),
105
+ 'id_field' => 'customer_id',
106
+ 'label_field' => 'customer_id',
107
+ 'is_system' => true,
108
+ 'width' => '50px',
109
+ 'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
110
+ 'object' => Mage::getSingleton('mzax_emarketing/object_customer')
111
+ ));
112
+
113
+ $grid->addColumn('created_at', array(
114
+ 'header' => Mage::helper('sales')->__('Purchased On'),
115
+ 'index' => 'created_at',
116
+ 'type' => 'datetime',
117
+ 'width' => '100px',
118
+ ));
119
+
120
+ $grid->addColumn('status', array(
121
+ 'header' => Mage::helper('sales')->__('Status'),
122
+ 'index' => 'status',
123
+ 'type' => 'options',
124
+ 'width' => '70px',
125
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
126
+ ));
127
+ }
128
+
129
+
130
+ }
app/code/community/Mzax/Emarketing/Model/Object/OrderAddress.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Object_OrderAddress extends Mzax_Emarketing_Model_Object_Address
34
+ {
35
+
36
+
37
+ public function _construct()
38
+ {
39
+ $this->_init('sales/order_address');
40
+ }
41
+
42
+
43
+
44
+ public function getName()
45
+ {
46
+ return $this->__('Order Address');
47
+ }
48
+
49
+
50
+
51
+ public function getQuery()
52
+ {
53
+ $query = parent::getQuery();
54
+ $query->addBinding('order_id', 'parent_id');
55
+
56
+ return $query;
57
+ }
58
+
59
+
60
+ }
app/code/community/Mzax/Emarketing/Model/Object/OrderItem.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ *
29
+ */
30
+ class Mzax_Emarketing_Model_Object_OrderItem extends Mzax_Emarketing_Model_Object_Abstract
31
+ {
32
+
33
+ public function _construct()
34
+ {
35
+ $this->_init('sales/order_item');
36
+ }
37
+
38
+
39
+
40
+ public function getName()
41
+ {
42
+ return $this->__('Order Item');
43
+ }
44
+
45
+
46
+ public function getAdminUrl($id)
47
+ {
48
+ return $this->getUrl('admin_mzax_emarketing/admin_shortcut/orderItem', array('id' => $id));
49
+ }
50
+
51
+
52
+ public function getQuery()
53
+ {
54
+ $query = parent::getQuery();
55
+ $query->addBinding('order_id', 'order_id');
56
+ $query->addBinding('product_id', 'product_id');
57
+ $query->addBinding('order_item_id', 'item_id');
58
+
59
+ return $query;
60
+ }
61
+
62
+
63
+
64
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
65
+ {
66
+ parent::prepareCollection($collection);
67
+
68
+ $collection->addField('order_item_id');
69
+ $collection->addField('product_type');
70
+ $collection->addField('product_id');
71
+ $collection->addField('sku');
72
+ $collection->addField('name');
73
+ $collection->addField('qty_invoiced');
74
+ }
75
+
76
+
77
+
78
+
79
+
80
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
81
+ {
82
+ foreach(Mage::getSingleton('catalog/product_type')->getOptions() as $option) {
83
+ $productTypes[$option['value']] = $option['label'];
84
+ }
85
+
86
+ $grid->addColumn('product_type', array(
87
+ 'header' => $this->__('Product Type'),
88
+ 'index' => 'product_type',
89
+ 'type' => 'options',
90
+ 'options' => $productTypes
91
+ ));
92
+
93
+
94
+ /*
95
+ $grid->addColumn('product', array(
96
+ 'header' => $this->__('Product SKU'),
97
+ 'is_system' => true,
98
+ 'width' => '25%',
99
+ 'id_field' => 'product_id',
100
+ 'label_field' => 'sku',
101
+ 'renderer' => 'mzax_emarketing/recipients_column_renderer_subject',
102
+ 'object' => Mage::getSingleton('mzax_emarketing/object_product'),
103
+ ));
104
+ */
105
+
106
+ $grid->addColumn('sku', array(
107
+ 'header' => Mage::helper('sales')->__('SKU'),
108
+ 'index' => 'sku',
109
+ 'width' => '30%'
110
+ ));
111
+
112
+ $grid->addColumn('name', array(
113
+ 'header' => Mage::helper('sales')->__('Name'),
114
+ 'index' => 'name',
115
+ ));
116
+ }
117
+
118
+ }
app/code/community/Mzax/Emarketing/Model/Object/Product.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ *
29
+ */
30
+ class Mzax_Emarketing_Model_Object_Product extends Mzax_Emarketing_Model_Object_Abstract
31
+ {
32
+
33
+ public function _construct()
34
+ {
35
+ $this->_init('catalog/product');
36
+ }
37
+
38
+
39
+
40
+ public function getName()
41
+ {
42
+ return $this->__('Product');
43
+ }
44
+
45
+
46
+
47
+
48
+ public function getQuery()
49
+ {
50
+ $query = parent::getQuery();
51
+ $query->addBinding('product_id', 'product_id');
52
+
53
+ return $query;
54
+ }
55
+
56
+
57
+
58
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
59
+ {
60
+ parent::prepareCollection($collection);
61
+ $collection->addField('sku');
62
+ }
63
+
64
+
65
+
66
+
67
+
68
+ public function getAdminUrl($id)
69
+ {
70
+ return $this->getUrl('adminhtml/catalog_product/edit', array('id' => $id));
71
+ }
72
+
73
+
74
+
75
+
76
+ }
app/code/community/Mzax/Emarketing/Model/Object/Quote.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Object_Quote extends Mzax_Emarketing_Model_Object_Abstract
34
+ {
35
+
36
+ public function _construct()
37
+ {
38
+ $this->_init('sales/quote');
39
+ }
40
+
41
+
42
+
43
+ public function getName()
44
+ {
45
+ return $this->__('Quote');
46
+ }
47
+
48
+
49
+
50
+ public function getQuery()
51
+ {
52
+ $query = parent::getQuery();
53
+ $query->where('`main_table`.`is_active` = 1');
54
+ $query->where('`main_table`.`items_count` > 0');
55
+ // @todo Should be medium ?
56
+ $query->where('`main_table`.`customer_email` > ""');
57
+ $query->addBinding('store_id', 'store_id');
58
+ $query->addBinding('quote_id', 'entity_id');
59
+ $query->addBinding('customer_id', 'customer_id');
60
+ $query->addBinding('email', 'customer_email');
61
+
62
+ return $query;
63
+ }
64
+
65
+
66
+
67
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
68
+ {
69
+ parent::prepareCollection($collection);
70
+
71
+ $collection->addField('store_id');
72
+ $collection->addField('created_at');
73
+ $collection->addField('updated_at');
74
+ $collection->addField('customer_id');
75
+ $collection->addField('email');
76
+ }
77
+
78
+
79
+
80
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
81
+ {
82
+
83
+ if (!Mage::app()->isSingleStoreMode()) {
84
+ $grid->addColumn('store_id', array(
85
+ 'header' => Mage::helper('sales')->__('Purchased From (Store)'),
86
+ 'index' => 'store_id',
87
+ 'type' => 'store',
88
+ 'store_view'=> false,
89
+ 'display_deleted' => true,
90
+ 'width' => '20%',
91
+ ));
92
+ }
93
+
94
+ $grid->addColumn('customer_id', array(
95
+ 'header' => $this->__('Customer ID'),
96
+ 'id_field' => 'customer_id',
97
+ 'label_field' => 'customer_id',
98
+ 'is_system' => true,
99
+ 'width' => '50px',
100
+ 'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
101
+ 'object' => Mage::getSingleton('mzax_emarketing/object_customer')
102
+ ));
103
+
104
+
105
+ $grid->addColumn('email', array(
106
+ 'header' => $this->__('Email'),
107
+ 'index' => 'email'
108
+ ));
109
+
110
+
111
+ $grid->addColumn('created_at', array(
112
+ 'header' => Mage::helper('sales')->__('Created At'),
113
+ 'index' => 'created_at',
114
+ 'type' => 'datetime',
115
+ 'width' => '120px',
116
+ ));
117
+
118
+ $grid->addColumn('updated_at', array(
119
+ 'header' => Mage::helper('sales')->__('Last Touch'),
120
+ 'index' => 'updated_at',
121
+ 'type' => 'datetime',
122
+ 'width' => '120px',
123
+ ));
124
+
125
+ }
126
+
127
+
128
+ }
app/code/community/Mzax/Emarketing/Model/Object/QuoteAddress.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Object_QuoteAddress extends Mzax_Emarketing_Model_Object_Address
34
+ {
35
+
36
+
37
+ public function _construct()
38
+ {
39
+ $this->_init('sales/quote_address');
40
+ }
41
+
42
+
43
+
44
+ public function getName()
45
+ {
46
+ return $this->__('Quote Address');
47
+ }
48
+
49
+
50
+ public function getAdminUrl($id)
51
+ {
52
+ return null;
53
+ }
54
+
55
+
56
+ public function getQuery()
57
+ {
58
+ $query = parent::getQuery();
59
+ $query->addBinding('quote_id', 'parent_id');
60
+
61
+ return $query;
62
+ }
63
+
64
+
65
+ }
app/code/community/Mzax/Emarketing/Model/Object/Recipient.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ *
29
+ */
30
+ class Mzax_Emarketing_Model_Object_Recipient extends Mzax_Emarketing_Model_Object_Abstract
31
+ {
32
+
33
+ public function _construct()
34
+ {
35
+ $this->_init('mzax_emarketing/recipient');
36
+ }
37
+
38
+
39
+
40
+
41
+ public function getName()
42
+ {
43
+ return $this->__('Recipient');
44
+ }
45
+
46
+
47
+
48
+
49
+
50
+ public function getQuery()
51
+ {
52
+ $query = parent::getQuery();
53
+ $query->addBinding('recipient_id', 'recipient_id');
54
+ $query->addBinding('recipient_sent_at', 'sent_at');
55
+ $query->addBinding('campaign_id', 'campaign_id');
56
+ $query->addBinding('variation_id', 'variation_id');
57
+
58
+ return $query;
59
+ }
60
+
61
+
62
+
63
+
64
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
65
+ {
66
+ parent::prepareCollection($collection);
67
+
68
+ $collection->addField('sent_at');
69
+ $collection->addField('object_id');
70
+ $collection->addField('variation_id');
71
+ $collection->addField('campaign_id');
72
+ }
73
+
74
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
75
+ {
76
+ $grid->addColumn('sent_at', array(
77
+ 'header' => Mage::helper('sales')->__('Sent at'),
78
+ 'index' => 'sent_at',
79
+ 'type' => 'datetime',
80
+ 'width' => '150px',
81
+ ));
82
+
83
+ $grid->addColumn('object_id', array(
84
+ 'header' => Mage::helper('sales')->__('Object ID'),
85
+ 'index' => 'object_id',
86
+ 'type' => 'number',
87
+ ));
88
+
89
+ $grid->addColumn('campaign_id', array(
90
+ 'header' => Mage::helper('sales')->__('Campaign ID'),
91
+ 'index' => 'campaign_id',
92
+ 'type' => 'number',
93
+ ));
94
+
95
+ $grid->addColumn('variation_id', array(
96
+ 'header' => Mage::helper('sales')->__('Variation ID'),
97
+ 'index' => 'variation_id',
98
+ 'type' => 'number',
99
+ ));
100
+
101
+
102
+ }
103
+
104
+
105
+ }
app/code/community/Mzax/Emarketing/Model/Object/Subscriber.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Object_Subscriber extends Mzax_Emarketing_Model_Object_Abstract
33
+ {
34
+
35
+
36
+ public function _construct()
37
+ {
38
+ $this->_init('newsletter/subscriber');
39
+ }
40
+
41
+
42
+
43
+ public function getName()
44
+ {
45
+ return $this->__('Subscriber');
46
+ }
47
+
48
+
49
+ public function getAdminUrl($id)
50
+ {
51
+ // @todo maybe try setting filter
52
+ return $this->getUrl('adminhtml/newsletter_subscriber/index');
53
+ }
54
+
55
+
56
+ public function getQuery()
57
+ {
58
+ $query = parent::getQuery();
59
+ $query->addBinding('customer_id', 'customer_id');
60
+ $query->addBinding('email', 'subscriber_email');
61
+ $query->addBinding('subscriber_status', 'subscriber_status');
62
+
63
+
64
+
65
+ return $query;
66
+ }
67
+
68
+
69
+
70
+
71
+ /**
72
+ *
73
+ * @return Mzax_Emarketing_Model_Object_Collection
74
+ */
75
+ public function getCollection()
76
+ {
77
+ $collection = parent::getCollection();
78
+
79
+ $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
80
+ $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
81
+
82
+ $adapter = $this->getResourceHelper()->getAdapter();
83
+
84
+ $nameExpr[] = "LTRIM(RTRIM($firstname))";
85
+ $nameExpr[] = "LTRIM(RTRIM($lastname))";
86
+ $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
87
+
88
+ $collection->addField('name', $nameExpr);
89
+ $collection->addField('email', 'email');
90
+
91
+ return $collection;
92
+ }
93
+
94
+
95
+
96
+ public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
97
+ {
98
+ parent::prepareCollection($collection);
99
+
100
+ $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
101
+ $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
102
+
103
+ $adapter = $this->getResourceHelper()->getAdapter();
104
+
105
+ $nameExpr[] = "LTRIM(RTRIM($firstname))";
106
+ $nameExpr[] = "LTRIM(RTRIM($lastname))";
107
+ $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
108
+
109
+ $collection->addField('name', $nameExpr);
110
+ $collection->addField('email', 'email');
111
+ $collection->addField('newsletter_status', 'subscriber_status');
112
+
113
+ }
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+ public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
122
+ {
123
+
124
+ $grid->addColumn('name', array(
125
+ 'header' => Mage::helper('mzax_emarketing')->__('Name'),
126
+ 'index' => 'name'
127
+ ));
128
+
129
+ $grid->addColumn('email', array(
130
+ 'header' => Mage::helper('mzax_emarketing')->__('Email'),
131
+ 'index' => 'email',
132
+ ));
133
+
134
+ $grid->addColumn('newsletter_status', array(
135
+ 'header' => $this->__('Newsletter'),
136
+ 'width' => '80px',
137
+ 'index' => 'newsletter_status',
138
+ 'align' => 'center',
139
+ 'type' => 'options',
140
+ 'options' => array_map('ucwords', array(
141
+ Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED => $this->__('subscribed'),
142
+ Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED => $this->__('unsubscribed'),
143
+ Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE => $this->__('not activated'),
144
+ Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => $this->__('unconfirmed')
145
+ ))
146
+ ));
147
+
148
+
149
+
150
+ }
151
+
152
+
153
+
154
+
155
+ public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
156
+ {
157
+ $snippets->addVar('customer.firstname', $this->__("Customers Firstname"));
158
+ $snippets->addVar('customer.lastname', $this->__("Customers Lastname"));
159
+ $snippets->addVar('subscriber.status', $this->__("Subscriber Status"));
160
+ }
161
+
162
+
163
+
164
+ /**
165
+ * (non-PHPdoc)
166
+ * @see Mzax_Emarketing_Model_Object_Abstract::prepareRecipient()
167
+ *//*
168
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
169
+ {
170
+ parent::prepareRecipient($recipient);
171
+
172
+ /* @var $customer Mage_Customer_Model_Customer * /
173
+ $customer = $recipient->getObject();
174
+
175
+ $recipient->setCustomer($customer);
176
+ $recipient->setEmail($customer->getEmail());
177
+ $recipient->setName($customer->getName());
178
+ }*/
179
+ }
app/code/community/Mzax/Emarketing/Model/Observer.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Observer extends Mzax_Emarketing_Model_Observer_Abstract
25
+ {
26
+
27
+
28
+
29
+ /**
30
+ * If requried we want to get the users timezone offset
31
+ *
32
+ * We will inject a tiny javascript code to the bottom of the page
33
+ * which will set a cookie which we then can use to determin the exact
34
+ * time zone.
35
+ *
36
+ * @see Mage_Core_Controller_Varien_Action::renderLayout()
37
+ * @event controller_action_layout_generate_blocks_after
38
+ */
39
+ public function injectTimeOffsetJs(Varien_Event_Observer $observer)
40
+ {
41
+ if(!Mage::getStoreConfigFlag('mzax_emarketing/tracking/inject_timeoffset_js')) {
42
+ return;
43
+ }
44
+
45
+ if(!$this->getSession()->requireTimeOffset()) {
46
+ return;
47
+ }
48
+
49
+ /* @var $layout Mage_Core_Model_Layout */
50
+ $layout = $observer->getEvent()->getLayout();
51
+
52
+ $script = $this->getTimeOffsetScript();
53
+
54
+ /* @var $block Mage_Core_Block_Text_List */
55
+ $block = $layout->getBlock('before_body_end');
56
+ if($block && $script) {
57
+ /* @var $script Mage_Core_Block_Text_Tag_Js */
58
+ $jsTag = $layout->createBlock('core/text_tag_js', 'time_offset_js');
59
+ $jsTag->setContents($script);
60
+ $block->append($jsTag);
61
+ }
62
+ }
63
+
64
+
65
+
66
+
67
+ /**
68
+ * Retrieve script for setting time offset cookie
69
+ *
70
+ * @return string
71
+ */
72
+ public function getTimeOffsetScript()
73
+ {
74
+ $cookie = Mzax_Emarketing_Model_Session::TIME_OFFSET_COOKIE;
75
+ return "(Mage && Mage.Cookies && Mage.Cookies.set('$cookie', (new Date).getTimezoneOffset()));";
76
+ }
77
+
78
+
79
+
80
+
81
+ }
app/code/community/Mzax/Emarketing/Model/Observer/Abstract.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Observer Abstract
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ abstract class Mzax_Emarketing_Model_Observer_Abstract
33
+ {
34
+
35
+
36
+ /**
37
+ * Retrieve session object model
38
+ *
39
+ * @return Mzax_Emarketing_Model_Session
40
+ */
41
+ public function getSession()
42
+ {
43
+ return Mage::getSingleton('mzax_emarketing/session');
44
+ }
45
+
46
+ }
app/code/community/Mzax/Emarketing/Model/Observer/Cron.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * All cron tab commands are here, you can disable them
27
+ * and run your own scripts if ever needed.
28
+ *
29
+ *
30
+ * @author Jacob Siefer
31
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
+ * @version 0.2.5
33
+ */
34
+ class Mzax_Emarketing_Model_Observer_Cron
35
+ extends Mzax_Emarketing_Model_Observer_Abstract
36
+ {
37
+
38
+ /**
39
+ *
40
+ * @var boolean
41
+ */
42
+ protected $_testMode = false;
43
+
44
+
45
+
46
+ /**
47
+ * Simple test
48
+ *
49
+ * @access private
50
+ * @return void
51
+ */
52
+ public function test()
53
+ {
54
+ $this->_testMode = true;
55
+
56
+ echo "Fetch recipients... ";
57
+ $this->fetchRecipients();
58
+ echo "done\n\n";
59
+
60
+ echo "Send recipients... ";
61
+ $this->sendRecipients();
62
+ echo "done\n\n";
63
+
64
+ echo "Outbox send... ";
65
+ $this->outboxSend();
66
+ echo "done\n\n";
67
+
68
+ echo "Inbox load... ";
69
+ $this->inboxLoad();
70
+ echo "done\n\n";
71
+
72
+ echo "Run report tasks... ";
73
+ $this->runReportTasks();
74
+ echo "done\n\n";
75
+
76
+ echo "Aggregate reports... ";
77
+ $this->aggregateWeekly();
78
+ echo "done\n\n";
79
+
80
+ $this->_testMode = false;
81
+ }
82
+
83
+
84
+
85
+ /**
86
+ * Can run cron tabs
87
+ *
88
+ * @return boolean
89
+ */
90
+ public function enabled()
91
+ {
92
+ if($this->_testMode) {
93
+ return true;
94
+ }
95
+ return Mage::getStoreConfigFlag('mzax_emarketing/general/enable');
96
+ }
97
+
98
+
99
+
100
+ /**
101
+ * Check all campaigns for new recipients
102
+ *
103
+ * @return void
104
+ */
105
+ public function fetchRecipients()
106
+ {
107
+ if(!$this->enabled()) {
108
+ return;
109
+ }
110
+
111
+ $options = array(
112
+ 'timeout' => 60*5,
113
+ 'break_on_error' => false,
114
+ 'verbose' => $this->_testMode
115
+ );
116
+ Mage::helper('mzax_emarketing/campaign')->fetchNewRecipients($options);
117
+ }
118
+
119
+
120
+
121
+ /**
122
+ * Send recipients
123
+ *
124
+ * @return void
125
+ */
126
+ public function sendRecipients()
127
+ {
128
+ if(!$this->enabled()) {
129
+ return;
130
+ }
131
+
132
+ $options = array(
133
+ 'timeout' => 60*5,
134
+ 'maximum' => 1000,
135
+ 'break_on_error' => false,
136
+ 'verbose' => $this->_testMode
137
+ );
138
+ Mage::helper('mzax_emarketing/campaign')->sendRecipients($options);
139
+ }
140
+
141
+
142
+
143
+
144
+
145
+ /**
146
+ * Send emails from outbox and queue in template
147
+ *
148
+ * @return void
149
+ */
150
+ public function outboxSend()
151
+ {
152
+ if(!$this->enabled()) {
153
+ return;
154
+ }
155
+
156
+ $options = array(
157
+ 'timeout' => 60*5,
158
+ 'maximum' => 200,
159
+ 'break_on_error' => false,
160
+ 'verbose' => $this->_testMode
161
+ );
162
+
163
+ /* @var $outbox Mzax_Emarketing_Model_Outbox */
164
+ $outbox = Mage::getModel('mzax_emarketing/outbox');
165
+ $outbox->sendEmails($options);
166
+ }
167
+
168
+
169
+
170
+ /**
171
+ * Connect to email inbox and check for new messages
172
+ *
173
+ * @return void
174
+ */
175
+ public function inboxLoad()
176
+ {
177
+ if(!$this->enabled()) {
178
+ return;
179
+ }
180
+
181
+ /* @var $inbox Mzax_Emarketing_Model_Inbox */
182
+ $inbox = Mage::getModel('mzax_emarketing/inbox');
183
+ $inbox->downloadEmails();
184
+ $inbox->parseEmails();
185
+ }
186
+
187
+
188
+
189
+
190
+
191
+ /**
192
+ * Run tasks related to report
193
+ *
194
+ * @return void
195
+ */
196
+ public function runReportTasks()
197
+ {
198
+ if(!$this->enabled()) {
199
+ return;
200
+ }
201
+
202
+ /* @var $report Mzax_Emarketing_Model_Report */
203
+ $report = Mage::getModel('mzax_emarketing/report');
204
+ $report->fetchGeoIp();
205
+ $report->parseUseragents();
206
+ }
207
+
208
+
209
+
210
+ /**
211
+ * Aggregate reports for the past 2 days
212
+ *
213
+ * This can run fairly quick only updating records from the past 2 days
214
+ * making it a fast way for aggregating new data.
215
+ *
216
+ * However there might be some rare duplicates
217
+ *
218
+ * @return void
219
+ */
220
+ public function aggregateHourly()
221
+ {
222
+ /* @var $aggregator Mzax_Emarketing_Model_Report_Aggregator */
223
+ $aggregator = Mage::getModel('mzax_emarketing/report_aggregator');
224
+ $aggregator->run(array(
225
+ 'incremental' => 5,
226
+ 'verbose' => $this->_testMode
227
+ ));
228
+ }
229
+
230
+
231
+
232
+ /**
233
+ * Aggregate reports for the past 5 days
234
+ *
235
+ * This runs quite quick as well but will definitely have less duplicates
236
+ *
237
+ * @return void
238
+ */
239
+ public function aggregateDaily()
240
+ {
241
+ /* @var $aggregator Mzax_Emarketing_Model_Report_Aggregator */
242
+ $aggregator = Mage::getModel('mzax_emarketing/report_aggregator');
243
+ $aggregator->run(array(
244
+ 'incremental' => 20,
245
+ 'verbose' => $this->_testMode
246
+ ));
247
+ }
248
+
249
+
250
+
251
+
252
+ /**
253
+ * Aggregate reports for the past 60 days
254
+ *
255
+ * Will be slower but quite accurate results. Running it once a week is perfect.
256
+ *
257
+ * @todo allow full manual reindex
258
+ * @return void
259
+ */
260
+ public function aggregateWeekly()
261
+ {
262
+ /* @var $aggregator Mzax_Emarketing_Model_Report_Aggregator */
263
+ $aggregator = Mage::getModel('mzax_emarketing/report_aggregator');
264
+ $aggregator->run(array(
265
+ 'incremental' => 60,
266
+ 'verbose' => $this->_testMode
267
+ ));
268
+ }
269
+
270
+
271
+
272
+ }
app/code/community/Mzax/Emarketing/Model/Observer/Customer.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Observer_Customer
34
+ extends Mzax_Emarketing_Model_Observer_Goal
35
+ {
36
+
37
+ protected $_goalType = Mzax_Emarketing_Model_Goal::TYPE_SIGNUP;
38
+
39
+ }
app/code/community/Mzax/Emarketing/Model/Observer/Goal.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Goal observer helper abstract
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Observer_Goal
34
+ extends Mzax_Emarketing_Model_Observer_Abstract
35
+ {
36
+
37
+
38
+ /**
39
+ * A goal type id pre defined
40
+ *
41
+ * 1 = orders
42
+ * 2 = signups
43
+ *
44
+ * If you plan on implementing custom types
45
+ * use a type id greater than 100
46
+ *
47
+ * @var integer
48
+ */
49
+ protected $_goalType;
50
+
51
+
52
+
53
+ /**
54
+ * Carefully handle save events
55
+ *
56
+ * @event sales_order_save_before
57
+ * @param Varien_Event_Observer $observer
58
+ * @return void
59
+ */
60
+ public function beforeSave(Varien_Event_Observer $observer)
61
+ {
62
+ try {
63
+ $object = $observer->getEvent()->getDataObject();
64
+ if($object && method_exists($this, '_beforeSave')) {
65
+ $this->_beforeSave($object);
66
+ }
67
+ }
68
+ catch(Exception $e) {
69
+ Mage::logException($e);
70
+ }
71
+ }
72
+
73
+
74
+
75
+
76
+ /**
77
+ * Carefully handle save events
78
+ *
79
+ * @event sales_order_save_after
80
+ * @param Varien_Event_Observer $observer
81
+ * @return void
82
+ */
83
+ public function afterSave(Varien_Event_Observer $observer)
84
+ {
85
+ try {
86
+ $object = $observer->getEvent()->getDataObject();
87
+ if($object && method_exists($this, '_afterSave')) {
88
+ $this->_afterSave($object);
89
+ }
90
+ }
91
+ catch(Exception $e) {
92
+ Mage::logException($e);
93
+ }
94
+ }
95
+
96
+
97
+
98
+
99
+
100
+ /**
101
+ * Check before save is object is new and set a flag
102
+ *
103
+ * @param Mage_Core_Model_Abstract $object
104
+ */
105
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
106
+ {
107
+ if( $object->isObjectNew() && $object->getSaveMzaxGoalReferences() === null ) {
108
+ // only if object is new
109
+ $object->setSaveMzaxGoalReferences(true);
110
+ }
111
+ }
112
+
113
+
114
+
115
+ /**
116
+ * Save goals for this object
117
+ *
118
+ * @param Mage_Core_Model_Abstract $object
119
+ */
120
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
121
+ {
122
+ if(!$object->getSaveMzaxGoalReferences()) {
123
+ return;
124
+ }
125
+
126
+ // only do it once
127
+ $object->setSaveMzaxGoalReferences(false);
128
+
129
+ $clicks = $this->getSession()->getClickReferences();
130
+
131
+ $data = array();
132
+ foreach($clicks as $click) {
133
+ $data[] = array(
134
+ 'object_type' => $this->_goalType,
135
+ 'object_id' => $object->getId(),
136
+ 'recipient_id' => $click['recipient_id'],
137
+ 'click_id' => $click['click_id'],
138
+ );
139
+ }
140
+
141
+ if(!empty($data)) {
142
+ /* @see Mzax_Emarketing_Model_Resource_Goal */
143
+ Mage::getResourceModel('mzax_emarketing/goal')->insertMultiple($data);
144
+ }
145
+ }
146
+
147
+
148
+
149
+
150
+
151
+
152
+ /**
153
+ *
154
+ *
155
+ * @event mzax_emarketing_bind_recipients
156
+ * @param Varien_Event_Observer $observer
157
+ */
158
+ public function bindRecipients(Varien_Event_Observer $observer)
159
+ {
160
+ /* @var $binder Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder */
161
+ $binder = $observer->getEvent()->getBinder();
162
+
163
+ if($binder->hasBinding('ORDER')) {
164
+ $binder->createBinding()
165
+ ->joinTable(array(
166
+ 'object_type' => Mzax_Emarketing_Model_Goal::TYPE_ORDER,
167
+ 'object_id' => '{ORDER}'
168
+ ), 'goal')
169
+ ->joinTable(array('recipient_id' => '{recipient_id}'), 'recipient')
170
+ ->addBinding('recipient_id', 'recipient.recipient_id')
171
+ ->addBinding('sent_at', 'recipient.sent_at')
172
+ ->addBinding('variation_id', 'recipient.variation_id')
173
+ ->addBinding('campaign_id', 'recipient.campaign_id');
174
+ }
175
+ }
176
+
177
+
178
+ }
app/code/community/Mzax/Emarketing/Model/Observer/Order.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Observer_Order
34
+ extends Mzax_Emarketing_Model_Observer_Goal
35
+ {
36
+
37
+ protected $_goalType = Mzax_Emarketing_Model_Goal::TYPE_ORDER;
38
+
39
+ }
app/code/community/Mzax/Emarketing/Model/Outbox.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Model_Outbox
26
+ {
27
+
28
+
29
+
30
+ /**
31
+ * Retrieve emails
32
+ *
33
+ * @param string $ids
34
+ * @return Mzax_Emarketing_Model_Resource_Outbox_Email_Collection
35
+ */
36
+ public function getEmails($ids = null)
37
+ {
38
+ /* @var $collection Mzax_Emarketing_Model_Resource_Outbox_Email_Collection */
39
+ $collection = Mage::getResourceModel('mzax_emarketing/outbox_email_collection');
40
+ $collection->assignRecipients();
41
+ $collection->assignCampaigns();
42
+ if($ids) {
43
+ $collection->addIdFilter($ids);
44
+ }
45
+ return $collection;
46
+ }
47
+
48
+
49
+ /**
50
+ * Retrieve email by recipient
51
+ *
52
+ * @param mixed $recipient
53
+ * @return Mzax_Emarketing_Model_Outbox_Email
54
+ */
55
+ public function getEmailByRecipient($recipient)
56
+ {
57
+ if($recipient instanceof Mzax_Emarketing_Model_Recipient) {
58
+ $recipient = $recipient->getId();
59
+ }
60
+
61
+ /* @var $email Mzax_Emarketing_Model_Outbox_Email */
62
+ $email = Mage::getModel('mzax_emarketing/outbox_email');
63
+ $email->load($recipient, 'recipient_id');
64
+
65
+ return $email;
66
+ }
67
+
68
+
69
+
70
+
71
+ /**
72
+ * Send out emails
73
+ *
74
+ */
75
+ public function sendEmails(array $options = array())
76
+ {
77
+ $lock = Mage::helper('mzax_emarketing')->lock('send_emails');
78
+ if(!$lock) {
79
+ return false;
80
+ }
81
+
82
+ $options = new Varien_Object($options);
83
+
84
+ $timeout = $options->getDataSetDefault('timeout', 60*5);
85
+ $maximum = $options->getDataSetDefault('maximum', 200);
86
+ $now = $options->getDataSetDefault('now', time());
87
+ $emailIds = $options->getDataSetDefault('ids', false);
88
+
89
+
90
+
91
+ /* @var $emails Mzax_Emarketing_Model_Resource_Outbox_Email_Collection */
92
+ $emails = Mage::getResourceModel('mzax_emarketing/outbox_email_collection');
93
+ $emails->assignCampaigns();
94
+ $emails->assignRecipients();
95
+ $emails->addFieldToFilter('sent_at', array('null' => true));
96
+ $emails->addFieldToFilter('status', Mzax_Emarketing_Model_Outbox_Email::STATUS_NOT_SEND);
97
+ $emails->addTimeFilter();
98
+ $emails->setOrder('expire_at', 'ASC');
99
+ $emails->setPageSize($maximum);
100
+
101
+ if(!empty($emailIds)) {
102
+ $emails->addFieldToFilter('email_id', array('in' => $emailIds));
103
+ }
104
+
105
+ if($options->getVerbose()) {
106
+ echo "\n\n{$emails->getSelect()}\n\n";
107
+ }
108
+
109
+
110
+ $domainThrottle = $this->enableDomainThrottling();
111
+ if($domainThrottle) {
112
+ /* @var $domainThrottle Mzax_Emarketing_Model_DomainThrottle */
113
+ $domainThrottle = Mage::getModel('mzax_emarketing/domainThrottle');
114
+ $domainThrottle->setTimeThreshold($this->getConfig('time_threshold'));
115
+ $domainThrottle->setSendThreshold($this->getConfig('send_threshold'));
116
+ $domainThrottle->setRestTime($this->getConfig('rest_time'));
117
+
118
+ $domainSpecific = $this->getConfig('domain_specific');
119
+ if($domainSpecific) {
120
+ foreach(unserialize($domainSpecific) as $data) {
121
+ $domainThrottle->addDomainOption($data['domain'],
122
+ $data['time_threshold'],
123
+ $data['send_threshold'],
124
+ $data['rest_time']);
125
+ }
126
+ }
127
+
128
+ $domainThrottle->purge();
129
+ }
130
+
131
+
132
+ $start = time();
133
+
134
+ $count = 0;
135
+
136
+ /* @var $email Mzax_Emarketing_Model_Outbox_Email */
137
+ foreach($emails as $email) {
138
+
139
+ // recipient may has been removed, if so - discard email
140
+ if(!$email->getRecipient()->getId()) {
141
+ $email->setStatus(Mzax_Emarketing_Model_Outbox_Email::STATUS_DISCARDED);
142
+ $email->getLog()->warn("Recipient does not exist any more.");
143
+ $email->save();
144
+ continue;
145
+ }
146
+
147
+ if(time() - $start > $timeout) {
148
+ $this->log("Mzax Emarketing: Reached timelimit of {$timeout}sec");
149
+ break;
150
+ }
151
+
152
+ // check if we can still send the message or if we missed the expire date
153
+ if($email->isExpired($now)) {
154
+ $email->setStatus(Mzax_Emarketing_Model_Outbox_Email::STATUS_EXPIRED);
155
+ $warn = "Message has expired, stop sending";
156
+ $email->getLog()->warn($warn);
157
+ $email->save();
158
+ continue;
159
+ }
160
+
161
+ // check if we can send now if not ignore
162
+ if(!$email->canSend($now)) {
163
+ continue;
164
+ }
165
+
166
+ if($domainThrottle && ($time = $domainThrottle->isResting($email->getDomain()))) {
167
+ $notice = "DomainThrottle currently prevents this message from sending for at least $time more seconds";
168
+ $this->log($notice);
169
+ $email->getLog()->notice($notice);
170
+ $email->save();
171
+ continue;
172
+ }
173
+
174
+ $email->send();
175
+ $lock->touch();
176
+ $count++;
177
+ }
178
+
179
+ $lock->unlock();
180
+ return $count;
181
+ }
182
+
183
+
184
+
185
+ protected function log($message)
186
+ {
187
+ Mage::log($message);
188
+ echo "$message\n";
189
+ }
190
+
191
+
192
+ /**
193
+ * Enable domain throttling
194
+ * This will prevent to send to many emails in a to short
195
+ * of time to the same domain
196
+ *
197
+ * @return boolean
198
+ */
199
+ public function enableDomainThrottling()
200
+ {
201
+ return Mage::getStoreConfigFlag('mzax_emarketing/domain_throttling/enable');
202
+ }
203
+
204
+
205
+ /**
206
+ * Retrieve config option
207
+ *
208
+ * @param string $path
209
+ * @return mixed
210
+ */
211
+ protected function getConfig($path)
212
+ {
213
+ return Mage::getStoreConfig('mzax_emarketing/domain_throttling/' . $path);
214
+ }
215
+
216
+
217
+
218
+
219
+
220
+ /**
221
+ * Retrieve resource object
222
+ *
223
+ * @return Mzax_Emarketing_Model_Resource_Outbox_Email
224
+ */
225
+ public function getResource()
226
+ {
227
+ return Mage::getResourceSingleton('mzax_emarketing/outbox_email');
228
+ }
229
+
230
+
231
+
232
+ }
app/code/community/Mzax/Emarketing/Model/Outbox/Email.php ADDED
@@ -0,0 +1,615 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @method string getExpireAt()
26
+ * @method string getStatus()
27
+ * @method string getEmail()
28
+ * @method string getDomain()
29
+ * @method string getSubject()
30
+ * @method string getBodyText()
31
+ * @method string getBodyHtml()
32
+ * @method string getMessageId()
33
+ * @method string getTimeFilter()
34
+ * @method string getDayFilter()
35
+ * @method string getLog()
36
+ *
37
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setExpireAt()
38
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setStatus()
39
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setEmail()
40
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setDomain()
41
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setSubject()
42
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setBodyText()
43
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setBodyHtml()
44
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setMessageId()
45
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setTimeFilter()
46
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setDayFilter()
47
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email setLog()
48
+ *
49
+ *
50
+ *
51
+ * @method Mzax_Emarketing_Model_Resource_Outbox_Email getResource()
52
+ *
53
+ *
54
+ * @author Jacob Siefer
55
+ *
56
+ */
57
+ class Mzax_Emarketing_Model_Outbox_Email
58
+ extends Mzax_Emarketing_Model_Email
59
+ {
60
+
61
+ const STATUS_NOT_SEND = 0;
62
+ const STATUS_SENT = 1;
63
+ const STATUS_EXPIRED = 2;
64
+ const STATUS_FAILED = 3;
65
+ const STATUS_DISCARDED = 4;
66
+
67
+
68
+
69
+ const REGEX_EMAIL = '/^[a-z0-9_\-]+(?:\.[_a-z0-9\-]+)*@((?:[_a-z0-9\-]+\.)+(?:[a-z]{2,}))$/i';
70
+
71
+
72
+
73
+
74
+ /**
75
+ * Use a tranport mock to for viewing the
76
+ * message that will be usend with all its headers
77
+ *
78
+ * @var Mzax_Mail_Transport_Mock
79
+ */
80
+ protected $_source;
81
+
82
+
83
+
84
+ /**
85
+ * Zend_Log
86
+ *
87
+ * @var Zend_Log
88
+ */
89
+ protected $_log;
90
+
91
+
92
+
93
+ /**
94
+ *
95
+ * @var array
96
+ */
97
+ protected $_logEvents;
98
+
99
+
100
+
101
+ /**
102
+ * List of all generated link references
103
+ *
104
+ * @var array
105
+ */
106
+ protected $_linkReferences = array();
107
+
108
+
109
+
110
+
111
+
112
+
113
+ protected function _construct()
114
+ {
115
+ $this->_init('mzax_emarketing/outbox_email');
116
+ }
117
+
118
+
119
+
120
+
121
+ /**
122
+ * Retrieve medium
123
+ *
124
+ * @return Mzax_Emarketing_Model_Medium_Email
125
+ */
126
+ public function getMedium()
127
+ {
128
+ return Mage::getSingleton('mzax_emarketing/medium_email');
129
+ }
130
+
131
+
132
+
133
+
134
+ protected function _beforeSave()
135
+ {
136
+ if(!empty($this->_logEvents)) {
137
+ $this->setData('log', Zend_Json::encode($this->_logEvents));
138
+ }
139
+
140
+ // make sure we have a message id
141
+ $this->getMessageId();
142
+
143
+ parent::_beforeSave();
144
+ }
145
+
146
+
147
+
148
+ protected function _afterSave()
149
+ {
150
+ if(!empty($this->_linkReferences)) {
151
+ $this->saveLinks();
152
+ }
153
+ }
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+ /**
162
+ * Retrieve all created link references
163
+ *
164
+ * @return array
165
+ */
166
+ public function getLinkReferences()
167
+ {
168
+ return $this->_linkReferences;
169
+ }
170
+
171
+
172
+ /**
173
+ * Remove all temporary links
174
+ *
175
+ * @return Mzax_Emarketing_Model_Queue_Recipient
176
+ */
177
+ public function clearLinks()
178
+ {
179
+ $this->_linkReferences = array();
180
+ return $this;
181
+ }
182
+
183
+
184
+
185
+
186
+ /**
187
+ * save all attached links
188
+ *
189
+ * @return Mzax_Emarketing_Model_Queue_Recipient
190
+ */
191
+ protected function saveLinks()
192
+ {
193
+ foreach($this->_linkReferences as $link) {
194
+ $link->save();
195
+ }
196
+ $this->_linkReferences = array();
197
+ return $this;
198
+ }
199
+
200
+
201
+
202
+
203
+
204
+ /**
205
+ * Use a mock mail transport to genereate the
206
+ * final output
207
+ *
208
+ * @return Mzax_Mail_Transport_Mock
209
+ */
210
+ public function getSource()
211
+ {
212
+ if(!$this->_source) {
213
+ $this->_source = new Mzax_Mail_Transport_Mock();
214
+ $this->createMailObject()->send($this->_source);
215
+ }
216
+ return $this->_source;
217
+ }
218
+
219
+
220
+
221
+ /**
222
+ * Get plain text message version
223
+ *
224
+ * @return string
225
+ */
226
+ public function getMessage()
227
+ {
228
+ return $this->getBodyText();
229
+ }
230
+
231
+
232
+
233
+ /**
234
+ * Get raw mime email content
235
+ *
236
+ * @return string
237
+ */
238
+ public function getContent()
239
+ {
240
+ return $this->getSource()->body;
241
+ }
242
+
243
+
244
+ /**
245
+ * Get raw email headers
246
+ *
247
+ * @return string
248
+ */
249
+ public function getHeaders()
250
+ {
251
+ return $this->getSource()->header;
252
+ }
253
+
254
+
255
+
256
+ /**
257
+ *
258
+ * @return Zend_Log
259
+ */
260
+ public function getLog()
261
+ {
262
+ if(!$this->_log) {
263
+ $writer = new Zend_Log_Writer_Mock;
264
+ if($data = $this->getData('log')) {
265
+ try {
266
+ $writer->events = Zend_Json::decode($data);
267
+ }
268
+ catch(Exception $e) {
269
+ // @todo backup current data
270
+ Mage::logException($e);
271
+ }
272
+ }
273
+
274
+ $this->_logEvents = &$writer->events;
275
+
276
+ $this->_log = new Zend_Log;
277
+ $this->_log->addWriter($writer);
278
+ }
279
+ return $this->_log;
280
+ }
281
+
282
+
283
+
284
+ /**
285
+ * Retrieve email composer
286
+ *
287
+ * @return Mzax_Emarketing_Model_Medium_Email_Composer
288
+ */
289
+ public function getEmailComposer()
290
+ {
291
+ return Mage::getSingleton('mzax_emarketing/medium_email_composer');
292
+ }
293
+
294
+
295
+
296
+
297
+ /**
298
+ * Render this email
299
+ * An email can be rerendered as lon as it has not been sent
300
+ *
301
+ * @return Mzax_Emarketing_Model_Outbox_Email
302
+ */
303
+ public function render()
304
+ {
305
+ if($this->getStatus() == self::STATUS_NOT_SEND) {
306
+
307
+ $composer = $this->getEmailComposer();
308
+ $composer->setRecipient($this->getRecipient());
309
+ $composer->compose();
310
+
311
+ $this->setSubject( $composer->getSubject() );
312
+ $this->setBodyHtml( $composer->getBodyHtml() );
313
+ $this->setBodyText( $composer->getBodyText() );
314
+ $this->setRenderTime( $composer->getRenderTime() );
315
+
316
+ $this->_linkReferences = $composer->getLinkReferences();
317
+ }
318
+ return $this;
319
+ }
320
+
321
+
322
+
323
+
324
+ /**
325
+ * Retreive message id or generate new one if
326
+ * we don't have one yet
327
+ *
328
+ * @return string
329
+ */
330
+ public function getMessageId()
331
+ {
332
+ $id = $this->getData('message_id');
333
+ if(!$id) {
334
+ $sender = $this->getCampaign()->getSender();
335
+ $serverName = strstr($sender['email'], '@');
336
+
337
+ if(!$serverName) {
338
+ $baseUrl = $this->getCampaign()->getStore()->getBaseUrl();
339
+ if(preg_match('/([a-z0-9][a-z0-9-]{1,61}[a-z0-9]\.[a-z]{2,})/i', $baseUrl, $match)) {
340
+ $serverName = '@' . $match[1];
341
+ }
342
+ else {
343
+ $serverName = '@' . Mage::app()->getRequest()->getServer('SERVER_NAME');
344
+ }
345
+ }
346
+
347
+ $id = time() . '.' . $this->getRecipient()->getBeaconHash() . $serverName;
348
+ $this->setData('message_id', $id);
349
+ }
350
+ return $id;
351
+ }
352
+
353
+
354
+
355
+
356
+ /**
357
+ * Create zend mail object for sending out
358
+ * the email
359
+ *
360
+ * @return Zend_Mail
361
+ */
362
+ public function createMailObject()
363
+ {
364
+ $sender = $this->getCampaign()->getSender();
365
+
366
+ $recipient = $this->getRecipient();
367
+ $recipient->prepare();
368
+
369
+ $mail = new Zend_Mail('utf-8');
370
+ $mail->setSubject($this->getSubject());
371
+ $mail->addTo($recipient->getAddress(), '=?utf-8?B?'.base64_encode($recipient->getName()).'?=');
372
+ $mail->setMessageId($this->getMessageId());
373
+ $mail->setBodyText($this->getBodyText());
374
+ $mail->setBodyHtml($this->getBodyHtml());
375
+ $mail->setFrom($sender['email'], $sender['name']);
376
+ $mail->addHeader('X-Mailer', 'Mzax-Emarketing '.Mage::helper('mzax_emarketing')->getVersion());
377
+ $mail->addHeader('X-Mailer-Version', Mage::helper('mzax_emarketing')->getVersion());
378
+ $mail->addHeader('X-Originating-IP', Mage::app()->getRequest()->getServer('SERVER_ADDR'));
379
+
380
+ // Add List-Unsubscribe
381
+ if(Mage::getStoreConfigFlag('mzax_emarketing/email/list_unsubscribe', $recipient->getStoreId())) {
382
+ $unsubscribe = array();
383
+
384
+ $address = Mage::getStoreConfig('mzax_emarketing/email/list_unsubscribe_address', $recipient->getStoreId());
385
+ if($address) {
386
+ $unsubscribe[] = "mailto:{$address}?subject=Unsubscribe%20{$recipient->getAddress()}%20({$recipient->getBeaconHash()})";
387
+ }
388
+ foreach($unsubscribe as &$value) {
389
+ $value = "<{$value}>";
390
+ }
391
+
392
+ $unsubscribe[] = $recipient->getUrl('mzax_emarketing/unsubscribe/list', array('id' => $recipient->getBeaconHash()));
393
+
394
+ $mail->addHeader('List-Unsubscribe', implode(',', $unsubscribe));
395
+ }
396
+
397
+
398
+ $this->setCancelEmail(false);
399
+ Mage::dispatchEvent('mzax_emarketing_create_mail_object', array(
400
+ 'mail' => $mail,
401
+ 'recipient' => $recipient,
402
+ 'outbox_email' => $this
403
+ ));
404
+
405
+ if($this->getCancelEmail()) {
406
+ return null;
407
+ }
408
+
409
+
410
+ if(Mage::getStoreConfigFlag('mzax_emarketing/email/test_mode', $recipient->getStoreId())) {
411
+ $address = Mage::getStoreConfig('mzax_emarketing/email/test_mode_address', $recipient->getStoreId());
412
+ if(!$address) {
413
+ return null;
414
+ }
415
+ $mail->clearRecipients();
416
+ $mail->addTo($address);
417
+ }
418
+
419
+
420
+ return $mail;
421
+ }
422
+
423
+
424
+
425
+
426
+ /**
427
+ * Set recipients email address
428
+ *
429
+ * @param string $email
430
+ * @return Mzax_Emarketing_Model_Outbox_Email
431
+ */
432
+ public function setTo($email)
433
+ {
434
+ $this->setData('to', $email);
435
+ if(preg_match(self::REGEX_EMAIL, $email, $match)) {
436
+ $this->setData('domain', $match[1]);
437
+ }
438
+ return $this;
439
+ }
440
+
441
+
442
+
443
+
444
+ /**
445
+ * If a time filter is set, then the outbox will only send
446
+ * this email if the current time (hour of the day [0-23]) matches
447
+ * this filter
448
+ *
449
+ * Note: Setting a time filter can cause a significant delay
450
+ * for the email beore it gets send or it prevents the email from
451
+ * sending at all if the expire date has reached
452
+ *
453
+ * @param array $times
454
+ * @return Mzax_Emarketing_Model_Outbox_Email
455
+ */
456
+ public function setTimeFilter($times)
457
+ {
458
+ if(is_array($times)) {
459
+ $times = implode(',', $times);
460
+ }
461
+ return $this->setData('time_filter', $times);
462
+ }
463
+
464
+
465
+ /**
466
+ * If a day filter is set, then the outbox will only send
467
+ * this email if the current day (day of the week [0-6]) matches
468
+ * this filter
469
+ *
470
+ * Note: Setting a day filter can cause a significant delay
471
+ * for the email beore it gets send or it prevents the email from
472
+ * sending at all if the expire date has reached
473
+ *
474
+ * @param array $days
475
+ * @return Mzax_Emarketing_Model_Outbox_Email
476
+ */
477
+ public function setDayFilter($days)
478
+ {
479
+ if(is_array($days)) {
480
+ $days = implode(',', $days);
481
+ }
482
+ return $this->setData('day_filter', $days);
483
+ }
484
+
485
+
486
+
487
+
488
+ /**
489
+ * Check if email is expired and should not
490
+ * get send out anymore
491
+ *
492
+ * @param integer $now
493
+ * @return boolean
494
+ */
495
+ public function isExpired($now = null)
496
+ {
497
+ if(!$now) {
498
+ $now = time();
499
+ }
500
+ if($this->getExpireAt()) {
501
+ $expireAt = Varien_Date::toTimestamp($this->getExpireAt());
502
+ return $expireAt < $now;
503
+ }
504
+ return false;
505
+ }
506
+
507
+
508
+
509
+
510
+ /**
511
+ * Can email be send right now
512
+ * Check any filters (e.g. Time and Day) and make
513
+ * sure none of them prevent the email from sending
514
+ *
515
+ * @param integer $now
516
+ * @return boolean
517
+ */
518
+ public function canSend($now)
519
+ {
520
+ if(!$now) {
521
+ $now = time();
522
+ }
523
+
524
+ if($filter = $this->getDayFilter()) {
525
+ $dayOfWeek = date('w', $now);
526
+ $filter = explode(',', $filter);
527
+
528
+ if(!in_array($dayOfWeek, $filter)) {
529
+ return false;
530
+ }
531
+ }
532
+ if($filter = $this->getTimeFilter()) {
533
+ $hourOfDay = date('G', $now);
534
+ $filter = explode(',', $filter);
535
+
536
+ if(!in_array($hourOfDay, $filter)) {
537
+ return false;
538
+ }
539
+ }
540
+ return !$this->isExpired($now);
541
+ }
542
+
543
+
544
+
545
+ /**
546
+ * Prepare mail transporter
547
+ *
548
+ * @return Mzax_Emarketing_Model_Outbox_Transporter_Interface
549
+ */
550
+ protected function _prepareTransporter()
551
+ {
552
+ $store = $this->getCampaign()->getStore();
553
+
554
+ $transporter = Mage::getStoreConfig('mzax_emarketing/email/transporter', $store);
555
+ $transporter = Mage::getSingleton('mzax_emarketing/outbox_transporter')->factory($transporter);
556
+ $transporter->setup($this);
557
+
558
+
559
+ $wrapper = new Varien_Object();
560
+ $wrapper->setTransporter($transporter);
561
+ Mage::dispatchEvent('mzax_emarketing_email_prepare_transport', array(
562
+ 'data' => $wrapper,
563
+ 'email' => $this
564
+ ));
565
+
566
+ return $wrapper->getTransporter();
567
+ }
568
+
569
+
570
+
571
+
572
+ public function send()
573
+ {
574
+ try {
575
+ Mage::log("Send Message: #{$this->getId()} - {$this->getEmail()}");
576
+ $this->_send();
577
+ $this->setStatus(self::STATUS_SENT);
578
+ $this->setSentAt(now());
579
+ $this->getRecipient()->isSent(true);
580
+ }
581
+ catch(Exception $e) {
582
+ Mage::logException($e);
583
+
584
+ $message = $e->getMessage() . "\nStackTrace:\n";
585
+ $message.= $e->getTraceAsString();
586
+
587
+ $this->getLog()->err($message);
588
+ $this->setStatus(self::STATUS_FAILED);
589
+
590
+ if(Mage::getIsDeveloperMode()) {
591
+ throw $e;
592
+ }
593
+ }
594
+
595
+ $this->save();
596
+ $this->getRecipient()->save();
597
+ return $this;
598
+ }
599
+
600
+
601
+
602
+
603
+ protected function _send()
604
+ {
605
+ $mail = $this->createMailObject();
606
+ if($mail) {
607
+ $mail->send($this->_prepareTransporter());
608
+ }
609
+ }
610
+
611
+
612
+
613
+
614
+
615
+ }
app/code/community/Mzax/Emarketing/Model/Outbox/Transporter.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Outbox_Transporter
25
+ {
26
+
27
+ protected $_config;
28
+
29
+
30
+
31
+ /**
32
+ *
33
+ * @param string $name
34
+ * @throws Exception
35
+ * @return Mzax_Emarketing_Model_Outbox_Email_Transporter_Interface
36
+ */
37
+ public function factory($name)
38
+ {
39
+ $config = $this->getConfig();
40
+ if(!isset($config->$name)) {
41
+ throw new Exception("No such email transporter found ({$name})");
42
+ }
43
+ $config = $config->$name;
44
+
45
+
46
+ $transporterClass = $config->getClassName();
47
+
48
+ if(!class_exists($transporterClass)) {
49
+ throw new Exception("Email transporter config found, but model ($transporterClass) was not found");
50
+ }
51
+
52
+ /* @var $transporter Mzax_Emarketing_Model_Outbox_Transporter_Interface */
53
+ $transporter = new $transporterClass;
54
+
55
+ if(!$transporter instanceof Mzax_Emarketing_Model_Outbox_Transporter_Interface) {
56
+ throw new Exception("Email transporter '{$name}' must implement 'Mzax_Emarketing_Model_Outbox_Email_Transporter_Interface'");
57
+ }
58
+
59
+ return $transporter;
60
+ }
61
+
62
+
63
+
64
+ public function toOptionArray($withEmpty = false)
65
+ {
66
+ return $this->getAllOptions($withEmpty);
67
+ }
68
+
69
+
70
+
71
+ /**
72
+ * Retrieve All options
73
+ *
74
+ * @return array
75
+ */
76
+ public function getAllOptions($withEmpty = true, $defaultValues = false)
77
+ {
78
+ $options = array();
79
+
80
+ foreach($this->getConfig()->children() as $name => $cfg) {
81
+ $options[] = array(
82
+ 'label' => (string) $cfg->title,
83
+ 'value' => $name
84
+ );
85
+ }
86
+ if ($withEmpty) {
87
+ array_unshift($options, array('label'=>'', 'value'=>''));
88
+ }
89
+
90
+ return $options;
91
+ }
92
+
93
+
94
+
95
+
96
+
97
+
98
+ /**
99
+ * Retrieve config
100
+ *
101
+ * @return Mage_Core_Model_Config_Element
102
+ */
103
+ public function getConfig()
104
+ {
105
+ if(!$this->_config) {
106
+ $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/mediums/email/transporters');
107
+ }
108
+ return $this->_config;
109
+ }
110
+
111
+
112
+ }
app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/File.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Simple transporter for testing
26
+ *
27
+ * emails will be saved to ./var/mzax_emails/...
28
+ *
29
+ *
30
+ * @author Jacob Siefer
31
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
+ * @version 0.2.5
33
+ */
34
+ class Mzax_Emarketing_Model_Outbox_Transporter_File
35
+ extends Mzax_Mail_Transport_File
36
+ implements Mzax_Emarketing_Model_Outbox_Transporter_Interface
37
+ {
38
+
39
+
40
+ public function setup(Mzax_Emarketing_Model_Outbox_Email $email)
41
+ {
42
+ $path[] = Mage::getBaseDir('var');
43
+ $path[] = 'mzax_emails' ;
44
+ $path[] = 'campaign_' . $email->getCampaignId();
45
+ $path[] = 'mail.txt';
46
+
47
+ $this->setFile(implode(DS, $path));
48
+ $this->setSaveHtml(true);
49
+ }
50
+
51
+
52
+ }
app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/Interface.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ interface Mzax_Emarketing_Model_Outbox_Transporter_Interface
25
+ {
26
+
27
+ public function send(Zend_Mail $mail);
28
+
29
+ public function setup(Mzax_Emarketing_Model_Outbox_Email $email);
30
+
31
+ }
app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/Sendmail.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * PHP Sendmail transporter
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Outbox_Transporter_Sendmail
34
+ extends Zend_Mail_Transport_Smtp
35
+ implements Mzax_Emarketing_Model_Outbox_Transporter_Interface
36
+ {
37
+
38
+
39
+
40
+ public function setup(Mzax_Emarketing_Model_Outbox_Email $email)
41
+ {
42
+ $store = $email->getCampaign()->getStore();
43
+ $sender = $email->getCampaign()->getSender();
44
+
45
+ ini_set('SMTP', Mage::getStoreConfig('system/smtp/host', $store));
46
+ ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port', $store));
47
+
48
+
49
+ switch (Mage::getStoreConfig(Mage_Core_Model_Email_Template::XML_PATH_SENDING_SET_RETURN_PATH, $store)) {
50
+ case 1:
51
+ $this->parameters = "-f" . $sender['email'];
52
+ break;
53
+ case 2:
54
+ $this->parameters = "-f" . Mage::getStoreConfig(Mage_Core_Model_Email_Template::XML_PATH_SENDING_RETURN_PATH_EMAIL, $store);
55
+ break;
56
+ }
57
+ }
58
+
59
+
60
+ }
app/code/community/Mzax/Emarketing/Model/Outbox/Transporter/Smtp.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * PHP Sendmail transporter
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Outbox_Transporter_Smtp
34
+ extends Zend_Mail_Transport_Smtp
35
+ implements Mzax_Emarketing_Model_Outbox_Transporter_Interface
36
+ {
37
+
38
+
39
+
40
+ public function setup(Mzax_Emarketing_Model_Outbox_Email $email)
41
+ {
42
+ $store = $email->getCampaign()->getStore();
43
+
44
+ $hostname = Mage::getStoreConfig('mzax_emarketing/email/smtp_hostname', $store);
45
+ $username = Mage::getStoreConfig('mzax_emarketing/email/smtp_username', $store);
46
+ $password = Mage::getStoreConfig('mzax_emarketing/email/smtp_password', $store);
47
+ $auth = Mage::getStoreConfig('mzax_emarketing/email/smtp_auth', $store);
48
+ $ssl = Mage::getStoreConfig('mzax_emarketing/email/smtp_ssl', $store);
49
+ $port = Mage::getStoreConfig('mzax_emarketing/email/smtp_port', $store);
50
+
51
+ $this->_auth = $auth;
52
+ $this->_host = $hostname;
53
+ $this->_port = $port;
54
+
55
+ $this->_config = array(
56
+ 'username' => $username,
57
+ 'password' => $password,
58
+ 'port' => $port,
59
+ 'ssl' => $ssl ? 'tls' : false,
60
+ );
61
+
62
+
63
+ }
64
+
65
+
66
+ }
app/code/community/Mzax/Emarketing/Model/Premailer.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ *
27
+ *
28
+ * @see http://premailer.dialect.ca/api
29
+ * @author Jacob Siefer
30
+ *
31
+ */
32
+ class Mzax_Emarketing_Model_Premailer
33
+ {
34
+
35
+ const ADAPTER_HPRICOT = 'hpricot';
36
+ const ADAPTER_NOKOGIRI = 'nokogiri';
37
+
38
+ const API_URI = 'http://premailer.dialect.ca/api/0.1/documents';
39
+
40
+ const CACHE_KEY = 'emarketing_premailer';
41
+
42
+
43
+ protected $_clientConfig = array(
44
+ 'maxredirects' => 0,
45
+ 'timeout' => 30,
46
+ 'useragent' => 'Magento - Emarketing Mailer v1'
47
+ );
48
+
49
+
50
+
51
+ public $html;
52
+
53
+
54
+ public $cacheId;
55
+
56
+
57
+ public $adapter = self::ADAPTER_HPRICOT;
58
+
59
+
60
+ public $baseUrl = '';
61
+
62
+
63
+ public $lineLength = 65;
64
+
65
+
66
+ public $linkQueryString = '';
67
+
68
+
69
+ public $preserveStyles = true;
70
+
71
+
72
+ public $removeIds = false;
73
+
74
+
75
+ public $removeClasses = false;
76
+
77
+
78
+ public $removeComments = false;
79
+
80
+
81
+ public function __construct()
82
+ {
83
+
84
+ }
85
+
86
+
87
+ protected function getParams()
88
+ {
89
+ $params = array(
90
+ 'adapter' => $this->adapter,
91
+ 'base_url' => $this->baseUrl,
92
+ 'html' => $this->html,
93
+ 'line_length' => $this->lineLength,
94
+ 'link_query_string' => $this->linkQueryString,
95
+ 'preserve_styles' => $this->preserveStyles,
96
+ 'remove_ids' => $this->removeIds,
97
+ 'remove_classes' => $this->removeClasses,
98
+ 'remove_comments' => $this->removeComments
99
+ );
100
+ return $params;
101
+ }
102
+
103
+
104
+
105
+ protected function _getCacheKey()
106
+ {
107
+ if(!$this->cacheId) {
108
+ return false;
109
+ }
110
+ $params = $this->getParams();
111
+ unset($params['html']);
112
+ return self::CACHE_KEY . '_' . md5($this->cacheId . '_' . print_r($params, true));
113
+ }
114
+
115
+
116
+ /**
117
+ *
118
+ * @throws Exception
119
+ * @return Varien_Object
120
+ */
121
+ public function process()
122
+ {
123
+ $cacheId = $this->_getCacheKey();
124
+ $response = $cacheId ? Mage::app()->loadCache($cacheId) : false;
125
+ if($response) {
126
+ $response = unserialize($response);
127
+ }
128
+ if(!$response instanceof Varien_Object) {
129
+ $client = new Zend_Http_Client(self::API_URI, $this->_clientConfig);
130
+ $client->setMethod(Zend_Http_Client::POST);
131
+ $client->setParameterPost($this->getParams());
132
+ $result = $client->request();
133
+
134
+ $data = Zend_Json::decode($result->getBody());
135
+
136
+
137
+ if($data['status'] != 201) {
138
+ throw new Exception("Premailer failed to run: {$data['message']} #{$data['status']}");
139
+ }
140
+
141
+ $htmlClient = new Zend_Http_Client($data['documents']['html'], $this->_clientConfig);
142
+ $textClient = new Zend_Http_Client($data['documents']['txt'], $this->_clientConfig);
143
+
144
+
145
+ $response = new Varien_Object();
146
+ $response->setVersion($data['version']);
147
+ $response->setHtml($htmlClient->request()->getBody());
148
+ $response->setText($textClient->request()->getBody());
149
+
150
+ if($cacheId) {
151
+ $data = Mage::app()->saveCache(serialize($response), $cacheId, array(self::CACHE_KEY), 60*60);
152
+ }
153
+ }
154
+
155
+ return $response;
156
+ }
157
+
158
+
159
+
160
+
161
+
162
+
163
+ }
app/code/community/Mzax/Emarketing/Model/Recipient.php ADDED
@@ -0,0 +1,610 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+
26
+
27
+ /**
28
+ * Recipient
29
+ *
30
+ *
31
+ * @method Mzax_Emarketing_Model_Recipient setCreatedAt(string $value)
32
+ * @method Mzax_Emarketing_Model_Recipient setSentAt(string $value)
33
+ * @method Mzax_Emarketing_Model_Recipient setViewedAt(string $value)
34
+ * @method Mzax_Emarketing_Model_Recipient setObjectId(string $value)
35
+ * @method Mzax_Emarketing_Model_Recipient setCampaignId(string $value)
36
+ * @method Mzax_Emarketing_Model_Recipient setVariationId(string $value)
37
+ * @method Mzax_Emarketing_Model_Recipient setIsMock(string $value)
38
+ *
39
+ * @method Mzax_Emarketing_Model_Recipient setAddress(string $value)
40
+ * @method Mzax_Emarketing_Model_Recipient setName(string $value)
41
+ *
42
+ * @method Mzax_Emarketing_Model_Resource_Recipient getResource()
43
+ *
44
+ * @method string getCreatedAt()
45
+ * @method string getSentAt()
46
+ * @method string getViewedAt()
47
+ * @method string getObjectId()
48
+ * @method string getCampaignId()
49
+ * @method string getVariationId()
50
+ * @method string getIsMock()
51
+ *
52
+ * @method string getAddress()
53
+ * @method string getName()
54
+ *
55
+ * @author Jacob Siefer
56
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
57
+ * @version 0.2.5
58
+ */
59
+ class Mzax_Emarketing_Model_Recipient extends Mage_Core_Model_Abstract
60
+ {
61
+
62
+ const EVENT_TYPE_VIEW = 1;
63
+ const EVENT_TYPE_CLICK = 2;
64
+
65
+
66
+ const BEACON_SECRET_PATH = 'mzax_emarketing/beacon_secret';
67
+
68
+
69
+
70
+ /**
71
+ * Campaign
72
+ *
73
+ * @var Mzax_Emarketing_Model_Campaign
74
+ */
75
+ protected $_campaign;
76
+
77
+
78
+
79
+ /**
80
+ * Content Provider
81
+ *
82
+ * @var Mzax_Emarketing_Model_Campaign_Content
83
+ */
84
+ protected $_content;
85
+
86
+
87
+
88
+
89
+ protected function _construct()
90
+ {
91
+ $this->_init('mzax_emarketing/recipient');
92
+ }
93
+
94
+
95
+
96
+ /**
97
+ * Little helper function to add URLs for the content
98
+ * so they are available via {{var urls.key}}
99
+ *
100
+ * @param string $key
101
+ * @param string|null $routePath
102
+ * @param array|null $routeParams
103
+ * @return Mzax_Emarketing_Model_Recipient
104
+ */
105
+ public function addUrl($key, $routePath = null, $routeParams = null)
106
+ {
107
+ $this->getUrls()->setData($key, $this->getUrl($routePath, $routeParams));
108
+ return $this;
109
+ }
110
+
111
+
112
+
113
+ /**
114
+ * Retrieve URL in scope of campaign sender store
115
+ *
116
+ * @param string|null $routePath
117
+ * @param array|null $routeParams
118
+ * @return string
119
+ */
120
+ public function getUrl($routePath = null, $routeParams = null)
121
+ {
122
+ return $this->getCampaign()->getUrlModel()->getUrl($routePath, $routeParams);
123
+ }
124
+
125
+
126
+
127
+
128
+ /**
129
+ * A temporary namespace for urls that can be later used
130
+ * in emails
131
+ *
132
+ *
133
+ * @return Varien_Object
134
+ */
135
+ public function getUrls()
136
+ {
137
+ $urls = $this->getData('url_namespace');
138
+ if(!$urls) {
139
+ $urls = new Varien_Object();
140
+ $this->setData('url_namespace', $urls);
141
+ }
142
+ return $urls;
143
+ }
144
+
145
+
146
+
147
+
148
+
149
+ /**
150
+ * Return true if recipient is a mock used
151
+ * by the preview
152
+ *
153
+ * @return boolean
154
+ */
155
+ public function isMock($flag = null)
156
+ {
157
+ if(is_bool($flag)) {
158
+ $this->setData('is_mock', $flag ? 1 : 0);
159
+ }
160
+ return (boolean) $this->getData('is_mock');
161
+ }
162
+
163
+
164
+
165
+ /**
166
+ * Retrieve recipient address
167
+ *
168
+ * Depending on the medium the address can
169
+ * be an email, telephone number or real address
170
+ *
171
+ * @return string
172
+ */
173
+ public function getAddress()
174
+ {
175
+ $address = $this->getData('address');
176
+ if($address) {
177
+ return $address;
178
+ }
179
+ if($this->getAddressId()) {
180
+ $address = Mage::getResourceSingleton('mzax_emarketing/recipient_address')->getAddress($this->getAddressId());
181
+ $this->setData('address', $address);
182
+ }
183
+ return $address;
184
+ }
185
+
186
+
187
+
188
+
189
+ /**
190
+ *
191
+ * @param string $hash
192
+ */
193
+ public function loadByBeacon($hash)
194
+ {
195
+ return $this->load($hash, 'beacon_hash');
196
+ }
197
+
198
+
199
+
200
+
201
+ /**
202
+ * Retrieve beacon hash
203
+ *
204
+ * @return string
205
+ */
206
+ public function getBeaconHash()
207
+ {
208
+ $hash = $this->getData('beacon_hash');
209
+ if(!$hash) {
210
+ $hash = md5($this->getObjectId() .
211
+ $this->getAddress() .
212
+ $this->getCampaignId() .
213
+ mt_rand(0, 99999999) .
214
+ microtime());
215
+
216
+ $hash = Mage::helper('mzax_emarketing')->compressHash($hash);
217
+ $this->setBeaconHash($hash);
218
+ }
219
+ return $hash;
220
+ }
221
+
222
+
223
+
224
+
225
+ /**
226
+ * Get campaign content
227
+ * This is either a campaign or a variation
228
+ *
229
+ * @return Mzax_Emarketing_Model_Campaign_Content
230
+ */
231
+ public function getContent()
232
+ {
233
+ if(!$this->_content) {
234
+ $this->_content = $this->getCampaign()->getContent($this->getVariationId());
235
+
236
+ if($this->getVariationId() === null) {
237
+ $this->setVariationId((int) $this->_content->getVariationId());
238
+ }
239
+ }
240
+ return $this->_content;
241
+ }
242
+
243
+
244
+
245
+
246
+ /**
247
+ * Set content
248
+ *
249
+ * @param Mzax_Emarketing_Model_Campaign_Content $content
250
+ * @return Mzax_Emarketing_Model_Recipient
251
+ */
252
+ public function setContent(Mzax_Emarketing_Model_Campaign_Content $content)
253
+ {
254
+ $this->_content = $content;
255
+ if($content) {
256
+ $this->setVariationId((int) $content->getVariationId());
257
+ }
258
+ return $this;
259
+ }
260
+
261
+
262
+
263
+
264
+ /**
265
+ * Retrieve variation
266
+ *
267
+ * @deprecated
268
+ * @return Mzax_Emarketing_Model_Campaign_Variation
269
+ */
270
+ public function getVariation()
271
+ {
272
+ $id = $this->getVariationId();
273
+ if($id === null) {
274
+ return null;
275
+ }
276
+
277
+ if($id) {
278
+ $variation = $this->getCampaign()->getVariation($id);
279
+ }
280
+ else if($id == 0) {
281
+ $variation = $this->getCampaign()->createVaration();
282
+ $variation->setName('Original');
283
+ }
284
+ else {
285
+ $variation = $this->getCampaign()->createVaration();
286
+ $variation->setName('No Testing');
287
+ }
288
+
289
+ return $variation;
290
+ }
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+ protected function _beforeSave()
299
+ {
300
+ // generate hash
301
+ $this->getBeaconHash();
302
+
303
+ parent::_beforeSave();
304
+ if($this->_campaign) {
305
+ $this->setCampaignId($this->_campaign->getId());
306
+ }
307
+ }
308
+
309
+
310
+ public function save()
311
+ {
312
+ try {
313
+ parent::save();
314
+ }
315
+ catch(Exception $e) {
316
+ $this->unsetData('beacon_hash');
317
+ $this->save();
318
+ }
319
+ }
320
+
321
+
322
+
323
+ /**
324
+ *
325
+ * @deprecated
326
+ * @return Mzax_Emarketing_Model_Recipient
327
+ */
328
+ public function reload()
329
+ {
330
+ $this->load($this->getId());
331
+ return $this;
332
+ }
333
+
334
+
335
+
336
+
337
+ /**
338
+ * Retrieve campaign
339
+ *
340
+ * @return Mzax_Emarketing_Model_Campaign
341
+ */
342
+ public function getCampaign()
343
+ {
344
+ if(!$this->_campaign) {
345
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign');
346
+ $this->_campaign->load($this->getCampaignId());
347
+ }
348
+ return $this->_campaign;
349
+ }
350
+
351
+
352
+
353
+ /**
354
+ * Set campaign
355
+ *
356
+ * @param Mzax_Emarketing_Model_Campaign $campaign
357
+ * @return Mzax_Emarketing_Model_Recipient
358
+ */
359
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
360
+ {
361
+ $this->_campaign = $campaign;
362
+ $this->setCampaignId($campaign->getId());
363
+ return $this;
364
+ }
365
+
366
+
367
+
368
+ /**
369
+ * Retrieve store id from campaign
370
+ *
371
+ * @return string
372
+ */
373
+ public function getStoreId()
374
+ {
375
+ return $this->getCampaign()->getStoreId();
376
+ }
377
+
378
+
379
+ /**
380
+ * Retrieve store from campaign
381
+ *
382
+ * @return Mage_Core_Model_Store
383
+ */
384
+ public function getStore()
385
+ {
386
+ return $this->getCampaign()->getStore();
387
+ }
388
+
389
+
390
+
391
+ /**
392
+ * Prepare recipient
393
+ *
394
+ * @return Mzax_Emarketing_Model_Recipient
395
+ */
396
+ public function prepare()
397
+ {
398
+ if(!$this->getIsPrepared())
399
+ {
400
+ $this->setIsPrepared(true);
401
+ $this->getCampaign()->prepareRecipient($this);
402
+ Mage::dispatchEvent($this->_eventPrefix.'_prepare', $this->_getEventData());
403
+ }
404
+ return $this;
405
+ }
406
+
407
+
408
+
409
+
410
+
411
+
412
+ /**
413
+ * Is sent out
414
+ *
415
+ * @param boolean $flag
416
+ * @return boolean
417
+ */
418
+ public function isSent($flag = null)
419
+ {
420
+ if(is_bool($flag)) {
421
+ $this->setSentAt($flag ? now() : null);
422
+ }
423
+ return $this->getSentAt() !== null;
424
+ }
425
+
426
+
427
+
428
+ /**
429
+ * Is prepared
430
+ *
431
+ * @param boolean $flag
432
+ * @return boolean
433
+ */
434
+ public function isPrepared($flag = null)
435
+ {
436
+ if(is_bool($flag)) {
437
+ $this->setPreparedAt($flag ? now() : null);
438
+ }
439
+ return $this->getPreparedAt() !== null;
440
+ }
441
+
442
+
443
+
444
+ /**
445
+ * The expire at time stamp for this recipient
446
+ *
447
+ * @return string|NULL
448
+ */
449
+ public function getExpireAt()
450
+ {
451
+ $expireTime = (int) $this->getCampaign()->getExpireTime();
452
+ if($expireTime > 0) {
453
+ $expireAt = strtotime($this->getCreatedAt()) + ($expireTime*60);
454
+ return date(Varien_Date::DATETIME_PHP_FORMAT, $expireAt);
455
+ }
456
+ return null;
457
+ }
458
+
459
+
460
+
461
+
462
+ /**
463
+ * Retrieve the number of seconds since the email
464
+ * was sent
465
+ *
466
+ * @return integer|false
467
+ */
468
+ public function getAge()
469
+ {
470
+ $sentAt = $this->getSentAt();
471
+ if($sentAt) {
472
+ $sentAt = new Zend_Date($sentAt, Zend_Date::DATETIME);
473
+ return Zend_Date::now()->sub($sentAt)->toValue();
474
+ }
475
+ return false;
476
+ }
477
+
478
+
479
+
480
+ /**
481
+ * Try to loggin in customer by id
482
+ *
483
+ * The method usually gets called by the email provider
484
+ * on link click.
485
+ *
486
+ * @param string $customerId
487
+ * @return boolean
488
+ */
489
+ public function autologin($customerId)
490
+ {
491
+ $enabled = Mage::getStoreConfigFlag('mzax_emarketing/autologin/enable', $this->getStoreId());
492
+ $expire = (float) Mage::getStoreConfig('mzax_emarketing/autologin/expire', $this->getStoreId());
493
+
494
+
495
+ if($enabled && $customerId && $this->getCampaign()->getAutologin()) {
496
+ $age = $this->getAge();
497
+
498
+ if($expire <= 0 || ($age && $age < 60*60 * $expire)) {
499
+ /* @var $session Mage_Customer_Model_Session */
500
+ $session = Mage::getSingleton('customer/session');
501
+ if(!$session->isLoggedIn()) {
502
+ return $session->loginById($customerId);
503
+ }
504
+ }
505
+ }
506
+ return false;
507
+ }
508
+
509
+
510
+
511
+
512
+ /**
513
+ * log exception
514
+ *
515
+ * @param Exception $exception
516
+ * @return Mzax_Emarketing_Model_Recipient_Error
517
+ */
518
+ public function logException(Exception $exception)
519
+ {
520
+ /* @var $error Mzax_Emarketing_Model_Recipient_Error */
521
+ $error = Mage::getModel('mzax_emarketing/recipient_error');
522
+ $error->setRecipient($this)
523
+ ->setException($exception)
524
+ ->save();
525
+
526
+ return $error;
527
+ }
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+ /**
536
+ * Capture view event
537
+ *
538
+ * @param Zend_Controller_Request_Http $request
539
+ * @return Mzax_Emarketing_Model_Recipient
540
+ */
541
+ public function captureView(Zend_Controller_Request_Http $request = null)
542
+ {
543
+ return $this->_capture(self::EVENT_TYPE_VIEW, $request);
544
+ }
545
+
546
+
547
+
548
+
549
+ /**
550
+ * Capture click event
551
+ *
552
+ * @param Zend_Controller_Request_Http $request
553
+ * @return Mzax_Emarketing_Model_Recipient
554
+ */
555
+ public function captureClick(Zend_Controller_Request_Http $request = null)
556
+ {
557
+ return $this->_capture(self::EVENT_TYPE_CLICK, $request);
558
+ }
559
+
560
+
561
+
562
+ /**
563
+ * Capture new recipient event and
564
+ * return event id
565
+ *
566
+ * @param int $type
567
+ * @param Zend_Controller_Request_Http $request
568
+ * @return integer EventID
569
+ */
570
+ protected function _capture($type, Zend_Controller_Request_Http $request = null)
571
+ {
572
+ if(!$this->getId()) {
573
+ return false;
574
+ }
575
+ try {
576
+ if(!$request) {
577
+ $request = Mage::app()->getRequest();
578
+ }
579
+
580
+ /* @var $session Mzax_Emarketing_Model_Session */
581
+ $session = Mage::getSingleton('mzax_emarketing/session');
582
+
583
+ $eventId = $this->getResource()->insertEvent(array(
584
+ 'event_type' => $type,
585
+ 'recipient_id' => $this->getId(),
586
+ 'ip' => $request->getServer('REMOTE_ADDR'),
587
+ 'useragent' => $request->getServer('HTTP_USER_AGENT'),
588
+ 'time_offset' => $session->getTimeOffset()
589
+ ));
590
+
591
+
592
+ if($session->getTimeOffset() === null) {
593
+ // try to get the timeoffset using javascript if possible
594
+ $session->fetchTimeOffset($this->getId());
595
+ }
596
+ return $eventId;
597
+ }
598
+ catch(Exception $e) {
599
+ if(Mage::getIsDeveloperMode()) {
600
+ throw $e;
601
+ }
602
+ Mage::logException($e);
603
+ }
604
+
605
+ return false;
606
+ }
607
+
608
+
609
+
610
+ }
app/code/community/Mzax/Emarketing/Model/Recipient/Error.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ *
25
+ *
26
+ *
27
+ * @author Jacob Siefer
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @version 0.2.5
30
+ */
31
+ class Mzax_Emarketing_Model_Recipient_Error extends Mage_Core_Model_Abstract
32
+ {
33
+
34
+
35
+ protected function _construct()
36
+ {
37
+ $this->_init('mzax_emarketing/recipient_error');
38
+ }
39
+
40
+
41
+
42
+
43
+ public function setException(Exception $error)
44
+ {
45
+ $this->setMessage("{$error->getMessage()}\n\n{$error->getTraceAsString()}");
46
+ return $this;
47
+ }
48
+
49
+
50
+ /**
51
+ * set recipient id
52
+ *
53
+ * @param string|integer recipientId
54
+ * @return Mzax_Emarketing_Model_Recipient_Error
55
+ */
56
+ public function setRecipientId($recipientId)
57
+ {
58
+ if(($recipient = $this->getData('recipient')) &&
59
+ ($recipient->getId() != $recipientId)) {
60
+ $this->getData('recipient', null);
61
+ }
62
+ $this->setData('recipient_id', $recipientId);
63
+ return $this;
64
+ }
65
+
66
+
67
+
68
+
69
+ /**
70
+ * set recipient
71
+ *
72
+ * @param Varien_Object $recipient
73
+ * @return Mzax_Emarketing_Model_Recipient_Error
74
+ */
75
+ public function setRecipient(Varien_Object $recipient)
76
+ {
77
+ $this->setRecipientId($recipient->getId());
78
+ $this->setData('recipient', $recipient);
79
+
80
+ return $this;
81
+ }
82
+
83
+
84
+
85
+ /**
86
+ * (non-PHPdoc)
87
+ * @see magento/app/code/core/Mage/Core/Model/Mage_Core_Model_Abstract#_beforeSave()
88
+ */
89
+ public function _beforeSave()
90
+ {
91
+ if($this->getRecipient()) {
92
+ $this->setRecipientId($this->getRecipient()->getId());
93
+ $this->setCampaignId($this->getRecipient()->getCampaignId());
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Retrieve recipient
99
+ *
100
+ * @return Mzax_Emarketing_Model_Recipient
101
+ */
102
+ public function getRecipient()
103
+ {
104
+ if(!$recipient = $this->getData('recipient')) {
105
+ $recipient = Mage::getModel('mzax_emarketing/recipient')->load($this->getRecipientId());
106
+ $this->setData('recipient', $recipient);
107
+ }
108
+ return $recipient;
109
+ }
110
+
111
+
112
+
113
+ }
app/code/community/Mzax/Emarketing/Model/Recipient/Provider.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Factory class for recipient providers
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Recipient_Provider implements Mage_Eav_Model_Entity_Attribute_Source_Interface
34
+ {
35
+
36
+ /**
37
+ *
38
+ * @var Mage_Core_Model_Config_Element
39
+ */
40
+ protected $_config;
41
+
42
+
43
+
44
+ /**
45
+ *
46
+ * @var array
47
+ */
48
+ protected $_providers;
49
+
50
+
51
+
52
+ /**
53
+ * Retrieve Provider
54
+ *
55
+ * @param string $name
56
+ * @throws Exception
57
+ * @return Mzax_Emarketing_Model_Recipient_Provider_Abstract
58
+ */
59
+ public function factory($name)
60
+ {
61
+
62
+ $config = $this->getConfig();
63
+ if(!isset($config->$name)) {
64
+ throw new Exception("No such email provider ({$name}) found");
65
+ }
66
+ $config = $config->$name;
67
+
68
+
69
+ $providerClass = $config->getClassName();
70
+
71
+ if(!class_exists($providerClass)) {
72
+ throw new Exception("Email provider config found, but model ($providerClass) was not found");
73
+ }
74
+
75
+ /* @var $provider Mzax_Emarketing_Model_Recipient_Provider_Abstract */
76
+ $provider = new $providerClass;
77
+ $provider->setName($name);
78
+ $provider->setType($name);
79
+
80
+ return $provider;
81
+ }
82
+
83
+
84
+
85
+ /**
86
+ * Retrieve All options
87
+ *
88
+ * @return array
89
+ */
90
+ public function getAllOptions($withEmpty = true, $defaultValues = false)
91
+ {
92
+ $options = array();
93
+
94
+ /* @var $provider Mzax_Emarketing_Model_Recipient_Provider_Abstract */
95
+ foreach($this->getProviders() as $name => $provider) {
96
+ $options[] = array(
97
+ 'value' => $name,
98
+ 'label' => $provider->getTitle()
99
+ );
100
+ }
101
+ if ($withEmpty) {
102
+ array_unshift($options, array('label'=>'', 'value'=>''));
103
+ }
104
+
105
+ return $options;
106
+ }
107
+
108
+
109
+ public function getOptionHash()
110
+ {
111
+ $options = array();
112
+
113
+ /* @var $provider Mzax_Emarketing_Model_Recipient_Provider_Abstract */
114
+ foreach($this->getProviders() as $name => $provider) {
115
+ $options[$name] = $provider->getTitle();
116
+ }
117
+
118
+ return $options;
119
+ }
120
+
121
+
122
+
123
+ /**
124
+ * Retrieve all providers
125
+ *
126
+ * Only use those providers to retrieve genaral information,
127
+ * they are meant to treat as singletons.
128
+ * Create an instance using the facory() method if you would like to use one.
129
+ *
130
+ * @return array
131
+ */
132
+ public function getProviders()
133
+ {
134
+ if(!$this->_providers) {
135
+ $this->_providers = array();
136
+
137
+ foreach($this->getConfig()->children() as $name => $cfg) {
138
+ $this->_providers[$name] = $this->factory($name);
139
+ }
140
+ }
141
+ return $this->_providers;
142
+ }
143
+
144
+
145
+
146
+
147
+
148
+
149
+ /**
150
+ * Retrieve Option value text
151
+ *
152
+ * @param string $value
153
+ * @return mixed
154
+ */
155
+ public function getOptionText($value)
156
+ {
157
+ $options = $this->getProviders();
158
+ if(isset($options[$value])) {
159
+ return $options[$value]->getTitle();
160
+ }
161
+ return false;
162
+ }
163
+
164
+
165
+
166
+
167
+ /**
168
+ * Retrieve email marketing collection config
169
+ *
170
+ * @return Mage_Core_Model_Config_Element
171
+ */
172
+ public function getConfig()
173
+ {
174
+ if(!$this->_config) {
175
+ $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/providers');
176
+ }
177
+ return $this->_config;
178
+ }
179
+
180
+
181
+
182
+ }
app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Abstract.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ abstract class Mzax_Emarketing_Model_Recipient_Provider_Abstract
25
+ extends Mzax_Emarketing_Model_Object_Filter_Main
26
+ {
27
+
28
+
29
+ /**
30
+ *
31
+ * @var Mzax_Emarketing_Model_Campaign
32
+ */
33
+ protected $_campaign;
34
+
35
+
36
+ public function getTitle()
37
+ {
38
+ return 'Provider Title';
39
+ }
40
+
41
+
42
+
43
+
44
+ /**
45
+ * Prepare recipient for sending
46
+ *
47
+ * @param Mzax_Emarketing_Model_Recipient $recipient
48
+ * @return void
49
+ */
50
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
51
+ {
52
+ $this->getObject()->prepareRecipient($recipient);
53
+ }
54
+
55
+
56
+
57
+ public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
58
+ {
59
+ $this->getObject()->prepareSnippets($snippets);
60
+ }
61
+
62
+
63
+
64
+
65
+ public function prepareParams()
66
+ {
67
+ if($this->_campaign) {
68
+ $this->setParam('campaign', $this->_campaign);
69
+ $this->setParam('store_id', $this->_campaign->getStoreId());
70
+
71
+ $gmtOffset = Mage::app()->getLocale()->storeDate($this->_campaign->getStoreId())->getGmtOffset()/60;
72
+ $this->setParam('gmt_offset', $gmtOffset);
73
+ }
74
+ }
75
+
76
+
77
+
78
+
79
+ /**
80
+ *
81
+ * @param Mzax_Emarketing_Model_Campaign $campaign
82
+ * @return Mzax_Emarketing_Model_Recipient_Provider_Abstract
83
+ */
84
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
85
+ {
86
+ $this->_campaign = $campaign;
87
+ $this->load($campaign->getFilterData());
88
+ return $this;
89
+ }
90
+
91
+
92
+
93
+
94
+
95
+ /**
96
+ * Retrieve campaign
97
+ *
98
+ * @return Mzax_Emarketing_Model_Campaign
99
+ */
100
+ public function getCampaign()
101
+ {
102
+ return $this->_campaign;
103
+ }
104
+
105
+
106
+
107
+
108
+
109
+
110
+ /**
111
+ * Every recipient provider gets notified when a link is clicked
112
+ *
113
+ * @param Mzax_Emarketing_Model_Link_Reference $linkReference
114
+ */
115
+ public function linkClicked(Mzax_Emarketing_Model_Link_Reference $linkReference)
116
+ {}
117
+
118
+
119
+
120
+
121
+ public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
122
+ {
123
+ }
124
+
125
+
126
+ }
app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Customer.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ class Mzax_Emarketing_Model_Recipient_Provider_Customer
25
+ extends Mzax_Emarketing_Model_Recipient_Provider_Abstract
26
+ {
27
+
28
+
29
+
30
+
31
+ public function getTitle()
32
+ {
33
+ return "Magento Customers";
34
+ }
35
+
36
+
37
+
38
+ /**
39
+ *
40
+ * @return Mzax_Emarketing_Model_Object_Customer
41
+ */
42
+ public function getObject()
43
+ {
44
+ return Mage::getSingleton('mzax_emarketing/object_customer');
45
+ }
46
+
47
+
48
+
49
+
50
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
51
+ {
52
+ $customer = Mage::getModel('customer/customer')->load($recipient->getObjectId());
53
+
54
+ $recipient->setCustomer($customer);
55
+ $recipient->setEmail($customer->getEmail());
56
+ $recipient->setName($customer->getName());
57
+ }
58
+
59
+
60
+
61
+
62
+ /**
63
+ * Every recipient provider gets notified when a link is clicked
64
+ *
65
+ * @param Mzax_Emarketing_Model_Link_Reference $linkReference
66
+ */
67
+ public function linkClicked(Mzax_Emarketing_Model_Link_Reference $linkReference)
68
+ {
69
+
70
+ $this->getSession()->setCustomerId($linkReference->getRecipient()->getObjectId());
71
+
72
+ $linkReference->getRecipient()->autologin($linkReference->getRecipient()->getObjectId());
73
+ }
74
+
75
+
76
+
77
+
78
+ /**
79
+ * Help to bind recipients to provider
80
+ *
81
+ * It is not straight forwared to link recipients to customers
82
+ * or order to customer or any other address provider dynamically.
83
+ *
84
+ * There for you can use the binding object to define binding ports available
85
+ * and then have the provider look for any possible ports it can handle
86
+ *
87
+ * @return void
88
+ */
89
+ public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
90
+ {
91
+
92
+ if($binder->hasBinding('customer_id')) {
93
+ $binder->createBinding()
94
+ ->joinTable(array('object_id' => '{customer_id}'), 'recipient')
95
+ ->addBinding('campaign_id', 'recipient.campaign_id')
96
+ ->addBinding('recipient_id', 'recipient.recipient_id')
97
+ ->addBinding('variation_id', 'recipient.variation_id')
98
+ ->addBinding('is_mock', 'recipient.is_mock')
99
+ ->addBinding('sent_at', 'recipient.sent_at');
100
+ }
101
+
102
+
103
+ if($binder->hasBinding('email')) {
104
+ $binder->createBinding()
105
+ ->joinTable(array('address' => '{email}'), 'recipient_address', 'address')
106
+ ->joinTable(array('address_id' => '`address`.`address_id`'), 'recipient')
107
+ ->addBinding('campaign_id', 'recipient.campaign_id')
108
+ ->addBinding('recipient_id', 'recipient.recipient_id')
109
+ ->addBinding('variation_id', 'recipient.variation_id')
110
+ ->addBinding('is_mock', 'recipient.is_mock')
111
+ ->addBinding('sent_at', 'recipient.sent_at');
112
+ }
113
+
114
+ }
115
+
116
+ }
app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Newsletter.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Recipient_Provider_Newsletter
33
+ extends Mzax_Emarketing_Model_Recipient_Provider_Abstract
34
+ {
35
+
36
+
37
+
38
+
39
+ public function getTitle()
40
+ {
41
+ return "Magento Newsletter";
42
+ }
43
+
44
+
45
+
46
+ /**
47
+ *
48
+ * @return Mzax_Emarketing_Model_Object_Subscriber
49
+ */
50
+ public function getObject()
51
+ {
52
+ return Mage::getSingleton('mzax_emarketing/object_subscriber');
53
+ }
54
+
55
+
56
+
57
+
58
+
59
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
60
+ {
61
+ parent::prepareRecipient($recipient);
62
+
63
+ /* @var $subscriber Mage_Newsletter_Model_Subscriber */
64
+ $subscriber = $recipient->getObject();
65
+ $recipient->setSubscriber($subscriber);
66
+ $recipient->setEmail($subscriber->getEmail());
67
+
68
+ if($subscriber->getCustomerId()) {
69
+ /* @var $customer Mage_Customer_Model_Customer */
70
+ $customer = Mage::getModel('customer/customer')->load($subscriber->getCustomerId());
71
+ $recipient->setCustomer($customer);
72
+ $recipient->setName($customer->getName());
73
+ }
74
+ }
75
+
76
+
77
+
78
+
79
+ /**
80
+ * Every recipient provider gets notified when a link is clicked
81
+ *
82
+ * @param Mzax_Emarketing_Model_Link_Reference $linkReference
83
+ */
84
+ public function linkClicked(Mzax_Emarketing_Model_Link_Reference $linkReference)
85
+ {
86
+ $recipient = $linkReference->getRecipient();
87
+
88
+ $this->getSession()->setSubscriberId($recipient->getObjectId());
89
+
90
+ /* @var $subscriber Mage_Newsletter_Model_Subscriber */
91
+ $subscriber = Mage::getModel('newsletter/subscriber')->load($recipient->getObjectId());
92
+
93
+ if($subscriber->getCustomerId()) {
94
+ $this->getSession()->setCustomerId($subscriber->getCustomerId());
95
+ $recipient->autologin($subscriber->getCustomerId());
96
+ }
97
+ }
98
+
99
+
100
+
101
+
102
+ /**
103
+ * Help to bind recipients to provider
104
+ *
105
+ * It is not straight forwared to link recipients to customers
106
+ * or order to customer or any other address provider dynamically.
107
+ *
108
+ * There for you can use the binding object to define binding ports available
109
+ * and then have the provider look for any possible ports it can handle
110
+ *
111
+ * @return void
112
+ */
113
+ public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
114
+ {
115
+
116
+ if($binder->hasBinding('customer_id')) {
117
+ $binder->createBinding()
118
+ ->joinTable(array('customer_id' => '{customer_id}'), 'newsletter/subscriber', 'subscriber')
119
+ ->joinTable(array('object_id' => '`subscriber`.`subscriber_id`'), 'recipient')
120
+ ->addBinding('campaign_id', 'recipient.campaign_id')
121
+ ->addBinding('recipient_id', 'recipient.recipient_id')
122
+ ->addBinding('variation_id', 'recipient.variation_id')
123
+ ->addBinding('is_mock', 'recipient.is_mock')
124
+ ->addBinding('sent_at', 'recipient.sent_at');
125
+ }
126
+
127
+
128
+ if($binder->hasBinding('email')) {
129
+ $binder->createBinding()
130
+ ->joinTable(array('address' => '{email}'), 'recipient_address', 'address')
131
+ ->joinTable(array('address_id' => '`address`.`address_id`'), 'recipient')
132
+ ->addBinding('campaign_id', 'recipient.campaign_id')
133
+ ->addBinding('recipient_id', 'recipient.recipient_id')
134
+ ->addBinding('variation_id', 'recipient.variation_id')
135
+ ->addBinding('is_mock', 'recipient.is_mock')
136
+ ->addBinding('sent_at', 'recipient.sent_at');
137
+ }
138
+
139
+ }
140
+
141
+ }
app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Order.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Recipient Order Provider
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Recipient_Provider_Order
33
+ extends Mzax_Emarketing_Model_Recipient_Provider_Abstract
34
+ {
35
+
36
+
37
+
38
+
39
+ public function getTitle()
40
+ {
41
+ return "Magento Orders";
42
+ }
43
+
44
+
45
+
46
+ /**
47
+ *
48
+ * @return Mzax_Emarketing_Model_Object_Order
49
+ */
50
+ public function getObject()
51
+ {
52
+ return Mage::getSingleton('mzax_emarketing/object_order');
53
+ }
54
+
55
+
56
+
57
+
58
+
59
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
60
+ {
61
+ /* @var $order Mage_Sales_Model_Order */
62
+ $order = Mage::getModel('sales/order')->load($recipient->getObjectId());
63
+
64
+ $recipient->setOrder($order);
65
+ $recipient->setCustomer($order->getCustomer());
66
+ $recipient->setEmail($order->getCustomerEmail());
67
+ $recipient->setName($order->getCustomerName());
68
+ }
69
+
70
+
71
+
72
+
73
+
74
+ /**
75
+ * Every recipient provider gets notified when a link is clicked
76
+ *
77
+ * @param Mzax_Emarketing_Model_Link_Reference $linkReference
78
+ */
79
+ public function linkClicked(Mzax_Emarketing_Model_Link_Reference $linkReference)
80
+ {
81
+ $recipient = $linkReference->getRecipient();
82
+
83
+ $this->getSession()->setOrderId($recipient->getObjectId());
84
+
85
+ /* @var $order Mage_Sales_Model_Order */
86
+ $order = Mage::getModel('sales/order')->load($recipient->getObjectId());
87
+
88
+ if($order->getCustomerId()) {
89
+ $this->getSession()->setCustomerId($order->getCustomerId());
90
+ $recipient->autologin($order->getCustomerId());
91
+ }
92
+ }
93
+
94
+
95
+
96
+
97
+
98
+
99
+ /**
100
+ * Help to bind recipients to provider
101
+ *
102
+ * It is not straight forwared to link recipients to customers
103
+ * or order to customer or any other address provider dynamically.
104
+ *
105
+ * There for you can use the binding object to define binding ports available
106
+ * and then have the provider look for any possible ports it can handle
107
+ *
108
+ * @return void
109
+ */
110
+ public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
111
+ {
112
+
113
+ if($binder->hasBinding('customer_id')) {
114
+ $binder->createBinding()
115
+ ->joinTable(array('object_id' => '{customer_id}'), 'recipient')
116
+ ->addBinding('campaign_id', 'recipient.campaign_id')
117
+ ->addBinding('recipient_id', 'recipient.recipient_id')
118
+ ->addBinding('variation_id', 'recipient.variation_id')
119
+ ->addBinding('is_mock', 'recipient.is_mock')
120
+ ->addBinding('sent_at', 'recipient.sent_at');
121
+ }
122
+
123
+
124
+ if($binder->hasBinding('email')) {
125
+ $binder->createBinding()
126
+ ->joinTable(array('address' => '{email}'), 'recipient_address', 'address')
127
+ ->joinTable(array('address_id' => '`address`.`address_id`'), 'recipient')
128
+ ->addBinding('campaign_id', 'recipient.campaign_id')
129
+ ->addBinding('recipient_id', 'recipient.recipient_id')
130
+ ->addBinding('variation_id', 'recipient.variation_id')
131
+ ->addBinding('is_mock', 'recipient.is_mock')
132
+ ->addBinding('sent_at', 'recipient.sent_at');
133
+ }
134
+
135
+ }
136
+
137
+ }
app/code/community/Mzax/Emarketing/Model/Recipient/Provider/Quote.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Recipient Quote Provider
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Recipient_Provider_Quote
33
+ extends Mzax_Emarketing_Model_Recipient_Provider_Abstract
34
+ {
35
+
36
+
37
+
38
+
39
+ public function getTitle()
40
+ {
41
+ return "Magento Shopping Carts";
42
+ }
43
+
44
+
45
+
46
+ /**
47
+ *
48
+ * @return Mzax_Emarketing_Model_Object_Quote
49
+ */
50
+ public function getObject()
51
+ {
52
+ return Mage::getSingleton('mzax_emarketing/object_quote');
53
+ }
54
+
55
+
56
+
57
+
58
+
59
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
60
+ {
61
+ /* @var $quote Mage_Sales_Model_Quote */
62
+ $quote = Mage::getModel('sales/quote')->load($recipient->getObjectId());
63
+
64
+ $recipient->setQuote($quote);
65
+ $recipient->setCustomer($quote->getCustomer());
66
+ $recipient->setEmail($quote->getCustomerEmail());
67
+ $recipient->setName($quote->getCustomerName());
68
+ }
69
+
70
+
71
+
72
+
73
+ /**
74
+ * Every recipient provider gets notified when a link is clicked
75
+ *
76
+ * @param Mzax_Emarketing_Model_Link_Reference $linkReference
77
+ */
78
+ public function linkClicked(Mzax_Emarketing_Model_Link_Reference $linkReference)
79
+ {
80
+ $recipient = $linkReference->getRecipient();
81
+
82
+ $this->getSession()->setQuoteId($recipient->getObjectId());
83
+
84
+ /* @var $quote Mage_Sales_Model_Quote */
85
+ $quote = Mage::getModel('sales/quote')->load($recipient->getObjectId());
86
+
87
+ if($quote->getCustomerId()) {
88
+ $this->getSession()->setCustomerId($quote->getCustomerId());
89
+ $recipient->autologin($quote->getCustomerId());
90
+ }
91
+ }
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ /**
100
+ * Help to bind recipients to provider
101
+ *
102
+ * It is not straight forwared to link recipients to customers
103
+ * or order to customer or any other address provider dynamically.
104
+ *
105
+ * There for you can use the binding object to define binding ports available
106
+ * and then have the provider look for any possible ports it can handle
107
+ *
108
+ * @return void
109
+ */
110
+ public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
111
+ {
112
+
113
+ if($binder->hasBinding('customer_id')) {
114
+ $binder->createBinding()
115
+ ->joinTable(array('object_id' => '{customer_id}'), 'recipient')
116
+ ->addBinding('campaign_id', 'recipient.campaign_id')
117
+ ->addBinding('recipient_id', 'recipient.recipient_id')
118
+ ->addBinding('variation_id', 'recipient.variation_id')
119
+ ->addBinding('is_mock', 'recipient.is_mock')
120
+ ->addBinding('sent_at', 'recipient.sent_at');
121
+ }
122
+
123
+
124
+ if($binder->hasBinding('email')) {
125
+ $binder->createBinding()
126
+ ->joinTable(array('address' => '{email}'), 'recipient_address', 'address')
127
+ ->joinTable(array('address_id' => '`address`.`address_id`'), 'recipient')
128
+ ->addBinding('campaign_id', 'recipient.campaign_id')
129
+ ->addBinding('recipient_id', 'recipient.recipient_id')
130
+ ->addBinding('variation_id', 'recipient.variation_id')
131
+ ->addBinding('is_mock', 'recipient.is_mock')
132
+ ->addBinding('sent_at', 'recipient.sent_at');
133
+ }
134
+
135
+ }
136
+
137
+ }
app/code/community/Mzax/Emarketing/Model/Report.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ * Simple facades for report related tasks
26
+ *
27
+ * Mage::getSingleton('mzax_emarketing/report');
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Report
34
+ {
35
+
36
+
37
+
38
+
39
+
40
+ /**
41
+ * Run all report aggregators
42
+ *
43
+ * @param array $options
44
+ * @return void
45
+ */
46
+ public function aggregate(array $options = array())
47
+ {
48
+ /* @var $aggregator Mzax_Emarketing_Model_Report_Aggregator */
49
+ $aggregator = Mage::getModel('mzax_emarketing/report_aggregator');
50
+ $aggregator->run($options);
51
+ }
52
+
53
+
54
+
55
+
56
+ /**
57
+ * Parse useragents
58
+ *
59
+ * @return void
60
+ */
61
+ public function parseUseragents($all = false)
62
+ {
63
+ /* Mzax_Emarketing_Model_Resource_Useragent */
64
+ Mage::getResourceSingleton('mzax_emarketing/useragent')->parse($all);
65
+ }
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+ /**
74
+ * Look for recipient events that have an IP but now location info
75
+ *
76
+ * @throws Exception
77
+ * @return void
78
+ */
79
+ public function fetchGeoIp()
80
+ {
81
+ if(!Mage::getStoreConfigFlag('mzax_emarketing/tracking/use_geo_ip')) {
82
+ return;
83
+ }
84
+
85
+ $lock = Mage::helper('mzax_emarketing')->lock('fetch_geop_ip');
86
+ if(!$lock) {
87
+ return;
88
+ }
89
+
90
+ // configure geo ip
91
+ $geoIp = new Mzax_GeoIp(Mage::getBaseDir('tmp') . DS . 'geoip.sess');
92
+ $geoIp->clearAdapters();
93
+
94
+ $adapters = Mage::getSingleton('mzax_emarketing/system_config_source_geoIp')->getSelectedAdapters();
95
+
96
+ /* @var $adapter Mzax_GeoIp_Adapter_Abstract */
97
+ foreach($adapters as $adapter) {
98
+ $geoIp->addAdapter($adapter);
99
+ }
100
+
101
+ if(!$geoIp->hasAdapters()) {
102
+ throw new Exception("No GeoIP adapters defined");
103
+ }
104
+
105
+
106
+
107
+
108
+ /* @var $resource Mzax_Emarketing_Model_Resource_Recipient_Event */
109
+ $resource = Mage::getResourceSingleton('mzax_emarketing/recipient_event');
110
+
111
+ $rows = $resource->fetchPendingGeoIpRows(3 /* expire in hours*/);
112
+
113
+ // noting todo, stop
114
+ if(empty($rows)) {
115
+ return;
116
+ }
117
+
118
+
119
+
120
+ $startTime = time();
121
+ $maxRunTime = 60*2;
122
+
123
+ foreach($rows as $row)
124
+ {
125
+ /* By default we use free public APIs to retrieve the location
126
+ * of an IP, those however limit each server to only a certain number
127
+ * of requests per day/hour.
128
+ *
129
+ * If this limit is reached it might be required to go for a payed version
130
+ * or implmented a custom version
131
+ */
132
+ if(!$geoIp->getRemainingRequests()) {
133
+ Mage::log("MzaxEmarketing: No GeoIP requests left, you might want to consider different solution.");
134
+ break;
135
+ }
136
+
137
+
138
+ /* Prevent flooding the APIs by doing to many calls in a short time or there might be
139
+ * en error happening every now and then.
140
+ * If this showes up in the log too ofter then there is a chance that something
141
+ * does not work OK.
142
+ */
143
+ if($geoIp->getRestTime()) {
144
+ Mage::log("MzaxEmarketing: GeoIP is resting, try again later.");
145
+ break;
146
+ }
147
+
148
+ /* Don't run forever...
149
+ * The next cron tab can always finish this later
150
+ */
151
+ if((time()-$startTime) >= $maxRunTime) {
152
+ Mage::log("MzaxEmarketing: Maximum run time exceeded");
153
+ break;
154
+ }
155
+
156
+ try {
157
+ //$randIp = implode('.', array(rand(1,254),rand(1,254),rand(1,254),rand(1,254)));
158
+ $result = $geoIp->fetch(inet_ntop($row['ip']));
159
+ if(!$result) {
160
+ continue;
161
+ }
162
+
163
+ $update = array();
164
+ if(!empty($row['country_id'])) {
165
+ $update['country_id'] = (string) $result->countryId;
166
+ }
167
+ if(!empty($row['region_id'])) {
168
+ $update['region_id'] = (string) $result->regionId;
169
+ }
170
+ if($row['time_offset'] === null) {
171
+ // assume magento store local time if we could not find out.
172
+ // INFO: we also use javascript to find the offset
173
+ // @see injectTimeOffsetJs()
174
+ if($result->timeOffset === null) {
175
+ //$update['time_offset'] = Mage::app()->getLocale()
176
+ // ->storeDate($row['store_id'])->getGmtOffset()/60;
177
+ }
178
+ else {
179
+ $update['time_offset'] = $result->timeOffset;
180
+ }
181
+ }
182
+ $resource->updateEvent($row['event_id'], $update);
183
+ $lock->touch();
184
+ }
185
+ catch(Exception $e) {
186
+ Mage::logException($e);
187
+ if(Mage::getIsDeveloperMode()) {
188
+ $lock->unlock();
189
+ throw $e;
190
+ }
191
+ }
192
+
193
+ } // foreach($rows as $row)
194
+ $lock->unlock();
195
+ }
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+ }
app/code/community/Mzax/Emarketing/Model/Report/Aggregator.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ class Mzax_Emarketing_Model_Report_Aggregator extends Mzax_Emarketing_Model_Report_Aggregator_Abstract
33
+ {
34
+
35
+ protected $_aggregators = array(
36
+ 'events',
37
+ 'recipient',
38
+ 'goals',
39
+ 'tracker',
40
+ 'dimension',
41
+ 'rates',
42
+ 'campaign',
43
+ );
44
+
45
+
46
+
47
+ /**
48
+ * Prepare options an run all aggregators
49
+ *
50
+ * @param array $options
51
+ */
52
+ public function run(array $options = array())
53
+ {
54
+ if($lock = Mage::helper('mzax_emarketing')->lock('report_aggregator'))
55
+ {
56
+ $options = new Varien_Object($options);
57
+ $options->setLock($lock);
58
+
59
+ if($aggregator = $options->getAggregator()) {
60
+ $options->setAggregator((array) $aggregator);
61
+ }
62
+ if($dimension = $options->getDimension()) {
63
+ $options->setDimension((array) $dimension);
64
+ }
65
+ if($trackerId = $options->getTrackerId()) {
66
+ $options->setTrackerId((array) $trackerId);
67
+ }
68
+
69
+ if($options->getData('full')) {
70
+ $options->unsAggregator();
71
+ $options->unsDimension();
72
+ $options->unsTrackerId();
73
+ $options->unsAggregator();
74
+ $options->unsIncremental();
75
+ }
76
+
77
+ $this->aggregate($options);
78
+ $lock->unlock();
79
+ }
80
+ }
81
+
82
+
83
+
84
+
85
+
86
+ protected function _aggregate()
87
+ {
88
+ $filter = $this->getOption('aggregator');
89
+
90
+ foreach($this->_aggregators as $type) {
91
+ if(empty($filter) || in_array($type, $filter)) {
92
+ $aggregator = $this->getAggregator($type);
93
+ $aggregator->aggregate($this->_options);
94
+ $this->_options->getLock()->touch();
95
+ }
96
+ }
97
+ }
98
+
99
+
100
+
101
+
102
+ /**
103
+ *
104
+ * @param string $type
105
+ * @return Mzax_Emarketing_Model_Report_Aggregator_Abstract
106
+ */
107
+ public function getAggregator($type)
108
+ {
109
+ return Mage::getSingleton('mzax_emarketing/report_aggregator_' . $type);
110
+ }
111
+
112
+
113
+
114
+ }
app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Abstract.php ADDED
@@ -0,0 +1,475 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ *
28
+ * @author Jacob Siefer
29
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
+ * @version 0.2.5
31
+ */
32
+ abstract class Mzax_Emarketing_Model_Report_Aggregator_Abstract
33
+ {
34
+
35
+ /**
36
+ * Default table for insert quieries
37
+ *
38
+ * @var string
39
+ */
40
+ protected $_reportTable;
41
+
42
+
43
+
44
+ /**
45
+ *
46
+ * @see getLastRecordTime()
47
+ * @var string
48
+ */
49
+ protected $_lastRecordTime;
50
+
51
+
52
+
53
+ /**
54
+ * Aggregation Options
55
+ *
56
+ * @var Varien_Object
57
+ */
58
+ protected $_options;
59
+
60
+
61
+
62
+ public function aggregate(Varien_Object $options)
63
+ {
64
+ $this->_options = $options;
65
+ $this->_lastRecordTime = null;
66
+ $this->_aggregate();
67
+ }
68
+
69
+
70
+ abstract protected function _aggregate();
71
+
72
+
73
+
74
+
75
+
76
+ /**
77
+ * Truncate specified table
78
+ *
79
+ * @param string $table
80
+ * @return Mzax_Emarketing_Model_Report_Aggregator_Abstract
81
+ */
82
+ protected function truncateTable($table = null)
83
+ {
84
+ if(!$table) {
85
+ $table = $this->_reportTable;
86
+ }
87
+
88
+ $this->log("Truncate table: %s", $table);
89
+ $this->_getWriteAdapter()->truncateTable($this->_getTable($table));
90
+ return $this;
91
+ }
92
+
93
+
94
+ /**
95
+ * Delete certain elements from table
96
+ *
97
+ * @param array $where
98
+ * @param string $table
99
+ * @return Mzax_Emarketing_Model_Report_Aggregator_Abstract
100
+ */
101
+ protected function delete($where, $table = null)
102
+ {
103
+ if(!$table) {
104
+ $table = $this->_reportTable;
105
+ }
106
+
107
+ $this->log("Delete from table `%s` where: %s", $table, var_export($where, true));
108
+ $this->_getWriteAdapter()->delete($this->_getTable($table), $where);
109
+ return $this;
110
+ }
111
+
112
+
113
+
114
+
115
+ /**
116
+ * Retrieve option value
117
+ *
118
+ * @param string $key
119
+ * @param mixed $default
120
+ * @return mixed
121
+ */
122
+ protected function getOption($key, $default = null)
123
+ {
124
+ return $this->_options->getDataSetDefault($key, $default);
125
+ }
126
+
127
+
128
+
129
+
130
+
131
+ /**
132
+ * Print log message
133
+ *
134
+ * @param string $message
135
+ * @param _ mixed[optional]
136
+ * @return Mzax_Emarketing_Model_Report_Aggregator_Abstract
137
+ */
138
+ protected function log($message)
139
+ {
140
+ if(func_num_args() > 1) {
141
+ $message = call_user_func_array('sprintf', func_get_args());
142
+ }
143
+ if($this->_options->getVerbose()) {
144
+ echo $message . "\n";
145
+ flush();
146
+ }
147
+ return $this;
148
+ }
149
+
150
+
151
+
152
+ /**
153
+ * Update stats table from select
154
+ *
155
+ * @param Zend_Db_Select $select
156
+ * @param array $fields
157
+ * @return Zend_Db_Statement_Interface
158
+ */
159
+ protected function insertSelect(Mzax_Emarketing_Db_Select $select, $table = null)
160
+ {
161
+ $sql = $select->insertFromSelect($this->_getTable($table ? $table : $this->_reportTable));
162
+
163
+ $startTime = microtime(true);
164
+ try {
165
+ $this->log("\n\n\n\n$sql\n");
166
+ $this->_getWriteAdapter()->query($sql);
167
+ $duration = microtime(true)-$startTime;
168
+ $this->log("QueryTime [%s]: %01.4fsec\n\n", get_class($this), microtime(true)-$startTime);
169
+ return $duration;
170
+ }
171
+ catch(Exception $e) {
172
+ $this->log($e->getMessage());
173
+ $this->log($e->getTraceAsString());
174
+ $this->log($sql);
175
+
176
+ throw $e;
177
+ }
178
+ }
179
+
180
+
181
+
182
+
183
+
184
+ /**
185
+ * Retrieve session model
186
+ *
187
+ * @return Mzax_Emarketing_Model_Session
188
+ */
189
+ public function getSession()
190
+ {
191
+ return Mage::getSingleton('mzax_emarketing/session');
192
+ }
193
+
194
+
195
+
196
+
197
+ /**
198
+ *
199
+ * @return Mzax_Emarketing_Model_Resource_Helper
200
+ */
201
+ protected function getResourceHelper()
202
+ {
203
+ return Mage::getResourceSingleton('mzax_emarketing/helper');
204
+ }
205
+
206
+
207
+
208
+ /**
209
+ * Retrieve connection for read data
210
+ *
211
+ * @return Varien_Db_Adapter_Interface
212
+ */
213
+ protected function _getWriteAdapter()
214
+ {
215
+ return $this->getResourceHelper()->getWriteAdapter();
216
+ }
217
+
218
+
219
+
220
+ /**
221
+ * Retrieve new select object
222
+ *
223
+ * @param string $table
224
+ * @param string $alias
225
+ * @param string $cols
226
+ * @return Mzax_Emarketing_Db_Select
227
+ */
228
+ protected function _select($table = null, $alias = null, $cols = null)
229
+ {
230
+ $select = new Mzax_Emarketing_Db_Select($this->_getWriteAdapter());
231
+ if($table) {
232
+ $select->from($this->_getTable($table, $alias), $cols);
233
+ }
234
+ return $select;
235
+ }
236
+
237
+
238
+ /**
239
+ * Retrieve table name
240
+ *
241
+ * @param string $table
242
+ * @param string $alias
243
+ * @return string
244
+ */
245
+ protected function _getTable($table, $alias = null)
246
+ {
247
+ if($table instanceof Zend_Db_Select) {
248
+ return array($alias => $table);
249
+ }
250
+ $table = $this->getResourceHelper()->getTable($table);
251
+ if($alias) {
252
+ return array($alias => $table);
253
+ }
254
+ return $table;
255
+ }
256
+
257
+
258
+
259
+ /**
260
+ * Retrieve an attribute by entityname/attributename
261
+ *
262
+ * getAttribute(entity/attribute);
263
+ * getAttribute(customer/signupdate);
264
+ *
265
+ * @param string $attribute
266
+ * @throws Exception
267
+ *
268
+ * @return Mage_Catalog_Model_Resource_Eav_Attribute
269
+ */
270
+ protected function _getAttribute($attribute)
271
+ {
272
+ return $this->getResourceHelper()->getAttribute($attribute);
273
+ }
274
+
275
+
276
+
277
+
278
+
279
+
280
+ /**
281
+ * Retrieve form helper
282
+ *
283
+ * @return Mzax_Emarketing_Helper_Data
284
+ */
285
+ protected function helper()
286
+ {
287
+ return Mage::helper('mzax_emarketing');
288
+ }
289
+
290
+
291
+
292
+ /**
293
+ * Translate
294
+ *
295
+ * @param string $message
296
+ * @param string $args,...
297
+ * @return string
298
+ */
299
+ protected function __()
300
+ {
301
+ return call_user_func_array(array($this->helper(), '__'), func_get_args());
302
+ }
303
+
304
+
305
+
306
+ /**
307
+ *
308
+ * @param string $type
309
+ * @return Mzax_Emarketing_Model_Report_Aggregator_Abstract
310
+ */
311
+ public function getAggregator($type)
312
+ {
313
+ return Mage::getSingleton('mzax_emarketing/report_aggregator')->getAggregator($type);
314
+ }
315
+
316
+
317
+
318
+
319
+
320
+
321
+ /**
322
+ * Retrieve field list for insert query
323
+ *
324
+ * @param array $fields
325
+ * @return string
326
+ */
327
+ protected function quoteIdentifiers(array $fields)
328
+ {
329
+ $adapter = $this->_getWriteAdapter();
330
+ $fieldList = array();
331
+ foreach($fields as $field) {
332
+ $fieldList[] = $adapter->quoteIdentifier($field);
333
+ }
334
+ return implode(", ", $fieldList);
335
+ }
336
+
337
+
338
+
339
+
340
+
341
+ /**
342
+ * Retrieve update list for insert query
343
+ *
344
+ * @param array $fields
345
+ * @return string
346
+ */
347
+ protected function getUpdateOn(array $fields)
348
+ {
349
+ $write = $this->_getWriteAdapter();
350
+ $updateList = array();
351
+
352
+ foreach($fields as $field) {
353
+ $field = $write->quoteIdentifier($field);
354
+ $updateList[] = "$field = VALUES($field)";
355
+ }
356
+ return implode(",\n\t", $updateList);
357
+ }
358
+
359
+
360
+
361
+ /**
362
+ * Get incremental sql expressions
363
+ *
364
+ * $field '?' will usally get replaced by getLastRecordTime()
365
+ *
366
+ * @see applyDateFilter()
367
+ * @param string $field
368
+ * @return string
369
+ */
370
+ public function getIncrementalSql($field = '?')
371
+ {
372
+ $incremental = abs((int) $this->getOption('incremental'));
373
+ return "DATE_SUB($field, INTERVAL $incremental DAY)";
374
+ }
375
+
376
+
377
+
378
+ /**
379
+ * Apply the incremental day look back on the date_filter expression
380
+ *
381
+ * @param Mzax_Emarketing_Db_Select $select
382
+ * @param string $lastRecord
383
+ */
384
+ protected function applyDateFilter(Mzax_Emarketing_Db_Select $select, $lastRecord = null)
385
+ {
386
+ $incremental = $this->getOption('incremental');
387
+ if($incremental && !$this->getOption('full')) {
388
+ if( $lastRecord === null ) {
389
+ $lastRecord = $this->getLastRecordTime();
390
+ }
391
+ if($lastRecord && $select->hasBinding('date_filter') ) {
392
+ $select->where("{date_filter} >= {$this->getIncrementalSql()}", $lastRecord);
393
+ }
394
+ }
395
+ }
396
+
397
+
398
+
399
+ /**
400
+ * Retrieve the datetime value of the last record
401
+ * that has been insert by this aggregator
402
+ *
403
+ * This is value is used to do incremental aggregation
404
+ *
405
+ * @see applyDateFilter()
406
+ * @return string|null
407
+ */
408
+ public function getLastRecordTime()
409
+ {
410
+ if(!$this->_lastRecordTime && $this->_options) {
411
+ $this->_lastRecordTime = $this->_getLastRecordTime();
412
+ }
413
+ return $this->_lastRecordTime;
414
+ }
415
+
416
+
417
+ protected function _getLastRecordTime()
418
+ {
419
+ $adapter = $this->_getWriteAdapter();
420
+ $select = $this->_select($this->_reportTable, 'report', 'MAX(`date`)');
421
+ $select->filter('report.campagin_id', $this->_options->getCampaignId());
422
+
423
+ return $adapter->fetchOne($select);
424
+ }
425
+
426
+
427
+
428
+
429
+ /**
430
+ * Retrieve default gmt offset in miuntes
431
+ * by each store
432
+ *
433
+ * @return Zend_Db_Expr
434
+ */
435
+ protected function getDefaultGmtOffset($store = true)
436
+ {
437
+ $gmtOffset = (int) Mage::app()->getLocale()->storeDate(Mage_Core_Model_App::ADMIN_STORE_ID)->getGmtOffset()/60;
438
+
439
+ if($store) {
440
+ $adapter = $this->_getWriteAdapter();
441
+
442
+ /* @var $store Mage_Core_Model_Store */
443
+ foreach(Mage::app()->getStores() as $store) {
444
+ $storeGmtOffset = Mage::app()->getLocale()->storeDate($store)->getGmtOffset()/60;
445
+ $gmtOffset = $adapter->getCheckSql("{store_id} = {$store->getId()}", $storeGmtOffset, $gmtOffset);
446
+ }
447
+ }
448
+
449
+ return $gmtOffset;
450
+ }
451
+
452
+
453
+
454
+
455
+ /**
456
+ * Retreive sql local time
457
+ *
458
+ * @param string $field
459
+ * @param string $gmtOffset
460
+ * @param boolean $dateOnly
461
+ * @return Zend_Db_Expr
462
+ */
463
+ protected function getLocalTimeSql($field, $gmtOffset = null)
464
+ {
465
+ if( $gmtOffset !== null ) {
466
+ $gmtOffset = $this->_getWriteAdapter()->getIfNullSql($gmtOffset, $this->getDefaultGmtOffset());
467
+ }
468
+ else {
469
+ $gmtOffset = $this->getDefaultGmtOffset();
470
+ }
471
+ return new Zend_Db_Expr("DATE_SUB($field, INTERVAL $gmtOffset MINUTE)");
472
+ }
473
+
474
+
475
+ }
app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Campaign.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ /**
26
+ * Final summary data for each campaign for grid view
27
+ *
28
+ *
29
+ * @author Jacob Siefer
30
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
+ * @version 0.2.5
32
+ */
33
+ class Mzax_Emarketing_Model_Report_Aggregator_Campaign
34
+ extends Mzax_Emarketing_Model_Report_Aggregator_Abstract
35
+ {
36
+
37
+
38
+
39
+ protected function _aggregate()
40
+ {
41
+ $startTime = microtime(true);
42
+
43
+ $this->aggregateReportTable();
44
+ $this->aggregateReportConversionTable();
45
+
46
+
47
+ $this->log("Aggregation Time: %01.4fsec", microtime(true)-$startTime);
48
+ }
49
+
50
+
51
+
52
+
53
+ /**
54
+ * Retrieve the campaigns interactions and send stats from
55
+ * the report table previously aggregated by the recipient
56
+ *
57
+ * @return void
58
+ */
59
+ protected function aggregateReportTable()
60
+ {
61
+ $select = $this->_select('report');
62
+ $select->group('campaign_id');
63
+ $select->setColumn('campaign_id', 'campaign_id');
64
+
65
+ $select->setColumn('sending_stats', new Zend_Db_Expr('SUM(sendings)'));
66
+ $select->setColumn('interaction_stats', new Zend_Db_Expr('SUM(clicks)'));
67
+ $select->setColumn('fail_stats', new Zend_Db_Expr('SUM(bounces) + SUM(optouts)'));
68
+
69
+
70
+ $updateSql = "UPDATE `{$this->_getTable('campaign')}` AS `campaign`\n";
71
+ $updateSql.= "LEFT JOIN ($select) AS `report` ON `report`.`campaign_id` = `campaign`.`campaign_id`\n";
72
+ $updateSql.= "SET\n";
73
+ $updateSql.= "`campaign`.`sending_stats` = IFNULL(`report`.`sending_stats`, 0),\n";
74
+ $updateSql.= "`campaign`.`interaction_stats` = IFNULL(`report`.`interaction_stats`, 0),\n";
75
+ $updateSql.= "`campaign`.`fail_stats` = IFNULL(`report`.`fail_stats`, 0)";
76
+
77
+ $this->_getWriteAdapter()->query($updateSql);
78
+ }
79
+
80
+
81
+
82
+
83
+ /**
84
+ * Retrieve conversion and revenue stats from conversion table
85
+ * that was previously aggregated by the trackers
86
+ *
87
+ * We will use the campaigns default tracker for that
88
+ *
89
+ * @return void
90
+ */
91
+ protected function aggregateReportConversionTable()
92
+ {
93
+ $defaultTracker = $this->getDefaultTrackerId();
94
+
95
+ $select = $this->_select('report_conversion');
96
+ $select->group('campaign_id', 'tracker_id');
97
+ $select->setColumn('campaign_id', 'campaign_id');
98
+ $select->setColumn('tracker_id', 'tracker_id');
99
+ $select->setColumn('conversion_stats', new Zend_Db_Expr('SUM(hits)'));
100
+ $select->setColumn('revenue_stats', new Zend_Db_Expr('SUM(hit_revenue)'));
101
+
102
+
103
+ $updateSql = "UPDATE `{$this->_getTable('campaign')}` AS `campaign`\n";
104
+ $updateSql.= "LEFT JOIN ($select) AS `report` ON (`report`.`campaign_id` = `campaign`.`campaign_id` AND `report`.`tracker_id` = IFNULL(`campaign`.`default_tracker_id`, $defaultTracker))\n";
105
+ $updateSql.= "SET\n";
106
+ $updateSql.= "`campaign`.`conversion_stats` = IFNULL(`report`.`conversion_stats`, 0),\n";
107
+ $updateSql.= "`campaign`.`revenue_stats` = IFNULL(`report`.`revenue_stats`, 0)";
108
+
109
+ $this->_getWriteAdapter()->query($updateSql);
110
+
111
+ }
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+ /**
120
+ * Retrieve default tracker id
121
+ *
122
+ * @return number
123
+ */
124
+ public function getDefaultTrackerId()
125
+ {
126
+ return (int) $this->_getWriteAdapter()->fetchOne(
127
+ $this->_select('conversion_tracker', null, 'tracker_id')->where('`is_default` = 1'));
128
+ }
129
+
130
+
131
+
132
+
133
+
134
+
135
+ }
app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Model_Report_Aggregator_Dimension extends Mzax_Emarketing_Model_Report_Aggregator_Abstract
26
+ {
27
+
28
+ const TABLE_REPORT = 'report_dimension';
29
+ const TABLE_CONVERSION = 'report_dimension_conversion';
30
+
31
+
32
+ protected $_dimensions = array(
33
+ 'dayofweek',
34
+ 'hour',
35
+ 'useragent',
36
+ 'deviceType',
37
+ 'deviceBrand',
38
+ 'os',
39
+ 'country',
40
+ 'region',
41
+ );
42
+
43
+
44
+
45
+ protected function _aggregate()
46
+ {
47
+ $filter = $this->_options->getDimension();
48
+
49
+ if($this->getOption('full', false)) {
50
+ $this->truncateTable(self::TABLE_REPORT);
51
+ $this->truncateTable(self::TABLE_CONVERSION);
52
+ }
53
+ else {
54
+ if($trackerId = $this->getOption('tracker_id')) {
55
+ $this->delete(array('`tracker_id` IN(?)' => $trackerId), self::TABLE_CONVERSION);
56
+ }
57
+ if($campaignId = $this->getOption('campaign_id')) {
58
+ $this->delete(array('`campaign_id` IN(?)' => $campaignId), self::TABLE_REPORT);
59
+ $this->delete(array('`campaign_id` IN(?)' => $campaignId), self::TABLE_CONVERSION);
60
+ }
61
+ }
62
+ foreach($this->_dimensions as $type) {
63
+ if(empty($filter) || in_array($type, $filter)) {
64
+ $dimension = $this->getDimension($type);
65
+ $dimension->aggregate($this->_options);
66
+ $this->_options->getLock()->touch();
67
+ }
68
+ }
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @param string $type
74
+ * @return Mzax_Emarketing_Model_Report_Aggregator_Dimension_Abstract
75
+ */
76
+ public function getDimension($type)
77
+ {
78
+ return Mage::getSingleton('mzax_emarketing/report_aggregator_dimension_' . $type);
79
+ }
80
+
81
+
82
+
83
+ }
app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension/Abstract.php ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ abstract class Mzax_Emarketing_Model_Report_Aggregator_Dimension_Abstract
26
+ extends Mzax_Emarketing_Model_Report_Aggregator_Abstract
27
+ {
28
+
29
+
30
+
31
+ protected $_reportTable = 'report_dimension';
32
+
33
+
34
+
35
+
36
+
37
+ abstract public function getTitle();
38
+
39
+
40
+ abstract public function getValues();
41
+
42
+
43
+ public function getSqlValues()
44
+ {
45
+ return null;
46
+ }
47
+
48
+
49
+ public function aggregate(Varien_Object $options)
50
+ {
51
+ $this->_options = $options;
52
+ $this->_lastRecordTime = null;
53
+
54
+ // only aggregate if we have any values
55
+ if(count($this->getValues())) {
56
+ $this->_aggregate();
57
+ }
58
+ }
59
+
60
+
61
+ protected function _aggregate()
62
+ {
63
+ if(!$this->_options->getTrackerId()) {
64
+ $this->aggregateSendings();
65
+ $this->aggregateEvent(Mzax_Emarketing_Model_Recipient::EVENT_TYPE_VIEW, 'views');
66
+ $this->aggregateEvent(Mzax_Emarketing_Model_Recipient::EVENT_TYPE_CLICK, 'clicks');
67
+ $this->aggregateBounces();
68
+ $this->aggregateOptouts();
69
+ }
70
+ $this->aggregateTrackers();
71
+ }
72
+
73
+
74
+
75
+
76
+
77
+
78
+ protected function aggregateSendings()
79
+ {
80
+ $select = $this->getAggregateSendingsSelect();
81
+ $this->insertSelect($select);
82
+
83
+ // change query to group by variations
84
+ $select->group(array('{campaign_id}', '{variation_id}', 'DATE({store_date})', '{value}'), true);
85
+ $select->where('{variation_id} >= 0');
86
+ $select->setColumn('variation_id', null);
87
+
88
+ $this->insertSelect($select);
89
+
90
+ }
91
+
92
+
93
+
94
+ protected function aggregateEvent($eventType, $fieldName)
95
+ {
96
+ $select = $this->getAggregateEventSelect($eventType, $fieldName);
97
+ $this->insertSelect($select);
98
+
99
+ // change query to group by variations
100
+ $select->group(array('{campaign_id}', '{variation_id}', 'DATE({store_date})', '{value}'), true);
101
+ $select->where('{variation_id} >= 0');
102
+ $select->setColumn('variation_id', null);
103
+
104
+ $this->insertSelect($select);
105
+
106
+ }
107
+
108
+
109
+ protected function aggregateOptouts()
110
+ {
111
+ $select = $this->getAggregateOptoutSelect();
112
+ $this->insertSelect($select);
113
+
114
+ // change query to group by variations
115
+ $select->group(array('{campaign_id}', '{variation_id}', 'DATE({store_date})', '{value}'), true);
116
+ $select->where('{variation_id} >= 0');
117
+ $select->setColumn('variation_id', null);
118
+
119
+ $this->insertSelect($select);
120
+
121
+
122
+ }
123
+
124
+
125
+
126
+ protected function aggregateBounces()
127
+ {
128
+ $select = $this->getAggregateBounceSelect();
129
+ $this->insertSelect($select);
130
+
131
+ // change query to group by variations
132
+ $select->group(array('{campaign_id}', '{variation_id}', 'DATE({store_date})', '{value}'), true);
133
+ $select->where('{variation_id} >= 0');
134
+ $select->setColumn('variation_id', null);
135
+
136
+ $this->insertSelect($select);
137
+
138
+ }
139
+
140
+
141
+
142
+
143
+
144
+ protected function aggregateTrackers()
145
+ {
146
+ $select = $this->getAggregateTrackersSelect();
147
+ $this->insertSelect($select, $this->_reportTable . '_conversion');
148
+
149
+ // change query to group by variations
150
+ $select->group(array('{campaign_id}', '{variation_id}', 'DATE({store_date})', '{value}'), true);
151
+ $select->where('{variation_id} >= 0');
152
+ $select->setColumn('variation_id', null);
153
+
154
+ $this->insertSelect($select, $this->_reportTable . '_conversion');
155
+ }
156
+
157
+
158
+
159
+
160
+
161
+
162
+ protected function prepareAggregationSelect(Mzax_Emarketing_Db_Select $select)
163
+ {}
164
+
165
+
166
+
167
+ /**
168
+ * Retrieve aggregation select for sending
169
+ *
170
+ *
171
+ * +-------------+--------------+------+--------------+----------+----------+
172
+ * | campaign_id | variation_id | date | dimension_id | value_id | sendings |
173
+ * +-------------+--------------+------+--------------+----------+----------+
174
+ * | ... | -1 OR >=0 | ... | ID | ... | ... |
175
+ * : : : : ID : : :
176
+ * +-------------+--------------+------+--------------+----------+----------+
177
+ *
178
+ * @return Mzax_Emarketing_Db_Select
179
+ */
180
+ protected function getAggregateSendingsSelect()
181
+ {
182
+ $select = $this->_select('recipient', 'recipient');
183
+ $select->joinTable('campaign_id', 'campaign');
184
+
185
+ $select->where('`recipient`.`sent_at` IS NOT NULL');
186
+ $select->where('`recipient`.`is_mock` = 0');
187
+ $select->where('`campaign`.`archived` = 0');
188
+
189
+ $select->addBinding('date_filter', 'recipient.sent_at');
190
+ $select->addBinding('recipient_id', 'recipient_id');
191
+ $select->addBinding('campaign_id', 'campaign_id');
192
+ $select->addBinding('variation_id', 'variation_id');
193
+ $select->addBinding('store_id', 'campaign.store_id');
194
+ $select->addBinding('local_date', $this->getLocalTimeSql('`recipient`.`sent_at`'));
195
+ $select->addBinding('store_date', $this->getLocalTimeSql('`recipient`.`sent_at`'));
196
+ $select->addBinding('sendings', 'COUNT(DISTINCT {recipient_id})');
197
+
198
+ $select->setColumn('campaign_id');
199
+ $select->setColumn('variation_id', new Zend_Db_Expr(-1));
200
+ $select->setColumn('date', '{store_date}');
201
+ $select->setColumn('dimension_id', new Zend_Db_Expr($this->getDimensionId()));
202
+ $select->setColumn('value_id', $this->getValueIdExpr());
203
+ $select->setColumn('sendings');
204
+
205
+ $select->group(array('{campaign_id}', 'DATE({store_date})', '{value}'));
206
+ $select->filter('recipient.campaign_id', $this->_options->getCampaignId());
207
+ $this->applyDateFilter($select);
208
+
209
+ $this->prepareAggregationSelect($select->lock());
210
+
211
+ return $select;
212
+ }
213
+
214
+
215
+
216
+
217
+ /**
218
+ * Retrieve aggregation select for the given event type
219
+ *
220
+ * +-------------+--------------+------+--------------+----------+------------+
221
+ * | campaign_id | variation_id | date | dimension_id | value_id | $fieldName |
222
+ * +-------------+--------------+------+--------------+----------+------------+
223
+ * | ... | -1 OR >=0 | ... | ID | ... | ... |
224
+ * : : : : ID : : :
225
+ * +-------------+--------------+------+--------------+----------+------------+
226
+ *
227
+ *
228
+ * @param string $eventType
229
+ * @param string $fieldName
230
+ * @return Mzax_Emarketing_Db_Select
231
+ */
232
+ protected function getAggregateEventSelect($eventType, $fieldName)
233
+ {
234
+ $select = $this->_select('recipient_event', 'event');
235
+ $select->joinTable('recipient_id', 'recipient');
236
+ $select->joinTable('campaign_id', 'campaign');
237
+
238
+ $select->where('`event`.`event_type` = ?', $eventType);
239
+ $select->where('`recipient`.`is_mock` = 0');
240
+ $select->where('`campaign`.`archived` = 0');
241
+
242
+ $select->addBinding('date_filter', 'event.captured_at');
243
+ $select->addBinding('recipient_id', 'event.recipient_id');
244
+ $select->addBinding('campaign_id', 'recipient.campaign_id');
245
+ $select->addBinding('variation_id', 'recipient.variation_id');
246
+ $select->addBinding('store_id', 'campaign.store_id');
247
+ $select->addBinding('local_date', $this->getLocalTimeSql('`event`.`captured_at`', '`event`.`time_offset` * 15'));
248
+ $select->addBinding('store_date', $this->getLocalTimeSql('`event`.`captured_at`'));
249
+ $select->addBinding($fieldName, 'COUNT(DISTINCT {recipient_id})');
250
+
251
+ $select->setColumn('campaign_id');
252
+ $select->setColumn('variation_id', new Zend_Db_Expr(-1));
253
+ $select->setColumn('date', 'DATE({store_date})');
254
+ $select->setColumn('dimension_id', new Zend_Db_Expr($this->getDimensionId()));
255
+ $select->setColumn('value_id', $this->getValueIdExpr());
256
+ $select->setColumn($fieldName);
257
+
258
+ $select->group(array('{campaign_id}', 'DATE({store_date})', '{value}'));
259
+ $select->filter('recipient.campaign_id', $this->_options->getCampaignId());
260
+ $this->applyDateFilter($select);
261
+
262
+ $this->prepareAggregationSelect($select->lock());
263
+
264
+ return $select;
265
+ }
266
+
267
+
268
+
269
+
270
+
271
+ /**
272
+ * Retrieve aggregation select for bounces
273
+ *
274
+ * +-------------+--------------+------+--------------+----------+---------+
275
+ * | campaign_id | variation_id | date | dimension_id | value_id | bounces |
276
+ * +-------------+--------------+------+--------------+----------+---------+
277
+ * | ... | -1 OR >=0 | ... | ID | ... | ... |
278
+ * : : : : ID : : :
279
+ * +-------------+--------------+------+--------------+----------+---------+
280
+ *
281
+ *
282
+ * @return Mzax_Emarketing_Db_Select
283
+ */
284
+ protected function getAggregateBounceSelect()
285
+ {
286
+ $bouncedAt = $this->_getWriteAdapter()->getIfNullSql('`inbox`.`sent_at`', '`inbox`.`created_at`');
287
+ $bouncedAt = $this->getLocalTimeSql($bouncedAt);
288
+
289
+ $select = $this->_select('inbox_email', 'inbox');
290
+ $select->joinTable('recipient_id', 'recipient');
291
+ $select->joinTable('campaign_id', 'campaign');
292
+
293
+ $select->where('`inbox`.`is_parsed` = 1');
294
+ $select->where('`inbox`.`type` = "SB" OR `inbox`.`type` = "HB"');
295
+ $select->where('`recipient`.`is_mock` = 0');
296
+ $select->where('`campaign`.`archived` = 0');
297
+
298
+ $select->addBinding('date_filter', 'inbox.created_at');
299
+ $select->addBinding('recipient_id', 'inbox.recipient_id');
300
+ $select->addBinding('campaign_id', 'recipient.campaign_id');
301
+ $select->addBinding('variation_id', 'recipient.variation_id');
302
+ $select->addBinding('store_id', 'campaign.store_id');
303
+ $select->addBinding('local_date', $bouncedAt);
304
+ $select->addBinding('store_date', $bouncedAt);
305
+ $select->addBinding('bounces', 'COUNT(DISTINCT {recipient_id})');
306
+
307
+ $select->setColumn('campaign_id');
308
+ $select->setColumn('variation_id', new Zend_Db_Expr(-1));
309
+ $select->setColumn('date', 'DATE({store_date})');
310
+ $select->setColumn('dimension_id', new Zend_Db_Expr($this->getDimensionId()));
311
+ $select->setColumn('value_id', $this->getValueIdExpr());
312
+ $select->setColumn('bounces');
313
+
314
+ $select->group(array('{campaign_id}', 'DATE({store_date})', '{value}'));
315
+ $select->filter('recipient.campaign_id', $this->_options->getCampaignId());
316
+ $this->applyDateFilter($select);
317
+
318
+ $this->prepareAggregationSelect($select->lock());
319
+
320
+ return $select;
321
+ }
322
+
323
+
324
+
325
+
326
+
327
+ /**
328
+ * Aggregate the number of unique optouts per day
329
+ *
330
+ * We are tracking the number of clicks on optout links
331
+ * An email failed if the user clicked on a unsubscribe link.
332
+ *
333
+ * +-------------+--------------+------+--------------+----------+---------+
334
+ * | campaign_id | variation_id | date | dimension_id | value_id | optouts |
335
+ * +-------------+--------------+------+--------------+----------+---------+
336
+ * | ... | -1 OR >=0 | ... | ID | ... | ... |
337
+ * : : : : ID : : :
338
+ * +-------------+--------------+------+--------------+----------+---------+
339
+ *
340
+ *
341
+ * @return void
342
+ */
343
+ protected function getAggregateOptoutSelect()
344
+ {
345
+ $select = $this->_select('link_reference_click', 'click');
346
+ $select->joinTable('reference_id', 'link_reference', 'reference');
347
+ $select->joinTable('link_id', 'link');
348
+ $select->joinTable('recipient_id', 'recipient');
349
+ $select->joinTable('campaign_id', 'campaign');
350
+ $select->joinTableLeft('event_id', 'recipient_event', 'click_event');
351
+
352
+ $select->where('`link`.`optout` = 1');
353
+ $select->where('`recipient`.`is_mock` = 0');
354
+ $select->where('`campaign`.`archived` = 0');
355
+
356
+ $select->addBinding('date_filter', 'click.clicked_at');
357
+ $select->addBinding('click_id', 'click.click_id');
358
+ $select->addBinding('reference_id', 'click.reference_id');
359
+ $select->addBinding('link_id', 'reference.link_id');
360
+ $select->addBinding('recipient_id', 'reference.recipient_id');
361
+ $select->addBinding('campaign_id', 'recipient.campaign_id');
362
+ $select->addBinding('variation_id', 'recipient.variation_id');
363
+ $select->addBinding('store_id', 'campaign.store_id');
364
+ $select->addBinding('local_date', $this->getLocalTimeSql('`click`.`clicked_at`', '`click_event`.`time_offset` * 15'));
365
+ $select->addBinding('store_date', $this->getLocalTimeSql('`click`.`clicked_at`'));
366
+ $select->addBinding('optouts', 'COUNT(DISTINCT {recipient_id})');
367
+
368
+ $select->setColumn('campaign_id');
369
+ $select->setColumn('variation_id', new Zend_Db_Expr(-1));
370
+ $select->setColumn('date', 'DATE({store_date})');
371
+ $select->setColumn('dimension_id', new Zend_Db_Expr($this->getDimensionId()));
372
+ $select->setColumn('value_id', $this->getValueIdExpr());
373
+ $select->setColumn('optouts');
374
+
375
+ $select->group(array('{campaign_id}', 'DATE({store_date})', '{value}'));
376
+ $select->filter('recipient.campaign_id', $this->_options->getCampaignId());
377
+ $this->applyDateFilter($select);
378
+
379
+ $this->prepareAggregationSelect($select->lock());
380
+
381
+ return $select;
382
+ }
383
+
384
+
385
+
386
+
387
+
388
+
389
+ /**
390
+ * Aggregate dimension for each tracker
391
+ *
392
+ * Use 'conversion_tracker_goal' as source table which has been aggregated
393
+ * by the tracker aggregator.
394
+ *
395
+ *
396
+ * +-------------+--------------+------+--------------+----------+------------+------+-----------+
397
+ * | campaign_id | variation_id | date | dimension_id | value_id | tracker_id | hits | hit_value |
398
+ * +-------------+--------------+------+--------------+----------+------------+------+-----------+
399
+ * | ... | -1 OR >=0 | ... | ID | ... | ... | ... | ... |
400
+ * : : : : ID : : : : :
401
+ * +-------------+--------------+------+--------------+----------+------------+------+-----------+
402
+ *
403
+ *
404
+ * @see Mzax_Emarketing_Model_Report_Aggregator_Tracker
405
+ * @return Mzax_Emarketing_Db_Select
406
+ */
407
+ public function getAggregateTrackersSelect()
408
+ {
409
+ $goalTime = $this->getLocalTimeSql('`goal`.`goal_time`');
410
+
411
+ $select = $this->_select('conversion_tracker_goal', 'goal');
412
+ $select->joinTable('recipient_id', 'recipient');
413
+ $select->joinTable('campaign_id', 'campaign');
414
+
415
+ $select->where('`recipient`.`is_mock` = 0');
416
+ $select->where('`campaign`.`archived` = 0');
417
+
418
+ $select->addBinding('date_filter', 'goal_time');
419
+ $select->addBinding('goal_id', 'goal_id');
420
+ $select->addBinding('goal_time', 'goal_time');
421
+ $select->addBinding('tracker_id', 'tracker_id');
422
+ $select->addBinding('recipient_id', 'recipient_id');
423
+ $select->addBinding('campaign_id', 'recipient.campaign_id');
424
+ $select->addBinding('variation_id', 'recipient.variation_id');
425
+ $select->addBinding('store_id', 'campaign.store_id');
426
+ $select->addBinding('local_date', $goalTime);
427
+ $select->addBinding('store_date', $goalTime);
428
+ $select->addBinding('hits', 'COUNT(DISTINCT {goal_id})');
429
+ $select->addBinding('hit_value', 'SUM(`goal`.`goal_value`)');
430
+
431
+ $select->setColumn('campaign_id');
432
+ $select->setColumn('variation_id', new Zend_Db_Expr(-1));
433
+ $select->setColumn('date', 'DATE({store_date})');
434
+ $select->setColumn('dimension_id', new Zend_Db_Expr($this->getDimensionId()));
435
+ $select->setColumn('value_id', $this->getValueIdExpr());
436
+ $select->setColumn('tracker_id');
437
+ $select->setColumn('hits');
438
+ $select->setColumn('hit_value');
439
+
440
+ $select->group(array('{campaign_id}', 'DATE({store_date})', '{value}'));
441
+
442
+ $select->filter('goal.campaign_id', $this->_options->getCampaignId());
443
+ $select->filter('goal.tracker_id', $this->_options->getTrackerId());
444
+ $this->applyDateFilter($select);
445
+
446
+ $this->prepareAggregationSelect($select->lock());
447
+
448
+ return $select;
449
+ }
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+ /**
458
+ * Retreive value ids
459
+ *
460
+ * @return array
461
+ */
462
+ public function getValueIds()
463
+ {
464
+ return $this->_getValueId($this->getValues());
465
+ }
466
+
467
+
468
+ /**
469
+ * Retreive dimension id
470
+ *
471
+ * @return integer
472
+ */
473
+ public function getDimensionId()
474
+ {
475
+ return $this->_getValueId($this->getTitle());
476
+ }
477
+
478
+
479
+
480
+
481
+ /**
482
+ * Retreive value ID for the given value.
483
+ * If value is array, return hash array in
484
+ * form of:
485
+ * value => value_id
486
+ *
487
+ *
488
+ * @param string|array $value
489
+ * @return string|array
490
+ */
491
+ protected function _getValueId($value)
492
+ {
493
+ if(is_array($value)) {
494
+ $result = array();
495
+ foreach($value as $v) {
496
+ if($v) {
497
+ $result[$v] = $this->_getValueId($v);
498
+ }
499
+ }
500
+ return $result;
501
+ }
502
+
503
+ $adapter = $this->_getWriteAdapter();
504
+ $table = $this->_getTable('report_enum');
505
+
506
+ $valueId = $adapter->fetchOne(
507
+ $this->_select()->from($table, 'value_id')->where('`value` = ?', $value));
508
+
509
+ if(!$valueId) {
510
+ $adapter->insert($table, array('value' => $value));
511
+ $valueId = (int) $adapter->lastInsertId($table);
512
+ }
513
+
514
+ return $valueId;
515
+ }
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+ /**
524
+ * Create expression that convers a string value to
525
+ * the value id previously insert into the enum table
526
+ *
527
+ * @param Zend_Db_Expr $valueExpr
528
+ * @return Zend_Db_Expr
529
+ */
530
+ public function getValueIdExpr()
531
+ {
532
+ $adapter = $this->_getWriteAdapter();
533
+
534
+ $sqlValues = $this->getSqlValues();
535
+ $values = array();
536
+ $ids = array();
537
+
538
+ foreach($this->getValueIds() as $value => $id) {
539
+ if(!empty($sqlValues)) {
540
+ $values[] = array_search($value, $sqlValues);
541
+ }
542
+ else {
543
+ $values[] = $adapter->quote($value);
544
+ }
545
+ $ids[] = (int) $id;
546
+ }
547
+
548
+ $values = implode(', ', $values);
549
+ $ids = implode(', ', $ids);
550
+
551
+ return new Zend_Db_Expr("ELT(FIELD({value}, $values), $ids)");
552
+ }
553
+
554
+
555
+
556
+
557
+ public function getLastRecordTime()
558
+ {
559
+ $adapter = $this->_getWriteAdapter();
560
+
561
+ $select = $this->_select($this->_reportTable, 'report', 'MAX(`date`)');
562
+ $select->filter('report.campagin_id', $this->_options->getCampaignId());
563
+ $select->filter('report.dimension_id', $this->getDimensionId());
564
+
565
+ return $adapter->fetchOne($select);
566
+ }
567
+
568
+
569
+
570
+
571
+ }
app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension/Country.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Model_Report_Aggregator_Dimension_Country
26
+ extends Mzax_Emarketing_Model_Report_Aggregator_Dimension_Abstract
27
+ {
28
+
29
+ protected $_values;
30
+
31
+
32
+ public function getTitle()
33
+ {
34
+ return "country";
35
+ }
36
+
37
+
38
+
39
+ protected function _aggregate()
40
+ {
41
+ if(!$this->_options->getTrackerId()) {
42
+ $this->aggregateSendings();
43
+ $this->aggregateEvent(Mzax_Emarketing_Model_Recipient::EVENT_TYPE_VIEW, 'views');
44
+ $this->aggregateEvent(Mzax_Emarketing_Model_Recipient::EVENT_TYPE_CLICK, 'clicks');
45
+ }
46
+
47
+ }
48
+
49
+
50
+
51
+ /**
52
+ * Add last available view event_id
53
+ * We don't have any useragent data available just by sending out
54
+ * an email. However we might have data from previous campaigns that we can borrow.
55
+ *
56
+ * We use the address ID to search crosswide around all address
57
+ *
58
+ * @todo Add a time limit so we don't use to old data
59
+ * @param Mzax_Emarketing_Db_Select $select
60
+ */
61
+ protected function joinLastViewEvent(Mzax_Emarketing_Db_Select $select, $type = Mzax_Emarketing_Model_Recipient::EVENT_TYPE_VIEW)
62
+ {
63
+ if($select->hasAnyBindings('country_id')) {
64
+ return;
65
+ }
66
+
67
+ $select->joinTable('address_id', 'recipient_address', 'address');
68
+ $select->joinTable(array('event_id' => '`address`.`view_id`'), 'recipient_event', 'event');
69
+
70
+ $select->addBinding('event_id', 'event.event_id');
71
+ $select->addBinding('country_id', 'event.country_id');
72
+ }
73
+
74
+
75
+
76
+
77
+ protected function getAggregateSendingsSelect()
78
+ {
79
+ // @todo this needs to be tested
80
+ $select = parent::getAggregateSendingsSelect();
81
+ $this->joinLastViewEvent($select);
82
+
83
+ return $select;
84
+ }
85
+
86
+
87
+
88
+ protected function getAggregateEventSelect($eventType, $fieldName)
89
+ {
90
+ $select = parent::getAggregateEventSelect($eventType, $fieldName);
91
+ $select->where('`event`.`country_id` IS NOT NULL');
92
+
93
+ return $select;
94
+ }
95
+
96
+
97
+
98
+
99
+
100
+ public function getValues()
101
+ {
102
+ if(!$this->_values) {
103
+ $select = $this->_select('recipient_event', 'event', 'country_id')->distinct();
104
+ $this->_values = $this->_getWriteAdapter()->fetchCol($select);
105
+ $this->_values = array_filter($this->_values);
106
+ }
107
+ return $this->_values;
108
+ }
109
+
110
+
111
+
112
+
113
+
114
+ protected function prepareAggregationSelect(Mzax_Emarketing_Db_Select $select)
115
+ {
116
+ $select->addBinding('value', 'event.country_id');
117
+ }
118
+
119
+
120
+
121
+
122
+ }
app/code/community/Mzax/Emarketing/Model/Report/Aggregator/Dimension/Dayofweek.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mzax Emarketing (www.mzax.de)
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with Magento in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @version 0.2.5
16
+ * @category Mzax
17
+ * @package Mzax_Emarketing
18
+ * @author Jacob Siefer (jacob@mzax.de)
19
+ * @copyright Copyright (c) 2015 Jacob Siefer
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+
25
+ class Mzax_Emarketing_Model_Report_Aggregator_Dimension_Dayofweek
26
+ extends Mzax_Emarketing_Model_Report_Aggregator_Dimension_Abstract
27
+ {
28
+
29
+
30
+
31
+ public function getTitle()
32
+ {
33
+ return "dayofweek";
34
+ }
35
+
36
+
37
+ public function getValues()
38
+ {
39
+ return array('Monday', 'Thuesday', 'Wednesday',
40
+ 'Thursday', 'Friday', 'Saturday', 'Sunday');
41
+ }
42
+
43
+
44
+
45
+ public function getSqlValues()
46
+ {
47
+ return array(
48
+ '2' => 'Monday',
49
+ '3' => 'Thuesday',
50
+ '4' => 'Wednesday',
51
+ '5' => 'Thursday',
52
+ '6' => 'Friday',
53
+ '7' => 'Saturday',
54
+ '1' => 'Sunday'
55
+ );
56
+ }
57
+
58
+
59
+
60
+
61
+ protected function prepareAggregationSelect(Mzax_Emarketing_Db_Select $select)
62
+ {
63
+ $select->addBinding('value', 'DAYOFWEEK({local_date})');
64
+ }
65
+
66
+
67
+
68
+
69
+
70
+
71
+ }