Mzax_Emarketing - Version 0.5.0

Version Notes

Find help at https://github.com/mage-mzax/emarketing

Download this release

Release Info

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


Code changes from version 0.4.10 to 0.5.0

Files changed (204) hide show
  1. LICENSE +0 -48
  2. app/code/community/Mzax/Emarketing/Block/Campaign/Edit.php +80 -61
  3. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Form.php +20 -8
  4. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Abstract.php +16 -26
  5. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email.php +62 -109
  6. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Inbox.php +18 -21
  7. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Outbox.php +47 -31
  8. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content.php +58 -91
  9. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Original.php +21 -27
  10. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Variation.php +21 -32
  11. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Errors.php +48 -44
  12. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Filters.php +20 -22
  13. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Inbox.php +32 -18
  14. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Medium.php +42 -46
  15. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients.php +43 -38
  16. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients/Grid.php +34 -41
  17. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Report.php +184 -195
  18. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Settings.php +163 -100
  19. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Tasks.php +20 -14
  20. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Test.php +11 -19
  21. app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tabs.php +78 -53
  22. app/code/community/Mzax/Emarketing/Block/Campaign/Grid.php +91 -68
  23. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Filter/Filter.php +23 -17
  24. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Action.php +14 -8
  25. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Filter.php +30 -24
  26. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/SendMail.php +15 -7
  27. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Sender.php +23 -14
  28. app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Stats.php +32 -24
  29. app/code/community/Mzax/Emarketing/Block/Campaign/New.php +21 -23
  30. app/code/community/Mzax/Emarketing/Block/Campaign/New/Presets.php +15 -14
  31. app/code/community/Mzax/Emarketing/Block/Campaign/Preview.php +78 -82
  32. app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail.php +20 -15
  33. app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail/Form.php +98 -28
  34. app/code/community/Mzax/Emarketing/Block/Campaign/Test.php +20 -25
  35. app/code/community/Mzax/Emarketing/Block/Campaign/Test/Emulate.php +53 -66
  36. app/code/community/Mzax/Emarketing/Block/Campaign/View.php +10 -11
  37. app/code/community/Mzax/Emarketing/Block/Chart/Abstract.php +189 -140
  38. app/code/community/Mzax/Emarketing/Block/Chart/Area.php +11 -11
  39. app/code/community/Mzax/Emarketing/Block/Chart/Bar.php +10 -10
  40. app/code/community/Mzax/Emarketing/Block/Chart/Column.php +10 -10
  41. app/code/community/Mzax/Emarketing/Block/Chart/Geo.php +10 -10
  42. app/code/community/Mzax/Emarketing/Block/Chart/Line.php +11 -11
  43. app/code/community/Mzax/Emarketing/Block/Chart/Pie.php +11 -11
  44. app/code/community/Mzax/Emarketing/Block/Chart/Scatter.php +10 -10
  45. app/code/community/Mzax/Emarketing/Block/Chart/SteppedArea.php +10 -10
  46. app/code/community/Mzax/Emarketing/Block/Chart/Widget/Container.php +27 -25
  47. app/code/community/Mzax/Emarketing/Block/Chart/Widget/Geo.php +63 -65
  48. app/code/community/Mzax/Emarketing/Block/Chart/Widget/Tab.php +102 -98
  49. app/code/community/Mzax/Emarketing/Block/Conditions.php +24 -23
  50. app/code/community/Mzax/Emarketing/Block/Editable.php +21 -17
  51. app/code/community/Mzax/Emarketing/Block/Filter/Object/Grid.php +73 -74
  52. app/code/community/Mzax/Emarketing/Block/Filter/Test/Recursive.php +36 -38
  53. app/code/community/Mzax/Emarketing/Block/Filter/Test/Single.php +70 -70
  54. app/code/community/Mzax/Emarketing/Block/Filters.php +24 -24
  55. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Action.php +14 -24
  56. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Campaign.php +7 -17
  57. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Recipient.php +11 -20
  58. app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Size.php +20 -29
  59. app/code/community/Mzax/Emarketing/Block/Inbox/Email.php +51 -33
  60. app/code/community/Mzax/Emarketing/Block/Inbox/Email/Form.php +36 -54
  61. app/code/community/Mzax/Emarketing/Block/Inbox/Grid.php +85 -78
  62. app/code/community/Mzax/Emarketing/Block/Inbox/View.php +13 -13
  63. app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit.php +32 -18
  64. app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Form.php +14 -8
  65. app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Tab/Settings.php +8 -24
  66. app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Tab/Subscribers.php +32 -22
  67. app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Tabs.php +25 -17
  68. app/code/community/Mzax/Emarketing/Block/Newsletter/List/Grid.php +37 -20
  69. app/code/community/Mzax/Emarketing/Block/Newsletter/List/View.php +11 -11
  70. app/code/community/Mzax/Emarketing/Block/Outbox/Email.php +31 -28
  71. app/code/community/Mzax/Emarketing/Block/Outbox/Email/Form.php +39 -51
  72. app/code/community/Mzax/Emarketing/Block/Outbox/Grid.php +72 -85
  73. app/code/community/Mzax/Emarketing/Block/Outbox/View.php +13 -14
  74. app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Attribute.php +21 -27
  75. app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Object.php +21 -19
  76. app/code/community/Mzax/Emarketing/Block/Recipients/Grid.php +45 -60
  77. app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/DomainThreshold.php +9 -8
  78. app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/MailStorage.php +21 -21
  79. app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/Mandrill.php +33 -36
  80. app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/MandrillApi.php +74 -0
  81. app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/Sendgrid.php +33 -36
  82. app/code/community/Mzax/Emarketing/Block/Template.php +103 -121
  83. app/code/community/Mzax/Emarketing/Block/Template/Edit.php +32 -23
  84. app/code/community/Mzax/Emarketing/Block/Template/Edit/Form.php +24 -32
  85. app/code/community/Mzax/Emarketing/Block/Template/Grid.php +33 -13
  86. app/code/community/Mzax/Emarketing/Block/Template/Upload.php +13 -13
  87. app/code/community/Mzax/Emarketing/Block/Template/Upload/Form.php +21 -12
  88. app/code/community/Mzax/Emarketing/Block/Template/View.php +12 -11
  89. app/code/community/Mzax/Emarketing/Block/Tracker/Edit.php +40 -39
  90. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Form.php +14 -7
  91. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Conditions.php +15 -20
  92. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/GoalType.php +27 -41
  93. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Settings.php +40 -59
  94. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Tasks.php +15 -23
  95. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Test.php +9 -19
  96. app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tabs.php +30 -31
  97. app/code/community/Mzax/Emarketing/Block/Tracker/Grid.php +42 -25
  98. app/code/community/Mzax/Emarketing/Block/Tracker/New.php +21 -24
  99. app/code/community/Mzax/Emarketing/Block/Tracker/Test.php +16 -23
  100. app/code/community/Mzax/Emarketing/Block/Tracker/Test/Emulate.php +50 -63
  101. app/code/community/Mzax/Emarketing/Block/Tracker/Upload.php +11 -18
  102. app/code/community/Mzax/Emarketing/Block/Tracker/Upload/Form.php +24 -26
  103. app/code/community/Mzax/Emarketing/Block/Tracker/View.php +12 -12
  104. app/code/community/Mzax/Emarketing/Block/Unsubscribe.php +46 -31
  105. app/code/community/Mzax/Emarketing/Block/Widget/Form.php +60 -0
  106. app/code/community/Mzax/Emarketing/Controller/Admin/Action.php +60 -0
  107. app/code/community/Mzax/Emarketing/Db/Select.php +98 -99
  108. app/code/community/Mzax/Emarketing/Helper/Campaign.php +63 -67
  109. app/code/community/Mzax/Emarketing/Helper/Data.php +158 -149
  110. app/code/community/Mzax/Emarketing/Helper/Newsletter.php +17 -30
  111. app/code/community/Mzax/Emarketing/Helper/Request.php +43 -65
  112. app/code/community/Mzax/Emarketing/Helper/SqlFormatter.php +6 -7
  113. app/code/community/Mzax/Emarketing/Model/AbstractModel.php +42 -0
  114. app/code/community/Mzax/Emarketing/Model/Campaign.php +429 -480
  115. app/code/community/Mzax/Emarketing/Model/Campaign/Content.php +11 -16
  116. app/code/community/Mzax/Emarketing/Model/Campaign/Preset.php +37 -36
  117. app/code/community/Mzax/Emarketing/Model/Campaign/Variation.php +89 -110
  118. app/code/community/Mzax/Emarketing/Model/Config.php +51 -0
  119. app/code/community/Mzax/Emarketing/Model/Conversion/Goal.php +47 -63
  120. app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Abstract.php +80 -57
  121. app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Orders.php +66 -74
  122. app/code/community/Mzax/Emarketing/Model/Conversion/Select.php +28 -33
  123. app/code/community/Mzax/Emarketing/Model/Conversion/Tracker.php +139 -122
  124. app/code/community/Mzax/Emarketing/Model/DomainThrottle.php +134 -107
  125. app/code/community/Mzax/Emarketing/Model/Email.php +59 -60
  126. app/code/community/Mzax/Emarketing/Model/Factory.php +129 -0
  127. app/code/community/Mzax/Emarketing/Model/Form/Element/Ace.php +107 -105
  128. app/code/community/Mzax/Emarketing/Model/Form/Element/Credits.php +11 -9
  129. app/code/community/Mzax/Emarketing/Model/Form/Element/EmailEditor.php +40 -61
  130. app/code/community/Mzax/Emarketing/Model/Form/Element/Info.php +9 -6
  131. app/code/community/Mzax/Emarketing/Model/Form/Element/TemplateEditor.php +29 -38
  132. app/code/community/Mzax/Emarketing/Model/Form/Element/Textarea.php +10 -13
  133. app/code/community/Mzax/Emarketing/Model/Form/Element/Wildselect.php +7 -16
  134. app/code/community/Mzax/Emarketing/Model/Goal.php +22 -35
  135. app/code/community/Mzax/Emarketing/Model/Inbox.php +40 -38
  136. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Abstract.php +5 -11
  137. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Recipient.php +71 -93
  138. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Store.php +28 -35
  139. app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Unsubscribe.php +19 -30
  140. app/code/community/Mzax/Emarketing/Model/Inbox/Email.php +157 -185
  141. app/code/community/Mzax/Emarketing/Model/Inbox/Email/Collector.php +19 -39
  142. app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Abstract.php +34 -18
  143. app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Storage.php +67 -101
  144. app/code/community/Mzax/Emarketing/Model/Link.php +32 -40
  145. app/code/community/Mzax/Emarketing/Model/Link/Reference.php +174 -179
  146. app/code/community/Mzax/Emarketing/Model/Medium.php +39 -64
  147. app/code/community/Mzax/Emarketing/Model/Medium/Abstract.php +41 -41
  148. app/code/community/Mzax/Emarketing/Model/Medium/Email.php +82 -116
  149. app/code/community/Mzax/Emarketing/Model/Medium/Email/Composer.php +279 -245
  150. app/code/community/Mzax/Emarketing/Model/Medium/Email/Filter.php +76 -96
  151. app/code/community/Mzax/Emarketing/Model/Medium/Email/FullCache.php +82 -0
  152. app/code/community/Mzax/Emarketing/Model/Medium/Email/Processor.php +169 -140
  153. app/code/community/Mzax/Emarketing/Model/Medium/Email/Snippets.php +48 -32
  154. app/code/community/Mzax/Emarketing/Model/Newsletter/List.php +55 -50
  155. app/code/community/Mzax/Emarketing/Model/Newsletter/List/Subscriber.php +16 -20
  156. app/code/community/Mzax/Emarketing/Model/Object/Abstract.php +84 -125
  157. app/code/community/Mzax/Emarketing/Model/Object/Address.php +28 -26
  158. app/code/community/Mzax/Emarketing/Model/Object/Collection.php +75 -92
  159. app/code/community/Mzax/Emarketing/Model/Object/Collection/Item.php +11 -19
  160. app/code/community/Mzax/Emarketing/Model/Object/Customer.php +54 -54
  161. app/code/community/Mzax/Emarketing/Model/Object/Customer/Address.php +32 -34
  162. app/code/community/Mzax/Emarketing/Model/Object/Filter.php +46 -64
  163. app/code/community/Mzax/Emarketing/Model/Object/Filter/Abstract.php +584 -611
  164. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/City.php +15 -23
  165. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Country.php +24 -30
  166. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Postcode.php +15 -23
  167. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Region.php +16 -23
  168. app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Street.php +16 -23
  169. app/code/community/Mzax/Emarketing/Model/Object/Filter/Attribute.php +190 -199
  170. app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Goal.php +50 -55
  171. app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Abstract.php +10 -12
  172. app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Interact.php +13 -17
  173. app/code/community/Mzax/Emarketing/Model/Object/Filter/Column.php +101 -109
  174. app/code/community/Mzax/Emarketing/Model/Object/Filter/Combine.php +68 -64
  175. app/code/community/Mzax/Emarketing/Model/Object/Filter/Component.php +337 -301
  176. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Abstract.php +10 -12
  177. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address.php +63 -84
  178. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address/Attribute.php +12 -18
  179. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Attribute.php +22 -20
  180. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Event.php +81 -120
  181. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Lastlogin.php +31 -29
  182. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Name.php +22 -18
  183. app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Order.php +55 -88
  184. app/code/community/Mzax/Emarketing/Model/Object/Filter/Main.php +42 -57
  185. app/code/community/Mzax/Emarketing/Model/Object/Filter/Newsletter.php +142 -78
  186. app/code/community/Mzax/Emarketing/Model/Object/Filter/Newsletter/List.php +103 -39
  187. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Abstract.php +9 -16
  188. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Address.php +43 -63
  189. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Campaign.php +82 -108
  190. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Abstract.php +9 -16
  191. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Table.php +46 -63
  192. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Items.php +51 -69
  193. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Previous.php +58 -80
  194. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/ShippedAt.php +36 -32
  195. app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Table.php +51 -50
  196. app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Abstract.php +10 -14
  197. app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Attribute.php +32 -33
  198. app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Category.php +45 -60
  199. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Abstract.php +9 -16
  200. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Address.php +33 -72
  201. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Item/Table.php +44 -57
  202. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Items.php +51 -68
  203. app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Table.php +45 -44
  204. app/code/community/Mzax/Emarketing/Model/Object/Filter/Table.php +158 -195
LICENSE DELETED
@@ -1,48 +0,0 @@
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 CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,103 +16,120 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
22
  {
 
 
 
23
  public function __construct()
24
  {
25
  $this->_objectId = 'id';
26
-
27
  $this->_blockGroup = 'mzax_emarketing';
28
  $this->_controller = 'campaign';
29
-
30
  parent::__construct();
31
-
32
  $this->_updateButton('save', 'label', $this->__('Save Campaign'));
33
  $this->_updateButton('delete', 'label', $this->__('Delete Campaign'));
34
-
35
  }
36
 
37
-
 
 
 
 
38
  public function getHeaderCssClass()
39
  {
40
  return 'head-' . strtr($this->_controller, '_', '-');
41
  }
42
 
 
 
 
 
 
43
  public function getHeaderText()
44
  {
45
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
46
  $campaign = Mage::registry('current_campaign');
47
  if ($campaign->getId()) {
48
  $text = $this->htmlEscape($campaign->getName());
49
- if($campaign->isRunning()) {
50
  return '<span class="mzax-running"></span>' . $text;
51
  }
52
  return $text;
53
- }
54
- else {
55
- if($preset = $campaign->getPreset()) {
56
- return $this->__('New %s - %s campaign',
57
- Mage::getSingleton('mzax_emarketing/medium')->getOptionText($campaign->getData('medium')),
58
  $preset->getName());
59
- }
60
- else {
61
  return $this->__('New %s Campaign',
62
  Mage::getSingleton('mzax_emarketing/medium')->getOptionText($campaign->getData('medium')));
63
  }
64
  }
65
  }
66
 
 
 
 
 
 
67
  public function getValidationUrl()
68
  {
69
  return $this->getUrl('*/*/validate', array('_current'=>true));
70
  }
71
-
 
 
 
 
 
72
  protected function _prepareLayout()
73
  {
74
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
75
  $campaign = Mage::registry('current_campaign');
76
-
77
- $this->_addButton('save_and_continue', array(
78
  'label' => $this->__('Save And Continue Edit'),
79
  'onclick' => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
80
  'class' => 'save'
81
  ), 10);
82
-
83
-
84
- if($campaign->getId() && !$campaign->isArchived()) {
85
-
86
- if($campaign->isRunning()) {
87
-
88
- $this->_removeButton('save');
89
- $this->removeButton('delete');
90
-
91
- $this->_addButton('stop', array(
92
- 'label' => $this->__('STOP'),
93
- 'onclick' => "confirmSetLocation('{$this->__('Are you sure you want to stop this campaign?')}', '{$this->getUrl('*/*/stop', array('_current' => true))}')",
94
- 'class' => 'mzax-stop'
95
- ), 100, 0);
96
-
97
-
98
- $this->_addButton('save_and_continue', array(
99
- 'label' => $this->__('Save Changes'),
100
- 'onclick' => "saveAndContinueEdit('{$this->_getSaveAndContinueUrl()}', '{$this->__('Are you sure you want to apply those changes to this running campaign?')}')",
101
- 'class' => 'save'
102
- ), 10);
103
- }
104
- else {
105
- $this->_addButton('start', array(
106
- 'label' => $this->__('Start'),
107
- 'onclick' => "confirmSetLocation('{$this->__('Are you sure you want to start this campaign?')}', '{$this->getUrl('*/*/start', array('_current' => true))}')",
108
- 'class' => 'mzax-start'
109
- ), 100, 0);
110
- }
111
- }
112
-
113
- return parent::_prepareLayout();
114
  }
115
-
116
-
117
  /**
118
  * Get form action URL
119
  *
@@ -124,18 +140,21 @@ class Mzax_Emarketing_Block_Campaign_Edit extends Mage_Adminhtml_Block_Widget_Fo
124
  if ($this->hasFormActionUrl()) {
125
  return $this->getData('form_action_url');
126
  }
127
-
128
-
129
  return $this->getUrl('*/*/save');
130
  }
131
-
132
-
 
 
 
 
133
  protected function _getSaveAndContinueUrl()
134
  {
135
- return $this->getUrl('*/*/save', array(
136
  '_current' => true,
137
  'back' => 'edit',
138
- 'tab' => '{{tab_id}}'
139
  ));
140
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Block_Campaign_Edit
21
+ */
22
  class Mzax_Emarketing_Block_Campaign_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
23
  {
24
+ /**
25
+ * Mzax_Emarketing_Block_Campaign_Edit constructor.
26
+ */
27
  public function __construct()
28
  {
29
  $this->_objectId = 'id';
30
+
31
  $this->_blockGroup = 'mzax_emarketing';
32
  $this->_controller = 'campaign';
33
+
34
  parent::__construct();
35
+
36
  $this->_updateButton('save', 'label', $this->__('Save Campaign'));
37
  $this->_updateButton('delete', 'label', $this->__('Delete Campaign'));
 
38
  }
39
 
40
+ /**
41
+ * Retrieve header css classes
42
+ *
43
+ * @return string
44
+ */
45
  public function getHeaderCssClass()
46
  {
47
  return 'head-' . strtr($this->_controller, '_', '-');
48
  }
49
 
50
+ /**
51
+ * Retrieve header text
52
+ *
53
+ * @return string
54
+ */
55
  public function getHeaderText()
56
  {
57
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
58
  $campaign = Mage::registry('current_campaign');
59
  if ($campaign->getId()) {
60
  $text = $this->htmlEscape($campaign->getName());
61
+ if ($campaign->isRunning()) {
62
  return '<span class="mzax-running"></span>' . $text;
63
  }
64
  return $text;
65
+ } else {
66
+ if ($preset = $campaign->getPreset()) {
67
+ return $this->__('New %s - %s campaign',
68
+ Mage::getSingleton('mzax_emarketing/medium')->getOptionText($campaign->getData('medium')),
 
69
  $preset->getName());
70
+ } else {
 
71
  return $this->__('New %s Campaign',
72
  Mage::getSingleton('mzax_emarketing/medium')->getOptionText($campaign->getData('medium')));
73
  }
74
  }
75
  }
76
 
77
+ /**
78
+ * Retrieve validation url
79
+ *
80
+ * @return string
81
+ */
82
  public function getValidationUrl()
83
  {
84
  return $this->getUrl('*/*/validate', array('_current'=>true));
85
  }
86
+
87
+ /**
88
+ * Prepare layout
89
+ *
90
+ * @return Mage_Core_Block_Abstract
91
+ */
92
  protected function _prepareLayout()
93
  {
94
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
95
  $campaign = Mage::registry('current_campaign');
96
+
97
+ $this->_addButton('save_and_continue', array(
98
  'label' => $this->__('Save And Continue Edit'),
99
  'onclick' => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
100
  'class' => 'save'
101
  ), 10);
102
+
103
+
104
+ if ($campaign->getId() && !$campaign->isArchived()) {
105
+ if ($campaign->isRunning()) {
106
+ $this->_removeButton('save');
107
+ $this->removeButton('delete');
108
+
109
+ $this->_addButton('stop', array(
110
+ 'label' => $this->__('STOP'),
111
+ 'onclick' => "confirmSetLocation('{$this->__('Are you sure you want to stop this campaign?')}', '{$this->getUrl('*/*/stop', array('_current' => true))}')",
112
+ 'class' => 'mzax-stop'
113
+ ), 100, 0);
114
+
115
+
116
+ $this->_addButton('save_and_continue', array(
117
+ 'label' => $this->__('Save Changes'),
118
+ 'onclick' => "saveAndContinueEdit('{$this->_getSaveAndContinueUrl()}', '{$this->__('Are you sure you want to apply those changes to this running campaign?')}')",
119
+ 'class' => 'save'
120
+ ), 10);
121
+ } else {
122
+ $this->_addButton('start', array(
123
+ 'label' => $this->__('Start'),
124
+ 'onclick' => "confirmSetLocation('{$this->__('Are you sure you want to start this campaign?')}', '{$this->getUrl('*/*/start', array('_current' => true))}')",
125
+ 'class' => 'mzax-start'
126
+ ), 100, 0);
127
+ }
128
+ }
129
+
130
+ return parent::_prepareLayout();
 
 
 
131
  }
132
+
 
133
  /**
134
  * Get form action URL
135
  *
140
  if ($this->hasFormActionUrl()) {
141
  return $this->getData('form_action_url');
142
  }
143
+
 
144
  return $this->getUrl('*/*/save');
145
  }
146
+
147
+ /**
148
+ * Retrieve save and continue url
149
+ *
150
+ * @return string
151
+ */
152
  protected function _getSaveAndContinueUrl()
153
  {
154
+ return $this->getUrl('*/*/save', array(
155
  '_current' => true,
156
  'back' => 'edit',
157
+ 'tab' => '{{tab_id}}'
158
  ));
159
  }
160
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,24 +17,37 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
 
 
 
 
24
  protected function _prepareForm()
25
  {
26
- $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
 
 
 
 
 
 
27
 
28
  $campaign = Mage::registry('current_campaign');
29
-
30
  if ($campaign->getId()) {
31
  $form->addField('campaign_id', 'hidden', array(
32
  'name' => 'campaign_id',
33
  'value' => $campaign->getId()
34
  ));
35
  }
36
-
37
  $form->setUseContainer(true);
38
  $this->setForm($form);
 
39
  return parent::_prepareForm();
40
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Form
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * Prepare form
27
+ *
28
+ * @return Mage_Adminhtml_Block_Widget_Form
29
+ */
30
  protected function _prepareForm()
31
  {
32
+ $form = new Varien_Data_Form(
33
+ array(
34
+ 'id' => 'edit_form',
35
+ 'action' => $this->getData('action'),
36
+ 'method' => 'post'
37
+ )
38
+ );
39
 
40
  $campaign = Mage::registry('current_campaign');
 
41
  if ($campaign->getId()) {
42
  $form->addField('campaign_id', 'hidden', array(
43
  'name' => 'campaign_id',
44
  'value' => $campaign->getId()
45
  ));
46
  }
47
+
48
  $form->setUseContainer(true);
49
  $this->setForm($form);
50
+
51
  return parent::_prepareForm();
52
  }
53
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,53 +16,44 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract extends Mage_Adminhtml_Block_Widget_Form
21
  {
22
-
23
- protected function _prepareLayout()
24
- {
25
- parent::_prepareLayout();
26
- }
27
-
28
-
29
  /**
30
  * Retrieve current campaign
31
- *
32
  * @return Mzax_Emarketing_Model_Campaign
33
  */
34
  public function getCampaign()
35
  {
36
  return Mage::registry('current_campaign');
37
  }
38
-
39
-
40
  /**
41
  * Retrieve campaign content
42
- * Usally the campaign it self or a variation object
43
- *
44
  * @return Mzax_Emarketing_Model_Campaign_Content
45
  */
46
  public function getContent()
47
  {
48
  return $this->getData('content');
49
  }
50
-
51
-
52
  /**
53
- *
54
  * @param Varien_Data_Form $form
55
- * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
 
56
  */
57
  public function initForm(Varien_Data_Form $form)
58
  {
59
  $this->setForm($form);
60
  $this->_prepareForm();
 
61
  return $this;
62
  }
63
-
64
-
65
-
66
-
67
-
68
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract extends Mage_Adminhtml_Block_Widget_Form
24
  {
 
 
 
 
 
 
 
25
  /**
26
  * Retrieve current campaign
27
+ *
28
  * @return Mzax_Emarketing_Model_Campaign
29
  */
30
  public function getCampaign()
31
  {
32
  return Mage::registry('current_campaign');
33
  }
34
+
 
35
  /**
36
  * Retrieve campaign content
37
+ * Usually the campaign it self or a variation object
38
+ *
39
  * @return Mzax_Emarketing_Model_Campaign_Content
40
  */
41
  public function getContent()
42
  {
43
  return $this->getData('content');
44
  }
45
+
 
46
  /**
47
+ *
48
  * @param Varien_Data_Form $form
49
+ *
50
+ * @return $this
51
  */
52
  public function initForm(Varien_Data_Form $form)
53
  {
54
  $this->setForm($form);
55
  $this->_prepareForm();
56
+
57
  return $this;
58
  }
 
 
 
 
 
 
59
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,33 +16,35 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
21
  {
22
-
23
- protected function _prepareLayout()
24
- {
25
- parent::_prepareLayout();
26
- }
27
-
28
-
29
-
30
  protected function getTemplateOptions()
31
  {
32
- $templates = Mage::getResourceSingleton('mzax_emarketing/template_collection')->toOptionArray();
 
 
 
33
  array_unshift($templates, array(
34
- 'value' => '',
35
  'label' => $this->__('Choose a Template...')
36
  ));
37
-
38
  return $templates;
39
  }
40
-
41
-
42
-
43
  /**
44
  * Prepare form before rendering HTML
45
  *
46
- * @return Mage_Adminhtml_Block_Widget_Form
47
  */
48
  protected function _prepareForm()
49
  {
@@ -51,33 +52,33 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_B
51
  $campaign = $this->getCampaign();
52
  $content = $this->getContent();
53
  $data = $content->getMediumData();
54
-
55
-
56
-
57
- $fieldset = $form->addFieldset('email_fieldset', array(
58
- 'legend' => $this->__('Email'),
59
- 'class' => 'fieldset-wide',
60
- ));
61
-
 
62
  $fieldset->addType('editor', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_emailEditor'));
63
-
64
-
65
  $templateOptions = $this->getTemplateOptions();
66
-
67
-
68
  /* Stop if no template exist */
69
- if(count($templateOptions) === 1) {
70
-
71
  $fieldset->addField('template_note', 'note', array(
72
  'label' => $this->__('Template'),
73
  'class' => 'mzax-template-select',
74
  'text' => $this->__("Before you can create an email campaign, you need to setup at least one email template."),
75
  'after_element_html' => $this->__(' <a href="%s" target="_blank">Edit Templates</a>', $this->getUrl('*/emarketing_template')),
76
  ));
77
- return;
 
78
  }
79
-
80
-
81
  $fieldset->addField('designmode', 'select', array(
82
  'label' => $this->__('Design Mode'),
83
  'note' => $this->__("If design mode is disabled the WYSIWYG editor will be disabled and will not mess with your html code."),
@@ -88,7 +89,7 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_B
88
  ),
89
  'value' => '1'
90
  ));
91
-
92
  $template = $fieldset->addField('template_id', 'select', array(
93
  'name' => 'template_id',
94
  'required' => true,
@@ -99,32 +100,27 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_B
99
  'note' => $this->__("A template is required for sending out emails"),
100
  'after_element_html' => $this->__(' <a href="%s" target="_blank">Edit Templates</a>', $this->getUrl('*/emarketing_template')),
101
  ));
102
-
103
-
104
  $subject = $fieldset->addField('subject', 'text', array(
105
  'name' => 'subject',
106
  'required' => true,
107
  'label' => $this->__('Email Subject'),
108
  'title' => $this->__('Email Subject'),
109
  ));
110
-
111
-
112
-
113
-
114
  $urlParams = array('id' => $campaign->getId());
115
- if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
116
  $contentName = $content->getName();
117
  $urlParams['variation'] = $content->getId();
118
- }
119
- else {
120
  $contentName = $this->__('Original');
121
  }
122
-
123
  $quickSaveUrl = $this->getUrl('*/*/quicksave', $urlParams);
124
  $previewUrl = $this->getUrl('*/*/preview', $urlParams);
125
-
126
-
127
-
128
  $editorConfig = new Varien_Object();
129
  $editorConfig->setTranslator($this);
130
  $editorConfig->setFilesBrowserWindowUrl($this->getUrl('adminhtml/cms_wysiwyg_images/index'));
@@ -134,9 +130,9 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_B
134
  $editorConfig->setQuicksaveFields(array($subject, $template));
135
  $editorConfig->setTemplateField($template);
136
  $editorConfig->setEnableCkeditor($data->getDataSetDefault('designmode', 1));
137
-
138
-
139
- if($campaign->getId()) {
140
  $editorConfig->setButtons(array(
141
  array(
142
  'title' => $this->__('Quick Save'),
@@ -152,11 +148,10 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_B
152
  ),
153
  ));
154
  }
155
-
156
-
157
  $editorConfig->setSnippets($campaign->getSnippets());
158
-
159
-
160
  $editor = $fieldset->addField('body', 'editor', array(
161
  'name' => 'body',
162
  'label' => $this->__('Email Body'),
@@ -168,34 +163,28 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_B
168
  'config' => $editorConfig,
169
  'template' => Mage::getModel('mzax_emarketing/template')->load($data->getTemplateId())
170
  ));
171
-
172
-
173
  // Setting custom renderer for content field to remove label column
174
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
175
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
176
  $editor->setRenderer($renderer);
177
-
178
-
179
-
180
-
181
-
182
-
183
 
184
  $fieldset = $form->addFieldset('email_delay', array(
185
  'legend' => $this->__('Only send out emails at certain times'),
186
  'class' => 'fieldset-wide mzax-checkboxes',
187
  ));
188
  $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
189
-
190
  $hourOptions = array();
191
- for($i = 0; $i < 24; $i++) {
192
  $hourOptions[$i] = $this->__("%'.02d:00h", $i);
193
  }
194
-
195
  $fieldset->addField('info', 'info', array(
196
  '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.')
197
  ))->setRenderer($renderer);
198
-
199
 
200
 
201
  $fieldset->addField('day_filter_empty', 'hidden', array(
@@ -206,59 +195,23 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_B
206
  'name' => 'time_filter',
207
  'value' => '',
208
  ));
209
-
210
  $fieldset->addField('day_filter', 'checkboxes', array(
211
  'name' => 'day_filter[]',
212
  'label' => $this->__('Send only on selected weekdays'),
213
  'values' => Mage::app()->getLocale()->getOptionWeekdays(),
214
  'note' => $this->__("If nothing select, this filter is disabled.")
215
  ));
216
-
217
  $fieldset->addField('time_filter', 'checkboxes', array(
218
  'name' => 'time_filter[]',
219
  'label' => $this->__('Send only at selected hours'),
220
  'options' => $hourOptions,
221
  'note' => $this->__("If nothing select, this filter is disabled.")
222
  ));
223
-
224
-
225
-
226
-
227
-
228
- /*
229
-
230
-
231
- $fieldset = $form->addFieldset('email_advanced', array(
232
- 'legend' => $this->__('Advanced Options'),
233
- 'class' => 'fieldset-wide',
234
- ));
235
-
236
- $fieldset->addField('prerender', 'select', array(
237
- 'label' => $this->__('Pre-Render'),
238
- '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."),
239
- 'name' => 'prerender',
240
- 'options' => array(
241
- '0' => $this->__('Disabled'),
242
- '1' => $this->__('Enabled'),
243
- ),
244
- 'value' => '0'
245
- ));
246
-
247
-
248
- if($campaign === $content) {
249
- $subject = $fieldset->addField('forward_emails', 'text', array(
250
- 'name' => 'forward_emails',
251
- 'label' => $this->__('Forward Email'),
252
- 'note' => $this->__("All non-auto email replies will get forward to this email address."),
253
- ));
254
- }
255
-
256
- */
257
  $form->addValues($data->getData());
258
-
259
- return $this;
260
-
261
 
 
262
  }
263
-
264
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email extends Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
24
  {
25
+ /**
26
+ * Retrieve template options
27
+ *
28
+ * @return array
29
+ */
 
 
 
30
  protected function getTemplateOptions()
31
  {
32
+ /** @var Mzax_Emarketing_Model_Resource_Template_Collection $templateCollection */
33
+ $templateCollection = Mage::getResourceSingleton('mzax_emarketing/template_collection');
34
+
35
+ $templates = $templateCollection->toOptionArray();
36
  array_unshift($templates, array(
37
+ 'value' => '',
38
  'label' => $this->__('Choose a Template...')
39
  ));
40
+
41
  return $templates;
42
  }
43
+
 
 
44
  /**
45
  * Prepare form before rendering HTML
46
  *
47
+ * @return $this
48
  */
49
  protected function _prepareForm()
50
  {
52
  $campaign = $this->getCampaign();
53
  $content = $this->getContent();
54
  $data = $content->getMediumData();
55
+
56
+ $fieldset = $form->addFieldset(
57
+ 'email_fieldset',
58
+ array(
59
+ 'legend' => $this->__('Email'),
60
+ 'class' => 'fieldset-wide',
61
+ )
62
+ );
63
+
64
  $fieldset->addType('editor', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_emailEditor'));
65
+
66
+
67
  $templateOptions = $this->getTemplateOptions();
68
+
69
+
70
  /* Stop if no template exist */
71
+ if (count($templateOptions) === 1) {
 
72
  $fieldset->addField('template_note', 'note', array(
73
  'label' => $this->__('Template'),
74
  'class' => 'mzax-template-select',
75
  'text' => $this->__("Before you can create an email campaign, you need to setup at least one email template."),
76
  'after_element_html' => $this->__(' <a href="%s" target="_blank">Edit Templates</a>', $this->getUrl('*/emarketing_template')),
77
  ));
78
+
79
+ return $this;
80
  }
81
+
 
82
  $fieldset->addField('designmode', 'select', array(
83
  'label' => $this->__('Design Mode'),
84
  'note' => $this->__("If design mode is disabled the WYSIWYG editor will be disabled and will not mess with your html code."),
89
  ),
90
  'value' => '1'
91
  ));
92
+
93
  $template = $fieldset->addField('template_id', 'select', array(
94
  'name' => 'template_id',
95
  'required' => true,
100
  'note' => $this->__("A template is required for sending out emails"),
101
  'after_element_html' => $this->__(' <a href="%s" target="_blank">Edit Templates</a>', $this->getUrl('*/emarketing_template')),
102
  ));
103
+
 
104
  $subject = $fieldset->addField('subject', 'text', array(
105
  'name' => 'subject',
106
  'required' => true,
107
  'label' => $this->__('Email Subject'),
108
  'title' => $this->__('Email Subject'),
109
  ));
110
+
111
+
 
 
112
  $urlParams = array('id' => $campaign->getId());
113
+ if ($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
114
  $contentName = $content->getName();
115
  $urlParams['variation'] = $content->getId();
116
+ } else {
 
117
  $contentName = $this->__('Original');
118
  }
119
+
120
  $quickSaveUrl = $this->getUrl('*/*/quicksave', $urlParams);
121
  $previewUrl = $this->getUrl('*/*/preview', $urlParams);
122
+
123
+
 
124
  $editorConfig = new Varien_Object();
125
  $editorConfig->setTranslator($this);
126
  $editorConfig->setFilesBrowserWindowUrl($this->getUrl('adminhtml/cms_wysiwyg_images/index'));
130
  $editorConfig->setQuicksaveFields(array($subject, $template));
131
  $editorConfig->setTemplateField($template);
132
  $editorConfig->setEnableCkeditor($data->getDataSetDefault('designmode', 1));
133
+
134
+
135
+ if ($campaign->getId()) {
136
  $editorConfig->setButtons(array(
137
  array(
138
  'title' => $this->__('Quick Save'),
148
  ),
149
  ));
150
  }
151
+
 
152
  $editorConfig->setSnippets($campaign->getSnippets());
153
+
154
+
155
  $editor = $fieldset->addField('body', 'editor', array(
156
  'name' => 'body',
157
  'label' => $this->__('Email Body'),
163
  'config' => $editorConfig,
164
  'template' => Mage::getModel('mzax_emarketing/template')->load($data->getTemplateId())
165
  ));
166
+
167
+
168
  // Setting custom renderer for content field to remove label column
169
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
170
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
171
  $editor->setRenderer($renderer);
172
+
 
 
 
 
 
173
 
174
  $fieldset = $form->addFieldset('email_delay', array(
175
  'legend' => $this->__('Only send out emails at certain times'),
176
  'class' => 'fieldset-wide mzax-checkboxes',
177
  ));
178
  $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
179
+
180
  $hourOptions = array();
181
+ for ($i = 0; $i < 24; $i++) {
182
  $hourOptions[$i] = $this->__("%'.02d:00h", $i);
183
  }
184
+
185
  $fieldset->addField('info', 'info', array(
186
  '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.')
187
  ))->setRenderer($renderer);
 
188
 
189
 
190
  $fieldset->addField('day_filter_empty', 'hidden', array(
195
  'name' => 'time_filter',
196
  'value' => '',
197
  ));
198
+
199
  $fieldset->addField('day_filter', 'checkboxes', array(
200
  'name' => 'day_filter[]',
201
  'label' => $this->__('Send only on selected weekdays'),
202
  'values' => Mage::app()->getLocale()->getOptionWeekdays(),
203
  'note' => $this->__("If nothing select, this filter is disabled.")
204
  ));
205
+
206
  $fieldset->addField('time_filter', 'checkboxes', array(
207
  'name' => 'time_filter[]',
208
  'label' => $this->__('Send only at selected hours'),
209
  'options' => $hourOptions,
210
  'note' => $this->__("If nothing select, this filter is disabled.")
211
  ));
212
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  $form->addValues($data->getData());
 
 
 
214
 
215
+ return $this;
216
  }
 
217
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Inbox.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,32 +17,33 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox extends Mzax_Emarketing_Block_Inbox_Grid
22
  {
23
-
24
-
25
  /**
26
- *
27
  * @var Mzax_Emarketing_Model_Campaign
28
  */
29
  protected $_campaign;
30
-
31
-
32
-
33
  /**
 
34
  *
35
  * @return Mzax_Emarketing_Model_Campaign
36
  */
37
  public function getCampaign()
38
  {
39
- if(!$this->_campaign) {
40
  $campaignId = (int) $this->getRequest()->getParam('id');
41
- $this->_campaign = Mage::getModel('mzax_emarketing/campaign')->load($campaignId);
 
 
42
  }
 
43
  return $this->_campaign;
44
  }
45
 
46
-
47
  /**
48
  * Apply campaign id
49
  *
@@ -52,9 +52,11 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox extends Mzax_Em
52
  protected function _prepareCollection()
53
  {
54
  $this->getCollection()->addFieldToFilter('campaign_id', $this->getCampaign()->getId());
 
55
  parent::_prepareCollection();
56
- }
57
 
 
 
58
 
59
  /**
60
  * Remove campaign column
@@ -65,12 +67,9 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox extends Mzax_Em
65
  {
66
  parent::_prepareColumns();
67
  $this->removeColumn('campaign');
68
-
69
  }
70
 
71
-
72
  /**
73
- *
74
  * @return string
75
  */
76
  public function getGridUrl()
@@ -78,10 +77,10 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox extends Mzax_Em
78
  return $this->getUrl('*/emarketing_inbox/campaignGrid', array('_current'=> true));
79
  }
80
 
81
-
82
  /**
83
  *
84
- * @param $row
 
85
  * @return string
86
  */
87
  public function getRowUrl($row)
@@ -89,8 +88,6 @@ class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox extends Mzax_Em
89
  return $this->getUrl('*/emarketing_inbox/email', array('id'=>$row->getId()));
90
  }
91
 
92
-
93
-
94
  /**
95
  * Make massaction js object public so it works for tabs
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Inbox extends Mzax_Emarketing_Block_Inbox_Grid
24
  {
 
 
25
  /**
 
26
  * @var Mzax_Emarketing_Model_Campaign
27
  */
28
  protected $_campaign;
29
+
 
 
30
  /**
31
+ * Retrieve campaign
32
  *
33
  * @return Mzax_Emarketing_Model_Campaign
34
  */
35
  public function getCampaign()
36
  {
37
+ if (!$this->_campaign) {
38
  $campaignId = (int) $this->getRequest()->getParam('id');
39
+
40
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign');
41
+ $this->_campaign->load($campaignId);
42
  }
43
+
44
  return $this->_campaign;
45
  }
46
 
 
47
  /**
48
  * Apply campaign id
49
  *
52
  protected function _prepareCollection()
53
  {
54
  $this->getCollection()->addFieldToFilter('campaign_id', $this->getCampaign()->getId());
55
+
56
  parent::_prepareCollection();
 
57
 
58
+ return $this;
59
+ }
60
 
61
  /**
62
  * Remove campaign column
67
  {
68
  parent::_prepareColumns();
69
  $this->removeColumn('campaign');
 
70
  }
71
 
 
72
  /**
 
73
  * @return string
74
  */
75
  public function getGridUrl()
77
  return $this->getUrl('*/emarketing_inbox/campaignGrid', array('_current'=> true));
78
  }
79
 
 
80
  /**
81
  *
82
+ * @param Mzax_Emarketing_Model_Inbox_Email $row
83
+ *
84
  * @return string
85
  */
86
  public function getRowUrl($row)
88
  return $this->getUrl('*/emarketing_inbox/email', array('id'=>$row->getId()));
89
  }
90
 
 
 
91
  /**
92
  * Make massaction js object public so it works for tabs
93
  *
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Medium/Email/Tab/Outbox.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,74 +17,91 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Outbox extends Mzax_Emarketing_Block_Outbox_Grid
22
  {
23
-
24
-
25
  /**
26
- *
27
  * @var Mzax_Emarketing_Model_Campaign
28
  */
29
  protected $_campaign;
30
-
31
-
32
-
33
  /**
34
- *
 
35
  * @return Mzax_Emarketing_Model_Campaign
36
  */
37
  public function getCampaign()
38
  {
39
- if(!$this->_campaign) {
40
  $campaignId = (int) $this->getRequest()->getParam('id');
41
- $this->_campaign = Mage::getModel('mzax_emarketing/campaign')->load($campaignId);
 
 
42
  }
 
43
  return $this->_campaign;
44
  }
45
-
46
-
47
-
 
 
 
48
  protected function _prepareCollection()
49
  {
50
  $this->getCollection()->addFieldToFilter('campaign_id', $this->getCampaign()->getId());
51
  parent::_prepareCollection();
 
 
52
  }
53
-
54
-
55
-
56
-
57
  protected function _prepareColumns()
58
  {
59
  parent::_prepareColumns();
60
  $this->removeColumn('campaign');
 
 
61
  }
62
-
63
-
64
 
 
 
 
65
  public function getGridUrl()
66
  {
67
  return $this->getUrl('*/*/campaignGrid', array('grid_ajax' => 1, '_current'=> true));
68
  }
69
-
 
 
 
 
 
70
  public function getRowUrl($row)
71
  {
72
  return $this->getUrl('*/emarketing_outbox/email', array('id'=>$row->getId()));
73
  }
74
-
75
-
76
-
 
77
  public function canDisplayContainer()
78
  {
79
- if($this->getRequest()->getParam('grid_ajax')) {
80
  return false;
81
  }
82
  return true;
83
  }
84
-
85
-
86
- protected function getAdditionalJavascript()
 
 
87
  {
88
  return "window.{$this->getId()}_massactionJsObject = {$this->getId()}_massactionJsObject;";
89
  }
90
-
91
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Outbox
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Medium_Email_Tab_Outbox extends Mzax_Emarketing_Block_Outbox_Grid
24
  {
 
 
25
  /**
 
26
  * @var Mzax_Emarketing_Model_Campaign
27
  */
28
  protected $_campaign;
29
+
 
 
30
  /**
31
+ * Retrieve campaign
32
+ *
33
  * @return Mzax_Emarketing_Model_Campaign
34
  */
35
  public function getCampaign()
36
  {
37
+ if (!$this->_campaign) {
38
  $campaignId = (int) $this->getRequest()->getParam('id');
39
+
40
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign');
41
+ $this->_campaign->load($campaignId);
42
  }
43
+
44
  return $this->_campaign;
45
  }
46
+
47
+ /**
48
+ * Prepare collection
49
+ *
50
+ * @return $this
51
+ */
52
  protected function _prepareCollection()
53
  {
54
  $this->getCollection()->addFieldToFilter('campaign_id', $this->getCampaign()->getId());
55
  parent::_prepareCollection();
56
+
57
+ return $this;
58
  }
59
+
60
+ /**
61
+ * @return $this
62
+ */
63
  protected function _prepareColumns()
64
  {
65
  parent::_prepareColumns();
66
  $this->removeColumn('campaign');
67
+
68
+ return $this;
69
  }
 
 
70
 
71
+ /**
72
+ * @return string
73
+ */
74
  public function getGridUrl()
75
  {
76
  return $this->getUrl('*/*/campaignGrid', array('grid_ajax' => 1, '_current'=> true));
77
  }
78
+
79
+ /**
80
+ * @param Mzax_Emarketing_Model_Outbox_Email $row
81
+ *
82
+ * @return string
83
+ */
84
  public function getRowUrl($row)
85
  {
86
  return $this->getUrl('*/emarketing_outbox/email', array('id'=>$row->getId()));
87
  }
88
+
89
+ /**
90
+ * @return bool
91
+ */
92
  public function canDisplayContainer()
93
  {
94
+ if ($this->getRequest()->getParam('grid_ajax')) {
95
  return false;
96
  }
97
  return true;
98
  }
99
+
100
+ /**
101
+ * @return string
102
+ */
103
+ protected function getAdditionalJavascript()
104
  {
105
  return "window.{$this->getId()}_massactionJsObject = {$this->getId()}_massactionJsObject;";
106
  }
 
107
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,181 +16,149 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content extends Mage_Adminhtml_Block_Widget_Tabs
22
  {
23
-
24
- /**
25
- *
26
- * @var string
27
- */
28
  const TAB_BLOCK_CAMPAIGN = 'mzax_emarketing/campaign_edit_tab_content_original';
29
-
30
- /**
31
- *
32
- * @var string
33
- */
34
  const TAB_BLOCK_VARIATION = 'mzax_emarketing/campaign_edit_tab_content_variation';
35
-
36
 
37
  /**
38
- * Initialize Tabs
39
- *
40
  */
41
  public function __construct()
42
  {
43
- /* @var $campaign Mzax_Emarketing_Model_Campaign */
44
- $campaign = Mage::registry('current_campaign');
45
-
46
  parent::__construct();
 
47
  $this->setId('campaign_email_tab');
48
  $this->setDestElementId('mzax_emarketing_info_tabs_content_content');
49
  $this->setTemplate('mzax/emarketing/campaign/content-tabs.phtml');
50
  $this->setCurrentTabId('mzax_emarketing_info_tabs_content');
51
  }
52
-
53
-
54
-
55
  /**
56
  * Prepare Layout Content
57
  *
58
- * @return Mage_Adminhtml_Block_Catalog_Category_Tabs
59
  */
60
  protected function _prepareLayout()
61
  {
62
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
63
  $campaign = Mage::registry('current_campaign');
64
-
65
- $tabId = 'mzax_emarketing_info_tabs_content';
66
-
67
-
68
  $this->addTab('original', array(
69
- 'label' => Mage::helper('mzax_emarketing')->__('Orignal'),
70
- 'content' => $campaign,
71
- 'active' => true,
72
  ));
73
-
74
 
75
- if(!$campaign->getId()) {
76
  $this->setDisabled(true);
77
- return;
78
  }
79
-
80
- $activeTab = (int) $this->getRequest()->getParam('variation');
81
-
82
  /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
83
- foreach($campaign->getVariations() as $variation)
84
- {
85
  $this->addTab('variation_' . $variation->getId(), array(
86
- 'label' => $variation->getName(),
87
- 'content' => $variation,
88
- 'active' => $activeTab == $variation->getId(),
89
  'remove_url' => $this->getRemoveUrl($variation)
90
  ));
91
  }
 
 
92
  }
93
-
94
-
95
-
96
-
97
  /**
98
  * Retrieve add variation url
99
- *
100
  * @return string
101
  */
102
  public function getAddUrl()
103
  {
104
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
105
  $campaign = Mage::registry('current_campaign');
106
-
107
  return $this->getUrl('*/*/addVariation', array(
108
  'id' => $campaign->getId(),
109
  'tab' => $this->getCurrentTabId()
110
  ));
111
  }
112
-
113
-
114
  /**
115
  * Retrieve delete variation url
116
- *
117
  * @param Mzax_Emarketing_Model_Campaign_Variation $variation
 
118
  * @return string
119
  */
120
  public function getRemoveUrl(Mzax_Emarketing_Model_Campaign_Variation $variation = null)
121
- {
122
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
123
  $campaign = Mage::registry('current_campaign');
124
-
125
  $params = array('id' => $campaign->getId(), 'tab' => $this->getCurrentTabId());
126
-
127
- if($variation) {
128
  $params['variation'] = $variation->getId();
129
- }
130
- else {
131
  $params['variation'] = 'all';
132
  }
133
-
134
  return $this->getUrl('*/*/deleteVariation', $params);
135
  }
136
-
137
-
138
-
139
-
140
  /**
141
- * (non-PHPdoc)
142
- * @see Mage_Adminhtml_Block_Widget_Tabs::getTabContent()
 
143
  */
144
  public function getTabContent($tab)
145
  {
146
  $content = $tab->getContent();
147
-
148
- if($content instanceof Mzax_Emarketing_Model_Campaign) {
149
  $content = $this->getLayout()
150
  ->createBlock(self::TAB_BLOCK_CAMPAIGN)
151
- ->setContent($content)
152
- ->initForm();
153
- }
154
- else if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
155
  $content = $this->getLayout()
156
  ->createBlock(self::TAB_BLOCK_VARIATION)
157
- ->setContent($content)
158
- ->initForm();
159
  }
160
-
161
- if($content instanceof Mage_Core_Block_Abstract) {
162
  $content = $content->toHtml();
163
  }
164
-
165
  return $content;
166
  }
167
-
168
-
169
-
170
-
171
  /**
172
- *
173
- *
174
- * @see Mage_Adminhtml_Block_Widget_Tabs::getTabClass()
175
  * @return string
176
  */
177
  public function getTabClass($tab)
178
  {
179
  $classes[] = parent::getTabClass($tab);
180
-
181
  $content = $tab->getContent();
182
- if($content instanceof Mzax_Emarketing_Model_Campaign) {
183
  $classes[] = "original";
184
  }
185
- if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
186
  $classes[] = "variation";
187
- if(!$content->getIsActive()) {
188
  $classes[] = "inactive";
189
  }
190
  }
191
  return implode(' ', $classes);
192
  }
193
-
194
-
195
-
196
-
197
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content
21
+ */
22
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content extends Mage_Adminhtml_Block_Widget_Tabs
23
  {
 
 
 
 
 
24
  const TAB_BLOCK_CAMPAIGN = 'mzax_emarketing/campaign_edit_tab_content_original';
 
 
 
 
 
25
  const TAB_BLOCK_VARIATION = 'mzax_emarketing/campaign_edit_tab_content_variation';
 
26
 
27
  /**
28
+ * Mzax_Emarketing_Block_Campaign_Edit_Tab_Content constructor.
 
29
  */
30
  public function __construct()
31
  {
 
 
 
32
  parent::__construct();
33
+
34
  $this->setId('campaign_email_tab');
35
  $this->setDestElementId('mzax_emarketing_info_tabs_content_content');
36
  $this->setTemplate('mzax/emarketing/campaign/content-tabs.phtml');
37
  $this->setCurrentTabId('mzax_emarketing_info_tabs_content');
38
  }
39
+
 
 
40
  /**
41
  * Prepare Layout Content
42
  *
43
+ * @return $this
44
  */
45
  protected function _prepareLayout()
46
  {
47
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
48
  $campaign = Mage::registry('current_campaign');
49
+
 
 
 
50
  $this->addTab('original', array(
51
+ 'label' => Mage::helper('mzax_emarketing')->__('Orignal'),
52
+ 'content' => $campaign,
53
+ 'active' => true,
54
  ));
 
55
 
56
+ if (!$campaign->getId()) {
57
  $this->setDisabled(true);
58
+ return $this;
59
  }
60
+
61
+ $activeTab = (int)$this->getRequest()->getParam('variation');
62
+
63
  /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
64
+ foreach ($campaign->getVariations() as $variation) {
 
65
  $this->addTab('variation_' . $variation->getId(), array(
66
+ 'label' => $variation->getName(),
67
+ 'content' => $variation,
68
+ 'active' => $activeTab == $variation->getId(),
69
  'remove_url' => $this->getRemoveUrl($variation)
70
  ));
71
  }
72
+
73
+ return $this;
74
  }
75
+
 
 
 
76
  /**
77
  * Retrieve add variation url
78
+ *
79
  * @return string
80
  */
81
  public function getAddUrl()
82
  {
83
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
84
  $campaign = Mage::registry('current_campaign');
85
+
86
  return $this->getUrl('*/*/addVariation', array(
87
  'id' => $campaign->getId(),
88
  'tab' => $this->getCurrentTabId()
89
  ));
90
  }
91
+
 
92
  /**
93
  * Retrieve delete variation url
94
+ *
95
  * @param Mzax_Emarketing_Model_Campaign_Variation $variation
96
+ *
97
  * @return string
98
  */
99
  public function getRemoveUrl(Mzax_Emarketing_Model_Campaign_Variation $variation = null)
100
+ {
101
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
102
  $campaign = Mage::registry('current_campaign');
103
+
104
  $params = array('id' => $campaign->getId(), 'tab' => $this->getCurrentTabId());
105
+
106
+ if ($variation) {
107
  $params['variation'] = $variation->getId();
108
+ } else {
 
109
  $params['variation'] = 'all';
110
  }
111
+
112
  return $this->getUrl('*/*/deleteVariation', $params);
113
  }
114
+
 
 
 
115
  /**
116
+ * @param Mage_Adminhtml_Block_Widget_Tab_Interface $tab
117
+ *
118
+ * @return string
119
  */
120
  public function getTabContent($tab)
121
  {
122
  $content = $tab->getContent();
123
+
124
+ if ($content instanceof Mzax_Emarketing_Model_Campaign) {
125
  $content = $this->getLayout()
126
  ->createBlock(self::TAB_BLOCK_CAMPAIGN)
127
+ ->setContent($content)
128
+ ->initForm();
129
+ } elseif ($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
 
130
  $content = $this->getLayout()
131
  ->createBlock(self::TAB_BLOCK_VARIATION)
132
+ ->setContent($content)
133
+ ->initForm();
134
  }
135
+
136
+ if ($content instanceof Mage_Core_Block_Abstract) {
137
  $content = $content->toHtml();
138
  }
139
+
140
  return $content;
141
  }
142
+
 
 
 
143
  /**
144
+ * @param Mage_Adminhtml_Block_Widget_Tab_Interface $tab
145
+ *
 
146
  * @return string
147
  */
148
  public function getTabClass($tab)
149
  {
150
  $classes[] = parent::getTabClass($tab);
151
+
152
  $content = $tab->getContent();
153
+ if ($content instanceof Mzax_Emarketing_Model_Campaign) {
154
  $classes[] = "original";
155
  }
156
+ if ($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
157
  $classes[] = "variation";
158
+ if (!$content->getIsActive()) {
159
  $classes[] = "inactive";
160
  }
161
  }
162
  return implode(' ', $classes);
163
  }
 
 
 
 
164
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Original.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,31 +16,28 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original extends Mage_Adminhtml_Block_Widget_Form
21
  {
22
-
23
- protected function _prepareLayout()
24
- {
25
- parent::_prepareLayout();
26
- }
27
-
28
-
29
-
30
  public function initForm()
31
  {
32
  $form = new Varien_Data_Form();
33
  $form->setHtmlIdPrefix('campaign_');
34
  $form->setFieldNameSuffix('campaign');
35
-
36
  $this->setForm($form);
37
-
38
  return $this;
39
  }
40
-
41
-
42
-
43
  /**
44
- *
45
  * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
46
  */
47
  public function getContentForm()
@@ -49,25 +45,23 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original extends Mage_Admi
49
  $form = new Varien_Data_Form();
50
  $form->setHtmlIdPrefix('campaign_mediumdata_');
51
  $form->setFieldNameSuffix('campaign[medium_data]');
52
-
53
  /* @var $mediumForm Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract */
54
  $mediumForm = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_medium_email');
55
  $mediumForm->setContent($this->getContent());
56
  $mediumForm->initForm($form);
57
-
58
  return $mediumForm;
59
  }
60
-
61
-
62
-
63
-
64
  public function getFormHtml()
65
  {
66
  $html = $this->getContentForm()->getFormHtml();
67
  $html.= parent::getFormHtml();
68
-
69
  return $html;
70
  }
71
-
72
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return $this
27
+ */
 
 
 
 
 
28
  public function initForm()
29
  {
30
  $form = new Varien_Data_Form();
31
  $form->setHtmlIdPrefix('campaign_');
32
  $form->setFieldNameSuffix('campaign');
33
+
34
  $this->setForm($form);
35
+
36
  return $this;
37
  }
38
+
 
 
39
  /**
40
+ *
41
  * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
42
  */
43
  public function getContentForm()
45
  $form = new Varien_Data_Form();
46
  $form->setHtmlIdPrefix('campaign_mediumdata_');
47
  $form->setFieldNameSuffix('campaign[medium_data]');
48
+
49
  /* @var $mediumForm Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract */
50
  $mediumForm = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_medium_email');
51
  $mediumForm->setContent($this->getContent());
52
  $mediumForm->initForm($form);
53
+
54
  return $mediumForm;
55
  }
56
+
57
+ /**
58
+ * @return string
59
+ */
60
  public function getFormHtml()
61
  {
62
  $html = $this->getContentForm()->getFormHtml();
63
  $html.= parent::getFormHtml();
64
+
65
  return $html;
66
  }
 
 
67
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Content/Variation.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,16 +17,12 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Variation
22
  extends Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original
23
  {
24
-
25
- protected function _prepareLayout()
26
- {
27
- parent::_prepareLayout();
28
- }
29
-
30
-
31
  /**
32
  *
33
  * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
@@ -35,36 +30,34 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Variation
35
  public function getContentForm()
36
  {
37
  $variation = $this->getContent();
38
-
39
-
40
  $form = new Varien_Data_Form();
41
  $form->setHtmlIdPrefix("variation_medium_{$variation->getId()}_");
42
  $form->setFieldNameSuffix("variation[{$variation->getId()}][medium_data]");
43
-
44
  /* @var $mediumForm Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract */
45
  $mediumForm = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_medium_email');
46
  $mediumForm->setContent($this->getContent());
47
  $mediumForm->initForm($form);
48
-
49
  return $mediumForm;
50
  }
51
-
52
-
53
-
54
-
55
  public function initForm()
56
  {
57
  parent::initForm();
58
-
59
  $form = $this->getForm();
60
-
61
  /* @var $content Mzax_Emarketing_Model_Campaign_Content */
62
  $variation = $this->getContent();
63
-
64
  $form->setHtmlIdPrefix("variation_{$variation->getId()}_");
65
  $form->setFieldNameSuffix("variation[{$variation->getId()}]");
66
-
67
-
68
 
69
  /*
70
  * Variation
@@ -73,8 +66,7 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Variation
73
  'legend' => $this->__('Settings'),
74
  'class' => 'fieldset-wide',
75
  ));
76
-
77
-
78
  $fieldset->addField('is_active', 'select', array(
79
  'label' => $this->__('Is Active'),
80
  'title' => $this->__('Is Active'),
@@ -86,19 +78,16 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Variation
86
  ),
87
  'value' => '1'
88
  ));
89
-
90
-
91
  $fieldset->addField('name', 'text', array(
92
  'name' => 'name',
93
  'required' => true,
94
  'label' => $this->__('Name'),
95
  'title' => $this->__('Name'),
96
  ));
97
-
98
  $form->addValues($variation->getData());
99
-
100
- return $this;
101
-
102
 
 
103
  }
104
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Variation
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Variation
24
  extends Mzax_Emarketing_Block_Campaign_Edit_Tab_Content_Original
25
  {
 
 
 
 
 
 
 
26
  /**
27
  *
28
  * @return Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract
30
  public function getContentForm()
31
  {
32
  $variation = $this->getContent();
33
+
 
34
  $form = new Varien_Data_Form();
35
  $form->setHtmlIdPrefix("variation_medium_{$variation->getId()}_");
36
  $form->setFieldNameSuffix("variation[{$variation->getId()}][medium_data]");
37
+
38
  /* @var $mediumForm Mzax_Emarketing_Block_Campaign_Edit_Medium_Abstract */
39
  $mediumForm = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_medium_email');
40
  $mediumForm->setContent($this->getContent());
41
  $mediumForm->initForm($form);
42
+
43
  return $mediumForm;
44
  }
45
+
46
+ /**
47
+ * @return $this
48
+ */
49
  public function initForm()
50
  {
51
  parent::initForm();
52
+
53
  $form = $this->getForm();
54
+
55
  /* @var $content Mzax_Emarketing_Model_Campaign_Content */
56
  $variation = $this->getContent();
57
+
58
  $form->setHtmlIdPrefix("variation_{$variation->getId()}_");
59
  $form->setFieldNameSuffix("variation[{$variation->getId()}]");
60
+
 
61
 
62
  /*
63
  * Variation
66
  'legend' => $this->__('Settings'),
67
  'class' => 'fieldset-wide',
68
  ));
69
+
 
70
  $fieldset->addField('is_active', 'select', array(
71
  'label' => $this->__('Is Active'),
72
  'title' => $this->__('Is Active'),
78
  ),
79
  'value' => '1'
80
  ));
81
+
 
82
  $fieldset->addField('name', 'text', array(
83
  'name' => 'name',
84
  'required' => true,
85
  'label' => $this->__('Name'),
86
  'title' => $this->__('Name'),
87
  ));
88
+
89
  $form->addValues($variation->getData());
 
 
 
90
 
91
+ return $this;
92
  }
93
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Errors.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,47 +16,51 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Errors extends Mage_Adminhtml_Block_Widget_Grid
29
  {
30
-
 
 
31
  public function __construct()
32
  {
33
  parent::__construct();
 
34
  $this->setId('recipient_error_grid');
35
  $this->setUseAjax(true);
36
  $this->setDefaultSort('created_at');
37
  $this->setDefaultDir('desc');
38
  }
39
-
40
-
41
-
42
-
43
 
 
 
 
 
 
44
  protected function _prepareCollection()
45
  {
46
  /* @var $collection Mzax_Emarketing_Model_Resource_Recipient_Error_Collection */
47
  $collection = Mage::getResourceModel('mzax_emarketing/recipient_error_collection');
48
-
49
- if($campaign = Mage::registry('current_campaign')) {
50
  $collection->addFieldToFilter('campaign_id', $campaign->getId());
51
  }
52
-
53
  $this->setCollection($collection);
54
-
55
- return parent::_prepareCollection();
 
 
56
  }
57
-
58
-
59
-
60
-
 
 
61
  protected function _prepareColumns()
62
  {
63
  $this->addColumn('created_at', array(
@@ -66,50 +69,51 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Errors extends Mage_Adminhtml_Bloc
66
  'gmtoffset' => true,
67
  'type' =>'datetime'
68
  ));
69
-
70
-
71
-
72
  $this->addColumn('recipient', array(
73
  'header' => $this->__('Recipient'),
74
  'index' => 'recipient_id'
75
  ));
76
-
77
-
78
  $this->addColumn('message', array(
79
  'header' => $this->__('Message'),
80
  'index' => 'message',
81
  'type' => 'text',
82
- 'getter' => function($row) {
83
  return nl2br($row->getMessage());
84
  },
85
  'truncate' => 500
86
  ));
87
-
88
-
89
-
90
- return parent::_prepareColumns();
91
  }
92
-
93
-
94
-
95
-
96
-
97
 
 
 
 
98
  public function getGridUrl()
99
  {
100
  return $this->getUrl('*/*/errorGrid', array('grid_ajax' => 1, '_current'=> true));
101
  }
102
-
 
 
 
 
 
103
  public function getRowUrl($row)
104
  {
105
  return null;
106
- //return $this->getUrl('*/emarketing_outbox/email', array('id'=>$row->getId()));
107
  }
108
-
109
-
 
 
110
  public function canDisplayContainer()
111
  {
112
- if($this->getRequest()->getParam('grid_ajax')) {
113
  return false;
114
  }
115
  return true;
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Errors
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Errors extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Campaign_Edit_Tab_Errors constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('recipient_error_grid');
33
  $this->setUseAjax(true);
34
  $this->setDefaultSort('created_at');
35
  $this->setDefaultDir('desc');
36
  }
 
 
 
 
37
 
38
+ /**
39
+ * Prepare collection
40
+ *
41
+ * @return $this
42
+ */
43
  protected function _prepareCollection()
44
  {
45
  /* @var $collection Mzax_Emarketing_Model_Resource_Recipient_Error_Collection */
46
  $collection = Mage::getResourceModel('mzax_emarketing/recipient_error_collection');
47
+
48
+ if ($campaign = Mage::registry('current_campaign')) {
49
  $collection->addFieldToFilter('campaign_id', $campaign->getId());
50
  }
51
+
52
  $this->setCollection($collection);
53
+
54
+ parent::_prepareCollection();
55
+
56
+ return $this;
57
  }
58
+
59
+ /**
60
+ * Prepare columns
61
+ *
62
+ * @return $this
63
+ */
64
  protected function _prepareColumns()
65
  {
66
  $this->addColumn('created_at', array(
69
  'gmtoffset' => true,
70
  'type' =>'datetime'
71
  ));
72
+
 
 
73
  $this->addColumn('recipient', array(
74
  'header' => $this->__('Recipient'),
75
  'index' => 'recipient_id'
76
  ));
77
+
 
78
  $this->addColumn('message', array(
79
  'header' => $this->__('Message'),
80
  'index' => 'message',
81
  'type' => 'text',
82
+ 'getter' => function ($row) {
83
  return nl2br($row->getMessage());
84
  },
85
  'truncate' => 500
86
  ));
87
+
88
+ parent::_prepareColumns();
89
+
90
+ return $this;
91
  }
 
 
 
 
 
92
 
93
+ /**
94
+ * @return string
95
+ */
96
  public function getGridUrl()
97
  {
98
  return $this->getUrl('*/*/errorGrid', array('grid_ajax' => 1, '_current'=> true));
99
  }
100
+
101
+ /**
102
+ * @param $row
103
+ *
104
+ * @return null
105
+ */
106
  public function getRowUrl($row)
107
  {
108
  return null;
 
109
  }
110
+
111
+ /**
112
+ * @return bool
113
+ */
114
  public function canDisplayContainer()
115
  {
116
+ if ($this->getRequest()->getParam('grid_ajax')) {
117
  return false;
118
  }
119
  return true;
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Filters.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,20 +17,23 @@
18
  */
19
 
20
 
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
24
-
 
25
  public function initForm()
26
  {
27
  $form = new Varien_Data_Form();
28
  $form->setHtmlIdPrefix('_mzax_emarketing');
29
  $form->setFieldNameSuffix('mzax_emarketing');
30
 
31
-
32
  $campaign = Mage::registry('current_campaign');
33
 
34
-
35
  $form->setHtmlIdPrefix('filter_');
36
 
37
  $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
@@ -40,25 +42,23 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters extends Mage_Adminhtml_Blo
40
  ->setNewFilterUrl($this->getUrl('*/*/newFilterHtml', array('campaign' => $campaign->getId())));
41
 
42
  $fieldset = $form->addFieldset('conditions_fieldset', array(
43
- 'legend'=>Mage::helper('salesrule')->__('Only send campaign to people matching the filters below')
44
  ))->setRenderer($renderer);
45
-
46
-
47
-
48
- $fieldset->addField('filters', 'text', array(
49
  'name' => 'filters',
50
  'label' => $this->__('Filters'),
51
  'title' => $this->__('Filters'),
52
- ))->setCampaign($campaign)
53
- ->setRenderer(Mage::getBlockSingleton('mzax_emarketing/filters'));
54
-
 
 
55
  $this->setForm($form);
56
-
57
- return $this;
58
-
59
 
 
60
  }
61
-
62
  /**
63
  * This method is called before rendering HTML
64
  *
@@ -68,6 +68,4 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters extends Mage_Adminhtml_Blo
68
  {
69
  return parent::_beforeToHtml();
70
  }
71
-
72
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+
21
+ /**
22
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters
23
+ */
24
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters extends Mage_Adminhtml_Block_Widget_Form
25
  {
26
+ /**
27
+ * @return $this
28
+ */
29
  public function initForm()
30
  {
31
  $form = new Varien_Data_Form();
32
  $form->setHtmlIdPrefix('_mzax_emarketing');
33
  $form->setFieldNameSuffix('mzax_emarketing');
34
 
 
35
  $campaign = Mage::registry('current_campaign');
36
 
 
37
  $form->setHtmlIdPrefix('filter_');
38
 
39
  $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
42
  ->setNewFilterUrl($this->getUrl('*/*/newFilterHtml', array('campaign' => $campaign->getId())));
43
 
44
  $fieldset = $form->addFieldset('conditions_fieldset', array(
45
+ 'legend' => $this->__('Only send campaign to people matching the filters below')
46
  ))->setRenderer($renderer);
47
+
48
+ $field = $fieldset->addField('filters', 'text', array(
 
 
49
  'name' => 'filters',
50
  'label' => $this->__('Filters'),
51
  'title' => $this->__('Filters'),
52
+ ));
53
+
54
+ $field->setCampaign($campaign);
55
+ $field->setRenderer(Mage::getBlockSingleton('mzax_emarketing/filters'));
56
+
57
  $this->setForm($form);
 
 
 
58
 
59
+ return $this;
60
  }
61
+
62
  /**
63
  * This method is called before rendering HTML
64
  *
68
  {
69
  return parent::_beforeToHtml();
70
  }
 
 
71
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Inbox.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,40 +17,55 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Inbox extends Mzax_Emarketing_Block_Inbox_Grid
22
  {
23
-
24
-
25
-
 
 
26
  protected function _prepareCollection()
27
  {
28
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
29
  $campaign = Mage::registry('current_campaign');
30
-
31
  $this->getCollection()->addFieldToFilter('campaign_id', $campaign->getId());
 
32
  parent::_prepareCollection();
 
 
33
  }
34
-
35
-
36
-
37
-
 
 
38
  protected function _prepareColumns()
39
  {
40
  parent::_prepareColumns();
41
  $this->removeColumn('campaign');
42
-
 
43
  }
44
-
45
-
46
 
 
 
 
47
  public function getGridUrl()
48
  {
49
  return $this->getUrl('*/*/bounces', array('_current'=> true));
50
  }
51
-
 
 
 
 
 
52
  public function getRowUrl($row)
53
  {
54
- return $this->getUrl('*/emarketing_inbox/email', array('id'=>$row->getId()));
55
  }
56
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Inbox
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Inbox extends Mzax_Emarketing_Block_Inbox_Grid
24
  {
25
+ /**
26
+ * Prepare collection
27
+ *
28
+ * @return $this
29
+ */
30
  protected function _prepareCollection()
31
  {
32
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
33
  $campaign = Mage::registry('current_campaign');
 
34
  $this->getCollection()->addFieldToFilter('campaign_id', $campaign->getId());
35
+
36
  parent::_prepareCollection();
37
+
38
+ return $this;
39
  }
40
+
41
+ /**
42
+ * Prepare columns
43
+ *
44
+ * @return $this
45
+ */
46
  protected function _prepareColumns()
47
  {
48
  parent::_prepareColumns();
49
  $this->removeColumn('campaign');
50
+
51
+ return $this;
52
  }
 
 
53
 
54
+ /**
55
+ * @return string
56
+ */
57
  public function getGridUrl()
58
  {
59
  return $this->getUrl('*/*/bounces', array('_current'=> true));
60
  }
61
+
62
+ /**
63
+ * @param $row
64
+ *
65
+ * @return string
66
+ */
67
  public function getRowUrl($row)
68
  {
69
+ return $this->getUrl('*/emarketing_inbox/email', array('id' => $row->getId()));
70
  }
 
71
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Medium.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,18 +17,19 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Medium extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
24
- protected function _prepareLayout()
25
- {
26
- parent::_prepareLayout();
27
- }
28
-
29
-
30
-
31
  public function initForm()
32
  {
 
 
 
33
  $form = new Varien_Data_Form();
34
  $form->setHtmlIdPrefix('campaign_');
35
  $form->setFieldNameSuffix('campaign');
@@ -37,12 +37,9 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Medium extends Mage_Adminhtml_Bloc
37
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
38
  $campaign = Mage::registry('current_campaign');
39
 
40
-
41
-
42
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
43
  ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
44
-
45
-
46
  /**
47
  * Campaign
48
  */
@@ -50,40 +47,39 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Medium extends Mage_Adminhtml_Bloc
50
  'legend' => $this->__('Campaign'),
51
  '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')
52
  ))->setRenderer($renderer);
53
-
54
 
55
- $fieldset->addField('name','text', array(
56
- 'name' => 'name',
57
- 'required' => true,
58
- 'label' => $this->__('Campaign Name'),
59
- 'title' => $this->__('Campaign Name'),
60
- ));
61
-
62
-
63
- $fieldset->addField('medium','select', array(
64
- 'name' => 'medium',
65
- 'label' => $this->__('Send Medium'),
66
- 'title' => $this->__('Send Medium'),
67
- 'values' => Mage::getSingleton('mzax_emarketing/medium')->getAllOptions(false),
68
- 'note' => $this->__('Which medium would you like to use to send out this campaign?'),
69
- 'required' => true,
70
- ));
71
-
72
-
73
-
74
- /**
75
- * Campaign
76
- */
77
- $fieldset = $form->addFieldset('presets', array(
 
 
 
78
  'legend' => $this->__('Campaign Presets'),
79
- ))->setRenderer($this->getLayout()->createBlock('mzax_emarketing/campaign_new_presets'));
80
-
81
-
82
  $form->addValues($campaign->getData());
83
  $this->setForm($form);
84
-
85
- return $this;
86
-
87
 
 
88
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Medium
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Medium extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return $this
27
+ */
 
 
 
 
 
28
  public function initForm()
29
  {
30
+ /** @var Mzax_Emarketing_Model_Medium $mediums */
31
+ $mediums = Mage::getSingleton('mzax_emarketing/medium');
32
+
33
  $form = new Varien_Data_Form();
34
  $form->setHtmlIdPrefix('campaign_');
35
  $form->setFieldNameSuffix('campaign');
37
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
38
  $campaign = Mage::registry('current_campaign');
39
 
 
 
40
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
41
  ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
42
+
 
43
  /**
44
  * Campaign
45
  */
47
  'legend' => $this->__('Campaign'),
48
  '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')
49
  ))->setRenderer($renderer);
 
50
 
51
+
52
+ $fieldset->addField(
53
+ 'name',
54
+ 'text',
55
+ array(
56
+ 'name' => 'name',
57
+ 'required' => true,
58
+ 'label' => $this->__('Campaign Name'),
59
+ 'title' => $this->__('Campaign Name'),
60
+ )
61
+ );
62
+
63
+ $fieldset->addField(
64
+ 'medium',
65
+ 'select',
66
+ array(
67
+ 'name' => 'medium',
68
+ 'label' => $this->__('Send Medium'),
69
+ 'title' => $this->__('Send Medium'),
70
+ 'values' => $mediums->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->addFieldset('presets', array(
77
  'legend' => $this->__('Campaign Presets'),
78
+ ))->setRenderer($this->getLayout()->createBlock('mzax_emarketing/campaign_new_presets'));
79
+
 
80
  $form->addValues($campaign->getData());
81
  $this->setForm($form);
 
 
 
82
 
83
+ return $this;
84
  }
85
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,82 +17,88 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients extends Mage_Adminhtml_Block_Template
22
  {
23
-
24
  /**
25
  * @var Mzax_Emarketing_Model_Campaign
26
  */
27
  protected $_campaign;
28
 
29
-
30
  /**
31
- * @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid
32
  */
33
- protected $_grid;
34
-
35
-
36
-
37
  public function _construct()
38
  {
39
  parent::_construct();
 
40
  $this->setTemplate('mzax/emarketing/campaign/recipients.phtml');
41
  }
42
-
43
-
44
-
 
45
  protected function _prepareLayout()
46
  {
 
 
 
 
47
  $emulate = $this->getLayout()->createBlock('mzax_emarketing/campaign_test_emulate');
48
  $emulate->setTemplate('mzax/emarketing/campaign/filters/emulate.phtml');
49
-
50
- $grid = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_recipients_grid');
51
-
52
  $this->setChild('emulate', $emulate);
53
  $this->setChild('grid', $grid);
 
 
54
  }
55
-
56
-
57
-
58
-
 
 
59
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
60
  {
61
  $child = $this->getChild('emulate');
62
- if($child && method_exists($child, 'prepareEmulation')) {
63
  $child->prepareEmulation($filter);
64
  }
65
  }
66
-
67
-
68
-
69
  /**
70
  * Retrieve grid
71
- *
72
  * @return Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid
73
  */
74
  public function getGrid()
75
  {
76
  return $this->getChild('grid');
77
  }
78
-
79
-
80
-
81
-
82
-
83
  /**
84
- *
85
  * @return Mzax_Emarketing_Model_Campaign
86
  */
87
  public function getCampaign()
88
  {
89
- if(!$this->_campaign) {
90
  $this->_campaign = Mage::registry('current_campaign');
91
  }
92
  return $this->_campaign;
93
  }
94
-
95
-
96
-
97
-
98
-
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients extends Mage_Adminhtml_Block_Template
24
  {
 
25
  /**
26
  * @var Mzax_Emarketing_Model_Campaign
27
  */
28
  protected $_campaign;
29
 
 
30
  /**
31
+ * @return void
32
  */
 
 
 
 
33
  public function _construct()
34
  {
35
  parent::_construct();
36
+
37
  $this->setTemplate('mzax/emarketing/campaign/recipients.phtml');
38
  }
39
+
40
+ /**
41
+ * @return $this
42
+ */
43
  protected function _prepareLayout()
44
  {
45
+ /** @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid */
46
+ $grid = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_recipients_grid');
47
+
48
+ /** @var Mzax_Emarketing_Block_Campaign_Test_Emulate $emulate */
49
  $emulate = $this->getLayout()->createBlock('mzax_emarketing/campaign_test_emulate');
50
  $emulate->setTemplate('mzax/emarketing/campaign/filters/emulate.phtml');
51
+ $emulate->setGrid($grid);
52
+
 
53
  $this->setChild('emulate', $emulate);
54
  $this->setChild('grid', $grid);
55
+
56
+ return $this;
57
  }
58
+
59
+ /**
60
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
61
+ *
62
+ * @return void
63
+ */
64
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
65
  {
66
  $child = $this->getChild('emulate');
67
+ if ($child && method_exists($child, 'prepareEmulation')) {
68
  $child->prepareEmulation($filter);
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
  * @return Mzax_Emarketing_Model_Campaign
85
  */
86
  public function getCampaign()
87
  {
88
+ if (!$this->_campaign) {
89
  $this->_campaign = Mage::registry('current_campaign');
90
  }
91
  return $this->_campaign;
92
  }
93
+
94
+ /**
95
+ * @return string
96
+ */
97
+ protected function _toHtml()
98
+ {
99
+ if ($this->getRequest()->getParam('emulate')) {
100
+ return $this->getGrid()->toHtml();
101
+ }
102
+ return parent::_toHtml();
103
+ }
104
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Recipients/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,91 +17,85 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid extends Mzax_Emarketing_Block_Filter_Object_Grid
22
  {
23
-
24
  /**
25
  * @var Mzax_Emarketing_Model_Campaign
26
  */
27
  protected $_campaign;
28
 
29
-
30
-
 
31
  public function __construct()
32
  {
33
  parent::__construct();
34
  $this->setId('recipients_grid');
35
  $this->setUseAjax(true);
36
-
37
  $this->addExportType('*/*/exportRecipients', 'CSV');
38
  }
39
-
40
-
41
 
42
  /**
43
  * @return Mzax_Emarketing_Model_Campaign
44
  */
45
  public function getCampaign()
46
  {
47
- if(!$this->_campaign) {
48
  $this->_campaign = Mage::registry('current_campaign');
49
  }
 
50
  return $this->_campaign;
51
  }
52
-
53
-
54
-
55
-
56
  public function getFilter()
57
  {
58
  $filter = $this->getCampaign()->getRecipientProvider();
59
  $this->prepareEmulation($filter);
60
-
61
  return $filter;
62
  }
63
-
64
-
65
-
 
66
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
67
  {
68
  $parent = $this->getParentBlock();
69
- if($parent && method_exists($parent, 'prepareEmulation')) {
 
70
  $parent->prepareEmulation($filter);
71
  }
72
  }
73
-
74
-
75
-
76
  /**
77
  * Prepare grid columns
78
- *
79
  * This is done by the email provider. The grid
80
  * does not know what type of objects it is loading
81
- *
82
  */
83
  protected function _prepareColumns()
84
- {
85
  parent::_prepareColumns();
86
-
87
  $this->removeColumn('matches');
88
  $this->getCampaign()->getMedium()->prepareRecipientGrid($this);
89
-
90
  return $this;
91
  }
92
-
93
-
94
-
95
- public function getGridUrl()
96
- {
97
- return $this->getUrl('*/*/*', array('_current' => true));
98
- }
99
 
100
-
101
- public function getAdditionalJavaScript()
 
 
102
  {
103
- $object = $this->getMassactionBlock()->getJsObjectName();
104
- return "window.{$object} = {$object};";
105
  }
106
-
107
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid extends Mzax_Emarketing_Block_Filter_Object_Grid
24
  {
 
25
  /**
26
  * @var Mzax_Emarketing_Model_Campaign
27
  */
28
  protected $_campaign;
29
 
30
+ /**
31
+ * Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid constructor.
32
+ */
33
  public function __construct()
34
  {
35
  parent::__construct();
36
  $this->setId('recipients_grid');
37
  $this->setUseAjax(true);
38
+
39
  $this->addExportType('*/*/exportRecipients', 'CSV');
40
  }
 
 
41
 
42
  /**
43
  * @return Mzax_Emarketing_Model_Campaign
44
  */
45
  public function getCampaign()
46
  {
47
+ if (!$this->_campaign) {
48
  $this->_campaign = Mage::registry('current_campaign');
49
  }
50
+
51
  return $this->_campaign;
52
  }
53
+
54
+ /**
55
+ * @return Mzax_Emarketing_Model_Recipient_Provider_Abstract
56
+ */
57
  public function getFilter()
58
  {
59
  $filter = $this->getCampaign()->getRecipientProvider();
60
  $this->prepareEmulation($filter);
61
+
62
  return $filter;
63
  }
64
+
65
+ /**
66
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
67
+ */
68
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
69
  {
70
  $parent = $this->getParentBlock();
71
+
72
+ if ($parent && method_exists($parent, 'prepareEmulation')) {
73
  $parent->prepareEmulation($filter);
74
  }
75
  }
76
+
 
 
77
  /**
78
  * Prepare grid columns
79
+ *
80
  * This is done by the email provider. The grid
81
  * does not know what type of objects it is loading
82
+ *
83
  */
84
  protected function _prepareColumns()
85
+ {
86
  parent::_prepareColumns();
87
+
88
  $this->removeColumn('matches');
89
  $this->getCampaign()->getMedium()->prepareRecipientGrid($this);
90
+
91
  return $this;
92
  }
 
 
 
 
 
 
 
93
 
94
+ /**
95
+ * @return string
96
+ */
97
+ public function getGridUrl()
98
  {
99
+ return $this->getUrl('*/*/recipientsGrid', array('_current' => true));
 
100
  }
 
 
101
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Report.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,31 +17,34 @@
18
  */
19
 
20
 
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.4.10
29
  */
30
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Block_Widget
31
  {
32
-
 
 
 
 
 
 
 
33
 
34
  /**
35
- *
36
  * @var Mzax_Emarketing_Model_Campaign
37
  */
38
  protected $_campaign;
39
 
40
-
 
 
41
  protected $_dateRange;
42
 
43
-
44
-
45
-
 
46
  protected function _construct()
47
  {
48
  parent::_construct();
@@ -51,8 +53,6 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
51
  $this->setTemplate('mzax/emarketing/campaign/report.phtml');
52
  }
53
 
54
-
55
-
56
  /**
57
  * Retrieve campaign
58
  *
@@ -60,17 +60,17 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
60
  */
61
  public function getCampaign()
62
  {
63
- if(!$this->_campaign) {
64
  $this->_campaign = Mage::registry('current_campaign');
65
  }
66
  return $this->_campaign;
67
  }
68
 
69
-
70
  /**
71
  * Set campaign
72
  *
73
  * @param Mzax_Emarketing_Model_Campaign $campaign
 
74
  * @return Mzax_Emarketing_Block_Campaign_Edit_Tab_Report
75
  */
76
  public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
@@ -79,8 +79,6 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
79
  return $this;
80
  }
81
 
82
-
83
-
84
  /**
85
  * Has campaign any trackers
86
  *
@@ -91,15 +89,14 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
91
  return (bool) count($this->getCampaign()->getTrackers());
92
  }
93
 
94
-
95
-
96
-
97
  /**
98
  * Query report data tables
99
  *
100
  * @param string $dimension
101
  * @param array $metrics
102
- * @param boolean $variation
 
 
103
  * @return Mzax_Emarketing_Model_Report_Query
104
  */
105
  public function queryReport($dimension, $metrics, $variations, $order = null)
@@ -110,8 +107,6 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
110
  return $query;
111
  }
112
 
113
-
114
-
115
  /**
116
  * Retrieve date range from request
117
  *
@@ -119,94 +114,82 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
119
  */
120
  public function getDateRange()
121
  {
122
- if($this->_dateRange === null) {
123
  $validator = new Zend_Validate_Date;
124
 
125
  $from = $this->getRequest()->getParam('from');
126
  $to = $this->getRequest()->getParam('to');
127
 
128
- if($validator->isValid($from) && $validator->isValid($to)) {
129
  $this->_dateRange = array($from, $to);
130
- }
131
- else {
132
  $this->_dateRange = false;
133
  }
134
  }
 
135
  return $this->_dateRange;
136
  }
137
 
138
-
139
-
140
  /**
141
- * Retreive query from local cache or create new
142
  *
143
  * @param string $key
144
  * @param string $dimension
145
  * @param array $metrics
146
- * @param boolean $variation
 
 
147
  * @return Mzax_Emarketing_Model_Report_Query
148
  */
149
  public function getCachedQuery($key, $dimension, $metrics, $variations, $order = null)
150
  {
151
  $query = $this->getData('query_' . $key);
152
- if(!$query) {
153
  $query = $this->queryReport($dimension, $metrics, $variations, $order);
154
  $this->setData('query_' . $key, $query);
155
  }
 
156
  return $query;
157
  }
158
 
159
-
160
-
161
-
162
-
163
  /**
164
  *
165
  * @return Mzax_Emarketing_Model_Report_Query
166
  */
167
  public function getTotals()
168
  {
169
- return $this->getCachedQuery('totals', 'campaign', array('sendings', 'views', 'clicks', 'bounces', 'optouts', 'conversion' => '#?'), false);
 
 
 
 
 
170
  }
171
 
172
-
173
-
174
-
175
-
176
-
177
  public function getTotal()
178
  {
179
  return (int) $this->getTotals()->getCell('sendings');
180
  }
181
 
182
-
183
- const COLOR_BLANK = 'E7EFEF';
184
- const COLOR_SENDINGS = '899DA8';
185
- const COLOR_VIEWS = '159FC4';
186
- const COLOR_CLICKS = 'D7D020';
187
- const COLOR_ORDERS = 'A9C200';
188
- const COLOR_CONVERSIONS = 'A9C200';
189
- const COLOR_OPTOUT = 'BF3A3A';
190
- const COLOR_BOUNDS = '712B2B';
191
-
192
-
193
-
194
-
195
-
196
  /**
197
  * Prepare chart data table by providing correct
198
  * column lables and colors
199
  *
200
  * @param Mzax_Chart_Table $table
 
 
201
  */
202
  public function prepareTable(Mzax_Chart_Table $table)
203
  {
204
  $variations = $table->getTableProperty('variations');
205
  $dimension = $table->getTableProperty('dimension');
206
 
207
- foreach($table->getColumns() as $column) {
208
- if(isset($column->p->metric)) {
209
- switch($column->p->metric) {
210
  case 'sendings':
211
  $column->label = $this->__('Recipients');
212
  $column->p->color = self::COLOR_SENDINGS;
@@ -233,55 +216,61 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
233
  break;
234
  }
235
  }
236
- if(isset($column->p->tracker_id)) {
237
  $tracker = $this->getCampaign()->getTracker($column->p->tracker_id);
238
- if($tracker) {
239
  $column->label = $tracker->getTitle();
240
- }
241
- else {
242
  $column->label = $this->__('Tracker (%s)', $column->p->tracker_id);
243
  }
244
  $column->p->color = self::COLOR_CLICKS;
245
  }
246
 
247
- if(isset($column->p->color)) {
248
  $column->p->color_axis = array($this->brightness($column->p->color, 80), $this->brightness($column->p->color, -80));
249
  }
250
 
251
- if(isset($column->p->variation_id)) {
252
  $vid = $column->p->variation_id;
253
 
254
  $index = array_search($vid, $variations);
255
 
256
  $gradient = $this->gradient(
257
- $this->brightness($column->p->color, -100),
258
- $this->brightness($column->p->color, 20),
259
- count($variations));
 
260
 
261
  $column->p->color = $gradient[$index];
262
 
263
  $variation = $this->getCampaign()->getVariation($vid);
264
- if($variation) {
265
  $column->label = $variation->getName();
266
- }
267
- else {
268
  $column->label = $this->__('Variation (%s)', $vid);
269
  }
270
  }
271
  }
272
 
273
- if($dimension !== 'date') {
274
- $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');
 
 
 
 
 
 
 
 
275
 
276
  //$table->addColumn('style', Mzax_Chart_Table::TYPE_STRING, 'style', array('role' => 'style'));
277
- foreach($colors as $row => $color) {
278
  $table->setRowProperty($row, 'color', $color);
279
  }
280
  $table->setTableProperty('dye', true);
281
  }
282
 
283
-
284
- switch(strtolower($dimension)) {
285
  case 'hour':
286
  $table->setColumnType(0, Mzax_Chart_Table::TYPE_TIME);
287
  $table->setTableProperty('stacked', true);
@@ -292,47 +281,56 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
292
  $table->setTableProperty('dye', false);
293
  break;
294
  }
295
-
296
-
297
  }
298
 
 
 
 
 
 
 
 
299
  protected function gradient($start, $end, $steps)
300
  {
301
  $steps = max($steps, 2);
302
  $start = array_map('hexdec', str_split($start, 2));
303
  $end = array_map('hexdec', str_split($end, 2));
304
 
305
- foreach($start as $j => $v) {
 
306
  $step[$j] = ($v - $end[$j]) / ($steps-1);
307
  }
308
 
309
  $colors = array();
310
- for($i = 0; $i <= $steps; $i++) {
311
  $rgb = array();
312
- foreach($step as $j => $v) {
313
  $rgb[$j] = sprintf('%02x', floor($start[$j] - $v * $i));
314
  }
315
  $colors[] = implode('', $rgb);
316
  }
 
317
  return $colors;
318
  }
319
 
320
-
321
-
 
 
 
 
322
  protected function brightness($color, $adjust)
323
  {
324
  $rgb = array_map('hexdec', str_split($color, 2));
325
- foreach($rgb as &$v) {
326
- $v = sprintf('%02x', max(0,min(255,$v + $adjust)));
327
  }
328
  return implode('', $rgb);
329
  }
330
 
331
-
332
-
333
-
334
-
335
-
336
  protected function getGoogleJs()
337
  {
338
  $locale = Mage::app()->getLocale()->getLocaleCode();
@@ -343,18 +341,16 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Bloc
343
  google.load("visualization", "1", {packages:["corechart"], language:'$locale'});
344
  </script>
345
  JS;
346
- return $this->getLayout()
347
- ->createBlock('core/text')->setText($js);
348
  }
349
 
350
-
351
-
352
-
353
  protected function _beforeToHtml()
354
  {
355
  parent::_beforeToHtml();
356
 
357
-
358
  $views = $this->createCircle('viewes', $this->getTotals()->getCell('views'), self::COLOR_VIEWS);
359
  $clicks = $this->createCircle('clicks', $this->getTotals()->getCell('clicks'), self::COLOR_CLICKS);
360
  $orders = $this->createCircle('orders', $this->getTotals()->getCell('conversion'), self::COLOR_CONVERSIONS);
@@ -370,26 +366,23 @@ JS;
370
  $this->setClicksCircle($clicks);
371
  $this->setOrdersCircle($orders);
372
  $this->setOptoutCircle($optout);
373
-
374
-
375
  }
376
 
377
-
378
-
379
-
380
  protected function _prepareLayout()
381
  {
382
  /* @var $content Mage_Core_Block_Text_List */
383
  $content = $this->getLayout()->getBlock('content');
384
- if($content) {
385
  $content->append($this->getGoogleJs());
386
  }
387
  }
388
 
389
-
390
-
391
-
392
-
393
  public function getConversionBlock()
394
  {
395
  $query = $this->getCachedQuery('conversion', 'date', 'view_rate', false);
@@ -406,9 +399,6 @@ JS;
406
  return $block;
407
  }
408
 
409
-
410
-
411
-
412
  /**
413
  *
414
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
@@ -422,24 +412,22 @@ JS;
422
  $block->setType('column');
423
  $block->setQuery($query);
424
 
425
-
426
- $this->prepareTabs($block, '%ss', null);
427
  $this->prepareTable($block->getTable());
 
428
  return $block;
429
  }
430
 
431
-
432
-
433
-
434
-
435
  /**
 
 
 
436
  *
437
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
438
  */
439
  public function getDimensionPie($dimension, $tabs = array('views', 'clicks'))
440
  {
441
- $query = $this->getCachedQuery('dimension_'.$dimension, $dimension, 'views', false , 1);
442
-
443
 
444
  /* @var $block Mzax_Emarketing_Block_Chart_Widget_Tab */
445
  $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_tab');
@@ -455,8 +443,6 @@ JS;
455
  'height' => '90%'
456
  ));
457
  $block->getChart()->setPieHole(0.25);
458
-
459
-
460
  $block->getChart()->setLegend(array(
461
  'position' => 'left',
462
  'alignment' => 'center'
@@ -464,12 +450,15 @@ JS;
464
 
465
  $this->prepareTabs($block, '%ss', $tabs);
466
  $this->prepareTable($block->getTable());
 
467
  return $block;
468
  }
469
 
470
-
471
-
472
  /**
 
 
 
 
473
  *
474
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
475
  */
@@ -491,75 +480,81 @@ JS;
491
  'height' => '100%'
492
  ));
493
 
494
- if($charType === 'geo') {
495
  $block->getChart()->setHeight(400);
496
  }
497
 
498
  $this->prepareTabs($block, '%ss', $tabs);
499
  $this->prepareTable($block->getTable());
 
500
  return $block;
501
  }
502
 
503
-
504
-
 
 
 
 
 
505
  protected function prepareTabs(Mzax_Emarketing_Block_Chart_Widget_Tab $block, $metric = "%ss", $tabs = null)
506
  {
507
- if(!$tabs || in_array('sendings', $tabs)) {
508
  $block->addTab('sendings', array(
509
- 'label' => $this->__('Sendings'),
510
- 'metric' => sprintf($metric, 'sending')
511
  ));
512
  }
513
 
514
- if(!$tabs || in_array('views', $tabs)) {
515
  $block->addTab('views', array(
516
- 'label' => $this->__('Views'),
517
- 'metric' => sprintf($metric, 'view')
518
  ));
519
  }
520
 
521
- if(!$tabs || in_array('clicks', $tabs)) {
522
  $block->addTab('clicks', array(
523
- 'label' => $this->__('Clicks'),
524
- 'metric' => sprintf($metric, 'click')
525
  ));
526
  }
527
 
528
- if($this->hasTracker()) {
529
- if(!$tabs || in_array('trackers', $tabs)) {
530
  $trackers = array();
531
- foreach($this->getCampaign()->getTrackers() as $tracker) {
532
  $trackers[sprintf($metric, '#'.$tracker->getId())] = $tracker->getTitle();
533
  }
534
- if($tracker = $this->getCampaign()->getDefaultTracker()) {
535
  $block->addTab('trackers', array(
536
- 'label' => $tracker->getTitle(),
537
- 'default' => sprintf($metric, '#'.$tracker->getId()),
538
- 'metric' => $trackers
539
  ));
540
  }
541
  }
542
  }
543
 
544
- if($tabs && in_array('optouts/bounces', $tabs)) {
545
  $block->addTab('optouts', array(
546
  'label' => $this->__('Optouts'),
547
  'default' => 'optouts',
548
  'metric' => array(
549
- sprintf($metric, 'optout') => $this->__('Optouts'),
550
- sprintf($metric, 'bounce') => $this->__('Bounces'),
551
  )
552
  ));
553
  }
554
 
555
- if(!$tabs || in_array('optouts', $tabs)) {
556
  $block->addTab('optouts', array(
557
  'label' => $this->__('Optouts'),
558
  'metric' => sprintf($metric, 'optout')
559
  ));
560
  }
561
 
562
- if(!$tabs || in_array('bounces', $tabs)) {
563
  $block->addTab('bounces', array(
564
  'label' => $this->__('Bounces'),
565
  'metric' => sprintf($metric, 'bounce')
@@ -567,11 +562,6 @@ JS;
567
  }
568
  }
569
 
570
-
571
-
572
-
573
-
574
-
575
  /**
576
  *
577
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
@@ -586,13 +576,15 @@ JS;
586
 
587
  $this->prepareTabs($block, '%ss', array('views', 'clicks'));
588
  $this->prepareTable($block->getTable());
 
589
  return $block;
590
  }
591
 
592
 
593
-
594
-
595
  /**
 
 
 
596
  *
597
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
598
  */
@@ -609,7 +601,7 @@ JS;
609
  $block->setType($chartType);
610
  $block->setQuery($query);
611
 
612
- foreach($this->getCampaign()->getTrackers() as $tracker) {
613
  $block->addTab('tracker_'.$tracker->getId(), array(
614
  'class' => 'trackers',
615
  'label' => $tracker->getTitle(),
@@ -618,19 +610,22 @@ JS;
618
  }
619
 
620
  $this->prepareTable($block->getTable());
 
621
  return $block;
622
  }
623
 
624
-
625
-
626
-
627
-
628
-
 
 
629
  public function createCircle($label = '', $value = 0, $color = 'EA7601')
630
  {
631
  $total = $this->getTotal();
632
 
633
- $percentage = $total ? round(($value/$total)*100,1) : 0;
634
 
635
  $chart = $this->createChart('pie');
636
  $chart->setColors(array($color, 'E7EFEF'));
@@ -653,20 +648,16 @@ JS;
653
  $chart->setAutoRedraw(false);
654
  $chart->setAutoRedraw(false);
655
  $chart->addOverlay('percentage', "{$percentage}%");
656
- $chart->addColumn('Label', 'string');
657
  $chart->addColumn('Values', 'number');
658
-
659
  $chart->addRow(array($label, $value));
660
- $chart->addRow(array('', max(0,$total-$value)));
661
-
662
  $chart->setValue($value);
663
  $chart->setLabel($label);
664
 
665
  return $chart;
666
  }
667
 
668
-
669
-
670
  /**
671
  * Create chart type
672
  *
@@ -681,44 +672,42 @@ JS;
681
  $chart = $this->getLayout()->createBlock($block);
682
 
683
  return $chart;
684
-
685
  }
686
 
687
-
688
-
689
  /**
690
  * Retrieve GeoIP credits
691
- *
692
  * @return array
693
  */
694
  public function getGeoIpCredits()
695
  {
696
- $adapters = Mage::getSingleton('mzax_emarketing/system_config_source_geoIp')->getSelectedAdapters();
 
 
 
697
  $credits = array();
698
-
699
  $geoLiteCredit = 'GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.';
700
  $geoLite = false;
701
  /* @var $adapter Mzax_GeoIp_Adapter_Abstract */
702
- foreach($adapters as $adapter) {
703
  $credit = $adapter->getCredits();
704
- if($credit) {
705
- if(strpos($credit, $geoLiteCredit)) {
706
  $geoLite = true;
707
  $credit = str_replace($geoLiteCredit, 'GeoLite*', $credit);
708
  }
709
  $credits[] = $credit;
710
  }
711
  }
712
-
713
- if($geoLite) {
714
  $credits[] = '*' . $geoLiteCredit;
715
  }
716
-
717
  return $credits;
718
  }
719
 
720
-
721
-
722
  /**
723
  * Retrieve Varien Data Form
724
  *
@@ -731,34 +720,34 @@ JS;
731
 
732
  $form = new Varien_Data_Form();
733
  $form->setElementRenderer($elementRenderer);
 
734
  return $form;
735
  }
736
 
737
-
738
-
739
  /**
740
  * Helper for simple select element
741
  *
742
  * @param string $key
743
- * @param array $options
744
  * @return Varien_Data_Form_Element_Abstract
745
  */
746
- public function getDateElement($key, $default = null)
747
  {
748
  $format = Varien_Date::DATE_INTERNAL_FORMAT;
749
  $value = $this->getRequest()->getParam($key, '');
750
 
751
- return $this->getForm()->addField($key, 'date',array(
 
 
 
752
  'name' => $key,
753
  'value_name' => $value,
754
- 'value' => $value,
755
  'explicit_apply' => true,
756
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
757
  'input_format' => $format,
758
  'format' => $format
759
- ))->setId('report_'.$key);
 
760
  }
761
-
762
-
763
-
764
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Report extends Mage_Adminhtml_Block_Widget
24
  {
25
+ const COLOR_BLANK = 'E7EFEF';
26
+ const COLOR_SENDINGS = '899DA8';
27
+ const COLOR_VIEWS = '159FC4';
28
+ const COLOR_CLICKS = 'D7D020';
29
+ const COLOR_ORDERS = 'A9C200';
30
+ const COLOR_CONVERSIONS = 'A9C200';
31
+ const COLOR_OPTOUT = 'BF3A3A';
32
+ const COLOR_BOUNDS = '712B2B';
33
 
34
  /**
 
35
  * @var Mzax_Emarketing_Model_Campaign
36
  */
37
  protected $_campaign;
38
 
39
+ /**
40
+ * @var
41
+ */
42
  protected $_dateRange;
43
 
44
+ /**
45
+ *
46
+ * @return void
47
+ */
48
  protected function _construct()
49
  {
50
  parent::_construct();
53
  $this->setTemplate('mzax/emarketing/campaign/report.phtml');
54
  }
55
 
 
 
56
  /**
57
  * Retrieve campaign
58
  *
60
  */
61
  public function getCampaign()
62
  {
63
+ if (!$this->_campaign) {
64
  $this->_campaign = Mage::registry('current_campaign');
65
  }
66
  return $this->_campaign;
67
  }
68
 
 
69
  /**
70
  * Set campaign
71
  *
72
  * @param Mzax_Emarketing_Model_Campaign $campaign
73
+ *
74
  * @return Mzax_Emarketing_Block_Campaign_Edit_Tab_Report
75
  */
76
  public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
79
  return $this;
80
  }
81
 
 
 
82
  /**
83
  * Has campaign any trackers
84
  *
89
  return (bool) count($this->getCampaign()->getTrackers());
90
  }
91
 
 
 
 
92
  /**
93
  * Query report data tables
94
  *
95
  * @param string $dimension
96
  * @param array $metrics
97
+ * @param bool $variations
98
+ * @param string $order
99
+ *
100
  * @return Mzax_Emarketing_Model_Report_Query
101
  */
102
  public function queryReport($dimension, $metrics, $variations, $order = null)
107
  return $query;
108
  }
109
 
 
 
110
  /**
111
  * Retrieve date range from request
112
  *
114
  */
115
  public function getDateRange()
116
  {
117
+ if ($this->_dateRange === null) {
118
  $validator = new Zend_Validate_Date;
119
 
120
  $from = $this->getRequest()->getParam('from');
121
  $to = $this->getRequest()->getParam('to');
122
 
123
+ if ($validator->isValid($from) && $validator->isValid($to)) {
124
  $this->_dateRange = array($from, $to);
125
+ } else {
 
126
  $this->_dateRange = false;
127
  }
128
  }
129
+
130
  return $this->_dateRange;
131
  }
132
 
 
 
133
  /**
134
+ * Retrieve query from local cache or create new
135
  *
136
  * @param string $key
137
  * @param string $dimension
138
  * @param array $metrics
139
+ * @param bool $variations
140
+ * @param string $order
141
+ *
142
  * @return Mzax_Emarketing_Model_Report_Query
143
  */
144
  public function getCachedQuery($key, $dimension, $metrics, $variations, $order = null)
145
  {
146
  $query = $this->getData('query_' . $key);
147
+ if (!$query) {
148
  $query = $this->queryReport($dimension, $metrics, $variations, $order);
149
  $this->setData('query_' . $key, $query);
150
  }
151
+
152
  return $query;
153
  }
154
 
 
 
 
 
155
  /**
156
  *
157
  * @return Mzax_Emarketing_Model_Report_Query
158
  */
159
  public function getTotals()
160
  {
161
+ return $this->getCachedQuery(
162
+ 'totals',
163
+ 'campaign',
164
+ array('sendings', 'views', 'clicks', 'bounces', 'optouts', 'conversion' => '#?'),
165
+ false
166
+ );
167
  }
168
 
169
+ /**
170
+ * @return int
171
+ */
 
 
172
  public function getTotal()
173
  {
174
  return (int) $this->getTotals()->getCell('sendings');
175
  }
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  /**
178
  * Prepare chart data table by providing correct
179
  * column lables and colors
180
  *
181
  * @param Mzax_Chart_Table $table
182
+ *
183
+ * @return void
184
  */
185
  public function prepareTable(Mzax_Chart_Table $table)
186
  {
187
  $variations = $table->getTableProperty('variations');
188
  $dimension = $table->getTableProperty('dimension');
189
 
190
+ foreach ($table->getColumns() as $column) {
191
+ if (isset($column->p->metric)) {
192
+ switch ($column->p->metric) {
193
  case 'sendings':
194
  $column->label = $this->__('Recipients');
195
  $column->p->color = self::COLOR_SENDINGS;
216
  break;
217
  }
218
  }
219
+ if (isset($column->p->tracker_id)) {
220
  $tracker = $this->getCampaign()->getTracker($column->p->tracker_id);
221
+ if ($tracker) {
222
  $column->label = $tracker->getTitle();
223
+ } else {
 
224
  $column->label = $this->__('Tracker (%s)', $column->p->tracker_id);
225
  }
226
  $column->p->color = self::COLOR_CLICKS;
227
  }
228
 
229
+ if (isset($column->p->color)) {
230
  $column->p->color_axis = array($this->brightness($column->p->color, 80), $this->brightness($column->p->color, -80));
231
  }
232
 
233
+ if (isset($column->p->variation_id)) {
234
  $vid = $column->p->variation_id;
235
 
236
  $index = array_search($vid, $variations);
237
 
238
  $gradient = $this->gradient(
239
+ $this->brightness($column->p->color, -100),
240
+ $this->brightness($column->p->color, 20),
241
+ count($variations)
242
+ );
243
 
244
  $column->p->color = $gradient[$index];
245
 
246
  $variation = $this->getCampaign()->getVariation($vid);
247
+ if ($variation) {
248
  $column->label = $variation->getName();
249
+ } else {
 
250
  $column->label = $this->__('Variation (%s)', $vid);
251
  }
252
  }
253
  }
254
 
255
+ if ($dimension !== 'date') {
256
+ $colors = array(
257
+ '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4',
258
+ 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E',
259
+ 'D7D020', '00A6D4', 'A559BF', '14D277', '627379', 'FC7A00',
260
+ 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277',
261
+ '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4',
262
+ 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E',
263
+ 'D7D020', '00A6D4', 'A559BF', '14D277'
264
+ );
265
 
266
  //$table->addColumn('style', Mzax_Chart_Table::TYPE_STRING, 'style', array('role' => 'style'));
267
+ foreach ($colors as $row => $color) {
268
  $table->setRowProperty($row, 'color', $color);
269
  }
270
  $table->setTableProperty('dye', true);
271
  }
272
 
273
+ switch (strtolower($dimension)) {
 
274
  case 'hour':
275
  $table->setColumnType(0, Mzax_Chart_Table::TYPE_TIME);
276
  $table->setTableProperty('stacked', true);
281
  $table->setTableProperty('dye', false);
282
  break;
283
  }
 
 
284
  }
285
 
286
+ /**
287
+ * @param string $start
288
+ * @param string $end
289
+ * @param int $steps
290
+ *
291
+ * @return string[]
292
+ */
293
  protected function gradient($start, $end, $steps)
294
  {
295
  $steps = max($steps, 2);
296
  $start = array_map('hexdec', str_split($start, 2));
297
  $end = array_map('hexdec', str_split($end, 2));
298
 
299
+ $step = array();
300
+ foreach ($start as $j => $v) {
301
  $step[$j] = ($v - $end[$j]) / ($steps-1);
302
  }
303
 
304
  $colors = array();
305
+ for ($i = 0; $i <= $steps; $i++) {
306
  $rgb = array();
307
+ foreach ($step as $j => $v) {
308
  $rgb[$j] = sprintf('%02x', floor($start[$j] - $v * $i));
309
  }
310
  $colors[] = implode('', $rgb);
311
  }
312
+
313
  return $colors;
314
  }
315
 
316
+ /**
317
+ * @param string $color
318
+ * @param float $adjust
319
+ *
320
+ * @return string
321
+ */
322
  protected function brightness($color, $adjust)
323
  {
324
  $rgb = array_map('hexdec', str_split($color, 2));
325
+ foreach ($rgb as &$v) {
326
+ $v = sprintf('%02x', max(0, min(255, $v + $adjust)));
327
  }
328
  return implode('', $rgb);
329
  }
330
 
331
+ /**
332
+ * @return Mage_Core_Block_Text
333
+ */
 
 
334
  protected function getGoogleJs()
335
  {
336
  $locale = Mage::app()->getLocale()->getLocaleCode();
341
  google.load("visualization", "1", {packages:["corechart"], language:'$locale'});
342
  </script>
343
  JS;
344
+ return $this->getLayout()->createBlock('core/text')->setText($js);
 
345
  }
346
 
347
+ /**
348
+ * @return void
349
+ */
350
  protected function _beforeToHtml()
351
  {
352
  parent::_beforeToHtml();
353
 
 
354
  $views = $this->createCircle('viewes', $this->getTotals()->getCell('views'), self::COLOR_VIEWS);
355
  $clicks = $this->createCircle('clicks', $this->getTotals()->getCell('clicks'), self::COLOR_CLICKS);
356
  $orders = $this->createCircle('orders', $this->getTotals()->getCell('conversion'), self::COLOR_CONVERSIONS);
366
  $this->setClicksCircle($clicks);
367
  $this->setOrdersCircle($orders);
368
  $this->setOptoutCircle($optout);
 
 
369
  }
370
 
371
+ /**
372
+ * @return void
373
+ */
374
  protected function _prepareLayout()
375
  {
376
  /* @var $content Mage_Core_Block_Text_List */
377
  $content = $this->getLayout()->getBlock('content');
378
+ if ($content) {
379
  $content->append($this->getGoogleJs());
380
  }
381
  }
382
 
383
+ /**
384
+ * @return Mzax_Emarketing_Block_Chart_Widget_Tab
385
+ */
 
386
  public function getConversionBlock()
387
  {
388
  $query = $this->getCachedQuery('conversion', 'date', 'view_rate', false);
399
  return $block;
400
  }
401
 
 
 
 
402
  /**
403
  *
404
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
412
  $block->setType('column');
413
  $block->setQuery($query);
414
 
415
+ $this->prepareTabs($block, '%ss', null);
 
416
  $this->prepareTable($block->getTable());
417
+
418
  return $block;
419
  }
420
 
 
 
 
 
421
  /**
422
+ *
423
+ * @param string $dimension
424
+ * @param string[] $tabs
425
  *
426
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
427
  */
428
  public function getDimensionPie($dimension, $tabs = array('views', 'clicks'))
429
  {
430
+ $query = $this->getCachedQuery('dimension_'.$dimension, $dimension, 'views', false, 1);
 
431
 
432
  /* @var $block Mzax_Emarketing_Block_Chart_Widget_Tab */
433
  $block = $this->getLayout()->createBlock('mzax_emarketing/chart_widget_tab');
443
  'height' => '90%'
444
  ));
445
  $block->getChart()->setPieHole(0.25);
 
 
446
  $block->getChart()->setLegend(array(
447
  'position' => 'left',
448
  'alignment' => 'center'
450
 
451
  $this->prepareTabs($block, '%ss', $tabs);
452
  $this->prepareTable($block->getTable());
453
+
454
  return $block;
455
  }
456
 
 
 
457
  /**
458
+ *
459
+ * @param string $dimension
460
+ * @param string $charType
461
+ * @param string[] $tabs
462
  *
463
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
464
  */
480
  'height' => '100%'
481
  ));
482
 
483
+ if ($charType === 'geo') {
484
  $block->getChart()->setHeight(400);
485
  }
486
 
487
  $this->prepareTabs($block, '%ss', $tabs);
488
  $this->prepareTable($block->getTable());
489
+
490
  return $block;
491
  }
492
 
493
+ /**
494
+ * @param Mzax_Emarketing_Block_Chart_Widget_Tab $block
495
+ * @param string $metric
496
+ * @param string[] $tabs
497
+ *
498
+ * @return void
499
+ */
500
  protected function prepareTabs(Mzax_Emarketing_Block_Chart_Widget_Tab $block, $metric = "%ss", $tabs = null)
501
  {
502
+ if (!$tabs || in_array('sendings', $tabs)) {
503
  $block->addTab('sendings', array(
504
+ 'label' => $this->__('Sendings'),
505
+ 'metric' => sprintf($metric, 'sending')
506
  ));
507
  }
508
 
509
+ if (!$tabs || in_array('views', $tabs)) {
510
  $block->addTab('views', array(
511
+ 'label' => $this->__('Views'),
512
+ 'metric' => sprintf($metric, 'view')
513
  ));
514
  }
515
 
516
+ if (!$tabs || in_array('clicks', $tabs)) {
517
  $block->addTab('clicks', array(
518
+ 'label' => $this->__('Clicks'),
519
+ 'metric' => sprintf($metric, 'click')
520
  ));
521
  }
522
 
523
+ if ($this->hasTracker()) {
524
+ if (!$tabs || in_array('trackers', $tabs)) {
525
  $trackers = array();
526
+ foreach ($this->getCampaign()->getTrackers() as $tracker) {
527
  $trackers[sprintf($metric, '#'.$tracker->getId())] = $tracker->getTitle();
528
  }
529
+ if ($tracker = $this->getCampaign()->getDefaultTracker()) {
530
  $block->addTab('trackers', array(
531
+ 'label' => $tracker->getTitle(),
532
+ 'default' => sprintf($metric, '#'.$tracker->getId()),
533
+ 'metric' => $trackers
534
  ));
535
  }
536
  }
537
  }
538
 
539
+ if ($tabs && in_array('optouts/bounces', $tabs)) {
540
  $block->addTab('optouts', array(
541
  'label' => $this->__('Optouts'),
542
  'default' => 'optouts',
543
  'metric' => array(
544
+ sprintf($metric, 'optout') => $this->__('Optouts'),
545
+ sprintf($metric, 'bounce') => $this->__('Bounces'),
546
  )
547
  ));
548
  }
549
 
550
+ if (!$tabs || in_array('optouts', $tabs)) {
551
  $block->addTab('optouts', array(
552
  'label' => $this->__('Optouts'),
553
  'metric' => sprintf($metric, 'optout')
554
  ));
555
  }
556
 
557
+ if (!$tabs || in_array('bounces', $tabs)) {
558
  $block->addTab('bounces', array(
559
  'label' => $this->__('Bounces'),
560
  'metric' => sprintf($metric, 'bounce')
562
  }
563
  }
564
 
 
 
 
 
 
565
  /**
566
  *
567
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
576
 
577
  $this->prepareTabs($block, '%ss', array('views', 'clicks'));
578
  $this->prepareTable($block->getTable());
579
+
580
  return $block;
581
  }
582
 
583
 
 
 
584
  /**
585
+ *
586
+ * @param string $type
587
+ * @param string $chartType
588
  *
589
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
590
  */
601
  $block->setType($chartType);
602
  $block->setQuery($query);
603
 
604
+ foreach ($this->getCampaign()->getTrackers() as $tracker) {
605
  $block->addTab('tracker_'.$tracker->getId(), array(
606
  'class' => 'trackers',
607
  'label' => $tracker->getTitle(),
610
  }
611
 
612
  $this->prepareTable($block->getTable());
613
+
614
  return $block;
615
  }
616
 
617
+ /**
618
+ * @param string $label
619
+ * @param int $value
620
+ * @param string $color
621
+ *
622
+ * @return Mzax_Emarketing_Block_Chart_Abstract
623
+ */
624
  public function createCircle($label = '', $value = 0, $color = 'EA7601')
625
  {
626
  $total = $this->getTotal();
627
 
628
+ $percentage = $total ? round(($value/$total)*100, 1) : 0;
629
 
630
  $chart = $this->createChart('pie');
631
  $chart->setColors(array($color, 'E7EFEF'));
648
  $chart->setAutoRedraw(false);
649
  $chart->setAutoRedraw(false);
650
  $chart->addOverlay('percentage', "{$percentage}%");
651
+ $chart->addColumn('Label', 'string');
652
  $chart->addColumn('Values', 'number');
 
653
  $chart->addRow(array($label, $value));
654
+ $chart->addRow(array('', max(0, $total-$value)));
 
655
  $chart->setValue($value);
656
  $chart->setLabel($label);
657
 
658
  return $chart;
659
  }
660
 
 
 
661
  /**
662
  * Create chart type
663
  *
672
  $chart = $this->getLayout()->createBlock($block);
673
 
674
  return $chart;
 
675
  }
676
 
 
 
677
  /**
678
  * Retrieve GeoIP credits
679
+ *
680
  * @return array
681
  */
682
  public function getGeoIpCredits()
683
  {
684
+ /** @var Mzax_Emarketing_Model_System_Config_Source_Geoip $geoIpSource */
685
+ $geoIpSource = Mage::getSingleton('mzax_emarketing/system_config_source_geoIp');
686
+
687
+ $adapters = $geoIpSource->getSelectedAdapters();
688
  $credits = array();
689
+
690
  $geoLiteCredit = 'GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.';
691
  $geoLite = false;
692
  /* @var $adapter Mzax_GeoIp_Adapter_Abstract */
693
+ foreach ($adapters as $adapter) {
694
  $credit = $adapter->getCredits();
695
+ if ($credit) {
696
+ if (strpos($credit, $geoLiteCredit)) {
697
  $geoLite = true;
698
  $credit = str_replace($geoLiteCredit, 'GeoLite*', $credit);
699
  }
700
  $credits[] = $credit;
701
  }
702
  }
703
+
704
+ if ($geoLite) {
705
  $credits[] = '*' . $geoLiteCredit;
706
  }
707
+
708
  return $credits;
709
  }
710
 
 
 
711
  /**
712
  * Retrieve Varien Data Form
713
  *
720
 
721
  $form = new Varien_Data_Form();
722
  $form->setElementRenderer($elementRenderer);
723
+
724
  return $form;
725
  }
726
 
 
 
727
  /**
728
  * Helper for simple select element
729
  *
730
  * @param string $key
731
+ *
732
  * @return Varien_Data_Form_Element_Abstract
733
  */
734
+ public function getDateElement($key)
735
  {
736
  $format = Varien_Date::DATE_INTERNAL_FORMAT;
737
  $value = $this->getRequest()->getParam($key, '');
738
 
739
+ return $this->getForm()->addField(
740
+ $key,
741
+ 'date',
742
+ array(
743
  'name' => $key,
744
  'value_name' => $value,
745
+ 'value' => $value,
746
  'explicit_apply' => true,
747
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
748
  'input_format' => $format,
749
  'format' => $format
750
+ )
751
+ )->setId('report_'.$key);
752
  }
 
 
 
753
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Settings.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,27 +17,54 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
22
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- protected function _prepareLayout()
 
 
 
 
 
25
  {
26
- parent::_prepareLayout();
 
 
 
27
  }
28
 
29
-
30
-
 
31
  public function initForm()
32
  {
33
- $form = new Varien_Data_Form();
34
  $form->setHtmlIdPrefix('campaign_');
35
  $form->setFieldNameSuffix('campaign');
36
 
37
- /* @var $campaign Mzax_Emarketing_Model_Campaign */
38
- $campaign = Mage::registry('current_campaign');
 
39
 
40
- $outputFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
41
-
42
  /**
43
  * Campaign
44
  */
@@ -47,38 +73,35 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
47
  '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'),
48
  'continue' => false
49
  ));
50
-
51
- if(!$campaign->getId()) {
52
- $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
53
- ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
 
 
54
  $fieldset->setRenderer($renderer);
55
  }
56
-
57
-
58
- $fieldset->addField('medium','hidden', array(
59
  'name' => 'medium'
60
  ));
61
-
62
-
63
- if($campaign->getPreset()) {
64
- $fieldset->addField('preset_name','hidden', array(
65
  'name' => 'preset_name',
66
  'value' => $campaign->getPreset()->getName()
67
  ));
68
  }
69
-
70
-
71
 
72
- $fieldset->addField('name','text', array(
73
  'name' => 'name',
74
- 'required' => true,
75
  'label' => $this->__('Campaign Name'),
76
  'title' => $this->__('Campaign Name'),
77
  ));
78
-
79
-
80
- if($campaign->getId()) {
81
- $fieldset->addField('description','textarea', array(
82
  'name' => 'description',
83
  'required' => false,
84
  'style' => 'height:60px;',
@@ -86,8 +109,8 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
86
  'title' => $this->__('Description'),
87
  'note' => $this->__("For internal use only"),
88
  ));
89
-
90
- $fieldset->addField('tags','text', array(
91
  'name' => 'tags',
92
  'required' => false,
93
  'label' => $this->__('Tags'),
@@ -95,14 +118,14 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
95
  'note' => $this->__("Space separated tags for internal organising purpose only (e.g. draft reminder ad need-review…)"),
96
  ));
97
  }
98
-
99
-
100
  // don't show when creating by presets
101
- if(!$campaign->getPreset()) {
102
- $fieldset->addField('provider','select', array(
103
  'name' => 'provider',
104
  'label' => $this->__('Campaign Recipient'),
105
- 'title' => $this->__('Campaign Recipient'),
106
  'values' => $campaign->getAvailableProviders(false),
107
  'note' => !$campaign->getId()
108
  ? $this->__("Who are the recipients of this campaign")
@@ -111,16 +134,14 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
111
  : $this->__("This can not be changed once a recipient has been created.")
112
  ),
113
  'disabled' => $campaign->getId() && $campaign->countRecipients(),
114
- 'required' => true,
115
  ));
116
- }
117
- else {
118
  $fieldset->addField('provider', 'hidden', array(
119
  'name' => 'provider'
120
  ));
121
  }
122
-
123
-
124
  $fieldset->addField('store_id', 'select', array(
125
  'name' => 'store_id',
126
  'label' => $this->__('Sender Store'),
@@ -128,11 +149,9 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
128
  'values' => Mage::getModel('adminhtml/system_config_source_store')->toOptionArray(),
129
  'required' => true,
130
  ));
131
-
132
-
133
  // don't show when creating by presets
134
- if(!$campaign->getPreset())
135
- {
136
  $fieldset->addField('check_frequency', 'select', array(
137
  'label' => $this->__('Check Frequency'),
138
  'title' => $this->__('Check Frequency'),
@@ -151,7 +170,7 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
151
  'value' => '720',
152
  '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."),
153
  ));
154
-
155
  $fieldset->addField('min_resend_interval', 'select', array(
156
  'label' => $this->__('Minimum Resend Interval'),
157
  'title' => $this->__('Minimum Resend Interval'),
@@ -176,7 +195,6 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
176
  'note' => $this->__("The minimum time before a recipient can recieve this campaign again."),
177
  ));
178
 
179
-
180
  $fieldset->addField('max_per_recipient', 'text', array(
181
  'label' => $this->__('Max Send-outs per Recipient'),
182
  'title' => $this->__('Max Send-outs per Recipient'),
@@ -185,17 +203,10 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
185
  'value' => '0',
186
  'note' => $this->__("Maximum send-outs per recipient, zero = unlimited"),
187
  ));
188
-
189
-
190
  }
191
-
192
-
193
-
194
-
195
-
196
- if($campaign->getId()) {
197
-
198
- $fieldset->addField('start_at','date',array(
199
  'name' => 'start_at',
200
  'time' => true,
201
  'style' => 'width:60%;',
@@ -203,7 +214,7 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
203
  'label' => $this->__('Date Start'),
204
  'image' => $this->getSkinUrl('images/grid-cal.gif')
205
  ));
206
- $fieldset->addField('end_at','date',array(
207
  'name' => 'end_at',
208
  'time' => true,
209
  'style' => 'width:60%;',
@@ -211,8 +222,7 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
211
  'label' => $this->__('Date End'),
212
  'image' => $this->getSkinUrl('images/grid-cal.gif')
213
  ));
214
-
215
-
216
  /**
217
  * Ab Test
218
  */
@@ -220,8 +230,8 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
220
  'note' => "If enabled, the user will be logged in if possible.",
221
  'legend' => $this->__('AB Testing'),
222
  ));
223
-
224
-
225
  $abtestFieldset->addField('abtest_enable', 'select', array(
226
  'label' => $this->__('Enabled'),
227
  'title' => $this->__('Enabled'),
@@ -233,7 +243,7 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
233
  ),
234
  'value' => '0'
235
  ));
236
-
237
  $abtestFieldset->addField('abtest_traffic', 'text', array(
238
  'name' => 'abtest_traffic',
239
  'label' => $this->__('Traffic Percentage'),
@@ -241,17 +251,14 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
241
  'required' => true,
242
  'value' => '100'
243
  ));
244
-
245
-
246
-
247
-
248
  /**
249
  * Campaign
250
  */
251
- $advanced = $form->addFieldset('advanced_fieldset',
 
252
  array('legend'=>$this->__('Advanced Settings'))
253
  );
254
-
255
 
256
  $advanced->addField('autologin', 'select', array(
257
  'label' => $this->__('Autologin'),
@@ -265,9 +272,7 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
265
  ),
266
  'value' => '1'
267
  ));
268
-
269
-
270
-
271
  $advanced->addField('expire_time', 'select', array(
272
  'name' => 'expire_time',
273
  'label' => $this->__('Expire Time'),
@@ -291,48 +296,106 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Bl
291
  'value' => '120',
292
  '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."),
293
  ));
294
-
295
-
296
-
297
-
298
- $advanced->addField('identity','select', array(
299
  'name' => 'identity',
300
  'label' => $this->__('Email Sender'),
301
  'title' => $this->__('Email Sender'),
302
  'values' => Mage::getModel('adminhtml/system_config_source_email_identity')->toOptionArray(),
303
  'required' => true,
304
- '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.")
305
  ));
306
-
307
-
308
-
309
- $trackers = Mage::getResourceSingleton('mzax_emarketing/conversion_tracker_collection')->toOptionArray();
310
-
311
- array_unshift($trackers, array('value' => '0', 'label' => $this->__("Use Config Default Tracker")));
312
-
313
-
314
- $advanced->addField('default_tracker_id','select', array(
315
  'name' => 'default_tracker_id',
316
  'label' => $this->__('Default Conversion Tracker'),
317
  'title' => $this->__('Default Conversion Tracker'),
318
- 'values' => $trackers,
319
  'required' => true,
320
  ));
321
-
322
-
323
- if($medium = $campaign->getMedium()) {
324
  $medium->initSettingsForm($form, $campaign);
325
  $form->addValues($campaign->getMediumData()->getData());
326
  }
327
-
328
  } // has id
329
-
330
-
331
  $form->addValues($campaign->getData());
332
- $this->setForm($form);
333
-
334
  return $this;
335
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @var Mzax_Emarketing_Model_Campaign
27
+ */
28
+ protected $_campaign;
29
+
30
+ /**
31
+ * Dependency
32
+ *
33
+ * @var Mage_Core_Model_Locale
34
+ */
35
+ protected $_locale;
36
+
37
+ /**
38
+ * @var Mzax_Emarketing_Model_System_Config_Source_Trackers
39
+ */
40
+ protected $_trackers;
41
 
42
+ /**
43
+ * Load dependencies
44
+ *
45
+ * @return void
46
+ */
47
+ protected function _construct()
48
  {
49
+ parent::_construct();
50
+
51
+ $this->_locale = Mage::app()->getLocale();
52
+ $this->_trackers = Mage::getSingleton('mzax_emarketing/system_config_source_trackers');
53
  }
54
 
55
+ /**
56
+ * @return $this
57
+ */
58
  public function initForm()
59
  {
60
+ $form = $this->getForm();
61
  $form->setHtmlIdPrefix('campaign_');
62
  $form->setFieldNameSuffix('campaign');
63
 
64
+ $campaign = $this->getCampaign();
65
+
66
+ $outputFormat = $this->_locale->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
67
 
 
 
68
  /**
69
  * Campaign
70
  */
73
  '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'),
74
  'continue' => false
75
  ));
76
+
77
+ if (!$campaign->getId()) {
78
+ /** @var Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset $renderer */
79
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset');
80
+ $renderer->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
81
+
82
  $fieldset->setRenderer($renderer);
83
  }
84
+
85
+ $fieldset->addField('medium', 'hidden', array(
 
86
  'name' => 'medium'
87
  ));
88
+
89
+ if ($campaign->getPreset()) {
90
+ $fieldset->addField('preset_name', 'hidden', array(
 
91
  'name' => 'preset_name',
92
  'value' => $campaign->getPreset()->getName()
93
  ));
94
  }
 
 
95
 
96
+ $fieldset->addField('name', 'text', array(
97
  'name' => 'name',
98
+ 'required' => true,
99
  'label' => $this->__('Campaign Name'),
100
  'title' => $this->__('Campaign Name'),
101
  ));
102
+
103
+ if ($campaign->getId()) {
104
+ $fieldset->addField('description', 'textarea', array(
 
105
  'name' => 'description',
106
  'required' => false,
107
  'style' => 'height:60px;',
109
  'title' => $this->__('Description'),
110
  'note' => $this->__("For internal use only"),
111
  ));
112
+
113
+ $fieldset->addField('tags', 'text', array(
114
  'name' => 'tags',
115
  'required' => false,
116
  'label' => $this->__('Tags'),
118
  'note' => $this->__("Space separated tags for internal organising purpose only (e.g. draft reminder ad need-review…)"),
119
  ));
120
  }
121
+
122
+
123
  // don't show when creating by presets
124
+ if (!$campaign->getPreset()) {
125
+ $fieldset->addField('provider', 'select', array(
126
  'name' => 'provider',
127
  'label' => $this->__('Campaign Recipient'),
128
+ 'title' => $this->__('Campaign Recipient'),
129
  'values' => $campaign->getAvailableProviders(false),
130
  'note' => !$campaign->getId()
131
  ? $this->__("Who are the recipients of this campaign")
134
  : $this->__("This can not be changed once a recipient has been created.")
135
  ),
136
  'disabled' => $campaign->getId() && $campaign->countRecipients(),
137
+ 'required' => true,
138
  ));
139
+ } else {
 
140
  $fieldset->addField('provider', 'hidden', array(
141
  'name' => 'provider'
142
  ));
143
  }
144
+
 
145
  $fieldset->addField('store_id', 'select', array(
146
  'name' => 'store_id',
147
  'label' => $this->__('Sender Store'),
149
  'values' => Mage::getModel('adminhtml/system_config_source_store')->toOptionArray(),
150
  'required' => true,
151
  ));
152
+
 
153
  // don't show when creating by presets
154
+ if (!$campaign->getPreset()) {
 
155
  $fieldset->addField('check_frequency', 'select', array(
156
  'label' => $this->__('Check Frequency'),
157
  'title' => $this->__('Check Frequency'),
170
  'value' => '720',
171
  '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."),
172
  ));
173
+
174
  $fieldset->addField('min_resend_interval', 'select', array(
175
  'label' => $this->__('Minimum Resend Interval'),
176
  'title' => $this->__('Minimum Resend Interval'),
195
  'note' => $this->__("The minimum time before a recipient can recieve this campaign again."),
196
  ));
197
 
 
198
  $fieldset->addField('max_per_recipient', 'text', array(
199
  'label' => $this->__('Max Send-outs per Recipient'),
200
  'title' => $this->__('Max Send-outs per Recipient'),
203
  'value' => '0',
204
  'note' => $this->__("Maximum send-outs per recipient, zero = unlimited"),
205
  ));
 
 
206
  }
207
+
208
+ if ($campaign->getId()) {
209
+ $fieldset->addField('start_at', 'date', array(
 
 
 
 
 
210
  'name' => 'start_at',
211
  'time' => true,
212
  'style' => 'width:60%;',
214
  'label' => $this->__('Date Start'),
215
  'image' => $this->getSkinUrl('images/grid-cal.gif')
216
  ));
217
+ $fieldset->addField('end_at', 'date', array(
218
  'name' => 'end_at',
219
  'time' => true,
220
  'style' => 'width:60%;',
222
  'label' => $this->__('Date End'),
223
  'image' => $this->getSkinUrl('images/grid-cal.gif')
224
  ));
225
+
 
226
  /**
227
  * Ab Test
228
  */
230
  'note' => "If enabled, the user will be logged in if possible.",
231
  'legend' => $this->__('AB Testing'),
232
  ));
233
+
234
+
235
  $abtestFieldset->addField('abtest_enable', 'select', array(
236
  'label' => $this->__('Enabled'),
237
  'title' => $this->__('Enabled'),
243
  ),
244
  'value' => '0'
245
  ));
246
+
247
  $abtestFieldset->addField('abtest_traffic', 'text', array(
248
  'name' => 'abtest_traffic',
249
  'label' => $this->__('Traffic Percentage'),
251
  'required' => true,
252
  'value' => '100'
253
  ));
254
+
 
 
 
255
  /**
256
  * Campaign
257
  */
258
+ $advanced = $form->addFieldset(
259
+ 'advanced_fieldset',
260
  array('legend'=>$this->__('Advanced Settings'))
261
  );
 
262
 
263
  $advanced->addField('autologin', 'select', array(
264
  'label' => $this->__('Autologin'),
272
  ),
273
  'value' => '1'
274
  ));
275
+
 
 
276
  $advanced->addField('expire_time', 'select', array(
277
  'name' => 'expire_time',
278
  'label' => $this->__('Expire Time'),
296
  'value' => '120',
297
  '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."),
298
  ));
299
+
300
+
301
+ $advanced->addField('identity', 'select', array(
 
 
302
  'name' => 'identity',
303
  'label' => $this->__('Email Sender'),
304
  'title' => $this->__('Email Sender'),
305
  'values' => Mage::getModel('adminhtml/system_config_source_email_identity')->toOptionArray(),
306
  'required' => true,
307
+ '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.")
308
  ));
309
+
310
+
311
+ $advanced->addField('default_tracker_id', 'select', array(
 
 
 
 
 
 
312
  'name' => 'default_tracker_id',
313
  'label' => $this->__('Default Conversion Tracker'),
314
  'title' => $this->__('Default Conversion Tracker'),
315
+ 'values' => $this->getTrackerOptions(),
316
  'required' => true,
317
  ));
318
+
319
+
320
+ if ($medium = $campaign->getMedium()) {
321
  $medium->initSettingsForm($form, $campaign);
322
  $form->addValues($campaign->getMediumData()->getData());
323
  }
324
+
325
  } // has id
326
+
 
327
  $form->addValues($campaign->getData());
328
+
 
329
  return $this;
330
+ }
331
+
332
+ /**
333
+ * Retrieve tracker options
334
+ *
335
+ * @return array
336
+ */
337
+ public function getTrackerOptions()
338
+ {
339
+ $options = $this->_trackers->toOptionArray();
340
+ array_unshift(
341
+ $options,
342
+ array(
343
+ 'value' => '0',
344
+ 'label' => $this->__("Use Config Default Tracker")
345
+ )
346
+ );
347
 
348
+ return $options;
349
+ }
350
+
351
+ /**
352
+ * Retrieve form
353
+ *
354
+ * @return Varien_Data_Form
355
+ */
356
+ public function getForm()
357
+ {
358
+ if (!$this->_form) {
359
+ $this->_form = new Varien_Data_Form();
360
+ }
361
+
362
+ return $this->_form;
363
+ }
364
+
365
+ /**
366
+ * @param Varien_Data_Form $form
367
+ *
368
+ * @return $this
369
+ */
370
+ public function setForm(Varien_Data_Form $form)
371
+ {
372
+ $this->_form = $form;
373
+
374
+ return $this;
375
+ }
376
+
377
+ /**
378
+ * Retrieve current campaign
379
+ *
380
+ * @return Mzax_Emarketing_Model_Campaign
381
+ */
382
+ public function getCampaign()
383
+ {
384
+ if (!$this->_campaign) {
385
+ $this->_campaign = Mage::registry('current_campaign');
386
+ }
387
+ return $this->_campaign;
388
+ }
389
+
390
+ /**
391
+ * @param Mzax_Emarketing_Model_Campaign $campaign
392
+ *
393
+ * @return $this
394
+ */
395
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
396
+ {
397
+ $this->_campaign = $campaign;
398
+
399
+ return $this;
400
  }
401
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Tasks.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,30 +17,39 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Tasks extends Mage_Adminhtml_Block_Template
22
  {
23
-
 
 
 
 
24
  protected function _prepareLayout()
25
  {
26
  parent::_prepareLayout();
27
  $this->setTemplate('mzax/emarketing/campaign/tasks.phtml');
 
 
28
  }
29
-
30
-
31
  /**
32
- *
 
33
  * @return Mzax_Emarketing_Model_Campaign
34
  */
35
  public function getCampaign()
36
  {
37
  return Mage::registry('current_campaign');
38
  }
39
-
40
-
41
-
42
  /**
43
  * Retrieve action url
44
- *
 
 
45
  * @return string
46
  */
47
  public function getActionUrl($action)
@@ -50,6 +58,4 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Tasks extends Mage_Adminhtml_Block
50
  'id' => $this->getCampaign()->getId()
51
  ));
52
  }
53
-
54
-
55
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Tasks
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Tasks extends Mage_Adminhtml_Block_Template
24
  {
25
+ /**
26
+ * Prepare layout
27
+ *
28
+ * @return $this
29
+ */
30
  protected function _prepareLayout()
31
  {
32
  parent::_prepareLayout();
33
  $this->setTemplate('mzax/emarketing/campaign/tasks.phtml');
34
+
35
+ return $this;
36
  }
37
+
 
38
  /**
39
+ * Retrieve campaign
40
+ *
41
  * @return Mzax_Emarketing_Model_Campaign
42
  */
43
  public function getCampaign()
44
  {
45
  return Mage::registry('current_campaign');
46
  }
47
+
 
 
48
  /**
49
  * Retrieve action url
50
+ *
51
+ * @param string $action
52
+ *
53
  * @return string
54
  */
55
  public function getActionUrl($action)
58
  'id' => $this->getCampaign()->getId()
59
  ));
60
  }
 
 
61
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tab/Test.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,27 +17,24 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
22
  {
23
-
24
-
25
  /**
26
  * Retrieve filter
27
- *
28
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
29
  */
30
  public function getFilter()
31
  {
32
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
33
  $campaign = Mage::registry('current_campaign');
 
34
  return $campaign->getRecipientProvider()->getFilter();
35
  }
36
-
37
-
38
-
39
-
40
-
41
-
42
  /**
43
  * Generate url by route and parameters
44
  *
@@ -49,12 +45,10 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Test extends Mzax_Emarketing_Block
49
  public function getUrl($route = '', $params = array())
50
  {
51
  $params['campaign'] = $this->getCampaign()->getId();
 
52
  return parent::getUrl($route, $params);
53
  }
54
-
55
-
56
-
57
-
58
  /**
59
  * Retrieve current campaign
60
  *
@@ -64,6 +58,4 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tab_Test extends Mzax_Emarketing_Block
64
  {
65
  return Mage::registry('current_campaign');
66
  }
67
-
68
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tab_Test
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Edit_Tab_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
24
  {
 
 
25
  /**
26
  * Retrieve filter
27
+ *
28
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
29
  */
30
  public function getFilter()
31
  {
32
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
33
  $campaign = Mage::registry('current_campaign');
34
+
35
  return $campaign->getRecipientProvider()->getFilter();
36
  }
37
+
 
 
 
 
 
38
  /**
39
  * Generate url by route and parameters
40
  *
45
  public function getUrl($route = '', $params = array())
46
  {
47
  $params['campaign'] = $this->getCampaign()->getId();
48
+
49
  return parent::getUrl($route, $params);
50
  }
51
+
 
 
 
52
  /**
53
  * Retrieve current campaign
54
  *
58
  {
59
  return Mage::registry('current_campaign');
60
  }
 
 
61
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Edit/Tabs.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,70 +17,91 @@
18
  */
19
 
20
 
 
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
  parent::__construct();
 
27
  $this->setId('mzax_emarketing_info_tabs');
28
  $this->setDestElementId('edit_form');
29
  $this->setTitle($this->__('Setup Campaign'));
30
  }
31
 
 
 
 
32
  protected function _beforeToHtml()
33
  {
34
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
35
  $campaign = Mage::registry('current_campaign');
36
-
37
-
38
-
39
- if(!$campaign->getMedium()) {
 
 
40
  $this->addTab('medium', array(
41
  'label' => $this->__('Choose Medium'),
42
- 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_medium')->initForm()->toHtml(),
43
  'active' => true
44
  ));
45
- }
46
- else {
47
-
48
- $mediumTitle = Mage::getSingleton('mzax_emarketing/medium')->getOptionText($campaign->getData('medium'));
49
- if($campaign->getId()) {
50
  $this->setTitle($this->__('%s Campaign', $mediumTitle));
51
- }
52
- else {
53
  $this->setTitle($this->__('New %s Campaign', $mediumTitle));
54
  }
55
-
56
-
 
 
 
 
 
57
  $this->addTab('settings', array(
58
  'label' => $this->__('Settings'),
59
- 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_settings')->initForm()->toHtml(),
60
  'active' => true
61
  ));
62
-
63
-
64
- $this->addTab('content', array(
65
- 'label' => $this->__('Content'),
66
- 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_content')->toHtml(),
67
- 'active' => false
68
  ));
69
-
70
  // only available if saved
71
- if($campaign->getId())
72
- {
 
 
 
 
 
73
  $this->addTab('filters', array(
74
  'label' => $this->__('Filters / Segmentation'),
75
- 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_filters')->initForm()->toHtml(),
76
  'active' => false
77
- ));
78
  $this->addTab('recipients', array(
79
  'label' => $this->__('Find Recipients'),
80
  'class' => 'ajax',
81
  'url' => $this->getUrl('*/*/recipients', array('_current' => true)),
82
  ));
83
-
84
- if(!$campaign->isArchived()) {
85
  $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_report');
86
  $this->addTab('report', array(
87
  'label' => $this->__('Report'),
@@ -89,47 +109,52 @@ class Mzax_Emarketing_Block_Campaign_Edit_Tabs extends Mage_Adminhtml_Block_Widg
89
  'url' => $this->getUrl('*/*/report', array('_current' => true)),
90
  ));
91
  }
92
-
93
-
94
  $this->addTab('tasks', array(
95
  'label' => $this->__('Tasks'),
96
- 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_tasks')->toHtml(),
97
  'active' => false
98
  ));
99
-
100
  $campaign->getMedium()->prepareCampaignTabs($this);
101
-
102
- if($count = $campaign->countRecipientErrors()) {
103
  $this->addTab('errors', array(
104
  'label' => $this->__('Recipient Errors (%s)', $count),
105
  'class' => 'ajax',
106
  'url' => $this->getUrl('*/*/errorGrid', array('_current' => true))
107
  ));
108
  }
109
- }
110
- else if($campaign->getPreset())
111
- {
 
112
  $this->addTab('filters', array(
113
  'label' => $this->__('Filters / Segmentation'),
114
- 'content' => $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_filters')->initForm()->toHtml(),
115
  'active' => false
116
  ));
117
  }
118
  }
119
-
120
-
121
  $this->_updateActiveTab();
 
122
  return parent::_beforeToHtml();
123
  }
124
 
 
 
 
 
 
125
  protected function _updateActiveTab()
126
  {
127
- $tabId = $this->getRequest()->getParam('tab');
128
- if( $tabId ) {
129
- $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
130
- if($tabId) {
131
- $this->setActiveTab($tabId);
132
- }
133
- }
134
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Edit_Tabs
22
+ *
23
+ * @method setTitle(string $title)
24
+ */
25
  class Mzax_Emarketing_Block_Campaign_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
26
  {
27
+ /**
28
+ * Mzax_Emarketing_Block_Campaign_Edit_Tabs constructor.
29
+ */
30
  public function __construct()
31
  {
32
  parent::__construct();
33
+
34
  $this->setId('mzax_emarketing_info_tabs');
35
  $this->setDestElementId('edit_form');
36
  $this->setTitle($this->__('Setup Campaign'));
37
  }
38
 
39
+ /**
40
+ * @return Mage_Core_Block_Abstract
41
+ */
42
  protected function _beforeToHtml()
43
  {
44
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
45
  $campaign = Mage::registry('current_campaign');
46
+
47
+ if (!$campaign->getMedium()) {
48
+ /** @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Medium $mediumTab */
49
+ $mediumTab = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_medium');
50
+ $mediumTabContent = $mediumTab->initForm()->toHtml();
51
+
52
  $this->addTab('medium', array(
53
  'label' => $this->__('Choose Medium'),
54
+ 'content' => $mediumTabContent,
55
  'active' => true
56
  ));
57
+ } else {
58
+ /** @var Mzax_Emarketing_Model_Medium $mediumFactory */
59
+ $mediumFactory = Mage::getSingleton('mzax_emarketing/medium');
60
+ $mediumTitle = $mediumFactory->getOptionText($campaign->getData('medium'));
61
+ if ($campaign->getId()) {
62
  $this->setTitle($this->__('%s Campaign', $mediumTitle));
63
+ } else {
 
64
  $this->setTitle($this->__('New %s Campaign', $mediumTitle));
65
  }
66
+
67
+ /** @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Settings $settingsTab */
68
+ $settingsTab = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_settings');
69
+
70
+ /** @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Content $contentTab */
71
+ $contentTab = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_content');
72
+
73
  $this->addTab('settings', array(
74
  'label' => $this->__('Settings'),
75
+ 'content' => $settingsTab->initForm()->toHtml(),
76
  'active' => true
77
  ));
78
+
79
+ $this->addTab('content', array(
80
+ 'label' => $this->__('Content'),
81
+ 'content' => $contentTab->toHtml(),
82
+ 'active' => false
 
83
  ));
84
+
85
  // only available if saved
86
+ if ($campaign->getId()) {
87
+ /** @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters $filtersTab */
88
+ $filtersTab = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_filters');
89
+
90
+ /** @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Tasks $taskTab */
91
+ $taskTab = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_tasks');
92
+
93
  $this->addTab('filters', array(
94
  'label' => $this->__('Filters / Segmentation'),
95
+ 'content' => $filtersTab->initForm()->toHtml(),
96
  'active' => false
97
+ ));
98
  $this->addTab('recipients', array(
99
  'label' => $this->__('Find Recipients'),
100
  'class' => 'ajax',
101
  'url' => $this->getUrl('*/*/recipients', array('_current' => true)),
102
  ));
103
+
104
+ if (!$campaign->isArchived()) {
105
  $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_report');
106
  $this->addTab('report', array(
107
  'label' => $this->__('Report'),
109
  'url' => $this->getUrl('*/*/report', array('_current' => true)),
110
  ));
111
  }
112
+
 
113
  $this->addTab('tasks', array(
114
  'label' => $this->__('Tasks'),
115
+ 'content' => $taskTab->toHtml(),
116
  'active' => false
117
  ));
118
+
119
  $campaign->getMedium()->prepareCampaignTabs($this);
120
+
121
+ if ($count = $campaign->countRecipientErrors()) {
122
  $this->addTab('errors', array(
123
  'label' => $this->__('Recipient Errors (%s)', $count),
124
  'class' => 'ajax',
125
  'url' => $this->getUrl('*/*/errorGrid', array('_current' => true))
126
  ));
127
  }
128
+ } elseif ($campaign->getData('preset')) {
129
+ /** @var Mzax_Emarketing_Block_Campaign_Edit_Tab_Filters $filtersTab */
130
+ $filtersTab = $this->getLayout()->createBlock('mzax_emarketing/campaign_edit_tab_filters');
131
+
132
  $this->addTab('filters', array(
133
  'label' => $this->__('Filters / Segmentation'),
134
+ 'content' => $filtersTab->initForm()->toHtml(),
135
  'active' => false
136
  ));
137
  }
138
  }
139
+
 
140
  $this->_updateActiveTab();
141
+
142
  return parent::_beforeToHtml();
143
  }
144
 
145
+ /**
146
+ * Update current active tab
147
+ *
148
+ * @return void
149
+ */
150
  protected function _updateActiveTab()
151
  {
152
+ $tabId = $this->getRequest()->getParam('tab');
153
+ if ($tabId) {
154
+ $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
155
+ if ($tabId) {
156
+ $this->setActiveTab($tabId);
157
+ }
158
+ }
159
  }
160
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,54 +17,67 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- * Campaign Grid
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.4.10
29
  */
30
  class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Grid
31
  {
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
-
34
- protected $_tagColors = 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');
35
-
36
  protected $_tagColorMap = array();
37
-
38
-
 
 
39
  public function __construct()
40
  {
41
  parent::__construct();
 
42
  $this->setId('campaign_grid');
43
  $this->setUseAjax(true);
44
  $this->setSaveParametersInSession(true);
45
  $this->setDefaultSort('campaign_id');
46
  }
47
-
48
-
49
 
 
 
 
50
  protected function _prepareCollection()
51
  {
52
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
53
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
54
-
55
- if(!$this->getRequest()->getParam('archive')) {
56
  $collection->addArchiveFilter(false);
57
  }
58
-
59
  $this->setCollection($collection);
60
-
61
  return parent::_prepareCollection();
62
  }
63
 
64
-
65
-
 
 
 
66
  protected function _prepareLayout()
67
  {
68
- if( $this->getRequest()->getParam('archive') ) {
69
  $this->setChild('archive_button',
70
  $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
71
  'label' => $this->__('Hide Archived'),
@@ -73,8 +85,7 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
73
  'class' => 'task'
74
  ))
75
  );
76
- }
77
- else {
78
  $this->setChild('archive_button',
79
  $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
80
  'label' => $this->__('Show Archived'),
@@ -83,24 +94,30 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
83
  ))
84
  );
85
  }
86
-
87
- return parent::_prepareLayout();
 
 
88
  }
89
-
90
-
91
-
92
-
 
 
93
  public function getMainButtonsHtml()
94
  {
95
  $html = parent::getMainButtonsHtml();
96
  $html = $this->getChildHtml('archive_button') . $html;
97
-
98
  return $html;
99
  }
100
 
101
-
102
-
103
-
 
 
104
  protected function _prepareColumns()
105
  {
106
  $this->addColumn('added_at', array(
@@ -118,14 +135,13 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
118
  'width' => 150,
119
  'type' => 'datetime'
120
  ));
121
-
122
  $this->addColumn('name', array(
123
  'header' => $this->__('Name'),
124
  'index' => 'name',
125
  'frame_callback' => array($this, 'renderName')
126
  ));
127
-
128
-
129
  $this->addColumn('recipients', array(
130
  'header' => $this->__('Recipients'),
131
  'index' => 'provider',
@@ -133,7 +149,7 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
133
  'width' => 150,
134
  'options' => Mage::getSingleton('mzax_emarketing/recipient_provider')->getOptionHash()
135
  ));
136
-
137
  $this->addColumn('medium', array(
138
  'header' => $this->__('Medium'),
139
  'index' => 'medium',
@@ -141,7 +157,7 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
141
  'width' => 100,
142
  'options' => Mage::getSingleton('mzax_emarketing/medium')->getMediums()
143
  ));
144
-
145
  $this->addColumn('running', array(
146
  'header' => $this->__('Is running'),
147
  'index' => 'running',
@@ -152,14 +168,14 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
152
  1 => $this->__('Yes')
153
  )
154
  ));
155
-
156
  $this->addColumn('stats', array(
157
  'header' => Mage::helper('mzax_emarketing')->__('Quick Stats'),
158
  'filter' => false,
159
  'sortable' => false,
160
  'renderer' => 'mzax_emarketing/campaign_grid_renderer_stats'
161
  ));
162
-
163
  $this->addColumn('count', array(
164
  'header' => $this->__('Recip.'),
165
  'index' => 'sending_stats',
@@ -168,48 +184,50 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
168
  'type' => 'number'
169
  ));
170
 
171
- return parent::_prepareColumns();
 
 
172
  }
173
-
174
-
175
  /**
176
  * Name Frame Callback
177
- *
178
  * @param string $value
179
  * @param Mzax_Emarketing_Model_Campaign $row
180
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
181
  * @param boolean $export
 
182
  * @return string
183
  */
184
  public function renderName($value, $row, $column, $export)
185
  {
186
- if(!$export) {
187
-
188
- if($row->isRunning()) {
189
  $value .= ' <span class="mzax-grid-running"></span>';
190
  }
191
-
192
- foreach($row->getTags() as $tag) {
193
-
194
  $t = strtolower($tag);
195
- if(!isset($this->_tagColorMap[$t])) {
196
  $this->_tagColorMap[$t] = $this->_tagColors[count($this->_tagColorMap)%count($this->_tagColors)];
197
  }
198
-
199
  $value .= ' <span class="mzax-grid-tag" style="background-color: #' . $this->_tagColorMap[$t] . ';">' . $this->escapeHtml($tag) . '</span>';
200
  }
201
  }
202
  return $value;
203
  }
204
-
205
-
206
-
207
 
 
 
 
 
 
208
  protected function _prepareMassaction()
209
  {
210
  $this->setMassactionIdField('campaign_id');
211
  $this->getMassactionBlock()->setFormFieldName('campaigns');
212
-
213
  $this->getMassactionBlock()->addItem('start', array(
214
  'label' => $this->__('Start campaigns'),
215
  'url' => $this->getUrl('*/*/massStart'),
@@ -225,7 +243,6 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
225
  'url' => $this->getUrl('*/*/massArchive'),
226
  'confirm' => $this->__('Are you sure you want to archive all selected campaigns?')
227
  ));
228
-
229
  $this->getMassactionBlock()->addItem('add_tag', array(
230
  'label'=> $this->__('Add tag(s)...'),
231
  'url' => $this->getUrl('*/*/massAddTag', array('_current'=>true)),
@@ -238,7 +255,6 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
238
  )
239
  )
240
  ));
241
-
242
  $this->getMassactionBlock()->addItem('remove_tag', array(
243
  'label'=> $this->__('Remove tag(s)...'),
244
  'url' => $this->getUrl('*/*/massRemoveTag', array('_current'=>true)),
@@ -251,20 +267,27 @@ class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Gr
251
  )
252
  )
253
  ));
254
-
255
-
256
  return $this;
257
  }
258
-
259
-
260
-
261
-
262
 
 
 
 
 
 
263
  public function getGridUrl()
264
  {
265
  return $this->getUrl('*/*/grid', array('_current'=> true));
266
  }
267
 
 
 
 
 
 
 
 
268
  public function getRowUrl($row)
269
  {
270
  return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Grid
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * @var string[]
27
+ */
28
+ protected $_tagColors = array(
29
+ '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4',
30
+ 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E',
31
+ 'D7D020', '00A6D4', 'A559BF', '14D277', '627379', 'FC7A00',
32
+ 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277',
33
+ '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4',
34
+ 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E',
35
+ 'D7D020', '00A6D4', 'A559BF', '14D277'
36
+ );
37
 
38
+ /**
39
+ * @var array
40
+ */
41
  protected $_tagColorMap = array();
42
+
43
+ /**
44
+ * Mzax_Emarketing_Block_Campaign_Grid constructor.
45
+ */
46
  public function __construct()
47
  {
48
  parent::__construct();
49
+
50
  $this->setId('campaign_grid');
51
  $this->setUseAjax(true);
52
  $this->setSaveParametersInSession(true);
53
  $this->setDefaultSort('campaign_id');
54
  }
 
 
55
 
56
+ /**
57
+ * @return Mage_Adminhtml_Block_Widget_Grid
58
+ */
59
  protected function _prepareCollection()
60
  {
61
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
62
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
63
+
64
+ if (!$this->getRequest()->getParam('archive')) {
65
  $collection->addArchiveFilter(false);
66
  }
67
+
68
  $this->setCollection($collection);
69
+
70
  return parent::_prepareCollection();
71
  }
72
 
73
+ /**
74
+ * Prepare layout
75
+ *
76
+ * @return $this
77
+ */
78
  protected function _prepareLayout()
79
  {
80
+ if ($this->getRequest()->getParam('archive')) {
81
  $this->setChild('archive_button',
82
  $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
83
  'label' => $this->__('Hide Archived'),
85
  'class' => 'task'
86
  ))
87
  );
88
+ } else {
 
89
  $this->setChild('archive_button',
90
  $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
91
  'label' => $this->__('Show Archived'),
94
  ))
95
  );
96
  }
97
+
98
+ parent::_prepareLayout();
99
+
100
+ return $this;
101
  }
102
+
103
+ /**
104
+ * Retrieve main buttons html
105
+ *
106
+ * @return string
107
+ */
108
  public function getMainButtonsHtml()
109
  {
110
  $html = parent::getMainButtonsHtml();
111
  $html = $this->getChildHtml('archive_button') . $html;
112
+
113
  return $html;
114
  }
115
 
116
+ /**
117
+ * Prepare columns
118
+ *
119
+ * @return $this
120
+ */
121
  protected function _prepareColumns()
122
  {
123
  $this->addColumn('added_at', array(
135
  'width' => 150,
136
  'type' => 'datetime'
137
  ));
138
+
139
  $this->addColumn('name', array(
140
  'header' => $this->__('Name'),
141
  'index' => 'name',
142
  'frame_callback' => array($this, 'renderName')
143
  ));
144
+
 
145
  $this->addColumn('recipients', array(
146
  'header' => $this->__('Recipients'),
147
  'index' => 'provider',
149
  'width' => 150,
150
  'options' => Mage::getSingleton('mzax_emarketing/recipient_provider')->getOptionHash()
151
  ));
152
+
153
  $this->addColumn('medium', array(
154
  'header' => $this->__('Medium'),
155
  'index' => 'medium',
157
  'width' => 100,
158
  'options' => Mage::getSingleton('mzax_emarketing/medium')->getMediums()
159
  ));
160
+
161
  $this->addColumn('running', array(
162
  'header' => $this->__('Is running'),
163
  'index' => 'running',
168
  1 => $this->__('Yes')
169
  )
170
  ));
171
+
172
  $this->addColumn('stats', array(
173
  'header' => Mage::helper('mzax_emarketing')->__('Quick Stats'),
174
  'filter' => false,
175
  'sortable' => false,
176
  'renderer' => 'mzax_emarketing/campaign_grid_renderer_stats'
177
  ));
178
+
179
  $this->addColumn('count', array(
180
  'header' => $this->__('Recip.'),
181
  'index' => 'sending_stats',
184
  'type' => 'number'
185
  ));
186
 
187
+ parent::_prepareColumns();
188
+
189
+ return $this;
190
  }
191
+
 
192
  /**
193
  * Name Frame Callback
194
+ *
195
  * @param string $value
196
  * @param Mzax_Emarketing_Model_Campaign $row
197
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
198
  * @param boolean $export
199
+ *
200
  * @return string
201
  */
202
  public function renderName($value, $row, $column, $export)
203
  {
204
+ if (!$export) {
205
+ if ($row->isRunning()) {
 
206
  $value .= ' <span class="mzax-grid-running"></span>';
207
  }
208
+
209
+ foreach ($row->getTags() as $tag) {
 
210
  $t = strtolower($tag);
211
+ if (!isset($this->_tagColorMap[$t])) {
212
  $this->_tagColorMap[$t] = $this->_tagColors[count($this->_tagColorMap)%count($this->_tagColors)];
213
  }
214
+
215
  $value .= ' <span class="mzax-grid-tag" style="background-color: #' . $this->_tagColorMap[$t] . ';">' . $this->escapeHtml($tag) . '</span>';
216
  }
217
  }
218
  return $value;
219
  }
 
 
 
220
 
221
+ /**
222
+ * Prepare mass action options
223
+ *
224
+ * @return $this
225
+ */
226
  protected function _prepareMassaction()
227
  {
228
  $this->setMassactionIdField('campaign_id');
229
  $this->getMassactionBlock()->setFormFieldName('campaigns');
230
+
231
  $this->getMassactionBlock()->addItem('start', array(
232
  'label' => $this->__('Start campaigns'),
233
  'url' => $this->getUrl('*/*/massStart'),
243
  'url' => $this->getUrl('*/*/massArchive'),
244
  'confirm' => $this->__('Are you sure you want to archive all selected campaigns?')
245
  ));
 
246
  $this->getMassactionBlock()->addItem('add_tag', array(
247
  'label'=> $this->__('Add tag(s)...'),
248
  'url' => $this->getUrl('*/*/massAddTag', array('_current'=>true)),
255
  )
256
  )
257
  ));
 
258
  $this->getMassactionBlock()->addItem('remove_tag', array(
259
  'label'=> $this->__('Remove tag(s)...'),
260
  'url' => $this->getUrl('*/*/massRemoveTag', array('_current'=>true)),
267
  )
268
  )
269
  ));
270
+
 
271
  return $this;
272
  }
 
 
 
 
273
 
274
+ /**
275
+ * Retrieve grid url
276
+ *
277
+ * @return string
278
+ */
279
  public function getGridUrl()
280
  {
281
  return $this->getUrl('*/*/grid', array('_current'=> true));
282
  }
283
 
284
+ /**
285
+ * Retrieve row url
286
+ *
287
+ * @param Mzax_Emarketing_Model_Campaign $row
288
+ *
289
+ * @return string
290
+ */
291
  public function getRowUrl($row)
292
  {
293
  return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Filter/Filter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,17 +16,27 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Grid_Filter_Filter extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Select
22
  {
23
-
24
-
 
 
 
25
  protected function _getOptions()
26
  {
27
- return Mage::getModel('mzax_emarketing/object_filter')->getAllOptions();
 
 
 
28
  }
29
-
30
-
31
  /**
32
  * Retrieve condition
33
  *
@@ -37,15 +46,12 @@ class Mzax_Emarketing_Block_Campaign_Grid_Filter_Filter extends Mage_Adminhtml_B
37
  {
38
  $id = $this->getValue();
39
  $length = strlen($id);
40
-
41
  $search = "{s:4:\"type\";s:{$length}:\"{$id}\"";
42
-
43
  $helper = Mage::getResourceHelper('core');
44
  $likeExpression = $helper->addLikeEscape($search, array('position' => 'any'));
 
45
  return array('like' => $likeExpression);
46
  }
47
-
48
-
49
-
50
-
51
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Grid_Filter_Filter
22
+ *
23
+ * @method string getValue()
24
+ */
25
  class Mzax_Emarketing_Block_Campaign_Grid_Filter_Filter extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Select
26
  {
27
+ /**
28
+ * Retrieve all options
29
+ *
30
+ * @return array
31
+ */
32
  protected function _getOptions()
33
  {
34
+ /** @var Mzax_Emarketing_Model_Object_Filter $filter */
35
+ $filter = Mage::getModel('mzax_emarketing/object_filter');
36
+
37
+ return $filter->getAllOptions();
38
  }
39
+
 
40
  /**
41
  * Retrieve condition
42
  *
46
  {
47
  $id = $this->getValue();
48
  $length = strlen($id);
49
+
50
  $search = "{s:4:\"type\";s:{$length}:\"{$id}\"";
51
+
52
  $helper = Mage::getResourceHelper('core');
53
  $likeExpression = $helper->addLikeEscape($search, array('position' => 'any'));
54
+
55
  return array('like' => $likeExpression);
56
  }
57
+ }
 
 
 
 
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Action.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,24 +17,31 @@
18
  */
19
 
20
 
21
- class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
 
 
 
 
22
  {
 
 
 
 
 
23
  public function render(Varien_Object $row)
24
  {
25
- if($row->isValidForSend()) {
26
  $actions[] = array(
27
  'url' => $this->getUrl('*/emarketing_queue/edit', array('campaign_id' => $row->getId())),
28
  'caption' => Mage::helper('mzax_emarketing')->__('Queue Campaign...')
29
  );
30
  }
31
 
32
-
33
  $actions[] = array(
34
  'url' => $this->getUrl('*/*/preview', array('campaign'=>$row->getId())),
35
  'popup' => true,
36
  'caption' => Mage::helper('mzax_emarketing')->__('Preview')
37
  );
38
-
39
 
40
  $this->getColumn()->setActions($actions);
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Action
22
+ */
23
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Action
24
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
25
  {
26
+ /**
27
+ * @param Varien_Object $row
28
+ *
29
+ * @return string
30
+ */
31
  public function render(Varien_Object $row)
32
  {
33
+ if ($row->isValidForSend()) {
34
  $actions[] = array(
35
  'url' => $this->getUrl('*/emarketing_queue/edit', array('campaign_id' => $row->getId())),
36
  'caption' => Mage::helper('mzax_emarketing')->__('Queue Campaign...')
37
  );
38
  }
39
 
 
40
  $actions[] = array(
41
  'url' => $this->getUrl('*/*/preview', array('campaign'=>$row->getId())),
42
  'popup' => true,
43
  'caption' => Mage::helper('mzax_emarketing')->__('Preview')
44
  );
 
45
 
46
  $this->getColumn()->setActions($actions);
47
 
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Filter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,46 +16,53 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Filter extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
22
  {
 
 
 
 
 
23
  public function render(Varien_Object $row)
24
  {
25
- if($row instanceof Mzax_Emarketing_Model_Campaign) {
26
  return $this->renderFilters($row);
27
  }
 
28
  return '';
29
-
30
  }
31
-
32
-
33
-
34
- public function renderFilters(Mzax_Emarketing_Model_Campaign $campagin)
 
 
 
35
  {
36
  $html = array();
37
-
38
  $columnFilter = $this->getColumn()->getFilter();
39
- if( $columnFilter ) {
40
  $columnFilter = $columnFilter->getValue();
41
  }
42
-
43
-
44
  /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
45
- foreach($campagin->getFilters() as $filter) {
46
  $style = '';
47
- if($filter->getType() == $columnFilter) {
48
  $style = 'background:#FFFFDD; color:#222';
49
  }
50
-
51
  $html[] = "<li style=\"{$style}\">{$filter->getQueryString()}</li>";
52
  }
53
-
54
  $html = implode("\n", $html);
55
  $html = "<ul style=\"list-style: inside disc; font-size: 0.8em; color: #666;\">$html</ul>";
56
-
57
  return $html;
58
  }
59
-
60
-
61
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Filter
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Filter extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
24
  {
25
+ /**
26
+ * @param Varien_Object $row
27
+ *
28
+ * @return string
29
+ */
30
  public function render(Varien_Object $row)
31
  {
32
+ if ($row instanceof Mzax_Emarketing_Model_Campaign) {
33
  return $this->renderFilters($row);
34
  }
35
+
36
  return '';
 
37
  }
38
+
39
+ /**
40
+ * @param Mzax_Emarketing_Model_Campaign $campaign
41
+ *
42
+ * @return string
43
+ */
44
+ public function renderFilters(Mzax_Emarketing_Model_Campaign $campaign)
45
  {
46
  $html = array();
47
+
48
  $columnFilter = $this->getColumn()->getFilter();
49
+ if ($columnFilter) {
50
  $columnFilter = $columnFilter->getValue();
51
  }
52
+
 
53
  /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
54
+ foreach ($campaign->getFilters() as $filter) {
55
  $style = '';
56
+ if ($filter->getType() == $columnFilter) {
57
  $style = 'background:#FFFFDD; color:#222';
58
  }
59
+
60
  $html[] = "<li style=\"{$style}\">{$filter->getQueryString()}</li>";
61
  }
62
+
63
  $html = implode("\n", $html);
64
  $html = "<ul style=\"list-style: inside disc; font-size: 0.8em; color: #666;\">$html</ul>";
65
+
66
  return $html;
67
  }
68
+ }
 
 
 
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/SendMail.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,15 +17,24 @@
18
  */
19
 
20
 
21
- class Mzax_Emarketing_Block_Campaign_Grid_Renderer_SendMail extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
 
 
 
 
22
  {
 
 
 
 
 
23
  public function render(Varien_Object $row)
24
- {
25
  $url = $this->getUrl('*/*/sendTestMail', array(
26
  'campaign' => $this->getColumn()->getCampaign()->getId(),
27
  'recipient' => $row->getId(),
28
  ));
29
-
30
  return "<a href=\"{$url}\">{$this->__('Send Mail')}</span>";
31
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Grid_Renderer_SendMail
22
+ */
23
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_SendMail
24
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
25
  {
26
+ /**
27
+ * @param Varien_Object $row
28
+ *
29
+ * @return string
30
+ */
31
  public function render(Varien_Object $row)
32
+ {
33
  $url = $this->getUrl('*/*/sendTestMail', array(
34
  'campaign' => $this->getColumn()->getCampaign()->getId(),
35
  'recipient' => $row->getId(),
36
  ));
37
+
38
  return "<a href=\"{$url}\">{$this->__('Send Mail')}</span>";
39
  }
40
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Sender.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,23 +16,33 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
21
- class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Sender extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
 
 
 
 
22
  {
 
 
 
 
 
23
  public function render(Varien_Object $row)
24
  {
25
  $sender = $row->getSender();
26
-
27
  $str = '';
28
- if(isset($sender['name'])) {
29
  $str .= htmlspecialchars($sender['name']) . ' ';
30
- }
31
- if($sender['email']) {
32
  $str .= '[' . $sender['email'] . ']';
33
- }
34
- if($str == '') {
35
  $str .= '---';
36
- }
 
37
  return $str;
38
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Sender
22
+ */
23
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Sender
24
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
  {
26
+ /**
27
+ * @param Varien_Object $row
28
+ *
29
+ * @return string
30
+ */
31
  public function render(Varien_Object $row)
32
  {
33
  $sender = $row->getSender();
34
+
35
  $str = '';
36
+ if (isset($sender['name'])) {
37
  $str .= htmlspecialchars($sender['name']) . ' ';
38
+ }
39
+ if ($sender['email']) {
40
  $str .= '[' . $sender['email'] . ']';
41
+ }
42
+ if ($str == '') {
43
  $str .= '---';
44
+ }
45
+
46
  return $str;
47
  }
48
+ }
app/code/community/Mzax/Emarketing/Block/Campaign/Grid/Renderer/Stats.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,40 +16,49 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
21
- class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Stats extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
 
 
 
 
22
  {
 
 
 
 
 
23
  public function render(Varien_Object $row)
24
  {
25
- if($row instanceof Mzax_Emarketing_Model_Campaign && $row->getSendingStats() > 0) {
26
  return $this->renderStats($row);
27
  }
28
  return '';
29
-
30
  }
31
-
32
-
33
-
34
- public function renderStats(Mzax_Emarketing_Model_Campaign $campagin)
 
 
 
35
  {
36
  $html = array();
37
-
38
- $sendings = $campagin->getSendingStats();
39
- $views = $campagin->getViewStats();
40
- $interactions = $campagin->getInteractionStats();
41
- $conversions = $campagin->getConversionStats();
42
- $fails = $campagin->getFailStats();
43
-
44
  $html[] = sprintf('<div class="mzax-grid-stats" title="%s">', $this->__('%s Sendings', $sendings));
45
  $html[] = sprintf('<div class="mzax-grid-stat views" style="width:%01.3f%%" title="%s"></div>', (($views)/$sendings)*100, $this->__('%s Views', $views));
46
  $html[] = sprintf('<div class="mzax-grid-stat interactions" style="width:%01.3f%%" title="%s"></div>', (($interactions)/$sendings)*100, $this->__('%s Interactions', $interactions));
47
  $html[] = sprintf('<div class="mzax-grid-stat conversions" style="width:%01.3f%%" title="%s"></div>', (($conversions)/$sendings)*100, $this->__('%s Conversions', $conversions));
48
  $html[] = sprintf('<div class="mzax-grid-stat fails" style="width:%01.3f%%" title="%s"></div>', (($fails)/$sendings)*100, $this->__('%s Bounces and Optouts', $fails));
49
  $html[] = '</div>';
50
-
51
  return implode("\n", $html);
52
  }
53
-
54
-
55
-
56
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Stats
22
+ */
23
+ class Mzax_Emarketing_Block_Campaign_Grid_Renderer_Stats
24
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
  {
26
+ /**
27
+ * @param Varien_Object $row
28
+ *
29
+ * @return string
30
+ */
31
  public function render(Varien_Object $row)
32
  {
33
+ if ($row instanceof Mzax_Emarketing_Model_Campaign && $row->getSendingStats() > 0) {
34
  return $this->renderStats($row);
35
  }
36
  return '';
37
+
38
  }
39
+
40
+ /**
41
+ * @param Mzax_Emarketing_Model_Campaign $campaign
42
+ *
43
+ * @return string
44
+ */
45
+ public function renderStats(Mzax_Emarketing_Model_Campaign $campaign)
46
  {
47
  $html = array();
48
+
49
+ $sendings = $campaign->getSendingStats();
50
+ $views = $campaign->getViewStats();
51
+ $interactions = $campaign->getInteractionStats();
52
+ $conversions = $campaign->getConversionStats();
53
+ $fails = $campaign->getFailStats();
54
+
55
  $html[] = sprintf('<div class="mzax-grid-stats" title="%s">', $this->__('%s Sendings', $sendings));
56
  $html[] = sprintf('<div class="mzax-grid-stat views" style="width:%01.3f%%" title="%s"></div>', (($views)/$sendings)*100, $this->__('%s Views', $views));
57
  $html[] = sprintf('<div class="mzax-grid-stat interactions" style="width:%01.3f%%" title="%s"></div>', (($interactions)/$sendings)*100, $this->__('%s Interactions', $interactions));
58
  $html[] = sprintf('<div class="mzax-grid-stat conversions" style="width:%01.3f%%" title="%s"></div>', (($conversions)/$sendings)*100, $this->__('%s Conversions', $conversions));
59
  $html[] = sprintf('<div class="mzax-grid-stat fails" style="width:%01.3f%%" title="%s"></div>', (($fails)/$sendings)*100, $this->__('%s Bounces and Optouts', $fails));
60
  $html[] = '</div>';
61
+
62
  return implode("\n", $html);
63
  }
64
+ }
 
 
 
app/code/community/Mzax/Emarketing/Block/Campaign/New.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,42 +16,42 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- *
23
- * @author Jacob Siefer
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- * @version 0.4.10
26
  */
27
  class Mzax_Emarketing_Block_Campaign_New extends Mzax_Emarketing_Block_Campaign_Edit
28
  {
29
-
30
-
 
31
  public function getHeaderText()
32
  {
33
  return $this->__('New Campaign');
34
  }
35
 
36
-
 
 
37
  public function getValidationUrl()
38
  {
39
  return null;
40
  }
41
-
42
-
 
 
43
  protected function _prepareLayout()
44
  {
45
- parent::_prepareLayout();
46
-
47
- /* @var $campaign Mzax_Emarketing_Model_Campaign */
48
- $campaign = Mage::registry('current_campaign');
49
-
50
  $this->_removeButton('reset');
51
  $this->_removeButton('save');
52
- $this->_removeButton('save_and_continue');
 
 
53
  }
54
-
55
-
56
  /**
57
  * Get form action URL
58
  *
@@ -62,5 +61,4 @@ class Mzax_Emarketing_Block_Campaign_New extends Mzax_Emarketing_Block_Campaign_
62
  {
63
  return $this->getUrl('*/*/new');
64
  }
65
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Block_Campaign_New
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Campaign_New extends Mzax_Emarketing_Block_Campaign_Edit
24
  {
25
+ /**
26
+ * @return string
27
+ */
28
  public function getHeaderText()
29
  {
30
  return $this->__('New Campaign');
31
  }
32
 
33
+ /**
34
+ * @return null
35
+ */
36
  public function getValidationUrl()
37
  {
38
  return null;
39
  }
40
+
41
+ /**
42
+ * @return $this
43
+ */
44
  protected function _prepareLayout()
45
  {
46
+ parent::_prepareLayout();
47
+
 
 
 
48
  $this->_removeButton('reset');
49
  $this->_removeButton('save');
50
+ $this->_removeButton('save_and_continue');
51
+
52
+ return $this;
53
  }
54
+
 
55
  /**
56
  * Get form action URL
57
  *
61
  {
62
  return $this->getUrl('*/*/new');
63
  }
 
64
  }
app/code/community/Mzax/Emarketing/Block/Campaign/New/Presets.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,35 +17,37 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_New_Presets extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset
22
  {
23
-
24
  /**
25
- *
26
  * @var Mzax_Emarketing_Model_Resource_Campaign_Preset_Collection
27
  */
28
  protected $_presets;
29
-
30
-
 
 
31
  public function _construct()
32
  {
33
  parent::_construct();
 
34
  $this->setTemplate('mzax/emarketing/campaign/presets.phtml');
35
  }
36
-
37
-
38
-
39
  /**
40
  * Retrieve presets
41
- *
42
  * @return Mzax_Emarketing_Model_Resource_Campaign_Preset_Collection
43
  */
44
  public function getPresets()
45
  {
46
- if(!$this->_presets) {
47
  $this->_presets = Mage::getResourceModel('mzax_emarketing/campaign_preset_collection');
48
  }
 
49
  return $this->_presets;
50
  }
51
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_New_Presets
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_New_Presets extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset
24
  {
 
25
  /**
 
26
  * @var Mzax_Emarketing_Model_Resource_Campaign_Preset_Collection
27
  */
28
  protected $_presets;
29
+
30
+ /**
31
+ * @return void
32
+ */
33
  public function _construct()
34
  {
35
  parent::_construct();
36
+
37
  $this->setTemplate('mzax/emarketing/campaign/presets.phtml');
38
  }
39
+
 
 
40
  /**
41
  * Retrieve presets
42
+ *
43
  * @return Mzax_Emarketing_Model_Resource_Campaign_Preset_Collection
44
  */
45
  public function getPresets()
46
  {
47
+ if (!$this->_presets) {
48
  $this->_presets = Mage::getResourceModel('mzax_emarketing/campaign_preset_collection');
49
  }
50
+
51
  return $this->_presets;
52
  }
 
53
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Preview.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,109 +16,117 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Campaign_Preview extends Mage_Adminhtml_Block_Widget
21
  {
22
-
 
 
23
  protected $_campaign;
24
-
25
-
 
 
26
  protected $_recipient;
27
-
28
-
29
-
30
  /**
31
- *
32
  * @var Mzax_Emarketing_Model_Outbox_Email
33
  */
34
  protected $_email;
35
-
36
-
 
 
 
 
37
  protected function _preparePreview()
38
  {
39
  $campaign = $this->getCampaign();
40
-
41
  $this->setTemplate("mzax/emarketing/campaign/medium/{$campaign->getMedium()->getMediumId()}/preview.phtml");
42
-
 
43
  $head = $this->getLayout()->getBlock('head');
44
- if($head) {
45
  $content = $this->getRecipient()->getContent();
46
-
47
- if($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
48
  $head->setTitle($this->__('Preview - %s / %s', $campaign->getName(), $content->getName()));
49
- }
50
- else {
51
  $head->setTitle($this->__('Preview - %s / Original', $campaign->getName(), $content->getName()));
52
  }
53
  }
54
  }
55
-
56
-
57
- public function setCampaign($campaign)
 
 
 
 
58
  {
59
  $this->_campaign = $campaign;
60
  $this->_recipient = null;
61
  $this->_preparePreview();
 
62
  return $this;
63
  }
64
-
65
-
66
-
67
  /**
68
- *
69
- * @throws Exception
70
  * @return Mzax_Emarketing_Model_Campaign
 
71
  */
72
  public function getCampaign()
73
  {
74
- if(!$this->_campaign) {
75
-
76
  $id = (int) $this->getRequest()->getParam('campaign');
77
-
78
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
79
  $campaign = Mage::getModel('mzax_emarketing/campaign');
80
  $campaign->load($id);
81
-
82
- if(!$campaign->getId()) {
83
  throw new Exception("No campaign found");
84
  }
85
-
86
  $this->_campaign = $campaign;
87
  }
88
  return $this->_campaign;
89
  }
90
-
91
-
92
-
93
-
94
  /**
95
  * Retrieve recipient model
96
- *
97
  * @return Mzax_Emarketing_Model_Recipient
98
  */
99
  public function getRecipient()
100
  {
101
- if(!$this->_recipient) {
102
  $objectId = $this->getRequest()->getParam('entity');
103
-
104
  $content = $this->getCampaign();
105
  // check if we want to preview a certain variation
106
- if($variationId = $this->getRequest()->getParam('variation')) {
107
  $content = $this->getCampaign()->getVariation($variationId);
108
- $this->setEditorId('variation_'.$content->getId().'_body');
109
- }
110
- else {
111
  $this->setEditorId('campaign_body');
112
  }
113
-
114
  $this->_recipient = $this->getCampaign()->createMockRecipient($objectId);
115
  $this->_recipient->setContent($content);
116
-
117
  }
118
  return $this->_recipient;
119
  }
120
-
121
-
122
-
123
  /**
124
  * Retrieve email body
125
  *
@@ -129,19 +136,17 @@ class Mzax_Emarketing_Block_Campaign_Preview extends Mage_Adminhtml_Block_Widget
129
  {
130
  return $this->getEmail()->getSubject();
131
  }
132
-
133
-
134
  /**
135
  * Retrieve email body
136
- *
137
  * @return string
138
  */
139
  public function getBodyHtml()
140
  {
141
  return $this->getEmail()->getBodyHtml();
142
  }
143
-
144
-
145
  /**
146
  * Retrieve email body
147
  *
@@ -151,55 +156,53 @@ class Mzax_Emarketing_Block_Campaign_Preview extends Mage_Adminhtml_Block_Widget
151
  {
152
  return $this->getEmail()->getBodyText();
153
  }
154
-
155
-
156
-
157
  /**
158
- *
159
- * @return array
 
160
  */
161
  public function getLinkReferences()
162
  {
163
  return $this->getEmail()->getLinkReferences();
164
  }
165
-
166
-
167
-
168
  /**
169
- *
 
170
  * @return Mzax_Emarketing_Model_Outbox_Email
171
  */
172
  public function getEmail()
173
  {
174
- if(!$this->_email) {
175
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
176
  $this->_email = Mage::getModel('mzax_emarketing/outbox_email');
177
  try {
178
  $recipient = $this->getRecipient();
179
  $recipient->prepare();
 
180
  $this->_email->setTo($recipient->getAddress());
181
  $this->_email->setRecipient($recipient);
182
  $this->_email->render(true);
183
- }
184
- catch(Exception $error) {
185
  $this->setError($error);
186
  }
187
  }
188
  return $this->_email;
189
  }
190
-
191
-
192
-
 
 
 
193
  public function getRenderTime()
194
  {
195
- if($this->_email) {
196
  return (float) $this->_email->getRenderTime();
197
  }
198
  return 0;
199
  }
200
-
201
-
202
-
203
 
204
  /**
205
  * Is ACE editor enabled
@@ -208,13 +211,6 @@ class Mzax_Emarketing_Block_Campaign_Preview extends Mage_Adminhtml_Block_Widget
208
  */
209
  public function aceEnabled()
210
  {
211
- $enabled = Mage::getStoreConfigFlag('mzax_emarketing/content_management/enable_ace');
212
- if(!$enabled) {
213
- return 0;
214
- }
215
- return (int) $this->getConfig('enable_ace', 1);
216
  }
217
-
218
-
219
-
220
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Preview
22
+ *
23
+ * @method $this setEditorId(string $value)
24
+ * @method $this setError(Exception $value)
25
+ */
26
  class Mzax_Emarketing_Block_Campaign_Preview extends Mage_Adminhtml_Block_Widget
27
  {
28
+ /**
29
+ * @var Mzax_Emarketing_Model_Campaign
30
+ */
31
  protected $_campaign;
32
+
33
+ /**
34
+ * @var Mzax_Emarketing_Model_Recipient
35
+ */
36
  protected $_recipient;
37
+
 
 
38
  /**
 
39
  * @var Mzax_Emarketing_Model_Outbox_Email
40
  */
41
  protected $_email;
42
+
43
+ /**
44
+ * Prepare preview
45
+ *
46
+ * @return void
47
+ */
48
  protected function _preparePreview()
49
  {
50
  $campaign = $this->getCampaign();
51
+
52
  $this->setTemplate("mzax/emarketing/campaign/medium/{$campaign->getMedium()->getMediumId()}/preview.phtml");
53
+
54
+ /** @var Mage_Page_Block_Html_Head $head */
55
  $head = $this->getLayout()->getBlock('head');
56
+ if ($head) {
57
  $content = $this->getRecipient()->getContent();
58
+
59
+ if ($content instanceof Mzax_Emarketing_Model_Campaign_Variation) {
60
  $head->setTitle($this->__('Preview - %s / %s', $campaign->getName(), $content->getName()));
61
+ } else {
 
62
  $head->setTitle($this->__('Preview - %s / Original', $campaign->getName(), $content->getName()));
63
  }
64
  }
65
  }
66
+
67
+ /**
68
+ * @param Mzax_Emarketing_Model_Campaign $campaign
69
+ *
70
+ * @return $this
71
+ */
72
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
73
  {
74
  $this->_campaign = $campaign;
75
  $this->_recipient = null;
76
  $this->_preparePreview();
77
+
78
  return $this;
79
  }
80
+
 
 
81
  /**
82
+ * Retrieve campaign
83
+ *
84
  * @return Mzax_Emarketing_Model_Campaign
85
+ * @throws Exception
86
  */
87
  public function getCampaign()
88
  {
89
+ if (!$this->_campaign) {
 
90
  $id = (int) $this->getRequest()->getParam('campaign');
91
+
92
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
93
  $campaign = Mage::getModel('mzax_emarketing/campaign');
94
  $campaign->load($id);
95
+
96
+ if (!$campaign->getId()) {
97
  throw new Exception("No campaign found");
98
  }
99
+
100
  $this->_campaign = $campaign;
101
  }
102
  return $this->_campaign;
103
  }
104
+
 
 
 
105
  /**
106
  * Retrieve recipient model
107
+ *
108
  * @return Mzax_Emarketing_Model_Recipient
109
  */
110
  public function getRecipient()
111
  {
112
+ if (!$this->_recipient) {
113
  $objectId = $this->getRequest()->getParam('entity');
114
+
115
  $content = $this->getCampaign();
116
  // check if we want to preview a certain variation
117
+ if ($variationId = $this->getRequest()->getParam('variation')) {
118
  $content = $this->getCampaign()->getVariation($variationId);
119
+ $this->setEditorId('variation_' . $content->getId() . '_body');
120
+ } else {
 
121
  $this->setEditorId('campaign_body');
122
  }
123
+
124
  $this->_recipient = $this->getCampaign()->createMockRecipient($objectId);
125
  $this->_recipient->setContent($content);
 
126
  }
127
  return $this->_recipient;
128
  }
129
+
 
 
130
  /**
131
  * Retrieve email body
132
  *
136
  {
137
  return $this->getEmail()->getSubject();
138
  }
139
+
 
140
  /**
141
  * Retrieve email body
142
+ *
143
  * @return string
144
  */
145
  public function getBodyHtml()
146
  {
147
  return $this->getEmail()->getBodyHtml();
148
  }
149
+
 
150
  /**
151
  * Retrieve email body
152
  *
156
  {
157
  return $this->getEmail()->getBodyText();
158
  }
159
+
 
 
160
  /**
161
+ * Retrieve link references
162
+ *
163
+ * @return Mzax_Emarketing_Model_Link_Reference[]
164
  */
165
  public function getLinkReferences()
166
  {
167
  return $this->getEmail()->getLinkReferences();
168
  }
169
+
 
 
170
  /**
171
+ * Prepare recipient and render email in preview mode
172
+ *
173
  * @return Mzax_Emarketing_Model_Outbox_Email
174
  */
175
  public function getEmail()
176
  {
177
+ if (!$this->_email) {
178
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
179
  $this->_email = Mage::getModel('mzax_emarketing/outbox_email');
180
  try {
181
  $recipient = $this->getRecipient();
182
  $recipient->prepare();
183
+
184
  $this->_email->setTo($recipient->getAddress());
185
  $this->_email->setRecipient($recipient);
186
  $this->_email->render(true);
187
+ } catch (Exception $error) {
 
188
  $this->setError($error);
189
  }
190
  }
191
  return $this->_email;
192
  }
193
+
194
+ /**
195
+ * Retrieve render time
196
+ *
197
+ * @return float
198
+ */
199
  public function getRenderTime()
200
  {
201
+ if ($this->_email) {
202
  return (float) $this->_email->getRenderTime();
203
  }
204
  return 0;
205
  }
 
 
 
206
 
207
  /**
208
  * Is ACE editor enabled
211
  */
212
  public function aceEnabled()
213
  {
214
+ return Mage::getStoreConfigFlag('mzax_emarketing/content_management/enable_ace');
 
 
 
 
215
  }
 
 
 
216
  }
app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,12 +17,18 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_SendTestMail extends Mage_Adminhtml_Block_Widget_Form_Container
22
  {
 
 
 
23
  public function __construct()
24
  {
25
  $this->_objectId = 'id';
26
-
27
  $this->_blockGroup = 'mzax_emarketing';
28
  $this->_controller = 'campaign';
29
  $this->_mode = 'sendTestMail';
@@ -36,22 +41,22 @@ class Mzax_Emarketing_Block_Campaign_SendTestMail extends Mage_Adminhtml_Block_W
36
  $this->_removeButton('back');
37
  }
38
 
39
-
40
-
41
-
42
  public function getHeaderText()
43
  {
44
  return $this->__('Send Test Mail');
45
  }
46
 
 
 
 
47
  public function getValidationUrl()
48
  {
49
  return $this->getUrl('*/*/validateTestMail', array('_current'=>true));
50
  }
51
-
52
 
53
-
54
-
55
  /**
56
  * Get form action URL
57
  *
@@ -59,11 +64,11 @@ class Mzax_Emarketing_Block_Campaign_SendTestMail extends Mage_Adminhtml_Block_W
59
  */
60
  public function getFormActionUrl()
61
  {
62
- if ($this->hasFormActionUrl()) {
63
- return $this->getData('form_action_url');
 
64
  }
 
65
  return $this->getUrl('*/*/sendTestMailPost', array('_current' => true));
66
  }
67
-
68
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_SendTestMail
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_SendTestMail extends Mage_Adminhtml_Block_Widget_Form_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Campaign_SendTestMail constructor.
27
+ */
28
  public function __construct()
29
  {
30
  $this->_objectId = 'id';
31
+
32
  $this->_blockGroup = 'mzax_emarketing';
33
  $this->_controller = 'campaign';
34
  $this->_mode = 'sendTestMail';
41
  $this->_removeButton('back');
42
  }
43
 
44
+ /**
45
+ * @return string
46
+ */
47
  public function getHeaderText()
48
  {
49
  return $this->__('Send Test Mail');
50
  }
51
 
52
+ /**
53
+ * @return string
54
+ */
55
  public function getValidationUrl()
56
  {
57
  return $this->getUrl('*/*/validateTestMail', array('_current'=>true));
58
  }
 
59
 
 
 
60
  /**
61
  * Get form action URL
62
  *
64
  */
65
  public function getFormActionUrl()
66
  {
67
+ $url = $this->getData('form_action_url');
68
+ if ($url) {
69
+ return $url;
70
  }
71
+
72
  return $this->getUrl('*/*/sendTestMailPost', array('_current' => true));
73
  }
 
 
74
  }
app/code/community/Mzax/Emarketing/Block/Campaign/SendTestMail/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,65 +17,136 @@
18
  */
19
 
20
 
21
- class Mzax_Emarketing_Block_Campaign_SendTestMail_Form extends Mage_Adminhtml_Block_Widget_Form
 
 
 
22
  {
 
 
 
 
23
 
 
 
 
 
 
 
 
 
 
 
24
  protected function _prepareForm()
25
  {
26
- $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
 
 
 
 
 
 
27
 
28
- /* @var $campaign Mzax_Emarketing_Model_Campaign */
29
- $campaign = Mage::registry('current_campaign');
30
-
31
- /* @var $recipient Mzax_Emarketing_Model_Recipient */
32
- $recipient = Mage::registry('current_recipient');
33
 
34
  $form->addField('id', 'hidden', array(
35
  'name' => 'id',
36
  'value' => $campaign->getId()
37
  ));
38
-
39
  $form->addField('object_id', 'hidden', array(
40
  'name' => 'object_id',
41
  'value' => $recipient->getObjectId()
42
  ));
43
-
44
  $form->addField('recipient_name', 'text', array(
45
  'name' => 'recipient_name',
46
  'label' => $this->__("Recipient Name"),
47
  'value' => $recipient->getName()
48
  ));
49
-
50
-
51
- $user = Mage::getSingleton('admin/session')->getUser();
52
-
53
  $form->addField('recipient_email', 'text', array(
54
  'name' => 'recipient_email',
55
  'label' => $this->__("Recipient Email"),
56
  'value' => $user->getEmail()
57
  ));
58
-
59
-
60
- if($campaign->hasVariations()) {
61
-
62
  $options = $campaign->getVariations()->toOptionArray();
63
-
64
  array_unshift($options, array('value' => '0', 'label' => $this->__('[Orignal]')));
65
-
66
  $form->addField('variation', 'select', array(
67
  'name' => 'variation',
68
  'label' => $this->__("Variation"),
69
  'value' => $this->getRequest()->getParam('variation', '0'),
70
  'values' => $options
71
  ));
72
-
73
-
74
-
75
  }
76
 
77
-
78
  $form->setUseContainer(true);
79
  $this->setForm($form);
80
- return parent::_prepareForm();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_SendTestMail_Form
22
+ */
23
+ class Mzax_Emarketing_Block_Campaign_SendTestMail_Form extends Mzax_Emarketing_Block_Widget_Form
24
  {
25
+ /**
26
+ * @var Mzax_Emarketing_Model_Campaign
27
+ */
28
+ protected $_campaign;
29
 
30
+ /**
31
+ * @var Mzax_Emarketing_Model_Recipient
32
+ */
33
+ protected $_recipient;
34
+
35
+ /**
36
+ * Prepare form
37
+ *
38
+ * @return $this
39
+ */
40
  protected function _prepareForm()
41
  {
42
+ $form = new Varien_Data_Form(
43
+ array(
44
+ 'id' => 'edit_form',
45
+ 'action' => $this->getData('action'),
46
+ 'method' => 'post'
47
+ )
48
+ );
49
 
50
+ $campaign = $this->getCampaign();
51
+ $recipient = $this->getRecipient();
 
 
 
52
 
53
  $form->addField('id', 'hidden', array(
54
  'name' => 'id',
55
  'value' => $campaign->getId()
56
  ));
57
+
58
  $form->addField('object_id', 'hidden', array(
59
  'name' => 'object_id',
60
  'value' => $recipient->getObjectId()
61
  ));
62
+
63
  $form->addField('recipient_name', 'text', array(
64
  'name' => 'recipient_name',
65
  'label' => $this->__("Recipient Name"),
66
  'value' => $recipient->getName()
67
  ));
68
+
69
+ /** @var Mage_Admin_Model_User $user */
70
+ $user = $this->_sessionManager->getAdminSession()->getData('user');
71
+
72
  $form->addField('recipient_email', 'text', array(
73
  'name' => 'recipient_email',
74
  'label' => $this->__("Recipient Email"),
75
  'value' => $user->getEmail()
76
  ));
77
+
78
+ if ($campaign->hasVariations()) {
 
 
79
  $options = $campaign->getVariations()->toOptionArray();
80
+
81
  array_unshift($options, array('value' => '0', 'label' => $this->__('[Orignal]')));
82
+
83
  $form->addField('variation', 'select', array(
84
  'name' => 'variation',
85
  'label' => $this->__("Variation"),
86
  'value' => $this->getRequest()->getParam('variation', '0'),
87
  'values' => $options
88
  ));
 
 
 
89
  }
90
 
 
91
  $form->setUseContainer(true);
92
  $this->setForm($form);
93
+
94
+ return $this;
95
+ }
96
+
97
+ /**
98
+ * Retrieve Campaign
99
+ *
100
+ * @return Mzax_Emarketing_Model_Campaign
101
+ */
102
+ public function getCampaign()
103
+ {
104
+ if (!$this->_campaign) {
105
+ $this->_campaign = Mage::registry('current_campaign');
106
+ }
107
+
108
+ return $this->_campaign;
109
+ }
110
+
111
+ /**
112
+ * Set Campaign
113
+ *
114
+ * @param Mzax_Emarketing_Model_Campaign $campaign
115
+ *
116
+ * @return $this
117
+ */
118
+ public function setCampaign(Mzax_Emarketing_Model_Campaign$campaign)
119
+ {
120
+ $this->_campaign = $campaign;
121
+
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Retrieve Recipient
127
+ *
128
+ * @return Mzax_Emarketing_Model_Recipient
129
+ */
130
+ public function getRecipient()
131
+ {
132
+ if (!$this->_recipient) {
133
+ $this->_recipient = Mage::registry('current_recipient');
134
+ }
135
+
136
+ return $this->_recipient;
137
+ }
138
+
139
+ /**
140
+ * Set Recipient
141
+ *
142
+ * @param Mzax_Emarketing_Model_Recipient $recipient
143
+ *
144
+ * @return $this
145
+ */
146
+ public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
147
+ {
148
+ $this->_recipient = $recipient;
149
+
150
+ return $this;
151
  }
152
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Test.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,10 +17,11 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
22
  {
23
-
24
-
25
  /**
26
  * Retrieve filter
27
  *
@@ -33,38 +33,36 @@ class Mzax_Emarketing_Block_Campaign_Test extends Mzax_Emarketing_Block_Filter_T
33
  $this->prepareEmulation($filter);
34
  return $filter;
35
  }
36
-
37
-
38
-
 
 
 
 
 
39
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
40
  {
41
  $child = $this->getChild('emulate');
42
- if($child && method_exists($child, 'prepareEmulation')) {
43
  $child->prepareEmulation($filter);
44
  }
45
  }
46
-
47
-
48
-
49
-
50
-
51
 
52
  /**
53
  * Generate url by route and parameters
54
  *
55
- * @param string $route
56
- * @param array $params
57
- * @return string
 
58
  */
59
  public function getUrl($route = '', $params = array())
60
  {
61
  $params['id'] = $this->getCampaign()->getId();
62
  return parent::getUrl($route, $params);
63
  }
64
-
65
-
66
-
67
-
68
  /**
69
  * Retrieve current campaign
70
  *
@@ -74,7 +72,4 @@ class Mzax_Emarketing_Block_Campaign_Test extends Mzax_Emarketing_Block_Filter_T
74
  {
75
  return Mage::registry('current_campaign');
76
  }
77
-
78
-
79
-
80
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Test
22
+ */
23
  class Mzax_Emarketing_Block_Campaign_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
24
  {
 
 
25
  /**
26
  * Retrieve filter
27
  *
33
  $this->prepareEmulation($filter);
34
  return $filter;
35
  }
36
+
37
+ /**
38
+ * Prepare emulation
39
+ *
40
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
41
+ *
42
+ * @return void
43
+ */
44
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
45
  {
46
  $child = $this->getChild('emulate');
47
+ if ($child && method_exists($child, 'prepareEmulation')) {
48
  $child->prepareEmulation($filter);
49
  }
50
  }
 
 
 
 
 
51
 
52
  /**
53
  * Generate url by route and parameters
54
  *
55
+ * @param string $route
56
+ * @param array $params
57
+ *
58
+ * @return string
59
  */
60
  public function getUrl($route = '', $params = array())
61
  {
62
  $params['id'] = $this->getCampaign()->getId();
63
  return parent::getUrl($route, $params);
64
  }
65
+
 
 
 
66
  /**
67
  * Retrieve current campaign
68
  *
72
  {
73
  return Mage::registry('current_campaign');
74
  }
 
 
 
75
  }
app/code/community/Mzax/Emarketing/Block/Campaign/Test/Emulate.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,17 +17,18 @@
18
  */
19
 
20
 
 
 
 
 
 
21
  class Mzax_Emarketing_Block_Campaign_Test_Emulate extends Mage_Adminhtml_Block_Template
22
  {
23
-
24
  /**
25
- *
26
  * @var Varien_Data_Form
27
  */
28
  protected $_form;
29
-
30
-
31
-
32
  /**
33
  * Retrieve Varien Data Form
34
  *
@@ -36,48 +36,46 @@ class Mzax_Emarketing_Block_Campaign_Test_Emulate extends Mage_Adminhtml_Block_T
36
  */
37
  public function getForm()
38
  {
39
- if(!$this->_form) {
40
  $this->_form = new Varien_Data_Form();
41
  $this->_form->setElementRenderer(Mage::getBlockSingleton('mzax_emarketing/editable')->setFormat('form'));
42
  $this->_form->setHtmlIdPrefix("emulate_");
43
  $this->_form->setFieldNameSuffix("emulate");
44
  }
 
45
  return $this->_form;
46
  }
47
-
48
-
49
  /**
50
  * Prepare filter
51
- *
52
- * Usally called by parent block class
53
- *
54
  * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
55
  */
56
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
57
  {
58
  $emulate = $this->getRequest()->getParam('emulate');
59
-
60
- if($this->emulate('time')) {
61
- if(isset($emulate['from']) && isset($emulate['to'])) {
62
  $filter->setParam('current_time', array($emulate['from'], $emulate['to']));
63
  $filter->setParam('is_local_time', true);
64
-
65
  }
66
  }
67
-
68
- if($this->emulate('campaign')) {
69
- /* @var $campagin Mzax_Emarketing_Model_Campaign */
70
- $campagin = Mage::getModel('mzax_emarketing/campaign');
71
- $campagin->load($emulate['campaign_id']);
72
-
73
- if($campagin->getId()) {
74
- $filter->setParam('campaign', $campagin);
75
  }
76
  }
77
  }
78
-
79
-
80
-
81
  /**
82
  * Check if we should emulate the specified key
83
  *
@@ -87,85 +85,74 @@ class Mzax_Emarketing_Block_Campaign_Test_Emulate extends Mage_Adminhtml_Block_T
87
  public function emulate($key)
88
  {
89
  $emulate = $this->getRequest()->getParam('emulate');
90
-
91
- if(isset($emulate[$key])) {
92
  return ($emulate[$key] == 1);
93
  }
 
94
  return false;
95
  }
96
-
97
-
98
-
99
-
100
-
101
  /**
102
- *
103
  *
104
  * @return Varien_Data_Form_Element_Abstract
105
  */
106
  public function getCampaignSelect()
107
  {
108
  $params = $this->getRequest()->getParam('emulate');
109
-
110
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
111
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
112
  $collection->addArchiveFilter(false);
113
-
114
  $options = array();
115
- if($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
116
  $options['current'] = $this->__('beeing tracked');
117
  }
118
  $options += $collection->toOptionHash();
119
-
120
- /* @var $campagin Mzax_Emarketing_Model_Campaign */
121
- $campagin = Mage::getModel('mzax_emarketing/campaign');
122
-
123
- if(isset($params['campaign_id'])) {
124
- $campagin->load($params['campaign_id']);
125
  }
126
-
127
  return $this->getForm()->addField('campaign_id', 'select', array(
128
  'name' => 'campaign_id',
129
- 'value_name' => (string) $campagin->getName(),
130
- 'value' => $campagin->getId(),
131
  'options' => $options,
132
  ));
133
-
134
  }
135
-
136
-
137
-
138
-
139
  /**
140
  * Helper for simple select element
141
  *
142
  * @param string $key
143
- * @param array $options
144
  * @return Varien_Data_Form_Element_Abstract
145
  */
146
  public function getDateElement($key)
147
  {
148
  $format = Varien_Date::DATE_INTERNAL_FORMAT;
149
-
150
  $params = $this->getRequest()->getParam('emulate');
151
-
152
- if(isset($params[$key])) {
153
  $value = $params[$key];
154
- }
155
- else {
156
  $value = Zend_Date::now()->toString($format);
157
  }
158
-
159
- return $this->getForm()->addField($key, 'date',array(
160
  'name' => $key,
161
  'value_name' => $value,
162
- 'value' => $value,
163
  'explicit_apply' => true,
164
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
165
  'input_format' => $format,
166
  'format' => $format
167
  ));
168
  }
169
-
170
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Campaign_Test_Emulate
22
+ *
23
+ * @method $this setGrid($grid)
24
+ */
25
  class Mzax_Emarketing_Block_Campaign_Test_Emulate extends Mage_Adminhtml_Block_Template
26
  {
 
27
  /**
 
28
  * @var Varien_Data_Form
29
  */
30
  protected $_form;
31
+
 
 
32
  /**
33
  * Retrieve Varien Data Form
34
  *
36
  */
37
  public function getForm()
38
  {
39
+ if (!$this->_form) {
40
  $this->_form = new Varien_Data_Form();
41
  $this->_form->setElementRenderer(Mage::getBlockSingleton('mzax_emarketing/editable')->setFormat('form'));
42
  $this->_form->setHtmlIdPrefix("emulate_");
43
  $this->_form->setFieldNameSuffix("emulate");
44
  }
45
+
46
  return $this->_form;
47
  }
48
+
 
49
  /**
50
  * Prepare filter
51
+ *
52
+ * Usually called by parent block class
53
+ *
54
  * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
55
  */
56
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
57
  {
58
  $emulate = $this->getRequest()->getParam('emulate');
59
+
60
+ if ($this->emulate('time')) {
61
+ if (isset($emulate['from']) && isset($emulate['to'])) {
62
  $filter->setParam('current_time', array($emulate['from'], $emulate['to']));
63
  $filter->setParam('is_local_time', true);
64
+
65
  }
66
  }
67
+
68
+ if ($this->emulate('campaign')) {
69
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
70
+ $campaign = Mage::getModel('mzax_emarketing/campaign');
71
+ $campaign->load($emulate['campaign_id']);
72
+
73
+ if ($campaign->getId()) {
74
+ $filter->setParam('campaign', $campaign);
75
  }
76
  }
77
  }
78
+
 
 
79
  /**
80
  * Check if we should emulate the specified key
81
  *
85
  public function emulate($key)
86
  {
87
  $emulate = $this->getRequest()->getParam('emulate');
88
+
89
+ if (isset($emulate[$key])) {
90
  return ($emulate[$key] == 1);
91
  }
92
+
93
  return false;
94
  }
95
+
 
 
 
 
96
  /**
 
97
  *
98
  * @return Varien_Data_Form_Element_Abstract
99
  */
100
  public function getCampaignSelect()
101
  {
102
  $params = $this->getRequest()->getParam('emulate');
103
+
104
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
105
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
106
  $collection->addArchiveFilter(false);
107
+
108
  $options = array();
109
+ if ($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
110
  $options['current'] = $this->__('beeing tracked');
111
  }
112
  $options += $collection->toOptionHash();
113
+
114
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
115
+ $campaign = Mage::getModel('mzax_emarketing/campaign');
116
+
117
+ if (isset($params['campaign_id'])) {
118
+ $campaign->load($params['campaign_id']);
119
  }
120
+
121
  return $this->getForm()->addField('campaign_id', 'select', array(
122
  'name' => 'campaign_id',
123
+ 'value_name' => (string) $campaign->getName(),
124
+ 'value' => $campaign->getId(),
125
  'options' => $options,
126
  ));
 
127
  }
128
+
 
 
 
129
  /**
130
  * Helper for simple select element
131
  *
132
  * @param string $key
133
+ *
134
  * @return Varien_Data_Form_Element_Abstract
135
  */
136
  public function getDateElement($key)
137
  {
138
  $format = Varien_Date::DATE_INTERNAL_FORMAT;
139
+
140
  $params = $this->getRequest()->getParam('emulate');
141
+
142
+ if (isset($params[$key])) {
143
  $value = $params[$key];
144
+ } else {
 
145
  $value = Zend_Date::now()->toString($format);
146
  }
147
+
148
+ return $this->getForm()->addField($key, 'date', array(
149
  'name' => $key,
150
  'value_name' => $value,
151
+ 'value' => $value,
152
  'explicit_apply' => true,
153
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
154
  'input_format' => $format,
155
  'format' => $format
156
  ));
157
  }
 
 
158
  }
app/code/community/Mzax/Emarketing/Block/Campaign/View.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,21 +16,21 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Block_Campaign_View extends Mage_Adminhtml_Block_Widget_Grid_Container
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
- $this->_blockGroup = 'mzax_emarketing';
27
  $this->_controller = 'campaign';
28
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Campaigns');
29
  $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Campaign');
30
-
31
 
32
  parent::__construct();
33
  }
34
-
35
-
36
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Block_Campaign_View
21
+ */
22
  class Mzax_Emarketing_Block_Campaign_View extends Mage_Adminhtml_Block_Widget_Grid_Container
23
  {
24
+ /**
25
+ * Mzax_Emarketing_Block_Campaign_View constructor.
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
  parent::__construct();
35
  }
 
 
 
36
  }
app/code/community/Mzax/Emarketing/Block/Chart/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,192 +16,242 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Abstract extends Mage_Core_Block_Template
21
  {
22
-
23
-
 
24
  protected $_chartClass = '';
25
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  protected function _construct()
27
  {
28
  parent::_construct();
29
- $this->setElementId('gchart_'.rand(0, 100000));
 
30
  }
31
-
 
 
 
 
 
32
  public function getChartClass()
33
  {
34
  return "google.visualization.{$this->_chartClass}";
35
  }
36
-
37
-
38
-
39
-
40
-
41
- protected $_columns = array();
42
-
43
-
44
- protected $_rows = array();
45
-
46
-
47
- protected $_overlays = array();
48
-
49
-
50
  public function addOverlay($name, $overlay)
51
  {
52
  $this->_overlays[$name] = $overlay;
 
53
  return $this;
54
  }
55
-
56
-
57
- public function addColumn($label, $type = 'number', $p = null)
58
- {
59
- $this->_columns[] = array($label, $type, $p);
60
- return $this;
61
- }
62
-
63
-
 
 
 
 
 
 
 
 
 
 
 
 
64
  public function clearRows()
65
  {
66
  $this->_rows = array();
 
67
  return $this;
68
- }
69
-
70
- public function addRow(array $row, $offset = null)
 
 
 
 
 
 
 
 
71
  {
72
- if($offset === null) {
73
  $this->_rows[] = $row;
74
- }
75
- else {
76
  array_splice($this->_rows, $offset, 0, array($row));
77
- }
78
- return $this;
79
- }
80
-
81
-
82
- public function getOptionJs()
 
 
 
 
 
83
  {
84
  $ignore = array('type', 'module_name', 'auto_redraw');
85
  $options = array();
86
- foreach($this->_data as $key => $value) {
87
- if(in_array($key, $ignore)) {
88
  continue;
89
  }
90
  $name = lcfirst($this->_camelize($key));
91
  $options[$name] = $value;
92
  }
93
-
94
- return Zend_Json::encode($options);
95
- }
96
-
97
-
98
-
99
-
100
-
101
- protected function _getDataJson()
102
- {
103
- $json = array();
104
- foreach($this->_rows as $row) {
105
- $data = array();
106
- foreach($this->_columns as $i => $column) {
 
107
  list($label, $type, $p) = $column;
108
- $value = $row[$i];
109
- if($value === null) {
110
- $value = 'null';
111
- }
112
- else {
113
- switch($type) {
114
- case 'tooltip':
115
- case 'string':
116
- $value = "'".$this->jsQuoteEscape($value)."'";
117
  break;
118
-
119
  case 'date':
120
- if($value instanceof DateTime) {
121
  $value = "new Date({$value->format('Y, n-1, j')})";
122
- }
123
- break;
124
-
125
- default:
126
- $value = (float) $value;
127
- break;
128
- }
129
- }
130
- $data[] = $value;
131
- }
132
-
133
- $json[] = "[" . implode(', ', $data) . "]";
134
- }
135
- return "[" . implode(",\n", $json) . "]";
136
- }
137
-
138
-
139
-
140
- protected function _getDataTableJs($name = 'data')
141
- {
142
- $html = "var {$name} = new google.visualization.DataTable();\n";
143
-
144
- foreach($this->_columns as $column) {
 
 
 
145
  list($label, $type, $p) = $column;
146
-
147
  $json = array('type' => $type, 'label' => $label);
148
- if($p) {
149
  $json['p'] = $p;
150
  }
151
  $json = Zend_Json::encode($json);
152
-
153
- $html .= "{$name}.addColumn($json);\n";
154
- }
155
-
156
- $html .= "{$name}.addRows({$this->_getDataJson()});";
157
-
158
- return $html;
159
- }
160
-
161
-
162
-
163
-
164
-
165
- public function _toHtml()
 
166
  {
167
  $autoredraw = (int) $this->getDataSetDefault('auto_redraw', true);
168
-
169
  $overlayHtml = '';
170
- foreach($this->_overlays as $name => $overlay) {
171
- if($overlay instanceof Mage_Core_Block_Abstract) {
172
  $overlay = $overlay->toHtml();
173
  }
174
  $overlayHtml .= "<div class=\"overlay $name\">$overlay</div>";
175
  }
176
-
177
-
178
  return <<<HTML
179
- <div id="{$this->getElementId()}-wrapper" class="chart-wrapper">
180
  <div id="{$this->getElementId()}"></div>
181
  {$overlayHtml}
182
- </div>
183
- <script type="text/javascript">
184
- (function() {
185
- {$this->_getDataTableJs('data')}
186
- var chart = new {$this->getChartClass()}(document.getElementById('{$this->getElementId()}'));
187
  chart.draw(data, {$this->getOptionJs()});
188
- if($autoredraw) {
189
- Event.observe(window, "resize", function() {
190
- chart.draw(data, options);
191
  });
192
- }
193
- }());
194
- </script>
195
- HTML;
196
- }
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Abstract
22
+ *
23
+ * @method setBackgroundColor(string $value)
24
+ * @method setHAxis(array $value)
25
+ * @method setVAxis(array $value)
26
+ * @method setBar(array $value)
27
+ * @method setChartArea(array $value)
28
+ * @method setLegend(string $value)
29
+ * @method setHeight(int $value)
30
+ * @method setElementId(string $value)
31
+ */
32
  class Mzax_Emarketing_Block_Chart_Abstract extends Mage_Core_Block_Template
33
  {
34
+ /**
35
+ * @var string
36
+ */
37
  protected $_chartClass = '';
38
+
39
+ /**
40
+ * @var array
41
+ */
42
+ protected $_columns = array();
43
+
44
+ /**
45
+ * @var array
46
+ */
47
+ protected $_rows = array();
48
+
49
+ /**
50
+ * @var array
51
+ */
52
+ protected $_overlays = array();
53
+
54
+ /**
55
+ * @return void
56
+ */
57
  protected function _construct()
58
  {
59
  parent::_construct();
60
+
61
+ $this->setElementId('gchart_' . rand(0, 100000));
62
  }
63
+
64
+ /**
65
+ * Retrieve Google API chart class
66
+ *
67
+ * @return string
68
+ */
69
  public function getChartClass()
70
  {
71
  return "google.visualization.{$this->_chartClass}";
72
  }
73
+
74
+ /**
75
+ * @param string $name
76
+ * @param string $overlay
77
+ *
78
+ * @return $this
79
+ */
 
 
 
 
 
 
 
80
  public function addOverlay($name, $overlay)
81
  {
82
  $this->_overlays[$name] = $overlay;
83
+
84
  return $this;
85
  }
86
+
87
+ /**
88
+ * Add column
89
+ *
90
+ * @param string $label
91
+ * @param string $type
92
+ * @param array $p
93
+ *
94
+ * @return $this
95
+ */
96
+ public function addColumn($label, $type = 'number', $p = null)
97
+ {
98
+ $this->_columns[] = array($label, $type, $p);
99
+ return $this;
100
+ }
101
+
102
+ /**
103
+ * Clear all rows
104
+ *
105
+ * @return $this
106
+ */
107
  public function clearRows()
108
  {
109
  $this->_rows = array();
110
+
111
  return $this;
112
+ }
113
+
114
+ /**
115
+ * Add row
116
+ *
117
+ * @param array $row
118
+ * @param int $offset
119
+ *
120
+ * @return $this
121
+ */
122
+ public function addRow(array $row, $offset = null)
123
  {
124
+ if ($offset === null) {
125
  $this->_rows[] = $row;
126
+ } else {
 
127
  array_splice($this->_rows, $offset, 0, array($row));
128
+ }
129
+
130
+ return $this;
131
+ }
132
+
133
+ /**
134
+ * Retrieve options as json
135
+ *
136
+ * @return string
137
+ */
138
+ public function getOptionJs()
139
  {
140
  $ignore = array('type', 'module_name', 'auto_redraw');
141
  $options = array();
142
+ foreach ($this->_data as $key => $value) {
143
+ if (in_array($key, $ignore)) {
144
  continue;
145
  }
146
  $name = lcfirst($this->_camelize($key));
147
  $options[$name] = $value;
148
  }
149
+
150
+ return Zend_Json::encode($options);
151
+ }
152
+
153
+ /**
154
+ * Retrieve data json
155
+ *
156
+ * @return string
157
+ */
158
+ protected function _getDataJson()
159
+ {
160
+ $json = array();
161
+ foreach ($this->_rows as $row) {
162
+ $data = array();
163
+ foreach ($this->_columns as $i => $column) {
164
  list($label, $type, $p) = $column;
165
+ $value = $row[$i];
166
+ if ($value === null) {
167
+ $value = 'null';
168
+ } else {
169
+ switch ($type) {
170
+ case 'tooltip':
171
+ case 'string':
172
+ $value = "'".$this->jsQuoteEscape($value)."'";
 
173
  break;
174
+
175
  case 'date':
176
+ if ($value instanceof DateTime) {
177
  $value = "new Date({$value->format('Y, n-1, j')})";
178
+ }
179
+ break;
180
+
181
+ default:
182
+ $value = (float) $value;
183
+ break;
184
+ }
185
+ }
186
+ $data[] = $value;
187
+ }
188
+
189
+ $json[] = "[" . implode(', ', $data) . "]";
190
+ }
191
+ return "[" . implode(",\n", $json) . "]";
192
+ }
193
+
194
+ /**
195
+ * @param string $name
196
+ *
197
+ * @return string
198
+ */
199
+ protected function _getDataTableJs($name = 'data')
200
+ {
201
+ $html = "var {$name} = new google.visualization.DataTable();\n";
202
+
203
+ foreach ($this->_columns as $column) {
204
  list($label, $type, $p) = $column;
205
+
206
  $json = array('type' => $type, 'label' => $label);
207
+ if ($p) {
208
  $json['p'] = $p;
209
  }
210
  $json = Zend_Json::encode($json);
211
+
212
+ $html .= "{$name}.addColumn($json);\n";
213
+ }
214
+
215
+ $html .= "{$name}.addRows({$this->_getDataJson()});";
216
+
217
+ return $html;
218
+ }
219
+
220
+ /**
221
+ * Create chart html
222
+ *
223
+ * @return string
224
+ */
225
+ public function _toHtml()
226
  {
227
  $autoredraw = (int) $this->getDataSetDefault('auto_redraw', true);
228
+
229
  $overlayHtml = '';
230
+ foreach ($this->_overlays as $name => $overlay) {
231
+ if ($overlay instanceof Mage_Core_Block_Abstract) {
232
  $overlay = $overlay->toHtml();
233
  }
234
  $overlayHtml .= "<div class=\"overlay $name\">$overlay</div>";
235
  }
236
+
237
+
238
  return <<<HTML
239
+ <div id="{$this->getElementId()}-wrapper" class="chart-wrapper">
240
  <div id="{$this->getElementId()}"></div>
241
  {$overlayHtml}
242
+ </div>
243
+ <script type="text/javascript">
244
+ (function() {
245
+ {$this->_getDataTableJs('data')}
246
+ var chart = new {$this->getChartClass()}(document.getElementById('{$this->getElementId()}'));
247
  chart.draw(data, {$this->getOptionJs()});
248
+ if ($autoredraw) {
249
+ Event.observe(window, "resize", function() {
250
+ chart.draw(data, options);
251
  });
252
+ }
253
+ }());
254
+ </script>
255
+ HTML;
256
+ }
 
 
 
 
 
 
 
 
 
 
 
257
  }
app/code/community/Mzax/Emarketing/Block/Chart/Area.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Area extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
22
-
23
- protected $_chartClass = 'AreaChart';
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Area
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Area extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
+ protected $_chartClass = 'AreaChart';
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/Bar.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Bar extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
 
 
 
22
  protected $_chartClass = 'BarChart';
23
-
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Bar
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Bar extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_chartClass = 'BarChart';
 
 
 
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/Column.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Column extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
 
 
 
22
  protected $_chartClass = 'ColumnChart';
23
-
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Column
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Column extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_chartClass = 'ColumnChart';
 
 
 
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/Geo.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Geo extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
 
 
 
22
  protected $_chartClass = 'GeoChart';
23
-
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Geo
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Geo extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_chartClass = 'GeoChart';
 
 
 
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/Line.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Line extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
22
-
23
- protected $_chartClass = 'LineChart';
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Line
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Line extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
+ protected $_chartClass = 'LineChart';
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/Pie.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Pie extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
22
-
23
- protected $_chartClass = 'PieChart';
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Pie
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Pie extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
+ protected $_chartClass = 'PieChart';
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/Scatter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_Scatter extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
 
 
 
22
  protected $_chartClass = 'ScatterChart';
23
-
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Scatter
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Scatter extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_chartClass = 'ScatterChart';
 
 
 
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/SteppedArea.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,13 +16,14 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Block_Chart_SteppedArea extends Mzax_Emarketing_Block_Chart_Abstract
21
  {
 
 
 
22
  protected $_chartClass = 'SteppedAreaChart';
23
-
24
-
25
-
26
-
27
-
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_SteppedArea
22
+ */
23
  class Mzax_Emarketing_Block_Chart_SteppedArea extends Mzax_Emarketing_Block_Chart_Abstract
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_chartClass = 'SteppedAreaChart';
 
 
 
 
 
 
29
  }
app/code/community/Mzax/Emarketing/Block/Chart/Widget/Container.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,48 +17,51 @@
18
  */
19
 
20
 
 
21
 
 
 
 
22
  class Mzax_Emarketing_Block_Chart_Widget_Container extends Mage_Adminhtml_Block_Abstract
23
  {
24
-
25
  /**
26
- *
27
- * @var Mzax_Emarketing_Block_Chart_Abstract
28
  */
29
  protected $_chart;
30
-
31
-
32
  /**
33
- *
34
- * @param Mzax_Emarketing_Block_Chart_Abstract $chart
35
- * @return Mzax_Emarketing_Block_Chart_Widget_Container
 
 
36
  */
37
- public function setChart(Mzax_Emarketing_Block_Chart_Abstract $chart)
38
  {
39
  $this->_chart = $chart;
 
40
  return $this;
41
  }
42
-
43
-
44
  /**
45
- *
46
- * @return Mzax_Emarketing_Block_Chart_Abstract
 
47
  */
48
  public function getChart()
49
  {
50
  return $this->_chart;
51
  }
52
-
53
-
54
-
 
55
  protected function _toHtml()
56
  {
57
- if($this->_chart) {
58
  return $this->_chart->toHtml();
59
  }
 
60
  return '';
61
  }
62
-
63
-
64
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ use Mzax_Emarketing_Block_Chart_Abstract as Chart;
21
 
22
+ /**
23
+ * Class Mzax_Emarketing_Block_Chart_Widget_Container
24
+ */
25
  class Mzax_Emarketing_Block_Chart_Widget_Container extends Mage_Adminhtml_Block_Abstract
26
  {
 
27
  /**
28
+ * @var Chart
 
29
  */
30
  protected $_chart;
31
+
 
32
  /**
33
+ * Set chart
34
+ *
35
+ * @param Chart $chart
36
+ *
37
+ * @return $this
38
  */
39
+ public function setChart(Chart $chart)
40
  {
41
  $this->_chart = $chart;
42
+
43
  return $this;
44
  }
45
+
 
46
  /**
47
+ * Retrieve chart
48
+ *
49
+ * @return Chart
50
  */
51
  public function getChart()
52
  {
53
  return $this->_chart;
54
  }
55
+
56
+ /**
57
+ * @return string
58
+ */
59
  protected function _toHtml()
60
  {
61
+ if ($this->_chart) {
62
  return $this->_chart->toHtml();
63
  }
64
+
65
  return '';
66
  }
67
+ }
 
 
 
app/code/community/Mzax/Emarketing/Block/Chart/Widget/Geo.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,83 +17,82 @@
18
  */
19
 
20
 
21
-
 
 
22
  class Mzax_Emarketing_Block_Chart_Widget_Geo extends Mzax_Emarketing_Block_Chart_Widget_Tab
23
  {
24
-
25
-
26
-
27
-
28
-
29
  protected function _construct()
30
  {
31
  parent::_construct();
 
32
  $this->setTemplate('mzax/emarketing/widget/chart-geo.phtml');
33
  }
34
-
35
-
36
-
 
 
 
37
  public function getType()
38
  {
39
  return 'geo';
40
  }
41
-
42
-
43
-
44
-
45
  /**
46
- *
 
47
  * @return Mzax_Emarketing_Block_Chart_Abstract
48
  */
49
  public function getChart()
50
  {
51
- if(!$this->_chart) {
52
-
53
-
54
- $block = 'mzax_emarketing/chart_' . $this->getType();
55
-
56
- /* @var $chart Mzax_Emarketing_Block_Chart_Abstract */
57
- $chart = $this->_chart = $this->getLayout()->createBlock($block);
58
- $chart->setBackgroundColor('#f5f5f5');
59
- $chart->setHAxis(array(
60
- 'baselineColor' => 'white',
61
- 'gridlines' => array(
62
- 'color' => '#DDD'
63
- ),
64
- 'textPosition'=> 'in',
65
- 'textStyle' => array(
66
- 'fontSize' => 11,
67
- 'color' => '#333'
68
- )
69
- ));
70
- $chart->setVAxis(array(
71
- 'baselineColor' => 'white',
72
- 'gridlines' => array(
73
- 'color' => '#DDD'
74
- ),
75
- 'textPosition'=> 'in',
76
- 'textStyle' => array(
77
- 'fontSize' => 11,
78
- 'color' => '#333'
79
- )
80
- ));
81
- $chart->setBar(array(
82
- 'groupWidth' => '80%'
83
- ));
84
- $chart->setChartArea(array(
85
- 'top' => '5%',
86
- 'right' => '0',
87
- 'bottom' => '0',
88
- 'left' => '0',
89
- 'width' => '100%',
90
- 'height' => '100%'
91
- ));
92
- $chart->setLegend('none');
93
- $chart->setHeight(400);
94
-
95
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  return $this->_chart;
97
  }
98
-
99
-
100
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Chart_Widget_Geo
22
+ */
23
  class Mzax_Emarketing_Block_Chart_Widget_Geo extends Mzax_Emarketing_Block_Chart_Widget_Tab
24
  {
25
+ /**
26
+ * @return void
27
+ */
 
 
28
  protected function _construct()
29
  {
30
  parent::_construct();
31
+
32
  $this->setTemplate('mzax/emarketing/widget/chart-geo.phtml');
33
  }
34
+
35
+ /**
36
+ * Chart type
37
+ *
38
+ * @return string
39
+ */
40
  public function getType()
41
  {
42
  return 'geo';
43
  }
44
+
 
 
 
45
  /**
46
+ * Retrieve chart instance
47
+ *
48
  * @return Mzax_Emarketing_Block_Chart_Abstract
49
  */
50
  public function getChart()
51
  {
52
+ if ($this->_chart) {
53
+ return $this->_chart;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }
55
+
56
+ $block = 'mzax_emarketing/chart_' . $this->getType();
57
+
58
+ $this->_chart = $this->getLayout()->createBlock($block);
59
+ $this->_chart->setBackgroundColor('#f5f5f5');
60
+ $this->_chart->setHAxis(array(
61
+ 'baselineColor' => 'white',
62
+ 'gridlines' => array(
63
+ 'color' => '#DDD'
64
+ ),
65
+ 'textPosition'=> 'in',
66
+ 'textStyle' => array(
67
+ 'fontSize' => 11,
68
+ 'color' => '#333'
69
+ )
70
+ ));
71
+ $this->_chart->setVAxis(array(
72
+ 'baselineColor' => 'white',
73
+ 'gridlines' => array(
74
+ 'color' => '#DDD'
75
+ ),
76
+ 'textPosition'=> 'in',
77
+ 'textStyle' => array(
78
+ 'fontSize' => 11,
79
+ 'color' => '#333'
80
+ )
81
+ ));
82
+ $this->_chart->setBar(array(
83
+ 'groupWidth' => '80%'
84
+ ));
85
+ $this->_chart->setChartArea(array(
86
+ 'top' => '5%',
87
+ 'right' => '0',
88
+ 'bottom' => '0',
89
+ 'left' => '0',
90
+ 'width' => '100%',
91
+ 'height' => '100%'
92
+ ));
93
+ $this->_chart->setLegend('none');
94
+ $this->_chart->setHeight(400);
95
+
96
  return $this->_chart;
97
  }
98
+ }
 
 
app/code/community/Mzax/Emarketing/Block/Chart/Widget/Tab.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,92 +17,103 @@
18
  */
19
 
20
 
 
 
21
  /**
22
- *
23
- * @method Mzax_Emarketing_Model_Campaign getCampaign()
24
  *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Block_Chart_Widget_Tab extends Mage_Adminhtml_Block_Abstract
30
  {
31
-
 
32
  /**
33
- *
34
  * @var Mzax_Emarketing_Block_Chart_Abstract
35
  */
36
  protected $_chart;
37
-
38
-
39
  /**
40
- *
41
  * @var Mzax_Emarketing_Model_Report_Query
42
  */
43
  protected $_query;
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
  protected $_tabs = array();
52
-
53
-
 
 
54
  protected static $_uid = 1;
55
-
56
-
57
-
58
-
 
 
 
 
 
 
 
59
  public function getHtmlId()
60
  {
61
  $id = $this->getData('html_id');
62
- if(!$id) {
63
  $id = 'charttab_' . (self::$_uid++);
64
  $this->setData('html_id', $id);
65
  }
66
  return $id;
67
  }
68
-
69
-
70
-
71
-
72
  protected function _construct()
73
  {
74
  parent::_construct();
 
75
  $this->setTemplate('mzax/emarketing/widget/chart-tab.phtml');
 
 
76
  }
77
-
78
-
79
-
 
 
 
 
80
  public function addTab($id, $params)
81
  {
82
  $this->_tabs[$id] = $params;
83
  return $this;
84
  }
85
-
 
 
 
86
  public function getTabs()
87
  {
88
  return $this->_tabs;
89
  }
90
-
91
-
92
-
93
  /**
94
  * Retrieve query
95
- *
96
  * @return Mzax_Emarketing_Model_Report_Query
97
  */
98
  public function getQuery()
99
  {
100
  return $this->_query;
101
  }
102
-
103
-
104
  /**
105
  * Set query
106
- *
107
  * @param Mzax_Emarketing_Model_Report_Query $query
108
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
109
  */
@@ -112,28 +122,24 @@ class Mzax_Emarketing_Block_Chart_Widget_Tab extends Mage_Adminhtml_Block_Abstra
112
  $this->_query = $query;
113
  return $this;
114
  }
115
-
116
-
117
-
 
118
  public function getType()
119
  {
120
  return $this->getDataSetDefault('type', 'line');
121
  }
122
-
123
-
124
-
125
-
126
  /**
127
- *
128
  * @return Mzax_Emarketing_Block_Chart_Abstract
129
  */
130
  public function getChart()
131
  {
132
- if(!$this->_chart) {
133
-
134
-
135
  $block = 'mzax_emarketing/chart_' . $this->getType();
136
-
137
  /* @var $chart Mzax_Emarketing_Block_Chart_Abstract */
138
  $chart = $this->_chart = $this->getLayout()->createBlock($block);
139
  $chart->setBackgroundColor('#f5f5f5');
@@ -172,63 +178,58 @@ class Mzax_Emarketing_Block_Chart_Widget_Tab extends Mage_Adminhtml_Block_Abstra
172
  ));
173
  $chart->setLegend('none');
174
  $chart->setHeight(200);
175
-
176
  }
 
177
  return $this->_chart;
178
  }
179
-
180
-
181
-
182
-
183
-
184
-
185
 
186
  /**
187
- *
188
  * @return Mzax_Chart_Table
189
  */
190
  public function getTable()
191
  {
192
  return $this->getQuery()->getDataTable();
193
  }
194
-
195
-
196
-
197
-
198
  /**
199
  * Retrieve query params as JSON
200
- *
201
  * @return string
202
  */
203
  public function getQueryParams()
204
  {
205
  return Zend_Json::encode($this->getQuery()->getParams());
206
  }
207
-
208
-
209
-
 
210
  public function getQueryUrl()
211
  {
212
  $url = $this->getData('query_url');
213
- if(!$url) {
 
 
214
  $url = $this->getUrl('*/*/queryReport', array(
215
- '_current' => true,
216
- 'form_key' => Mage::getSingleton('core/session')->getFormKey()
217
  ));
218
  }
 
219
  return $url;
220
  }
221
-
222
-
223
-
224
-
225
-
226
-
227
  public function getTabMetric(array $tab)
228
  {
229
- if(isset($tab['metric'])) {
230
- if(is_array($tab['metric'])) {
231
- if(isset($tab['default'])) {
232
  return $tab['default'];
233
  }
234
  return reset(array_keys($tab['metric']));
@@ -237,35 +238,38 @@ class Mzax_Emarketing_Block_Chart_Widget_Tab extends Mage_Adminhtml_Block_Abstra
237
  }
238
  return '';
239
  }
240
-
241
-
 
 
 
 
242
  public function getTabLabel(array $tab)
243
  {
244
- if(isset($tab['label'])) {
245
  return $tab['label'];
246
  }
247
  return '';
248
  }
249
-
250
-
 
 
 
 
251
  public function getTabClass(array $tab)
252
  {
253
  $class = array();
254
- if(isset($tab['id'])) {
255
  $class[] = $tab['id'];
256
  }
257
- if(isset($tab['class'])) {
258
  $class[] = $tab['class'];
259
  }
260
- if(isset($tab['metric'])) {
261
  $class[] = is_string($tab['metric']) ? $tab['metric'] : 'dropdown';
262
  }
263
-
264
-
265
  return implode(' ', array_unique($class));
266
  }
267
-
268
-
269
-
270
-
271
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ use Mzax_Emarketing_Model_Campaign as Campaign;
21
+
22
  /**
23
+ * Class Mzax_Emarketing_Block_Chart_Widget_Tab
 
24
  *
25
+ * @method Campaign getCampaign()
26
+ * @method $this setType(string $value)
 
27
  */
28
  class Mzax_Emarketing_Block_Chart_Widget_Tab extends Mage_Adminhtml_Block_Abstract
29
  {
30
+
31
+
32
  /**
 
33
  * @var Mzax_Emarketing_Block_Chart_Abstract
34
  */
35
  protected $_chart;
36
+
 
37
  /**
 
38
  * @var Mzax_Emarketing_Model_Report_Query
39
  */
40
  protected $_query;
41
+
42
+ /**
43
+ * @var array
44
+ */
 
 
 
45
  protected $_tabs = array();
46
+
47
+ /**
48
+ * @var int
49
+ */
50
  protected static $_uid = 1;
51
+
52
+ /**
53
+ * Session Manager
54
+ *
55
+ * @var Mzax_Emarketing_Model_SessionManager
56
+ */
57
+ protected $_sessionManager;
58
+
59
+ /**
60
+ * @return mixed|string
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
+ * @return void
74
+ */
75
  protected function _construct()
76
  {
77
  parent::_construct();
78
+
79
  $this->setTemplate('mzax/emarketing/widget/chart-tab.phtml');
80
+
81
+ $this->_sessionManager = Mage::getSingleton('mzax_emarketing/sessionManager');
82
  }
83
+
84
+ /**
85
+ * @param $id
86
+ * @param $params
87
+ *
88
+ * @return $this
89
+ */
90
  public function addTab($id, $params)
91
  {
92
  $this->_tabs[$id] = $params;
93
  return $this;
94
  }
95
+
96
+ /**
97
+ * @return array
98
+ */
99
  public function getTabs()
100
  {
101
  return $this->_tabs;
102
  }
103
+
 
 
104
  /**
105
  * Retrieve query
106
+ *
107
  * @return Mzax_Emarketing_Model_Report_Query
108
  */
109
  public function getQuery()
110
  {
111
  return $this->_query;
112
  }
113
+
 
114
  /**
115
  * Set query
116
+ *
117
  * @param Mzax_Emarketing_Model_Report_Query $query
118
  * @return Mzax_Emarketing_Block_Chart_Widget_Tab
119
  */
122
  $this->_query = $query;
123
  return $this;
124
  }
125
+
126
+ /**
127
+ * @return string
128
+ */
129
  public function getType()
130
  {
131
  return $this->getDataSetDefault('type', 'line');
132
  }
133
+
 
 
 
134
  /**
135
+ *
136
  * @return Mzax_Emarketing_Block_Chart_Abstract
137
  */
138
  public function getChart()
139
  {
140
+ if (!$this->_chart) {
 
 
141
  $block = 'mzax_emarketing/chart_' . $this->getType();
142
+
143
  /* @var $chart Mzax_Emarketing_Block_Chart_Abstract */
144
  $chart = $this->_chart = $this->getLayout()->createBlock($block);
145
  $chart->setBackgroundColor('#f5f5f5');
178
  ));
179
  $chart->setLegend('none');
180
  $chart->setHeight(200);
 
181
  }
182
+
183
  return $this->_chart;
184
  }
 
 
 
 
 
 
185
 
186
  /**
187
+ *
188
  * @return Mzax_Chart_Table
189
  */
190
  public function getTable()
191
  {
192
  return $this->getQuery()->getDataTable();
193
  }
194
+
 
 
 
195
  /**
196
  * Retrieve query params as JSON
197
+ *
198
  * @return string
199
  */
200
  public function getQueryParams()
201
  {
202
  return Zend_Json::encode($this->getQuery()->getParams());
203
  }
204
+
205
+ /**
206
+ * @return string
207
+ */
208
  public function getQueryUrl()
209
  {
210
  $url = $this->getData('query_url');
211
+ if (!$url) {
212
+ $formKey = $this->_sessionManager->getCoreSession()->getFormKey();
213
+
214
  $url = $this->getUrl('*/*/queryReport', array(
215
+ '_current' => true,
216
+ 'form_key' => $formKey
217
  ));
218
  }
219
+
220
  return $url;
221
  }
222
+
223
+ /**
224
+ * @param array $tab
225
+ *
226
+ * @return string
227
+ */
228
  public function getTabMetric(array $tab)
229
  {
230
+ if (isset($tab['metric'])) {
231
+ if (is_array($tab['metric'])) {
232
+ if (isset($tab['default'])) {
233
  return $tab['default'];
234
  }
235
  return reset(array_keys($tab['metric']));
238
  }
239
  return '';
240
  }
241
+
242
+ /**
243
+ * @param array $tab
244
+ *
245
+ * @return string
246
+ */
247
  public function getTabLabel(array $tab)
248
  {
249
+ if (isset($tab['label'])) {
250
  return $tab['label'];
251
  }
252
  return '';
253
  }
254
+
255
+ /**
256
+ * @param array $tab
257
+ *
258
+ * @return string
259
+ */
260
  public function getTabClass(array $tab)
261
  {
262
  $class = array();
263
+ if (isset($tab['id'])) {
264
  $class[] = $tab['id'];
265
  }
266
+ if (isset($tab['class'])) {
267
  $class[] = $tab['class'];
268
  }
269
+ if (isset($tab['metric'])) {
270
  $class[] = is_string($tab['metric']) ? $tab['metric'] : 'dropdown';
271
  }
272
+
 
273
  return implode(' ', array_unique($class));
274
  }
275
+ }
 
 
 
 
app/code/community/Mzax/Emarketing/Block/Conditions.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,25 +18,27 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Block_Conditions implements Varien_Data_Form_Element_Renderer_Interface
30
  {
31
- public function render(Varien_Data_Form_Element_Abstract $element)
32
- {
33
- $goal = $element->getTracker()->getGoal();
34
-
35
- if($goal) {
36
- $html = '<div class="filters">';
37
- $html .= $goal->getFilter()->asHtml();
38
- $html .= '</div>';
39
- return $html;
40
- }
41
- return '';
42
- }
43
- }
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Conditions
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Conditions implements Varien_Data_Form_Element_Renderer_Interface
24
  {
25
+ /**
26
+ * @param Varien_Data_Form_Element_Abstract $element
27
+ *
28
+ * @return string
29
+ */
30
+ public function render(Varien_Data_Form_Element_Abstract $element)
31
+ {
32
+ /** @var Mzax_Emarketing_Model_Conversion_Goal_Abstract $goal */
33
+ $goal = $element->getTracker()->getGoal();
34
+
35
+ if ($goal) {
36
+ $html = '<div class="filters">';
37
+ $html .= $goal->getFilter()->asHtml();
38
+ $html .= '</div>';
39
+
40
+ return $html;
41
+ }
42
+ return '';
43
+ }
44
+ }
app/code/community/Mzax/Emarketing/Block/Editable.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,37 +18,42 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
  *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Block_Editable extends Mage_Core_Block_Abstract
30
  implements Varien_Data_Form_Element_Renderer_Interface
31
  {
 
 
 
 
 
 
 
32
  public function render(Varien_Data_Form_Element_Abstract $element)
33
  {
34
  $element->addClass('element-value-changer');
35
-
36
  $valueName = $element->getValueName();
37
- if ($valueName==='') {
38
  $valueName = '...';
39
  }
40
-
41
  $valueLabel = htmlspecialchars(Mage::helper('core/string')->truncate($valueName, 150, '...'));
42
-
43
- switch($this->getFormat())
44
- {
45
  case 'text':
46
  $html = $valueLabel;
47
  break;
48
-
49
  case 'html':
50
  $html = '<strong>' . $valueLabel . '</strong>' ;
51
  break;
52
-
 
53
  default:
54
  if ($element->getIsMeta()) {
55
  $html = '<input type="hidden" class="hidden" id="'.$element->getHtmlId().'" name="'.$element->getName().'" value="'.$element->getValue().'"/>';
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Editable
 
22
  *
23
+ * @method string|null getFormat()
24
+ * @method $this setFormat(string $value)
 
25
  */
26
  class Mzax_Emarketing_Block_Editable extends Mage_Core_Block_Abstract
27
  implements Varien_Data_Form_Element_Renderer_Interface
28
  {
29
+ /**
30
+ * Render form element
31
+ *
32
+ * @param Varien_Data_Form_Element_Abstract $element
33
+ *
34
+ * @return string
35
+ */
36
  public function render(Varien_Data_Form_Element_Abstract $element)
37
  {
38
  $element->addClass('element-value-changer');
39
+
40
  $valueName = $element->getValueName();
41
+ if ($valueName === '') {
42
  $valueName = '...';
43
  }
44
+
45
  $valueLabel = htmlspecialchars(Mage::helper('core/string')->truncate($valueName, 150, '...'));
46
+
47
+ switch ($this->getFormat()) {
 
48
  case 'text':
49
  $html = $valueLabel;
50
  break;
51
+
52
  case 'html':
53
  $html = '<strong>' . $valueLabel . '</strong>' ;
54
  break;
55
+
56
+ case 'form':
57
  default:
58
  if ($element->getIsMeta()) {
59
  $html = '<input type="hidden" class="hidden" id="'.$element->getHtmlId().'" name="'.$element->getName().'" value="'.$element->getValue().'"/>';
app/code/community/Mzax/Emarketing/Block/Filter/Object/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,83 +17,82 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
- *
25
- * @method Mzax_Emarketing_Model_Object_Collection getCollection()
26
- *
27
- * @author Jacob Siefer
28
- *
29
  */
30
  class Mzax_Emarketing_Block_Filter_Object_Grid extends Mage_Adminhtml_Block_Widget_Grid
31
  {
32
-
33
  /**
34
  * @var Mzax_Emarketing_Model_Object_Filter_Component
35
  */
36
  protected $_filter;
37
 
38
-
39
-
 
 
 
40
  public function __construct($attributes = array())
41
  {
42
- if(isset($attributes['filter'])) {
43
  $this->setFilter($attributes['filter']);
44
  unset($attributes['filter']);
45
- }
46
  parent::__construct($attributes);
47
  }
48
-
49
-
50
-
 
 
 
51
  protected function _prepareLayout()
52
  {
53
- $this->setChild('hide_button',
 
54
  $this->getLayout()->createBlock('adminhtml/widget_button')
55
- ->setData(array(
56
- 'label' => Mage::helper('adminhtml')->__('&times;'),
57
- 'class' => 'close-grid'
58
- ))
 
 
59
  );
60
  return parent::_prepareLayout();
61
  }
62
-
63
-
64
-
 
65
  public function getMainButtonsHtml()
66
  {
67
  $html = parent::getMainButtonsHtml();
68
  $html.= $this->getChildHtml('hide_button');
 
69
  return $html;
70
  }
71
-
72
-
73
-
74
-
75
  /**
76
- *
77
- *
78
  * @return Mzax_Emarketing_Model_Object_Filter_Component
79
  */
80
  public function getFilter()
81
  {
82
  return $this->_filter;
83
  }
84
-
85
-
86
  /**
87
- *
88
- * @param Mzax_Emarketing_Model_Object_Filter_Component $source
89
- * @return Mzax_Emarketing_Block_Filter_Object_Grid
90
  */
91
  public function setFilter(Mzax_Emarketing_Model_Object_Filter_Component $filter)
92
  {
93
  $this->_filter = $filter;
 
94
  return $this;
95
  }
96
-
97
-
98
 
99
  /**
100
  *
@@ -104,81 +102,82 @@ class Mzax_Emarketing_Block_Filter_Object_Grid extends Mage_Adminhtml_Block_Widg
104
  {
105
  return $this->getFilter()->getParentObject();
106
  }
107
-
108
-
109
  /**
110
- * (non-PHPdoc)
111
- * @see Mage_Adminhtml_Block_Widget_Grid::getCollection()
112
  * @return Mzax_Emarketing_Model_Object_Collection
113
  */
114
  public function getCollection()
115
  {
116
  return $this->getFilter()->getCollection();
117
  }
118
-
119
-
120
-
121
  /**
122
  * Allow provider and filters to alter the grid
123
- *
 
124
  */
125
  protected function _afterLoadCollection()
126
  {
127
- parent::_afterLoadCollection();
128
- $this->getFilter()->afterGridLoadCollection($this);
129
-
 
130
  return $this;
131
  }
132
-
133
-
134
-
135
-
136
-
137
  /**
138
  * Prepare grid columns
139
- *
140
  * This is done by the email provider. The grid
141
  * does not know what type of objects it is loading
142
- *
 
143
  */
144
  protected function _prepareColumns()
145
  {
146
  $object = $this->getObject();
147
-
148
  $this->setFilterVisibility(true);
149
  $this->setPagerVisibility(true);
150
-
151
  $this->addColumn('main_object_id', array(
152
  'header' => $this->__($object->getName() .' ID'),
153
  'index' => 'id',
154
  'is_system' => true,
155
- 'width' => '50px',
 
156
  'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
157
  'object' => $object,
158
  ));
159
-
160
  $this->setDefaultSort('main_object_id');
161
  $this->setDefaultDir('DESC');
162
-
163
  $this->getFilter()->prepareGridColumns($this);
164
- return parent::_prepareColumns();
 
 
165
  }
166
-
167
-
168
-
 
 
 
169
  public function getGridUrl()
170
  {
171
  return $this->getData('grid_url');
172
  }
173
-
174
-
175
-
 
 
 
 
 
176
  public function getRowUrl($row)
177
  {
178
  return null;
179
  }
180
-
181
-
182
-
183
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Filter_Object_Grid
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Filter_Object_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
 
25
  /**
26
  * @var Mzax_Emarketing_Model_Object_Filter_Component
27
  */
28
  protected $_filter;
29
 
30
+ /**
31
+ * Mzax_Emarketing_Block_Filter_Object_Grid constructor.
32
+ *
33
+ * @param array $attributes
34
+ */
35
  public function __construct($attributes = array())
36
  {
37
+ if (isset($attributes['filter'])) {
38
  $this->setFilter($attributes['filter']);
39
  unset($attributes['filter']);
40
+ }
41
  parent::__construct($attributes);
42
  }
43
+
44
+ /**
45
+ * Prepare Layout
46
+ *
47
+ * @return Mage_Core_Block_Abstract
48
+ */
49
  protected function _prepareLayout()
50
  {
51
+ $this->setChild(
52
+ 'hide_button',
53
  $this->getLayout()->createBlock('adminhtml/widget_button')
54
+ ->setData(
55
+ array(
56
+ 'label' => Mage::helper('adminhtml')->__('&times;'),
57
+ 'class' => 'close-grid'
58
+ )
59
+ )
60
  );
61
  return parent::_prepareLayout();
62
  }
63
+
64
+ /**
65
+ * @return string
66
+ */
67
  public function getMainButtonsHtml()
68
  {
69
  $html = parent::getMainButtonsHtml();
70
  $html.= $this->getChildHtml('hide_button');
71
+
72
  return $html;
73
  }
74
+
 
 
 
75
  /**
76
+ *
77
+ *
78
  * @return Mzax_Emarketing_Model_Object_Filter_Component
79
  */
80
  public function getFilter()
81
  {
82
  return $this->_filter;
83
  }
84
+
 
85
  /**
86
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $filter
87
+ *
88
+ * @return $this
89
  */
90
  public function setFilter(Mzax_Emarketing_Model_Object_Filter_Component $filter)
91
  {
92
  $this->_filter = $filter;
93
+
94
  return $this;
95
  }
 
 
96
 
97
  /**
98
  *
102
  {
103
  return $this->getFilter()->getParentObject();
104
  }
105
+
 
106
  /**
 
 
107
  * @return Mzax_Emarketing_Model_Object_Collection
108
  */
109
  public function getCollection()
110
  {
111
  return $this->getFilter()->getCollection();
112
  }
113
+
 
 
114
  /**
115
  * Allow provider and filters to alter the grid
116
+ *
117
+ * @deprecated
118
  */
119
  protected function _afterLoadCollection()
120
  {
121
+ parent::_afterLoadCollection();
122
+
123
+ $this->getFilter()->afterGridLoadCollection($this);
124
+
125
  return $this;
126
  }
127
+
 
 
 
 
128
  /**
129
  * Prepare grid columns
130
+ *
131
  * This is done by the email provider. The grid
132
  * does not know what type of objects it is loading
133
+ *
134
+ * @return $this
135
  */
136
  protected function _prepareColumns()
137
  {
138
  $object = $this->getObject();
139
+
140
  $this->setFilterVisibility(true);
141
  $this->setPagerVisibility(true);
142
+
143
  $this->addColumn('main_object_id', array(
144
  'header' => $this->__($object->getName() .' ID'),
145
  'index' => 'id',
146
  'is_system' => true,
147
+ 'filter' => false,
148
+ 'width' => '50px',
149
  'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
150
  'object' => $object,
151
  ));
152
+
153
  $this->setDefaultSort('main_object_id');
154
  $this->setDefaultDir('DESC');
155
+
156
  $this->getFilter()->prepareGridColumns($this);
157
+ parent::_prepareColumns();
158
+
159
+ return $this;
160
  }
161
+
162
+ /**
163
+ * Retrieve grid url
164
+ *
165
+ * @return string
166
+ */
167
  public function getGridUrl()
168
  {
169
  return $this->getData('grid_url');
170
  }
171
+
172
+ /**
173
+ * No row url used
174
+ *
175
+ * @param $row
176
+ *
177
+ * @return null
178
+ */
179
  public function getRowUrl($row)
180
  {
181
  return null;
182
  }
 
 
 
 
183
  }
app/code/community/Mzax/Emarketing/Block/Filter/Test/Recursive.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,86 +17,85 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Filter_Test_Recursive extends Mzax_Emarketing_Block_Filter_Test_Single
22
  {
23
-
24
-
25
  /**
26
- *
27
  * @var Mzax_Emarketing_Block_Filter_Test_Single
28
  */
29
  protected $_filterBlock;
30
-
31
-
32
-
 
33
  protected function _construct()
34
  {
35
  parent::_construct();
36
  $this->setTemplate('mzax/emarketing/filter/test/recursive.phtml');
37
  }
38
-
39
-
40
-
41
  /**
42
  * Retrieve filter
43
- *
44
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
45
  */
46
  public function getFilter()
47
  {
48
  return Mage::registry('current_filter');
49
  }
50
-
51
-
52
-
53
-
54
 
 
 
 
 
 
55
  protected function _beforeToHtml()
56
  {
57
  $time = microtime(true);
58
  $html = $this->_toHtmlRecursive($this->getFilter());
59
  $time = microtime(true) - $time;
60
-
61
  $this->setTime($time);
62
  $this->setFilterHtml($html);
63
  }
64
-
65
-
66
-
67
-
 
 
 
 
68
  protected function _toHtmlRecursive(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
69
  {
70
  $block = $this->getFilterBlock();
71
  $block->setFilter($filter);
72
-
73
- $subfilters = '';
74
  $filters = $filter->getFilters();
75
- if(count($filters)) {
76
- foreach($filters as $f) {
77
- $subfilters .= $this->_toHtmlRecursive($f);
78
  }
79
  }
80
- $block->setSubfilters($subfilters);
81
-
82
  return $block->toHtml();
83
  }
84
-
85
 
86
-
87
  /**
 
88
  *
89
  * @return Mzax_Emarketing_Block_Filter_Test_Single
90
  */
91
  public function getFilterBlock()
92
  {
 
93
  $block = $this->getLayout()->createBlock('mzax_emarketing/filter_test_single');
94
  $block->setTemplate('mzax/emarketing/filter/test/filter.phtml');
95
-
96
  return $block;
97
  }
98
-
99
-
100
-
101
-
102
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Filter_Test_Recursive
22
+ */
23
  class Mzax_Emarketing_Block_Filter_Test_Recursive extends Mzax_Emarketing_Block_Filter_Test_Single
24
  {
 
 
25
  /**
 
26
  * @var Mzax_Emarketing_Block_Filter_Test_Single
27
  */
28
  protected $_filterBlock;
29
+
30
+ /**
31
+ * @return void
32
+ */
33
  protected function _construct()
34
  {
35
  parent::_construct();
36
  $this->setTemplate('mzax/emarketing/filter/test/recursive.phtml');
37
  }
38
+
 
 
39
  /**
40
  * Retrieve filter
41
+ *
42
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
43
  */
44
  public function getFilter()
45
  {
46
  return Mage::registry('current_filter');
47
  }
 
 
 
 
48
 
49
+ /**
50
+ * Prepare html
51
+ *
52
+ * @return void
53
+ */
54
  protected function _beforeToHtml()
55
  {
56
  $time = microtime(true);
57
  $html = $this->_toHtmlRecursive($this->getFilter());
58
  $time = microtime(true) - $time;
59
+
60
  $this->setTime($time);
61
  $this->setFilterHtml($html);
62
  }
63
+
64
+ /**
65
+ * Recursively render filters
66
+ *
67
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
68
+ *
69
+ * @return string
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
+ * Retrieve filter block
90
  *
91
  * @return Mzax_Emarketing_Block_Filter_Test_Single
92
  */
93
  public function getFilterBlock()
94
  {
95
+ /** @var Mzax_Emarketing_Block_Filter_Test_Single $block */
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
  }
app/code/community/Mzax/Emarketing/Block/Filter/Test/Single.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,18 +19,19 @@
20
 
21
 
22
  /**
23
- *
24
- *
25
- *
26
  * @method Mzax_Emarketing_Model_Object_Filter_Abstract getFilter()
 
 
27
  * @method boolean getError()
28
  * @method string getSelect()
29
  * @method Mzax_Emarketing_Block_Filter_Object_Grid getGrid()
30
  * @method string getGridHtml()
31
  *
32
- * @author Jacob Siefer
33
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
- * @version 0.4.10
35
  */
36
  class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Template
37
  {
@@ -41,46 +41,46 @@ class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Temp
41
  parent::_construct();
42
  $this->setTemplate('mzax/emarketing/filter/test/single.phtml');
43
  }
44
-
45
-
46
  protected function _toHtml()
47
  {
48
  $filter = $this->getFilter();
49
- if(!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
50
  return 'NO FILTER :(';
51
  }
52
  return parent::_toHtml();
53
  }
54
-
55
-
56
  protected function _beforeToHtml()
57
  {
58
  $filter = $this->getFilter();
59
- if(!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
60
  return;
61
  }
62
-
63
  $error = false;
64
  $select = false;
65
  $grid = null;
66
-
67
  $time = microtime(true);
68
-
69
  try {
70
  $select = $filter->getSelect()->assembleAll();
71
  $grid = $this->getFilterGrid($filter);
72
  $total = $grid->getCollection()->getSize();
73
  $gridHtml = $grid->getHtml();
74
- if($this->isDebugMode()) {
75
  $queryTime = microtime(true);
76
  $filter->runFilterQuery();
77
  $this->setQueryTime(microtime(true) - $queryTime);
78
  }
79
  $this->setGridSelect($grid->getCollection()->getSelect());
80
  $this->setTotal($total);
81
-
82
- $result = $filter->checkIndexes(false);
83
- if(is_string($result)) {
84
  $this->setIndexCheckResult($result);
85
  }
86
  }
@@ -89,86 +89,86 @@ class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Temp
89
  $gridHtml.= "<pre>{$e->getTraceAsString()}</pre>";
90
  $error = true;
91
  }
92
-
93
  $time = microtime(true) - $time;
94
-
95
  $this->setError($error);
96
  $this->setGrid($grid);
97
  $this->setGridHtml($gridHtml);
98
  $this->setSelect($select);
99
  $this->setTime($time);
100
  }
101
-
102
-
103
-
104
-
105
-
106
-
107
  /**
108
  * Is debug mode?
109
- *
110
  * @return boolean
111
  */
112
  public function isDebugMode()
113
  {
114
- if(Mage::getIsDeveloperMode()) {
115
  return true;
116
  }
117
  return true;
118
  }
119
-
120
-
121
  public function getObjectName()
122
  {
123
  return $this->getFilter()->getParentObject()->getName();
124
  }
125
-
126
-
127
 
128
  public function getStatusMessage()
129
  {
130
  $name = $this->getObjectName();
131
  $total = $this->getTotal();
132
-
133
- if($this->getError()) {
134
  return $this->__("Error retrieving {$name}s");
135
  }
136
- if($total == 0) {
137
  return $this->__("No {$name}s found");
138
  }
139
-
140
  return $this->__("%s {$name}s found", $total);
141
  }
142
-
143
-
144
-
145
  public function getStatusIcon()
146
  {
147
  $total = $this->getTotal();
148
-
149
- if($this->getError()) {
150
  return $this->getSkinUrl('images/error_msg_icon.gif');
151
  }
152
- if($total == 0) {
153
  return $this->getSkinUrl('images/warning_msg_icon.gif');
154
  }
155
-
156
  return $this->getSkinUrl('images/success_msg_icon.gif');
157
  }
158
-
159
-
160
-
161
  public function getPreviewUrl()
162
  {
163
  return $this->getUrl('*/*/filterPreview', array('_current' => true, '_filter' => $this->getFilter()));
164
  }
165
-
166
-
167
-
168
-
169
  /**
170
- *
171
- *
172
  * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
173
  * @return Mzax_Emarketing_Block_Filter_Object_Grid
174
  */
@@ -183,12 +183,12 @@ class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Temp
183
  $grid->setDefaultLimit(5);
184
  $grid->setGridUrl($this->getUrl('*/*/filterGrid', array('_filter' => $filter, '_current' => true)));
185
  $grid->setUseAjax(true);
186
-
187
  return $grid;
188
  }
189
-
190
-
191
-
192
 
193
 
194
  /**
@@ -199,10 +199,10 @@ class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Temp
199
  {
200
  return $this->helper('mzax_emarketing/sqlFormatter');
201
  }
202
-
203
-
204
-
205
-
206
 
207
  /**
208
  * Generate url by route and parameters
@@ -213,14 +213,14 @@ class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Temp
213
  */
214
  public function getUrl($route = '', $params = array())
215
  {
216
- if(isset($params['_filter'])) {
217
  $params['filter_id'] = $params['_filter']->getId();
218
  unset($params['_filter']);
219
  }
220
  return parent::getUrl($route, $params);
221
  }
222
-
223
-
224
-
225
-
226
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
 
21
  /**
22
+ *
23
+ *
24
+ *
25
  * @method Mzax_Emarketing_Model_Object_Filter_Abstract getFilter()
26
+ * @method $this setFilter(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
27
+ *
28
  * @method boolean getError()
29
  * @method string getSelect()
30
  * @method Mzax_Emarketing_Block_Filter_Object_Grid getGrid()
31
  * @method string getGridHtml()
32
  *
33
+ * @method setSubfilters(string $filters)
34
+ *
 
35
  */
36
  class Mzax_Emarketing_Block_Filter_Test_Single extends Mage_Adminhtml_Block_Template
37
  {
41
  parent::_construct();
42
  $this->setTemplate('mzax/emarketing/filter/test/single.phtml');
43
  }
44
+
45
+
46
  protected function _toHtml()
47
  {
48
  $filter = $this->getFilter();
49
+ if (!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
50
  return 'NO FILTER :(';
51
  }
52
  return parent::_toHtml();
53
  }
54
+
55
+
56
  protected function _beforeToHtml()
57
  {
58
  $filter = $this->getFilter();
59
+ if (!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
60
  return;
61
  }
62
+
63
  $error = false;
64
  $select = false;
65
  $grid = null;
66
+
67
  $time = microtime(true);
68
+
69
  try {
70
  $select = $filter->getSelect()->assembleAll();
71
  $grid = $this->getFilterGrid($filter);
72
  $total = $grid->getCollection()->getSize();
73
  $gridHtml = $grid->getHtml();
74
+ if ($this->isDebugMode()) {
75
  $queryTime = microtime(true);
76
  $filter->runFilterQuery();
77
  $this->setQueryTime(microtime(true) - $queryTime);
78
  }
79
  $this->setGridSelect($grid->getCollection()->getSelect());
80
  $this->setTotal($total);
81
+
82
+ $result = $filter->checkIndexes(true);
83
+ if (is_string($result)) {
84
  $this->setIndexCheckResult($result);
85
  }
86
  }
89
  $gridHtml.= "<pre>{$e->getTraceAsString()}</pre>";
90
  $error = true;
91
  }
92
+
93
  $time = microtime(true) - $time;
94
+
95
  $this->setError($error);
96
  $this->setGrid($grid);
97
  $this->setGridHtml($gridHtml);
98
  $this->setSelect($select);
99
  $this->setTime($time);
100
  }
101
+
102
+
103
+
104
+
105
+
106
+
107
  /**
108
  * Is debug mode?
109
+ *
110
  * @return boolean
111
  */
112
  public function isDebugMode()
113
  {
114
+ if (Mage::getIsDeveloperMode()) {
115
  return true;
116
  }
117
  return true;
118
  }
119
+
120
+
121
  public function getObjectName()
122
  {
123
  return $this->getFilter()->getParentObject()->getName();
124
  }
125
+
126
+
127
 
128
  public function getStatusMessage()
129
  {
130
  $name = $this->getObjectName();
131
  $total = $this->getTotal();
132
+
133
+ if ($this->getError()) {
134
  return $this->__("Error retrieving {$name}s");
135
  }
136
+ if ($total == 0) {
137
  return $this->__("No {$name}s found");
138
  }
139
+
140
  return $this->__("%s {$name}s found", $total);
141
  }
142
+
143
+
144
+
145
  public function getStatusIcon()
146
  {
147
  $total = $this->getTotal();
148
+
149
+ if ($this->getError()) {
150
  return $this->getSkinUrl('images/error_msg_icon.gif');
151
  }
152
+ if ($total == 0) {
153
  return $this->getSkinUrl('images/warning_msg_icon.gif');
154
  }
155
+
156
  return $this->getSkinUrl('images/success_msg_icon.gif');
157
  }
158
+
159
+
160
+
161
  public function getPreviewUrl()
162
  {
163
  return $this->getUrl('*/*/filterPreview', array('_current' => true, '_filter' => $this->getFilter()));
164
  }
165
+
166
+
167
+
168
+
169
  /**
170
+ *
171
+ *
172
  * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
173
  * @return Mzax_Emarketing_Block_Filter_Object_Grid
174
  */
183
  $grid->setDefaultLimit(5);
184
  $grid->setGridUrl($this->getUrl('*/*/filterGrid', array('_filter' => $filter, '_current' => true)));
185
  $grid->setUseAjax(true);
186
+
187
  return $grid;
188
  }
189
+
190
+
191
+
192
 
193
 
194
  /**
199
  {
200
  return $this->helper('mzax_emarketing/sqlFormatter');
201
  }
202
+
203
+
204
+
205
+
206
 
207
  /**
208
  * Generate url by route and parameters
213
  */
214
  public function getUrl($route = '', $params = array())
215
  {
216
+ if (isset($params['_filter'])) {
217
  $params['filter_id'] = $params['_filter']->getId();
218
  unset($params['_filter']);
219
  }
220
  return parent::getUrl($route, $params);
221
  }
222
+
223
+
224
+
225
+
226
  }
app/code/community/Mzax/Emarketing/Block/Filters.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,27 +17,28 @@
18
  */
19
 
20
 
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.4.10
29
  */
30
  class Mzax_Emarketing_Block_Filters implements Varien_Data_Form_Element_Renderer_Interface
31
  {
32
- public function render(Varien_Data_Form_Element_Abstract $element)
33
- {
34
- $provider = $element->getCampaign()->getRecipientProvider();
35
-
36
- if($provider) {
37
- $html = '<div class="filters">';
38
- $html .= $provider->getFilter()->asHtml();
39
- $html .= '</div>';
40
- return $html;
41
- }
42
- return '';
43
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Filters
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Filters implements Varien_Data_Form_Element_Renderer_Interface
24
  {
25
+ /**
26
+ * @param Varien_Data_Form_Element_Abstract $element
27
+ *
28
+ * @return string
29
+ */
30
+ public function render(Varien_Data_Form_Element_Abstract $element)
31
+ {
32
+ /** @var Mzax_Emarketing_Model_Recipient_Provider_Abstract $provider */
33
+ $provider = $element->getCampaign()->getRecipientProvider();
34
+
35
+ if ($provider) {
36
+ $html = '<div class="filters">';
37
+ $html .= $provider->getFilter()->asHtml();
38
+ $html .= '</div>';
39
+
40
+ return $html;
41
+ }
42
+ return '';
43
+ }
44
+ }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Action.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,52 +18,43 @@
19
 
20
 
21
  /**
22
- * Action render that allows option groups
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
30
  {
31
-
32
  /**
33
  * Renders column
34
  *
35
  * @param Varien_Object $row
 
36
  * @return string
37
  */
38
  public function render(Varien_Object $row)
39
  {
40
  $actions = $this->getColumn()->getActions();
41
- if ( empty($actions) || !is_array($actions) ) {
42
  return '&nbsp;';
43
  }
44
-
45
  $out = '<select class="action-select" onchange="varienGridAction.execute(this);">'
46
  . '<option value=""></option>';
47
-
48
- foreach ($actions as $action){
49
- if ( !is_array($action) ) {
50
  continue;
51
  }
52
- if(isset($action['actions']) && is_array($action['actions'])) {
53
  $out .='<optgroup label="' . $action['caption'] . '">';
54
- foreach($action['actions'] as $subaction) {
55
  $out .= $this->_toOptionHtml($subaction, $row);
56
  }
57
  $out .='</optgroup>';
58
- }
59
- else if ( is_array($action) ) {
60
  $out .= $this->_toOptionHtml($action, $row);
61
  }
62
  }
63
  $out .= '</select>';
 
64
  return $out;
65
  }
66
-
67
-
68
-
69
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Grid_Column_Renderer_Action
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
24
  {
 
25
  /**
26
  * Renders column
27
  *
28
  * @param Varien_Object $row
29
+ *
30
  * @return string
31
  */
32
  public function render(Varien_Object $row)
33
  {
34
  $actions = $this->getColumn()->getActions();
35
+ if (empty($actions) || !is_array($actions)) {
36
  return '&nbsp;';
37
  }
38
+
39
  $out = '<select class="action-select" onchange="varienGridAction.execute(this);">'
40
  . '<option value=""></option>';
41
+
42
+ foreach ($actions as $action) {
43
+ if (!is_array($action)) {
44
  continue;
45
  }
46
+ if (isset($action['actions']) && is_array($action['actions'])) {
47
  $out .='<optgroup label="' . $action['caption'] . '">';
48
+ foreach ($action['actions'] as $subaction) {
49
  $out .= $this->_toOptionHtml($subaction, $row);
50
  }
51
  $out .='</optgroup>';
52
+ } elseif (is_array($action)) {
 
53
  $out .= $this->_toOptionHtml($action, $row);
54
  }
55
  }
56
  $out .= '</select>';
57
+
58
  return $out;
59
  }
 
 
 
 
60
  }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Campaign.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,17 +18,11 @@
19
 
20
 
21
  /**
22
- * Renderer for campaigns
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Campaign
29
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Options
30
  {
31
-
32
-
33
  /**
34
  * Render a grid cell as options
35
  *
@@ -39,16 +32,13 @@ class Mzax_Emarketing_Block_Grid_Column_Renderer_Campaign
39
  public function render(Varien_Object $row)
40
  {
41
  $html = parent::render($row);
42
-
43
  $id = $row->getCampaignId();
44
- if($id) {
45
  $url = $this->getUrl('*/campaign/edit', array('id' => $id));
46
  return sprintf('<a href="%s">%s</a>', $url, $html);
47
  }
 
48
  return $html;
49
  }
50
-
51
-
52
-
53
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Grid_Column_Renderer_Campaign
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Campaign
24
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Options
25
  {
 
 
26
  /**
27
  * Render a grid cell as options
28
  *
32
  public function render(Varien_Object $row)
33
  {
34
  $html = parent::render($row);
35
+
36
  $id = $row->getCampaignId();
37
+ if ($id) {
38
  $url = $this->getUrl('*/campaign/edit', array('id' => $id));
39
  return sprintf('<a href="%s">%s</a>', $url, $html);
40
  }
41
+
42
  return $html;
43
  }
 
 
 
 
44
  }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Recipient.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,41 +17,33 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- * Recipient renderer
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.4.10
29
  */
30
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Recipient
31
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
32
  {
33
-
34
-
35
  /**
36
  * Renders grid column
37
  *
38
  * @param Varien_Object $row
39
- * @return mixed
 
40
  */
41
  public function _getValue(Varien_Object $row)
42
  {
43
  $value = parent::_getValue($row);
44
  $recipient = $row->getRecipient();
45
-
46
- if($recipient instanceof Mzax_Emarketing_Model_Recipient)
47
- {
48
  $campaign = $recipient->getCampaign();
49
  $subject = $campaign->getRecipientProvider()->getSubject();
50
-
51
- if($subject) {
52
  $url = $subject->getAdminUrl($recipient->getObjectId());
53
  return sprintf('<a href="%s">%s</a>', $url, $value);
54
  }
55
-
56
  }
57
  return $value;
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Grid_Column_Renderer_Recipient
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Recipient
24
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
  {
 
 
26
  /**
27
  * Renders grid column
28
  *
29
  * @param Varien_Object $row
30
+ *
31
+ * @return string
32
  */
33
  public function _getValue(Varien_Object $row)
34
  {
35
  $value = parent::_getValue($row);
36
  $recipient = $row->getRecipient();
37
+
38
+ if ($recipient instanceof Mzax_Emarketing_Model_Recipient) {
 
39
  $campaign = $recipient->getCampaign();
40
  $subject = $campaign->getRecipientProvider()->getSubject();
41
+
42
+ if ($subject) {
43
  $url = $subject->getAdminUrl($recipient->getObjectId());
44
  return sprintf('<a href="%s">%s</a>', $url, $value);
45
  }
46
+
47
  }
48
  return $value;
49
  }
app/code/community/Mzax/Emarketing/Block/Grid/Column/Renderer/Size.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,54 +17,46 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- * Size renderer
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.4.10
29
  */
30
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Size
31
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
32
  {
33
-
34
-
35
  /**
36
  * Renders grid column
37
  *
38
  * @param Varien_Object $row
39
- * @return mixed
 
40
  */
41
  public function render(Varien_Object $row)
42
  {
43
  $bytes = (int) $this::_getValue($row);
44
-
45
  $html = $this->formatSize($bytes);
46
-
47
  $html = "<div style=\"text-align:right;\">$html</div>";
48
-
49
  return $html;
50
-
51
-
52
  }
53
-
54
-
55
-
 
 
 
 
 
56
  public function formatSize($bytes)
57
- {
58
- if($bytes > 0) {
59
  $unit = intval(log($bytes, 1024));
60
  $units = array('B', 'KB', 'MB', 'GB');
61
- if (array_key_exists($unit, $units)) {
62
  return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]);
63
  }
64
  }
 
65
  return '';
66
-
67
-
68
  }
69
-
70
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Grid_Column_Renderer_Size
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Grid_Column_Renderer_Size
24
  extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
  {
 
 
26
  /**
27
  * Renders grid column
28
  *
29
  * @param Varien_Object $row
30
+ *
31
+ * @return string
32
  */
33
  public function render(Varien_Object $row)
34
  {
35
  $bytes = (int) $this::_getValue($row);
36
+
37
  $html = $this->formatSize($bytes);
 
38
  $html = "<div style=\"text-align:right;\">$html</div>";
39
+
40
  return $html;
 
 
41
  }
42
+
43
+ /**
44
+ * Format bytes
45
+ *
46
+ * @param int $bytes
47
+ *
48
+ * @return string
49
+ */
50
  public function formatSize($bytes)
51
+ {
52
+ if ($bytes > 0) {
53
  $unit = intval(log($bytes, 1024));
54
  $units = array('B', 'KB', 'MB', 'GB');
55
+ if (array_key_exists($unit, $units)) {
56
  return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]);
57
  }
58
  }
59
+
60
  return '';
 
 
61
  }
 
 
62
  }
app/code/community/Mzax/Emarketing/Block/Inbox/Email.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,12 +17,18 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Inbox_Email extends Mage_Adminhtml_Block_Widget_Form_Container
22
  {
 
 
 
23
  public function __construct()
24
  {
25
  $this->_objectId = 'id';
26
-
27
  $this->_blockGroup = 'mzax_emarketing';
28
  $this->_controller = 'inbox';
29
  $this->_mode = 'email';
@@ -34,48 +39,56 @@ class Mzax_Emarketing_Block_Inbox_Email extends Mage_Adminhtml_Block_Widget_Form
34
  $this->_updateButton('delete', 'label', $this->__('Delete'));
35
 
36
  }
37
-
38
-
 
 
39
  public function getHeaderText()
40
  {
41
  $message = Mage::registry('current_email');
42
  if ($message->getId()) {
43
- return $this->htmlEscape($message->getSubject());
44
- }
45
- else {
46
  return $this->__('New Email');
47
  }
48
  }
49
 
50
-
51
-
 
52
  public function getValidationUrl()
53
  {
54
  return $this->getUrl('*/*/validate', array('_current'=>true));
55
  }
56
-
57
-
58
-
 
 
 
59
  protected function _prepareLayout()
60
  {
61
- // return false;
62
- $this->_addButton('save_and_continue', array(
63
  'label' => $this->__('Save And Continue Edit'),
64
  'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
65
  'class' => 'save'
66
  ), 10);
67
-
68
-
69
- $this->_addButton('parse', array(
70
- 'label' => $this->__('Parse'),
71
- 'onclick' => "setLocation('{$this->getUrl('*/*/parse', array('_current' => true))}')"
72
- ), 10);
73
-
74
 
75
- return parent::_prepareLayout();
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
-
78
-
79
  /**
80
  * Get form action URL
81
  *
@@ -88,13 +101,18 @@ class Mzax_Emarketing_Block_Inbox_Email extends Mage_Adminhtml_Block_Widget_Form
88
  }
89
  return $this->getUrl('*/*/save');
90
  }
91
-
92
-
 
 
93
  protected function _getSaveAndContinueUrl()
94
  {
95
- return $this->getUrl('*/*/save', array(
96
- '_current' => true,
97
- 'back' => 'edit'
98
- ));
 
 
 
99
  }
100
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Inbox_Email
22
+ */
23
  class Mzax_Emarketing_Block_Inbox_Email extends Mage_Adminhtml_Block_Widget_Form_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Inbox_Email constructor.
27
+ */
28
  public function __construct()
29
  {
30
  $this->_objectId = 'id';
31
+
32
  $this->_blockGroup = 'mzax_emarketing';
33
  $this->_controller = 'inbox';
34
  $this->_mode = 'email';
39
  $this->_updateButton('delete', 'label', $this->__('Delete'));
40
 
41
  }
42
+
43
+ /**
44
+ * @return string
45
+ */
46
  public function getHeaderText()
47
  {
48
  $message = Mage::registry('current_email');
49
  if ($message->getId()) {
50
+ return $this->escapeHtml($message->getSubject());
51
+ } else {
 
52
  return $this->__('New Email');
53
  }
54
  }
55
 
56
+ /**
57
+ * @return string
58
+ */
59
  public function getValidationUrl()
60
  {
61
  return $this->getUrl('*/*/validate', array('_current'=>true));
62
  }
63
+
64
+ /**
65
+ * Prepare layout
66
+ *
67
+ * @return $this
68
+ */
69
  protected function _prepareLayout()
70
  {
71
+ $this->_addButton('save_and_continue', array(
 
72
  'label' => $this->__('Save And Continue Edit'),
73
  'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
74
  'class' => 'save'
75
  ), 10);
 
 
 
 
 
 
 
76
 
77
+
78
+ $this->_addButton(
79
+ 'parse',
80
+ array(
81
+ 'label' => $this->__('Parse'),
82
+ 'onclick' => "setLocation('{$this->getUrl('*/*/parse', array('_current' => true))}')"
83
+ ),
84
+ 10
85
+ );
86
+
87
+ parent::_prepareLayout();
88
+
89
+ return $this;
90
  }
91
+
 
92
  /**
93
  * Get form action URL
94
  *
101
  }
102
  return $this->getUrl('*/*/save');
103
  }
104
+
105
+ /**
106
+ * @return string
107
+ */
108
  protected function _getSaveAndContinueUrl()
109
  {
110
+ return $this->getUrl(
111
+ '*/*/save',
112
+ array(
113
+ '_current' => true,
114
+ 'back' => 'edit'
115
+ )
116
+ );
117
  }
118
  }
app/code/community/Mzax/Emarketing/Block/Inbox/Email/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,37 +18,31 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget_Form
30
  {
31
-
 
 
32
  protected function _prepareForm()
33
  {
34
  $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
35
  $form->setHtmlIdPrefix("email");
36
  $form->setFieldNameSuffix("email");
37
-
38
-
39
  /* @var $email Mzax_Emarketing_Model_Inbox_Email */
40
  $email = Mage::registry('current_email');
41
-
42
-
43
-
44
  // Setting custom renderer for content field to remove label column
45
  $rendererWide = $this->getLayout()
46
  ->createBlock('adminhtml/widget_form_renderer_fieldset_element')
47
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
48
-
49
  $aceType = Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_ace');
50
-
51
-
52
- if($email->getId()) {
53
  $form->addField('message_id', 'hidden', array(
54
  'name' => 'message_id',
55
  'value' => $email->getId()
@@ -60,10 +53,8 @@ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget
60
  'legend' => $this->__('Bounce Message'),
61
  'class' => 'fieldset-wide',
62
  ))->addType('ace', $aceType);
63
-
64
-
65
-
66
-
67
  $fieldset->addField('type', 'select', array(
68
  'name' => 'type',
69
  'required' => true,
@@ -77,8 +68,7 @@ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget
77
  ),
78
  'note' => "Email Bounce Type",
79
  ));
80
-
81
-
82
  $fieldset->addField('email', 'text', array(
83
  'name' => 'email',
84
  'label' => $this->__('Email (From)'),
@@ -86,31 +76,30 @@ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget
86
  'note' => $this->__('The recipient we detected after parsing, may not be correct'),
87
  'readonly' => true
88
  ));
89
-
90
-
91
  $fieldset->addField('subject', 'text', array(
92
  'name' => 'subject',
93
  'label' => $this->__('Email Subject'),
94
  'title' => $this->__('Email Subject'),
95
  'readonly' => true
96
  ));
97
-
98
-
99
- if($campaign = $email->getCampaign()) {
100
-
101
  $fieldset->addField('campaign_name', 'link', array(
102
  'label' => $this->__('Campagin'),
103
  'value' => $campaign->getName(),
104
  'href' => $this->getUrl('*/emarketing_campaign/edit', array('id' => $campaign->getId()))
105
  ));
106
-
107
  }
108
-
109
- if($recipient = $email->getRecipient()) {
110
- if($campaign) {
111
  $href = $campaign->getRecipientProvider()->getObject()->getAdminUrl($recipient->getId());
112
  $recipient->prepare();
113
-
114
  $fieldset->addField('recipient_email', 'link', array(
115
  'label' => $this->__('Recipient'),
116
  'value' => sprintf('%s <%s>', $recipient->getName(), $recipient->getEmail()),
@@ -118,8 +107,7 @@ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget
118
  ));
119
  }
120
  }
121
-
122
-
123
  $editor = $fieldset->addField('message', 'ace', array(
124
  'name' => 'message',
125
  'label' => $this->__('Message'),
@@ -129,17 +117,13 @@ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget
129
  'readonly' => true,
130
  'autosize' => true
131
  ));
132
-
133
-
134
-
135
-
136
-
137
-
138
  $fieldset = $form->addFieldset('headers_fieldset', array(
139
  'legend' => $this->__('Email Headers'),
140
  'class' => 'fieldset-wide',
141
  ))->addType('ace', $aceType);
142
-
143
  $editor = $fieldset->addField('headers', 'ace', array(
144
  'name' => 'headers',
145
  'label' => $this->__('Headers'),
@@ -152,14 +136,14 @@ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget
152
  'readonly' => true,
153
  'autosize' => true
154
  ))->setRenderer($rendererWide);
155
-
156
-
157
-
158
  $fieldset = $form->addFieldset('content_fieldset', array(
159
  'legend' => $this->__('Email Content'),
160
  'class' => 'fieldset-wide',
161
  ))->addType('ace', $aceType);
162
-
163
  $editor = $fieldset->addField('content', 'ace', array(
164
  'name' => 'content',
165
  'label' => $this->__('Content'),
@@ -172,13 +156,11 @@ class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget
172
  'readonly' => true,
173
  'value' => $email->getContent()
174
  ))->setRenderer($rendererWide);
175
-
176
-
177
-
178
-
179
  $form->addValues($email->getData());
180
  $this->setForm($form);
181
  $form->setUseContainer(true);
 
182
  return parent::_prepareForm();
183
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Inbox_Email_Form
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Inbox_Email_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
28
  protected function _prepareForm()
29
  {
30
  $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
31
  $form->setHtmlIdPrefix("email");
32
  $form->setFieldNameSuffix("email");
33
+
 
34
  /* @var $email Mzax_Emarketing_Model_Inbox_Email */
35
  $email = Mage::registry('current_email');
36
+
 
 
37
  // Setting custom renderer for content field to remove label column
38
  $rendererWide = $this->getLayout()
39
  ->createBlock('adminhtml/widget_form_renderer_fieldset_element')
40
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
41
+
42
  $aceType = Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_ace');
43
+
44
+
45
+ if ($email->getId()) {
46
  $form->addField('message_id', 'hidden', array(
47
  'name' => 'message_id',
48
  'value' => $email->getId()
53
  'legend' => $this->__('Bounce Message'),
54
  'class' => 'fieldset-wide',
55
  ))->addType('ace', $aceType);
56
+
57
+
 
 
58
  $fieldset->addField('type', 'select', array(
59
  'name' => 'type',
60
  'required' => true,
68
  ),
69
  'note' => "Email Bounce Type",
70
  ));
71
+
 
72
  $fieldset->addField('email', 'text', array(
73
  'name' => 'email',
74
  'label' => $this->__('Email (From)'),
76
  'note' => $this->__('The recipient we detected after parsing, may not be correct'),
77
  'readonly' => true
78
  ));
79
+
80
+
81
  $fieldset->addField('subject', 'text', array(
82
  'name' => 'subject',
83
  'label' => $this->__('Email Subject'),
84
  'title' => $this->__('Email Subject'),
85
  'readonly' => true
86
  ));
87
+
88
+
89
+ if ($campaign = $email->getCampaign()) {
 
90
  $fieldset->addField('campaign_name', 'link', array(
91
  'label' => $this->__('Campagin'),
92
  'value' => $campaign->getName(),
93
  'href' => $this->getUrl('*/emarketing_campaign/edit', array('id' => $campaign->getId()))
94
  ));
95
+
96
  }
97
+
98
+ if ($recipient = $email->getRecipient()) {
99
+ if ($campaign) {
100
  $href = $campaign->getRecipientProvider()->getObject()->getAdminUrl($recipient->getId());
101
  $recipient->prepare();
102
+
103
  $fieldset->addField('recipient_email', 'link', array(
104
  'label' => $this->__('Recipient'),
105
  'value' => sprintf('%s <%s>', $recipient->getName(), $recipient->getEmail()),
107
  ));
108
  }
109
  }
110
+
 
111
  $editor = $fieldset->addField('message', 'ace', array(
112
  'name' => 'message',
113
  'label' => $this->__('Message'),
117
  'readonly' => true,
118
  'autosize' => true
119
  ));
120
+
121
+
 
 
 
 
122
  $fieldset = $form->addFieldset('headers_fieldset', array(
123
  'legend' => $this->__('Email Headers'),
124
  'class' => 'fieldset-wide',
125
  ))->addType('ace', $aceType);
126
+
127
  $editor = $fieldset->addField('headers', 'ace', array(
128
  'name' => 'headers',
129
  'label' => $this->__('Headers'),
136
  'readonly' => true,
137
  'autosize' => true
138
  ))->setRenderer($rendererWide);
139
+
140
+
141
+
142
  $fieldset = $form->addFieldset('content_fieldset', array(
143
  'legend' => $this->__('Email Content'),
144
  'class' => 'fieldset-wide',
145
  ))->addType('ace', $aceType);
146
+
147
  $editor = $fieldset->addField('content', 'ace', array(
148
  'name' => 'content',
149
  'label' => $this->__('Content'),
156
  'readonly' => true,
157
  'value' => $email->getContent()
158
  ))->setRenderer($rendererWide);
159
+
 
 
 
160
  $form->addValues($email->getData());
161
  $this->setForm($form);
162
  $form->setUseContainer(true);
163
+
164
  return parent::_prepareForm();
165
  }
166
  }
app/code/community/Mzax/Emarketing/Block/Inbox/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,34 +17,50 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
  parent::__construct();
 
27
  $this->setId('inbox_grid');
28
  $this->setUseAjax(true);
29
  $this->setSaveParametersInSession(true);
30
  $this->setDefaultSort('created_at');
31
  $this->setDefaultDir('desc');
32
  }
33
-
34
-
 
 
35
  public function getCollection()
36
  {
37
- if(!$this->_collection) {
38
  /* Mzax_Emarketing_Model_Resource_Inbox_Email_Collection */
39
  $this->_collection = Mage::getResourceModel('mzax_emarketing/inbox_email_collection');
40
  $this->_collection->assignRecipients();
41
  $this->_collection->assignCampaigns();
42
  }
 
43
  return $this->_collection;
44
  }
45
-
46
-
 
 
 
 
47
  protected function _prepareColumns()
48
  {
 
 
 
49
  $this->addColumn('created_at', array(
50
  'header' => $this->__('Created At'),
51
  'index' => 'created_at',
@@ -53,13 +68,13 @@ class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
53
  'width' => 150,
54
  'type' =>'datetime'
55
  ));
56
-
57
  $this->addColumn('recipient', array(
58
  'header' => $this->__('Recipient'),
59
  'index' => 'email',
60
  'frame_callback' => array($this, 'addCampaignLink'),
61
  ));
62
-
63
  $this->addColumn('subject', array(
64
  'header' => $this->__('Subject'),
65
  'index' => 'subject',
@@ -85,11 +100,7 @@ class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
85
  ),
86
  'width' => '100px',
87
  ));
88
-
89
-
90
- /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
91
- $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
92
-
93
  $this->addColumn('campaign', array(
94
  'header' => $this->__('Campaign'),
95
  'index' => 'campaign_id',
@@ -99,7 +110,6 @@ class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
99
  'width' => '100px',
100
  ));
101
 
102
-
103
  if (!Mage::app()->isSingleStoreMode()) {
104
  $this->addColumn('store_id', array(
105
  'header' => $this->__('Store'),
@@ -109,7 +119,7 @@ class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
109
  'display_deleted' => true,
110
  ));
111
  }
112
-
113
  $this->addColumn('status_code', array(
114
  'header' => $this->__('Status'),
115
  'index' =>'status_code'
@@ -122,43 +132,40 @@ class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
122
  'renderer' => 'mzax_emarketing/grid_column_renderer_size',
123
  'width' => '50px',
124
  ));
125
-
126
- return parent::_prepareColumns();
 
 
127
  }
128
 
129
-
130
-
131
-
132
  /**
133
  * Frame Callback
134
- *
135
  * Add link to admin for subject if available
136
- *
137
- *
138
  * @param string $value
139
- * @param Varien_Object $row
140
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
141
  * @param boolean $export
 
142
  * @return string
143
  */
144
  public function addSubjectLink($value, $row, $column, $export)
145
  {
146
  $recipient = $row->getRecipient();
147
-
148
- if($recipient instanceof Mzax_Emarketing_Model_Recipient && !$export)
149
- {
150
  $campaign = $recipient->getCampaign();
151
- $subject = $campaign->getRecipientProvider()->getSubject();
152
-
153
- if($subject) {
154
  $url = $subject->getAdminUrl($recipient->getObjectId());
155
  return sprintf('<a href="%s">%s</a>', $url, $value);
156
  }
157
-
158
  }
 
 
159
  }
160
-
161
-
162
 
163
  /**
164
  * Frame Callback
@@ -166,100 +173,100 @@ class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
166
  * Add link to campaign if available
167
  *
168
  * @param string $value
169
- * @param Varien_Object $row
170
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
171
  * @param boolean $export
 
172
  * @return string
173
  */
174
  public function addCampaignLink($value, $row, $column, $export)
175
  {
176
  $id = $row->getCampaignId();
177
- if($id && !$export) {
178
  $url = $this->getUrl('*/emarketing_campaign/edit', array('id' => $id));
179
  return sprintf('<a href="%s">%s</a>', $url, $value);
180
  }
181
  return $value;
182
  }
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
  protected function _prepareMassaction()
192
  {
193
  $this->setMassactionIdField('email_id');
194
  $this->getMassactionBlock()->setFormFieldName('messages');
195
 
196
-
197
  $this->getMassactionBlock()->addItem('unsubscribe', array(
198
  'label' => $this->__('Unsubscribe Email(s)'),
199
  'url' => $this->getUrl('*/*/massUnsubscribe'),
200
  'confirm' => $this->__('Are you sure you want to unsubscribe all selected emails?')
201
  ));
202
-
203
  $this->getMassactionBlock()->addItem('delete', array(
204
  'label' => $this->__('Delete Email(s)'),
205
  'url' => $this->getUrl('*/*/massDelete'),
206
  'confirm' => $this->__('Are you sure?')
207
  ));
208
-
209
  $this->getMassactionBlock()->addItem('reparse', array(
210
  'label' => $this->__('Re-parse Email(s)'),
211
  'url' => $this->getUrl('*/*/massParse')
212
  ));
213
-
214
- $this->getMassactionBlock()->addItem('flag_as', array(
215
- 'label'=> $this->__('Flag as...'),
 
 
216
  'url' => $this->getUrl('*/*/massFlag', array('_current'=>true)),
217
  'additional' => array(
218
- 'visibility' => array(
219
- 'name' => 'type',
220
- 'type' => 'select',
221
- 'class' => 'required-entry',
222
- 'label' => $this->__('Type'),
223
- 'options' => array(
224
- Mzax_Emarketing_Model_Inbox_Email::BOUNCE_SOFT => $this->__('Soft'),
225
- Mzax_Emarketing_Model_Inbox_Email::BOUNCE_HARD => $this->__('Hard'),
226
- Mzax_Emarketing_Model_Inbox_Email::AUTOREPLY => $this->__('Autoreply'),
227
- Mzax_Emarketing_Model_Inbox_Email::NO_BOUNCE => $this->__('No Bounce'),
228
- ),
 
229
  )
230
  )
231
- ));
232
-
233
  $this->getMassactionBlock()->addItem('forward', array(
234
  'label' => $this->__('Forward emails'),
235
  'url' => $this->getUrl('*/*/massForward')
236
  ));
237
-
238
-
239
  // enable disable
240
  $this->getMassactionBlock()->addItem('report', array(
241
  'label' => $this->__('Report as bounce'),
242
  'url' => $this->getUrl('*/*/massReport'),
243
- '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.')
244
  ));
245
-
246
  return $this;
247
  }
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
 
 
 
 
256
  public function getGridUrl()
257
  {
258
  return $this->getUrl('*/*/grid', array('_current'=> true));
259
  }
260
 
 
 
 
 
 
261
  public function getRowUrl($row)
262
  {
263
- return $this->getUrl('*/*/email', array('id'=>$row->getId()));
264
  }
265
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Inbox_Grid
22
+ */
23
  class Mzax_Emarketing_Block_Inbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Inbox_Grid constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('inbox_grid');
33
  $this->setUseAjax(true);
34
  $this->setSaveParametersInSession(true);
35
  $this->setDefaultSort('created_at');
36
  $this->setDefaultDir('desc');
37
  }
38
+
39
+ /**
40
+ * @return Mzax_Emarketing_Model_Resource_Inbox_Email_Collection
41
+ */
42
  public function getCollection()
43
  {
44
+ if (!$this->_collection) {
45
  /* Mzax_Emarketing_Model_Resource_Inbox_Email_Collection */
46
  $this->_collection = Mage::getResourceModel('mzax_emarketing/inbox_email_collection');
47
  $this->_collection->assignRecipients();
48
  $this->_collection->assignCampaigns();
49
  }
50
+
51
  return $this->_collection;
52
  }
53
+
54
+ /**
55
+ * Prepare columns
56
+ *
57
+ * @return $this
58
+ */
59
  protected function _prepareColumns()
60
  {
61
+ /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
62
+ $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
63
+
64
  $this->addColumn('created_at', array(
65
  'header' => $this->__('Created At'),
66
  'index' => 'created_at',
68
  'width' => 150,
69
  'type' =>'datetime'
70
  ));
71
+
72
  $this->addColumn('recipient', array(
73
  'header' => $this->__('Recipient'),
74
  'index' => 'email',
75
  'frame_callback' => array($this, 'addCampaignLink'),
76
  ));
77
+
78
  $this->addColumn('subject', array(
79
  'header' => $this->__('Subject'),
80
  'index' => 'subject',
100
  ),
101
  'width' => '100px',
102
  ));
103
+
 
 
 
 
104
  $this->addColumn('campaign', array(
105
  'header' => $this->__('Campaign'),
106
  'index' => 'campaign_id',
110
  'width' => '100px',
111
  ));
112
 
 
113
  if (!Mage::app()->isSingleStoreMode()) {
114
  $this->addColumn('store_id', array(
115
  'header' => $this->__('Store'),
119
  'display_deleted' => true,
120
  ));
121
  }
122
+
123
  $this->addColumn('status_code', array(
124
  'header' => $this->__('Status'),
125
  'index' =>'status_code'
132
  'renderer' => 'mzax_emarketing/grid_column_renderer_size',
133
  'width' => '50px',
134
  ));
135
+
136
+ parent::_prepareColumns();
137
+
138
+ return $this;
139
  }
140
 
 
 
 
141
  /**
142
  * Frame Callback
143
+ *
144
  * Add link to admin for subject if available
145
+ *
 
146
  * @param string $value
147
+ * @param Mzax_Emarketing_Model_Inbox_Email $row
148
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
149
  * @param boolean $export
150
+ *
151
  * @return string
152
  */
153
  public function addSubjectLink($value, $row, $column, $export)
154
  {
155
  $recipient = $row->getRecipient();
156
+
157
+ if ($recipient instanceof Mzax_Emarketing_Model_Recipient && !$export) {
 
158
  $campaign = $recipient->getCampaign();
159
+ $subject = $campaign->getRecipientProvider()->getSubject();
160
+
161
+ if ($subject) {
162
  $url = $subject->getAdminUrl($recipient->getObjectId());
163
  return sprintf('<a href="%s">%s</a>', $url, $value);
164
  }
 
165
  }
166
+
167
+ return '';
168
  }
 
 
169
 
170
  /**
171
  * Frame Callback
173
  * Add link to campaign if available
174
  *
175
  * @param string $value
176
+ * @param Mzax_Emarketing_Model_Inbox_Email $row
177
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
178
  * @param boolean $export
179
+ *
180
  * @return string
181
  */
182
  public function addCampaignLink($value, $row, $column, $export)
183
  {
184
  $id = $row->getCampaignId();
185
+ if ($id && !$export) {
186
  $url = $this->getUrl('*/emarketing_campaign/edit', array('id' => $id));
187
  return sprintf('<a href="%s">%s</a>', $url, $value);
188
  }
189
  return $value;
190
  }
191
+
192
+ /**
193
+ * @return $this
194
+ */
 
 
 
 
195
  protected function _prepareMassaction()
196
  {
197
  $this->setMassactionIdField('email_id');
198
  $this->getMassactionBlock()->setFormFieldName('messages');
199
 
200
+
201
  $this->getMassactionBlock()->addItem('unsubscribe', array(
202
  'label' => $this->__('Unsubscribe Email(s)'),
203
  'url' => $this->getUrl('*/*/massUnsubscribe'),
204
  'confirm' => $this->__('Are you sure you want to unsubscribe all selected emails?')
205
  ));
206
+
207
  $this->getMassactionBlock()->addItem('delete', array(
208
  'label' => $this->__('Delete Email(s)'),
209
  'url' => $this->getUrl('*/*/massDelete'),
210
  'confirm' => $this->__('Are you sure?')
211
  ));
212
+
213
  $this->getMassactionBlock()->addItem('reparse', array(
214
  'label' => $this->__('Re-parse Email(s)'),
215
  'url' => $this->getUrl('*/*/massParse')
216
  ));
217
+
218
+ $this->getMassactionBlock()->addItem(
219
+ 'flag_as',
220
+ array(
221
+ 'label' => $this->__('Flag as...'),
222
  'url' => $this->getUrl('*/*/massFlag', array('_current'=>true)),
223
  'additional' => array(
224
+ 'visibility' => array(
225
+ 'name' => 'type',
226
+ 'type' => 'select',
227
+ 'class' => 'required-entry',
228
+ 'label' => $this->__('Type'),
229
+ 'options' => array(
230
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_SOFT => $this->__('Soft'),
231
+ Mzax_Emarketing_Model_Inbox_Email::BOUNCE_HARD => $this->__('Hard'),
232
+ Mzax_Emarketing_Model_Inbox_Email::AUTOREPLY => $this->__('Autoreply'),
233
+ Mzax_Emarketing_Model_Inbox_Email::NO_BOUNCE => $this->__('No Bounce'),
234
+ )
235
+ )
236
  )
237
  )
238
+ );
239
+
240
  $this->getMassactionBlock()->addItem('forward', array(
241
  'label' => $this->__('Forward emails'),
242
  'url' => $this->getUrl('*/*/massForward')
243
  ));
244
+
 
245
  // enable disable
246
  $this->getMassactionBlock()->addItem('report', array(
247
  'label' => $this->__('Report as bounce'),
248
  'url' => $this->getUrl('*/*/massReport'),
249
+ '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 original content.')
250
  ));
251
+
252
  return $this;
253
  }
 
 
 
 
 
 
 
254
 
255
+ /**
256
+ * @return string
257
+ */
258
  public function getGridUrl()
259
  {
260
  return $this->getUrl('*/*/grid', array('_current'=> true));
261
  }
262
 
263
+ /**
264
+ * @param Mzax_Emarketing_Model_Inbox_Email $row
265
+ *
266
+ * @return string
267
+ */
268
  public function getRowUrl($row)
269
  {
270
+ return $this->getUrl('*/*/email', array('id' => $row->getId()));
271
  }
272
  }
app/code/community/Mzax/Emarketing/Block/Inbox/View.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,27 +17,28 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Inbox_View extends Mage_Adminhtml_Block_Widget_Grid_Container
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
- $this->_blockGroup = 'mzax_emarketing';
27
  $this->_controller = 'inbox';
28
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Inbox');
29
-
30
  parent::__construct();
31
-
32
  $this->removeButton('add');
33
-
34
  $this->_addButton('fetch', array(
35
  'label' => $this->__('Get new messages'),
36
  'onclick' => 'setLocation(\'' . $this->getUrl('*/*/fetch') .'\')',
37
  'class' => '',
38
  ));
39
-
40
  }
41
-
42
-
43
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Inbox_View
22
+ */
23
  class Mzax_Emarketing_Block_Inbox_View extends Mage_Adminhtml_Block_Widget_Grid_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Inbox_View constructor.
27
+ */
28
  public function __construct()
29
  {
30
+ $this->_blockGroup = 'mzax_emarketing';
31
  $this->_controller = 'inbox';
32
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Inbox');
33
+
34
  parent::__construct();
35
+
36
  $this->removeButton('add');
37
+
38
  $this->_addButton('fetch', array(
39
  'label' => $this->__('Get new messages'),
40
  'onclick' => 'setLocation(\'' . $this->getUrl('*/*/fetch') .'\')',
41
  'class' => '',
42
  ));
 
43
  }
 
 
 
44
  }
app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,12 +17,18 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Newsletter_List_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
22
  {
 
 
 
23
  public function __construct()
24
  {
25
  $this->_objectId = 'id';
26
-
27
  $this->_blockGroup = 'mzax_emarketing';
28
  $this->_controller = 'newsletter_list';
29
 
@@ -33,37 +38,43 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit extends Mage_Adminhtml_Block_Wi
33
  $this->_updateButton('delete', 'label', $this->__('Delete List'));
34
  }
35
 
36
-
37
-
38
-
39
  public function getHeaderText()
40
  {
41
  $list = Mage::registry('current_list');
42
  if ($list->getId()) {
43
  return $this->escapeHtml($list->getName());
44
- }
45
- else {
46
  return $this->__('New Template');
47
  }
48
  }
49
 
 
 
 
50
  public function getValidationUrl()
51
  {
52
  return $this->getUrl('*/*/validate', array('_current'=>true));
53
  }
54
-
 
 
 
55
  protected function _prepareLayout()
56
  {
57
- $this->_addButton('save_and_continue', array(
58
  'label' => $this->__('Save And Continue Edit'),
59
  'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
60
  'class' => 'save'
61
  ), 10);
62
 
63
- return parent::_prepareLayout();
 
 
64
  }
65
-
66
-
67
  /**
68
  * Get form action URL
69
  *
@@ -74,13 +85,16 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit extends Mage_Adminhtml_Block_Wi
74
  if ($this->hasFormActionUrl()) {
75
  return $this->getData('form_action_url');
76
  }
 
77
  return $this->getUrl('*/*/save');
78
  }
79
-
80
-
 
 
81
  protected function _getSaveAndContinueUrl()
82
  {
83
- return $this->getUrl('*/*/save', array(
84
  '_current' => true,
85
  'back' => 'edit'
86
  ));
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Newsletter_List_Edit
22
+ */
23
  class Mzax_Emarketing_Block_Newsletter_List_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Newsletter_List_Edit constructor.
27
+ */
28
  public function __construct()
29
  {
30
  $this->_objectId = 'id';
31
+
32
  $this->_blockGroup = 'mzax_emarketing';
33
  $this->_controller = 'newsletter_list';
34
 
38
  $this->_updateButton('delete', 'label', $this->__('Delete List'));
39
  }
40
 
41
+ /**
42
+ * @return string
43
+ */
44
  public function getHeaderText()
45
  {
46
  $list = Mage::registry('current_list');
47
  if ($list->getId()) {
48
  return $this->escapeHtml($list->getName());
49
+ } else {
 
50
  return $this->__('New Template');
51
  }
52
  }
53
 
54
+ /**
55
+ * @return string
56
+ */
57
  public function getValidationUrl()
58
  {
59
  return $this->getUrl('*/*/validate', array('_current'=>true));
60
  }
61
+
62
+ /**
63
+ * @return $this
64
+ */
65
  protected function _prepareLayout()
66
  {
67
+ $this->_addButton('save_and_continue', array(
68
  'label' => $this->__('Save And Continue Edit'),
69
  'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
70
  'class' => 'save'
71
  ), 10);
72
 
73
+ parent::_prepareLayout();
74
+
75
+ return $this;
76
  }
77
+
 
78
  /**
79
  * Get form action URL
80
  *
85
  if ($this->hasFormActionUrl()) {
86
  return $this->getData('form_action_url');
87
  }
88
+
89
  return $this->getUrl('*/*/save');
90
  }
91
+
92
+ /**
93
+ * @return string
94
+ */
95
  protected function _getSaveAndContinueUrl()
96
  {
97
+ return $this->getUrl('*/*/save', array(
98
  '_current' => true,
99
  'back' => 'edit'
100
  ));
app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,26 +17,33 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
 
 
24
  protected function _prepareForm()
25
  {
26
- $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
 
 
27
 
28
  /* @var $list Mzax_Emarketing_Model_Newsletter_List */
29
  $list = Mage::registry('current_list');
30
 
31
- if($list->getId()) {
32
  $form->addField('list_id', 'hidden', array(
33
  'name' => 'list_id',
34
  'value' => $list->getId()
35
  ));
36
  }
37
 
38
-
39
  $this->setForm($form);
40
  $form->setUseContainer(true);
 
41
  return parent::_prepareForm();
42
  }
43
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Newsletter_List_Edit_Form
22
+ */
23
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
28
  protected function _prepareForm()
29
  {
30
+ $form = new Varien_Data_Form(
31
+ array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')
32
+ );
33
 
34
  /* @var $list Mzax_Emarketing_Model_Newsletter_List */
35
  $list = Mage::registry('current_list');
36
 
37
+ if ($list->getId()) {
38
  $form->addField('list_id', 'hidden', array(
39
  'name' => 'list_id',
40
  'value' => $list->getId()
41
  ));
42
  }
43
 
 
44
  $this->setForm($form);
45
  $form->setUseContainer(true);
46
+
47
  return parent::_prepareForm();
48
  }
49
  }
app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Tab/Settings.php CHANGED
@@ -9,7 +9,6 @@
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
  *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,43 +17,36 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
24
- protected function _prepareLayout()
25
- {
26
- parent::_prepareLayout();
27
- }
28
-
29
-
30
-
31
  public function initForm()
32
  {
33
  $form = new Varien_Data_Form();
34
  $form->setHtmlIdPrefix('list_');
35
  $form->setFieldNameSuffix('list');
36
 
37
-
38
-
39
  /* @var $list Mzax_Emarketing_Model_Newsletter_List */
40
  $list = Mage::registry('current_list');
41
 
42
 
43
- if($list->getId()) {
44
  $form->addField('list_id', 'hidden', array(
45
  'name' => 'list_id',
46
  'value' => $list->getId()
47
  ));
48
  }
49
 
50
-
51
  $fieldset = $form->addFieldset('base_fieldset', array(
52
  'legend' => $this->__('List Options'),
53
  'class' => 'fieldset-wide',
54
  ));
55
 
56
-
57
-
58
  $fieldset->addField('name', 'text', array(
59
  'name' => 'name',
60
  'required' => true,
@@ -71,8 +63,6 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Settings extends Mage_Admin
71
  'note' => "Optional short description for the subscriber",
72
  ));
73
 
74
-
75
-
76
  $fieldset->addField('is_private', 'select', array(
77
  'label' => $this->__('Visibility'),
78
  'title' => $this->__('Visibility'),
@@ -86,8 +76,6 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Settings extends Mage_Admin
86
  'value' => '0'
87
  ));
88
 
89
-
90
-
91
  $fieldset->addField('auto_subscribe', 'select', array(
92
  'label' => $this->__('Auto Subscribe'),
93
  'title' => $this->__('Auto Subscribe'),
@@ -101,8 +89,6 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Settings extends Mage_Admin
101
  'value' => '1'
102
  ));
103
 
104
-
105
-
106
  if (!Mage::app()->isSingleStoreMode()) {
107
  $fieldset->addField('store_ids', 'multiselect', array(
108
  'name' => 'store_ids[]',
@@ -111,14 +97,12 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Settings extends Mage_Admin
111
  'required' => true,
112
  'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
113
  ));
114
- }
115
- else {
116
  $fieldset->addField('store_ids', 'hidden', array(
117
  'name' => 'store_ids[]'
118
  ));
119
  }
120
 
121
-
122
  $form->addValues($list->getData());
123
  $this->setForm($form);
124
 
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
  *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Settings
22
+ */
23
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
 
 
 
 
 
28
  public function initForm()
29
  {
30
  $form = new Varien_Data_Form();
31
  $form->setHtmlIdPrefix('list_');
32
  $form->setFieldNameSuffix('list');
33
 
 
 
34
  /* @var $list Mzax_Emarketing_Model_Newsletter_List */
35
  $list = Mage::registry('current_list');
36
 
37
 
38
+ if ($list->getId()) {
39
  $form->addField('list_id', 'hidden', array(
40
  'name' => 'list_id',
41
  'value' => $list->getId()
42
  ));
43
  }
44
 
 
45
  $fieldset = $form->addFieldset('base_fieldset', array(
46
  'legend' => $this->__('List Options'),
47
  'class' => 'fieldset-wide',
48
  ));
49
 
 
 
50
  $fieldset->addField('name', 'text', array(
51
  'name' => 'name',
52
  'required' => true,
63
  'note' => "Optional short description for the subscriber",
64
  ));
65
 
 
 
66
  $fieldset->addField('is_private', 'select', array(
67
  'label' => $this->__('Visibility'),
68
  'title' => $this->__('Visibility'),
76
  'value' => '0'
77
  ));
78
 
 
 
79
  $fieldset->addField('auto_subscribe', 'select', array(
80
  'label' => $this->__('Auto Subscribe'),
81
  'title' => $this->__('Auto Subscribe'),
89
  'value' => '1'
90
  ));
91
 
 
 
92
  if (!Mage::app()->isSingleStoreMode()) {
93
  $fieldset->addField('store_ids', 'multiselect', array(
94
  'name' => 'store_ids[]',
97
  'required' => true,
98
  'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
99
  ));
100
+ } else {
 
101
  $fieldset->addField('store_ids', 'hidden', array(
102
  'name' => 'store_ids[]'
103
  ));
104
  }
105
 
 
106
  $form->addValues($list->getData());
107
  $this->setForm($form);
108
 
app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Tab/Subscribers.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,12 +17,18 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers extends Mage_Adminhtml_Block_Widget_Grid
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
  parent::__construct();
 
27
  $this->setId('list_subscriber_grid');
28
  $this->setUseAjax(true);
29
  $this->setSaveParametersInSession(true);
@@ -33,8 +38,9 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers extends Mage_Ad
33
 
34
  }
35
 
36
-
37
-
 
38
  protected function _prepareCollection()
39
  {
40
  /* @var $collection Mzax_Emarketing_Model_Resource_Newsletter_List_Subscriber_Collection */
@@ -47,9 +53,9 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers extends Mage_Ad
47
  return parent::_prepareCollection();
48
  }
49
 
50
-
51
-
52
-
53
  protected function _prepareColumns()
54
  {
55
  $this->addColumn('subscriber_id', array(
@@ -106,13 +112,14 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers extends Mage_Ad
106
  'type' =>'datetime'
107
  ));
108
 
 
109
 
110
- return parent::_prepareColumns();
111
  }
112
 
113
-
114
-
115
-
116
  protected function _prepareMassaction()
117
  {
118
  $this->setMassactionIdField('subscriber_id');
@@ -132,27 +139,30 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers extends Mage_Ad
132
  return $this;
133
  }
134
 
135
-
136
-
 
137
  public function getAdditionalJavaScript()
138
  {
139
  $object = $this->getMassactionBlock()->getJsObjectName();
140
  return "window.{$object} = {$object};";
141
  }
142
 
143
-
144
-
145
-
146
-
147
-
148
  public function getGridUrl()
149
  {
150
  return $this->getUrl('*/*/subscribers', array('_current' => true));
151
  }
152
 
 
 
 
 
 
153
  public function getRowUrl($row)
154
  {
155
  return null;
156
  }
157
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers
22
+ */
23
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Newsletter_List_Edit_Tab_Subscribers constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('list_subscriber_grid');
33
  $this->setUseAjax(true);
34
  $this->setSaveParametersInSession(true);
38
 
39
  }
40
 
41
+ /**
42
+ * @return Mage_Adminhtml_Block_Widget_Grid
43
+ */
44
  protected function _prepareCollection()
45
  {
46
  /* @var $collection Mzax_Emarketing_Model_Resource_Newsletter_List_Subscriber_Collection */
53
  return parent::_prepareCollection();
54
  }
55
 
56
+ /**
57
+ * @return $this
58
+ */
59
  protected function _prepareColumns()
60
  {
61
  $this->addColumn('subscriber_id', array(
112
  'type' =>'datetime'
113
  ));
114
 
115
+ parent::_prepareColumns();
116
 
117
+ return $this;
118
  }
119
 
120
+ /**
121
+ * @return $this
122
+ */
123
  protected function _prepareMassaction()
124
  {
125
  $this->setMassactionIdField('subscriber_id');
139
  return $this;
140
  }
141
 
142
+ /**
143
+ * @return string
144
+ */
145
  public function getAdditionalJavaScript()
146
  {
147
  $object = $this->getMassactionBlock()->getJsObjectName();
148
  return "window.{$object} = {$object};";
149
  }
150
 
151
+ /**
152
+ * @return string
153
+ */
 
 
154
  public function getGridUrl()
155
  {
156
  return $this->getUrl('*/*/subscribers', array('_current' => true));
157
  }
158
 
159
+ /**
160
+ * @param $row
161
+ *
162
+ * @return null
163
+ */
164
  public function getRowUrl($row)
165
  {
166
  return null;
167
  }
 
168
  }
app/code/community/Mzax/Emarketing/Block/Newsletter/List/Edit/Tabs.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,17 +17,26 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
  parent::__construct();
 
27
  $this->setId('mzax_emarketing_newsletter_list_tabs');
28
  $this->setDestElementId('edit_form');
29
  $this->setTitle($this->__('Newsletter List'));
30
  }
31
 
 
 
 
32
  protected function _beforeToHtml()
33
  {
34
  /* @var $list Mzax_Emarketing_Model_Newsletter_List */
@@ -41,7 +49,7 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tabs extends Mage_Adminhtml_Blo
41
  'active' => true
42
  ));
43
 
44
- if($list->getId()) {
45
  $this->addTab('subscribers', array(
46
  'label' => $this->__('Subscribers'),
47
  'content' => $this->getLayout()->createBlock('mzax_emarketing/newsletter_list_edit_tab_subscribers')->toHtml(),
@@ -53,17 +61,17 @@ class Mzax_Emarketing_Block_Newsletter_List_Edit_Tabs extends Mage_Adminhtml_Blo
53
  return parent::_beforeToHtml();
54
  }
55
 
56
-
57
-
58
-
59
  protected function _updateActiveTab()
60
  {
61
- $tabId = $this->getRequest()->getParam('tab');
62
- if( $tabId ) {
63
- $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
64
- if($tabId) {
65
- $this->setActiveTab($tabId);
66
- }
67
- }
68
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Newsletter_List_Edit_Tabs
22
+ */
23
  class Mzax_Emarketing_Block_Newsletter_List_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Newsletter_List_Edit_Tabs constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('mzax_emarketing_newsletter_list_tabs');
33
  $this->setDestElementId('edit_form');
34
  $this->setTitle($this->__('Newsletter List'));
35
  }
36
 
37
+ /**
38
+ * @return Mage_Core_Block_Abstract
39
+ */
40
  protected function _beforeToHtml()
41
  {
42
  /* @var $list Mzax_Emarketing_Model_Newsletter_List */
49
  'active' => true
50
  ));
51
 
52
+ if ($list->getId()) {
53
  $this->addTab('subscribers', array(
54
  'label' => $this->__('Subscribers'),
55
  'content' => $this->getLayout()->createBlock('mzax_emarketing/newsletter_list_edit_tab_subscribers')->toHtml(),
61
  return parent::_beforeToHtml();
62
  }
63
 
64
+ /**
65
+ * @return void
66
+ */
67
  protected function _updateActiveTab()
68
  {
69
+ $tabId = $this->getRequest()->getParam('tab');
70
+ if ($tabId) {
71
+ $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
72
+ if ($tabId) {
73
+ $this->setActiveTab($tabId);
74
+ }
75
+ }
76
  }
77
+ }
app/code/community/Mzax/Emarketing/Block/Newsletter/List/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,30 +17,41 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Newsletter_List_Grid extends Mage_Adminhtml_Block_Widget_Grid
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
  parent::__construct();
 
27
  $this->setId('newsletter_list_grid');
28
  $this->setUseAjax(true);
29
  $this->setSaveParametersInSession(true);
30
  $this->setDefaultSort('list_id');
31
  }
32
 
33
-
 
 
34
  protected function _prepareCollection()
35
  {
36
  /* @var $collection Mzax_Emarketing_Model_Resource_Newsletter_List_Collection */
37
  $collection = Mage::getResourceModel('mzax_emarketing/newsletter_list_collection');
38
  $collection->addSubscriberCount();
 
39
  $this->setCollection($collection);
40
-
41
  return parent::_prepareCollection();
42
  }
43
-
44
-
 
 
45
  protected function _prepareColumns()
46
  {
47
  $this->addColumn('created_at', array(
@@ -51,7 +61,7 @@ class Mzax_Emarketing_Block_Newsletter_List_Grid extends Mage_Adminhtml_Block_Wi
51
  'type' =>'datetime',
52
  'width' => 200
53
  ));
54
-
55
  $this->addColumn('updated_at', array(
56
  'header' => $this->__('Updated At'),
57
  'index' =>'created_at',
@@ -59,7 +69,7 @@ class Mzax_Emarketing_Block_Newsletter_List_Grid extends Mage_Adminhtml_Block_Wi
59
  'type' =>'datetime',
60
  'width' => 200
61
  ));
62
-
63
  $this->addColumn('name', array(
64
  'header' => $this->__('Name'),
65
  'index' => 'name',
@@ -106,31 +116,38 @@ class Mzax_Emarketing_Block_Newsletter_List_Grid extends Mage_Adminhtml_Block_Wi
106
  'width' => 80
107
  ));
108
 
109
- return parent::_prepareColumns();
110
- }
111
 
112
-
113
- protected function _prepareMassaction()
114
- {
115
  return $this;
116
  }
117
 
118
-
119
-
 
 
 
 
120
  protected function _filterStoreCondition($collection, $column)
121
  {
122
  if (!$value = $column->getFilter()->getValue()) {
123
  return;
124
  }
125
- $this->getCollection()->addStoreFilter($value);
126
  }
127
 
128
-
 
 
129
  public function getGridUrl()
130
  {
131
  return $this->getUrl('*/*/grid', array('_current'=> true));
132
  }
133
 
 
 
 
 
 
134
  public function getRowUrl($row)
135
  {
136
  return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Newsletter_List_Grid
22
+ */
23
  class Mzax_Emarketing_Block_Newsletter_List_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Newsletter_List_Grid constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('newsletter_list_grid');
33
  $this->setUseAjax(true);
34
  $this->setSaveParametersInSession(true);
35
  $this->setDefaultSort('list_id');
36
  }
37
 
38
+ /**
39
+ * @return Mage_Adminhtml_Block_Widget_Grid
40
+ */
41
  protected function _prepareCollection()
42
  {
43
  /* @var $collection Mzax_Emarketing_Model_Resource_Newsletter_List_Collection */
44
  $collection = Mage::getResourceModel('mzax_emarketing/newsletter_list_collection');
45
  $collection->addSubscriberCount();
46
+
47
  $this->setCollection($collection);
48
+
49
  return parent::_prepareCollection();
50
  }
51
+
52
+ /**
53
+ * @return $this
54
+ */
55
  protected function _prepareColumns()
56
  {
57
  $this->addColumn('created_at', array(
61
  'type' =>'datetime',
62
  'width' => 200
63
  ));
64
+
65
  $this->addColumn('updated_at', array(
66
  'header' => $this->__('Updated At'),
67
  'index' =>'created_at',
69
  'type' =>'datetime',
70
  'width' => 200
71
  ));
72
+
73
  $this->addColumn('name', array(
74
  'header' => $this->__('Name'),
75
  'index' => 'name',
116
  'width' => 80
117
  ));
118
 
119
+ parent::_prepareColumns();
 
120
 
 
 
 
121
  return $this;
122
  }
123
 
124
+ /**
125
+ * @param Mzax_Emarketing_Model_Resource_Newsletter_List_Collection $collection
126
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
127
+ *
128
+ * @return void
129
+ */
130
  protected function _filterStoreCondition($collection, $column)
131
  {
132
  if (!$value = $column->getFilter()->getValue()) {
133
  return;
134
  }
135
+ $collection->addStoreFilter($value);
136
  }
137
 
138
+ /**
139
+ * @return string
140
+ */
141
  public function getGridUrl()
142
  {
143
  return $this->getUrl('*/*/grid', array('_current'=> true));
144
  }
145
 
146
+ /**
147
+ * @param $row
148
+ *
149
+ * @return string
150
+ */
151
  public function getRowUrl($row)
152
  {
153
  return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
app/code/community/Mzax/Emarketing/Block/Newsletter/List/View.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,20 +16,21 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Block_Newsletter_List_View extends Mage_Adminhtml_Block_Widget_Grid_Container
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
- $this->_blockGroup = 'mzax_emarketing';
27
  $this->_controller = 'newsletter_list';
28
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Newsletter Lists');
29
  $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New List');
30
-
31
  parent::__construct();
32
  }
33
-
34
-
35
-
36
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Block_Newsletter_List_View
21
+ */
22
  class Mzax_Emarketing_Block_Newsletter_List_View extends Mage_Adminhtml_Block_Widget_Grid_Container
23
  {
24
+ /**
25
+ * Mzax_Emarketing_Block_Newsletter_List_View constructor.
26
+ */
27
  public function __construct()
28
  {
29
+ $this->_blockGroup = 'mzax_emarketing';
30
  $this->_controller = 'newsletter_list';
31
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Newsletter Lists');
32
  $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New List');
33
+
34
  parent::__construct();
35
  }
 
 
 
36
  }
app/code/community/Mzax/Emarketing/Block/Outbox/Email.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,25 +16,30 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Block_Outbox_Email extends Mage_Adminhtml_Block_Widget_Form_Container
22
  {
 
 
 
23
  public function __construct()
24
  {
25
  $this->_objectId = 'id';
26
-
27
  $this->_blockGroup = 'mzax_emarketing';
28
  $this->_controller = 'outbox';
29
  $this->_mode = 'email';
30
 
31
  parent::__construct();
32
  $email = Mage::registry('current_email');
33
-
34
-
35
  $this->_updateButton('save', 'label', $this->__('Save'));
36
  $this->_updateButton('delete', 'label', $this->__('Delete'));
37
-
38
- if($email->getId() && $email->getStatus() == Mzax_Emarketing_Model_Outbox_Email::STATUS_NOT_SEND) {
39
  $this->_addButton('discard', array(
40
  'label' => $this->__('Discard'),
41
  'class' => 'delete',
@@ -48,46 +52,47 @@ class Mzax_Emarketing_Block_Outbox_Email extends Mage_Adminhtml_Block_Widget_For
48
  'onclick' => "setLocation('{$this->getUrl('*/*/render', array('_current' => true))}')",
49
  ));
50
  }
51
-
52
  $this->_addButton('download', array(
53
  'label' => Mage::helper('adminhtml')->__('Download'),
54
  'class' => 'download',
55
  'onclick' => "setLocation('{$this->getUrl('*/*/download', array('_current' => true))}')",
56
  ));
57
-
58
-
59
  $this->_removeButton('save');
60
  $this->_removeButton('reset');
61
-
62
  }
63
-
64
-
 
 
65
  public function getHeaderText()
66
  {
67
  $message = Mage::registry('current_email');
68
  if ($message->getId()) {
69
  return $this->htmlEscape($message->getSubject());
70
- }
71
- else {
72
  return $this->__('New Email');
73
  }
74
  }
75
 
76
-
77
-
 
78
  public function getValidationUrl()
79
  {
80
  return $this->getUrl('*/*/validate', array('_current'=>true));
81
  }
82
-
83
-
84
-
 
85
  protected function _prepareLayout()
86
  {
87
- return parent::_prepareLayout();
88
  }
89
-
90
-
91
  /**
92
  * Get form action URL
93
  *
@@ -100,6 +105,4 @@ class Mzax_Emarketing_Block_Outbox_Email extends Mage_Adminhtml_Block_Widget_For
100
  }
101
  return $this->getUrl('*/*/save');
102
  }
103
-
104
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Block_Outbox_Email
21
+ */
22
  class Mzax_Emarketing_Block_Outbox_Email extends Mage_Adminhtml_Block_Widget_Form_Container
23
  {
24
+ /**
25
+ * Mzax_Emarketing_Block_Outbox_Email constructor.
26
+ */
27
  public function __construct()
28
  {
29
  $this->_objectId = 'id';
30
+
31
  $this->_blockGroup = 'mzax_emarketing';
32
  $this->_controller = 'outbox';
33
  $this->_mode = 'email';
34
 
35
  parent::__construct();
36
  $email = Mage::registry('current_email');
37
+
38
+
39
  $this->_updateButton('save', 'label', $this->__('Save'));
40
  $this->_updateButton('delete', 'label', $this->__('Delete'));
41
+
42
+ if ($email->getId() && $email->getStatus() == Mzax_Emarketing_Model_Outbox_Email::STATUS_NOT_SEND) {
43
  $this->_addButton('discard', array(
44
  'label' => $this->__('Discard'),
45
  'class' => 'delete',
52
  'onclick' => "setLocation('{$this->getUrl('*/*/render', array('_current' => true))}')",
53
  ));
54
  }
55
+
56
  $this->_addButton('download', array(
57
  'label' => Mage::helper('adminhtml')->__('Download'),
58
  'class' => 'download',
59
  'onclick' => "setLocation('{$this->getUrl('*/*/download', array('_current' => true))}')",
60
  ));
61
+
62
+
63
  $this->_removeButton('save');
64
  $this->_removeButton('reset');
 
65
  }
66
+
67
+ /**
68
+ * @return string
69
+ */
70
  public function getHeaderText()
71
  {
72
  $message = Mage::registry('current_email');
73
  if ($message->getId()) {
74
  return $this->htmlEscape($message->getSubject());
75
+ } else {
 
76
  return $this->__('New Email');
77
  }
78
  }
79
 
80
+ /**
81
+ * @return string
82
+ */
83
  public function getValidationUrl()
84
  {
85
  return $this->getUrl('*/*/validate', array('_current'=>true));
86
  }
87
+
88
+ /**
89
+ * @return Mage_Core_Block_Abstract
90
+ */
91
  protected function _prepareLayout()
92
  {
93
+ return parent::_prepareLayout();
94
  }
95
+
 
96
  /**
97
  * Get form action URL
98
  *
105
  }
106
  return $this->getUrl('*/*/save');
107
  }
 
 
108
  }
app/code/community/Mzax/Emarketing/Block/Outbox/Email/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,30 +17,31 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
 
 
24
  protected function _prepareForm()
25
  {
26
  $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
27
  $form->setHtmlIdPrefix("email");
28
  $form->setFieldNameSuffix("email");
29
-
30
-
31
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
32
  $email = Mage::registry('current_email');
33
-
34
-
35
-
36
  // Setting custom renderer for content field to remove label column
37
  $rendererWide = $this->getLayout()
38
  ->createBlock('adminhtml/widget_form_renderer_fieldset_element')
39
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
40
-
41
  $aceType = Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_ace');
42
-
43
-
44
- if($email->getId()) {
45
  $form->addField('message_id', 'hidden', array(
46
  'name' => 'message_id',
47
  'value' => $email->getId()
@@ -52,18 +52,16 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
52
  'legend' => $this->__('Details'),
53
  'class' => 'fieldset-wide',
54
  ))->addType('ace', $aceType);
55
-
56
-
57
-
58
-
59
  $fieldset->addField('email', 'text', array(
60
  'name' => 'email',
61
  'label' => $this->__('Email (From)'),
62
  'title' => $this->__('Email (From)'),
63
  'readonly' => true
64
  ));
65
-
66
-
67
  $fieldset->addField('subject', 'text', array(
68
  'name' => 'subject',
69
  'label' => $this->__('Email Subject'),
@@ -71,23 +69,22 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
71
  'value' => $email->getSubject(),
72
  'readonly' => true
73
  ));
74
-
75
-
76
- if($campaign = $email->getCampaign()) {
77
-
78
  $fieldset->addField('campaign_name', 'link', array(
79
  'label' => $this->__('Campagin'),
80
  'value' => $campaign->getName(),
81
  'href' => $this->getUrl('*/emarketing_campaign/edit', array('id' => $campaign->getId()))
82
  ));
83
-
84
  }
85
-
86
- if($recipient = $email->getRecipient()) {
87
- if($campaign) {
88
  $href = $campaign->getRecipientProvider()->getObject()->getAdminUrl($recipient->getId());
89
  $recipient->prepare();
90
-
91
  $fieldset->addField('recipient_email', 'link', array(
92
  'label' => $this->__('Recipient'),
93
  'value' => sprintf('%s <%s>', $recipient->getName(), $recipient->getEmail()),
@@ -95,8 +92,7 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
95
  ));
96
  }
97
  }
98
-
99
-
100
  $editor = $fieldset->addField('message', 'ace', array(
101
  'name' => 'message',
102
  'label' => $this->__('Message'),
@@ -109,8 +105,6 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
109
  'value' => $email->getMessage(),
110
  'note' => $this->__('The plain text version of this email'),
111
  ));
112
-
113
-
114
 
115
  $fieldset->addField('log', 'ace', array(
116
  'name' => 'log',
@@ -123,16 +117,12 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
123
  'autosize' => true,
124
  'value' => $this->getData('log')
125
  ));
126
-
127
-
128
-
129
-
130
-
131
  $fieldset = $form->addFieldset('headers_fieldset', array(
132
  'legend' => $this->__('Email Headers'),
133
  'class' => 'fieldset-wide',
134
  ))->addType('ace', $aceType);
135
-
136
  $editor = $fieldset->addField('headers', 'ace', array(
137
  'name' => 'headers',
138
  'label' => $this->__('Headers'),
@@ -146,14 +136,13 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
146
  'autosize' => true,
147
  'value' => $email->getHeaders()
148
  ))->setRenderer($rendererWide);
149
-
150
-
151
-
152
  $fieldset = $form->addFieldset('html_fieldset', array(
153
  'legend' => $this->__('HTML Code'),
154
  'class' => 'fieldset-wide',
155
  ))->addType('ace', $aceType);
156
-
157
  $editor = $fieldset->addField('html_body', 'ace', array(
158
  'name' => 'html_body',
159
  'label' => $this->__('HTML Code'),
@@ -166,16 +155,14 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
166
  'readonly' => true,
167
  'value' => $email->getBodyHtml()
168
  ))->setRenderer($rendererWide);
169
-
170
-
171
-
172
-
173
-
174
  $fieldset = $form->addFieldset('content_fieldset', array(
175
  'legend' => $this->__('Raw Content'),
176
  'class' => 'fieldset-wide',
177
  ))->addType('ace', $aceType);
178
-
179
  $editor = $fieldset->addField('content', 'ace', array(
180
  'name' => 'content',
181
  'label' => $this->__('Content'),
@@ -188,11 +175,12 @@ class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widge
188
  'readonly' => true,
189
  'value' => $email->getContent()
190
  ))->setRenderer($rendererWide);
191
-
192
-
193
  $form->addValues($email->getData());
194
  $this->setForm($form);
195
  $form->setUseContainer(true);
 
196
  return parent::_prepareForm();
197
  }
198
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Outbox_Email_Form
22
+ */
23
  class Mzax_Emarketing_Block_Outbox_Email_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
28
  protected function _prepareForm()
29
  {
30
  $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
31
  $form->setHtmlIdPrefix("email");
32
  $form->setFieldNameSuffix("email");
33
+
 
34
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
35
  $email = Mage::registry('current_email');
36
+
 
 
37
  // Setting custom renderer for content field to remove label column
38
  $rendererWide = $this->getLayout()
39
  ->createBlock('adminhtml/widget_form_renderer_fieldset_element')
40
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
41
+
42
  $aceType = Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_ace');
43
+
44
+ if ($email->getId()) {
 
45
  $form->addField('message_id', 'hidden', array(
46
  'name' => 'message_id',
47
  'value' => $email->getId()
52
  'legend' => $this->__('Details'),
53
  'class' => 'fieldset-wide',
54
  ))->addType('ace', $aceType);
55
+
56
+
 
 
57
  $fieldset->addField('email', 'text', array(
58
  'name' => 'email',
59
  'label' => $this->__('Email (From)'),
60
  'title' => $this->__('Email (From)'),
61
  'readonly' => true
62
  ));
63
+
64
+
65
  $fieldset->addField('subject', 'text', array(
66
  'name' => 'subject',
67
  'label' => $this->__('Email Subject'),
69
  'value' => $email->getSubject(),
70
  'readonly' => true
71
  ));
72
+
73
+
74
+ if ($campaign = $email->getCampaign()) {
 
75
  $fieldset->addField('campaign_name', 'link', array(
76
  'label' => $this->__('Campagin'),
77
  'value' => $campaign->getName(),
78
  'href' => $this->getUrl('*/emarketing_campaign/edit', array('id' => $campaign->getId()))
79
  ));
80
+
81
  }
82
+
83
+ if ($recipient = $email->getRecipient()) {
84
+ if ($campaign) {
85
  $href = $campaign->getRecipientProvider()->getObject()->getAdminUrl($recipient->getId());
86
  $recipient->prepare();
87
+
88
  $fieldset->addField('recipient_email', 'link', array(
89
  'label' => $this->__('Recipient'),
90
  'value' => sprintf('%s <%s>', $recipient->getName(), $recipient->getEmail()),
92
  ));
93
  }
94
  }
95
+
 
96
  $editor = $fieldset->addField('message', 'ace', array(
97
  'name' => 'message',
98
  'label' => $this->__('Message'),
105
  'value' => $email->getMessage(),
106
  'note' => $this->__('The plain text version of this email'),
107
  ));
 
 
108
 
109
  $fieldset->addField('log', 'ace', array(
110
  'name' => 'log',
117
  'autosize' => true,
118
  'value' => $this->getData('log')
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'),
136
  'autosize' => true,
137
  'value' => $email->getHeaders()
138
  ))->setRenderer($rendererWide);
139
+
140
+
 
141
  $fieldset = $form->addFieldset('html_fieldset', array(
142
  'legend' => $this->__('HTML Code'),
143
  'class' => 'fieldset-wide',
144
  ))->addType('ace', $aceType);
145
+
146
  $editor = $fieldset->addField('html_body', 'ace', array(
147
  'name' => 'html_body',
148
  'label' => $this->__('HTML Code'),
155
  'readonly' => true,
156
  'value' => $email->getBodyHtml()
157
  ))->setRenderer($rendererWide);
158
+
159
+
160
+
 
 
161
  $fieldset = $form->addFieldset('content_fieldset', array(
162
  'legend' => $this->__('Raw Content'),
163
  'class' => 'fieldset-wide',
164
  ))->addType('ace', $aceType);
165
+
166
  $editor = $fieldset->addField('content', 'ace', array(
167
  'name' => 'content',
168
  'label' => $this->__('Content'),
175
  'readonly' => true,
176
  'value' => $email->getContent()
177
  ))->setRenderer($rendererWide);
178
+
179
+
180
  $form->addValues($email->getData());
181
  $this->setForm($form);
182
  $form->setUseContainer(true);
183
+
184
  return parent::_prepareForm();
185
  }
186
  }
app/code/community/Mzax/Emarketing/Block/Outbox/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,31 +17,40 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
22
  {
23
-
 
 
24
  protected function _construct()
25
  {
26
  parent::_construct();
 
27
  $this->setId('outbox_grid');
28
  $this->setUseAjax(true);
29
  $this->setSaveParametersInSession(true);
30
  $this->setDefaultSort('created_at');
31
  $this->setDefaultDir('desc');
32
  }
33
-
34
-
 
 
35
  protected function _beforeToHtml()
36
  {
37
  $this->setId('outbox_grid');
38
  parent::_beforeToHtml();
39
  }
40
-
41
-
42
-
 
43
  public function getCollection()
44
  {
45
- if(!$this->_collection) {
46
  /* Mzax_Emarketing_Model_Resource_Outbox_Email_Collection */
47
  $this->_collection = Mage::getResourceModel('mzax_emarketing/outbox_email_collection');
48
  $this->_collection->assignRecipients();
@@ -50,10 +58,16 @@ class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
50
  }
51
  return $this->_collection;
52
  }
53
-
54
-
 
 
55
  protected function _prepareColumns()
56
  {
 
 
 
 
57
  $this->addColumn('created_at', array(
58
  'header' => $this->__('Created at'),
59
  'index' => 'created_at',
@@ -61,14 +75,14 @@ class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
61
  'gmtoffset' => true,
62
  'type' =>'datetime'
63
  ));
64
-
65
  $this->addColumn('recipient', array(
66
  'header' => $this->__('Recipient'),
67
  'index' => 'to',
68
  'frame_callback' => array($this, 'addObjectLink'),
69
  ));
70
-
71
-
72
  $this->addColumn('sent_at', array(
73
  'header' => $this->__('Sent at'),
74
  'index' => 'sent_at',
@@ -83,32 +97,7 @@ class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
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',
@@ -116,8 +105,7 @@ class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
116
  'options' => $campaigns->toOptionHash(),
117
  'frame_callback' => array($this, 'addCampaignLink')
118
  ));
119
-
120
-
121
  $this->addColumn('status', array(
122
  'header' => $this->__('Status'),
123
  'index' => 'status',
@@ -129,51 +117,49 @@ class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
129
  Mzax_Emarketing_Model_Outbox_Email::STATUS_SENT => $this->__('Sent'),
130
  Mzax_Emarketing_Model_Outbox_Email::STATUS_DISCARDED => $this->__('Discarded'),
131
  ),
132
- 'frame_callback' => function($value, $row, $column, $export){
133
  $status = $row->getData($column->getIndex());
134
  return "<span class=\"outbox-status-{$status}\">!!$value!!</span>";
135
  },
136
  'width' => '100px',
137
  ));
138
-
139
- return parent::_prepareColumns();
 
 
140
  }
141
 
142
-
143
-
144
-
145
  /**
146
  * Frame Callback
147
- *
148
  * Add link to admin for subject if available
149
- *
150
- *
151
  * @param string $value
152
- * @param Varien_Object $row
153
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
154
  * @param boolean $export
 
155
  * @return string
156
  */
157
  public function addObjectLink($value, $row, $column, $export)
158
  {
159
  $recipient = $row->getRecipient();
160
-
161
- if($recipient instanceof Mzax_Emarketing_Model_Recipient && !$export)
162
- {
163
  $campaign = $recipient->getCampaign();
164
- if($campaign->getRecipientProvider()) {
165
  $object = $campaign->getRecipientProvider()->getObject();
166
-
167
- if($object) {
168
  $url = $object->getAdminUrl($recipient->getObjectId());
169
  return sprintf('<a href="%s">%s</a>', $url, $value);
170
  }
171
  }
172
  }
 
173
  return $value;
174
  }
175
-
176
-
177
 
178
  /**
179
  * Frame Callback
@@ -181,68 +167,69 @@ class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
181
  * Add link to campaign if available
182
  *
183
  * @param string $value
184
- * @param Varien_Object $row
185
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
186
  * @param boolean $export
 
187
  * @return string
188
  */
189
  public function addCampaignLink($value, $row, $column, $export)
190
  {
191
  $id = $row->getCampaignId();
192
- if($id && !$export) {
193
  $url = $this->getUrl('*/emarketing_campaign/edit', array('id' => $id));
194
  return sprintf('<a href="%s">%s</a>', $url, $value);
195
  }
 
196
  return $value;
197
  }
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
  protected function _prepareMassaction()
207
  {
208
  $this->setMassactionIdField('email_id');
209
  $this->getMassactionBlock()->setFormFieldName('messages');
210
-
211
-
212
  $this->getMassactionBlock()->addItem('send', array(
213
  'label' => $this->__('Send'),
214
  'url' => $this->getUrl('*/emarketing_outbox/massSend'),
215
  'confirm' => $this->__('Are you sure you want to send those emails now?')
216
  ));
217
-
218
  $this->getMassactionBlock()->addItem('delete', array(
219
  'label' => $this->__('Delete'),
220
  'url' => $this->getUrl('*/emarketing_outbox/massDelete'),
221
  'confirm' => $this->__('Are you sure?')
222
  ));
223
-
224
  $this->getMassactionBlock()->addItem('discard', array(
225
  'label' => $this->__('Discard'),
226
  'url' => $this->getUrl('*/emarketing_outbox/massDiscard'),
227
  'confirm' => $this->__('Are you sure?')
228
  ));
229
-
230
-
231
  return $this;
232
  }
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
 
 
 
 
 
 
241
  public function getGridUrl()
242
  {
243
  return $this->getUrl('*/*/grid', array('_current'=> true));
244
  }
245
 
 
 
 
 
 
 
 
246
  public function getRowUrl($row)
247
  {
248
  return $this->getUrl('*/*/email', array('id'=>$row->getId()));
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Outbox_Grid
22
+ */
23
  class Mzax_Emarketing_Block_Outbox_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * @return void
27
+ */
28
  protected function _construct()
29
  {
30
  parent::_construct();
31
+
32
  $this->setId('outbox_grid');
33
  $this->setUseAjax(true);
34
  $this->setSaveParametersInSession(true);
35
  $this->setDefaultSort('created_at');
36
  $this->setDefaultDir('desc');
37
  }
38
+
39
+ /**
40
+ * @return void
41
+ */
42
  protected function _beforeToHtml()
43
  {
44
  $this->setId('outbox_grid');
45
  parent::_beforeToHtml();
46
  }
47
+
48
+ /**
49
+ * @return Mzax_Emarketing_Model_Resource_Outbox_Email_Collection
50
+ */
51
  public function getCollection()
52
  {
53
+ if (!$this->_collection) {
54
  /* Mzax_Emarketing_Model_Resource_Outbox_Email_Collection */
55
  $this->_collection = Mage::getResourceModel('mzax_emarketing/outbox_email_collection');
56
  $this->_collection->assignRecipients();
58
  }
59
  return $this->_collection;
60
  }
61
+
62
+ /**
63
+ * @return $this
64
+ */
65
  protected function _prepareColumns()
66
  {
67
+ /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
68
+ $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
69
+
70
+
71
  $this->addColumn('created_at', array(
72
  'header' => $this->__('Created at'),
73
  'index' => 'created_at',
75
  'gmtoffset' => true,
76
  'type' =>'datetime'
77
  ));
78
+
79
  $this->addColumn('recipient', array(
80
  'header' => $this->__('Recipient'),
81
  'index' => 'to',
82
  'frame_callback' => array($this, 'addObjectLink'),
83
  ));
84
+
85
+
86
  $this->addColumn('sent_at', array(
87
  'header' => $this->__('Sent at'),
88
  'index' => 'sent_at',
97
  'gmtoffset' => true,
98
  'type' =>'datetime'
99
  ));
100
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  $this->addColumn('campaign', array(
102
  'header' => $this->__('Campaign'),
103
  'index' => 'campaign_id',
105
  'options' => $campaigns->toOptionHash(),
106
  'frame_callback' => array($this, 'addCampaignLink')
107
  ));
108
+
 
109
  $this->addColumn('status', array(
110
  'header' => $this->__('Status'),
111
  'index' => 'status',
117
  Mzax_Emarketing_Model_Outbox_Email::STATUS_SENT => $this->__('Sent'),
118
  Mzax_Emarketing_Model_Outbox_Email::STATUS_DISCARDED => $this->__('Discarded'),
119
  ),
120
+ 'frame_callback' => function ($value, $row, $column, $export) {
121
  $status = $row->getData($column->getIndex());
122
  return "<span class=\"outbox-status-{$status}\">!!$value!!</span>";
123
  },
124
  'width' => '100px',
125
  ));
126
+
127
+ parent::_prepareColumns();
128
+
129
+ return $this;
130
  }
131
 
 
 
 
132
  /**
133
  * Frame Callback
134
+ *
135
  * Add link to admin for subject if available
136
+ *
137
+ *
138
  * @param string $value
139
+ * @param Mzax_Emarketing_Model_Outbox_Email $row
140
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
141
  * @param boolean $export
142
+ *
143
  * @return string
144
  */
145
  public function addObjectLink($value, $row, $column, $export)
146
  {
147
  $recipient = $row->getRecipient();
148
+
149
+ if ($recipient instanceof Mzax_Emarketing_Model_Recipient && !$export) {
 
150
  $campaign = $recipient->getCampaign();
151
+ if ($campaign->getRecipientProvider()) {
152
  $object = $campaign->getRecipientProvider()->getObject();
153
+
154
+ if ($object) {
155
  $url = $object->getAdminUrl($recipient->getObjectId());
156
  return sprintf('<a href="%s">%s</a>', $url, $value);
157
  }
158
  }
159
  }
160
+
161
  return $value;
162
  }
 
 
163
 
164
  /**
165
  * Frame Callback
167
  * Add link to campaign if available
168
  *
169
  * @param string $value
170
+ * @param Mzax_Emarketing_Model_Outbox_Email $row
171
  * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
172
  * @param boolean $export
173
+ *
174
  * @return string
175
  */
176
  public function addCampaignLink($value, $row, $column, $export)
177
  {
178
  $id = $row->getCampaignId();
179
+ if ($id && !$export) {
180
  $url = $this->getUrl('*/emarketing_campaign/edit', array('id' => $id));
181
  return sprintf('<a href="%s">%s</a>', $url, $value);
182
  }
183
+
184
  return $value;
185
  }
186
+
187
+ /**
188
+ * @return $this
189
+ */
 
 
 
 
190
  protected function _prepareMassaction()
191
  {
192
  $this->setMassactionIdField('email_id');
193
  $this->getMassactionBlock()->setFormFieldName('messages');
194
+
 
195
  $this->getMassactionBlock()->addItem('send', array(
196
  'label' => $this->__('Send'),
197
  'url' => $this->getUrl('*/emarketing_outbox/massSend'),
198
  'confirm' => $this->__('Are you sure you want to send those emails now?')
199
  ));
200
+
201
  $this->getMassactionBlock()->addItem('delete', array(
202
  'label' => $this->__('Delete'),
203
  'url' => $this->getUrl('*/emarketing_outbox/massDelete'),
204
  'confirm' => $this->__('Are you sure?')
205
  ));
206
+
207
  $this->getMassactionBlock()->addItem('discard', array(
208
  'label' => $this->__('Discard'),
209
  'url' => $this->getUrl('*/emarketing_outbox/massDiscard'),
210
  'confirm' => $this->__('Are you sure?')
211
  ));
212
+
 
213
  return $this;
214
  }
 
 
 
 
 
 
 
215
 
216
+ /**
217
+ * Retrieve grid url
218
+ *
219
+ * @return string
220
+ */
221
  public function getGridUrl()
222
  {
223
  return $this->getUrl('*/*/grid', array('_current'=> true));
224
  }
225
 
226
+ /**
227
+ * Retrieve row url
228
+ *
229
+ * @param Mzax_Emarketing_Model_Outbox_Email $row
230
+ *
231
+ * @return string
232
+ */
233
  public function getRowUrl($row)
234
  {
235
  return $this->getUrl('*/*/email', array('id'=>$row->getId()));
app/code/community/Mzax/Emarketing/Block/Outbox/View.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,28 +16,28 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Block_Outbox_View extends Mage_Adminhtml_Block_Widget_Grid_Container
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
- $this->_blockGroup = 'mzax_emarketing';
27
  $this->_controller = 'outbox';
28
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Outbox');
29
-
30
  parent::__construct();
31
-
32
-
33
  $this->_removeButton('add');
34
-
35
  $this->_addButton('send', array(
36
  'label' => $this->__('Send Pending'),
37
  'onclick' => 'setLocation(\'' . $this->getUrl('*/*/send') .'\')',
38
  'class' => '',
39
  ));
40
  }
41
-
42
-
43
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Block_Outbox_View
21
+ */
22
  class Mzax_Emarketing_Block_Outbox_View extends Mage_Adminhtml_Block_Widget_Grid_Container
23
  {
24
+ /**
25
+ * Mzax_Emarketing_Block_Outbox_View constructor.
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
  $this->_removeButton('add');
36
+
37
  $this->_addButton('send', array(
38
  'label' => $this->__('Send Pending'),
39
  'onclick' => 'setLocation(\'' . $this->getUrl('*/*/send') .'\')',
40
  'class' => '',
41
  ));
42
  }
 
 
 
43
  }
app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Attribute.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,52 +17,47 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Recipients_Column_Renderer_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
22
  {
23
-
24
  /**
25
  * Retrieve attribute
26
- *
27
  * @return Mage_Catalog_Model_Resource_Eav_Attribute
28
  */
29
  public function getAttribute()
30
  {
31
  return $this->getColumn()->getAttribute();
32
  }
33
-
34
-
35
-
36
-
 
 
37
  public function render(Varien_Object $row)
38
  {
39
  $attribute = $this->getAttribute();
40
-
41
-
42
  $data = $row->getData($attribute->getAttributeCode());
43
-
44
- if($attribute->getFrontendInput() === 'multiselect') {
45
-
46
  $searchValue = (array) $this->getColumn()->getSearchValue();
47
-
48
  $result = array();
49
- foreach(explode(',', $data) as $value) {
50
  $valueText = $attribute->getSource()->getOptionText($value);
51
- if(in_array($value, $searchValue)) {
52
  $valueText = "<strong>$valueText</strong>";
53
  }
54
  $result[] = $valueText;
55
  }
56
-
57
  $data = implode(', ', $result);
58
  }
59
-
60
-
61
-
62
  return $data;
63
  }
64
-
65
-
66
-
67
-
68
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Recipients_Column_Renderer_Attribute
22
+ */
23
  class Mzax_Emarketing_Block_Recipients_Column_Renderer_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
24
  {
 
25
  /**
26
  * Retrieve attribute
27
+ *
28
  * @return Mage_Catalog_Model_Resource_Eav_Attribute
29
  */
30
  public function getAttribute()
31
  {
32
  return $this->getColumn()->getAttribute();
33
  }
34
+
35
+ /**
36
+ * @param Varien_Object $row
37
+ *
38
+ * @return mixed|string
39
+ */
40
  public function render(Varien_Object $row)
41
  {
42
  $attribute = $this->getAttribute();
43
+
 
44
  $data = $row->getData($attribute->getAttributeCode());
45
+
46
+ if ($attribute->getFrontendInput() === 'multiselect') {
 
47
  $searchValue = (array) $this->getColumn()->getSearchValue();
48
+
49
  $result = array();
50
+ foreach (explode(',', $data) as $value) {
51
  $valueText = $attribute->getSource()->getOptionText($value);
52
+ if (in_array($value, $searchValue)) {
53
  $valueText = "<strong>$valueText</strong>";
54
  }
55
  $result[] = $valueText;
56
  }
57
+
58
  $data = implode(', ', $result);
59
  }
60
+
 
 
61
  return $data;
62
  }
 
 
 
 
 
63
  }
app/code/community/Mzax/Emarketing/Block/Recipients/Column/Renderer/Object.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,42 +17,45 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Recipients_Column_Renderer_Object extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
22
  {
23
-
24
  /**
25
  * Retrieve current object
26
- *
27
  * @return Mzax_Emarketing_Model_Object_Abstract
28
  */
29
  public function getObject()
30
  {
31
  return $this->getColumn()->getObject();
32
  }
33
-
34
-
35
-
36
-
 
 
37
  public function render(Varien_Object $row)
38
- {
39
  $idField = $this->getColumn()->getIdField();
40
- if(!$idField) {
41
  $idField = $row->getIdFieldName();
42
  }
43
-
44
  $labelField = $this->getColumn()->getLabelField();
45
- if($labelField) {
46
  $label = $row->getData($labelField);
47
- }
48
- else {
49
  $label = $this->getObject()->getRowId($row);
50
  }
51
-
52
-
53
  $url = $this->getObject()->getAdminUrl($row->getData($idField));
54
- if($url) {
55
  return "<a href=\"{$url}\" target=\"_blank\">$label</a>";
56
  }
 
57
  return $label;
58
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Recipients_Column_Renderer_Object
22
+ */
23
  class Mzax_Emarketing_Block_Recipients_Column_Renderer_Object extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
24
  {
 
25
  /**
26
  * Retrieve current object
27
+ *
28
  * @return Mzax_Emarketing_Model_Object_Abstract
29
  */
30
  public function getObject()
31
  {
32
  return $this->getColumn()->getObject();
33
  }
34
+
35
+ /**
36
+ * @param Varien_Object $row
37
+ *
38
+ * @return string
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
+ } else {
 
51
  $label = $this->getObject()->getRowId($row);
52
  }
53
+
 
54
  $url = $this->getObject()->getAdminUrl($row->getData($idField));
55
+ if ($url) {
56
  return "<a href=\"{$url}\" target=\"_blank\">$label</a>";
57
  }
58
+
59
  return $label;
60
  }
61
  }
app/code/community/Mzax/Emarketing/Block/Recipients/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,138 +17,124 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
- *
25
- * @method Mzax_Emarketing_Model_Object_Collection getCollection()
26
- *
27
- * @author Jacob Siefer
28
- *
29
  */
30
  class Mzax_Emarketing_Block_Recipients_Grid extends Mage_Adminhtml_Block_Widget_Grid
31
  {
32
-
33
  /**
34
  * @var Mzax_Emarketing_Model_Object_Filter_Component
35
  */
36
  protected $_source;
37
 
38
-
39
-
 
40
  public function __construct()
41
  {
42
  parent::__construct();
43
  }
44
-
45
-
46
  /**
47
- *
48
- *
49
  * @return Mzax_Emarketing_Model_Object_Filter_Component
50
  */
51
  public function getSource()
52
  {
53
  return $this->_source;
54
  }
55
-
56
-
57
  /**
58
- *
59
  * @return Mzax_Emarketing_Model_Object_Abstract
60
  */
61
  public function getObject()
62
  {
63
  return $this->getCollection()->getObject();
64
  }
65
-
66
-
67
  /**
68
- *
69
  * @param Mzax_Emarketing_Model_Object_Filter_Component $source
70
- * @return Mzax_Emarketing_Block_Recipients_Grid
 
71
  */
72
  public function setSource(Mzax_Emarketing_Model_Object_Filter_Component $source)
73
  {
74
  $this->_source = $source;
 
75
  return $this;
76
  }
77
-
78
-
79
-
80
  /**
81
- * (non-PHPdoc)
82
- * @see Mage_Adminhtml_Block_Widget_Grid::getCollection()
83
  * @return Mzax_Emarketing_Model_Object_Collection
84
  */
85
  public function getCollection()
86
  {
87
  return $this->getSource()->getCollection();
88
  }
89
-
90
-
91
-
92
  /**
93
  * Allow provider and filters to alter the grid
94
- *
 
 
95
  */
96
  protected function _afterLoadCollection()
97
  {
98
- parent::_afterLoadCollection();
99
- $this->getSource()->afterGridLoadCollection($this);
100
-
101
  return $this;
102
  }
103
-
104
-
105
-
106
-
107
-
108
  /**
109
  * Prepare grid columns
110
- *
111
  * This is done by the email provider. The grid
112
  * does not know what type of objects it is loading
113
- *
 
114
  */
115
  protected function _prepareColumns()
116
  {
117
  $object = $this->getObject();
118
-
119
  $this->setFilterVisibility(true);
120
  $this->setPagerVisibility(true);
121
-
122
  $this->addColumn('main_object_id', array(
123
  'header' => $this->__($object->getName() .' ID'),
124
  'index' => 'id',
125
  'is_system' => true,
126
- 'width' => '50px',
127
  'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
128
  'object' => $object,
129
  ));
130
-
131
  $this->setDefaultSort('main_object_id');
132
  $this->setDefaultDir('DESC');
133
-
134
  $this->getSource()->prepareGridColumns($this);
135
- return parent::_prepareColumns();
 
 
 
136
  }
137
-
138
-
139
-
 
140
  public function getGridUrl()
141
  {
142
  return $this->getData('grid_url');
143
  }
144
-
145
-
146
-
 
 
 
147
  public function getRowUrl($row)
148
  {
149
  return null;
150
  }
151
-
152
-
153
-
154
-
155
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Recipients_Grid
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Recipients_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
 
25
  /**
26
  * @var Mzax_Emarketing_Model_Object_Filter_Component
27
  */
28
  protected $_source;
29
 
30
+ /**
31
+ * Mzax_Emarketing_Block_Recipients_Grid constructor.
32
+ */
33
  public function __construct()
34
  {
35
  parent::__construct();
36
  }
37
+
 
38
  /**
 
 
39
  * @return Mzax_Emarketing_Model_Object_Filter_Component
40
  */
41
  public function getSource()
42
  {
43
  return $this->_source;
44
  }
45
+
 
46
  /**
 
47
  * @return Mzax_Emarketing_Model_Object_Abstract
48
  */
49
  public function getObject()
50
  {
51
  return $this->getCollection()->getObject();
52
  }
53
+
 
54
  /**
55
+ *
56
  * @param Mzax_Emarketing_Model_Object_Filter_Component $source
57
+ *
58
+ * @return $this
59
  */
60
  public function setSource(Mzax_Emarketing_Model_Object_Filter_Component $source)
61
  {
62
  $this->_source = $source;
63
+
64
  return $this;
65
  }
66
+
 
 
67
  /**
 
 
68
  * @return Mzax_Emarketing_Model_Object_Collection
69
  */
70
  public function getCollection()
71
  {
72
  return $this->getSource()->getCollection();
73
  }
74
+
 
 
75
  /**
76
  * Allow provider and filters to alter the grid
77
+ *
78
+ * @return $this
79
+ * @deprecated
80
  */
81
  protected function _afterLoadCollection()
82
  {
83
+ parent::_afterLoadCollection();
84
+ $this->getSource()->afterGridLoadCollection($this);
85
+
86
  return $this;
87
  }
88
+
 
 
 
 
89
  /**
90
  * Prepare grid columns
91
+ *
92
  * This is done by the email provider. The grid
93
  * does not know what type of objects it is loading
94
+ *
95
+ * @return $this
96
  */
97
  protected function _prepareColumns()
98
  {
99
  $object = $this->getObject();
100
+
101
  $this->setFilterVisibility(true);
102
  $this->setPagerVisibility(true);
103
+
104
  $this->addColumn('main_object_id', array(
105
  'header' => $this->__($object->getName() .' ID'),
106
  'index' => 'id',
107
  'is_system' => true,
108
+ 'width' => '50px',
109
  'renderer' => 'mzax_emarketing/recipients_column_renderer_object',
110
  'object' => $object,
111
  ));
112
+
113
  $this->setDefaultSort('main_object_id');
114
  $this->setDefaultDir('DESC');
115
+
116
  $this->getSource()->prepareGridColumns($this);
117
+
118
+ parent::_prepareColumns();
119
+
120
+ return $this;
121
  }
122
+
123
+ /**
124
+ * @return mixed
125
+ */
126
  public function getGridUrl()
127
  {
128
  return $this->getData('grid_url');
129
  }
130
+
131
+ /**
132
+ * @param $row
133
+ *
134
+ * @return null
135
+ */
136
  public function getRowUrl($row)
137
  {
138
  return null;
139
  }
 
 
 
 
140
  }
app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/DomainThreshold.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,13 +18,14 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
24
- *
25
  */
26
  class Mzax_Emarketing_Block_System_Config_Form_Field_DomainThreshold
27
  extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
28
  {
 
 
 
29
  public function __construct()
30
  {
31
  $this->addColumn('domain', array(
@@ -48,9 +48,10 @@ class Mzax_Emarketing_Block_System_Config_Form_Field_DomainThreshold
48
  'style' => 'width:30px',
49
  'class' => 'required-entry validate-zero-or-greater'
50
  ));
51
-
52
  $this->_addAfter = false;
53
  $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add Domain');
 
54
  parent::__construct();
55
  }
56
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_System_Config_Form_Field_DomainThreshold
 
 
22
  */
23
  class Mzax_Emarketing_Block_System_Config_Form_Field_DomainThreshold
24
  extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
25
  {
26
+ /**
27
+ * Mzax_Emarketing_Block_System_Config_Form_Field_DomainThreshold constructor.
28
+ */
29
  public function __construct()
30
  {
31
  $this->addColumn('domain', array(
48
  'style' => 'width:30px',
49
  'class' => 'required-entry validate-zero-or-greater'
50
  ));
51
+
52
  $this->_addAfter = false;
53
  $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add Domain');
54
+
55
  parent::__construct();
56
  }
57
  }
app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/MailStorage.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,48 +18,49 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
24
- *
25
  */
26
  class Mzax_Emarketing_Block_System_Config_Form_Field_MailStorage
27
  extends Mage_Adminhtml_Block_System_Config_Form_Field
28
  {
29
-
30
-
31
-
32
  protected function _getHtml()
33
  {
34
  /* @var $inbox Mzax_Emarketing_Model_Inbox_Email_Collector */
35
  $collector = Mage::getSingleton('mzax_emarketing/inbox_email_collector');
36
  $result = $collector->test();
37
-
38
- if($result) {
39
  $message = Mage::helper('mzax_emarketing')->__('Successfully conntected to inbox');
40
  $class = 'inbox-success';
41
- }
42
- else {
43
  $message = Mage::helper('mzax_emarketing')->__('Failed to conntected to inbox');
44
  $class = 'inbox-failure';
45
  }
46
-
47
  return '<div class="inbox-status '.$class.'">' . $message . '</div>';
48
  }
49
-
50
-
51
-
 
 
 
52
  public function render(Varien_Data_Form_Element_Abstract $element)
53
  {
54
  $id = $element->getHtmlId();
55
-
56
- if(!Mage::getStoreConfigFlag('mzax_emarketing/inbox/enable')) {
57
  return '';
58
  }
59
-
60
  $useContainerId = $element->getData('use_container_id');
61
  $html = '<tr id="row_' . $id . '">'
62
  . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
63
  . '</tr>';
 
64
  return $html;
65
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_System_Config_Form_Field_MailStorage
 
 
22
  */
23
  class Mzax_Emarketing_Block_System_Config_Form_Field_MailStorage
24
  extends Mage_Adminhtml_Block_System_Config_Form_Field
25
  {
26
+ /**
27
+ * @return string
28
+ */
29
  protected function _getHtml()
30
  {
31
  /* @var $inbox Mzax_Emarketing_Model_Inbox_Email_Collector */
32
  $collector = Mage::getSingleton('mzax_emarketing/inbox_email_collector');
33
  $result = $collector->test();
34
+
35
+ if ($result) {
36
  $message = Mage::helper('mzax_emarketing')->__('Successfully conntected to inbox');
37
  $class = 'inbox-success';
38
+ } else {
 
39
  $message = Mage::helper('mzax_emarketing')->__('Failed to conntected to inbox');
40
  $class = 'inbox-failure';
41
  }
42
+
43
  return '<div class="inbox-status '.$class.'">' . $message . '</div>';
44
  }
45
+
46
+ /**
47
+ * @param Varien_Data_Form_Element_Abstract $element
48
+ *
49
+ * @return string
50
+ */
51
  public function render(Varien_Data_Form_Element_Abstract $element)
52
  {
53
  $id = $element->getHtmlId();
54
+
55
+ if (!Mage::getStoreConfigFlag('mzax_emarketing/inbox/enable')) {
56
  return '';
57
  }
58
+
59
  $useContainerId = $element->getData('use_container_id');
60
  $html = '<tr id="row_' . $id . '">'
61
  . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
62
  . '</tr>';
63
+
64
  return $html;
65
  }
66
  }
app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/Mandrill.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,62 +18,60 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
24
- *
25
  */
26
  class Mzax_Emarketing_Block_System_Config_Form_Field_Mandrill
27
  extends Mage_Adminhtml_Block_System_Config_Form_Field
28
  {
29
-
30
-
31
-
32
  protected function _getHtml()
33
  {
34
  $username = Mage::getStoreConfig('mzax_emarketing/email/mandrill_username');
35
  $password = Mage::getStoreConfig('mzax_emarketing/email/mandrill_password');
36
-
37
- if(empty($username)) {
38
- $message = Mage::helper('mzax_emarketing')->__('Please provider a valid Mandrill username.');
39
  $class = 'inbox-failure';
40
- }
41
- else if(empty($password)) {
42
- $message = Mage::helper('mzax_emarketing')->__('Please provider a valid Mandrill password.');
43
  $class = 'inbox-failure';
44
- }
45
- else {
46
- /* @var $transprot Mzax_Emarketing_Model_Outbox_Transporter_Mandrill */
47
- $transprot = Mage::getModel('mzax_emarketing/outbox_transporter_mandrill');
48
-
49
- $result = $transprot->testAuth($username, $password);
50
-
51
- if($result === true) {
52
- $message = Mage::helper('mzax_emarketing')->__('Successfully conntected to Mandrill');
53
  $class = 'inbox-success';
54
- }
55
- else {
56
- $message = Mage::helper('mzax_emarketing')->__('Failed to connect to Mandrill: %s', $result);
57
  $class = 'inbox-failure';
58
  }
59
  }
60
-
61
  return '<div class="inbox-status '.$class.'">' . $message . '</div>';
62
  }
63
-
64
-
65
-
 
 
 
66
  public function render(Varien_Data_Form_Element_Abstract $element)
67
  {
68
  $id = $element->getHtmlId();
69
-
70
- if(Mage::getStoreConfig('mzax_emarketing/email/transporter') !== 'mandrill') {
71
  return '';
72
  }
73
-
74
- $useContainerId = $element->getData('use_container_id');
75
  $html = '<tr id="row_' . $id . '">'
76
  . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
77
  . '</tr>';
 
78
  return $html;
79
  }
80
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_System_Config_Form_Field_Mandrill
 
 
22
  */
23
  class Mzax_Emarketing_Block_System_Config_Form_Field_Mandrill
24
  extends Mage_Adminhtml_Block_System_Config_Form_Field
25
  {
26
+ /**
27
+ * @return string
28
+ */
29
  protected function _getHtml()
30
  {
31
  $username = Mage::getStoreConfig('mzax_emarketing/email/mandrill_username');
32
  $password = Mage::getStoreConfig('mzax_emarketing/email/mandrill_password');
33
+
34
+ if (empty($username)) {
35
+ $message = $this->__('Please provider a valid Mandrill username.');
36
  $class = 'inbox-failure';
37
+ } elseif (empty($password)) {
38
+ $message = $this->__('Please provider a valid Mandrill password.');
 
39
  $class = 'inbox-failure';
40
+ } else {
41
+ /* @var $transport Mzax_Emarketing_Model_Outbox_Transporter_Mandrill */
42
+ $transport = Mage::getModel('mzax_emarketing/outbox_transporter_mandrill');
43
+
44
+ $result = $transport->testAuth($username, $password);
45
+
46
+ if ($result === true) {
47
+ $message = $this->__('Successfully connected to Mandrill');
 
48
  $class = 'inbox-success';
49
+ } else {
50
+ $message = $this->__('Failed to connect to Mandrill: %s', $result);
 
51
  $class = 'inbox-failure';
52
  }
53
  }
54
+
55
  return '<div class="inbox-status '.$class.'">' . $message . '</div>';
56
  }
57
+
58
+ /**
59
+ * @param Varien_Data_Form_Element_Abstract $element
60
+ *
61
+ * @return string
62
+ */
63
  public function render(Varien_Data_Form_Element_Abstract $element)
64
  {
65
  $id = $element->getHtmlId();
66
+
67
+ if (Mage::getStoreConfig('mzax_emarketing/email/transporter') !== 'mandrill') {
68
  return '';
69
  }
70
+
 
71
  $html = '<tr id="row_' . $id . '">'
72
  . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
73
  . '</tr>';
74
+
75
  return $html;
76
  }
77
  }
app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/MandrillApi.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 this Extension in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mzax
13
+ * @package Mzax_Emarketing
14
+ * @author Jacob Siefer (jacob@mzax.de)
15
+ * @copyright Copyright (c) 2015 Jacob Siefer
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_System_Config_Form_Field_MandrillApi
22
+ */
23
+ class Mzax_Emarketing_Block_System_Config_Form_Field_MandrillApi
24
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
25
+ {
26
+ /**
27
+ * @return string
28
+ */
29
+ protected function _getHtml()
30
+ {
31
+ $apiKey = Mage::getStoreConfig('mzax_emarketing/email/mandrill_api_key');
32
+ $subAccount = Mage::getStoreConfig('mzax_emarketing/email/mandrill_api_subaccount');
33
+
34
+ if (empty($apiKey)) {
35
+ $message = Mage::helper('mzax_emarketing')->__('Please provider a valid Mandrill API key.');
36
+ $class = 'inbox-failure';
37
+ } else {
38
+ /* @var $transport Mzax_Emarketing_Model_Outbox_Transporter_MandrillApi */
39
+ $transport = Mage::getModel('mzax_emarketing/outbox_transporter_mandrillApi');
40
+
41
+ $result = $transport->testApi($apiKey, $subAccount);
42
+
43
+ if ($result === true) {
44
+ $message = Mage::helper('mzax_emarketing')->__('Successfully connected to Mandrill API');
45
+ $class = 'inbox-success';
46
+ } else {
47
+ $message = Mage::helper('mzax_emarketing')->__('Failed to connect to Mandrill API: %s', $result);
48
+ $class = 'inbox-failure';
49
+ }
50
+ }
51
+
52
+ return '<div class="inbox-status '.$class.'">' . $message . '</div>';
53
+ }
54
+
55
+ /**
56
+ * @param Varien_Data_Form_Element_Abstract $element
57
+ *
58
+ * @return string
59
+ */
60
+ public function render(Varien_Data_Form_Element_Abstract $element)
61
+ {
62
+ $id = $element->getHtmlId();
63
+
64
+ if (Mage::getStoreConfig('mzax_emarketing/email/transporter') !== 'mandrill_api') {
65
+ return '';
66
+ }
67
+
68
+ $html = '<tr id="row_' . $id . '">'
69
+ . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
70
+ . '</tr>';
71
+
72
+ return $html;
73
+ }
74
+ }
app/code/community/Mzax/Emarketing/Block/System/Config/Form/Field/Sendgrid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,62 +18,60 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
24
- *
25
  */
26
  class Mzax_Emarketing_Block_System_Config_Form_Field_Sendgrid
27
  extends Mage_Adminhtml_Block_System_Config_Form_Field
28
  {
29
-
30
-
31
-
32
  protected function _getHtml()
33
  {
34
  $username = Mage::getStoreConfig('mzax_emarketing/email/sendgrid_username');
35
  $password = Mage::getStoreConfig('mzax_emarketing/email/sendgrid_password');
36
-
37
- if(empty($username)) {
38
- $message = Mage::helper('mzax_emarketing')->__('Please provider a valid SandGrid username.');
39
  $class = 'inbox-failure';
40
- }
41
- else if(empty($password)) {
42
- $message = Mage::helper('mzax_emarketing')->__('Please provider a valid SandGrid password.');
43
  $class = 'inbox-failure';
44
- }
45
- else {
46
- /* @var $transprot Mzax_Emarketing_Model_Outbox_Transporter_Sendgrid */
47
- $transprot = Mage::getModel('mzax_emarketing/outbox_transporter_sendgrid');
48
-
49
- $result = $transprot->testAuth($username, $password);
50
-
51
- if($result === true) {
52
- $message = Mage::helper('mzax_emarketing')->__('Successfully conntected to SendGrid');
53
  $class = 'inbox-success';
54
- }
55
- else {
56
- $message = Mage::helper('mzax_emarketing')->__('Failed to connect to SendGird: %s', $result);
57
  $class = 'inbox-failure';
58
  }
59
  }
60
-
61
  return '<div class="inbox-status '.$class.'">' . $message . '</div>';
62
  }
63
-
64
-
65
-
 
 
 
66
  public function render(Varien_Data_Form_Element_Abstract $element)
67
  {
68
  $id = $element->getHtmlId();
69
-
70
- if(Mage::getStoreConfig('mzax_emarketing/email/transporter') !== 'sendgird') {
71
  return '';
72
  }
73
-
74
- $useContainerId = $element->getData('use_container_id');
75
  $html = '<tr id="row_' . $id . '">'
76
  . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
77
  . '</tr>';
 
78
  return $html;
79
  }
80
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_System_Config_Form_Field_Sendgrid
 
 
22
  */
23
  class Mzax_Emarketing_Block_System_Config_Form_Field_Sendgrid
24
  extends Mage_Adminhtml_Block_System_Config_Form_Field
25
  {
26
+ /**
27
+ * @return string
28
+ */
29
  protected function _getHtml()
30
  {
31
  $username = Mage::getStoreConfig('mzax_emarketing/email/sendgrid_username');
32
  $password = Mage::getStoreConfig('mzax_emarketing/email/sendgrid_password');
33
+
34
+ if (empty($username)) {
35
+ $message = $this->__('Please provider a valid SandGrid username.');
36
  $class = 'inbox-failure';
37
+ } elseif (empty($password)) {
38
+ $message = $this->__('Please provider a valid SandGrid password.');
 
39
  $class = 'inbox-failure';
40
+ } else {
41
+ /* @var $transport Mzax_Emarketing_Model_Outbox_Transporter_Sendgrid */
42
+ $transport = Mage::getModel('mzax_emarketing/outbox_transporter_sendgrid');
43
+
44
+ $result = $transport->testAuth($username, $password);
45
+
46
+ if ($result === true) {
47
+ $message = $this->__('Successfully conntected to SendGrid');
 
48
  $class = 'inbox-success';
49
+ } else {
50
+ $message = $this->__('Failed to connect to SendGird: %s', $result);
 
51
  $class = 'inbox-failure';
52
  }
53
  }
54
+
55
  return '<div class="inbox-status '.$class.'">' . $message . '</div>';
56
  }
57
+
58
+ /**
59
+ * @param Varien_Data_Form_Element_Abstract $element
60
+ *
61
+ * @return string
62
+ */
63
  public function render(Varien_Data_Form_Element_Abstract $element)
64
  {
65
  $id = $element->getHtmlId();
66
+
67
+ if (Mage::getStoreConfig('mzax_emarketing/email/transporter') !== 'sendgird') {
68
  return '';
69
  }
70
+
 
71
  $html = '<tr id="row_' . $id . '">'
72
  . '<td class="mzax-mail-storage-test" colspan="3">' . $this->_getHtml(). '</td>'
73
  . '</tr>';
74
+
75
  return $html;
76
  }
77
  }
app/code/community/Mzax/Emarketing/Block/Template.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -21,20 +20,13 @@
21
 
22
  /**
23
  * Template block helper class with usefull methods
24
- *
25
  *
26
  * @method Mage_Sales_Model_Order getOrder()
27
  * @method Mage_Sales_Model_Quote getQuote()
28
  * @method Mage_Customer_Model_Customer getCustomer()
29
- *
30
- * @author Jacob Siefer
31
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
- * @version 0.4.10
33
  */
34
  class Mzax_Emarketing_Block_Template extends Mage_Core_Block_Template
35
  {
36
-
37
-
38
  /**
39
  * Retrieve store id
40
  *
@@ -44,41 +36,37 @@ class Mzax_Emarketing_Block_Template extends Mage_Core_Block_Template
44
  {
45
  return Mage::app()->getStore()->getId();
46
  }
47
-
48
-
49
  /**
50
  * Retrieve website id
51
- *
52
  * @return number
53
  */
54
  public function getWebsiteId()
55
  {
56
  return Mage::app()->getStore()->getWebsiteId();
57
  }
58
-
59
-
60
-
61
  /**
62
  * Format Price
63
- *
64
  * @param number $price
65
- * @param string $includeContainer
 
66
  * @return string
67
  */
68
  public function formatPrice($price, $includeContainer = false)
69
  {
70
  return Mage::app()->getStore()->formatPrice($price, $includeContainer);
71
  }
72
-
73
 
74
-
75
-
76
  /**
77
  * Retrieve the products viewd by the specified customer [of the last X days]
78
- *
79
  * @param Mage_Customer_Model_Customer $customer
80
- * @param number $count
81
- * @param number $lastDays
 
82
  * @return Mzax_Emarketing_Model_Resource_Collection_Product
83
  */
84
  public function getLastViewedProducts(Mage_Customer_Model_Customer $customer, $count = 6, $lastDays = false)
@@ -88,21 +76,19 @@ class Mzax_Emarketing_Block_Template extends Mage_Core_Block_Template
88
  $collection->addCustomerViewFilter($customer);
89
  $collection->addAttributeToSort('logged_at', 'DESC');
90
  $collection->addAttributeToFilter('event_store', Mage::app()->getStore()->getId());
91
-
92
- if($lastDays) {
93
  $collection->addEventDateFilter(450);
94
  }
95
-
96
  return $collection;
97
  }
98
-
99
-
100
-
101
  /**
102
  * Retrieve last X orders for the given customer
103
- *
104
  * Will return order collection that can be altered.
105
- *
106
  * @param Mage_Customer_Model_Customer $customer
107
  * @return Mage_Sales_Model_Resource_Order_Collection
108
  */
@@ -113,97 +99,94 @@ class Mzax_Emarketing_Block_Template extends Mage_Core_Block_Template
113
  $collection->addFieldToFilter('customer_id', $customer->getId());
114
  $collection->addOrder('entity_id', 'DESC');
115
  $collection->setPageSize($count);
116
-
117
  return $collection;
118
  }
119
-
120
-
121
-
122
 
123
  /**
124
- * Retreive cross-sell product list
125
  *
126
  * @param mixed $object
 
127
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
128
  */
129
  public function getCrosssellProducts($object)
130
  {
131
  $productIds = $this->extractProductIds($object);
132
- $collection = $this->getLinkedProducts($productIds,
133
- Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL);
134
-
 
 
135
  return $collection;
136
  }
137
-
138
-
139
-
140
 
141
  /**
142
- * Retreive up-sell product list
143
  *
144
  * @param mixed $object
 
145
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
146
  */
147
  public function getUpsellProducts($object)
148
  {
149
  $productIds = $this->extractProductIds($object);
150
- $collection = $this->getLinkedProducts($productIds,
151
- Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL);
152
-
 
 
153
  return $collection;
154
  }
155
-
156
-
157
  /**
158
- * Retreive related product list
159
- *
160
  * @param mixed $object
 
161
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
162
  */
163
  public function getRelatedProducts($object)
164
  {
165
  $productIds = $this->extractProductIds($object);
166
- $collection = $this->getLinkedProducts($productIds,
167
- Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED);
168
-
 
 
169
  return $collection;
170
  }
171
-
172
-
173
-
174
-
175
  /**
176
  * Extract all product ids from a given object,
177
  * this can be an order, quote or product
178
- *
179
  * @param mixed $object
180
- * @return array
 
181
  */
182
  public function extractProductIds($object)
183
  {
184
  $productIds = array();
185
-
186
- if($object instanceof Mage_Sales_Model_Order ||
187
- $object instanceof Mage_Sales_Model_Quote)
188
- {
189
- foreach($object->getAllVisibleItems() as $item) {
190
  $productIds[] = $item->getProductId();
191
  }
192
- }
193
- else if($object instanceof Mage_Catalog_Model_Product) {
194
  $productIds[] = $object->getId();
195
  }
196
-
197
  return $productIds;
198
  }
199
-
200
-
201
-
202
-
203
  /**
204
  * Retrieve linked products
205
- *
206
  * @param array $productIds
 
 
207
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
208
  */
209
  public function getLinkedProducts($productIds, $linkType = Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED)
@@ -211,110 +194,109 @@ class Mzax_Emarketing_Block_Template extends Mage_Core_Block_Template
211
  /* @var $linkModel Mage_Catalog_Model_Product_Link */
212
  $linkModel = Mage::getModel('catalog/product_link');
213
  $linkModel->setLinkTypeId($linkType);
214
-
215
  $productIds = (array) $productIds;
216
-
217
  /* @var $collection Mage_Catalog_Model_Resource_Product_Link_Product_Collection */
218
  $collection = Mage::getResourceModel('catalog/product_link_product_collection');
219
- $collection->setLinkModel($linkModel)
220
- ->addProductFilter($productIds)
221
- ->addExcludeProductFilter($productIds);
222
-
223
  return $collection;
224
  }
225
-
226
-
227
-
228
-
229
  /**
230
  * Retrieve all items from order or quote and
231
  * include product object
232
- *
233
  * @param mixed $object
234
  * @param string $attributes
235
- * @return Mage_Sales_Model_Resource_Order_Collection
 
236
  */
237
  public function getAllItems($object, $attributes = '*')
238
  {
239
  $result = array();
240
-
241
  /* @var $collection Mage_Sales_Model_Resource_Order_Collection */
242
  $collection = $object->getItemsCollection();
243
-
244
  /* @var $productsCollection Mzax_Emarketing_Model_Resource_Collection_Product */
245
- $productsCollection = Mage::getResourceModel('mzax_emarketing/collection_product')
246
- ->addIdFilter($collection->getColumnValues('product_id'))
247
- ->addAttributeToSelect($attributes)
248
- ->addPriceData()
249
- ->load();
250
-
251
- foreach($collection as $item) {
252
  $product = $productsCollection->getItemById($item->getProductId());
253
- if($product) {
254
  $item->setProduct($product);
255
- if(!$item->getParentItem()) {
256
  $result[] = $item;
257
  }
258
  }
259
  }
 
260
  return $result;
261
  }
262
-
263
-
264
-
265
  /**
266
  * Retrieve product
267
- *
268
  * @param mixed $object
 
269
  * @return Mage_Catalog_Model_Product|NULL
270
  */
271
  public function getProduct($object = null)
272
  {
273
- if(!$object) {
274
  return $this->getData('product');
275
  }
276
- if($object instanceof Mage_Catalog_Model_Product) {
 
277
  return $object;
278
  }
279
- if( $object instanceof Mage_Sales_Model_Order_Item ||
280
- $object instanceof Mage_Sales_Model_Quote_Item ||
 
281
  $object instanceof Mage_Sales_Model_Order_Invoice_Item ||
282
  $object instanceof Mage_Sales_Model_Order_Shipment_Item ||
283
- $object instanceof Mage_Sales_Model_Order_Creditmemo_Item)
284
- {
285
  return $object->getProduct();
286
  }
287
-
288
  // @todo check for productId or sku?
289
  return null;
290
  }
291
-
292
-
293
-
294
-
295
  /**
296
  * Retrieve catalog image helper instance
297
- *
298
  * @param mixed $object
299
  * @param string $attribute
300
- * @param number $size
 
301
  * @return Mage_Catalog_Helper_Image
302
  */
303
  public function getProductImage($object, $attribute = 'small_image', $size = 100)
304
  {
305
- $product = $this->getProduct($object);
306
  $helper = $this->helper('catalog/image');
307
- if($product) {
308
- $helper->init($product, 'small_image')
 
 
309
  ->constrainOnly(true)
310
  ->keepAspectRatio(true)
311
  ->keepFrame(false)
312
  ->setQuality(40)
313
  ->resize($size, $size);
314
  }
 
315
  return $helper;
316
  }
317
-
318
-
319
-
320
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
20
 
21
  /**
22
  * Template block helper class with usefull methods
 
23
  *
24
  * @method Mage_Sales_Model_Order getOrder()
25
  * @method Mage_Sales_Model_Quote getQuote()
26
  * @method Mage_Customer_Model_Customer getCustomer()
 
 
 
 
27
  */
28
  class Mzax_Emarketing_Block_Template extends Mage_Core_Block_Template
29
  {
 
 
30
  /**
31
  * Retrieve store id
32
  *
36
  {
37
  return Mage::app()->getStore()->getId();
38
  }
39
+
 
40
  /**
41
  * Retrieve website id
42
+ *
43
  * @return number
44
  */
45
  public function getWebsiteId()
46
  {
47
  return Mage::app()->getStore()->getWebsiteId();
48
  }
49
+
 
 
50
  /**
51
  * Format Price
52
+ *
53
  * @param number $price
54
+ * @param bool $includeContainer
55
+ *
56
  * @return string
57
  */
58
  public function formatPrice($price, $includeContainer = false)
59
  {
60
  return Mage::app()->getStore()->formatPrice($price, $includeContainer);
61
  }
 
62
 
 
 
63
  /**
64
  * Retrieve the products viewd by the specified customer [of the last X days]
65
+ *
66
  * @param Mage_Customer_Model_Customer $customer
67
+ * @param int $count
68
+ * @param bool $lastDays
69
+ *
70
  * @return Mzax_Emarketing_Model_Resource_Collection_Product
71
  */
72
  public function getLastViewedProducts(Mage_Customer_Model_Customer $customer, $count = 6, $lastDays = false)
76
  $collection->addCustomerViewFilter($customer);
77
  $collection->addAttributeToSort('logged_at', 'DESC');
78
  $collection->addAttributeToFilter('event_store', Mage::app()->getStore()->getId());
79
+
80
+ if ($lastDays) {
81
  $collection->addEventDateFilter(450);
82
  }
83
+
84
  return $collection;
85
  }
86
+
 
 
87
  /**
88
  * Retrieve last X orders for the given customer
89
+ *
90
  * Will return order collection that can be altered.
91
+ *
92
  * @param Mage_Customer_Model_Customer $customer
93
  * @return Mage_Sales_Model_Resource_Order_Collection
94
  */
99
  $collection->addFieldToFilter('customer_id', $customer->getId());
100
  $collection->addOrder('entity_id', 'DESC');
101
  $collection->setPageSize($count);
102
+
103
  return $collection;
104
  }
 
 
 
105
 
106
  /**
107
+ * Retrieve cross-sell product list
108
  *
109
  * @param mixed $object
110
+ *
111
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
112
  */
113
  public function getCrosssellProducts($object)
114
  {
115
  $productIds = $this->extractProductIds($object);
116
+ $collection = $this->getLinkedProducts(
117
+ $productIds,
118
+ Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL
119
+ );
120
+
121
  return $collection;
122
  }
 
 
 
123
 
124
  /**
125
+ * Retrieve up-sell product list
126
  *
127
  * @param mixed $object
128
+ *
129
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
130
  */
131
  public function getUpsellProducts($object)
132
  {
133
  $productIds = $this->extractProductIds($object);
134
+ $collection = $this->getLinkedProducts(
135
+ $productIds,
136
+ Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL
137
+ );
138
+
139
  return $collection;
140
  }
141
+
 
142
  /**
143
+ * Retrieve related product list
144
+ *
145
  * @param mixed $object
146
+ *
147
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
148
  */
149
  public function getRelatedProducts($object)
150
  {
151
  $productIds = $this->extractProductIds($object);
152
+ $collection = $this->getLinkedProducts(
153
+ $productIds,
154
+ Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED
155
+ );
156
+
157
  return $collection;
158
  }
159
+
 
 
 
160
  /**
161
  * Extract all product ids from a given object,
162
  * this can be an order, quote or product
163
+ *
164
  * @param mixed $object
165
+ *
166
+ * @return string[]
167
  */
168
  public function extractProductIds($object)
169
  {
170
  $productIds = array();
171
+
172
+ if ($object instanceof Mage_Sales_Model_Order ||
173
+ $object instanceof Mage_Sales_Model_Quote) {
174
+ foreach ($object->getAllVisibleItems() as $item) {
 
175
  $productIds[] = $item->getProductId();
176
  }
177
+ } elseif ($object instanceof Mage_Catalog_Model_Product) {
 
178
  $productIds[] = $object->getId();
179
  }
180
+
181
  return $productIds;
182
  }
183
+
 
 
 
184
  /**
185
  * Retrieve linked products
186
+ *
187
  * @param array $productIds
188
+ * @param int $linkType
189
+ *
190
  * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
191
  */
192
  public function getLinkedProducts($productIds, $linkType = Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED)
194
  /* @var $linkModel Mage_Catalog_Model_Product_Link */
195
  $linkModel = Mage::getModel('catalog/product_link');
196
  $linkModel->setLinkTypeId($linkType);
197
+
198
  $productIds = (array) $productIds;
199
+
200
  /* @var $collection Mage_Catalog_Model_Resource_Product_Link_Product_Collection */
201
  $collection = Mage::getResourceModel('catalog/product_link_product_collection');
202
+ $collection->setLinkModel($linkModel);
203
+ $collection->addProductFilter($productIds);
204
+ $collection->addExcludeProductFilter($productIds);
205
+
206
  return $collection;
207
  }
208
+
 
 
 
209
  /**
210
  * Retrieve all items from order or quote and
211
  * include product object
212
+ *
213
  * @param mixed $object
214
  * @param string $attributes
215
+ *
216
+ * @return Mage_Sales_Model_Abstract[]
217
  */
218
  public function getAllItems($object, $attributes = '*')
219
  {
220
  $result = array();
221
+
222
  /* @var $collection Mage_Sales_Model_Resource_Order_Collection */
223
  $collection = $object->getItemsCollection();
224
+
225
  /* @var $productsCollection Mzax_Emarketing_Model_Resource_Collection_Product */
226
+ $productsCollection = Mage::getResourceModel('mzax_emarketing/collection_product');
227
+ $productsCollection->addIdFilter($collection->getColumnValues('product_id'));
228
+ $productsCollection->addAttributeToSelect($attributes);
229
+ $productsCollection->addPriceData();
230
+ $productsCollection->load();
231
+
232
+ foreach ($collection as $item) {
233
  $product = $productsCollection->getItemById($item->getProductId());
234
+ if ($product) {
235
  $item->setProduct($product);
236
+ if (!$item->getParentItem()) {
237
  $result[] = $item;
238
  }
239
  }
240
  }
241
+
242
  return $result;
243
  }
244
+
245
+
246
+
247
  /**
248
  * Retrieve product
249
+ *
250
  * @param mixed $object
251
+ *
252
  * @return Mage_Catalog_Model_Product|NULL
253
  */
254
  public function getProduct($object = null)
255
  {
256
+ if (!$object) {
257
  return $this->getData('product');
258
  }
259
+
260
+ if ($object instanceof Mage_Catalog_Model_Product) {
261
  return $object;
262
  }
263
+
264
+ if ($object instanceof Mage_Sales_Model_Order_Item ||
265
+ $object instanceof Mage_Sales_Model_Quote_Item ||
266
  $object instanceof Mage_Sales_Model_Order_Invoice_Item ||
267
  $object instanceof Mage_Sales_Model_Order_Shipment_Item ||
268
+ $object instanceof Mage_Sales_Model_Order_Creditmemo_Item) {
 
269
  return $object->getProduct();
270
  }
271
+
272
  // @todo check for productId or sku?
273
  return null;
274
  }
275
+
 
 
 
276
  /**
277
  * Retrieve catalog image helper instance
278
+ *
279
  * @param mixed $object
280
  * @param string $attribute
281
+ * @param int $size
282
+ *
283
  * @return Mage_Catalog_Helper_Image
284
  */
285
  public function getProductImage($object, $attribute = 'small_image', $size = 100)
286
  {
287
+ /** @var Mage_Catalog_Helper_Image $helper */
288
  $helper = $this->helper('catalog/image');
289
+ $product = $this->getProduct($object);
290
+
291
+ if ($product) {
292
+ $helper->init($product, $attribute)
293
  ->constrainOnly(true)
294
  ->keepAspectRatio(true)
295
  ->keepFrame(false)
296
  ->setQuality(40)
297
  ->resize($size, $size);
298
  }
299
+
300
  return $helper;
301
  }
302
+ }
 
 
 
app/code/community/Mzax/Emarketing/Block/Template/Edit.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,62 +17,70 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Template_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
22
  {
 
 
 
23
  public function __construct()
24
  {
25
  $this->_objectId = 'id';
26
-
27
  $this->_blockGroup = 'mzax_emarketing';
28
  $this->_controller = 'template';
29
 
30
-
31
  parent::__construct();
32
 
33
  $this->_updateButton('save', 'label', $this->__('Save Template'));
34
  $this->_updateButton('delete', 'label', $this->__('Delete Template'));
35
-
36
- if(Mage::registry('current_template')->getId()) {
37
  $this->_addButton('download', array(
38
  'label' => $this->__('Download'),
39
  'class' => 'download',
40
  'onclick' => "setLocation('{$this->getUrl('*/*/download', array('_current' => true))}')",
41
  ));
42
  }
43
-
44
  }
45
 
46
-
47
-
48
-
49
  public function getHeaderText()
50
  {
51
  $template = Mage::registry('current_template');
52
  if ($template->getId()) {
53
- return $this->htmlEscape($template->getName());
54
- }
55
- else {
56
  return $this->__('New Template');
57
  }
58
  }
59
 
 
 
 
60
  public function getValidationUrl()
61
  {
62
  return $this->getUrl('*/*/validate', array('_current'=>true));
63
  }
64
-
 
 
 
65
  protected function _prepareLayout()
66
  {
67
- $this->_addButton('save_and_continue', array(
68
  'label' => $this->__('Save And Continue Edit'),
69
  'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
70
  'class' => 'save'
71
  ), 10);
72
 
73
- return parent::_prepareLayout();
74
  }
75
-
76
-
77
  /**
78
  * Get form action URL
79
  *
@@ -86,11 +93,13 @@ class Mzax_Emarketing_Block_Template_Edit extends Mage_Adminhtml_Block_Widget_Fo
86
  }
87
  return $this->getUrl('*/*/save');
88
  }
89
-
90
-
 
 
91
  protected function _getSaveAndContinueUrl()
92
  {
93
- return $this->getUrl('*/*/save', array(
94
  '_current' => true,
95
  'back' => 'edit'
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Template_Edit
22
+ */
23
  class Mzax_Emarketing_Block_Template_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Template_Edit constructor.
27
+ */
28
  public function __construct()
29
  {
30
  $this->_objectId = 'id';
31
+
32
  $this->_blockGroup = 'mzax_emarketing';
33
  $this->_controller = 'template';
34
 
 
35
  parent::__construct();
36
 
37
  $this->_updateButton('save', 'label', $this->__('Save Template'));
38
  $this->_updateButton('delete', 'label', $this->__('Delete Template'));
39
+
40
+ if (Mage::registry('current_template')->getId()) {
41
  $this->_addButton('download', array(
42
  'label' => $this->__('Download'),
43
  'class' => 'download',
44
  'onclick' => "setLocation('{$this->getUrl('*/*/download', array('_current' => true))}')",
45
  ));
46
  }
 
47
  }
48
 
49
+ /**
50
+ * @return string
51
+ */
52
  public function getHeaderText()
53
  {
54
  $template = Mage::registry('current_template');
55
  if ($template->getId()) {
56
+ return $this->escapeHtml($template->getName());
57
+ } else {
 
58
  return $this->__('New Template');
59
  }
60
  }
61
 
62
+ /**
63
+ * @return string
64
+ */
65
  public function getValidationUrl()
66
  {
67
  return $this->getUrl('*/*/validate', array('_current'=>true));
68
  }
69
+
70
+ /**
71
+ * @return Mage_Core_Block_Abstract
72
+ */
73
  protected function _prepareLayout()
74
  {
75
+ $this->_addButton('save_and_continue', array(
76
  'label' => $this->__('Save And Continue Edit'),
77
  'onclick' => 'editForm.submit(\''.$this->_getSaveAndContinueUrl().'\')',
78
  'class' => 'save'
79
  ), 10);
80
 
81
+ return parent::_prepareLayout();
82
  }
83
+
 
84
  /**
85
  * Get form action URL
86
  *
93
  }
94
  return $this->getUrl('*/*/save');
95
  }
96
+
97
+ /**
98
+ * @return string
99
+ */
100
  protected function _getSaveAndContinueUrl()
101
  {
102
+ return $this->getUrl('*/*/save', array(
103
  '_current' => true,
104
  'back' => 'edit'
105
  ));
app/code/community/Mzax/Emarketing/Block/Template/Edit/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,53 +17,51 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Template_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
 
 
24
  protected function _prepareForm()
25
  {
26
  $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
27
  $form->setHtmlIdPrefix("template");
28
  $form->setFieldNameSuffix("template");
29
-
30
-
31
-
32
-
33
-
34
  /* @var $template Mzax_Emarketing_Model_Template */
35
  $template = Mage::registry('current_template');
36
-
37
-
38
- if($template->getId()) {
39
  $form->addField('template_id', 'hidden', array(
40
  'name' => 'template_id',
41
  'value' => $template->getId()
42
  ));
43
  }
44
 
45
-
46
  $fieldset = $form->addFieldset('base_fieldset', array(
47
  'legend' => $this->__('Template Option'),
48
  'class' => 'fieldset-wide',
49
  ))
50
  ->addType('editor', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_templateEditor'))
51
  ->addType('credits', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_credits'));
52
-
53
 
54
-
55
  $fieldset->addField('credits', 'credits', array(
56
  'name' => 'credits',
57
  'required' => true
58
  ));
59
-
60
-
61
  $fieldset->addField('name', 'text', array(
62
  'name' => 'name',
63
  'required' => true,
64
  'label' => $this->__('Template Name'),
65
  'title' => $this->__('Template Name'),
66
  ));
67
-
68
  $fieldset->addField('description', 'textarea', array(
69
  'name' => 'description',
70
  'required' => true,
@@ -73,20 +70,17 @@ class Mzax_Emarketing_Block_Template_Edit_Form extends Mage_Adminhtml_Block_Widg
73
  'style' => 'height:4em;',
74
  'note' => "For internal use only",
75
  ));
76
-
77
-
78
-
79
  $snippets = new Mzax_Emarketing_Model_Medium_Email_Snippets;
80
  Mage::getSingleton('mzax_emarketing/medium_email')->prepareSnippets($snippets);
81
-
82
-
83
  $editorConfig = new Varien_Object();
84
  $editorConfig->setFilesBrowserWindowUrl($this->getUrl('adminhtml/cms_wysiwyg_images/index'));
85
  $editorConfig->setWidgetWindowUrl($this->getUrl('adminhtml/widget/index'));
86
  $editorConfig->setSnippets($snippets);
87
-
88
-
89
-
90
  $editor = $fieldset->addField('body', 'editor', array(
91
  'name' => 'body',
92
  'required' => true,
@@ -98,18 +92,16 @@ class Mzax_Emarketing_Block_Template_Edit_Form extends Mage_Adminhtml_Block_Widg
98
  'value' => '',
99
  'config' => $editorConfig
100
  ));
101
-
102
  // Setting custom renderer for content field to remove label column
103
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
104
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
105
  $editor->setRenderer($renderer);
106
-
107
-
108
-
109
-
110
  $form->addValues($template->getData());
111
  $this->setForm($form);
112
  $form->setUseContainer(true);
 
113
  return parent::_prepareForm();
114
  }
115
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Template_Edit_Form
22
+ */
23
  class Mzax_Emarketing_Block_Template_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
28
  protected function _prepareForm()
29
  {
30
  $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
31
  $form->setHtmlIdPrefix("template");
32
  $form->setFieldNameSuffix("template");
33
+
 
 
 
 
34
  /* @var $template Mzax_Emarketing_Model_Template */
35
  $template = Mage::registry('current_template');
36
+
37
+ if ($template->getId()) {
 
38
  $form->addField('template_id', 'hidden', array(
39
  'name' => 'template_id',
40
  'value' => $template->getId()
41
  ));
42
  }
43
 
44
+
45
  $fieldset = $form->addFieldset('base_fieldset', array(
46
  'legend' => $this->__('Template Option'),
47
  'class' => 'fieldset-wide',
48
  ))
49
  ->addType('editor', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_templateEditor'))
50
  ->addType('credits', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_credits'));
 
51
 
 
52
  $fieldset->addField('credits', 'credits', array(
53
  'name' => 'credits',
54
  'required' => true
55
  ));
56
+
57
+
58
  $fieldset->addField('name', 'text', array(
59
  'name' => 'name',
60
  'required' => true,
61
  'label' => $this->__('Template Name'),
62
  'title' => $this->__('Template Name'),
63
  ));
64
+
65
  $fieldset->addField('description', 'textarea', array(
66
  'name' => 'description',
67
  'required' => true,
70
  'style' => 'height:4em;',
71
  'note' => "For internal use only",
72
  ));
73
+
74
+
 
75
  $snippets = new Mzax_Emarketing_Model_Medium_Email_Snippets;
76
  Mage::getSingleton('mzax_emarketing/medium_email')->prepareSnippets($snippets);
77
+
78
+
79
  $editorConfig = new Varien_Object();
80
  $editorConfig->setFilesBrowserWindowUrl($this->getUrl('adminhtml/cms_wysiwyg_images/index'));
81
  $editorConfig->setWidgetWindowUrl($this->getUrl('adminhtml/widget/index'));
82
  $editorConfig->setSnippets($snippets);
83
+
 
 
84
  $editor = $fieldset->addField('body', 'editor', array(
85
  'name' => 'body',
86
  'required' => true,
92
  'value' => '',
93
  'config' => $editorConfig
94
  ));
95
+
96
  // Setting custom renderer for content field to remove label column
97
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
98
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
99
  $editor->setRenderer($renderer);
100
+
 
 
 
101
  $form->addValues($template->getData());
102
  $this->setForm($form);
103
  $form->setUseContainer(true);
104
+
105
  return parent::_prepareForm();
106
  }
107
  }
app/code/community/Mzax/Emarketing/Block/Template/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,29 +17,39 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Template_Grid extends Mage_Adminhtml_Block_Widget_Grid
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
  parent::__construct();
 
27
  $this->setId('template_grid');
28
  $this->setUseAjax(true);
29
  $this->setSaveParametersInSession(true);
30
  $this->setDefaultSort('template_id');
31
  }
32
 
33
-
 
 
34
  protected function _prepareCollection()
35
  {
36
  /* @var $collection Mzax_Emarketing_Model_Resource_Template_Collection */
37
  $collection = Mage::getResourceModel('mzax_emarketing/template_collection');
38
  $this->setCollection($collection);
39
-
40
  return parent::_prepareCollection();
41
  }
42
-
43
-
 
 
44
  protected function _prepareColumns()
45
  {
46
  $this->addColumn('created_at', array(
@@ -49,34 +58,45 @@ class Mzax_Emarketing_Block_Template_Grid extends Mage_Adminhtml_Block_Widget_Gr
49
  'gmtoffset' => true,
50
  'type' =>'datetime'
51
  ));
52
-
53
  $this->addColumn('updated_at', array(
54
  'header' => $this->__('Updated At'),
55
  'index' =>'created_at',
56
  'gmtoffset' => true,
57
  'type' =>'datetime'
58
  ));
59
-
60
  $this->addColumn('name', array(
61
  'header' => $this->__('Name'),
62
  'index' => 'name',
63
  ));
64
 
 
65
 
66
- return parent::_prepareColumns();
67
  }
68
 
69
-
 
 
70
  protected function _prepareMassaction()
71
  {
72
  return $this;
73
  }
74
 
 
 
 
75
  public function getGridUrl()
76
  {
77
  return $this->getUrl('*/*/grid', array('_current'=> true));
78
  }
79
 
 
 
 
 
 
80
  public function getRowUrl($row)
81
  {
82
  return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Template_Grid
22
+ */
23
  class Mzax_Emarketing_Block_Template_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Template_Grid constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('template_grid');
33
  $this->setUseAjax(true);
34
  $this->setSaveParametersInSession(true);
35
  $this->setDefaultSort('template_id');
36
  }
37
 
38
+ /**
39
+ * @return Mage_Adminhtml_Block_Widget_Grid
40
+ */
41
  protected function _prepareCollection()
42
  {
43
  /* @var $collection Mzax_Emarketing_Model_Resource_Template_Collection */
44
  $collection = Mage::getResourceModel('mzax_emarketing/template_collection');
45
  $this->setCollection($collection);
46
+
47
  return parent::_prepareCollection();
48
  }
49
+
50
+ /**
51
+ * @return $this
52
+ */
53
  protected function _prepareColumns()
54
  {
55
  $this->addColumn('created_at', array(
58
  'gmtoffset' => true,
59
  'type' =>'datetime'
60
  ));
61
+
62
  $this->addColumn('updated_at', array(
63
  'header' => $this->__('Updated At'),
64
  'index' =>'created_at',
65
  'gmtoffset' => true,
66
  'type' =>'datetime'
67
  ));
68
+
69
  $this->addColumn('name', array(
70
  'header' => $this->__('Name'),
71
  'index' => 'name',
72
  ));
73
 
74
+ parent::_prepareColumns();
75
 
76
+ return $this;
77
  }
78
 
79
+ /**
80
+ * @return $this
81
+ */
82
  protected function _prepareMassaction()
83
  {
84
  return $this;
85
  }
86
 
87
+ /**
88
+ * @return string
89
+ */
90
  public function getGridUrl()
91
  {
92
  return $this->getUrl('*/*/grid', array('_current'=> true));
93
  }
94
 
95
+ /**
96
+ * @param $row
97
+ *
98
+ * @return string
99
+ */
100
  public function getRowUrl($row)
101
  {
102
  return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
app/code/community/Mzax/Emarketing/Block/Template/Upload.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,12 +17,18 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Template_Upload extends Mage_Adminhtml_Block_Widget_Form_Container
22
  {
 
 
 
23
  public function __construct()
24
  {
25
  $this->_objectId = 'id';
26
-
27
  $this->_blockGroup = 'mzax_emarketing';
28
  $this->_controller = 'template';
29
  $this->_mode = 'upload';
@@ -32,19 +37,16 @@ class Mzax_Emarketing_Block_Template_Upload extends Mage_Adminhtml_Block_Widget_
32
 
33
  $this->_updateButton('save', 'label', $this->__('Upload Template'));
34
  $this->removeButton('delete');
35
-
36
  }
37
 
38
-
39
-
40
-
41
  public function getHeaderText()
42
  {
43
  return $this->__('Upload New Template');
44
  }
45
 
46
-
47
-
48
  /**
49
  * Get form action URL
50
  *
@@ -54,6 +56,4 @@ class Mzax_Emarketing_Block_Template_Upload extends Mage_Adminhtml_Block_Widget_
54
  {
55
  return $this->getUrl('*/*/uploadPost');
56
  }
57
-
58
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Template_Upload
22
+ */
23
  class Mzax_Emarketing_Block_Template_Upload extends Mage_Adminhtml_Block_Widget_Form_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Template_Upload constructor.
27
+ */
28
  public function __construct()
29
  {
30
  $this->_objectId = 'id';
31
+
32
  $this->_blockGroup = 'mzax_emarketing';
33
  $this->_controller = 'template';
34
  $this->_mode = 'upload';
37
 
38
  $this->_updateButton('save', 'label', $this->__('Upload Template'));
39
  $this->removeButton('delete');
 
40
  }
41
 
42
+ /**
43
+ * @return string
44
+ */
45
  public function getHeaderText()
46
  {
47
  return $this->__('Upload New Template');
48
  }
49
 
 
 
50
  /**
51
  * Get form action URL
52
  *
56
  {
57
  return $this->getUrl('*/*/uploadPost');
58
  }
 
 
59
  }
app/code/community/Mzax/Emarketing/Block/Template/Upload/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,32 +17,42 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Template_Upload_Form extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
 
 
24
  protected function _prepareForm()
25
  {
26
- $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data'));
 
 
 
 
 
 
 
27
  $form->setHtmlIdPrefix("template");
28
  $form->setFieldNameSuffix("template");
29
-
30
-
31
  $fieldset = $form->addFieldset('base_fieldset', array(
32
  'legend' => $this->__('Template'),
33
  'class' => 'fieldset-wide',
34
  ));
35
-
36
-
37
  $fieldset->addField('template', 'file', array(
38
  'name' => 'file',
39
  'required' => true,
40
  'label' => $this->__('Template File'),
41
  'title' => $this->__('Template File'),
42
  ));
43
-
44
-
45
  $this->setForm($form);
46
  $form->setUseContainer(true);
 
47
  return parent::_prepareForm();
48
  }
49
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Template_Upload_Form
22
+ */
23
  class Mzax_Emarketing_Block_Template_Upload_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
28
  protected function _prepareForm()
29
  {
30
+ $form = new Varien_Data_Form(
31
+ array(
32
+ 'id' => 'edit_form',
33
+ 'action' => $this->getData('action'),
34
+ 'method' => 'post',
35
+ 'enctype' => 'multipart/form-data'
36
+ )
37
+ );
38
  $form->setHtmlIdPrefix("template");
39
  $form->setFieldNameSuffix("template");
40
+
 
41
  $fieldset = $form->addFieldset('base_fieldset', array(
42
  'legend' => $this->__('Template'),
43
  'class' => 'fieldset-wide',
44
  ));
45
+
 
46
  $fieldset->addField('template', 'file', array(
47
  'name' => 'file',
48
  'required' => true,
49
  'label' => $this->__('Template File'),
50
  'title' => $this->__('Template File'),
51
  ));
52
+
 
53
  $this->setForm($form);
54
  $form->setUseContainer(true);
55
+
56
  return parent::_prepareForm();
57
  }
58
  }
app/code/community/Mzax/Emarketing/Block/Template/View.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,25 +17,27 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Template_View extends Mage_Adminhtml_Block_Widget_Grid_Container
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
- $this->_blockGroup = 'mzax_emarketing';
27
  $this->_controller = 'template';
28
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Templates');
29
  $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Template');
30
-
31
  $this->_addButton('upload', array(
32
  'label' => $this->__('Upload'),
33
  'class' => 'upload',
34
  'onclick' => "setLocation('{$this->getUrl('*/*/upload')}')",
35
  ));
36
-
37
  parent::__construct();
38
  }
39
-
40
-
41
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Template_View
22
+ */
23
  class Mzax_Emarketing_Block_Template_View extends Mage_Adminhtml_Block_Widget_Grid_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Template_View constructor.
27
+ */
28
  public function __construct()
29
  {
30
+ $this->_blockGroup = 'mzax_emarketing';
31
  $this->_controller = 'template';
32
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Templates');
33
  $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Template');
34
+
35
  $this->_addButton('upload', array(
36
  'label' => $this->__('Upload'),
37
  'class' => 'upload',
38
  'onclick' => "setLocation('{$this->getUrl('*/*/upload')}')",
39
  ));
40
+
41
  parent::__construct();
42
  }
 
 
 
43
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,76 +18,75 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Block_Tracker_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
29
  {
 
 
 
30
  public function __construct()
31
  {
32
  $this->_objectId = 'id';
33
-
34
  $this->_blockGroup = 'mzax_emarketing';
35
  $this->_controller = 'tracker';
36
 
37
-
38
  parent::__construct();
39
 
40
  $this->_updateButton('save', 'label', $this->__('Save Tracker'));
41
  $this->_updateButton('delete', 'label', $this->__('Delete Tracker'));
42
  }
43
 
44
-
45
-
 
46
  public function getHeaderText()
47
  {
48
  $tracker = Mage::registry('current_tracker');
49
  if ($tracker->getId()) {
50
  $title = $this->htmlEscape($tracker->getTitle());
51
- if($tracker->isDefault()) {
52
  return $title . ' <sup>' . $this->__('[Default]') . '</sup>';
53
  }
54
  return $title;
55
- }
56
- else {
57
  return $this->__('New Conversion Tracker');
58
  }
59
  }
60
 
 
 
 
61
  public function getValidationUrl()
62
  {
63
  return $this->getUrl('*/*/validate', array('_current'=>true));
64
  }
65
-
66
-
67
-
68
-
69
  protected function _prepareLayout()
70
  {
71
  $tracker = Mage::registry('current_tracker');
72
  if ($tracker->getId()) {
73
- $this->_addButton('save_and_continue', array(
74
  'label' => $this->__('Save And Continue Edit'),
75
  'onclick' => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
76
  'class' => 'save'
77
  ), 10);
78
-
79
- if($tracker->isDefault()) {
80
- $this->_removeButton('delete');
81
- }
82
- }
83
- else {
84
  $this->_removeButton('save');
85
  $this->_removeButton('reset');
86
  }
87
 
88
- return parent::_prepareLayout();
89
  }
90
-
91
-
92
  /**
93
  * Get form action URL
94
  *
@@ -101,16 +99,19 @@ class Mzax_Emarketing_Block_Tracker_Edit extends Mage_Adminhtml_Block_Widget_For
101
  }
102
  return $this->getUrl('*/*/save');
103
  }
104
-
105
-
106
-
107
-
108
  protected function _getSaveAndContinueUrl()
109
  {
110
- return $this->getUrl('*/*/save', array(
111
- '_current' => true,
112
- 'back' => 'edit',
113
- 'tab' => '{{tab_id}}'
114
- ));
 
 
 
115
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Tracker_Edit constructor.
27
+ */
28
  public function __construct()
29
  {
30
  $this->_objectId = 'id';
31
+
32
  $this->_blockGroup = 'mzax_emarketing';
33
  $this->_controller = 'tracker';
34
 
 
35
  parent::__construct();
36
 
37
  $this->_updateButton('save', 'label', $this->__('Save Tracker'));
38
  $this->_updateButton('delete', 'label', $this->__('Delete Tracker'));
39
  }
40
 
41
+ /**
42
+ * @return string
43
+ */
44
  public function getHeaderText()
45
  {
46
  $tracker = Mage::registry('current_tracker');
47
  if ($tracker->getId()) {
48
  $title = $this->htmlEscape($tracker->getTitle());
49
+ if ($tracker->isDefault()) {
50
  return $title . ' <sup>' . $this->__('[Default]') . '</sup>';
51
  }
52
  return $title;
53
+ } else {
 
54
  return $this->__('New Conversion Tracker');
55
  }
56
  }
57
 
58
+ /**
59
+ * @return string
60
+ */
61
  public function getValidationUrl()
62
  {
63
  return $this->getUrl('*/*/validate', array('_current'=>true));
64
  }
65
+
66
+ /**
67
+ * @return Mage_Core_Block_Abstract
68
+ */
69
  protected function _prepareLayout()
70
  {
71
  $tracker = Mage::registry('current_tracker');
72
  if ($tracker->getId()) {
73
+ $this->_addButton('save_and_continue', array(
74
  'label' => $this->__('Save And Continue Edit'),
75
  'onclick' => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
76
  'class' => 'save'
77
  ), 10);
78
+
79
+ if ($tracker->isDefault()) {
80
+ $this->_removeButton('delete');
81
+ }
82
+ } else {
 
83
  $this->_removeButton('save');
84
  $this->_removeButton('reset');
85
  }
86
 
87
+ return parent::_prepareLayout();
88
  }
89
+
 
90
  /**
91
  * Get form action URL
92
  *
99
  }
100
  return $this->getUrl('*/*/save');
101
  }
102
+
103
+ /**
104
+ * @return string
105
+ */
106
  protected function _getSaveAndContinueUrl()
107
  {
108
+ return $this->getUrl(
109
+ '*/*/save',
110
+ array(
111
+ '_current' => true,
112
+ 'back' => 'edit',
113
+ 'tab' => '{{tab_id}}'
114
+ )
115
+ );
116
  }
117
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,12 +17,19 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Tracker_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
 
 
24
  protected function _prepareForm()
25
  {
26
- $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
 
 
27
 
28
  $tracker = Mage::registry('current_tracker');
29
 
@@ -33,9 +39,10 @@ class Mzax_Emarketing_Block_Tracker_Edit_Form extends Mage_Adminhtml_Block_Widge
33
  'value' => $tracker->getId()
34
  ));
35
  }
36
-
37
  $form->setUseContainer(true);
38
  $this->setForm($form);
 
39
  return parent::_prepareForm();
40
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit_Form
22
+ */
23
  class Mzax_Emarketing_Block_Tracker_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
28
  protected function _prepareForm()
29
  {
30
+ $form = new Varien_Data_Form(
31
+ array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')
32
+ );
33
 
34
  $tracker = Mage::registry('current_tracker');
35
 
39
  'value' => $tracker->getId()
40
  ));
41
  }
42
+
43
  $form->setUseContainer(true);
44
  $this->setForm($form);
45
+
46
  return parent::_prepareForm();
47
  }
48
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Conditions.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,20 +17,22 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Conditions extends Mage_Adminhtml_Block_Widget_Form
22
  {
23
-
24
-
 
25
  public function initForm()
26
  {
27
  $form = new Varien_Data_Form();
28
  $form->setHtmlIdPrefix('_mzax_emarketing');
29
  $form->setFieldNameSuffix('mzax_emarketing');
30
 
31
-
32
  $tracker = Mage::registry('current_tracker');
33
-
34
-
35
  $form->setHtmlIdPrefix('conditions_');
36
 
37
  $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
@@ -42,21 +43,15 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Conditions extends Mage_Adminhtml_B
42
  $fieldset = $form->addFieldset('conditions_fieldset', array(
43
  'legend'=>Mage::helper('salesrule')->__('Only track conversion goals matching the conditions below')
44
  ))->setRenderer($renderer);
45
-
46
-
47
-
48
- $fieldset->addField('conditions', 'text', array(
49
  'name' => 'conditions',
50
  'label' => $this->__('Conditions'),
51
  'title' => $this->__('Conditions'),
52
- ))->setTracker($tracker)
53
- ->setRenderer(Mage::getBlockSingleton('mzax_emarketing/conditions'));
54
-
55
  $this->setForm($form);
56
-
57
  return $this;
58
  }
59
-
60
-
61
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit_Tab_Conditions
22
+ */
23
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Conditions extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return $this
27
+ */
28
  public function initForm()
29
  {
30
  $form = new Varien_Data_Form();
31
  $form->setHtmlIdPrefix('_mzax_emarketing');
32
  $form->setFieldNameSuffix('mzax_emarketing');
33
 
 
34
  $tracker = Mage::registry('current_tracker');
35
+
 
36
  $form->setHtmlIdPrefix('conditions_');
37
 
38
  $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
43
  $fieldset = $form->addFieldset('conditions_fieldset', array(
44
  'legend'=>Mage::helper('salesrule')->__('Only track conversion goals matching the conditions below')
45
  ))->setRenderer($renderer);
46
+
47
+ $fieldset->addField('conditions', 'text', array(
 
 
48
  'name' => 'conditions',
49
  'label' => $this->__('Conditions'),
50
  'title' => $this->__('Conditions'),
51
+ ))->setTracker($tracker)->setRenderer(Mage::getBlockSingleton('mzax_emarketing/conditions'));
52
+
 
53
  $this->setForm($form);
54
+
55
  return $this;
56
  }
 
 
 
57
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/GoalType.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,24 +18,18 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_GoalType extends Mage_Adminhtml_Block_Widget_Form
29
  {
30
-
31
- protected function _prepareLayout()
32
- {
33
- parent::_prepareLayout();
34
- }
35
-
36
-
37
-
38
  public function initForm()
39
  {
 
 
 
40
  $form = new Varien_Data_Form();
41
  $form->setHtmlIdPrefix('tracker_');
42
  $form->setFieldNameSuffix('tracker');
@@ -44,10 +37,9 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_GoalType extends Mage_Adminhtml_Blo
44
  /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
45
  $tracker = Mage::registry('current_tracker');
46
 
47
-
48
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
49
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
50
-
51
  /**
52
  * Tracker
53
  */
@@ -57,47 +49,41 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_GoalType extends Mage_Adminhtml_Blo
57
  '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'),
58
  'continue' => !$tracker->getId()
59
  ));
60
-
61
  $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
62
  $fieldset->addType('wildselect', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_wildselect'));
63
-
64
-
65
-
66
  $offerRenderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
67
  ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
68
  $fieldset->setRenderer($offerRenderer);
69
-
70
-
71
  $fieldset->addField('info', 'info', array(
72
  'text' => $this->__('First you must decide what conversion goals this tracker should use as this will drive what filters are available.')
73
  ))->setRenderer($renderer);
74
-
75
-
76
-
77
- $fieldset->addField('title','text', array(
78
  'name' => 'title',
79
- 'required' => true,
80
  'label' => $this->__('Title'),
81
  'title' => $this->__('Title'),
82
  ));
83
-
84
-
85
  // @todo disable if it has reci
86
- $fieldset->addField('goal_type','select', array(
87
  'name' => 'goal_type',
88
  'label' => $this->__('What goals to track?'),
89
- 'values' => Mage::getSingleton('mzax_emarketing/conversion_goal')->getAllOptions(false),
90
  'note' => $this->__("What conversion goal would you like to track"),
91
- 'required' => true
92
  ));
93
-
94
-
95
-
96
  $form->addValues($tracker->getData());
97
  $this->setForm($form);
98
-
99
- return $this;
100
-
101
 
 
102
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit_Tab_GoalType
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_GoalType extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return $this
27
+ */
 
 
 
 
 
28
  public function initForm()
29
  {
30
+ /** @var Mzax_Emarketing_Model_Conversion_Goal $goal */
31
+ $goal = Mage::getSingleton('mzax_emarketing/conversion_goal');
32
+
33
  $form = new Varien_Data_Form();
34
  $form->setHtmlIdPrefix('tracker_');
35
  $form->setFieldNameSuffix('tracker');
37
  /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
38
  $tracker = Mage::registry('current_tracker');
39
 
 
40
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
41
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
42
+
43
  /**
44
  * Tracker
45
  */
49
  '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'),
50
  'continue' => !$tracker->getId()
51
  ));
52
+
53
  $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
54
  $fieldset->addType('wildselect', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_wildselect'));
55
+
56
+
 
57
  $offerRenderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
58
  ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
59
  $fieldset->setRenderer($offerRenderer);
60
+
61
+
62
  $fieldset->addField('info', 'info', array(
63
  'text' => $this->__('First you must decide what conversion goals this tracker should use as this will drive what filters are available.')
64
  ))->setRenderer($renderer);
65
+
66
+
67
+ $fieldset->addField('title', 'text', array(
 
68
  'name' => 'title',
69
+ 'required' => true,
70
  'label' => $this->__('Title'),
71
  'title' => $this->__('Title'),
72
  ));
73
+
74
+
75
  // @todo disable if it has reci
76
+ $fieldset->addField('goal_type', 'select', array(
77
  'name' => 'goal_type',
78
  'label' => $this->__('What goals to track?'),
79
+ 'values' => $goal->getAllOptions(false),
80
  'note' => $this->__("What conversion goal would you like to track"),
81
+ 'required' => true
82
  ));
83
+
 
 
84
  $form->addValues($tracker->getData());
85
  $this->setForm($form);
 
 
 
86
 
87
+ return $this;
88
  }
89
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Settings.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,23 +18,13 @@
19
 
20
 
21
  /**
22
- * Default tracker settings tab
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
29
  {
30
-
31
-
32
- protected function _prepareLayout()
33
- {
34
- parent::_prepareLayout();
35
- }
36
-
37
-
38
-
39
  public function initForm()
40
  {
41
  $form = new Varien_Data_Form();
@@ -45,10 +34,10 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Blo
45
  /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
46
  $tracker = Mage::registry('current_tracker');
47
 
48
-
49
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
50
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
51
-
52
  /**
53
  * Tracker
54
  */
@@ -58,61 +47,54 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Blo
58
  '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'),
59
  'continue' => !$tracker->getId()
60
  ));
61
-
62
- $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
63
  $fieldset->addType('wildselect', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_wildselect'));
64
- $fieldset->addType('textarea', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_textarea'));
65
-
66
-
67
  $offerRenderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
68
  ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
69
  $fieldset->setRenderer($offerRenderer);
70
-
71
-
72
-
73
-
74
  $fieldset->addField('info', 'info', array(
75
  '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.')
76
  ))->setRenderer($renderer);
77
-
78
-
79
-
80
 
81
- $fieldset->addField('title','text', array(
 
82
  'name' => 'title',
83
- 'required' => true,
84
  'label' => $this->__('Title'),
85
  'title' => $this->__('Title')
86
  ));
87
-
88
-
89
- if(!$tracker->getId()) {
90
- $fieldset->addField('goal_type','hidden', array(
91
  'name' => 'goal_type'
92
  ));
93
- }
94
- else {
95
- $fieldset->addField('goal_type','select', array(
96
  'name' => 'goal_type',
97
  'label' => $this->__('Goals'),
98
  'values' => Mage::getSingleton('mzax_emarketing/conversion_goal')->getAllOptions(false),
99
- 'note' => $tracker->hasFilters()
100
  ? $this->__("You can not change this value if you have any filters defined")
101
  : false,
102
- 'required' => true,
103
  'disabled' => $tracker->hasFilters()
104
  ));
105
  }
106
-
107
-
108
  $fieldset->addField('is_active', 'select', array(
109
  'label' => $this->__('Enabled'),
110
  'title' => $this->__('Enabled'),
111
  'name' => 'is_active',
112
  'required' => true,
113
  'disabled' => $tracker->isDefault(),
114
- 'note' => $tracker->isDefault()
115
- ? $this->__('You can not disable the default tracker.')
116
  : '',
117
  'options' => array(
118
  '1' => $this->__('Yes'),
@@ -120,8 +102,8 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Blo
120
  ),
121
  'value' => '1'
122
  ));
123
-
124
-
125
  $fieldset->addField('description', 'textarea', array(
126
  'label' => $this->__('Description'),
127
  'title' => $this->__('Description'),
@@ -129,14 +111,14 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Blo
129
  'name' => 'description',
130
  'style' => 'height:4em;',
131
  ));
132
-
133
-
134
  /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
135
  $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
136
  $campaigns->addArchiveFilter(false);
137
-
138
-
139
- if($tracker->isDefault()) {
140
  $fieldset->addField('is_default', 'checkbox', array(
141
  'label' => $this->__('Track Campaigns'),
142
  'title' => $this->__('Track Campaigns'),
@@ -146,10 +128,9 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Blo
146
  'name' => 'is_default',
147
  'after_element_html' => '<label>'.$this->__('Always track all campaigns').'</label>'
148
  ));
149
- }
150
- else {
151
  $campaignOptions = $campaigns->toOptionArray();
152
-
153
  $fieldset->addField('campaign_ids', 'wildselect', array(
154
  'label' => $this->__('Track Campaigns'),
155
  'title' => $this->__('Track Campaigns'),
@@ -158,10 +139,10 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Blo
158
  'values' => $campaignOptions
159
  ));
160
  }
161
-
162
  $form->addValues($tracker->getData());
163
  $this->setForm($form);
164
-
165
  return $this;
166
  }
167
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return $this
27
+ */
 
 
 
 
 
 
28
  public function initForm()
29
  {
30
  $form = new Varien_Data_Form();
34
  /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
35
  $tracker = Mage::registry('current_tracker');
36
 
37
+
38
  $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
39
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
40
+
41
  /**
42
  * Tracker
43
  */
47
  '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'),
48
  'continue' => !$tracker->getId()
49
  ));
50
+
51
+ $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
52
  $fieldset->addType('wildselect', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_wildselect'));
53
+ $fieldset->addType('textarea', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_textarea'));
54
+
 
55
  $offerRenderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
56
  ->setTemplate('mzax/emarketing/campaign/fieldset-offer.phtml');
57
  $fieldset->setRenderer($offerRenderer);
58
+
59
+
 
 
60
  $fieldset->addField('info', 'info', array(
61
  '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.')
62
  ))->setRenderer($renderer);
 
 
 
63
 
64
+
65
+ $fieldset->addField('title', 'text', array(
66
  'name' => 'title',
67
+ 'required' => true,
68
  'label' => $this->__('Title'),
69
  'title' => $this->__('Title')
70
  ));
71
+
72
+
73
+ if (!$tracker->getId()) {
74
+ $fieldset->addField('goal_type', 'hidden', array(
75
  'name' => 'goal_type'
76
  ));
77
+ } else {
78
+ $fieldset->addField('goal_type', 'select', array(
 
79
  'name' => 'goal_type',
80
  'label' => $this->__('Goals'),
81
  'values' => Mage::getSingleton('mzax_emarketing/conversion_goal')->getAllOptions(false),
82
+ 'note' => $tracker->hasFilters()
83
  ? $this->__("You can not change this value if you have any filters defined")
84
  : false,
85
+ 'required' => true,
86
  'disabled' => $tracker->hasFilters()
87
  ));
88
  }
89
+
 
90
  $fieldset->addField('is_active', 'select', array(
91
  'label' => $this->__('Enabled'),
92
  'title' => $this->__('Enabled'),
93
  'name' => 'is_active',
94
  'required' => true,
95
  'disabled' => $tracker->isDefault(),
96
+ 'note' => $tracker->isDefault()
97
+ ? $this->__('You can not disable the default tracker.')
98
  : '',
99
  'options' => array(
100
  '1' => $this->__('Yes'),
102
  ),
103
  'value' => '1'
104
  ));
105
+
106
+
107
  $fieldset->addField('description', 'textarea', array(
108
  'label' => $this->__('Description'),
109
  'title' => $this->__('Description'),
111
  'name' => 'description',
112
  'style' => 'height:4em;',
113
  ));
114
+
115
+
116
  /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
117
  $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
118
  $campaigns->addArchiveFilter(false);
119
+
120
+
121
+ if ($tracker->isDefault()) {
122
  $fieldset->addField('is_default', 'checkbox', array(
123
  'label' => $this->__('Track Campaigns'),
124
  'title' => $this->__('Track Campaigns'),
128
  'name' => 'is_default',
129
  'after_element_html' => '<label>'.$this->__('Always track all campaigns').'</label>'
130
  ));
131
+ } else {
 
132
  $campaignOptions = $campaigns->toOptionArray();
133
+
134
  $fieldset->addField('campaign_ids', 'wildselect', array(
135
  'label' => $this->__('Track Campaigns'),
136
  'title' => $this->__('Track Campaigns'),
139
  'values' => $campaignOptions
140
  ));
141
  }
142
+
143
  $form->addValues($tracker->getData());
144
  $this->setForm($form);
145
+
146
  return $this;
147
  }
148
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Tasks.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,48 +18,41 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Tasks extends Mage_Adminhtml_Block_Template
30
  {
31
-
 
 
32
  protected function _prepareLayout()
33
  {
34
  parent::_prepareLayout();
 
35
  $this->setTemplate('mzax/emarketing/tracker/tasks.phtml');
36
  }
37
 
38
-
39
  /**
40
  * Retrieve Current Tracker
41
- *
42
  * @return Mzax_Emarketing_Model_Conversion_Tracker
43
  */
44
  public function getTracker()
45
  {
46
  return Mage::registry('current_tracker');
47
  }
48
-
49
-
50
-
51
  /**
52
- * (non-PHPdoc)
53
- * @see Mage_Core_Block_Abstract::getUrl()
 
 
54
  */
55
  public function getUrl($route = '', $params = array())
56
  {
57
- if(!isset($params['_tracker'])) {
58
  $params['id'] = $this->getTracker()->getId();
59
  }
60
  return parent::getUrl($route, $params);
61
  }
62
-
63
-
64
-
65
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit_Tab_Tasks
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Tasks extends Mage_Adminhtml_Block_Template
24
  {
25
+ /**
26
+ * @return void
27
+ */
28
  protected function _prepareLayout()
29
  {
30
  parent::_prepareLayout();
31
+
32
  $this->setTemplate('mzax/emarketing/tracker/tasks.phtml');
33
  }
34
 
 
35
  /**
36
  * Retrieve Current Tracker
37
+ *
38
  * @return Mzax_Emarketing_Model_Conversion_Tracker
39
  */
40
  public function getTracker()
41
  {
42
  return Mage::registry('current_tracker');
43
  }
44
+
 
 
45
  /**
46
+ * @param string $route
47
+ * @param array $params
48
+ *
49
+ * @return string
50
  */
51
  public function getUrl($route = '', $params = array())
52
  {
53
+ if (!isset($params['_tracker'])) {
54
  $params['id'] = $this->getTracker()->getId();
55
  }
56
  return parent::getUrl($route, $params);
57
  }
 
 
 
 
58
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tab/Test.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,10 +17,11 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
22
  {
23
-
24
-
25
  /**
26
  * Retrieve filter
27
  *
@@ -33,16 +33,13 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Test extends Mzax_Emarketing_Block_
33
  $tracker = Mage::registry('current_tracker');
34
  return $tracker->getGoal();
35
  }
36
-
37
-
38
-
39
-
40
-
41
  /**
42
  * Generate url by route and parameters
43
  *
44
  * @param string $route
45
  * @param array $params
 
46
  * @return string
47
  */
48
  public function getUrl($route = '', $params = array())
@@ -50,10 +47,7 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Test extends Mzax_Emarketing_Block_
50
  $params['tracker'] = $this->getCampaign()->getId();
51
  return parent::getUrl($route, $params);
52
  }
53
-
54
-
55
-
56
-
57
  /**
58
  * Retrieve current campaign
59
  *
@@ -63,8 +57,4 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tab_Test extends Mzax_Emarketing_Block_
63
  {
64
  return Mage::registry('current_tracker');
65
  }
66
-
67
-
68
-
69
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit_Tab_Test
22
+ */
23
  class Mzax_Emarketing_Block_Tracker_Edit_Tab_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
24
  {
 
 
25
  /**
26
  * Retrieve filter
27
  *
33
  $tracker = Mage::registry('current_tracker');
34
  return $tracker->getGoal();
35
  }
36
+
 
 
 
 
37
  /**
38
  * Generate url by route and parameters
39
  *
40
  * @param string $route
41
  * @param array $params
42
+ *
43
  * @return string
44
  */
45
  public function getUrl($route = '', $params = array())
47
  $params['tracker'] = $this->getCampaign()->getId();
48
  return parent::getUrl($route, $params);
49
  }
50
+
 
 
 
51
  /**
52
  * Retrieve current campaign
53
  *
57
  {
58
  return Mage::registry('current_tracker');
59
  }
 
 
 
 
60
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Edit/Tabs.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,51 +18,50 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Block_Tracker_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
29
  {
30
-
 
 
31
  public function __construct()
32
  {
33
  parent::__construct();
 
34
  $this->setId('mzax_emarketing_info_tabs');
35
  $this->setDestElementId('edit_form');
36
  $this->setTitle($this->__('Conversion Tracker'));
37
  }
38
 
 
 
 
39
  protected function _beforeToHtml()
40
  {
41
  /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
42
  $tracker = Mage::registry('current_tracker');
43
-
44
- if(!$tracker->getGoalType())
45
- {
46
  $this->addTab('goaltype', array(
47
  'label' => $this->__('Choose a goal type'),
48
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_goalType')->initForm()->toHtml(),
49
  'active' => true
50
  ));
51
- }
52
- else
53
- {
54
  $this->addTab('settings', array(
55
  'label' => $this->__('Settings'),
56
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_settings')->initForm()->toHtml(),
57
  'active' => true
58
  ));
59
-
60
  $this->addTab('conditions', array(
61
  'label' => $this->__('Conditions'),
62
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_conditions')->initForm()->toHtml(),
63
  'active' => false
64
  ));
65
-
66
- if($tracker->getId()) {
67
  $this->addTab('task', array(
68
  'label' => $this->__('Tasks'),
69
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_tasks')->toHtml(),
@@ -71,22 +69,23 @@ class Mzax_Emarketing_Block_Tracker_Edit_Tabs extends Mage_Adminhtml_Block_Widge
71
  ));
72
  }
73
  }
74
-
75
-
76
  $this->_updateActiveTab();
 
77
  return parent::_beforeToHtml();
78
  }
79
 
80
-
81
-
 
82
  protected function _updateActiveTab()
83
  {
84
- $tabId = $this->getRequest()->getParam('tab');
85
- if( $tabId ) {
86
- $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
87
- if($tabId) {
88
- $this->setActiveTab($tabId);
89
- }
90
- }
91
  }
92
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Edit_Tabs
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Tracker_Edit_Tabs constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('mzax_emarketing_info_tabs');
33
  $this->setDestElementId('edit_form');
34
  $this->setTitle($this->__('Conversion Tracker'));
35
  }
36
 
37
+ /**
38
+ * @return Mage_Core_Block_Abstract
39
+ */
40
  protected function _beforeToHtml()
41
  {
42
  /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
43
  $tracker = Mage::registry('current_tracker');
44
+
45
+ if (!$tracker->getGoalType()) {
 
46
  $this->addTab('goaltype', array(
47
  'label' => $this->__('Choose a goal type'),
48
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_goalType')->initForm()->toHtml(),
49
  'active' => true
50
  ));
51
+ } else {
 
 
52
  $this->addTab('settings', array(
53
  'label' => $this->__('Settings'),
54
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_settings')->initForm()->toHtml(),
55
  'active' => true
56
  ));
57
+
58
  $this->addTab('conditions', array(
59
  'label' => $this->__('Conditions'),
60
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_conditions')->initForm()->toHtml(),
61
  'active' => false
62
  ));
63
+
64
+ if ($tracker->getId()) {
65
  $this->addTab('task', array(
66
  'label' => $this->__('Tasks'),
67
  'content' => $this->getLayout()->createBlock('mzax_emarketing/tracker_edit_tab_tasks')->toHtml(),
69
  ));
70
  }
71
  }
72
+
 
73
  $this->_updateActiveTab();
74
+
75
  return parent::_beforeToHtml();
76
  }
77
 
78
+ /**
79
+ * @return void
80
+ */
81
  protected function _updateActiveTab()
82
  {
83
+ $tabId = $this->getRequest()->getParam('tab');
84
+ if ($tabId) {
85
+ $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
86
+ if ($tabId) {
87
+ $this->setActiveTab($tabId);
88
+ }
89
+ }
90
  }
91
+ }
app/code/community/Mzax/Emarketing/Block/Tracker/Grid.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,29 +17,41 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Grid
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
  parent::__construct();
 
27
  $this->setId('tracker_grid');
28
  $this->setUseAjax(true);
29
  $this->setSaveParametersInSession(true);
30
  $this->setDefaultSort('tracker_id');
31
  }
32
 
33
-
 
 
34
  protected function _prepareCollection()
35
  {
36
  /* @var $collection Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection */
37
  $collection = Mage::getResourceModel('mzax_emarketing/conversion_tracker_collection');
38
  $this->setCollection($collection);
39
-
40
- return parent::_prepareCollection();
 
 
41
  }
42
-
43
-
 
 
44
  protected function _prepareColumns()
45
  {
46
  $this->addColumn('updated_at', array(
@@ -49,17 +60,17 @@ class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Gri
49
  'gmtoffset' => true,
50
  'type' =>'datetime'
51
  ));
52
-
53
  $this->addColumn('title', array(
54
  'header' => $this->__('Title'),
55
  'index' => 'title',
56
  ));
57
-
58
  $this->addColumn('description', array(
59
  'header' => $this->__('Description'),
60
  'index' => 'description',
61
  ));
62
-
63
  $this->addColumn('is_active', array(
64
  'header' => Mage::helper('cms')->__('Active'),
65
  'index' => 'is_active',
@@ -70,7 +81,7 @@ class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Gri
70
  1 => $this->__('Enabled')
71
  ),
72
  ));
73
-
74
  $this->addColumn('is_aggregated', array(
75
  'header' => Mage::helper('cms')->__('Is Aggregated'),
76
  'index' => 'is_aggregated',
@@ -81,13 +92,15 @@ class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Gri
81
  1 => $this->__('Yes')
82
  ),
83
  ));
84
-
85
-
86
 
87
- return parent::_prepareColumns();
 
 
88
  }
89
 
90
-
 
 
91
  protected function _prepareMassaction()
92
  {
93
  $this->setMassactionIdField('tracker_id');
@@ -98,7 +111,7 @@ class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Gri
98
  'url' => $this->getUrl('*/*/massDelete'),
99
  'confirm' => $this->__('Are you sure?')
100
  ));
101
-
102
  $this->getMassactionBlock()->addItem('is_active', array(
103
  'label'=> $this->__('Enable/Disable'),
104
  'url' => $this->getUrl('*/*/massEnable', array('_current'=>true)),
@@ -120,21 +133,25 @@ class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Gri
120
  'confirm' => $this->__('This may take some time depending on the size of your data, would you like to continue?'),
121
  'url' => $this->getUrl('*/*/massAggregate')
122
  ));
123
-
124
-
125
-
126
  return $this;
127
  }
128
-
129
-
130
 
 
 
 
131
  public function getGridUrl()
132
  {
133
  return $this->getUrl('*/*/grid', array('_current'=> true));
134
  }
135
 
 
 
 
 
 
136
  public function getRowUrl($row)
137
  {
138
- return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
139
  }
140
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Grid
22
+ */
23
  class Mzax_Emarketing_Block_Tracker_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Tracker_Grid constructor.
27
+ */
28
  public function __construct()
29
  {
30
  parent::__construct();
31
+
32
  $this->setId('tracker_grid');
33
  $this->setUseAjax(true);
34
  $this->setSaveParametersInSession(true);
35
  $this->setDefaultSort('tracker_id');
36
  }
37
 
38
+ /**
39
+ * @return $this
40
+ */
41
  protected function _prepareCollection()
42
  {
43
  /* @var $collection Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection */
44
  $collection = Mage::getResourceModel('mzax_emarketing/conversion_tracker_collection');
45
  $this->setCollection($collection);
46
+
47
+ parent::_prepareCollection();
48
+
49
+ return $this;
50
  }
51
+
52
+ /**
53
+ * @return $this
54
+ */
55
  protected function _prepareColumns()
56
  {
57
  $this->addColumn('updated_at', array(
60
  'gmtoffset' => true,
61
  'type' =>'datetime'
62
  ));
63
+
64
  $this->addColumn('title', array(
65
  'header' => $this->__('Title'),
66
  'index' => 'title',
67
  ));
68
+
69
  $this->addColumn('description', array(
70
  'header' => $this->__('Description'),
71
  'index' => 'description',
72
  ));
73
+
74
  $this->addColumn('is_active', array(
75
  'header' => Mage::helper('cms')->__('Active'),
76
  'index' => 'is_active',
81
  1 => $this->__('Enabled')
82
  ),
83
  ));
84
+
85
  $this->addColumn('is_aggregated', array(
86
  'header' => Mage::helper('cms')->__('Is Aggregated'),
87
  'index' => 'is_aggregated',
92
  1 => $this->__('Yes')
93
  ),
94
  ));
 
 
95
 
96
+ parent::_prepareColumns();
97
+
98
+ return $this;
99
  }
100
 
101
+ /**
102
+ * @return $this
103
+ */
104
  protected function _prepareMassaction()
105
  {
106
  $this->setMassactionIdField('tracker_id');
111
  'url' => $this->getUrl('*/*/massDelete'),
112
  'confirm' => $this->__('Are you sure?')
113
  ));
114
+
115
  $this->getMassactionBlock()->addItem('is_active', array(
116
  'label'=> $this->__('Enable/Disable'),
117
  'url' => $this->getUrl('*/*/massEnable', array('_current'=>true)),
133
  'confirm' => $this->__('This may take some time depending on the size of your data, would you like to continue?'),
134
  'url' => $this->getUrl('*/*/massAggregate')
135
  ));
136
+
 
 
137
  return $this;
138
  }
 
 
139
 
140
+ /**
141
+ * @return string
142
+ */
143
  public function getGridUrl()
144
  {
145
  return $this->getUrl('*/*/grid', array('_current'=> true));
146
  }
147
 
148
+ /**
149
+ * @param $row
150
+ *
151
+ * @return string
152
+ */
153
  public function getRowUrl($row)
154
  {
155
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
156
  }
157
  }
app/code/community/Mzax/Emarketing/Block/Tracker/New.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,42 +16,42 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- *
23
- * @author Jacob Siefer
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- * @version 0.4.10
26
  */
27
  class Mzax_Emarketing_Block_Tracker_New extends Mzax_Emarketing_Block_Tracker_Edit
28
  {
29
-
30
-
 
31
  public function getHeaderText()
32
  {
33
  return $this->__('New Conversion Goal Tracker');
34
  }
35
 
36
-
 
 
37
  public function getValidationUrl()
38
  {
39
  return null;
40
  }
41
-
42
-
 
 
 
 
43
  protected function _prepareLayout()
44
  {
45
- parent::_prepareLayout();
46
-
47
- /* @var $tracker Mzax_Emarketing_Model_Conversion_Tracker */
48
- $tracker = Mage::registry('current_tracker');
49
-
50
  $this->_removeButton('reset');
51
  $this->_removeButton('save');
52
- $this->_removeButton('save_and_continue');
53
  }
54
-
55
-
56
  /**
57
  * Get form action URL
58
  *
@@ -62,6 +61,4 @@ class Mzax_Emarketing_Block_Tracker_New extends Mzax_Emarketing_Block_Tracker_Ed
62
  {
63
  return $this->getUrl('*/*/new');
64
  }
65
-
66
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_New
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_New extends Mzax_Emarketing_Block_Tracker_Edit
24
  {
25
+ /**
26
+ * @return string
27
+ */
28
  public function getHeaderText()
29
  {
30
  return $this->__('New Conversion Goal Tracker');
31
  }
32
 
33
+ /**
34
+ * @return null
35
+ */
36
  public function getValidationUrl()
37
  {
38
  return null;
39
  }
40
+
41
+ /**
42
+ * Prepare layout
43
+ *
44
+ * @return void
45
+ */
46
  protected function _prepareLayout()
47
  {
48
+ parent::_prepareLayout();
49
+
 
 
 
50
  $this->_removeButton('reset');
51
  $this->_removeButton('save');
52
+ $this->_removeButton('save_and_continue');
53
  }
54
+
 
55
  /**
56
  * Get form action URL
57
  *
61
  {
62
  return $this->getUrl('*/*/new');
63
  }
 
 
64
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Test.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,10 +17,11 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Tracker_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
22
  {
23
-
24
-
25
  /**
26
  * Retrieve filter
27
  *
@@ -31,39 +31,36 @@ class Mzax_Emarketing_Block_Tracker_Test extends Mzax_Emarketing_Block_Filter_Te
31
  {
32
  $filter = $this->getTracker()->getGoal();
33
  $this->prepareEmulation($filter);
 
34
  return $filter;
35
  }
36
-
37
-
38
-
 
39
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
40
  {
41
  $child = $this->getChild('emulate');
42
- if($child && method_exists($child, 'prepareEmulation')) {
43
  $child->prepareEmulation($filter);
44
  }
45
  }
46
-
47
-
48
-
49
-
50
-
51
  /**
52
  * Generate url by route and parameters
53
  *
54
  * @param string $route
55
  * @param array $params
 
56
  * @return string
57
  */
58
  public function getUrl($route = '', $params = array())
59
  {
60
  $params['id'] = $this->getTracker()->getId();
 
61
  return parent::getUrl($route, $params);
62
  }
63
-
64
-
65
-
66
-
67
  /**
68
  * Retrieve current tracker
69
  *
@@ -73,8 +70,4 @@ class Mzax_Emarketing_Block_Tracker_Test extends Mzax_Emarketing_Block_Filter_Te
73
  {
74
  return Mage::registry('current_tracker');
75
  }
76
-
77
-
78
-
79
-
80
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Test
22
+ */
23
  class Mzax_Emarketing_Block_Tracker_Test extends Mzax_Emarketing_Block_Filter_Test_Recursive
24
  {
 
 
25
  /**
26
  * Retrieve filter
27
  *
31
  {
32
  $filter = $this->getTracker()->getGoal();
33
  $this->prepareEmulation($filter);
34
+
35
  return $filter;
36
  }
37
+
38
+ /**
39
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
40
+ */
41
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
42
  {
43
  $child = $this->getChild('emulate');
44
+ if ($child && method_exists($child, 'prepareEmulation')) {
45
  $child->prepareEmulation($filter);
46
  }
47
  }
48
+
 
 
 
 
49
  /**
50
  * Generate url by route and parameters
51
  *
52
  * @param string $route
53
  * @param array $params
54
+ *
55
  * @return string
56
  */
57
  public function getUrl($route = '', $params = array())
58
  {
59
  $params['id'] = $this->getTracker()->getId();
60
+
61
  return parent::getUrl($route, $params);
62
  }
63
+
 
 
 
64
  /**
65
  * Retrieve current tracker
66
  *
70
  {
71
  return Mage::registry('current_tracker');
72
  }
 
 
 
 
73
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Test/Emulate.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,17 +17,16 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Tracker_Test_Emulate extends Mage_Adminhtml_Block_Template
22
  {
23
-
24
  /**
25
- *
26
  * @var Varien_Data_Form
27
  */
28
  protected $_form;
29
-
30
-
31
-
32
  /**
33
  * Retrieve Varien Data Form
34
  *
@@ -36,135 +34,124 @@ class Mzax_Emarketing_Block_Tracker_Test_Emulate extends Mage_Adminhtml_Block_Te
36
  */
37
  public function getForm()
38
  {
39
- if(!$this->_form) {
40
  $this->_form = new Varien_Data_Form();
41
  $this->_form->setElementRenderer(Mage::getBlockSingleton('mzax_emarketing/editable')->setFormat('form'));
42
  $this->_form->setHtmlIdPrefix("emulate_");
43
  $this->_form->setFieldNameSuffix("emulate");
44
  }
 
45
  return $this->_form;
46
  }
47
-
48
-
49
  /**
50
  * Prepare filter
51
- *
52
- * Usally called by parent block class
53
- *
54
  * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
55
  */
56
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
57
  {
58
  $emulate = $this->getRequest()->getParam('emulate');
59
-
60
- if($this->emulate('time')) {
61
- if(isset($emulate['from']) && isset($emulate['to'])) {
62
  $filter->setParam('current_time', array($emulate['from'], $emulate['to']));
63
  $filter->setParam('is_local_time', true);
64
  }
65
  }
66
-
67
- if($this->emulate('campaign')) {
68
  /* @var $campagin Mzax_Emarketing_Model_Campaign */
69
  $campagin = Mage::getModel('mzax_emarketing/campaign');
70
  $campagin->load($emulate['campaign_id']);
71
-
72
- if($campagin->getId()) {
73
  $filter->setParam('campaign', $campagin);
74
  }
75
  }
76
  }
77
-
78
-
79
-
80
  /**
81
  * Check if we should emulate the specified key
82
  *
83
  * @param string $key
 
84
  * @return boolean
85
  */
86
  public function emulate($key)
87
  {
88
  $emulate = $this->getRequest()->getParam('emulate');
89
-
90
- if(isset($emulate[$key])) {
91
  return ($emulate[$key] == 1);
92
  }
 
93
  return false;
94
  }
95
-
96
-
97
-
98
-
99
-
100
  /**
101
- *
102
  *
103
  * @return Varien_Data_Form_Element_Abstract
104
  */
105
  public function getCampaignSelect()
106
  {
107
  $params = $this->getRequest()->getParam('emulate');
108
-
109
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
110
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
111
  $collection->addArchiveFilter(false);
112
-
113
  $options = array();
114
- if($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
 
 
115
  $options['current'] = $this->__('beeing tracked');
116
  }
117
  $options += $collection->toOptionHash();
118
-
119
- /* @var $campagin Mzax_Emarketing_Model_Campaign */
120
- $campagin = Mage::getModel('mzax_emarketing/campaign');
121
-
122
- if(isset($params['campaign_id'])) {
123
- $campagin->load($params['campaign_id']);
124
  }
125
-
126
  return $this->getForm()->addField('campaign_id', 'select', array(
127
- 'name' => 'campaign_id',
128
- 'value_name' => (string) $campagin->getName(),
129
- 'value' => $campagin->getId(),
130
- 'options' => $options,
131
  ));
132
-
133
  }
134
-
135
-
136
-
137
-
138
  /**
139
  * Helper for simple select element
140
  *
141
  * @param string $key
142
- * @param array $options
143
  * @return Varien_Data_Form_Element_Abstract
144
  */
145
  public function getDateElement($key)
146
  {
147
  $format = Varien_Date::DATE_INTERNAL_FORMAT;
148
-
149
  $params = $this->getRequest()->getParam('emulate');
150
-
151
- if(isset($params[$key])) {
152
  $value = $params[$key];
153
- }
154
- else {
155
  $value = Zend_Date::now()->toString($format);
156
  }
157
-
158
- return $this->getForm()->addField($key, 'date',array(
159
  'name' => $key,
160
  'value_name' => $value,
161
- 'value' => $value,
162
  'explicit_apply' => true,
163
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
164
  'input_format' => $format,
165
  'format' => $format
166
  ));
167
  }
168
-
169
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Test_Emulate
22
+ */
23
  class Mzax_Emarketing_Block_Tracker_Test_Emulate extends Mage_Adminhtml_Block_Template
24
  {
 
25
  /**
 
26
  * @var Varien_Data_Form
27
  */
28
  protected $_form;
29
+
 
 
30
  /**
31
  * Retrieve Varien Data Form
32
  *
34
  */
35
  public function getForm()
36
  {
37
+ if (!$this->_form) {
38
  $this->_form = new Varien_Data_Form();
39
  $this->_form->setElementRenderer(Mage::getBlockSingleton('mzax_emarketing/editable')->setFormat('form'));
40
  $this->_form->setHtmlIdPrefix("emulate_");
41
  $this->_form->setFieldNameSuffix("emulate");
42
  }
43
+
44
  return $this->_form;
45
  }
46
+
 
47
  /**
48
  * Prepare filter
49
+ *
50
+ * Usually called by parent block class
51
+ *
52
  * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
53
  */
54
  public function prepareEmulation(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
55
  {
56
  $emulate = $this->getRequest()->getParam('emulate');
57
+
58
+ if ($this->emulate('time')) {
59
+ if (isset($emulate['from']) && isset($emulate['to'])) {
60
  $filter->setParam('current_time', array($emulate['from'], $emulate['to']));
61
  $filter->setParam('is_local_time', true);
62
  }
63
  }
64
+
65
+ if ($this->emulate('campaign')) {
66
  /* @var $campagin Mzax_Emarketing_Model_Campaign */
67
  $campagin = Mage::getModel('mzax_emarketing/campaign');
68
  $campagin->load($emulate['campaign_id']);
69
+
70
+ if ($campagin->getId()) {
71
  $filter->setParam('campaign', $campagin);
72
  }
73
  }
74
  }
75
+
 
 
76
  /**
77
  * Check if we should emulate the specified key
78
  *
79
  * @param string $key
80
+ *
81
  * @return boolean
82
  */
83
  public function emulate($key)
84
  {
85
  $emulate = $this->getRequest()->getParam('emulate');
86
+ if (isset($emulate[$key])) {
 
87
  return ($emulate[$key] == 1);
88
  }
89
+
90
  return false;
91
  }
92
+
 
 
 
 
93
  /**
 
94
  *
95
  * @return Varien_Data_Form_Element_Abstract
96
  */
97
  public function getCampaignSelect()
98
  {
99
  $params = $this->getRequest()->getParam('emulate');
100
+
101
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
102
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
103
  $collection->addArchiveFilter(false);
104
+
105
  $options = array();
106
+
107
+ // @todo Potential error
108
+ if ($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
109
  $options['current'] = $this->__('beeing tracked');
110
  }
111
  $options += $collection->toOptionHash();
112
+
113
+ /* @var $campaign Mzax_Emarketing_Model_Campaign */
114
+ $campaign = Mage::getModel('mzax_emarketing/campaign');
115
+
116
+ if (isset($params['campaign_id'])) {
117
+ $campaign->load($params['campaign_id']);
118
  }
119
+
120
  return $this->getForm()->addField('campaign_id', 'select', array(
121
+ 'name' => 'campaign_id',
122
+ 'value_name' => (string) $campaign->getName(),
123
+ 'value' => $campaign->getId(),
124
+ 'options' => $options,
125
  ));
 
126
  }
127
+
 
 
 
128
  /**
129
  * Helper for simple select element
130
  *
131
  * @param string $key
132
+ *
133
  * @return Varien_Data_Form_Element_Abstract
134
  */
135
  public function getDateElement($key)
136
  {
137
  $format = Varien_Date::DATE_INTERNAL_FORMAT;
138
+
139
  $params = $this->getRequest()->getParam('emulate');
140
+
141
+ if (isset($params[$key])) {
142
  $value = $params[$key];
143
+ } else {
 
144
  $value = Zend_Date::now()->toString($format);
145
  }
146
+
147
+ return $this->getForm()->addField($key, 'date', array(
148
  'name' => $key,
149
  'value_name' => $value,
150
+ 'value' => $value,
151
  'explicit_apply' => true,
152
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
153
  'input_format' => $format,
154
  'format' => $format
155
  ));
156
  }
 
 
157
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Upload.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,19 +18,17 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Block_Tracker_Upload extends Mage_Adminhtml_Block_Widget_Form_Container
30
  {
 
 
 
31
  public function __construct()
32
  {
33
  $this->_objectId = 'id';
34
-
35
  $this->_blockGroup = 'mzax_emarketing';
36
  $this->_controller = 'tracker';
37
  $this->_mode = 'upload';
@@ -40,18 +37,16 @@ class Mzax_Emarketing_Block_Tracker_Upload extends Mage_Adminhtml_Block_Widget_F
40
 
41
  $this->_updateButton('save', 'label', $this->__('Upload Tracker'));
42
  $this->removeButton('delete');
43
-
44
  }
45
 
46
-
47
-
 
48
  public function getHeaderText()
49
  {
50
  return $this->__('Upload New Tracker');
51
  }
52
 
53
-
54
-
55
  /**
56
  * Get form action URL
57
  *
@@ -61,6 +56,4 @@ class Mzax_Emarketing_Block_Tracker_Upload extends Mage_Adminhtml_Block_Widget_F
61
  {
62
  return $this->getUrl('*/*/uploadPost');
63
  }
64
-
65
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Upload
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_Upload extends Mage_Adminhtml_Block_Widget_Form_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Tracker_Upload constructor.
27
+ */
28
  public function __construct()
29
  {
30
  $this->_objectId = 'id';
31
+
32
  $this->_blockGroup = 'mzax_emarketing';
33
  $this->_controller = 'tracker';
34
  $this->_mode = 'upload';
37
 
38
  $this->_updateButton('save', 'label', $this->__('Upload Tracker'));
39
  $this->removeButton('delete');
 
40
  }
41
 
42
+ /**
43
+ * @return string
44
+ */
45
  public function getHeaderText()
46
  {
47
  return $this->__('Upload New Tracker');
48
  }
49
 
 
 
50
  /**
51
  * Get form action URL
52
  *
56
  {
57
  return $this->getUrl('*/*/uploadPost');
58
  }
 
 
59
  }
app/code/community/Mzax/Emarketing/Block/Tracker/Upload/Form.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,44 +17,43 @@
18
  */
19
 
20
 
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.4.10
29
  */
30
  class Mzax_Emarketing_Block_Tracker_Upload_Form extends Mage_Adminhtml_Block_Widget_Form
31
  {
32
-
 
 
33
  protected function _prepareForm()
34
  {
35
- $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data'));
 
 
 
 
 
 
 
36
  $form->setHtmlIdPrefix("tracker");
37
  $form->setFieldNameSuffix("tracker");
38
-
39
-
40
  $fieldset = $form->addFieldset('base_fieldset', array(
41
  'legend' => $this->__('Upload new conversion tracker'),
42
  'class' => 'fieldset-wide',
43
  ));
44
-
45
  $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
46
-
47
-
48
  $noLabel = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
49
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
50
-
51
-
52
  $fieldset->addField('info', 'info', array(
53
  '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.')
54
  ))->setRenderer($noLabel);
55
-
56
-
57
-
58
-
59
  $fieldset->addField('template', 'file', array(
60
  'name' => 'file',
61
  'required' => true,
@@ -63,10 +61,10 @@ class Mzax_Emarketing_Block_Tracker_Upload_Form extends Mage_Adminhtml_Block_Wid
63
  'title' => $this->__('Conversion Tracker File'),
64
  'note' => $this->__('Select the tracker file that you want to upload (*.mzax.tracker).'),
65
  ));
66
-
67
-
68
  $this->setForm($form);
69
  $form->setUseContainer(true);
 
70
  return parent::_prepareForm();
71
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Tracker_Upload_Form
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Tracker_Upload_Form extends Mage_Adminhtml_Block_Widget_Form
24
  {
25
+ /**
26
+ * @return Mage_Adminhtml_Block_Widget_Form
27
+ */
28
  protected function _prepareForm()
29
  {
30
+ $form = new Varien_Data_Form(
31
+ array(
32
+ 'id' => 'edit_form',
33
+ 'action' => $this->getData('action'),
34
+ 'method' => 'post',
35
+ 'enctype' => 'multipart/form-data'
36
+ )
37
+ );
38
  $form->setHtmlIdPrefix("tracker");
39
  $form->setFieldNameSuffix("tracker");
40
+
 
41
  $fieldset = $form->addFieldset('base_fieldset', array(
42
  'legend' => $this->__('Upload new conversion tracker'),
43
  'class' => 'fieldset-wide',
44
  ));
45
+
46
  $fieldset->addType('info', Mage::getConfig()->getModelClassName('mzax_emarketing/form_element_info'));
47
+
 
48
  $noLabel = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
49
  ->setTemplate('cms/page/edit/form/renderer/content.phtml');
50
+
51
+
52
  $fieldset->addField('info', 'info', array(
53
  '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.')
54
  ))->setRenderer($noLabel);
55
+
56
+
 
 
57
  $fieldset->addField('template', 'file', array(
58
  'name' => 'file',
59
  'required' => true,
61
  'title' => $this->__('Conversion Tracker File'),
62
  'note' => $this->__('Select the tracker file that you want to upload (*.mzax.tracker).'),
63
  ));
64
+
 
65
  $this->setForm($form);
66
  $form->setUseContainer(true);
67
+
68
  return parent::_prepareForm();
69
  }
70
  }
app/code/community/Mzax/Emarketing/Block/Tracker/View.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,26 +17,27 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Block_Tracker_View extends Mage_Adminhtml_Block_Widget_Grid_Container
22
  {
23
-
 
 
24
  public function __construct()
25
  {
26
- $this->_blockGroup = 'mzax_emarketing';
27
  $this->_controller = 'tracker';
28
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Trackers');
29
  $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Tracker');
30
-
31
  $this->_addButton('upload', array(
32
  'label' => $this->__('Upload'),
33
  'class' => 'upload',
34
  'onclick' => "setLocation('{$this->getUrl('*/*/upload')}')",
35
  ));
36
-
37
-
38
  parent::__construct();
39
  }
40
-
41
-
42
-
43
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Tracker_View
22
+ */
23
  class Mzax_Emarketing_Block_Tracker_View extends Mage_Adminhtml_Block_Widget_Grid_Container
24
  {
25
+ /**
26
+ * Mzax_Emarketing_Block_Tracker_View constructor.
27
+ */
28
  public function __construct()
29
  {
30
+ $this->_blockGroup = 'mzax_emarketing';
31
  $this->_controller = 'tracker';
32
  $this->_headerText = Mage::helper('mzax_emarketing')->__('Manage Trackers');
33
  $this->_addButtonLabel = Mage::helper('mzax_emarketing')->__('New Tracker');
34
+
35
  $this->_addButton('upload', array(
36
  'label' => $this->__('Upload'),
37
  'class' => 'upload',
38
  'onclick' => "setLocation('{$this->getUrl('*/*/upload')}')",
39
  ));
40
+
 
41
  parent::__construct();
42
  }
 
 
 
43
  }
app/code/community/Mzax/Emarketing/Block/Unsubscribe.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,53 +17,59 @@
18
  */
19
 
20
 
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.4.10
29
  */
30
  class Mzax_Emarketing_Block_Unsubscribe extends Mage_Core_Block_Template
31
  {
32
-
33
-
 
 
 
 
34
 
35
  /**
36
- * Retrieve session model
37
  *
38
- * @return Mzax_Emarketing_Model_Session
39
  */
40
- public function getSession()
41
  {
42
- return Mage::getSingleton('mzax_emarketing/session');
 
 
43
  }
44
-
45
-
46
-
47
  /**
48
  * Retrieve address
49
- *
50
  * @return string
51
  */
52
  public function getAddress()
53
  {
54
- return $this->getSession()->getLastAddress();
 
 
55
  }
56
-
57
-
58
-
 
59
  public function getFormKey()
60
  {
61
- return $this->getSession()->getFormKey();
62
- }
63
 
 
 
64
 
 
 
 
65
  public function getCustomerNewsletterLists()
66
  {
67
- $customer = Mage::getSingleton('customer/session')->getCustomer();
 
68
 
69
  /* @var $subscriber Mage_Newsletter_Model_Subscriber */
70
  $subscriber = Mage::getModel('newsletter/subscriber');
@@ -78,7 +83,9 @@ class Mzax_Emarketing_Block_Unsubscribe extends Mage_Core_Block_Template
78
  return $collection;
79
  }
80
 
81
-
 
 
82
  public function getNewsletterLists()
83
  {
84
  /* @var $subscriber Mage_Newsletter_Model_Subscriber */
@@ -93,17 +100,25 @@ class Mzax_Emarketing_Block_Unsubscribe extends Mage_Core_Block_Template
93
  return $collection;
94
  }
95
 
 
 
 
96
  public function getUpdateUrl()
97
  {
98
  return $this->getUrl('*/*/update');
99
  }
100
 
101
-
 
 
102
  public function getYesUrl()
103
  {
104
  return $this->getUrl('*/*/do');
105
  }
106
-
 
 
 
107
  public function getNoUrl()
108
  {
109
  return $this->getUrl('/');
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Block_Unsubscribe
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Block_Unsubscribe extends Mage_Core_Block_Template
24
  {
25
+ /**
26
+ * Session manager
27
+ *
28
+ * @var Mzax_Emarketing_Model_SessionManager
29
+ */
30
+ protected $_sessionManager;
31
 
32
  /**
33
+ * Load dependencies
34
  *
35
+ * @return void
36
  */
37
+ public function _construct()
38
  {
39
+ parent::_construct();
40
+
41
+ $this->_sessionManager = Mage::getSingleton('mzax_emarketing/sessionManager');
42
  }
43
+
 
 
44
  /**
45
  * Retrieve address
46
+ *
47
  * @return string
48
  */
49
  public function getAddress()
50
  {
51
+ $session = $this->_sessionManager->getSession();
52
+
53
+ return $session->getLastAddress();
54
  }
55
+
56
+ /**
57
+ * @return string
58
+ */
59
  public function getFormKey()
60
  {
61
+ $session = $this->_sessionManager->getCoreSession();
 
62
 
63
+ return $session->getFormKey();
64
+ }
65
 
66
+ /**
67
+ * @return Mzax_Emarketing_Model_Resource_Newsletter_List_Collection
68
+ */
69
  public function getCustomerNewsletterLists()
70
  {
71
+ $session = $this->_sessionManager->getCustomerSession();
72
+ $customer = $session->getCustomer();
73
 
74
  /* @var $subscriber Mage_Newsletter_Model_Subscriber */
75
  $subscriber = Mage::getModel('newsletter/subscriber');
83
  return $collection;
84
  }
85
 
86
+ /**
87
+ * @return Mzax_Emarketing_Model_Resource_Newsletter_List_Collection
88
+ */
89
  public function getNewsletterLists()
90
  {
91
  /* @var $subscriber Mage_Newsletter_Model_Subscriber */
100
  return $collection;
101
  }
102
 
103
+ /**
104
+ * @return string
105
+ */
106
  public function getUpdateUrl()
107
  {
108
  return $this->getUrl('*/*/update');
109
  }
110
 
111
+ /**
112
+ * @return string
113
+ */
114
  public function getYesUrl()
115
  {
116
  return $this->getUrl('*/*/do');
117
  }
118
+
119
+ /**
120
+ * @return string
121
+ */
122
  public function getNoUrl()
123
  {
124
  return $this->getUrl('/');
app/code/community/Mzax/Emarketing/Block/Widget/Form.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 this Extension in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mzax
13
+ * @package Mzax_Emarketing
14
+ * @author Jacob Siefer (jacob@mzax.de)
15
+ * @copyright Copyright (c) 2015 Jacob Siefer
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Block_Widget_Form
22
+ */
23
+ class Mzax_Emarketing_Block_Widget_Form extends Mage_Adminhtml_Block_Widget_Form
24
+ {
25
+ /**
26
+ * Session Manager
27
+ *
28
+ * @var Mzax_Emarketing_Model_SessionManager
29
+ */
30
+ protected $_sessionManager;
31
+
32
+ /**
33
+ * Store configuration
34
+ *
35
+ * @var Mzax_Emarketing_Model_Config
36
+ */
37
+ protected $_config;
38
+
39
+ /**
40
+ * Model factory
41
+ *
42
+ * @var Mzax_Emarketing_Model_Factory
43
+ */
44
+ protected $_factory;
45
+
46
+ /**
47
+ * FormWidget Constructor.
48
+ * Load dependencies.
49
+ *
50
+ * @return void
51
+ */
52
+ public function _construct()
53
+ {
54
+ parent::_construct();
55
+
56
+ $this->_sessionManager = Mage::getSingleton('mzax_emarketing/sessionManager');
57
+ $this->_factory = Mage::getSingleton('mzax_emarketing/factory');
58
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
59
+ }
60
+ }
app/code/community/Mzax/Emarketing/Controller/Admin/Action.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 this Extension in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mzax
13
+ * @package Mzax_Emarketing
14
+ * @author Jacob Siefer (jacob@mzax.de)
15
+ * @copyright Copyright (c) 2015 Jacob Siefer
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Controller_Admin_Action
22
+ */
23
+ class Mzax_Emarketing_Controller_Admin_Action extends Mage_Adminhtml_Controller_Action
24
+ {
25
+ /**
26
+ * Session Manager
27
+ *
28
+ * @var Mzax_Emarketing_Model_SessionManager
29
+ */
30
+ protected $_sessionManager;
31
+
32
+ /**
33
+ * Store configuration
34
+ *
35
+ * @var Mzax_Emarketing_Model_Config
36
+ */
37
+ protected $_config;
38
+
39
+ /**
40
+ * Model factory
41
+ *
42
+ * @var Mzax_Emarketing_Model_Factory
43
+ */
44
+ protected $_factory;
45
+
46
+ /**
47
+ * Controller Constructor.
48
+ * Load dependencies.
49
+ *
50
+ * @return void
51
+ */
52
+ public function _construct()
53
+ {
54
+ parent::_construct();
55
+
56
+ $this->_sessionManager = Mage::getSingleton('mzax_emarketing/sessionManager');
57
+ $this->_factory = Mage::getSingleton('mzax_emarketing/factory');
58
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
59
+ }
60
+ }
app/code/community/Mzax/Emarketing/Db/Select.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -21,18 +20,18 @@
21
 
22
  class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
23
  {
24
-
25
-
26
  static protected $_assambleAll = false;
27
-
28
  static protected $_tempTables = array();
29
-
30
  protected $_temporaryTable = false;
31
-
32
-
33
  /**
34
  * If select uses temproary table use table join instead
35
- *
36
  * @param string $bind
37
  * @param Zend_Db_Select $select
38
  * @param string $alias
@@ -41,15 +40,15 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
41
  */
42
  public function joinSelect($bind, Zend_Db_Select $select, $alias)
43
  {
44
- if($select instanceof Mzax_Emarketing_Db_Select && ($table = $select->getTemporaryTable())) {
45
- if($select->createTemporaryTable()) {
46
  return $this->joinTable($bind, new Zend_Db_Expr($table), $alias);
47
  }
48
  }
49
  return parent::joinSelect($bind, $select, $alias);
50
  }
51
-
52
-
53
  /**
54
  * If select uses temproary table use table join instead
55
  *
@@ -61,18 +60,18 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
61
  */
62
  public function joinSelectLeft($bind, Zend_Db_Select $select, $alias)
63
  {
64
- if($select instanceof Mzax_Emarketing_Db_Select && ($table = $select->getTemporaryTable())) {
65
- if($select->createTemporaryTable()) {
66
  return $this->joinTableLeft($bind, new Zend_Db_Expr($table), $alias);
67
  }
68
  }
69
  return parent::joinSelectLeft($bind, $select, $alias);
70
  }
71
-
72
-
73
  /**
74
  * Use temporary table for this select object
75
- *
76
  * @param string $tableName
77
  * @return Mzax_Emarketing_Db_Select
78
  */
@@ -81,67 +80,67 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
81
  $this->_temporaryTable = $tableName ? $tableName : false;
82
  return $this;
83
  }
84
-
85
-
86
-
87
  /**
88
  * Retrieve temporary table if available
89
- *
90
  * @return boolean|string
91
  */
92
  public function getTemporaryTable()
93
  {
94
- if($this->_temporaryTable) {
95
  return $this->_temporaryTable;
96
  }
97
  return false;
98
  }
99
-
100
-
101
-
102
  /**
103
  * Create temporary table with this select object
104
- *
105
  * @return boolean|multitype:|string
106
  */
107
  public function createTemporaryTable()
108
  {
109
  $name = $this->getTemporaryTable();
110
- if(!$name) {
111
  return false;
112
  }
113
-
114
  $adapter = $this->getResourceHelper()->getAdapter();
115
-
116
- if(isset(self::$_tempTables[$name])) {
117
  return self::$_tempTables[$name];
118
  }
119
-
120
-
121
  $sql[] = "CREATE TEMPORARY TABLE IF NOT EXISTS `$name`";
122
  $sql[] = "ENGINE = MEMORY";
123
  $sql[] = parent::assemble();
124
-
125
  try {
126
  $adapter->query(implode("\n", $sql));
127
  }
128
  catch(Exception $e) {
129
  Mage::logException($e);
130
- if(Mage::getIsDeveloperMode()) {
131
  die($e->getMessage() . "<br />\n<br />\n<br />\n" . implode("\n", $sql));
132
  }
133
  return self::$_tempTables[$name] = false;
134
  }
135
-
136
  return self::$_tempTables[$name] = "SELECT * FROM `$name`";
137
  }
138
-
139
-
140
-
141
  /**
142
  * Assamble the select object without using temporary
143
  * tables
144
- *
145
  * @return string
146
  */
147
  public function assembleAll()
@@ -151,41 +150,41 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
151
  $sql = parent::assemble();
152
  self::$_assambleAll = false;
153
  return $sql;
154
- }
155
  catch(Exception $e) {
156
  self::$_assambleAll = false;
157
  throw $e;
158
  }
159
  }
160
-
161
-
162
-
163
  /**
164
  * Allow to use temporary tabes for this filter
165
  * result
166
- *
167
  * @return string
168
  */
169
  public function assemble()
170
  {
171
- if(!self::$_assambleAll && $sql = $this->createTemporaryTable()) {
172
  return $sql;
173
  }
174
  else {
175
  return parent::assemble();
176
  }
177
  }
178
-
179
-
180
-
181
-
182
-
183
-
184
  /**
185
  * Join attribute to current query
186
- *
187
  * Will return an expression that points to the value column
188
- *
189
  * @param string $attribute
190
  * @param string $binding Optional binding column
191
  * @param boolean $joinStatic Join attribute even if static
@@ -193,28 +192,28 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
193
  */
194
  public function joinAttribute($bind, $attribute, $joinStatic = false)
195
  {
196
- if($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) {
197
  $joinKey = "{$attribute->getEntityType()->getEntityTypeCode()}/{$attribute->getAttributeCode()}";
198
- }
199
  else {
200
  $joinKey = $attribute;
201
  }
202
-
203
- if($this->getJoin($joinKey)) {
204
  return $this->getJoin($joinKey);
205
  }
206
-
207
  $this->_joins[$joinKey] = $this->getResourceHelper()->joinAttribute($this, $attribute, $this->_getBindExpr($bind), null, $joinStatic);
208
  return $this->_joins[$joinKey];
209
  }
210
-
211
-
212
-
213
-
214
-
215
  /**
216
  * Preform a right table join using the binder
217
- *
218
  * @param string|array $bind
219
  * @param string $table
220
  * @param string $tableAlias
@@ -224,12 +223,12 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
224
  {
225
  return $this->_joinTable('Right', $bind, $table, $tableAlias);
226
  }
227
-
228
-
229
-
230
  /**
231
  * Preform a left table join using the binder
232
- *
233
  * @param string|array $binding
234
  * @param string $table
235
  * @param string $tableAlias
@@ -239,12 +238,12 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
239
  {
240
  return $this->_joinTable('Left', $bind, $table, $tableAlias);
241
  }
242
-
243
-
244
-
245
  /**
246
  * Preform a inner table join using the binder
247
- *
248
  * @param string|array $binding
249
  * @param string $table
250
  * @param string $tableAlias
@@ -254,12 +253,12 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
254
  {
255
  return $this->_joinTable('Inner', $bind, $table, $tableAlias);
256
  }
257
-
258
-
259
-
260
  /**
261
  * Preform a table join using the binder
262
- *
263
  * @param string $joinType
264
  * @param string|array $binding
265
  * @param string $table
@@ -268,31 +267,31 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
268
  */
269
  protected function _joinTable($joinType, $bind, $table, $tableAlias = null)
270
  {
271
- if(!$tableAlias) {
272
  $tableAlias = $table;
273
  }
274
- if(isset($this->_joins[$tableAlias])) {
275
  return $this;
276
  }
277
-
278
  $joinFunc = "join{$joinType}";
279
-
280
  // assume that same name for binding and column
281
- if(is_string($bind)) {
282
  //$bind = array($bind => '{' . $bind . '}');
283
  }
284
-
285
  $tableName = $this->getTable($table);
286
  $cond = $this->_getJoinCondition($tableAlias, $bind);
287
  $this->$joinFunc(array($tableAlias => $tableName), $cond, null);
288
  $this->_joins[$tableAlias] = $tableName;
289
  return $this;
290
  }
291
-
292
-
293
-
294
-
295
-
296
  /**
297
  * Retrieve table name
298
  *
@@ -303,11 +302,11 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
303
  {
304
  return $this->getResourceHelper()->getTable($table);
305
  }
306
-
307
-
308
-
309
-
310
-
311
  /**
312
  * Retrieve resource helper
313
  *
@@ -317,7 +316,7 @@ class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
317
  {
318
  return Mage::getResourceSingleton('mzax_emarketing/helper');
319
  }
320
-
321
-
322
-
323
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
20
 
21
  class Mzax_Emarketing_Db_Select extends Mzax_Db_Select
22
  {
23
+
24
+
25
  static protected $_assambleAll = false;
26
+
27
  static protected $_tempTables = array();
28
+
29
  protected $_temporaryTable = false;
30
+
31
+
32
  /**
33
  * If select uses temproary table use table join instead
34
+ *
35
  * @param string $bind
36
  * @param Zend_Db_Select $select
37
  * @param string $alias
40
  */
41
  public function joinSelect($bind, Zend_Db_Select $select, $alias)
42
  {
43
+ if ($select instanceof Mzax_Emarketing_Db_Select && ($table = $select->getTemporaryTable())) {
44
+ if ($select->createTemporaryTable()) {
45
  return $this->joinTable($bind, new Zend_Db_Expr($table), $alias);
46
  }
47
  }
48
  return parent::joinSelect($bind, $select, $alias);
49
  }
50
+
51
+
52
  /**
53
  * If select uses temproary table use table join instead
54
  *
60
  */
61
  public function joinSelectLeft($bind, Zend_Db_Select $select, $alias)
62
  {
63
+ if ($select instanceof Mzax_Emarketing_Db_Select && ($table = $select->getTemporaryTable())) {
64
+ if ($select->createTemporaryTable()) {
65
  return $this->joinTableLeft($bind, new Zend_Db_Expr($table), $alias);
66
  }
67
  }
68
  return parent::joinSelectLeft($bind, $select, $alias);
69
  }
70
+
71
+
72
  /**
73
  * Use temporary table for this select object
74
+ *
75
  * @param string $tableName
76
  * @return Mzax_Emarketing_Db_Select
77
  */
80
  $this->_temporaryTable = $tableName ? $tableName : false;
81
  return $this;
82
  }
83
+
84
+
85
+
86
  /**
87
  * Retrieve temporary table if available
88
+ *
89
  * @return boolean|string
90
  */
91
  public function getTemporaryTable()
92
  {
93
+ if ($this->_temporaryTable) {
94
  return $this->_temporaryTable;
95
  }
96
  return false;
97
  }
98
+
99
+
100
+
101
  /**
102
  * Create temporary table with this select object
103
+ *
104
  * @return boolean|multitype:|string
105
  */
106
  public function createTemporaryTable()
107
  {
108
  $name = $this->getTemporaryTable();
109
+ if (!$name) {
110
  return false;
111
  }
112
+
113
  $adapter = $this->getResourceHelper()->getAdapter();
114
+
115
+ if (isset(self::$_tempTables[$name])) {
116
  return self::$_tempTables[$name];
117
  }
118
+
119
+
120
  $sql[] = "CREATE TEMPORARY TABLE IF NOT EXISTS `$name`";
121
  $sql[] = "ENGINE = MEMORY";
122
  $sql[] = parent::assemble();
123
+
124
  try {
125
  $adapter->query(implode("\n", $sql));
126
  }
127
  catch(Exception $e) {
128
  Mage::logException($e);
129
+ if (Mage::getIsDeveloperMode()) {
130
  die($e->getMessage() . "<br />\n<br />\n<br />\n" . implode("\n", $sql));
131
  }
132
  return self::$_tempTables[$name] = false;
133
  }
134
+
135
  return self::$_tempTables[$name] = "SELECT * FROM `$name`";
136
  }
137
+
138
+
139
+
140
  /**
141
  * Assamble the select object without using temporary
142
  * tables
143
+ *
144
  * @return string
145
  */
146
  public function assembleAll()
150
  $sql = parent::assemble();
151
  self::$_assambleAll = false;
152
  return $sql;
153
+ }
154
  catch(Exception $e) {
155
  self::$_assambleAll = false;
156
  throw $e;
157
  }
158
  }
159
+
160
+
161
+
162
  /**
163
  * Allow to use temporary tabes for this filter
164
  * result
165
+ *
166
  * @return string
167
  */
168
  public function assemble()
169
  {
170
+ if (!self::$_assambleAll && $sql = $this->createTemporaryTable()) {
171
  return $sql;
172
  }
173
  else {
174
  return parent::assemble();
175
  }
176
  }
177
+
178
+
179
+
180
+
181
+
182
+
183
  /**
184
  * Join attribute to current query
185
+ *
186
  * Will return an expression that points to the value column
187
+ *
188
  * @param string $attribute
189
  * @param string $binding Optional binding column
190
  * @param boolean $joinStatic Join attribute even if static
192
  */
193
  public function joinAttribute($bind, $attribute, $joinStatic = false)
194
  {
195
+ if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) {
196
  $joinKey = "{$attribute->getEntityType()->getEntityTypeCode()}/{$attribute->getAttributeCode()}";
197
+ }
198
  else {
199
  $joinKey = $attribute;
200
  }
201
+
202
+ if ($this->getJoin($joinKey)) {
203
  return $this->getJoin($joinKey);
204
  }
205
+
206
  $this->_joins[$joinKey] = $this->getResourceHelper()->joinAttribute($this, $attribute, $this->_getBindExpr($bind), null, $joinStatic);
207
  return $this->_joins[$joinKey];
208
  }
209
+
210
+
211
+
212
+
213
+
214
  /**
215
  * Preform a right table join using the binder
216
+ *
217
  * @param string|array $bind
218
  * @param string $table
219
  * @param string $tableAlias
223
  {
224
  return $this->_joinTable('Right', $bind, $table, $tableAlias);
225
  }
226
+
227
+
228
+
229
  /**
230
  * Preform a left table join using the binder
231
+ *
232
  * @param string|array $binding
233
  * @param string $table
234
  * @param string $tableAlias
238
  {
239
  return $this->_joinTable('Left', $bind, $table, $tableAlias);
240
  }
241
+
242
+
243
+
244
  /**
245
  * Preform a inner table join using the binder
246
+ *
247
  * @param string|array $binding
248
  * @param string $table
249
  * @param string $tableAlias
253
  {
254
  return $this->_joinTable('Inner', $bind, $table, $tableAlias);
255
  }
256
+
257
+
258
+
259
  /**
260
  * Preform a table join using the binder
261
+ *
262
  * @param string $joinType
263
  * @param string|array $binding
264
  * @param string $table
267
  */
268
  protected function _joinTable($joinType, $bind, $table, $tableAlias = null)
269
  {
270
+ if (!$tableAlias) {
271
  $tableAlias = $table;
272
  }
273
+ if (isset($this->_joins[$tableAlias])) {
274
  return $this;
275
  }
276
+
277
  $joinFunc = "join{$joinType}";
278
+
279
  // assume that same name for binding and column
280
+ if (is_string($bind)) {
281
  //$bind = array($bind => '{' . $bind . '}');
282
  }
283
+
284
  $tableName = $this->getTable($table);
285
  $cond = $this->_getJoinCondition($tableAlias, $bind);
286
  $this->$joinFunc(array($tableAlias => $tableName), $cond, null);
287
  $this->_joins[$tableAlias] = $tableName;
288
  return $this;
289
  }
290
+
291
+
292
+
293
+
294
+
295
  /**
296
  * Retrieve table name
297
  *
302
  {
303
  return $this->getResourceHelper()->getTable($table);
304
  }
305
+
306
+
307
+
308
+
309
+
310
  /**
311
  * Retrieve resource helper
312
  *
316
  {
317
  return Mage::getResourceSingleton('mzax_emarketing/helper');
318
  }
319
+
320
+
321
+
322
+ }
app/code/community/Mzax/Emarketing/Helper/Campaign.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,171 +19,168 @@
20
 
21
  /**
22
  * Helper class for campaign related tasks
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Helper_Campaign extends Mage_Core_Helper_Abstract
30
  {
31
-
32
-
33
  /**
34
  * Check all campaigns for new recipients
35
- *
36
  * This will look for new recipients that match the current filters
37
  * and should recieve the campaign
38
  *
39
- * @return integer The number of new recipients
 
 
 
40
  */
41
  public function fetchNewRecipients(array $options)
42
  {
43
- $lock = Mage::helper('mzax_emarketing')->lock('fetch_new_recipients');
44
- if(!$lock) {
 
 
 
45
  return false;
46
  }
47
-
48
  /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
49
  $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
50
  $campaigns->addCheckFilter();
51
  $campaigns->addRunningFilter();
52
-
53
  // do the once that get checked more often at the end
54
  $campaigns->setOrder('check_frequency', 'DESC');
55
  // then go for a random sort to make sure they all get a chance
56
  $campaigns->setOrder('RAND()', 'ASC');
57
-
58
-
59
  $options = new Varien_Object($options);
60
  $options->getDataSetDefault('timeout', 150);
61
  $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
62
-
63
- if($options->getVerbose()) {
 
 
64
  echo "\n\n{$campaigns->getSelect()}\n\n";
65
  }
66
 
67
  $start = time();
68
  $timeout = (int) $options->getTimeout();
69
-
70
  $count = 0;
71
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
72
- foreach($campaigns as $campaign) {
73
  try {
74
- if($options->getVerbose()) {
75
  echo sprintf("Find Recipients for '%s' (#%s)...", $campaign->getName(), $campaign->getId());
76
  }
77
-
78
  $count += $found = $campaign->findRecipients();
79
-
80
- if($options->getVerbose()) {
81
  echo sprintf(" \tfound %s\n", $found);
82
  }
83
-
84
  $lock->touch();
85
- }
86
- catch(Exception $e) {
87
- if($options->getBreakOnError()) {
88
  $lock->unlock();
89
  throw $e;
90
  }
91
  Mage::logException($e);
92
-
93
- if($options->getVerbose()) {
94
  echo "\n{$e->getMessage()}\n{$e->getTraceAsString()}\n\n";
95
  }
96
  }
97
  // make sure we don't exceed the timeout
98
- if($timeout && time()-$start > $timeout) {
99
  break;
100
  }
101
  }
102
  $lock->unlock();
 
103
  return $count;
104
  }
105
-
106
-
107
-
108
-
109
  /**
110
  * Send recipients
111
- *
112
  * @param array $options
 
 
113
  * @throws Exception
114
- * @return number
115
  */
116
  public function sendRecipients(array $options)
117
  {
118
- $lock = Mage::helper('mzax_emarketing')->lock('send_recipients');
119
- if(!$lock) {
120
- return false;
 
 
 
121
  }
122
-
123
-
124
  /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
125
  $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
126
  $campaigns->addRunningFilter();
127
  //$campaigns->setOrder('last_check', 'DESC');
128
  $campaigns->setOrder('RAND()', 'ASC');
129
-
130
  $options = new Varien_Object($options);
131
  $options->getDataSetDefault('timeout', 100);
132
  $options->getDataSetDefault('maximum', 500);
133
  $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
134
-
135
-
136
- if($options->getVerbose()) {
 
137
  echo "\n\n{$campaigns->getSelect()}\n\n";
138
  }
139
-
140
  $start = time();
141
-
142
  $timeout = (int) $options->getTimeout();
143
  $maximum = (int) $options->getMaximum();
144
-
145
  $count = 0;
146
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
147
- foreach($campaigns as $campaign) {
148
  try {
149
- if($options->getVerbose()) {
150
  echo sprintf("Send Recipients for '%s' (#%s)...", $campaign->getName(), $campaign->getId());
151
  }
152
-
153
  $count += $sent = $campaign->sendRecipients(array(
154
  'timeout' => $timeout - (time()-$start),
155
  'maximum' => $maximum - $count,
156
  'break_on_error' => $options->getBreakOnError()
157
  ));
158
-
159
- if($options->getVerbose()) {
160
  echo sprintf(" \tsent %s\n", $sent);
161
  }
162
- }
163
- catch(Exception $e) {
164
- if($options->getBreakOnError()) {
165
  $lock->unlock();
166
  throw $e;
167
  }
168
  Mage::logException($e);
169
- if($options->getVerbose()) {
170
  echo "\n{$e->getMessage()}\n{$e->getTraceAsString()}\n\n";
171
  }
172
  }
173
  // make sure we don't exceed the timeout
174
- if($timeout && time()-$start > $timeout) {
175
  break;
176
  }
177
  // don't send more then max at once
178
- if($maximum && $maximum <= $count) {
179
  break;
180
  }
181
  $lock->touch();
182
  }
183
  $lock->unlock();
 
184
  return $count;
185
  }
186
-
187
-
188
-
189
-
190
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
  /**
21
  * Helper class for campaign related tasks
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Helper_Campaign extends Mage_Core_Helper_Abstract
24
  {
 
 
25
  /**
26
  * Check all campaigns for new recipients
27
+ *
28
  * This will look for new recipients that match the current filters
29
  * and should recieve the campaign
30
  *
31
+ * @param array $options
32
+ *
33
+ * @return int The number of new recipients
34
+ * @throws Exception
35
  */
36
  public function fetchNewRecipients(array $options)
37
  {
38
+ /** @var Mzax_Emarketing_Helper_Data $helper */
39
+ $helper = Mage::helper('mzax_emarketing');
40
+
41
+ $lock = $helper->lock('fetch_new_recipients');
42
+ if (!$lock) {
43
  return false;
44
  }
45
+
46
  /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
47
  $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
48
  $campaigns->addCheckFilter();
49
  $campaigns->addRunningFilter();
50
+
51
  // do the once that get checked more often at the end
52
  $campaigns->setOrder('check_frequency', 'DESC');
53
  // then go for a random sort to make sure they all get a chance
54
  $campaigns->setOrder('RAND()', 'ASC');
55
+
 
56
  $options = new Varien_Object($options);
57
  $options->getDataSetDefault('timeout', 150);
58
  $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
59
+
60
+ $verbose = (bool)$options->getData('verbose');
61
+
62
+ if ($verbose) {
63
  echo "\n\n{$campaigns->getSelect()}\n\n";
64
  }
65
 
66
  $start = time();
67
  $timeout = (int) $options->getTimeout();
68
+
69
  $count = 0;
70
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
71
+ foreach ($campaigns as $campaign) {
72
  try {
73
+ if ($verbose) {
74
  echo sprintf("Find Recipients for '%s' (#%s)...", $campaign->getName(), $campaign->getId());
75
  }
76
+
77
  $count += $found = $campaign->findRecipients();
78
+
79
+ if ($verbose) {
80
  echo sprintf(" \tfound %s\n", $found);
81
  }
82
+
83
  $lock->touch();
84
+ } catch (Exception $e) {
85
+ if ($options->getBreakOnError()) {
 
86
  $lock->unlock();
87
  throw $e;
88
  }
89
  Mage::logException($e);
90
+
91
+ if ($verbose) {
92
  echo "\n{$e->getMessage()}\n{$e->getTraceAsString()}\n\n";
93
  }
94
  }
95
  // make sure we don't exceed the timeout
96
+ if ($timeout && time()-$start > $timeout) {
97
  break;
98
  }
99
  }
100
  $lock->unlock();
101
+
102
  return $count;
103
  }
104
+
 
 
 
105
  /**
106
  * Send recipients
107
+ *
108
  * @param array $options
109
+ *
110
+ * @return int
111
  * @throws Exception
 
112
  */
113
  public function sendRecipients(array $options)
114
  {
115
+ /** @var Mzax_Emarketing_Helper_Data $helper */
116
+ $helper = Mage::helper('mzax_emarketing');
117
+
118
+ $lock = $helper->lock('send_recipients');
119
+ if (!$lock) {
120
+ return 0;
121
  }
122
+
 
123
  /* @var $campaigns Mzax_Emarketing_Model_Resource_Campaign_Collection */
124
  $campaigns = Mage::getResourceModel('mzax_emarketing/campaign_collection');
125
  $campaigns->addRunningFilter();
126
  //$campaigns->setOrder('last_check', 'DESC');
127
  $campaigns->setOrder('RAND()', 'ASC');
128
+
129
  $options = new Varien_Object($options);
130
  $options->getDataSetDefault('timeout', 100);
131
  $options->getDataSetDefault('maximum', 500);
132
  $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
133
+
134
+ $verbose = (bool)$options->getData('verbose');
135
+
136
+ if ($verbose) {
137
  echo "\n\n{$campaigns->getSelect()}\n\n";
138
  }
139
+
140
  $start = time();
141
+
142
  $timeout = (int) $options->getTimeout();
143
  $maximum = (int) $options->getMaximum();
144
+
145
  $count = 0;
146
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
147
+ foreach ($campaigns as $campaign) {
148
  try {
149
+ if ($verbose) {
150
  echo sprintf("Send Recipients for '%s' (#%s)...", $campaign->getName(), $campaign->getId());
151
  }
152
+
153
  $count += $sent = $campaign->sendRecipients(array(
154
  'timeout' => $timeout - (time()-$start),
155
  'maximum' => $maximum - $count,
156
  'break_on_error' => $options->getBreakOnError()
157
  ));
158
+
159
+ if ($verbose) {
160
  echo sprintf(" \tsent %s\n", $sent);
161
  }
162
+ } catch (Exception $e) {
163
+ if ($options->getBreakOnError()) {
 
164
  $lock->unlock();
165
  throw $e;
166
  }
167
  Mage::logException($e);
168
+ if ($verbose) {
169
  echo "\n{$e->getMessage()}\n{$e->getTraceAsString()}\n\n";
170
  }
171
  }
172
  // make sure we don't exceed the timeout
173
+ if ($timeout && time()-$start > $timeout) {
174
  break;
175
  }
176
  // don't send more then max at once
177
+ if ($maximum && $maximum <= $count) {
178
  break;
179
  }
180
  $lock->touch();
181
  }
182
  $lock->unlock();
183
+
184
  return $count;
185
  }
 
 
 
 
186
  }
app/code/community/Mzax/Emarketing/Helper/Data.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,47 +16,76 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
 
 
20
  class Mzax_Emarketing_Helper_Data extends Mage_Core_Helper_Abstract
21
  {
22
-
23
-
24
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  /**
26
- * Retreive version
27
- *
28
  * @return string
29
  */
30
  public function getVersion()
31
  {
32
  return (string) Mage::getConfig()->getModuleConfig('Mzax_Emarketing')->version;
33
  }
34
-
35
-
36
-
37
  /**
38
  * Can show credits?
39
- * Credits can be disabled by setting
40
  * global/mzax_emarketing/hide_credits = true
41
  * in your local.xml
42
- *
43
  * @return boolean
44
  */
45
  public function showCredits()
46
  {
47
- if(Mage::getConfig()->getNode('global/mzax_emarketing')->is('hide_credits', false)) {
48
  return false;
49
  }
50
- if(Mage::getResourceSingleton('mzax_emarketing/recipient')->countRecipients() <= 1000) {
51
  return false;
52
  }
53
  return true;
54
  }
55
 
56
-
57
-
58
  /**
59
  * Log message
60
  *
 
 
61
  * @return $this
62
  */
63
  public function log($message)
@@ -65,53 +93,66 @@ class Mzax_Emarketing_Helper_Data extends Mage_Core_Helper_Abstract
65
  $message = call_user_func_array(array($this, '__'), func_get_args());
66
 
67
  Mage::log($message, null, 'mzax_emarketing.log', true);
 
68
  return $this;
69
  }
70
-
71
 
72
-
73
  /**
74
  * Create a lock with the given name
75
- *
76
  * @param string $name
77
- * @param number $timeout
78
- * @param number $maxRunTime
79
- * @return Ambigous <boolean, Mzax_Once>|boolean
 
80
  */
81
  public function lock($name, $timeout = 5, $maxRunTime = 3600)
82
  {
83
  $filename = Mage::getBaseDir('tmp') . DS . 'mzax_emarketing_' . $name . '.lock';
84
-
85
- if($lock = Mzax_Once::lock($filename, $timeout, $maxRunTime)) {
86
- return $lock;
87
- }
88
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
-
91
-
92
-
93
  /**
94
- * Compress a 32 char hex hash to a 16 char accii hash
95
- * without loosing to much of uniqueness
96
- *
97
  * @param string $hash
 
98
  * @return string
99
  */
100
  public function compressHash($hash)
101
  {
102
- $parts = str_split($hash, 2);
103
-
104
  $base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXQZ';
105
  $baseLength = strlen($base);
106
  $compress = '';
107
- foreach($parts as $part) {
108
  $compress .= $base{hexdec($part)%$baseLength};
109
  }
 
110
  return $compress;
111
  }
112
-
113
-
114
-
115
 
116
  /**
117
  * Encode magento expressions
@@ -121,66 +162,44 @@ class Mzax_Emarketing_Helper_Data extends Mage_Core_Helper_Abstract
121
  *
122
  * We can encode them and decode them later
123
  *
124
- * @param unknown $html
125
- * @return string
 
126
  */
127
  public function encodeMageExpr(&$html)
128
  {
129
- $html = preg_replace_callback('/\{\{(.*?)\}\}/', function($match) {
130
  return '#MAGE_EXPR(' . base64_encode($match[0]) . ')';
131
- },$html);
132
  }
133
-
134
-
135
  /**
136
  * Decode magento expressions that have been encoded
137
  *
138
  * @param string $html
139
- * @return string
 
140
  */
141
  public function decodeMageExpr(&$html)
142
  {
143
- $html = preg_replace_callback('/#MAGE_EXPR\((.*?)\)/', function($match) {
144
  return base64_decode($match[1]);
145
- },$html);
146
  }
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
- protected $_operatorsByType = array(
156
- 'string' => array('==', '!=', '>=', '>', '<=', '<', '{}', '!{}', '()', '!()'),
157
- 'numeric' => array('==', '!=', '>=', '>', '<=', '<', '()', '!()'),
158
- 'date' => array('==', '>=', '<='),
159
- 'select' => array('==', '!=', '()', '!()'),
160
- 'boolean' => array('==', '!='),
161
- 'multiselect' => array('()', '!()'),
162
- 'grid' => array('()', '!()'),
163
- );
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
  /**
173
  * Retrieve Store Options
174
- *
175
  * @return array
176
  */
177
  public function getStoreOptions()
178
  {
179
- /* Mage_Adminhtml_Model_System_Config_Source_Store */
180
- return Mage::getModel('adminhtml/system_config_source_store')->toOptionArray();
 
 
181
  }
182
-
183
-
184
 
185
  /**
186
  * Retrieve Website Options
@@ -189,64 +208,67 @@ class Mzax_Emarketing_Helper_Data extends Mage_Core_Helper_Abstract
189
  */
190
  public function getWebsitesOptions()
191
  {
192
- /* Mage_Adminhtml_Model_System_Config_Source_Website */
193
- returnMage::getModel('adminhtml/system_config_source_website')->toOptionArray();
 
 
194
  }
195
-
196
-
197
-
198
-
199
 
 
 
 
 
 
200
  public function getDefaultValueByType($type)
201
  {
202
- switch($type) {
203
- case 'numeric': return '1';
 
204
  }
205
  return '';
206
  }
207
-
208
-
209
-
210
-
 
 
211
  public function getDefaultOperatorByType($type)
212
  {
213
- switch($type) {
214
- case 'boolean':
215
- case 'numeric':
216
- case 'select':
217
- case 'date':
218
  return '==';
219
- case 'multiselect':
220
  return '()';
221
  }
222
  return '{}';
223
  }
224
-
225
-
226
-
227
  /**
228
  * Retrieve operators by type
229
- *
230
  * @param string $type
231
  * @return array
232
  */
233
  public function getOperatorOptionsByType($type)
234
  {
235
  $operators = $this->getOperatorOptions();
236
-
237
- if(isset($this->_operatorsByType[$type])) {
238
  return $this->getOperatorOptions($this->_operatorsByType[$type]);
239
  }
240
  return $operators;
241
  }
242
-
243
-
244
-
245
-
246
  /**
247
  * Retrieve operator options
248
- *
249
- * @return array
 
 
250
  */
251
  public function getOperatorOptions($filter = null)
252
  {
@@ -262,86 +284,73 @@ class Mzax_Emarketing_Helper_Data extends Mage_Core_Helper_Abstract
262
  '()' => $this->__('is one of'),
263
  '!()' => $this->__('is not one of')
264
  );
265
-
266
- if(is_array($filter)) {
267
  $result = array();
268
- foreach($options as $key => $label) {
269
- if(in_array($key, $filter)) {
270
  $result[$key] = $label;
271
  }
272
  }
273
  return $result;
274
  }
 
275
  return $options;
276
  }
277
-
278
-
279
-
280
-
281
-
282
-
283
  /**
284
  * Retrieve time unit options
285
  *
286
- * @param string $value
287
- * @return array
288
  */
289
  public function getTimeUnitOptions()
290
  {
291
  return array(
292
- 'hours' => $this->__('hour(s)'),
293
- 'days' => $this->__('day(s)'),
294
- 'weeks' => $this->__('week(s)'),
295
- 'months' => $this->__('month(s)'),
296
- 'years' => $this->__('year(s)')
297
  );
298
  }
299
-
300
-
301
-
302
-
303
  /**
304
  * Calculate date
305
  *
306
  * @param number $value
307
  * @param string $unit
308
- * @param number $roundDate
 
 
309
  * @return Zend_Date
310
  */
311
- public function calcDate($value, $unit, $roundDate = null, $sign = '-')
312
  {
313
  // validate unit
314
- if(!key_exists($unit, $this->getTimeUnitOptions())) {
315
  return null;
316
  }
317
-
318
  $timestamp = strtotime("{$sign}{$value} {$unit}");
319
- if($timestamp) {
320
- // don't calculate with extrem high numbers (preformance)
321
  $timestamp = min(max($timestamp, 0), 10000000000);
322
  $date = new Zend_Date;
323
  $date->setTimestamp($timestamp);
324
-
325
- if($roundDate === self::DAY_START) {
326
  $date->setHour(0);
327
  $date->setMinute(0);
328
  $date->setSecond(0);
329
- }
330
- else if($roundDate === self::DAY_END) {
331
  $date->setHour(23);
332
  $date->setMinute(59);
333
  $date->setSecond(59);
334
  }
335
-
336
  return $date;
337
  }
338
-
339
  return null;
340
  }
341
-
342
-
343
-
344
-
345
-
346
-
347
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Helper_Data
22
+ */
23
  class Mzax_Emarketing_Helper_Data extends Mage_Core_Helper_Abstract
24
  {
25
+ const DAY_START = 1;
26
+ const DAY_END = 2;
27
+
28
+ const TIME_UNIT_HOURS = 'hours';
29
+ const TIME_UNIT_DAYS = 'days';
30
+ const TIME_UNIT_WEEKS = 'weeks';
31
+ const TIME_UNIT_MONTHS = 'months';
32
+ const TIME_UNIT_YEARS = 'years';
33
+
34
+ const TYPE_STRING = 'string';
35
+ const TYPE_NUMERIC = 'numeric';
36
+ const TYPE_DATE = 'date';
37
+ const TYPE_SELECT = 'select';
38
+ const TYPE_BOOLEAN = 'boolean';
39
+ const TYPE_MULTISELECT = 'multiselect';
40
+ const TYPE_GRID = 'grid';
41
+
42
+ /**
43
+ * @var string[][]
44
+ */
45
+ protected $_operatorsByType = array(
46
+ self::TYPE_STRING => array('==', '!=', '>=', '>', '<=', '<', '{}', '!{}', '()', '!()'),
47
+ self::TYPE_NUMERIC => array('==', '!=', '>=', '>', '<=', '<', '()', '!()'),
48
+ self::TYPE_DATE => array('==', '>=', '<='),
49
+ self::TYPE_SELECT => array('==', '!=', '()', '!()'),
50
+ self::TYPE_BOOLEAN => array('==', '!='),
51
+ self::TYPE_MULTISELECT => array('()', '!()'),
52
+ self::TYPE_GRID => array('()', '!()'),
53
+ );
54
+
55
  /**
56
+ * Retrieve version
57
+ *
58
  * @return string
59
  */
60
  public function getVersion()
61
  {
62
  return (string) Mage::getConfig()->getModuleConfig('Mzax_Emarketing')->version;
63
  }
64
+
 
 
65
  /**
66
  * Can show credits?
67
+ * Credits can be disabled by setting
68
  * global/mzax_emarketing/hide_credits = true
69
  * in your local.xml
70
+ *
71
  * @return boolean
72
  */
73
  public function showCredits()
74
  {
75
+ if (Mage::getConfig()->getNode('global/mzax_emarketing')->is('hide_credits', false)) {
76
  return false;
77
  }
78
+ if (Mage::getResourceSingleton('mzax_emarketing/recipient')->countRecipients() <= 1000) {
79
  return false;
80
  }
81
  return true;
82
  }
83
 
 
 
84
  /**
85
  * Log message
86
  *
87
+ * @param $message
88
+ *
89
  * @return $this
90
  */
91
  public function log($message)
93
  $message = call_user_func_array(array($this, '__'), func_get_args());
94
 
95
  Mage::log($message, null, 'mzax_emarketing.log', true);
96
+
97
  return $this;
98
  }
 
99
 
 
100
  /**
101
  * Create a lock with the given name
102
+ *
103
  * @param string $name
104
+ * @param int $timeout
105
+ * @param int $maxRunTime
106
+ *
107
+ * @return Mzax_Once|bool
108
  */
109
  public function lock($name, $timeout = 5, $maxRunTime = 3600)
110
  {
111
  $filename = Mage::getBaseDir('tmp') . DS . 'mzax_emarketing_' . $name . '.lock';
112
+ $lock = Mzax_Once::createLock($filename, $timeout, $maxRunTime);
113
+
114
+ return $lock;
115
+ }
116
+
117
+ /**
118
+ * Create a compressed random hash using a extra seed
119
+ *
120
+ * @param string $seed
121
+ *
122
+ * @return string
123
+ */
124
+ public function randomHash($seed)
125
+ {
126
+ $hash = md5(
127
+ $seed .
128
+ mt_rand(0, 99999999) .
129
+ microtime()
130
+ );
131
+
132
+ return $this->compressHash($hash);
133
  }
134
+
 
 
135
  /**
136
+ * Compress a 32 char hex hash to a 16 char asci hash
137
+ * without loosing to much of "uniqueness"
138
+ *
139
  * @param string $hash
140
+ *
141
  * @return string
142
  */
143
  public function compressHash($hash)
144
  {
145
+ $parts = str_split($hash, 2);
146
+
147
  $base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXQZ';
148
  $baseLength = strlen($base);
149
  $compress = '';
150
+ foreach ($parts as $part) {
151
  $compress .= $base{hexdec($part)%$baseLength};
152
  }
153
+
154
  return $compress;
155
  }
 
 
 
156
 
157
  /**
158
  * Encode magento expressions
162
  *
163
  * We can encode them and decode them later
164
  *
165
+ * @param string $html
166
+ *
167
+ * @return void
168
  */
169
  public function encodeMageExpr(&$html)
170
  {
171
+ $html = preg_replace_callback('/\{\{(.*?)\}\}/', function ($match) {
172
  return '#MAGE_EXPR(' . base64_encode($match[0]) . ')';
173
+ }, $html);
174
  }
175
+
176
+
177
  /**
178
  * Decode magento expressions that have been encoded
179
  *
180
  * @param string $html
181
+ *
182
+ * @return void
183
  */
184
  public function decodeMageExpr(&$html)
185
  {
186
+ $html = preg_replace_callback('/#MAGE_EXPR\((.*?)\)/', function ($match) {
187
  return base64_decode($match[1]);
188
+ }, $html);
189
  }
190
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  /**
192
  * Retrieve Store Options
193
+ *
194
  * @return array
195
  */
196
  public function getStoreOptions()
197
  {
198
+ /** @var Mage_Adminhtml_Model_System_Config_Source_Store $source */
199
+ $source = Mage::getSingleton('adminhtml/system_config_source_store');
200
+
201
+ return $source->toOptionArray();
202
  }
 
 
203
 
204
  /**
205
  * Retrieve Website Options
208
  */
209
  public function getWebsitesOptions()
210
  {
211
+ /** @var Mage_Adminhtml_Model_System_Config_Source_Website $source */
212
+ $source = Mage::getSingleton('adminhtml/system_config_source_website');
213
+
214
+ return $source->toOptionArray();
215
  }
 
 
 
 
216
 
217
+ /**
218
+ * @param string $type
219
+ *
220
+ * @return string
221
+ */
222
  public function getDefaultValueByType($type)
223
  {
224
+ switch ($type) {
225
+ case 'numeric':
226
+ return '1';
227
  }
228
  return '';
229
  }
230
+
231
+ /**
232
+ * @param string $type
233
+ *
234
+ * @return string
235
+ */
236
  public function getDefaultOperatorByType($type)
237
  {
238
+ switch ($type) {
239
+ case self::TYPE_BOOLEAN:
240
+ case self::TYPE_NUMERIC:
241
+ case self::TYPE_SELECT:
242
+ case self::TYPE_DATE:
243
  return '==';
244
+ case self::TYPE_MULTISELECT:
245
  return '()';
246
  }
247
  return '{}';
248
  }
249
+
 
 
250
  /**
251
  * Retrieve operators by type
252
+ *
253
  * @param string $type
254
  * @return array
255
  */
256
  public function getOperatorOptionsByType($type)
257
  {
258
  $operators = $this->getOperatorOptions();
259
+
260
+ if (isset($this->_operatorsByType[$type])) {
261
  return $this->getOperatorOptions($this->_operatorsByType[$type]);
262
  }
263
  return $operators;
264
  }
265
+
 
 
 
266
  /**
267
  * Retrieve operator options
268
+ *
269
+ * @param string[] $filter
270
+ *
271
+ * @return string[]
272
  */
273
  public function getOperatorOptions($filter = null)
274
  {
284
  '()' => $this->__('is one of'),
285
  '!()' => $this->__('is not one of')
286
  );
287
+
288
+ if (is_array($filter)) {
289
  $result = array();
290
+ foreach ($options as $key => $label) {
291
+ if (in_array($key, $filter)) {
292
  $result[$key] = $label;
293
  }
294
  }
295
  return $result;
296
  }
297
+
298
  return $options;
299
  }
300
+
 
 
 
 
 
301
  /**
302
  * Retrieve time unit options
303
  *
304
+ * @return string[]
 
305
  */
306
  public function getTimeUnitOptions()
307
  {
308
  return array(
309
+ self::TIME_UNIT_HOURS => $this->__('hour(s)'),
310
+ self::TIME_UNIT_DAYS => $this->__('day(s)'),
311
+ self::TIME_UNIT_WEEKS => $this->__('week(s)'),
312
+ self::TIME_UNIT_MONTHS => $this->__('month(s)'),
313
+ self::TIME_UNIT_YEARS => $this->__('year(s)')
314
  );
315
  }
316
+
 
 
 
317
  /**
318
  * Calculate date
319
  *
320
  * @param number $value
321
  * @param string $unit
322
+ * @param int $roundDate
323
+ * @param string $sign
324
+ *
325
  * @return Zend_Date
326
  */
327
+ public function calcDate($value, $unit, $roundDate = 0, $sign = '-')
328
  {
329
  // validate unit
330
+ if (!key_exists($unit, $this->getTimeUnitOptions())) {
331
  return null;
332
  }
333
+
334
  $timestamp = strtotime("{$sign}{$value} {$unit}");
335
+ if ($timestamp) {
336
+ // don't calculate with too high numbers (performance issue)
337
  $timestamp = min(max($timestamp, 0), 10000000000);
338
  $date = new Zend_Date;
339
  $date->setTimestamp($timestamp);
340
+
341
+ if ($roundDate === self::DAY_START) {
342
  $date->setHour(0);
343
  $date->setMinute(0);
344
  $date->setSecond(0);
345
+ } elseif ($roundDate === self::DAY_END) {
 
346
  $date->setHour(23);
347
  $date->setMinute(59);
348
  $date->setSecond(59);
349
  }
350
+
351
  return $date;
352
  }
353
+
354
  return null;
355
  }
 
 
 
 
 
 
356
  }
app/code/community/Mzax/Emarketing/Helper/Newsletter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,58 +17,46 @@
18
  */
19
 
20
 
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.4.10
29
  */
30
  class Mzax_Emarketing_Helper_Newsletter extends Mage_Core_Helper_Abstract
31
  {
32
-
33
-
34
-
35
  /**
36
  * Unsubscribe email from newsletter
37
- *
38
  * @param string $email
39
  * @param integer $storeId
40
- * @param boolean $sendUnsubscriptionEmail
 
41
  * @return Mage_Newsletter_Model_Subscriber
42
  */
43
- public function unsubscribe($email, $storeId, $sendUnsubscriptionEmail = false)
44
  {
45
- if(!$storeId) {
46
  $storeId = Mage::app()->getStore()->getId();
47
  }
48
-
49
  /* @var $subscriber Mage_Newsletter_Model_Subscriber */
50
  $subscriber = Mage::getModel('newsletter/subscriber');
51
  $subscriber->setStoreId($storeId);
52
  $subscriber->loadByEmail($email);
53
-
54
- if(!$subscriber->getId()) {
55
  $subscriber->setEmail($email);
56
  $subscriber->setSubscriberConfirmCode($subscriber->randomSequence());
57
  }
58
-
59
- if($subscriber->getStatus() != $subscriber::STATUS_UNSUBSCRIBED) {
60
  $subscriber->setIsStatusChanged(true);
61
  $subscriber->setChangeStatusAt(now());
62
  $subscriber->setSubscriberStatus($subscriber::STATUS_UNSUBSCRIBED)->save();
63
-
64
- if($sendUnsubscriptionEmail) {
65
  $subscriber->sendUnsubscriptionEmail();
66
  }
67
  }
68
-
69
  return $subscriber;
70
  }
71
-
72
-
73
-
74
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Helper_Newsletter
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Helper_Newsletter extends Mage_Core_Helper_Abstract
24
  {
 
 
 
25
  /**
26
  * Unsubscribe email from newsletter
27
+ *
28
  * @param string $email
29
  * @param integer $storeId
30
+ * @param boolean $sendUnSubscriptionEmail
31
+ *
32
  * @return Mage_Newsletter_Model_Subscriber
33
  */
34
+ public function unsubscribe($email, $storeId, $sendUnSubscriptionEmail = false)
35
  {
36
+ if (!$storeId) {
37
  $storeId = Mage::app()->getStore()->getId();
38
  }
39
+
40
  /* @var $subscriber Mage_Newsletter_Model_Subscriber */
41
  $subscriber = Mage::getModel('newsletter/subscriber');
42
  $subscriber->setStoreId($storeId);
43
  $subscriber->loadByEmail($email);
44
+
45
+ if (!$subscriber->getId()) {
46
  $subscriber->setEmail($email);
47
  $subscriber->setSubscriberConfirmCode($subscriber->randomSequence());
48
  }
49
+
50
+ if ($subscriber->getStatus() != $subscriber::STATUS_UNSUBSCRIBED) {
51
  $subscriber->setIsStatusChanged(true);
52
  $subscriber->setChangeStatusAt(now());
53
  $subscriber->setSubscriberStatus($subscriber::STATUS_UNSUBSCRIBED)->save();
54
+
55
+ if ($sendUnSubscriptionEmail) {
56
  $subscriber->sendUnsubscriptionEmail();
57
  }
58
  }
59
+
60
  return $subscriber;
61
  }
 
 
 
 
62
  }
app/code/community/Mzax/Emarketing/Helper/Request.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,159 +17,141 @@
18
  */
19
 
20
 
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.4.10
29
  */
30
  class Mzax_Emarketing_Helper_Request extends Mage_Core_Helper_Abstract
31
  {
32
  /**
33
- *
34
  * @var string
35
  */
36
  const CACHE_ID = 'mzax_emarketing_bad_requests';
37
-
38
-
39
  /**
40
- *
41
  * @var integer
42
  */
43
  const MAX_BAD_REQUESTS = 25;
44
-
45
-
46
  /**
47
- *
48
  * @var integer
49
  */
50
  const RESET_TIME = 3600;
51
-
52
-
53
  /**
54
- *
55
  * @var array
56
  */
57
  protected $_data;
58
-
59
-
60
-
61
  /**
62
  * Check if we can "trust" the request
63
- *
 
 
 
64
  * @param string $request
65
  * @return boolean
66
  */
67
  public function isTrustable($request = null)
68
  {
69
  $data = $this->getData($request);
 
70
  return ($data[0] < self::MAX_BAD_REQUESTS);
71
  }
72
-
73
-
74
-
75
  /**
76
  * Flag current connection
77
- *
78
  * if a connection (IP) has to many bad requests
79
  * then we should not trust them anymore with
80
- * any sensetive data
81
- *
82
  * @param string $request
 
83
  * @return number
84
  */
85
  public function bad($request = null)
86
  {
87
  $data = $this->getData($request);
88
-
89
  // reset counter if last bad request is a while ago
90
- if(time() - $data[1] >= self::RESET_TIME) {
91
  $data[0] = 0;
92
  }
93
-
94
  // increase
95
  $data[0]++;
96
  $data[1] = time();
97
-
98
  $this->setData($data, $request);
 
99
  return $data[0];
100
  }
101
-
102
-
103
-
104
 
105
  /**
106
  * Retrieve data for request
107
- *
108
  * @param string $request
 
109
  * @return array
110
  */
111
  public function getData($request = null)
112
  {
113
- if(!$request) {
114
  $request = Mage::app()->getRequest();
115
  }
116
  $ip = $request->getServer('REMOTE_ADDR');
117
-
118
  $data = $this->loadData();
119
-
120
- if( isset($data[$ip]) ) {
121
  return $data[$ip];
122
  }
123
-
124
  // no request yet made by this ip yet
125
  return array(0, time());
126
  }
127
-
128
-
129
-
130
  /**
131
  * Set dat for request
132
- *
133
  * @param array $data
134
  * @param string $request
 
 
135
  */
136
  public function setData(array $data, $request = null)
137
  {
138
- if(!$request) {
139
  $request = Mage::app()->getRequest();
140
  }
141
  $ip = $request->getServer('REMOTE_ADDR');
142
-
143
  $cacheData = $this->loadData();
144
  $cacheData[$ip] = $data;
145
  $this->saveData($cacheData);
146
  }
147
-
148
-
149
-
150
  /**
151
  * Load dat from cache
152
- *
153
  * @return array
154
  */
155
  public function loadData()
156
  {
157
- if(!$this->_data) {
158
  $this->_data = Mage::app()->loadCache(self::CACHE_ID);
159
- if($this->_data) {
160
  $this->_data = unserialize($this->_data);
161
- }
162
- else {
163
  $this->_data = array();
164
  }
165
  }
166
  return $this->_data;
167
  }
168
-
169
-
170
-
171
  /**
172
  * save data to cache
173
- *
174
  * @param array $data
175
  */
176
  public function saveData(array $data)
@@ -178,7 +159,4 @@ class Mzax_Emarketing_Helper_Request extends Mage_Core_Helper_Abstract
178
  $this->_data = $data;
179
  Mage::app()->saveCache(serialize($data), self::CACHE_ID);
180
  }
181
-
182
-
183
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Helper_Request
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Helper_Request extends Mage_Core_Helper_Abstract
24
  {
25
  /**
 
26
  * @var string
27
  */
28
  const CACHE_ID = 'mzax_emarketing_bad_requests';
29
+
 
30
  /**
 
31
  * @var integer
32
  */
33
  const MAX_BAD_REQUESTS = 25;
34
+
 
35
  /**
 
36
  * @var integer
37
  */
38
  const RESET_TIME = 3600;
39
+
 
40
  /**
 
41
  * @var array
42
  */
43
  protected $_data;
44
+
 
 
45
  /**
46
  * Check if we can "trust" the request
47
+ *
48
+ * If to any bad request have been logged for a given IP
49
+ * then it will be flagged for not trustable.
50
+ *
51
  * @param string $request
52
  * @return boolean
53
  */
54
  public function isTrustable($request = null)
55
  {
56
  $data = $this->getData($request);
57
+
58
  return ($data[0] < self::MAX_BAD_REQUESTS);
59
  }
60
+
 
 
61
  /**
62
  * Flag current connection
63
+ *
64
  * if a connection (IP) has to many bad requests
65
  * then we should not trust them anymore with
66
+ * any sensitive data
67
+ *
68
  * @param string $request
69
+ *
70
  * @return number
71
  */
72
  public function bad($request = null)
73
  {
74
  $data = $this->getData($request);
75
+
76
  // reset counter if last bad request is a while ago
77
+ if (time() - $data[1] >= self::RESET_TIME) {
78
  $data[0] = 0;
79
  }
80
+
81
  // increase
82
  $data[0]++;
83
  $data[1] = time();
84
+
85
  $this->setData($data, $request);
86
+
87
  return $data[0];
88
  }
 
 
 
89
 
90
  /**
91
  * Retrieve data for request
92
+ *
93
  * @param string $request
94
+ *
95
  * @return array
96
  */
97
  public function getData($request = null)
98
  {
99
+ if (!$request) {
100
  $request = Mage::app()->getRequest();
101
  }
102
  $ip = $request->getServer('REMOTE_ADDR');
103
+
104
  $data = $this->loadData();
105
+
106
+ if (isset($data[$ip])) {
107
  return $data[$ip];
108
  }
109
+
110
  // no request yet made by this ip yet
111
  return array(0, time());
112
  }
113
+
 
 
114
  /**
115
  * Set dat for request
116
+ *
117
  * @param array $data
118
  * @param string $request
119
+ *
120
+ * @return void
121
  */
122
  public function setData(array $data, $request = null)
123
  {
124
+ if (!$request) {
125
  $request = Mage::app()->getRequest();
126
  }
127
  $ip = $request->getServer('REMOTE_ADDR');
128
+
129
  $cacheData = $this->loadData();
130
  $cacheData[$ip] = $data;
131
  $this->saveData($cacheData);
132
  }
133
+
 
 
134
  /**
135
  * Load dat from cache
136
+ *
137
  * @return array
138
  */
139
  public function loadData()
140
  {
141
+ if (!$this->_data) {
142
  $this->_data = Mage::app()->loadCache(self::CACHE_ID);
143
+ if ($this->_data) {
144
  $this->_data = unserialize($this->_data);
145
+ } else {
 
146
  $this->_data = array();
147
  }
148
  }
149
  return $this->_data;
150
  }
151
+
 
 
152
  /**
153
  * save data to cache
154
+ *
155
  * @param array $data
156
  */
157
  public function saveData(array $data)
159
  $this->_data = $data;
160
  Mage::app()->saveCache(serialize($data), self::CACHE_ID);
161
  }
 
 
 
162
  }
app/code/community/Mzax/Emarketing/Helper/SqlFormatter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -282,7 +281,7 @@ class Mzax_Emarketing_Helper_SqlFormatter extends Mage_Core_Helper_Abstract
282
  }
283
  }
284
 
285
- if($ret[self::TOKEN_VALUE] !== null) return $ret;
286
  }
287
 
288
  // Number (decimal, binary, or hex)
@@ -716,9 +715,9 @@ class Mzax_Emarketing_Helper_SqlFormatter extends Mage_Core_Helper_Abstract
716
  }
717
 
718
  // If this is the "-" of a negative number, it shouldn't have a space after it
719
- if($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i+1]) && $tokens[$i+1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i-1])) {
720
  $prev = $tokens[$i-1][self::TOKEN_TYPE];
721
- if($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
722
  $return = rtrim($return,' ');
723
  }
724
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
281
  }
282
  }
283
 
284
+ if ($ret[self::TOKEN_VALUE] !== null) return $ret;
285
  }
286
 
287
  // Number (decimal, binary, or hex)
715
  }
716
 
717
  // If this is the "-" of a negative number, it shouldn't have a space after it
718
+ if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i+1]) && $tokens[$i+1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i-1])) {
719
  $prev = $tokens[$i-1][self::TOKEN_TYPE];
720
+ if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
721
  $return = rtrim($return,' ');
722
  }
723
  }
app/code/community/Mzax/Emarketing/Model/AbstractModel.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 this Extension in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mzax
13
+ * @package Mzax_Emarketing
14
+ * @author Jacob Siefer (jacob@mzax.de)
15
+ * @copyright Copyright (c) 2015 Jacob Siefer
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+
20
+ /**
21
+ * Class Mzax_Emarketing_Model_AbstractModel
22
+ */
23
+ abstract class Mzax_Emarketing_Model_AbstractModel
24
+ extends Mage_Core_Model_Abstract
25
+ {
26
+ /**
27
+ * @var Mzax_Emarketing_Model_Factory
28
+ */
29
+ protected $_factory;
30
+
31
+ /**
32
+ * Load dependencies
33
+ *
34
+ * @return void
35
+ */
36
+ protected function _construct()
37
+ {
38
+ parent::_construct();
39
+
40
+ $this->_factory = Mage::getSingleton('mzax_emarketing/factory');
41
+ }
42
+ }
app/code/community/Mzax/Emarketing/Model/Campaign.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,33 +17,36 @@
18
  */
19
 
20
 
 
 
21
 
22
  /**
23
  * Campaign
24
- *
25
- * @method Mzax_Emarketing_Model_Campaign setCreatedAt(string $value)
26
- * @method Mzax_Emarketing_Model_Campaign setUpdatedAt(string $value)
27
- * @method Mzax_Emarketing_Model_Campaign setStartAt(string $value)
28
- * @method Mzax_Emarketing_Model_Campaign setEndAt(string $value)
29
- * @method Mzax_Emarketing_Model_Campaign setRunning(string $value)
30
- * @method Mzax_Emarketing_Model_Campaign setAutologin(string $value)
31
- * @method Mzax_Emarketing_Model_Campaign setCheckFrequency(string $value)
32
- * @method Mzax_Emarketing_Model_Campaign setLastCheck(string $value)
33
- * @method Mzax_Emarketing_Model_Campaign setMinResendInterval(string $value)
34
- * @method Mzax_Emarketing_Model_Campaign setExpireTime(string $value)
35
- * @method Mzax_Emarketing_Model_Campaign setAbtestEnable(string $value)
36
- * @method Mzax_Emarketing_Model_Campaign setAbtestTraffic(string $value)
37
- * @method Mzax_Emarketing_Model_Campaign setStoreId(string $value)
38
- * @method Mzax_Emarketing_Model_Campaign setTemplateId(string $value)
39
- * @method Mzax_Emarketing_Model_Campaign setDefaultTrackerId(string $value)
40
- * @method Mzax_Emarketing_Model_Campaign setName(string $value)
41
- * @method Mzax_Emarketing_Model_Campaign setIdentity(string $value)
42
- * @method Mzax_Emarketing_Model_Campaign setProvider(string $value)
43
- * @method Mzax_Emarketing_Model_Campaign setFilterData(string $value)
44
- * @method Mzax_Emarketing_Model_Campaign setMediumJson(string $value)
45
- *
 
46
  * @method Mzax_Emarketing_Model_Resource_Campaign getResource()
47
- *
48
  * @method string getCreatedAt()
49
  * @method string getUpdatedAt()
50
  * @method string getStartAt()
@@ -72,59 +74,48 @@
72
  * @method string getConversionStats()
73
  * @method string getFailStats()
74
  * @method string getRevenueStats()
75
- *
76
- *
77
- * @author Jacob Siefer
78
- *
79
  */
80
- class Mzax_Emarketing_Model_Campaign
81
- extends Mage_Core_Model_Abstract
82
  implements Mzax_Emarketing_Model_Campaign_Content
83
  {
84
-
85
-
86
 
87
  const DEFAULT_EMAIL_PROVIDER = 'customers';
88
-
89
-
90
  const CACHE_TAG = 'MZAX_EMARKETING_CAMPAIGN';
91
-
92
-
93
- //protected $_cacheTag = self::CACHE_TAG;
94
 
95
-
 
 
 
 
96
  /**
97
  * Recipient provider
98
- *
99
- * @var Mzax_Emarketing_Model_Recipient_Provider_Abstract
100
  */
101
  protected $_provider;
102
-
103
-
104
-
105
  /**
106
  * Medium provider
107
- *
108
- * @var Mzax_Emarketing_Model_Medium_Abstract
109
  */
110
  protected $_medium;
111
-
112
-
113
  /**
114
  *
115
  * @var Varien_Object
116
  */
117
  protected $_mediumData;
118
-
119
-
120
  /**
121
  * Available variations
122
- *
123
  * @var Mzax_Emarketing_Model_Resource_Campaign_Variation_Collection
124
  */
125
  protected $_variations;
126
-
127
-
128
  /**
129
  * Prefix of model events names
130
  *
@@ -140,57 +131,52 @@ class Mzax_Emarketing_Model_Campaign
140
  * @var string
141
  */
142
  protected $_eventObject = 'campaign';
143
-
144
-
145
-
146
  /**
147
  *
148
  * @var Mzax_Emarketing_Model_Resource_Recipient_Collection
149
  */
150
  protected $_recipients;
151
-
152
-
153
-
154
  /**
 
155
  *
156
  * @var Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection
157
  */
158
  protected $_trackers;
159
-
160
 
161
  /**
 
162
  *
163
  * @var Mzax_Emarketing_Model_Conversion_Tracker
164
  */
165
  protected $_defaultTracker;
166
-
167
-
168
-
169
  /**
170
  * Store url model
171
  *
172
  * @var Mage_Core_Model_Url
173
  */
174
  protected $_urlModel;
175
-
176
-
177
-
178
-
179
-
 
180
  protected function _construct()
181
  {
 
 
182
  $this->_init('mzax_emarketing/campaign');
183
  $this->setMinResendInterval(0);
184
  $this->setCheckFrequency(720);
185
  $this->setExpireTime(720);
186
  $this->setIdentity('emarketing');
187
  }
188
-
189
-
190
 
191
-
192
-
193
  /**
 
194
  *
195
  * @return string
196
  */
@@ -198,71 +184,73 @@ class Mzax_Emarketing_Model_Campaign
198
  {
199
  return $this->_eventObject . '_' . $this->getId();
200
  }
201
-
202
-
203
-
204
-
 
 
 
205
  protected function _beforeSave()
206
  {
207
-
208
  parent::_beforeSave();
209
-
210
- if($this->_mediumData) {
211
  $this->setData('medium_json', $this->_mediumData->toJson());
212
  }
213
-
214
- if($this->_provider) {
215
  $this->setProvider($this->_provider->getType());
216
  $this->setFilterData($this->_provider->getFilter()->asJson());
217
  }
218
-
219
- if(!$this->getData('medium')) {
220
  throw new Exception("Campaign must define a medium");
221
  }
222
- if(!$this->getData('provider')) {
223
  throw new Exception("Campaign must define a recipient provider");
224
  }
225
-
226
  }
227
-
228
-
229
 
 
 
 
 
 
230
  protected function _afterSave()
231
  {
232
  parent::_afterSave();
233
-
234
  // save all variations if loaded
235
- if( $this->_variations ) {
236
  $this->_variations->save();
237
  }
238
-
239
- if( $variations = $this->getClonedVariations() ) {
240
- foreach($variations as $variation) {
 
 
 
241
  $variation->save();
242
  }
243
- $this->setClonedVariations(false);
244
  }
245
  }
246
-
247
 
248
  /**
249
  * Processing object after load data
250
  *
251
- * @return Mage_Core_Model_Abstract
252
  */
253
  protected function _afterLoad()
254
  {
255
- if($filters = $this->getData('filters')) {
 
256
  $this->setFilters($filters);
257
  }
258
  }
259
-
260
-
261
 
262
-
263
-
264
-
265
-
266
  /**
267
  * Retrieve store object
268
  *
@@ -270,89 +258,105 @@ class Mzax_Emarketing_Model_Campaign
270
  */
271
  public function getStore()
272
  {
273
- return Mage::app()->getStore($this->getStoreId());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  }
275
-
276
-
277
-
278
  /**
279
  * Retrieve URL model
280
- *
281
  * @return Mage_Core_Model_Url
282
  */
283
  public function getUrlModel()
284
  {
285
- if(!$this->_urlModel) {
286
- $this->_urlModel = Mage::getModel('core/url')->setStore($this->getStore());
 
287
  }
288
  return $this->_urlModel;
289
  }
290
-
291
-
292
-
293
-
294
-
295
  /**
296
  * Is campaign archived
297
  *
298
- * @return boolean
299
- */
 
 
300
  public function isArchived($flag = null)
301
  {
302
- if(is_bool($flag)) {
303
  $this->setData('archived', $flag ? 1 : 0);
304
  }
305
- return (boolean) $this->getData('archived');
 
306
  }
307
-
308
-
309
-
310
-
311
  /**
312
  * Is campaign currently running
313
  *
314
- * @return boolean
 
 
315
  */
316
  public function isRunning($flag = null)
317
  {
318
- if(is_bool($flag)) {
319
  $this->setData('running', $flag ? 1 : 0);
320
  }
321
- return (boolean) $this->getData('running');
 
322
  }
323
-
324
-
325
-
326
-
 
 
327
  public function start()
328
  {
329
  $this->isRunning(true);
 
330
  return $this;
331
  }
332
-
333
-
334
  /**
335
  * Will not just stop but also remove any
336
  * already queued recipients
337
- *
338
- * @return Mzax_Emarketing_Model_Campaign
339
  */
340
  public function stop()
341
  {
342
  $this->isRunning(false);
343
-
344
  /* @see Mzax_Emarketing_Model_Resource_Recipient */
345
  Mage::getResourceSingleton('mzax_emarketing/recipient')->removePending($this->getId());
346
-
347
  return $this;
348
  }
349
-
350
-
351
-
352
-
353
  /**
354
  * check if the campaign is valid for sending
355
- *
356
  * @deprecated
357
  * @return boolean
358
  */
@@ -360,12 +364,10 @@ class Mzax_Emarketing_Model_Campaign
360
  {
361
  return true;
362
  }
363
-
364
-
365
-
366
  /**
367
  * Is a plain text email campaign
368
- *
369
  * @deprecated
370
  * @return boolean
371
  */
@@ -373,57 +375,55 @@ class Mzax_Emarketing_Model_Campaign
373
  {
374
  return false;
375
  }
376
-
377
-
378
-
379
-
380
  /**
381
  * Retrieve tags
382
- *
383
- * @return array
384
  */
385
  public function getTags()
386
  {
387
  $data = $this->getData('tags');
 
388
  return preg_split('/[\s,]+/', $data, -1, PREG_SPLIT_NO_EMPTY);
389
  }
390
-
391
-
392
  /**
393
  * Set tags
394
- *
395
- * @param string|array $value
396
- * @return Mzax_Emarketing_Model_Campaign
 
397
  */
398
  public function setTags($value)
399
  {
400
- if(is_array($value)) {
401
  $value = array_unique($value);
402
  $value = implode(',', $value);
403
  }
404
- return $this->setData('tags', $value);
 
 
405
  }
406
-
407
-
408
  /**
409
  * Add tags to campaign
410
- *
411
  * @param string|array $tags
412
  * @return Mzax_Emarketing_Model_Campaign
413
  */
414
  public function addTags($tags)
415
  {
416
- if(is_string($tags)) {
417
  $tags = preg_split('/[\s,]+/', $tags, -1, PREG_SPLIT_NO_EMPTY);
418
  }
419
- if(is_array($tags)) {
420
  $tags = array_merge($this->getTags(), $tags);
421
  $this->setTags($tags);
422
  }
423
  return $this;
424
  }
425
-
426
-
427
  /**
428
  * Remove tags from campaign
429
  *
@@ -432,42 +432,56 @@ class Mzax_Emarketing_Model_Campaign
432
  */
433
  public function removeTags($tags)
434
  {
435
- if(is_string($tags)) {
436
  $tags = preg_split('/[\s,]+/', $tags, -1, PREG_SPLIT_NO_EMPTY);
437
  }
438
- if(is_array($tags)) {
439
  $tags = array_diff($this->getTags(), $tags);
440
  $this->setTags($tags);
441
  }
442
  return $this;
443
  }
444
-
445
-
446
 
447
  //--------------------------------------------------------------------------
448
  //
449
  // Medium
450
  //
451
  //--------------------------------------------------------------------------
452
-
453
-
454
-
455
-
456
  /**
457
  * Retrieve medium
458
  *
459
- * @return Mzax_Emarketing_Model_Medium_Abstract
460
  */
461
  public function getMedium()
462
  {
463
- if(!$this->_medium && $this->getData('medium')) {
464
- $this->_medium = Mage::getSingleton('mzax_emarketing/medium')->factory($this->getData('medium'));
 
 
465
  }
 
466
  return $this->_medium;
467
  }
468
-
469
-
470
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
 
472
  /**
473
  * Retrieve content data
@@ -476,61 +490,68 @@ class Mzax_Emarketing_Model_Campaign
476
  */
477
  public function getMediumData()
478
  {
479
- if(!$this->_mediumData) {
480
- if($data = $this->getMediumJson()) {
481
- $data = Zend_Json::decode($data);
 
 
482
  $this->_mediumData = new Varien_Object($data);
483
- }
484
- else {
485
  $this->_mediumData = new Varien_Object;
486
  }
487
  $this->setDataChanges(true);
488
  }
 
489
  return $this->_mediumData;
490
  }
491
-
492
-
493
-
494
-
495
  //--------------------------------------------------------------------------
496
  //
497
  // Provider
498
  //
499
  //--------------------------------------------------------------------------
500
-
501
-
502
-
503
  /**
504
  * Retrieve all available recipient provider options
505
- *
506
  * @return array
507
  */
508
  public function getAvailableProviders()
509
  {
510
  return self::getProviderFactory()->getAllOptions(false);
511
  }
512
-
513
-
514
 
515
-
516
  /**
517
  * Retrieve recipient provider for this campaign
518
- *
519
- * @return Mzax_Emarketing_Model_Recipient_Provider_Abstract
520
  */
521
  public function getRecipientProvider()
522
  {
523
- if(!$this->_provider && $this->getData('provider')) {
524
  $type = $this->getData('provider');
525
- $this->_provider = self::getProviderFactory()
526
- ->factory($this->getData('provider'))
527
- ->setCampaign($this);
528
  }
 
529
  return $this->_provider;
530
  }
531
-
532
-
533
-
 
 
 
 
 
 
 
 
 
 
 
 
534
 
535
  /**
536
  * Retrieve provider factory
@@ -541,14 +562,10 @@ class Mzax_Emarketing_Model_Campaign
541
  {
542
  return Mage::getSingleton('mzax_emarketing/recipient_provider');
543
  }
544
-
545
-
546
-
547
-
548
-
549
  /**
550
  * Retrieve filter by id
551
- *
552
  * @param string $id e.g. 1-1-2-3-1-2
553
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
554
  */
@@ -556,77 +573,63 @@ class Mzax_Emarketing_Model_Campaign
556
  {
557
  return $this->getRecipientProvider()->getFilterById($id);
558
  }
559
-
560
-
561
-
562
-
563
-
564
-
565
-
566
 
567
  //--------------------------------------------------------------------------
568
  //
569
  // Email
570
  //
571
  //--------------------------------------------------------------------------
572
-
573
-
574
-
575
-
576
  /**
577
  * Retrieve magento email sender
578
- *
579
  * @return array
580
  */
581
  public function getSender()
582
  {
583
  $sender = $this->getData('sender');
584
- if(empty($sender)) {
585
  $sender = $this->getIdentity();
586
  }
587
 
588
  if (!is_array($sender)) {
 
 
 
589
  $sender = array(
590
- 'name' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/name', $this->getStore()),
591
- 'email' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/email', $this->getStore()),
592
  );
593
  }
594
- $this->setSender($sender);
 
595
  return $sender;
596
  }
597
-
598
-
599
-
600
-
601
-
602
-
603
  /**
604
  * Create a mock recipient instance
605
- *
606
- * @param string $entityId Target entity id
607
  * @return Mzax_Emarketing_Model_Recipient
608
  */
609
  public function createMockRecipient($objectId = null)
610
  {
611
  /* @var $recipient Mzax_Emarketing_Model_Recipient */
612
- $recipient = Mage::getModel('mzax_emarketing/recipient');
613
  $recipient->setCampaign($this);
614
  $recipient->setObjectId($objectId);
615
  $recipient->isMock(true);
616
-
617
  return $recipient;
618
  }
619
-
620
-
621
-
622
-
623
  /**
624
  * Prepare recipient
625
- *
626
  * before we send out an email and prepare the template
627
  * we will give the email provider and the filters a chance to prepare the recipient
628
  * to add any data usefull information
629
- *
630
  * @param Mzax_Emarketing_Model_Recipient $recipient
631
  * @return Mzax_Emarketing_Model_Campaign
632
  */
@@ -634,201 +637,178 @@ class Mzax_Emarketing_Model_Campaign
634
  {
635
  $this->getRecipientProvider()->prepareRecipient($recipient);
636
  $this->getMedium()->prepareRecipient($recipient);
 
637
  return $this;
638
  }
639
-
640
 
641
-
642
-
643
  /**
644
  * Retrieve campaign content
645
- *
646
  * If ab-testing is enabled we need to retrieve
647
  * a random variation
648
  *
 
 
649
  * @return Mzax_Emarketing_Model_Campaign_Content
650
  */
651
  public function getContent($variationId = null)
652
  {
653
- if($variationId !== null) {
654
- // if zero, use orginal campaign
655
- if($variationId == Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL) {
656
  return $this;
657
  }
658
-
659
  $variation = $this->getVariation($variationId);
660
- if(!$variation) {
661
  return $this;
662
  }
663
  return $variation;
664
  }
665
-
666
  $this->setVariationId(Mzax_Emarketing_Model_Campaign_Variation::NONE);
667
-
668
  // check if ab-testing is enabled
669
- if(!$this->getAbtestEnable() && $this->getAbtestTraffic() > 0) {
670
  return $this;
671
  }
672
-
673
  // include include in test?
674
- if(mt_rand(0,999)/10 >= $this->getAbtestTraffic()) {
675
  return $this;
676
  }
677
-
678
  $this->setVariationId(Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL);
679
  $active = array($this);
680
-
681
  /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
682
- foreach($this->getVariations() as $variation) {
683
- if($variation->getIsActive()) {
684
  $active[] = $variation;
685
  }
686
  }
687
-
688
- // pick randrom content
689
  return $active[array_rand($active)];
690
  }
691
-
692
-
693
-
694
-
695
-
696
  /**
697
  * Retrieve available snippets for the content manager
698
- *
699
  * @return Mzax_Emarketing_Model_Medium_Email_Snippets
700
  */
701
  public function getSnippets()
702
  {
703
- /* @var $snippets Mzax_Emarketing_Model_Medium_Email_Snippets */
704
- $snippets = Mage::getModel('mzax_emarketing/medium_email_snippets');
705
-
706
- if($this->getRecipientProvider()) {
707
  $this->getRecipientProvider()->prepareSnippets($snippets);
708
  }
709
- if($this->getMedium()) {
710
  $this->getMedium()->prepareSnippets($snippets);
711
  }
712
  $this->getMedium()->prepareSnippets($snippets);
713
-
714
  return $snippets;
715
  }
716
-
717
-
718
-
719
-
720
  //--------------------------------------------------------------------------
721
  //
722
  // Variations
723
  //
724
  //--------------------------------------------------------------------------
725
-
726
-
727
-
728
  /**
729
- * Check if campagin has any variations
730
- *
731
  * @return int
732
  */
733
  public function hasVariations()
734
  {
735
  return count($this->getVariations());
736
  }
737
-
738
-
739
-
740
-
741
-
742
-
743
  /**
744
  * Retrieve all variations
745
- *
746
  * @return Mzax_Emarketing_Model_Resource_Campaign_Variation_Collection
747
  */
748
  public function getVariations()
749
  {
750
- if(!$this->_variations) {
751
- $this->_variations = Mage::getResourceModel('mzax_emarketing/campaign_variation_collection');
752
  $this->_variations->addCampaignFilter($this);
753
  }
 
754
  return $this->_variations;
755
  }
756
-
757
-
758
-
759
-
760
-
761
  /**
762
  * Retrieve variation by id
763
- *
764
  * @param string $id
 
765
  * @return Mzax_Emarketing_Model_Campaign_Variation
766
  */
767
  public function getVariation($id)
768
  {
769
- return $this->getVariations()->getItemById($id);
 
 
770
  }
771
-
772
-
773
-
774
-
775
  /**
776
  * Create new variation
777
- *
778
- * @param bool $save
779
  * @return Mzax_Emarketing_Model_Campaign_Variation
780
  */
781
  public function createVariation()
782
  {
783
  $variations = $this->getVariations();
784
-
785
- /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
786
- $variation = Mage::getModel('mzax_emarketing/campaign_variation');
787
  $variation->setCampaign($this);
788
  $variation->setName('Variation ' . (count($variations)+1));
789
  $variation->setMediumJson($this->getMediumJson());
790
-
791
  return $variation;
792
  }
793
-
794
-
795
  //--------------------------------------------------------------------------
796
  //
797
  // Trackers
798
  //
799
  //--------------------------------------------------------------------------
800
 
801
-
802
-
803
-
804
  /**
805
  * Retrieve all conversion trackers
806
- *
807
  * @return Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection
808
  */
809
  public function getTrackers()
810
  {
811
- if(!$this->_trackers) {
812
- $this->_trackers = Mage::getResourceModel('mzax_emarketing/conversion_tracker_collection');
813
  $this->_trackers->addCampaignFilter($this);
814
  $this->_trackers->addActiveFilter();
815
  }
 
816
  return $this->_trackers;
817
  }
818
-
819
-
820
  /**
821
  * Retrieve tracker by id
822
- *
823
  * @param string $id
 
824
  * @return Mzax_Emarketing_Model_Conversion_Tracker
825
  */
826
  public function getTracker($id)
827
  {
828
- return $this->getTrackers()->getItemById($id);
 
 
829
  }
830
-
831
-
832
 
833
  /**
834
  * Retrieve default tracker for this campaign
@@ -837,31 +817,27 @@ class Mzax_Emarketing_Model_Campaign
837
  */
838
  public function getDefaultTracker()
839
  {
840
- if(!$this->_defaultTracker) {
841
  $tracker = $this->getTracker($this->getDefaultTrackerId());
842
- if(!$tracker) {
843
- foreach($this->getTrackers() as $tracker) {
844
- if($tracker->isDefault()) {
845
  break;
846
  }
847
  }
848
  }
849
  $this->_defaultTracker = $tracker;
850
  }
 
851
  return $this->_defaultTracker;
852
  }
853
-
854
-
855
-
856
-
857
 
858
  //--------------------------------------------------------------------------
859
  //
860
  // Recipients
861
  //
862
  //--------------------------------------------------------------------------
863
-
864
-
865
  /**
866
  * Check number of recipients
867
  *
@@ -870,100 +846,89 @@ class Mzax_Emarketing_Model_Campaign
870
  public function countRecipients()
871
  {
872
  $count = $this->getData('recipients_count');
873
- if($count === null) {
874
  $count = $this->getResource()->countRecipients($this);
875
  $this->setData('recipients_count', $count);
876
  }
 
877
  return $count;
878
  }
879
-
880
-
881
-
882
-
883
  /**
884
  * Try to bind recipients to goals
885
- *
886
  * The recipient provider has to do that
887
- *
888
  * @param Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder
889
- * @return Mzax_Emarketing_Model_Campaign
 
890
  */
891
  public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
892
  {
893
- if($provider = $this->getRecipientProvider()) {
894
  $provider->bindRecipients($binder);
895
  }
 
896
  return $this;
897
  }
898
-
899
-
900
-
901
-
902
  /**
903
  * Find and queue new recipients for this campaign that
904
  * match the current filters
905
- *
906
- * @return integer the number of recipients found
 
 
907
  */
908
  public function findRecipients($force = false)
909
  {
910
- if($force || $this->getRunning()) {
911
- $this->setCurrentTime(null);
912
  return $this->getResource()->findRecipients($this);
913
  }
 
914
  return 0;
915
  }
916
-
917
-
918
-
919
-
920
-
921
-
922
-
923
  /**
924
  * Retrieve all recipients for this campaign
925
- *
926
  * @return Mzax_Emarketing_Model_Resource_Recipient_Collection
927
  */
928
  public function getRecipients()
929
  {
930
- if($this->_recipients) {
931
- $this->_recipients = Mage::getResourceModel('mzax_emarketing/recipient_collection');
932
  $this->_recipients->setCampaign($this);
933
  }
934
  return $this->_recipients;
935
  }
936
-
937
-
938
-
939
-
940
-
941
  /**
942
  * Retrieve all recipients that have not yet been send
943
- *
944
  * @return Mzax_Emarketing_Model_Resource_Recipient_Collection
945
  */
946
  public function getPendingRecipients()
947
  {
948
- /* @var $recipients Mzax_Emarketing_Model_Resource_Recipient_Collection */
949
- $recipients = Mage::getResourceModel('mzax_emarketing/recipient_collection');
950
  $recipients->setCampaign($this);
951
  $recipients->addPrepareFilter(false);
952
-
953
  return $recipients;
954
  }
955
-
956
-
957
-
958
-
959
  /**
960
  * Prepare pending recipients and move them to
961
  * the email outbox
962
  * This will render all emails and makes them ready
963
  * to get send
964
- *
965
  * @see Mzax_Emarketing_Model_Outbox
966
- * @return integer Number of prepared recipients
 
 
 
967
  */
968
  public function sendRecipients($options = array())
969
  {
@@ -971,17 +936,14 @@ class Mzax_Emarketing_Model_Campaign
971
  $options->getDataSetDefault('timeout', 300);
972
  $options->getDataSetDefault('maximum', 500);
973
  $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
974
-
975
- if($this->getId() && $this->getRecipientProvider() && $this->getMedium()) {
976
  return $this->getMedium()->sendRecipients($this, $options);
977
  }
 
978
  return 0;
979
  }
980
-
981
-
982
-
983
-
984
-
985
  /**
986
  * Retrieve number of recipient errors
987
  *
@@ -990,39 +952,36 @@ class Mzax_Emarketing_Model_Campaign
990
  public function countRecipientErrors()
991
  {
992
  $count = $this->getData('recipient_errors_count');
993
- if($count === null) {
994
  $count = $this->getResource()->countRecipientErrors($this);
995
  $this->setData('recipient_errors_count', $count);
996
  }
 
997
  return $count;
998
  }
999
-
1000
-
1001
-
1002
-
1003
  //--------------------------------------------------------------------------
1004
  //
1005
  // Inbox/Outbox
1006
  //
1007
  //--------------------------------------------------------------------------
1008
-
1009
  /**
1010
  * Check number of messages in inbox
1011
- *
1012
  * @return integer
1013
  */
1014
  public function countInbox()
1015
  {
1016
  $count = $this->getData('inbox_count');
1017
- if($count === null) {
1018
  $count = $this->getResource()->countInbox($this);
1019
  $this->setData('inbox_count', $count);
1020
  }
 
1021
  return $count;
1022
  }
1023
 
1024
-
1025
-
1026
  /**
1027
  * Check number of messages in outbox
1028
  *
@@ -1031,26 +990,19 @@ class Mzax_Emarketing_Model_Campaign
1031
  public function countOutbox()
1032
  {
1033
  $count = $this->getData('outbox_count');
1034
- if($count === null) {
1035
  $count = $this->getResource()->countOutbox($this);
1036
  $this->setData('outbox_count', $count);
1037
  }
 
1038
  return $count;
1039
  }
1040
-
1041
-
1042
-
1043
-
1044
-
1045
-
1046
-
1047
  //--------------------------------------------------------------------------
1048
  //
1049
  // Report
1050
  //
1051
  //--------------------------------------------------------------------------
1052
-
1053
-
1054
 
1055
  /**
1056
  * Aggregate data for this campaign
@@ -1064,82 +1016,68 @@ class Mzax_Emarketing_Model_Campaign
1064
  'campaign_id' => $this->getId(),
1065
  'verbose' => false
1066
  ));
1067
-
1068
- Mage::dispatchEvent($this->_eventPrefix . '_aggregate',
1069
- array('options' => $options, 'campaign' => $this));
1070
-
1071
- if($incremental) {
1072
- $options->setIncremental((int) $incremental);
 
 
1073
  }
1074
-
1075
  /* @var $report Mzax_Emarketing_Model_Report */
1076
  $report = Mage::getSingleton('mzax_emarketing/report');
1077
  $report->aggregate($options->toArray());
1078
-
1079
  return $this;
1080
  }
1081
-
1082
-
1083
-
1084
-
1085
-
1086
-
1087
-
1088
  /**
1089
  * Retrieve a new report query instance
1090
- *
1091
  * @param string $dimension
1092
  * @param array $metrics
1093
- * @param boolean $variation
 
 
1094
  * @return Mzax_Emarketing_Model_Report_Query
1095
  */
1096
  public function queryReport($dimension = 'campaign', $metrics = array('sendings', 'views', 'clicks'), $variations = false, $order = null)
1097
  {
1098
  $metrics = (array) $metrics;
1099
-
1100
  // replace default tracker id
1101
- foreach($metrics as $key => $metric) {
1102
- if( strpos($metric,'#?') !== false) {
1103
- if($tracker = $this->getDefaultTracker()) {
1104
  $metrics[$key] = str_replace('#?', '#' . $tracker->getId(), $metric);
1105
- }
1106
- else {
1107
  unset($metrics[$key]);
1108
  }
1109
  }
1110
- if($metric instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
1111
  $metrics[$key] = '#' . $metric->getId();
1112
  }
1113
  }
1114
-
1115
  /* @var $query Mzax_Emarketing_Model_Report_Query */
1116
  $query = Mage::getModel('mzax_emarketing/report_query');
1117
- $query->setParam('campaign', $this->getId());
1118
- $query->setParam('dimension', $dimension);
1119
- $query->setParam('metrics', $metrics);
1120
  $query->setParam('variations', $variations);
1121
- $query->setParam('order', $order);
1122
-
1123
-
1124
  return $query;
1125
  }
1126
-
1127
-
1128
-
1129
 
1130
-
1131
-
1132
-
1133
-
1134
-
1135
  //--------------------------------------------------------------------------
1136
  //
1137
  // Misc
1138
  //
1139
  //--------------------------------------------------------------------------
1140
-
1141
-
1142
-
1143
  /**
1144
  * Convert to campaign to encoded string
1145
  *
@@ -1147,55 +1085,66 @@ class Mzax_Emarketing_Model_Campaign
1147
  */
1148
  public function export()
1149
  {
1150
- // set current extension version
1151
- $this->setVersion(Mage::helper('mzax_emarketing')->getVersion());
1152
-
1153
  $filterData = $this->getRecipientProvider()->export();
1154
- $this->setFilterExport(Zend_Json::encode($filterData));
1155
-
1156
- $json = $this->toJson(array(
1157
- 'version',
1158
- 'name',
1159
- 'description',
1160
- 'check_frequency',
1161
- 'min_resend_interval',
1162
- 'autologin',
1163
- 'expire_time',
1164
- 'provider',
1165
- 'filter_export',
1166
- 'medium',
1167
- 'medium_json'));
1168
-
1169
- return base64_encode($json);
 
 
 
 
 
 
 
1170
  }
1171
-
1172
-
1173
-
 
 
 
 
 
1174
  public function __clone()
1175
  {
 
 
1176
  $variations = array();
1177
- foreach($this->getVariations() as $variation) {
1178
  $newVariation = clone $variation;
1179
  $newVariation->setCampaign($this);
1180
  $variations[] = $newVariation;
1181
  }
1182
  $this->_variations = null;
1183
-
1184
- $this->setDuplicateOf($this->getId());
1185
  $this->setId(null);
1186
  $this->setCreatedAt(null);
1187
  $this->setUpdatedAt(null);
1188
- $this->setClonedVariations($variations);
 
1189
 
1190
  // reset aggregated statistics
1191
- $this->setSendingStats(null);
1192
- $this->setViewStats(null);
1193
- $this->setInteractionStats(null);
1194
- $this->setConversionStats(null);
1195
- $this->setFailStats(null);
1196
- $this->setRevenueStats(null);
1197
-
1198
  }
1199
-
1200
-
1201
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ use Mzax_Emarketing_Model_Medium_Abstract as Medium;
21
+ use Mzax_Emarketing_Model_Recipient_Provider_Abstract as RecipientProvider;
22
 
23
  /**
24
  * Campaign
25
+ *
26
+ * @method $this setCreatedAt(string $value)
27
+ * @method $this setUpdatedAt(string $value)
28
+ * @method $this setStartAt(string $value)
29
+ * @method $this setEndAt(string $value)
30
+ * @method $this setRunning(string $value)
31
+ * @method $this setAutologin(string $value)
32
+ * @method $this setCheckFrequency(string $value)
33
+ * @method $this setLastCheck(string $value)
34
+ * @method $this setMinResendInterval(string $value)
35
+ * @method $this setExpireTime(string $value)
36
+ * @method $this setAbtestEnable(string $value)
37
+ * @method $this setAbtestTraffic(string $value)
38
+ * @method $this setStoreId(string $value)
39
+ * @method $this setTemplateId(string $value)
40
+ * @method $this setDefaultTrackerId(string $value)
41
+ * @method $this setName(string $value)
42
+ * @method $this setIdentity(string $value)
43
+ * @method $this setProvider(string $value)
44
+ * @method $this setFilterData(string $value)
45
+ * @method $this setMediumJson(string $value)
46
+ * @method $this setVariationId(string $value)
47
+ *
48
  * @method Mzax_Emarketing_Model_Resource_Campaign getResource()
49
+ *
50
  * @method string getCreatedAt()
51
  * @method string getUpdatedAt()
52
  * @method string getStartAt()
74
  * @method string getConversionStats()
75
  * @method string getFailStats()
76
  * @method string getRevenueStats()
77
+ * @method string getVariationId()
 
 
 
78
  */
79
+ class Mzax_Emarketing_Model_Campaign
80
+ extends Mzax_Emarketing_Model_AbstractModel
81
  implements Mzax_Emarketing_Model_Campaign_Content
82
  {
 
 
83
 
84
  const DEFAULT_EMAIL_PROVIDER = 'customers';
 
 
85
  const CACHE_TAG = 'MZAX_EMARKETING_CAMPAIGN';
 
 
 
86
 
87
+ /**
88
+ * @var Mage_Core_Model_Store
89
+ */
90
+ protected $_store;
91
+
92
  /**
93
  * Recipient provider
94
+ *
95
+ * @var RecipientProvider
96
  */
97
  protected $_provider;
98
+
 
 
99
  /**
100
  * Medium provider
101
+ *
102
+ * @var Medium
103
  */
104
  protected $_medium;
105
+
 
106
  /**
107
  *
108
  * @var Varien_Object
109
  */
110
  protected $_mediumData;
111
+
 
112
  /**
113
  * Available variations
114
+ *
115
  * @var Mzax_Emarketing_Model_Resource_Campaign_Variation_Collection
116
  */
117
  protected $_variations;
118
+
 
119
  /**
120
  * Prefix of model events names
121
  *
131
  * @var string
132
  */
133
  protected $_eventObject = 'campaign';
134
+
 
 
135
  /**
136
  *
137
  * @var Mzax_Emarketing_Model_Resource_Recipient_Collection
138
  */
139
  protected $_recipients;
140
+
 
 
141
  /**
142
+ * Available trackers for this campaign
143
  *
144
  * @var Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection
145
  */
146
  protected $_trackers;
 
147
 
148
  /**
149
+ * Default campaign tracker
150
  *
151
  * @var Mzax_Emarketing_Model_Conversion_Tracker
152
  */
153
  protected $_defaultTracker;
154
+
 
 
155
  /**
156
  * Store url model
157
  *
158
  * @var Mage_Core_Model_Url
159
  */
160
  protected $_urlModel;
161
+
162
+ /**
163
+ * Construct.
164
+ *
165
+ * @return void
166
+ */
167
  protected function _construct()
168
  {
169
+ parent::_construct();
170
+
171
  $this->_init('mzax_emarketing/campaign');
172
  $this->setMinResendInterval(0);
173
  $this->setCheckFrequency(720);
174
  $this->setExpireTime(720);
175
  $this->setIdentity('emarketing');
176
  }
 
 
177
 
 
 
178
  /**
179
+ * Retrieve cache id
180
  *
181
  * @return string
182
  */
184
  {
185
  return $this->_eventObject . '_' . $this->getId();
186
  }
187
+
188
+ /**
189
+ * Before campaign save
190
+ *
191
+ * @return void
192
+ * @throws Exception
193
+ */
194
  protected function _beforeSave()
195
  {
196
+
197
  parent::_beforeSave();
198
+
199
+ if ($this->_mediumData) {
200
  $this->setData('medium_json', $this->_mediumData->toJson());
201
  }
202
+
203
+ if ($this->_provider) {
204
  $this->setProvider($this->_provider->getType());
205
  $this->setFilterData($this->_provider->getFilter()->asJson());
206
  }
207
+
208
+ if (!$this->getData('medium')) {
209
  throw new Exception("Campaign must define a medium");
210
  }
211
+ if (!$this->getData('provider')) {
212
  throw new Exception("Campaign must define a recipient provider");
213
  }
 
214
  }
 
 
215
 
216
+ /**
217
+ * After campaign save
218
+ *
219
+ * @return void
220
+ */
221
  protected function _afterSave()
222
  {
223
  parent::_afterSave();
224
+
225
  // save all variations if loaded
226
+ if ($this->_variations) {
227
  $this->_variations->save();
228
  }
229
+
230
+ /** @var Mzax_Emarketing_Model_Campaign_Variation[] $variations */
231
+ $variations = $this->getData('cloned_variations');
232
+
233
+ if ($variations) {
234
+ foreach ($variations as $variation) {
235
  $variation->save();
236
  }
237
+ $this->unsetData('cloned_variations');
238
  }
239
  }
 
240
 
241
  /**
242
  * Processing object after load data
243
  *
244
+ * @return void
245
  */
246
  protected function _afterLoad()
247
  {
248
+ if ($filters = $this->getData('filters')) {
249
+ // @todo what does this do?
250
  $this->setFilters($filters);
251
  }
252
  }
 
 
253
 
 
 
 
 
254
  /**
255
  * Retrieve store object
256
  *
258
  */
259
  public function getStore()
260
  {
261
+ if (!$this->_store) {
262
+ $this->_store = Mage::app()->getStore($this->getStoreId());
263
+ }
264
+
265
+ return $this->_store;
266
+ }
267
+
268
+ /**
269
+ * Set store
270
+ *
271
+ * @param Mage_Core_Model_Store $store
272
+ *
273
+ * @return $this
274
+ */
275
+ public function setStore(Mage_Core_Model_Store $store)
276
+ {
277
+ $this->_store = $store;
278
+ $this->setStoreId($store->getId());
279
+
280
+ return $this;
281
  }
282
+
 
 
283
  /**
284
  * Retrieve URL model
285
+ *
286
  * @return Mage_Core_Model_Url
287
  */
288
  public function getUrlModel()
289
  {
290
+ if (!$this->_urlModel) {
291
+ $this->_urlModel = $this->_factory->createUrl();
292
+ $this->_urlModel->setStore($this->getStore());
293
  }
294
  return $this->_urlModel;
295
  }
296
+
 
 
 
 
297
  /**
298
  * Is campaign archived
299
  *
300
+ * @param null|bool $flag
301
+ *
302
+ * @return bool
303
+ */
304
  public function isArchived($flag = null)
305
  {
306
+ if (is_bool($flag)) {
307
  $this->setData('archived', $flag ? 1 : 0);
308
  }
309
+
310
+ return (boolean)$this->getData('archived');
311
  }
312
+
 
 
 
313
  /**
314
  * Is campaign currently running
315
  *
316
+ * @param null|bool $flag
317
+ *
318
+ * @return bool
319
  */
320
  public function isRunning($flag = null)
321
  {
322
+ if (is_bool($flag)) {
323
  $this->setData('running', $flag ? 1 : 0);
324
  }
325
+
326
+ return (boolean)$this->getData('running');
327
  }
328
+
329
+ /**
330
+ * Start campaign
331
+ *
332
+ * @return $this
333
+ */
334
  public function start()
335
  {
336
  $this->isRunning(true);
337
+
338
  return $this;
339
  }
340
+
 
341
  /**
342
  * Will not just stop but also remove any
343
  * already queued recipients
344
+ *
345
+ * @return $this
346
  */
347
  public function stop()
348
  {
349
  $this->isRunning(false);
350
+
351
  /* @see Mzax_Emarketing_Model_Resource_Recipient */
352
  Mage::getResourceSingleton('mzax_emarketing/recipient')->removePending($this->getId());
353
+
354
  return $this;
355
  }
356
+
 
 
 
357
  /**
358
  * check if the campaign is valid for sending
359
+ *
360
  * @deprecated
361
  * @return boolean
362
  */
364
  {
365
  return true;
366
  }
367
+
 
 
368
  /**
369
  * Is a plain text email campaign
370
+ *
371
  * @deprecated
372
  * @return boolean
373
  */
375
  {
376
  return false;
377
  }
378
+
 
 
 
379
  /**
380
  * Retrieve tags
381
+ *
382
+ * @return string[]
383
  */
384
  public function getTags()
385
  {
386
  $data = $this->getData('tags');
387
+
388
  return preg_split('/[\s,]+/', $data, -1, PREG_SPLIT_NO_EMPTY);
389
  }
390
+
 
391
  /**
392
  * Set tags
393
+ *
394
+ * @param string|string[] $value
395
+ *
396
+ * @return $this
397
  */
398
  public function setTags($value)
399
  {
400
+ if (is_array($value)) {
401
  $value = array_unique($value);
402
  $value = implode(',', $value);
403
  }
404
+ $this->setData('tags', $value);
405
+
406
+ return $this;
407
  }
408
+
 
409
  /**
410
  * Add tags to campaign
411
+ *
412
  * @param string|array $tags
413
  * @return Mzax_Emarketing_Model_Campaign
414
  */
415
  public function addTags($tags)
416
  {
417
+ if (is_string($tags)) {
418
  $tags = preg_split('/[\s,]+/', $tags, -1, PREG_SPLIT_NO_EMPTY);
419
  }
420
+ if (is_array($tags)) {
421
  $tags = array_merge($this->getTags(), $tags);
422
  $this->setTags($tags);
423
  }
424
  return $this;
425
  }
426
+
 
427
  /**
428
  * Remove tags from campaign
429
  *
432
  */
433
  public function removeTags($tags)
434
  {
435
+ if (is_string($tags)) {
436
  $tags = preg_split('/[\s,]+/', $tags, -1, PREG_SPLIT_NO_EMPTY);
437
  }
438
+ if (is_array($tags)) {
439
  $tags = array_diff($this->getTags(), $tags);
440
  $this->setTags($tags);
441
  }
442
  return $this;
443
  }
 
 
444
 
445
  //--------------------------------------------------------------------------
446
  //
447
  // Medium
448
  //
449
  //--------------------------------------------------------------------------
450
+
 
 
 
451
  /**
452
  * Retrieve medium
453
  *
454
+ * @return Medium
455
  */
456
  public function getMedium()
457
  {
458
+ if (!$this->_medium && $this->getData('medium')) {
459
+ /** @var Mzax_Emarketing_Model_Medium $factory */
460
+ $factory = Mage::getSingleton('mzax_emarketing/medium');
461
+ $this->_medium = $factory->factory($this->getData('medium'));
462
  }
463
+
464
  return $this->_medium;
465
  }
466
+
467
+ /**
468
+ * Set medium
469
+ *
470
+ * @param Medium|string $medium
471
+ *
472
+ * @return $this
473
+ */
474
+ public function setMedium($medium)
475
+ {
476
+ if ($medium instanceof Medium) {
477
+ $this->_medium = $medium;
478
+ $medium = $medium->getMediumId();
479
+ }
480
+
481
+ $this->setData('medium', $medium);
482
+
483
+ return $this;
484
+ }
485
 
486
  /**
487
  * Retrieve content data
490
  */
491
  public function getMediumData()
492
  {
493
+ if (!$this->_mediumData) {
494
+ if ($data = $this->getMediumJson()) {
495
+ if (is_string($data)) {
496
+ $data = Zend_Json::decode($data);
497
+ }
498
  $this->_mediumData = new Varien_Object($data);
499
+ } else {
 
500
  $this->_mediumData = new Varien_Object;
501
  }
502
  $this->setDataChanges(true);
503
  }
504
+
505
  return $this->_mediumData;
506
  }
507
+
 
 
 
508
  //--------------------------------------------------------------------------
509
  //
510
  // Provider
511
  //
512
  //--------------------------------------------------------------------------
513
+
 
 
514
  /**
515
  * Retrieve all available recipient provider options
516
+ *
517
  * @return array
518
  */
519
  public function getAvailableProviders()
520
  {
521
  return self::getProviderFactory()->getAllOptions(false);
522
  }
 
 
523
 
 
524
  /**
525
  * Retrieve recipient provider for this campaign
526
+ *
527
+ * @return RecipientProvider
528
  */
529
  public function getRecipientProvider()
530
  {
531
+ if (!$this->_provider && $this->getData('provider')) {
532
  $type = $this->getData('provider');
533
+
534
+ $this->_provider = self::getProviderFactory()->factory($type);
535
+ $this->_provider->setCampaign($this);
536
  }
537
+
538
  return $this->_provider;
539
  }
540
+
541
+ /**
542
+ * Set recipient provider
543
+ *
544
+ * @param RecipientProvider $provider
545
+ *
546
+ * @return $this
547
+ */
548
+ public function setRecipientProvider(RecipientProvider $provider)
549
+ {
550
+ $this->_provider = $provider;
551
+ $this->_provider->setCampaign($this);
552
+
553
+ return $this;
554
+ }
555
 
556
  /**
557
  * Retrieve provider factory
562
  {
563
  return Mage::getSingleton('mzax_emarketing/recipient_provider');
564
  }
565
+
 
 
 
 
566
  /**
567
  * Retrieve filter by id
568
+ *
569
  * @param string $id e.g. 1-1-2-3-1-2
570
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
571
  */
573
  {
574
  return $this->getRecipientProvider()->getFilterById($id);
575
  }
 
 
 
 
 
 
 
576
 
577
  //--------------------------------------------------------------------------
578
  //
579
  // Email
580
  //
581
  //--------------------------------------------------------------------------
582
+
 
 
 
583
  /**
584
  * Retrieve magento email sender
585
+ *
586
  * @return array
587
  */
588
  public function getSender()
589
  {
590
  $sender = $this->getData('sender');
591
+ if (empty($sender)) {
592
  $sender = $this->getIdentity();
593
  }
594
 
595
  if (!is_array($sender)) {
596
+ /** @var Mzax_Emarketing_Model_Config $config */
597
+ $config = Mage::getSingleton('mzax_emarketing/config');
598
+
599
  $sender = array(
600
+ 'name' => $config->get('trans_email/ident_'.$sender.'/name', $this->getStore()),
601
+ 'email' => $config->get('trans_email/ident_'.$sender.'/email', $this->getStore()),
602
  );
603
  }
604
+ $this->setData('sender', $sender);
605
+
606
  return $sender;
607
  }
608
+
 
 
 
 
 
609
  /**
610
  * Create a mock recipient instance
611
+ *
612
+ * @param string $objectId Target object id
613
  * @return Mzax_Emarketing_Model_Recipient
614
  */
615
  public function createMockRecipient($objectId = null)
616
  {
617
  /* @var $recipient Mzax_Emarketing_Model_Recipient */
618
+ $recipient = $this->_factory->createRecipient();
619
  $recipient->setCampaign($this);
620
  $recipient->setObjectId($objectId);
621
  $recipient->isMock(true);
622
+
623
  return $recipient;
624
  }
625
+
 
 
 
626
  /**
627
  * Prepare recipient
628
+ *
629
  * before we send out an email and prepare the template
630
  * we will give the email provider and the filters a chance to prepare the recipient
631
  * to add any data usefull information
632
+ *
633
  * @param Mzax_Emarketing_Model_Recipient $recipient
634
  * @return Mzax_Emarketing_Model_Campaign
635
  */
637
  {
638
  $this->getRecipientProvider()->prepareRecipient($recipient);
639
  $this->getMedium()->prepareRecipient($recipient);
640
+
641
  return $this;
642
  }
 
643
 
 
 
644
  /**
645
  * Retrieve campaign content
646
+ *
647
  * If ab-testing is enabled we need to retrieve
648
  * a random variation
649
  *
650
+ * @param null|int $variationId
651
+ *
652
  * @return Mzax_Emarketing_Model_Campaign_Content
653
  */
654
  public function getContent($variationId = null)
655
  {
656
+ if ($variationId !== null) {
657
+ // if zero, use original campaign
658
+ if ($variationId == Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL) {
659
  return $this;
660
  }
661
+
662
  $variation = $this->getVariation($variationId);
663
+ if (!$variation) {
664
  return $this;
665
  }
666
  return $variation;
667
  }
668
+
669
  $this->setVariationId(Mzax_Emarketing_Model_Campaign_Variation::NONE);
670
+
671
  // check if ab-testing is enabled
672
+ if (!$this->getAbtestEnable() && $this->getAbtestTraffic() > 0) {
673
  return $this;
674
  }
675
+
676
  // include include in test?
677
+ if (mt_rand(0, 999)/10 >= $this->getAbtestTraffic()) {
678
  return $this;
679
  }
680
+
681
  $this->setVariationId(Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL);
682
  $active = array($this);
683
+
684
  /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
685
+ foreach ($this->getVariations() as $variation) {
686
+ if ($variation->getIsActive()) {
687
  $active[] = $variation;
688
  }
689
  }
690
+
691
+ // pick random content
692
  return $active[array_rand($active)];
693
  }
694
+
 
 
 
 
695
  /**
696
  * Retrieve available snippets for the content manager
697
+ *
698
  * @return Mzax_Emarketing_Model_Medium_Email_Snippets
699
  */
700
  public function getSnippets()
701
  {
702
+ $snippets = $this->_factory->createSnippets();
703
+
704
+ if ($this->getRecipientProvider()) {
 
705
  $this->getRecipientProvider()->prepareSnippets($snippets);
706
  }
707
+ if ($this->getMedium()) {
708
  $this->getMedium()->prepareSnippets($snippets);
709
  }
710
  $this->getMedium()->prepareSnippets($snippets);
711
+
712
  return $snippets;
713
  }
714
+
 
 
 
715
  //--------------------------------------------------------------------------
716
  //
717
  // Variations
718
  //
719
  //--------------------------------------------------------------------------
720
+
 
 
721
  /**
722
+ * Check if campaign has any variations
723
+ *
724
  * @return int
725
  */
726
  public function hasVariations()
727
  {
728
  return count($this->getVariations());
729
  }
730
+
 
 
 
 
 
731
  /**
732
  * Retrieve all variations
733
+ *
734
  * @return Mzax_Emarketing_Model_Resource_Campaign_Variation_Collection
735
  */
736
  public function getVariations()
737
  {
738
+ if (!$this->_variations) {
739
+ $this->_variations = $this->_factory->createVariationCollection();
740
  $this->_variations->addCampaignFilter($this);
741
  }
742
+
743
  return $this->_variations;
744
  }
745
+
 
 
 
 
746
  /**
747
  * Retrieve variation by id
748
+ *
749
  * @param string $id
750
+ *
751
  * @return Mzax_Emarketing_Model_Campaign_Variation
752
  */
753
  public function getVariation($id)
754
  {
755
+ $variation = $this->getVariations()->getItemById($id);
756
+
757
+ return $variation;
758
  }
759
+
 
 
 
760
  /**
761
  * Create new variation
762
+ *
 
763
  * @return Mzax_Emarketing_Model_Campaign_Variation
764
  */
765
  public function createVariation()
766
  {
767
  $variations = $this->getVariations();
768
+
769
+ $variation = $this->_factory->createVariation();
 
770
  $variation->setCampaign($this);
771
  $variation->setName('Variation ' . (count($variations)+1));
772
  $variation->setMediumJson($this->getMediumJson());
773
+
774
  return $variation;
775
  }
776
+
 
777
  //--------------------------------------------------------------------------
778
  //
779
  // Trackers
780
  //
781
  //--------------------------------------------------------------------------
782
 
 
 
 
783
  /**
784
  * Retrieve all conversion trackers
785
+ *
786
  * @return Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection
787
  */
788
  public function getTrackers()
789
  {
790
+ if (!$this->_trackers) {
791
+ $this->_trackers = $this->_factory->createTrackerCollection();
792
  $this->_trackers->addCampaignFilter($this);
793
  $this->_trackers->addActiveFilter();
794
  }
795
+
796
  return $this->_trackers;
797
  }
798
+
 
799
  /**
800
  * Retrieve tracker by id
801
+ *
802
  * @param string $id
803
+ *
804
  * @return Mzax_Emarketing_Model_Conversion_Tracker
805
  */
806
  public function getTracker($id)
807
  {
808
+ $tracker = $this->getTrackers()->getItemById($id);
809
+
810
+ return $tracker;
811
  }
 
 
812
 
813
  /**
814
  * Retrieve default tracker for this campaign
817
  */
818
  public function getDefaultTracker()
819
  {
820
+ if (!$this->_defaultTracker) {
821
  $tracker = $this->getTracker($this->getDefaultTrackerId());
822
+ if (!$tracker) {
823
+ foreach ($this->getTrackers() as $tracker) {
824
+ if ($tracker->isDefault()) {
825
  break;
826
  }
827
  }
828
  }
829
  $this->_defaultTracker = $tracker;
830
  }
831
+
832
  return $this->_defaultTracker;
833
  }
 
 
 
 
834
 
835
  //--------------------------------------------------------------------------
836
  //
837
  // Recipients
838
  //
839
  //--------------------------------------------------------------------------
840
+
 
841
  /**
842
  * Check number of recipients
843
  *
846
  public function countRecipients()
847
  {
848
  $count = $this->getData('recipients_count');
849
+ if ($count === null) {
850
  $count = $this->getResource()->countRecipients($this);
851
  $this->setData('recipients_count', $count);
852
  }
853
+
854
  return $count;
855
  }
856
+
 
 
 
857
  /**
858
  * Try to bind recipients to goals
859
+ *
860
  * The recipient provider has to do that
861
+ *
862
  * @param Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder
863
+ *
864
+ * @return $this
865
  */
866
  public function bindRecipients(Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder $binder)
867
  {
868
+ if ($provider = $this->getRecipientProvider()) {
869
  $provider->bindRecipients($binder);
870
  }
871
+
872
  return $this;
873
  }
874
+
 
 
 
875
  /**
876
  * Find and queue new recipients for this campaign that
877
  * match the current filters
878
+ *
879
+ * @param bool $force
880
+ *
881
+ * @return int the number of recipients found
882
  */
883
  public function findRecipients($force = false)
884
  {
885
+ if ($force || $this->getRunning()) {
886
+ $this->unsetData('current_time');
887
  return $this->getResource()->findRecipients($this);
888
  }
889
+
890
  return 0;
891
  }
892
+
 
 
 
 
 
 
893
  /**
894
  * Retrieve all recipients for this campaign
895
+ *
896
  * @return Mzax_Emarketing_Model_Resource_Recipient_Collection
897
  */
898
  public function getRecipients()
899
  {
900
+ if ($this->_recipients) {
901
+ $this->_recipients = $this->_factory->createRecipientCollection();
902
  $this->_recipients->setCampaign($this);
903
  }
904
  return $this->_recipients;
905
  }
906
+
 
 
 
 
907
  /**
908
  * Retrieve all recipients that have not yet been send
909
+ *
910
  * @return Mzax_Emarketing_Model_Resource_Recipient_Collection
911
  */
912
  public function getPendingRecipients()
913
  {
914
+ $recipients = $this->_factory->createRecipientCollection();
 
915
  $recipients->setCampaign($this);
916
  $recipients->addPrepareFilter(false);
917
+
918
  return $recipients;
919
  }
920
+
 
 
 
921
  /**
922
  * Prepare pending recipients and move them to
923
  * the email outbox
924
  * This will render all emails and makes them ready
925
  * to get send
926
+ *
927
  * @see Mzax_Emarketing_Model_Outbox
928
+ *
929
+ * @param array $options
930
+ *
931
+ * @return int Number of prepared recipients
932
  */
933
  public function sendRecipients($options = array())
934
  {
936
  $options->getDataSetDefault('timeout', 300);
937
  $options->getDataSetDefault('maximum', 500);
938
  $options->getDataSetDefault('break_on_error', Mage::getIsDeveloperMode());
939
+
940
+ if ($this->getId() && $this->getRecipientProvider() && $this->getMedium()) {
941
  return $this->getMedium()->sendRecipients($this, $options);
942
  }
943
+
944
  return 0;
945
  }
946
+
 
 
 
 
947
  /**
948
  * Retrieve number of recipient errors
949
  *
952
  public function countRecipientErrors()
953
  {
954
  $count = $this->getData('recipient_errors_count');
955
+ if ($count === null) {
956
  $count = $this->getResource()->countRecipientErrors($this);
957
  $this->setData('recipient_errors_count', $count);
958
  }
959
+
960
  return $count;
961
  }
962
+
 
 
 
963
  //--------------------------------------------------------------------------
964
  //
965
  // Inbox/Outbox
966
  //
967
  //--------------------------------------------------------------------------
968
+
969
  /**
970
  * Check number of messages in inbox
971
+ *
972
  * @return integer
973
  */
974
  public function countInbox()
975
  {
976
  $count = $this->getData('inbox_count');
977
+ if ($count === null) {
978
  $count = $this->getResource()->countInbox($this);
979
  $this->setData('inbox_count', $count);
980
  }
981
+
982
  return $count;
983
  }
984
 
 
 
985
  /**
986
  * Check number of messages in outbox
987
  *
990
  public function countOutbox()
991
  {
992
  $count = $this->getData('outbox_count');
993
+ if ($count === null) {
994
  $count = $this->getResource()->countOutbox($this);
995
  $this->setData('outbox_count', $count);
996
  }
997
+
998
  return $count;
999
  }
1000
+
 
 
 
 
 
 
1001
  //--------------------------------------------------------------------------
1002
  //
1003
  // Report
1004
  //
1005
  //--------------------------------------------------------------------------
 
 
1006
 
1007
  /**
1008
  * Aggregate data for this campaign
1016
  'campaign_id' => $this->getId(),
1017
  'verbose' => false
1018
  ));
1019
+
1020
+ Mage::dispatchEvent(
1021
+ $this->_eventPrefix . '_aggregate',
1022
+ array('options' => $options, 'campaign' => $this)
1023
+ );
1024
+
1025
+ if ($incremental) {
1026
+ $options->setData('incremental', (int)$incremental);
1027
  }
1028
+
1029
  /* @var $report Mzax_Emarketing_Model_Report */
1030
  $report = Mage::getSingleton('mzax_emarketing/report');
1031
  $report->aggregate($options->toArray());
1032
+
1033
  return $this;
1034
  }
1035
+
 
 
 
 
 
 
1036
  /**
1037
  * Retrieve a new report query instance
1038
+ *
1039
  * @param string $dimension
1040
  * @param array $metrics
1041
+ * @param bool $variations
1042
+ * @param string $order
1043
+ *
1044
  * @return Mzax_Emarketing_Model_Report_Query
1045
  */
1046
  public function queryReport($dimension = 'campaign', $metrics = array('sendings', 'views', 'clicks'), $variations = false, $order = null)
1047
  {
1048
  $metrics = (array) $metrics;
1049
+
1050
  // replace default tracker id
1051
+ foreach ($metrics as $key => $metric) {
1052
+ if (strpos($metric, '#?') !== false) {
1053
+ if ($tracker = $this->getDefaultTracker()) {
1054
  $metrics[$key] = str_replace('#?', '#' . $tracker->getId(), $metric);
1055
+ } else {
 
1056
  unset($metrics[$key]);
1057
  }
1058
  }
1059
+ if ($metric instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
1060
  $metrics[$key] = '#' . $metric->getId();
1061
  }
1062
  }
1063
+
1064
  /* @var $query Mzax_Emarketing_Model_Report_Query */
1065
  $query = Mage::getModel('mzax_emarketing/report_query');
1066
+ $query->setParam('campaign', $this->getId());
1067
+ $query->setParam('dimension', $dimension);
1068
+ $query->setParam('metrics', $metrics);
1069
  $query->setParam('variations', $variations);
1070
+ $query->setParam('order', $order);
1071
+
 
1072
  return $query;
1073
  }
 
 
 
1074
 
 
 
 
 
 
1075
  //--------------------------------------------------------------------------
1076
  //
1077
  // Misc
1078
  //
1079
  //--------------------------------------------------------------------------
1080
+
 
 
1081
  /**
1082
  * Convert to campaign to encoded string
1083
  *
1085
  */
1086
  public function export()
1087
  {
1088
+ /** @var Mzax_Emarketing_Helper_Data $helper */
1089
+ $helper = Mage::helper('mzax_emarketing');
1090
+
1091
  $filterData = $this->getRecipientProvider()->export();
1092
+ $filterData = Zend_Json::encode($filterData);
1093
+
1094
+ $this->setData('filter_export', $filterData);
1095
+ $this->setData('version', $helper->getVersion());
1096
+
1097
+ $json = $this->toJson(
1098
+ array(
1099
+ 'version',
1100
+ 'name',
1101
+ 'description',
1102
+ 'check_frequency',
1103
+ 'min_resend_interval',
1104
+ 'autologin',
1105
+ 'expire_time',
1106
+ 'provider',
1107
+ 'filter_export',
1108
+ 'medium',
1109
+ 'medium_json'
1110
+ )
1111
+ );
1112
+ $result = base64_encode($json);
1113
+
1114
+ return $result;
1115
  }
1116
+
1117
+ /**
1118
+ * Clone campaign
1119
+ *
1120
+ * Deep clone campaign
1121
+ *
1122
+ * @return void
1123
+ */
1124
  public function __clone()
1125
  {
1126
+ $originalId = $this->getId();
1127
+
1128
  $variations = array();
1129
+ foreach ($this->getVariations() as $variation) {
1130
  $newVariation = clone $variation;
1131
  $newVariation->setCampaign($this);
1132
  $variations[] = $newVariation;
1133
  }
1134
  $this->_variations = null;
1135
+
 
1136
  $this->setId(null);
1137
  $this->setCreatedAt(null);
1138
  $this->setUpdatedAt(null);
1139
+ $this->setData('cloned_variations', $variations);
1140
+ $this->setData('duplicate_of', $originalId);
1141
 
1142
  // reset aggregated statistics
1143
+ $this->unsetData('sending_stats');
1144
+ $this->unsetData('view_stats');
1145
+ $this->unsetData('interaction_stats');
1146
+ $this->unsetData('conversion_stats');
1147
+ $this->unsetData('fail_stats');
1148
+ $this->unsetData('revenue_stats');
 
1149
  }
 
 
1150
  }
app/code/community/Mzax/Emarketing/Model/Campaign/Content.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,26 +17,22 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- *
24
- * @author Jacob Siefer
25
- *
26
  */
27
  interface Mzax_Emarketing_Model_Campaign_Content
28
  {
29
-
30
-
 
 
 
31
  public function getContentCacheId();
32
-
33
-
34
  /**
35
  * Retrieve content data
36
- *
37
  * @return Varien_Object
38
  */
39
  public function getMediumData();
40
-
41
-
42
-
43
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Interface Mzax_Emarketing_Model_Campaign_Content
 
 
22
  */
23
  interface Mzax_Emarketing_Model_Campaign_Content
24
  {
25
+ /**
26
+ * Retrieve content cache id
27
+ *
28
+ * @return string
29
+ */
30
  public function getContentCacheId();
31
+
 
32
  /**
33
  * Retrieve content data
34
+ *
35
  * @return Varien_Object
36
  */
37
  public function getMediumData();
 
 
 
38
  }
app/code/community/Mzax/Emarketing/Model/Campaign/Preset.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,82 +16,78 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
21
-
22
  /**
23
- *
 
24
  * @method string getName()
 
25
  * @method string getDescription()
26
  * @method string getFile()
27
  * @method string getFilename()
28
- *
 
29
  * @author Jacob Siefer
30
  *
31
  */
32
  class Mzax_Emarketing_Model_Campaign_Preset extends Varien_Object
33
  {
34
-
35
-
36
  /**
37
  * Validate the version of the preset
38
  * against the installed extension version
39
- *
40
  * @return boolean
41
  */
42
  public function validateVersion()
43
  {
44
- if($version = $this->getVersion()) {
45
- return (version_compare($version, Mage::helper('mzax_emarketing')->getVersion()) < 0);
 
 
 
46
  }
47
  return true;
48
  }
49
-
50
-
51
-
52
  /**
53
  * Make new campaign from this preset
54
- *
55
  * @return Mzax_Emarketing_Model_Campaign
56
  */
57
  public function makeCampaign()
58
  {
59
- /* @var $campaign Mzax_Emarketing_Model_Campaign */
60
- $campaign = Mage::getModel('mzax_emarketing/campaign');
61
  $campaign->addData($this->getData());
62
- $campaign->setPreset($this);
63
  $campaign->setName(null);
64
-
65
- if( $provider = $campaign->getRecipientProvider() ) {
66
  $provider->load($this->getFilterExport());
67
  }
68
-
69
  Mage::dispatchEvent('mzax_emarketing_preset_make_campaign', array(
70
  'preset' => $this,
71
  'campaign' => $campaign
72
  ));
73
-
74
  return $campaign;
75
  }
76
-
77
-
78
-
79
  /**
80
  * Load by file
81
- *
82
  * @param string $file
83
  * @return Mzax_Emarketing_Model_Campaign_Preset
84
  */
85
  public function loadByFile($file)
86
  {
87
  $this->_getResource()->loadByFile($this, $file);
 
88
  return $this;
89
-
90
  }
91
-
92
-
93
  /**
94
  * Load by filename
95
- *
96
  * @param string $name
97
  * @return Mzax_Emarketing_Model_Campaign_Preset
98
  */
@@ -101,9 +96,6 @@ class Mzax_Emarketing_Model_Campaign_Preset extends Varien_Object
101
  $this->_getResource()->load($this, $name);
102
  return $this;
103
  }
104
-
105
-
106
-
107
 
108
  /**
109
  * Retrieve resource model
@@ -114,5 +106,14 @@ class Mzax_Emarketing_Model_Campaign_Preset extends Varien_Object
114
  {
115
  return Mage::getResourceSingleton('mzax_emarketing/campaign_preset');
116
  }
117
-
 
 
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
 
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Campaign_Preset
21
+ *
22
  * @method string getName()
23
+ * @method string getVersion()
24
  * @method string getDescription()
25
  * @method string getFile()
26
  * @method string getFilename()
27
+ * @method string getFilterExport()
28
+ *
29
  * @author Jacob Siefer
30
  *
31
  */
32
  class Mzax_Emarketing_Model_Campaign_Preset extends Varien_Object
33
  {
 
 
34
  /**
35
  * Validate the version of the preset
36
  * against the installed extension version
37
+ *
38
  * @return boolean
39
  */
40
  public function validateVersion()
41
  {
42
+ /** @var Mzax_Emarketing_Helper_Data $helper */
43
+ $helper = Mage::helper('mzax_emarketing');
44
+
45
+ if ($version = $this->getVersion()) {
46
+ return (version_compare($version, $helper->getVersion()) < 0);
47
  }
48
  return true;
49
  }
50
+
 
 
51
  /**
52
  * Make new campaign from this preset
53
+ *
54
  * @return Mzax_Emarketing_Model_Campaign
55
  */
56
  public function makeCampaign()
57
  {
58
+ $campaign = $this->_createCampaignModel();
 
59
  $campaign->addData($this->getData());
60
+ $campaign->setData('preset', $this);
61
  $campaign->setName(null);
62
+
63
+ if ($provider = $campaign->getRecipientProvider()) {
64
  $provider->load($this->getFilterExport());
65
  }
66
+
67
  Mage::dispatchEvent('mzax_emarketing_preset_make_campaign', array(
68
  'preset' => $this,
69
  'campaign' => $campaign
70
  ));
71
+
72
  return $campaign;
73
  }
74
+
 
 
75
  /**
76
  * Load by file
77
+ *
78
  * @param string $file
79
  * @return Mzax_Emarketing_Model_Campaign_Preset
80
  */
81
  public function loadByFile($file)
82
  {
83
  $this->_getResource()->loadByFile($this, $file);
84
+
85
  return $this;
 
86
  }
87
+
 
88
  /**
89
  * Load by filename
90
+ *
91
  * @param string $name
92
  * @return Mzax_Emarketing_Model_Campaign_Preset
93
  */
96
  $this->_getResource()->load($this, $name);
97
  return $this;
98
  }
 
 
 
99
 
100
  /**
101
  * Retrieve resource model
106
  {
107
  return Mage::getResourceSingleton('mzax_emarketing/campaign_preset');
108
  }
109
+
110
+ /**
111
+ * Create new campaign model
112
+ *
113
+ * @return Mzax_Emarketing_Model_Campaign
114
+ */
115
+ protected function _createCampaignModel()
116
+ {
117
+ return Mage::getModel('mzax_emarketing/campaign');
118
+ }
119
  }
app/code/community/Mzax/Emarketing/Model/Campaign/Variation.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,37 +17,29 @@
18
  */
19
 
20
  /**
21
- *
 
22
  * @method string getCreatedAt()
23
  * @method string getUpdatedAt()
24
  * @method string getName()
25
  * @method string getIsActive()
26
  * @method string getIsRemoved()
27
  * @method string getMediumJson()
28
- *
29
- * @method Mzax_Emarketing_Model_Campaign_Variation setCreatedAt()
30
- * @method Mzax_Emarketing_Model_Campaign_Variation setUpdatedAt()
31
- * @method Mzax_Emarketing_Model_Campaign_Variation setName()
32
- * @method Mzax_Emarketing_Model_Campaign_Variation setIsActive()
33
- * @method Mzax_Emarketing_Model_Campaign_Variation setIsRemoved()
34
- * @method Mzax_Emarketing_Model_Campaign_Variation setMediumJson()
35
- *
36
- *
37
- *
38
- * @author Jacob Siefer
39
  *
 
 
 
 
 
 
40
  */
41
- class Mzax_Emarketing_Model_Campaign_Variation
42
- extends Mage_Core_Model_Abstract
43
  implements Mzax_Emarketing_Model_Campaign_Content
44
  {
45
-
46
-
47
-
48
-
49
  const ORIGNAL = 0;
50
  const NONE = -1;
51
-
52
  /**
53
  * Prefix of model events names
54
  *
@@ -64,144 +55,132 @@ class Mzax_Emarketing_Model_Campaign_Variation
64
  * @var string
65
  */
66
  protected $_eventObject = 'variation';
67
-
68
-
69
-
70
  /**
71
- *
 
72
  * @var Mzax_Emarketing_Model_Campaign
73
  */
74
  protected $_campaign;
75
-
76
-
77
  /**
78
- *
 
79
  * @var Varien_Object
80
  */
81
  protected $_mediumData;
82
-
83
-
84
-
85
-
 
 
86
  protected function _construct()
87
  {
88
  $this->_init('mzax_emarketing/campaign_variation');
89
  }
90
-
91
-
92
  /**
93
- *
 
94
  * @return string
95
  */
96
  public function getContentCacheId()
97
  {
98
  return $this->_eventObject . '_' . $this->getId();
99
  }
100
-
101
-
102
-
103
 
 
 
 
 
 
104
  protected function _beforeSave()
105
  {
106
- if($this->_mediumData) {
107
  $this->setData('medium_json', $this->_mediumData->toJson());
108
  }
109
- if($this->_campaign) {
110
  $this->setCampaignId($this->_campaign->getId());
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
  *
@@ -209,21 +188,23 @@ class Mzax_Emarketing_Model_Campaign_Variation
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
  public function __clone()
228
  {
229
  $this->setDuplicateOf($this->getId());
@@ -231,6 +212,4 @@ class Mzax_Emarketing_Model_Campaign_Variation
231
  $this->setCreatedAt(null);
232
  $this->setUpdatedAt(null);
233
  }
234
-
235
-
236
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ Class Mzax_Emarketing_Model_Campaign_Variation
21
+ *
22
  * @method string getCreatedAt()
23
  * @method string getUpdatedAt()
24
  * @method string getName()
25
  * @method string getIsActive()
26
  * @method string getIsRemoved()
27
  * @method string getMediumJson()
 
 
 
 
 
 
 
 
 
 
 
28
  *
29
+ * @method $this setCreatedAt($value)
30
+ * @method $this setUpdatedAt($value)
31
+ * @method $this setName($value)
32
+ * @method $this setIsActive($value)
33
+ * @method $this setIsRemoved($value)
34
+ * @method $this setMediumJson($value)
35
  */
36
+ class Mzax_Emarketing_Model_Campaign_Variation
37
+ extends Mage_Core_Model_Abstract
38
  implements Mzax_Emarketing_Model_Campaign_Content
39
  {
 
 
 
 
40
  const ORIGNAL = 0;
41
  const NONE = -1;
42
+
43
  /**
44
  * Prefix of model events names
45
  *
55
  * @var string
56
  */
57
  protected $_eventObject = 'variation';
58
+
 
 
59
  /**
60
+ * Campaign
61
+ *
62
  * @var Mzax_Emarketing_Model_Campaign
63
  */
64
  protected $_campaign;
65
+
 
66
  /**
67
+ * Medium Data
68
+ *
69
  * @var Varien_Object
70
  */
71
  protected $_mediumData;
72
+
73
+ /**
74
+ * Construct.
75
+ *
76
+ * @return void
77
+ */
78
  protected function _construct()
79
  {
80
  $this->_init('mzax_emarketing/campaign_variation');
81
  }
82
+
 
83
  /**
84
+ * Retrieve cache id
85
+ *
86
  * @return string
87
  */
88
  public function getContentCacheId()
89
  {
90
  return $this->_eventObject . '_' . $this->getId();
91
  }
 
 
 
92
 
93
+ /**
94
+ * Convert current data to JSON and set campaign id
95
+ *
96
+ * @return void
97
+ */
98
  protected function _beforeSave()
99
  {
100
+ if ($this->_mediumData) {
101
  $this->setData('medium_json', $this->_mediumData->toJson());
102
  }
103
+ if ($this->_campaign) {
104
  $this->setCampaignId($this->_campaign->getId());
105
  }
106
+
107
  parent::_beforeSave();
108
  }
109
+
110
+ /**
111
+ * Set campaign id
112
+ *
113
+ * @param string|integer $campaignId
114
+ *
115
+ * @return $this
116
+ */
117
+ public function setCampaignId($campaignId)
 
 
118
  {
119
+ if ($this->_campaign && $this->_campaign->getId() != $campaignId) {
120
  $this->_campaign = null;
121
  }
122
+ $this->setData('campaign_id', $campaignId);
123
+
124
+ return $this;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
126
+
 
 
 
127
  /**
128
+ * Set campaign
129
+ *
130
+ * @param Mzax_Emarketing_Model_Campaign $campaign
131
+ *
132
+ * @return $this
133
+ */
134
+ public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
135
+ {
136
+ $this->setCampaignId($campaign->getId());
137
+ $this->_campaign = $campaign;
138
+
139
+ return $this;
140
+ }
141
+
142
+ /**
143
+ * Retrieve campaign
144
+ *
145
  * @return Mzax_Emarketing_Model_Campaign
146
  */
147
  public function getCampaign()
148
  {
149
  return $this->_campaign;
150
  }
151
+
 
 
 
152
  /**
153
  * Is variation removed
154
+ *
155
  * For statistical reference, variations should not get deleted
156
+ *
157
  * @param string $flag
158
  * @return boolean
159
  */
160
  public function isRemoved($flag = null)
161
  {
162
+ if (is_bool($flag)) {
163
+ $this->setIsRemoved((int)$flag);
164
  }
165
+
166
  return (bool) $this->getIsRemoved();
167
  }
168
+
 
 
169
  /**
170
  * Is variation active
171
+ *
172
  * @param string $flag
173
  * @return boolean
174
  */
175
  public function isActive($flag = null)
176
  {
177
+ if (is_bool($flag)) {
178
+ $this->setIsActive((int)$flag);
179
  }
180
+
181
  return (bool) $this->getIsActive();
182
  }
183
+
 
 
 
 
 
184
  /**
185
  * Retrieve content data
186
  *
188
  */
189
  public function getMediumData()
190
  {
191
+ if (!$this->_mediumData) {
192
+ if ($json = $this->getMediumJson()) {
193
  $json = Zend_Json::decode($json);
194
  $this->_mediumData = new Varien_Object($json);
195
+ } else {
 
196
  $this->_mediumData = new Varien_Object;
197
  }
198
  }
199
+
200
  return $this->_mediumData;
201
  }
 
 
 
202
 
203
+ /**
204
+ * Reset details on clone
205
+ *
206
+ * @return void
207
+ */
208
  public function __clone()
209
  {
210
  $this->setDuplicateOf($this->getId());
212
  $this->setCreatedAt(null);
213
  $this->setUpdatedAt(null);
214
  }
 
 
215
  }
app/code/community/Mzax/Emarketing/Model/Config.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mzax
13
+ * @package Mzax_Emarketing
14
+ * @author Jacob Siefer (jacob@mzax.de)
15
+ * @copyright Copyright (c) 2015 Jacob Siefer
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+
20
+ use Mage_Core_Model_Store as Store;
21
+
22
+
23
+ /**
24
+ * Class Mzax_Emarketing_Model_Config
25
+ *
26
+ * Config manager to minimize the usage of super class Mage
27
+ */
28
+ class Mzax_Emarketing_Model_Config
29
+ {
30
+ /**
31
+ * @param string $path
32
+ * @param int|Store $store
33
+ *
34
+ * @return string
35
+ */
36
+ public function get($path, $store = null)
37
+ {
38
+ return Mage::getStoreConfig($path, $store);
39
+ }
40
+
41
+ /**
42
+ * @param string $path
43
+ * @param int|Store $store
44
+ *
45
+ * @return bool
46
+ */
47
+ public function flag($path, $store = null)
48
+ {
49
+ return Mage::getStoreConfigFlag($path, $store);
50
+ }
51
+ }
app/code/community/Mzax/Emarketing/Model/Conversion/Goal.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,60 +16,56 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Model_Conversion_Goal implements Mage_Eav_Model_Entity_Attribute_Source_Interface
22
  {
23
-
24
  /**
25
- *
26
  * @var Mage_Core_Model_Config_Element
27
  */
28
  protected $_config;
29
-
30
-
31
-
32
  /**
33
- *
34
- * @var array
 
35
  */
36
  protected $_goals;
37
-
38
-
39
  /**
40
- *
 
41
  * @param string $name
 
42
  * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
43
  */
44
  public function factory($name)
45
  {
46
  $config = $this->getConfig();
47
- if(!isset($config->$name)) {
48
- return null;
49
  }
 
50
  $config = $config->$name;
51
  $class = $config->getClassName();
52
-
53
  $instance = new $class($config);
54
-
55
  return $instance;
56
  }
57
-
58
-
59
-
60
-
61
-
62
-
63
  /**
64
  * Retrieve All options
65
  *
 
 
66
  * @return array
67
  */
68
- public function getAllOptions($withEmpty = true, $defaultValues = false)
69
  {
70
  $options = array();
71
-
72
- /* @var $goal Mzax_Emarketing_Model_Conversion_Goal_Abstract */
73
- foreach($this->getGoals() as $name => $goal) {
74
  $options[] = array(
75
  'value' => $name,
76
  'label' => $goal->getTitle()
@@ -79,66 +74,55 @@ class Mzax_Emarketing_Model_Conversion_Goal implements Mage_Eav_Model_Entity_Att
79
  if ($withEmpty) {
80
  array_unshift($options, array('label'=>'', 'value'=>''));
81
  }
82
-
83
  return $options;
84
  }
85
-
86
-
87
-
88
-
89
-
90
-
91
- /**
92
- * Retrieve all conversion goals
93
- *
94
- * @return array
95
- */
96
- public function getGoals()
97
  {
98
- if(!$this->_goals) {
99
  $this->_goals = array();
100
-
101
- foreach($this->getConfig()->children() as $name => $cfg) {
102
- $this->_goals[$name] = self::factory($name);
103
  }
104
- }
105
- return $this->_goals;
106
  }
107
-
108
-
109
-
110
-
111
 
112
  /**
113
  * Retrieve Option value text
114
  *
115
  * @param string $value
116
- * @return mixed
 
117
  */
118
  public function getOptionText($value)
119
  {
120
- $options = $this->getFilters();
121
- if(isset($options[$value])) {
122
  return $options[$value]->getTitle();
123
  }
 
124
  return false;
125
  }
126
-
127
-
128
-
129
  /**
130
  * Retrieve config
131
- *
132
  * @return Mage_Core_Model_Config_Element
133
  */
134
  public function getConfig()
135
  {
136
- if(!$this->_config) {
137
  $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/goal_types');
138
  }
 
139
  return $this->_config;
140
  }
141
-
142
-
143
-
144
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Model_Conversion_Goal
21
+ */
22
  class Mzax_Emarketing_Model_Conversion_Goal implements Mage_Eav_Model_Entity_Attribute_Source_Interface
23
  {
 
24
  /**
 
25
  * @var Mage_Core_Model_Config_Element
26
  */
27
  protected $_config;
28
+
 
 
29
  /**
30
+ * Available goal types
31
+ *
32
+ * @var Mzax_Emarketing_Model_Conversion_Goal_Abstract[]
33
  */
34
  protected $_goals;
35
+
 
36
  /**
37
+ * Create goal instance from name
38
+ *
39
  * @param string $name
40
+ *
41
  * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
42
  */
43
  public function factory($name)
44
  {
45
  $config = $this->getConfig();
46
+ if (!isset($config->$name)) {
47
+ return null;
48
  }
49
+
50
  $config = $config->$name;
51
  $class = $config->getClassName();
52
+
53
  $instance = new $class($config);
54
+
55
  return $instance;
56
  }
57
+
 
 
 
 
 
58
  /**
59
  * Retrieve All options
60
  *
61
+ * @param bool $withEmpty
62
+ *
63
  * @return array
64
  */
65
+ public function getAllOptions($withEmpty = true)
66
  {
67
  $options = array();
68
+ foreach ($this->getGoals() as $name => $goal) {
 
 
69
  $options[] = array(
70
  'value' => $name,
71
  'label' => $goal->getTitle()
74
  if ($withEmpty) {
75
  array_unshift($options, array('label'=>'', 'value'=>''));
76
  }
77
+
78
  return $options;
79
  }
80
+
81
+ /**
82
+ * Retrieve all available conversion goals
83
+ *
84
+ * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract[]
85
+ */
86
+ public function getGoals()
 
 
 
 
 
87
  {
88
+ if (!$this->_goals) {
89
  $this->_goals = array();
90
+
91
+ foreach ($this->getConfig()->children() as $name => $cfg) {
92
+ $this->_goals[$name] = self::factory($name);
93
  }
94
+ }
95
+ return $this->_goals;
96
  }
 
 
 
 
97
 
98
  /**
99
  * Retrieve Option value text
100
  *
101
  * @param string $value
102
+ *
103
+ * @return string|bool
104
  */
105
  public function getOptionText($value)
106
  {
107
+ $options = $this->getGoals();
108
+ if (isset($options[$value])) {
109
  return $options[$value]->getTitle();
110
  }
111
+
112
  return false;
113
  }
114
+
 
 
115
  /**
116
  * Retrieve config
117
+ *
118
  * @return Mage_Core_Model_Config_Element
119
  */
120
  public function getConfig()
121
  {
122
+ if (!$this->_config) {
123
  $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/goal_types');
124
  }
125
+
126
  return $this->_config;
127
  }
 
 
 
128
  }
app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,63 +17,81 @@
18
  */
19
 
20
 
21
-
22
- abstract class Mzax_Emarketing_Model_Conversion_Goal_Abstract
 
 
23
  extends Mzax_Emarketing_Model_Object_Filter_Main
24
  {
25
-
 
 
26
  protected $_type;
27
-
28
-
29
  /**
30
- *
31
  * @var Mzax_Emarketing_Model_Conversion_Tracker
32
  */
33
  protected $_tracker;
34
 
35
-
36
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  abstract public function getAggregationSelect($campaign);
38
-
39
-
40
  /**
41
  * Set default filters when newly created
42
- *
43
  * @return void
44
  */
45
  public function setDefaultFilters()
46
- {}
47
-
48
-
49
- public function __construct($config)
50
  {
51
- parent::__construct();
52
-
53
- if($config instanceof Mage_Core_Model_Config_Element) {
54
- $this->_setup($config);
55
- }
56
  }
57
-
58
-
 
 
 
 
59
  protected function _setup(Mage_Core_Model_Config_Element $config)
60
  {
61
  $this->_type = $config->getName();
62
-
63
  Mage::dispatchEvent("mzax_emarketing_conversion_goal_setup", array('goal' => $this));
64
  Mage::dispatchEvent("mzax_emarketing_conversion_goal_setup_" . $this->_type, array('goal' => $this));
65
  }
66
-
67
-
 
 
 
 
68
  public function getType()
69
  {
70
  return $this->_type;
71
  }
72
-
73
-
74
-
75
  /**
76
  * Set Tracker
77
- *
78
  * @param Mzax_Emarketing_Model_Conversion_Tracker $tracker
79
  * @param $validateFilters
80
  * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
@@ -84,45 +101,49 @@ abstract class Mzax_Emarketing_Model_Conversion_Goal_Abstract
84
  $this->_tracker = $tracker;
85
  $this->load($tracker->getFilterData(), !$validateFilters);
86
  $this->setParam('tracker', $tracker);
87
-
88
  return $this;
89
  }
90
-
91
-
92
-
93
  /**
94
  * Retrieve Tracker
95
- *
96
  * @return Mzax_Emarketing_Model_Conversion_Tracker
97
  */
98
  public function getTracker()
99
  {
100
  return $this->_tracker;
101
  }
102
-
103
-
 
 
 
 
104
  public function getFormPrefix()
105
  {
106
  return 'conditions';
107
  }
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
  public function getQuery()
116
  {
117
  $query = parent::getQuery();
118
  $query->seek('recipient_id');
119
-
120
  return $query;
121
  }
122
-
123
  /**
 
 
 
124
  *
125
- * @return Zend_Db_Select
126
  */
127
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
128
  {
@@ -130,9 +151,14 @@ abstract class Mzax_Emarketing_Model_Conversion_Goal_Abstract
130
  $query->addBinding('recipient_id', new Zend_Db_Expr('MIN(`filter`.`recipient_id`)'));
131
  $query->setColumn('recipient_id');
132
  }
133
-
134
-
135
-
 
 
 
 
 
136
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
137
  {
138
  parent::prepareGridColumns($grid);
@@ -142,7 +168,4 @@ abstract class Mzax_Emarketing_Model_Conversion_Goal_Abstract
142
  'index' => 'recipient_id'
143
  ));
144
  }
145
-
146
-
147
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Conversion_Goal_Abstract
22
+ */
23
+ abstract class Mzax_Emarketing_Model_Conversion_Goal_Abstract
24
  extends Mzax_Emarketing_Model_Object_Filter_Main
25
  {
26
+ /**
27
+ * @var string
28
+ */
29
  protected $_type;
30
+
 
31
  /**
32
+ *
33
  * @var Mzax_Emarketing_Model_Conversion_Tracker
34
  */
35
  protected $_tracker;
36
 
37
+ /**
38
+ * Mzax_Emarketing_Model_Conversion_Goal_Abstract constructor.
39
+ *
40
+ * @param Mage_Core_Model_Config_Element $config
41
+ */
42
+ public function __construct($config = null)
43
+ {
44
+ parent::__construct();
45
+
46
+ if ($config instanceof Mage_Core_Model_Config_Element) {
47
+ $this->_setup($config);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Retrieve aggregate select for goal
53
+ *
54
+ * @param Mzax_Emarketing_Model_Campaign $campaign
55
+ *
56
+ * @return Mzax_Emarketing_Db_Select
57
+ */
58
  abstract public function getAggregationSelect($campaign);
59
+
 
60
  /**
61
  * Set default filters when newly created
62
+ *
63
  * @return void
64
  */
65
  public function setDefaultFilters()
 
 
 
 
66
  {
 
 
 
 
 
67
  }
68
+
69
+ /**
70
+ * Setup goal
71
+ *
72
+ * @param Mage_Core_Model_Config_Element $config
73
+ */
74
  protected function _setup(Mage_Core_Model_Config_Element $config)
75
  {
76
  $this->_type = $config->getName();
77
+
78
  Mage::dispatchEvent("mzax_emarketing_conversion_goal_setup", array('goal' => $this));
79
  Mage::dispatchEvent("mzax_emarketing_conversion_goal_setup_" . $this->_type, array('goal' => $this));
80
  }
81
+
82
+ /**
83
+ * Retrieve type
84
+ *
85
+ * @return string
86
+ */
87
  public function getType()
88
  {
89
  return $this->_type;
90
  }
91
+
 
 
92
  /**
93
  * Set Tracker
94
+ *
95
  * @param Mzax_Emarketing_Model_Conversion_Tracker $tracker
96
  * @param $validateFilters
97
  * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
101
  $this->_tracker = $tracker;
102
  $this->load($tracker->getFilterData(), !$validateFilters);
103
  $this->setParam('tracker', $tracker);
104
+
105
  return $this;
106
  }
107
+
 
 
108
  /**
109
  * Retrieve Tracker
110
+ *
111
  * @return Mzax_Emarketing_Model_Conversion_Tracker
112
  */
113
  public function getTracker()
114
  {
115
  return $this->_tracker;
116
  }
117
+
118
+ /**
119
+ * Retrieve form prefix for form filter rendering
120
+ *
121
+ * @return string
122
+ */
123
  public function getFormPrefix()
124
  {
125
  return 'conditions';
126
  }
127
+
128
+ /**
129
+ * Retrieve sql select query
130
+ *
131
+ * @return Mzax_Emarketing_Db_Select
132
+ */
 
133
  public function getQuery()
134
  {
135
  $query = parent::getQuery();
136
  $query->seek('recipient_id');
137
+
138
  return $query;
139
  }
140
+
141
  /**
142
+ * Prepare sql select query
143
+ *
144
+ * @param Mzax_Emarketing_Db_Select $query
145
  *
146
+ * @return void
147
  */
148
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
149
  {
151
  $query->addBinding('recipient_id', new Zend_Db_Expr('MIN(`filter`.`recipient_id`)'));
152
  $query->setColumn('recipient_id');
153
  }
154
+
155
+ /**
156
+ * Prepare grid columns
157
+ *
158
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
159
+ *
160
+ * @return void
161
+ */
162
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
163
  {
164
  parent::prepareGridColumns($grid);
168
  'index' => 'recipient_id'
169
  ));
170
  }
171
+ }
 
 
 
app/code/community/Mzax/Emarketing/Model/Conversion/Goal/Orders.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,25 +18,21 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
- class Mzax_Emarketing_Model_Conversion_Goal_Orders
29
  extends Mzax_Emarketing_Model_Conversion_Goal_Abstract
30
  {
31
-
32
-
33
-
 
 
34
  public function getTitle()
35
  {
36
  return "Magento Orders";
37
  }
38
-
39
 
40
-
41
  /**
42
  * Set default filters when newly created
43
  *
@@ -45,37 +40,32 @@ class Mzax_Emarketing_Model_Conversion_Goal_Orders
45
  */
46
  public function setDefaultFilters()
47
  {
48
- /* @var $campaginFilter Mzax_Emarketing_Model_Object_Filter_Order_Campaign */
49
- $campaginFilter = $this->addFilter('order_campaign');
50
- if($campaginFilter) {
51
- $campaginFilter->setCampaign($campaginFilter::DEFAULT_CAMPAIGN);
52
- $campaginFilter->setJoin($campaginFilter::DEFAULT_JOIN);
53
-
54
  /* @var $goalFilter Mzax_Emarketing_Model_Object_Filter_Campaign_Goal */
55
- $goalFilter = $campaginFilter->addFilter('campaign_goal');
56
- if($goalFilter) {
57
  $goalFilter->setAction($goalFilter::ACTION_CLICKED);
58
  $goalFilter->setOffsetValue(5);
59
  $goalFilter->setOffsetUnit('days');
60
  }
61
-
62
  }
63
-
64
  /* @var $tableFilter Mzax_Emarketing_Model_Object_Filter_Order_Table */
65
  $tableFilter = $this->addFilter('order_table');
66
- if($tableFilter) {
67
  $tableFilter->setColumn('status');
68
  $tableFilter->setOperator('()');
69
  $tableFilter->setValue(Mage_Sales_Model_Order::STATE_COMPLETE);
70
  }
71
-
72
-
73
  }
74
-
75
-
76
-
77
-
78
  /**
 
79
  *
80
  * @return Mzax_Emarketing_Model_Object_Order
81
  */
@@ -83,16 +73,18 @@ class Mzax_Emarketing_Model_Conversion_Goal_Orders
83
  {
84
  return Mage::getSingleton('mzax_emarketing/object_order');
85
  }
86
-
87
-
88
  /**
89
- *
 
 
 
90
  * @return Mzax_Emarketing_Db_Select
91
  */
92
  public function getAggregationSelect($campaign)
93
  {
94
  $this->setParam('campaign', $campaign);
95
-
96
  $query = $this->getObject()->getQuery();
97
  $query->addBinding('date_filter', 'created_at');
98
  $query->joinSelect('id', $this->getSelect(), 'filter');
@@ -104,21 +96,19 @@ class Mzax_Emarketing_Model_Conversion_Goal_Orders
104
  $query->setColumn('goal_id', 'order_id');
105
  $query->setColumn('goal_time', 'ordered_at');
106
  $query->setColumn('goal_value', 'base_grand_total');
107
-
108
  $query->setColumn('recipient_id', 'IFNULL(MAX(`filter`.`recipient_id`), MAX(`recipients`.`recipient_id`))');
109
-
110
  return $query;
111
  }
112
-
113
-
114
 
115
-
116
  /**
117
  * Get goal <-> recipient binder
118
- *
119
  * @param Mzax_Emarketing_Model_Campaign $campaign
120
  * @param boolean $direct
121
- * @param integer|false $variation
 
122
  * @return Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder
123
  */
124
  public function getRecipientBinder($campaign, $direct = false, $variation = false)
@@ -130,52 +120,54 @@ class Mzax_Emarketing_Model_Conversion_Goal_Orders
130
  $select->addBinding('email', 'customer_email');
131
  $select->addBinding('quote_id', 'quote_id');
132
  $select->addBinding('campaign', new Zend_Db_Expr($campaign->getId()));
133
-
134
  $select->where('{campaign_id} = ?', $campaign->getId());
135
  $select->where('{order_time} > ?', $campaign->getCreatedAt());
136
  $select->where('{order_time} > {sent_at}');
137
  $select->where('{is_mock} = 0');
138
-
139
  $select->setColumn('order_id');
140
  $select->setColumn('order_time');
141
  $select->setColumn('recipient_id');
142
-
143
- if($variation !== false) {
144
  $select->where('{variation_id} = ?', $variation);
145
  }
146
-
147
-
148
  /* @var $binder Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder */
149
  $binder = Mage::getResourceModel('mzax_emarketing/recipient_goal_binder');
150
  $binder->setSelect($select);
151
-
152
-
153
  // create a direct binding using the goal table
154
- $binder->createBinding()
155
- ->joinTable(array(
156
- 'object_type' => Mzax_Emarketing_Model_Goal::TYPE_ORDER,
157
- 'object_id' => '{order_id}'
158
- ), 'goal')
159
- ->joinTable(array('recipient_id' => '{recipient_id}'), 'recipient')
160
- ->addBinding('recipient_id', 'goal.recipient_id')
161
- ->addBinding('sent_at', 'recipient.sent_at')
162
- ->addBinding('variation_id', 'recipient.variation_id')
163
- ->addBinding('campaign_id', 'recipient.campaign_id')
164
- ->addBinding('is_mock', 'recipient.is_mock');
165
-
166
- if(!$direct) {
 
 
 
167
  // see if we can get any indirect bindings via email etc
168
  $campaign->bindRecipients($binder);
169
  }
170
-
171
- Mage::dispatchEvent('mzax_emarketing_order_recipient_binder', array(
172
- 'binder' => $binder,
173
- 'direct' => $direct,
174
- 'campaign' => $campaign
175
- ));
176
-
 
 
 
177
  return $binder;
178
  }
179
-
180
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Conversion_Goal_Orders
 
 
 
 
22
  */
23
+ class Mzax_Emarketing_Model_Conversion_Goal_Orders
24
  extends Mzax_Emarketing_Model_Conversion_Goal_Abstract
25
  {
26
+ /**
27
+ * Retrieve goal title
28
+ *
29
+ * @return string
30
+ */
31
  public function getTitle()
32
  {
33
  return "Magento Orders";
34
  }
 
35
 
 
36
  /**
37
  * Set default filters when newly created
38
  *
40
  */
41
  public function setDefaultFilters()
42
  {
43
+ /* @var $campaignFilter Mzax_Emarketing_Model_Object_Filter_Order_Campaign */
44
+ $campaignFilter = $this->addFilter('order_campaign');
45
+ if ($campaignFilter) {
46
+ $campaignFilter->setCampaign($campaignFilter::DEFAULT_CAMPAIGN);
47
+ $campaignFilter->setJoin($campaignFilter::DEFAULT_JOIN);
48
+
49
  /* @var $goalFilter Mzax_Emarketing_Model_Object_Filter_Campaign_Goal */
50
+ $goalFilter = $campaignFilter->addFilter('campaign_goal');
51
+ if ($goalFilter) {
52
  $goalFilter->setAction($goalFilter::ACTION_CLICKED);
53
  $goalFilter->setOffsetValue(5);
54
  $goalFilter->setOffsetUnit('days');
55
  }
 
56
  }
57
+
58
  /* @var $tableFilter Mzax_Emarketing_Model_Object_Filter_Order_Table */
59
  $tableFilter = $this->addFilter('order_table');
60
+ if ($tableFilter) {
61
  $tableFilter->setColumn('status');
62
  $tableFilter->setOperator('()');
63
  $tableFilter->setValue(Mage_Sales_Model_Order::STATE_COMPLETE);
64
  }
 
 
65
  }
66
+
 
 
 
67
  /**
68
+ * Retrieve object
69
  *
70
  * @return Mzax_Emarketing_Model_Object_Order
71
  */
73
  {
74
  return Mage::getSingleton('mzax_emarketing/object_order');
75
  }
76
+
 
77
  /**
78
+ * Retrieve aggregation select statement
79
+ *
80
+ * @param Mzax_Emarketing_Model_Campaign $campaign
81
+ *
82
  * @return Mzax_Emarketing_Db_Select
83
  */
84
  public function getAggregationSelect($campaign)
85
  {
86
  $this->setParam('campaign', $campaign);
87
+
88
  $query = $this->getObject()->getQuery();
89
  $query->addBinding('date_filter', 'created_at');
90
  $query->joinSelect('id', $this->getSelect(), 'filter');
96
  $query->setColumn('goal_id', 'order_id');
97
  $query->setColumn('goal_time', 'ordered_at');
98
  $query->setColumn('goal_value', 'base_grand_total');
99
+
100
  $query->setColumn('recipient_id', 'IFNULL(MAX(`filter`.`recipient_id`), MAX(`recipients`.`recipient_id`))');
101
+
102
  return $query;
103
  }
 
 
104
 
 
105
  /**
106
  * Get goal <-> recipient binder
107
+ *
108
  * @param Mzax_Emarketing_Model_Campaign $campaign
109
  * @param boolean $direct
110
+ * @param integer|bool $variation
111
+ *
112
  * @return Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder
113
  */
114
  public function getRecipientBinder($campaign, $direct = false, $variation = false)
120
  $select->addBinding('email', 'customer_email');
121
  $select->addBinding('quote_id', 'quote_id');
122
  $select->addBinding('campaign', new Zend_Db_Expr($campaign->getId()));
123
+
124
  $select->where('{campaign_id} = ?', $campaign->getId());
125
  $select->where('{order_time} > ?', $campaign->getCreatedAt());
126
  $select->where('{order_time} > {sent_at}');
127
  $select->where('{is_mock} = 0');
128
+
129
  $select->setColumn('order_id');
130
  $select->setColumn('order_time');
131
  $select->setColumn('recipient_id');
132
+
133
+ if ($variation !== false) {
134
  $select->where('{variation_id} = ?', $variation);
135
  }
136
+
 
137
  /* @var $binder Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder */
138
  $binder = Mage::getResourceModel('mzax_emarketing/recipient_goal_binder');
139
  $binder->setSelect($select);
140
+
 
141
  // create a direct binding using the goal table
142
+ $sql = $binder->createBinding();
143
+ $sql->joinTable(
144
+ array(
145
+ 'object_type' => Mzax_Emarketing_Model_Goal::TYPE_ORDER,
146
+ 'object_id' => '{order_id}'
147
+ ),
148
+ 'goal'
149
+ );
150
+ $sql->joinTable(array('recipient_id' => '{recipient_id}'), 'recipient');
151
+ $sql->addBinding('recipient_id', 'goal.recipient_id');
152
+ $sql->addBinding('sent_at', 'recipient.sent_at');
153
+ $sql->addBinding('variation_id', 'recipient.variation_id');
154
+ $sql->addBinding('campaign_id', 'recipient.campaign_id');
155
+ $sql->addBinding('is_mock', 'recipient.is_mock');
156
+
157
+ if (!$direct) {
158
  // see if we can get any indirect bindings via email etc
159
  $campaign->bindRecipients($binder);
160
  }
161
+
162
+ Mage::dispatchEvent(
163
+ 'mzax_emarketing_order_recipient_binder',
164
+ array(
165
+ 'binder' => $binder,
166
+ 'direct' => $direct,
167
+ 'campaign' => $campaign
168
+ )
169
+ );
170
+
171
  return $binder;
172
  }
173
+ }
 
 
app/code/community/Mzax/Emarketing/Model/Conversion/Select.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,70 +17,66 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Model_Conversion_Select
22
  {
23
-
24
-
25
-
26
-
27
  protected $_bindings = array();
28
-
29
-
 
 
30
  protected $_unionSelects = array();
31
-
32
-
33
-
34
  /**
35
- *
36
  * @param string $name
37
  * @param Zend_Db_Select $select
38
  * @param string $field
39
- * @return Mzax_Emarketing_Model_Conversion_Select
 
40
  */
41
  public function addIndirectBinding($name, Zend_Db_Select $select, $field)
42
  {
43
  $this->_bindings[$name] = array(
44
- 'select' => $select,
45
  'field' => $field
46
  );
 
47
  return $this;
48
  }
49
-
50
-
51
-
52
  /**
53
  * Check if we can bind
54
- *
55
  * @param string $name
56
  * @return string
57
  */
58
  public function getBinding($name)
59
  {
60
- if(isset($this->_bindings[$name])) {
61
  return $this->_bindings[$name]['field'];
62
  }
 
63
  return false;
64
  }
65
-
66
-
67
-
68
  /**
69
  * Bind using binging select
70
- *
71
  * @param string $name
 
72
  * @return Zend_Db_Select
73
  */
74
  public function bind($name)
75
  {
76
  $select = clone $this->_bindings[$name]['select'];
77
  $this->_unionSelects[] = $select;
78
-
79
  return $select;
80
  }
81
-
82
-
83
-
84
-
85
-
86
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Conversion_Select
22
+ */
23
  class Mzax_Emarketing_Model_Conversion_Select
24
  {
25
+ /**
26
+ * @var array[]
27
+ */
 
28
  protected $_bindings = array();
29
+
30
+ /**
31
+ * @var Zend_Db_Select[]
32
+ */
33
  protected $_unionSelects = array();
34
+
 
 
35
  /**
36
+ *
37
  * @param string $name
38
  * @param Zend_Db_Select $select
39
  * @param string $field
40
+ *
41
+ * @return $this
42
  */
43
  public function addIndirectBinding($name, Zend_Db_Select $select, $field)
44
  {
45
  $this->_bindings[$name] = array(
46
+ 'select' => $select,
47
  'field' => $field
48
  );
49
+
50
  return $this;
51
  }
52
+
 
 
53
  /**
54
  * Check if we can bind
55
+ *
56
  * @param string $name
57
  * @return string
58
  */
59
  public function getBinding($name)
60
  {
61
+ if (isset($this->_bindings[$name])) {
62
  return $this->_bindings[$name]['field'];
63
  }
64
+
65
  return false;
66
  }
67
+
 
 
68
  /**
69
  * Bind using binging select
70
+ *
71
  * @param string $name
72
+ *
73
  * @return Zend_Db_Select
74
  */
75
  public function bind($name)
76
  {
77
  $select = clone $this->_bindings[$name]['select'];
78
  $this->_unionSelects[] = $select;
79
+
80
  return $select;
81
  }
82
+ }
 
 
 
 
 
 
app/code/community/Mzax/Emarketing/Model/Conversion/Tracker.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,27 +16,45 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
 
20
  /**
21
- *
22
  * @method string getCreatedAt()
 
 
23
  * @method string getUpdatedAt()
 
 
24
  * @method string getTitle()
 
 
25
  * @method string getDescription()
 
 
26
  * @method string getIsActive()
 
 
27
  * @method string getIsDefault()
 
 
28
  * @method string getIsAggregated()
 
 
29
  * @method string getGoalType()
 
 
30
  * @method string getFilters()
31
- *
32
- * @author Jacob Siefer
33
  *
 
 
 
 
34
  */
35
  class Mzax_Emarketing_Model_Conversion_Tracker
36
  extends Mage_Core_Model_Abstract
37
  {
38
-
39
-
40
-
41
  /**
42
  * Prefix of model events names
43
  *
@@ -53,119 +70,125 @@ class Mzax_Emarketing_Model_Conversion_Tracker
53
  * @var string
54
  */
55
  protected $_eventObject = 'tracker';
56
-
57
-
58
  /**
59
- *
60
  * @var Mzax_Emarketing_Model_Conversion_Goal_Abstract
61
  */
62
  protected $_goal;
63
-
64
-
65
-
 
 
 
66
  protected function _construct()
67
  {
68
  $this->_init('mzax_emarketing/conversion_tracker');
69
  }
70
-
71
-
72
 
 
 
 
 
 
73
  protected function _beforeSave()
74
  {
75
- if($this->_goal) {
76
  $json = $this->_goal->getFilter()->asJson();
77
- if($this->getFilterData() !== $json) {
78
  $this->setFilterData($json);
79
  $this->setIsAggregated(false);
80
  }
81
  }
82
-
83
  $campaigns = $this->getData('campaign_ids');
84
- if(is_array($campaigns)) {
85
- $campaigns = array_filter($campaigns, function($id) {
86
  return (bool) ($id === '*' || ((int) $id));
87
  });
88
  $this->setData('campaign_ids', implode(',', $campaigns));
89
  }
90
-
91
  parent::_beforeSave();
92
  }
93
-
94
-
95
-
96
  /**
97
- *
98
- *
99
- * @return array
100
  */
101
  public function getCampaignIds()
102
  {
103
  $data = $this->getData('campaign_ids');
104
- if(!is_array($data)) {
105
  $data = $data ? explode(',', $data) : array();
106
  $this->setData('campaign_ids', $data);
107
  }
 
108
  return $data;
109
  }
110
-
111
-
112
-
113
-
114
  /**
115
- * Retreive goal model
116
- *
 
 
117
  * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
 
118
  */
119
  public function getGoal($validateFilters = false)
120
  {
121
- if(!$this->_goal && $this->getGoalType()) {
122
- $this->_goal = Mage::getSingleton('mzax_emarketing/conversion_goal')->factory($this->getGoalType());
123
- if(!$this->_goal) {
124
- 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()));
 
 
 
 
 
 
 
 
125
  }
126
  $this->_goal->setTracker($this, $validateFilters);
127
  }
 
128
  return $this->_goal;
129
  }
130
-
131
-
132
-
133
-
134
  /**
135
  * Set this tracker as default tracker
136
- *
137
- * @return Mzax_Emarketing_Model_Conversion_Tracker
138
  */
139
  public function setAsDefault()
140
  {
141
  $this->getResource()->setDefaultTracker($this->getId());
 
142
  return $this;
143
  }
144
-
145
-
146
-
147
  /**
148
  * Check if tracker has any filters defined
149
- *
150
  * @return boolean
151
  */
152
  public function hasFilters()
153
  {
154
  return $this->getGoal()->hasFilters();
155
  }
156
-
157
-
158
-
159
  /**
160
  * Is current default tracker
161
- *
162
  * @return boolean
163
  */
164
  public function isDefault()
165
  {
166
- return (bool) $this->getIsDefault();
167
  }
168
-
169
 
170
  /**
171
  * Is tracker aggregated
@@ -174,11 +197,9 @@ class Mzax_Emarketing_Model_Conversion_Tracker
174
  */
175
  public function isAggregated()
176
  {
177
- return (bool) $this->getIsAggregated();
178
  }
179
-
180
 
181
-
182
  /**
183
  * Is tracker active
184
  *
@@ -186,51 +207,44 @@ class Mzax_Emarketing_Model_Conversion_Tracker
186
  */
187
  public function isActive()
188
  {
189
- return (bool) $this->getIsActive();
190
  }
191
-
192
-
193
-
194
  /**
195
  * Is tracking all campaigns
196
- *
197
  * @return boolean
198
  */
199
  public function isTrackingAllCampaigns()
200
  {
201
  return in_array('*', $this->getCampaignIds());
202
  }
203
-
204
-
205
-
206
  /**
207
- *
 
208
  * @return Mzax_Emarketing_Model_Resource_Campaign_Collection
209
  */
210
  public function getCampaigns()
211
- {
212
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
213
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
214
  $collection->addArchiveFilter(false);
215
-
216
- if(!$this->isTrackingAllCampaigns()) {
217
  $collection->addIdFilter($this->getCampaignIds());
218
  }
219
-
220
  return $collection;
221
  }
222
-
223
-
224
-
225
-
226
-
227
-
228
  /**
229
  * Aggregate data for this tracker
230
- *
231
  * @param string $incremental
232
  * @param Mzax_Emarketing_Model_Campaign $campaign
233
- * @return Mzax_Emarketing_Model_Conversion_Tracker
 
234
  */
235
  public function aggregate($incremental = null, Mzax_Emarketing_Model_Campaign $campaign = null)
236
  {
@@ -239,56 +253,58 @@ class Mzax_Emarketing_Model_Conversion_Tracker
239
  'tracker_id' => $this->getId(),
240
  'verbose' => false
241
  ));
242
-
243
- Mage::dispatchEvent($this->_eventPrefix . '_aggregate',
244
- array('options' => $options, 'campaign' => $campaign, 'tracker' => $this));
245
-
246
- if($incremental) {
247
- $options->setIncremental((int) $incremental);
 
 
 
 
 
 
248
  }
249
- if($campaign) {
250
- if($campaign instanceof Mzax_Emarketing_Model_Campaign) {
251
  $campaign = $campaign->getId();
252
  }
253
- $options->setCampaignId((int) $campaign);
254
  }
255
-
256
  /* @var $report Mzax_Emarketing_Model_Report */
257
  $report = Mage::getSingleton('mzax_emarketing/report');
258
  $report->aggregate($options->toArray());
259
-
260
  return $this;
261
  }
262
-
263
-
264
 
265
  /**
266
  * Load tracker data from file
267
  *
268
  * @param string $filename
 
 
269
  * @throws Mage_Exception
270
- * @return Mzax_Emarketing_Model_Conversion_Tracker
271
  */
272
  public function loadFromFile($filename)
273
  {
274
- if(!file_exists($filename)) {
275
  throw new Mage_Exception("File not found ($filename)");
276
  }
277
- return $this->import(file_get_contents($filename));
 
 
278
  }
279
-
280
-
281
-
282
-
283
-
284
-
285
  /**
286
  * Load tracker data from encoded string
287
  *
288
- * @see export()
289
  * @param string $str
290
- * @throws Mage_Exception
291
  * @return Mzax_Emarketing_Model_Conversion_Tracker
 
292
  */
293
  public function import($str)
294
  {
@@ -298,15 +314,14 @@ class Mzax_Emarketing_Model_Conversion_Tracker
298
  $this->_goal = null;
299
  // check and make sure goal and filters exist
300
  $this->getGoal(true);
301
- }
302
- catch(Zend_Json_Exception $e) {
303
  throw new Mage_Exception("Failed to decode template file");
304
  }
305
  return $this;
306
  }
307
-
308
-
309
-
310
  /**
311
  * Convert to tracker to encoded string
312
  *
@@ -314,17 +329,19 @@ class Mzax_Emarketing_Model_Conversion_Tracker
314
  */
315
  public function export()
316
  {
317
- // set current extension version
318
- $this->setVersion(Mage::helper('mzax_emarketing')->getVersion());
319
-
 
320
  $json = $this->toJson(array('version', 'title', 'description', 'goal_type', 'filter_data'));
321
  return base64_encode($json);
322
  }
323
-
324
-
325
-
326
-
327
-
 
328
  public function __clone()
329
  {
330
  $this->setId(null);
@@ -332,10 +349,10 @@ class Mzax_Emarketing_Model_Conversion_Tracker
332
  $this->setIsAggregated(true);
333
  $this->setCreatedAt(null);
334
  $this->setUpdatedAt(null);
335
-
336
  return $this;
337
  }
338
-
339
-
340
-
341
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
+
21
  /**
22
+ *
23
  * @method string getCreatedAt()
24
+ * @method $this setCreatedAt(string $value)
25
+ *
26
  * @method string getUpdatedAt()
27
+ * @method $this setUpdatedAt(string $value)
28
+ *
29
  * @method string getTitle()
30
+ * @method $this setTitle(string $value)
31
+ *
32
  * @method string getDescription()
33
+ * @method $this setDescription(string $value)
34
+ *
35
  * @method string getIsActive()
36
+ * @method $this setIsActive(bool $value)
37
+ *
38
  * @method string getIsDefault()
39
+ * @method $this setIsDefault(bool $value)
40
+ *
41
  * @method string getIsAggregated()
42
+ * @method $this setIsAggregated(bool $value)
43
+ *
44
  * @method string getGoalType()
45
+ * @method $this setGoalType(string $value)
46
+ *
47
  * @method string getFilters()
48
+ * @method $this setFilters(string $value)
 
49
  *
50
+ * @method string getFilterData()
51
+ * @method $this setFilterData(string $json)
52
+ *
53
+ * @method Mzax_Emarketing_Model_Resource_Conversion_Tracker getResource()
54
  */
55
  class Mzax_Emarketing_Model_Conversion_Tracker
56
  extends Mage_Core_Model_Abstract
57
  {
 
 
 
58
  /**
59
  * Prefix of model events names
60
  *
70
  * @var string
71
  */
72
  protected $_eventObject = 'tracker';
73
+
 
74
  /**
75
+ *
76
  * @var Mzax_Emarketing_Model_Conversion_Goal_Abstract
77
  */
78
  protected $_goal;
79
+
80
+ /**
81
+ * Model Constructor
82
+ *
83
+ * @return void
84
+ */
85
  protected function _construct()
86
  {
87
  $this->_init('mzax_emarketing/conversion_tracker');
88
  }
 
 
89
 
90
+ /**
91
+ * Before model save
92
+ *
93
+ * @return void
94
+ */
95
  protected function _beforeSave()
96
  {
97
+ if ($this->_goal) {
98
  $json = $this->_goal->getFilter()->asJson();
99
+ if ($this->getFilterData() !== $json) {
100
  $this->setFilterData($json);
101
  $this->setIsAggregated(false);
102
  }
103
  }
104
+
105
  $campaigns = $this->getData('campaign_ids');
106
+ if (is_array($campaigns)) {
107
+ $campaigns = array_filter($campaigns, function ($id) {
108
  return (bool) ($id === '*' || ((int) $id));
109
  });
110
  $this->setData('campaign_ids', implode(',', $campaigns));
111
  }
112
+
113
  parent::_beforeSave();
114
  }
115
+
 
 
116
  /**
117
+ * Retrieve campaign ids
118
+ *
119
+ * @return string[]
120
  */
121
  public function getCampaignIds()
122
  {
123
  $data = $this->getData('campaign_ids');
124
+ if (!is_array($data)) {
125
  $data = $data ? explode(',', $data) : array();
126
  $this->setData('campaign_ids', $data);
127
  }
128
+
129
  return $data;
130
  }
131
+
 
 
 
132
  /**
133
+ * Retrieve goal model
134
+ *
135
+ * @param bool $validateFilters
136
+ *
137
  * @return Mzax_Emarketing_Model_Conversion_Goal_Abstract
138
+ * @throws Mage_Exception
139
  */
140
  public function getGoal($validateFilters = false)
141
  {
142
+ if (!$this->_goal && $this->getGoalType()) {
143
+ /** @var Mzax_Emarketing_Model_Conversion_Goal $factory */
144
+ $factory = Mage::getSingleton('mzax_emarketing/conversion_goal');
145
+
146
+ $this->_goal = $factory->factory($this->getGoalType());
147
+ if (!$this->_goal) {
148
+ throw new Mage_Exception(
149
+ Mage::helper('mzax_emarketing')->__(
150
+ 'Failed to initialise goal type “%s”. This goal type might not be installed on your system.',
151
+ $this->getGoalType()
152
+ )
153
+ );
154
  }
155
  $this->_goal->setTracker($this, $validateFilters);
156
  }
157
+
158
  return $this->_goal;
159
  }
160
+
 
 
 
161
  /**
162
  * Set this tracker as default tracker
163
+ *
164
+ * @return $this
165
  */
166
  public function setAsDefault()
167
  {
168
  $this->getResource()->setDefaultTracker($this->getId());
169
+
170
  return $this;
171
  }
172
+
 
 
173
  /**
174
  * Check if tracker has any filters defined
175
+ *
176
  * @return boolean
177
  */
178
  public function hasFilters()
179
  {
180
  return $this->getGoal()->hasFilters();
181
  }
182
+
 
 
183
  /**
184
  * Is current default tracker
185
+ *
186
  * @return boolean
187
  */
188
  public function isDefault()
189
  {
190
+ return (bool)$this->getIsDefault();
191
  }
 
192
 
193
  /**
194
  * Is tracker aggregated
197
  */
198
  public function isAggregated()
199
  {
200
+ return (bool)$this->getIsAggregated();
201
  }
 
202
 
 
203
  /**
204
  * Is tracker active
205
  *
207
  */
208
  public function isActive()
209
  {
210
+ return (bool)$this->getIsActive();
211
  }
212
+
 
 
213
  /**
214
  * Is tracking all campaigns
215
+ *
216
  * @return boolean
217
  */
218
  public function isTrackingAllCampaigns()
219
  {
220
  return in_array('*', $this->getCampaignIds());
221
  }
222
+
 
 
223
  /**
224
+ * Retrieve campaigns tracked by this tracker
225
+ *
226
  * @return Mzax_Emarketing_Model_Resource_Campaign_Collection
227
  */
228
  public function getCampaigns()
229
+ {
230
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
231
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
232
  $collection->addArchiveFilter(false);
233
+
234
+ if (!$this->isTrackingAllCampaigns()) {
235
  $collection->addIdFilter($this->getCampaignIds());
236
  }
237
+
238
  return $collection;
239
  }
240
+
 
 
 
 
 
241
  /**
242
  * Aggregate data for this tracker
243
+ *
244
  * @param string $incremental
245
  * @param Mzax_Emarketing_Model_Campaign $campaign
246
+ *
247
+ * @return $this
248
  */
249
  public function aggregate($incremental = null, Mzax_Emarketing_Model_Campaign $campaign = null)
250
  {
253
  'tracker_id' => $this->getId(),
254
  'verbose' => false
255
  ));
256
+
257
+ Mage::dispatchEvent(
258
+ $this->_eventPrefix . '_aggregate',
259
+ array(
260
+ 'options' => $options,
261
+ 'campaign' => $campaign,
262
+ 'tracker' => $this
263
+ )
264
+ );
265
+
266
+ if ($incremental) {
267
+ $options->setData('incremental', (int)$incremental);
268
  }
269
+ if ($campaign) {
270
+ if ($campaign instanceof Mzax_Emarketing_Model_Campaign) {
271
  $campaign = $campaign->getId();
272
  }
273
+ $options->setData('campaign_id', (int)$campaign);
274
  }
275
+
276
  /* @var $report Mzax_Emarketing_Model_Report */
277
  $report = Mage::getSingleton('mzax_emarketing/report');
278
  $report->aggregate($options->toArray());
279
+
280
  return $this;
281
  }
 
 
282
 
283
  /**
284
  * Load tracker data from file
285
  *
286
  * @param string $filename
287
+ *
288
+ * @return $this
289
  * @throws Mage_Exception
 
290
  */
291
  public function loadFromFile($filename)
292
  {
293
+ if (!file_exists($filename)) {
294
  throw new Mage_Exception("File not found ($filename)");
295
  }
296
+ $this->import(file_get_contents($filename));
297
+
298
+ return $this;
299
  }
300
+
 
 
 
 
 
301
  /**
302
  * Load tracker data from encoded string
303
  *
 
304
  * @param string $str
305
+ *
306
  * @return Mzax_Emarketing_Model_Conversion_Tracker
307
+ * @throws Mage_Exception
308
  */
309
  public function import($str)
310
  {
314
  $this->_goal = null;
315
  // check and make sure goal and filters exist
316
  $this->getGoal(true);
317
+ } catch (Zend_Json_Exception $e) {
 
318
  throw new Mage_Exception("Failed to decode template file");
319
  }
320
  return $this;
321
  }
322
+
323
+
324
+
325
  /**
326
  * Convert to tracker to encoded string
327
  *
329
  */
330
  public function export()
331
  {
332
+ /** @var Mzax_Emarketing_Helper_Data $helper */
333
+ $helper = Mage::helper('mzax_emarketing');
334
+ $this->setData('version', $helper->getVersion());
335
+
336
  $json = $this->toJson(array('version', 'title', 'description', 'goal_type', 'filter_data'));
337
  return base64_encode($json);
338
  }
339
+
340
+ /**
341
+ * Clone Object
342
+ *
343
+ * @return $this
344
+ */
345
  public function __clone()
346
  {
347
  $this->setId(null);
349
  $this->setIsAggregated(true);
350
  $this->setCreatedAt(null);
351
  $this->setUpdatedAt(null);
352
+
353
  return $this;
354
  }
355
+
356
+
357
+
358
  }
app/code/community/Mzax/Emarketing/Model/DomainThrottle.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,186 +17,178 @@
18
  */
19
 
20
 
21
-
 
 
22
  class Mzax_Emarketing_Model_DomainThrottle
23
  {
24
-
25
-
26
  /**
27
- *
 
28
  * @var Mzax_Presist
29
  */
30
- protected $_presist;
31
-
32
 
33
-
34
  /**
35
  * The number of seconds for the threshold.
36
  * Works togher with send threshold
37
- *
38
  * @var integer
39
  */
40
  protected $_defaultTimeThreshold = 300;
41
-
42
-
43
-
44
  /**
45
  * The number of emails that can be send within the
46
  * threshold time before we rest the domain.
47
- *
48
  * @var integer
49
  */
50
  protected $_defaultSendThreshold = 50;
51
-
52
-
53
  /**
54
  * The number of seconds to wait before sending an email
55
  * to this domain again after the send threshold exceeded
56
- *
57
  * @var integer
58
  */
59
  protected $_defaultRestTime = 600;
60
-
61
-
62
  /**
63
  * Domain specific options
64
- *
65
  * @var array
66
  */
67
  protected $_domainOptions = array();
68
-
69
-
70
-
71
-
72
-
73
-
74
  public function __construct()
75
  {
76
- $this->_presist = new Mzax_Presist;
77
- $this->_presist->open(Mage::getBaseDir('tmp') . DS . 'domain_throttle.data');
78
-
79
- if(empty($this->_presist->data)) {
80
- $this->_presist->data = array();
 
 
81
  }
82
  }
83
-
84
-
85
-
86
  /**
87
  * Is given domain resting
88
- *
89
  * 0 = no resting, send out emails
90
- *
91
  * @param string $domain
 
92
  * @return integer
93
  */
94
  public function isResting($domain)
95
  {
96
  $domain = strtolower($domain);
97
- $data = &$this->_presist->data;
98
- if(!$domain || !isset($data[$domain])) {
99
  return false;
100
  }
101
  list($restTill, $lastTime, $count) = $data[$domain];
102
-
103
  return max(0, $restTill - time());
104
  }
105
-
106
-
107
-
108
-
109
  /**
110
  * Calculate current counter value
111
- *
112
  * The counter value can slowly decrease if enough
113
  * time passes without any send outs
114
- *
115
  * @param string $domain
116
  * @param array $entry
 
117
  * @return number
118
  */
119
  protected function _calcCounter($domain, $entry)
120
  {
121
- $timeThereshold = $this->getTimeThreshold($domain);
122
-
 
123
  list($restTill, $lastTime, $count) = $entry;
124
-
125
  // @todo maybe there is better formular
126
- return $count - max(floor(($now - $lastTime)/$timeThereshold), $count);
127
  }
128
-
129
-
130
-
131
-
132
  /**
133
  * Touch domain and increase the internal counter
134
  * and check if we have reached the threshold and
135
  * should wait with the next email
136
- *
137
  * @param string $domain
 
 
138
  */
139
  public function touchDomain($domain)
140
  {
141
  $domain = strtolower($domain);
142
-
143
  $now = time();
144
-
145
- $data = &$this->_presist->data;
146
-
147
-
148
- if(!isset($data[$domain])) {
149
  $restTill = false;
150
  $lastTime = $now;
151
  $count = 1;
152
- }
153
- else {
154
  list($restTill, $lastTime, $count) = $data[$domain];
155
  $count = $this->_calcCounter($domain, $data[$domain]);
156
  $count++;
157
  }
158
-
159
- if($count >= $this->getSendThreshold($domain)) {
160
  $restTill = $now + $this->getRestTime($domain);
161
  }
162
-
163
  $data[$domain] = array($restTill, $lastTime, $count);
164
  }
165
-
166
-
167
-
168
  /**
169
  * Check all records and remove the unrelevant ones
170
- *
171
- * @return Mzax_Emarketing_Model_Domain
172
  */
173
  public function purge()
174
  {
175
- $data = &$this->_presist->data;
176
- foreach($data as $domain => $entry) {
177
- if(!$this->_calcCounter($domain, $data[$domain])) {
178
  unset($data[$domain]);
179
  }
180
  }
 
181
  return $this;
182
  }
183
-
184
-
185
-
 
186
  public function __destruct()
187
  {
188
  try {
189
- $this->_presist->close();
190
- }
191
- catch(Exception $e) {
192
  // ignore
193
  }
194
  }
195
-
196
-
197
-
198
-
199
-
200
-
 
 
 
 
 
201
  public function addDomainOption($domain, $timeThreshold, $sendThreshold, $restTime)
202
  {
203
  $domain = strtolower($domain);
@@ -206,60 +197,96 @@ class Mzax_Emarketing_Model_DomainThrottle
206
  'send_threshold' => (int) $sendThreshold,
207
  'rest_time' => (int) $restTime
208
  );
 
209
  return $this;
210
  }
211
-
212
-
213
 
 
 
 
 
 
 
 
214
  public function setTimeThreshold($value)
215
  {
216
  $this->_defaultTimeThreshold = (int) $value;
 
217
  return $this;
218
  }
219
-
220
-
 
 
 
 
 
 
221
  public function setSendThreshold($value)
222
  {
223
  $this->_defaultSendThreshold = (int) $value;
224
  return $this;
225
  }
226
-
 
 
 
 
 
 
 
227
  public function setRestTime($value)
228
  {
229
  $this->_defaultRestTime = (int) $value;
 
230
  return $this;
231
  }
232
-
233
-
234
-
 
 
 
 
 
235
  public function getTimeThreshold($domain)
236
  {
237
- if(isset($this->_domainOptions[$domain])) {
238
  return $this->_domainOptions[$domain]['time_threshold'];
239
  }
 
240
  return $this->_defaultTimeThreshold;
241
  }
242
-
243
-
 
 
 
 
 
 
244
  public function getSendThreshold($domain)
245
  {
246
- if(isset($this->_domainOptions[$domain])) {
247
  return $this->_domainOptions[$domain]['send_threshold'];
248
  }
 
249
  return $this->_defaultSendThreshold;
250
  }
251
-
 
 
 
 
 
 
 
252
  public function getRestTime($domain)
253
  {
254
- if(isset($this->_domainOptions[$domain])) {
255
  return $this->_domainOptions[$domain]['rest_time'];
256
  }
 
257
  return $this->_defaultRestTime;
258
  }
259
-
260
-
261
-
262
-
263
-
264
-
265
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_DomainThrottle
22
+ */
23
  class Mzax_Emarketing_Model_DomainThrottle
24
  {
 
 
25
  /**
26
+ * Persist data
27
+ *
28
  * @var Mzax_Presist
29
  */
30
+ protected $_persist;
 
31
 
 
32
  /**
33
  * The number of seconds for the threshold.
34
  * Works togher with send threshold
35
+ *
36
  * @var integer
37
  */
38
  protected $_defaultTimeThreshold = 300;
39
+
 
 
40
  /**
41
  * The number of emails that can be send within the
42
  * threshold time before we rest the domain.
43
+ *
44
  * @var integer
45
  */
46
  protected $_defaultSendThreshold = 50;
47
+
 
48
  /**
49
  * The number of seconds to wait before sending an email
50
  * to this domain again after the send threshold exceeded
51
+ *
52
  * @var integer
53
  */
54
  protected $_defaultRestTime = 600;
55
+
 
56
  /**
57
  * Domain specific options
58
+ *
59
  * @var array
60
  */
61
  protected $_domainOptions = array();
62
+
63
+ /**
64
+ * Mzax_Emarketing_Model_DomainThrottle constructor.
65
+ */
 
 
66
  public function __construct()
67
  {
68
+ $persistData = Mage::getBaseDir('tmp') . DS . 'domain_throttle.data';
69
+
70
+ $this->_persist = new Mzax_Presist;
71
+ $this->_persist->open($persistData);
72
+
73
+ if (empty($this->_persist->data)) {
74
+ $this->_persist->data = array();
75
  }
76
  }
77
+
 
 
78
  /**
79
  * Is given domain resting
80
+ *
81
  * 0 = no resting, send out emails
82
+ *
83
  * @param string $domain
84
+ *
85
  * @return integer
86
  */
87
  public function isResting($domain)
88
  {
89
  $domain = strtolower($domain);
90
+ $data = &$this->_persist->data;
91
+ if (!$domain || !isset($data[$domain])) {
92
  return false;
93
  }
94
  list($restTill, $lastTime, $count) = $data[$domain];
95
+
96
  return max(0, $restTill - time());
97
  }
98
+
 
 
 
99
  /**
100
  * Calculate current counter value
101
+ *
102
  * The counter value can slowly decrease if enough
103
  * time passes without any send outs
104
+ *
105
  * @param string $domain
106
  * @param array $entry
107
+ *
108
  * @return number
109
  */
110
  protected function _calcCounter($domain, $entry)
111
  {
112
+ $now = time();
113
+ $timeThreshold = $this->getTimeThreshold($domain);
114
+
115
  list($restTill, $lastTime, $count) = $entry;
116
+
117
  // @todo maybe there is better formular
118
+ return $count - max(floor(($now - $lastTime)/$timeThreshold), $count);
119
  }
120
+
 
 
 
121
  /**
122
  * Touch domain and increase the internal counter
123
  * and check if we have reached the threshold and
124
  * should wait with the next email
125
+ *
126
  * @param string $domain
127
+ *
128
+ * @return void
129
  */
130
  public function touchDomain($domain)
131
  {
132
  $domain = strtolower($domain);
 
133
  $now = time();
134
+ $data = &$this->_persist->data;
135
+
136
+ if (!isset($data[$domain])) {
 
 
137
  $restTill = false;
138
  $lastTime = $now;
139
  $count = 1;
140
+ } else {
 
141
  list($restTill, $lastTime, $count) = $data[$domain];
142
  $count = $this->_calcCounter($domain, $data[$domain]);
143
  $count++;
144
  }
145
+
146
+ if ($count >= $this->getSendThreshold($domain)) {
147
  $restTill = $now + $this->getRestTime($domain);
148
  }
149
+
150
  $data[$domain] = array($restTill, $lastTime, $count);
151
  }
152
+
 
 
153
  /**
154
  * Check all records and remove the unrelevant ones
155
+ *
156
+ * @return $this
157
  */
158
  public function purge()
159
  {
160
+ $data = &$this->_persist->data;
161
+ foreach ($data as $domain => $entry) {
162
+ if (!$this->_calcCounter($domain, $data[$domain])) {
163
  unset($data[$domain]);
164
  }
165
  }
166
+
167
  return $this;
168
  }
169
+
170
+ /**
171
+ * Destructor
172
+ */
173
  public function __destruct()
174
  {
175
  try {
176
+ $this->_persist->close();
177
+ } catch (Exception $e) {
 
178
  // ignore
179
  }
180
  }
181
+
182
+ /**
183
+ * Add domain option
184
+ *
185
+ * @param string $domain
186
+ * @param int $timeThreshold
187
+ * @param int $sendThreshold
188
+ * @param int $restTime
189
+ *
190
+ * @return $this
191
+ */
192
  public function addDomainOption($domain, $timeThreshold, $sendThreshold, $restTime)
193
  {
194
  $domain = strtolower($domain);
197
  'send_threshold' => (int) $sendThreshold,
198
  'rest_time' => (int) $restTime
199
  );
200
+
201
  return $this;
202
  }
 
 
203
 
204
+ /**
205
+ * Set threshold
206
+ *
207
+ * @param int $value
208
+ *
209
+ * @return $this
210
+ */
211
  public function setTimeThreshold($value)
212
  {
213
  $this->_defaultTimeThreshold = (int) $value;
214
+
215
  return $this;
216
  }
217
+
218
+ /**
219
+ * Set send threshold
220
+ *
221
+ * @param int $value
222
+ *
223
+ * @return $this
224
+ */
225
  public function setSendThreshold($value)
226
  {
227
  $this->_defaultSendThreshold = (int) $value;
228
  return $this;
229
  }
230
+
231
+ /**
232
+ * Set rest time
233
+ *
234
+ * @param int $value
235
+ *
236
+ * @return $this
237
+ */
238
  public function setRestTime($value)
239
  {
240
  $this->_defaultRestTime = (int) $value;
241
+
242
  return $this;
243
  }
244
+
245
+ /**
246
+ * Retrieve threshold by domain
247
+ *
248
+ * @param string $domain
249
+ *
250
+ * @return int
251
+ */
252
  public function getTimeThreshold($domain)
253
  {
254
+ if (isset($this->_domainOptions[$domain])) {
255
  return $this->_domainOptions[$domain]['time_threshold'];
256
  }
257
+
258
  return $this->_defaultTimeThreshold;
259
  }
260
+
261
+ /**
262
+ * Retrieve send threshold by domain
263
+ *
264
+ * @param string $domain
265
+ *
266
+ * @return int
267
+ */
268
  public function getSendThreshold($domain)
269
  {
270
+ if (isset($this->_domainOptions[$domain])) {
271
  return $this->_domainOptions[$domain]['send_threshold'];
272
  }
273
+
274
  return $this->_defaultSendThreshold;
275
  }
276
+
277
+ /**
278
+ * Retrieve rest time by domain
279
+ *
280
+ * @param string $domain
281
+ *
282
+ * @return int
283
+ */
284
  public function getRestTime($domain)
285
  {
286
+ if (isset($this->_domainOptions[$domain])) {
287
  return $this->_domainOptions[$domain]['rest_time'];
288
  }
289
+
290
  return $this->_defaultRestTime;
291
  }
 
 
 
 
 
 
292
  }
app/code/community/Mzax/Emarketing/Model/Email.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,67 +19,75 @@
20
 
21
 
22
  /**
23
- *
 
24
  * @method string getCreatedAt()
 
 
25
  * @method string getMessageId()
 
 
26
  * @method string getCampaignId()
 
 
27
  * @method string getRecipientId()
28
- *
29
- * @author Jacob Siefer
30
  *
 
 
31
  */
32
  abstract class Mzax_Emarketing_Model_Email
33
- extends Mage_Core_Model_Abstract
34
  {
35
-
36
-
37
  /**
 
38
  *
39
  * @var Mzax_Emarketing_Model_Recipient
40
  */
41
  protected $_recipient;
42
-
43
-
44
  /**
 
45
  *
46
  * @var Mzax_Emarketing_Model_Campaign
47
  */
48
  protected $_campaign;
49
-
50
-
51
-
52
-
 
 
53
  protected function _beforeSave()
54
  {
55
- if($this->_campaign) {
56
  $this->setCampaignId($this->_campaign->getId());
57
  }
58
- if($this->_recipient) {
59
  $this->setRecipientId($this->_recipient->getId());
60
  }
61
-
62
- return parent::_beforeSave();
 
63
  }
64
-
65
-
66
 
67
  /**
68
  * Set campaign
69
  *
70
  * @param Mzax_Emarketing_Model_Campaign $campaign
71
- * @return Mzax_Emarketing_Model_Recipient_Bounce_Message
 
72
  */
73
  public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
74
  {
75
  $this->_campaign = $campaign;
76
- if( $this->_recipient ) {
77
  $this->_recipient->setCampaign($campaign);
78
  }
 
79
  return $this;
80
  }
81
-
82
-
83
-
84
  /**
85
  * Retrieve campaign if available
86
  *
@@ -88,35 +95,33 @@ abstract class Mzax_Emarketing_Model_Email
88
  */
89
  public function getCampaign()
90
  {
91
- if(!$this->_campaign && $this->getCampaignId()) {
92
- $this->_campaign = Mage::getModel('mzax_emarketing/campaign')->load($this->getCampaignId());
 
93
  }
 
94
  return $this->_campaign;
95
  }
96
-
97
-
98
-
99
-
100
  /**
101
  * Set recipient
102
  *
103
  * @param Mzax_Emarketing_Model_Recipient $recipient
104
- * @return Mzax_Emarketing_Model_Recipient_Bounce_Message
 
105
  */
106
  public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
107
  {
108
  $this->_recipient = $recipient;
109
- if( $this->_campaign ) {
110
  $this->_recipient->setCampaign($this->_campaign);
111
- }
112
- else {
113
  $this->_campaign = $recipient->getCampaign();
114
  }
 
115
  return $this;
116
  }
117
-
118
-
119
-
120
  /**
121
  * Retrieve recipient if available
122
  *
@@ -124,44 +129,38 @@ abstract class Mzax_Emarketing_Model_Email
124
  */
125
  public function getRecipient()
126
  {
127
- if(!$this->_recipient && $this->getRecipientId()) {
128
- $this->_recipient = Mage::getModel('mzax_emarketing/recipient')->load($this->getRecipientId());
 
129
  }
 
130
  return $this->_recipient;
131
  }
132
-
133
-
134
-
135
  /**
136
  * Retrieve store
137
- *
138
- * @return Mage_Core_Model_Store|NULL
139
  */
140
  public function getStore()
141
  {
142
- if($this->_campaign) {
143
  return $this->_campaign->getStore();
144
- }
 
145
  return Mage::app()->getStore($this->getStoreId());
146
  }
147
-
148
-
149
-
150
  /**
151
  * Load email by message id
152
- *
153
  * @param string $messageId
154
- * @return Mzax_Emarketing_Model_Email
155
  */
156
  public function loadByMessageId($messageId)
157
  {
158
  $this->getResource()->load($this, $messageId, 'message_id');
 
159
  return $this;
160
  }
161
-
162
-
163
-
164
-
165
-
166
-
167
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
 
21
  /**
22
+ * Class Mzax_Emarketing_Model_Email
23
+ *
24
  * @method string getCreatedAt()
25
+ * @method $this setCreatedAt(string $value)
26
+ *
27
  * @method string getMessageId()
28
+ * @method $this setMessageId(string $value)
29
+ *
30
  * @method string getCampaignId()
31
+ * @method $this setCampaignId(string $value)
32
+ *
33
  * @method string getRecipientId()
34
+ * @method $this setRecipientId(string $value)
 
35
  *
36
+ * @method string getStoreId()
37
+ * @method $this setStoreId(string $value)
38
  */
39
  abstract class Mzax_Emarketing_Model_Email
40
+ extends Mage_Core_Model_Abstract
41
  {
 
 
42
  /**
43
+ * Recipient
44
  *
45
  * @var Mzax_Emarketing_Model_Recipient
46
  */
47
  protected $_recipient;
48
+
 
49
  /**
50
+ * Campaign
51
  *
52
  * @var Mzax_Emarketing_Model_Campaign
53
  */
54
  protected $_campaign;
55
+
56
+ /**
57
+ * Before save
58
+ *
59
+ * @return $this
60
+ */
61
  protected function _beforeSave()
62
  {
63
+ if ($this->_campaign) {
64
  $this->setCampaignId($this->_campaign->getId());
65
  }
66
+ if ($this->_recipient) {
67
  $this->setRecipientId($this->_recipient->getId());
68
  }
69
+ parent::_beforeSave();
70
+
71
+ return $this;
72
  }
 
 
73
 
74
  /**
75
  * Set campaign
76
  *
77
  * @param Mzax_Emarketing_Model_Campaign $campaign
78
+ *
79
+ * @return $this
80
  */
81
  public function setCampaign(Mzax_Emarketing_Model_Campaign $campaign)
82
  {
83
  $this->_campaign = $campaign;
84
+ if ($this->_recipient) {
85
  $this->_recipient->setCampaign($campaign);
86
  }
87
+
88
  return $this;
89
  }
90
+
 
 
91
  /**
92
  * Retrieve campaign if available
93
  *
95
  */
96
  public function getCampaign()
97
  {
98
+ if (!$this->_campaign && $this->getCampaignId()) {
99
+ $this->_campaign = Mage::getModel('mzax_emarketing/campaign');
100
+ $this->_campaign->load($this->getCampaignId());
101
  }
102
+
103
  return $this->_campaign;
104
  }
105
+
 
 
 
106
  /**
107
  * Set recipient
108
  *
109
  * @param Mzax_Emarketing_Model_Recipient $recipient
110
+ *
111
+ * @return $this
112
  */
113
  public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
114
  {
115
  $this->_recipient = $recipient;
116
+ if ($this->_campaign) {
117
  $this->_recipient->setCampaign($this->_campaign);
118
+ } else {
 
119
  $this->_campaign = $recipient->getCampaign();
120
  }
121
+
122
  return $this;
123
  }
124
+
 
 
125
  /**
126
  * Retrieve recipient if available
127
  *
129
  */
130
  public function getRecipient()
131
  {
132
+ if (!$this->_recipient && $this->getRecipientId()) {
133
+ $this->_recipient = Mage::getModel('mzax_emarketing/recipient');
134
+ $this->_recipient->load($this->getRecipientId());
135
  }
136
+
137
  return $this->_recipient;
138
  }
139
+
 
 
140
  /**
141
  * Retrieve store
142
+ *
143
+ * @return Mage_Core_Model_Store
144
  */
145
  public function getStore()
146
  {
147
+ if ($this->_campaign) {
148
  return $this->_campaign->getStore();
149
+ }
150
+
151
  return Mage::app()->getStore($this->getStoreId());
152
  }
153
+
 
 
154
  /**
155
  * Load email by message id
156
+ *
157
  * @param string $messageId
158
+ * @return $this
159
  */
160
  public function loadByMessageId($messageId)
161
  {
162
  $this->getResource()->load($this, $messageId, 'message_id');
163
+
164
  return $this;
165
  }
 
 
 
 
 
 
166
  }
app/code/community/Mzax/Emarketing/Model/Factory.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mzax
13
+ * @package Mzax_Emarketing
14
+ * @author Jacob Siefer (jacob@mzax.de)
15
+ * @copyright Copyright (c) 2015 Jacob Siefer
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+
20
+
21
+ /**
22
+ * Class Mzax_Emarketing_Model_Factory
23
+ *
24
+ * Object and model factory
25
+ */
26
+ class Mzax_Emarketing_Model_Factory
27
+ {
28
+ /**
29
+ * Create new recipient model
30
+ *
31
+ * @return Mzax_Emarketing_Model_Recipient
32
+ */
33
+ public function createRecipient()
34
+ {
35
+ return Mage::getModel('mzax_emarketing/recipient');
36
+ }
37
+
38
+ /**
39
+ * @return Mzax_Emarketing_Model_Resource_Recipient_Collection
40
+ */
41
+ public function createRecipientCollection()
42
+ {
43
+ return Mage::getResourceModel('mzax_emarketing/recipient_collection');
44
+ }
45
+
46
+ /**
47
+ * @return Mzax_Emarketing_Model_Link_Reference
48
+ */
49
+ public function createLinkReference()
50
+ {
51
+ return Mage::getModel('mzax_emarketing/link_reference');
52
+ }
53
+
54
+ /**
55
+ * Create new campaign model
56
+ *
57
+ * @return Mzax_Emarketing_Model_Campaign
58
+ */
59
+ public function createCampaign()
60
+ {
61
+ return Mage::getModel('mzax_emarketing/campaign');
62
+ }
63
+
64
+ /**
65
+ * @return Mzax_Emarketing_Model_Medium_Email_Snippets
66
+ */
67
+ public function createSnippets()
68
+ {
69
+ return Mage::getModel('mzax_emarketing/medium_email_snippets');
70
+ }
71
+
72
+ /**
73
+ * @return Mzax_Emarketing_Model_Campaign_Variation
74
+ */
75
+ public function createVariation()
76
+ {
77
+ return Mage::getModel('mzax_emarketing/campaign_variation');
78
+ }
79
+
80
+ /**
81
+ * @return Mzax_Emarketing_Model_Resource_Campaign_Variation_Collection
82
+ */
83
+ public function createVariationCollection()
84
+ {
85
+ return Mage::getResourceModel('mzax_emarketing/campaign_variation_collection');
86
+ }
87
+
88
+ /**
89
+ * @return Mzax_Emarketing_Model_Resource_Conversion_Tracker_Collection
90
+ */
91
+ public function createTrackerCollection()
92
+ {
93
+ return Mage::getResourceModel('mzax_emarketing/conversion_tracker_collection');
94
+ }
95
+
96
+ /**
97
+ * @return Mzax_Emarketing_Model_Newsletter_List
98
+ */
99
+ public function createNewsletterList()
100
+ {
101
+ return Mage::getModel('mzax_emarketing/newsletter_list');
102
+ }
103
+
104
+ /**
105
+ * @return Mzax_Emarketing_Model_Resource_Newsletter_List_Collection
106
+ */
107
+ public function createNewsletterListCollection()
108
+ {
109
+ return Mage::getResourceModel('mzax_emarketing/newsletter_list_collection');
110
+ }
111
+
112
+ /**
113
+ * Create url model
114
+ *
115
+ * @return Mage_Core_Model_Url
116
+ */
117
+ public function createUrl()
118
+ {
119
+ return Mage::getModel('core/url');
120
+ }
121
+
122
+ /**
123
+ * @return Mage_Newsletter_Model_Subscriber
124
+ */
125
+ public function createNewsletterSubscriber()
126
+ {
127
+ return Mage::getModel('newsletter/subscriber');
128
+ }
129
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/Ace.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,31 +16,45 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Model_Form_Element_Ace extends Varien_Data_Form_Element_Abstract
22
  {
23
-
 
 
 
 
 
 
 
 
 
 
24
 
 
 
25
 
 
 
 
26
  public function getEditorClass()
27
  {
28
  return 'mzax.ui.TextEditor';
29
  }
30
-
31
-
32
 
 
 
 
33
  public function getTypeClass()
34
  {
35
  return 'mage-ace-editor';
36
  }
37
-
38
-
39
-
40
-
41
-
42
  /**
43
  * Retrieve editor options
44
- *
45
  * @return array
46
  */
47
  public function getEditorOptions()
@@ -54,28 +67,28 @@ class Mzax_Emarketing_Model_Form_Element_Ace extends Varien_Data_Form_Element_Ab
54
  'readOnly' => $this->getReadonly(),
55
  'snippets' => $this->getSnippets()
56
  );
57
-
58
  return $options;
59
  }
60
-
61
-
62
-
63
-
64
  public function getElementHtml()
65
  {
66
  $helper = Mage::helper('core');
67
-
68
  $id = $this->getHtmlId();
69
  $jsId = "editor{$id}";
70
-
71
  $logo = $this->getLogo();
72
- if($logo) {
73
  $logo = '<img src="' . $logo . '" class="logo" />';
74
  }
75
-
76
  $buttonsHtml = $this->_getPluginButtonsHtml();
77
-
78
-
79
  $toolbarHtml = <<<JS
80
  <div id="control-buttons-$id" class="mzax-editor-toolbar">
81
  $logo
@@ -85,42 +98,46 @@ class Mzax_Emarketing_Model_Form_Element_Ace extends Varien_Data_Form_Element_Ab
85
  </div>
86
  </div>
87
  JS;
88
-
89
  $toolbarHtml = str_replace('{editor}', $jsId, $toolbarHtml);
90
-
91
  $classes = array('mzax-editor');
92
  $classes[] = $this->getClass();
93
  $classes[] = $this->getTypeClass();
94
  $classes[] = $buttonsHtml ? 'has-plugin-buttons' : 'no-plugin-buttons';
95
-
96
  $classes = array_filter($classes);
97
-
98
  $html = '<div title="' . $this->getTitle()
99
  . '" id="' . $id . '"'
100
  . ' class="mzax-editor mage-ace-editor ' . implode(' ', $classes) .'" '
101
  . $this->serialize($this->getHtmlAttributes()) . ' >';
102
-
103
  $html.= '<textarea id="' . $id . '_txt" name="' . $this->getName() . '" style="display:none;">'.$this->getEscapedValue().'</textarea>';
104
  $html.= $toolbarHtml;
105
  $html.= '<div class="editor-container"></div>';
106
  $html.= '</div>';
107
-
108
  $html.= '<script type="text/javascript">';
109
  $html.= $this->getJavaScript($jsId);
110
  $html.= '</script>';
111
-
112
-
113
  return $html;
114
  }
115
-
116
-
 
 
 
 
117
  public function getJavaScript($jsId)
118
  {
119
  $options = Zend_Json::encode($this->getEditorOptions());
120
  $options = str_replace('{editor}', $jsId, $options);
121
-
122
  $cls = $this->getEditorClass();
123
-
124
  return <<<JS
125
  window.$jsId = (function() {
126
 
@@ -147,29 +164,29 @@ JS;
147
  })();
148
  JS;
149
  }
150
-
151
-
152
-
 
153
  public function getExtaScript()
154
  {
155
  return '';
156
  }
157
-
158
-
159
-
160
 
 
 
 
161
  public function getSnippets()
162
  {
163
  $data = $this->getConfig('snippets');
164
-
165
  /* @var $store Mage_Core_Model_Store */
166
  $store = $this->getConfig('store', Mage::app()->getStore(true));
167
-
168
- if(!$data instanceof Mzax_Emarketing_Model_Medium_Email_Snippets) {
169
  $data = new Mzax_Emarketing_Model_Medium_Email_Snippets;
170
  }
171
-
172
-
173
  /* @var $variable Mage_Core_Model_Variable */
174
  foreach (Mage::getResourceModel('core/variable_collection') as $variable) {
175
  $data->add(array(
@@ -182,10 +199,9 @@ JS;
182
  'shortcut' => null
183
  ));
184
  }
185
-
186
-
187
  $storeContactVariabls = Mage::getModel('core/source_email_variables')->toOptionArray(false);
188
- foreach($storeContactVariabls as $var) {
189
  $path = preg_replace('/\{\{config path="(.*)"\}\}/i', '$1', $var['value']);
190
  $data->add(array(
191
  'title' => $var['label'],
@@ -196,8 +212,8 @@ JS;
196
  'shortcut' => null
197
  ));
198
  }
199
-
200
-
201
  $data->add(array(
202
  'title' => $this->translate("Magento Template Block"),
203
  'description' => $this->translate('Insert html from a php block class'),
@@ -205,8 +221,8 @@ JS;
205
  'value' => 'mage.block.insert',
206
  'shortcut' => 'block'
207
  ));
208
-
209
-
210
  if ($this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
211
  $data->add(array(
212
  'title' => $this->translate('Magento Widget'),
@@ -216,7 +232,7 @@ JS;
216
  'shortcut' => 'widget'
217
  ));
218
  }
219
-
220
  if ($this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
221
  $data->add(array(
222
  'title' => $this->translate('Magento Image'),
@@ -226,14 +242,10 @@ JS;
226
  'shortcut' => 'image'
227
  ));
228
  }
229
-
230
-
231
  return $data->toArray();
232
  }
233
-
234
-
235
-
236
-
237
  /**
238
  * Prepare Html buttons for additional WYSIWYG features
239
  *
@@ -243,8 +255,8 @@ JS;
243
  protected function _getPluginButtonsHtml()
244
  {
245
  $buttonsHtml = '';
246
-
247
- if(!$this->getReadonly()) {
248
  // Button to widget insertion window
249
  $buttonsHtml .= $this->_getButtonHtml(array(
250
  'title' => $this->translate('Insert MageCode'),
@@ -252,7 +264,7 @@ JS;
252
  'class' => 'mzax-variable'
253
  ));
254
  }
255
-
256
  // Button to widget insertion window
257
  if (!$this->getReadonly() && $this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
258
  $buttonsHtml .= $this->_getButtonHtml(array(
@@ -261,8 +273,8 @@ JS;
261
  'class' => 'mzax-widget'
262
  ));
263
  }
264
-
265
- // Button to media images insertion window
266
  if (!$this->getReadonly() && $this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
267
  $buttonsHtml .= $this->_getButtonHtml(array(
268
  'title' => $this->translate('Insert Image'),
@@ -270,8 +282,8 @@ JS;
270
  'class' => 'mzax-image'
271
  ));
272
  }
273
-
274
-
275
  if ($this->getConfig('allow_fullscreen', true)) {
276
  $buttonsHtml .= $this->_getButtonHtml(array(
277
  'title' => $this->translate('Fullscreen'),
@@ -279,21 +291,17 @@ JS;
279
  'class' => 'mzax-fullscreen'
280
  ));
281
  }
282
-
283
  $buttons = $this->getConfig('buttons');
284
- if(is_array($buttons)) {
285
- foreach($buttons as $button) {
286
  $buttonsHtml .= $this->_getButtonHtml($button);
287
  }
288
  }
289
-
290
-
291
  return $buttonsHtml;
292
  }
293
-
294
-
295
-
296
-
297
  /**
298
  * Return custom button HTML
299
  *
@@ -310,14 +318,10 @@ JS;
310
  $html.= '>';
311
  $html.= isset($data['title']) ? '<span>'.$data['title'].'</span>' : '';
312
  $html.= '</button>';
313
-
314
  return $html;
315
  }
316
-
317
-
318
-
319
-
320
-
321
  /**
322
  * Editor config retriever
323
  *
@@ -326,62 +330,60 @@ JS;
326
  */
327
  public function getConfig($key = null, $default = null)
328
  {
329
- if ( !($this->_getData('config') instanceof Varien_Object) ) {
330
  $config = new Varien_Object();
331
  $this->setConfig($config);
332
  }
333
-
334
  if ($key !== null) {
335
  $data = $this->_getData('config')->getData($key);
336
- if($data !== null) {
337
  return $data;
338
  }
339
  $data = $this->getData($key);
340
- if($data !== null) {
341
  return $data;
342
  }
343
  return $default;
344
  }
345
  return $this->_getData('config');
346
  }
347
-
348
-
349
-
350
  /**
351
  * Is ACE editor enabled
352
- *
353
  * @return boolean
354
  */
355
  public function aceEnabled()
356
  {
357
- $enabled = Mage::getStoreConfigFlag('mzax_emarketing/content_management/enable_ace');
358
- if(!$enabled) {
359
  return 0;
360
  }
361
- return (int) $this->getConfig('enable_ace', 1);
 
362
  }
363
-
364
-
365
  /**
366
  * Is CKEditor enabled
367
- *
368
  * @return boolean
369
  */
370
  public function ckeEnabled()
371
  {
372
- $enabled = Mage::getStoreConfigFlag('mzax_emarketing/content_management/enable_ckeditor');
373
- if(!$enabled) {
374
  return 0;
375
  }
376
- return (int) $this->getConfig('enable_ckeditor', 1);
 
377
  }
378
-
379
-
380
-
381
  /**
382
  * Translate string using defined helper
383
  *
384
  * @param string $string String to be translated
 
385
  * @return string
386
  */
387
  public function translate($string)
@@ -393,7 +395,7 @@ JS;
393
  return $result;
394
  }
395
  }
396
-
397
  return $string;
398
  }
399
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Model_Form_Element_Ace
21
+ */
22
  class Mzax_Emarketing_Model_Form_Element_Ace extends Varien_Data_Form_Element_Abstract
23
  {
24
+ /**
25
+ * @var Mzax_Emarketing_Model_Config
26
+ */
27
+ protected $_config;
28
+
29
+ /**
30
+ * Mzax_Emarketing_Model_Outbox constructor.
31
+ */
32
+ public function _construct()
33
+ {
34
+ parent::_construct();
35
 
36
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
37
+ }
38
 
39
+ /**
40
+ * @return string
41
+ */
42
  public function getEditorClass()
43
  {
44
  return 'mzax.ui.TextEditor';
45
  }
 
 
46
 
47
+ /**
48
+ * @return string
49
+ */
50
  public function getTypeClass()
51
  {
52
  return 'mage-ace-editor';
53
  }
54
+
 
 
 
 
55
  /**
56
  * Retrieve editor options
57
+ *
58
  * @return array
59
  */
60
  public function getEditorOptions()
67
  'readOnly' => $this->getReadonly(),
68
  'snippets' => $this->getSnippets()
69
  );
70
+
71
  return $options;
72
  }
73
+
74
+ /**
75
+ * @return string
76
+ */
77
  public function getElementHtml()
78
  {
79
  $helper = Mage::helper('core');
80
+
81
  $id = $this->getHtmlId();
82
  $jsId = "editor{$id}";
83
+
84
  $logo = $this->getLogo();
85
+ if ($logo) {
86
  $logo = '<img src="' . $logo . '" class="logo" />';
87
  }
88
+
89
  $buttonsHtml = $this->_getPluginButtonsHtml();
90
+
91
+
92
  $toolbarHtml = <<<JS
93
  <div id="control-buttons-$id" class="mzax-editor-toolbar">
94
  $logo
98
  </div>
99
  </div>
100
  JS;
101
+
102
  $toolbarHtml = str_replace('{editor}', $jsId, $toolbarHtml);
103
+
104
  $classes = array('mzax-editor');
105
  $classes[] = $this->getClass();
106
  $classes[] = $this->getTypeClass();
107
  $classes[] = $buttonsHtml ? 'has-plugin-buttons' : 'no-plugin-buttons';
108
+
109
  $classes = array_filter($classes);
110
+
111
  $html = '<div title="' . $this->getTitle()
112
  . '" id="' . $id . '"'
113
  . ' class="mzax-editor mage-ace-editor ' . implode(' ', $classes) .'" '
114
  . $this->serialize($this->getHtmlAttributes()) . ' >';
115
+
116
  $html.= '<textarea id="' . $id . '_txt" name="' . $this->getName() . '" style="display:none;">'.$this->getEscapedValue().'</textarea>';
117
  $html.= $toolbarHtml;
118
  $html.= '<div class="editor-container"></div>';
119
  $html.= '</div>';
120
+
121
  $html.= '<script type="text/javascript">';
122
  $html.= $this->getJavaScript($jsId);
123
  $html.= '</script>';
124
+
125
+
126
  return $html;
127
  }
128
+
129
+ /**
130
+ * @param $jsId
131
+ *
132
+ * @return string
133
+ */
134
  public function getJavaScript($jsId)
135
  {
136
  $options = Zend_Json::encode($this->getEditorOptions());
137
  $options = str_replace('{editor}', $jsId, $options);
138
+
139
  $cls = $this->getEditorClass();
140
+
141
  return <<<JS
142
  window.$jsId = (function() {
143
 
164
  })();
165
  JS;
166
  }
167
+
168
+ /**
169
+ * @return string
170
+ */
171
  public function getExtaScript()
172
  {
173
  return '';
174
  }
 
 
 
175
 
176
+ /**
177
+ * @return array
178
+ */
179
  public function getSnippets()
180
  {
181
  $data = $this->getConfig('snippets');
182
+
183
  /* @var $store Mage_Core_Model_Store */
184
  $store = $this->getConfig('store', Mage::app()->getStore(true));
185
+
186
+ if (!$data instanceof Mzax_Emarketing_Model_Medium_Email_Snippets) {
187
  $data = new Mzax_Emarketing_Model_Medium_Email_Snippets;
188
  }
189
+
 
190
  /* @var $variable Mage_Core_Model_Variable */
191
  foreach (Mage::getResourceModel('core/variable_collection') as $variable) {
192
  $data->add(array(
199
  'shortcut' => null
200
  ));
201
  }
202
+
 
203
  $storeContactVariabls = Mage::getModel('core/source_email_variables')->toOptionArray(false);
204
+ foreach ($storeContactVariabls as $var) {
205
  $path = preg_replace('/\{\{config path="(.*)"\}\}/i', '$1', $var['value']);
206
  $data->add(array(
207
  'title' => $var['label'],
212
  'shortcut' => null
213
  ));
214
  }
215
+
216
+
217
  $data->add(array(
218
  'title' => $this->translate("Magento Template Block"),
219
  'description' => $this->translate('Insert html from a php block class'),
221
  'value' => 'mage.block.insert',
222
  'shortcut' => 'block'
223
  ));
224
+
225
+
226
  if ($this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
227
  $data->add(array(
228
  'title' => $this->translate('Magento Widget'),
232
  'shortcut' => 'widget'
233
  ));
234
  }
235
+
236
  if ($this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
237
  $data->add(array(
238
  'title' => $this->translate('Magento Image'),
242
  'shortcut' => 'image'
243
  ));
244
  }
245
+
 
246
  return $data->toArray();
247
  }
248
+
 
 
 
249
  /**
250
  * Prepare Html buttons for additional WYSIWYG features
251
  *
255
  protected function _getPluginButtonsHtml()
256
  {
257
  $buttonsHtml = '';
258
+
259
+ if (!$this->getReadonly()) {
260
  // Button to widget insertion window
261
  $buttonsHtml .= $this->_getButtonHtml(array(
262
  'title' => $this->translate('Insert MageCode'),
264
  'class' => 'mzax-variable'
265
  ));
266
  }
267
+
268
  // Button to widget insertion window
269
  if (!$this->getReadonly() && $this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
270
  $buttonsHtml .= $this->_getButtonHtml(array(
273
  'class' => 'mzax-widget'
274
  ));
275
  }
276
+
277
+ // Button to media images insertion window
278
  if (!$this->getReadonly() && $this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
279
  $buttonsHtml .= $this->_getButtonHtml(array(
280
  'title' => $this->translate('Insert Image'),
282
  'class' => 'mzax-image'
283
  ));
284
  }
285
+
286
+
287
  if ($this->getConfig('allow_fullscreen', true)) {
288
  $buttonsHtml .= $this->_getButtonHtml(array(
289
  'title' => $this->translate('Fullscreen'),
291
  'class' => 'mzax-fullscreen'
292
  ));
293
  }
294
+
295
  $buttons = $this->getConfig('buttons');
296
+ if (is_array($buttons)) {
297
+ foreach ($buttons as $button) {
298
  $buttonsHtml .= $this->_getButtonHtml($button);
299
  }
300
  }
301
+
 
302
  return $buttonsHtml;
303
  }
304
+
 
 
 
305
  /**
306
  * Return custom button HTML
307
  *
318
  $html.= '>';
319
  $html.= isset($data['title']) ? '<span>'.$data['title'].'</span>' : '';
320
  $html.= '</button>';
321
+
322
  return $html;
323
  }
324
+
 
 
 
 
325
  /**
326
  * Editor config retriever
327
  *
330
  */
331
  public function getConfig($key = null, $default = null)
332
  {
333
+ if (!($this->_getData('config') instanceof Varien_Object)) {
334
  $config = new Varien_Object();
335
  $this->setConfig($config);
336
  }
337
+
338
  if ($key !== null) {
339
  $data = $this->_getData('config')->getData($key);
340
+ if ($data !== null) {
341
  return $data;
342
  }
343
  $data = $this->getData($key);
344
+ if ($data !== null) {
345
  return $data;
346
  }
347
  return $default;
348
  }
349
  return $this->_getData('config');
350
  }
351
+
 
 
352
  /**
353
  * Is ACE editor enabled
354
+ *
355
  * @return boolean
356
  */
357
  public function aceEnabled()
358
  {
359
+ $enabled = $this->_config->flag('mzax_emarketing/content_management/enable_ace');
360
+ if (!$enabled) {
361
  return 0;
362
  }
363
+
364
+ return (int)$this->getConfig('enable_ace', 1);
365
  }
366
+
 
367
  /**
368
  * Is CKEditor enabled
369
+ *
370
  * @return boolean
371
  */
372
  public function ckeEnabled()
373
  {
374
+ $enabled = $this->_config->flag('mzax_emarketing/content_management/enable_ckeditor');
375
+ if (!$enabled) {
376
  return 0;
377
  }
378
+
379
+ return (int)$this->getConfig('enable_ckeditor', 1);
380
  }
381
+
 
 
382
  /**
383
  * Translate string using defined helper
384
  *
385
  * @param string $string String to be translated
386
+ *
387
  * @return string
388
  */
389
  public function translate($string)
395
  return $result;
396
  }
397
  }
398
+
399
  return $string;
400
  }
401
  }
app/code/community/Mzax/Emarketing/Model/Form/Element/Credits.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,18 +16,21 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Model_Form_Element_Credits extends Varien_Data_Form_Element_Abstract
22
  {
23
-
 
 
24
  public function getElementHtml()
25
  {
26
  $credits = $this->getEscapedValue();
27
  $credits = preg_replace('/\[(.*?)\|(.*?)\]/', '<a href="$2" target="_blank">$1</a>', $credits);
28
-
29
  $credits = nl2br($credits);
30
-
31
  return '<div class="mzax-credits">' . $credits . '</div>';
32
  }
33
-
34
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Model_Form_Element_Credits
21
+ */
22
  class Mzax_Emarketing_Model_Form_Element_Credits extends Varien_Data_Form_Element_Abstract
23
  {
24
+ /**
25
+ * @return string
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
  }
app/code/community/Mzax/Emarketing/Model/Form/Element/EmailEditor.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,43 +19,32 @@
20
 
21
  /**
22
  * Email Editor
23
- *
24
- * The email editor requires a template to work.
25
  *
26
- * @author Jacob Siefer
27
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
- * @version 0.4.10
29
  */
30
- class Mzax_Emarketing_Model_Form_Element_EmailEditor
31
  extends Mzax_Emarketing_Model_Form_Element_TemplateEditor
32
  {
33
-
34
-
35
  /**
36
  * The JS editor class
37
- *
38
  * @return string
39
  */
40
  public function getEditorClass()
41
  {
42
  return 'mzax.ui.PreviewFrame';
43
  }
44
-
45
-
46
-
47
  /**
48
  * CSS class for this editor
49
- *
50
  * @return string
51
  */
52
  public function getTypeClass()
53
  {
54
  return 'mage-email-editor';
55
  }
56
-
57
-
58
-
59
-
60
  /**
61
  * Retrieve editor options
62
  *
@@ -67,9 +55,9 @@ class Mzax_Emarketing_Model_Form_Element_EmailEditor
67
  $storeId = $this->getConfig('store_id');
68
  $store = Mage::app()->getStore($storeId);
69
  $storeParam = null !== $storeId ? 'store/' . $this->getConfig('store_id') . '/' : '';
70
-
71
  $options = parent::getEditorOptions();
72
-
73
  $options['quicksaveUrl'] = $this->getConfig('quicksave_url');
74
  $options['quicksaveFields'] = $this->getQuicksaveFields();
75
  $options['templateLoadUrl'] = $this->getConfig('template_load_url');
@@ -77,15 +65,15 @@ class Mzax_Emarketing_Model_Form_Element_EmailEditor
77
  $options['fieldName'] = $this->getData('name');
78
  $options['enableCKEditor'] = $this->ckeEnabled();
79
  $options['startEdit'] = true;
80
-
81
  /* Good enough - only for preview, no fallback required
82
- * http://www.example.com/skin/frontend/{package}/{theme}/
83
  */
84
  $skinPath = array();
85
  $skinPath[] = $store->getBaseUrl('skin') . 'frontend';
86
  $skinPath[] = $store->getConfig('design/package/name');
87
  $skinPath[] = $store->getConfig('design/theme/layout');
88
-
89
  $options['skinUrl'] = implode('/', $skinPath) . '/';
90
  $options['mediaUrl'] = $store->getBaseUrl($store::URL_TYPE_MEDIA);
91
  $options['storeUrl'] = $store->getBaseUrl($store::URL_TYPE_WEB);
@@ -95,19 +83,18 @@ class Mzax_Emarketing_Model_Form_Element_EmailEditor
95
 
96
  return $options;
97
  }
98
-
99
-
100
-
101
-
102
 
 
 
 
103
  public function getExtaScript()
104
  {
105
  $templateField = $this->getConfig('template_field') ? $this->getConfig('template_field')->getHtmlId() : '';
106
-
107
- if($templateField) {
108
  return <<<JS
109
  var templateField = $('$templateField');
110
- if(templateField) {
111
  templateField.on('change', function() {
112
  editor.loadTemplate(this.value);
113
  });
@@ -116,49 +103,46 @@ JS;
116
  }
117
  return '';
118
  }
119
-
120
-
121
-
 
122
  protected function getQuicksaveFields()
123
  {
124
  $fields = $this->getConfig('quicksave_fields');
125
  $quicksaveFields = array();
126
- if(is_array($fields)) {
127
- foreach($fields as $field) {
128
- if($field instanceof Varien_Data_Form_Element_Abstract) {
129
  $quicksaveFields[$field->getData('name')] = $field->getHtmlId();
130
  }
131
  }
132
  }
133
  return $quicksaveFields;
134
  }
135
-
136
-
137
-
 
138
  public function getTemplateHtml()
139
  {
140
- if($this->getTemplate()) {
141
  $html = (string) $this->getTemplate()->getBody();
142
- }
143
- else {
144
  $html = '';
145
  }
146
  return $html;
147
  }
148
-
149
-
150
-
151
-
152
  /**
153
  * Prepare Html buttons for additional WYSIWYG features
154
  *
155
- * @param bool $visible Display button or not
156
- * @return void
157
  */
158
  protected function _getPluginButtonsHtml()
159
  {
160
  $buttonsHtml = '';
161
-
162
  if ($this->getConfig('allow_fullscreen', true)) {
163
  $buttonsHtml .= $this->_getButtonHtml(array(
164
  'title' => $this->translate('Fullscreen'),
@@ -166,19 +150,14 @@ JS;
166
  'class' => 'mzax-fullscreen'
167
  ));
168
  }
169
-
170
  $buttons = $this->getConfig('buttons');
171
- if(is_array($buttons)) {
172
- foreach($buttons as $button) {
173
  $buttonsHtml .= $this->_getButtonHtml($button);
174
  }
175
  }
176
-
177
-
178
  return $buttonsHtml;
179
  }
180
-
181
-
182
-
183
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
  /**
21
  * Email Editor
 
 
22
  *
23
+ * The email editor requires a template to work.
 
 
24
  */
25
+ class Mzax_Emarketing_Model_Form_Element_EmailEditor
26
  extends Mzax_Emarketing_Model_Form_Element_TemplateEditor
27
  {
 
 
28
  /**
29
  * The JS editor class
30
+ *
31
  * @return string
32
  */
33
  public function getEditorClass()
34
  {
35
  return 'mzax.ui.PreviewFrame';
36
  }
37
+
 
 
38
  /**
39
  * CSS class for this editor
40
+ *
41
  * @return string
42
  */
43
  public function getTypeClass()
44
  {
45
  return 'mage-email-editor';
46
  }
47
+
 
 
 
48
  /**
49
  * Retrieve editor options
50
  *
55
  $storeId = $this->getConfig('store_id');
56
  $store = Mage::app()->getStore($storeId);
57
  $storeParam = null !== $storeId ? 'store/' . $this->getConfig('store_id') . '/' : '';
58
+
59
  $options = parent::getEditorOptions();
60
+
61
  $options['quicksaveUrl'] = $this->getConfig('quicksave_url');
62
  $options['quicksaveFields'] = $this->getQuicksaveFields();
63
  $options['templateLoadUrl'] = $this->getConfig('template_load_url');
65
  $options['fieldName'] = $this->getData('name');
66
  $options['enableCKEditor'] = $this->ckeEnabled();
67
  $options['startEdit'] = true;
68
+
69
  /* Good enough - only for preview, no fallback required
70
+ * http://www.example.com/skin/frontend/{package}/{theme}/
71
  */
72
  $skinPath = array();
73
  $skinPath[] = $store->getBaseUrl('skin') . 'frontend';
74
  $skinPath[] = $store->getConfig('design/package/name');
75
  $skinPath[] = $store->getConfig('design/theme/layout');
76
+
77
  $options['skinUrl'] = implode('/', $skinPath) . '/';
78
  $options['mediaUrl'] = $store->getBaseUrl($store::URL_TYPE_MEDIA);
79
  $options['storeUrl'] = $store->getBaseUrl($store::URL_TYPE_WEB);
83
 
84
  return $options;
85
  }
 
 
 
 
86
 
87
+ /**
88
+ * @return string
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
  });
103
  }
104
  return '';
105
  }
106
+
107
+ /**
108
+ * @return array
109
+ */
110
  protected function getQuicksaveFields()
111
  {
112
  $fields = $this->getConfig('quicksave_fields');
113
  $quicksaveFields = array();
114
+ if (is_array($fields)) {
115
+ foreach ($fields as $field) {
116
+ if ($field instanceof Varien_Data_Form_Element_Abstract) {
117
  $quicksaveFields[$field->getData('name')] = $field->getHtmlId();
118
  }
119
  }
120
  }
121
  return $quicksaveFields;
122
  }
123
+
124
+ /**
125
+ * @return string
126
+ */
127
  public function getTemplateHtml()
128
  {
129
+ if ($this->getTemplate()) {
130
  $html = (string) $this->getTemplate()->getBody();
131
+ } else {
 
132
  $html = '';
133
  }
134
  return $html;
135
  }
136
+
 
 
 
137
  /**
138
  * Prepare Html buttons for additional WYSIWYG features
139
  *
140
+ * @return string
 
141
  */
142
  protected function _getPluginButtonsHtml()
143
  {
144
  $buttonsHtml = '';
145
+
146
  if ($this->getConfig('allow_fullscreen', true)) {
147
  $buttonsHtml .= $this->_getButtonHtml(array(
148
  'title' => $this->translate('Fullscreen'),
150
  'class' => 'mzax-fullscreen'
151
  ));
152
  }
153
+
154
  $buttons = $this->getConfig('buttons');
155
+ if (is_array($buttons)) {
156
+ foreach ($buttons as $button) {
157
  $buttonsHtml .= $this->_getButtonHtml($button);
158
  }
159
  }
160
+
 
161
  return $buttonsHtml;
162
  }
 
 
 
 
163
  }
app/code/community/Mzax/Emarketing/Model/Form/Element/Info.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,12 +17,16 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Model_Form_Element_Info extends Varien_Data_Form_Element_Abstract
22
  {
23
-
 
 
24
  public function getElementHtml()
25
  {
26
  return '<div class="mzax-info-element">' . $this->getText() . '</div>';
27
  }
28
-
29
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Form_Element_Info
22
+ */
23
  class Mzax_Emarketing_Model_Form_Element_Info extends Varien_Data_Form_Element_Abstract
24
  {
25
+ /**
26
+ * @return string
27
+ */
28
  public function getElementHtml()
29
  {
30
  return '<div class="mzax-info-element">' . $this->getText() . '</div>';
31
  }
 
32
  }
app/code/community/Mzax/Emarketing/Model/Form/Element/TemplateEditor.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,23 +16,26 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_Model_Form_Element_Ace
22
  {
23
-
 
 
24
  public function getEditorClass()
25
  {
26
  return 'mzax.ui.TemplateEditor';
27
  }
28
-
29
-
 
 
30
  public function getTypeClass()
31
  {
32
  return 'mage-template-editor';
33
  }
34
-
35
-
36
-
37
 
38
  /**
39
  * Retrieve editor options
@@ -44,30 +46,24 @@ class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_
44
  {
45
  $storeId = $this->getConfig('store_id');
46
  $storeParam = null !== $storeId ? 'store/' . $this->getConfig('store_id') . '/' : '';
47
-
48
  $options = parent::getEditorOptions();
49
  $options['mediaBrowserUrl'] = "{$this->getConfig('files_browser_window_url')}target_element_id/{editor}/{$storeParam}";
50
  $options['widgetToolsUrl'] = "{$this->getConfig('widget_window_url')}widget_target_id/{editor}";
51
-
52
  return $options;
53
  }
54
-
55
 
56
-
57
-
58
-
59
-
60
  /**
61
  * Prepare Html buttons for additional WYSIWYG features
62
  *
63
- * @param bool $visible Display button or not
64
- * @return void
65
  */
66
  protected function _getPluginButtonsHtml()
67
  {
68
  $buttonsHtml = '';
69
-
70
- if(!$this->getReadonly()) {
71
  // Button to widget insertion window
72
  $buttonsHtml .= $this->_getButtonHtml(array(
73
  'title' => $this->translate('Insert MageCode'),
@@ -75,7 +71,7 @@ class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_
75
  'class' => 'mzax-variable'
76
  ));
77
  }
78
-
79
  // Button to widget insertion window
80
  if (!$this->getReadonly() && $this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
81
  $buttonsHtml .= $this->_getButtonHtml(array(
@@ -84,8 +80,8 @@ class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_
84
  'class' => 'mzax-widget'
85
  ));
86
  }
87
-
88
- // Button to media images insertion window
89
  if (!$this->getReadonly() && $this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
90
  $buttonsHtml .= $this->_getButtonHtml(array(
91
  'title' => $this->translate('Insert Image'),
@@ -93,8 +89,8 @@ class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_
93
  'class' => 'mzax-image'
94
  ));
95
  }
96
-
97
-
98
  if ($this->getConfig('allow_fullscreen', true)) {
99
  $buttonsHtml .= $this->_getButtonHtml(array(
100
  'title' => $this->translate('Fullscreen'),
@@ -102,26 +98,21 @@ class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_
102
  'class' => 'mzax-fullscreen'
103
  ));
104
  }
105
-
106
  $buttonsHtml .= $this->_getButtonHtml(array(
107
  'title' => $this->translate('Switch Vert/Horz'),
108
  'onclick' => "{editor}.switchLayout();",
109
  'class' => 'mzax-layout-mode'
110
  ));
111
-
112
-
113
  $buttons = $this->getConfig('buttons');
114
- if(is_array($buttons)) {
115
- foreach($buttons as $button) {
116
  $buttonsHtml .= $this->_getButtonHtml($button);
117
  }
118
  }
119
-
120
-
121
  return $buttonsHtml;
122
  }
123
-
124
-
125
-
126
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Model_Form_Element_TemplateEditor
21
+ */
22
  class Mzax_Emarketing_Model_Form_Element_TemplateEditor extends Mzax_Emarketing_Model_Form_Element_Ace
23
  {
24
+ /**
25
+ * @return string
26
+ */
27
  public function getEditorClass()
28
  {
29
  return 'mzax.ui.TemplateEditor';
30
  }
31
+
32
+ /**
33
+ * @return string
34
+ */
35
  public function getTypeClass()
36
  {
37
  return 'mage-template-editor';
38
  }
 
 
 
39
 
40
  /**
41
  * Retrieve editor options
46
  {
47
  $storeId = $this->getConfig('store_id');
48
  $storeParam = null !== $storeId ? 'store/' . $this->getConfig('store_id') . '/' : '';
49
+
50
  $options = parent::getEditorOptions();
51
  $options['mediaBrowserUrl'] = "{$this->getConfig('files_browser_window_url')}target_element_id/{editor}/{$storeParam}";
52
  $options['widgetToolsUrl'] = "{$this->getConfig('widget_window_url')}widget_target_id/{editor}";
53
+
54
  return $options;
55
  }
 
56
 
 
 
 
 
57
  /**
58
  * Prepare Html buttons for additional WYSIWYG features
59
  *
60
+ * @return string
 
61
  */
62
  protected function _getPluginButtonsHtml()
63
  {
64
  $buttonsHtml = '';
65
+
66
+ if (!$this->getReadonly()) {
67
  // Button to widget insertion window
68
  $buttonsHtml .= $this->_getButtonHtml(array(
69
  'title' => $this->translate('Insert MageCode'),
71
  'class' => 'mzax-variable'
72
  ));
73
  }
74
+
75
  // Button to widget insertion window
76
  if (!$this->getReadonly() && $this->getConfig('add_widgets', true) && $this->getConfig('widget_window_url')) {
77
  $buttonsHtml .= $this->_getButtonHtml(array(
80
  'class' => 'mzax-widget'
81
  ));
82
  }
83
+
84
+ // Button to media images insertion window
85
  if (!$this->getReadonly() && $this->getConfig('add_images', true) && $this->getConfig('files_browser_window_url')) {
86
  $buttonsHtml .= $this->_getButtonHtml(array(
87
  'title' => $this->translate('Insert Image'),
89
  'class' => 'mzax-image'
90
  ));
91
  }
92
+
93
+
94
  if ($this->getConfig('allow_fullscreen', true)) {
95
  $buttonsHtml .= $this->_getButtonHtml(array(
96
  'title' => $this->translate('Fullscreen'),
98
  'class' => 'mzax-fullscreen'
99
  ));
100
  }
101
+
102
  $buttonsHtml .= $this->_getButtonHtml(array(
103
  'title' => $this->translate('Switch Vert/Horz'),
104
  'onclick' => "{editor}.switchLayout();",
105
  'class' => 'mzax-layout-mode'
106
  ));
107
+
108
+
109
  $buttons = $this->getConfig('buttons');
110
+ if (is_array($buttons)) {
111
+ foreach ($buttons as $button) {
112
  $buttonsHtml .= $this->_getButtonHtml($button);
113
  }
114
  }
115
+
 
116
  return $buttonsHtml;
117
  }
 
 
 
 
118
  }
app/code/community/Mzax/Emarketing/Model/Form/Element/Textarea.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,21 +18,19 @@
19
 
20
 
21
  /**
22
- * Textare with placeholder attribute
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
- class Mzax_Emarketing_Model_Form_Element_Textarea
30
  extends Varien_Data_Form_Element_Textarea
31
  {
 
 
 
32
  public function getHtmlAttributes()
33
  {
34
  $attributes = parent::getHtmlAttributes();
35
  $attributes[] = 'placeholder';
36
-
37
  return $attributes;
38
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Textarea with placeholder attribute
 
 
 
 
 
22
  */
23
+ class Mzax_Emarketing_Model_Form_Element_Textarea
24
  extends Varien_Data_Form_Element_Textarea
25
  {
26
+ /**
27
+ * @return array
28
+ */
29
  public function getHtmlAttributes()
30
  {
31
  $attributes = parent::getHtmlAttributes();
32
  $attributes[] = 'placeholder';
33
+
34
  return $attributes;
35
  }
36
+ }
app/code/community/Mzax/Emarketing/Model/Form/Element/Wildselect.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,20 +18,12 @@
19
 
20
 
21
  /**
22
- * Works like multislect but one can also select all options
23
  * like a wildcard
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.4.10
29
  */
30
  class Mzax_Emarketing_Model_Form_Element_Wildselect
31
  extends Varien_Data_Form_Element_Multiselect
32
  {
33
-
34
-
35
-
36
  /**
37
  * Retrieve Element HTML fragment
38
  *
@@ -49,13 +40,13 @@ class Mzax_Emarketing_Model_Form_Element_Wildselect
49
  $htmlId = 'wildcard_' . $this->getHtmlId();
50
  $html .= '<input id="'.$htmlId.'" name="wildcard[]" value="' . $this->getId() . '"';
51
  $html .= ($disabled ? ' checked="checked"' : '');
52
-
53
  if ($this->getReadonly()) {
54
  $html .= ' disabled="disabled"';
55
  }
56
-
57
  $wildcardLabel = $this->getDataSetDefault('wildcard_label', Mage::helper('mzax_emarketing')->__('Use All'));
58
-
59
  $html .= ' onclick="toggleValueElements(this, this.parentNode);" class="checkbox" type="checkbox" />';
60
 
61
  $html .= ' <label for="'.$htmlId.'" class="normal">' . $wildcardLabel . '</label>';
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Works like multislect but one can also select all options
22
  * like a wildcard
 
 
 
 
 
23
  */
24
  class Mzax_Emarketing_Model_Form_Element_Wildselect
25
  extends Varien_Data_Form_Element_Multiselect
26
  {
 
 
 
27
  /**
28
  * Retrieve Element HTML fragment
29
  *
40
  $htmlId = 'wildcard_' . $this->getHtmlId();
41
  $html .= '<input id="'.$htmlId.'" name="wildcard[]" value="' . $this->getId() . '"';
42
  $html .= ($disabled ? ' checked="checked"' : '');
43
+
44
  if ($this->getReadonly()) {
45
  $html .= ' disabled="disabled"';
46
  }
47
+
48
  $wildcardLabel = $this->getDataSetDefault('wildcard_label', Mage::helper('mzax_emarketing')->__('Use All'));
49
+
50
  $html .= ' onclick="toggleValueElements(this, this.parentNode);" class="checkbox" type="checkbox" />';
51
 
52
  $html .= ' <label for="'.$htmlId.'" class="normal">' . $wildcardLabel . '</label>';
app/code/community/Mzax/Emarketing/Model/Goal.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,38 +17,29 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
- *
25
- * @method Mzax_Emarketing_Model_Link setObjectId(string)
26
- * @method Mzax_Emarketing_Model_Link setObjectType(string)
27
- * @method Mzax_Emarketing_Model_Link setRecipientId(string)
28
- * @method Mzax_Emarketing_Model_Link setClickId(string)
29
- *
 
30
  * @method string getObjectId()
31
  * @method string getObjectType()
32
  * @method string getRecipientId()
33
  * @method string getClickId()
34
- *
35
  * @method Mzax_Emarketing_Model_Resource_Goal getResource()
36
- *
37
- *
38
- * If you plan on implmenting custom events, use a type id greater than 100
39
- *
40
- *
41
- * @author Jacob Siefer
42
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
43
- * @version 0.4.10
44
  */
45
- class Mzax_Emarketing_Model_Goal extends Mage_Core_Model_Abstract
46
  {
47
-
48
  const TYPE_ORDER = 1;
49
  const TYPE_SIGNUP = 2;
50
-
51
-
52
-
53
  /**
54
  * Prefix of model events names
55
  *
@@ -65,17 +55,14 @@ class Mzax_Emarketing_Model_Goal extends Mage_Core_Model_Abstract
65
  * @var string
66
  */
67
  protected $_eventObject = 'goal';
68
-
69
-
70
-
71
-
 
 
72
  protected function _construct()
73
  {
74
  $this->_init('mzax_emarketing/goal');
75
  }
76
-
77
-
78
-
79
-
80
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Goal
22
+ *
23
+ * @method $this setObjectId(string)
24
+ * @method $this setObjectType(string)
25
+ * @method $this setRecipientId(string)
26
+ * @method $this setClickId(string)
27
+ *
28
  * @method string getObjectId()
29
  * @method string getObjectType()
30
  * @method string getRecipientId()
31
  * @method string getClickId()
32
+ *
33
  * @method Mzax_Emarketing_Model_Resource_Goal getResource()
34
+ *
35
+ *
36
+ * If you plan on implementing custom events, use a type id greater than 100
 
 
 
 
 
37
  */
38
+ class Mzax_Emarketing_Model_Goal extends Mage_Core_Model_Abstract
39
  {
 
40
  const TYPE_ORDER = 1;
41
  const TYPE_SIGNUP = 2;
42
+
 
 
43
  /**
44
  * Prefix of model events names
45
  *
55
  * @var string
56
  */
57
  protected $_eventObject = 'goal';
58
+
59
+ /**
60
+ * Model Construct
61
+ *
62
+ * @return void
63
+ */
64
  protected function _construct()
65
  {
66
  $this->_init('mzax_emarketing/goal');
67
  }
 
 
 
 
 
68
  }
app/code/community/Mzax/Emarketing/Model/Inbox.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,75 +18,78 @@
19
 
20
 
21
  /**
22
- * Email Inbox Facade
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Model_Inbox
29
  {
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
-
32
-
33
  /**
34
  * Retrieve new email messages
35
- *
36
- * @return Mzax_Emarketing_Model_Inbox
37
  */
38
  public function downloadEmails()
39
  {
40
- if(!Mage::getStoreConfigFlag('mzax_emarketing/inbox/enable')) {
41
- return;
42
  }
43
-
44
- $lock = Mage::helper('mzax_emarketing')->lock('download_emails');
45
- if(!$lock) {
 
 
 
46
  return $this;
47
  }
48
-
49
-
50
-
51
  /* @var $collector Mzax_Emarketing_Model_Inbox_Email_Collector */
52
  $collector = Mage::getModel('mzax_emarketing/inbox_email_collector');
53
  $collector->collect();
54
-
55
  $lock->unlock();
56
-
57
  return $this;
58
  }
59
-
60
-
61
-
62
 
63
  /**
64
  * Parse email messages
65
  *
66
- * @return Mzax_Emarketing_Model_Inbox
67
  */
68
  public function parseEmails()
69
  {
70
- $lock = Mage::helper('mzax_emarketing')->lock('parse_emails');
71
- if(!$lock) {
 
 
 
72
  return $this;
73
  }
74
-
75
  /* @var $collection Mzax_Emarketing_Model_Resource_Inbox_Email_Collection */
76
  $collection = Mage::getResourceModel('mzax_emarketing/inbox_email_collection');
77
  $collection->addFieldToFilter('is_parsed', 0);
78
-
79
  /* @var $email Mzax_Emarketing_Model_Inbox_Email */
80
- foreach($collection as $email) {
81
  $email->parse();
82
  $lock->touch();
83
  }
84
-
85
  $lock->unlock();
 
86
  return $this;
87
  }
88
-
89
-
90
-
91
-
92
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Inbox
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Inbox
24
  {
25
+ /**
26
+ * @var Mzax_Emarketing_Model_Config
27
+ */
28
+ protected $_config;
29
+
30
+ /**
31
+ * Mzax_Emarketing_Model_Outbox constructor.
32
+ */
33
+ public function __construct()
34
+ {
35
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
36
+ }
37
 
 
 
38
  /**
39
  * Retrieve new email messages
40
+ *
41
+ * @return $this
42
  */
43
  public function downloadEmails()
44
  {
45
+ if (!$this->_config->flag('mzax_emarketing/inbox/enable')) {
46
+ return $this;
47
  }
48
+
49
+ /** @var Mzax_Emarketing_Helper_Data $helper */
50
+ $helper = Mage::helper('mzax_emarketing');
51
+
52
+ $lock = $helper->lock('download_emails');
53
+ if (!$lock) {
54
  return $this;
55
  }
56
+
 
 
57
  /* @var $collector Mzax_Emarketing_Model_Inbox_Email_Collector */
58
  $collector = Mage::getModel('mzax_emarketing/inbox_email_collector');
59
  $collector->collect();
60
+
61
  $lock->unlock();
62
+
63
  return $this;
64
  }
 
 
 
65
 
66
  /**
67
  * Parse email messages
68
  *
69
+ * @return $this
70
  */
71
  public function parseEmails()
72
  {
73
+ /** @var Mzax_Emarketing_Helper_Data $helper */
74
+ $helper = Mage::helper('mzax_emarketing');
75
+
76
+ $lock = $helper->lock('parse_emails');
77
+ if (!$lock) {
78
  return $this;
79
  }
80
+
81
  /* @var $collection Mzax_Emarketing_Model_Resource_Inbox_Email_Collection */
82
  $collection = Mage::getResourceModel('mzax_emarketing/inbox_email_collection');
83
  $collection->addFieldToFilter('is_parsed', 0);
84
+
85
  /* @var $email Mzax_Emarketing_Model_Inbox_Email */
86
+ foreach ($collection as $email) {
87
  $email->parse();
88
  $lock->touch();
89
  }
90
+
91
  $lock->unlock();
92
+
93
  return $this;
94
  }
 
 
 
 
 
95
  }
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,14 +18,9 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
24
- *
25
  */
26
  abstract class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
27
  extends Mzax_Bounce_Detector_Abstract
28
  {
29
-
30
-
31
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
24
  extends Mzax_Bounce_Detector_Abstract
25
  {
26
+ }
 
 
 
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Recipient.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,125 +17,115 @@
18
  */
19
 
20
 
21
-
 
 
22
  class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Recipient
23
  extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
24
  {
25
-
26
-
27
  /**
28
  * try to find our beacon from mime boundary
29
- *
30
  * @see Mzax_Emarketing_Model_Recipient
31
  * @var string
32
  */
33
  const BOUNDARY_REGEX = '!\=\_MZAX\_\=([a-zA-Z0-9]{30})\_\=!';
34
-
35
-
36
  /**
37
- *
38
  * @see Mzax_Emarketing_Model_Recipient::getBeaconImage()
39
  * @var string
40
  */
41
  const IMAGE_REGEX = '!\/emarketing-media\/([a-zA-Z0-9]{16})\/logo\.gif!i';
42
-
43
-
44
-
45
  /**
46
- *
47
  * @var string
48
  */
49
  const LINK_REGEX = '!\/link-goto\/([a-zA-Z0-9]{16})!';
50
-
51
-
52
-
53
-
54
  /**
55
  * Try to detect unique beacon hash
56
- *
57
  * @param Mzax_Bounce_Message $message
58
- * @return Ambigous <string, boolean>|unknown|boolean
 
59
  */
60
  public function detectBeaconHash(Mzax_Bounce_Message $message)
61
  {
62
  $beacon = $message->header('x-campaign-ref');
63
- if($beacon) {
64
  return $beacon;
65
  }
66
-
67
-
68
  $content = $message->getContent();
69
-
70
- if(preg_match(self::BOUNDARY_REGEX, $content, $matches)) {
71
  return $matches[1];
72
  }
73
- if(preg_match(self::IMAGE_REGEX, $content, $matches)) {
74
  return $matches[1];
75
  }
76
-
77
  return false;
78
  }
79
-
80
-
81
-
82
-
83
  /**
84
  * Try to detect unique link hash
85
- *
86
  * @param Mzax_Bounce_Message $message
87
- * @return unknown|boolean
 
88
  */
89
  public function detectLinkHash(Mzax_Bounce_Message $message)
90
  {
91
  $content = $message->getContent();
92
-
93
- if(preg_match(self::LINK_REGEX, $content, $matches)) {
94
  return $matches[1];
95
  }
96
  return false;
97
  }
98
-
99
-
100
-
101
  /**
102
  * Detect original email by references headers
103
- *
104
  * @see http://th-h.de/faq/headerfaq.php#technisches
105
  * @param Mzax_Bounce_Message $message
106
- * @return Mzax_Emarketing_Model_Outbox_Email|NULL
 
107
  */
108
  public function detectReferenceEmail(Mzax_Bounce_Message $message)
109
  {
110
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
111
  $email = Mage::getModel('mzax_emarketing/outbox_email');
112
-
113
  // try to load original email by reference header
114
- foreach(array_reverse($message->getReferences()) as $messageId) {
115
  $email->loadByMessageId($messageId);
116
- if($email->getId()) {
117
  return $email;
118
  }
119
  }
120
-
121
  // try using in reply header
122
  $inReplyTo = $message->getHeader('in-reply-to');
123
- if(preg_match('/<(.+)>/', $inReplyTo, $match)) {
124
  $email->loadByMessageId($match[1]);
125
- if($email->getId()) {
126
  return $email;
127
  }
128
  }
 
129
  return null;
130
  }
131
-
132
-
133
-
134
  /**
135
  * Try to find an email that has been recently sent
136
  * to the sender address within the past 60 minutes
137
- *
138
  * This might not be fail proof, but lets see how we go
139
- *
140
  * @param Mzax_Bounce_Message $message
141
  * @return Mzax_Emarketing_Model_Outbox_Email|NULL
142
  */
@@ -144,91 +133,80 @@ class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Recipient
144
  {
145
  $date = $message->getDate();
146
  $email = $message->getFrom();
147
-
148
  $emailId = Mage::getResourceSingleton('mzax_emarketing/outbox_email')->findRecentlySent($email, $date, 60);
149
- if($emailId) {
150
  return Mage::getModel('mzax_emarketing/outbox_email')->load($emailId);
151
  }
 
152
  return null;
153
  }
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
  /**
162
- * Try to find orignal recipient
163
- *
164
- * @return Mzax_Emarketing_Model_Recipient|NULL
 
 
165
  */
166
  public function findRecipient(Mzax_Bounce_Message $message)
167
  {
168
  $email = $this->detectReferenceEmail($message);
169
- if($email) {
170
  return $email->getRecipient();
171
  }
172
-
173
  $hash = $this->detectBeaconHash($message);
174
- if($hash) {
175
  /* @var $recipient Mzax_Emarketing_Model_Recipient */
176
  $recipient = Mage::getModel('mzax_emarketing/recipient');
177
  $recipient = $recipient->load($hash, 'beacon_hash');
178
- if($recipient->getId()) {
179
  return $recipient;
180
  }
181
  }
182
-
183
  $hash = $this->detectLinkHash($message);
184
- if($hash) {
185
  /* @var $linkRef Mzax_Emarketing_Model_Link_Reference */
186
  $linkRef = Mage::getModel('mzax_emarketing/link_reference');
187
  $linkRef->load($hash, 'public_id');
188
-
189
- if($linkRef->getRecipientId()) {
190
  return $linkRef->getRecipient();
191
  }
192
  }
193
-
194
-
195
  // last try, check if we have send anything to the sender email recently
196
  $email = $this->detectRecientlySentEmail($message);
197
- if($email) {
198
  return $email->getRecipient();
199
  }
200
-
201
-
202
  return null;
203
  }
204
-
205
-
206
-
207
-
208
  /**
209
  * Try to detect the original recipiet id and campaign id
210
- *
211
- *
212
  * (non-PHPdoc)
213
  * @see Mzax_Bounce_Detector_Abstract::inspect()
 
 
214
  */
215
  public function inspect(Mzax_Bounce_Message $message)
216
  {
217
  $recipient = $this->findRecipient($message);
218
- if($recipient) {
219
  $recipient->prepare();
220
  $message->info('recipient_id', $recipient->getId());
221
- $message->info('campaign_id', $recipient->getCampaignId());
222
- $message->info('recipient', $recipient->getEmail(), 100);
223
-
224
  $storeId = Mage::getResourceSingleton('mzax_emarketing/recipient')->getStoreId($recipient->getId());
225
- if($storeId) {
226
  $message->info('store_id', $storeId, 100);
227
  }
228
-
229
  }
230
  }
231
-
232
-
233
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Recipient
22
+ */
23
  class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Recipient
24
  extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
25
  {
 
 
26
  /**
27
  * try to find our beacon from mime boundary
28
+ *
29
  * @see Mzax_Emarketing_Model_Recipient
30
  * @var string
31
  */
32
  const BOUNDARY_REGEX = '!\=\_MZAX\_\=([a-zA-Z0-9]{30})\_\=!';
33
+
 
34
  /**
35
+ *
36
  * @see Mzax_Emarketing_Model_Recipient::getBeaconImage()
37
  * @var string
38
  */
39
  const IMAGE_REGEX = '!\/emarketing-media\/([a-zA-Z0-9]{16})\/logo\.gif!i';
40
+
 
 
41
  /**
42
+ *
43
  * @var string
44
  */
45
  const LINK_REGEX = '!\/link-goto\/([a-zA-Z0-9]{16})!';
46
+
 
 
 
47
  /**
48
  * Try to detect unique beacon hash
49
+ *
50
  * @param Mzax_Bounce_Message $message
51
+ *
52
+ * @return string|boolean
53
  */
54
  public function detectBeaconHash(Mzax_Bounce_Message $message)
55
  {
56
  $beacon = $message->header('x-campaign-ref');
57
+ if ($beacon) {
58
  return $beacon;
59
  }
60
+
 
61
  $content = $message->getContent();
62
+
63
+ if (preg_match(self::BOUNDARY_REGEX, $content, $matches)) {
64
  return $matches[1];
65
  }
66
+ if (preg_match(self::IMAGE_REGEX, $content, $matches)) {
67
  return $matches[1];
68
  }
69
+
70
  return false;
71
  }
72
+
 
 
 
73
  /**
74
  * Try to detect unique link hash
75
+ *
76
  * @param Mzax_Bounce_Message $message
77
+ *
78
+ * @return string|boolean
79
  */
80
  public function detectLinkHash(Mzax_Bounce_Message $message)
81
  {
82
  $content = $message->getContent();
83
+
84
+ if (preg_match(self::LINK_REGEX, $content, $matches)) {
85
  return $matches[1];
86
  }
87
  return false;
88
  }
89
+
 
 
90
  /**
91
  * Detect original email by references headers
92
+ *
93
  * @see http://th-h.de/faq/headerfaq.php#technisches
94
  * @param Mzax_Bounce_Message $message
95
+ *
96
+ * @return Mzax_Emarketing_Model_Outbox_Email|null
97
  */
98
  public function detectReferenceEmail(Mzax_Bounce_Message $message)
99
  {
100
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
101
  $email = Mage::getModel('mzax_emarketing/outbox_email');
102
+
103
  // try to load original email by reference header
104
+ foreach (array_reverse($message->getReferences()) as $messageId) {
105
  $email->loadByMessageId($messageId);
106
+ if ($email->getId()) {
107
  return $email;
108
  }
109
  }
110
+
111
  // try using in reply header
112
  $inReplyTo = $message->getHeader('in-reply-to');
113
+ if (preg_match('/<(.+)>/', $inReplyTo, $match)) {
114
  $email->loadByMessageId($match[1]);
115
+ if ($email->getId()) {
116
  return $email;
117
  }
118
  }
119
+
120
  return null;
121
  }
122
+
 
 
123
  /**
124
  * Try to find an email that has been recently sent
125
  * to the sender address within the past 60 minutes
126
+ *
127
  * This might not be fail proof, but lets see how we go
128
+ *
129
  * @param Mzax_Bounce_Message $message
130
  * @return Mzax_Emarketing_Model_Outbox_Email|NULL
131
  */
133
  {
134
  $date = $message->getDate();
135
  $email = $message->getFrom();
136
+
137
  $emailId = Mage::getResourceSingleton('mzax_emarketing/outbox_email')->findRecentlySent($email, $date, 60);
138
+ if ($emailId) {
139
  return Mage::getModel('mzax_emarketing/outbox_email')->load($emailId);
140
  }
141
+
142
  return null;
143
  }
144
+
 
 
 
 
 
 
145
  /**
146
+ * Try to find original recipient
147
+ *
148
+ * @param Mzax_Bounce_Message $message
149
+ *
150
+ * @return Mzax_Emarketing_Model_Recipient|null
151
  */
152
  public function findRecipient(Mzax_Bounce_Message $message)
153
  {
154
  $email = $this->detectReferenceEmail($message);
155
+ if ($email) {
156
  return $email->getRecipient();
157
  }
158
+
159
  $hash = $this->detectBeaconHash($message);
160
+ if ($hash) {
161
  /* @var $recipient Mzax_Emarketing_Model_Recipient */
162
  $recipient = Mage::getModel('mzax_emarketing/recipient');
163
  $recipient = $recipient->load($hash, 'beacon_hash');
164
+ if ($recipient->getId()) {
165
  return $recipient;
166
  }
167
  }
168
+
169
  $hash = $this->detectLinkHash($message);
170
+ if ($hash) {
171
  /* @var $linkRef Mzax_Emarketing_Model_Link_Reference */
172
  $linkRef = Mage::getModel('mzax_emarketing/link_reference');
173
  $linkRef->load($hash, 'public_id');
174
+
175
+ if ($linkRef->getRecipientId()) {
176
  return $linkRef->getRecipient();
177
  }
178
  }
179
+
 
180
  // last try, check if we have send anything to the sender email recently
181
  $email = $this->detectRecientlySentEmail($message);
182
+ if ($email) {
183
  return $email->getRecipient();
184
  }
185
+
 
186
  return null;
187
  }
188
+
 
 
 
189
  /**
190
  * Try to detect the original recipiet id and campaign id
191
+ *
 
192
  * (non-PHPdoc)
193
  * @see Mzax_Bounce_Detector_Abstract::inspect()
194
+ *
195
+ * @return void
196
  */
197
  public function inspect(Mzax_Bounce_Message $message)
198
  {
199
  $recipient = $this->findRecipient($message);
200
+ if ($recipient) {
201
  $recipient->prepare();
202
  $message->info('recipient_id', $recipient->getId());
203
+ $message->info('campaign_id', $recipient->getCampaignId());
204
+ $message->info('recipient', $recipient->getEmail(), 100);
205
+
206
  $storeId = Mage::getResourceSingleton('mzax_emarketing/recipient')->getStoreId($recipient->getId());
207
+ if ($storeId) {
208
  $message->info('store_id', $storeId, 100);
209
  }
 
210
  }
211
  }
212
+ }
 
 
 
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Store.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,72 +19,66 @@
20
 
21
  /**
22
  * Detector for store id
23
- *
24
  * if no recipient was found we may can still find the right
25
  * store id by using the To email address
26
- *
27
- * @author Jacob Siefer
28
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
- * @version 0.4.10
30
  */
31
  class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Store
32
  extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
33
  {
34
-
35
-
36
-
37
  /**
38
- * Try to detect the original recipiet id and campaign id
39
- *
40
- *
41
- * (non-PHPdoc)
42
  * @see Mzax_Bounce_Detector_Abstract::inspect()
 
 
43
  */
44
  public function inspect(Mzax_Bounce_Message $message)
45
  {
46
  $to = strtolower($this->findEmail($message->getHeader('to')));
47
-
48
- if($store = $this->getStoreByEmail($to)) {
49
  $message->info('store_id', $store->getId());
50
  }
51
  }
52
-
53
-
54
-
 
 
 
 
 
55
  public function getStoreByEmail($email)
56
  {
57
  $email = strtolower($email);
58
  /* @var $store Mage_Core_Model_Store */
59
-
60
-
61
  /*
62
  * try to retrieve store by using the email
63
  */
64
- foreach(Mage::app()->getStores() as $store) {
65
  $config = $store->getConfig('trans_email');
66
- foreach($config as $key => $data) {
67
- if(isset($data['email']) && strtolower($data['email']) === $email) {
68
  return $store;
69
  }
70
  }
71
  }
72
-
73
  /*
74
  * try to retrieve the store by using the domain
75
  */
76
  $domain = trim(strstr($email, '@'), '@');
77
- foreach(Mage::app()->getStores() as $store) {
78
  $baseUrl = strtolower($store->getBaseUrl($store::URL_TYPE_WEB));
79
  $baseUrl = preg_replace('/^(?:https?:\/\/)?(?:www\.)?([^\/]+)(.*)$/i', '$1', $baseUrl);
80
-
81
- if($baseUrl === $domain) {
82
  return $store;
83
  }
84
  }
85
-
86
  return null;
87
  }
88
-
89
-
90
-
91
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
  /**
21
  * Detector for store id
22
+ *
23
  * if no recipient was found we may can still find the right
24
  * store id by using the To email address
 
 
 
 
25
  */
26
  class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Store
27
  extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
28
  {
 
 
 
29
  /**
30
+ * Try to detect the original sender store id by email
31
+ *
 
 
32
  * @see Mzax_Bounce_Detector_Abstract::inspect()
33
+ *
34
+ * @return void
35
  */
36
  public function inspect(Mzax_Bounce_Message $message)
37
  {
38
  $to = strtolower($this->findEmail($message->getHeader('to')));
39
+
40
+ if ($store = $this->getStoreByEmail($to)) {
41
  $message->info('store_id', $store->getId());
42
  }
43
  }
44
+
45
+ /**
46
+ * Try to retrieve store from email
47
+ *
48
+ * @param string $email
49
+ *
50
+ * @return Mage_Core_Model_Store|null
51
+ */
52
  public function getStoreByEmail($email)
53
  {
54
  $email = strtolower($email);
55
  /* @var $store Mage_Core_Model_Store */
56
+
 
57
  /*
58
  * try to retrieve store by using the email
59
  */
60
+ foreach (Mage::app()->getStores() as $store) {
61
  $config = $store->getConfig('trans_email');
62
+ foreach ($config as $key => $data) {
63
+ if (isset($data['email']) && strtolower($data['email']) === $email) {
64
  return $store;
65
  }
66
  }
67
  }
68
+
69
  /*
70
  * try to retrieve the store by using the domain
71
  */
72
  $domain = trim(strstr($email, '@'), '@');
73
+ foreach (Mage::app()->getStores() as $store) {
74
  $baseUrl = strtolower($store->getBaseUrl($store::URL_TYPE_WEB));
75
  $baseUrl = preg_replace('/^(?:https?:\/\/)?(?:www\.)?([^\/]+)(.*)$/i', '$1', $baseUrl);
76
+
77
+ if ($baseUrl === $domain) {
78
  return $store;
79
  }
80
  }
81
+
82
  return null;
83
  }
84
+ }
 
 
 
app/code/community/Mzax/Emarketing/Model/Inbox/Bounce/Detector/Unsubscribe.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,53 +18,43 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Unsubscribe
29
  extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
30
  {
31
-
32
-
33
  /**
34
- *
35
- * (non-PHPdoc)
36
- * @see Mzax_Bounce_Detector_Abstract::inspect()
37
  */
38
  public function inspect(Mzax_Bounce_Message $message)
39
  {
40
  $subject = urldecode(trim($message->getSubject()));
41
-
42
- if(preg_match('/^Unsubscribe ([^\s]+) \(([0-9A-Z]+)\)$/i', $subject, $matches)) {
43
  $email = $matches[1];
44
  $hash = $matches[2];
45
-
46
  /* @var $recipient Mzax_Emarketing_Model_Recipient */
47
  $recipient = Mage::getModel('mzax_emarketing/recipient')->loadByBeacon($hash);
48
- if($recipient->getId()) {
49
  $recipient->prepare();
50
- if(strtolower($recipient->getAddress()) == strtolower($email)) {
51
  $message->info('recipient_id', $recipient->getId(), 200);
52
- $message->info('campaign_id', $recipient->getCampaignId(), 200);
53
- $message->info('recipient', $email, 200);
54
  $message->info(Mzax_Bounce::TYPE_UNSUBSCRIBE, true);
55
  $message->info('type', Mzax_Bounce::TYPE_UNSUBSCRIBE);
56
-
57
  $storeId = Mage::getResourceSingleton('mzax_emarketing/recipient')->getStoreId($recipient->getId());
58
- if($storeId) {
59
  $message->info('store_id', $storeId, 100);
60
  }
61
-
62
- return true; // stop
63
  }
64
  }
65
-
66
  }
67
  }
68
-
69
-
70
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Unsubscribe
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Inbox_Bounce_Detector_Unsubscribe
24
  extends Mzax_Emarketing_Model_Inbox_Bounce_Detector_Abstract
25
  {
 
 
26
  /**
27
+ * @param Mzax_Bounce_Message $message
28
+ *
29
+ * @return bool
30
  */
31
  public function inspect(Mzax_Bounce_Message $message)
32
  {
33
  $subject = urldecode(trim($message->getSubject()));
34
+
35
+ if (preg_match('/^Unsubscribe ([^\s]+) \(([0-9A-Z]+)\)$/i', $subject, $matches)) {
36
  $email = $matches[1];
37
  $hash = $matches[2];
38
+
39
  /* @var $recipient Mzax_Emarketing_Model_Recipient */
40
  $recipient = Mage::getModel('mzax_emarketing/recipient')->loadByBeacon($hash);
41
+ if ($recipient->getId()) {
42
  $recipient->prepare();
43
+ if (strtolower($recipient->getAddress()) == strtolower($email)) {
44
  $message->info('recipient_id', $recipient->getId(), 200);
45
+ $message->info('campaign_id', $recipient->getCampaignId(), 200);
46
+ $message->info('recipient', $email, 200);
47
  $message->info(Mzax_Bounce::TYPE_UNSUBSCRIBE, true);
48
  $message->info('type', Mzax_Bounce::TYPE_UNSUBSCRIBE);
49
+
50
  $storeId = Mage::getResourceSingleton('mzax_emarketing/recipient')->getStoreId($recipient->getId());
51
+ if ($storeId) {
52
  $message->info('store_id', $storeId, 100);
53
  }
54
+
55
+ return true;
56
  }
57
  }
 
58
  }
59
  }
60
+ }
 
 
 
app/code/community/Mzax/Emarketing/Model/Inbox/Email.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,7 +17,8 @@
18
  */
19
 
20
  /**
21
- *
 
22
  * @method string getCreatedAt()
23
  * @method string getHeaders()
24
  * @method string getIsParsed()
@@ -30,34 +30,33 @@
30
  * @method string getEmail()
31
  * @method string getType()
32
  * @method string getPurged()
33
- *
34
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setCreatedAt(string)
35
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setHeaders(string)
36
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setContent(string)
37
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setIsParsed(string)
38
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setRecipientId(string)
39
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setCampaignId(string)
40
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setSubject(string)
41
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setMessage(string)
42
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setSentAt(string)
43
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setEmail(string)
44
- * @method Mzax_Emarketing_Model_Recipient_Bounce_Message setType(string)
45
- *
 
 
46
  * @method Mzax_Emarketing_Model_Resource_Inbox_Email getResource()
47
- *
48
- * @author Jacob Siefer
49
  *
50
  */
51
  class Mzax_Emarketing_Model_Inbox_Email
52
- extends Mzax_Emarketing_Model_Email
53
  {
54
-
55
  const BOUNCE_SOFT = 'SB';
56
  const BOUNCE_HARD = 'HB';
57
  const AUTOREPLY = 'AR';
58
  const NO_BOUNCE = 'NB';
59
  const UNSUBSCRIBE = 'US';
60
-
61
  /**
62
  * Prefix of model events names
63
  *
@@ -73,27 +72,28 @@ class Mzax_Emarketing_Model_Inbox_Email
73
  * @var string
74
  */
75
  protected $_eventObject = 'email';
76
-
77
-
78
-
79
  /**
80
  * Email content
81
- *
82
  * @var string
83
  */
84
  protected $_content;
85
-
86
-
87
-
 
 
 
88
  /**
89
  * Retrieve bounce decoder
90
- *
91
  * @return Mzax_Bounce_Detector
92
  */
93
  public static function getBounceDecoder()
94
  {
95
  static $bounceDecoder;
96
- if(!$bounceDecoder) {
97
  $bounceDecoder = new Mzax_Bounce_Detector;
98
  $bounceDecoder->addDetector(Mage::getModel('mzax_emarketing/inbox_bounce_detector_unsubscribe'), 0);
99
  $bounceDecoder->addDetector(Mage::getModel('mzax_emarketing/inbox_bounce_detector_recipient'), 1);
@@ -101,60 +101,64 @@ class Mzax_Emarketing_Model_Inbox_Email
101
  }
102
  return $bounceDecoder;
103
  }
104
-
105
-
106
-
107
-
108
-
109
  protected function _construct()
110
  {
111
  $this->_init('mzax_emarketing/inbox_email');
 
 
112
  }
113
-
114
-
115
-
 
 
 
116
  protected function _beforeSave()
117
  {
118
- if($this->_content !== null && !$this->isPurged()) {
119
  $this->setSize(strlen($this->_content));
120
  }
121
-
122
- return parent::_beforeSave();
 
123
  }
124
-
125
-
126
-
127
-
128
-
129
-
130
  /**
131
  * Parse the current message
132
- *
133
- * Return the parse time
134
- *
135
- * @return number
 
136
  */
137
  public function parse()
138
  {
 
 
 
 
 
 
139
  // not possible if email is purged
140
- if($this->isPurged()) {
141
  return 0;
142
  }
143
-
144
  $start = microtime(true);
145
-
146
  $this->getResource()->flagAsParsed($this);
147
-
148
-
149
  try {
150
  /* @var $message Mzax_Bounce_Message */
151
  $message = new Mzax_Bounce_Message($this->getRawData());
152
  $message->setHeader('created_at', $this->getCreatedAt());
153
-
154
  $result = self::getBounceDecoder()->inspect($message);
155
  $result = new Varien_Object($result);
156
-
157
-
158
  $update = array(
159
  'is_parsed' => 1,
160
  'email' => $result->getRecipient(),
@@ -167,117 +171,111 @@ class Mzax_Emarketing_Model_Inbox_Email
167
  'store_id' => $result->getStoreId(),
168
  'campaign_id' => $result->getCampaignId(),
169
  );
170
-
171
  $status = $result->getStatus();
172
- if($status) {
173
- if(strpos($status, '4.') === 0) {
174
  $update['type'] = self::BOUNCE_SOFT;
175
  }
176
- if(strpos($status, '5.') === 0) {
177
  $update['type'] = self::BOUNCE_HARD;
178
  }
179
- }
180
- else if($result->getAutoreply()) {
181
  $update['type'] = self::AUTOREPLY;
182
- }
183
- else if($result->getUnsubscribe()) {
184
  $update['type'] = self::UNSUBSCRIBE;
185
  /* @see $subscriber Mzax_Emarketing_Helper_Newsletter */
186
- Mage::helper('mzax_emarketing/newsletter')->unsubscribe($result->getRecipient(), $result->getStoreId(), false);
187
- }
188
- else {
189
  $update['type'] = self::NO_BOUNCE;
190
  }
191
-
192
-
193
- if($part = $message->findMinePart(Zend_Mime::TYPE_TEXT)) {
194
  $text = $part->getDecodedContent();
195
- }
196
- else {
197
  $text = $message->getDecodedContent();
198
  }
199
- if($pos = strpos($text, '---')) {
200
  $text = substr($text, 0, $pos);
201
  }
202
  $text = Mage::helper('core/string')->stripTags($text);
203
  $text = Mage::helper('core/string')->truncate($text, 512);
204
-
205
  $update['message'] = $text;
206
  $update['subject'] = $message->getSubject();
207
-
208
-
209
  $this->addData($update);
210
  $this->save();
211
-
212
  Mage::dispatchEvent('mzax_emarketing_inbox_email_parse', array(
213
  'email' => $this,
214
  'message' => $message,
215
  'result' => $result
216
  ));
217
-
218
- if($this->shouldForward()) {
219
  $this->forward($message);
220
  }
221
-
222
-
 
 
 
 
223
  // unsubscribe hard bounces
224
- if(!$this->getNoUnsubscribe() && $this->getType() == self::BOUNCE_HARD && Mage::getStoreConfigFlag('mzax_emarketing/inbox/unsubscribe_hard_bounce', $this->getStore())) {
225
- Mage::getSingleton('mzax_emarketing/medium_email')->unsubscribe($this->getEmail(), sprintf('%s bounce, email %s', $status, $this->getId()));
226
  }
227
- }
228
- catch(Exception $e) {
229
- if(Mage::getIsDeveloperMode()) {
230
  throw $e;
231
  }
232
  Mage::logException($e);
233
  }
234
-
235
  return microtime(true) - $start;
236
  }
237
-
238
-
239
-
240
-
241
-
242
-
243
  /**
244
  * Forward email
245
- *
246
  * @param Mzax_Bounce_Message $message
 
247
  * @return boolean
248
  */
249
  public function forward(Mzax_Bounce_Message $message = null)
250
  {
251
  // not possible if email is purged
252
- if($this->isPurged()) {
253
- return;
254
  }
255
 
256
- if(!$message) {
257
  $message = new Mzax_Bounce_Message($this->getRawData());
258
  }
259
 
260
  $mail = $message->forward();
261
-
262
  $canSend = false;
263
- foreach($this->getForwardToEmails() as $email) {
264
- if(Zend_Validate::is($email, 'EmailAddress')) {
265
  $mail->addTo($email);
266
  $canSend = true;
267
  }
268
  }
269
-
270
- if(!$canSend) {
271
  Mage::helper('mzax_emarketing')->log("Unable to forward message, no email address defined.");
272
  return false;
273
  }
274
-
275
-
276
  $sender = $this->getSender();
277
  $mail->setFrom($sender['email'], $sender['name']);
278
  $mail->addHeader('X-Mailer', 'Mzax-Emarketing '.Mage::helper('mzax_emarketing')->getVersion());
279
  $mail->addHeader('X-Originating-IP', Mage::app()->getRequest()->getServer('SERVER_ADDR'));
280
-
281
 
282
  $this->setMailTransport(null);
283
  Mage::dispatchEvent('mzax_emarketing_inbox_email_forward', array(
@@ -285,7 +283,7 @@ class Mzax_Emarketing_Model_Inbox_Email
285
  'email' => $this,
286
  'message' => $message
287
  ));
288
-
289
  // in case an event observer has set one
290
  $transport = $this->getMailTransport();
291
 
@@ -294,143 +292,125 @@ class Mzax_Emarketing_Model_Inbox_Email
294
 
295
  return true;
296
  }
297
-
298
-
299
-
300
-
 
 
301
  public function report()
302
  {
303
  // not possible if email is purged
304
- if($this->isPurged()) {
305
  return;
306
  }
 
307
 
308
  $mail = new Zend_Mail();
309
-
310
- $sender = $this->getSender();
311
  $mail->setFrom($sender['email'], $sender['name']);
312
  $mail->setSubject(sprintf("Bounce Report (%s)", Mage::helper('mzax_emarketing')->getVersion()));
313
  $mail->setBodyText("The following message appears to be a bounce.\nPlease verify.\n\n");
314
- $mail->createAttachment($this->getRawData(),
315
- 'message/rfc822',
316
- Zend_Mime::DISPOSITION_ATTACHMENT,
317
- Zend_Mime::ENCODING_BASE64,
318
- sprintf('bounce.%s.%s.eml', Mage::app()->getRequest()->getServer('SERVER_ADDR'), time()));
 
 
319
  $mail->addTo('jacob@mzax.de');
320
  $mail->addHeader('X-Mailer', 'Mzax-Emarketing '.Mage::helper('mzax_emarketing')->getVersion());
321
  $mail->send();
322
  }
323
-
324
-
325
-
326
-
327
-
328
  /**
329
  * Retrieve sender
330
- *
331
- * @return array
332
  */
333
  public function getSender()
334
  {
335
- if($campaign = $this->getCampaign()) {
336
  return $campaign->getSender();
337
  }
338
- $sender = Mage::getStoreConfig('mzax_emarketing/inbox/forward_identity', $this->getStore());
 
339
  return array(
340
- 'name' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/name', $this->getStore()),
341
- 'email' => Mage::getStoreConfig('trans_email/ident_'.$sender.'/email', $this->getStore()),
342
  );
343
  }
344
-
345
-
346
-
347
-
348
-
349
-
350
-
351
  /**
352
  * Retrieve email addresses to forward non-bonce messages
353
- *
354
- * @return array
355
  */
356
  public function getForwardToEmails()
357
  {
358
- $emails = Mage::getStoreConfig('mzax_emarketing/inbox/forward_emails', $this->getStore());
359
  $emails = explode(',', $emails);
360
  $emails = array_map('trim', $emails);
361
-
362
  $campaign = $this->getCampaign();
363
- if($campaign) {
364
  $campaignEmails = $campaign->getMediumData()->getForwardEmails();
365
- if(!empty($campaignEmails)) {
366
  $campaignEmails = explode(',', $campaignEmails);
367
  $emails = array_merge($emails, $campaignEmails);
368
  }
369
  }
370
-
371
  $emails = array_map('trim', $emails);
372
  $emails = array_map('strtolower', $emails);
373
  $emails = array_filter($emails);
374
  $emails = array_unique($emails);
375
-
376
  return $emails;
377
  }
378
-
379
-
380
-
381
-
382
  /**
383
  * Should this message get forwarded
384
- *
385
  * @return boolean
386
  */
387
  public function shouldForward()
388
  {
389
- if(!$this->getIsParsed() || $this->getNoForward() || $this->isPurged()) {
390
  return false;
391
  }
392
- if($this->isARF() || $this->isAutoreply() || $this->isBounce()) {
393
  return false;
394
  }
395
  return true;
396
  }
397
-
398
-
399
-
400
-
401
  /**
402
  * Load email content
403
- *
404
  * @return string
405
  */
406
  public function getContent()
407
  {
408
- if($this->_content === null && $this->getId() && !$this->isPurged()) {
409
  $file = $this->getResource()->getContentFile($this->getId());
410
- if(file_exists($file)) {
411
  $this->_content = file_get_contents($file);
412
- }
413
- else {
414
  $this->_content = (string) $this->getData('content');
415
  }
416
  }
417
  return $this->_content;
418
  }
419
-
420
-
421
-
422
-
423
  /**
424
  * Retrieve full raw email data
425
- *
426
  * @return string
427
  */
428
  public function getRawData()
429
  {
430
  return $this->getHeaders() . Zend_Mime::LINEEND . $this->getContent();
431
  }
432
-
433
-
434
 
435
  /**
436
  * Is purged
@@ -442,8 +422,6 @@ class Mzax_Emarketing_Model_Inbox_Email
442
  return (bool) $this->getData('purged');
443
  }
444
 
445
-
446
-
447
  /**
448
  * Is already parsed
449
  *
@@ -453,8 +431,7 @@ class Mzax_Emarketing_Model_Inbox_Email
453
  {
454
  return (bool) $this->getData('is_parsed');
455
  }
456
-
457
-
458
  /**
459
  * Is Bounce (soft or hard)
460
  *
@@ -462,27 +439,24 @@ class Mzax_Emarketing_Model_Inbox_Email
462
  */
463
  public function isBounce()
464
  {
465
- switch($this->getData('type')) {
466
  case self::BOUNCE_HARD:
467
  case self::BOUNCE_SOFT:
468
  return true;
469
  }
470
  return false;
471
  }
472
-
473
-
474
  /**
475
  * Is ARF (aka Feedback Loop)
476
- *
477
  * @return boolean
478
  */
479
  public function isARF()
480
  {
481
  return (bool) $this->getData('is_arf');
482
  }
483
-
484
-
485
-
486
  /**
487
  * Is autoreply
488
  *
@@ -492,6 +466,4 @@ class Mzax_Emarketing_Model_Inbox_Email
492
  {
493
  return (bool) $this->getData('is_autoreply');
494
  }
495
-
496
-
497
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Inbox_Email
21
+ *
22
  * @method string getCreatedAt()
23
  * @method string getHeaders()
24
  * @method string getIsParsed()
30
  * @method string getEmail()
31
  * @method string getType()
32
  * @method string getPurged()
33
+ * @method string getSize()
34
+ *
35
+ * @method $this setCreatedAt(string $value)
36
+ * @method $this setHeaders(string $value)
37
+ * @method $this setContent(string $value)
38
+ * @method $this setIsParsed(string $value)
39
+ * @method $this setRecipientId(string $value)
40
+ * @method $this setCampaignId(string $value)
41
+ * @method $this setSubject(string $value)
42
+ * @method $this setMessage(string $value)
43
+ * @method $this setSentAt(string $value)
44
+ * @method $this setEmail(string $value)
45
+ * @method $this setType(string $value)
46
+ * @method $this setSize(string $value)
47
+ *
48
  * @method Mzax_Emarketing_Model_Resource_Inbox_Email getResource()
 
 
49
  *
50
  */
51
  class Mzax_Emarketing_Model_Inbox_Email
52
+ extends Mzax_Emarketing_Model_Email
53
  {
 
54
  const BOUNCE_SOFT = 'SB';
55
  const BOUNCE_HARD = 'HB';
56
  const AUTOREPLY = 'AR';
57
  const NO_BOUNCE = 'NB';
58
  const UNSUBSCRIBE = 'US';
59
+
60
  /**
61
  * Prefix of model events names
62
  *
72
  * @var string
73
  */
74
  protected $_eventObject = 'email';
75
+
 
 
76
  /**
77
  * Email content
78
+ *
79
  * @var string
80
  */
81
  protected $_content;
82
+
83
+ /**
84
+ * @var Mzax_Emarketing_Model_Config
85
+ */
86
+ protected $_config;
87
+
88
  /**
89
  * Retrieve bounce decoder
90
+ *
91
  * @return Mzax_Bounce_Detector
92
  */
93
  public static function getBounceDecoder()
94
  {
95
  static $bounceDecoder;
96
+ if (!$bounceDecoder) {
97
  $bounceDecoder = new Mzax_Bounce_Detector;
98
  $bounceDecoder->addDetector(Mage::getModel('mzax_emarketing/inbox_bounce_detector_unsubscribe'), 0);
99
  $bounceDecoder->addDetector(Mage::getModel('mzax_emarketing/inbox_bounce_detector_recipient'), 1);
101
  }
102
  return $bounceDecoder;
103
  }
104
+
105
+ /**
106
+ * Model constructor
107
+ */
 
108
  protected function _construct()
109
  {
110
  $this->_init('mzax_emarketing/inbox_email');
111
+
112
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
113
  }
114
+
115
+ /**
116
+ * Before save
117
+ *
118
+ * @return $this
119
+ */
120
  protected function _beforeSave()
121
  {
122
+ if ($this->_content !== null && !$this->isPurged()) {
123
  $this->setSize(strlen($this->_content));
124
  }
125
+ parent::_beforeSave();
126
+
127
+ return $this;
128
  }
129
+
 
 
 
 
 
130
  /**
131
  * Parse the current message
132
+ *
133
+ * Return the parsing duration
134
+ *
135
+ * @return int
136
+ * @throws Exception
137
  */
138
  public function parse()
139
  {
140
+ /** @var Mzax_Emarketing_Helper_Newsletter $newsletterHelper */
141
+ $newsletterHelper = Mage::helper('mzax_emarketing/newsletter');
142
+
143
+ /** @var Mzax_Emarketing_Model_Medium_Email $emailMedium */
144
+ $emailMedium = Mage::getSingleton('mzax_emarketing/medium_email');
145
+
146
  // not possible if email is purged
147
+ if ($this->isPurged()) {
148
  return 0;
149
  }
 
150
  $start = microtime(true);
151
+
152
  $this->getResource()->flagAsParsed($this);
153
+
 
154
  try {
155
  /* @var $message Mzax_Bounce_Message */
156
  $message = new Mzax_Bounce_Message($this->getRawData());
157
  $message->setHeader('created_at', $this->getCreatedAt());
158
+
159
  $result = self::getBounceDecoder()->inspect($message);
160
  $result = new Varien_Object($result);
161
+
 
162
  $update = array(
163
  'is_parsed' => 1,
164
  'email' => $result->getRecipient(),
171
  'store_id' => $result->getStoreId(),
172
  'campaign_id' => $result->getCampaignId(),
173
  );
174
+
175
  $status = $result->getStatus();
176
+ if ($status) {
177
+ if (strpos($status, '4.') === 0) {
178
  $update['type'] = self::BOUNCE_SOFT;
179
  }
180
+ if (strpos($status, '5.') === 0) {
181
  $update['type'] = self::BOUNCE_HARD;
182
  }
183
+ } elseif ($result->getAutoreply()) {
 
184
  $update['type'] = self::AUTOREPLY;
185
+ } elseif ($result->getUnsubscribe()) {
 
186
  $update['type'] = self::UNSUBSCRIBE;
187
  /* @see $subscriber Mzax_Emarketing_Helper_Newsletter */
188
+ $newsletterHelper->unsubscribe($result->getRecipient(), $result->getStoreId(), false);
189
+ } else {
 
190
  $update['type'] = self::NO_BOUNCE;
191
  }
192
+
193
+
194
+ if ($part = $message->findMinePart(Zend_Mime::TYPE_TEXT)) {
195
  $text = $part->getDecodedContent();
196
+ } else {
 
197
  $text = $message->getDecodedContent();
198
  }
199
+ if ($pos = strpos($text, '---')) {
200
  $text = substr($text, 0, $pos);
201
  }
202
  $text = Mage::helper('core/string')->stripTags($text);
203
  $text = Mage::helper('core/string')->truncate($text, 512);
204
+
205
  $update['message'] = $text;
206
  $update['subject'] = $message->getSubject();
207
+
208
+
209
  $this->addData($update);
210
  $this->save();
211
+
212
  Mage::dispatchEvent('mzax_emarketing_inbox_email_parse', array(
213
  'email' => $this,
214
  'message' => $message,
215
  'result' => $result
216
  ));
217
+
218
+ if ($this->shouldForward()) {
219
  $this->forward($message);
220
  }
221
+
222
+ $unsubscribeHardBounce = $this->_config->flag(
223
+ 'mzax_emarketing/inbox/unsubscribe_hard_bounce',
224
+ $this->getStore()
225
+ );
226
+
227
  // unsubscribe hard bounces
228
+ if (!$this->getData('no_unsubscribe') && $this->getType() == self::BOUNCE_HARD && $unsubscribeHardBounce) {
229
+ $emailMedium->unsubscribe($this->getEmail(), sprintf('%s bounce, email %s', $status, $this->getId()));
230
  }
231
+ } catch (Exception $e) {
232
+ if (Mage::getIsDeveloperMode()) {
 
233
  throw $e;
234
  }
235
  Mage::logException($e);
236
  }
237
+
238
  return microtime(true) - $start;
239
  }
240
+
 
 
 
 
 
241
  /**
242
  * Forward email
243
+ *
244
  * @param Mzax_Bounce_Message $message
245
+ *
246
  * @return boolean
247
  */
248
  public function forward(Mzax_Bounce_Message $message = null)
249
  {
250
  // not possible if email is purged
251
+ if ($this->isPurged()) {
252
+ return false;
253
  }
254
 
255
+ if (!$message) {
256
  $message = new Mzax_Bounce_Message($this->getRawData());
257
  }
258
 
259
  $mail = $message->forward();
260
+
261
  $canSend = false;
262
+ foreach ($this->getForwardToEmails() as $email) {
263
+ if (Zend_Validate::is($email, 'EmailAddress')) {
264
  $mail->addTo($email);
265
  $canSend = true;
266
  }
267
  }
268
+
269
+ if (!$canSend) {
270
  Mage::helper('mzax_emarketing')->log("Unable to forward message, no email address defined.");
271
  return false;
272
  }
273
+
 
274
  $sender = $this->getSender();
275
  $mail->setFrom($sender['email'], $sender['name']);
276
  $mail->addHeader('X-Mailer', 'Mzax-Emarketing '.Mage::helper('mzax_emarketing')->getVersion());
277
  $mail->addHeader('X-Originating-IP', Mage::app()->getRequest()->getServer('SERVER_ADDR'));
278
+
279
 
280
  $this->setMailTransport(null);
281
  Mage::dispatchEvent('mzax_emarketing_inbox_email_forward', array(
283
  'email' => $this,
284
  'message' => $message
285
  ));
286
+
287
  // in case an event observer has set one
288
  $transport = $this->getMailTransport();
289
 
292
 
293
  return true;
294
  }
295
+
296
+ /**
297
+ * Send email report
298
+ *
299
+ * @return void
300
+ */
301
  public function report()
302
  {
303
  // not possible if email is purged
304
+ if ($this->isPurged()) {
305
  return;
306
  }
307
+ $sender = $this->getSender();
308
 
309
  $mail = new Zend_Mail();
 
 
310
  $mail->setFrom($sender['email'], $sender['name']);
311
  $mail->setSubject(sprintf("Bounce Report (%s)", Mage::helper('mzax_emarketing')->getVersion()));
312
  $mail->setBodyText("The following message appears to be a bounce.\nPlease verify.\n\n");
313
+ $mail->createAttachment(
314
+ $this->getRawData(),
315
+ 'message/rfc822',
316
+ Zend_Mime::DISPOSITION_ATTACHMENT,
317
+ Zend_Mime::ENCODING_BASE64,
318
+ sprintf('bounce.%s.%s.eml', Mage::app()->getRequest()->getServer('SERVER_ADDR'), time())
319
+ );
320
  $mail->addTo('jacob@mzax.de');
321
  $mail->addHeader('X-Mailer', 'Mzax-Emarketing '.Mage::helper('mzax_emarketing')->getVersion());
322
  $mail->send();
323
  }
324
+
 
 
 
 
325
  /**
326
  * Retrieve sender
327
+ *
328
+ * @return string[]
329
  */
330
  public function getSender()
331
  {
332
+ if ($campaign = $this->getCampaign()) {
333
  return $campaign->getSender();
334
  }
335
+ $sender = $this->_config->get('mzax_emarketing/inbox/forward_identity', $this->getStore());
336
+
337
  return array(
338
+ 'name' => $this->_config->get('trans_email/ident_'.$sender.'/name', $this->getStore()),
339
+ 'email' => $this->_config->get('trans_email/ident_'.$sender.'/email', $this->getStore()),
340
  );
341
  }
342
+
 
 
 
 
 
 
343
  /**
344
  * Retrieve email addresses to forward non-bonce messages
345
+ *
346
+ * @return string[]
347
  */
348
  public function getForwardToEmails()
349
  {
350
+ $emails = $this->_config->get('mzax_emarketing/inbox/forward_emails', $this->getStore());
351
  $emails = explode(',', $emails);
352
  $emails = array_map('trim', $emails);
353
+
354
  $campaign = $this->getCampaign();
355
+ if ($campaign) {
356
  $campaignEmails = $campaign->getMediumData()->getForwardEmails();
357
+ if (!empty($campaignEmails)) {
358
  $campaignEmails = explode(',', $campaignEmails);
359
  $emails = array_merge($emails, $campaignEmails);
360
  }
361
  }
362
+
363
  $emails = array_map('trim', $emails);
364
  $emails = array_map('strtolower', $emails);
365
  $emails = array_filter($emails);
366
  $emails = array_unique($emails);
367
+
368
  return $emails;
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() || $this->isPurged()) {
379
  return false;
380
  }
381
+ if ($this->isARF() || $this->isAutoreply() || $this->isBounce()) {
382
  return false;
383
  }
384
  return true;
385
  }
386
+
 
 
 
387
  /**
388
  * Load email content
389
+ *
390
  * @return string
391
  */
392
  public function getContent()
393
  {
394
+ if ($this->_content === null && $this->getId() && !$this->isPurged()) {
395
  $file = $this->getResource()->getContentFile($this->getId());
396
+ if (file_exists($file)) {
397
  $this->_content = file_get_contents($file);
398
+ } else {
 
399
  $this->_content = (string) $this->getData('content');
400
  }
401
  }
402
  return $this->_content;
403
  }
404
+
 
 
 
405
  /**
406
  * Retrieve full raw email data
407
+ *
408
  * @return string
409
  */
410
  public function getRawData()
411
  {
412
  return $this->getHeaders() . Zend_Mime::LINEEND . $this->getContent();
413
  }
 
 
414
 
415
  /**
416
  * Is purged
422
  return (bool) $this->getData('purged');
423
  }
424
 
 
 
425
  /**
426
  * Is already parsed
427
  *
431
  {
432
  return (bool) $this->getData('is_parsed');
433
  }
434
+
 
435
  /**
436
  * Is Bounce (soft or hard)
437
  *
439
  */
440
  public function isBounce()
441
  {
442
+ switch ($this->getData('type')) {
443
  case self::BOUNCE_HARD:
444
  case self::BOUNCE_SOFT:
445
  return true;
446
  }
447
  return false;
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
  * Is autoreply
462
  *
466
  {
467
  return (bool) $this->getData('is_autoreply');
468
  }
 
 
469
  }
app/code/community/Mzax/Emarketing/Model/Inbox/Email/Collector.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,82 +18,63 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Inbox_Email_Collector
30
  {
31
-
32
-
33
-
34
  /**
35
  * Retrieve puller
36
- *
37
  * @return Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract
38
  */
39
  public function getPuller()
40
  {
41
  return Mage::getModel('mzax_emarketing/inbox_email_pull_storage');
42
  }
43
-
44
-
45
-
46
-
47
  /**
48
  * Collect new messages from inbox
49
- *
50
  * Returns the number of new messages found
51
- *
52
  * @return integer
53
  */
54
  public function collect()
55
  {
56
  $puller = $this->getPuller();
57
  $messages = $puller->pull($this);
58
-
59
  return $messages;
60
  }
61
-
62
-
63
-
64
  /**
65
  * Test current setup
66
- *
67
  * @return boolean
68
  */
69
  public function test()
70
  {
71
  $puller = $this->getPuller();
72
- if($puller) {
73
  return $puller->test();
74
  }
75
  return false;
76
  }
77
-
78
-
79
-
80
-
81
-
82
  /**
83
- *
84
- *
85
  * @param string $header
86
  * @param string $content
87
- * @return Mzax_Emarketing_Model_Inbox_Bounce_Collector
 
88
  */
89
  public function add($header, $content)
90
  {
91
  /* @var $resource Mzax_Emarketing_Model_Resource_Inbox_Email */
92
  $resource = Mage::getResourceModel('mzax_emarketing/inbox_email');
93
  $resource->insertEmail($header, $content);
94
- return true;
 
95
  }
96
-
97
-
98
-
99
-
100
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Inbox_Email_Collector
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Inbox_Email_Collector
24
  {
 
 
 
25
  /**
26
  * Retrieve puller
27
+ *
28
  * @return Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract
29
  */
30
  public function getPuller()
31
  {
32
  return Mage::getModel('mzax_emarketing/inbox_email_pull_storage');
33
  }
34
+
 
 
 
35
  /**
36
  * Collect new messages from inbox
37
+ *
38
  * Returns the number of new messages found
39
+ *
40
  * @return integer
41
  */
42
  public function collect()
43
  {
44
  $puller = $this->getPuller();
45
  $messages = $puller->pull($this);
46
+
47
  return $messages;
48
  }
49
+
 
 
50
  /**
51
  * Test current setup
52
+ *
53
  * @return boolean
54
  */
55
  public function test()
56
  {
57
  $puller = $this->getPuller();
58
+ if ($puller) {
59
  return $puller->test();
60
  }
61
  return false;
62
  }
63
+
 
 
 
 
64
  /**
65
+ * Add email
66
+ *
67
  * @param string $header
68
  * @param string $content
69
+ *
70
+ * @return $this
71
  */
72
  public function add($header, $content)
73
  {
74
  /* @var $resource Mzax_Emarketing_Model_Resource_Inbox_Email */
75
  $resource = Mage::getResourceModel('mzax_emarketing/inbox_email');
76
  $resource->insertEmail($header, $content);
77
+
78
+ return $this;
79
  }
 
 
 
 
80
  }
app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,21 +18,38 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  abstract class Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract extends Varien_Object
30
  {
31
-
32
-
33
- abstract function pull(Mzax_Emarketing_Model_Inbox_Email_Collector $collector);
34
-
35
-
36
- abstract function test();
37
-
38
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract
 
 
 
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract extends Varien_Object
24
  {
25
+ /**
26
+ * @var Mzax_Emarketing_Model_Config
27
+ */
28
+ protected $_config;
29
+
30
+ /**
31
+ * Mzax_Emarketing_Model_Outbox constructor.
32
+ */
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+
37
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
38
+ }
39
+
40
+ /**
41
+ * Pull messages from storage
42
+ *
43
+ * @param Mzax_Emarketing_Model_Inbox_Email_Collector $collector
44
+ *
45
+ * @return int
46
+ */
47
+ abstract public function pull(Mzax_Emarketing_Model_Inbox_Email_Collector $collector);
48
+
49
+ /**
50
+ * Test storage
51
+ *
52
+ * @return bool
53
+ */
54
+ abstract public function test();
55
  }
app/code/community/Mzax/Emarketing/Model/Inbox/Email/Pull/Storage.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,188 +18,155 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
- class Mzax_Emarketing_Model_Inbox_Email_Pull_Storage
30
  extends Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract
31
  {
32
-
33
-
 
34
  protected $_storageAdapter = 'Zend_Mail_Storage_Pop3';
35
-
36
-
37
-
38
-
39
  /**
40
- *
41
  * @var Zend_Mail_Storage_Abstract
42
  */
43
  protected $_storage;
44
-
45
-
46
-
47
  /**
48
  * Retrieve storage config settings
49
- *
50
  * @return array
51
  */
52
  public function getConfig()
53
  {
54
  $config = array();
55
- $config['host'] = Mage::getStoreConfig('mzax_emarketing/inbox/hostname');
56
- $config['user'] = Mage::getStoreConfig('mzax_emarketing/inbox/username');
57
- $config['password'] = Mage::getStoreConfig('mzax_emarketing/inbox/password');
58
- $config['port'] = Mage::getStoreConfig('mzax_emarketing/inbox/port');
59
- $config['ssl'] = Mage::getStoreConfigFlag('mzax_emarketing/inbox/ssl');
60
-
61
  return $config;
62
  }
63
-
64
-
65
-
 
 
 
66
  public function test()
67
  {
68
  try {
69
  $adapter = $this->getStorage();
70
  $adapter->countMessages();
71
  return true;
72
- }
73
- catch(Exception $e) {
74
  return false;
75
  }
76
  }
77
-
78
-
79
-
80
-
81
-
82
  /**
83
  * Set storage adapter class
84
- *
85
  * @param string $adapter
86
- * @return Mzax_Emarketing_Model_Inbox_Bounce_Pull_Storage
 
87
  */
88
  public function setStorageAdapter($adapter)
89
  {
90
- if($this->_storageAdapter !== $adapter) {
91
  $this->_storageAdapter = $adapter;
92
  $this->_storage = null;
93
  }
 
94
  return $this;
95
  }
96
-
97
-
98
-
99
  /**
100
  * Retrieve storage adapter
101
- *
102
- * @throws Exception
103
  * @return Zend_Mail_Storage_Abstract
 
104
  */
105
  public function getStorage()
106
  {
107
- if(!$this->_storage) {
108
-
109
- $adapter = Mage::getStoreConfig('mzax_emarketing/inbox/storage_type');
110
- if(!$adapter) {
111
  $adapter = $this->_storageAdapter;
112
  }
113
-
114
- if(empty($adapter) || !class_exists($adapter)) {
115
  throw new Exception("No such email storage adapter ($adapter)");
116
  }
117
  $this->_storage = new $adapter($this->getConfig());
118
- if(!$this->_storage instanceof Zend_Mail_Storage_Abstract) {
119
  throw new Exception("Storage adapter '$adapter' does not extend from 'Zend_Mail_Storage_Abstract'");
120
  }
121
  }
122
  return $this->_storage;
123
  }
124
-
125
-
126
-
127
  /**
128
  * Maximum size of email for retrieving.
129
- *
130
  * Prevent large emails from crashing the php script
131
- *
132
  * @return number
133
  */
134
  public function getMaxMessageSize()
135
  {
136
- $size = (float) Mage::getStoreConfig('mzax_emarketing/inbox/max_download_size');
137
  $size = max($size, 0.5);
138
-
139
  return min(1024*1024 * $size, 16777000 /* db limit */);
140
  }
141
-
142
-
143
-
144
-
145
-
146
  /**
147
  * Connect to storage and retrieve emails
148
- *
 
 
 
 
149
  */
150
  public function pull(Mzax_Emarketing_Model_Inbox_Email_Collector $collector)
151
  {
152
  $adapter = $this->getStorage();
153
  $maxSize = $this->getMaxMessageSize();
154
-
155
  $messages = 0;
156
-
157
- foreach($adapter->getUniqueId() as $uid) {
158
  try {
159
  $id = $adapter->getNumberByUniqueId($uid);
160
-
161
  $size = $adapter->getSize($id);
162
  $header = $adapter->getRawHeader($id);
163
-
164
- if($size > $maxSize) {
165
- Mage::helper('mzax_emarketing')
166
- ->log("Email content size (%s) exceeded the maximum content size of %s.", $size, $maxSize);
167
- }
168
- else {
 
 
 
169
  $content = $adapter->getRawContent($id);
170
  }
171
-
172
  $messages++;
173
  $collector->add($header, $content);
174
  $adapter->removeMessage($adapter->getNumberByUniqueId($uid));
175
- }
176
- catch(Exception $e) {
177
- if(Mage::getIsDeveloperMode()) {
178
  throw $e;
179
  }
180
  Mage::logException($e);
181
  }
182
  }
183
-
184
  return $messages;
185
  }
186
-
187
-
188
  }
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Inbox_Email_Pull_Storage
 
 
 
 
 
22
  */
23
+ class Mzax_Emarketing_Model_Inbox_Email_Pull_Storage
24
  extends Mzax_Emarketing_Model_Inbox_Email_Pull_Abstract
25
  {
26
+ /**
27
+ * @var string
28
+ */
29
  protected $_storageAdapter = 'Zend_Mail_Storage_Pop3';
30
+
 
 
 
31
  /**
32
+ *
33
  * @var Zend_Mail_Storage_Abstract
34
  */
35
  protected $_storage;
36
+
 
 
37
  /**
38
  * Retrieve storage config settings
39
+ *
40
  * @return array
41
  */
42
  public function getConfig()
43
  {
44
  $config = array();
45
+ $config['host'] = $this->_config->get('mzax_emarketing/inbox/hostname');
46
+ $config['user'] = $this->_config->get('mzax_emarketing/inbox/username');
47
+ $config['password'] = $this->_config->get('mzax_emarketing/inbox/password');
48
+ $config['port'] = $this->_config->get('mzax_emarketing/inbox/port');
49
+ $config['ssl'] = $this->_config->flag('mzax_emarketing/inbox/ssl');
50
+
51
  return $config;
52
  }
53
+
54
+ /**
55
+ * Test connection
56
+ *
57
+ * @return bool
58
+ */
59
  public function test()
60
  {
61
  try {
62
  $adapter = $this->getStorage();
63
  $adapter->countMessages();
64
  return true;
65
+ } catch (Exception $e) {
 
66
  return false;
67
  }
68
  }
69
+
 
 
 
 
70
  /**
71
  * Set storage adapter class
72
+ *
73
  * @param string $adapter
74
+ *
75
+ * @return $this
76
  */
77
  public function setStorageAdapter($adapter)
78
  {
79
+ if ($this->_storageAdapter !== $adapter) {
80
  $this->_storageAdapter = $adapter;
81
  $this->_storage = null;
82
  }
83
+
84
  return $this;
85
  }
86
+
 
 
87
  /**
88
  * Retrieve storage adapter
89
+ *
 
90
  * @return Zend_Mail_Storage_Abstract
91
+ * @throws Exception
92
  */
93
  public function getStorage()
94
  {
95
+ if (!$this->_storage) {
96
+ $adapter = $this->_config->get('mzax_emarketing/inbox/storage_type');
97
+ if (!$adapter) {
 
98
  $adapter = $this->_storageAdapter;
99
  }
100
+
101
+ if (empty($adapter) || !class_exists($adapter)) {
102
  throw new Exception("No such email storage adapter ($adapter)");
103
  }
104
  $this->_storage = new $adapter($this->getConfig());
105
+ if (!$this->_storage instanceof Zend_Mail_Storage_Abstract) {
106
  throw new Exception("Storage adapter '$adapter' does not extend from 'Zend_Mail_Storage_Abstract'");
107
  }
108
  }
109
  return $this->_storage;
110
  }
111
+
 
 
112
  /**
113
  * Maximum size of email for retrieving.
114
+ *
115
  * Prevent large emails from crashing the php script
116
+ *
117
  * @return number
118
  */
119
  public function getMaxMessageSize()
120
  {
121
+ $size = (float)$this->_config->get('mzax_emarketing/inbox/max_download_size');
122
  $size = max($size, 0.5);
123
+
124
  return min(1024*1024 * $size, 16777000 /* db limit */);
125
  }
126
+
 
 
 
 
127
  /**
128
  * Connect to storage and retrieve emails
129
+ *
130
+ * @param Mzax_Emarketing_Model_Inbox_Email_Collector $collector
131
+ *
132
+ * @return int
133
+ * @throws Exception
134
  */
135
  public function pull(Mzax_Emarketing_Model_Inbox_Email_Collector $collector)
136
  {
137
  $adapter = $this->getStorage();
138
  $maxSize = $this->getMaxMessageSize();
 
139
  $messages = 0;
140
+
141
+ foreach ($adapter->getUniqueId() as $uid) {
142
  try {
143
  $id = $adapter->getNumberByUniqueId($uid);
144
+
145
  $size = $adapter->getSize($id);
146
  $header = $adapter->getRawHeader($id);
147
+
148
+ if ($size > $maxSize) {
149
+ $content = sprintf(
150
+ "Email content size (%s) exceeded the maximum content size of %s.",
151
+ $size,
152
+ $maxSize
153
+ );
154
+ Mage::helper('mzax_emarketing')->log($content);
155
+ } else {
156
  $content = $adapter->getRawContent($id);
157
  }
158
+
159
  $messages++;
160
  $collector->add($header, $content);
161
  $adapter->removeMessage($adapter->getNumberByUniqueId($uid));
162
+ } catch (Exception $e) {
163
+ if (Mage::getIsDeveloperMode()) {
 
164
  throw $e;
165
  }
166
  Mage::logException($e);
167
  }
168
  }
169
+
170
  return $messages;
171
  }
 
 
172
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Mzax/Emarketing/Model/Link.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,32 +17,25 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
- *
25
- * @method Mzax_Emarketing_Model_Link setLinkGroupId(string)
26
- * @method Mzax_Emarketing_Model_Link setLinkHash(string)
27
- * @method Mzax_Emarketing_Model_Link setUrl(string)
28
- * @method Mzax_Emarketing_Model_Link setAnchor(string)
29
- * @method Mzax_Emarketing_Model_Link setOptout(boolean)
30
- *
 
31
  * @method string getLinkGroupId()
32
  * @method string getLinkHash()
33
  * @method string getUrl()
34
  * @method string getAnchor()
35
  * @method string getOptout()
36
- *
37
- *
38
- * @method Mzax_Emarketing_Model_Resource_Link getResource()
39
- *
40
- * @author Jacob Siefer
41
  *
 
42
  */
43
- class Mzax_Emarketing_Model_Link extends Mage_Core_Model_Abstract
44
  {
45
-
46
-
47
  /**
48
  * Prefix of model events names
49
  *
@@ -59,51 +51,51 @@ class Mzax_Emarketing_Model_Link extends Mage_Core_Model_Abstract
59
  * @var string
60
  */
61
  protected $_eventObject = 'link';
62
-
63
-
64
-
65
-
 
 
66
  protected function _construct()
67
  {
68
  $this->_init('mzax_emarketing/link');
69
  }
70
-
71
-
72
-
73
-
74
-
75
  /**
76
  * Try loading url model by url
77
- *
78
  * @param string $url
79
  * @param string $anchor
80
- * @return Mzax_Emarketing_Model_Url
 
81
  */
82
  public function loadByUrl($url, $anchor)
83
  {
84
  $this->getResource()->loadByUrl($this, $url, $anchor);
 
85
  return $this;
86
  }
87
-
88
-
89
  /**
90
  * Load or initialize new link instance
91
- *
92
  * @param string $url
93
  * @param string $anchor
 
 
94
  */
95
  public function init($url, $anchor)
96
  {
97
  $this->loadByUrl($url, $anchor);
98
-
99
- if(!$this->getId()) {
100
- if(preg_match('!unsubscribe!i', $url.$anchor)) {
101
  $this->setOptout(true);
102
  }
103
  $this->save();
104
  }
 
105
  return $this;
106
  }
107
-
108
-
109
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Link
22
+ *
23
+ * @method $this setLinkGroupId(string $value)
24
+ * @method $this setLinkHash(string $value)
25
+ * @method $this setUrl(string $value)
26
+ * @method $this setAnchor(string $value)
27
+ * @method $this setOptout(bool $value)
28
+ *
29
  * @method string getLinkGroupId()
30
  * @method string getLinkHash()
31
  * @method string getUrl()
32
  * @method string getAnchor()
33
  * @method string getOptout()
 
 
 
 
 
34
  *
35
+ * @method Mzax_Emarketing_Model_Resource_Link getResource()
36
  */
37
+ class Mzax_Emarketing_Model_Link extends Mage_Core_Model_Abstract
38
  {
 
 
39
  /**
40
  * Prefix of model events names
41
  *
51
  * @var string
52
  */
53
  protected $_eventObject = 'link';
54
+
55
+ /**
56
+ * Model Constructor
57
+ *
58
+ * @return void
59
+ */
60
  protected function _construct()
61
  {
62
  $this->_init('mzax_emarketing/link');
63
  }
64
+
 
 
 
 
65
  /**
66
  * Try loading url model by url
67
+ *
68
  * @param string $url
69
  * @param string $anchor
70
+ *
71
+ * @return $this
72
  */
73
  public function loadByUrl($url, $anchor)
74
  {
75
  $this->getResource()->loadByUrl($this, $url, $anchor);
76
+
77
  return $this;
78
  }
79
+
 
80
  /**
81
  * Load or initialize new link instance
82
+ *
83
  * @param string $url
84
  * @param string $anchor
85
+ *
86
+ * @return $this
87
  */
88
  public function init($url, $anchor)
89
  {
90
  $this->loadByUrl($url, $anchor);
91
+
92
+ if (!$this->getId()) {
93
+ if (preg_match('!unsubscribe!i', $url.$anchor)) {
94
  $this->setOptout(true);
95
  }
96
  $this->save();
97
  }
98
+
99
  return $this;
100
  }
 
 
101
  }
app/code/community/Mzax/Emarketing/Model/Link/Reference.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,23 +17,25 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- *
24
- *
25
- * @method Mzax_Emarketing_Model_Resource_Link_Reference getResource()
26
  * @method string getLinkId()
 
 
27
  * @method string getRecipientId()
 
 
28
  * @method string getPublicId()
29
- *
30
- * @author Jacob Siefer
31
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
- * @version 0.4.10
33
  */
34
- class Mzax_Emarketing_Model_Link_Reference extends Mage_Core_Model_Abstract
35
  {
36
-
37
-
38
  /**
39
  * Prefix of model events names
40
  *
@@ -42,7 +43,6 @@ class Mzax_Emarketing_Model_Link_Reference extends Mage_Core_Model_Abstract
42
  */
43
  protected $_eventPrefix = 'mzax_emarketing_link_reference';
44
 
45
-
46
  /**
47
  * Parameter name in event
48
  *
@@ -51,372 +51,367 @@ class Mzax_Emarketing_Model_Link_Reference extends Mage_Core_Model_Abstract
51
  * @var string
52
  */
53
  protected $_eventObject = 'reference';
54
-
55
-
56
  /**
57
  * url model
58
- *
59
  * @var Mzax_Emarketing_Model_Link
60
  */
61
  protected $_link;
62
-
63
-
64
  /**
65
  * recipient model
66
- *
67
  * @var Mzax_Emarketing_Model_Recipient
68
  */
69
  protected $_recipient;
70
-
71
-
72
-
73
-
74
-
 
 
 
 
 
 
 
 
75
  protected function _construct()
76
  {
77
  $this->_init('mzax_emarketing/link_reference');
 
 
78
  }
79
-
80
-
81
-
82
-
83
  /**
84
  * Load public id or create new if non available
85
- *
86
  * @return Mzax_Emarketing_Model_Link_Reference
87
  */
88
  public function loadPublicId()
89
  {
90
- if(!$this->getPublicId() && $this->getLinkId() && $this->getRecipientId()) {
91
  $this->_getResource()->loadPublicId($this, $this->getLinkId(), $this->getRecipientId());
92
  }
93
- if(!$this->getPublicId()) {
94
- $this->setPublicId( $this->makePublicKey($this->getLink()));
95
  }
96
  return $this;
97
  }
98
-
99
-
100
  /**
101
  * Make random public key
102
- *
103
- * @param string $link
 
104
  * @return string
105
  */
106
- public function makePublicKey($link)
107
  {
108
- $hash = md5($link->getId() .
109
- $link->getLinkHash() .
110
- mt_rand(0, 99999999) .
111
- microtime());
112
-
113
- return Mage::helper('mzax_emarketing')->compressHash($hash);
 
114
  }
115
-
116
-
117
-
 
 
 
 
118
  protected function _beforeSave()
119
  {
120
  // make sure the link is saved
121
- if( $this->_link && !$this->_link->getId()) {
122
  $this->_link->save();
123
  }
124
- if($this->_link) {
125
  $this->setLinkId($this->_link->getId());
126
  }
127
- if($this->_recipient) {
128
  $this->setRecipientId($this->_recipient->getId());
129
  }
130
-
131
- if(!$this->getLinkId()) {
132
  throw new Exception("Unable to save link reference, no link id set");
133
  }
134
-
135
  $this->loadPublicId();
136
-
137
  parent::_beforeSave();
138
  }
139
-
140
-
141
-
142
-
143
-
144
-
145
  /**
146
  * Retrieve link model
147
- *
148
  * @return Mzax_Emarketing_Model_Link
149
  */
150
  public function getLink()
151
  {
152
- if(!$this->_link) {
153
  $this->_link = Mage::getModel('mzax_emarketing/link');
154
  $this->_link->load($this->getLinkId());
155
  }
 
156
  return $this->_link;
157
  }
158
-
159
-
160
-
161
  /**
162
- *
163
- * @param Mzax_Emarketing_Model_Link|string $url
 
164
  * @param string $anchor
165
- * @throws BadMethodCallException
166
  * @return Mzax_Emarketing_Model_Link_Reference
 
167
  */
168
  public function setLink($link, $anchor)
169
  {
170
- if(is_string($link)) {
171
- $this->_link = Mage::getModel('mzax_emarketing/link')->init($link, $anchor);
172
- }
173
- else if($link instanceof Mzax_Emarketing_Model_Link) {
174
  $this->_link = $link;
175
- }
176
- else {
177
  throw new BadMethodCallException("Invalid link argument");
178
  }
179
-
180
  $this->setLinkId($this->_link->getId());
181
  $this->loadPublicId();
182
-
183
  return $this;
184
  }
185
-
186
-
187
-
188
  /**
189
  * Retrieve recipient
190
- *
191
  * @return Mzax_Emarketing_Model_Recipient
192
  */
193
  public function getRecipient()
194
  {
195
- if(!$this->_recipient) {
196
  $this->_recipient = Mage::getModel('mzax_emarketing/recipient');
197
  $this->_recipient->load($this->getRecipientId());
198
  }
199
  return $this->_recipient;
200
  }
201
-
202
-
203
-
204
  /**
205
  * Set recipient model
206
- *
207
  * @param Mzax_Emarketing_Model_Recipient $recipient
208
- * @return Mzax_Emarketing_Model_Link
209
  */
210
  public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
211
  {
212
  $this->_recipient = $recipient;
213
  $this->setRecipientId($recipient->getId());
214
-
215
  return $this;
216
  }
217
-
218
-
219
-
220
-
221
  /**
222
  * Retrieve campaign
223
- *
224
  * @return Mzax_Emarketing_Model_Campaign
 
225
  */
226
  public function getCampagin()
 
 
 
 
 
 
 
 
 
 
227
  {
228
  return $this->getRecipient()->getCampaign();
229
  }
230
-
231
-
232
-
233
-
234
  /**
235
  * Retrieve redirect URL used in emails
236
- *
237
  * @param array $params
 
238
  * @return string
239
  */
240
  public function getRedirectUrl($params = array())
241
  {
242
- $store = $this->getCampagin()->getStore();
243
-
244
  $url = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . "link-goto/".$this->getPublicId();
245
-
246
- if(!empty($params)) {
247
  $url .= '?' . http_build_query($params);
248
  }
 
249
  return $url;
250
  }
251
-
252
-
253
-
254
-
255
  /**
256
- * Retreive target url
257
- *
258
  * @return string
259
  */
260
  public function getTargetUrl()
261
  {
262
- $storeId = $this->getCampagin()->getStoreId();
263
-
264
  $url = $this->getLink()->getUrl();
265
-
266
- if(Mage::getStoreConfigFlag('mzax_emarketing/google_analytics/enable', $storeId)) {
267
-
 
268
  $utmParams = array();
269
  $utmParams['utm_source'] = $this->getUtmSource();
270
  $utmParams['utm_medium'] = $this->getUtmMedium();
271
  $utmParams['utm_campaign'] = $this->getUtmCampaign();
272
-
273
- if($content = $this->getUtmContent()) {
274
  $utmParams['utm_content'] = $content;
275
  }
276
- if($term = $this->getUtmTerm()) {
277
  $utmParams['utm_term'] = $term;
278
  }
279
-
280
  $url .= (strpos($url, '?') ? '&' : '?') . http_build_query($utmParams);
281
  }
282
-
283
  return $url;
284
  }
285
-
286
-
287
-
288
  /**
289
- * Source is globaly set
290
- *
291
  * @return string
292
  */
293
  public function getUtmSource()
294
  {
295
- return Mage::getStoreConfig(
296
- 'mzax_emarketing/google_analytics/utm_source',
297
- $this->getCampagin()->getStoreId());
 
298
  }
299
-
300
-
301
  /**
302
- * Medium is globaly set
303
- *
304
  * @todo should be defined by campaign medium?
305
  * @return string
306
  */
307
  public function getUtmMedium()
308
  {
309
- return Mage::getStoreConfig(
310
- 'mzax_emarketing/google_analytics/utm_medium',
311
- $this->getCampagin()->getStoreId());
 
312
  }
313
-
314
-
315
-
316
  /**
317
  * Retrieve the utm term
318
  * Use variation name
319
- *
320
  * @return string
321
  */
322
  public function getUtmContent()
323
  {
324
  $variationId = $this->getRecipient()->getVariationId();
325
-
326
- switch($variationId) {
327
  case Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL:
328
  return '[Original]';
329
  case Mzax_Emarketing_Model_Campaign_Variation::NONE:
330
  return '[None]';
331
  }
332
-
333
- $variation = $this->getCampagin()->getVariation($variationId);
334
- if($variation) {
335
  return $variation->getName();
336
  }
337
-
338
  return '[N/A]';
339
  }
340
-
341
 
342
-
343
  /**
344
  * Use a stripped version of the link anchor text as term
345
- *
346
  * @return string
347
  */
348
  public function getUtmTerm()
349
  {
350
  $anchor = trim($this->getLink()->getAnchor());
351
-
352
- if($this->getLink()->getUrl() === $anchor) {
353
  return "DIRECT LINK";
354
  }
355
-
356
  // check for any image tag <img src="foo" alt="bar" />
357
- $anchor = preg_replace_callback('/<img\s+(.*)\s*\/?>/i', function($matches) {
358
-
359
  // if an alt tag is given, use it
360
- if(preg_match('/alt=("|\')(.*?)(?:\1)/i',$matches[1], $m)) {
361
  return "IMG[{$m[2]}]";
362
  }
363
-
364
  // otherwise use the image src but only the basename to keep it short
365
- if(preg_match('/src=("|\')(.*?)(?:\1)/i',$matches[1], $m)) {
366
  $src = basename($m[2]);
367
  return "IMG[{$src}]";
368
  }
369
-
370
  return 'IMG';
371
-
372
  }, $anchor);
373
-
374
  return strip_tags($anchor);
375
  }
376
-
377
-
378
-
379
-
380
-
381
  /**
382
  * Use the campaign name
383
- *
384
  * @todo Add extra field for GA name
385
  * @return string
386
  */
387
  public function getUtmCampaign()
388
  {
389
- $name = $this->getCampagin()->getName();
 
390
  return $name;
391
  }
392
-
393
-
394
-
395
-
396
-
397
  /**
398
  * Log click for this link so we know that someone clicked
399
  * on a link inside an email
400
- *
401
  * @param Zend_Controller_Request_Http $request
402
- * @param mixed $clickId
403
- * @param mixed $eventId
 
404
  * @return Mzax_Emarketing_Model_Link_Reference
405
  */
406
  public function captureClick(Zend_Controller_Request_Http $request = null, &$clickId = null, &$eventId = null)
407
  {
408
- $eventId = $this->getRecipient()->captureClick($this->getRequest());
409
  $clickId = $this->getResource()->captureClick($this, $eventId);
 
410
  return $this;
411
  }
412
-
413
-
414
 
 
 
 
 
 
415
  public function __toString()
416
  {
417
  return $this->getRedirectUrl();
418
  }
419
-
420
-
421
-
422
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Link_Reference
22
+ *
 
23
  * @method string getLinkId()
24
+ * @method $this setLinkId(string $value)
25
+ *
26
  * @method string getRecipientId()
27
+ * @method $this setRecipientId(string $value)
28
+ *
29
  * @method string getPublicId()
30
+ * @method $this setPublicId(string $value)
31
+ *
32
+ * @method Mzax_Emarketing_Model_Resource_Link_Reference getResource()
33
+ * @method Mzax_Emarketing_Model_Resource_Link_Reference _getResource()
34
  */
35
+ class Mzax_Emarketing_Model_Link_Reference extends Mzax_Emarketing_Model_AbstractModel
36
  {
37
+ const CONFIG_ENABLE_GA = 'mzax_emarketing/google_analytics/enable';
38
+
39
  /**
40
  * Prefix of model events names
41
  *
43
  */
44
  protected $_eventPrefix = 'mzax_emarketing_link_reference';
45
 
 
46
  /**
47
  * Parameter name in event
48
  *
51
  * @var string
52
  */
53
  protected $_eventObject = 'reference';
54
+
 
55
  /**
56
  * url model
57
+ *
58
  * @var Mzax_Emarketing_Model_Link
59
  */
60
  protected $_link;
61
+
 
62
  /**
63
  * recipient model
64
+ *
65
  * @var Mzax_Emarketing_Model_Recipient
66
  */
67
  protected $_recipient;
68
+
69
+ /**
70
+ * Dependencies
71
+ *
72
+ * @var Mzax_Emarketing_Model_Config
73
+ */
74
+ protected $_config;
75
+
76
+ /**
77
+ * Model Constructor
78
+ *
79
+ * @return void
80
+ */
81
  protected function _construct()
82
  {
83
  $this->_init('mzax_emarketing/link_reference');
84
+
85
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
86
  }
87
+
 
 
 
88
  /**
89
  * Load public id or create new if non available
90
+ *
91
  * @return Mzax_Emarketing_Model_Link_Reference
92
  */
93
  public function loadPublicId()
94
  {
95
+ if (!$this->getPublicId() && $this->getLinkId() && $this->getRecipientId()) {
96
  $this->_getResource()->loadPublicId($this, $this->getLinkId(), $this->getRecipientId());
97
  }
98
+ if (!$this->getPublicId()) {
99
+ $this->setPublicId($this->makePublicKey($this->getLink()));
100
  }
101
  return $this;
102
  }
103
+
 
104
  /**
105
  * Make random public key
106
+ *
107
+ * @param Mzax_Emarketing_Model_Link $link
108
+ *
109
  * @return string
110
  */
111
+ public function makePublicKey(Mzax_Emarketing_Model_Link $link)
112
  {
113
+ /** @var Mzax_Emarketing_Helper_Data $helper */
114
+ $helper = Mage::helper('mzax_emarketing');
115
+
116
+ return $helper->randomHash(
117
+ $link->getId() .
118
+ $link->getLinkHash()
119
+ );
120
  }
121
+
122
+ /**
123
+ * Before save
124
+ *
125
+ * @return void
126
+ * @throws Exception
127
+ */
128
  protected function _beforeSave()
129
  {
130
  // make sure the link is saved
131
+ if ($this->_link && !$this->_link->getId()) {
132
  $this->_link->save();
133
  }
134
+ if ($this->_link) {
135
  $this->setLinkId($this->_link->getId());
136
  }
137
+ if ($this->_recipient) {
138
  $this->setRecipientId($this->_recipient->getId());
139
  }
140
+
141
+ if (!$this->getLinkId()) {
142
  throw new Exception("Unable to save link reference, no link id set");
143
  }
144
+
145
  $this->loadPublicId();
146
+
147
  parent::_beforeSave();
148
  }
149
+
 
 
 
 
 
150
  /**
151
  * Retrieve link model
152
+ *
153
  * @return Mzax_Emarketing_Model_Link
154
  */
155
  public function getLink()
156
  {
157
+ if (!$this->_link) {
158
  $this->_link = Mage::getModel('mzax_emarketing/link');
159
  $this->_link->load($this->getLinkId());
160
  }
161
+
162
  return $this->_link;
163
  }
164
+
 
 
165
  /**
166
+ * Set link
167
+ *
168
+ * @param Mzax_Emarketing_Model_Link|string $link
169
  * @param string $anchor
170
+ *
171
  * @return Mzax_Emarketing_Model_Link_Reference
172
+ * @throws BadMethodCallException
173
  */
174
  public function setLink($link, $anchor)
175
  {
176
+ if (is_string($link)) {
177
+ $this->_link = Mage::getModel('mzax_emarketing/link');
178
+ $this->_link->init($link, $anchor);
179
+ } elseif ($link instanceof Mzax_Emarketing_Model_Link) {
180
  $this->_link = $link;
181
+ } else {
 
182
  throw new BadMethodCallException("Invalid link argument");
183
  }
184
+
185
  $this->setLinkId($this->_link->getId());
186
  $this->loadPublicId();
187
+
188
  return $this;
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
  * Set recipient model
207
+ *
208
  * @param Mzax_Emarketing_Model_Recipient $recipient
209
+ * @return $this
210
  */
211
  public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
212
  {
213
  $this->_recipient = $recipient;
214
  $this->setRecipientId($recipient->getId());
215
+
216
  return $this;
217
  }
218
+
 
 
 
219
  /**
220
  * Retrieve campaign
221
+ *
222
  * @return Mzax_Emarketing_Model_Campaign
223
+ * @deprecated Typo in name
224
  */
225
  public function getCampagin()
226
+ {
227
+ return $this->getCampaign();
228
+ }
229
+
230
+ /**
231
+ * Retrieve campaign
232
+ *
233
+ * @return Mzax_Emarketing_Model_Campaign
234
+ */
235
+ public function getCampaign()
236
  {
237
  return $this->getRecipient()->getCampaign();
238
  }
239
+
 
 
 
240
  /**
241
  * Retrieve redirect URL used in emails
242
+ *
243
  * @param array $params
244
+ *
245
  * @return string
246
  */
247
  public function getRedirectUrl($params = array())
248
  {
249
+ $store = $this->getCampaign()->getStore();
 
250
  $url = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . "link-goto/".$this->getPublicId();
251
+
252
+ if (!empty($params)) {
253
  $url .= '?' . http_build_query($params);
254
  }
255
+
256
  return $url;
257
  }
258
+
 
 
 
259
  /**
260
+ * Retrieve target url
261
+ *
262
  * @return string
263
  */
264
  public function getTargetUrl()
265
  {
266
+ $storeId = $this->getCampaign()->getStoreId();
267
+
268
  $url = $this->getLink()->getUrl();
269
+
270
+ $gaEnabled = $this->_config->flag(self::CONFIG_ENABLE_GA, $storeId);
271
+
272
+ if ($gaEnabled) {
273
  $utmParams = array();
274
  $utmParams['utm_source'] = $this->getUtmSource();
275
  $utmParams['utm_medium'] = $this->getUtmMedium();
276
  $utmParams['utm_campaign'] = $this->getUtmCampaign();
277
+
278
+ if ($content = $this->getUtmContent()) {
279
  $utmParams['utm_content'] = $content;
280
  }
281
+ if ($term = $this->getUtmTerm()) {
282
  $utmParams['utm_term'] = $term;
283
  }
284
+
285
  $url .= (strpos($url, '?') ? '&' : '?') . http_build_query($utmParams);
286
  }
287
+
288
  return $url;
289
  }
290
+
 
 
291
  /**
292
+ * Source is globally set
293
+ *
294
  * @return string
295
  */
296
  public function getUtmSource()
297
  {
298
+ return $this->_config->flag(
299
+ 'mzax_emarketing/google_analytics/utm_source',
300
+ $this->getCampaign()->getStoreId()
301
+ );
302
  }
303
+
 
304
  /**
305
+ * Medium is globally set
306
+ *
307
  * @todo should be defined by campaign medium?
308
  * @return string
309
  */
310
  public function getUtmMedium()
311
  {
312
+ return$this->_config->get(
313
+ 'mzax_emarketing/google_analytics/utm_medium',
314
+ $this->getCampaign()->getStoreId()
315
+ );
316
  }
317
+
 
 
318
  /**
319
  * Retrieve the utm term
320
  * Use variation name
321
+ *
322
  * @return string
323
  */
324
  public function getUtmContent()
325
  {
326
  $variationId = $this->getRecipient()->getVariationId();
327
+
328
+ switch ($variationId) {
329
  case Mzax_Emarketing_Model_Campaign_Variation::ORIGNAL:
330
  return '[Original]';
331
  case Mzax_Emarketing_Model_Campaign_Variation::NONE:
332
  return '[None]';
333
  }
334
+
335
+ $variation = $this->getCampaign()->getVariation($variationId);
336
+ if ($variation) {
337
  return $variation->getName();
338
  }
339
+
340
  return '[N/A]';
341
  }
 
342
 
 
343
  /**
344
  * Use a stripped version of the link anchor text as term
345
+ *
346
  * @return string
347
  */
348
  public function getUtmTerm()
349
  {
350
  $anchor = trim($this->getLink()->getAnchor());
351
+
352
+ if ($this->getLink()->getUrl() === $anchor) {
353
  return "DIRECT LINK";
354
  }
355
+
356
  // check for any image tag <img src="foo" alt="bar" />
357
+ $anchor = preg_replace_callback('/<img\s+(.*)\s*\/?>/i', function ($matches) {
358
+
359
  // if an alt tag is given, use it
360
+ if (preg_match('/alt=("|\')(.*?)(?:\1)/i', $matches[1], $m)) {
361
  return "IMG[{$m[2]}]";
362
  }
363
+
364
  // otherwise use the image src but only the basename to keep it short
365
+ if (preg_match('/src=("|\')(.*?)(?:\1)/i', $matches[1], $m)) {
366
  $src = basename($m[2]);
367
  return "IMG[{$src}]";
368
  }
369
+
370
  return 'IMG';
371
+
372
  }, $anchor);
373
+
374
  return strip_tags($anchor);
375
  }
376
+
 
 
 
 
377
  /**
378
  * Use the campaign name
379
+ *
380
  * @todo Add extra field for GA name
381
  * @return string
382
  */
383
  public function getUtmCampaign()
384
  {
385
+ $name = $this->getCampaign()->getName();
386
+
387
  return $name;
388
  }
389
+
 
 
 
 
390
  /**
391
  * Log click for this link so we know that someone clicked
392
  * on a link inside an email
393
+ *
394
  * @param Zend_Controller_Request_Http $request
395
+ * @param string $clickId
396
+ * @param string $eventId
397
+ *
398
  * @return Mzax_Emarketing_Model_Link_Reference
399
  */
400
  public function captureClick(Zend_Controller_Request_Http $request = null, &$clickId = null, &$eventId = null)
401
  {
402
+ $eventId = $this->getRecipient()->captureClick($request);
403
  $clickId = $this->getResource()->captureClick($this, $eventId);
404
+
405
  return $this;
406
  }
 
 
407
 
408
+ /**
409
+ * Convert to string
410
+ *
411
+ * @return string
412
+ */
413
  public function __toString()
414
  {
415
  return $this->getRedirectUrl();
416
  }
 
 
 
417
  }
app/code/community/Mzax/Emarketing/Model/Medium.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,64 +17,51 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- * Factory class for meidums
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.4.10
29
  */
30
  class Mzax_Emarketing_Model_Medium implements Mage_Eav_Model_Entity_Attribute_Source_Interface
31
  {
32
-
33
  /**
34
- *
35
  * @var Mage_Core_Model_Config_Element
36
  */
37
  protected $_config;
38
-
39
-
40
-
41
  /**
42
- *
43
- * @var array
44
  */
45
  protected $_mediums;
46
-
47
-
48
-
49
  /**
50
  * Retrieve Medium
51
- *
52
  * @param string $name
53
- * @throws Exception
54
  * @return Mzax_Emarketing_Model_Medium_Abstract
 
55
  */
56
  public function factory($name)
57
  {
58
  $config = $this->getConfig();
59
- if(!isset($config->$name)) {
60
  throw new Exception("No such email provider ({$name}) found");
61
  }
 
62
  $config = $config->$name;
63
-
64
-
65
  $mediumClass = $config->getClassName();
66
-
67
- if(!class_exists($mediumClass)) {
68
- throw new Exception("Meidum config found, but model ($mediumClass) was not found");
69
  }
70
-
71
  /* @var $medium Mzax_Emarketing_Model_Medium_Abstract */
72
  $medium = new $mediumClass;
73
-
74
  return $medium;
75
  }
76
-
77
-
78
-
79
  /**
80
  * Retrieve All options
81
  *
@@ -84,9 +70,8 @@ class Mzax_Emarketing_Model_Medium implements Mage_Eav_Model_Entity_Attribute_So
84
  public function getAllOptions($withEmpty = true, $defaultValues = false)
85
  {
86
  $options = array();
87
-
88
- /* @var medium Mzax_Emarketing_Model_Medium_Abstract */
89
- foreach($this->getMediums() as $medium => $title) {
90
  $options[] = array(
91
  'value' => $medium,
92
  'label' => $title
@@ -95,66 +80,56 @@ class Mzax_Emarketing_Model_Medium implements Mage_Eav_Model_Entity_Attribute_So
95
  if ($withEmpty) {
96
  array_unshift($options, array('label'=>'', 'value'=>''));
97
  }
98
-
99
  return $options;
100
  }
101
-
102
-
103
-
104
-
105
  /**
106
  * Retrieve all mediums
107
- *
108
- * @return array
109
  */
110
  public function getMediums()
111
  {
112
- if(!$this->_mediums) {
113
  $this->_mediums = array();
114
-
115
- foreach($this->getConfig()->children() as $name => $cfg) {
116
  $this->_mediums[$name] = (string) $cfg->title;
117
  }
118
  }
 
119
  return $this->_mediums;
120
  }
121
-
122
-
123
-
124
-
125
-
126
-
127
  /**
128
  * Retrieve Option value text
129
  *
130
  * @param string $value
131
- * @return mixed
 
132
  */
133
  public function getOptionText($value)
134
  {
135
  $options = $this->getMediums();
136
- if(isset($options[$value])) {
137
  return $options[$value];
138
  }
 
139
  return false;
140
  }
141
-
142
-
143
-
144
-
145
  /**
146
  * Retrieve email marketing collection config
147
- *
148
  * @return Mage_Core_Model_Config_Element
149
  */
150
  public function getConfig()
151
  {
152
- if(!$this->_config) {
153
  $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/mediums');
154
  }
 
155
  return $this->_config;
156
  }
157
-
158
-
159
-
160
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Medium
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Medium implements Mage_Eav_Model_Entity_Attribute_Source_Interface
24
  {
 
25
  /**
26
+ *
27
  * @var Mage_Core_Model_Config_Element
28
  */
29
  protected $_config;
30
+
 
 
31
  /**
32
+ *
33
+ * @var Mzax_Emarketing_Model_Medium_Abstract[]
34
  */
35
  protected $_mediums;
36
+
 
 
37
  /**
38
  * Retrieve Medium
39
+ *
40
  * @param string $name
41
+ *
42
  * @return Mzax_Emarketing_Model_Medium_Abstract
43
+ * @throws Exception
44
  */
45
  public function factory($name)
46
  {
47
  $config = $this->getConfig();
48
+ if (!isset($config->$name)) {
49
  throw new Exception("No such email provider ({$name}) found");
50
  }
51
+
52
  $config = $config->$name;
 
 
53
  $mediumClass = $config->getClassName();
54
+
55
+ if (!class_exists($mediumClass)) {
56
+ throw new Exception("Medium config found, but model ($mediumClass) was not found");
57
  }
58
+
59
  /* @var $medium Mzax_Emarketing_Model_Medium_Abstract */
60
  $medium = new $mediumClass;
61
+
62
  return $medium;
63
  }
64
+
 
 
65
  /**
66
  * Retrieve All options
67
  *
70
  public function getAllOptions($withEmpty = true, $defaultValues = false)
71
  {
72
  $options = array();
73
+
74
+ foreach ($this->getMediums() as $medium => $title) {
 
75
  $options[] = array(
76
  'value' => $medium,
77
  'label' => $title
80
  if ($withEmpty) {
81
  array_unshift($options, array('label'=>'', 'value'=>''));
82
  }
83
+
84
  return $options;
85
  }
86
+
 
 
 
87
  /**
88
  * Retrieve all mediums
89
+ *
90
+ * @return Mzax_Emarketing_Model_Medium_Abstract[]
91
  */
92
  public function getMediums()
93
  {
94
+ if (!$this->_mediums) {
95
  $this->_mediums = array();
96
+
97
+ foreach ($this->getConfig()->children() as $name => $cfg) {
98
  $this->_mediums[$name] = (string) $cfg->title;
99
  }
100
  }
101
+
102
  return $this->_mediums;
103
  }
104
+
 
 
 
 
 
105
  /**
106
  * Retrieve Option value text
107
  *
108
  * @param string $value
109
+ *
110
+ * @return string|bool
111
  */
112
  public function getOptionText($value)
113
  {
114
  $options = $this->getMediums();
115
+ if (isset($options[$value])) {
116
  return $options[$value];
117
  }
118
+
119
  return false;
120
  }
121
+
 
 
 
122
  /**
123
  * Retrieve email marketing collection config
124
+ *
125
  * @return Mage_Core_Model_Config_Element
126
  */
127
  public function getConfig()
128
  {
129
+ if (!$this->_config) {
130
  $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/mediums');
131
  }
132
+
133
  return $this->_config;
134
  }
 
 
 
135
  }
app/code/community/Mzax/Emarketing/Model/Medium/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,66 +19,68 @@
20
 
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.4.10
29
  */
30
  abstract class Mzax_Emarketing_Model_Medium_Abstract
31
  {
32
  /**
33
  * Unique Medium ID
34
- *
35
  * @return string
36
  */
37
  abstract public function getMediumId();
38
-
39
-
40
  /**
41
  * Send a single recipient
42
- *
43
  * @param Mzax_Emarketing_Model_Recipient $recipient
44
  */
45
  abstract public function sendRecipient(Mzax_Emarketing_Model_Recipient $recipient);
46
-
47
-
48
-
49
  public function prepareRecipientGrid(Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid)
50
  {
51
  }
52
-
53
-
54
-
55
  public function prepareCampaignTabs(Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs)
56
  {
57
  }
58
-
59
-
60
  public function initSettingsForm(Varien_Data_Form $form, Mzax_Emarketing_Model_Campaign $campaign)
61
  {
62
-
63
  }
64
-
65
 
66
-
 
 
 
 
 
67
  /**
68
- *
69
  * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
70
  */
71
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
72
  {
73
  }
74
-
75
-
76
-
77
-
78
-
79
-
80
  /**
81
  * Send message to all pending recipients
82
- *
83
  * @param Mzax_Emarketing_Model_Campaign $campaign
84
  * @param Varien_Object $options
85
  * @throws Exception
@@ -89,34 +90,33 @@ abstract class Mzax_Emarketing_Model_Medium_Abstract
89
  {
90
  $recipients = $campaign->getPendingRecipients();
91
  $recipients->setPageSize($options->getMaximum());
92
-
93
  $start = time();
94
-
95
  $prepared = 0;
96
  $timeout = (int) $options->getTimeout();
97
-
98
- /* @var $recipient Mzax_Emarketing_Model_Recipient */
99
- foreach($recipients as $recipient) {
100
  try {
101
  $this->sendRecipient($recipient);
102
  $prepared++;
103
  }
104
  catch(Exception $e) {
105
  $recipient->logException($e);
106
- if($options->getBreakOnError()) {
107
  throw $e;
108
  }
109
  Mage::logException($e);
110
  }
111
  $recipient->isPrepared(true);
112
  $recipient->save();
113
-
114
- if($timeout && time()-$start > $timeout) {
115
  break;
116
  }
117
  }
118
  return $prepared;
119
  }
120
-
121
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
 
21
  /**
22
+ *
23
+ *
24
  *
25
  * @author Jacob Siefer
26
+ * @license {{license}}
 
27
  */
28
  abstract class Mzax_Emarketing_Model_Medium_Abstract
29
  {
30
  /**
31
  * Unique Medium ID
32
+ *
33
  * @return string
34
  */
35
  abstract public function getMediumId();
36
+
37
+
38
  /**
39
  * Send a single recipient
40
+ *
41
  * @param Mzax_Emarketing_Model_Recipient $recipient
42
  */
43
  abstract public function sendRecipient(Mzax_Emarketing_Model_Recipient $recipient);
44
+
45
+
46
+
47
  public function prepareRecipientGrid(Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid)
48
  {
49
  }
50
+
51
+
52
+
53
  public function prepareCampaignTabs(Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs)
54
  {
55
  }
56
+
57
+
58
  public function initSettingsForm(Varien_Data_Form $form, Mzax_Emarketing_Model_Campaign $campaign)
59
  {
 
60
  }
 
61
 
62
+ public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
63
+ {
64
+ }
65
+
66
+
67
+
68
  /**
69
+ *
70
  * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
71
  */
72
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
73
  {
74
  }
75
+
76
+
77
+
78
+
79
+
80
+
81
  /**
82
  * Send message to all pending recipients
83
+ *
84
  * @param Mzax_Emarketing_Model_Campaign $campaign
85
  * @param Varien_Object $options
86
  * @throws Exception
90
  {
91
  $recipients = $campaign->getPendingRecipients();
92
  $recipients->setPageSize($options->getMaximum());
93
+
94
  $start = time();
95
+
96
  $prepared = 0;
97
  $timeout = (int) $options->getTimeout();
98
+
99
+ foreach ($recipients as $recipient) {
 
100
  try {
101
  $this->sendRecipient($recipient);
102
  $prepared++;
103
  }
104
  catch(Exception $e) {
105
  $recipient->logException($e);
106
+ if ($options->getBreakOnError()) {
107
  throw $e;
108
  }
109
  Mage::logException($e);
110
  }
111
  $recipient->isPrepared(true);
112
  $recipient->save();
113
+
114
+ if ($timeout && time()-$start > $timeout) {
115
  break;
116
  }
117
  }
118
  return $prepared;
119
  }
120
+
121
+
122
  }
app/code/community/Mzax/Emarketing/Model/Medium/Email.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,100 +16,84 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Abstract
30
  {
31
-
32
-
33
  /**
34
  * Retrieve medium id
35
- *
36
  * @return string
37
  */
38
  public function getMediumId()
39
  {
40
  return 'email';
41
  }
42
-
43
-
44
-
45
-
46
 
47
  /**
 
48
  *
49
  * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
 
50
  * @return void
51
  */
52
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
53
  {
54
  $hlp = Mage::helper('mzax_emarketing');
55
-
56
  $snippets->addVar('urls.unsubscribe', $hlp->__('Unsubscribe link'));
57
  $snippets->addVar('urls.broswer_view', $hlp->__('View in browser link'));
58
  $snippets->addVar('subject', $hlp->__('Email Subject'));
59
  $snippets->addVar('address', $hlp->__('Recipient Address'));
60
  $snippets->addVar('email', $hlp->__('Recipient Email'));
61
-
62
  // requires version 1.6 of sales rule (magento 1.7)
63
- if(version_compare(Mage::getConfig()->getModuleConfig('Mage_SalesRule')->version, '1.6.0') >= 0) {
64
  $snippets->addSnippets(
65
- 'mage.coupon',
66
- '{{coupon rule="${1:1}" length="${2:8}" expire="${3:120}" prefix="${4:ABC-}" }}',
67
- $hlp->__('Coupon Code'),
68
- $hlp->__('Generates a coupon code for the specifed shopping cart price rule.'));
 
69
  }
70
-
71
-
72
  }
73
-
74
-
75
-
76
-
77
-
78
  /**
79
  * Prepare recipient
80
- *
81
  * @param Mzax_Emarketing_Model_Recipient $recipient
82
  */
83
  public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
84
  {
85
- $recipient->setAddress( $recipient->getEmail() );
86
-
87
- $recipient->addUrl('unsubscribe', 'mzax_emarketing/unsubscribe');
88
  $recipient->addUrl('browser_view', 'mzax_emarketing/email');
89
  }
90
-
91
-
92
 
93
  /**
94
- *
95
- *
96
  * @see Mzax_Emarketing_Model_Medium_Abstract::prepareCampaignTabs()
97
  * @param Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs
 
 
98
  */
99
  public function prepareCampaignTabs(Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs)
100
  {
101
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
102
  $campaign = Mage::registry('current_campaign');
103
-
104
-
105
- if($count = $campaign->countInbox()) {
106
  $tabs->addTab('inbox', array(
107
  'label' => $tabs->__('Inbox (%s)', $count),
108
  'class' => 'ajax',
109
  'url' => $tabs->getUrl('*/emarketing_inbox/campaignGrid', array('_current' => true)),
110
  ));
111
  }
112
-
113
- if($count = $campaign->countOutbox()) {
114
  $tabs->addTab('outbox', array(
115
  'label' => $tabs->__('Outbox (%s)', $count),
116
  'class' => 'ajax',
@@ -118,25 +101,21 @@ class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Ab
118
  ));
119
  }
120
  }
121
-
122
-
123
-
124
  /**
125
  * Init settings form
126
- *
127
  * @param Varien_Data_Form $form
128
  * @param Mzax_Emarketing_Model_Campaign $campaign
129
  */
130
  public function initSettingsForm(Varien_Data_Form $form, Mzax_Emarketing_Model_Campaign $campaign)
131
  {
132
  $helper = Mage::helper('mzax_emarketing');
133
-
134
-
135
  $fieldset = $form->addFieldset('email_options', array(
136
  'legend' => $helper->__('Email Specific Options')
137
  ), 'base_fieldset');
138
-
139
-
140
  $fieldset->addField('prerender', 'select', array(
141
  'label' => $helper->__('Pre-Render'),
142
  '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."),
@@ -147,29 +126,24 @@ class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Ab
147
  ),
148
  'value' => 0
149
  ));
150
-
151
-
152
  $fieldset->addField('forward_emails', 'text', array(
153
  'name' => 'medium_data[forward_emails]',
154
  'label' => $helper->__('Forward Email'),
155
  'note' => $helper->__("All non-auto email replies will get forward to this email address.")
156
  ));
157
-
158
  }
159
-
160
-
161
-
162
-
163
  /**
164
  * Prepare Recipient Grid
165
- *
166
  * @param Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid
167
  * @return void
168
  */
169
  public function prepareRecipientGrid(Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid)
170
  {
171
  $campaign = $grid->getCampaign();
172
-
173
  $previewAction = array(
174
  'target' => "campaign_{$campaign->getId()}_{id}",
175
  'url' => array(
@@ -194,11 +168,10 @@ class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Ab
194
  'popup' => true,
195
  'caption' => $grid->__('Send Test Email')
196
  );
197
-
198
- if($campaign->hasVariations())
199
- {
200
  $sendAction['caption'] = $previewAction['caption'] = $grid->__('[Orignal]');
201
-
202
  $previewAction = array(
203
  'caption' => $grid->__('Preview'),
204
  'actions' => array($previewAction)
@@ -207,15 +180,14 @@ class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Ab
207
  'caption' => $grid->__('Send Test Email'),
208
  'actions' => array($sendAction)
209
  );
210
-
211
  /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
212
- foreach($campaign->getVariations() as $variation)
213
- {
214
  $params = array(
215
  'id' => $campaign->getId(),
216
  'variation' => $variation->getId()
217
  );
218
-
219
  $previewAction['actions'][] = array(
220
  'target' => "campaign_{$campaign->getId()}_{$variation->getId()}_{id}",
221
  'url' => array(
@@ -237,84 +209,74 @@ class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Ab
237
  );
238
  }
239
  }
240
-
241
  $grid->addColumn('action', array(
242
  'header' => $grid->__('Action'),
243
- 'index' =>'id',
244
- 'getter' => 'getId',
245
  'renderer' => 'mzax_emarketing/grid_column_renderer_action',
246
- 'type' => 'action',
247
  'sortable' => false,
248
  'filter' => false,
249
  'no_link' => true,
250
  'is_system' => true,
251
- 'width' => '80px',
252
  'actions' => array($previewAction, $sendAction)
253
  ));
254
  }
255
-
256
-
257
-
258
-
259
-
260
-
261
  /**
262
  * Send email to recipient
263
- *
264
  * Note: The email medium is not responsible for sending out the email directly
265
  * it will prepare the recipient and the email and push the email to the Outbox
266
  * model, which then will send out the emails
267
- *
268
  * @param Mzax_Emarketing_Model_Recipient $recipient
269
  * @throws Exception
270
  */
271
  public function sendRecipient(Mzax_Emarketing_Model_Recipient $recipient)
272
  {
273
  $recipient->prepare();
274
-
275
- if(!$recipient->getAddress()) {
276
  throw new Exception("No address set");
277
  }
278
-
279
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
280
  $email = Mage::getModel('mzax_emarketing/outbox_email');
281
  $email->setTo($recipient->getAddress());
282
  $email->setRecipient($recipient);
283
  $email->render();
284
  $email->setExpireAt($recipient->getExpireAt());
285
-
286
- if(!$recipient->isMock()) {
287
  $data = $recipient->getContent()->getMediumData();
288
- $dayFilter = $data->getDayFilter();
289
- $timeFilter = $data->getTimeFilter();
290
-
291
  // apply day filter
292
- if(is_array($dayFilter) && count($dayFilter) && count($dayFilter) < 7) {
293
- $email->setDayFilter(implode(',', $dayFilter));
294
  }
295
-
296
  // apply time filter
297
- if(is_array($timeFilter) && count($timeFilter) && count($timeFilter) < 24) {
298
- $email->setTimeFilter(implode(',', $timeFilter));
299
  }
300
  }
301
-
302
  $email->save();
303
-
304
  // if mock, send out email straight away
305
- if($recipient->isMock() && !$recipient->getSkipSend()) {
306
  $email->send();
307
  }
308
  }
309
-
310
-
311
-
312
-
313
-
314
  /**
315
- * Unsubscibe email from all stores for any given reason
316
- *
317
- *
318
  * @todo Can be done better...
319
  * @param string $email
320
  * @param string $reason Reason for log purpose only
@@ -323,19 +285,23 @@ class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Ab
323
  {
324
  /* @var $helper Mzax_Emarketing_Helper_Newsletter */
325
  $helper = Mage::helper('mzax_emarketing/newsletter');
326
-
327
  /* @var $store Mage_Core_Model_Store */
328
- foreach(Mage::app()->getStores() as $store) {
329
  $subscriber = $helper->unsubscribe($email, $store->getId(), false);
330
- if($subscriber->getIsStatusChanged()) {
331
- Mage::log(sprintf("unsubscribe '%s' from store '%s': %s", $email, $store->getName(), $reason), null, 'mzax_email_unsubscribe.log');
 
 
 
 
 
 
 
 
 
332
  }
333
  }
334
-
335
-
336
  }
337
-
338
-
339
-
340
  }
341
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Medium_Email
 
 
 
 
 
21
  */
22
  class Mzax_Emarketing_Model_Medium_Email extends Mzax_Emarketing_Model_Medium_Abstract
23
  {
 
 
24
  /**
25
  * Retrieve medium id
26
+ *
27
  * @return string
28
  */
29
  public function getMediumId()
30
  {
31
  return 'email';
32
  }
 
 
 
 
33
 
34
  /**
35
+ * Prepare snippets
36
  *
37
  * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
38
+ *
39
  * @return void
40
  */
41
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
42
  {
43
  $hlp = Mage::helper('mzax_emarketing');
44
+
45
  $snippets->addVar('urls.unsubscribe', $hlp->__('Unsubscribe link'));
46
  $snippets->addVar('urls.broswer_view', $hlp->__('View in browser link'));
47
  $snippets->addVar('subject', $hlp->__('Email Subject'));
48
  $snippets->addVar('address', $hlp->__('Recipient Address'));
49
  $snippets->addVar('email', $hlp->__('Recipient Email'));
50
+
51
  // requires version 1.6 of sales rule (magento 1.7)
52
+ if (version_compare(Mage::getConfig()->getModuleConfig('Mage_SalesRule')->version, '1.6.0') >= 0) {
53
  $snippets->addSnippets(
54
+ 'mage.coupon',
55
+ '{{coupon rule="${1:1}" length="${2:8}" expire="${3:120}" prefix="${4:ABC-}" }}',
56
+ $hlp->__('Coupon Code'),
57
+ $hlp->__('Generates a coupon code for the specifed shopping cart price rule.')
58
+ );
59
  }
 
 
60
  }
61
+
 
 
 
 
62
  /**
63
  * Prepare recipient
64
+ *
65
  * @param Mzax_Emarketing_Model_Recipient $recipient
66
  */
67
  public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
68
  {
69
+ $recipient->setAddress($recipient->getEmail());
70
+
71
+ $recipient->addUrl('unsubscribe', 'mzax_emarketing/unsubscribe');
72
  $recipient->addUrl('browser_view', 'mzax_emarketing/email');
73
  }
 
 
74
 
75
  /**
76
+ * Prepare campaign tabs
77
+ *
78
  * @see Mzax_Emarketing_Model_Medium_Abstract::prepareCampaignTabs()
79
  * @param Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs
80
+ *
81
+ * @return void
82
  */
83
  public function prepareCampaignTabs(Mzax_Emarketing_Block_Campaign_Edit_Tabs $tabs)
84
  {
85
  /* @var $campaign Mzax_Emarketing_Model_Campaign */
86
  $campaign = Mage::registry('current_campaign');
87
+
88
+ if ($count = $campaign->countInbox()) {
 
89
  $tabs->addTab('inbox', array(
90
  'label' => $tabs->__('Inbox (%s)', $count),
91
  'class' => 'ajax',
92
  'url' => $tabs->getUrl('*/emarketing_inbox/campaignGrid', array('_current' => true)),
93
  ));
94
  }
95
+
96
+ if ($count = $campaign->countOutbox()) {
97
  $tabs->addTab('outbox', array(
98
  'label' => $tabs->__('Outbox (%s)', $count),
99
  'class' => 'ajax',
101
  ));
102
  }
103
  }
104
+
 
 
105
  /**
106
  * Init settings form
107
+ *
108
  * @param Varien_Data_Form $form
109
  * @param Mzax_Emarketing_Model_Campaign $campaign
110
  */
111
  public function initSettingsForm(Varien_Data_Form $form, Mzax_Emarketing_Model_Campaign $campaign)
112
  {
113
  $helper = Mage::helper('mzax_emarketing');
114
+
 
115
  $fieldset = $form->addFieldset('email_options', array(
116
  'legend' => $helper->__('Email Specific Options')
117
  ), 'base_fieldset');
118
+
 
119
  $fieldset->addField('prerender', 'select', array(
120
  'label' => $helper->__('Pre-Render'),
121
  '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."),
126
  ),
127
  'value' => 0
128
  ));
129
+
 
130
  $fieldset->addField('forward_emails', 'text', array(
131
  'name' => 'medium_data[forward_emails]',
132
  'label' => $helper->__('Forward Email'),
133
  'note' => $helper->__("All non-auto email replies will get forward to this email address.")
134
  ));
 
135
  }
136
+
 
 
 
137
  /**
138
  * Prepare Recipient Grid
139
+ *
140
  * @param Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid
141
  * @return void
142
  */
143
  public function prepareRecipientGrid(Mzax_Emarketing_Block_Campaign_Edit_Tab_Recipients_Grid $grid)
144
  {
145
  $campaign = $grid->getCampaign();
146
+
147
  $previewAction = array(
148
  'target' => "campaign_{$campaign->getId()}_{id}",
149
  'url' => array(
168
  'popup' => true,
169
  'caption' => $grid->__('Send Test Email')
170
  );
171
+
172
+ if ($campaign->hasVariations()) {
 
173
  $sendAction['caption'] = $previewAction['caption'] = $grid->__('[Orignal]');
174
+
175
  $previewAction = array(
176
  'caption' => $grid->__('Preview'),
177
  'actions' => array($previewAction)
180
  'caption' => $grid->__('Send Test Email'),
181
  'actions' => array($sendAction)
182
  );
183
+
184
  /* @var $variation Mzax_Emarketing_Model_Campaign_Variation */
185
+ foreach ($campaign->getVariations() as $variation) {
 
186
  $params = array(
187
  'id' => $campaign->getId(),
188
  'variation' => $variation->getId()
189
  );
190
+
191
  $previewAction['actions'][] = array(
192
  'target' => "campaign_{$campaign->getId()}_{$variation->getId()}_{id}",
193
  'url' => array(
209
  );
210
  }
211
  }
212
+
213
  $grid->addColumn('action', array(
214
  'header' => $grid->__('Action'),
215
+ 'index' => 'id',
216
+ 'getter' => 'getId',
217
  'renderer' => 'mzax_emarketing/grid_column_renderer_action',
218
+ 'type' => 'action',
219
  'sortable' => false,
220
  'filter' => false,
221
  'no_link' => true,
222
  'is_system' => true,
223
+ 'width' => '80px',
224
  'actions' => array($previewAction, $sendAction)
225
  ));
226
  }
227
+
 
 
 
 
 
228
  /**
229
  * Send email to recipient
230
+ *
231
  * Note: The email medium is not responsible for sending out the email directly
232
  * it will prepare the recipient and the email and push the email to the Outbox
233
  * model, which then will send out the emails
234
+ *
235
  * @param Mzax_Emarketing_Model_Recipient $recipient
236
  * @throws Exception
237
  */
238
  public function sendRecipient(Mzax_Emarketing_Model_Recipient $recipient)
239
  {
240
  $recipient->prepare();
241
+
242
+ if (!$recipient->getAddress()) {
243
  throw new Exception("No address set");
244
  }
245
+
246
  /* @var $email Mzax_Emarketing_Model_Outbox_Email */
247
  $email = Mage::getModel('mzax_emarketing/outbox_email');
248
  $email->setTo($recipient->getAddress());
249
  $email->setRecipient($recipient);
250
  $email->render();
251
  $email->setExpireAt($recipient->getExpireAt());
252
+
253
+ if (!$recipient->isMock()) {
254
  $data = $recipient->getContent()->getMediumData();
255
+ $dayFilter = $data->getData('day_filter');
256
+ $timeFilter = $data->getData('time_filter');
257
+
258
  // apply day filter
259
+ if (is_array($dayFilter) && count($dayFilter) && count($dayFilter) < 7) {
260
+ $email->setDayFilter($dayFilter);
261
  }
262
+
263
  // apply time filter
264
+ if (is_array($timeFilter) && count($timeFilter) && count($timeFilter) < 24) {
265
+ $email->setTimeFilter($timeFilter);
266
  }
267
  }
268
+
269
  $email->save();
270
+
271
  // if mock, send out email straight away
272
+ if ($recipient->isMock() && !$recipient->getData('skip_send')) {
273
  $email->send();
274
  }
275
  }
276
+
 
 
 
 
277
  /**
278
+ * Unsubscribe email from all stores for any given reason
279
+ *
 
280
  * @todo Can be done better...
281
  * @param string $email
282
  * @param string $reason Reason for log purpose only
285
  {
286
  /* @var $helper Mzax_Emarketing_Helper_Newsletter */
287
  $helper = Mage::helper('mzax_emarketing/newsletter');
288
+
289
  /* @var $store Mage_Core_Model_Store */
290
+ foreach (Mage::app()->getStores() as $store) {
291
  $subscriber = $helper->unsubscribe($email, $store->getId(), false);
292
+ if ($subscriber->getIsStatusChanged()) {
293
+ Mage::log(
294
+ sprintf(
295
+ "unsubscribe '%s' from store '%s': %s",
296
+ $email,
297
+ $store->getName(),
298
+ $reason
299
+ ),
300
+ null,
301
+ 'mzax_email_unsubscribe.log'
302
+ );
303
  }
304
  }
 
 
305
  }
 
 
 
306
  }
307
 
app/code/community/Mzax/Emarketing/Model/Medium/Email/Composer.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,65 +17,103 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Medium_Email_Composer
30
  extends Mage_Core_Model_Template
31
  implements Mzax_Emarketing_Model_SalesRule_ICouponManager
32
  {
33
-
34
  const PRERENDER_CACHE_PREFIX = 'MZAX_EMARKETING_PRERENDER_CACHE_';
35
-
36
  const BEACON_PLACEHOLDER ='{BEACON}';
37
-
38
  const LINK_A_TAG = "!<a [^>]*href=\"(.*?)\"[^>]*>(.*?)</a>!is";
39
-
40
  const LINK_MAP_TAG = "!<map [^>]*name=\"(.*?)\"[^>]*>.*?</map>!is";
41
-
42
  const LINK_AREA_TAG = "!<area [^>]*href=\"(.*?)\"[^>]*/>!i";
43
-
44
-
45
-
46
  /**
47
- *
48
  * @var Mzax_Emarketing_Model_Recipient
49
  */
50
  protected $_recipient;
51
-
52
-
 
 
53
  protected $_bodyText;
54
-
 
 
 
55
  protected $_bodyHtml;
56
-
 
 
 
57
  protected $_subject;
58
-
59
-
 
 
60
  protected $_linkReferences;
61
-
 
 
 
62
  protected $_coupons = array();
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();
@@ -85,110 +122,116 @@ class Mzax_Emarketing_Model_Medium_Email_Composer
85
  $this->_bodyText = null;
86
  $this->_subject = null;
87
  }
88
-
89
-
90
-
 
 
 
91
  public function getType()
92
  {
93
  return self::TYPE_HTML;
94
  }
95
-
96
-
97
-
98
-
99
  /**
100
  * Retrieve all created link references
101
  *
102
- * @return array
103
  */
104
  public function getLinkReferences()
105
  {
106
  return $this->_linkReferences;
107
  }
108
-
109
  /**
110
- *
111
  * @return Mzax_Emarketing_Model_Recipient
112
  */
113
  public function getRecipient()
114
  {
115
  return $this->_recipient;
116
  }
117
-
118
-
 
 
119
  public function getBodyHtml()
120
  {
121
  return $this->_bodyHtml;
122
  }
123
-
124
-
 
 
125
  public function getBodyText()
126
  {
127
  return $this->_bodyText;
128
  }
129
-
130
-
 
 
131
  public function getSubject()
132
  {
133
  return $this->_subject;
134
  }
135
-
136
-
 
 
137
  public function getRenderTime()
138
  {
139
  return $this->_renderTime;
140
  }
141
-
142
-
 
 
143
  public function allowPrerender()
144
  {
145
  $data = $this->getRecipient()->getContent()->getMediumData();
146
- if(isset($data['prerender']) && $data['prerender']) {
147
  return true;
148
  }
149
  return false;
150
  }
151
-
152
-
153
-
154
  /**
155
  * Add coupon
156
- *
157
- * @see Mzax_Emarketing_Model_SalesRule_ICouponManager
158
  * @param Mage_SalesRule_Model_Coupon $coupon
159
- * @return Mzax_Emarketing_Model_Medium_Email_Composer
 
160
  */
161
  public function addCoupon(Mage_SalesRule_Model_Coupon $coupon)
162
  {
163
  $this->_coupons[] = $coupon;
 
164
  return $this;
165
  }
166
-
167
-
168
  /**
169
- *
170
- * @see Mzax_Emarketing_Model_SalesRule_ICouponManager
171
- * @return array
172
  */
173
  public function getCoupons()
174
  {
175
  return $this->_coupons;
176
  }
177
-
178
-
179
-
180
  /**
181
- *
 
182
  * @return Mzax_Emarketing_Model_Medium_Email_Processor
183
  */
184
  public function getTemplateProcessor()
185
  {
186
  $store = $this->getRecipient()->getStore();
187
-
188
  $recipient = $this->getRecipient();
189
  $recipient->prepare();
190
-
191
-
192
  /* @var $processor Mzax_Emarketing_Model_Medium_Email_Processor */
193
  $processor = Mage::getModel('mzax_emarketing/medium_email_processor');
194
  $processor->setCouponManager($this);
@@ -196,36 +239,38 @@ class Mzax_Emarketing_Model_Medium_Email_Composer
196
  $processor->setStoreId($recipient->getStoreId());
197
  $processor->setContent($this->getContent());
198
  $processor->setVariables($recipient->getData());
199
- $processor->setVariables(array(
200
- 'current_year' => date('Y'),
201
- 'date' => Mage::app()->getLocale()->storeDate($store),
202
- 'store' => $recipient->getCampaign()->getStore(),
203
- 'url' => $recipient->getUrls()
204
- ));
205
-
 
 
206
  return $processor;
207
  }
208
-
209
-
210
-
211
-
212
-
 
213
  public function getContent()
214
  {
215
  $content = $this->getRecipient()->getContent();
216
  $store = $this->getRecipient()->getStore();
217
-
218
- if($this->allowPrerender()) {
219
  $cacheId = self::PRERENDER_CACHE_PREFIX . $content->getContentCacheId();
220
-
221
  $data = Mage::app()->loadCache($cacheId);
222
- if($data) {
223
  $data = unserialize($data);
224
  }
225
- if(!$data) {
226
-
227
  $storeId = $this->getRecipient()->getStoreId();
228
-
229
  /* @var $processor Mzax_Emarketing_Model_Medium_Email_Processor */
230
  $processor = Mage::getModel('mzax_emarketing/medium_email_processor');
231
  $processor->disableVarDirective(true);
@@ -236,238 +281,241 @@ class Mzax_Emarketing_Model_Medium_Email_Composer
236
  'date' => Mage::app()->getLocale()->storeDate($store),
237
  'store' => $this->getRecipient()->getCampaign()->getStore()
238
  ));
239
-
240
  $this->emulateDesign($storeId);
241
  $subject = $processor->getSubject();
242
  $bodyHtml = $processor->getBodyHtml();
243
  $bodyText = $processor->getBodyText();
244
  $this->revertDesign();
245
-
246
- if(Mage::getStoreConfigFlag('mzax_emarketing/email/css_inliner', $storeId)) {
247
  $this->inlineCss($bodyHtml);
248
  }
249
-
250
- if(Mage::getStoreConfigFlag('mzax_emarketing/email/remove_comments', $storeId)) {
251
  $this->removeComments($bodyHtml);
252
  }
253
-
254
  $data = new Varien_Object;
255
- $data->setSubject($subject);
256
- $data->setBodyHtml($bodyHtml);
257
- $data->setBodyText($bodyText);
258
-
259
  Mage::app()->saveCache(serialize($data), $cacheId, array(Mzax_Emarketing_Model_Campaign::CACHE_TAG));
260
  }
261
  /* @var $fullCache Mzax_Emarketing_Model_Medium_Email_FullCache */
262
  $fullCache = Mage::getModel('mzax_emarketing/medium_email_fullCache');
 
263
  $fullCache->setMediumData($data);
264
-
265
  return $fullCache;
266
  }
267
-
268
  return $content;
269
  }
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
  /**
280
  * Compose Email
281
- *
282
- * Parse all mage expresions and prepare html for sending
283
- *
284
  * @throws Exception
285
  * @param boolean $previewMode
286
  * @return Mzax_Emarketing_Model_Medium_Email_Composer
287
  */
288
  public function compose($previewMode = false)
289
  {
290
- if(!$this->_recipient) {
291
  throw new Exception("Can not compose email without a recipient");
292
  }
293
  $this->reset();
294
-
295
  $start = microtime(true);
296
-
297
  $recipient = $this->getRecipient();
298
  $storeId = $recipient->getStoreId();
299
  $processor = $this->getTemplateProcessor();
300
  $processor->isPreview($previewMode);
301
-
302
- if($this->allowPrerender()) {
303
  $this->_subject = $processor->getSubject();
304
  $processor->setVariables(array('subject' => $this->_subject));
305
-
306
  $this->_bodyHtml = $processor->getBodyHtml();
307
  $this->_bodyText = $processor->getBodyText();
308
-
309
  // insert view tacking beacon
310
  $this->insertBeacon($this->_bodyHtml);
311
-
 
312
  // make links trackable
313
  $this->parseLinks($this->_bodyHtml);
314
- }
315
- else {
316
  $this->emulateDesign($recipient->getStoreId());
317
  $this->_subject = $processor->getSubject();
318
  $processor->setVariables(array('subject' => $this->_subject));
319
-
320
  $this->_bodyHtml = $processor->getBodyHtml();
321
  $this->_bodyText = $processor->getBodyText();
322
  $this->revertDesign();
323
-
324
  // insert view tacking beacon
325
  $this->insertBeacon($this->_bodyHtml);
326
-
 
327
  // make links trackable
328
  $this->parseLinks($this->_bodyHtml);
329
-
330
-
331
- if(Mage::getStoreConfigFlag('mzax_emarketing/email/css_inliner', $storeId)) {
332
  $this->inlineCss($this->_bodyHtml);
333
  }
334
- if(Mage::getStoreConfigFlag('mzax_emarketing/email/remove_comments', $storeId)) {
335
  $this->removeComments($this->_bodyHtml);
336
  }
337
  }
338
-
339
  $this->_renderTime = microtime(true) - $start;
340
-
341
  return $this;
342
  }
343
-
344
-
345
-
 
 
 
 
 
346
  protected function inlineCss(&$html)
347
  {
348
- Mage::helper('mzax_emarketing')->encodeMageExpr($html);
349
-
 
 
 
350
  // @todo Maybe use Pelago_Emogrifier (but only available in later versionsof Magento)
351
  $cssInliner = new TijsVerkoyen_CssToInlineStyles_CssToInlineStyles($html);
352
  $cssInliner->setUseInlineStylesBlock(true);
353
  $html = $cssInliner->convert();
354
-
355
- Mage::helper('mzax_emarketing')->decodeMageExpr($html);
356
  }
357
-
358
-
359
- const STYLE_TAGS = '!<style\s+type="text/css">(.+?)</style>!is';
360
-
 
 
 
 
361
  protected function removeComments(&$html)
362
  {
363
  // remove leading & trailing spaces
364
  $html = preg_replace('/^\s+|\s+$/m', "", $html);
365
-
366
  // remove html comments
367
  $html = preg_replace('/<!--(.*)-->/Uis', '', $html);
368
-
369
  // remove empty lines
370
  $html = preg_replace("/([\n\r]+)/", "\n", $html);
371
-
372
  // cleanup css tags
373
  $html = preg_replace_callback(self::STYLE_TAGS, array($this, 'cleanUpCss'), $html);
374
  }
375
-
376
-
377
-
 
 
 
 
 
378
  protected function cleanUpCss($match)
379
  {
380
  $css = $match[1];
381
-
382
  // replace double quotes by single quotes
383
  $css = str_replace('"', '\'', $css);
384
-
385
  // remove comments
386
  $css = preg_replace('/\/\*.*?\*\//s', '', $css);
387
-
388
  // remove leading & trailing spaces
389
  $css = preg_replace('/^\s+|\s+$/m', '', $css);
390
-
391
  // remove lines
392
  $css = preg_replace("/([\n\r]+)/", "", $css);
393
  $css = preg_replace("/}\\s*/", "}\n", $css);
394
-
395
  // allow extra line for @media queries
396
  $css = preg_replace("/^@(.*?){/m", "\n@$1{\n", $css);
397
-
398
-
399
-
400
  return "<style type=\"text/css\">\n$css</style>\n";
401
-
402
  }
403
-
404
-
405
-
406
-
407
-
 
 
 
408
  protected function parseLinks(&$html)
409
  {
410
  // replace all links with trackable links
411
- $html = preg_replace_callback(self::LINK_A_TAG, array($this, '__replaceLinkCallback'), $html);
412
- $html = preg_replace_callback(self::LINK_MAP_TAG, array($this, '__replaceMapCallback'), $html);
413
  }
414
-
415
-
416
  /**
417
  * PregReplace callback for <a> tag links
418
  *
419
- * @param array $matches
 
420
  * @return string
421
  */
422
  public function __replaceLinkCallback($matches)
423
  {
424
  list($linkHtml, $url, $anchor) = $matches;
425
-
426
- if(strpos(strtolower($url), 'mailto:') === 0) {
427
  return $linkHtml;
428
  }
429
-
430
  $link = $this->createLinkReference($url, $anchor);
431
-
432
  $linkHtml = str_replace("href=\"{$url}\"", "href=\"{$link}\"", $linkHtml);
 
433
  return preg_replace("!\s+!", ' ', $linkHtml);
434
  }
435
-
436
-
437
-
438
-
439
-
440
  /**
441
  * Create new link reference
442
  *
443
  * @param string $url
444
  * @param string $anchor
 
445
  * @return Mzax_Emarketing_Model_Link_Reference
446
  */
447
  public function createLinkReference($url, $anchor)
448
  {
449
  // normalize anchor text
450
  $anchor = trim(preg_replace("!\s+!s", ' ', $anchor));
451
-
452
- // unqiue key
453
  $key = md5(strtolower($url.$anchor));
454
-
455
  // if not yet created, create new one
456
- if(!isset($this->_linkReferences[$key])) {
457
  /* @var $reference Mzax_Emarketing_Model_Link_Reference */
458
  $reference = Mage::getModel('mzax_emarketing/link_reference');
459
  $reference->setRecipient($this->_recipient);
460
  $reference->setLink($url, $anchor);
461
-
462
  $this->_linkReferences[$key] = $reference;
463
  }
 
464
  return $this->_linkReferences[$key];
465
-
466
  }
467
-
468
-
469
-
470
-
471
 
472
  /**
473
  * Get url to beacon image
@@ -476,13 +524,11 @@ class Mzax_Emarketing_Model_Medium_Email_Composer
476
  */
477
  public function getBeaconImage()
478
  {
479
- $baseUrl = $this->_recipient->getCampaign()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, false);
 
 
480
  return $baseUrl . "emarketing-media/{$this->_recipient->getBeaconHash()}/logo.gif";
481
  }
482
-
483
-
484
-
485
-
486
 
487
  /**
488
  * Insert tracking beacon
@@ -493,33 +539,26 @@ class Mzax_Emarketing_Model_Medium_Email_Composer
493
  public function insertBeacon(&$html)
494
  {
495
  $beaconHtml = "<img alt=\"{$this->_recipient->getCampaign()->getStore()->getName()}\" src=\"{$this->getBeaconImage()}\" style=\"width:10px; height:5px;\" />";
496
-
497
  // if beacon placeholder exist replace it
498
- if(strpos($html, self::BEACON_PLACEHOLDER) !== false) {
499
  $html = str_replace(self::BEACON_PLACEHOLDER, $beaconHtml, $html);
500
- }
501
- // if not try to append it just before the body tag closes
502
- else if(strpos($html, "</body>") !== false) {
503
  $html = str_replace("</body>", "{$beaconHtml}\n</body>", $html);
504
- }
505
- // if everything fails add it to the end
506
- else {
507
  $html .= $beaconHtml;
508
  }
509
-
510
  return $this;
511
  }
512
-
513
-
514
-
515
-
516
-
517
-
518
  protected $_currentMapName;
519
-
520
-
521
-
522
-
523
  /**
524
  * PregReplace callback for <map> tag links
525
  *
@@ -529,62 +568,60 @@ class Mzax_Emarketing_Model_Medium_Email_Composer
529
  public function __replaceMapCallback($matches)
530
  {
531
  list($mapHtml, $name) = $matches;
532
-
533
  $this->_currentMapName = array($name, $this->_getTagByUsemap($name));
534
  $mapHtml = preg_replace_callback(self::LINK_AREA_TAG, array($this, '__replaceMapLinkCallback'), $mapHtml);
535
  $this->_currentMapName = null;
536
-
537
  return $mapHtml;
538
  }
539
-
540
-
541
-
542
-
543
  /**
544
- * Retrieve orginal tag that binds to the given usemap
545
  *
546
- * Helpfull to retrieve the image that was used for a <area> tag
547
  *
548
  * @param string $usemap
 
549
  * @return string
550
  */
551
  public function _getTagByUsemap($usemap)
552
  {
553
- if(preg_match("!<[^>]*usemap=\"#{$usemap}\"[^>]*>!is", $this->_bodyHtml, $matches)) {
554
  return $matches[0];
555
  }
 
556
  return '';
557
  }
558
-
559
-
560
-
561
-
562
-
 
563
  public function __replaceMapLinkCallback($matches)
564
  {
565
  list($area, $url) = $matches;
566
-
567
- if(strpos(strtolower($url), 'mailto:') === 0) {
568
  return $url;
569
  }
570
-
571
  $label = array($this->_currentMapName[1]);
572
-
573
- if($shape = $this->_extractAttribute($area, 'shape')) {
574
  $label[] = $shape;
575
  }
576
- if($coords = $this->_extractAttribute($area, 'coords')) {
577
  $label[] = $coords;
578
  }
579
-
580
  /* @var $link Mzax_Emarketing_Model_Link */
581
  $link = $this->createLinkReference($url, implode(':', $label));
582
-
583
  return str_replace("href=\"{$url}\"", "href=\"{$link}\"", $area);
584
  }
585
-
586
-
587
-
588
  /**
589
  * Extract attribute from a html tag
590
  *
@@ -597,13 +634,10 @@ class Mzax_Emarketing_Model_Medium_Email_Composer
597
  */
598
  protected function _extractAttribute($htmlTag, $attribute)
599
  {
600
- if(preg_match("!{$attribute}=\"(.*?)\"!i", $htmlTag, $match)) {
601
  return $match[1];
602
  }
 
603
  return null;
604
  }
605
-
606
-
607
-
608
-
609
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Medium_Email_Composer
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Medium_Email_Composer
24
  extends Mage_Core_Model_Template
25
  implements Mzax_Emarketing_Model_SalesRule_ICouponManager
26
  {
 
27
  const PRERENDER_CACHE_PREFIX = 'MZAX_EMARKETING_PRERENDER_CACHE_';
28
+
29
  const BEACON_PLACEHOLDER ='{BEACON}';
30
+
31
  const LINK_A_TAG = "!<a [^>]*href=\"(.*?)\"[^>]*>(.*?)</a>!is";
32
+
33
  const LINK_MAP_TAG = "!<map [^>]*name=\"(.*?)\"[^>]*>.*?</map>!is";
34
+
35
  const LINK_AREA_TAG = "!<area [^>]*href=\"(.*?)\"[^>]*/>!i";
36
+
37
+ const STYLE_TAGS = '!<style\s+type="text/css">(.+?)</style>!is';
38
+
39
  /**
40
+ *
41
  * @var Mzax_Emarketing_Model_Recipient
42
  */
43
  protected $_recipient;
44
+
45
+ /**
46
+ * @var string
47
+ */
48
  protected $_bodyText;
49
+
50
+ /**
51
+ * @var string
52
+ */
53
  protected $_bodyHtml;
54
+
55
+ /**
56
+ * @var string
57
+ */
58
  protected $_subject;
59
+
60
+ /**
61
+ * @var Mzax_Emarketing_Model_Link_Reference[]
62
+ */
63
  protected $_linkReferences;
64
+
65
+ /**
66
+ * @var Mage_SalesRule_Model_Coupon[]
67
+ */
68
  protected $_coupons = array();
69
+
70
+ /**
71
+ * Render and cache
72
+ *
73
+ * @var bool
74
+ */
75
  protected $_prerender = true;
76
+
77
+ /**
78
+ * @var int
79
+ */
80
  protected $_renderTime;
81
+
82
+ /**
83
+ * @var Mzax_Emarketing_Model_Config
84
+ */
85
+ protected $_config;
86
+
87
+ /**
88
+ * Load dependencies
89
+ *
90
+ * @return void
91
+ */
92
+ protected function _construct()
93
+ {
94
+ parent::_construct();
95
+
96
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
97
+ }
98
+
99
+ /**
100
+ * Set recipient
101
+ *
102
+ * @param Mzax_Emarketing_Model_Recipient $recipient
103
+ *
104
+ * @return $this
105
+ */
106
  public function setRecipient(Mzax_Emarketing_Model_Recipient $recipient)
107
  {
108
  $this->_recipient = $recipient;
109
  $this->reset();
110
+
111
  return $this;
112
  }
113
+
114
+ /**
115
+ * Reset composer
116
+ */
117
  public function reset()
118
  {
119
  $this->_linkReferences = array();
122
  $this->_bodyText = null;
123
  $this->_subject = null;
124
  }
125
+
126
+ /**
127
+ * Get type
128
+ *
129
+ * @return int
130
+ */
131
  public function getType()
132
  {
133
  return self::TYPE_HTML;
134
  }
135
+
 
 
 
136
  /**
137
  * Retrieve all created link references
138
  *
139
+ * @return Mzax_Emarketing_Model_Link_Reference[]
140
  */
141
  public function getLinkReferences()
142
  {
143
  return $this->_linkReferences;
144
  }
145
+
146
  /**
147
+ *
148
  * @return Mzax_Emarketing_Model_Recipient
149
  */
150
  public function getRecipient()
151
  {
152
  return $this->_recipient;
153
  }
154
+
155
+ /**
156
+ * @return string
157
+ */
158
  public function getBodyHtml()
159
  {
160
  return $this->_bodyHtml;
161
  }
162
+
163
+ /**
164
+ * @return string
165
+ */
166
  public function getBodyText()
167
  {
168
  return $this->_bodyText;
169
  }
170
+
171
+ /**
172
+ * @return string
173
+ */
174
  public function getSubject()
175
  {
176
  return $this->_subject;
177
  }
178
+
179
+ /**
180
+ * @return int
181
+ */
182
  public function getRenderTime()
183
  {
184
  return $this->_renderTime;
185
  }
186
+
187
+ /**
188
+ * @return bool
189
+ */
190
  public function allowPrerender()
191
  {
192
  $data = $this->getRecipient()->getContent()->getMediumData();
193
+ if (isset($data['prerender']) && $data['prerender']) {
194
  return true;
195
  }
196
  return false;
197
  }
198
+
 
 
199
  /**
200
  * Add coupon
201
+ *
 
202
  * @param Mage_SalesRule_Model_Coupon $coupon
203
+ *
204
+ * @return $this
205
  */
206
  public function addCoupon(Mage_SalesRule_Model_Coupon $coupon)
207
  {
208
  $this->_coupons[] = $coupon;
209
+
210
  return $this;
211
  }
212
+
 
213
  /**
214
+ * Retrieve coupons
215
+ *
216
+ * @return Mage_SalesRule_Model_Coupon[]
217
  */
218
  public function getCoupons()
219
  {
220
  return $this->_coupons;
221
  }
222
+
 
 
223
  /**
224
+ * Retrieve template processor
225
+ *
226
  * @return Mzax_Emarketing_Model_Medium_Email_Processor
227
  */
228
  public function getTemplateProcessor()
229
  {
230
  $store = $this->getRecipient()->getStore();
231
+
232
  $recipient = $this->getRecipient();
233
  $recipient->prepare();
234
+
 
235
  /* @var $processor Mzax_Emarketing_Model_Medium_Email_Processor */
236
  $processor = Mage::getModel('mzax_emarketing/medium_email_processor');
237
  $processor->setCouponManager($this);
239
  $processor->setStoreId($recipient->getStoreId());
240
  $processor->setContent($this->getContent());
241
  $processor->setVariables($recipient->getData());
242
+ $processor->setVariables(
243
+ array(
244
+ 'current_year' => date('Y'),
245
+ 'date' => Mage::app()->getLocale()->storeDate($store),
246
+ 'store' => $recipient->getCampaign()->getStore(),
247
+ 'url' => $recipient->getUrls()
248
+ )
249
+ );
250
+
251
  return $processor;
252
  }
253
+
254
+ /**
255
+ * Retrieve content
256
+ *
257
+ * @return Mzax_Emarketing_Model_Campaign_Content
258
+ */
259
  public function getContent()
260
  {
261
  $content = $this->getRecipient()->getContent();
262
  $store = $this->getRecipient()->getStore();
263
+
264
+ if ($this->allowPrerender()) {
265
  $cacheId = self::PRERENDER_CACHE_PREFIX . $content->getContentCacheId();
266
+
267
  $data = Mage::app()->loadCache($cacheId);
268
+ if ($data) {
269
  $data = unserialize($data);
270
  }
271
+ if (!$data) {
 
272
  $storeId = $this->getRecipient()->getStoreId();
273
+
274
  /* @var $processor Mzax_Emarketing_Model_Medium_Email_Processor */
275
  $processor = Mage::getModel('mzax_emarketing/medium_email_processor');
276
  $processor->disableVarDirective(true);
281
  'date' => Mage::app()->getLocale()->storeDate($store),
282
  'store' => $this->getRecipient()->getCampaign()->getStore()
283
  ));
284
+
285
  $this->emulateDesign($storeId);
286
  $subject = $processor->getSubject();
287
  $bodyHtml = $processor->getBodyHtml();
288
  $bodyText = $processor->getBodyText();
289
  $this->revertDesign();
290
+
291
+ if ($this->_config->flag('mzax_emarketing/email/css_inliner', $storeId)) {
292
  $this->inlineCss($bodyHtml);
293
  }
294
+
295
+ if ($this->_config->flag('mzax_emarketing/email/remove_comments', $storeId)) {
296
  $this->removeComments($bodyHtml);
297
  }
298
+
299
  $data = new Varien_Object;
300
+ $data->setData('subject', $subject);
301
+ $data->setData('body_html', $bodyHtml);
302
+ $data->setData('body_text', $bodyText);
303
+
304
  Mage::app()->saveCache(serialize($data), $cacheId, array(Mzax_Emarketing_Model_Campaign::CACHE_TAG));
305
  }
306
  /* @var $fullCache Mzax_Emarketing_Model_Medium_Email_FullCache */
307
  $fullCache = Mage::getModel('mzax_emarketing/medium_email_fullCache');
308
+ $fullCache->setContentCacheId($cacheId);
309
  $fullCache->setMediumData($data);
310
+
311
  return $fullCache;
312
  }
313
+
314
  return $content;
315
  }
316
+
 
 
 
 
 
 
 
 
317
  /**
318
  * Compose Email
319
+ *
320
+ * Parse all mage expressions and prepare html for sending
321
+ *
322
  * @throws Exception
323
  * @param boolean $previewMode
324
  * @return Mzax_Emarketing_Model_Medium_Email_Composer
325
  */
326
  public function compose($previewMode = false)
327
  {
328
+ if (!$this->_recipient) {
329
  throw new Exception("Can not compose email without a recipient");
330
  }
331
  $this->reset();
332
+
333
  $start = microtime(true);
334
+
335
  $recipient = $this->getRecipient();
336
  $storeId = $recipient->getStoreId();
337
  $processor = $this->getTemplateProcessor();
338
  $processor->isPreview($previewMode);
339
+
340
+ if ($this->allowPrerender()) {
341
  $this->_subject = $processor->getSubject();
342
  $processor->setVariables(array('subject' => $this->_subject));
343
+
344
  $this->_bodyHtml = $processor->getBodyHtml();
345
  $this->_bodyText = $processor->getBodyText();
346
+
347
  // insert view tacking beacon
348
  $this->insertBeacon($this->_bodyHtml);
349
+ $this->_bodyText = str_replace(self::BEACON_PLACEHOLDER, '', $this->_bodyText);
350
+
351
  // make links trackable
352
  $this->parseLinks($this->_bodyHtml);
353
+ } else {
 
354
  $this->emulateDesign($recipient->getStoreId());
355
  $this->_subject = $processor->getSubject();
356
  $processor->setVariables(array('subject' => $this->_subject));
357
+
358
  $this->_bodyHtml = $processor->getBodyHtml();
359
  $this->_bodyText = $processor->getBodyText();
360
  $this->revertDesign();
361
+
362
  // insert view tacking beacon
363
  $this->insertBeacon($this->_bodyHtml);
364
+ $this->_bodyText = str_replace(self::BEACON_PLACEHOLDER, '', $this->_bodyText);
365
+
366
  // make links trackable
367
  $this->parseLinks($this->_bodyHtml);
368
+
369
+ if ($this->_config->flag('mzax_emarketing/email/css_inliner', $storeId)) {
 
370
  $this->inlineCss($this->_bodyHtml);
371
  }
372
+ if ($this->_config->flag('mzax_emarketing/email/remove_comments', $storeId)) {
373
  $this->removeComments($this->_bodyHtml);
374
  }
375
  }
 
376
  $this->_renderTime = microtime(true) - $start;
377
+
378
  return $this;
379
  }
380
+
381
+ /**
382
+ * Inline CSS
383
+ *
384
+ * @param string $html
385
+ *
386
+ * @return void
387
+ */
388
  protected function inlineCss(&$html)
389
  {
390
+ /** @var Mzax_Emarketing_Helper_Data $helper */
391
+ $helper = Mage::helper('mzax_emarketing');
392
+
393
+ $helper->encodeMageExpr($html);
394
+
395
  // @todo Maybe use Pelago_Emogrifier (but only available in later versionsof Magento)
396
  $cssInliner = new TijsVerkoyen_CssToInlineStyles_CssToInlineStyles($html);
397
  $cssInliner->setUseInlineStylesBlock(true);
398
  $html = $cssInliner->convert();
399
+
400
+ $helper->decodeMageExpr($html);
401
  }
402
+
403
+ /**
404
+ * Remove comments
405
+ *
406
+ * @param string $html
407
+ *
408
+ * @return void
409
+ */
410
  protected function removeComments(&$html)
411
  {
412
  // remove leading & trailing spaces
413
  $html = preg_replace('/^\s+|\s+$/m', "", $html);
414
+
415
  // remove html comments
416
  $html = preg_replace('/<!--(.*)-->/Uis', '', $html);
417
+
418
  // remove empty lines
419
  $html = preg_replace("/([\n\r]+)/", "\n", $html);
420
+
421
  // cleanup css tags
422
  $html = preg_replace_callback(self::STYLE_TAGS, array($this, 'cleanUpCss'), $html);
423
  }
424
+
425
+ /**
426
+ * Clean up CSS
427
+ *
428
+ * @param string[] $match
429
+ *
430
+ * @return string
431
+ */
432
  protected function cleanUpCss($match)
433
  {
434
  $css = $match[1];
435
+
436
  // replace double quotes by single quotes
437
  $css = str_replace('"', '\'', $css);
438
+
439
  // remove comments
440
  $css = preg_replace('/\/\*.*?\*\//s', '', $css);
441
+
442
  // remove leading & trailing spaces
443
  $css = preg_replace('/^\s+|\s+$/m', '', $css);
444
+
445
  // remove lines
446
  $css = preg_replace("/([\n\r]+)/", "", $css);
447
  $css = preg_replace("/}\\s*/", "}\n", $css);
448
+
449
  // allow extra line for @media queries
450
  $css = preg_replace("/^@(.*?){/m", "\n@$1{\n", $css);
451
+
 
 
452
  return "<style type=\"text/css\">\n$css</style>\n";
 
453
  }
454
+
455
+ /**
456
+ * Parse links
457
+ *
458
+ * @param string $html
459
+ *
460
+ * @return void
461
+ */
462
  protected function parseLinks(&$html)
463
  {
464
  // replace all links with trackable links
465
+ $html = preg_replace_callback(self::LINK_A_TAG, array($this, '__replaceLinkCallback'), $html);
466
+ $html = preg_replace_callback(self::LINK_MAP_TAG, array($this, '__replaceMapCallback'), $html);
467
  }
468
+
469
+
470
  /**
471
  * PregReplace callback for <a> tag links
472
  *
473
+ * @param string[] $matches
474
+ *
475
  * @return string
476
  */
477
  public function __replaceLinkCallback($matches)
478
  {
479
  list($linkHtml, $url, $anchor) = $matches;
480
+
481
+ if (strpos(strtolower($url), 'mailto:') === 0) {
482
  return $linkHtml;
483
  }
484
+
485
  $link = $this->createLinkReference($url, $anchor);
 
486
  $linkHtml = str_replace("href=\"{$url}\"", "href=\"{$link}\"", $linkHtml);
487
+
488
  return preg_replace("!\s+!", ' ', $linkHtml);
489
  }
490
+
 
 
 
 
491
  /**
492
  * Create new link reference
493
  *
494
  * @param string $url
495
  * @param string $anchor
496
+ *
497
  * @return Mzax_Emarketing_Model_Link_Reference
498
  */
499
  public function createLinkReference($url, $anchor)
500
  {
501
  // normalize anchor text
502
  $anchor = trim(preg_replace("!\s+!s", ' ', $anchor));
503
+
504
+ // unique key
505
  $key = md5(strtolower($url.$anchor));
506
+
507
  // if not yet created, create new one
508
+ if (!isset($this->_linkReferences[$key])) {
509
  /* @var $reference Mzax_Emarketing_Model_Link_Reference */
510
  $reference = Mage::getModel('mzax_emarketing/link_reference');
511
  $reference->setRecipient($this->_recipient);
512
  $reference->setLink($url, $anchor);
513
+
514
  $this->_linkReferences[$key] = $reference;
515
  }
516
+
517
  return $this->_linkReferences[$key];
 
518
  }
 
 
 
 
519
 
520
  /**
521
  * Get url to beacon image
524
  */
525
  public function getBeaconImage()
526
  {
527
+ $store = $this->_recipient->getCampaign()->getStore();
528
+ $baseUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, false);
529
+
530
  return $baseUrl . "emarketing-media/{$this->_recipient->getBeaconHash()}/logo.gif";
531
  }
 
 
 
 
532
 
533
  /**
534
  * Insert tracking beacon
539
  public function insertBeacon(&$html)
540
  {
541
  $beaconHtml = "<img alt=\"{$this->_recipient->getCampaign()->getStore()->getName()}\" src=\"{$this->getBeaconImage()}\" style=\"width:10px; height:5px;\" />";
542
+
543
  // if beacon placeholder exist replace it
544
+ if (strpos($html, self::BEACON_PLACEHOLDER) !== false) {
545
  $html = str_replace(self::BEACON_PLACEHOLDER, $beaconHtml, $html);
546
+ } elseif (strpos($html, "</body>") !== false) {
547
+ // if not try to append it just before the body tag closes
 
548
  $html = str_replace("</body>", "{$beaconHtml}\n</body>", $html);
549
+ } else {
550
+ // if everything fails add it to the end
 
551
  $html .= $beaconHtml;
552
  }
553
+
554
  return $this;
555
  }
556
+
557
+ /**
558
+ * @var string[]
559
+ */
 
 
560
  protected $_currentMapName;
561
+
 
 
 
562
  /**
563
  * PregReplace callback for <map> tag links
564
  *
568
  public function __replaceMapCallback($matches)
569
  {
570
  list($mapHtml, $name) = $matches;
571
+
572
  $this->_currentMapName = array($name, $this->_getTagByUsemap($name));
573
  $mapHtml = preg_replace_callback(self::LINK_AREA_TAG, array($this, '__replaceMapLinkCallback'), $mapHtml);
574
  $this->_currentMapName = null;
575
+
576
  return $mapHtml;
577
  }
578
+
 
 
 
579
  /**
580
+ * Retrieve original tag that binds to the given usemap
581
  *
582
+ * Helpful to retrieve the image that was used for a <area> tag
583
  *
584
  * @param string $usemap
585
+ *
586
  * @return string
587
  */
588
  public function _getTagByUsemap($usemap)
589
  {
590
+ if (preg_match("!<[^>]*usemap=\"#{$usemap}\"[^>]*>!is", $this->_bodyHtml, $matches)) {
591
  return $matches[0];
592
  }
593
+
594
  return '';
595
  }
596
+
597
+ /**
598
+ * @param string[] $matches
599
+ *
600
+ * @return string
601
+ */
602
  public function __replaceMapLinkCallback($matches)
603
  {
604
  list($area, $url) = $matches;
605
+
606
+ if (strpos(strtolower($url), 'mailto:') === 0) {
607
  return $url;
608
  }
609
+
610
  $label = array($this->_currentMapName[1]);
611
+
612
+ if ($shape = $this->_extractAttribute($area, 'shape')) {
613
  $label[] = $shape;
614
  }
615
+ if ($coords = $this->_extractAttribute($area, 'coords')) {
616
  $label[] = $coords;
617
  }
618
+
619
  /* @var $link Mzax_Emarketing_Model_Link */
620
  $link = $this->createLinkReference($url, implode(':', $label));
621
+
622
  return str_replace("href=\"{$url}\"", "href=\"{$link}\"", $area);
623
  }
624
+
 
 
625
  /**
626
  * Extract attribute from a html tag
627
  *
634
  */
635
  protected function _extractAttribute($htmlTag, $attribute)
636
  {
637
+ if (preg_match("!{$attribute}=\"(.*?)\"!i", $htmlTag, $match)) {
638
  return $match[1];
639
  }
640
+
641
  return null;
642
  }
 
 
 
 
643
  }
app/code/community/Mzax/Emarketing/Model/Medium/Email/Filter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,132 +18,122 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Medium_Email_Filter
30
  extends Mage_Widget_Model_Template_Filter
31
  {
32
-
33
  /**
34
  * Simple cache for loaded sales rules by id
35
- *
36
  * @var array
37
  */
38
  protected static $_salesRules = array();
39
-
40
-
41
  /**
42
- *
43
  * @var Mzax_Emarketing_Model_SalesRule_ICouponManager
44
  */
45
  protected $_couponManager;
46
-
47
-
48
  /**
49
- *
50
  * @var boolean
51
  */
52
  protected $_enableVarDirective = true;
53
 
54
-
55
  /**
56
  * Is in preview mode?
57
  *
58
  * @var bool
59
  */
60
  protected $_isPreview = false;
61
-
62
-
63
-
64
  /**
65
  * Set coupon mananger
66
- *
67
  * All coupons generated by this filter will get added
68
  * to the coupon manager which is responsible for saving them
69
- *
70
- * @param unknown $manager
71
- * @return Mzax_Emarketing_Model_SalesRule_ICouponManager
 
72
  */
73
  public function setCouponManager(Mzax_Emarketing_Model_SalesRule_ICouponManager $manager)
74
  {
75
  $this->_couponManager = $manager;
 
76
  return $this;
77
  }
78
-
79
-
80
-
81
-
82
  /**
83
  * Disable var directive
84
- *
85
- * @param string $flag
86
- * @return Mzax_Emarketing_Model_Medium_Email_Filter
 
87
  */
88
  public function disableVarDirective($flag = true)
89
  {
90
  $this->_enableVarDirective = !$flag;
 
91
  return $this;
92
  }
93
 
94
-
95
  /**
96
  * Flag as preview mode
97
  *
98
- * @param string $flag
99
- * @return Mzax_Emarketing_Model_Medium_Email_Filter
 
100
  */
101
  public function isPreview($flag = true)
102
  {
103
  $this->_isPreview = $flag;
 
104
  return $this;
105
  }
106
 
107
-
108
-
109
  /**
110
  * Var directive with modifiers support
111
  *
112
  * @param array $construction
 
113
  * @return string
114
  */
115
  public function varDirective($construction)
116
  {
117
- if($this->_enableVarDirective) {
118
  return parent::varDirective($construction);
119
  }
 
120
  return $construction[0];
121
  }
122
-
123
-
124
-
125
-
126
  /**
127
  * Generate widget HTML if template variables are assigned
128
  *
129
  * @param array $construction
 
130
  * @return string
131
  */
132
  public function widgetDirective($construction)
133
  {
134
  $construction[2] .= sprintf(' store_id ="%s"', $this->getStoreId());
 
135
  return parent::widgetDirective($construction);
136
  }
137
 
138
-
139
  /**
140
  * Retrieve Block html directive
141
  *
142
  * @param array $construction
 
143
  * @return string
144
  */
145
  public function blockDirective($construction)
146
  {
147
- if($this->_isPreview && isset($this->_permissionBlock)) {
148
  $blockParameters = $this->_getIncludeParameters($construction[2]);
149
  if (isset($blockParameters['type'])) {
150
  $type = $blockParameters['type'];
@@ -152,38 +141,38 @@ class Mzax_Emarketing_Model_Medium_Email_Filter
152
  $msg = Mage::helper('mzax_emarketing')
153
  ->__('[BLOCK(%s) is not allowed (Check System -> Permissions -> Block)]', $type);
154
 
155
- if(!$this->_permissionBlock->isTypeAllowed($type)) {
156
  return '<pre style="color:red;">' . $msg . '</pre>';
157
  }
158
  }
159
  }
 
160
  return parent::blockDirective($construction);
161
  }
162
 
163
-
164
-
165
-
166
  /**
167
  * Coupon Directive
168
- *
169
  * Will generated a coupon code on the fly.
170
  * Syntax: {{coupon rule="5" length="8" prefix="ABC-" dash="4"}}
171
  *
172
  * @param array $construction
 
173
  * @return string
 
174
  */
175
  public function couponDirective($construction)
176
  {
177
  // ignore if no coupon manager is defined
178
- if(!$this->_couponManager) {
179
  return $construction[0];
180
  }
181
-
182
  // requires version 1.6 of sales rule (magento 1.7)
183
- if(version_compare(Mage::getConfig()->getModuleConfig('Mage_SalesRule')->version, '1.6.0') < 0) {
184
  return $construction[0];
185
  }
186
-
187
  $defaults = array(
188
  'format' => Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC,
189
  'length' => 8,
@@ -193,14 +182,14 @@ class Mzax_Emarketing_Model_Medium_Email_Filter
193
  'delimer' => '-'
194
  );
195
  $params = array_merge($defaults, $this->_getIncludeParameters($construction[2]));
196
-
197
  /* @var $coupon Mage_SalesRule_Model_Coupon */
198
  $coupon = Mage::getModel('salesrule/coupon');
199
-
200
-
201
- if(isset($params['rule'])) {
202
  $rule = self::getSalesRule($params['rule']);
203
- if(!$rule) {
204
  throw new Exception("Rule defined for coupon directive ({$params['rule']}) does not exist");
205
  }
206
  if ($rule->getCouponType() == $rule::COUPON_TYPE_NO_COUPON) {
@@ -208,64 +197,59 @@ class Mzax_Emarketing_Model_Medium_Email_Filter
208
  }
209
  if (!$rule->getUseAutoGeneration()) {
210
  $coupon = $rule->getPrimaryCoupon();
211
- if($coupon->getId()) {
212
  return $coupon->getCode();
213
  }
214
  throw new Exception("Rule defined for coupon directive ({$params['rule']}) does not have a coupon defined");
215
  }
216
  $coupon->setRuleId($rule->getId());
217
- }
218
- else {
219
  throw new Exception('No rule defined for coupon directive');
220
  }
221
-
222
-
223
  /* @var $generator Mage_SalesRule_Model_Coupon_Massgenerator */
224
  $generator = Mage::getSingleton('salesrule/coupon_massgenerator');
225
  $generator->setData($params);
226
-
227
  // allow to increase length if no luck finding one
228
  $attempts = 0;
229
  do {
230
- if(++$attempts >= 4) {
231
  $attempts = 0;
232
  $generator->setLength($generator->getLength() + 1);
233
  }
234
  $code = $generator->generateCode();
235
- }
236
- while($coupon->getResource()->exists($code));
237
-
238
-
239
  $coupon->setCreatedAt(now());
240
  $coupon->setType(Mage_SalesRule_Helper_Coupon::COUPON_TYPE_SPECIFIC_AUTOGENERATED);
241
  $coupon->setCode($code);
242
  $coupon->setUsageLimit(1);
243
  $coupon->setUsagePerCustomer(1);
244
  $coupon->setExpirationDate($rule->getToDate());
245
-
246
- if(isset($params['limit'])) {
247
  $coupon->setUsageLimit((int) $params['limit']);
248
  }
249
- if(isset($params['climit'])) {
250
  $coupon->setUsagePerCustomer((int) $params['climit']);
251
  }
252
- if(isset($params['expire'])) {
253
  $expr = time() + ($params['expire'] * 3600);
254
- if($rule->getToDate()) {
255
  $expr = min($expr, strtotime($rule->getToDate()));
256
  }
257
-
258
- $expr = date('Y-m-d H:i:s', $expr);
259
  $coupon->setExpirationDate($expr);
260
  }
261
-
262
  $this->_couponManager->addCoupon($coupon);
263
-
264
  return $code;
265
  }
266
-
267
-
268
-
269
 
270
  /**
271
  * Retrieve rule by id
@@ -274,38 +258,34 @@ class Mzax_Emarketing_Model_Medium_Email_Filter
274
  */
275
  public static function getSalesRule($id)
276
  {
277
- if(array_key_exists($id, self::$_salesRules)) {
278
  return self::$_salesRules[$id];
279
  }
280
-
281
  /* @var $rule Mage_SalesRule_Model_Rule */
282
  $rule = Mage::getModel('salesrule/rule')->load($id);
283
-
284
- if(!$rule->getId()) {
285
  $rule = null;
286
  }
287
-
288
  return self::$_salesRules[$id] = $rule;
289
  }
290
-
291
-
292
-
293
-
294
-
295
-
296
  /**
297
  * Filter the string as template.
298
- * Rewrited for logging exceptions
299
  *
300
  * @param string $value
 
301
  * @return string
 
302
  */
303
  public function filter($value)
304
  {
305
  try {
306
  $value = Varien_Filter_Template::filter($value);
307
- }
308
- catch (Exception $e) {
309
  throw $e;
310
  //$value = '';
311
  //Mage::logException($e);
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Medium_Email_Filter
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Medium_Email_Filter
24
  extends Mage_Widget_Model_Template_Filter
25
  {
 
26
  /**
27
  * Simple cache for loaded sales rules by id
28
+ *
29
  * @var array
30
  */
31
  protected static $_salesRules = array();
32
+
 
33
  /**
34
+ *
35
  * @var Mzax_Emarketing_Model_SalesRule_ICouponManager
36
  */
37
  protected $_couponManager;
38
+
 
39
  /**
40
+ *
41
  * @var boolean
42
  */
43
  protected $_enableVarDirective = true;
44
 
 
45
  /**
46
  * Is in preview mode?
47
  *
48
  * @var bool
49
  */
50
  protected $_isPreview = false;
51
+
 
 
52
  /**
53
  * Set coupon mananger
54
+ *
55
  * All coupons generated by this filter will get added
56
  * to the coupon manager which is responsible for saving them
57
+ *
58
+ * @param Mzax_Emarketing_Model_SalesRule_ICouponManager $manager
59
+ *
60
+ * @return $this
61
  */
62
  public function setCouponManager(Mzax_Emarketing_Model_SalesRule_ICouponManager $manager)
63
  {
64
  $this->_couponManager = $manager;
65
+
66
  return $this;
67
  }
68
+
 
 
 
69
  /**
70
  * Disable var directive
71
+ *
72
+ * @param bool $flag
73
+ *
74
+ * @return $this
75
  */
76
  public function disableVarDirective($flag = true)
77
  {
78
  $this->_enableVarDirective = !$flag;
79
+
80
  return $this;
81
  }
82
 
 
83
  /**
84
  * Flag as preview mode
85
  *
86
+ * @param bool $flag
87
+ *
88
+ * @return $this
89
  */
90
  public function isPreview($flag = true)
91
  {
92
  $this->_isPreview = $flag;
93
+
94
  return $this;
95
  }
96
 
 
 
97
  /**
98
  * Var directive with modifiers support
99
  *
100
  * @param array $construction
101
+ *
102
  * @return string
103
  */
104
  public function varDirective($construction)
105
  {
106
+ if ($this->_enableVarDirective) {
107
  return parent::varDirective($construction);
108
  }
109
+
110
  return $construction[0];
111
  }
112
+
 
 
 
113
  /**
114
  * Generate widget HTML if template variables are assigned
115
  *
116
  * @param array $construction
117
+ *
118
  * @return string
119
  */
120
  public function widgetDirective($construction)
121
  {
122
  $construction[2] .= sprintf(' store_id ="%s"', $this->getStoreId());
123
+
124
  return parent::widgetDirective($construction);
125
  }
126
 
 
127
  /**
128
  * Retrieve Block html directive
129
  *
130
  * @param array $construction
131
+ *
132
  * @return string
133
  */
134
  public function blockDirective($construction)
135
  {
136
+ if ($this->_isPreview && isset($this->_permissionBlock)) {
137
  $blockParameters = $this->_getIncludeParameters($construction[2]);
138
  if (isset($blockParameters['type'])) {
139
  $type = $blockParameters['type'];
141
  $msg = Mage::helper('mzax_emarketing')
142
  ->__('[BLOCK(%s) is not allowed (Check System -> Permissions -> Block)]', $type);
143
 
144
+ if (!$this->_permissionBlock->isTypeAllowed($type)) {
145
  return '<pre style="color:red;">' . $msg . '</pre>';
146
  }
147
  }
148
  }
149
+
150
  return parent::blockDirective($construction);
151
  }
152
 
 
 
 
153
  /**
154
  * Coupon Directive
155
+ *
156
  * Will generated a coupon code on the fly.
157
  * Syntax: {{coupon rule="5" length="8" prefix="ABC-" dash="4"}}
158
  *
159
  * @param array $construction
160
+ *
161
  * @return string
162
+ * @throws Exception
163
  */
164
  public function couponDirective($construction)
165
  {
166
  // ignore if no coupon manager is defined
167
+ if (!$this->_couponManager) {
168
  return $construction[0];
169
  }
170
+
171
  // requires version 1.6 of sales rule (magento 1.7)
172
+ if (version_compare(Mage::getConfig()->getModuleConfig('Mage_SalesRule')->version, '1.6.0') < 0) {
173
  return $construction[0];
174
  }
175
+
176
  $defaults = array(
177
  'format' => Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC,
178
  'length' => 8,
182
  'delimer' => '-'
183
  );
184
  $params = array_merge($defaults, $this->_getIncludeParameters($construction[2]));
185
+
186
  /* @var $coupon Mage_SalesRule_Model_Coupon */
187
  $coupon = Mage::getModel('salesrule/coupon');
188
+
189
+
190
+ if (isset($params['rule'])) {
191
  $rule = self::getSalesRule($params['rule']);
192
+ if (!$rule) {
193
  throw new Exception("Rule defined for coupon directive ({$params['rule']}) does not exist");
194
  }
195
  if ($rule->getCouponType() == $rule::COUPON_TYPE_NO_COUPON) {
197
  }
198
  if (!$rule->getUseAutoGeneration()) {
199
  $coupon = $rule->getPrimaryCoupon();
200
+ if ($coupon->getId()) {
201
  return $coupon->getCode();
202
  }
203
  throw new Exception("Rule defined for coupon directive ({$params['rule']}) does not have a coupon defined");
204
  }
205
  $coupon->setRuleId($rule->getId());
206
+ } else {
 
207
  throw new Exception('No rule defined for coupon directive');
208
  }
209
+
210
+
211
  /* @var $generator Mage_SalesRule_Model_Coupon_Massgenerator */
212
  $generator = Mage::getSingleton('salesrule/coupon_massgenerator');
213
  $generator->setData($params);
214
+
215
  // allow to increase length if no luck finding one
216
  $attempts = 0;
217
  do {
218
+ if (++$attempts >= 4) {
219
  $attempts = 0;
220
  $generator->setLength($generator->getLength() + 1);
221
  }
222
  $code = $generator->generateCode();
223
+ } while ($coupon->getResource()->exists($code));
224
+
225
+
 
226
  $coupon->setCreatedAt(now());
227
  $coupon->setType(Mage_SalesRule_Helper_Coupon::COUPON_TYPE_SPECIFIC_AUTOGENERATED);
228
  $coupon->setCode($code);
229
  $coupon->setUsageLimit(1);
230
  $coupon->setUsagePerCustomer(1);
231
  $coupon->setExpirationDate($rule->getToDate());
232
+
233
+ if (isset($params['limit'])) {
234
  $coupon->setUsageLimit((int) $params['limit']);
235
  }
236
+ if (isset($params['climit'])) {
237
  $coupon->setUsagePerCustomer((int) $params['climit']);
238
  }
239
+ if (isset($params['expire'])) {
240
  $expr = time() + ($params['expire'] * 3600);
241
+ if ($rule->getToDate()) {
242
  $expr = min($expr, strtotime($rule->getToDate()));
243
  }
244
+
245
+ $expr = date('Y-m-d H:i:s', $expr);
246
  $coupon->setExpirationDate($expr);
247
  }
248
+
249
  $this->_couponManager->addCoupon($coupon);
250
+
251
  return $code;
252
  }
 
 
 
253
 
254
  /**
255
  * Retrieve rule by id
258
  */
259
  public static function getSalesRule($id)
260
  {
261
+ if (array_key_exists($id, self::$_salesRules)) {
262
  return self::$_salesRules[$id];
263
  }
264
+
265
  /* @var $rule Mage_SalesRule_Model_Rule */
266
  $rule = Mage::getModel('salesrule/rule')->load($id);
267
+
268
+ if (!$rule->getId()) {
269
  $rule = null;
270
  }
271
+
272
  return self::$_salesRules[$id] = $rule;
273
  }
274
+
 
 
 
 
 
275
  /**
276
  * Filter the string as template.
277
+ * Rewrite for logging exceptions
278
  *
279
  * @param string $value
280
+ *
281
  * @return string
282
+ * @throws Exception
283
  */
284
  public function filter($value)
285
  {
286
  try {
287
  $value = Varien_Filter_Template::filter($value);
288
+ } catch (Exception $e) {
 
289
  throw $e;
290
  //$value = '';
291
  //Mage::logException($e);
app/code/community/Mzax/Emarketing/Model/Medium/Email/FullCache.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 this Extension in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mzax
13
+ * @package Mzax_Emarketing
14
+ * @author Jacob Siefer (jacob@mzax.de)
15
+ * @copyright Copyright (c) 2015 Jacob Siefer
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Class Mzax_Emarketing_Model_Medium_Email_FullCache
21
+ */
22
+ class Mzax_Emarketing_Model_Medium_Email_FullCache
23
+ implements Mzax_Emarketing_Model_Campaign_Content
24
+ {
25
+ /**
26
+ * @var string
27
+ */
28
+ protected $_cacheId;
29
+
30
+ /**
31
+ * @var Varien_Object
32
+ */
33
+ protected $_mediumData;
34
+
35
+ /**
36
+ * Retrieve cache id
37
+ *
38
+ * return string
39
+ */
40
+ public function getContentCacheId()
41
+ {
42
+ return $this->_cacheId;
43
+ }
44
+
45
+ /**
46
+ * Set cache id
47
+ *
48
+ * @param $id
49
+ *
50
+ * @return $this
51
+ */
52
+ public function setContentCacheId($id)
53
+ {
54
+ $this->_cacheId = $id;
55
+
56
+ return $this;
57
+ }
58
+
59
+ /**
60
+ * Retrieve content data
61
+ *
62
+ * @return Varien_Object
63
+ */
64
+ public function getMediumData()
65
+ {
66
+ return $this->_mediumData;
67
+ }
68
+
69
+ /**
70
+ * Set medium data
71
+ *
72
+ * @param Varien_Object $data
73
+ *
74
+ * @return $this
75
+ */
76
+ public function setMediumData(Varien_Object $data)
77
+ {
78
+ $this->_mediumData = $data;
79
+
80
+ return $this;
81
+ }
82
+ }
app/code/community/Mzax/Emarketing/Model/Medium/Email/Processor.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,209 +18,202 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Medium_Email_Processor
30
  {
31
-
32
-
33
  /**
34
- *
35
  * @var Mzax_Emarketing_Model_Medium_Email_Filter
36
  */
37
  protected $filter;
38
-
39
-
40
  /**
41
- *
42
  * @var Mzax_Emarketing_Model_Campaign_Content
43
  */
44
  protected $_content;
45
-
46
-
47
  /**
48
- *
49
  * @var string
50
  */
51
  protected $_subject;
52
-
53
-
54
  /**
55
- *
56
  * @var string
57
  */
58
  protected $_bodyHtml;
59
-
60
-
61
  /**
62
- *
63
  * @var string
64
  */
65
  protected $_bodyText;
66
-
67
-
68
  /**
69
- *
70
  * @var boolean
71
  */
72
  protected $_enableFullCache = false;
73
-
74
-
 
 
75
  public function __construct()
76
  {
77
  $this->filter = Mage::getModel('mzax_emarketing/medium_email_filter');
78
  $this->filter->setUseAbsoluteLinks(true);
79
  }
80
-
81
-
82
  /**
83
- *
84
- *
85
- * @param string $flag
86
- * @return Mzax_Emarketing_Model_Medium_Email_Processor
 
 
 
 
 
 
 
87
  */
88
  public function disableVarDirective($flag = true)
89
  {
90
  $this->filter->disableVarDirective($flag);
 
91
  return $this;
92
  }
93
 
94
-
95
  /**
 
96
  *
97
- *
98
- * @param string $flag
99
- * @return Mzax_Emarketing_Model_Medium_Email_Processor
100
  */
101
  public function isPreview($flag = true)
102
  {
103
  $this->filter->isPreview($flag);
 
104
  return $this;
105
  }
106
 
107
-
108
-
109
  /**
110
  * Add content provider
111
- *
112
  * @param Mzax_Emarketing_Model_Campaign_Content $content
113
- * @return Mzax_Emarketing_Model_Recipient_Processor
 
114
  */
115
  public function setContent(Mzax_Emarketing_Model_Campaign_Content $content)
116
  {
117
  $this->_content = $content;
 
118
  return $this;
119
  }
120
-
121
-
122
  /**
123
- *
 
124
  * @param string $key
 
125
  * @return mixed
126
  */
127
  public function getMediumData($key)
128
  {
129
  return $this->getContent()->getMediumData()->getData($key);
130
  }
131
-
132
-
133
-
134
  /**
135
  * Retrieve content provider
136
- *
137
- * @throws Exception
138
  * @return Mzax_Emarketing_Model_Campaign_Content
 
139
  */
140
  public function getContent()
141
  {
142
- if(!$this->_content) {
143
  throw new Exception("No content provider added to processor");
144
  }
 
145
  return $this->_content;
146
  }
147
-
148
-
149
  /**
150
- *
151
  * @param array $variables
152
- * @return Mzax_Emarketing_Model_Medium_Email_Processor
 
153
  */
154
  public function setVariables($variables)
155
  {
156
  $this->filter->setVariables($variables);
 
157
  return $this;
158
  }
159
-
160
-
161
  /**
162
- *
163
  * @param mixed $storeId
164
- * @return Mzax_Emarketing_Model_Medium_Email_Processor
 
165
  */
166
  public function setStoreId($storeId)
167
  {
168
  $this->filter->setStoreId($storeId);
169
  return $this;
170
  }
171
-
172
-
173
-
174
  /**
175
  * Set coupon manager
176
- *
177
- * @param unknown $manager
178
- * @return Mzax_Emarketing_Model_Medium_Email_Processor
 
179
  */
180
- public function setCouponManager($manager)
181
  {
182
  $this->filter->setCouponManager($manager);
 
183
  return $this;
184
  }
185
-
186
-
187
-
188
  /**
189
  * Retrieve processed email subject
190
- *
191
  * @return string
192
  */
193
  public function getSubject()
194
  {
195
- if(!$this->_subject) {
196
  $subject = $this->getMediumData('subject');
197
-
198
  // @TODO prepare template vars?
199
  $this->_subject = $this->filter->filter($subject);
200
  }
 
201
  return $this->_subject;
202
  }
203
-
204
 
205
-
206
  /**
207
  * Retrieve template used by content
208
- *
209
- * @throws Exception
210
  * @return Mzax_Emarketing_Model_Template
 
211
  */
212
  public function getTemplate()
213
  {
 
 
 
 
 
214
  $templateId = $this->getMediumData('template_id');
215
- $template = Mage::getModel('mzax_emarketing/template')->load($templateId);
216
- if(!$template->getId()) {
 
 
217
  throw new Exception("Template not found");
218
  }
 
219
  return $template;
220
  }
221
-
222
-
223
-
224
-
225
  /**
226
  * Retrieve processed email body
227
  *
@@ -229,70 +221,107 @@ class Mzax_Emarketing_Model_Medium_Email_Processor
229
  */
230
  public function getBodyHtml()
231
  {
232
- if(!$this->_bodyHtml) {
233
-
234
- $bodyHtml = $this->getMediumData('body_html');
235
- // if no body html is set, render template
236
- if(!$bodyHtml) {
237
- $cacheKey = 'mzax_email_cache_' . $this->_content->getContentCacheId();
238
- $bodyHtml = Mage::app()->loadCache($cacheKey);
239
-
240
- if(!$bodyHtml) {
241
- $template = $this->getTemplate();
242
-
243
- $data = Zend_Json::decode($this->getMediumData('body'));
244
- $bodyHtml = $template->render($data);
245
-
246
- Mage::app()->saveCache($bodyHtml, $cacheKey, array(Mzax_Emarketing_Model_Campaign::CACHE_TAG));
247
- }
248
- }
249
-
250
- // @TODO prepare template vars?
251
- $this->_bodyHtml = $this->filter->filter($bodyHtml);
252
  }
253
  return $this->_bodyHtml;
254
  }
255
-
256
-
257
  /**
258
- *
 
259
  * @return string
260
  */
261
  public function getBodyText()
262
  {
263
- if(!$this->_bodyText) {
264
-
265
- $bodyText = $this->getMediumData('body_text');
266
-
267
- // if body text is defined, use it
268
- if($bodyText) {
269
- $this->_bodyText = $this->filter->filter($bodyText);
270
- }
271
- // create one using the html
272
- else {
273
- // @todo Allow custom body text
274
- try {
275
- libxml_use_internal_errors(true);
276
- $this->_bodyText = Html2Text_Html2Text::convert($this->getBodyHtml());
277
- }
278
- catch(Exception $e) {
279
- if(Mage::getIsDeveloperMode()) {
280
- $this->_bodyText = $e->getMessage();
281
- }
282
- else {
283
- $this->_bodyText = '';
284
- }
285
-
286
- }
287
- }
288
  }
 
289
  return $this->_bodyText;
290
  }
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Medium_Email_Processor
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Medium_Email_Processor
24
  {
 
 
25
  /**
 
26
  * @var Mzax_Emarketing_Model_Medium_Email_Filter
27
  */
28
  protected $filter;
29
+
 
30
  /**
 
31
  * @var Mzax_Emarketing_Model_Campaign_Content
32
  */
33
  protected $_content;
34
+
 
35
  /**
 
36
  * @var string
37
  */
38
  protected $_subject;
39
+
 
40
  /**
 
41
  * @var string
42
  */
43
  protected $_bodyHtml;
44
+
 
45
  /**
 
46
  * @var string
47
  */
48
  protected $_bodyText;
49
+
 
50
  /**
 
51
  * @var boolean
52
  */
53
  protected $_enableFullCache = false;
54
+
55
+ /**
56
+ * Mzax_Emarketing_Model_Medium_Email_Processor constructor.
57
+ */
58
  public function __construct()
59
  {
60
  $this->filter = Mage::getModel('mzax_emarketing/medium_email_filter');
61
  $this->filter->setUseAbsoluteLinks(true);
62
  }
63
+
 
64
  /**
65
+ * Disable var directive
66
+ *
67
+ * Allow to disable the var directive to prevent parsing {{$variable}} expressions.
68
+ *
69
+ * This is used to pre-cache templates for faster sending.
70
+ * This only makes sense if other expressions do not render any recipient
71
+ * specific data.
72
+ *
73
+ * @param bool $flag
74
+ *
75
+ * @return $this
76
  */
77
  public function disableVarDirective($flag = true)
78
  {
79
  $this->filter->disableVarDirective($flag);
80
+
81
  return $this;
82
  }
83
 
 
84
  /**
85
+ * @param bool $flag
86
  *
87
+ * @return $this
 
 
88
  */
89
  public function isPreview($flag = true)
90
  {
91
  $this->filter->isPreview($flag);
92
+
93
  return $this;
94
  }
95
 
 
 
96
  /**
97
  * Add content provider
98
+ *
99
  * @param Mzax_Emarketing_Model_Campaign_Content $content
100
+ *
101
+ * @return $this
102
  */
103
  public function setContent(Mzax_Emarketing_Model_Campaign_Content $content)
104
  {
105
  $this->_content = $content;
106
+
107
  return $this;
108
  }
109
+
 
110
  /**
111
+ * Retrieve medium data
112
+ *
113
  * @param string $key
114
+ *
115
  * @return mixed
116
  */
117
  public function getMediumData($key)
118
  {
119
  return $this->getContent()->getMediumData()->getData($key);
120
  }
121
+
 
 
122
  /**
123
  * Retrieve content provider
124
+ *
 
125
  * @return Mzax_Emarketing_Model_Campaign_Content
126
+ * @throws Exception
127
  */
128
  public function getContent()
129
  {
130
+ if (!$this->_content) {
131
  throw new Exception("No content provider added to processor");
132
  }
133
+
134
  return $this->_content;
135
  }
136
+
 
137
  /**
138
+ *
139
  * @param array $variables
140
+ *
141
+ * @return $this
142
  */
143
  public function setVariables($variables)
144
  {
145
  $this->filter->setVariables($variables);
146
+
147
  return $this;
148
  }
149
+
 
150
  /**
151
+ *
152
  * @param mixed $storeId
153
+ *
154
+ * @return $this
155
  */
156
  public function setStoreId($storeId)
157
  {
158
  $this->filter->setStoreId($storeId);
159
  return $this;
160
  }
161
+
 
 
162
  /**
163
  * Set coupon manager
164
+ *
165
+ * @param Mzax_Emarketing_Model_SalesRule_ICouponManager $manager
166
+ *
167
+ * @return $this
168
  */
169
+ public function setCouponManager(Mzax_Emarketing_Model_SalesRule_ICouponManager $manager)
170
  {
171
  $this->filter->setCouponManager($manager);
172
+
173
  return $this;
174
  }
175
+
 
 
176
  /**
177
  * Retrieve processed email subject
178
+ *
179
  * @return string
180
  */
181
  public function getSubject()
182
  {
183
+ if (!$this->_subject) {
184
  $subject = $this->getMediumData('subject');
185
+
186
  // @TODO prepare template vars?
187
  $this->_subject = $this->filter->filter($subject);
188
  }
189
+
190
  return $this->_subject;
191
  }
 
192
 
 
193
  /**
194
  * Retrieve template used by content
195
+ *
 
196
  * @return Mzax_Emarketing_Model_Template
197
+ * @throws Exception
198
  */
199
  public function getTemplate()
200
  {
201
+ $template = $this->getMediumData('template');
202
+ if ($template instanceof Mzax_Emarketing_Model_Template) {
203
+ return $template;
204
+ }
205
+
206
  $templateId = $this->getMediumData('template_id');
207
+ $template = $this->createTemplateModel();
208
+ $template->load($templateId);
209
+
210
+ if (!$template->getId()) {
211
  throw new Exception("Template not found");
212
  }
213
+
214
  return $template;
215
  }
216
+
 
 
 
217
  /**
218
  * Retrieve processed email body
219
  *
221
  */
222
  public function getBodyHtml()
223
  {
224
+ if ($this->_bodyHtml === null) {
225
+ $html = $this->composeBodyHtml();
226
+ $html = $this->filter->filter($html);
227
+
228
+ $this->_bodyHtml = $html;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  }
230
  return $this->_bodyHtml;
231
  }
232
+
 
233
  /**
234
+ * Retrieve body text
235
+ *
236
  * @return string
237
  */
238
  public function getBodyText()
239
  {
240
+ if ($this->_bodyText === null) {
241
+ $text = $this->composeBodyText();
242
+ $text = $this->filter->filter($text);
243
+
244
+ $this->_bodyText = $text;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  }
246
+
247
  return $this->_bodyText;
248
  }
249
+
250
+ /**
251
+ * Retrieve email body template
252
+ *
253
+ * @return string
254
+ */
255
+ protected function composeBodyHtml()
256
+ {
257
+ // check if medium data provides a body html
258
+ $bodyHtml = $this->getMediumData('body_html');
259
+ if ($bodyHtml) {
260
+ return $bodyHtml;
261
+ }
262
+
263
+ $cacheKey = 'mzax_email_cache_' . $this->_content->getContentCacheId();
264
+
265
+ // check if template has already been cached
266
+ $bodyHtml = Mage::app()->loadCache($cacheKey);
267
+ if ($bodyHtml) {
268
+ return $bodyHtml;
269
+ }
270
+
271
+ $template = $this->getTemplate();
272
+ $contentBody = $this->getMediumData('body');
273
+ if (is_string($contentBody)) {
274
+ $contentBody = Zend_Json::decode($contentBody);
275
+ }
276
+
277
+ $bodyHtml = $template->render($contentBody);
278
+
279
+ Mage::app()->saveCache($bodyHtml, $cacheKey, array(Mzax_Emarketing_Model_Campaign::CACHE_TAG));
280
+
281
+ return $bodyHtml;
282
+ }
283
+
284
+ /**
285
+ * Compose text version of the email body
286
+ *
287
+ * Check if the medium provides a text version, if that the case use it
288
+ * other wise create a text version from the HTML version using
289
+ * the Html2Text lib.
290
+ *
291
+ * @return string
292
+ */
293
+ protected function composeBodyText()
294
+ {
295
+ // check if medium data provides a body text
296
+ $bodyText = $this->getMediumData('body_text');
297
+ if ($bodyText) {
298
+ return $bodyText;
299
+ }
300
+
301
+ try {
302
+ $html = $this->getBodyHtml();
303
+
304
+ libxml_use_internal_errors(true);
305
+ $text = Html2Text_Html2Text::convert($html);
306
+
307
+ return $text;
308
+ }
309
+ catch(Exception $e) {
310
+ if (Mage::getIsDeveloperMode()) {
311
+ return $e->getMessage();
312
+ }
313
+ }
314
+
315
+ return '';
316
+ }
317
+
318
+ /**
319
+ * Create new template model
320
+ *
321
+ * @return Mzax_Emarketing_Model_Template
322
+ */
323
+ protected function createTemplateModel()
324
+ {
325
+ return Mage::getModel('mzax_emarketing/template');
326
+ }
327
+ }
app/code/community/Mzax/Emarketing/Model/Medium/Email/Snippets.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,38 +18,51 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
  *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Medium_Email_Snippets
30
  {
31
-
 
 
32
  protected $_snippets = array();
33
-
34
-
35
-
 
 
 
 
36
  public function add(array $snippet)
37
  {
38
- if(!isset($snippet['value'])) {
39
  throw new Exception("No value property defined for snippet");
40
  }
41
- if(!isset($snippet['title'])) {
42
  throw new Exception("No title property defined for snippet");
43
  }
44
- if(!isset($snippet['snippet'])) {
45
  throw new Exception("No snippet property defined for snippet");
46
  }
47
-
48
  $this->_snippets[$snippet['value']] = $snippet;
 
49
  return $this;
50
  }
51
-
52
-
53
-
 
 
 
 
 
 
 
 
 
54
  public function addSnippets($value, $snippet, $title, $description = null, $shortcut = null)
55
  {
56
  return $this->add(array(
@@ -61,26 +73,30 @@ class Mzax_Emarketing_Model_Medium_Email_Snippets
61
  'shortcut' => $shortcut
62
  ));
63
  }
64
-
65
-
66
-
 
 
 
 
 
 
 
 
67
  public function addVar($value, $title, $description = null, $shortcut = null)
68
  {
69
  return $this->addSnippets('mage.' . $value, '{{var ' . $value . '}}', $title, $description, $shortcut);
70
  }
71
-
72
-
73
-
74
-
75
-
76
  public function toArray()
77
  {
78
  $data = $this->_snippets;
79
  ksort($data);
80
-
81
  return array_values($data);
82
  }
83
-
84
-
85
-
86
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Medium_Email_Snippets
 
22
  *
23
+ * Snippets are used by the ACE code editor for auto completion
 
 
24
  */
25
  class Mzax_Emarketing_Model_Medium_Email_Snippets
26
  {
27
+ /**
28
+ * @var array[]
29
+ */
30
  protected $_snippets = array();
31
+
32
+ /**
33
+ * @param array $snippet
34
+ *
35
+ * @return $this
36
+ * @throws Exception
37
+ */
38
  public function add(array $snippet)
39
  {
40
+ if (!isset($snippet['value'])) {
41
  throw new Exception("No value property defined for snippet");
42
  }
43
+ if (!isset($snippet['title'])) {
44
  throw new Exception("No title property defined for snippet");
45
  }
46
+ if (!isset($snippet['snippet'])) {
47
  throw new Exception("No snippet property defined for snippet");
48
  }
49
+
50
  $this->_snippets[$snippet['value']] = $snippet;
51
+
52
  return $this;
53
  }
54
+
55
+ /**
56
+ * Add snippet
57
+ *
58
+ * @param $value
59
+ * @param $snippet
60
+ * @param $title
61
+ * @param null $description
62
+ * @param null $shortcut
63
+ *
64
+ * @return $this
65
+ */
66
  public function addSnippets($value, $snippet, $title, $description = null, $shortcut = null)
67
  {
68
  return $this->add(array(
73
  'shortcut' => $shortcut
74
  ));
75
  }
76
+
77
+ /**
78
+ * Add var snippet
79
+ *
80
+ * @param $value
81
+ * @param $title
82
+ * @param null $description
83
+ * @param null $shortcut
84
+ *
85
+ * @return $this
86
+ */
87
  public function addVar($value, $title, $description = null, $shortcut = null)
88
  {
89
  return $this->addSnippets('mage.' . $value, '{{var ' . $value . '}}', $title, $description, $shortcut);
90
  }
91
+
92
+ /**
93
+ * @return array
94
+ */
 
95
  public function toArray()
96
  {
97
  $data = $this->_snippets;
98
  ksort($data);
99
+
100
  return array_values($data);
101
  }
 
 
 
102
  }
app/code/community/Mzax/Emarketing/Model/Newsletter/List.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,23 +17,31 @@
18
  */
19
 
20
  /**
21
- *
 
22
  * @method string getCreatedAt()
 
 
23
  * @method string getUpdatedAt()
 
 
24
  * @method string getName()
 
 
25
  * @method string getDescription()
 
 
26
  * @method string getIsPrivate()
 
 
27
  * @method string getAutoSubscribe()
 
28
  *
29
  * @method Mzax_Emarketing_Model_Resource_Newsletter_List getResource()
30
- *
31
- * @author Jacob Siefer
32
- *
33
  */
34
  class Mzax_Emarketing_Model_Newsletter_List
35
- extends Mage_Core_Model_Abstract
36
  {
37
-
38
  /**
39
  * Prefix of model events names
40
  *
@@ -50,49 +57,55 @@ class Mzax_Emarketing_Model_Newsletter_List
50
  * @var string
51
  */
52
  protected $_eventObject = 'list';
53
-
54
-
55
-
56
-
57
 
 
 
 
 
 
58
  protected function _construct()
59
  {
60
  $this->_init('mzax_emarketing/newsletter_list');
61
  }
62
 
63
-
64
-
65
-
 
 
66
  protected function _beforeSave()
67
  {
68
  // serialize store id
69
  $storeIds = $this->getData('store_ids');
70
- if(empty($storeIds)) {
71
  $storeIds = Mage_Core_Model_App::ADMIN_STORE_ID;
72
  }
73
- if(is_array($storeIds)) {
74
  $storeIds = array_filter($storeIds, 'is_numeric');
75
  $storeIds = implode(',', $storeIds);
76
  }
77
  $this->setData('store_ids', $storeIds);
78
 
79
- return parent::_beforeSave();
80
- }
81
 
 
 
82
 
83
  /**
84
- * @return Mzax_Emarketing_Model_Newsletter_List
 
 
85
  */
86
  protected function _afterSave()
87
  {
88
- if($this->isAutoSubscribe() && $this->isObjectNew()) {
89
  $this->addAllSubscribers();
90
  }
 
91
 
92
- return parent::_afterSave();
93
  }
94
 
95
-
96
  /**
97
  * Add all current subscribers to this list
98
  *
@@ -103,7 +116,6 @@ class Mzax_Emarketing_Model_Newsletter_List
103
  return $this->getResource()->addAllSubscribers($this);
104
  }
105
 
106
-
107
  /**
108
  * Remove all subscribers from this list
109
  *
@@ -114,7 +126,6 @@ class Mzax_Emarketing_Model_Newsletter_List
114
  return $this->getResource()->removeAllSubscribers($this);
115
  }
116
 
117
-
118
  /**
119
  * Add subscribers to list
120
  *
@@ -123,11 +134,11 @@ class Mzax_Emarketing_Model_Newsletter_List
123
  */
124
  public function addSubscribers($subscribers)
125
  {
126
- $subscribers = (array) $subscribers;
 
127
  return $this->getResource()->addSubscribers($this, $subscribers);
128
  }
129
 
130
-
131
  /**
132
  * Remove subscribers from list
133
  *
@@ -136,12 +147,11 @@ class Mzax_Emarketing_Model_Newsletter_List
136
  */
137
  public function removeSubscribers($subscribers)
138
  {
139
- $subscribers = (array) $subscribers;
 
140
  return $this->getResource()->removeSubscribers($this, $subscribers);
141
  }
142
 
143
-
144
-
145
  /**
146
  * Check if list is private
147
  *
@@ -149,19 +159,18 @@ class Mzax_Emarketing_Model_Newsletter_List
149
  * they are subscribed.
150
  *
151
  * Only an admin can subscribe a subscriber to this list
152
- *
153
  * @param string $value
154
  * @return boolean
155
  */
156
  protected function isPrivate($value = null)
157
  {
158
- if(is_bool($value)) {
159
  $this->setIsPrivate($value ? 1 : 0);
160
  }
161
- return (bool) $this->getIsPrivate();
162
- }
163
-
164
 
 
 
165
 
166
  /**
167
  * If auto subscribed all new subscribers will get added
@@ -175,18 +184,18 @@ class Mzax_Emarketing_Model_Newsletter_List
175
  */
176
  protected function isAutoSubscribe($value = null)
177
  {
178
- if(is_bool($value)) {
179
  $this->setAutoSubscribe($value ? 1 : 0);
180
  }
 
181
  return (bool) $this->getAutoSubscribe();
182
  }
183
 
184
-
185
-
186
  /**
187
  * Set store ids
188
  *
189
  * @param array $storeIds
 
190
  * @return $this
191
  */
192
  public function setStoreIds(array $storeIds)
@@ -197,22 +206,20 @@ class Mzax_Emarketing_Model_Newsletter_List
197
  return $this;
198
  }
199
 
200
-
201
  /**
202
  * Retrieve all store ids
203
  *
204
- * @return array
205
  */
206
  public function getStoreIds()
207
  {
208
  $ids = $this->getData('store_ids');
209
- if(empty($ids)) {
210
  return array(Mage::app()->getStore(true)->getId());
211
  }
212
  return explode(',', $ids);
213
  }
214
 
215
-
216
  /**
217
  * Check if list is allowed for specified store
218
  *
@@ -226,7 +233,7 @@ class Mzax_Emarketing_Model_Newsletter_List
226
  $storeIds = $this->getStoreIds();
227
 
228
  // either store is allowed
229
- if(in_array($store->getId(), $storeIds)) {
230
  return true;
231
  }
232
 
@@ -234,20 +241,18 @@ class Mzax_Emarketing_Model_Newsletter_List
234
  return in_array(Mage_Core_Model_App::ADMIN_STORE_ID, $storeIds);
235
  }
236
 
237
-
238
  /**
239
- *
240
  *
241
  * @param string $key
242
  * @param null $index
 
243
  * @return mixed
244
  */
245
- public function getData($key='', $index=null)
246
  {
247
- if($key === 'allowed_stores') {
248
  return $this->getStoreIds();
249
  }
250
  return parent::getData($key, $index);
251
  }
252
-
253
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Newsletter_List
21
+ *
22
  * @method string getCreatedAt()
23
+ * @method $this setCreatedAt(string $value)
24
+ *
25
  * @method string getUpdatedAt()
26
+ * @method $this setUpdatedAt(string $value)
27
+ *
28
  * @method string getName()
29
+ * @method $this setName(string $value)
30
+ *
31
  * @method string getDescription()
32
+ * @method $this setDescription(string $value)
33
+ *
34
  * @method string getIsPrivate()
35
+ * @method $this setIsPrivate(string $value)
36
+ *
37
  * @method string getAutoSubscribe()
38
+ * @method $this setAutoSubscribe(string $value)
39
  *
40
  * @method Mzax_Emarketing_Model_Resource_Newsletter_List getResource()
 
 
 
41
  */
42
  class Mzax_Emarketing_Model_Newsletter_List
43
+ extends Mage_Core_Model_Abstract
44
  {
 
45
  /**
46
  * Prefix of model events names
47
  *
57
  * @var string
58
  */
59
  protected $_eventObject = 'list';
 
 
 
 
60
 
61
+ /**
62
+ * Model Constructor
63
+ *
64
+ * @return void
65
+ */
66
  protected function _construct()
67
  {
68
  $this->_init('mzax_emarketing/newsletter_list');
69
  }
70
 
71
+ /**
72
+ * Before save
73
+ *
74
+ * @return $this
75
+ */
76
  protected function _beforeSave()
77
  {
78
  // serialize store id
79
  $storeIds = $this->getData('store_ids');
80
+ if (empty($storeIds)) {
81
  $storeIds = Mage_Core_Model_App::ADMIN_STORE_ID;
82
  }
83
+ if (is_array($storeIds)) {
84
  $storeIds = array_filter($storeIds, 'is_numeric');
85
  $storeIds = implode(',', $storeIds);
86
  }
87
  $this->setData('store_ids', $storeIds);
88
 
89
+ parent::_beforeSave();
 
90
 
91
+ return $this;
92
+ }
93
 
94
  /**
95
+ * After save
96
+ *
97
+ * @return $this
98
  */
99
  protected function _afterSave()
100
  {
101
+ if ($this->isAutoSubscribe() && $this->isObjectNew()) {
102
  $this->addAllSubscribers();
103
  }
104
+ parent::_afterSave();
105
 
106
+ return $this;
107
  }
108
 
 
109
  /**
110
  * Add all current subscribers to this list
111
  *
116
  return $this->getResource()->addAllSubscribers($this);
117
  }
118
 
 
119
  /**
120
  * Remove all subscribers from this list
121
  *
126
  return $this->getResource()->removeAllSubscribers($this);
127
  }
128
 
 
129
  /**
130
  * Add subscribers to list
131
  *
134
  */
135
  public function addSubscribers($subscribers)
136
  {
137
+ $subscribers = (array)$subscribers;
138
+
139
  return $this->getResource()->addSubscribers($this, $subscribers);
140
  }
141
 
 
142
  /**
143
  * Remove subscribers from list
144
  *
147
  */
148
  public function removeSubscribers($subscribers)
149
  {
150
+ $subscribers = (array)$subscribers;
151
+
152
  return $this->getResource()->removeSubscribers($this, $subscribers);
153
  }
154
 
 
 
155
  /**
156
  * Check if list is private
157
  *
159
  * they are subscribed.
160
  *
161
  * Only an admin can subscribe a subscriber to this list
162
+ *
163
  * @param string $value
164
  * @return boolean
165
  */
166
  protected function isPrivate($value = null)
167
  {
168
+ if (is_bool($value)) {
169
  $this->setIsPrivate($value ? 1 : 0);
170
  }
 
 
 
171
 
172
+ return (bool)$this->getIsPrivate();
173
+ }
174
 
175
  /**
176
  * If auto subscribed all new subscribers will get added
184
  */
185
  protected function isAutoSubscribe($value = null)
186
  {
187
+ if (is_bool($value)) {
188
  $this->setAutoSubscribe($value ? 1 : 0);
189
  }
190
+
191
  return (bool) $this->getAutoSubscribe();
192
  }
193
 
 
 
194
  /**
195
  * Set store ids
196
  *
197
  * @param array $storeIds
198
+ *
199
  * @return $this
200
  */
201
  public function setStoreIds(array $storeIds)
206
  return $this;
207
  }
208
 
 
209
  /**
210
  * Retrieve all store ids
211
  *
212
+ * @return string[]
213
  */
214
  public function getStoreIds()
215
  {
216
  $ids = $this->getData('store_ids');
217
+ if (empty($ids)) {
218
  return array(Mage::app()->getStore(true)->getId());
219
  }
220
  return explode(',', $ids);
221
  }
222
 
 
223
  /**
224
  * Check if list is allowed for specified store
225
  *
233
  $storeIds = $this->getStoreIds();
234
 
235
  // either store is allowed
236
+ if (in_array($store->getId(), $storeIds)) {
237
  return true;
238
  }
239
 
241
  return in_array(Mage_Core_Model_App::ADMIN_STORE_ID, $storeIds);
242
  }
243
 
 
244
  /**
 
245
  *
246
  * @param string $key
247
  * @param null $index
248
+ *
249
  * @return mixed
250
  */
251
+ public function getData($key = '', $index = null)
252
  {
253
+ if ($key === 'allowed_stores') {
254
  return $this->getStoreIds();
255
  }
256
  return parent::getData($key, $index);
257
  }
 
258
  }
app/code/community/Mzax/Emarketing/Model/Newsletter/List/Subscriber.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,37 +17,34 @@
18
  */
19
 
20
  /**
21
- *
 
22
  * @method string getListId()
23
  * @method string getSubscriberId()
24
  * @method string getChangedAt()
25
  * @method string getListStatus()
26
- *
27
- * @method Mzax_Emarketing_Model_Resource_Newsletter_List getResource()
28
- *
29
- * @author Jacob Siefer
30
- *
31
  */
32
  class Mzax_Emarketing_Model_Newsletter_List_Subscriber
33
  extends Varien_Object
34
  {
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
  /**
44
  * Retrieve list resource model
45
  *
46
  * @return Mzax_Emarketing_Model_Resource_Newsletter_List
47
  */
48
- protected function getResouce()
49
  {
50
  return Mage::getResourceSingleton('mzax_emarketing/newsletter_list');
51
  }
52
-
53
 
 
 
 
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Newsletter_List_Subscriber
21
+ *
22
  * @method string getListId()
23
  * @method string getSubscriberId()
24
  * @method string getChangedAt()
25
  * @method string getListStatus()
 
 
 
 
 
26
  */
27
  class Mzax_Emarketing_Model_Newsletter_List_Subscriber
28
  extends Varien_Object
29
  {
 
 
 
 
 
 
 
 
30
  /**
31
  * Retrieve list resource model
32
  *
33
  * @return Mzax_Emarketing_Model_Resource_Newsletter_List
34
  */
35
+ protected function getResource()
36
  {
37
  return Mage::getResourceSingleton('mzax_emarketing/newsletter_list');
38
  }
 
39
 
40
+ /**
41
+ * Retrieve list resource model
42
+ *
43
+ * @return Mzax_Emarketing_Model_Resource_Newsletter_List
44
+ * @deprecated Typo
45
+ */
46
+ protected function getResouce()
47
+ {
48
+ return $this->getResource();
49
+ }
50
  }
app/code/community/Mzax/Emarketing/Model/Object/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,55 +17,40 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
- *
25
- *
26
- * @author Jacob Siefer
27
- *
28
  */
29
  abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
30
  {
31
-
32
  /**
33
- *
34
  * @var Mage_Core_Model_Resource_Abstract
35
  */
36
  protected $_resource;
37
-
38
-
39
-
40
  /**
41
- *
42
  * @var string
43
  */
44
  protected $_entityId;
45
-
46
-
47
-
48
-
49
  /**
50
- *
51
  * @return string
52
  */
53
- abstract function getName();
54
-
55
-
56
-
57
-
58
-
 
59
  protected function _init($entityId)
60
  {
61
  $this->_entityId = $entityId;
62
  $this->_resource = Mage::getResourceSingleton($entityId);
63
  }
64
-
65
-
66
-
67
  /**
68
- * Retreive resource model
69
- *
70
  * Mage_Core_Model_Resource_Db_Abstract
71
  * Mage_Eav_Model_Entity_Abstract
72
  * @return Mage_Core_Model_Resource_Abstract
@@ -75,50 +59,46 @@ abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
75
  {
76
  return $this->_resource;
77
  }
78
-
79
-
80
-
81
  /**
82
  * Retrieve object table name
83
- *
84
  * @return string
85
  */
86
  public function getObjectTable()
87
  {
88
  $resource = $this->getResource();
89
- if($resource instanceof Mage_Eav_Model_Entity_Abstract) {
90
  return $resource->getEntityTable();
91
  }
92
- if($resource instanceof Mage_Core_Model_Resource_Db_Abstract) {
93
  return $resource->getMainTable();
94
  }
 
95
  return null;
96
  }
97
-
98
-
99
- /**
100
  * Retrieve object id field name
101
- *
102
  * @return string
103
  */
104
  public function getIdFieldName()
105
  {
106
  $resource = $this->getResource();
107
- if($resource instanceof Mage_Eav_Model_Entity_Abstract) {
108
  return $resource->getEntityIdField();
109
  }
110
- if($resource instanceof Mage_Core_Model_Resource_Db_Abstract) {
111
  return $resource->getIdFieldName();
112
  }
 
113
  return null;
114
  }
115
-
116
-
117
-
118
-
119
  /**
120
  * Retrieve collection instance from object model
121
- *
122
  * @return Mzax_Emarketing_Model_Object_Collection
123
  */
124
  public function getCollection()
@@ -126,17 +106,14 @@ abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
126
  /* @var $collection Mzax_Emarketing_Model_Object_Collection */
127
  $collection = Mage::getModel('mzax_emarketing/object_collection');
128
  $collection->setObject($this);
129
-
130
  return $collection;
131
  }
132
-
133
-
134
-
135
-
136
  /**
137
- * Retreive select object for this object
138
  * This method should be extended to add custom bindings
139
- *
140
  * @return Mzax_Emarketing_Db_Select
141
  */
142
  public function getQuery()
@@ -145,44 +122,38 @@ abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
145
  $select->from($this->getObjectTable());
146
  $select->addBinding('id', $this->getIdFieldName());
147
  $select->setColumn('id');
148
-
149
  return $select;
150
  }
151
-
152
-
153
-
154
-
155
-
156
  /**
157
  * Retrieve direct admin url for this model
158
  * use null of not available
159
- *
160
  * Used by filter test grid columns to add a link
161
  * to the object when showing object ids (e.g. customer_id, order_id)
162
- *
163
  * @param string $id
164
- * @return NULL|string
 
165
  */
166
  public function getAdminUrl($id)
167
  {
168
  return null;
169
  }
170
-
171
-
172
-
173
  /**
174
  * Retrieve row id for an object
175
- *
176
  * @param Varien_Object $row
 
177
  * @return mixed
178
  */
179
  public function getRowId(Varien_Object $row)
180
  {
181
  return $row->getId();
182
  }
183
-
184
 
185
-
186
  /**
187
  * Retrieve form helper
188
  *
@@ -192,126 +163,114 @@ abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
192
  {
193
  return Mage::helper('mzax_emarketing');
194
  }
195
-
196
-
197
-
198
  /**
199
  * Translate
200
  *
201
  * @param string $message
202
  * @param string $args,...
 
203
  * @return string
204
  */
205
  protected function __()
206
  {
207
  return call_user_func_array(array($this->helper(), '__'), func_get_args());
208
  }
209
-
210
-
211
-
212
 
213
  /**
214
  * Get admin url
215
  *
216
  * @param string $routePath
217
  * @param array $routeParams
 
218
  * @return string
219
  */
220
  public function getUrl($routePath = null, $routeParams = null)
221
  {
222
  return $this->_getUrlModel()->getUrl($routePath, $routeParams);
223
  }
224
-
225
-
226
-
227
-
228
  /**
229
  * Retrieve admin url model
230
- *
231
  * @see Mzax_Emarketing_Model_Object_Abstract::getUrl()
 
232
  * @return Mage_Adminhtml_Model_Url
233
  */
234
  protected function _getUrlModel()
235
  {
236
  return Mage::getSingleton('adminhtml/url');
237
  }
238
-
239
-
240
-
241
-
242
  /**
243
  * Retrieve resource helper
244
- *
245
  * @return Mzax_Emarketing_Model_Resource_Helper
246
  */
247
  protected function getResourceHelper()
248
  {
249
  return Mage::getResourceSingleton('mzax_emarketing/helper');
250
  }
251
-
252
-
253
- //--------------------------------------------------------------------------
254
- //
255
- // Recipient Grid Methods
256
- //
257
- //--------------------------------------------------------------------------
258
-
259
-
260
  /**
261
  * Prepare collection for use in object grid
262
- *
263
- * @param Mzax_Emarketing_Model_Object_Collection $collection
264
  * @see Mzax_Emarketing_Model_Object_Abstract::prepareGridColumns()
 
 
 
265
  * @return void
266
  */
267
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
268
  {
269
  $collection->setObject($this);
270
  }
271
-
272
-
273
-
274
  /**
275
  * Prepare the magento grid for this object
276
  * Can be overwritten to add default columns to a filter grid
277
  * used for the filter testing.
278
- *
279
  * Use 'prepareCollection()' method to add all necesery data for
280
  * the grid frist
281
- *
282
  * @see Mzax_Emarketing_Model_Object_Abstract::prepareCollection()
283
  * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
284
  * @return void
285
  */
286
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
287
- {}
288
-
289
-
290
  /**
291
- *
292
- * @deprecated
293
  * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
 
 
 
294
  */
295
  public function afterGridLoadCollection(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
296
- {}
297
-
298
-
299
-
300
  /**
301
- *
 
 
302
  * @deprecated
303
- * @param unknown $collection
304
  */
305
  public function afterLoadCollection($collection)
306
- {}
307
-
308
 
309
-
310
-
 
 
 
311
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
312
- {}
313
-
314
-
315
  /**
316
  * Prepare recipient for sending
317
  * this should at least set email and name to the recipient
@@ -319,14 +278,14 @@ abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
319
  * inside the templates
320
  *
321
  * @param Mzax_Emarketing_Model_Recipient $recipient
 
 
322
  */
323
  public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
324
  {
325
  $object = Mage::getModel($this->_entityId);
326
  $object->load($recipient->getObjectId());
327
-
328
- $recipient->setObject($object);
329
  }
330
-
331
-
332
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Abstract
 
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Abstract extends Varien_Object
24
  {
 
25
  /**
 
26
  * @var Mage_Core_Model_Resource_Abstract
27
  */
28
  protected $_resource;
29
+
 
 
30
  /**
 
31
  * @var string
32
  */
33
  protected $_entityId;
34
+
 
 
 
35
  /**
 
36
  * @return string
37
  */
38
+ abstract public function getName();
39
+
40
+ /**
41
+ * @param string $entityId
42
+ *
43
+ * @return void
44
+ */
45
  protected function _init($entityId)
46
  {
47
  $this->_entityId = $entityId;
48
  $this->_resource = Mage::getResourceSingleton($entityId);
49
  }
50
+
 
 
51
  /**
52
+ * Retrieve resource model
53
+ *
54
  * Mage_Core_Model_Resource_Db_Abstract
55
  * Mage_Eav_Model_Entity_Abstract
56
  * @return Mage_Core_Model_Resource_Abstract
59
  {
60
  return $this->_resource;
61
  }
62
+
 
 
63
  /**
64
  * Retrieve object table name
65
+ *
66
  * @return string
67
  */
68
  public function getObjectTable()
69
  {
70
  $resource = $this->getResource();
71
+ if ($resource instanceof Mage_Eav_Model_Entity_Abstract) {
72
  return $resource->getEntityTable();
73
  }
74
+ if ($resource instanceof Mage_Core_Model_Resource_Db_Abstract) {
75
  return $resource->getMainTable();
76
  }
77
+
78
  return null;
79
  }
80
+
81
+ /**
 
82
  * Retrieve object id field name
83
+ *
84
  * @return string
85
  */
86
  public function getIdFieldName()
87
  {
88
  $resource = $this->getResource();
89
+ if ($resource instanceof Mage_Eav_Model_Entity_Abstract) {
90
  return $resource->getEntityIdField();
91
  }
92
+ if ($resource instanceof Mage_Core_Model_Resource_Db_Abstract) {
93
  return $resource->getIdFieldName();
94
  }
95
+
96
  return null;
97
  }
98
+
 
 
 
99
  /**
100
  * Retrieve collection instance from object model
101
+ *
102
  * @return Mzax_Emarketing_Model_Object_Collection
103
  */
104
  public function getCollection()
106
  /* @var $collection Mzax_Emarketing_Model_Object_Collection */
107
  $collection = Mage::getModel('mzax_emarketing/object_collection');
108
  $collection->setObject($this);
109
+
110
  return $collection;
111
  }
112
+
 
 
 
113
  /**
114
+ * Retrieve select object for this object
115
  * This method should be extended to add custom bindings
116
+ *
117
  * @return Mzax_Emarketing_Db_Select
118
  */
119
  public function getQuery()
122
  $select->from($this->getObjectTable());
123
  $select->addBinding('id', $this->getIdFieldName());
124
  $select->setColumn('id');
125
+
126
  return $select;
127
  }
128
+
 
 
 
 
129
  /**
130
  * Retrieve direct admin url for this model
131
  * use null of not available
132
+ *
133
  * Used by filter test grid columns to add a link
134
  * to the object when showing object ids (e.g. customer_id, order_id)
135
+ *
136
  * @param string $id
137
+ *
138
+ * @return null|string
139
  */
140
  public function getAdminUrl($id)
141
  {
142
  return null;
143
  }
144
+
 
 
145
  /**
146
  * Retrieve row id for an object
147
+ *
148
  * @param Varien_Object $row
149
+ *
150
  * @return mixed
151
  */
152
  public function getRowId(Varien_Object $row)
153
  {
154
  return $row->getId();
155
  }
 
156
 
 
157
  /**
158
  * Retrieve form helper
159
  *
163
  {
164
  return Mage::helper('mzax_emarketing');
165
  }
166
+
 
 
167
  /**
168
  * Translate
169
  *
170
  * @param string $message
171
  * @param string $args,...
172
+ *
173
  * @return string
174
  */
175
  protected function __()
176
  {
177
  return call_user_func_array(array($this->helper(), '__'), func_get_args());
178
  }
 
 
 
179
 
180
  /**
181
  * Get admin url
182
  *
183
  * @param string $routePath
184
  * @param array $routeParams
185
+ *
186
  * @return string
187
  */
188
  public function getUrl($routePath = null, $routeParams = null)
189
  {
190
  return $this->_getUrlModel()->getUrl($routePath, $routeParams);
191
  }
192
+
 
 
 
193
  /**
194
  * Retrieve admin url model
195
+ *
196
  * @see Mzax_Emarketing_Model_Object_Abstract::getUrl()
197
+ *
198
  * @return Mage_Adminhtml_Model_Url
199
  */
200
  protected function _getUrlModel()
201
  {
202
  return Mage::getSingleton('adminhtml/url');
203
  }
204
+
 
 
 
205
  /**
206
  * Retrieve resource helper
207
+ *
208
  * @return Mzax_Emarketing_Model_Resource_Helper
209
  */
210
  protected function getResourceHelper()
211
  {
212
  return Mage::getResourceSingleton('mzax_emarketing/helper');
213
  }
214
+
 
 
 
 
 
 
 
 
215
  /**
216
  * Prepare collection for use in object grid
217
+ *
 
218
  * @see Mzax_Emarketing_Model_Object_Abstract::prepareGridColumns()
219
+ *
220
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
221
+ *
222
  * @return void
223
  */
224
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
225
  {
226
  $collection->setObject($this);
227
  }
228
+
 
 
229
  /**
230
  * Prepare the magento grid for this object
231
  * Can be overwritten to add default columns to a filter grid
232
  * used for the filter testing.
233
+ *
234
  * Use 'prepareCollection()' method to add all necesery data for
235
  * the grid frist
236
+ *
237
  * @see Mzax_Emarketing_Model_Object_Abstract::prepareCollection()
238
  * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
239
  * @return void
240
  */
241
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
242
+ {
243
+ }
244
+
245
  /**
 
 
246
  * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
247
+ *
248
+ * @return void
249
+ * @deprecated
250
  */
251
  public function afterGridLoadCollection(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
252
+ {
253
+ }
254
+
 
255
  /**
256
+ * @param mixed $collection
257
+ *
258
+ * @return void
259
  * @deprecated
 
260
  */
261
  public function afterLoadCollection($collection)
262
+ {
263
+ }
264
 
265
+ /**
266
+ * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
267
+ *
268
+ * @return void
269
+ */
270
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
271
+ {
272
+ }
273
+
274
  /**
275
  * Prepare recipient for sending
276
  * this should at least set email and name to the recipient
278
  * inside the templates
279
  *
280
  * @param Mzax_Emarketing_Model_Recipient $recipient
281
+ *
282
+ * @return void
283
  */
284
  public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
285
  {
286
  $object = Mage::getModel($this->_entityId);
287
  $object->load($recipient->getObjectId());
288
+
289
+ $recipient->setData('object', $object);
290
  }
 
 
291
  }
app/code/community/Mzax/Emarketing/Model/Object/Address.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,14 +18,13 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @author Jacob Siefer
25
- *
26
  */
27
  abstract class Mzax_Emarketing_Model_Object_Address extends Mzax_Emarketing_Model_Object_Abstract
28
  {
29
-
 
 
30
  public function getQuery()
31
  {
32
  $query = parent::getQuery();
@@ -40,41 +38,48 @@ abstract class Mzax_Emarketing_Model_Object_Address extends Mzax_Emarketing_Mode
40
  $query->addBinding('firstname', 'firstname');
41
  $query->addBinding('lastname', 'lastname');
42
  $query->addBinding('email', 'email');
43
-
44
  return $query;
45
  }
46
-
47
-
48
-
 
 
 
49
  public function getAdminUrl($id)
50
  {
51
  return null;
52
  }
53
-
54
-
55
 
 
 
 
 
 
56
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
57
  {
58
  parent::prepareCollection($collection);
59
-
60
  $adapter = $this->getResourceHelper()->getAdapter();
61
-
62
  $nameExpr[] = "LTRIM(RTRIM({firstname}))";
63
  $nameExpr[] = "LTRIM(RTRIM({lastname}))";
64
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
65
-
66
  $collection->addField('name', $nameExpr);
67
  $collection->addField('email', 'email');
68
  $collection->addField('city', 'city');
69
  $collection->addField('postcode', 'postcode');
70
  }
71
-
72
-
73
-
74
-
 
 
75
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
76
  {
77
-
78
  $grid->addColumn('name', array(
79
  'header' => Mage::helper('mzax_emarketing')->__('Name'),
80
  'index' => 'name'
@@ -92,7 +97,4 @@ abstract class Mzax_Emarketing_Model_Object_Address extends Mzax_Emarketing_Mode
92
  'index' => 'postcode',
93
  ));
94
  }
95
-
96
-
97
-
98
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Address
 
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Address extends Mzax_Emarketing_Model_Object_Abstract
24
  {
25
+ /**
26
+ * @return Mzax_Emarketing_Db_Select
27
+ */
28
  public function getQuery()
29
  {
30
  $query = parent::getQuery();
38
  $query->addBinding('firstname', 'firstname');
39
  $query->addBinding('lastname', 'lastname');
40
  $query->addBinding('email', 'email');
41
+
42
  return $query;
43
  }
44
+
45
+ /**
46
+ * @param string $id
47
+ *
48
+ * @return null
49
+ */
50
  public function getAdminUrl($id)
51
  {
52
  return null;
53
  }
 
 
54
 
55
+ /**
56
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
57
+ *
58
+ * @return void
59
+ */
60
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
61
  {
62
  parent::prepareCollection($collection);
63
+
64
  $adapter = $this->getResourceHelper()->getAdapter();
65
+
66
  $nameExpr[] = "LTRIM(RTRIM({firstname}))";
67
  $nameExpr[] = "LTRIM(RTRIM({lastname}))";
68
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
69
+
70
  $collection->addField('name', $nameExpr);
71
  $collection->addField('email', 'email');
72
  $collection->addField('city', 'city');
73
  $collection->addField('postcode', 'postcode');
74
  }
75
+
76
+ /**
77
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
78
+ *
79
+ * @return void
80
+ */
81
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
82
  {
 
83
  $grid->addColumn('name', array(
84
  'header' => Mage::helper('mzax_emarketing')->__('Name'),
85
  'index' => 'name'
97
  'index' => 'postcode',
98
  ));
99
  }
 
 
 
100
  }
app/code/community/Mzax/Emarketing/Model/Object/Collection.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,111 +17,86 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
- *
25
- *
26
- * @author Jacob Siefer
27
- *
28
  */
29
  class Mzax_Emarketing_Model_Object_Collection extends Varien_Data_Collection_Db
30
  {
31
-
32
  /**
33
- *
34
- * @var Mzax_Emarketing_Db_Select
35
  */
36
  protected $_query;
37
-
38
-
39
  /**
40
- *
41
  * @var Mzax_Emarketing_Model_Object_Abstract
42
  */
43
  protected $_object;
44
-
45
-
46
-
 
47
  public function __construct()
48
  {
49
  parent::__construct();
50
  $this->setItemObjectClass('mzax_emarketing/object_collection_item');
51
  }
52
-
53
-
54
-
55
-
56
-
57
  /**
58
  * Set Object
59
- *
60
  * @param Mzax_Emarketing_Model_Object_Abstract $object
61
- * @return Mzax_Emarketing_Model_Object_Collection
 
62
  */
63
  public function setObject($object)
64
  {
65
  $this->_object = $object;
 
66
  return $this;
67
  }
68
-
69
-
70
-
71
  /**
72
  * Retrieve Object
73
- *
74
  * @return Mzax_Emarketing_Model_Object_Abstract
75
  */
76
  public function getObject()
77
  {
78
  return $this->_object;
79
  }
80
-
81
-
82
-
83
-
84
  /**
85
  * Set Query
86
- *
87
  * @param Mzax_Emarketing_Db_Select $query
88
- * @return Mzax_Emarketing_Model_Object_Collection
89
  */
90
  public function setQuery(Mzax_Emarketing_Db_Select $query)
91
  {
92
  $this->_conn = $query->getAdapter();
93
  $this->_select = $query;
 
94
  return $this;
95
  }
96
-
97
-
98
-
99
-
100
  /**
101
  * Retrieve Query
102
- *
103
  * @return Mzax_Emarketing_Db_Select
104
  */
105
  public function getQuery()
106
  {
107
  return $this->_select;
108
  }
109
-
110
-
111
-
112
-
113
  /**
114
- * (non-PHPdoc)
115
- * @see Varien_Data_Collection_Db::getIdFieldName()
116
  * @return string
117
  */
118
  public function getIdFieldName()
119
  {
120
  return 'id';
121
  }
122
-
123
-
124
-
125
-
126
  /**
127
  * Retrieve collection empty item
128
  *
@@ -133,99 +107,108 @@ class Mzax_Emarketing_Model_Object_Collection extends Varien_Data_Collection_Db
133
  /* @var $item Mzax_Emarketing_Model_Object_Collection_Item */
134
  $item = parent::getNewEmptyItem();
135
  $item->setObject($this->getObject());
136
-
137
  return $item;
138
  }
139
-
140
-
141
-
142
-
 
 
 
143
  public function applyFilter(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
144
  {
145
- if($this->getObject() !== $filter->getObject()) {
146
  throw new Exception("You can not apply filters for different objects");
147
  }
148
  $this->getQuery()->joinSelect('id', $filter->getSelect(), 'filter');
 
149
  return $this;
150
  }
151
-
152
-
153
-
154
-
 
 
 
155
  public function addField($alias, $expr = null)
156
  {
157
- if(!$expr) {
158
  $expr = $alias;
159
  }
160
- if(is_string($expr)) {
161
- if(!strpos($expr, '.')) {
162
  $query = $this->getQuery();
163
-
164
  // assume field in main table if binding does not exist
165
- if(!$query->hasBinding($expr)) {
166
  $query->addBinding($expr, $expr);
167
  }
168
  $expr = $query->getBinding($expr);
169
- }
170
- else {
171
  $expr = new Zend_Db_Expr($expr);
172
  }
173
  }
174
 
175
  $this->addFilterToMap($alias, $expr);
176
  $this->getQuery()->setColumn($alias, $expr);
 
177
  return $this;
178
  }
179
-
180
-
181
-
 
 
 
 
 
182
  public function joinAttribute($alias, $binding, $attribute)
183
  {
184
  $expr = $this->getQuery()->joinAttribute($binding, $attribute);
185
  $this->getQuery()->addBinding($alias, $expr);
186
  $this->addField($alias, $expr);
187
-
188
  return $expr;
189
  }
190
-
191
-
192
-
 
 
 
193
  public function hasBinding($name)
194
  {
195
  return $this->getQuery()->hasBinding($name);
196
  }
197
-
198
-
199
-
200
-
201
  /**
202
  * Get SQL for get record count
203
  *
204
- * @return Varien_Db_Select
205
  */
206
  public function getSelectCountSql()
207
  {
208
  $this->_renderFilters();
209
-
210
  $countSelect = clone $this->getSelect();
211
  $countSelect->reset(Zend_Db_Select::ORDER);
212
  $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
213
  $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
214
-
215
- if($countSelect->getPart(Zend_Db_Select::GROUP)) {
216
  $select = $this->getQuery()->getAdapter()->select();
217
  $select->from(array('results' => $countSelect), null);
218
  $select->columns('COUNT(*)');
219
-
220
  return $select;
221
  }
222
- else {
223
- $countSelect->reset(Zend_Db_Select::COLUMNS);
224
- $countSelect->columns('COUNT(*)');
225
- }
226
  return $countSelect;
227
-
228
-
229
  }
230
-
231
- }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Collection
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Collection extends Varien_Data_Collection_Db
24
  {
 
25
  /**
26
+ * @var
 
27
  */
28
  protected $_query;
29
+
 
30
  /**
 
31
  * @var Mzax_Emarketing_Model_Object_Abstract
32
  */
33
  protected $_object;
34
+
35
+ /**
36
+ * Mzax_Emarketing_Model_Object_Collection constructor.
37
+ */
38
  public function __construct()
39
  {
40
  parent::__construct();
41
  $this->setItemObjectClass('mzax_emarketing/object_collection_item');
42
  }
43
+
 
 
 
 
44
  /**
45
  * Set Object
46
+ *
47
  * @param Mzax_Emarketing_Model_Object_Abstract $object
48
+ *
49
+ * @return $this
50
  */
51
  public function setObject($object)
52
  {
53
  $this->_object = $object;
54
+
55
  return $this;
56
  }
57
+
 
 
58
  /**
59
  * Retrieve Object
60
+ *
61
  * @return Mzax_Emarketing_Model_Object_Abstract
62
  */
63
  public function getObject()
64
  {
65
  return $this->_object;
66
  }
67
+
 
 
 
68
  /**
69
  * Set Query
70
+ *
71
  * @param Mzax_Emarketing_Db_Select $query
72
+ * @return $this
73
  */
74
  public function setQuery(Mzax_Emarketing_Db_Select $query)
75
  {
76
  $this->_conn = $query->getAdapter();
77
  $this->_select = $query;
78
+
79
  return $this;
80
  }
81
+
 
 
 
82
  /**
83
  * Retrieve Query
84
+ *
85
  * @return Mzax_Emarketing_Db_Select
86
  */
87
  public function getQuery()
88
  {
89
  return $this->_select;
90
  }
91
+
 
 
 
92
  /**
 
 
93
  * @return string
94
  */
95
  public function getIdFieldName()
96
  {
97
  return 'id';
98
  }
99
+
 
 
 
100
  /**
101
  * Retrieve collection empty item
102
  *
107
  /* @var $item Mzax_Emarketing_Model_Object_Collection_Item */
108
  $item = parent::getNewEmptyItem();
109
  $item->setObject($this->getObject());
110
+
111
  return $item;
112
  }
113
+
114
+ /**
115
+ * @param Mzax_Emarketing_Model_Object_Filter_Abstract $filter
116
+ *
117
+ * @return $this
118
+ * @throws Exception
119
+ */
120
  public function applyFilter(Mzax_Emarketing_Model_Object_Filter_Abstract $filter)
121
  {
122
+ if ($this->getObject() !== $filter->getObject()) {
123
  throw new Exception("You can not apply filters for different objects");
124
  }
125
  $this->getQuery()->joinSelect('id', $filter->getSelect(), 'filter');
126
+
127
  return $this;
128
  }
129
+
130
+ /**
131
+ * @param $alias
132
+ * @param null $expr
133
+ *
134
+ * @return $this
135
+ */
136
  public function addField($alias, $expr = null)
137
  {
138
+ if (!$expr) {
139
  $expr = $alias;
140
  }
141
+ if (is_string($expr)) {
142
+ if (!strpos($expr, '.')) {
143
  $query = $this->getQuery();
144
+
145
  // assume field in main table if binding does not exist
146
+ if (!$query->hasBinding($expr)) {
147
  $query->addBinding($expr, $expr);
148
  }
149
  $expr = $query->getBinding($expr);
150
+ } else {
 
151
  $expr = new Zend_Db_Expr($expr);
152
  }
153
  }
154
 
155
  $this->addFilterToMap($alias, $expr);
156
  $this->getQuery()->setColumn($alias, $expr);
157
+
158
  return $this;
159
  }
160
+
161
+ /**
162
+ * @param $alias
163
+ * @param $binding
164
+ * @param $attribute
165
+ *
166
+ * @return Zend_Db_Expr
167
+ */
168
  public function joinAttribute($alias, $binding, $attribute)
169
  {
170
  $expr = $this->getQuery()->joinAttribute($binding, $attribute);
171
  $this->getQuery()->addBinding($alias, $expr);
172
  $this->addField($alias, $expr);
173
+
174
  return $expr;
175
  }
176
+
177
+ /**
178
+ * @param $name
179
+ *
180
+ * @return bool
181
+ */
182
  public function hasBinding($name)
183
  {
184
  return $this->getQuery()->hasBinding($name);
185
  }
186
+
 
 
 
187
  /**
188
  * Get SQL for get record count
189
  *
190
+ * @return Zend_Db_Select
191
  */
192
  public function getSelectCountSql()
193
  {
194
  $this->_renderFilters();
195
+
196
  $countSelect = clone $this->getSelect();
197
  $countSelect->reset(Zend_Db_Select::ORDER);
198
  $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
199
  $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
200
+
201
+ if ($countSelect->getPart(Zend_Db_Select::GROUP)) {
202
  $select = $this->getQuery()->getAdapter()->select();
203
  $select->from(array('results' => $countSelect), null);
204
  $select->columns('COUNT(*)');
205
+
206
  return $select;
207
  }
208
+
209
+ $countSelect->reset(Zend_Db_Select::COLUMNS);
210
+ $countSelect->columns('COUNT(*)');
211
+
212
  return $countSelect;
 
 
213
  }
214
+ }
 
app/code/community/Mzax/Emarketing/Model/Object/Collection/Item.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -21,44 +20,37 @@
21
 
22
  /**
23
  * Collection item
24
- *
25
  * @see Mzax_Emarketing_Model_Object_Collection::getNewEmptyItem()
26
- * @author Jacob Siefer
27
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
- * @version 0.4.10
29
  */
30
  class Mzax_Emarketing_Model_Object_Collection_Item extends Varien_Object
31
  {
32
-
33
  /**
34
- *
35
  * @var Mzax_Emarketing_Model_Object_Abstract
36
  */
37
  protected $_object;
38
-
39
-
40
  /**
41
  * Set Object
42
- *
43
  * @param Mzax_Emarketing_Model_Object_Abstract $object
44
- * @return Mzax_Emarketing_Model_Recipient_Object
 
45
  */
46
  public function setObject($object)
47
  {
48
  $this->_object = $object;
 
49
  return $this;
50
  }
51
-
52
-
53
-
54
  /**
55
  * Retrieve Object
56
- *
57
  * @return Mzax_Emarketing_Model_Object_Abstract
58
  */
59
  public function getObject()
60
  {
61
  return $this->_object;
62
  }
63
-
64
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
20
 
21
  /**
22
  * Collection item
23
+ *
24
  * @see Mzax_Emarketing_Model_Object_Collection::getNewEmptyItem()
 
 
 
25
  */
26
  class Mzax_Emarketing_Model_Object_Collection_Item extends Varien_Object
27
  {
 
28
  /**
 
29
  * @var Mzax_Emarketing_Model_Object_Abstract
30
  */
31
  protected $_object;
32
+
 
33
  /**
34
  * Set Object
35
+ *
36
  * @param Mzax_Emarketing_Model_Object_Abstract $object
37
+ *
38
+ * @return $this
39
  */
40
  public function setObject($object)
41
  {
42
  $this->_object = $object;
43
+
44
  return $this;
45
  }
46
+
 
 
47
  /**
48
  * Retrieve Object
49
+ *
50
  * @return Mzax_Emarketing_Model_Object_Abstract
51
  */
52
  public function getObject()
53
  {
54
  return $this->_object;
55
  }
 
56
  }
app/code/community/Mzax/Emarketing/Model/Object/Customer.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,45 +18,47 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @author Jacob Siefer
25
- *
26
  */
27
  class Mzax_Emarketing_Model_Object_Customer extends Mzax_Emarketing_Model_Object_Abstract
28
  {
29
-
30
-
 
31
  public function _construct()
32
  {
33
  $this->_init('customer/customer');
34
  }
35
-
36
-
37
-
 
38
  public function getName()
39
  {
40
  return $this->__('Customer');
41
  }
42
-
43
-
 
 
 
 
44
  public function getAdminUrl($id)
45
  {
46
  return $this->getUrl('adminhtml/customer/edit', array('id' => $id));
47
  }
48
-
49
-
 
 
50
  public function getQuery()
51
  {
52
  $query = parent::getQuery();
53
  $query->addBinding('customer_id', 'entity_id');
54
- $query->addBinding('email', 'email');
55
-
56
  return $query;
57
  }
58
-
59
-
60
-
61
 
62
  /**
63
  *
@@ -66,82 +67,81 @@ class Mzax_Emarketing_Model_Object_Customer extends Mzax_Emarketing_Model_Object
66
  public function getCollection()
67
  {
68
  $collection = parent::getCollection();
69
-
70
  $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
71
  $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
72
-
73
  $adapter = $this->getResourceHelper()->getAdapter();
74
-
75
  $nameExpr[] = "LTRIM(RTRIM($firstname))";
76
  $nameExpr[] = "LTRIM(RTRIM($lastname))";
77
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
78
-
79
  $collection->addField('name', $nameExpr);
80
  $collection->addField('email', 'email');
81
-
82
  return $collection;
83
  }
84
-
85
-
86
-
 
87
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
88
  {
89
  parent::prepareCollection($collection);
90
-
91
  $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
92
  $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
93
-
94
  $adapter = $this->getResourceHelper()->getAdapter();
95
-
96
  $nameExpr[] = "LTRIM(RTRIM($firstname))";
97
  $nameExpr[] = "LTRIM(RTRIM($lastname))";
98
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
99
-
100
  $collection->addField('name', $nameExpr);
101
  $collection->addField('email', 'email');
102
  }
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
111
  {
112
-
113
  $grid->addColumn('name', array(
114
  'header' => Mage::helper('mzax_emarketing')->__('Name'),
115
  'index' => 'name'
116
  ));
117
-
118
  $grid->addColumn('email', array(
119
  'header' => Mage::helper('mzax_emarketing')->__('Email'),
120
  'index' => 'email',
121
  ));
122
-
123
-
124
  }
125
-
126
-
127
-
128
-
129
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
130
  {
131
  $snippets->addVar('customer.firstname', $this->__("Customers Firstname"));
132
- $snippets->addVar('customer.lastname', $this->__("Customers Lastname"));
133
-
134
  }
135
 
136
  /**
137
- * (non-PHPdoc)
138
- * @see Mzax_Emarketing_Model_Object_Abstract::prepareRecipient()
 
 
 
139
  */
140
  public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
141
  {
142
  parent::prepareRecipient($recipient);
143
-
144
  /* @var $customer Mage_Customer_Model_Customer */
 
145
  $customer = $recipient->getObject();
146
  $recipient->setCustomer($customer);
147
  $recipient->setEmail($customer->getEmail());
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Customer
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Customer extends Mzax_Emarketing_Model_Object_Abstract
24
  {
25
+ /**
26
+ * @return void
27
+ */
28
  public function _construct()
29
  {
30
  $this->_init('customer/customer');
31
  }
32
+
33
+ /**
34
+ * @return string
35
+ */
36
  public function getName()
37
  {
38
  return $this->__('Customer');
39
  }
40
+
41
+ /**
42
+ * @param string $id
43
+ *
44
+ * @return string
45
+ */
46
  public function getAdminUrl($id)
47
  {
48
  return $this->getUrl('adminhtml/customer/edit', array('id' => $id));
49
  }
50
+
51
+ /**
52
+ * @return Mzax_Emarketing_Db_Select
53
+ */
54
  public function getQuery()
55
  {
56
  $query = parent::getQuery();
57
  $query->addBinding('customer_id', 'entity_id');
58
+ $query->addBinding('email', 'email');
59
+
60
  return $query;
61
  }
 
 
 
62
 
63
  /**
64
  *
67
  public function getCollection()
68
  {
69
  $collection = parent::getCollection();
70
+
71
  $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
72
  $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
73
+
74
  $adapter = $this->getResourceHelper()->getAdapter();
75
+
76
  $nameExpr[] = "LTRIM(RTRIM($firstname))";
77
  $nameExpr[] = "LTRIM(RTRIM($lastname))";
78
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
79
+
80
  $collection->addField('name', $nameExpr);
81
  $collection->addField('email', 'email');
82
+
83
  return $collection;
84
  }
85
+
86
+ /**
87
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
88
+ */
89
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
90
  {
91
  parent::prepareCollection($collection);
92
+
93
  $firstname = $collection->getQuery()->joinAttribute('customer_id', 'customer/firstname');
94
  $lastname = $collection->getQuery()->joinAttribute('customer_id', 'customer/lastname');
95
+
96
  $adapter = $this->getResourceHelper()->getAdapter();
97
+
98
  $nameExpr[] = "LTRIM(RTRIM($firstname))";
99
  $nameExpr[] = "LTRIM(RTRIM($lastname))";
100
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
101
+
102
  $collection->addField('name', $nameExpr);
103
  $collection->addField('email', 'email');
104
  }
105
+
106
+ /**
107
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
108
+ */
 
 
 
109
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
110
  {
 
111
  $grid->addColumn('name', array(
112
  'header' => Mage::helper('mzax_emarketing')->__('Name'),
113
  'index' => 'name'
114
  ));
115
+
116
  $grid->addColumn('email', array(
117
  'header' => Mage::helper('mzax_emarketing')->__('Email'),
118
  'index' => 'email',
119
  ));
 
 
120
  }
121
+
122
+ /**
123
+ * @param Mzax_Emarketing_Model_Medium_Email_Snippets $snippets
124
+ */
125
  public function prepareSnippets(Mzax_Emarketing_Model_Medium_Email_Snippets $snippets)
126
  {
127
  $snippets->addVar('customer.firstname', $this->__("Customers Firstname"));
128
+ $snippets->addVar('customer.lastname', $this->__("Customers Lastname"));
129
+
130
  }
131
 
132
  /**
133
+ * Prepare recipient for sending
134
+ *
135
+ * @param Mzax_Emarketing_Model_Recipient $recipient
136
+ *
137
+ * @return void
138
  */
139
  public function prepareRecipient(Mzax_Emarketing_Model_Recipient $recipient)
140
  {
141
  parent::prepareRecipient($recipient);
142
+
143
  /* @var $customer Mage_Customer_Model_Customer */
144
+
145
  $customer = $recipient->getObject();
146
  $recipient->setCustomer($customer);
147
  $recipient->setEmail($customer->getEmail());
app/code/community/Mzax/Emarketing/Model/Object/Customer/Address.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,16 +19,15 @@
20
 
21
  /**
22
  * Object Model for customer address
23
- *
24
  *
25
  * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Object_Customer_Address extends Mzax_Emarketing_Model_Object_Abstract
30
  {
31
-
32
-
33
  /**
34
  * (non-PHPdoc)
35
  * @see Varien_Object::_construct()
@@ -38,68 +36,68 @@ class Mzax_Emarketing_Model_Object_Customer_Address extends Mzax_Emarketing_Mode
38
  {
39
  $this->_init('customer/address');
40
  }
41
-
42
-
43
-
44
  /**
45
  * The title of this object
46
- *
47
  * @return string
48
  */
49
  public function getName()
50
  {
51
  return $this->__('Customer Address');
52
  }
53
-
54
-
55
-
56
  /**
57
  * Retrieve query for customer address
58
- *
59
  * @return Mzax_Emarketing_Db_Select
60
  */
61
  public function getQuery()
62
  {
63
  $query = parent::getQuery();
64
  $query->addBinding('customer_address_id', 'entity_id');
65
-
66
  return $query;
67
  }
68
-
69
-
70
-
71
  /**
72
  * Add name, city and postcode to collection as
73
  * we use them to show in every grid
74
- *
75
  * @see Mzax_Emarketing_Model_Object_Customer_Address::prepareGridColumns()
76
  */
77
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
78
  {
79
  parent::prepareCollection($collection);
80
-
81
  $firstname = $collection->getQuery()->joinAttribute('{id}', 'customer_address/firstname');
82
  $lastname = $collection->getQuery()->joinAttribute('{id}', 'customer_address/lastname');
83
  $postcode = $collection->getQuery()->joinAttribute('{id}', 'customer_address/city');
84
  $city = $collection->getQuery()->joinAttribute('{id}', 'customer_address/postcode');
85
-
86
  $adapter = $this->getResourceHelper()->getAdapter();
87
-
88
  $nameExpr[] = "LTRIM(RTRIM({$firstname}))";
89
  $nameExpr[] = "LTRIM(RTRIM({$lastname}))";
90
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
91
-
92
  $collection->addField('name', $nameExpr);
93
  $collection->addField('city', $city);
94
  $collection->addField('postcode', $postcode);
95
  }
96
-
97
-
98
-
99
  /**
100
  * Add name, city and postcode to grid
101
- *
102
- * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
103
  * @return void
104
  */
105
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
@@ -117,7 +115,7 @@ class Mzax_Emarketing_Model_Object_Customer_Address extends Mzax_Emarketing_Mode
117
  'index' => 'postcode',
118
  ));
119
  }
120
-
121
-
122
-
123
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
  /**
21
  * Object Model for customer address
22
+ *
23
  *
24
  * @author Jacob Siefer
25
+ * @license {{license}}
 
26
  */
27
  class Mzax_Emarketing_Model_Object_Customer_Address extends Mzax_Emarketing_Model_Object_Abstract
28
  {
29
+
30
+
31
  /**
32
  * (non-PHPdoc)
33
  * @see Varien_Object::_construct()
36
  {
37
  $this->_init('customer/address');
38
  }
39
+
40
+
41
+
42
  /**
43
  * The title of this object
44
+ *
45
  * @return string
46
  */
47
  public function getName()
48
  {
49
  return $this->__('Customer Address');
50
  }
51
+
52
+
53
+
54
  /**
55
  * Retrieve query for customer address
56
+ *
57
  * @return Mzax_Emarketing_Db_Select
58
  */
59
  public function getQuery()
60
  {
61
  $query = parent::getQuery();
62
  $query->addBinding('customer_address_id', 'entity_id');
63
+
64
  return $query;
65
  }
66
+
67
+
68
+
69
  /**
70
  * Add name, city and postcode to collection as
71
  * we use them to show in every grid
72
+ *
73
  * @see Mzax_Emarketing_Model_Object_Customer_Address::prepareGridColumns()
74
  */
75
  public function prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
76
  {
77
  parent::prepareCollection($collection);
78
+
79
  $firstname = $collection->getQuery()->joinAttribute('{id}', 'customer_address/firstname');
80
  $lastname = $collection->getQuery()->joinAttribute('{id}', 'customer_address/lastname');
81
  $postcode = $collection->getQuery()->joinAttribute('{id}', 'customer_address/city');
82
  $city = $collection->getQuery()->joinAttribute('{id}', 'customer_address/postcode');
83
+
84
  $adapter = $this->getResourceHelper()->getAdapter();
85
+
86
  $nameExpr[] = "LTRIM(RTRIM({$firstname}))";
87
  $nameExpr[] = "LTRIM(RTRIM({$lastname}))";
88
  $nameExpr = $adapter->getConcatSql($nameExpr, ' ');
89
+
90
  $collection->addField('name', $nameExpr);
91
  $collection->addField('city', $city);
92
  $collection->addField('postcode', $postcode);
93
  }
94
+
95
+
96
+
97
  /**
98
  * Add name, city and postcode to grid
99
+ *
100
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
101
  * @return void
102
  */
103
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
115
  'index' => 'postcode',
116
  ));
117
  }
118
+
119
+
120
+
121
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,60 +17,54 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Model_Object_Filter implements Mage_Eav_Model_Entity_Attribute_Source_Interface
22
  {
23
-
24
  /**
25
- *
26
  * @var Mage_Core_Model_Config_Element
27
  */
28
  protected $_config;
29
-
30
-
31
-
32
  /**
33
- *
34
- * @var array
35
  */
36
  protected $_filters;
37
-
38
-
39
  /**
40
- *
 
 
41
  * @param string $name
42
- * @return Mzax_Emarketing_Model_Object_Filter_Abstract
 
43
  */
44
  public function factory($name)
45
  {
46
  $config = $this->getConfig();
47
- if(!isset($config->$name)) {
48
- return null;
49
- //throw new Exception("No such filter ({$name}) found");
50
  }
51
  $config = $config->$name;
52
  $class = $config->getClassName();
53
-
54
  $instance = new $class($config);
55
-
56
  return $instance;
57
  }
58
-
59
-
60
-
61
-
62
-
63
-
64
  /**
65
  * Retrieve All options
66
  *
67
- * @return array
 
 
68
  */
69
- public function getAllOptions($withEmpty = true, $defaultValues = false)
70
  {
71
  $options = array();
72
-
73
- /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
74
- foreach($this->getFilters() as $name => $filter) {
75
  $options[] = array(
76
  'value' => $name,
77
  'label' => $filter->getTitle()
@@ -80,66 +73,55 @@ class Mzax_Emarketing_Model_Object_Filter implements Mage_Eav_Model_Entity_Attri
80
  if ($withEmpty) {
81
  array_unshift($options, array('label'=>'', 'value'=>''));
82
  }
83
-
84
  return $options;
85
  }
86
-
87
-
88
-
89
-
90
-
91
-
92
- /**
93
- * Retrieve all filters
94
- *
95
- * @return array
96
- */
97
- public function getFilters()
98
  {
99
- if(!$this->_filters) {
100
  $this->_filters = array();
101
-
102
- foreach($this->getConfig()->children() as $name => $cfg) {
103
- $this->_filters[$name] = self::factory($name);
104
  }
105
- }
106
- return $this->_filters;
107
  }
108
-
109
-
110
-
111
-
112
 
113
  /**
114
  * Retrieve Option value text
115
  *
116
  * @param string $value
117
- * @return mixed
 
118
  */
119
  public function getOptionText($value)
120
  {
121
  $options = $this->getFilters();
122
- if(isset($options[$value])) {
123
  return $options[$value]->getTitle();
124
  }
 
125
  return false;
126
  }
127
-
128
-
129
-
130
  /**
131
  * Retrieve email marketing collection config
132
- *
133
  * @return Mage_Core_Model_Config_Element
134
  */
135
  public function getConfig()
136
  {
137
- if(!$this->_config) {
138
  $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/filters');
139
  }
 
140
  return $this->_config;
141
  }
142
-
143
-
144
-
145
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter
22
+ */
23
  class Mzax_Emarketing_Model_Object_Filter implements Mage_Eav_Model_Entity_Attribute_Source_Interface
24
  {
 
25
  /**
 
26
  * @var Mage_Core_Model_Config_Element
27
  */
28
  protected $_config;
29
+
 
 
30
  /**
31
+ * @var Mzax_Emarketing_Model_Object_Filter[]
 
32
  */
33
  protected $_filters;
34
+
 
35
  /**
36
+ * Create filter by name or return null
37
+ * if filter is not found
38
+ *
39
  * @param string $name
40
+ *
41
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract|null
42
  */
43
  public function factory($name)
44
  {
45
  $config = $this->getConfig();
46
+ if (!isset($config->$name)) {
47
+ return null;
 
48
  }
49
  $config = $config->$name;
50
  $class = $config->getClassName();
51
+
52
  $instance = new $class($config);
53
+
54
  return $instance;
55
  }
56
+
 
 
 
 
 
57
  /**
58
  * Retrieve All options
59
  *
60
+ * @param bool $withEmpty
61
+ *
62
+ * @return string[][]
63
  */
64
+ public function getAllOptions($withEmpty = true)
65
  {
66
  $options = array();
67
+ foreach ($this->getFilters() as $name => $filter) {
 
 
68
  $options[] = array(
69
  'value' => $name,
70
  'label' => $filter->getTitle()
73
  if ($withEmpty) {
74
  array_unshift($options, array('label'=>'', 'value'=>''));
75
  }
76
+
77
  return $options;
78
  }
79
+
80
+ /**
81
+ * Retrieve all available filters
82
+ *
83
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract[]
84
+ */
85
+ public function getFilters()
 
 
 
 
 
86
  {
87
+ if (!$this->_filters) {
88
  $this->_filters = array();
89
+
90
+ foreach ($this->getConfig()->children() as $name => $cfg) {
91
+ $this->_filters[$name] = self::factory($name);
92
  }
93
+ }
94
+ return $this->_filters;
95
  }
 
 
 
 
96
 
97
  /**
98
  * Retrieve Option value text
99
  *
100
  * @param string $value
101
+ *
102
+ * @return string|false
103
  */
104
  public function getOptionText($value)
105
  {
106
  $options = $this->getFilters();
107
+ if (isset($options[$value])) {
108
  return $options[$value]->getTitle();
109
  }
110
+
111
  return false;
112
  }
113
+
 
 
114
  /**
115
  * Retrieve email marketing collection config
116
+ *
117
  * @return Mage_Core_Model_Config_Element
118
  */
119
  public function getConfig()
120
  {
121
+ if (!$this->_config) {
122
  $this->_config = Mage::getConfig()->getNode('global/mzax_emarketing/filters');
123
  }
124
+
125
  return $this->_config;
126
  }
 
 
 
127
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,287 +17,297 @@
18
  */
19
 
20
 
 
 
 
21
  abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarketing_Model_Object_Filter_Component
22
  {
23
-
24
-
 
 
 
 
 
 
 
 
25
 
26
  /**
27
  * Child Filters
28
  *
29
- * @var array
30
  */
31
  protected $_filters = array();
32
-
33
-
34
-
35
  /**
36
- *
37
  * @var string
38
  */
39
  protected $_formHtml;
40
-
41
-
42
-
43
  /**
44
- * Unique filter type id
45
- *
46
- * @var string
47
  */
48
- protected $_type;
49
-
50
 
51
-
52
-
53
-
 
 
54
  public function __construct($config = null)
55
  {
56
- $this->_construct();
57
-
58
- if($config instanceof Mage_Core_Model_Config_Element) {
59
  $this->_prepareFilter($config);
60
  }
61
  }
62
-
63
-
64
-
 
 
 
 
 
65
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
66
  {
67
  $this->_type = $config->getName();
68
-
69
  Mage::dispatchEvent("mzax_emarketing_email_filter_prepare", array('filter' => $this));
70
  Mage::dispatchEvent("mzax_emarketing_email_filter_prepare_" . $this->_type, array('filter' => $this));
71
  }
72
-
73
-
74
- public function setType($type)
75
- {
76
- $this->_type = $type;
77
- return $this;
78
- }
79
-
80
-
81
- public function getType()
82
- {
83
- return $this->_type;
84
- }
85
-
86
-
87
-
88
  /**
89
  * Retrieve object
90
- *
91
  * @return Mzax_Emarketing_Model_Object_Abstract
92
  */
93
  public function getObject()
94
  {
95
  return $this->getParentObject();
96
  }
97
-
98
-
99
 
100
  /**
101
  * Set ID
102
  *
103
  * @param string $id
104
- * @return Mzax_Emarketing_Model_Object_Filter_Component
 
105
  */
106
  public function setId($id)
107
  {
108
  $this->_id = $id;
109
- if($this->_filters) {
110
- foreach($this->_filters as $i => $filter) {
111
  $filter->setId($this->_id . '--' . ($i+1));
112
  }
113
  }
 
114
  return $this;
115
  }
116
-
117
 
118
  /**
119
  * Add child filter
120
  *
121
- * @param mixed $param
 
 
122
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
 
123
  */
124
  public function addFilter($param, $quite = true)
125
  {
126
- if(is_string($param)) {
127
  $filter = self::getFilterFactory()->factory($param);
128
- if(!$filter) {
129
- if(!$quite) {
130
- 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']));
131
  }
132
- return null;
 
 
 
 
 
 
133
  }
134
- }
135
- else if(is_array($param) && isset($param['type'])) {
136
  $filter = self::getFilterFactory()->factory($param['type']);
137
- if(!$filter) {
138
- if(!$quite) {
139
- 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']));
140
  }
141
- return null;
 
 
 
 
 
 
142
  }
143
- }
144
- else {
145
  $filter = $param;
146
  }
147
-
148
- if(!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
149
  return null;
150
  }
151
-
152
- if(!$this->acceptFilter($filter)) {
153
- if(!$quite) {
154
- throw new Mage_Exception(Mage::helper('mzax_emarketing')->__('Filter of type “%s” does not allow child of type %s.', $this->getType(), $filter->getType()));
155
  }
156
- return null;
 
 
 
 
 
 
157
  }
158
-
159
  $this->_filters[] = $filter->setParent($this);
160
  $filter->setId($this->getId() . '--' . count($this->_filters));
161
-
162
- if(is_array($param)) {
163
  $filter->load($param);
164
  }
165
-
166
  return $filter;
167
  }
168
-
169
-
170
-
171
  /**
172
- * Retrieve all filters
173
- *
174
- * @return array
175
  */
176
  public function getFilters()
177
  {
178
  return $this->_filters;
179
  }
180
-
181
-
182
-
183
  /**
184
  * Retrieve filter by index
185
  *
 
 
186
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
187
  */
188
  public function getFilterByIndex($index)
189
  {
190
- if(isset($this->_filters[$index])) {
191
  return $this->_filters[$index];
192
  }
 
193
  return null;
194
  }
195
-
196
-
197
-
198
  /**
199
  * Retrieve all filter options for this filter
200
- *
201
  * @return array
202
  */
203
  public function getOptions()
204
  {
205
  return array($this->getType() => $this->getTitle());
206
  }
207
-
208
-
209
-
210
-
211
  /**
212
  * Retrieve Varien Data Form
213
- *
214
  * @return Varien_Data_Form
215
  */
216
  public function getForm()
217
  {
 
218
  $elementRenderer = Mage::getBlockSingleton('mzax_emarketing/editable');
219
-
220
  $prefix = $this->getRoot()->getFormPrefix();
221
-
222
  $form = new Varien_Data_Form();
223
  $form->setHtmlIdPrefix("{$prefix}__{$this->getId()}__");
224
  $form->setFieldNameSuffix("{$prefix}[{$this->getId()}]");
225
  $form->setElementRenderer($elementRenderer);
 
226
  return $form;
227
  }
228
-
229
-
230
-
231
-
 
 
232
  public function reset()
233
  {
234
  $this->unsetData();
235
  $this->_filters = array();
236
  $this->_formHtml = null;
 
237
  return $this;
238
  }
239
-
240
-
241
-
242
-
243
 
244
  /**
245
  * Retrieve data
246
- *
247
  * @param string $key
248
  * @param string $default
 
249
  * @return string
250
  */
251
  public function getDataSetDefault($key, $default = null)
252
  {
253
- // check for default constant
254
- if($default === null) {
255
  $const = get_class($this) . '::DEFAULT_' . strtoupper($key);
256
- if(defined($const)) {
257
  $default = constant($const);
258
  }
259
  }
 
260
  return parent::getDataSetDefault($key, $default);
261
  }
262
-
263
-
264
-
265
-
 
 
266
  public function prepareParams()
267
- {}
268
-
269
-
270
-
271
-
272
  /**
273
  * Load filters from data
274
- *
275
  * @param mixed $data
276
- * @param boolean $quite Throw en exception if a filter was not avaialble
277
- * @throws Exception
 
278
  * @throws Mage_Exception
279
- * @return Mzax_Emarketing_Model_Object_Filter_Abstract
280
  */
281
  public function load($data, $quite = true)
282
  {
283
  $this->reset();
284
-
285
- if(empty($data)) {
286
  return $this;
287
  }
288
-
289
  // string should be a JSON
290
- if(is_string($data)) {
291
  try {
292
  $data = Zend_Json::decode($data);
293
- }
294
- catch(Zend_Json_Exception $e) {
295
  throw new Exception("Failed to decode filter json: {$e->getMessage()}", 0, $e);
296
  }
297
  }
298
-
299
- if(is_array($data)) {
300
- if(isset($data['filters'])) {
301
- foreach($data['filters'] as $filter) {
302
  $this->addFilter($filter, $quite);
303
  }
304
  unset($data['filters']);
@@ -307,14 +316,13 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
307
  $this->prepareParams();
308
  $this->setDataChanges(false);
309
  }
 
310
  return $this;
311
  }
312
-
313
-
314
-
315
  /**
316
  * Load data from flat post array
317
- *
318
  * e.g.
319
  * array(4) {
320
  * [1]=>
@@ -350,48 +358,43 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
350
  * string(15) "not_unsubscript"
351
  * }
352
  * }
353
- *
354
  * @param array $data
355
- * @return Mzax_Emarketing_Model_Object_Filter_Abstract
 
356
  */
357
  public function loadFlatArray(array $data)
358
  {
359
  $filters = array();
360
-
361
- foreach($data as $id => $filterData)
362
- {
363
  $path = explode('--', $id);
364
  $list =& $filters;
365
-
366
- while(count($path) > 1) {
367
-
368
  $id = array_shift($path);
369
- if(!isset($list[$id])) {
370
  continue 2;
371
  }
372
- if(!isset($list[$id]['filters'])) {
373
  $list[$id]['filters'] = array();
374
  }
375
  $list =& $list[$id]['filters'];
376
  }
377
-
378
  $id = array_shift($path);
379
  $list[$id] = $filterData;
380
  }
381
-
382
- if(!empty($filters)) {
383
  $this->load(array_shift($filters));
384
- }
385
- else {
386
  $this->setData(array());
387
  $this->prepareParams();
388
  }
389
-
390
  return $this;
391
  }
392
-
393
-
394
-
395
 
396
  /**
397
  * Retrieve filter data as array
@@ -401,20 +404,19 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
401
  public function asArray()
402
  {
403
  $data = $this->getData();
404
- if($this->_filters) {
405
  $data['filters'] = array();
406
- foreach($this->_filters as $filter) {
407
  $data['filters'][] = $filter->asArray();
408
  }
409
  }
410
-
411
  // not required for save
412
  unset($data['new_child']);
 
413
  return $data;
414
  }
415
-
416
-
417
-
418
  /**
419
  * Retrieve filter data as json
420
  *
@@ -424,80 +426,80 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
424
  {
425
  return Zend_Json::encode($this->asArray());
426
  }
427
-
428
-
429
  /**
430
- * Retreive data for export
431
- *
432
  * @return array
433
  */
434
  public function export()
435
  {
436
  return $this->asArray();
437
  }
438
-
439
-
440
-
441
-
442
  /**
443
  * Retrieve human readable filter text
444
  *
445
- * @param format
446
- * @return mixed
 
447
  */
448
  public function asString($format = 'html')
449
  {
450
  $form = $this->getForm();
451
- $form->getElementRenderer()->setFormat($format);
452
-
 
 
 
 
453
  $html = $this->_getFormHtml($form);
454
-
455
  return $html;
456
  }
457
-
458
-
459
-
460
-
461
  /**
462
  * Retrieve filter as html
463
- *
464
  * @return string
465
  */
466
  public function asHtml()
467
  {
468
  $html = $this->getFormHtml();
469
-
470
  if ($this->getId() != '1') {
471
  $html .= $this->getRemoveLinkHtml();
472
  }
473
-
474
  $result = $this->checkIndexes(false);
475
- if(is_string($result)) {
476
  $html .= '<div class="maax-index-check">' . $result . '</div>';
477
  }
478
-
479
  $html .= $this->getChooserContainerHtml();
480
-
481
  $prefix = $this->getRoot()->getFormPrefix();
482
-
483
- if(count($this->getAvailableFilters())) {
484
  $html .= '<ul id="'.$prefix.'__'.$this->getId().'__children" class="rule-param-children">';
485
  foreach ($this->_filters as $filter) {
486
  $html .= '<li>'.$filter->asHtml().'</li>';
487
  }
488
  $html .= '<li>'.$this->getNewChildElement()->getHtml().'</li></ul>';
489
  }
490
-
491
  return $html;
492
  }
493
-
494
 
495
-
496
-
497
- public final function getFormHtml()
 
 
 
498
  {
499
  $form = $this->getForm();
500
-
501
  $typeField = $form->addField('type', 'hidden', array(
502
  'name' => 'type',
503
  'class' => 'hidden',
@@ -505,339 +507,352 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
505
  'is_meta' => true,
506
  'value' => $this->getType()
507
  ));
508
-
509
  $html = $typeField->toHtml();
510
  $html .= $this->_getFormHtml($form);
511
-
512
  return $html;
513
  }
514
-
515
-
516
 
 
 
 
 
 
517
  protected function _getFormHtml(Varien_Data_Form $form)
518
  {
519
  $this->_form = $form;
 
520
  return $this->prepareForm();
521
  }
522
-
 
 
 
 
 
523
  protected function prepareForm()
524
  {
525
  return '';
526
  }
527
-
528
-
 
 
 
 
529
  public function getChooserContainerHtml()
530
  {
531
- $url = $this->getChooserUrl();
532
  if ($url) {
533
- $url = Mage::helper('adminhtml')->getUrl($url);
 
 
 
534
  return '<div class="rule-chooser" url="' . $url . '"></div>';
535
  }
 
536
  return '';
537
  }
538
-
539
-
540
 
541
- abstract function getTitle();
542
-
543
-
544
-
545
-
 
 
546
  /**
547
  * Run filter query and return result
548
- *
549
  * This method should only used for testing
550
  * and debugging
551
- *
552
  * @return array
553
  */
554
  public function runFilterQuery()
555
  {
556
  $select = $this->getSelect();
557
- $result = $this->_getReadAdapter()->query($select->assembleAll());
558
-
 
 
559
  return $result;
560
  }
561
-
562
-
563
 
 
 
 
564
  public function beforeLoad($provider)
565
- {}
566
-
567
-
568
-
 
 
569
  public function afterLoad($provider)
570
- {}
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
 
 
 
 
 
 
580
  protected function getAddLinkHtml()
581
  {
582
  $src = Mage::getDesign()->getSkinUrl('mzax/images/add-tiny.png');
583
  $html = '<img src="' . $src . '" class="rule-param-add v-middle" alt="" title="' . $this->__('Add Filter') . '"/>';
 
584
  return $html;
585
  }
586
-
587
-
588
-
 
 
 
589
  protected function getRemoveLinkHtml()
590
  {
591
  $src = Mage::getDesign()->getSkinUrl('mzax/images/delete-tiny.png');
592
  $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>';
593
  return $html;
594
  }
595
-
596
-
597
-
 
 
 
598
  public function getChooserTriggerHtml()
599
  {
600
  $src = Mage::getDesign()->getSkinUrl('images/rule_chooser_trigger.gif');
601
  $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>';
602
  return $html;
603
  }
604
-
605
-
606
-
607
 
608
  /**
609
  * Prepare recipient collection
610
  *
 
 
611
  * @return void
612
  */
613
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
614
  {
615
  parent::_prepareCollection($collection);
616
- //$collection->applyFilter($this);
617
  }
618
-
619
-
620
-
621
 
622
  //--------------------------------------------------------------------------
623
  //
624
  // Quick Helpers
625
  //
626
  //--------------------------------------------------------------------------
627
-
628
-
629
-
630
-
631
  /**
632
  * Helper for new child filter element
633
- *
634
  * @return Varien_Data_Form_Element_Abstract
635
  */
636
  protected function getNewChildElement()
637
  {
638
  $path = $this->getTypePath() . '-';
639
-
640
-
641
  $filters = array();
642
- foreach($this->getAvailableFilters() as $type => $title) {
643
-
644
  $title = $this->_explode($title, '|');
645
-
646
  $list =& $filters;
647
-
648
- while(count($title) > 1) {
649
  $n = array_shift($title);
650
- if(!isset($list[$n])) {
651
  $list[$n] = array('label' => $n, 'value' => array());
652
  }
653
  $list =& $list[$n]['value'];
654
  }
655
-
656
  $list[] = array('value' => $path . $type, 'label' => array_shift($title));
657
  }
658
-
659
  array_unshift($filters, array('value'=>'', 'label' => $this->__('Please choose a filter to add...')));
660
-
661
  return $this->getForm()->addField('new_child', 'select', array(
662
  'name' => 'new_child',
663
  'values' => $filters,
664
  'value_name' => $this->getAddLinkHtml(),
665
  ))->setRenderer(Mage::getBlockSingleton('rule/newchild'));
666
  }
667
-
668
-
669
-
670
  /**
671
  * Helper for simple input element
672
- *
673
  * @param string $key
 
 
674
  * @return Varien_Data_Form_Element_Abstract
675
  */
676
  protected function getInputElement($key, $default = null)
677
  {
678
  $value = (string) $this->getDataSetDefault($key, $default);
679
-
680
- return $this->getForm()->addField($key, 'text',array(
681
- 'name' => $key,
682
- 'value_name' => $value,
683
- 'value' => $value
684
  ));
685
  }
686
-
687
-
688
-
689
  /**
690
  * Add hidden input field
691
  *
692
  * @param string $name
693
  * @param string $value
 
694
  * @return Varien_Data_Form_Element_Abstract
695
  */
696
  protected function getHiddenField($name, $value)
697
  {
698
- return $this->getForm()->addField($name, 'hidden', array(
699
- 'name' => $name,
700
- 'class' => 'hidden',
701
- 'no_span' => true,
702
- 'is_meta' => true,
703
- 'value' => $value
704
- ));
 
 
 
 
705
  }
706
-
707
-
708
-
709
  /**
710
  * Helper for simple select element
711
- *
712
  * @param string $key
 
713
  * @param array $options
 
714
  * @return Varien_Data_Form_Element_Abstract
715
  */
716
  protected function getSelectElement($key, $default = null, $options = null)
717
  {
718
- if(empty($options)) {
719
  $options = $this->getDataUsingMethod($key . '_options');
720
  }
721
-
722
  $value = $this->getDataSetDefault($key, $default);
723
- if(is_array($value)) {
724
  $value = $value[0];
725
  }
726
  $valueName = '';
727
- if(isset($options[$value])) {
728
  $valueName = $options[$value];
729
  }
730
-
731
- return $this->getForm()->addField($key, 'select',array(
732
- 'name' => $key,
733
- 'value_name' => ($valueName ? $valueName : '...'),
734
- 'value' => $value,
735
- 'values' => $options
736
  ));
737
  }
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 = (string) $this->getDataSetDefault($key, $default);
753
-
754
- if(!$value) {
755
  $value = Zend_Date::now()->toString($format);
756
  }
757
-
758
  $value = Mage::app()->getLocale()->date($value, $format, null, false)->toString($format);
759
-
760
- return $this->getForm()->addField($key, 'date',array(
761
  'name' => $key,
762
  'value_name' => $value,
763
- 'value' => $value,
764
  'explicit_apply' => true,
765
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
766
  'input_format' => $format,
767
  'format' => $format
768
  ));
769
  }
770
-
771
-
772
  /**
773
  * Helper for simple select element
774
  *
775
  * @param string $key
776
- * @param array $options
 
 
777
  * @return Varien_Data_Form_Element_Abstract
778
  */
779
- protected function getMultiSelectElement($key, $default = null, $options = null)
780
  {
781
- if(empty($options)) {
782
  $optionHash = $this->getDataUsingMethod($key . '_options');
783
  }
784
-
785
  $values = $this->getDataSetDefault($key, $default);
786
- if(is_string($values)) {
787
  $values = $this->_explode($values);
788
  }
789
- if(empty($values)) {
790
  $values = array();
791
  }
792
-
793
  $valueName = array();
794
  $options = array();
795
- foreach($optionHash as $value => $option) {
796
  $options[] = array('value' => $value, 'label' => $option);
797
- if(in_array($value, $values)) {
798
  $valueName[] = $option;
799
  }
800
  }
801
-
802
- return $this->getForm()->addField($key, 'multiselect',array(
803
  'name' => $key,
804
  'value_name' => implode(', ', $valueName),
805
- 'value' => $values,
806
- 'values' => $options
807
  ));
808
  }
809
-
810
-
811
-
812
-
813
-
814
-
815
-
816
- /**
817
  * Helper for simple time html
818
- *
819
  * The time html consists of two form fields
820
- * a select for the unit and the value (e.g. 5 days, 6 weeks)
821
- *
822
- * @return string
823
- */
824
- protected function getTimeHtml($key, $html = "%s %s")
 
 
 
825
  {
826
  $valueKey = "{$key}_value";
827
  $unitKey = "{$key}_unit";
828
-
829
- $unitElement = $this->getSelectElement($unitKey, 'days', $this->helper()->getTimeUnitOptions());
830
- $valueElement = $this->getInputElement($valueKey);
831
-
832
- return $this->__($html,
833
- $valueElement->toHtml(),
834
- $unitElement->toHtml()
835
- );
836
- }
837
-
838
-
839
 
 
 
840
 
 
 
 
 
 
 
841
 
842
  /**
843
  * Helper for simple time html
@@ -845,6 +860,9 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
845
  * The time html consists of two form fields
846
  * a select for the unit and the value (e.g. 5 days, 6 weeks)
847
  *
 
 
 
848
  * @return string
849
  */
850
  protected function getTimeRangeHtml($key, $html = "%s to %s %s")
@@ -852,45 +870,55 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
852
  $fromKey = "{$key}_from";
853
  $toKey = "{$key}_to";
854
  $unitKey = "{$key}_unit";
855
-
856
  $unitElement = $this->getSelectElement($unitKey, 'days', $this->helper()->getTimeUnitOptions());
857
  $fromElement = $this->getInputElement($fromKey, 2);
858
  $toElement = $this->getInputElement($toKey, 5);
859
-
860
- return $this->__($html,
 
861
  $fromElement->toHtml(),
862
  $toElement->toHtml(),
863
  $unitElement->toHtml()
864
  );
865
  }
866
-
867
-
868
-
869
  /**
870
  * Retrieve time direction as boolean value
871
  * true => for future
872
  * false => for past
873
- *
874
  * @param string $key
875
  * @param string $default
 
876
  * @return boolean
877
  */
878
  protected function getTimeDirection($key, $default = null)
879
  {
880
  $dir = (string) $this->getDataSetDefault("{$key}_dir", $default);
 
881
  return ($dir === 'future');
882
  }
883
-
884
-
 
 
 
 
885
  protected function getTimeDirectionHtml($key)
886
  {
887
  $dirKey = "{$key}_dir";
888
-
889
  $unitElement = $this->getSelectElement($dirKey, 'future', $this->getTimeDirectionOptions());
 
890
  return $unitElement->getHtml();
891
  }
892
-
893
-
 
 
 
 
894
  protected function getTimeDirectionOptions()
895
  {
896
  return array(
@@ -898,13 +926,9 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
898
  'past' => $this->__('is past'),
899
  );
900
  }
901
-
902
-
903
-
904
-
905
 
906
  /**
907
- * Retrieve time range expresion from two time expr values
908
  *
909
  * value unit value unit
910
  * | | | |
@@ -915,308 +939,285 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
915
  * ...WHERE `field` BETWEEN `from` AND `to`...
916
  *
917
  * @param string|Zend_Db_Expr $field
918
- * @param string $fromKey
919
- * @param string $toKey
920
  * @param boolean $future
 
 
 
921
  * @return Zend_Db_Expr
 
922
  */
923
  protected function getTimeRangeExpr($field, $key, $future = null, $dateOnly = false, $useLocalTime = false)
924
  {
925
  $now = $this->getCurrentTime(!$useLocalTime);
926
-
927
  $fromKey = "{$key}_from";
928
  $toKey = "{$key}_to";
929
  $unitKey = "{$key}_unit";
930
-
931
- if($future === null) {
932
  $future = $this->getTimeDirection($key);
933
  }
934
-
935
  $from = (float) $this->getData($fromKey);
936
  $to = (float) $this->getData($toKey);
937
  $unit = (string) $this->getData($unitKey);
938
  // days => DAY, weeks => WEEK,...
939
  $unit = substr(strtoupper($unit), 0, -1);
940
-
941
- if(!preg_match('/^[A-Z]+$/', $unit)) {
942
  throw new Exception("Invalid time unit ($unit)");
943
  }
944
-
945
  $func = $future ? 'DATE_ADD' : 'DATE_SUB';
946
-
947
  $limits = array();
948
- if(is_array($now)) {
949
- foreach($now as $date) {
950
  // $date = $gmtOffset ? $this->addGmtOffset($date) : $date;
951
  $limits[] = "$func($date, INTERVAL $from $unit)";
952
  $limits[] = "$func($date, INTERVAL $to $unit)";
953
  }
954
- }
955
- else {
956
  //$now = $gmtOffset ? $this->addGmtOffset($now) : $date;
957
  $limits[] = "$func($now, INTERVAL $from $unit)";
958
  $limits[] = "$func($now, INTERVAL $to $unit)";
959
  }
960
-
961
-
962
  $limits = implode(', ', $limits);
963
-
964
- if($dateOnly) {
965
  return new Zend_Db_Expr("$field BETWEEN DATE(LEAST($limits)) AND DATE(GREATEST($limits))");
966
  }
967
-
968
  return new Zend_Db_Expr("$field BETWEEN LEAST($limits) AND GREATEST($limits)");
969
-
970
  }
971
-
972
-
973
 
974
  /**
975
  * Retrieve anniversary expression
976
- *
977
  * @param string $field
978
  * @param string $key
979
  * @param boolean $future
980
- * @param boolean $applyGmtOffset
 
981
  * @return Zend_Db_Expr
982
  */
983
  protected function getAnniversaryTimeExpr($field, $key, $future = false, $fieldIsLocalTime = false)
984
  {
985
  // if data field is in local time, don't do any conversion
986
- if(!$fieldIsLocalTime) {
987
  $localField = $this->toLocalTime($field);
988
- }
989
- else {
990
  $localField = $field;
991
  }
992
-
993
  $currentTime = $this->getCurrentTimeExpr(false, '%s', !$future);
994
-
995
  $age = "YEAR($currentTime) - YEAR($localField)";
996
- // if we look into the future we need to add one year if the day of the year is already past
997
- if($future) {
 
998
  $age.= "+IF(DAYOFYEAR($currentTime) > DAYOFYEAR($localField),1,0)";
999
- }
1000
- // if we look into the past we need to substract a year if the day of the year is in front
1001
- else {
1002
  $age.= "-IF(DAYOFYEAR($currentTime) < DAYOFYEAR($localField),1,0)";
1003
  }
1004
-
1005
  $anniversary = "DATE_ADD($localField, INTERVAL $age YEAR)";
1006
  $anniversary = "DATE($anniversary)";
1007
-
1008
  // it needs to be at least one year old
1009
  $lastYear = $this->getCurrentTimeExpr(!$fieldIsLocalTime, 'DATE_SUB(%s, INTERVAL 6 MONTH)', $future);
1010
-
1011
-
1012
- $expr[] = "$field <= DATE($lastYear)";
1013
  $expr[] = $this->getTimeRangeExpr($anniversary, $key, $future, true, true);
1014
-
1015
  return new Zend_Db_Expr(implode(' AND ', $expr));
1016
  }
1017
-
1018
-
1019
-
1020
-
1021
-
1022
-
 
 
 
 
1023
  protected function getCurrentTimeExpr($gmt = true, $format = '%s', $max = false)
1024
  {
1025
  $results = array();
1026
- foreach($this->getCurrentTime($gmt) as $date) {
1027
  $results[] = sprintf($format, $date);
1028
  }
1029
- if($max) {
1030
  return $this->getGreatestSql($results);
1031
  }
1032
  return $this->getLeastSql($results);
1033
  }
1034
-
1035
-
1036
-
1037
-
1038
-
1039
-
1040
  protected function getLeastSql(array $data)
1041
  {
1042
- if(count($data) > 1) {
1043
  return $this->_getReadAdapter()->getLeastSql($data);
1044
  }
1045
  return $data[0];
1046
  }
1047
-
1048
-
 
 
 
 
1049
  protected function getGreatestSql(array $data)
1050
  {
1051
- if(count($data) > 1) {
1052
  return $this->_getReadAdapter()->getGreatestSql($data);
1053
  }
1054
  return $data[0];
1055
  }
1056
-
1057
-
1058
-
1059
-
1060
-
1061
-
1062
  /**
1063
  * Add gmt offset if available
1064
- *
1065
  * @param string $dateExpr
1066
  * @return string
1067
  */
1068
  protected function addGmtOffset($dateExpr)
1069
  {
1070
  $gmtOffset = (int) $this->getParam('gmt_offset', 0);
1071
- if($gmtOffset) {
1072
  $dateExpr = "DATE_SUB($dateExpr, INTERVAL $gmtOffset MINUTE)";
1073
  }
1074
  return $dateExpr;
1075
  }
1076
-
1077
-
1078
-
1079
 
1080
  /**
1081
- * Converts local date expresion to gmt time
1082
- * gmt offset
1083
  *
1084
- * @param string $dateExpr
1085
- * @return string
1086
- */
1087
- protected function toGmtTime($localDateExpr)
1088
- {
1089
- $gmtOffset = (int) $this->getParam('gmt_offset', 0);
1090
- if($gmtOffset) {
1091
- $localDateExpr = "DATE_SUB($localDateExpr, INTERVAL $gmtOffset MINUTE)";
1092
- }
1093
- return $localDateExpr;
1094
- }
1095
-
1096
-
1097
-
1098
-
1099
- /**
1100
- * Convert database field to local time by appling specified
1101
- * gmt offset
1102
  *
1103
- * @param string $dateExpr
1104
- * @return string
1105
  */
1106
- protected function toLocalTime($gmtDateExpr)
1107
  {
1108
- $gmtOffset = (int) $this->getParam('gmt_offset', 0);
1109
- if($gmtOffset) {
1110
- $gmtDateExpr = "DATE_SUB($gmtDateExpr, INTERVAL $gmtOffset MINUTE)";
1111
- }
1112
- return $gmtDateExpr;
1113
  }
1114
-
1115
-
1116
-
1117
-
1118
-
1119
  /**
1120
- * Retrieve date value
1121
- *
1122
  * @param string $key
1123
- * @param integer $roundDate
1124
- * @return Zend_Date
 
 
1125
  */
1126
- protected function getTimeValue($key, $roundDate = false)
1127
- {
1128
- return $this->helper()->calcDate(
1129
- (int) $this->getData("{$key}_value"),
1130
- (string) $this->getData("{$key}_unit"),
1131
- $roundDate);
1132
- }
1133
-
1134
-
1135
-
1136
-
1137
-
1138
-
1139
-
1140
- protected function getTimeExpr($key, $field, $substract = false)
1141
  {
1142
- $value = (float) $this->getData("{$key}_value");
1143
- $unit = (string) $this->getData("{$key}_unit");
1144
-
1145
  $unit = substr(strtoupper($unit), 0, -1);
1146
-
1147
- $func = $substract ? 'DATE_SUB' : 'DATE_ADD';
1148
-
1149
  return new Zend_Db_Expr("$func($field, INTERVAL $value $unit)");
1150
  }
1151
-
1152
-
1153
 
1154
-
1155
-
 
 
 
 
 
 
1156
  protected function getInputHtml($key, $type = "string", $default = null, $html = null)
1157
  {
1158
  $operations = $this->helper()->getOperatorOptionsByType($type);
1159
-
1160
- $defaultOpertator = '{}';
1161
- if($type === 'numeric') {
1162
- $defaultOpertator = '==';
1163
- if($default === null) {
1164
  $default = '1';
1165
  }
1166
- if($html === null) {
1167
  $html = '%s %s';
1168
  }
1169
  }
1170
-
1171
- if($html === null) {
1172
  $html = '%s "%s"';
1173
  }
1174
-
1175
-
1176
- $operatorElment = $this->getSelectElement($key . '_operator', $defaultOpertator, $operations);
1177
  $inputElement = $this->getInputElement($key, $default);
1178
-
1179
- if($type === 'numeric') {
1180
- //$inputElement->addClass(''); numeric validation?
1181
- }
1182
-
1183
- return $this->__($html,
1184
- $operatorElment->toHtml(),
1185
  $inputElement->toHtml()
1186
  );
1187
  }
1188
-
1189
-
1190
-
 
 
 
 
 
 
 
 
 
1191
  protected function getWhereSql($key, $field, $quoteField = null)
1192
  {
1193
  $adapter = $this->_getReadAdapter();
1194
-
1195
- if($quoteField) {
1196
  $field = str_replace('?', $adapter->quoteIdentifier($quoteField), $field);
1197
  }
1198
-
1199
  $value = $this->getData($key);
1200
  $operator = $this->getDataSetDefault($key . '_operator', '{}');
1201
-
1202
- switch($operator) {
1203
- case '!=':
1204
- case '>=':
1205
- case '<=':
1206
- case '>':
1207
- case '<': return $adapter->quoteInto("{$field} {$operator} ?", $value);
1208
- case '{}': return $adapter->quoteInto("{$field} LIKE ?", "%$value%");
1209
- case '!{}': return $adapter->quoteInto("{$field} NOT LIKE ?", "%$value%");
1210
- case '()': return $adapter->quoteInto("{$field} IN (?)", $this->_explode($value));
1211
- case '!()': return $adapter->quoteInto("{$field} NOT IN (?)", $this->_explode($value));
1212
- default: return $adapter->quoteInto("{$field} = ?", $value);
 
 
 
 
 
 
 
1213
  }
1214
- }
1215
-
1216
-
1217
  /**
1218
  * Check if where select would match zero
1219
- *
1220
  * @param string $key
1221
  * @return boolean
1222
  */
@@ -1224,28 +1225,38 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
1224
  {
1225
  return (bool) $this->_getReadAdapter()->fetchOne("SELECT ".$this->getWhereSql($key, '0'));
1226
  }
1227
-
1228
-
 
 
 
 
 
1229
  protected function _explode($string, $delimiter = ',')
1230
  {
1231
- if(is_array($string)) {
1232
  return $string;
1233
  }
1234
  return array_map('trim', explode($delimiter, $string));
1235
  }
1236
-
1237
-
 
 
 
 
 
1238
  protected function _implode($string, $glue = ',')
1239
  {
1240
- if(is_array($string)) {
1241
  return implode($glue, $string);
1242
  }
1243
  return $string;
1244
  }
1245
-
1246
-
1247
-
1248
 
 
 
 
1249
  protected function getAggregatorOptions()
1250
  {
1251
  return array(
@@ -1253,8 +1264,10 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
1253
  'all' => $this->__('ALL'),
1254
  );
1255
  }
1256
-
1257
-
 
 
1258
  protected function getExpectationOptions()
1259
  {
1260
  return array(
@@ -1262,13 +1275,6 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
1262
  'false' => $this->__('FALSE'),
1263
  );
1264
  }
1265
-
1266
-
1267
-
1268
-
1269
-
1270
-
1271
-
1272
 
1273
  /**
1274
  * Use SQL UNION to combine all conditions into one
@@ -1277,67 +1283,57 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
1277
  * @param array $conditions
1278
  * @param string $aggregator
1279
  * @param string $expectation
 
1280
  * @return Mzax_Emarketing_Db_Select
1281
  */
1282
- protected function _combineConditions($conditions, $aggregator, $expectation, $alias = 'combine')
1283
  {
1284
- if(empty($conditions)) {
1285
  return $this->getQuery()
1286
  ->setColumn('matches', new Zend_Db_Expr('0'));
1287
  }
1288
-
1289
  $negate = ($expectation === 'false');
1290
-
1291
  // if negate, add all options to query
1292
- if($negate) {
1293
  $conditions[] = $this->getQuery();
1294
  }
1295
-
1296
  $conditionCount = count($conditions);
1297
-
1298
- if($conditionCount === 1) {
1299
  $select = $conditions[0];
1300
- }
1301
- else {
1302
  $select = $this->_select()->union($conditions, Zend_Db_Select::SQL_UNION_ALL);
1303
  }
1304
-
1305
  $select = $this->_select($select, 'combine_union', $select::SQL_WILDCARD);
1306
  $select->group();
1307
-
1308
- if($negate) {
1309
  $select->columns(array('matches' => "$conditionCount - COUNT(*)"));
1310
- }
1311
- else {
1312
  $select->columns(array('matches' => 'COUNT(*)'));
1313
  }
1314
-
1315
- if($aggregator === 'all') {
1316
-
1317
- if($negate) { // ALL ARE FALSE
1318
  $select->having("COUNT(*) = ?", 1);
1319
- }
1320
- else {// ALL ARE TRUE
1321
  $select->having("COUNT(*) = ?", $conditionCount);
1322
  }
1323
- }
1324
- else {
1325
- if($negate) { // ANY ARE FALSE
1326
  $select->having("COUNT(*) < ?", $conditionCount);
1327
- }
1328
- else { // ANY ARE TRUE
1329
  //$select->having("COUNT(*) > ?", 0);
1330
  }
1331
  }
1332
-
1333
  return $select;
1334
  }
1335
-
1336
-
1337
-
1338
-
1339
-
1340
-
1341
  /**
1342
  * Retrieve all filter selects from
1343
  * all children
@@ -1347,61 +1343,38 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarket
1347
  protected function _getConditions()
1348
  {
1349
  $conditions = array();
1350
-
1351
  /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
1352
- foreach($this->_filters as $filter) {
1353
- if($select = $filter->getSelect()) {
1354
  $conditions[] = $select;
1355
  }
1356
  }
1357
  return $conditions;
1358
  }
1359
-
1360
 
1361
-
1362
- /**
1363
- * Negate select
1364
- *
1365
- * Return query that selects all ids but the ones from
1366
- * the given select
1367
- *
1368
- * @deprecated
1369
- * @param Zend_Db_Select $select
1370
- * @return Zend_Db_Select
1371
- *//*
1372
- protected function _negateSql($select)
1373
- {
1374
- return $this->getQuery()->where("NOT EXISTS ($select)")->getSelect();
1375
- }
1376
- */
1377
-
1378
-
1379
  /**
1380
  * Check database for indexes that the filter requires and
1381
  * if possible create any missing indexes if
1382
  * canCreateIndex() allows to do so.
1383
- *
1384
- * @param boolean $create Wheather to try to create an index or not
 
1385
  * @return true|string
1386
  */
1387
  public function checkIndexes($create = false)
1388
  {
1389
  return true;
1390
  }
1391
-
1392
 
1393
-
1394
  /**
1395
  * Check if filter can create indexes
1396
- *
1397
  * @return boolean
1398
  */
1399
  public function canCreateIndex()
1400
  {
1401
- return Mage::getStoreConfigFlag('mzax_emarketing/general/can_create_indexes');
1402
  }
1403
-
1404
-
1405
-
1406
-
1407
  }
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Abstract
22
+ */
23
  abstract class Mzax_Emarketing_Model_Object_Filter_Abstract extends Mzax_Emarketing_Model_Object_Filter_Component
24
  {
25
+ const NOT_EQUAL = '!=';
26
+ const EQUAL = '=';
27
+ const GREATER_THAN = '>';
28
+ const GREATER_OR_EQUAL_THAN = '>=';
29
+ const LESS_THAN = '<';
30
+ const LESS_OR_EQUAL_THAN = '<=';
31
+ const LIKE = '{}';
32
+ const NOT_LIKE = '!{}';
33
+ const IN = '()';
34
+ const NOT_IN = '!()';
35
 
36
  /**
37
  * Child Filters
38
  *
39
+ * @var Mzax_Emarketing_Model_Object_Filter_Abstract[]
40
  */
41
  protected $_filters = array();
42
+
 
 
43
  /**
 
44
  * @var string
45
  */
46
  protected $_formHtml;
47
+
 
 
48
  /**
49
+ * @var Varien_Data_Form
 
 
50
  */
51
+ protected $_form;
 
52
 
53
+ /**
54
+ * Mzax_Emarketing_Model_Object_Filter_Abstract constructor.
55
+ *
56
+ * @param null $config
57
+ */
58
  public function __construct($config = null)
59
  {
60
+ parent::__construct();
61
+
62
+ if ($config instanceof Mage_Core_Model_Config_Element) {
63
  $this->_prepareFilter($config);
64
  }
65
  }
66
+
67
+ /**
68
+ * Prepare filter
69
+ *
70
+ * @param Mage_Core_Model_Config_Element $config
71
+ *
72
+ * @return void
73
+ */
74
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
75
  {
76
  $this->_type = $config->getName();
77
+
78
  Mage::dispatchEvent("mzax_emarketing_email_filter_prepare", array('filter' => $this));
79
  Mage::dispatchEvent("mzax_emarketing_email_filter_prepare_" . $this->_type, array('filter' => $this));
80
  }
81
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  /**
83
  * Retrieve object
84
+ *
85
  * @return Mzax_Emarketing_Model_Object_Abstract
86
  */
87
  public function getObject()
88
  {
89
  return $this->getParentObject();
90
  }
 
 
91
 
92
  /**
93
  * Set ID
94
  *
95
  * @param string $id
96
+ *
97
+ * @return $this
98
  */
99
  public function setId($id)
100
  {
101
  $this->_id = $id;
102
+ if ($this->_filters) {
103
+ foreach ($this->_filters as $i => $filter) {
104
  $filter->setId($this->_id . '--' . ($i+1));
105
  }
106
  }
107
+
108
  return $this;
109
  }
 
110
 
111
  /**
112
  * Add child filter
113
  *
114
+ * @param string|array|Mzax_Emarketing_Model_Object_Filter_Abstract $param
115
+ * @param bool $quite
116
+ *
117
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
118
+ * @throws Mage_Exception
119
  */
120
  public function addFilter($param, $quite = true)
121
  {
122
+ if (is_string($param)) {
123
  $filter = self::getFilterFactory()->factory($param);
124
+ if (!$filter) {
125
+ if ($quite) {
126
+ return null;
127
  }
128
+
129
+ throw new Mage_Exception(
130
+ Mage::helper('mzax_emarketing')->__(
131
+ 'Failed to initialise filter with type “%s”. This filter might not be installed on your system.',
132
+ $param
133
+ )
134
+ );
135
  }
136
+ } elseif (is_array($param) && isset($param['type'])) {
 
137
  $filter = self::getFilterFactory()->factory($param['type']);
138
+ if (!$filter) {
139
+ if ($quite) {
140
+ return null;
141
  }
142
+
143
+ throw new Mage_Exception(
144
+ Mage::helper('mzax_emarketing')->__(
145
+ 'Failed to initialise filter with type “%s”. This filter might not be installed on your system.',
146
+ $param['type']
147
+ )
148
+ );
149
  }
150
+ } else {
 
151
  $filter = $param;
152
  }
153
+
154
+ if (!$filter instanceof Mzax_Emarketing_Model_Object_Filter_Abstract) {
155
  return null;
156
  }
157
+
158
+ if (!$this->acceptFilter($filter)) {
159
+ if ($quite) {
160
+ return null;
161
  }
162
+ throw new Mage_Exception(
163
+ Mage::helper('mzax_emarketing')->__(
164
+ 'Filter of type “%s” does not allow child of type %s.',
165
+ $this->getType(),
166
+ $filter->getType()
167
+ )
168
+ );
169
  }
170
+
171
  $this->_filters[] = $filter->setParent($this);
172
  $filter->setId($this->getId() . '--' . count($this->_filters));
173
+
174
+ if (is_array($param)) {
175
  $filter->load($param);
176
  }
177
+
178
  return $filter;
179
  }
180
+
 
 
181
  /**
182
+ * Retrieve all child filters
183
+ *
184
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract[]
185
  */
186
  public function getFilters()
187
  {
188
  return $this->_filters;
189
  }
190
+
 
 
191
  /**
192
  * Retrieve filter by index
193
  *
194
+ * @param int $index
195
+ *
196
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
197
  */
198
  public function getFilterByIndex($index)
199
  {
200
+ if (isset($this->_filters[$index])) {
201
  return $this->_filters[$index];
202
  }
203
+
204
  return null;
205
  }
206
+
 
 
207
  /**
208
  * Retrieve all filter options for this filter
209
+ *
210
  * @return array
211
  */
212
  public function getOptions()
213
  {
214
  return array($this->getType() => $this->getTitle());
215
  }
216
+
 
 
 
217
  /**
218
  * Retrieve Varien Data Form
219
+ *
220
  * @return Varien_Data_Form
221
  */
222
  public function getForm()
223
  {
224
+ /** @var Mzax_Emarketing_Block_Editable $elementRenderer */
225
  $elementRenderer = Mage::getBlockSingleton('mzax_emarketing/editable');
226
+
227
  $prefix = $this->getRoot()->getFormPrefix();
228
+
229
  $form = new Varien_Data_Form();
230
  $form->setHtmlIdPrefix("{$prefix}__{$this->getId()}__");
231
  $form->setFieldNameSuffix("{$prefix}[{$this->getId()}]");
232
  $form->setElementRenderer($elementRenderer);
233
+
234
  return $form;
235
  }
236
+
237
+ /**
238
+ * Reset filter
239
+ *
240
+ * @return $this
241
+ */
242
  public function reset()
243
  {
244
  $this->unsetData();
245
  $this->_filters = array();
246
  $this->_formHtml = null;
247
+
248
  return $this;
249
  }
 
 
 
 
250
 
251
  /**
252
  * Retrieve data
253
+ *
254
  * @param string $key
255
  * @param string $default
256
+ *
257
  * @return string
258
  */
259
  public function getDataSetDefault($key, $default = null)
260
  {
261
+ // check for default class constant
262
+ if ($default === null) {
263
  $const = get_class($this) . '::DEFAULT_' . strtoupper($key);
264
+ if (defined($const)) {
265
  $default = constant($const);
266
  }
267
  }
268
+
269
  return parent::getDataSetDefault($key, $default);
270
  }
271
+
272
+ /**
273
+ * Prepare parameters
274
+ *
275
+ * @return void
276
+ */
277
  public function prepareParams()
278
+ {
279
+ }
280
+
 
 
281
  /**
282
  * Load filters from data
283
+ *
284
  * @param mixed $data
285
+ * @param boolean $quite Throw en exception if a filter was not available
286
+ *
287
+ * @return $this
288
  * @throws Mage_Exception
289
+ * @throws Exception
290
  */
291
  public function load($data, $quite = true)
292
  {
293
  $this->reset();
294
+
295
+ if (empty($data)) {
296
  return $this;
297
  }
298
+
299
  // string should be a JSON
300
+ if (is_string($data)) {
301
  try {
302
  $data = Zend_Json::decode($data);
303
+ } catch (Zend_Json_Exception $e) {
 
304
  throw new Exception("Failed to decode filter json: {$e->getMessage()}", 0, $e);
305
  }
306
  }
307
+
308
+ if (is_array($data)) {
309
+ if (isset($data['filters'])) {
310
+ foreach ($data['filters'] as $filter) {
311
  $this->addFilter($filter, $quite);
312
  }
313
  unset($data['filters']);
316
  $this->prepareParams();
317
  $this->setDataChanges(false);
318
  }
319
+
320
  return $this;
321
  }
322
+
 
 
323
  /**
324
  * Load data from flat post array
325
+ *
326
  * e.g.
327
  * array(4) {
328
  * [1]=>
358
  * string(15) "not_unsubscript"
359
  * }
360
  * }
361
+ *
362
  * @param array $data
363
+ *
364
+ * @return $this
365
  */
366
  public function loadFlatArray(array $data)
367
  {
368
  $filters = array();
369
+
370
+ foreach ($data as $id => $filterData) {
 
371
  $path = explode('--', $id);
372
  $list =& $filters;
373
+
374
+ while (count($path) > 1) {
 
375
  $id = array_shift($path);
376
+ if (!isset($list[$id])) {
377
  continue 2;
378
  }
379
+ if (!isset($list[$id]['filters'])) {
380
  $list[$id]['filters'] = array();
381
  }
382
  $list =& $list[$id]['filters'];
383
  }
384
+
385
  $id = array_shift($path);
386
  $list[$id] = $filterData;
387
  }
388
+
389
+ if (!empty($filters)) {
390
  $this->load(array_shift($filters));
391
+ } else {
 
392
  $this->setData(array());
393
  $this->prepareParams();
394
  }
395
+
396
  return $this;
397
  }
 
 
 
398
 
399
  /**
400
  * Retrieve filter data as array
404
  public function asArray()
405
  {
406
  $data = $this->getData();
407
+ if ($this->_filters) {
408
  $data['filters'] = array();
409
+ foreach ($this->_filters as $filter) {
410
  $data['filters'][] = $filter->asArray();
411
  }
412
  }
413
+
414
  // not required for save
415
  unset($data['new_child']);
416
+
417
  return $data;
418
  }
419
+
 
 
420
  /**
421
  * Retrieve filter data as json
422
  *
426
  {
427
  return Zend_Json::encode($this->asArray());
428
  }
429
+
 
430
  /**
431
+ * Retrieve data for export
432
+ *
433
  * @return array
434
  */
435
  public function export()
436
  {
437
  return $this->asArray();
438
  }
439
+
 
 
 
440
  /**
441
  * Retrieve human readable filter text
442
  *
443
+ * @param string $format
444
+ *
445
+ * @return string
446
  */
447
  public function asString($format = 'html')
448
  {
449
  $form = $this->getForm();
450
+ $renderer = $form->getElementRenderer();
451
+
452
+ if ($renderer instanceof Mzax_Emarketing_Block_Editable) {
453
+ $renderer->setFormat($format);
454
+ }
455
+
456
  $html = $this->_getFormHtml($form);
457
+
458
  return $html;
459
  }
460
+
 
 
 
461
  /**
462
  * Retrieve filter as html
463
+ *
464
  * @return string
465
  */
466
  public function asHtml()
467
  {
468
  $html = $this->getFormHtml();
469
+
470
  if ($this->getId() != '1') {
471
  $html .= $this->getRemoveLinkHtml();
472
  }
473
+
474
  $result = $this->checkIndexes(false);
475
+ if (is_string($result)) {
476
  $html .= '<div class="maax-index-check">' . $result . '</div>';
477
  }
478
+
479
  $html .= $this->getChooserContainerHtml();
480
+
481
  $prefix = $this->getRoot()->getFormPrefix();
482
+
483
+ if (count($this->getAvailableFilters())) {
484
  $html .= '<ul id="'.$prefix.'__'.$this->getId().'__children" class="rule-param-children">';
485
  foreach ($this->_filters as $filter) {
486
  $html .= '<li>'.$filter->asHtml().'</li>';
487
  }
488
  $html .= '<li>'.$this->getNewChildElement()->getHtml().'</li></ul>';
489
  }
490
+
491
  return $html;
492
  }
 
493
 
494
+ /**
495
+ * Retrieve form html
496
+ *
497
+ * @return string
498
+ */
499
+ public function getFormHtml()
500
  {
501
  $form = $this->getForm();
502
+
503
  $typeField = $form->addField('type', 'hidden', array(
504
  'name' => 'type',
505
  'class' => 'hidden',
507
  'is_meta' => true,
508
  'value' => $this->getType()
509
  ));
510
+
511
  $html = $typeField->toHtml();
512
  $html .= $this->_getFormHtml($form);
513
+
514
  return $html;
515
  }
 
 
516
 
517
+ /**
518
+ * @param Varien_Data_Form $form
519
+ *
520
+ * @return string
521
+ */
522
  protected function _getFormHtml(Varien_Data_Form $form)
523
  {
524
  $this->_form = $form;
525
+
526
  return $this->prepareForm();
527
  }
528
+
529
+ /**
530
+ * Prepare form
531
+ *
532
+ * @return string
533
+ */
534
  protected function prepareForm()
535
  {
536
  return '';
537
  }
538
+
539
+ /**
540
+ * Retrieve chooser container html
541
+ *
542
+ * @return string
543
+ */
544
  public function getChooserContainerHtml()
545
  {
546
+ $url = $this->getData('chooser_url');
547
  if ($url) {
548
+ /** @var Mage_Adminhtml_Helper_Data $helper */
549
+ $helper = Mage::helper('adminhtml');
550
+ $url = $helper->getUrl($url);
551
+
552
  return '<div class="rule-chooser" url="' . $url . '"></div>';
553
  }
554
+
555
  return '';
556
  }
 
 
557
 
558
+ /**
559
+ * Retrieve title
560
+ *
561
+ * @return string
562
+ */
563
+ abstract public function getTitle();
564
+
565
  /**
566
  * Run filter query and return result
567
+ *
568
  * This method should only used for testing
569
  * and debugging
570
+ *
571
  * @return array
572
  */
573
  public function runFilterQuery()
574
  {
575
  $select = $this->getSelect();
576
+
577
+ $sql = $select->assembleAll();
578
+ $result = $this->_getReadAdapter()->query($sql);
579
+
580
  return $result;
581
  }
 
 
582
 
583
+ /**
584
+ * @param $provider
585
+ */
586
  public function beforeLoad($provider)
587
+ {
588
+ }
589
+
590
+ /**
591
+ * @param $provider
592
+ */
593
  public function afterLoad($provider)
594
+ {
595
+ }
 
 
 
 
 
 
 
596
 
597
+ /**
598
+ * Get add sub-filter link html
599
+ *
600
+ * @return string
601
+ */
602
  protected function getAddLinkHtml()
603
  {
604
  $src = Mage::getDesign()->getSkinUrl('mzax/images/add-tiny.png');
605
  $html = '<img src="' . $src . '" class="rule-param-add v-middle" alt="" title="' . $this->__('Add Filter') . '"/>';
606
+
607
  return $html;
608
  }
609
+
610
+ /**
611
+ * Get remove filter link html
612
+ *
613
+ * @return string
614
+ */
615
  protected function getRemoveLinkHtml()
616
  {
617
  $src = Mage::getDesign()->getSkinUrl('mzax/images/delete-tiny.png');
618
  $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>';
619
  return $html;
620
  }
621
+
622
+ /**
623
+ * Add choose filter link html
624
+ *
625
+ * @return string
626
+ */
627
  public function getChooserTriggerHtml()
628
  {
629
  $src = Mage::getDesign()->getSkinUrl('images/rule_chooser_trigger.gif');
630
  $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>';
631
  return $html;
632
  }
 
 
 
633
 
634
  /**
635
  * Prepare recipient collection
636
  *
637
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
638
+ *
639
  * @return void
640
  */
641
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
642
  {
643
  parent::_prepareCollection($collection);
 
644
  }
 
 
 
645
 
646
  //--------------------------------------------------------------------------
647
  //
648
  // Quick Helpers
649
  //
650
  //--------------------------------------------------------------------------
651
+
 
 
 
652
  /**
653
  * Helper for new child filter element
654
+ *
655
  * @return Varien_Data_Form_Element_Abstract
656
  */
657
  protected function getNewChildElement()
658
  {
659
  $path = $this->getTypePath() . '-';
660
+
 
661
  $filters = array();
662
+ foreach ($this->getAvailableFilters() as $type => $title) {
 
663
  $title = $this->_explode($title, '|');
664
+
665
  $list =& $filters;
666
+
667
+ while (count($title) > 1) {
668
  $n = array_shift($title);
669
+ if (!isset($list[$n])) {
670
  $list[$n] = array('label' => $n, 'value' => array());
671
  }
672
  $list =& $list[$n]['value'];
673
  }
674
+
675
  $list[] = array('value' => $path . $type, 'label' => array_shift($title));
676
  }
677
+
678
  array_unshift($filters, array('value'=>'', 'label' => $this->__('Please choose a filter to add...')));
679
+
680
  return $this->getForm()->addField('new_child', 'select', array(
681
  'name' => 'new_child',
682
  'values' => $filters,
683
  'value_name' => $this->getAddLinkHtml(),
684
  ))->setRenderer(Mage::getBlockSingleton('rule/newchild'));
685
  }
686
+
 
 
687
  /**
688
  * Helper for simple input element
689
+ *
690
  * @param string $key
691
+ * @param null $default
692
+ *
693
  * @return Varien_Data_Form_Element_Abstract
694
  */
695
  protected function getInputElement($key, $default = null)
696
  {
697
  $value = (string) $this->getDataSetDefault($key, $default);
698
+
699
+ return $this->getForm()->addField($key, 'text', array(
700
+ 'name' => $key,
701
+ 'value_name' => $value,
702
+ 'value' => $value
703
  ));
704
  }
705
+
 
 
706
  /**
707
  * Add hidden input field
708
  *
709
  * @param string $name
710
  * @param string $value
711
+ *
712
  * @return Varien_Data_Form_Element_Abstract
713
  */
714
  protected function getHiddenField($name, $value)
715
  {
716
+ return $this->getForm()->addField(
717
+ $name,
718
+ 'hidden',
719
+ array(
720
+ 'name' => $name,
721
+ 'class' => 'hidden',
722
+ 'no_span' => true,
723
+ 'is_meta' => true,
724
+ 'value' => $value
725
+ )
726
+ );
727
  }
728
+
 
 
729
  /**
730
  * Helper for simple select element
731
+ *
732
  * @param string $key
733
+ * @param null $default
734
  * @param array $options
735
+ *
736
  * @return Varien_Data_Form_Element_Abstract
737
  */
738
  protected function getSelectElement($key, $default = null, $options = null)
739
  {
740
+ if (empty($options)) {
741
  $options = $this->getDataUsingMethod($key . '_options');
742
  }
743
+
744
  $value = $this->getDataSetDefault($key, $default);
745
+ if (is_array($value)) {
746
  $value = $value[0];
747
  }
748
  $valueName = '';
749
+ if (isset($options[$value])) {
750
  $valueName = $options[$value];
751
  }
752
+
753
+ return $this->getForm()->addField($key, 'select', array(
754
+ 'name' => $key,
755
+ 'value_name' => ($valueName ? $valueName : '...'),
756
+ 'value' => $value,
757
+ 'values' => $options
758
  ));
759
  }
760
 
 
 
 
761
  /**
762
  * Helper for simple select element
763
  *
764
  * @param string $key
765
+ * @param array $default
766
+ *
767
  * @return Varien_Data_Form_Element_Abstract
768
  */
769
  public function getDateElement($key, $default = null)
770
  {
771
  $format = Varien_Date::DATE_INTERNAL_FORMAT;
772
  $value = (string) $this->getDataSetDefault($key, $default);
773
+
774
+ if (!$value) {
775
  $value = Zend_Date::now()->toString($format);
776
  }
777
+
778
  $value = Mage::app()->getLocale()->date($value, $format, null, false)->toString($format);
779
+
780
+ return $this->getForm()->addField($key, 'date', array(
781
  'name' => $key,
782
  'value_name' => $value,
783
+ 'value' => $value,
784
  'explicit_apply' => true,
785
  'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'),
786
  'input_format' => $format,
787
  'format' => $format
788
  ));
789
  }
790
+
 
791
  /**
792
  * Helper for simple select element
793
  *
794
  * @param string $key
795
+ * @param null $default
796
+ * @param array $optionHash
797
+ *
798
  * @return Varien_Data_Form_Element_Abstract
799
  */
800
+ protected function getMultiSelectElement($key, $default = null, $optionHash = null)
801
  {
802
+ if (empty($optionHash)) {
803
  $optionHash = $this->getDataUsingMethod($key . '_options');
804
  }
805
+
806
  $values = $this->getDataSetDefault($key, $default);
807
+ if (is_string($values)) {
808
  $values = $this->_explode($values);
809
  }
810
+ if (empty($values)) {
811
  $values = array();
812
  }
813
+
814
  $valueName = array();
815
  $options = array();
816
+ foreach ($optionHash as $value => $option) {
817
  $options[] = array('value' => $value, 'label' => $option);
818
+ if (in_array($value, $values)) {
819
  $valueName[] = $option;
820
  }
821
  }
822
+
823
+ return $this->getForm()->addField($key, 'multiselect', array(
824
  'name' => $key,
825
  'value_name' => implode(', ', $valueName),
826
+ 'value' => $values,
827
+ 'values' => $options
828
  ));
829
  }
830
+
831
+ /**
 
 
 
 
 
 
832
  * Helper for simple time html
833
+ *
834
  * The time html consists of two form fields
835
+ * a select for the unit and the value (e.g. 5 days, 6 weeks)
836
+ *
837
+ * @param string $key
838
+ * @param string $html
839
+ *
840
+ * @return string
841
+ */
842
+ protected function getTimeHtml($key, $html = "%s %s")
843
  {
844
  $valueKey = "{$key}_value";
845
  $unitKey = "{$key}_unit";
 
 
 
 
 
 
 
 
 
 
 
846
 
847
+ $unitElement = $this->getSelectElement($unitKey, 'days', $this->helper()->getTimeUnitOptions());
848
+ $valueElement = $this->getInputElement($valueKey);
849
 
850
+ return $this->__(
851
+ $html,
852
+ $valueElement->toHtml(),
853
+ $unitElement->toHtml()
854
+ );
855
+ }
856
 
857
  /**
858
  * Helper for simple time html
860
  * The time html consists of two form fields
861
  * a select for the unit and the value (e.g. 5 days, 6 weeks)
862
  *
863
+ * @param string $key
864
+ * @param string $html
865
+ *
866
  * @return string
867
  */
868
  protected function getTimeRangeHtml($key, $html = "%s to %s %s")
870
  $fromKey = "{$key}_from";
871
  $toKey = "{$key}_to";
872
  $unitKey = "{$key}_unit";
873
+
874
  $unitElement = $this->getSelectElement($unitKey, 'days', $this->helper()->getTimeUnitOptions());
875
  $fromElement = $this->getInputElement($fromKey, 2);
876
  $toElement = $this->getInputElement($toKey, 5);
877
+
878
+ return $this->__(
879
+ $html,
880
  $fromElement->toHtml(),
881
  $toElement->toHtml(),
882
  $unitElement->toHtml()
883
  );
884
  }
885
+
 
 
886
  /**
887
  * Retrieve time direction as boolean value
888
  * true => for future
889
  * false => for past
890
+ *
891
  * @param string $key
892
  * @param string $default
893
+ *
894
  * @return boolean
895
  */
896
  protected function getTimeDirection($key, $default = null)
897
  {
898
  $dir = (string) $this->getDataSetDefault("{$key}_dir", $default);
899
+
900
  return ($dir === 'future');
901
  }
902
+
903
+ /**
904
+ * @param string $key
905
+ *
906
+ * @return mixed|string
907
+ */
908
  protected function getTimeDirectionHtml($key)
909
  {
910
  $dirKey = "{$key}_dir";
911
+
912
  $unitElement = $this->getSelectElement($dirKey, 'future', $this->getTimeDirectionOptions());
913
+
914
  return $unitElement->getHtml();
915
  }
916
+
917
+ /**
918
+ * Time direction options
919
+ *
920
+ * @return string[]
921
+ */
922
  protected function getTimeDirectionOptions()
923
  {
924
  return array(
926
  'past' => $this->__('is past'),
927
  );
928
  }
 
 
 
 
929
 
930
  /**
931
+ * Retrieve time range expression from two time expr values
932
  *
933
  * value unit value unit
934
  * | | | |
939
  * ...WHERE `field` BETWEEN `from` AND `to`...
940
  *
941
  * @param string|Zend_Db_Expr $field
942
+ * @param $key
 
943
  * @param boolean $future
944
+ * @param bool $dateOnly
945
+ * @param bool $useLocalTime
946
+ *
947
  * @return Zend_Db_Expr
948
+ * @throws Exception
949
  */
950
  protected function getTimeRangeExpr($field, $key, $future = null, $dateOnly = false, $useLocalTime = false)
951
  {
952
  $now = $this->getCurrentTime(!$useLocalTime);
953
+
954
  $fromKey = "{$key}_from";
955
  $toKey = "{$key}_to";
956
  $unitKey = "{$key}_unit";
957
+
958
+ if ($future === null) {
959
  $future = $this->getTimeDirection($key);
960
  }
961
+
962
  $from = (float) $this->getData($fromKey);
963
  $to = (float) $this->getData($toKey);
964
  $unit = (string) $this->getData($unitKey);
965
  // days => DAY, weeks => WEEK,...
966
  $unit = substr(strtoupper($unit), 0, -1);
967
+
968
+ if (!preg_match('/^[A-Z]+$/', $unit)) {
969
  throw new Exception("Invalid time unit ($unit)");
970
  }
971
+
972
  $func = $future ? 'DATE_ADD' : 'DATE_SUB';
973
+
974
  $limits = array();
975
+ if (is_array($now)) {
976
+ foreach ($now as $date) {
977
  // $date = $gmtOffset ? $this->addGmtOffset($date) : $date;
978
  $limits[] = "$func($date, INTERVAL $from $unit)";
979
  $limits[] = "$func($date, INTERVAL $to $unit)";
980
  }
981
+ } else {
 
982
  //$now = $gmtOffset ? $this->addGmtOffset($now) : $date;
983
  $limits[] = "$func($now, INTERVAL $from $unit)";
984
  $limits[] = "$func($now, INTERVAL $to $unit)";
985
  }
986
+
 
987
  $limits = implode(', ', $limits);
988
+
989
+ if ($dateOnly) {
990
  return new Zend_Db_Expr("$field BETWEEN DATE(LEAST($limits)) AND DATE(GREATEST($limits))");
991
  }
992
+
993
  return new Zend_Db_Expr("$field BETWEEN LEAST($limits) AND GREATEST($limits)");
 
994
  }
 
 
995
 
996
  /**
997
  * Retrieve anniversary expression
998
+ *
999
  * @param string $field
1000
  * @param string $key
1001
  * @param boolean $future
1002
+ * @param boolean $fieldIsLocalTime
1003
+ *
1004
  * @return Zend_Db_Expr
1005
  */
1006
  protected function getAnniversaryTimeExpr($field, $key, $future = false, $fieldIsLocalTime = false)
1007
  {
1008
  // if data field is in local time, don't do any conversion
1009
+ if (!$fieldIsLocalTime) {
1010
  $localField = $this->toLocalTime($field);
1011
+ } else {
 
1012
  $localField = $field;
1013
  }
1014
+
1015
  $currentTime = $this->getCurrentTimeExpr(false, '%s', !$future);
1016
+
1017
  $age = "YEAR($currentTime) - YEAR($localField)";
1018
+
1019
+ if ($future) {
1020
+ // if we look into the future we need to add one year if the day of the year is already past
1021
  $age.= "+IF(DAYOFYEAR($currentTime) > DAYOFYEAR($localField),1,0)";
1022
+ } else {
1023
+ // if we look into the past we need to substract a year if the day of the year is in front
 
1024
  $age.= "-IF(DAYOFYEAR($currentTime) < DAYOFYEAR($localField),1,0)";
1025
  }
1026
+
1027
  $anniversary = "DATE_ADD($localField, INTERVAL $age YEAR)";
1028
  $anniversary = "DATE($anniversary)";
1029
+
1030
  // it needs to be at least one year old
1031
  $lastYear = $this->getCurrentTimeExpr(!$fieldIsLocalTime, 'DATE_SUB(%s, INTERVAL 6 MONTH)', $future);
1032
+
1033
+
1034
+ $expr[] = "$field <= DATE($lastYear)";
1035
  $expr[] = $this->getTimeRangeExpr($anniversary, $key, $future, true, true);
1036
+
1037
  return new Zend_Db_Expr(implode(' AND ', $expr));
1038
  }
1039
+
1040
+ /**
1041
+ * Retrieve current time expression
1042
+ *
1043
+ * @param bool $gmt
1044
+ * @param string $format
1045
+ * @param bool $max
1046
+ *
1047
+ * @return mixed|Zend_Db_Expr
1048
+ */
1049
  protected function getCurrentTimeExpr($gmt = true, $format = '%s', $max = false)
1050
  {
1051
  $results = array();
1052
+ foreach ($this->getCurrentTime($gmt) as $date) {
1053
  $results[] = sprintf($format, $date);
1054
  }
1055
+ if ($max) {
1056
  return $this->getGreatestSql($results);
1057
  }
1058
  return $this->getLeastSql($results);
1059
  }
1060
+
1061
+ /**
1062
+ * @param array $data
1063
+ *
1064
+ * @return mixed|Zend_Db_Expr
1065
+ */
1066
  protected function getLeastSql(array $data)
1067
  {
1068
+ if (count($data) > 1) {
1069
  return $this->_getReadAdapter()->getLeastSql($data);
1070
  }
1071
  return $data[0];
1072
  }
1073
+
1074
+ /**
1075
+ * @param array $data
1076
+ *
1077
+ * @return mixed|Zend_Db_Expr
1078
+ */
1079
  protected function getGreatestSql(array $data)
1080
  {
1081
+ if (count($data) > 1) {
1082
  return $this->_getReadAdapter()->getGreatestSql($data);
1083
  }
1084
  return $data[0];
1085
  }
1086
+
 
 
 
 
 
1087
  /**
1088
  * Add gmt offset if available
1089
+ *
1090
  * @param string $dateExpr
1091
  * @return string
1092
  */
1093
  protected function addGmtOffset($dateExpr)
1094
  {
1095
  $gmtOffset = (int) $this->getParam('gmt_offset', 0);
1096
+ if ($gmtOffset) {
1097
  $dateExpr = "DATE_SUB($dateExpr, INTERVAL $gmtOffset MINUTE)";
1098
  }
1099
  return $dateExpr;
1100
  }
 
 
 
1101
 
1102
  /**
1103
+ * Retrieve date value
 
1104
  *
1105
+ * @param string $key
1106
+ * @param int $roundDate
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1107
  *
1108
+ * @return Zend_Date
 
1109
  */
1110
+ protected function getTimeValue($key, $roundDate = 0)
1111
  {
1112
+ return $this->helper()->calcDate(
1113
+ (int)$this->getData("{$key}_value"),
1114
+ (string)$this->getData("{$key}_unit"),
1115
+ $roundDate
1116
+ );
1117
  }
1118
+
 
 
 
 
1119
  /**
 
 
1120
  * @param string $key
1121
+ * @param string $field
1122
+ * @param bool $subtract
1123
+ *
1124
+ * @return Zend_Db_Expr
1125
  */
1126
+ protected function getTimeExpr($key, $field, $subtract = false)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1127
  {
1128
+ $value = (float)$this->getData("{$key}_value");
1129
+ $unit = (string)$this->getData("{$key}_unit");
1130
+
1131
  $unit = substr(strtoupper($unit), 0, -1);
1132
+
1133
+ $func = $subtract ? 'DATE_SUB' : 'DATE_ADD';
1134
+
1135
  return new Zend_Db_Expr("$func($field, INTERVAL $value $unit)");
1136
  }
 
 
1137
 
1138
+ /**
1139
+ * @param $key
1140
+ * @param string $type
1141
+ * @param null $default
1142
+ * @param null $html
1143
+ *
1144
+ * @return string
1145
+ */
1146
  protected function getInputHtml($key, $type = "string", $default = null, $html = null)
1147
  {
1148
  $operations = $this->helper()->getOperatorOptionsByType($type);
1149
+
1150
+ $defaultOperator = '{}';
1151
+ if ($type === 'numeric') {
1152
+ $defaultOperator = '==';
1153
+ if ($default === null) {
1154
  $default = '1';
1155
  }
1156
+ if ($html === null) {
1157
  $html = '%s %s';
1158
  }
1159
  }
1160
+
1161
+ if ($html === null) {
1162
  $html = '%s "%s"';
1163
  }
1164
+
1165
+ $operatorElement = $this->getSelectElement($key . '_operator', $defaultOperator, $operations);
 
1166
  $inputElement = $this->getInputElement($key, $default);
1167
+
1168
+ return $this->__(
1169
+ $html,
1170
+ $operatorElement->toHtml(),
 
 
 
1171
  $inputElement->toHtml()
1172
  );
1173
  }
1174
+
1175
+ /**
1176
+ * Create where sql string for a given data field
1177
+ *
1178
+ * Field value ($key) and operator ($key_operator) can be defined.
1179
+ *
1180
+ * @param string $key
1181
+ * @param string $field
1182
+ * @param null $quoteField
1183
+ *
1184
+ * @return string
1185
+ */
1186
  protected function getWhereSql($key, $field, $quoteField = null)
1187
  {
1188
  $adapter = $this->_getReadAdapter();
1189
+
1190
+ if ($quoteField) {
1191
  $field = str_replace('?', $adapter->quoteIdentifier($quoteField), $field);
1192
  }
1193
+
1194
  $value = $this->getData($key);
1195
  $operator = $this->getDataSetDefault($key . '_operator', '{}');
1196
+
1197
+ switch ($operator) {
1198
+ case self::NOT_EQUAL:
1199
+ case self::EQUAL:
1200
+ case self::GREATER_THAN:
1201
+ case self::GREATER_OR_EQUAL_THAN:
1202
+ case self::LESS_THAN:
1203
+ case self::LESS_OR_EQUAL_THAN:
1204
+ return $adapter->quoteInto("{$field} {$operator} ?", $value);
1205
+ case self::LIKE:
1206
+ return $adapter->quoteInto("{$field} LIKE ?", "%$value%");
1207
+ case self::NOT_LIKE:
1208
+ return $adapter->quoteInto("{$field} NOT LIKE ?", "%$value%");
1209
+ case self::IN:
1210
+ return $adapter->quoteInto("{$field} IN (?)", $this->_explode($value));
1211
+ case self::NOT_IN:
1212
+ return $adapter->quoteInto("{$field} NOT IN (?)", $this->_explode($value));
1213
+ default:
1214
+ return $adapter->quoteInto("{$field} = ?", $value);
1215
  }
1216
+ }
1217
+
 
1218
  /**
1219
  * Check if where select would match zero
1220
+ *
1221
  * @param string $key
1222
  * @return boolean
1223
  */
1225
  {
1226
  return (bool) $this->_getReadAdapter()->fetchOne("SELECT ".$this->getWhereSql($key, '0'));
1227
  }
1228
+
1229
+ /**
1230
+ * @param $string
1231
+ * @param string $delimiter
1232
+ *
1233
+ * @return array
1234
+ */
1235
  protected function _explode($string, $delimiter = ',')
1236
  {
1237
+ if (is_array($string)) {
1238
  return $string;
1239
  }
1240
  return array_map('trim', explode($delimiter, $string));
1241
  }
1242
+
1243
+ /**
1244
+ * @param $string
1245
+ * @param string $glue
1246
+ *
1247
+ * @return string
1248
+ */
1249
  protected function _implode($string, $glue = ',')
1250
  {
1251
+ if (is_array($string)) {
1252
  return implode($glue, $string);
1253
  }
1254
  return $string;
1255
  }
 
 
 
1256
 
1257
+ /**
1258
+ * @return string[]
1259
+ */
1260
  protected function getAggregatorOptions()
1261
  {
1262
  return array(
1264
  'all' => $this->__('ALL'),
1265
  );
1266
  }
1267
+
1268
+ /**
1269
+ * @return string[]
1270
+ */
1271
  protected function getExpectationOptions()
1272
  {
1273
  return array(
1275
  'false' => $this->__('FALSE'),
1276
  );
1277
  }
 
 
 
 
 
 
 
1278
 
1279
  /**
1280
  * Use SQL UNION to combine all conditions into one
1283
  * @param array $conditions
1284
  * @param string $aggregator
1285
  * @param string $expectation
1286
+ *
1287
  * @return Mzax_Emarketing_Db_Select
1288
  */
1289
+ protected function _combineConditions($conditions, $aggregator, $expectation)
1290
  {
1291
+ if (empty($conditions)) {
1292
  return $this->getQuery()
1293
  ->setColumn('matches', new Zend_Db_Expr('0'));
1294
  }
1295
+
1296
  $negate = ($expectation === 'false');
1297
+
1298
  // if negate, add all options to query
1299
+ if ($negate) {
1300
  $conditions[] = $this->getQuery();
1301
  }
1302
+
1303
  $conditionCount = count($conditions);
1304
+
1305
+ if ($conditionCount === 1) {
1306
  $select = $conditions[0];
1307
+ } else {
 
1308
  $select = $this->_select()->union($conditions, Zend_Db_Select::SQL_UNION_ALL);
1309
  }
1310
+
1311
  $select = $this->_select($select, 'combine_union', $select::SQL_WILDCARD);
1312
  $select->group();
1313
+
1314
+ if ($negate) {
1315
  $select->columns(array('matches' => "$conditionCount - COUNT(*)"));
1316
+ } else {
 
1317
  $select->columns(array('matches' => 'COUNT(*)'));
1318
  }
1319
+
1320
+ if ($aggregator === 'all') {
1321
+ if ($negate) { // ALL ARE FALSE
 
1322
  $select->having("COUNT(*) = ?", 1);
1323
+ } else {// ALL ARE TRUE
 
1324
  $select->having("COUNT(*) = ?", $conditionCount);
1325
  }
1326
+ } else {
1327
+ if ($negate) { // ANY ARE FALSE
 
1328
  $select->having("COUNT(*) < ?", $conditionCount);
1329
+ } else { // ANY ARE TRUE
 
1330
  //$select->having("COUNT(*) > ?", 0);
1331
  }
1332
  }
1333
+
1334
  return $select;
1335
  }
1336
+
 
 
 
 
 
1337
  /**
1338
  * Retrieve all filter selects from
1339
  * all children
1343
  protected function _getConditions()
1344
  {
1345
  $conditions = array();
1346
+
1347
  /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
1348
+ foreach ($this->_filters as $filter) {
1349
+ if ($select = $filter->getSelect()) {
1350
  $conditions[] = $select;
1351
  }
1352
  }
1353
  return $conditions;
1354
  }
 
1355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1356
  /**
1357
  * Check database for indexes that the filter requires and
1358
  * if possible create any missing indexes if
1359
  * canCreateIndex() allows to do so.
1360
+ *
1361
+ * @param boolean $create Whether to try to create an index or not
1362
+ *
1363
  * @return true|string
1364
  */
1365
  public function checkIndexes($create = false)
1366
  {
1367
  return true;
1368
  }
 
1369
 
 
1370
  /**
1371
  * Check if filter can create indexes
1372
+ *
1373
  * @return boolean
1374
  */
1375
  public function canCreateIndex()
1376
  {
1377
+ return $this->_config->flag('mzax_emarketing/general/can_create_indexes');
1378
  }
 
 
 
 
1379
  }
1380
+
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/City.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,38 +17,31 @@
18
  */
19
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Address_City
26
  extends Mzax_Emarketing_Model_Object_Filter_Column
27
  {
28
-
29
-
 
30
  protected $_formText = '%s %s %s.';
31
-
32
-
33
  /**
34
- *
35
  * @var string
36
  */
37
  protected $_requireBinding = 'city';
38
-
39
-
40
-
 
41
  protected $_label = 'City';
42
-
43
-
44
-
45
-
46
 
 
 
 
47
  public function getTitle()
48
  {
49
  return "Address | City";
50
  }
51
-
52
-
53
-
54
-
55
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Address_City
 
 
21
  */
22
  class Mzax_Emarketing_Model_Object_Filter_Address_City
23
  extends Mzax_Emarketing_Model_Object_Filter_Column
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_formText = '%s %s %s.';
29
+
 
30
  /**
 
31
  * @var string
32
  */
33
  protected $_requireBinding = 'city';
34
+
35
+ /**
36
+ * @var string
37
+ */
38
  protected $_label = 'City';
 
 
 
 
39
 
40
+ /**
41
+ * @return string
42
+ */
43
  public function getTitle()
44
  {
45
  return "Address | City";
46
  }
 
 
 
 
47
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Country.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,42 +16,42 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Address_Country
26
  extends Mzax_Emarketing_Model_Object_Filter_Column
27
  {
28
-
29
-
 
30
  protected $_formText = '%s %s %s.';
31
-
32
-
33
  /**
34
  *
35
  * @var string
36
  */
37
  protected $_requireBinding = 'country_id';
38
-
39
-
40
-
 
41
  protected $_label = 'Country';
42
-
43
-
 
 
44
  protected $_inputType = 'multiselect';
45
-
46
-
47
 
 
 
 
48
  public function getTitle()
49
  {
50
  return "Address | Country";
51
  }
52
-
53
-
54
-
55
-
56
  /**
57
  * Retrieve all value options as hash
58
  *
@@ -63,17 +62,12 @@ class Mzax_Emarketing_Model_Object_Filter_Address_Country
63
  public function getValueOptions()
64
  {
65
  $array = Mage::getResourceSingleton('directory/country_collection')->toOptionArray(false);
66
-
67
  $options = array();
68
- foreach($array as $option) {
69
  $options[$option['value']] = $option['label'];
70
  }
71
-
72
  return $options;
73
  }
74
-
75
-
76
-
77
-
78
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Address_Country
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Address_Country
24
  extends Mzax_Emarketing_Model_Object_Filter_Column
25
  {
26
+ /**
27
+ * @var string
28
+ */
29
  protected $_formText = '%s %s %s.';
30
+
 
31
  /**
32
  *
33
  * @var string
34
  */
35
  protected $_requireBinding = 'country_id';
36
+
37
+ /**
38
+ * @var string
39
+ */
40
  protected $_label = 'Country';
41
+
42
+ /**
43
+ * @var string
44
+ */
45
  protected $_inputType = 'multiselect';
 
 
46
 
47
+ /**
48
+ * @return string
49
+ */
50
  public function getTitle()
51
  {
52
  return "Address | Country";
53
  }
54
+
 
 
 
55
  /**
56
  * Retrieve all value options as hash
57
  *
62
  public function getValueOptions()
63
  {
64
  $array = Mage::getResourceSingleton('directory/country_collection')->toOptionArray(false);
65
+
66
  $options = array();
67
+ foreach ($array as $option) {
68
  $options[$option['value']] = $option['label'];
69
  }
70
+
71
  return $options;
72
  }
 
 
 
 
 
73
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Postcode.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,38 +17,31 @@
18
  */
19
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Address_Postcode
26
  extends Mzax_Emarketing_Model_Object_Filter_Column
27
  {
28
-
29
-
 
30
  protected $_formText = '%s %s %s.';
31
-
32
-
33
  /**
34
- *
35
  * @var string
36
  */
37
  protected $_requireBinding = 'postcode';
38
-
39
-
40
-
 
41
  protected $_label = 'Postcode';
42
-
43
-
44
-
45
-
46
 
 
 
 
47
  public function getTitle()
48
  {
49
  return "Address | Postcode";
50
  }
51
-
52
-
53
-
54
-
55
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Address_Postcode
 
 
21
  */
22
  class Mzax_Emarketing_Model_Object_Filter_Address_Postcode
23
  extends Mzax_Emarketing_Model_Object_Filter_Column
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_formText = '%s %s %s.';
29
+
 
30
  /**
 
31
  * @var string
32
  */
33
  protected $_requireBinding = 'postcode';
34
+
35
+ /**
36
+ * @var string
37
+ */
38
  protected $_label = 'Postcode';
 
 
 
 
39
 
40
+ /**
41
+ * @return string
42
+ */
43
  public function getTitle()
44
  {
45
  return "Address | Postcode";
46
  }
 
 
 
 
47
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Region.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,39 +16,33 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Address_Region
26
  extends Mzax_Emarketing_Model_Object_Filter_Column
27
  {
28
-
29
-
 
30
  protected $_formText = '%s %s %s.';
31
-
32
-
33
  /**
34
- *
35
  * @var string
36
  */
37
  protected $_requireBinding = 'region';
38
-
39
-
40
-
 
41
  protected $_label = 'Region';
42
-
43
-
44
-
45
-
46
 
 
 
 
47
  public function getTitle()
48
  {
49
  return "Address | Region";
50
  }
51
-
52
-
53
-
54
-
55
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Address_Region
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Address_Region
24
  extends Mzax_Emarketing_Model_Object_Filter_Column
25
  {
26
+ /**
27
+ * @var string
28
+ */
29
  protected $_formText = '%s %s %s.';
30
+
 
31
  /**
 
32
  * @var string
33
  */
34
  protected $_requireBinding = 'region';
35
+
36
+ /**
37
+ * @var string
38
+ */
39
  protected $_label = 'Region';
 
 
 
 
40
 
41
+ /**
42
+ * @return string
43
+ */
44
  public function getTitle()
45
  {
46
  return "Address | Region";
47
  }
 
 
 
 
48
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Address/Street.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,39 +16,33 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Address_Street
26
  extends Mzax_Emarketing_Model_Object_Filter_Column
27
  {
28
-
29
-
 
30
  protected $_formText = '%s %s %s.';
31
-
32
-
33
  /**
34
- *
35
  * @var string
36
  */
37
  protected $_requireBinding = 'street';
38
-
39
-
40
-
 
41
  protected $_label = 'Street';
42
-
43
-
44
-
45
-
46
 
 
 
 
47
  public function getTitle()
48
  {
49
  return "Address | Street";
50
  }
51
-
52
-
53
-
54
-
55
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Address_Street
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Address_Street
24
  extends Mzax_Emarketing_Model_Object_Filter_Column
25
  {
26
+ /**
27
+ * @var string
28
+ */
29
  protected $_formText = '%s %s %s.';
30
+
 
31
  /**
 
32
  * @var string
33
  */
34
  protected $_requireBinding = 'street';
35
+
36
+ /**
37
+ * @var string
38
+ */
39
  protected $_label = 'Street';
 
 
 
 
40
 
41
+ /**
42
+ * @return string
43
+ */
44
  public function getTitle()
45
  {
46
  return "Address | Street";
47
  }
 
 
 
 
48
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Attribute.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,178 +17,184 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
- * Abstract Attribute filter
25
- *
26
  * Define the entity type code and the required binding
27
  * and it will generate filters for all attributes
28
- *
29
  * use method isAttributeAllowed() for fine tuning
30
- *
31
  *
32
- * @author Jacob Siefer
33
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
- * @version 0.4.10
 
 
 
 
 
 
 
 
35
  */
36
  abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
37
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
38
  {
39
-
40
  const VALUE_KEY = 'value';
41
-
42
-
43
-
 
44
  /**
45
- *
46
  * @var Mage_Catalog_Model_Resource_Eav_Attribute
47
  */
48
  protected $_attribute;
49
-
50
-
51
-
52
  /**
53
- *
54
  * @var string
55
  */
56
  protected $_entity;
57
 
58
-
59
  /**
60
- *
61
  * @var string
62
  */
63
  protected $_requireBinding;
64
-
65
-
66
-
 
67
  protected $_attributeConfigs = array();
68
-
69
 
 
 
 
 
 
70
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
71
  {
72
  return $parent->hasBinding($this->_requireBinding);
73
  }
74
-
75
-
76
-
 
77
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
78
  {
79
- if(isset($config->attributes)) {
80
- /* @var $attrCfg Mage_Core_Model_Config_Element */
81
- foreach($config->attributes->children() as $code => $cfg) {
82
  $this->_attributeConfigs[$code] = $cfg->asCanonicalArray();
83
  }
84
  }
85
  parent::_prepareFilter($config);
86
  }
87
-
88
-
89
-
90
  /**
91
  * Retrieve attribute config value
92
- *
93
  * @param string $attribute
94
  * @param string $key
95
  * @param mixed $default
 
96
  * @return mixed
97
  */
98
  protected function getAttributeConfig($attribute, $key, $default = null)
99
  {
100
- if($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) {
101
  $attribute = $attribute->getAttributeCode();
102
  }
103
- if(isset($this->_attributeConfigs[$attribute][$key])) {
104
  return $this->_attributeConfigs[$attribute][$key];
105
  }
106
  return $default;
107
  }
108
-
109
-
110
-
111
-
112
-
 
113
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
114
  {
115
  $attribute = $this->getAttribute();
116
- $adapter = $query->getAdapter();
117
- $field = $query->joinAttribute($this->_requireBinding, $attribute, true);
118
-
119
  $query->addBinding('attribute_value', $field);
120
  $query->group();
121
 
122
- $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
123
- $value = $this->getData(self::VALUE_KEY);
124
-
125
-
126
-
127
- /*
128
- * Relative data attributes
129
- */
130
- if($this->getData('relative')) {
131
-
132
- $future = $this->getDirection() == 'future';
133
  $usesLocalTime = (bool) $this->getAttributeConfig($attribute, 'uses_local_time', false);
134
-
135
- if($this->getAnniversary()) {
136
  $query->where($this->getAnniversaryTimeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
137
- }
138
- else {
139
  $query->where($this->getTimeRangeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
140
  }
141
  return;
142
  }
143
-
144
-
145
-
146
  /*
147
  * Multi select attributes are saved as list in varchar
148
  * (e.g. 123,1457,124,21)
149
- *
150
  * @todo can we use an index?
151
  */
152
- if($attribute->getFrontendInput() === 'multiselect')
153
- {
154
  $value = (array) $value;
155
  $where = array();
156
- foreach($value as $v) {
157
  $where[] = $adapter->quoteInto("FIND_IN_SET(?, {attribute_value})", $v);
158
  }
159
- if(strpos($operator, '()') !== false) {
160
  $where = implode(' OR ', $where);
161
- }
162
- else {
163
  $where = implode(' AND ', $where);
164
  }
165
-
166
- if(strpos($operator, '!') === 0) {
167
  $where = "!($where)";
168
  }
169
-
170
  $query->where($where);
171
  return;
172
  }
173
-
174
- switch($operator) {
175
  case '!=':
176
  case '>=':
177
  case '<=':
178
  case '>':
179
- case '<': return $query->where("{attribute_value} {$operator} ?", $this->_implode($value)); break;
180
- case '{}': return $query->where("{attribute_value} LIKE ?", "%$value%"); break;
181
- case '!{}': return $query->where("{attribute_value} NOT LIKE ?", "%$value%"); break;
182
- case '()': return $query->where("{attribute_value} IN (?)", $this->_explode($value)); break;
183
- case '!()': return $query->where("{attribute_value} NOT IN (?)", $this->_explode($value)); break;
184
- default: return $query->where("{attribute_value} = ?", $this->_implode($value)); break;
 
 
 
 
 
 
 
 
 
 
 
 
185
  }
186
-
187
  }
188
-
189
-
190
  /**
191
  * Add attribute value to collection
192
- *
 
 
193
  * @return void
194
  */
195
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
@@ -197,17 +202,18 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
197
  parent::_prepareCollection($collection);
198
  $collection->addField('attribute_value');
199
  }
200
-
201
-
202
  /**
203
  * Add attribute value to grid
204
- *
 
 
205
  * @return void
206
  */
207
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
208
  {
209
  parent::prepareGridColumns($grid);
210
-
211
  $grid->addColumn('attribute_value', array(
212
  'header' => $this->getFrontendLabel(),
213
  'index' => 'attribute_value',
@@ -215,9 +221,6 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
215
  'options' => $this->getGridValueOptions(),
216
  ));
217
  }
218
-
219
-
220
-
221
 
222
  /**
223
  * Retrieve grid column type
@@ -226,7 +229,7 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
226
  */
227
  public function getColumnType()
228
  {
229
- switch($this->getInputType()) {
230
  case 'multiselect':
231
  case 'select':
232
  case 'boolean':
@@ -234,8 +237,6 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
234
  }
235
  return $this->getInputType();
236
  }
237
-
238
-
239
 
240
  /**
241
  * Retrieve value options for the grid
@@ -246,11 +247,7 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
246
  {
247
  return $this->getValueOptions();
248
  }
249
-
250
-
251
-
252
-
253
-
254
  /**
255
  * Retrieve attribute instance
256
  *
@@ -258,27 +255,30 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
258
  */
259
  public function getAttribute()
260
  {
261
- if(!$this->_attribute) {
262
  $code = $this->getData('attribute');
263
  $this->_attribute = $this->_getAttribute($this->_entity . '/' . $code);
264
  }
265
  return $this->_attribute;
266
  }
267
-
268
-
 
 
 
 
269
  public function getFrontendLabel($attribute = null)
270
  {
271
- if(!$attribute) {
272
  $attribute = $this->getAttribute();
273
  }
274
  $label = $this->getAttributeConfig($attribute, 'label');
275
- if(!$label) {
276
  return $attribute->getFrontendLabel();
277
  }
278
- return$this->__($label);
 
279
  }
280
-
281
-
282
 
283
  /**
284
  * html for settings in option form
@@ -288,56 +288,52 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
288
  protected function prepareForm()
289
  {
290
  $attribute = $this->getAttribute();
291
- if(!$attribute) {
292
  return "**ERROR** NO ATTRIBUTE SELECTED.";
293
  }
294
-
295
  $html = $this->getHiddenField('attribute', $attribute->getAttributeCode())->toHtml();
296
-
297
- if(!$this->getData('relative')) {
298
  $operatorElement = $this->getOperatorElement();
299
  $valueElement = $this->getValueElement();
300
-
301
- return $html. $this->__('%s %s %s.',
 
302
  $this->getFrontendLabel(),
303
  $operatorElement->toHtml(),
304
  $valueElement->toHtml()
305
  );
306
- }
307
- // relative date
308
- else {
309
  $html .= $this->getHiddenField('relative', 1)->toHtml();
310
  $html .= $this->getHiddenField('anniversary', $this->getAnniversary())->toHtml();
311
  $html .= $this->getHiddenField('direction', $this->getDirection())->toHtml();
312
-
313
  $timeRangeHtml = $this->getTimeRangeHtml(self::VALUE_KEY);
314
-
315
- if($this->getAnniversary()) {
316
  $text = $this->getDirection() == 'future'
317
  ? '%s anniversary is in %s.'
318
  : '%s anniversary was %s ago.';
319
- }
320
- else {
321
  $text = $this->getDirection() == 'future'
322
  ? '%s is in %s.'
323
  : '%s was %s ago.';
324
  }
325
-
326
- return $html. $this->__($text,
 
327
  $this->getFrontendLabel(),
328
  $timeRangeHtml
329
  );
330
-
331
  }
332
  }
333
-
334
-
335
-
336
-
337
-
338
  /**
339
  * Retrieve operator select element
340
- *
341
  * @return Varien_Data_Form_Element_Abstract
342
  */
343
  public function getOperatorElement()
@@ -345,72 +341,64 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
345
  $type = $this->getInputType();
346
  $default = $this->helper()->getDefaultOperatorByType($type);
347
  $options = $this->helper()->getOperatorOptionsByType($type);
348
-
349
  return $this->getSelectElement('operator', $default, $options);
350
  }
351
-
352
-
353
-
354
  /**
355
- * Retroeve value form element
356
- *
357
  * @return Varien_Data_Form_Element_Abstract
358
  */
359
  public function getValueElement()
360
  {
361
  $type = $this->getInputType();
362
-
363
- switch($type) {
364
-
365
  case 'date':
366
  $element = $this->getDateElement(self::VALUE_KEY);
367
  break;
368
-
369
  case 'select':
370
- if(count($this->getValueOptions()) <= 2) {
371
  $element = $this->getSelectElement(self::VALUE_KEY);
372
  break;
373
  }
374
-
375
  case 'multiselect':
376
  $element = $this->getMultiSelectElement(self::VALUE_KEY);
377
  break;
378
-
379
  default:
380
  $element = $this->getInputElement(self::VALUE_KEY);
381
  break;
382
  }
383
-
384
- if($this->getChooserUrl()) {
385
  $element->setExplicitApply(true);
386
  $element->setAfterElementHtml($this->getChooserTriggerHtml());
387
  }
388
-
389
  return $element;
390
  }
391
-
392
-
393
-
394
-
395
-
396
-
397
  /**
398
  * Retrieve all value options as hash
399
- *
400
  * array(value => label,...)
401
- *
402
- * @return array
403
  */
404
  public function getValueOptions()
405
  {
406
  $attribute = $this->getAttribute();
407
- if($attribute->usesSource()) {
408
  if ($attribute->getFrontendInput() == 'multiselect') {
409
  $addEmptyOption = false;
410
  } else {
411
  $addEmptyOption = true;
412
  }
413
- $options = $attribute->getSource()->getAllOptions(false);
414
  $hash = array();
415
  foreach ($options as $o) {
416
  if (is_array($o['value'])) {
@@ -422,15 +410,13 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
422
  }
423
  return array();
424
  }
425
-
426
-
427
-
428
-
429
  /**
430
  * Add hidden input field
431
- *
432
  * @param string $name
433
  * @param string $value
 
434
  * @return Varien_Data_Form_Element_Abstract
435
  */
436
  protected function getHiddenField($name, $value)
@@ -443,10 +429,7 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
443
  'value' => $value
444
  ));
445
  }
446
-
447
-
448
-
449
-
450
  /**
451
  * Retrieve input type
452
  *
@@ -455,65 +438,73 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
455
  public function getInputType()
456
  {
457
  switch ($this->getAttribute()->getFrontendInput()) {
458
- case 'select': return 'select';
459
- case 'multiselect': return 'multiselect';
460
- case 'date': return 'date';
461
- case 'boolean': return 'boolean';
462
- case 'price': return 'numeric';
 
 
 
 
 
463
  }
 
464
  return 'string';
465
  }
466
-
467
-
468
-
469
-
470
-
 
471
  public function getOptions()
472
  {
473
  $title = $this->getTitle();
474
  $type = $this->getType();
475
  $options = array();
476
-
477
  $attributes = $this->getResourceHelper()->getEntity($this->_entity)
478
  ->loadAllAttributes()
479
  ->getAttributesByCode();
480
-
481
  /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
482
- foreach($attributes as $attribute) {
483
- if($this->isAttributeAllowed($attribute)) {
484
-
485
  $label = $this->getFrontendLabel($attribute);
486
-
487
  $options[$type.'?attribute='.$attribute->getAttributeCode()] = "{$title} | {$label}";
488
-
489
- // dates can be filterd by a fixed date or relative to the time when checked
490
- if($attribute->getFrontendInput() === 'date') {
491
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?direction=future'] = $title . ' | ' . $this->__('%s is in...', $label);
492
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?direction=past'] = $title . ' | ' . $this->__('%s was ... ago', $label);
493
-
494
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?anniversary=1?direction=future'] = $title . ' | ' . $this->__('%s anniversary is in...', $label);
495
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?anniversary=1?direction=past'] = $title . ' | ' . $this->__('%s anniversary was ... ago', $label);
496
  }
497
  }
498
  }
499
-
500
  asort($options);
 
501
  return $options;
502
  }
503
-
504
-
 
 
 
 
505
  protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
506
  {
507
- if($this->getAttributeConfig($attribute, 'disable', false)) {
508
  return false;
509
  }
510
- if($attribute->getFrontendLabel()) {
511
  return true;
512
  }
513
-
514
-
515
  return false;
516
  }
517
-
518
-
519
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Attribute
22
+ *
23
  * Define the entity type code and the required binding
24
  * and it will generate filters for all attributes
25
+ *
26
  * use method isAttributeAllowed() for fine tuning
 
27
  *
28
+ * @method bool getAnniversary()
29
+ * @method string getDirection()
30
+ *
31
+ * @method $this setAttribute(string $attributeCode)
32
+ * @method $this setValue(string $value)
33
+ * @method $this setValueFrom(int $value)
34
+ * @method $this setValueTo(int $value)
35
+ * @method $this setValueUnit(string $value)
36
+ * @method $this setOperator(string $value)
37
+ * @method $this setRelative(bool $value)
38
+ * @method $this setAnniversary(bool $value)
39
  */
40
  abstract class Mzax_Emarketing_Model_Object_Filter_Attribute
41
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
42
  {
 
43
  const VALUE_KEY = 'value';
44
+
45
+ const FUTURE = 'future';
46
+ const PAST = 'past';
47
+
48
  /**
 
49
  * @var Mage_Catalog_Model_Resource_Eav_Attribute
50
  */
51
  protected $_attribute;
52
+
 
 
53
  /**
 
54
  * @var string
55
  */
56
  protected $_entity;
57
 
 
58
  /**
 
59
  * @var string
60
  */
61
  protected $_requireBinding;
62
+
63
+ /**
64
+ * @var array
65
+ */
66
  protected $_attributeConfigs = array();
 
67
 
68
+ /**
69
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
70
+ *
71
+ * @return bool
72
+ */
73
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
74
  {
75
  return $parent->hasBinding($this->_requireBinding);
76
  }
77
+
78
+ /**
79
+ * @param Mage_Core_Model_Config_Element $config
80
+ */
81
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
82
  {
83
+ if (isset($config->attributes)) {
84
+ /* @var $cfg Mage_Core_Model_Config_Element */
85
+ foreach ($config->attributes->children() as $code => $cfg) {
86
  $this->_attributeConfigs[$code] = $cfg->asCanonicalArray();
87
  }
88
  }
89
  parent::_prepareFilter($config);
90
  }
91
+
 
 
92
  /**
93
  * Retrieve attribute config value
94
+ *
95
  * @param string $attribute
96
  * @param string $key
97
  * @param mixed $default
98
+ *
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
+ * @param Mzax_Emarketing_Db_Select $query
114
+ *
115
+ * @return void
116
+ */
117
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
118
  {
119
  $attribute = $this->getAttribute();
120
+ $adapter = $query->getAdapter();
121
+ $field = $query->joinAttribute($this->_requireBinding, $attribute, true);
122
+
123
  $query->addBinding('attribute_value', $field);
124
  $query->group();
125
 
126
+ $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
127
+ $value = $this->getData(self::VALUE_KEY);
128
+
129
+ if ($this->getData('relative')) {
130
+ $future = $this->getDirection() == self::FUTURE;
 
 
 
 
 
 
131
  $usesLocalTime = (bool) $this->getAttributeConfig($attribute, 'uses_local_time', false);
132
+
133
+ if ($this->getAnniversary()) {
134
  $query->where($this->getAnniversaryTimeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
135
+ } else {
 
136
  $query->where($this->getTimeRangeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
137
  }
138
  return;
139
  }
140
+
 
 
141
  /*
142
  * Multi select attributes are saved as list in varchar
143
  * (e.g. 123,1457,124,21)
144
+ *
145
  * @todo can we use an index?
146
  */
147
+ if ($attribute->getFrontendInput() === 'multiselect') {
 
148
  $value = (array) $value;
149
  $where = array();
150
+ foreach ($value as $v) {
151
  $where[] = $adapter->quoteInto("FIND_IN_SET(?, {attribute_value})", $v);
152
  }
153
+ if (strpos($operator, '()') !== false) {
154
  $where = implode(' OR ', $where);
155
+ } else {
 
156
  $where = implode(' AND ', $where);
157
  }
158
+
159
+ if (strpos($operator, '!') === 0) {
160
  $where = "!($where)";
161
  }
162
+
163
  $query->where($where);
164
  return;
165
  }
166
+
167
+ switch ($operator) {
168
  case '!=':
169
  case '>=':
170
  case '<=':
171
  case '>':
172
+ case '<':
173
+ $query->where("{attribute_value} {$operator} ?", $this->_implode($value));
174
+ break;
175
+ case '{}':
176
+ $query->where("{attribute_value} LIKE ?", "%$value%");
177
+ break;
178
+ case '!{}':
179
+ $query->where("{attribute_value} NOT LIKE ?", "%$value%");
180
+ break;
181
+ case '()':
182
+ $query->where("{attribute_value} IN (?)", $this->_explode($value));
183
+ break;
184
+ case '!()':
185
+ $query->where("{attribute_value} NOT IN (?)", $this->_explode($value));
186
+ break;
187
+ default:
188
+ $query->where("{attribute_value} = ?", $this->_implode($value));
189
+ break;
190
  }
 
191
  }
192
+
 
193
  /**
194
  * Add attribute value to collection
195
+ *
196
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
197
+ *
198
  * @return void
199
  */
200
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
202
  parent::_prepareCollection($collection);
203
  $collection->addField('attribute_value');
204
  }
205
+
 
206
  /**
207
  * Add attribute value to grid
208
+ *
209
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
210
+ *
211
  * @return void
212
  */
213
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
214
  {
215
  parent::prepareGridColumns($grid);
216
+
217
  $grid->addColumn('attribute_value', array(
218
  'header' => $this->getFrontendLabel(),
219
  'index' => 'attribute_value',
221
  'options' => $this->getGridValueOptions(),
222
  ));
223
  }
 
 
 
224
 
225
  /**
226
  * Retrieve grid column type
229
  */
230
  public function getColumnType()
231
  {
232
+ switch ($this->getInputType()) {
233
  case 'multiselect':
234
  case 'select':
235
  case 'boolean':
237
  }
238
  return $this->getInputType();
239
  }
 
 
240
 
241
  /**
242
  * Retrieve value options for the grid
247
  {
248
  return $this->getValueOptions();
249
  }
250
+
 
 
 
 
251
  /**
252
  * Retrieve attribute instance
253
  *
255
  */
256
  public function getAttribute()
257
  {
258
+ if (!$this->_attribute) {
259
  $code = $this->getData('attribute');
260
  $this->_attribute = $this->_getAttribute($this->_entity . '/' . $code);
261
  }
262
  return $this->_attribute;
263
  }
264
+
265
+ /**
266
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
267
+ *
268
+ * @return string
269
+ */
270
  public function getFrontendLabel($attribute = null)
271
  {
272
+ if (!$attribute) {
273
  $attribute = $this->getAttribute();
274
  }
275
  $label = $this->getAttributeConfig($attribute, 'label');
276
+ if (!$label) {
277
  return $attribute->getFrontendLabel();
278
  }
279
+
280
+ return $this->__($label);
281
  }
 
 
282
 
283
  /**
284
  * html for settings in option form
288
  protected function prepareForm()
289
  {
290
  $attribute = $this->getAttribute();
291
+ if (!$attribute) {
292
  return "**ERROR** NO ATTRIBUTE SELECTED.";
293
  }
294
+
295
  $html = $this->getHiddenField('attribute', $attribute->getAttributeCode())->toHtml();
296
+
297
+ if (!$this->getData('relative')) {
298
  $operatorElement = $this->getOperatorElement();
299
  $valueElement = $this->getValueElement();
300
+
301
+ return $html . $this->__(
302
+ '%s %s %s.',
303
  $this->getFrontendLabel(),
304
  $operatorElement->toHtml(),
305
  $valueElement->toHtml()
306
  );
307
+ } else {
308
+ // relative date
 
309
  $html .= $this->getHiddenField('relative', 1)->toHtml();
310
  $html .= $this->getHiddenField('anniversary', $this->getAnniversary())->toHtml();
311
  $html .= $this->getHiddenField('direction', $this->getDirection())->toHtml();
312
+
313
  $timeRangeHtml = $this->getTimeRangeHtml(self::VALUE_KEY);
314
+
315
+ if ($this->getAnniversary()) {
316
  $text = $this->getDirection() == 'future'
317
  ? '%s anniversary is in %s.'
318
  : '%s anniversary was %s ago.';
319
+ } else {
 
320
  $text = $this->getDirection() == 'future'
321
  ? '%s is in %s.'
322
  : '%s was %s ago.';
323
  }
324
+
325
+ return $html . $this->__(
326
+ $text,
327
  $this->getFrontendLabel(),
328
  $timeRangeHtml
329
  );
330
+
331
  }
332
  }
333
+
 
 
 
 
334
  /**
335
  * Retrieve operator select element
336
+ *
337
  * @return Varien_Data_Form_Element_Abstract
338
  */
339
  public function getOperatorElement()
341
  $type = $this->getInputType();
342
  $default = $this->helper()->getDefaultOperatorByType($type);
343
  $options = $this->helper()->getOperatorOptionsByType($type);
344
+
345
  return $this->getSelectElement('operator', $default, $options);
346
  }
347
+
 
 
348
  /**
349
+ * Retrieve value form element
350
+ *
351
  * @return Varien_Data_Form_Element_Abstract
352
  */
353
  public function getValueElement()
354
  {
355
  $type = $this->getInputType();
356
+
357
+ switch ($type) {
 
358
  case 'date':
359
  $element = $this->getDateElement(self::VALUE_KEY);
360
  break;
361
+
362
  case 'select':
363
+ if (count($this->getValueOptions()) <= 2) {
364
  $element = $this->getSelectElement(self::VALUE_KEY);
365
  break;
366
  }
367
+ // fall through
368
  case 'multiselect':
369
  $element = $this->getMultiSelectElement(self::VALUE_KEY);
370
  break;
371
+
372
  default:
373
  $element = $this->getInputElement(self::VALUE_KEY);
374
  break;
375
  }
376
+
377
+ if ($this->getChooserUrl()) {
378
  $element->setExplicitApply(true);
379
  $element->setAfterElementHtml($this->getChooserTriggerHtml());
380
  }
381
+
382
  return $element;
383
  }
384
+
 
 
 
 
 
385
  /**
386
  * Retrieve all value options as hash
387
+ *
388
  * array(value => label,...)
389
+ *
390
+ * @return string[]
391
  */
392
  public function getValueOptions()
393
  {
394
  $attribute = $this->getAttribute();
395
+ if ($attribute->usesSource()) {
396
  if ($attribute->getFrontendInput() == 'multiselect') {
397
  $addEmptyOption = false;
398
  } else {
399
  $addEmptyOption = true;
400
  }
401
+ $options = $attribute->getSource()->getAllOptions($addEmptyOption);
402
  $hash = array();
403
  foreach ($options as $o) {
404
  if (is_array($o['value'])) {
410
  }
411
  return array();
412
  }
413
+
 
 
 
414
  /**
415
  * Add hidden input field
416
+ *
417
  * @param string $name
418
  * @param string $value
419
+ *
420
  * @return Varien_Data_Form_Element_Abstract
421
  */
422
  protected function getHiddenField($name, $value)
429
  'value' => $value
430
  ));
431
  }
432
+
 
 
 
433
  /**
434
  * Retrieve input type
435
  *
438
  public function getInputType()
439
  {
440
  switch ($this->getAttribute()->getFrontendInput()) {
441
+ case 'select':
442
+ return 'select';
443
+ case 'multiselect':
444
+ return 'multiselect';
445
+ case 'date':
446
+ return 'date';
447
+ case 'boolean':
448
+ return 'boolean';
449
+ case 'price':
450
+ return 'numeric';
451
  }
452
+
453
  return 'string';
454
  }
455
+
456
+ /**
457
+ * Retrieve all filter options
458
+ *
459
+ * @return string[]
460
+ */
461
  public function getOptions()
462
  {
463
  $title = $this->getTitle();
464
  $type = $this->getType();
465
  $options = array();
466
+
467
  $attributes = $this->getResourceHelper()->getEntity($this->_entity)
468
  ->loadAllAttributes()
469
  ->getAttributesByCode();
470
+
471
  /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
472
+ foreach ($attributes as $attribute) {
473
+ if ($this->isAttributeAllowed($attribute)) {
 
474
  $label = $this->getFrontendLabel($attribute);
475
+
476
  $options[$type.'?attribute='.$attribute->getAttributeCode()] = "{$title} | {$label}";
477
+
478
+ // dates can be filtered by a fixed date or relative to the time when checked
479
+ if ($attribute->getFrontendInput() === 'date') {
480
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?direction=future'] = $title . ' | ' . $this->__('%s is in...', $label);
481
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?direction=past'] = $title . ' | ' . $this->__('%s was ... ago', $label);
482
+
483
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?anniversary=1?direction=future'] = $title . ' | ' . $this->__('%s anniversary is in...', $label);
484
  $options[$type.'?attribute='.$attribute->getAttributeCode().'?relative=1?anniversary=1?direction=past'] = $title . ' | ' . $this->__('%s anniversary was ... ago', $label);
485
  }
486
  }
487
  }
488
+
489
  asort($options);
490
+
491
  return $options;
492
  }
493
+
494
+ /**
495
+ * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
496
+ *
497
+ * @return bool
498
+ */
499
  protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
500
  {
501
+ if ($this->getAttributeConfig($attribute, 'disable', false)) {
502
  return false;
503
  }
504
+ if ($attribute->getFrontendLabel()) {
505
  return true;
506
  }
507
+
 
508
  return false;
509
  }
 
 
510
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Goal.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,105 +17,103 @@
18
  */
19
 
20
  /**
21
- *
22
- * @method Mzax_Emarketing_Model_Object_Filter_Campaign_Goal setAction()
23
- * @method Mzax_Emarketing_Model_Object_Filter_Campaign_Goal setOffsetValue()
24
- * @method Mzax_Emarketing_Model_Object_Filter_Campaign_Goal setOffsetUnit()
25
- *
26
- *
27
- * @author Jacob Siefer
28
  *
 
 
 
29
  */
30
  class Mzax_Emarketing_Model_Object_Filter_Campaign_Goal
31
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
32
  {
33
-
34
-
35
  const ACTION_CLICKED = 'clicked';
36
  const ACTION_VIEWED = 'viewed';
37
  const ACTION_RECEIVED = 'recieved';
38
-
39
-
40
-
41
-
 
 
42
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
43
  {
44
  return $parent->getQuery()->hasAllBindings('recipient_id', 'goal_time', 'recipient_sent_at');
45
  }
46
-
47
-
48
-
 
49
  public function getTitle()
50
  {
51
  return "Goal | Occurred after recipient sent/viewed/click campaign";
52
  }
53
-
54
 
 
 
 
55
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
56
  {
57
  $action = $this->getDataSetDefault('action');
58
-
59
- switch($action) {
60
  case self::ACTION_CLICKED:
61
  case self::ACTION_VIEWED:
62
- switch($action) {
63
  case self::ACTION_CLICKED:
64
  $eventType = Mzax_Emarketing_Model_Recipient::EVENT_TYPE_CLICK;
65
  break;
66
  case self::ACTION_VIEWED:
 
67
  $eventType = Mzax_Emarketing_Model_Recipient::EVENT_TYPE_VIEW;
68
  break;
69
  }
70
-
71
- $query->joinTable(array('recipient_id', 'event_type' => $eventType), 'recipient_event', 'event')->group();
72
-
73
- //$select->join($this->_getTable('recipient_event', 'event'), "`event`.`recipient_id` = $recipientId AND `event`.`event_type` = $eventType", null);
74
-
 
 
75
  $eventTime = '`event`.`captured_at`';
76
  $timeLimit = $this->getTimeExpr('offset', $eventTime);
77
-
78
  $query->where("{goal_time} < $timeLimit");
79
  $query->where("{goal_time} > $eventTime");
80
  break;
81
-
82
  default:
83
  $timeLimit = $this->getTimeExpr('offset', '{recipient_sent_at}');
84
  $query->where("{goal_time} < $timeLimit");
85
  break;
86
-
87
  }
88
  $query->group();
89
- //die($query);
90
  }
91
-
92
-
93
-
94
 
 
 
 
95
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
96
  {
97
  parent::_prepareCollection($collection);
 
98
  $collection->addField('goal_time');
99
  }
100
-
101
-
 
 
102
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
103
  {
104
  parent::prepareGridColumns($grid);
105
-
106
  $grid->addColumn('goal_time', array(
107
  'header' => $this->__('Goal Time'),
108
  'type' => 'datetime',
109
  'index' => 'goal_time'
110
  ));
111
  }
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
  /**
121
  * html for settings in option form
122
  *
@@ -124,14 +121,16 @@ class Mzax_Emarketing_Model_Object_Filter_Campaign_Goal
124
  */
125
  protected function prepareForm()
126
  {
127
- return $this->__("If goal occurred no later then %s after recipient %s the campaign.",
 
128
  $this->getTimeHtml('offset'),
129
  $this->getSelectElement('action')->toHtml()
130
  );
131
  }
132
-
133
-
134
-
 
135
  public function getActionOptions()
136
  {
137
  return array(
@@ -140,8 +139,4 @@ class Mzax_Emarketing_Model_Object_Filter_Campaign_Goal
140
  self::ACTION_RECEIVED => $this->__('recieved'),
141
  );
142
  }
143
-
144
-
145
-
146
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Campaign_Goal
 
 
 
 
 
 
21
  *
22
+ * @method $this setAction(string $value)
23
+ * @method $this setOffsetValue(int $value)
24
+ * @method $this setOffsetUnit(string $value)
25
  */
26
  class Mzax_Emarketing_Model_Object_Filter_Campaign_Goal
27
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
28
  {
 
 
29
  const ACTION_CLICKED = 'clicked';
30
  const ACTION_VIEWED = 'viewed';
31
  const ACTION_RECEIVED = 'recieved';
32
+
33
+ /**
34
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
35
+ *
36
+ * @return bool
37
+ */
38
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
39
  {
40
  return $parent->getQuery()->hasAllBindings('recipient_id', 'goal_time', 'recipient_sent_at');
41
  }
42
+
43
+ /**
44
+ * @return string
45
+ */
46
  public function getTitle()
47
  {
48
  return "Goal | Occurred after recipient sent/viewed/click campaign";
49
  }
 
50
 
51
+ /**
52
+ * @param Mzax_Emarketing_Db_Select $query
53
+ */
54
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
55
  {
56
  $action = $this->getDataSetDefault('action');
57
+
58
+ switch ($action) {
59
  case self::ACTION_CLICKED:
60
  case self::ACTION_VIEWED:
61
+ switch ($action) {
62
  case self::ACTION_CLICKED:
63
  $eventType = Mzax_Emarketing_Model_Recipient::EVENT_TYPE_CLICK;
64
  break;
65
  case self::ACTION_VIEWED:
66
+ default:
67
  $eventType = Mzax_Emarketing_Model_Recipient::EVENT_TYPE_VIEW;
68
  break;
69
  }
70
+ $query->joinTable(
71
+ array('recipient_id', 'event_type' => $eventType),
72
+ 'recipient_event',
73
+ 'event'
74
+ );
75
+ $query->group();
76
+
77
  $eventTime = '`event`.`captured_at`';
78
  $timeLimit = $this->getTimeExpr('offset', $eventTime);
79
+
80
  $query->where("{goal_time} < $timeLimit");
81
  $query->where("{goal_time} > $eventTime");
82
  break;
83
+
84
  default:
85
  $timeLimit = $this->getTimeExpr('offset', '{recipient_sent_at}');
86
  $query->where("{goal_time} < $timeLimit");
87
  break;
88
+
89
  }
90
  $query->group();
 
91
  }
 
 
 
92
 
93
+ /**
94
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
95
+ */
96
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
97
  {
98
  parent::_prepareCollection($collection);
99
+
100
  $collection->addField('goal_time');
101
  }
102
+
103
+ /**
104
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
105
+ */
106
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
107
  {
108
  parent::prepareGridColumns($grid);
109
+
110
  $grid->addColumn('goal_time', array(
111
  'header' => $this->__('Goal Time'),
112
  'type' => 'datetime',
113
  'index' => 'goal_time'
114
  ));
115
  }
116
+
 
 
 
 
 
 
 
117
  /**
118
  * html for settings in option form
119
  *
121
  */
122
  protected function prepareForm()
123
  {
124
+ return $this->__(
125
+ "If goal occurred no later then %s after recipient %s the campaign.",
126
  $this->getTimeHtml('offset'),
127
  $this->getSelectElement('action')->toHtml()
128
  );
129
  }
130
+
131
+ /**
132
+ * @return string[]
133
+ */
134
  public function getActionOptions()
135
  {
136
  return array(
139
  self::ACTION_RECEIVED => $this->__('recieved'),
140
  );
141
  }
 
 
 
 
142
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,21 +16,20 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  abstract class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Abstract
26
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
27
  {
28
-
 
 
 
 
29
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
30
  {
31
  return $parent->hasInterface('recipient_id');
32
  }
33
-
34
-
35
-
36
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Abstract
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Abstract
24
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
25
  {
26
+ /**
27
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
28
+ *
29
+ * @return bool
30
+ */
31
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
32
  {
33
  return $parent->hasInterface('recipient_id');
34
  }
 
 
 
 
35
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Campaign/Recipient/Interact.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,22 +16,19 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Interact
26
  extends Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Abstract
27
  {
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Interact
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Interact
24
  extends Mzax_Emarketing_Model_Object_Filter_Campaign_Recipient_Abstract
25
  {
26
+ /**
27
+ * @return string
28
+ */
29
+ public function getTitle()
30
+ {
31
+ // TODO: Implement getTitle() method.
32
+ return '';
33
+ }
 
 
34
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Column.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,87 +16,106 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  abstract class Mzax_Emarketing_Model_Object_Filter_Column
26
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
27
  {
28
-
29
  const VALUE_KEY = 'value';
30
-
31
-
32
-
 
33
  protected $_formText = '%s %s %s.';
34
-
35
-
36
  /**
37
- *
38
  * @var string
39
  */
40
  protected $_requireBinding;
41
-
 
 
 
42
  protected $_label;
43
-
44
-
 
 
45
  protected $_inputType = 'string';
46
-
47
-
48
-
49
-
 
 
50
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
51
  {
52
  return $parent->hasBinding($this->_requireBinding);
53
  }
54
-
55
-
56
-
57
-
 
 
58
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
59
  {
60
- /* @var $adapter Zend_Db_Adapter_Abstract */
61
- $adapter = $query->getAdapter();
62
-
63
  $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->_inputType));
64
  $value = $this->getData(self::VALUE_KEY);
65
-
66
- if($this->_inputType === 'boolean') {
67
  $value = '1';
68
  }
69
-
70
- switch($operator) {
71
  case '!=':
72
  case '>=':
73
  case '<=':
74
  case '>':
75
- case '<': return $query->where("{{$this->_requireBinding}} {$operator} ?", $value); break;
76
- case '{}': return $query->where("{{$this->_requireBinding}} LIKE ?", "%$value%"); break;
77
- case '!{}': return $query->where("{{$this->_requireBinding}} NOT LIKE ?", "%$value%"); break;
78
- case '()': return $query->where("{{$this->_requireBinding}} IN (?)", $this->_explode($value)); break;
79
- case '!()': return $query->where("{{$this->_requireBinding}} NOT IN (?)", $this->_explode($value)); break;
80
- default: return $query->where("{{$this->_requireBinding}} = ?", $value); break;
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
  }
83
-
84
-
85
-
86
 
 
 
 
 
 
87
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
88
  {
89
  parent::_prepareCollection($collection);
90
  $collection->addField($this->_requireBinding);
91
  }
92
-
93
-
 
 
 
 
94
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
95
  {
96
  parent::prepareGridColumns($grid);
97
-
98
-
99
- if(!$grid->getColumn($this->_requireBinding))
100
- {
101
  $grid->addColumn($this->_requireBinding, array(
102
  'header' => $this->_label,
103
  'type' => $this->getColumnType(),
@@ -106,14 +124,9 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Column
106
  ));
107
  }
108
  }
109
-
110
-
111
-
112
-
113
-
114
 
115
  /**
116
- * html for settings in option form
117
  *
118
  * @return string
119
  */
@@ -121,125 +134,108 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Column
121
  {
122
  $operatorElement = $this->getOperatorElement();
123
  $valueElement = $this->getValueElement();
124
-
125
- switch($this->_inputType) {
126
  case 'boolean':
127
- return $html . $this->__($this->_formText,
 
128
  $operatorElement->toHtml(),
129
  $this->_label
130
  );
131
  }
132
-
133
- return $this->__($this->_formText,
 
134
  $this->_label,
135
  $operatorElement->toHtml(),
136
  $valueElement->toHtml()
137
  );
138
  }
139
-
140
-
141
-
142
-
143
-
144
  /**
145
  * Retrieve operator select element
146
- *
147
  * @return Varien_Data_Form_Element_Abstract
148
  */
149
  public function getOperatorElement()
150
  {
151
  $default = $this->helper()->getDefaultOperatorByType($this->_inputType);
152
  $options = $this->helper()->getOperatorOptionsByType($this->_inputType);
153
-
154
  return $this->getSelectElement('operator', $default, $options);
155
  }
156
-
157
-
158
-
159
  /**
160
- * Retroeve value form element
161
- *
162
  * @return Varien_Data_Form_Element_Abstract
163
  */
164
  public function getValueElement()
165
  {
166
- switch($this->_inputType) {
167
-
168
  case 'date':
169
  $element = $this->getDateElement(self::VALUE_KEY);
170
  break;
171
-
172
  case 'select':
173
  case 'boolean':
174
  $element = $this->getSelectElement(self::VALUE_KEY);
175
  break;
176
-
177
  case 'multiselect':
178
  $element = $this->getMultiSelectElement(self::VALUE_KEY);
179
  break;
180
-
181
  default:
182
  $element = $this->getInputElement(self::VALUE_KEY);
183
  break;
184
  }
185
-
186
- if($this->getChooserUrl()) {
187
  $element->setExplicitApply(true);
188
  $element->setAfterElementHtml($this->getChooserTriggerHtml());
189
  }
190
-
191
  return $element;
192
  }
193
-
194
-
195
-
196
-
197
-
198
-
199
  /**
200
  * Retrieve all value options as hash
201
- *
202
  * array(value => label,...)
203
- *
204
- * @return array
205
  */
206
  public function getValueOptions()
207
  {
208
- switch($this->_inputType) {
209
  case 'boolean':
210
  return array(
211
- '1' => $this->__('is'),
212
  '0' => $this->__('is not')
213
  );
214
- }
 
215
  return array();
216
  }
217
-
218
-
219
-
220
  /**
221
  * Retrieve value options for the grid
222
  *
223
- * @return array
224
  */
225
  public function getGridValueOptions()
226
  {
227
- switch($this->_inputType) {
228
  case 'boolean':
229
  return array(
230
  '1' => $this->__('Yes'),
231
  '0' => $this->__('No')
232
  );
233
  }
 
234
  return $this->getValueOptions();
235
  }
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
 
244
  /**
245
  * Retrieve input type
@@ -248,17 +244,13 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Column
248
  */
249
  public function getColumnType()
250
  {
251
- switch($this->_inputType) {
252
  case 'multiselect':
253
  case 'select':
254
- case 'boolean':
255
  return 'options';
256
  }
 
257
  return 'text';
258
  }
259
-
260
-
261
-
262
-
263
-
264
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Column
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Filter_Column
24
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
25
  {
 
26
  const VALUE_KEY = 'value';
27
+
28
+ /**
29
+ * @var string
30
+ */
31
  protected $_formText = '%s %s %s.';
32
+
 
33
  /**
 
34
  * @var string
35
  */
36
  protected $_requireBinding;
37
+
38
+ /**
39
+ * @var string
40
+ */
41
  protected $_label;
42
+
43
+ /**
44
+ * @var string
45
+ */
46
  protected $_inputType = 'string';
47
+
48
+ /**
49
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
50
+ *
51
+ * @return bool
52
+ */
53
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
54
  {
55
  return $parent->hasBinding($this->_requireBinding);
56
  }
57
+
58
+ /**
59
+ * @param Mzax_Emarketing_Db_Select $query
60
+ *
61
+ * @return void
62
+ */
63
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
64
  {
 
 
 
65
  $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->_inputType));
66
  $value = $this->getData(self::VALUE_KEY);
67
+
68
+ if ($this->_inputType === 'boolean') {
69
  $value = '1';
70
  }
71
+
72
+ switch ($operator) {
73
  case '!=':
74
  case '>=':
75
  case '<=':
76
  case '>':
77
+ case '<':
78
+ $query->where("{{$this->_requireBinding}} {$operator} ?", $value);
79
+ break;
80
+ case '{}':
81
+ $query->where("{{$this->_requireBinding}} LIKE ?", "%$value%");
82
+ break;
83
+ case '!{}':
84
+ $query->where("{{$this->_requireBinding}} NOT LIKE ?", "%$value%");
85
+ break;
86
+ case '()':
87
+ $query->where("{{$this->_requireBinding}} IN (?)", $this->_explode($value));
88
+ break;
89
+ case '!()':
90
+ $query->where("{{$this->_requireBinding}} NOT IN (?)", $this->_explode($value));
91
+ break;
92
+ default:
93
+ $query->where("{{$this->_requireBinding}} = ?", $value);
94
+ break;
95
  }
96
  }
 
 
 
97
 
98
+ /**
99
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
100
+ *
101
+ * @return void
102
+ */
103
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
104
  {
105
  parent::_prepareCollection($collection);
106
  $collection->addField($this->_requireBinding);
107
  }
108
+
109
+ /**
110
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
111
+ *
112
+ * @return void
113
+ */
114
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
115
  {
116
  parent::prepareGridColumns($grid);
117
+
118
+ if (!$grid->getColumn($this->_requireBinding)) {
 
 
119
  $grid->addColumn($this->_requireBinding, array(
120
  'header' => $this->_label,
121
  'type' => $this->getColumnType(),
124
  ));
125
  }
126
  }
 
 
 
 
 
127
 
128
  /**
129
+ * Prepare option form
130
  *
131
  * @return string
132
  */
134
  {
135
  $operatorElement = $this->getOperatorElement();
136
  $valueElement = $this->getValueElement();
137
+
138
+ switch ($this->_inputType) {
139
  case 'boolean':
140
+ return $this->__(
141
+ $this->_formText,
142
  $operatorElement->toHtml(),
143
  $this->_label
144
  );
145
  }
146
+
147
+ return $this->__(
148
+ $this->_formText,
149
  $this->_label,
150
  $operatorElement->toHtml(),
151
  $valueElement->toHtml()
152
  );
153
  }
154
+
 
 
 
 
155
  /**
156
  * Retrieve operator select element
157
+ *
158
  * @return Varien_Data_Form_Element_Abstract
159
  */
160
  public function getOperatorElement()
161
  {
162
  $default = $this->helper()->getDefaultOperatorByType($this->_inputType);
163
  $options = $this->helper()->getOperatorOptionsByType($this->_inputType);
164
+
165
  return $this->getSelectElement('operator', $default, $options);
166
  }
167
+
 
 
168
  /**
169
+ * Retrieve value form element
170
+ *
171
  * @return Varien_Data_Form_Element_Abstract
172
  */
173
  public function getValueElement()
174
  {
175
+ switch ($this->_inputType) {
 
176
  case 'date':
177
  $element = $this->getDateElement(self::VALUE_KEY);
178
  break;
179
+
180
  case 'select':
181
  case 'boolean':
182
  $element = $this->getSelectElement(self::VALUE_KEY);
183
  break;
184
+
185
  case 'multiselect':
186
  $element = $this->getMultiSelectElement(self::VALUE_KEY);
187
  break;
188
+
189
  default:
190
  $element = $this->getInputElement(self::VALUE_KEY);
191
  break;
192
  }
193
+
194
+ if ($this->getChooserUrl()) {
195
  $element->setExplicitApply(true);
196
  $element->setAfterElementHtml($this->getChooserTriggerHtml());
197
  }
198
+
199
  return $element;
200
  }
201
+
 
 
 
 
 
202
  /**
203
  * Retrieve all value options as hash
204
+ *
205
  * array(value => label,...)
206
+ *
207
+ * @return string[]
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
+
219
  return array();
220
  }
221
+
 
 
222
  /**
223
  * Retrieve value options for the grid
224
  *
225
+ * @return string[]
226
  */
227
  public function getGridValueOptions()
228
  {
229
+ switch ($this->_inputType) {
230
  case 'boolean':
231
  return array(
232
  '1' => $this->__('Yes'),
233
  '0' => $this->__('No')
234
  );
235
  }
236
+
237
  return $this->getValueOptions();
238
  }
 
 
 
 
 
 
 
239
 
240
  /**
241
  * Retrieve input type
244
  */
245
  public function getColumnType()
246
  {
247
+ switch ($this->_inputType) {
248
  case 'multiselect':
249
  case 'select':
250
+ case 'boolean':
251
  return 'options';
252
  }
253
+
254
  return 'text';
255
  }
 
 
 
 
 
256
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Combine.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,73 +17,87 @@
18
  */
19
 
20
 
 
 
 
21
  class Mzax_Emarketing_Model_Object_Filter_Combine
22
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
23
  {
24
-
25
  const DEFAULT_AGGREGATOR = 'all';
26
-
27
  const DEFAULT_EXPECTATION = 'true';
28
-
29
-
 
 
30
  protected $_type = 'combine';
31
-
32
-
 
 
33
  protected $_allowChildren = true;
34
-
35
-
36
-
 
 
 
 
 
37
 
38
  /**
39
  * Works with all parents
40
- *
41
- * @see Mzax_Emarketing_Model_Object_Filter_Component::acceptParent()
42
- * @return boolean Always true
 
43
  */
44
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
45
  {
46
  return true;
47
  }
48
-
49
-
50
-
 
 
 
 
 
51
  public function acceptChild(Mzax_Emarketing_Model_Object_Filter_Component $child)
52
  {
53
- if($this->_parent) {
54
  return $this->_parent->acceptChild($child);
55
  }
 
56
  return true;
57
  }
58
-
59
-
60
-
61
-
62
  /**
63
  * Retrieve final filter query that unites all id filter queries
64
  * and retrieve only those id's that exist in all filters
65
  *
66
- * @return string
67
- */
 
 
68
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
69
  {
70
- $conditions = $this->_getConditions();
71
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
72
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
73
-
74
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
75
  $select->useTemporaryTable($this->getTempTableName());
76
-
77
  $query->joinSelect('id', $select, 'filter');
78
  $query->group();
79
  }
80
-
81
-
82
 
83
-
84
-
85
  /**
86
  * Prepare recipient collection
87
  *
 
 
88
  * @return void
89
  */
90
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
@@ -92,9 +105,12 @@ class Mzax_Emarketing_Model_Object_Filter_Combine
92
  parent::_prepareCollection($collection);
93
  $collection->addField('matches', 'filter.matches');
94
  }
95
-
96
-
97
-
 
 
 
98
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
99
  {
100
  parent::prepareGridColumns($grid);
@@ -104,43 +120,31 @@ class Mzax_Emarketing_Model_Object_Filter_Combine
104
  'index' => 'matches'
105
  ));
106
  }
107
-
108
-
109
-
 
 
 
110
  public function getAvailableFilters()
111
  {
112
  return $this->_parent->getAvailableFilters();
113
  }
114
-
115
-
116
-
117
-
118
- public function getTitle()
119
- {
120
- return "Combinations of conditions";
121
- }
122
-
123
 
124
  /**
125
- * html for settings in option form
126
  *
127
  * @return string
128
  */
129
  protected function prepareForm()
130
  {
131
- $aggregatorElment = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
132
- $expectationElment = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
133
-
134
- return $this->__('If %s of these conditions are %s:',
135
- $aggregatorElment->toHtml(), $expectationElment->toHtml());
136
- }
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
 
 
 
 
 
 
 
146
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Combine
22
+ */
23
  class Mzax_Emarketing_Model_Object_Filter_Combine
24
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
25
  {
 
26
  const DEFAULT_AGGREGATOR = 'all';
 
27
  const DEFAULT_EXPECTATION = 'true';
28
+
29
+ /**
30
+ * @var string
31
+ */
32
  protected $_type = 'combine';
33
+
34
+ /**
35
+ * @var bool
36
+ */
37
  protected $_allowChildren = true;
38
+
39
+ /**
40
+ * @return string
41
+ */
42
+ public function getTitle()
43
+ {
44
+ return "Combinations of conditions";
45
+ }
46
 
47
  /**
48
  * Works with all parents
49
+ *
50
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
51
+ *
52
+ * @return bool Always true
53
  */
54
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
55
  {
56
  return true;
57
  }
58
+
59
+ /**
60
+ * Check if accepted by own parent as well
61
+ *
62
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $child
63
+ *
64
+ * @return bool
65
+ */
66
  public function acceptChild(Mzax_Emarketing_Model_Object_Filter_Component $child)
67
  {
68
+ if ($this->_parent) {
69
  return $this->_parent->acceptChild($child);
70
  }
71
+
72
  return true;
73
  }
74
+
 
 
 
75
  /**
76
  * Retrieve final filter query that unites all id filter queries
77
  * and retrieve only those id's that exist in all filters
78
  *
79
+ * @param Mzax_Emarketing_Db_Select $query
80
+ *
81
+ * @return void
82
+ */
83
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
84
  {
85
+ $conditions = $this->_getConditions();
86
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
87
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
88
+
89
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
90
  $select->useTemporaryTable($this->getTempTableName());
91
+
92
  $query->joinSelect('id', $select, 'filter');
93
  $query->group();
94
  }
 
 
95
 
 
 
96
  /**
97
  * Prepare recipient collection
98
  *
99
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
100
+ *
101
  * @return void
102
  */
103
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
105
  parent::_prepareCollection($collection);
106
  $collection->addField('matches', 'filter.matches');
107
  }
108
+
109
+ /**
110
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
111
+ *
112
+ * @return void
113
+ */
114
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
115
  {
116
  parent::prepareGridColumns($grid);
120
  'index' => 'matches'
121
  ));
122
  }
123
+
124
+ /**
125
+ * Retrieve available sub filters
126
+ *
127
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract[]
128
+ */
129
  public function getAvailableFilters()
130
  {
131
  return $this->_parent->getAvailableFilters();
132
  }
 
 
 
 
 
 
 
 
 
133
 
134
  /**
135
+ * Prepare form HTML
136
  *
137
  * @return string
138
  */
139
  protected function prepareForm()
140
  {
141
+ $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
142
+ $expectationElement = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
+ return $this->__(
145
+ 'If %s of these conditions are %s:',
146
+ $aggregatorElement->toHtml(),
147
+ $expectationElement->toHtml()
148
+ );
149
+ }
150
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Component.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,200 +16,201 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
 
 
21
  abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Object
22
  {
23
-
24
  const ID_ALIAS = 'object_id';
25
-
26
-
27
-
 
28
  protected $_id;
29
-
30
-
 
 
 
 
 
 
31
  /**
32
  * Parent Filter
33
  *
34
  * @var Mzax_Emarketing_Model_Object_Filter_Component
35
  */
36
  protected $_parent;
37
-
38
-
39
-
40
-
41
-
42
-
43
- /**
44
- *
45
  * @var Mzax_Emarketing_Model_Object_Collection
46
  */
47
  protected $_collection;
48
-
49
-
50
-
51
-
52
-
53
  /**
54
  * Can have children
55
- *
56
  * @var boolean
57
  */
58
  protected $_allowChildren = false;
59
-
60
-
61
-
62
-
63
-
64
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  * The subject provides generic information for the email provider/filter object.
67
- * So for instance, the email provider customer
68
- *
69
- *
70
  * @return Mzax_Emarketing_Model_Object_Abstract
71
  */
72
- abstract function getObject();
73
-
74
-
75
-
76
  /**
77
- *
 
78
  * @return Mzax_Emarketing_Model_Object_Abstract
79
  */
80
  public function getParentObject()
81
  {
82
  return $this->getParentOrSelf()->getObject();
83
  }
84
-
85
-
86
-
87
  /**
88
- * Retrieve Expresion used for current time
89
- *
90
- * By default the function should return the
91
  * mysql expression NOW() but we want to be able
92
  * to change the current time in order to test
93
  * filters etc for different times
94
- *
95
  * Also some filters may require the local time
96
  * not the gmt time
97
- *
98
- * @param boolean $gmt get as gmt time
99
- * @return array
 
100
  */
101
  public function getCurrentTime($gmt = true)
102
  {
103
  $adapter = $this->_getReadAdapter();
104
-
105
- // is current specfied time is the local time or not
106
- $isLocal = (bool) $this->getParam('is_local_time');
107
-
108
  // check if we emulate current itme
109
- $now = (array) $this->getParam('current_time');
110
  $now = array_filter($now);
111
- foreach($now as &$time) {
112
- if(!$time instanceof Zend_Db_Expr) {
113
  $time = $adapter->quote($time);
114
  }
115
  }
116
- if(empty($now)) {
117
  $now[] = $adapter->quote(now());
118
  }
119
-
120
  $result = array();
121
- foreach($now as $date) {
122
- if($gmt && $isLocal) {
123
  $result[] = $this->toGmtTime($date);
124
- }
125
- else if(!$gmt && !$isLocal) {
126
  $result[] = $this->toLocalTime($date);
127
- }
128
- else {
129
  $result[] = $date;
130
  }
131
  }
 
132
  return $result;
133
  }
134
-
135
-
136
-
137
  /**
138
  * Retrieve filter select
139
- *
140
  * @return Mzax_Emarketing_Db_Select
141
  */
142
  public function getSelect()
143
  {
144
  return $this->getPreparedQuery();
145
  }
146
-
147
-
148
-
149
  /**
150
  * Retrieve prepared query
151
- *
152
  * @return Mzax_Emarketing_Db_Select
153
  */
154
- final public function getPreparedQuery()
155
  {
156
  $query = $this->getParentOrSelf()->getQuery();
157
- $this->_prepareQuery($query->lock());
 
 
 
158
  $query->comment('FILTER: ' . get_class($this));
 
159
 
160
- return $query->lock(false);
161
  }
162
-
163
-
164
-
165
  /**
166
  * Takes the query provided by the parent and modifies it
167
  * to match the filter settings
168
- *
169
  * @param Mzax_Emarketing_Db_Select $query
 
 
170
  */
171
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
172
- {
173
  }
174
-
175
-
176
-
177
-
178
  /**
179
  * Retrieve objects id field name
180
- *
181
  * @return string
 
 
182
  */
183
  public function getIdFieldName()
184
  {
185
  throw new Exception("getid field???");
186
- return $this->getObject()->getIdFieldName();
187
  }
188
-
189
-
190
-
191
-
192
  /**
193
  * Get filter select that this object will
194
  * pass down to all sub filter
195
- *
196
  * By default it is the parents or the objects filter
197
  * This method can be overwritten
198
- *
199
  * @return Mzax_Emarketing_Db_Select
200
  */
201
  public function getQuery()
202
  {
203
- if(!$this->_allowChildren && $this->_parent) {
204
  return $this->_parent->getQuery();
205
  }
 
206
  return $this->getObject()->getQuery();
207
  }
208
-
209
-
210
-
211
-
212
-
213
-
214
  /**
215
  * Retrieve collection instance from object model
216
  *
@@ -218,81 +218,99 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
218
  */
219
  public function getCollection()
220
  {
221
- if(!$this->_collection) {
222
- /* @var $collection Mzax_Emarketing_Model_Object_Collection */
223
  $this->_collection = Mage::getModel('mzax_emarketing/object_collection');
224
  $this->_collection->setObject($this->getParentObject());
225
  $this->_collection->setQuery($this->getPreparedQuery());
226
-
227
  $this->_prepareCollection($this->_collection);
228
  }
 
229
  return $this->_collection;
230
  }
231
-
232
-
233
-
234
-
235
-
236
 
237
  /**
238
  * Prepare recipient collection
239
  *
 
 
240
  * @return void
241
  */
242
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
243
  {
244
  $this->getParentObject()->prepareCollection($collection);
245
  }
246
-
247
-
248
-
249
-
250
  /**
251
  * Set ID
252
- *
253
  * @param string $id
254
- * @return Mzax_Emarketing_Model_Object_Filter_Component
 
255
  */
256
  public function setId($id)
257
  {
258
  $this->_id = $id;
 
259
  return $this;
260
  }
261
-
262
-
263
  /**
264
- *
265
- *
266
  * @return string
267
  */
268
  public function getId()
269
  {
270
- if(!$this->_id) {
271
  $this->_id = '1';
272
  }
 
273
  return $this->_id;
274
  }
275
-
276
-
277
-
278
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
 
280
  /**
281
  * Set parent
282
  *
283
  * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
284
- * @return Mzax_Emarketing_Model_Object_Filter_Component
 
285
  */
286
  public function setParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
287
  {
288
  $this->_parent = $parent;
 
289
  return $this;
290
  }
291
-
292
-
293
  /**
294
  * Retrieve parent object
295
- *
296
  * @return Mzax_Emarketing_Model_Object_Filter_Component
297
  */
298
  public function getParent()
@@ -300,7 +318,6 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
300
  return $this->_parent;
301
  }
302
 
303
-
304
  /**
305
  * Retrieve parent object
306
  *
@@ -308,132 +325,128 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
308
  */
309
  public function getParentOrSelf()
310
  {
311
- if(!$this->_parent) {
312
  return $this;
313
  }
 
314
  return $this->_parent;
315
  }
316
-
317
-
318
-
319
  /**
320
  * Return all ancestors
321
- *
322
  * @return array
323
  */
324
  public function getAncestors()
325
  {
326
  $ancestors = array();
327
  $parent = $this;
328
- while($parent = $parent->getParent()) {
329
  $ancestors[] = $parent;
330
  }
 
331
  return $ancestors;
332
  }
333
-
334
-
335
-
336
-
337
-
338
  /**
339
- *
340
- *
341
  * @return boolean
342
  */
343
  public function hasBinding()
344
  {
345
  $func = array($this->getQuery(), 'hasBinding');
 
346
  return call_user_func_array($func, func_get_args());
347
  }
348
-
349
-
350
-
351
-
352
-
353
  /**
354
  * Retrieve top most object
355
- *
356
  * @return Mzax_Emarketing_Model_Object_Filter_Component
357
  */
358
  public function getRoot()
359
  {
360
- /* @var $object Mzax_Emarketing_Model_Object_Filter_Component */
361
  $object = $this;
362
-
363
- while($object->getParent()) {
364
  $object = $object->getParent();
365
  }
366
-
367
  return $object;
368
  }
369
-
370
-
371
-
372
-
373
 
374
  /**
375
  * Retrieve full type path
376
- *
377
- * @return $string
 
 
378
  */
379
  public function getTypePath($delimiter = '-')
380
  {
381
  $paths = array();
382
-
383
- /* @var $object Mzax_Emarketing_Model_Object_Filter_Component */
384
  $object = $this;
385
  do {
386
- if($object instanceof Mzax_Emarketing_Model_Object_Filter_Container) {
387
  break;
388
  }
389
  $paths[] = $object->getType();
390
- } while($object = $object->getParent());
391
-
392
  $paths = array_reverse($paths);
393
-
394
- return implode($delimiter, $paths);
 
 
395
  }
396
-
397
-
398
-
399
  /**
400
  * Both parent and child need to accept
401
- *
402
  * @param Mzax_Emarketing_Model_Object_Filter_Component $filter
 
403
  * @return boolean
404
  */
405
  public function acceptFilter(Mzax_Emarketing_Model_Object_Filter_Component $filter)
406
  {
407
- return $filter->acceptParent($this) && $this->acceptChild($filter);
 
 
 
 
 
 
 
 
408
  }
409
-
410
-
411
-
412
  /**
413
  * Accept child
414
- *
415
- * By default we can accept all childs, however if the parent
416
  * already accepts this child then skip it to prevent useless nesting.
417
- *
418
  * Sometimes this is unwanted, in that case overwrite this method
419
- *
420
  * @param Mzax_Emarketing_Model_Object_Filter_Component $child
 
421
  * @return boolean
422
  */
423
  public function acceptChild(Mzax_Emarketing_Model_Object_Filter_Component $child)
424
  {
425
- if($this->_parent) {
426
  return !$child->acceptParent($this->_parent);
427
  }
 
428
  return true;
429
  }
430
-
431
-
432
-
433
  /**
434
  * Accept parent
435
- *
436
  * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
 
437
  * @return boolean
438
  */
439
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
@@ -441,181 +454,189 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
441
  return false;
442
  }
443
 
444
-
445
-
446
-
447
  /**
448
  * Retrieve id filter name
449
- *
450
  * The name of the id field that we use
451
  * to filter.
452
- *
453
- * Usally it is the same name as the id field name
454
  * however some filter almost act as an adapter,
455
  * they allow to retrieve customer_ids, but use
456
  * the order_id as filter
457
- *
458
  * @return string
 
 
459
  */
460
  public function getIdFilterName()
461
  {
462
  throw new Exception("getIdFilterName!!!");
463
- return $this->getObject()->getIdFieldName();
464
  }
465
-
466
-
467
-
468
-
469
-
470
 
471
  /**
472
  * Retrieve available child filters
473
  *
474
- * @return array
475
  */
476
  public function getAvailableFilters()
477
  {
478
- if(!$this->_allowChildren) {
479
  return array();
480
  }
481
-
482
  $filters = self::getFilterFactory()->getFilters();
483
- $result = array();
484
-
485
- /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
486
- foreach($filters as $name => $filter) {
487
- if($this->acceptFilter($filter)) {
488
- foreach($filter->getOptions() as $key => $title) {
489
  $result[$key] = $title;
490
  }
491
  }
492
  }
493
-
494
  return $result;
495
  }
496
-
497
-
498
-
499
-
500
-
501
 
502
  //--------------------------------------------------------------------------
503
  //
504
  // Recipient Grid Methods
505
  //
506
  //--------------------------------------------------------------------------
507
-
508
 
 
 
 
 
 
 
 
 
 
509
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
510
  {
511
  $this->getParentObject()->prepareGridColumns($grid);
512
  }
513
-
514
-
 
 
 
 
 
 
 
 
 
515
  public function afterGridLoadCollection(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
516
  {
517
  $this->getParentObject()->afterGridLoadCollection($grid);
518
  }
519
-
520
-
 
 
 
 
 
 
 
521
  public function afterLoadCollection($collection)
522
  {
523
- $this->getParentObject()->afterLoadCollection($grid);
524
  }
525
-
526
-
527
-
528
-
 
 
529
  public function getFormPrefix()
530
  {
531
  return 'filter';
532
  }
533
-
534
-
535
-
536
-
537
 
538
  //--------------------------------------------------------------------------
539
  //
540
  // Helper Methods
541
  //
542
  //--------------------------------------------------------------------------
543
-
544
  const TEMP_TABLE_PREFIX = 'MZAX_TMP_FILTER_';
545
-
546
  /**
547
- * Retreive parameter set on the root object
548
- *
549
  * @param string $key
550
  * @param mixed $default
 
551
  * @return mixed
552
  */
553
  public function getParam($key, $default = null)
554
  {
555
  $value = $this->getRoot()->getData('param_' . $key);
556
- if($value === null) {
557
  return $default;
558
  }
559
  return $value;
560
  }
561
-
 
 
 
 
 
 
 
 
562
  public function setParam($key, $value)
563
  {
564
  $this->getRoot()->setData('param_' . $key, $value);
 
565
  return $this;
566
  }
567
-
568
-
569
-
570
-
571
  /**
572
- * Retrieve a uniqe temporary table name that is valid for the livetime of this
573
  * filter instance.
574
- *
575
- * @param string $sufix
 
576
  * @return string
577
  */
578
- public function getTempTableName($sufix = 'default')
579
  {
580
- // can be globaly disabled
581
- if(!Mage::getStoreConfigFlag('mzax_emarketing/general/use_temp_tables')) {
582
  return false;
583
  }
584
-
585
  // can be disabled by param
586
- if($this->getParam('disable_temp_tables')) {
587
  return false;
588
  }
589
-
590
  // only works if we have the rights
591
- if(!$this->getResourceHelper()->hasTemporaryTablePrivilege()) {
592
  return false;
593
  }
594
-
595
- //return false;
596
  $hash = $this->getParam('unique_filter_hash', microtime().mt_rand(0, 1000));
597
- return strtoupper(self::TEMP_TABLE_PREFIX . md5($hash . '__' . $this->getId()) . '_' . $sufix);
 
 
598
  }
599
-
600
-
601
-
602
-
603
-
604
  /**
605
  * Retrieve id column name
606
- *
607
  * @return Zend_Db_Expr
608
  */
609
  public function getIdColumn()
610
  {
611
  return new Zend_Db_Expr("`e`.`{$this->_idFieldName}`");
612
  }
613
-
614
-
615
-
616
-
617
-
618
-
619
 
620
  /**
621
  * Retrieve session model
@@ -624,12 +645,9 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
624
  */
625
  public function getSession()
626
  {
627
- return Mage::getSingleton('mzax_emarketing/session');
628
  }
629
-
630
-
631
-
632
-
633
  /**
634
  * Retrieve provider factory
635
  *
@@ -639,21 +657,16 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
639
  {
640
  return Mage::getSingleton('mzax_emarketing/object_filter');
641
  }
642
-
643
-
644
-
645
-
646
  /**
647
- *
648
  * @return Mzax_Emarketing_Model_Resource_Helper
649
  */
650
  protected function getResourceHelper()
651
  {
652
  return Mage::getResourceSingleton('mzax_emarketing/helper');
653
  }
654
-
655
-
656
-
657
  /**
658
  * Retrieve connection for read data
659
  *
@@ -663,9 +676,7 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
663
  {
664
  return $this->getResourceHelper()->getReadAdapter();
665
  }
666
-
667
-
668
-
669
  /**
670
  * Retrieve connection for write data
671
  *
@@ -675,89 +686,114 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Obje
675
  {
676
  return $this->getResourceHelper()->getWriteAdapter();
677
  }
678
-
679
-
680
-
681
-
682
  /**
683
- *
 
684
  * @param string $table
685
  * @param string $alias
686
  * @param string $cols
 
687
  * @return Mzax_Emarketing_Db_Select
688
  */
689
  protected function _select($table = null, $alias = null, $cols = null)
690
  {
691
  $select = $this->getResourceHelper()->select();
692
- if($table) {
693
  $select->from($this->_getTable($table, $alias), $cols);
694
  }
 
695
  return $select;
696
  }
697
-
698
-
699
  /**
700
  * Retrieve table name
701
  *
702
  * @param string $table
703
  * @param string $alias
 
704
  * @return string
705
  */
706
  protected function _getTable($table, $alias = null)
707
  {
708
  $table = $this->getResourceHelper()->getTable($table);
709
- if($alias) {
710
  return array($alias => $table);
711
  }
 
712
  return $table;
713
  }
714
-
715
-
716
-
717
  /**
718
- * Retrieve an attribute by entityname/attributename
719
  *
720
  * getAttribute(entity/attribute);
721
  * getAttribute(customer/signupdate);
722
  *
723
  * @param string $attribute
724
- * @throws Exception
725
  *
726
- * @return Mage_Catalog_Model_Resource_Eav_Attribute
 
727
  */
728
  protected function _getAttribute($attribute)
729
  {
730
  return $this->getResourceHelper()->getAttribute($attribute);
731
  }
732
-
733
-
734
-
735
-
736
-
737
-
738
  /**
739
  * Retrieve form helper
740
- *
741
  * @return Mzax_Emarketing_Helper_Data
742
  */
743
  protected function helper()
744
  {
745
  return Mage::helper('mzax_emarketing');
746
  }
747
-
748
 
749
-
750
  /**
751
  * Translate
752
- *
753
  * @param string $message
754
  * @param string $args,...
 
755
  * @return string
756
  */
757
- protected function __()
758
  {
759
  return call_user_func_array(array($this->helper(), '__'), func_get_args());
760
  }
761
-
762
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+ /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Component
21
+ */
22
  abstract class Mzax_Emarketing_Model_Object_Filter_Component extends Varien_Object
23
  {
 
24
  const ID_ALIAS = 'object_id';
25
+
26
+ /**
27
+ * @var string
28
+ */
29
  protected $_id;
30
+
31
+ /**
32
+ * Unique component type id
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_type;
37
+
38
  /**
39
  * Parent Filter
40
  *
41
  * @var Mzax_Emarketing_Model_Object_Filter_Component
42
  */
43
  protected $_parent;
44
+
45
+ /**
 
 
 
 
 
 
46
  * @var Mzax_Emarketing_Model_Object_Collection
47
  */
48
  protected $_collection;
49
+
 
 
 
 
50
  /**
51
  * Can have children
52
+ *
53
  * @var boolean
54
  */
55
  protected $_allowChildren = false;
56
+
57
+ /**
58
+ * @var Mzax_Emarketing_Model_Config
59
+ */
60
+ protected $_config;
61
+
62
+ /**
63
+ * @var Mzax_Emarketing_Model_SessionManager
64
+ */
65
+ protected $_sessionManager;
66
+
67
+ /**
68
+ * Mzax_Emarketing_Model_Outbox constructor.
69
+ */
70
+ public function _construct()
71
+ {
72
+ parent::_construct();
73
+
74
+ $this->_config = Mage::getSingleton('mzax_emarketing/config');
75
+ $this->_sessionManager = Mage::getSingleton('mzax_emarketing/sessionManager');
76
+ }
77
+
78
  /**
79
  * The subject provides generic information for the email provider/filter object.
80
+ * So for instance, the email provider customer
81
+ *
 
82
  * @return Mzax_Emarketing_Model_Object_Abstract
83
  */
84
+ abstract public function getObject();
85
+
 
 
86
  /**
87
+ * Retrieve parent object
88
+ *
89
  * @return Mzax_Emarketing_Model_Object_Abstract
90
  */
91
  public function getParentObject()
92
  {
93
  return $this->getParentOrSelf()->getObject();
94
  }
95
+
 
 
96
  /**
97
+ * Retrieve Expression used for current time
98
+ *
99
+ * By default the function should return the
100
  * mysql expression NOW() but we want to be able
101
  * to change the current time in order to test
102
  * filters etc for different times
103
+ *
104
  * Also some filters may require the local time
105
  * not the gmt time
106
+ *
107
+ * @param boolean $gmt Get as gmt time
108
+ *
109
+ * @return string[]|Zend_Db_Expr[]
110
  */
111
  public function getCurrentTime($gmt = true)
112
  {
113
  $adapter = $this->_getReadAdapter();
114
+
115
+ // is current specified time is the local time or not
116
+ $isLocal = (bool)$this->getParam('is_local_time');
117
+
118
  // check if we emulate current itme
119
+ $now = (array)$this->getParam('current_time');
120
  $now = array_filter($now);
121
+ foreach ($now as &$time) {
122
+ if (!$time instanceof Zend_Db_Expr) {
123
  $time = $adapter->quote($time);
124
  }
125
  }
126
+ if (empty($now)) {
127
  $now[] = $adapter->quote(now());
128
  }
129
+
130
  $result = array();
131
+ foreach ($now as $date) {
132
+ if ($gmt && $isLocal) {
133
  $result[] = $this->toGmtTime($date);
134
+ } elseif (!$gmt && !$isLocal) {
 
135
  $result[] = $this->toLocalTime($date);
136
+ } else {
 
137
  $result[] = $date;
138
  }
139
  }
140
+
141
  return $result;
142
  }
143
+
 
 
144
  /**
145
  * Retrieve filter select
146
+ *
147
  * @return Mzax_Emarketing_Db_Select
148
  */
149
  public function getSelect()
150
  {
151
  return $this->getPreparedQuery();
152
  }
153
+
 
 
154
  /**
155
  * Retrieve prepared query
156
+ *
157
  * @return Mzax_Emarketing_Db_Select
158
  */
159
+ public function getPreparedQuery()
160
  {
161
  $query = $this->getParentOrSelf()->getQuery();
162
+ $query->lock();
163
+
164
+ $this->_prepareQuery($query);
165
+
166
  $query->comment('FILTER: ' . get_class($this));
167
+ $query->lock(false);
168
 
169
+ return $query;
170
  }
171
+
 
 
172
  /**
173
  * Takes the query provided by the parent and modifies it
174
  * to match the filter settings
175
+ *
176
  * @param Mzax_Emarketing_Db_Select $query
177
+ *
178
+ * @return void
179
  */
180
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
181
+ {
182
  }
183
+
 
 
 
184
  /**
185
  * Retrieve objects id field name
186
+ *
187
  * @return string
188
+ * @throws Exception
189
+ * @deprecated
190
  */
191
  public function getIdFieldName()
192
  {
193
  throw new Exception("getid field???");
 
194
  }
195
+
 
 
 
196
  /**
197
  * Get filter select that this object will
198
  * pass down to all sub filter
199
+ *
200
  * By default it is the parents or the objects filter
201
  * This method can be overwritten
202
+ *
203
  * @return Mzax_Emarketing_Db_Select
204
  */
205
  public function getQuery()
206
  {
207
+ if (!$this->_allowChildren && $this->_parent) {
208
  return $this->_parent->getQuery();
209
  }
210
+
211
  return $this->getObject()->getQuery();
212
  }
213
+
 
 
 
 
 
214
  /**
215
  * Retrieve collection instance from object model
216
  *
218
  */
219
  public function getCollection()
220
  {
221
+ if (!$this->_collection) {
 
222
  $this->_collection = Mage::getModel('mzax_emarketing/object_collection');
223
  $this->_collection->setObject($this->getParentObject());
224
  $this->_collection->setQuery($this->getPreparedQuery());
225
+
226
  $this->_prepareCollection($this->_collection);
227
  }
228
+
229
  return $this->_collection;
230
  }
 
 
 
 
 
231
 
232
  /**
233
  * Prepare recipient collection
234
  *
235
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
236
+ *
237
  * @return void
238
  */
239
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
240
  {
241
  $this->getParentObject()->prepareCollection($collection);
242
  }
243
+
 
 
 
244
  /**
245
  * Set ID
246
+ *
247
  * @param string $id
248
+ *
249
+ * @return $this
250
  */
251
  public function setId($id)
252
  {
253
  $this->_id = $id;
254
+
255
  return $this;
256
  }
257
+
 
258
  /**
259
+ * Retrieve id
260
+ *
261
  * @return string
262
  */
263
  public function getId()
264
  {
265
+ if (!$this->_id) {
266
  $this->_id = '1';
267
  }
268
+
269
  return $this->_id;
270
  }
271
+
272
+ /**
273
+ * Set type
274
+ *
275
+ * @param string $type
276
+ *
277
+ * @return $this
278
+ */
279
+ public function setType($type)
280
+ {
281
+ $this->_type = $type;
282
+
283
+ return $this;
284
+ }
285
+
286
+
287
+ /**
288
+ * Retrieve type
289
+ *
290
+ * @return string
291
+ */
292
+ public function getType()
293
+ {
294
+ return $this->_type;
295
+ }
296
 
297
  /**
298
  * Set parent
299
  *
300
  * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
301
+ *
302
+ * @return $this
303
  */
304
  public function setParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
305
  {
306
  $this->_parent = $parent;
307
+
308
  return $this;
309
  }
310
+
 
311
  /**
312
  * Retrieve parent object
313
+ *
314
  * @return Mzax_Emarketing_Model_Object_Filter_Component
315
  */
316
  public function getParent()
318
  return $this->_parent;
319
  }
320
 
 
321
  /**
322
  * Retrieve parent object
323
  *
325
  */
326
  public function getParentOrSelf()
327
  {
328
+ if (!$this->_parent) {
329
  return $this;
330
  }
331
+
332
  return $this->_parent;
333
  }
334
+
 
 
335
  /**
336
  * Return all ancestors
337
+ *
338
  * @return array
339
  */
340
  public function getAncestors()
341
  {
342
  $ancestors = array();
343
  $parent = $this;
344
+ while ($parent = $parent->getParent()) {
345
  $ancestors[] = $parent;
346
  }
347
+
348
  return $ancestors;
349
  }
350
+
 
 
 
 
351
  /**
352
+ * Check if we have binding
353
+ *
354
  * @return boolean
355
  */
356
  public function hasBinding()
357
  {
358
  $func = array($this->getQuery(), 'hasBinding');
359
+
360
  return call_user_func_array($func, func_get_args());
361
  }
362
+
 
 
 
 
363
  /**
364
  * Retrieve top most object
365
+ *
366
  * @return Mzax_Emarketing_Model_Object_Filter_Component
367
  */
368
  public function getRoot()
369
  {
 
370
  $object = $this;
371
+
372
+ while ($object->getParent()) {
373
  $object = $object->getParent();
374
  }
375
+
376
  return $object;
377
  }
 
 
 
 
378
 
379
  /**
380
  * Retrieve full type path
381
+ *
382
+ * @param string $delimiter
383
+ *
384
+ * @return string $string
385
  */
386
  public function getTypePath($delimiter = '-')
387
  {
388
  $paths = array();
 
 
389
  $object = $this;
390
  do {
391
+ if ($object instanceof Mzax_Emarketing_Model_Object_Filter_Main) {
392
  break;
393
  }
394
  $paths[] = $object->getType();
395
+ } while ($object = $object->getParent());
396
+
397
  $paths = array_reverse($paths);
398
+
399
+ $path = implode($delimiter, $paths);
400
+
401
+ return $path;
402
  }
403
+
 
 
404
  /**
405
  * Both parent and child need to accept
406
+ *
407
  * @param Mzax_Emarketing_Model_Object_Filter_Component $filter
408
+ *
409
  * @return boolean
410
  */
411
  public function acceptFilter(Mzax_Emarketing_Model_Object_Filter_Component $filter)
412
  {
413
+ if (!$filter->acceptParent($this)) {
414
+ return false;
415
+ }
416
+
417
+ if (!$filter->acceptChild($this)) {
418
+ return false;
419
+ }
420
+
421
+ return true;
422
  }
423
+
 
 
424
  /**
425
  * Accept child
426
+ *
427
+ * By default we can accept all children, however if the parent
428
  * already accepts this child then skip it to prevent useless nesting.
429
+ *
430
  * Sometimes this is unwanted, in that case overwrite this method
431
+ *
432
  * @param Mzax_Emarketing_Model_Object_Filter_Component $child
433
+ *
434
  * @return boolean
435
  */
436
  public function acceptChild(Mzax_Emarketing_Model_Object_Filter_Component $child)
437
  {
438
+ if ($this->_parent) {
439
  return !$child->acceptParent($this->_parent);
440
  }
441
+
442
  return true;
443
  }
444
+
 
 
445
  /**
446
  * Accept parent
447
+ *
448
  * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
449
+ *
450
  * @return boolean
451
  */
452
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
454
  return false;
455
  }
456
 
 
 
 
457
  /**
458
  * Retrieve id filter name
459
+ *
460
  * The name of the id field that we use
461
  * to filter.
462
+ *
463
+ * Usually it is the same name as the id field name
464
  * however some filter almost act as an adapter,
465
  * they allow to retrieve customer_ids, but use
466
  * the order_id as filter
467
+ *
468
  * @return string
469
+ * @throws Exception
470
+ * @deprecated
471
  */
472
  public function getIdFilterName()
473
  {
474
  throw new Exception("getIdFilterName!!!");
 
475
  }
 
 
 
 
 
476
 
477
  /**
478
  * Retrieve available child filters
479
  *
480
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract[]
481
  */
482
  public function getAvailableFilters()
483
  {
484
+ if (!$this->_allowChildren) {
485
  return array();
486
  }
487
+
488
  $filters = self::getFilterFactory()->getFilters();
489
+ $result = array();
490
+
491
+ foreach ($filters as $name => $filter) {
492
+ if ($this->acceptFilter($filter)) {
493
+ foreach ($filter->getOptions() as $key => $title) {
 
494
  $result[$key] = $title;
495
  }
496
  }
497
  }
498
+
499
  return $result;
500
  }
 
 
 
 
 
501
 
502
  //--------------------------------------------------------------------------
503
  //
504
  // Recipient Grid Methods
505
  //
506
  //--------------------------------------------------------------------------
 
507
 
508
+ /**
509
+ * Prepare grid columns
510
+ *
511
+ * Allow filter to add additional gird columns relevant to it
512
+ *
513
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
514
+ *
515
+ * @return void
516
+ */
517
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
518
  {
519
  $this->getParentObject()->prepareGridColumns($grid);
520
  }
521
+
522
+ /**
523
+ * After collection load
524
+ *
525
+ * Allow grid to alter the collection after load
526
+ *
527
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
528
+ *
529
+ * @return void
530
+ * @deprecated
531
+ */
532
  public function afterGridLoadCollection(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
533
  {
534
  $this->getParentObject()->afterGridLoadCollection($grid);
535
  }
536
+
537
+ /**
538
+ * After collection load
539
+ *
540
+ * @param $collection
541
+ *
542
+ * @return void
543
+ * @deprecated
544
+ */
545
  public function afterLoadCollection($collection)
546
  {
547
+ $this->getParentObject()->afterLoadCollection($collection);
548
  }
549
+
550
+ /**
551
+ * Form prefix
552
+ *
553
+ * @return string
554
+ */
555
  public function getFormPrefix()
556
  {
557
  return 'filter';
558
  }
 
 
 
 
559
 
560
  //--------------------------------------------------------------------------
561
  //
562
  // Helper Methods
563
  //
564
  //--------------------------------------------------------------------------
565
+
566
  const TEMP_TABLE_PREFIX = 'MZAX_TMP_FILTER_';
567
+
568
  /**
569
+ * Retrieve parameter set on the root object
570
+ *
571
  * @param string $key
572
  * @param mixed $default
573
+ *
574
  * @return mixed
575
  */
576
  public function getParam($key, $default = null)
577
  {
578
  $value = $this->getRoot()->getData('param_' . $key);
579
+ if ($value === null) {
580
  return $default;
581
  }
582
  return $value;
583
  }
584
+
585
+ /**
586
+ * Set parameter
587
+ *
588
+ * @param string $key
589
+ * @param mixed $value
590
+ *
591
+ * @return $this
592
+ */
593
  public function setParam($key, $value)
594
  {
595
  $this->getRoot()->setData('param_' . $key, $value);
596
+
597
  return $this;
598
  }
599
+
 
 
 
600
  /**
601
+ * Retrieve a unique temporary table name that is valid for the live time of this
602
  * filter instance.
603
+ *
604
+ * @param string $suffix
605
+ *
606
  * @return string
607
  */
608
+ public function getTempTableName($suffix = 'default')
609
  {
610
+ // can be globally disabled
611
+ if (!$this->_config->flag('mzax_emarketing/general/use_temp_tables')) {
612
  return false;
613
  }
614
+
615
  // can be disabled by param
616
+ if ($this->getParam('disable_temp_tables')) {
617
  return false;
618
  }
619
+
620
  // only works if we have the rights
621
+ if (!$this->getResourceHelper()->hasTemporaryTablePrivilege()) {
622
  return false;
623
  }
624
+
 
625
  $hash = $this->getParam('unique_filter_hash', microtime().mt_rand(0, 1000));
626
+ $name = strtoupper(self::TEMP_TABLE_PREFIX . md5($hash . '__' . $this->getId()) . '_' . $suffix);
627
+
628
+ return $name;
629
  }
630
+
 
 
 
 
631
  /**
632
  * Retrieve id column name
633
+ *
634
  * @return Zend_Db_Expr
635
  */
636
  public function getIdColumn()
637
  {
638
  return new Zend_Db_Expr("`e`.`{$this->_idFieldName}`");
639
  }
 
 
 
 
 
 
640
 
641
  /**
642
  * Retrieve session model
645
  */
646
  public function getSession()
647
  {
648
+ return $this->_sessionManager->getSession();
649
  }
650
+
 
 
 
651
  /**
652
  * Retrieve provider factory
653
  *
657
  {
658
  return Mage::getSingleton('mzax_emarketing/object_filter');
659
  }
660
+
 
 
 
661
  /**
662
+ *
663
  * @return Mzax_Emarketing_Model_Resource_Helper
664
  */
665
  protected function getResourceHelper()
666
  {
667
  return Mage::getResourceSingleton('mzax_emarketing/helper');
668
  }
669
+
 
 
670
  /**
671
  * Retrieve connection for read data
672
  *
676
  {
677
  return $this->getResourceHelper()->getReadAdapter();
678
  }
679
+
 
 
680
  /**
681
  * Retrieve connection for write data
682
  *
686
  {
687
  return $this->getResourceHelper()->getWriteAdapter();
688
  }
689
+
 
 
 
690
  /**
691
+ * Create db select instance
692
+ *
693
  * @param string $table
694
  * @param string $alias
695
  * @param string $cols
696
+ *
697
  * @return Mzax_Emarketing_Db_Select
698
  */
699
  protected function _select($table = null, $alias = null, $cols = null)
700
  {
701
  $select = $this->getResourceHelper()->select();
702
+ if ($table) {
703
  $select->from($this->_getTable($table, $alias), $cols);
704
  }
705
+
706
  return $select;
707
  }
708
+
 
709
  /**
710
  * Retrieve table name
711
  *
712
  * @param string $table
713
  * @param string $alias
714
+ *
715
  * @return string
716
  */
717
  protected function _getTable($table, $alias = null)
718
  {
719
  $table = $this->getResourceHelper()->getTable($table);
720
+ if ($alias) {
721
  return array($alias => $table);
722
  }
723
+
724
  return $table;
725
  }
726
+
 
 
727
  /**
728
+ * Retrieve an attribute by entity-name/attribute-name
729
  *
730
  * getAttribute(entity/attribute);
731
  * getAttribute(customer/signupdate);
732
  *
733
  * @param string $attribute
 
734
  *
735
+ * @return Mage_Eav_Model_Entity_Attribute_Abstract
736
+ * @throws Exception
737
  */
738
  protected function _getAttribute($attribute)
739
  {
740
  return $this->getResourceHelper()->getAttribute($attribute);
741
  }
742
+
 
 
 
 
 
743
  /**
744
  * Retrieve form helper
745
+ *
746
  * @return Mzax_Emarketing_Helper_Data
747
  */
748
  protected function helper()
749
  {
750
  return Mage::helper('mzax_emarketing');
751
  }
 
752
 
 
753
  /**
754
  * Translate
755
+ *
756
  * @param string $message
757
  * @param string $args,...
758
+ *
759
  * @return string
760
  */
761
+ protected function __($message, $args = null)
762
  {
763
  return call_user_func_array(array($this->helper(), '__'), func_get_args());
764
  }
765
+
766
+ /**
767
+ * Converts local date expression to gmt time gmt offset
768
+ *
769
+ * @param string $localDateExpr
770
+ *
771
+ * @return string
772
+ */
773
+ protected function toGmtTime($localDateExpr)
774
+ {
775
+ $gmtOffset = (int)$this->getParam('gmt_offset', 0);
776
+ if ($gmtOffset) {
777
+ $localDateExpr = "DATE_SUB($localDateExpr, INTERVAL $gmtOffset MINUTE)";
778
+ }
779
+
780
+ return $localDateExpr;
781
+ }
782
+
783
+ /**
784
+ * Convert database field to local time by applying specified gmt offset
785
+ *
786
+ * @param string $gmtDateExpr
787
+ *
788
+ * @return string
789
+ */
790
+ protected function toLocalTime($gmtDateExpr)
791
+ {
792
+ $gmtOffset = (int) $this->getParam('gmt_offset', 0);
793
+ if ($gmtOffset) {
794
+ $gmtDateExpr = "DATE_SUB($gmtDateExpr, INTERVAL $gmtOffset MINUTE)";
795
+ }
796
+
797
+ return $gmtDateExpr;
798
+ }
799
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,21 +16,20 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  abstract class Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
26
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
27
  {
28
-
29
-
 
 
 
30
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
31
  {
32
  return $parent->hasBinding('customer_id');
33
  }
34
-
35
-
36
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
24
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
25
  {
26
+ /**
27
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
28
+ *
29
+ * @return bool
30
+ */
31
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
32
  {
33
  return $parent->hasBinding('customer_id');
34
  }
 
 
 
35
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,38 +18,29 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
24
- *
25
  */
26
  class Mzax_Emarketing_Model_Object_Filter_Customer_Address
27
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
28
  {
29
  const DEFAULT_AGGREGATOR = 'all';
30
-
31
  const DEFAULT_EXPECTATION = 'true';
32
-
33
  const TYPE_BILLING = 'billing';
34
  const TYPE_SHIPPING = 'shipping';
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 | Default Billing/Shippin Address...";
49
  }
50
-
51
-
52
-
53
-
54
  /**
55
  *
56
  * @return Mzax_Emarketing_Model_Object_Customer_Address
@@ -59,130 +49,119 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Address
59
  {
60
  return Mage::getSingleton('mzax_emarketing/object_customer_address');
61
  }
62
-
63
-
64
-
65
  /**
66
- *
67
- * @return Zend_Db_Select
 
 
68
  */
69
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
70
  {
71
  $this->checkIndexes(true);
72
-
73
  $conditions = $this->_getConditions();
74
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
75
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
76
-
77
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
78
  $select->useTemporaryTable($this->getTempTableName());
79
-
80
  $addressId = $query->joinAttribute('customer_id', 'customer/default_billing');
81
-
82
  $query->joinSelect(array('id' => $addressId), $select, 'filter');
83
  $query->group();
84
  }
85
-
86
-
87
-
88
-
89
 
 
 
 
 
 
90
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
91
  {
92
  parent::_prepareCollection($collection);
93
  }
94
-
95
-
96
-
97
-
98
-
 
99
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
100
  {
101
  parent::prepareGridColumns($grid);
102
-
103
-
104
  }
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
  /**
115
- * (non-PHPdoc)
116
- * @see Mzax_Emarketing_Model_Object_Filter_Abstract::prepareForm()
117
  */
118
  protected function prepareForm()
119
  {
120
- $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
121
-
122
- return $this->__('If default billing address matches %s of these conditions:',
 
123
  $aggregatorElement->toHtml()
124
- );
125
  }
126
-
127
-
128
-
129
-
130
  /**
131
- * The customer etnity int table does not have an index for value
132
  * which is sort of required by this index
133
- *
 
 
 
 
134
  */
135
  public function checkIndexes($create = false)
136
  {
137
  $adapter = $this->_getWriteAdapter();
138
-
139
  $table = $this->_getAttribute('customer/default_billing')->getBackendTable();
140
-
141
  $indexList = $adapter->getIndexList($table);
142
-
143
  // check if we already created an index
144
- if(isset($indexList['MZAX_IDX_VALUE_ID'])) {
145
  return true;
146
  }
147
-
148
  // check for other indexes that can work
149
- foreach($indexList as $index) {
150
- switch(count($index['fields'])) {
151
  case 1:
152
- if($index['fields'][0] === 'value') {
153
  return true;
154
  }
155
  break;
156
  case 2:
157
- if($index['fields'][0] === 'attribute_id' && $index['fields'][1] === 'value') {
158
  return true;
159
  }
160
  break;
161
  }
162
  }
163
-
164
-
165
- if($create && $this->canCreateIndex()) {
166
  try {
167
  $adapter->addIndex($table, 'MZAX_IDX_VALUE_ID', array('attribute_id', 'value'));
168
  return true;
169
- }
170
- catch(Exception $e) {
171
- if(Mage::getIsDeveloperMode()) {
172
  throw $e;
173
  }
174
  Mage::logException($e);
175
  return $this->__('Failed to create an index for the table "%s". Please check logs.', $table);
176
  }
177
- }
178
- else if($this->canCreateIndex()) {
179
  return true;
180
  }
181
-
182
- return $this->__('It is recommended to set an index on "value" for the table "%s" before using this filter.', $table);
183
- }
184
-
185
-
186
-
187
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Customer_Address
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Customer_Address
24
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
25
  {
26
  const DEFAULT_AGGREGATOR = 'all';
 
27
  const DEFAULT_EXPECTATION = 'true';
 
28
  const TYPE_BILLING = 'billing';
29
  const TYPE_SHIPPING = 'shipping';
 
 
30
 
31
+ /**
32
+ * @var bool
33
+ */
34
  protected $_allowChildren = true;
 
 
35
 
36
  /**
37
+ * @return string
 
38
  */
39
  public function getTitle()
40
  {
41
  return "Customer | Default Billing/Shippin Address...";
42
  }
43
+
 
 
 
44
  /**
45
  *
46
  * @return Mzax_Emarketing_Model_Object_Customer_Address
49
  {
50
  return Mage::getSingleton('mzax_emarketing/object_customer_address');
51
  }
52
+
 
 
53
  /**
54
+ *
55
+ * @param Mzax_Emarketing_Db_Select $query
56
+ *
57
+ * @return void
58
  */
59
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
60
  {
61
  $this->checkIndexes(true);
62
+
63
  $conditions = $this->_getConditions();
64
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
65
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
66
+
67
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
68
  $select->useTemporaryTable($this->getTempTableName());
69
+
70
  $addressId = $query->joinAttribute('customer_id', 'customer/default_billing');
71
+
72
  $query->joinSelect(array('id' => $addressId), $select, 'filter');
73
  $query->group();
74
  }
 
 
 
 
75
 
76
+ /**
77
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
78
+ *
79
+ * @return void
80
+ */
81
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
82
  {
83
  parent::_prepareCollection($collection);
84
  }
85
+
86
+ /**
87
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
88
+ *
89
+ * @return void
90
+ */
91
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
92
  {
93
  parent::prepareGridColumns($grid);
 
 
94
  }
95
+
 
 
 
 
 
 
 
 
96
  /**
97
+ * @return string
 
98
  */
99
  protected function prepareForm()
100
  {
101
+ $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
102
+
103
+ return $this->__(
104
+ 'If default billing address matches %s of these conditions:',
105
  $aggregatorElement->toHtml()
106
+ );
107
  }
108
+
 
 
 
109
  /**
110
+ * The customer entity int table does not have an index for value
111
  * which is sort of required by this index
112
+ *
113
+ * @param bool $create
114
+ *
115
+ * @return bool|string|true
116
+ * @throws Exception
117
  */
118
  public function checkIndexes($create = false)
119
  {
120
  $adapter = $this->_getWriteAdapter();
121
+
122
  $table = $this->_getAttribute('customer/default_billing')->getBackendTable();
123
+
124
  $indexList = $adapter->getIndexList($table);
125
+
126
  // check if we already created an index
127
+ if (isset($indexList['MZAX_IDX_VALUE_ID'])) {
128
  return true;
129
  }
130
+
131
  // check for other indexes that can work
132
+ foreach ($indexList as $index) {
133
+ switch (count($index['fields'])) {
134
  case 1:
135
+ if ($index['fields'][0] === 'value') {
136
  return true;
137
  }
138
  break;
139
  case 2:
140
+ if ($index['fields'][0] === 'attribute_id' && $index['fields'][1] === 'value') {
141
  return true;
142
  }
143
  break;
144
  }
145
  }
146
+
147
+ if ($create && $this->canCreateIndex()) {
 
148
  try {
149
  $adapter->addIndex($table, 'MZAX_IDX_VALUE_ID', array('attribute_id', 'value'));
150
  return true;
151
+ } catch (Exception $e) {
152
+ if (Mage::getIsDeveloperMode()) {
 
153
  throw $e;
154
  }
155
  Mage::logException($e);
156
  return $this->__('Failed to create an index for the table "%s". Please check logs.', $table);
157
  }
158
+ } elseif ($this->canCreateIndex()) {
 
159
  return true;
160
  }
 
 
 
 
 
 
161
 
162
+ return $this->__(
163
+ 'It is recommended to set an index on "value" for the table "%s" before using this filter.',
164
+ $table
165
+ );
166
+ }
167
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Address/Attribute.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,38 +17,33 @@
18
  */
19
 
20
 
21
-
22
  /**
 
 
23
  * Filter for customer address attributes
24
- *
25
- * @author Jacob Siefer
26
  */
27
  class Mzax_Emarketing_Model_Object_Filter_Customer_Address_Attribute
28
  extends Mzax_Emarketing_Model_Object_Filter_Attribute
29
  {
30
-
31
  /**
32
  * Entity type code
33
- *
34
  * @var string
35
  */
36
  protected $_entity = 'customer_address';
37
-
38
-
39
  /**
40
  * Binding required
41
- *
42
  * @var string
43
  */
44
  protected $_requireBinding = 'customer_address_id';
45
 
46
-
47
-
 
48
  public function getTitle()
49
  {
50
- return "Customer Adddress";
51
  }
52
-
53
-
54
-
55
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Customer_Address_Attribute
22
+ *
23
  * Filter for customer address attributes
 
 
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Customer_Address_Attribute
26
  extends Mzax_Emarketing_Model_Object_Filter_Attribute
27
  {
 
28
  /**
29
  * Entity type code
30
+ *
31
  * @var string
32
  */
33
  protected $_entity = 'customer_address';
34
+
 
35
  /**
36
  * Binding required
37
+ *
38
  * @var string
39
  */
40
  protected $_requireBinding = 'customer_address_id';
41
 
42
+ /**
43
+ * @return string
44
+ */
45
  public function getTitle()
46
  {
47
+ return "Customer Address";
48
  }
 
 
 
49
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Attribute.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,37 +17,40 @@
18
  */
19
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Customer_Attribute
26
  extends Mzax_Emarketing_Model_Object_Filter_Attribute
27
  {
28
-
29
-
 
30
  protected $_entity = 'customer';
31
-
32
-
 
 
33
  protected $_requireBinding = 'customer_id';
34
 
35
-
36
-
 
37
  public function getTitle()
38
  {
39
  return "Customer Attributes";
40
  }
41
-
42
-
43
-
 
 
 
44
  protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
45
  {
46
- if($attribute->getFrontendLabel()) {
47
  return true;
48
  }
 
49
  return false;
50
  }
51
-
52
-
53
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Customer_Attribute
 
 
21
  */
22
  class Mzax_Emarketing_Model_Object_Filter_Customer_Attribute
23
  extends Mzax_Emarketing_Model_Object_Filter_Attribute
24
  {
25
+ /**
26
+ * @var string
27
+ */
28
  protected $_entity = 'customer';
29
+
30
+ /**
31
+ * @var string
32
+ */
33
  protected $_requireBinding = 'customer_id';
34
 
35
+ /**
36
+ * @return string
37
+ */
38
  public function getTitle()
39
  {
40
  return "Customer Attributes";
41
  }
42
+
43
+ /**
44
+ * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
45
+ *
46
+ * @return bool
47
+ */
48
  protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
49
  {
50
+ if ($attribute->getFrontendLabel()) {
51
  return true;
52
  }
53
+
54
  return false;
55
  }
 
 
 
56
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Event.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,73 +17,57 @@
18
  */
19
 
20
 
21
-
22
  /**
23
- *
24
  * Listen to 'mzax_emarketing_email_filter_prepare_customer_events' to add
25
  * your own customer event filters
26
- *
27
- * @method Mzax_Emarketing_Model_Object_Filter_Customer_Event setName(string $value)
28
- * @method Mzax_Emarketing_Model_Object_Filter_Customer_Event setAggregator(string $value)
29
- * @method Mzax_Emarketing_Model_Object_Filter_Customer_Event setExpectation(string $value)
30
- * @method Mzax_Emarketing_Model_Object_Filter_Customer_Event setEventDateTo(string $value)
31
- * @method Mzax_Emarketing_Model_Object_Filter_Customer_Event setEventDateFrom(string $value)
32
- * @method Mzax_Emarketing_Model_Object_Filter_Customer_Event setEventDateUnit(string $value)
33
- *
34
- *
35
- * @author Jacob Siefer
36
  *
37
  */
38
  class Mzax_Emarketing_Model_Object_Filter_Customer_Event
39
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
40
  {
41
-
42
-
43
  const DEFAULT_AGGREGATOR = 'all';
44
-
45
  const DEFAULT_EXPECTATION = 'true';
46
-
47
-
48
  /**
49
- *
50
  * @var stdClass
51
  */
52
  protected $_event;
53
-
54
-
55
  /**
56
- *
57
  * @var array
58
  */
59
  protected $_events = array();
60
-
61
-
62
  /**
63
- *
64
  * @var array
65
  */
66
  protected $_eventTypeIds;
67
-
68
 
69
  /**
70
- *
71
  * @var boolean
72
  */
73
  protected $_allowChildren = true;
74
-
75
-
76
-
 
77
  public function getTitle()
78
  {
79
  return "Customer";
80
  }
81
-
82
-
83
-
84
  /**
 
85
  *
86
- * (non-PHPdoc)
87
- * @see Mzax_Emarketing_Model_Object_Filter_Abstract::_prepareFilter($config)
88
  */
89
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
90
  {
@@ -92,33 +75,30 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Event
92
  $this->_registerEvents();
93
  Mage::dispatchEvent("mzax_emarketing_email_filter_prepare_customer_events", array('filter' => $this));
94
  }
95
-
96
-
97
-
98
 
 
 
 
99
  public function _registerEvents()
100
  {
101
  $view = $this->addEvent('catalog_product_view');
102
  $view->label = $this->__('Customer viewed product ... ago.');
103
  $view->form = $this->__('Customer viewed product %s ago that matches %s of these conditions %s:');
104
-
105
  $friend = $this->addEvent('sendfriend_product');
106
  $friend->label = $this->__('Customer sent product to a friend ... ago.');
107
  $friend->form = $this->__('Customer sent product to a friend %s ago that matches %s of these conditions %s:');
108
-
109
  $cart = $this->addEvent('checkout_cart_add_product');
110
  $cart->label = $this->__('Customer added product to cart ... ago.');
111
  $cart->form = $this->__('Customer added product to cart %s ago that matches %s of these conditions %s:');
112
-
113
  $wishlist = $this->addEvent('wishlist_add_product');
114
  $wishlist->label = $this->__('Customer added product to wishlist ... ago.');
115
  $wishlist->form = $this->__('Customer added product to wishlist %s ago that matches %s of these conditions %s:');
116
-
117
  }
118
-
119
-
120
-
121
-
122
  /**
123
  * Use product object
124
  *
@@ -128,49 +108,52 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Event
128
  {
129
  return Mage::getSingleton('mzax_emarketing/object_product');
130
  }
131
-
132
-
133
-
134
 
 
 
 
135
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
136
  {
137
  $event = $this->getEvent();
138
-
139
  $conditions = $this->_getConditions();
140
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
141
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
142
-
143
-
144
  $query->useTemporaryTable($this->getTempTableName());
145
  $query->joinTable(array('subject_id' => '{customer_id}'), 'reports/event', 'event');
146
- if(!empty($conditions)) {
147
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
148
  $query->joinSelect(array('id' => '`event`.`object_id`'), $select, 'filter');
149
  }
150
  $query->where('`event`.`subtype` = 0'); // subject type = customer
151
  $query->where('`event`.`event_type_id` = ?', $event->typeId);
152
  $query->where($this->getTimeRangeExpr('`event`.`logged_at`', 'event_date', false));
153
-
154
- if($storeId = $this->getParam('store_id')) {
155
  $query->where('`event`.`store_id` = ?', $storeId);
156
  }
157
-
158
  $query->group();
159
  }
160
-
161
-
 
 
162
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
163
  {
164
  parent::_prepareCollection($collection);
165
  $collection->addField('event_date', new Zend_Db_Expr('MAX(`event`.`logged_at`)'));
166
  }
167
-
168
-
169
-
 
170
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
171
  {
172
  parent::prepareGridColumns($grid);
173
-
174
  $grid->addColumn('event_date', array(
175
  'header' => $this->__('Event Date'),
176
  'width' => '180px',
@@ -179,15 +162,10 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Event
179
  'type' =>'datetime'
180
  ));
181
  }
182
-
183
-
184
-
185
-
186
-
187
-
188
  /**
189
  * Add new event
190
- *
191
  * @param string $eventName
192
  * @return stdClass
193
  */
@@ -199,11 +177,6 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Event
199
  $this->_events[$eventName] = $event;
200
  return $event;
201
  }
202
-
203
-
204
-
205
-
206
-
207
 
208
  /**
209
  * html for settings in option form
@@ -213,47 +186,42 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Event
213
  protected function prepareForm()
214
  {
215
  $event = $this->getEvent();
216
-
217
- if(!$event) {
218
  return $this->__("No such event defined (%s)", $this->getName());
219
  }
220
-
221
- $aggregatorElment = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
222
- $expectationElment = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
223
-
224
  $html = $this->getHiddenField('name', $event->name)->toHtml();
225
-
226
- return $html . $this->__($event->form,
 
227
  $this->getTimeRangeHtml('event_date'),
228
- $aggregatorElment->toHtml(),
229
- $expectationElment->toHtml()
230
  );
231
  }
232
-
233
-
234
-
235
 
236
  /**
237
  * Retrieve current event
238
- *
239
  * @return stdClass
240
  */
241
  public function getEvent()
242
  {
243
- if( $this->_event === null) {
244
  $eventName = $this->getName();
245
- if(isset($this->_events[$eventName])) {
246
  $this->_event = $this->_events[$eventName];
247
  }
248
  }
249
  return $this->_event;
250
  }
251
-
252
-
253
-
254
-
255
  /**
256
- *
257
  * (non-PHPdoc)
258
  * @see Mzax_Emarketing_Model_Object_Filter_Abstract::getOptions()
259
  */
@@ -262,52 +230,45 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Event
262
  $title = $this->getTitle();
263
  $type = $this->getType();
264
  $options = array();
265
-
266
- foreach($this->_events as $event)
267
- {
268
  $options[$type.'?name=' . $event->name] = "{$title} | {$event->label}";
269
  }
270
-
271
  asort($options);
 
272
  return $options;
273
  }
274
-
275
-
276
-
277
-
278
-
279
  /**
280
  * Retrieve event type id by event name
281
- *
282
  * @param string $name
283
- * @return number
 
284
  */
285
  protected function getEventTypeId($name)
286
  {
287
  $typeIds = $this->getEventTypeIds();
288
-
289
- if(isset($typeIds[$name])) {
290
  return (int) $typeIds[$name];
291
  }
 
292
  return 0;
293
  }
294
-
295
-
296
-
297
  /**
298
  * Retrieve event name => id hash
299
- *
300
  * @return array
301
  */
302
  protected function getEventTypeIds()
303
  {
304
- if($this->_eventTypeIds === null) {
305
  $select = $this->_select('reports/event_type', null, array('event_name', 'event_type_id'));
306
  $this->_eventTypeIds = $this->_getReadAdapter()->fetchPairs($select);
307
  }
 
308
  return $this->_eventTypeIds;
309
  }
310
-
311
-
312
-
313
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
20
  /**
 
21
  * Listen to 'mzax_emarketing_email_filter_prepare_customer_events' to add
22
  * your own customer event filters
23
+ *
24
+ * @method string getName()
25
+ * @method $this setName(string $value)
26
+ * @method $this setAggregator(string $value)
27
+ * @method $this setExpectation(string $value)
28
+ * @method $this setEventDateTo(string $value)
29
+ * @method $this setEventDateFrom(string $value)
30
+ * @method $this setEventDateUnit(string $value)
 
 
31
  *
32
  */
33
  class Mzax_Emarketing_Model_Object_Filter_Customer_Event
34
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
35
  {
 
 
36
  const DEFAULT_AGGREGATOR = 'all';
 
37
  const DEFAULT_EXPECTATION = 'true';
38
+
 
39
  /**
 
40
  * @var stdClass
41
  */
42
  protected $_event;
43
+
 
44
  /**
 
45
  * @var array
46
  */
47
  protected $_events = array();
48
+
 
49
  /**
 
50
  * @var array
51
  */
52
  protected $_eventTypeIds;
 
53
 
54
  /**
 
55
  * @var boolean
56
  */
57
  protected $_allowChildren = true;
58
+
59
+ /**
60
+ * @return string
61
+ */
62
  public function getTitle()
63
  {
64
  return "Customer";
65
  }
66
+
 
 
67
  /**
68
+ * @param Mage_Core_Model_Config_Element $config
69
  *
70
+ * @return void
 
71
  */
72
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
73
  {
75
  $this->_registerEvents();
76
  Mage::dispatchEvent("mzax_emarketing_email_filter_prepare_customer_events", array('filter' => $this));
77
  }
 
 
 
78
 
79
+ /**
80
+ * @return void
81
+ */
82
  public function _registerEvents()
83
  {
84
  $view = $this->addEvent('catalog_product_view');
85
  $view->label = $this->__('Customer viewed product ... ago.');
86
  $view->form = $this->__('Customer viewed product %s ago that matches %s of these conditions %s:');
87
+
88
  $friend = $this->addEvent('sendfriend_product');
89
  $friend->label = $this->__('Customer sent product to a friend ... ago.');
90
  $friend->form = $this->__('Customer sent product to a friend %s ago that matches %s of these conditions %s:');
91
+
92
  $cart = $this->addEvent('checkout_cart_add_product');
93
  $cart->label = $this->__('Customer added product to cart ... ago.');
94
  $cart->form = $this->__('Customer added product to cart %s ago that matches %s of these conditions %s:');
95
+
96
  $wishlist = $this->addEvent('wishlist_add_product');
97
  $wishlist->label = $this->__('Customer added product to wishlist ... ago.');
98
  $wishlist->form = $this->__('Customer added product to wishlist %s ago that matches %s of these conditions %s:');
99
+
100
  }
101
+
 
 
 
102
  /**
103
  * Use product object
104
  *
108
  {
109
  return Mage::getSingleton('mzax_emarketing/object_product');
110
  }
 
 
 
111
 
112
+ /**
113
+ * @param Mzax_Emarketing_Db_Select $query
114
+ */
115
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
116
  {
117
  $event = $this->getEvent();
118
+
119
  $conditions = $this->_getConditions();
120
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
121
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
122
+
123
+
124
  $query->useTemporaryTable($this->getTempTableName());
125
  $query->joinTable(array('subject_id' => '{customer_id}'), 'reports/event', 'event');
126
+ if (!empty($conditions)) {
127
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
128
  $query->joinSelect(array('id' => '`event`.`object_id`'), $select, 'filter');
129
  }
130
  $query->where('`event`.`subtype` = 0'); // subject type = customer
131
  $query->where('`event`.`event_type_id` = ?', $event->typeId);
132
  $query->where($this->getTimeRangeExpr('`event`.`logged_at`', 'event_date', false));
133
+
134
+ if ($storeId = $this->getParam('store_id')) {
135
  $query->where('`event`.`store_id` = ?', $storeId);
136
  }
137
+
138
  $query->group();
139
  }
140
+
141
+ /**
142
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
143
+ */
144
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
145
  {
146
  parent::_prepareCollection($collection);
147
  $collection->addField('event_date', new Zend_Db_Expr('MAX(`event`.`logged_at`)'));
148
  }
149
+
150
+ /**
151
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
152
+ */
153
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
154
  {
155
  parent::prepareGridColumns($grid);
156
+
157
  $grid->addColumn('event_date', array(
158
  'header' => $this->__('Event Date'),
159
  'width' => '180px',
162
  'type' =>'datetime'
163
  ));
164
  }
165
+
 
 
 
 
 
166
  /**
167
  * Add new event
168
+ *
169
  * @param string $eventName
170
  * @return stdClass
171
  */
177
  $this->_events[$eventName] = $event;
178
  return $event;
179
  }
 
 
 
 
 
180
 
181
  /**
182
  * html for settings in option form
186
  protected function prepareForm()
187
  {
188
  $event = $this->getEvent();
189
+
190
+ if (!$event) {
191
  return $this->__("No such event defined (%s)", $this->getName());
192
  }
193
+
194
+ $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
195
+ $expectationElement = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
196
+
197
  $html = $this->getHiddenField('name', $event->name)->toHtml();
198
+
199
+ return $html . $this->__(
200
+ $event->form,
201
  $this->getTimeRangeHtml('event_date'),
202
+ $aggregatorElement->toHtml(),
203
+ $expectationElement->toHtml()
204
  );
205
  }
 
 
 
206
 
207
  /**
208
  * Retrieve current event
209
+ *
210
  * @return stdClass
211
  */
212
  public function getEvent()
213
  {
214
+ if ($this->_event === null) {
215
  $eventName = $this->getName();
216
+ if (isset($this->_events[$eventName])) {
217
  $this->_event = $this->_events[$eventName];
218
  }
219
  }
220
  return $this->_event;
221
  }
222
+
 
 
 
223
  /**
224
+ *
225
  * (non-PHPdoc)
226
  * @see Mzax_Emarketing_Model_Object_Filter_Abstract::getOptions()
227
  */
230
  $title = $this->getTitle();
231
  $type = $this->getType();
232
  $options = array();
233
+
234
+ foreach ($this->_events as $event) {
 
235
  $options[$type.'?name=' . $event->name] = "{$title} | {$event->label}";
236
  }
 
237
  asort($options);
238
+
239
  return $options;
240
  }
241
+
 
 
 
 
242
  /**
243
  * Retrieve event type id by event name
244
+ *
245
  * @param string $name
246
+ *
247
+ * @return int
248
  */
249
  protected function getEventTypeId($name)
250
  {
251
  $typeIds = $this->getEventTypeIds();
252
+
253
+ if (isset($typeIds[$name])) {
254
  return (int) $typeIds[$name];
255
  }
256
+
257
  return 0;
258
  }
259
+
 
 
260
  /**
261
  * Retrieve event name => id hash
262
+ *
263
  * @return array
264
  */
265
  protected function getEventTypeIds()
266
  {
267
+ if ($this->_eventTypeIds === null) {
268
  $select = $this->_select('reports/event_type', null, array('event_name', 'event_type_id'));
269
  $this->_eventTypeIds = $this->_getReadAdapter()->fetchPairs($select);
270
  }
271
+
272
  return $this->_eventTypeIds;
273
  }
 
 
 
274
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Lastlogin.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,48 +18,56 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
24
- *
25
  */
26
  class Mzax_Emarketing_Model_Object_Filter_Customer_Lastlogin
27
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
28
  {
29
-
30
-
 
31
  public function getTitle()
32
  {
33
  return "Customer | Last login";
34
  }
35
-
36
-
37
-
38
-
39
 
 
 
 
 
 
40
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
41
  {
42
  $query->joinTable('customer_id', 'log/customer', 'log');
43
-
44
- if($storeId = $this->getParam('store_id')) {
45
  $query->where('`log`.`store_id` = ?', $storeId);
46
  }
47
-
48
  $query->group();
49
  $query->having($this->getTimeRangeExpr('MAX(`log`.`login_at`)', 'login', false));
50
  }
51
-
52
-
 
 
 
 
53
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
54
  {
55
  parent::_prepareCollection($collection);
56
  $collection->addField('last_login', new Zend_Db_Expr('MAX(`log`.`login_at`)'));
57
  }
58
-
59
-
 
 
 
 
60
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
61
  {
62
  parent::prepareGridColumns($grid);
63
-
64
  $grid->addColumn('last_login', array(
65
  'header' => $this->__('Last Login'),
66
  'width' => '180px',
@@ -69,10 +76,6 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Lastlogin
69
  'type' =>'datetime'
70
  ));
71
  }
72
-
73
-
74
-
75
-
76
 
77
  /**
78
  * html for settings in option form
@@ -81,10 +84,9 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Lastlogin
81
  */
82
  protected function prepareForm()
83
  {
84
- return $this->__('Customers last login was %s ago.',
 
85
  $this->getTimeRangeHtml('login')
86
- );
87
  }
88
-
89
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Customer_Lastlogin
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Customer_Lastlogin
24
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
25
  {
26
+ /**
27
+ * @return string
28
+ */
29
  public function getTitle()
30
  {
31
  return "Customer | Last login";
32
  }
 
 
 
 
33
 
34
+ /**
35
+ * @param Mzax_Emarketing_Db_Select $query
36
+ *
37
+ * @return void
38
+ */
39
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
40
  {
41
  $query->joinTable('customer_id', 'log/customer', 'log');
42
+
43
+ if ($storeId = $this->getParam('store_id')) {
44
  $query->where('`log`.`store_id` = ?', $storeId);
45
  }
46
+
47
  $query->group();
48
  $query->having($this->getTimeRangeExpr('MAX(`log`.`login_at`)', 'login', false));
49
  }
50
+
51
+ /**
52
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
53
+ *
54
+ * @return void
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
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
64
+ *
65
+ * @return void
66
+ */
67
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
68
  {
69
  parent::prepareGridColumns($grid);
70
+
71
  $grid->addColumn('last_login', array(
72
  'header' => $this->__('Last Login'),
73
  'width' => '180px',
76
  'type' =>'datetime'
77
  ));
78
  }
 
 
 
 
79
 
80
  /**
81
  * html for settings in option form
84
  */
85
  protected function prepareForm()
86
  {
87
+ return $this->__(
88
+ 'Customers last login was %s ago.',
89
  $this->getTimeRangeHtml('login')
90
+ );
91
  }
 
 
92
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Name.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,30 +18,36 @@
19
 
20
 
21
  /**
22
- *
23
- * @author Jacob Siefer
 
 
 
 
 
24
  *
25
  */
26
  class Mzax_Emarketing_Model_Object_Filter_Customer_Name
27
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
28
  {
29
-
 
 
30
  public function getTitle()
31
  {
32
  return "Customer | Full Name";
33
  }
34
-
35
 
 
 
 
36
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
37
- {
38
  $firstname = $query->joinAttribute('customer_id', 'customer/firstname');
39
- $lastname = $query->joinAttribute('customer_id', 'customer/lastname');
40
-
41
  $query->where($this->getWhereSql('name', "CONCAT_WS(' ', $firstname, $lastname)"));
42
  }
43
-
44
-
45
-
46
 
47
  /**
48
  * html for settings in option form
@@ -51,10 +56,9 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Name
51
  */
52
  protected function prepareForm()
53
  {
54
- return $this->__('Customer name %s.',
 
55
  $this->getInputHtml('name')
56
- );
57
  }
58
-
59
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Customer_Name
22
+ *
23
+ * @method string getName()
24
+ * @method $this setName(string $value)
25
+ *
26
+ * @method string getNameOperator()
27
+ * @method $this setNameOperator(string $value)
28
  *
29
  */
30
  class Mzax_Emarketing_Model_Object_Filter_Customer_Name
31
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
32
  {
33
+ /**
34
+ * @return string
35
+ */
36
  public function getTitle()
37
  {
38
  return "Customer | Full Name";
39
  }
 
40
 
41
+ /**
42
+ * @param Mzax_Emarketing_Db_Select $query
43
+ */
44
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
45
+ {
46
  $firstname = $query->joinAttribute('customer_id', 'customer/firstname');
47
+ $lastname = $query->joinAttribute('customer_id', 'customer/lastname');
48
+
49
  $query->where($this->getWhereSql('name', "CONCAT_WS(' ', $firstname, $lastname)"));
50
  }
 
 
 
51
 
52
  /**
53
  * html for settings in option form
56
  */
57
  protected function prepareForm()
58
  {
59
+ return $this->__(
60
+ 'Customer name %s.',
61
  $this->getInputHtml('name')
62
+ );
63
  }
 
 
64
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Customer/Order.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,55 +18,45 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Object_Filter_Customer_Order
30
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
31
  {
32
-
33
-
34
  const DEFAULT_AGGREGATOR = 'all';
35
-
36
  const DEFAULT_EXPECTATION = 'true';
37
-
38
  const DEFAULT_SUM = '';
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 | If number/grand-total of orders,...";
52
  }
53
-
54
-
55
-
 
56
  public function getQuery()
57
  {
58
  $query = $this->getObject()->getQuery();
59
  $query->setColumn('customer_id');
60
  $query->setColumn('order_id');
61
-
62
- if($sumField = $this->getDataSetDefault('sum', self::DEFAULT_SUM)) {
63
  $query->addBinding('sum_field', $sumField);
64
  $query->setColumn('sum_field');
65
  }
66
-
67
  return $query;
68
  }
69
-
70
-
71
  /**
72
  *
73
  * @return Mzax_Emarketing_Model_Object_Order
@@ -76,128 +65,107 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Order
76
  {
77
  return Mage::getSingleton('mzax_emarketing/object_order');
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
  $sumField = $this->getDataSetDefault('sum', self::DEFAULT_SUM);
92
-
93
-
94
-
95
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
96
-
97
  // Check if we are looking for customer with no orders
98
- if($this->checkIfMatchZero('orders')) {
99
-
100
  $customerId = new Zend_Db_Expr('`customer`.`entity_id`');
101
-
102
  // Query with all orders + customers with out any orders
103
  $zeroOrderQuery = $this->getQuery();
104
  $zeroOrderQuery->joinTableRight(array('entity_id' => '{customer_id}'), 'customer/entity', 'customer');
105
  $zeroOrderQuery->setColumn('matches', new Zend_Db_Expr('0'));
106
  $zeroOrderQuery->setColumn('customer_id', $customerId);
107
  $zeroOrderQuery->group($customerId, true);
108
- if($sumField) {
109
  $zeroOrderQuery->setColumn('sum_field', new Zend_Db_Expr('0'));
110
  }
111
-
112
  $select = $this->_select()->union(array($zeroOrderQuery, $select));
113
-
114
-
115
- if($sumField) {
116
  $query->having($this->getWhereSql('orders', 'SUM(`sum_field`)'));
117
- }
118
- else {
119
  // count customer_id AS order_id maybe NULL
120
  // reduce by 1 as we added zero order results as well.
121
  $query->having($this->getWhereSql('orders', 'COUNT({customer_id})-1'));
122
  }
123
- }
124
- else {
125
- if($sumField) {
126
  $query->having($this->getWhereSql('orders', 'SUM(`sum_field`)'));
127
- }
128
- else {
129
  $query->having($this->getWhereSql('orders', 'COUNT(`filter`.`order_id`)'));
130
  }
131
-
132
  }
133
  $select->useTemporaryTable($this->getTempTableName());
134
-
135
- $query->joinSelect('customer_id', $select, 'filter', 'customer_id');
136
  $query->group();
137
  }
138
-
139
-
140
-
141
-
142
 
 
 
 
143
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
144
  {
145
  parent::_prepareCollection($collection);
 
146
  $collection->addField('customer_id');
147
  $collection->addField('orders', new Zend_Db_Expr('COUNT(DISTINCT `order_id`)'));
148
  }
149
-
150
-
151
-
152
-
153
-
154
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
155
  {
156
  parent::prepareGridColumns($grid);
157
-
158
  $grid->addColumn('orders', array(
159
  'header' => $this->__('Matching Orders'),
160
  'index' => 'orders',
161
  ));
162
-
163
  $grid->setDefaultSort('count_orders');
164
  $grid->setDefaultDir('DESC');
165
-
166
  }
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
  /**
177
- * (non-PHPdoc)
178
- * @see Mzax_Emarketing_Model_Object_Filter_Abstract::prepareForm()
179
  */
180
  protected function prepareForm()
181
  {
182
- $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
183
  $expectationElement = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
184
-
185
- return $this->__('If %s of orders, with %s of these conditions %s, %s:',
 
186
  $this->getSelectElement('sum')->toHtml(),
187
  $aggregatorElement->toHtml(),
188
  $expectationElement->toHtml(),
189
  $this->getInputHtml('orders', 'numeric')
190
- );
191
  }
192
-
193
-
194
 
195
-
196
-
197
  /**
198
  * List of fields to sum up and check against
199
  *
200
- * @return return array
201
  */
202
  protected function getSumOptions()
203
  {
@@ -214,5 +182,4 @@ class Mzax_Emarketing_Model_Object_Filter_Customer_Order
214
  'weight' => $this->__('summed weight'),
215
  );
216
  }
217
-
218
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Customer_Order
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Customer_Order
24
  extends Mzax_Emarketing_Model_Object_Filter_Customer_Abstract
25
  {
 
 
26
  const DEFAULT_AGGREGATOR = 'all';
 
27
  const DEFAULT_EXPECTATION = 'true';
 
28
  const DEFAULT_SUM = '';
 
29
 
30
+ /**
31
+ * @var bool
32
+ */
33
  protected $_allowChildren = true;
 
 
34
 
35
  /**
36
+ * @return string
 
37
  */
38
  public function getTitle()
39
  {
40
  return "Customer | If number/grand-total of orders,...";
41
  }
42
+
43
+ /**
44
+ * @return Mzax_Emarketing_Db_Select
45
+ */
46
  public function getQuery()
47
  {
48
  $query = $this->getObject()->getQuery();
49
  $query->setColumn('customer_id');
50
  $query->setColumn('order_id');
51
+
52
+ if ($sumField = $this->getDataSetDefault('sum', self::DEFAULT_SUM)) {
53
  $query->addBinding('sum_field', $sumField);
54
  $query->setColumn('sum_field');
55
  }
56
+
57
  return $query;
58
  }
59
+
 
60
  /**
61
  *
62
  * @return Mzax_Emarketing_Model_Object_Order
65
  {
66
  return Mage::getSingleton('mzax_emarketing/object_order');
67
  }
68
+
 
 
69
  /**
70
+ *
71
+ * @param Mzax_Emarketing_Db_Select $query
72
+ *
73
+ * @return void
74
  */
75
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
76
  {
77
  $conditions = $this->_getConditions();
78
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
79
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
80
  $sumField = $this->getDataSetDefault('sum', self::DEFAULT_SUM);
81
+
 
 
82
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
83
+
84
  // Check if we are looking for customer with no orders
85
+ if ($this->checkIfMatchZero('orders')) {
 
86
  $customerId = new Zend_Db_Expr('`customer`.`entity_id`');
87
+
88
  // Query with all orders + customers with out any orders
89
  $zeroOrderQuery = $this->getQuery();
90
  $zeroOrderQuery->joinTableRight(array('entity_id' => '{customer_id}'), 'customer/entity', 'customer');
91
  $zeroOrderQuery->setColumn('matches', new Zend_Db_Expr('0'));
92
  $zeroOrderQuery->setColumn('customer_id', $customerId);
93
  $zeroOrderQuery->group($customerId, true);
94
+ if ($sumField) {
95
  $zeroOrderQuery->setColumn('sum_field', new Zend_Db_Expr('0'));
96
  }
97
+
98
  $select = $this->_select()->union(array($zeroOrderQuery, $select));
99
+
100
+
101
+ if ($sumField) {
102
  $query->having($this->getWhereSql('orders', 'SUM(`sum_field`)'));
103
+ } else {
 
104
  // count customer_id AS order_id maybe NULL
105
  // reduce by 1 as we added zero order results as well.
106
  $query->having($this->getWhereSql('orders', 'COUNT({customer_id})-1'));
107
  }
108
+ } else {
109
+ if ($sumField) {
 
110
  $query->having($this->getWhereSql('orders', 'SUM(`sum_field`)'));
111
+ } else {
 
112
  $query->having($this->getWhereSql('orders', 'COUNT(`filter`.`order_id`)'));
113
  }
 
114
  }
115
  $select->useTemporaryTable($this->getTempTableName());
116
+
117
+ $query->joinSelect('customer_id', $select, 'filter');
118
  $query->group();
119
  }
 
 
 
 
120
 
121
+ /**
122
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
123
+ */
124
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
125
  {
126
  parent::_prepareCollection($collection);
127
+
128
  $collection->addField('customer_id');
129
  $collection->addField('orders', new Zend_Db_Expr('COUNT(DISTINCT `order_id`)'));
130
  }
131
+
132
+ /**
133
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
134
+ */
 
135
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
136
  {
137
  parent::prepareGridColumns($grid);
138
+
139
  $grid->addColumn('orders', array(
140
  'header' => $this->__('Matching Orders'),
141
  'index' => 'orders',
142
  ));
143
+
144
  $grid->setDefaultSort('count_orders');
145
  $grid->setDefaultDir('DESC');
 
146
  }
147
+
 
 
 
 
 
 
 
 
148
  /**
149
+ * @return string
 
150
  */
151
  protected function prepareForm()
152
  {
153
+ $aggregatorElement = $this->getSelectElement('aggregator', self::DEFAULT_AGGREGATOR);
154
  $expectationElement = $this->getSelectElement('expectation', self::DEFAULT_EXPECTATION);
155
+
156
+ return $this->__(
157
+ 'If %s of orders, with %s of these conditions %s, %s:',
158
  $this->getSelectElement('sum')->toHtml(),
159
  $aggregatorElement->toHtml(),
160
  $expectationElement->toHtml(),
161
  $this->getInputHtml('orders', 'numeric')
162
+ );
163
  }
 
 
164
 
 
 
165
  /**
166
  * List of fields to sum up and check against
167
  *
168
+ * @return string[]
169
  */
170
  protected function getSumOptions()
171
  {
182
  'weight' => $this->__('summed weight'),
183
  );
184
  }
 
185
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Main.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,60 +17,64 @@
18
  */
19
 
20
 
21
- abstract class Mzax_Emarketing_Model_Object_Filter_Main extends Mzax_Emarketing_Model_Object_Filter_Combine
 
 
 
 
22
  {
23
-
24
-
 
 
 
 
25
  public function getId()
26
  {
27
  return '1';
28
  }
29
-
30
-
31
  /**
32
  * Has any filters been added?
33
- *
34
  * @return boolean
35
  */
36
  public function hasFilters()
37
  {
38
  return !empty($this->_filters);
39
  }
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
  public function getAvailableFilters()
48
  {
49
  return Mzax_Emarketing_Model_Object_Filter_Component::getAvailableFilters();
50
  }
51
-
52
-
53
-
54
-
55
  /**
56
  * Retrieve filter using type path
57
  *
58
  * Filters depend on their parent and ancestor, therefor we need
59
  * to retrieve a new filter using its full type path.
60
  *
61
- * @param array $path
 
62
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
 
63
  */
64
  public function createFilterFromTypePath($path)
65
  {
66
  $params = array();
67
-
68
- if(is_string($path)) {
69
- if(strpos($path, '?')) {
70
  $parts = explode('?', $path);
71
  $path = array_shift($parts);
72
- foreach($parts as $part) {
73
  $var = explode('=', $part, 2);
74
- if(count($var) === 2) {
75
  $params[$var[0]] = urldecode($var[1]);
76
  }
77
  }
@@ -80,29 +83,28 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Main extends Mzax_Emarketing_
80
  }
81
  // ignore self
82
  array_shift($path);
83
-
84
  $filter = null;
85
  $parent = $this;
86
- while(count($path)) {
87
  $filterName = array_shift($path);
88
  $filter = $this->getFilterFactory()->factory($filterName);
89
- if(!$filter) {
90
  throw new Exception("No filter found by name: $filterName");
91
  }
92
  $filter->setParent($parent);
93
  $parent = $filter;
94
  }
95
  $filter->addData($params);
 
96
  return $filter;
97
  }
98
-
99
-
100
-
101
-
102
  /**
103
  * Retrieve filter by id
104
  *
105
  * @param string $id e.g. 1--1--2--3--1--2
 
106
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
107
  */
108
  public function getFilterById($id)
@@ -110,31 +112,24 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Main extends Mzax_Emarketing_
110
  $path = explode('--', $id);
111
  array_shift($path);
112
  $filter = $this->getFilter();
113
-
114
  /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
115
- while($filter && $i = (int) array_shift($path)) {
116
  $filter = $filter->getFilterByIndex($i-1);
117
  }
118
  return $filter;
119
  }
120
-
121
-
122
-
123
-
124
-
125
  /**
126
- * (non-PHPdoc)
127
- * @see Mzax_Emarketing_Model_Object_Filter_Component::getQuery()
128
  */
129
  public function getQuery()
130
  {
131
  $query = $this->getObject()->getQuery();
 
132
  return $query;
133
  }
134
-
135
-
136
-
137
-
138
  /**
139
  * The default filter instance
140
  *
@@ -143,15 +138,5 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Main extends Mzax_Emarketing_
143
  public function getFilter()
144
  {
145
  return $this;
146
- if(!$this->_filter) {
147
- $this->_filter = Mage::getModel('mzax_emarketing/object_filter_combine')
148
- ->load($this->getFilterData())
149
- ->setId('1')
150
- ->setParent($this);
151
- }
152
- return $this->_filter;
153
  }
154
-
155
-
156
-
157
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
20
+ /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Main
22
+ */
23
+ abstract class Mzax_Emarketing_Model_Object_Filter_Main
24
+ extends Mzax_Emarketing_Model_Object_Filter_Combine
25
  {
26
+
27
+ /**
28
+ * Main ID should always be "1"
29
+ *
30
+ * @return string
31
+ */
32
  public function getId()
33
  {
34
  return '1';
35
  }
36
+
 
37
  /**
38
  * Has any filters been added?
39
+ *
40
  * @return boolean
41
  */
42
  public function hasFilters()
43
  {
44
  return !empty($this->_filters);
45
  }
46
+
47
+ /**
48
+ * @return Mzax_Emarketing_Model_Object_Filter_Abstract[]
49
+ */
 
 
 
50
  public function getAvailableFilters()
51
  {
52
  return Mzax_Emarketing_Model_Object_Filter_Component::getAvailableFilters();
53
  }
54
+
55
+
 
 
56
  /**
57
  * Retrieve filter using type path
58
  *
59
  * Filters depend on their parent and ancestor, therefor we need
60
  * to retrieve a new filter using its full type path.
61
  *
62
+ * @param string[]|string $path
63
+ *
64
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
65
+ * @throws Exception
66
  */
67
  public function createFilterFromTypePath($path)
68
  {
69
  $params = array();
70
+
71
+ if (is_string($path)) {
72
+ if (strpos($path, '?')) {
73
  $parts = explode('?', $path);
74
  $path = array_shift($parts);
75
+ foreach ($parts as $part) {
76
  $var = explode('=', $part, 2);
77
+ if (count($var) === 2) {
78
  $params[$var[0]] = urldecode($var[1]);
79
  }
80
  }
83
  }
84
  // ignore self
85
  array_shift($path);
86
+
87
  $filter = null;
88
  $parent = $this;
89
+ while (count($path)) {
90
  $filterName = array_shift($path);
91
  $filter = $this->getFilterFactory()->factory($filterName);
92
+ if (!$filter) {
93
  throw new Exception("No filter found by name: $filterName");
94
  }
95
  $filter->setParent($parent);
96
  $parent = $filter;
97
  }
98
  $filter->addData($params);
99
+
100
  return $filter;
101
  }
102
+
 
 
 
103
  /**
104
  * Retrieve filter by id
105
  *
106
  * @param string $id e.g. 1--1--2--3--1--2
107
+ *
108
  * @return Mzax_Emarketing_Model_Object_Filter_Abstract
109
  */
110
  public function getFilterById($id)
112
  $path = explode('--', $id);
113
  array_shift($path);
114
  $filter = $this->getFilter();
115
+
116
  /* @var $filter Mzax_Emarketing_Model_Object_Filter_Abstract */
117
+ while ($filter && $i = (int) array_shift($path)) {
118
  $filter = $filter->getFilterByIndex($i-1);
119
  }
120
  return $filter;
121
  }
122
+
 
 
 
 
123
  /**
124
+ * @return Mzax_Emarketing_Db_Select
 
125
  */
126
  public function getQuery()
127
  {
128
  $query = $this->getObject()->getQuery();
129
+
130
  return $query;
131
  }
132
+
 
 
 
133
  /**
134
  * The default filter instance
135
  *
138
  public function getFilter()
139
  {
140
  return $this;
 
 
 
 
 
 
 
141
  }
 
 
 
142
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Newsletter.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -21,94 +20,98 @@
21
 
22
  /**
23
  * Simple newsletter status filter
24
- *
25
- * @method Mzax_Emarketing_Model_Object_Filter_Newsletter setCondition(string $value)
26
- * @method Mzax_Emarketing_Model_Object_Filter_Newsletter setStatus(string $value)
27
  *
28
- * @author Jacob Siefer
29
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
- * @version 0.4.10
 
 
 
 
 
 
31
  */
32
  class Mzax_Emarketing_Model_Object_Filter_Newsletter
33
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
34
  {
35
-
36
- const DEFAULT_STATUS = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
37
  const DEFAULT_CONDITION = 'is';
38
-
39
 
40
-
41
-
 
42
  public function getTitle()
43
  {
44
  return "Newsletter | Subscription Status";
45
  }
46
-
47
-
48
-
 
 
 
49
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
50
  {
51
  return $parent->hasBinding('email', 'customer_id', 'subscriber_id', 'subscriber_status');
52
  }
53
-
54
-
55
-
56
-
 
 
57
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
58
- {
59
  $condition = $this->getDataSetDefault('condition', self::DEFAULT_CONDITION);
60
- $status = $this->getDataSetDefault('status', self::DEFAULT_STATUS);
61
-
62
- if(!$query->hasBinding('subscriber_status'))
63
- {
64
- if($query->hasBinding('subscriber_id')) {
65
  $query->joinTableLeft('subscriber_id', 'newsletter/subscriber', 'subscriber');
66
- }
67
- else if($query->hasBinding('email')) {
68
  $query->joinTableLeft(array('subscriber_email' => 'email'), 'newsletter/subscriber', 'subscriber');
69
- }
70
-
71
- else if($query->hasBinding('customer_id')) {
72
  $query->joinTableLeft('customer_id', 'newsletter/subscriber', 'subscriber');
73
  }
74
  $query->addBinding('subscriber_status', 'subscriber.subscriber_status');
75
  $query->addBinding('subscriber_store', 'subscriber.store_id');
76
  $query->group();
77
- }
78
 
79
- if($condition === 'is') {
80
  $query->where("{subscriber_status} = ?", $status);
81
- }
82
- else {
83
  $query->where("{subscriber_status} != ? OR {subscriber_status} IS NULL", $status);
84
  }
85
 
86
-
87
- if(Mage::getStoreConfigFlag('mzax_emarketing/general/newsletter_multistore'))
88
- {
89
- if($storeId = $this->getParam('store_id') && $query->hasBinding('subscriber_store')) {
90
  $query->where("{subscriber_store} = ?", $storeId);
91
  }
92
  }
93
-
94
  }
95
-
96
-
97
-
98
-
 
 
99
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
100
  {
101
  parent::_prepareCollection($collection);
102
  $collection->addField('newsletter_status', 'subscriber_status');
103
  }
104
-
105
-
106
-
107
-
 
 
108
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
109
  {
110
  parent::prepareGridColumns($grid);
111
-
112
  $grid->addColumn('newsletter_status', array(
113
  'header' => $this->__('Newsletter'),
114
  'width' => '80px',
@@ -117,15 +120,7 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter
117
  'type' => 'options',
118
  'options' => array_map('ucwords', $this->getStatusOptions())
119
  ));
120
-
121
  }
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
 
130
  /**
131
  * html for settings in option form
@@ -133,20 +128,44 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter
133
  * @return string
134
  */
135
  protected function prepareForm()
136
- {
137
- $conditionElment = $this->getSelectElement('condition', self::DEFAULT_CONDITION);
138
- $subscribeElment = $this->getSelectElement('status', self::DEFAULT_STATUS);
139
-
140
- return $this->__('Newsletter subscription status %s %s.',
141
- $conditionElment->toHtml(),
142
- $subscribeElment->toHtml()
143
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  }
145
-
146
-
147
-
148
-
149
-
150
  protected function getStatusOptions()
151
  {
152
  return array(
@@ -156,9 +175,10 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter
156
  Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => $this->__('unconfirmed')
157
  );
158
  }
159
-
160
-
161
-
 
162
  protected function getConditionOptions()
163
  {
164
  return array(
@@ -166,8 +186,52 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter
166
  'is_not' => $this->__('is not')
167
  );
168
  }
169
-
170
-
171
-
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
20
 
21
  /**
22
  * Simple newsletter status filter
 
 
 
23
  *
24
+ * @method string getCondition()
25
+ * @method $this setCondition(string $value)
26
+ *
27
+ * @method string getStatus()
28
+ * @method $this setStatus(string $value)
29
+ *
30
+ *
31
+ * @method int getStore()
32
+ * @method $this setStore(int $value)
33
  */
34
  class Mzax_Emarketing_Model_Object_Filter_Newsletter
35
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
36
  {
37
+ const DEFAULT_STATUS = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
 
38
  const DEFAULT_CONDITION = 'is';
 
39
 
40
+ /**
41
+ * @return string
42
+ */
43
  public function getTitle()
44
  {
45
  return "Newsletter | Subscription Status";
46
  }
47
+
48
+ /**
49
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
50
+ *
51
+ * @return bool
52
+ */
53
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
54
  {
55
  return $parent->hasBinding('email', 'customer_id', 'subscriber_id', 'subscriber_status');
56
  }
57
+
58
+ /**
59
+ * @param Mzax_Emarketing_Db_Select $query
60
+ *
61
+ * @return void
62
+ */
63
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
64
+ {
65
  $condition = $this->getDataSetDefault('condition', self::DEFAULT_CONDITION);
66
+ $status = $this->getDataSetDefault('status', self::DEFAULT_STATUS);
67
+
68
+ if (!$query->hasBinding('subscriber_status')) {
69
+ if ($query->hasBinding('subscriber_id')) {
 
70
  $query->joinTableLeft('subscriber_id', 'newsletter/subscriber', 'subscriber');
71
+ } elseif ($query->hasBinding('email')) {
 
72
  $query->joinTableLeft(array('subscriber_email' => 'email'), 'newsletter/subscriber', 'subscriber');
73
+ } elseif ($query->hasBinding('customer_id')) {
 
 
74
  $query->joinTableLeft('customer_id', 'newsletter/subscriber', 'subscriber');
75
  }
76
  $query->addBinding('subscriber_status', 'subscriber.subscriber_status');
77
  $query->addBinding('subscriber_store', 'subscriber.store_id');
78
  $query->group();
79
+ }
80
 
81
+ if ($condition === 'is') {
82
  $query->where("{subscriber_status} = ?", $status);
83
+ } else {
 
84
  $query->where("{subscriber_status} != ? OR {subscriber_status} IS NULL", $status);
85
  }
86
 
87
+ if ($this->_config->flag('mzax_emarketing/general/newsletter_multistore')) {
88
+ $storeId = (int)$this->getStore();
89
+ if ($storeId && $query->hasBinding('subscriber_store')) {
 
90
  $query->where("{subscriber_store} = ?", $storeId);
91
  }
92
  }
 
93
  }
94
+
95
+ /**
96
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
97
+ *
98
+ * @return void
99
+ */
100
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
101
  {
102
  parent::_prepareCollection($collection);
103
  $collection->addField('newsletter_status', 'subscriber_status');
104
  }
105
+
106
+ /**
107
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
108
+ *
109
+ * @return void
110
+ */
111
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
112
  {
113
  parent::prepareGridColumns($grid);
114
+
115
  $grid->addColumn('newsletter_status', array(
116
  'header' => $this->__('Newsletter'),
117
  'width' => '80px',
120
  'type' => 'options',
121
  'options' => array_map('ucwords', $this->getStatusOptions())
122
  ));
 
123
  }
 
 
 
 
 
 
 
124
 
125
  /**
126
  * html for settings in option form
128
  * @return string
129
  */
130
  protected function prepareForm()
131
+ {
132
+ $conditionElement = $this->getSelectElement('condition', self::DEFAULT_CONDITION);
133
+ $subscribeElement = $this->getSelectElement('status', self::DEFAULT_STATUS);
134
+ $storeElement = $this->getSelectElement('store', '0');
135
+
136
+ return $this->__(
137
+ 'Newsletter subscription status for %s %s %s.',
138
+ $storeElement->toHtml(),
139
+ $conditionElement->toHtml(),
140
+ $subscribeElement->toHtml()
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Retrieve available stores
146
+ *
147
+ * @return string[]
148
+ */
149
+ protected function getStoreOptions()
150
+ {
151
+ $options = array(
152
+ '0' => $this->__('any store')
153
+ );
154
+
155
+ /** @var Mage_Adminhtml_Model_System_Config_Source_Store $source */
156
+ $source = Mage::getSingleton('adminhtml/system_config_source_store');
157
+ $stores = $source->toOptionArray();
158
+
159
+ foreach ($stores as $store) {
160
+ $options[$store['value']] = $store['label'];
161
+ }
162
+
163
+ return $options;
164
  }
165
+
166
+ /**
167
+ * @return string[]
168
+ */
 
169
  protected function getStatusOptions()
170
  {
171
  return array(
175
  Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => $this->__('unconfirmed')
176
  );
177
  }
178
+
179
+ /**
180
+ * @return string[]
181
+ */
182
  protected function getConditionOptions()
183
  {
184
  return array(
186
  'is_not' => $this->__('is not')
187
  );
188
  }
 
 
 
189
 
190
+ /**
191
+ * The newsletter table is missing an index for the email
192
+ *
193
+ * @param bool $create
194
+ *
195
+ * @return bool|string
196
+ * @throws Exception
197
+ */
198
+ public function checkIndexes($create = false)
199
+ {
200
+ $adapter = $this->_getWriteAdapter();
201
+ $table = $this->_getTable('newsletter/subscriber');
202
+ $indexList = $adapter->getIndexList($table);
203
+
204
+ // check if we already created an index
205
+ if (isset($indexList['MZAX_IDX_EMAIL'])) {
206
+ return true;
207
+ }
208
+
209
+ // check for other indexes that can work
210
+ foreach ($indexList as $index) {
211
+ switch (count($index['fields'])) {
212
+ case 1:
213
+ if ($index['fields'][0] === 'subscriber_email') {
214
+ return true;
215
+ }
216
+ break;
217
+ }
218
+ }
219
+
220
+ if ($create && $this->canCreateIndex()) {
221
+ try {
222
+ $adapter->addIndex($table, 'MZAX_IDX_EMAIL', array('subscriber_email'));
223
+ return true;
224
+ } catch (Exception $e) {
225
+ if (Mage::getIsDeveloperMode()) {
226
+ throw $e;
227
+ }
228
+ Mage::logException($e);
229
+ return $this->__('Failed to create an index for the table "%s". Please check logs.', $table);
230
+ }
231
+ } elseif ($this->canCreateIndex()) {
232
+ return true;
233
+ }
234
+
235
+ return $this->__('It is recommended to set an index on "subscriber_email" for the table "%s" before using this filter.', $table);
236
+ }
237
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Newsletter/List.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -21,21 +20,15 @@
21
 
22
  /**
23
  * Simple newsletter status filter
24
- *
25
- * @method Mzax_Emarketing_Model_Object_Filter_Newsletter setCondition(string $value)
26
- * @method Mzax_Emarketing_Model_Object_Filter_Newsletter setStatus(string $value)
27
  *
28
- * @author Jacob Siefer
29
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
- * @version 0.4.10
31
  */
32
  class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
33
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
34
  {
35
-
36
  const DEFAULT_STATUS = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
37
- const DEFAULT_CONDITION = 'is';
38
-
39
 
40
  /**
41
  * @return string
@@ -45,7 +38,6 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
45
  return "Newsletter | Subscriber belongs to list";
46
  }
47
 
48
-
49
  /**
50
  * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
51
  * @return bool
@@ -55,35 +47,45 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
55
  return $parent->hasBinding('customer_id', 'subscriber_id');
56
  }
57
 
58
-
59
-
60
  /**
61
  * @param Mzax_Emarketing_Db_Select $query
62
  */
63
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
64
- {
65
- $condition = $this->getDataSetDefault('condition', self::DEFAULT_CONDITION);
66
- $status = $this->getDataSetDefault('status', self::DEFAULT_STATUS);
67
-
68
-
69
- if($query->hasBinding('subscriber_id')) {
70
  $query->joinTableLeft('subscriber_id', 'mzax_emarketing/newsletter_list_subscriber', 'list_subscriber');
71
- }
72
- else if($query->hasBinding('customer_id')) {
73
  $query->addBinding('subscriber_id', 'subscriber.subscriber_id');
74
- $query->joinTable('customer_id', 'newsletter/subscriber', 'subscriber');
75
- $query->joinTable('subscriber_id', 'mzax_emarketing/newsletter_list_subscriber', 'list_subscriber');
 
 
 
 
76
  }
77
 
 
 
78
  $listIds = $this->_explode($this->getLists());
79
- $query->where("`list_subscriber`.`list_status` = ?", Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
80
- $query->where("`list_subscriber`.`list_id` IN(?)", $listIds);
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  $query->group();
82
  $query->addBinding('list_id', 'list_subscriber.list_id');
83
  }
84
 
85
-
86
-
87
  /**
88
  * @param Mzax_Emarketing_Model_Object_Collection $collection
89
  */
@@ -94,7 +96,6 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
94
  $collection->addField('newsletter_lists', new Zend_Db_Expr('GROUP_CONCAT(`list`.`name` SEPARATOR ", ")'));
95
  }
96
 
97
-
98
  /**
99
  * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
100
  * @throws Exception
@@ -103,11 +104,13 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
103
  {
104
  parent::prepareGridColumns($grid);
105
 
106
- $grid->addColumn('newsletter_lists', array(
107
- 'header' => $this->__('Lists'),
108
- 'index' => 'newsletter_lists',
109
- ));
110
-
 
 
111
  }
112
 
113
 
@@ -120,13 +123,15 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
120
  protected function prepareForm()
121
  {
122
  $listElement = $this->getMultiSelectElement('lists');
 
123
 
124
- return $this->__('Subscriber belongs to one of the following lists: %s.',
 
 
125
  $listElement->toHtml()
126
- );
127
  }
128
 
129
-
130
  /**
131
  * @return array
132
  */
@@ -137,6 +142,65 @@ class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
137
  return $collection->toOptionHash();
138
  }
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
 
 
 
 
 
 
 
 
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
20
 
21
  /**
22
  * Simple newsletter status filter
 
 
 
23
  *
24
+ * @method $this setCondition(string $value)
25
+ * @method $this setStatus(string $value)
 
26
  */
27
  class Mzax_Emarketing_Model_Object_Filter_Newsletter_List
28
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
29
  {
 
30
  const DEFAULT_STATUS = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
31
+ const DEFAULT_CONDITION = 'in';
 
32
 
33
  /**
34
  * @return string
38
  return "Newsletter | Subscriber belongs to list";
39
  }
40
 
 
41
  /**
42
  * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
43
  * @return bool
47
  return $parent->hasBinding('customer_id', 'subscriber_id');
48
  }
49
 
 
 
50
  /**
51
  * @param Mzax_Emarketing_Db_Select $query
52
  */
53
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
54
+ {
55
+ if ($query->hasBinding('subscriber_id')) {
 
 
 
 
56
  $query->joinTableLeft('subscriber_id', 'mzax_emarketing/newsletter_list_subscriber', 'list_subscriber');
57
+ } elseif ($query->hasBinding('email')) {
 
58
  $query->addBinding('subscriber_id', 'subscriber.subscriber_id');
59
+ $query->joinTableLeft(array('subscriber_email' => 'email'), 'newsletter/subscriber', 'subscriber');
60
+ $query->joinTableLeft('subscriber_id', 'mzax_emarketing/newsletter_list_subscriber', 'list_subscriber');
61
+ } elseif ($query->hasBinding('customer_id')) {
62
+ $query->addBinding('subscriber_id', 'subscriber.subscriber_id');
63
+ $query->joinTableLeft('customer_id', 'newsletter/subscriber', 'subscriber');
64
+ $query->joinTableLeft('subscriber_id', 'mzax_emarketing/newsletter_list_subscriber', 'list_subscriber');
65
  }
66
 
67
+ $condition = $this->getDataSetDefault('condition', self::DEFAULT_CONDITION);
68
+
69
  $listIds = $this->_explode($this->getLists());
70
+ $status = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
71
+
72
+ if ($condition == 'in') {
73
+ $query->where("`list_subscriber`.`list_status` = ?", $status);
74
+ $query->where("`list_subscriber`.`list_id` IN(?)", $listIds);
75
+ } else {
76
+ $adapter = $this->_getReadAdapter();
77
+ $where = array();
78
+ $where[] = $adapter->quoteInto("`list_subscriber`.`list_status` = ?", $status);
79
+ $where[] = $adapter->quoteInto("`list_subscriber`.`list_id` IN(?)", $listIds);
80
+ $where = implode(' AND ', $where);
81
+
82
+ $query->having('SUM(IF(' . $where . ', 1, 0)) = 0');
83
+ }
84
+
85
  $query->group();
86
  $query->addBinding('list_id', 'list_subscriber.list_id');
87
  }
88
 
 
 
89
  /**
90
  * @param Mzax_Emarketing_Model_Object_Collection $collection
91
  */
96
  $collection->addField('newsletter_lists', new Zend_Db_Expr('GROUP_CONCAT(`list`.`name` SEPARATOR ", ")'));
97
  }
98
 
 
99
  /**
100
  * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
101
  * @throws Exception
104
  {
105
  parent::prepareGridColumns($grid);
106
 
107
+ $grid->addColumn(
108
+ 'newsletter_lists',
109
+ array(
110
+ 'header' => $this->__('Lists'),
111
+ 'index' => 'newsletter_lists',
112
+ )
113
+ );
114
  }
115
 
116
 
123
  protected function prepareForm()
124
  {
125
  $listElement = $this->getMultiSelectElement('lists');
126
+ $condElement = $this->getSelectElement('condition');
127
 
128
+ return $this->__(
129
+ 'Subscriber belongs to %s of the following lists: %s.',
130
+ $condElement->toHtml(),
131
  $listElement->toHtml()
132
+ );
133
  }
134
 
 
135
  /**
136
  * @return array
137
  */
142
  return $collection->toOptionHash();
143
  }
144
 
145
+ /**
146
+ * @return array
147
+ */
148
+ protected function getConditionOptions()
149
+ {
150
+ return array(
151
+ 'in' => $this->__('one'),
152
+ 'not in' => $this->__('none')
153
+ );
154
+ }
155
+
156
+ /**
157
+ * The newsletter table is missing an index for the email
158
+ *
159
+ * @param bool $create
160
+ *
161
+ * @return bool|string|true
162
+ * @throws Exception
163
+ */
164
+ public function checkIndexes($create = false)
165
+ {
166
+ $adapter = $this->_getWriteAdapter();
167
+
168
 
169
+ $table = $this->_getTable('newsletter/subscriber');
170
+
171
+ $indexList = $adapter->getIndexList($table);
172
+
173
+ // check if we already created an index
174
+ if (isset($indexList['MZAX_IDX_EMAIL'])) {
175
+ return true;
176
+ }
177
 
178
+ // check for other indexes that can work
179
+ foreach ($indexList as $index) {
180
+ switch (count($index['fields'])) {
181
+ case 1:
182
+ if ($index['fields'][0] === 'subscriber_email') {
183
+ return true;
184
+ }
185
+ break;
186
+ }
187
+ }
188
+
189
+ if ($create && $this->canCreateIndex()) {
190
+ try {
191
+ $adapter->addIndex($table, 'MZAX_IDX_EMAIL', array('subscriber_email'));
192
+ return true;
193
+ } catch (Exception $e) {
194
+ if (Mage::getIsDeveloperMode()) {
195
+ throw $e;
196
+ }
197
+ Mage::logException($e);
198
+ return $this->__('Failed to create an index for the table "%s". Please check logs.', $table);
199
+ }
200
+ } elseif ($this->canCreateIndex()) {
201
+ return true;
202
+ }
203
+
204
+ return $this->__('It is recommended to set an index on "subscriber_email" for the table "%s" before using this filter.', $table);
205
+ }
206
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,24 +18,18 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  abstract class Mzax_Emarketing_Model_Object_Filter_Order_Abstract
30
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
31
  {
32
-
33
-
 
 
 
34
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
35
  {
36
  return $parent->hasBinding('order_id');
37
  }
38
-
39
-
40
-
41
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_Abstract
 
 
 
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Filter_Order_Abstract
24
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
25
  {
26
+ /**
27
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
28
+ *
29
+ * @return bool
30
+ */
31
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
32
  {
33
  return $parent->hasBinding('order_id');
34
  }
 
 
 
 
35
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Address.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,41 +16,31 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Model_Object_Filter_Order_Address
29
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
30
  {
31
-
32
  const DEFAULT_AGGREGATOR = 'all';
33
-
34
  const DEFAULT_EXPECTATION = 'true';
35
-
36
-
37
  const TYPE_BILLING = 'billing';
38
  const TYPE_SHIPPING = 'shipping';
39
 
40
-
 
 
41
  protected $_allowChildren = true;
42
-
43
-
44
-
45
-
46
  public function getTitle()
47
  {
48
  return "Order | Billing/Shipping Address matches...";
49
  }
50
-
51
-
52
-
53
-
54
-
55
  /**
56
  *
57
  * @return Mzax_Emarketing_Model_Object_OrderItem
@@ -60,59 +49,55 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Address
60
  {
61
  return Mage::getSingleton('mzax_emarketing/object_orderAddress');
62
  }
63
-
64
-
 
 
65
  public function getQuery()
66
  {
67
  $query = $this->getObject()->getQuery();
68
  $query->setColumn('order_id');
69
-
70
  $query->where('address_type = ?', $this->getDataSetDefault('address_type', self::TYPE_BILLING));
71
-
72
  return $query;
73
  }
74
-
75
-
76
 
77
-
78
-
79
  /**
80
- *
81
- * @return Zend_Db_Select
 
 
82
  */
83
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
84
  {
85
  $conditions = $this->_getConditions();
86
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
87
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
88
-
89
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
90
  $select->useTemporaryTable($this->getTempTableName());
91
-
92
  $query->joinSelect('order_id', $select, 'filter');
93
  $query->group();
94
  }
95
-
96
-
97
-
98
 
 
 
 
99
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
100
  {
101
  parent::_prepareCollection($collection);
102
  }
103
-
104
-
105
-
 
106
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
107
  {
108
  parent::prepareGridColumns($grid);
109
-
110
-
111
-
112
  }
113
-
114
-
115
-
116
  /**
117
  * html for settings in option form
118
  *
@@ -120,14 +105,16 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Address
120
  */
121
  protected function prepareForm()
122
  {
123
- return $this->__('If %s address matches %s of these conditions:',
124
- $this->getSelectElement('address_type', self::TYPE_BILLING)->toHtml(),
125
- $this->getSelectElement('aggregator', 'all')->toHtml()
126
- );
 
127
  }
128
-
129
-
130
-
 
131
  protected function getAddressTypeOptions()
132
  {
133
  return array(
@@ -135,11 +122,4 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Address
135
  self::TYPE_SHIPPING => $this->__('shipping'),
136
  );
137
  }
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_Address
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Order_Address
24
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
25
  {
 
26
  const DEFAULT_AGGREGATOR = 'all';
 
27
  const DEFAULT_EXPECTATION = 'true';
 
 
28
  const TYPE_BILLING = 'billing';
29
  const TYPE_SHIPPING = 'shipping';
30
 
31
+ /**
32
+ * @var bool
33
+ */
34
  protected $_allowChildren = true;
35
+
36
+ /**
37
+ * @return string
38
+ */
39
  public function getTitle()
40
  {
41
  return "Order | Billing/Shipping Address matches...";
42
  }
43
+
 
 
 
 
44
  /**
45
  *
46
  * @return Mzax_Emarketing_Model_Object_OrderItem
49
  {
50
  return Mage::getSingleton('mzax_emarketing/object_orderAddress');
51
  }
52
+
53
+ /**
54
+ * @return Mzax_Emarketing_Db_Select
55
+ */
56
  public function getQuery()
57
  {
58
  $query = $this->getObject()->getQuery();
59
  $query->setColumn('order_id');
60
+
61
  $query->where('address_type = ?', $this->getDataSetDefault('address_type', self::TYPE_BILLING));
62
+
63
  return $query;
64
  }
 
 
65
 
 
 
66
  /**
67
+ *
68
+ * @param Mzax_Emarketing_Db_Select $query
69
+ *
70
+ * @return void
71
  */
72
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
73
  {
74
  $conditions = $this->_getConditions();
75
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
76
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
77
+
78
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
79
  $select->useTemporaryTable($this->getTempTableName());
80
+
81
  $query->joinSelect('order_id', $select, 'filter');
82
  $query->group();
83
  }
 
 
 
84
 
85
+ /**
86
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
87
+ */
88
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
89
  {
90
  parent::_prepareCollection($collection);
91
  }
92
+
93
+ /**
94
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
95
+ */
96
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
97
  {
98
  parent::prepareGridColumns($grid);
 
 
 
99
  }
100
+
 
 
101
  /**
102
  * html for settings in option form
103
  *
105
  */
106
  protected function prepareForm()
107
  {
108
+ return $this->__(
109
+ 'If %s address matches %s of these conditions:',
110
+ $this->getSelectElement('address_type', self::TYPE_BILLING)->toHtml(),
111
+ $this->getSelectElement('aggregator', 'all')->toHtml()
112
+ );
113
  }
114
+
115
+ /**
116
+ * @return string[]
117
+ */
118
  protected function getAddressTypeOptions()
119
  {
120
  return array(
122
  self::TYPE_SHIPPING => $this->__('shipping'),
123
  );
124
  }
 
 
 
 
 
 
 
125
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Campaign.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,44 +17,39 @@
18
  */
19
 
20
  /**
21
- *
22
- * @method Mzax_Emarketing_Model_Object_Filter_Order_Campaign setJoin()
23
- * @method Mzax_Emarketing_Model_Object_Filter_Order_Campaign setCampaign()
 
24
  *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
30
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
31
  {
32
-
33
  const DEFAULT_JOIN = 'direct';
34
-
35
  const DEFAULT_CAMPAIGN = 'current';
36
-
37
  const DEFAULT_AGGREGATOR = 'all';
38
-
39
  const DEFAULT_EXPECTATION = 'true';
40
-
41
-
 
 
42
  protected $_allowChildren = true;
43
-
44
-
45
  /**
46
- *
47
  * @var Mzax_Emarketing_Model_Campaign
48
  */
49
  protected $_campaign;
50
-
51
 
 
 
 
52
  public function getTitle()
53
  {
54
  return "Order | Link directly/indirectly to emarketing campaign";
55
  }
56
-
57
-
58
-
59
  /**
60
  *
61
  * @return Mzax_Emarketing_Model_Object_Recipient
@@ -64,16 +58,16 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
64
  {
65
  return Mage::getSingleton('mzax_emarketing/object_recipient');
66
  }
67
-
68
-
69
-
70
-
71
  public function getQuery()
72
  {
73
  $campaign = $this->getCampaign();
74
 
75
  $query = $this->getObject()->getQuery();
76
- if($campaign) {
77
  $query->joinSelect('recipient_id', $this->getRecipientsByOrder(), 'recipient_order');
78
  $query->where('{campaign_id} = ?', $campaign->getId());
79
  }
@@ -81,87 +75,76 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
81
  $query->addBinding('goal_time', 'order_time', 'recipient_order');
82
  $query->setColumn('recipient_id');
83
  $query->setColumn('goal_id');
84
-
85
- if(($variationId = $this->getVariation()) !== null) {
86
  $query->where('{variation_id} = ?', $variationId);
87
  }
88
-
89
  return $query;
90
-
91
  }
92
-
93
-
94
-
95
 
96
  /**
 
97
  *
98
- * @return Zend_Db_Select
99
  */
100
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
101
  {
102
  $conditions = $this->_getConditions();
103
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
104
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
105
-
106
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
107
-
108
  $query->joinSelect(array('goal_id' => '{order_id}'), $select, 'recipients');
109
  $query->group();
110
-
111
  $query->provide('recipient_id', new Zend_Db_Expr('MAX(`recipients`.`id`)'));
112
  }
113
-
114
-
115
 
 
 
 
 
 
116
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
117
  {
118
  parent::_prepareCollection($collection);
119
  $collection->addField('recipient_ids', new Zend_Db_Expr('GROUP_CONCAT(`recipients`.`id` SEPARATOR ", ")'));
120
  }
121
-
122
-
123
-
124
-
125
-
 
126
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
127
  {
128
  parent::prepareGridColumns($grid);
129
-
130
  $grid->addColumn('recipient_ids', array(
131
  'header' => $this->__('Link Recipients'),
132
  'index' => 'recipient_ids',
133
  ));
134
  }
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
  /**
145
  * Retrieve recipients by order select
146
- *
147
- * @return Mzax_Emarketing_Model_Resource_Recipient_Goal_Binder
148
  */
149
- public function getRecipientsByOrder()
150
  {
151
  $campaign = $this->getCampaign();
152
  $type = $this->getDataSetDefault('join');
153
-
154
- $binder = Mage::getSingleton('mzax_emarketing/conversion_goal_orders')->getRecipientBinder($campaign, $type === 'direct');
155
-
 
 
 
156
  return $binder->getSelect();
157
  }
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
 
166
  /**
167
  * html for settings in option form
@@ -169,16 +152,17 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
169
  * @return string
170
  */
171
  protected function prepareForm()
172
- {
173
- return $this->__('Order is linked %s to emarketing campaign %s',
 
174
  $this->getSelectElement('join')->toHtml(),
175
  $this->getSelectElement('campaign')->toHtml()
176
- );
177
  }
178
-
179
-
180
-
181
-
182
  public function getJoinOptions()
183
  {
184
  return array(
@@ -186,77 +170,67 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
186
  'indirect' => $this->__('indirectly'),
187
  );
188
  }
189
-
190
-
191
-
 
192
  public function getCampaignOptions()
193
  {
194
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
195
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
196
  $collection->addArchiveFilter(false);
197
-
198
  $options = array();
199
- if($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
200
  $options['current'] = $this->__('beeing tracked');
201
  }
202
  $options += $collection->toOptionHash();
203
-
204
  return $options;
205
  }
206
-
207
-
208
-
209
-
210
-
211
  /**
212
- * Retreive current campaign
213
- *
214
  * We must always return a campaign object!
215
  * getQuery() needs to work with no data set
216
- *
217
  * @return Mzax_Emarketing_Model_Campaign
218
  */
219
  public function getCampaign()
220
  {
221
- if(!$this->_campaign) {
222
-
223
  $id = $this->getDataSetDefault('campaign');
224
-
225
- if($id === 'current') {
226
  return $this->getParam('campaign');
227
  }
228
  $campaign = Mage::getModel('mzax_emarketing/campaign');
229
- if(!$id) {
230
  return null;
231
  }
232
  $campaign->load($id);
233
- if(!$campaign->getId()) {
234
  return null;
235
  }
236
-
237
  $this->_campaign = $campaign;
238
  }
 
239
  return $this->_campaign;
240
  }
241
-
242
-
243
  /**
244
- * Retreive current campaign variation which we aggregate
245
  *
246
  * @return null|integer
247
  */
248
  public function getVariation()
249
  {
250
  $id = Mage::registry('mzax_aggregate_variation');
251
- if($id !== null && $id > -1) {
252
  return (int) $id;
253
  }
 
254
  return null;
255
  }
256
-
257
-
258
-
259
-
260
-
261
-
262
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
21
+ *
22
+ * @method string getJoin()
23
+ * @method $this setJoin(string $value)
24
  *
25
+ * @method $this setCampaign(Mzax_Emarketing_Model_Campaign|string $value)
 
 
26
  */
27
  class Mzax_Emarketing_Model_Object_Filter_Order_Campaign
28
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
29
  {
 
30
  const DEFAULT_JOIN = 'direct';
 
31
  const DEFAULT_CAMPAIGN = 'current';
 
32
  const DEFAULT_AGGREGATOR = 'all';
 
33
  const DEFAULT_EXPECTATION = 'true';
34
+
35
+ /**
36
+ * @var bool
37
+ */
38
  protected $_allowChildren = true;
39
+
 
40
  /**
 
41
  * @var Mzax_Emarketing_Model_Campaign
42
  */
43
  protected $_campaign;
 
44
 
45
+ /**
46
+ * @return string
47
+ */
48
  public function getTitle()
49
  {
50
  return "Order | Link directly/indirectly to emarketing campaign";
51
  }
52
+
 
 
53
  /**
54
  *
55
  * @return Mzax_Emarketing_Model_Object_Recipient
58
  {
59
  return Mage::getSingleton('mzax_emarketing/object_recipient');
60
  }
61
+
62
+ /**
63
+ * @return Mzax_Emarketing_Db_Select
64
+ */
65
  public function getQuery()
66
  {
67
  $campaign = $this->getCampaign();
68
 
69
  $query = $this->getObject()->getQuery();
70
+ if ($campaign) {
71
  $query->joinSelect('recipient_id', $this->getRecipientsByOrder(), 'recipient_order');
72
  $query->where('{campaign_id} = ?', $campaign->getId());
73
  }
75
  $query->addBinding('goal_time', 'order_time', 'recipient_order');
76
  $query->setColumn('recipient_id');
77
  $query->setColumn('goal_id');
78
+
79
+ if (($variationId = $this->getVariation()) !== null) {
80
  $query->where('{variation_id} = ?', $variationId);
81
  }
82
+
83
  return $query;
 
84
  }
 
 
 
85
 
86
  /**
87
+ * @param Mzax_Emarketing_Db_Select $query
88
  *
89
+ * @return void
90
  */
91
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
92
  {
93
  $conditions = $this->_getConditions();
94
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
95
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
96
+
97
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
98
+
99
  $query->joinSelect(array('goal_id' => '{order_id}'), $select, 'recipients');
100
  $query->group();
101
+
102
  $query->provide('recipient_id', new Zend_Db_Expr('MAX(`recipients`.`id`)'));
103
  }
 
 
104
 
105
+ /**
106
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
107
+ *
108
+ * @return void
109
+ */
110
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
111
  {
112
  parent::_prepareCollection($collection);
113
  $collection->addField('recipient_ids', new Zend_Db_Expr('GROUP_CONCAT(`recipients`.`id` SEPARATOR ", ")'));
114
  }
115
+
116
+ /**
117
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
118
+ *
119
+ * @return void
120
+ */
121
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
122
  {
123
  parent::prepareGridColumns($grid);
124
+
125
  $grid->addColumn('recipient_ids', array(
126
  'header' => $this->__('Link Recipients'),
127
  'index' => 'recipient_ids',
128
  ));
129
  }
130
+
 
 
 
 
 
 
 
 
131
  /**
132
  * Retrieve recipients by order select
133
+ *
134
+ * @return Mzax_Emarketing_Db_Select
135
  */
136
+ public function getRecipientsByOrder()
137
  {
138
  $campaign = $this->getCampaign();
139
  $type = $this->getDataSetDefault('join');
140
+
141
+ /** @var Mzax_Emarketing_Model_Conversion_Goal_Orders $conversionGoal */
142
+ $conversionGoal = Mage::getSingleton('mzax_emarketing/conversion_goal_orders');
143
+
144
+ $binder = $conversionGoal->getRecipientBinder($campaign, $type === 'direct');
145
+
146
  return $binder->getSelect();
147
  }
 
 
 
 
 
 
 
148
 
149
  /**
150
  * html for settings in option form
152
  * @return string
153
  */
154
  protected function prepareForm()
155
+ {
156
+ return $this->__(
157
+ 'Order is linked %s to emarketing campaign %s',
158
  $this->getSelectElement('join')->toHtml(),
159
  $this->getSelectElement('campaign')->toHtml()
160
+ );
161
  }
162
+
163
+ /**
164
+ * @return string[]
165
+ */
166
  public function getJoinOptions()
167
  {
168
  return array(
170
  'indirect' => $this->__('indirectly'),
171
  );
172
  }
173
+
174
+ /**
175
+ * @return string[]
176
+ */
177
  public function getCampaignOptions()
178
  {
179
  /* @var $collection Mzax_Emarketing_Model_Resource_Campaign_Collection */
180
  $collection = Mage::getResourceModel('mzax_emarketing/campaign_collection');
181
  $collection->addArchiveFilter(false);
182
+
183
  $options = array();
184
+ if ($this->getParam('tracker') instanceof Mzax_Emarketing_Model_Conversion_Tracker) {
185
  $options['current'] = $this->__('beeing tracked');
186
  }
187
  $options += $collection->toOptionHash();
188
+
189
  return $options;
190
  }
191
+
 
 
 
 
192
  /**
193
+ * Retrieve current campaign
194
+ *
195
  * We must always return a campaign object!
196
  * getQuery() needs to work with no data set
197
+ *
198
  * @return Mzax_Emarketing_Model_Campaign
199
  */
200
  public function getCampaign()
201
  {
202
+ if (!$this->_campaign) {
 
203
  $id = $this->getDataSetDefault('campaign');
204
+
205
+ if ($id === 'current') {
206
  return $this->getParam('campaign');
207
  }
208
  $campaign = Mage::getModel('mzax_emarketing/campaign');
209
+ if (!$id) {
210
  return null;
211
  }
212
  $campaign->load($id);
213
+ if (!$campaign->getId()) {
214
  return null;
215
  }
 
216
  $this->_campaign = $campaign;
217
  }
218
+
219
  return $this->_campaign;
220
  }
221
+
 
222
  /**
223
+ * Retrieve current campaign variation which we aggregate
224
  *
225
  * @return null|integer
226
  */
227
  public function getVariation()
228
  {
229
  $id = Mage::registry('mzax_aggregate_variation');
230
+ if ($id !== null && $id > -1) {
231
  return (int) $id;
232
  }
233
+
234
  return null;
235
  }
 
 
 
 
 
 
236
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,24 +18,18 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  abstract class Mzax_Emarketing_Model_Object_Filter_Order_Item_Abstract
30
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
31
  {
32
-
33
-
 
 
 
34
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
35
  {
36
  return $parent->hasBinding('order_item_id');
37
  }
38
-
39
-
40
-
41
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_Item_Abstract
 
 
 
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Filter_Order_Item_Abstract
24
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
25
  {
26
+ /**
27
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
28
+ *
29
+ * @return bool
30
+ */
31
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
32
  {
33
  return $parent->hasBinding('order_item_id');
34
  }
 
 
 
 
35
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Item/Table.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,113 +17,97 @@
18
  */
19
 
20
 
21
-
22
-
23
  /**
24
  * Setup filters for the order item table
25
- *
26
- *
27
  * Missing something?
28
  * use event "mzax_emarketing_email_filter_prepare_table_sales_order_item"
29
  * to register any custom columns
30
- *
31
- *
32
- *
33
- * @author Jacob Siefer
34
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
- * @version 0.4.10
36
  */
37
  class Mzax_Emarketing_Model_Object_Filter_Order_Item_Table
38
  extends Mzax_Emarketing_Model_Object_Filter_Table
39
  {
40
-
41
  /**
42
- *
43
  * @var string
44
  */
45
  protected $_table = 'sales/order_item';
46
-
47
-
 
 
48
  protected $_tableAlias = 'sales_order_item';
49
-
50
-
51
 
 
 
 
52
  protected $_tableIdFieldName = 'item_id';
53
 
54
  /**
55
- *
56
  * @var string
57
  */
58
  protected $_requireBinding = 'order_item_id';
59
-
60
-
61
 
 
 
 
62
  protected $_formText = 'Order Item `%s` %s %s.';
63
-
64
 
 
 
 
65
  protected $_boolFormText = 'Order Item %s `%s`.';
66
 
67
-
68
-
69
  /**
70
  * Group title
71
- *
72
  * @return string
73
  */
74
  public function getTitle()
75
  {
76
  return "Order Item";
77
  }
78
-
79
-
80
-
81
  /**
82
  * Register column filters
83
- *
84
  * Use mzax_emarketing_email_filter_prepare_table_sales_order_item event to register more
85
- *
86
  * @return void
87
  */
88
  protected function _registerColumns()
89
  {
90
  $this->addColumn('product_type', 'Product Type', 'multiselect', Mage::getSingleton('catalog/product_type')->getOptionArray());
91
-
92
- $this->addColumn('sku', 'SKU', 'string');
93
-
94
-
95
- $this->addColumn('base_price', 'Price', 'price');
96
- $this->addColumn('base_price_incl_tax', 'Price (inc. tax)', 'price');
97
-
98
- $this->addColumn('base_discount_amount', 'Discount Amount', 'price');
99
- $this->addColumn('base_tax_amount', 'Tax Amount', 'price');
100
-
101
-
102
- $this->addColumn('qty_ordered', 'Quantity Ordered', 'numeric');
103
- $this->addColumn('qty_invoiced', 'Quantity Invoiced', 'numeric');
104
- $this->addColumn('qty_refunded', 'Quantity Refunded', 'numeric');
105
- $this->addColumn('qty_canceled', 'Quantity Canceled', 'numeric');
106
- $this->addColumn('qty_shipped', 'Quantity Shipped', 'numeric');
107
- $this->addColumn('qty_backordered', 'Quantity Backordered', 'numeric');
108
-
109
- $this->addColumn('row_weight', 'Row Weight', 'numeric');
110
-
111
- $this->addColumn('is_virtual', 'Virtual', 'boolean');
112
- $this->addColumn('free_shipping', 'Free Shipping', 'boolean');
113
  }
114
-
115
-
116
-
117
-
118
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
119
  {
120
  parent::_prepareCollection($collection);
121
-
122
  // add currency code for price columns
123
  $collection->getQuery()->joinTable(array('entity_id' => '{order_id}'), 'sales/order', 'order');
124
  $collection->addField('currency_code', "`order`.`base_currency_code`");
125
  }
126
-
127
-
128
-
129
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
 
 
 
20
  /**
21
  * Setup filters for the order item table
22
+ *
 
23
  * Missing something?
24
  * use event "mzax_emarketing_email_filter_prepare_table_sales_order_item"
25
  * to register any custom columns
 
 
 
 
 
 
26
  */
27
  class Mzax_Emarketing_Model_Object_Filter_Order_Item_Table
28
  extends Mzax_Emarketing_Model_Object_Filter_Table
29
  {
 
30
  /**
 
31
  * @var string
32
  */
33
  protected $_table = 'sales/order_item';
34
+
35
+ /**
36
+ * @var string
37
+ */
38
  protected $_tableAlias = 'sales_order_item';
 
 
39
 
40
+ /**
41
+ * @var string
42
+ */
43
  protected $_tableIdFieldName = 'item_id';
44
 
45
  /**
 
46
  * @var string
47
  */
48
  protected $_requireBinding = 'order_item_id';
 
 
49
 
50
+ /**
51
+ * @var string
52
+ */
53
  protected $_formText = 'Order Item `%s` %s %s.';
 
54
 
55
+ /**
56
+ * @var string
57
+ */
58
  protected $_boolFormText = 'Order Item %s `%s`.';
59
 
 
 
60
  /**
61
  * Group title
62
+ *
63
  * @return string
64
  */
65
  public function getTitle()
66
  {
67
  return "Order Item";
68
  }
69
+
 
 
70
  /**
71
  * Register column filters
72
+ *
73
  * Use mzax_emarketing_email_filter_prepare_table_sales_order_item event to register more
74
+ *
75
  * @return void
76
  */
77
  protected function _registerColumns()
78
  {
79
  $this->addColumn('product_type', 'Product Type', 'multiselect', Mage::getSingleton('catalog/product_type')->getOptionArray());
80
+
81
+ $this->addColumn('sku', 'SKU', 'string');
82
+
83
+ $this->addColumn('base_price', 'Price', 'price');
84
+ $this->addColumn('base_price_incl_tax', 'Price (inc. tax)', 'price');
85
+
86
+ $this->addColumn('base_discount_amount', 'Discount Amount', 'price');
87
+ $this->addColumn('base_tax_amount', 'Tax Amount', 'price');
88
+
89
+ $this->addColumn('qty_ordered', 'Quantity Ordered', 'numeric');
90
+ $this->addColumn('qty_invoiced', 'Quantity Invoiced', 'numeric');
91
+ $this->addColumn('qty_refunded', 'Quantity Refunded', 'numeric');
92
+ $this->addColumn('qty_canceled', 'Quantity Canceled', 'numeric');
93
+ $this->addColumn('qty_shipped', 'Quantity Shipped', 'numeric');
94
+ $this->addColumn('qty_backordered', 'Quantity Backordered', 'numeric');
95
+
96
+ $this->addColumn('row_weight', 'Row Weight', 'numeric');
97
+
98
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
99
+ $this->addColumn('free_shipping', 'Free Shipping', 'boolean');
 
 
100
  }
101
+
102
+ /**
103
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
104
+ */
105
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
106
  {
107
  parent::_prepareCollection($collection);
108
+
109
  // add currency code for price columns
110
  $collection->getQuery()->joinTable(array('entity_id' => '{order_id}'), 'sales/order', 'order');
111
  $collection->addField('currency_code', "`order`.`base_currency_code`");
112
  }
 
 
 
 
113
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Items.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -18,49 +17,41 @@
18
  */
19
 
20
  /**
21
- *
22
- *
23
  *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Model_Object_Filter_Order_Items
29
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
30
  {
31
-
32
  const DEFAULT_AGGREGATOR = 'all';
33
-
34
  const DEFAULT_EXPECTATION = 'true';
35
-
36
  const DEFAULT_SUM = 'qty_ordered';
37
-
38
-
39
 
 
 
 
40
  protected $_allowChildren = true;
41
-
42
-
43
-
44
-
45
  public function getTitle()
46
  {
47
  return "Order | Items subselection matches...";
48
  }
49
-
50
-
51
-
52
  /**
53
  * Use order item object
54
- *
55
  * @return Mzax_Emarketing_Model_Object_OrderItem
56
  */
57
  public function getObject()
58
  {
59
  return Mage::getSingleton('mzax_emarketing/object_orderItem');
60
  }
61
-
62
-
63
-
64
  /**
65
  * Setup query for child filters
66
  * we need the order id and the sum_field
@@ -70,88 +61,81 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Items
70
  public function getQuery()
71
  {
72
  $sumField = $this->getDataSetDefault('sum');
73
-
74
  $query = $this->getObject()->getQuery();
75
  $query->addBinding('sum_field', $sumField);
76
  $query->setColumn('order_id');
77
  $query->setColumn('sum_field');
78
-
79
  return $query;
80
  }
81
-
82
-
83
 
84
-
85
-
86
  /**
87
- *
88
- * @return Zend_Db_Select
 
89
  */
90
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
91
  {
92
- $conditions = $this->_getConditions();
93
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
94
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
95
-
96
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
97
-
98
  // if value can match zero include all records
99
- if($this->checkIfMatchZero('value')) {
100
-
101
  $zeroRecords = $this->getQuery();
102
  // assume all orders have items, no right join required
103
  $zeroRecords->setColumn('sum_field', new Zend_Db_Expr('0'));
104
  $zeroRecords->setColumn('matches', new Zend_Db_Expr('0'));
105
-
106
  $select = $this->_select()->union(array($zeroRecords, $select));
107
  }
108
-
109
  $query->useTemporaryTable($this->getTempTableName());
110
  $query->joinSelect('order_id', $select, 'filter');
111
  $query->addBinding('value', new Zend_Db_Expr('SUM(`filter`.`sum_field`)'));
112
  $query->having($this->getWhereSql('value', '{value}'));
113
  $query->group();
114
  }
115
-
116
-
117
-
118
 
 
 
 
 
 
119
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
120
  {
121
  parent::_prepareCollection($collection);
122
  $collection->addField('value');
123
  }
124
-
125
-
126
-
 
 
 
127
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
128
  {
129
  parent::prepareGridColumns($grid);
130
-
131
  $sumOptions = $this->getSumOptions();
132
- if(isset($sumOptions[$this->getSum()])) {
133
  $title = ucwords($sumOptions[$this->getSum()]);
134
- }
135
- else {
136
  $title = $this->__('Total');
137
  }
138
-
139
  $grid->addColumn('value', array(
140
  'header' => $title,
141
  'index' => 'value',
142
  'type' => 'number'
143
  ));
144
-
145
  $grid->setDefaultSort('increment_id');
146
  $grid->setDefaultDir('DESC');
147
-
148
  }
149
-
150
-
151
-
152
-
153
-
154
-
155
 
156
  /**
157
  * html for settings in option form
@@ -160,19 +144,18 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Items
160
  */
161
  protected function prepareForm()
162
  {
163
- return $this->__('If total %s %s for subselection of items matching %s of these conditions:',
 
164
  $this->getSelectElement('sum')->toHtml(),
165
  $this->getInputHtml('value', 'numeric'),
166
- $this->getSelectElement('aggregator', 'all')->toHtml()
167
- );
168
  }
169
-
170
-
171
-
172
  /**
173
  * List of fields to sum up and check against
174
- *
175
- * @return return array
176
  */
177
  protected function getSumOptions()
178
  {
@@ -190,5 +173,4 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Items
190
  'base_cost' => $this->__('cost'),
191
  );
192
  }
193
-
194
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
17
  */
18
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_Items
 
21
  *
22
+ * @method string getSum()
23
+ * @method $this setSum(string $value)
 
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Order_Items
26
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
27
  {
 
28
  const DEFAULT_AGGREGATOR = 'all';
 
29
  const DEFAULT_EXPECTATION = 'true';
 
30
  const DEFAULT_SUM = 'qty_ordered';
 
 
31
 
32
+ /**
33
+ * @var bool
34
+ */
35
  protected $_allowChildren = true;
36
+
37
+ /**
38
+ * @return string
39
+ */
40
  public function getTitle()
41
  {
42
  return "Order | Items subselection matches...";
43
  }
44
+
 
 
45
  /**
46
  * Use order item object
47
+ *
48
  * @return Mzax_Emarketing_Model_Object_OrderItem
49
  */
50
  public function getObject()
51
  {
52
  return Mage::getSingleton('mzax_emarketing/object_orderItem');
53
  }
54
+
 
 
55
  /**
56
  * Setup query for child filters
57
  * we need the order id and the sum_field
61
  public function getQuery()
62
  {
63
  $sumField = $this->getDataSetDefault('sum');
64
+
65
  $query = $this->getObject()->getQuery();
66
  $query->addBinding('sum_field', $sumField);
67
  $query->setColumn('order_id');
68
  $query->setColumn('sum_field');
69
+
70
  return $query;
71
  }
 
 
72
 
 
 
73
  /**
74
+ * @param Mzax_Emarketing_Db_Select $query
75
+ *
76
+ * @return void
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
  // if value can match zero include all records
87
+ if ($this->checkIfMatchZero('value')) {
 
88
  $zeroRecords = $this->getQuery();
89
  // assume all orders have items, no right join required
90
  $zeroRecords->setColumn('sum_field', new Zend_Db_Expr('0'));
91
  $zeroRecords->setColumn('matches', new Zend_Db_Expr('0'));
92
+
93
  $select = $this->_select()->union(array($zeroRecords, $select));
94
  }
95
+
96
  $query->useTemporaryTable($this->getTempTableName());
97
  $query->joinSelect('order_id', $select, 'filter');
98
  $query->addBinding('value', new Zend_Db_Expr('SUM(`filter`.`sum_field`)'));
99
  $query->having($this->getWhereSql('value', '{value}'));
100
  $query->group();
101
  }
 
 
 
102
 
103
+ /**
104
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
105
+ *
106
+ * @return void
107
+ */
108
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
109
  {
110
  parent::_prepareCollection($collection);
111
  $collection->addField('value');
112
  }
113
+
114
+ /**
115
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
116
+ *
117
+ * @return void
118
+ */
119
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
120
  {
121
  parent::prepareGridColumns($grid);
122
+
123
  $sumOptions = $this->getSumOptions();
124
+ if (isset($sumOptions[$this->getSum()])) {
125
  $title = ucwords($sumOptions[$this->getSum()]);
126
+ } else {
 
127
  $title = $this->__('Total');
128
  }
129
+
130
  $grid->addColumn('value', array(
131
  'header' => $title,
132
  'index' => 'value',
133
  'type' => 'number'
134
  ));
135
+
136
  $grid->setDefaultSort('increment_id');
137
  $grid->setDefaultDir('DESC');
 
138
  }
 
 
 
 
 
 
139
 
140
  /**
141
  * html for settings in option form
144
  */
145
  protected function prepareForm()
146
  {
147
+ return $this->__(
148
+ 'If total %s %s for sub-selection 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
  * List of fields to sum up and check against
157
+ *
158
+ * @return string[]
159
  */
160
  protected function getSumOptions()
161
  {
173
  'base_cost' => $this->__('cost'),
174
  );
175
  }
 
176
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Previous.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,24 +18,14 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Object_Filter_Order_Previous
30
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
31
  {
32
-
33
  const DEFAULT_AGGREGATOR = 'all';
34
-
35
  const DEFAULT_EXPECTATION = 'true';
36
-
37
  const DEFAULT_DIRECTION = 'preceded';
38
-
39
-
40
 
41
  /**
42
  * Can have children
@@ -44,37 +33,37 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Previous
44
  * @var boolean
45
  */
46
  protected $_allowChildren = true;
47
-
48
-
49
-
 
 
 
 
 
 
50
  /**
51
  * Only works if parent object is the order object
52
- *
53
- * @return boolean
 
 
54
  */
55
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
56
  {
57
  return $parent->getObject() === Mage::getSingleton('mzax_emarketing/object_order');
58
  }
59
-
60
-
 
 
 
 
61
  public function acceptChild(Mzax_Emarketing_Model_Object_Filter_Component $child)
62
  {
63
  return true;
64
  }
65
-
66
-
67
-
68
-
69
- public function getTitle()
70
- {
71
- return "Order | Has preceded or followed orders matching...";
72
- }
73
-
74
-
75
-
76
-
77
-
78
  /**
79
  *
80
  * @return Mzax_Emarketing_Model_Object_Order
@@ -83,13 +72,9 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Previous
83
  {
84
  return Mage::getSingleton('mzax_emarketing/object_order');
85
  }
86
-
87
-
88
-
89
-
90
  /**
91
- * (non-PHPdoc)
92
- * @see Mzax_Emarketing_Model_Object_Filter_Component::getQuery()
93
  */
94
  public function getQuery()
95
  {
@@ -99,72 +84,66 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Previous
99
  $query->setColumn('customer_id');
100
  $query->setColumn('ordered_at');
101
  $query->setColumn('order_increment_id');
 
102
  return $query;
103
  }
104
-
105
-
106
 
 
 
 
 
 
107
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
108
  {
109
  $conditions = $this->_getConditions();
110
  $aggregator = $this->getDataSetDefault('aggregator');
111
  $expectation = $this->getDataSetDefault('expectation');
112
-
113
  $subFilterSelect = $this->_combineConditions($conditions, $aggregator, $expectation);
114
  $subFilterSelect->useTemporaryTable($this->getTempTableName());
115
-
116
  $type = $this->getDataSetDefault('direction');
117
  $cond['customer_id'] = '{customer_id}';
118
-
119
-
120
- if($type === 'preceded') {
121
  $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` < ' . '{ordered_at}');
122
  $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` > ' . $this->getTimeExpr('offset', '{ordered_at}', true));
123
- }
124
- else {
125
  $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` > ' . '{ordered_at}');
126
- $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` < ' . $this->getTimeExpr('offset', '{ordered_at}', false));
127
  }
128
-
129
-
130
-
131
  $query->joinSelect($cond, $subFilterSelect, 'prev_orders');
132
  $query->having($this->getWhereSql('orders', 'COUNT(`order_increment_id`)'));
133
  $query->group();
134
  }
135
-
136
 
137
-
138
-
139
-
 
 
140
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
141
  {
142
  parent::_prepareCollection($collection);
143
  $collection->addField('prev_orders', new Zend_Db_Expr('GROUP_CONCAT(`prev_orders`.`order_increment_id` SEPARATOR ", ")'));
144
  }
145
-
146
-
147
-
148
-
149
-
 
150
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
151
  {
152
  parent::prepareGridColumns($grid);
153
-
154
  $grid->addColumn('prev_orders', array(
155
  'header' => $this->__('Previous Orders'),
156
  'width' => '180px',
157
  'index' => 'prev_orders',
158
  ));
159
  }
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
 
169
  /**
170
  * html for settings in option form
@@ -175,8 +154,9 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Previous
175
  {
176
  $aggregatorElement = $this->getSelectElement('aggregator');
177
  $expectationElement = $this->getSelectElement('expectation');
178
-
179
- return $this->__('If number of %s orders, within %s and with %s of these conditions %s, %s:',
 
180
  $this->getSelectElement('direction')->toHtml(),
181
  $this->getTimeHtml('offset'),
182
  $aggregatorElement->toHtml(),
@@ -184,9 +164,10 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Previous
184
  $this->getInputHtml('orders', 'numeric')
185
  );
186
  }
187
-
188
-
189
-
 
190
  protected function getDirectionOptions()
191
  {
192
  return array(
@@ -194,7 +175,4 @@ class Mzax_Emarketing_Model_Object_Filter_Order_Previous
194
  'followed' => $this->__('followed'),
195
  );
196
  }
197
-
198
-
199
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_Previous
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Order_Previous
24
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
25
  {
 
26
  const DEFAULT_AGGREGATOR = 'all';
 
27
  const DEFAULT_EXPECTATION = 'true';
 
28
  const DEFAULT_DIRECTION = 'preceded';
 
 
29
 
30
  /**
31
  * Can have children
33
  * @var boolean
34
  */
35
  protected $_allowChildren = true;
36
+
37
+ /**
38
+ * @return string
39
+ */
40
+ public function getTitle()
41
+ {
42
+ return "Order | Has preceded or followed orders matching...";
43
+ }
44
+
45
  /**
46
  * Only works if parent object is the order object
47
+ *
48
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
49
+ *
50
+ * @return bool
51
  */
52
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
53
  {
54
  return $parent->getObject() === Mage::getSingleton('mzax_emarketing/object_order');
55
  }
56
+
57
+ /**
58
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $child
59
+ *
60
+ * @return bool
61
+ */
62
  public function acceptChild(Mzax_Emarketing_Model_Object_Filter_Component $child)
63
  {
64
  return true;
65
  }
66
+
 
 
 
 
 
 
 
 
 
 
 
 
67
  /**
68
  *
69
  * @return Mzax_Emarketing_Model_Object_Order
72
  {
73
  return Mage::getSingleton('mzax_emarketing/object_order');
74
  }
75
+
 
 
 
76
  /**
77
+ * @return Mzax_Emarketing_Db_Select
 
78
  */
79
  public function getQuery()
80
  {
84
  $query->setColumn('customer_id');
85
  $query->setColumn('ordered_at');
86
  $query->setColumn('order_increment_id');
87
+
88
  return $query;
89
  }
 
 
90
 
91
+ /**
92
+ * @param Mzax_Emarketing_Db_Select $query
93
+ *
94
+ * @return void
95
+ */
96
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
97
  {
98
  $conditions = $this->_getConditions();
99
  $aggregator = $this->getDataSetDefault('aggregator');
100
  $expectation = $this->getDataSetDefault('expectation');
101
+
102
  $subFilterSelect = $this->_combineConditions($conditions, $aggregator, $expectation);
103
  $subFilterSelect->useTemporaryTable($this->getTempTableName());
104
+
105
  $type = $this->getDataSetDefault('direction');
106
  $cond['customer_id'] = '{customer_id}';
107
+
108
+ if ($type === 'preceded') {
 
109
  $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` < ' . '{ordered_at}');
110
  $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` > ' . $this->getTimeExpr('offset', '{ordered_at}', true));
111
+ } else {
 
112
  $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` > ' . '{ordered_at}');
113
+ $cond[] = new Zend_Db_Expr('`prev_orders`.`ordered_at` < ' . $this->getTimeExpr('offset', '{ordered_at}', true));
114
  }
115
+
 
 
116
  $query->joinSelect($cond, $subFilterSelect, 'prev_orders');
117
  $query->having($this->getWhereSql('orders', 'COUNT(`order_increment_id`)'));
118
  $query->group();
119
  }
 
120
 
121
+ /**
122
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
123
+ *
124
+ * @return void
125
+ */
126
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
127
  {
128
  parent::_prepareCollection($collection);
129
  $collection->addField('prev_orders', new Zend_Db_Expr('GROUP_CONCAT(`prev_orders`.`order_increment_id` SEPARATOR ", ")'));
130
  }
131
+
132
+ /**
133
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
134
+ *
135
+ * @return void
136
+ */
137
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
138
  {
139
  parent::prepareGridColumns($grid);
140
+
141
  $grid->addColumn('prev_orders', array(
142
  'header' => $this->__('Previous Orders'),
143
  'width' => '180px',
144
  'index' => 'prev_orders',
145
  ));
146
  }
 
 
 
 
 
 
 
 
147
 
148
  /**
149
  * html for settings in option form
154
  {
155
  $aggregatorElement = $this->getSelectElement('aggregator');
156
  $expectationElement = $this->getSelectElement('expectation');
157
+
158
+ return $this->__(
159
+ 'If number of %s orders, within %s and with %s of these conditions %s, %s:',
160
  $this->getSelectElement('direction')->toHtml(),
161
  $this->getTimeHtml('offset'),
162
  $aggregatorElement->toHtml(),
164
  $this->getInputHtml('orders', 'numeric')
165
  );
166
  }
167
+
168
+ /**
169
+ * @return string[]
170
+ */
171
  protected function getDirectionOptions()
172
  {
173
  return array(
175
  'followed' => $this->__('followed'),
176
  );
177
  }
 
 
 
178
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/ShippedAt.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,50 +18,60 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- * @method Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt setShippedAtFrom(string $value)
25
- * @method Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt setShippedAtTo(string $value)
26
- * @method Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt setShippedAtUnit(string $value)
27
- *
28
- * @author Jacob Siefer
29
  *
 
 
 
 
 
 
 
 
30
  */
31
  class Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt
32
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
33
  {
34
-
35
-
 
36
  public function getTitle()
37
  {
38
  return "Order | Shipped ... ago";
39
  }
40
-
41
-
42
-
43
 
 
 
 
 
 
44
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
45
  {
46
  $query->joinTable('order_id', 'sales/shipment', 'shipment');
47
-
48
-
49
  $query->group();
50
  $query->having($this->getTimeRangeExpr('MIN(`shipment`.`created_at`)', 'shipped_at', false));
51
  }
52
-
53
-
 
 
 
 
54
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
55
  {
56
  parent::_prepareCollection($collection);
57
  $collection->addField('shipped_at', new Zend_Db_Expr('MIN(`shipment`.`created_at`)'));
58
  }
59
-
60
-
61
-
 
 
 
62
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
63
  {
64
  parent::prepareGridColumns($grid);
65
-
66
  $grid->addColumn('shipped_at', array(
67
  'header' => $this->__('Shipped At'),
68
  'width' => '180px',
@@ -71,10 +80,6 @@ class Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt
71
  'type' =>'datetime'
72
  ));
73
  }
74
-
75
-
76
-
77
-
78
 
79
  /**
80
  * html for settings in option form
@@ -83,10 +88,9 @@ class Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt
83
  */
84
  protected function prepareForm()
85
  {
86
- return $this->__('Order was shipped %s ago.',
 
87
  $this->getTimeRangeHtml('shipped_at')
88
- );
89
  }
90
-
91
-
92
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt
 
 
 
 
 
 
22
  *
23
+ * @method string getShippedAtFrom()
24
+ * @method $this setShippedAtFrom(string $value)
25
+ *
26
+ * @method string getShippedAtTo()
27
+ * @method $this setShippedAtTo(string $value)
28
+ *
29
+ * @method string getShippedAtUnit()
30
+ * @method $this setShippedAtUnit(string $value)
31
  */
32
  class Mzax_Emarketing_Model_Object_Filter_Order_ShippedAt
33
  extends Mzax_Emarketing_Model_Object_Filter_Order_Abstract
34
  {
35
+ /**
36
+ * @return string
37
+ */
38
  public function getTitle()
39
  {
40
  return "Order | Shipped ... ago";
41
  }
 
 
 
42
 
43
+ /**
44
+ * @param Mzax_Emarketing_Db_Select $query
45
+ *
46
+ * @return void
47
+ */
48
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
49
  {
50
  $query->joinTable('order_id', 'sales/shipment', 'shipment');
 
 
51
  $query->group();
52
  $query->having($this->getTimeRangeExpr('MIN(`shipment`.`created_at`)', 'shipped_at', false));
53
  }
54
+
55
+ /**
56
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
57
+ *
58
+ * @return void
59
+ */
60
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
61
  {
62
  parent::_prepareCollection($collection);
63
  $collection->addField('shipped_at', new Zend_Db_Expr('MIN(`shipment`.`created_at`)'));
64
  }
65
+
66
+ /**
67
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
68
+ *
69
+ * @return void
70
+ */
71
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
72
  {
73
  parent::prepareGridColumns($grid);
74
+
75
  $grid->addColumn('shipped_at', array(
76
  'header' => $this->__('Shipped At'),
77
  'width' => '180px',
80
  'type' =>'datetime'
81
  ));
82
  }
 
 
 
 
83
 
84
  /**
85
  * html for settings in option form
88
  */
89
  protected function prepareForm()
90
  {
91
+ return $this->__(
92
+ 'Order was shipped %s ago.',
93
  $this->getTimeRangeHtml('shipped_at')
94
+ );
95
  }
 
 
96
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Order/Table.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,87 +16,89 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- * Order table filters
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Model_Object_Filter_Order_Table
29
  extends Mzax_Emarketing_Model_Object_Filter_Table
30
  {
31
-
32
  /**
33
- *
34
  * @var string
35
  */
36
  protected $_table = 'sales/order';
37
-
38
-
 
 
39
  protected $_tableAlias = 'sales_order';
40
-
41
-
42
 
 
 
 
43
  protected $_tableIdFieldName = 'entity_id';
44
 
45
  /**
46
- *
47
  * @var string
48
  */
49
  protected $_requireBinding = 'order_id';
50
-
51
-
52
 
 
 
 
53
  protected $_formText = 'Order `%s` %s %s.';
54
-
55
 
 
 
 
56
  protected $_boolFormText = 'Order %s `%s`.';
57
 
58
-
59
-
60
-
61
  public function getTitle()
62
  {
63
  return "Order";
64
  }
65
-
66
-
 
 
67
  protected function _registerColumns()
68
  {
69
- $column = $this->addColumn('created_at', 'Order Date', 'date');
70
  $column->allowFuture = false;
71
-
72
- $this->addColumn('store_id', 'Store', 'multiselect', 'adminhtml/system_config_source_store');
73
- $this->addColumn('base_grand_total', 'Grand Total', 'currency');
74
- $this->addColumn('base_subtotal', 'Subtotal', 'currency');
75
- $this->addColumn('base_shipping_amount', 'Shipping Amount', 'currency');
76
- $this->addColumn('base_tax_amount', 'Tax Total', 'currency');
77
- $this->addColumn('base_discount_amount', 'Discount Amount', 'currency');
78
- $this->addColumn('base_total_refunded', 'Total Refunded', 'currency');
79
- $this->addColumn('weight', 'Total Weight', 'numeric');
80
- $this->addColumn('is_virtual', 'Virtual', 'boolean');
81
- $this->addColumn('customer_is_guest', 'Guest Checkout', 'boolean');
82
- $this->addColumn('status', 'Status', 'multiselect', Mage::getSingleton('sales/order_config')->getStatuses());
83
- $this->addColumn('customer_email', 'Customer Email', 'string');
84
- $this->addColumn('customer_firstname', 'Customer Firstname', 'string');
85
- $this->addColumn('customer_lastname', 'Customer Lastname', 'string');
 
 
 
86
  $this->addColumn('shipping_description', 'Shipping Description', 'string');
87
  }
88
-
89
-
90
-
91
-
 
 
92
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
93
  {
94
  parent::_prepareCollection($collection);
95
-
96
  // add currency code for price columns
97
  $collection->addField('currency_code', "`$this->_tableAlias`.`base_currency_code`");
98
  }
99
-
100
-
101
-
102
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Order_Table
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Order_Table
24
  extends Mzax_Emarketing_Model_Object_Filter_Table
25
  {
 
26
  /**
 
27
  * @var string
28
  */
29
  protected $_table = 'sales/order';
30
+
31
+ /**
32
+ * @var string
33
+ */
34
  protected $_tableAlias = 'sales_order';
 
 
35
 
36
+ /**
37
+ * @var string
38
+ */
39
  protected $_tableIdFieldName = 'entity_id';
40
 
41
  /**
 
42
  * @var string
43
  */
44
  protected $_requireBinding = 'order_id';
 
 
45
 
46
+ /**
47
+ * @var string
48
+ */
49
  protected $_formText = 'Order `%s` %s %s.';
 
50
 
51
+ /**
52
+ * @var string
53
+ */
54
  protected $_boolFormText = 'Order %s `%s`.';
55
 
56
+ /**
57
+ * @return string
58
+ */
59
  public function getTitle()
60
  {
61
  return "Order";
62
  }
63
+
64
+ /**
65
+ * @return void
66
+ */
67
  protected function _registerColumns()
68
  {
69
+ $column = $this->addColumn('created_at', 'Order Date', 'date');
70
  $column->allowFuture = false;
71
+
72
+ /** @var Mage_Sales_Model_Order_Config $orderConfig */
73
+ $orderConfig = Mage::getSingleton('sales/order_config');
74
+
75
+ $this->addColumn('store_id', 'Store', 'multiselect', 'adminhtml/system_config_source_store');
76
+ $this->addColumn('base_grand_total', 'Grand Total', 'currency');
77
+ $this->addColumn('base_subtotal', 'Subtotal', 'currency');
78
+ $this->addColumn('base_shipping_amount', 'Shipping Amount', 'currency');
79
+ $this->addColumn('base_tax_amount', 'Tax Total', 'currency');
80
+ $this->addColumn('base_discount_amount', 'Discount Amount', 'currency');
81
+ $this->addColumn('base_total_refunded', 'Total Refunded', 'currency');
82
+ $this->addColumn('weight', 'Total Weight', 'numeric');
83
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
84
+ $this->addColumn('customer_is_guest', 'Guest Checkout', 'boolean');
85
+ $this->addColumn('status', 'Status', 'multiselect', $orderConfig->getStatuses());
86
+ $this->addColumn('customer_email', 'Customer Email', 'string');
87
+ $this->addColumn('customer_firstname', 'Customer Firstname', 'string');
88
+ $this->addColumn('customer_lastname', 'Customer Lastname', 'string');
89
  $this->addColumn('shipping_description', 'Shipping Description', 'string');
90
  }
91
+
92
+ /**
93
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
94
+ *
95
+ * @return void
96
+ */
97
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
98
  {
99
  parent::_prepareCollection($collection);
100
+
101
  // add currency code for price columns
102
  $collection->addField('currency_code', "`$this->_tableAlias`.`base_currency_code`");
103
  }
 
 
 
 
104
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,23 +16,20 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  abstract class Mzax_Emarketing_Model_Object_Filter_Product_Abstract
26
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
27
  {
28
-
29
-
 
 
 
30
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
31
  {
32
  return $parent->hasBinding('product_id');
33
  }
34
-
35
-
36
-
37
-
38
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Product_Abstract
 
 
22
  */
23
  abstract class Mzax_Emarketing_Model_Object_Filter_Product_Abstract
24
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
25
  {
26
+ /**
27
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
28
+ *
29
+ * @return bool
30
+ */
31
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
32
  {
33
  return $parent->hasBinding('product_id');
34
  }
 
 
 
 
 
35
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Attribute.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,62 +16,62 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Product_Attribute
26
  extends Mzax_Emarketing_Model_Object_Filter_Attribute
27
  {
28
-
29
-
30
-
31
  /**
32
  * Attribute data key that indicates whether it should be used for rules
33
  *
34
  * @var string
35
  */
36
  protected $_isUsedForRuleProperty = 'is_used_for_promo_rules';
37
-
38
-
 
 
39
  protected $_entity = Mage_Catalog_Model_Product::ENTITY;
40
-
41
-
 
 
42
  protected $_requireBinding = 'product_id';
43
 
44
-
45
-
 
46
  public function getTitle()
47
  {
48
  return "Product Attributes";
49
  }
50
-
51
-
52
-
 
 
 
53
  protected function isAttributeAllowed(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
54
  {
55
- if($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute) {
56
- if($attribute->isAllowedForRuleCondition() && $attribute->getDataUsingMethod($this->_isUsedForRuleProperty)) {
57
  return true;
58
  }
59
  }
60
  return false;
61
  }
62
-
63
-
64
-
65
-
66
-
67
-
68
  public function getChooserUrl()
69
  {
70
- if($this->getAttribute()->getAttributeCode() === 'sku') {
71
  return 'adminhtml/promo_widget/chooser/attribute/sku/form/filter_conditions_fieldset';
72
- }
73
- }
74
-
75
-
76
-
77
 
 
 
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Product_Attribute
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Product_Attribute
24
  extends Mzax_Emarketing_Model_Object_Filter_Attribute
25
  {
 
 
 
26
  /**
27
  * Attribute data key that indicates whether it should be used for rules
28
  *
29
  * @var string
30
  */
31
  protected $_isUsedForRuleProperty = 'is_used_for_promo_rules';
32
+
33
+ /**
34
+ * @var string
35
+ */
36
  protected $_entity = Mage_Catalog_Model_Product::ENTITY;
37
+
38
+ /**
39
+ * @var string
40
+ */
41
  protected $_requireBinding = 'product_id';
42
 
43
+ /**
44
+ * @return string
45
+ */
46
  public function getTitle()
47
  {
48
  return "Product Attributes";
49
  }
50
+
51
+ /**
52
+ * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
53
+ *
54
+ * @return bool
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
+ * @return string
68
+ */
 
 
69
  public function getChooserUrl()
70
  {
71
+ if ($this->getAttribute()->getAttributeCode() === 'sku') {
72
  return 'adminhtml/promo_widget/chooser/attribute/sku/form/filter_conditions_fieldset';
73
+ }
 
 
 
 
74
 
75
+ return null;
76
+ }
77
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Product/Category.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,114 +16,100 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- * @author Jacob Siefer
23
- *
24
  */
25
  class Mzax_Emarketing_Model_Object_Filter_Product_Category
26
  extends Mzax_Emarketing_Model_Object_Filter_Product_Abstract
27
  {
28
-
29
-
30
-
31
  public function getTitle()
32
  {
33
  return "Product | Category";
34
  }
35
-
36
-
37
-
 
38
  public function getChooserUrl()
39
  {
40
  return 'adminhtml/promo_widget/chooser/attribute/category_ids/form/filter_conditions_fieldset';
41
  }
42
-
43
-
44
-
45
-
46
 
 
 
 
47
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
48
  {
49
  $categoryIds = $this->getData('value');
50
- if(empty($categoryIds)) {
51
  $query->where('FALSE = TRUE');
52
  return;
53
  }
54
-
55
  $categoryIds = $this->_explode($categoryIds);
56
  $operator = $this->getDataSetDefault('operator', '()');
57
-
58
  $query->joinTable('product_id', 'catalog/category_product', 'link')->group();
59
  $query->addBinding('category_id', 'category_id', 'link');
60
-
61
- if($operator === '()') {
62
  $query->where('`link`.`category_id` IN(?)', $categoryIds);
63
- }
64
- else {
65
  $query->where('`link`.`category_id` NOT IN(?)', $categoryIds);
66
- }
67
  }
68
-
69
-
70
 
71
-
72
-
 
 
 
73
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
74
  {
75
  parent::_prepareCollection($collection);
76
-
77
  $expr = $collection->joinAttribute('catname', 'category_id', 'catalog_category/name');
78
-
79
  $collection->addField('categories', new Zend_Db_Expr("GROUP_CONCAT($expr SEPARATOR ', ')"));
80
-
81
  }
82
-
83
-
 
 
 
 
84
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
85
  {
86
  parent::prepareGridColumns($grid);
87
-
88
  $grid->addColumn('categories', array(
89
  'header' => $this->__('Categories'),
90
  'index' => 'categories',
91
  ));
92
  }
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
  /**
102
- * html for settings in option form
103
- *
104
  * @return string
105
  */
106
  protected function prepareForm()
107
  {
108
-
109
  $operations = $this->helper()->getOperatorOptions(array('()', '!()'));
110
-
111
- $operatorElment = $this->getSelectElement('operator', '()', $operations);
 
112
  $valueElement = $this->getInputElement('value');
113
  $valueElement->setExplicitApply(true);
114
  $valueElement->setAfterElementHtml($this->getChooserTriggerHtml());
115
-
116
- return $this->__('Product category %s %s',
117
- $operatorElment->toHtml(),
 
118
  $valueElement->toHtml()
119
  );
120
  }
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Product_Category
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Product_Category
24
  extends Mzax_Emarketing_Model_Object_Filter_Product_Abstract
25
  {
26
+ /**
27
+ * @return string
28
+ */
29
  public function getTitle()
30
  {
31
  return "Product | Category";
32
  }
33
+
34
+ /**
35
+ * @return string
36
+ */
37
  public function getChooserUrl()
38
  {
39
  return 'adminhtml/promo_widget/chooser/attribute/category_ids/form/filter_conditions_fieldset';
40
  }
 
 
 
 
41
 
42
+ /**
43
+ * @param Mzax_Emarketing_Db_Select $query
44
+ */
45
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
46
  {
47
  $categoryIds = $this->getData('value');
48
+ if (empty($categoryIds)) {
49
  $query->where('FALSE = TRUE');
50
  return;
51
  }
52
+
53
  $categoryIds = $this->_explode($categoryIds);
54
  $operator = $this->getDataSetDefault('operator', '()');
55
+
56
  $query->joinTable('product_id', 'catalog/category_product', 'link')->group();
57
  $query->addBinding('category_id', 'category_id', 'link');
58
+
59
+ if ($operator === '()') {
60
  $query->where('`link`.`category_id` IN(?)', $categoryIds);
61
+ } else {
 
62
  $query->where('`link`.`category_id` NOT IN(?)', $categoryIds);
63
+ }
64
  }
 
 
65
 
66
+ /**
67
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
68
+ *
69
+ * @return void
70
+ */
71
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
72
  {
73
  parent::_prepareCollection($collection);
74
+
75
  $expr = $collection->joinAttribute('catname', 'category_id', 'catalog_category/name');
76
+
77
  $collection->addField('categories', new Zend_Db_Expr("GROUP_CONCAT($expr SEPARATOR ', ')"));
78
+
79
  }
80
+
81
+ /**
82
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
83
+ *
84
+ * @return void
85
+ */
86
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
87
  {
88
  parent::prepareGridColumns($grid);
89
+
90
  $grid->addColumn('categories', array(
91
  'header' => $this->__('Categories'),
92
  'index' => 'categories',
93
  ));
94
  }
95
+
 
 
 
 
 
 
 
96
  /**
 
 
97
  * @return string
98
  */
99
  protected function prepareForm()
100
  {
 
101
  $operations = $this->helper()->getOperatorOptions(array('()', '!()'));
102
+
103
+ $operatorElement = $this->getSelectElement('operator', '()', $operations);
104
+
105
  $valueElement = $this->getInputElement('value');
106
  $valueElement->setExplicitApply(true);
107
  $valueElement->setAfterElementHtml($this->getChooserTriggerHtml());
108
+
109
+ return $this->__(
110
+ 'Product category %s %s',
111
+ $operatorElement->toHtml(),
112
  $valueElement->toHtml()
113
  );
114
  }
 
 
 
 
 
 
 
 
 
115
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Abstract.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,25 +16,19 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
20
-
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  abstract class Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
30
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
31
  {
32
-
33
-
 
 
 
34
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
35
  {
36
  return $parent->hasBinding('quote_id');
37
  }
38
-
39
-
40
-
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
 
19
  /**
20
+ * Class Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
 
 
 
 
 
21
  */
22
  abstract class Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
23
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
24
  {
25
+ /**
26
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
27
+ *
28
+ * @return bool
29
+ */
30
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
31
  {
32
  return $parent->hasBinding('quote_id');
33
  }
 
 
 
34
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Address.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,101 +18,68 @@
19
 
20
 
21
  /**
22
- *
23
- *
24
- *
25
- * @author Jacob Siefer
26
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
- * @version 0.4.10
28
  */
29
  class Mzax_Emarketing_Model_Object_Filter_Quote_Address
30
  extends Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
31
  {
32
-
33
  const DEFAULT_AGGREGATOR = 'all';
34
-
35
  const DEFAULT_EXPECTATION = 'true';
36
-
37
-
38
  const TYPE_BILLING = 'billing';
39
  const TYPE_SHIPPING = 'shipping';
40
 
41
-
 
 
42
  protected $_allowChildren = true;
43
-
44
-
45
-
46
-
47
  public function getTitle()
48
  {
49
  return "Shopping Cart / Quote | Billing/Shipping Address matches...";
50
  }
51
-
52
-
53
-
54
-
55
-
56
  /**
57
- *
58
  * @return Mzax_Emarketing_Model_Object_OrderAddress
59
  */
60
  public function getObject()
61
  {
62
  return Mage::getSingleton('mzax_emarketing/object_quoteAddress');
63
  }
64
-
65
-
 
 
66
  public function getQuery()
67
  {
68
  $query = $this->getObject()->getQuery();
69
  $query->setColumn('quote_id');
70
-
71
  $query->where('address_type = ?', $this->getDataSetDefault('address_type', self::TYPE_BILLING));
72
-
73
  return $query;
74
  }
75
-
76
-
77
 
78
-
79
-
80
  /**
81
- *
82
- * @return Zend_Db_Select
 
83
  */
84
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
85
  {
86
  $conditions = $this->_getConditions();
87
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
88
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
89
-
90
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
91
  $select->useTemporaryTable($this->getTempTableName());
92
-
93
  $query->joinSelect('quote_id', $select, 'filter');
94
  $query->group();
95
  }
96
-
97
-
98
-
99
 
100
- protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
101
- {
102
- parent::_prepareCollection($collection);
103
- }
104
-
105
-
106
-
107
- public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
108
- {
109
- parent::prepareGridColumns($grid);
110
-
111
-
112
-
113
- }
114
-
115
-
116
-
117
  /**
118
  * html for settings in option form
119
  *
@@ -121,14 +87,16 @@ class Mzax_Emarketing_Model_Object_Filter_Quote_Address
121
  */
122
  protected function prepareForm()
123
  {
124
- return $this->__('If %s address matches %s of these conditions:',
125
- $this->getSelectElement('address_type', self::TYPE_BILLING)->toHtml(),
126
- $this->getSelectElement('aggregator', 'all')->toHtml()
127
- );
 
128
  }
129
-
130
-
131
-
 
132
  protected function getAddressTypeOptions()
133
  {
134
  return array(
@@ -136,11 +104,4 @@ class Mzax_Emarketing_Model_Object_Filter_Quote_Address
136
  self::TYPE_SHIPPING => $this->__('shipping'),
137
  );
138
  }
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Quote_Address
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Quote_Address
24
  extends Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
25
  {
 
26
  const DEFAULT_AGGREGATOR = 'all';
 
27
  const DEFAULT_EXPECTATION = 'true';
 
 
28
  const TYPE_BILLING = 'billing';
29
  const TYPE_SHIPPING = 'shipping';
30
 
31
+ /**
32
+ * @var bool
33
+ */
34
  protected $_allowChildren = true;
35
+
36
+ /**
37
+ * @return string
38
+ */
39
  public function getTitle()
40
  {
41
  return "Shopping Cart / Quote | Billing/Shipping Address matches...";
42
  }
43
+
 
 
 
 
44
  /**
 
45
  * @return Mzax_Emarketing_Model_Object_OrderAddress
46
  */
47
  public function getObject()
48
  {
49
  return Mage::getSingleton('mzax_emarketing/object_quoteAddress');
50
  }
51
+
52
+ /**
53
+ * @return Mzax_Emarketing_Db_Select
54
+ */
55
  public function getQuery()
56
  {
57
  $query = $this->getObject()->getQuery();
58
  $query->setColumn('quote_id');
59
+
60
  $query->where('address_type = ?', $this->getDataSetDefault('address_type', self::TYPE_BILLING));
61
+
62
  return $query;
63
  }
 
 
64
 
 
 
65
  /**
66
+ * @param Mzax_Emarketing_Db_Select $query
67
+ *
68
+ * @return void
69
  */
70
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
71
  {
72
  $conditions = $this->_getConditions();
73
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
74
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
75
+
76
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
77
  $select->useTemporaryTable($this->getTempTableName());
78
+
79
  $query->joinSelect('quote_id', $select, 'filter');
80
  $query->group();
81
  }
 
 
 
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  /**
84
  * html for settings in option form
85
  *
87
  */
88
  protected function prepareForm()
89
  {
90
+ return $this->__(
91
+ 'If %s address matches %s of these conditions:',
92
+ $this->getSelectElement('address_type', self::TYPE_BILLING)->toHtml(),
93
+ $this->getSelectElement('aggregator', 'all')->toHtml()
94
+ );
95
  }
96
+
97
+ /**
98
+ * @return string[]
99
+ */
100
  protected function getAddressTypeOptions()
101
  {
102
  return array(
104
  self::TYPE_SHIPPING => $this->__('shipping'),
105
  );
106
  }
 
 
 
 
 
 
 
107
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Item/Table.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -19,106 +18,94 @@
19
 
20
 
21
 
22
-
23
  /**
24
  * Setup filters for the quote item table
25
- *
26
- *
27
  * Missing something?
28
  * use event "mzax_emarketing_email_filter_prepare_table_sales_quote_item"
29
  * to register any custom columns
30
- *
31
- *
32
- *
33
- * @author Jacob Siefer
34
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
- * @version 0.4.10
36
  */
37
  class Mzax_Emarketing_Model_Object_Filter_Quote_Item_Table
38
  extends Mzax_Emarketing_Model_Object_Filter_Table
39
  {
40
-
41
  /**
42
- *
43
  * @var string
44
  */
45
  protected $_table = 'sales/quote_item';
46
-
47
-
 
 
48
  protected $_tableAlias = 'sales_quote_item';
49
-
50
-
51
 
 
 
 
52
  protected $_tableIdFieldName = 'item_id';
53
 
54
  /**
55
- *
56
  * @var string
57
  */
58
  protected $_requireBinding = 'quote_item_id';
59
-
60
-
61
 
 
 
 
62
  protected $_formText = 'Quote Item `%s` %s %s.';
63
-
64
 
 
 
 
65
  protected $_boolFormText = 'Quote Item %s `%s`.';
66
 
67
-
68
-
69
  /**
70
  * Group title
71
- *
72
  * @return string
73
  */
74
  public function getTitle()
75
  {
76
  return "Quote Item";
77
  }
78
-
79
-
80
-
81
  /**
82
  * Register column filters
83
- *
84
  * Use mzax_emarketing_email_filter_prepare_table_sales_order_item event to register more
85
- *
86
  * @return void
87
  */
88
  protected function _registerColumns()
89
  {
90
- $this->addColumn('product_type', 'Product Type', 'multiselect', Mage::getSingleton('catalog/product_type')->getOptionArray());
91
-
92
- $this->addColumn('sku', 'SKU', 'string');
93
-
94
- $this->addColumn('base_price', 'Price', 'price');
95
- $this->addColumn('custom_price', 'Custom Price', 'price');
96
-
97
- $this->addColumn('base_row_total', 'Row Total', 'price');
98
- $this->addColumn('base_discount_amount', 'Discount Amount', 'price');
99
- $this->addColumn('base_tax_amount', 'Tax Amount', 'price');
100
-
101
- $this->addColumn('qty', 'Quantity', 'numeric');
102
-
103
- $this->addColumn('row_weight', 'Row Weight', 'numeric');
104
-
105
- $this->addColumn('is_virtual', 'Virtual', 'boolean');
106
- $this->addColumn('free_shipping', 'Free Shipping', 'boolean');
107
  }
108
-
109
-
110
-
111
-
 
 
112
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
113
  {
114
  parent::_prepareCollection($collection);
115
-
116
  // add currency code for price columns
117
  $collection->getQuery()->joinTable(array('entity_id' => '{quote_id}'), 'sales/quote', 'quote');
118
  $collection->addField('currency_code', "`quote`.`base_currency_code`");
119
  }
120
-
121
-
122
-
123
-
124
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
18
 
19
 
20
 
 
21
  /**
22
  * Setup filters for the quote item table
23
+ *
24
+ *
25
  * Missing something?
26
  * use event "mzax_emarketing_email_filter_prepare_table_sales_quote_item"
27
  * to register any custom columns
 
 
 
 
 
 
28
  */
29
  class Mzax_Emarketing_Model_Object_Filter_Quote_Item_Table
30
  extends Mzax_Emarketing_Model_Object_Filter_Table
31
  {
 
32
  /**
 
33
  * @var string
34
  */
35
  protected $_table = 'sales/quote_item';
36
+
37
+ /**
38
+ * @var string
39
+ */
40
  protected $_tableAlias = 'sales_quote_item';
 
 
41
 
42
+ /**
43
+ * @var string
44
+ */
45
  protected $_tableIdFieldName = 'item_id';
46
 
47
  /**
 
48
  * @var string
49
  */
50
  protected $_requireBinding = 'quote_item_id';
 
 
51
 
52
+ /**
53
+ * @var string
54
+ */
55
  protected $_formText = 'Quote Item `%s` %s %s.';
 
56
 
57
+ /**
58
+ * @var string
59
+ */
60
  protected $_boolFormText = 'Quote Item %s `%s`.';
61
 
 
 
62
  /**
63
  * Group title
64
+ *
65
  * @return string
66
  */
67
  public function getTitle()
68
  {
69
  return "Quote Item";
70
  }
71
+
 
 
72
  /**
73
  * Register column filters
74
+ *
75
  * Use mzax_emarketing_email_filter_prepare_table_sales_order_item event to register more
76
+ *
77
  * @return void
78
  */
79
  protected function _registerColumns()
80
  {
81
+ /** @var Mage_Catalog_Model_Product_Type $types */
82
+ $types = Mage::getSingleton('catalog/product_type');
83
+
84
+ $this->addColumn('product_type', 'Product Type', 'multiselect', $types->getOptionArray());
85
+
86
+ $this->addColumn('sku', 'SKU', 'string');
87
+ $this->addColumn('base_price', 'Price', 'price');
88
+ $this->addColumn('custom_price', 'Custom Price', 'price');
89
+ $this->addColumn('base_row_total', 'Row Total', 'price');
90
+ $this->addColumn('base_discount_amount', 'Discount Amount', 'price');
91
+ $this->addColumn('base_tax_amount', 'Tax Amount', 'price');
92
+ $this->addColumn('qty', 'Quantity', 'numeric');
93
+ $this->addColumn('row_weight', 'Row Weight', 'numeric');
94
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
95
+ $this->addColumn('free_shipping', 'Free Shipping', 'boolean');
 
 
96
  }
97
+
98
+ /**
99
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
100
+ *
101
+ * @return void
102
+ */
103
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
104
  {
105
  parent::_prepareCollection($collection);
106
+
107
  // add currency code for price columns
108
  $collection->getQuery()->joinTable(array('entity_id' => '{quote_id}'), 'sales/quote', 'quote');
109
  $collection->addField('currency_code', "`quote`.`base_currency_code`");
110
  }
 
 
 
 
111
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Items.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,50 +16,43 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- *
22
- *
23
  *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Model_Object_Filter_Quote_Items
29
  extends Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
30
  {
31
-
32
  const DEFAULT_AGGREGATOR = 'all';
33
-
34
  const DEFAULT_EXPECTATION = 'true';
35
-
36
  const DEFAULT_SUM = 'qty';
37
-
38
-
39
 
 
 
 
40
  protected $_allowChildren = true;
41
-
42
-
43
-
44
-
45
  public function getTitle()
46
  {
47
- return "Shopping Cart / Quote | Items subselection matches...";
48
  }
49
-
50
-
51
-
52
  /**
53
  * Use order item object
54
- *
55
  * @return Mzax_Emarketing_Model_Object_QuoteItem
56
  */
57
  public function getObject()
58
  {
59
  return Mage::getSingleton('mzax_emarketing/object_quoteItem');
60
  }
61
-
62
-
63
-
64
  /**
65
  * Setup query for child filters
66
  * we need the order id and the sum_field
@@ -70,88 +62,81 @@ class Mzax_Emarketing_Model_Object_Filter_Quote_Items
70
  public function getQuery()
71
  {
72
  $sumField = $this->getDataSetDefault('sum');
73
-
74
  $query = $this->getObject()->getQuery();
75
  $query->addBinding('sum_field', $sumField);
76
  $query->setColumn('quote_id');
77
  $query->setColumn('sum_field');
78
-
79
  return $query;
80
  }
81
-
82
-
83
 
84
-
85
-
86
  /**
87
- *
88
- * @return Zend_Db_Select
 
89
  */
90
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
91
  {
92
  $conditions = $this->_getConditions();
93
- $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
94
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
95
-
96
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
97
-
98
  // if value can match zero include all records
99
- if($this->checkIfMatchZero('value')) {
100
-
101
  $zeroRecords = $this->getQuery();
102
  // assume all quotes have items, no right join required
103
  $zeroRecords->setColumn('sum_field', new Zend_Db_Expr('0'));
104
  $zeroRecords->setColumn('matches', new Zend_Db_Expr('0'));
105
-
106
  $select = $this->_select()->union(array($zeroRecords, $select));
107
  }
108
-
109
  $query->useTemporaryTable($this->getTempTableName());
110
  $query->joinSelect('quote_id', $select, 'filter');
111
  $query->addBinding('value', new Zend_Db_Expr('SUM(`filter`.`sum_field`)'));
112
  $query->having($this->getWhereSql('value', '{value}'));
113
  $query->group();
114
  }
115
-
116
-
117
-
118
 
 
 
 
 
 
119
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
120
  {
121
  parent::_prepareCollection($collection);
122
  $collection->addField('value');
123
  }
124
-
125
-
126
-
 
 
 
127
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
128
  {
129
  parent::prepareGridColumns($grid);
130
-
131
  $sumOptions = $this->getSumOptions();
132
- if(isset($sumOptions[$this->getSum()])) {
133
  $title = ucwords($sumOptions[$this->getSum()]);
134
- }
135
- else {
136
  $title = $this->__('Total');
137
  }
138
-
139
  $grid->addColumn('value', array(
140
  'header' => $title,
141
  'index' => 'value',
142
  'type' => 'number'
143
  ));
144
-
145
  $grid->setDefaultSort('quote_id');
146
  $grid->setDefaultDir('DESC');
147
-
148
  }
149
-
150
-
151
-
152
-
153
-
154
-
155
 
156
  /**
157
  * html for settings in option form
@@ -160,19 +145,18 @@ class Mzax_Emarketing_Model_Object_Filter_Quote_Items
160
  */
161
  protected function prepareForm()
162
  {
163
- return $this->__('If total %s %s for subselection of items matching %s of these conditions:',
 
164
  $this->getSelectElement('sum')->toHtml(),
165
  $this->getInputHtml('value', 'numeric'),
166
- $this->getSelectElement('aggregator', 'all')->toHtml()
167
  );
168
  }
169
-
170
-
171
-
172
  /**
173
  * List of fields to sum up and check against
174
- *
175
- * @return return array
176
  */
177
  protected function getSumOptions()
178
  {
@@ -185,5 +169,4 @@ class Mzax_Emarketing_Model_Object_Filter_Quote_Items
185
  'base_cost' => $this->__('cost'),
186
  );
187
  }
188
-
189
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Quote_Items
 
22
  *
23
+ * @method string getSum()
24
+ * @method $this setSum(string $value)
 
25
  */
26
  class Mzax_Emarketing_Model_Object_Filter_Quote_Items
27
  extends Mzax_Emarketing_Model_Object_Filter_Quote_Abstract
28
  {
 
29
  const DEFAULT_AGGREGATOR = 'all';
 
30
  const DEFAULT_EXPECTATION = 'true';
 
31
  const DEFAULT_SUM = 'qty';
 
 
32
 
33
+ /**
34
+ * @var bool
35
+ */
36
  protected $_allowChildren = true;
37
+
38
+ /**
39
+ * @return string
40
+ */
41
  public function getTitle()
42
  {
43
+ return "Shopping Cart / Quote | Items sub-selection matches...";
44
  }
45
+
 
 
46
  /**
47
  * Use order item object
48
+ *
49
  * @return Mzax_Emarketing_Model_Object_QuoteItem
50
  */
51
  public function getObject()
52
  {
53
  return Mage::getSingleton('mzax_emarketing/object_quoteItem');
54
  }
55
+
 
 
56
  /**
57
  * Setup query for child filters
58
  * we need the order id and the sum_field
62
  public function getQuery()
63
  {
64
  $sumField = $this->getDataSetDefault('sum');
65
+
66
  $query = $this->getObject()->getQuery();
67
  $query->addBinding('sum_field', $sumField);
68
  $query->setColumn('quote_id');
69
  $query->setColumn('sum_field');
70
+
71
  return $query;
72
  }
 
 
73
 
 
 
74
  /**
75
+ * @param Mzax_Emarketing_Db_Select $query
76
+ *
77
+ * @return void
78
  */
79
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
80
  {
81
  $conditions = $this->_getConditions();
82
+ $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
83
  $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
84
+
85
  $select = $this->_combineConditions($conditions, $aggregator, $expectation);
86
+
87
  // if value can match zero include all records
88
+ if ($this->checkIfMatchZero('value')) {
 
89
  $zeroRecords = $this->getQuery();
90
  // assume all quotes have items, no right join required
91
  $zeroRecords->setColumn('sum_field', new Zend_Db_Expr('0'));
92
  $zeroRecords->setColumn('matches', new Zend_Db_Expr('0'));
93
+
94
  $select = $this->_select()->union(array($zeroRecords, $select));
95
  }
96
+
97
  $query->useTemporaryTable($this->getTempTableName());
98
  $query->joinSelect('quote_id', $select, 'filter');
99
  $query->addBinding('value', new Zend_Db_Expr('SUM(`filter`.`sum_field`)'));
100
  $query->having($this->getWhereSql('value', '{value}'));
101
  $query->group();
102
  }
 
 
 
103
 
104
+ /**
105
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
106
+ *
107
+ * @return void
108
+ */
109
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
110
  {
111
  parent::_prepareCollection($collection);
112
  $collection->addField('value');
113
  }
114
+
115
+ /**
116
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
117
+ *
118
+ * @return void
119
+ */
120
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
121
  {
122
  parent::prepareGridColumns($grid);
123
+
124
  $sumOptions = $this->getSumOptions();
125
+ if (isset($sumOptions[$this->getSum()])) {
126
  $title = ucwords($sumOptions[$this->getSum()]);
127
+ } else {
 
128
  $title = $this->__('Total');
129
  }
130
+
131
  $grid->addColumn('value', array(
132
  'header' => $title,
133
  'index' => 'value',
134
  'type' => 'number'
135
  ));
136
+
137
  $grid->setDefaultSort('quote_id');
138
  $grid->setDefaultDir('DESC');
 
139
  }
 
 
 
 
 
 
140
 
141
  /**
142
  * html for settings in option form
145
  */
146
  protected function prepareForm()
147
  {
148
+ return $this->__(
149
+ 'If total %s %s for sub-selection of items matching %s of these conditions:',
150
  $this->getSelectElement('sum')->toHtml(),
151
  $this->getInputHtml('value', 'numeric'),
152
+ $this->getSelectElement('aggregator', 'all')->toHtml()
153
  );
154
  }
155
+
 
 
156
  /**
157
  * List of fields to sum up and check against
158
+ *
159
+ * @return string[]
160
  */
161
  protected function getSumOptions()
162
  {
169
  'base_cost' => $this->__('cost'),
170
  );
171
  }
 
172
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Quote/Table.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -17,81 +16,83 @@
17
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
  */
19
 
 
20
  /**
21
- * Quote table filters
22
- *
23
- *
24
- * @author Jacob Siefer
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- * @version 0.4.10
27
  */
28
  class Mzax_Emarketing_Model_Object_Filter_Quote_Table
29
  extends Mzax_Emarketing_Model_Object_Filter_Table
30
  {
31
-
32
  /**
33
- *
34
  * @var string
35
  */
36
  protected $_table = 'sales/quote';
37
-
38
-
 
 
39
  protected $_tableAlias = 'sales_quote';
40
-
41
-
42
 
 
 
 
43
  protected $_tableIdFieldName = 'entity_id';
44
 
45
  /**
46
- *
47
  * @var string
48
  */
49
  protected $_requireBinding = 'quote_id';
50
-
51
-
52
 
 
 
 
53
  protected $_formText = 'Quote `%s` %s %s.';
54
-
55
 
 
 
 
56
  protected $_boolFormText = 'Quote %s `%s`.';
57
 
58
-
59
-
60
-
61
  public function getTitle()
62
  {
63
  return "Shopping Cart / Quote";
64
  }
65
-
66
-
 
 
67
  protected function _registerColumns()
68
  {
69
- $column = $this->addColumn('created_at', 'Created Date', 'date');
70
  $column->allowFuture = false;
71
-
72
- $column = $this->addColumn('updated_at', 'Last Update', 'date');
73
  $column->allowFuture = false;
74
-
75
- $this->addColumn('store_id', 'Store', 'multiselect', 'adminhtml/system_config_source_store');
76
- $this->addColumn('base_grand_total', 'Grand Total', 'currency');
77
- $this->addColumn('base_subtotal', 'Subtotal', 'currency');
78
- $this->addColumn('is_virtual', 'Virtual', 'boolean');
79
- $this->addColumn('customer_is_guest', 'Guest Checkout', 'boolean');
80
- $this->addColumn('base_subtotal_with_discount', 'Subtotal with Discount', 'currency');
 
 
 
81
  }
82
-
83
-
84
-
85
-
 
 
86
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
87
  {
88
  parent::_prepareCollection($collection);
89
-
90
  // add currency code for price columns
91
  $collection->addField('currency_code', "`$this->_tableAlias`.`base_currency_code`");
92
  }
93
-
94
-
95
-
96
-
97
  }
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
+
20
  /**
21
+ * Class Mzax_Emarketing_Model_Object_Filter_Quote_Table
 
 
 
 
 
22
  */
23
  class Mzax_Emarketing_Model_Object_Filter_Quote_Table
24
  extends Mzax_Emarketing_Model_Object_Filter_Table
25
  {
 
26
  /**
 
27
  * @var string
28
  */
29
  protected $_table = 'sales/quote';
30
+
31
+ /**
32
+ * @var string
33
+ */
34
  protected $_tableAlias = 'sales_quote';
 
 
35
 
36
+ /**
37
+ * @var string
38
+ */
39
  protected $_tableIdFieldName = 'entity_id';
40
 
41
  /**
 
42
  * @var string
43
  */
44
  protected $_requireBinding = 'quote_id';
 
 
45
 
46
+ /**
47
+ * @var string
48
+ */
49
  protected $_formText = 'Quote `%s` %s %s.';
 
50
 
51
+ /**
52
+ * @var string
53
+ */
54
  protected $_boolFormText = 'Quote %s `%s`.';
55
 
56
+ /**
57
+ * @return string
58
+ */
59
  public function getTitle()
60
  {
61
  return "Shopping Cart / Quote";
62
  }
63
+
64
+ /**
65
+ * @return void
66
+ */
67
  protected function _registerColumns()
68
  {
69
+ $column = $this->addColumn('created_at', 'Created Date', 'date');
70
  $column->allowFuture = false;
71
+
72
+ $column = $this->addColumn('updated_at', 'Last Update', 'date');
73
  $column->allowFuture = false;
74
+
75
+ $this->addColumn('store_id', 'Store', 'multiselect', 'adminhtml/system_config_source_store');
76
+ $this->addColumn('base_grand_total', 'Grand Total', 'currency');
77
+ $this->addColumn('base_subtotal', 'Subtotal', 'currency');
78
+ $this->addColumn('is_virtual', 'Virtual', 'boolean');
79
+ $this->addColumn('customer_is_guest', 'Guest Checkout', 'boolean');
80
+ $this->addColumn('base_subtotal_with_discount', 'Subtotal with Discount', 'currency');
81
+ $this->addColumn('customer_email', 'Customer Email', 'string');
82
+ $this->addColumn('customer_firstname', 'Customer Firstname', 'string');
83
+ $this->addColumn('customer_lastname', 'Customer Lastname', 'string');
84
  }
85
+
86
+ /**
87
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
88
+ *
89
+ * @return void
90
+ */
91
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
92
  {
93
  parent::_prepareCollection($collection);
94
+
95
  // add currency code for price columns
96
  $collection->addField('currency_code', "`$this->_tableAlias`.`base_currency_code`");
97
  }
 
 
 
 
98
  }
app/code/community/Mzax/Emarketing/Model/Object/Filter/Table.php CHANGED
@@ -1,15 +1,14 @@
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
- *
12
- * @version 0.4.10
13
  * @category Mzax
14
  * @package Mzax_Emarketing
15
  * @author Jacob Siefer (jacob@mzax.de)
@@ -20,233 +19,226 @@
20
 
21
 
22
  /**
23
- *
24
- * @method Mzax_Emarketing_Model_Object_Filter_Table setColumn(string $name)
25
- * @method Mzax_Emarketing_Model_Object_Filter_Table setRelative(boolean $flag)
26
- * @method Mzax_Emarketing_Model_Object_Filter_Table setValue(mixed $value)
27
- * @method Mzax_Emarketing_Model_Object_Filter_Table setOperator(string $value)
28
- *
29
- * @author Jacob Siefer
30
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
- * @version 0.4.10
 
 
 
 
 
 
 
 
 
 
 
32
  */
33
  abstract class Mzax_Emarketing_Model_Object_Filter_Table
34
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
35
  {
36
-
37
  const VALUE_KEY = 'value';
38
-
39
-
40
  /**
41
  * Name of table e.g. sales/order
42
- *
43
  * @var string
44
  */
45
  protected $_table;
46
 
47
-
48
  /**
49
  * Query alias
50
- *
51
  * @var string
52
  */
53
  protected $_tableAlias;
54
-
55
-
56
  /**
57
  * Id field/column name
58
- *
59
  * @var string
60
  */
61
  protected $_tableIdFieldName = 'entity_id';
62
-
63
-
64
-
65
  /**
66
  * Form text
67
- *
68
  * 1. Column Name
69
  * 2. Operator (is, is not, contains,...)
70
  * 3. Value
71
- *
72
  * @var string
73
  */
74
  protected $_formText = '%s %s %s.';
75
-
76
-
77
-
78
  /**
79
  * Form text for boolean checks
80
  *
81
  * 1. Column Name
82
  * 2. Value (Yes, No)
83
- *
84
- * e.g
85
  * Quote %s %s. => Quote [is|is not] "Virtual".
86
  *
87
  * @var string
88
  */
89
  protected $_boolFormText = '%s %s.';
90
-
91
-
92
-
93
  /**
94
  * The binding that is required to show this filter.
95
  * Usally this is the table id field (order_id, quote_id, customer_id,...)
96
- *
97
  * @var string
98
  */
99
  protected $_requireBinding;
100
-
101
-
102
-
103
  /**
104
  * Use _registerColumns() and addColumn()
105
- *
106
  * @internal
107
  * @see Mzax_Emarketing_Model_Object_Filter_Table::_registerColumns()
108
  * @see Mzax_Emarketing_Model_Object_Filter_Table::addColumn()
109
  * @var array
110
  */
111
  protected $_columnOptions = array();
112
-
113
-
114
-
115
  /**
116
  * Reference to the selected table column
117
- *
118
  * @internal
119
  * @see Mzax_Emarketing_Model_Object_Filter_Table::getTableColumn()
120
  * @var array
121
  */
122
  protected $_tableColumn;
123
-
124
-
125
-
126
  /**
127
  * Abstract method to register all columns
128
- *
129
  * @return void
130
  */
131
  abstract protected function _registerColumns();
132
-
133
-
134
 
135
  /**
136
- *
137
- * (non-PHPdoc)
138
- * @see Mzax_Emarketing_Model_Object_Filter_Component::acceptParent()
139
  */
140
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
141
  {
142
  return $parent->hasBinding($this->_requireBinding);
143
  }
144
-
145
-
146
-
147
  /**
148
- *
149
- * (non-PHPdoc)
150
- * @see Mzax_Emarketing_Model_Object_Filter_Abstract::_prepareFilter($config)
151
  */
152
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
153
  {
154
  parent::_prepareFilter($config);
155
  $this->_registerColumns();
156
- Mage::dispatchEvent("mzax_emarketing_email_filter_prepare_table_" . $this->_tableAlias, array('filter' => $this));
 
 
 
 
157
  }
158
-
159
-
160
-
161
-
162
  /**
163
- *
164
- * (non-PHPdoc)
165
- * @see Mzax_Emarketing_Model_Object_Filter_Component::_prepareQuery()
 
166
  */
167
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
168
  {
169
  /* @var $adapter Zend_Db_Adapter_Abstract */
170
  $column = $this->getTableColumn();
171
- $adapter = $query->getAdapter();
172
-
173
- if(!$column) {
174
  throw new Exception("No valid table column defined");
175
  }
176
-
177
- if($this->_tableIdFieldName) {
178
  $bind = array($this->_tableIdFieldName => $this->_requireBinding);
179
- }
180
- else {
181
  $bind = $this->_requireBinding;
182
  }
183
-
184
  $query->joinTable($bind, $this->_table, $this->_tableAlias);
185
  $query->addBinding('column_value', $column->name, $this->_tableAlias);
186
-
187
  $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
188
  $value = $this->getData(self::VALUE_KEY);
189
-
190
-
191
 
192
  // relative date
193
- if($this->getData('relative')) {
194
  $future = $this->getDirection() == 'future';
195
-
196
- if($this->getAnniversary()) {
197
  $query->where($this->getAnniversaryTimeExpr('{column_value}', self::VALUE_KEY, $future, $column->applyGmtOffset));
198
- }
199
- else {
200
  $query->where($this->getTimeRangeExpr('{column_value}', self::VALUE_KEY, $future));
201
  }
202
  return;
203
  }
204
-
205
- if($column->type === 'boolean') {
206
  $value = '1';
207
  }
208
-
209
- switch($operator) {
210
  case '!=':
211
  case '>=':
212
  case '<=':
213
  case '>':
214
- case '<': return $query->where("{column_value} {$operator} ?", $value); break;
215
- case '{}': return $query->where("{column_value} LIKE ?", "%$value%"); break;
216
- case '!{}': return $query->where("{column_value} NOT LIKE ?", "%$value%"); break;
217
- case '()': return $query->where("{column_value} IN (?)", $this->_explode($value)); break;
218
- case '!()': return $query->where("{column_value} NOT IN (?)", $this->_explode($value)); break;
219
- default: return $query->where("{column_value} = ?", $value); break;
 
 
 
 
 
 
 
 
 
 
 
 
220
  }
221
  }
222
-
223
-
224
-
225
 
226
  /**
227
- *
228
- * (non-PHPdoc)
229
- * @see Mzax_Emarketing_Model_Object_Filter_Abstract::_prepareCollection($collection)
230
  */
231
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
232
  {
233
  parent::_prepareCollection($collection);
234
  $collection->addField('column_value');
235
  }
236
-
237
-
238
-
239
  /**
240
- *
241
- * (non-PHPdoc)
242
- * @see Mzax_Emarketing_Model_Object_Filter_Component::prepareGridColumns()
243
  */
244
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
245
  {
246
  parent::prepareGridColumns($grid);
247
-
248
- if($column = $this->getTableColumn())
249
- {
250
  $grid->addColumn('column_value', array(
251
  'header' => ucfirst($column->label),
252
  'type' => $this->getColumnType(),
@@ -256,35 +248,27 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Table
256
  'gmtoffset' => true
257
  ));
258
  }
259
-
260
  }
261
-
262
-
263
-
264
 
265
  /**
266
  * Retrieve table column name
267
  *
268
- * @return array
269
  */
270
  public function getTableColumn()
271
  {
272
- if( $this->_tableColumn === null) {
273
  $column = $this->getData('column');
274
- if(isset($this->_columnOptions[$column])) {
275
  $this->_tableColumn = $this->_columnOptions[$column];
276
- }
277
- else {
278
  $this->_tableColumn = false;
279
  }
280
-
281
  }
 
282
  return $this->_tableColumn;
283
  }
284
-
285
-
286
-
287
-
288
 
289
  /**
290
  * html for settings in option form
@@ -294,173 +278,152 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Table
294
  protected function prepareForm()
295
  {
296
  $column = $this->getTableColumn();
297
- if(!$column) {
298
  return "**ERROR** NO COLUMN SELECTED.";
299
  }
300
-
301
  $html = $this->getHiddenField('column', $column->name)->toHtml();
302
-
303
  $operatorElement = $this->getOperatorElement();
304
  $valueElement = $this->getValueElement();
305
-
306
-
307
- if($this->getData('relative')) {
308
-
309
- $timeRangeHtml = $this->getTimeRangeHtml(self::VALUE_KEY);
310
-
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
- $timeDirHtml = $this->getTimeDirectionHtml(self::VALUE_KEY);
317
-
318
- if($this->getAnniversary()) {
319
  $text = $this->getDirection() == 'future'
320
  ? '%s anniversary is in %s.'
321
  : '%s anniversary was %s ago.';
322
- }
323
- else {
324
  $text = $this->getDirection() == 'future'
325
  ? '%s is in %s.'
326
  : '%s was %s ago.';
327
  }
328
-
329
- return $html. $this->__($text,
 
330
  $column->label,
331
  $timeRangeHtml
332
  );
333
  }
334
-
335
-
336
- switch($column->type) {
337
  case 'boolean':
338
- return $html . $this->__($this->_boolFormText,
 
339
  $operatorElement->toHtml(),
340
  $column->label
341
  );
342
  }
343
-
344
- return $html . $this->__($this->_formText,
 
345
  $column->label,
346
  $operatorElement->toHtml(),
347
  $valueElement->toHtml()
348
  );
349
  }
350
-
351
-
352
-
353
-
354
-
355
  /**
356
  * Retrieve operator select element
357
- *
358
  * @return Varien_Data_Form_Element_Abstract
359
  */
360
  public function getOperatorElement()
361
  {
362
- $type = $this->getInputType();
363
  $default = $this->helper()->getDefaultOperatorByType($type);
364
  $options = $this->helper()->getOperatorOptionsByType($type);
365
-
366
  return $this->getSelectElement('operator', $default, $options);
367
  }
368
-
369
-
370
-
371
  /**
372
- * Retroeve value form element
373
- *
374
  * @return Varien_Data_Form_Element_Abstract
375
  */
376
  public function getValueElement()
377
  {
378
  $type = $this->getInputType();
379
-
380
- switch($type) {
381
-
382
  case 'date':
383
  $element = $this->getDateElement(self::VALUE_KEY);
384
  break;
385
-
386
  case 'select':
387
  case 'boolean':
388
  $element = $this->getSelectElement(self::VALUE_KEY);
389
  break;
390
-
391
  case 'multiselect':
392
  $element = $this->getMultiSelectElement(self::VALUE_KEY);
393
  break;
394
-
395
  default:
396
  $element = $this->getInputElement(self::VALUE_KEY);
397
  break;
398
  }
399
-
400
- if($this->getChooserUrl()) {
401
  $element->setExplicitApply(true);
402
  $element->setAfterElementHtml($this->getChooserTriggerHtml());
403
  }
404
-
405
  return $element;
406
  }
407
-
408
-
409
-
410
-
411
-
412
-
413
  /**
414
  * Retrieve all value options as hash
415
- *
416
  * array(value => label,...)
417
- *
418
- * @return array
419
  */
420
  public function getValueOptions()
421
  {
422
- if($column = $this->getTableColumn()) {
423
- switch($column->type) {
424
  case 'boolean':
425
  return array(
426
- '1' => $this->__('is'),
427
  '0' => $this->__('is not')
428
  );
429
  }
430
  return $column->options;
431
- }
 
432
  return array();
433
  }
434
-
435
-
436
-
437
  /**
438
  * Retrieve value options for the grid
439
  *
440
- * @return array
441
  */
442
  public function getGridValueOptions()
443
  {
444
- if($column = $this->getTableColumn()) {
445
- switch($column->type) {
446
  case 'boolean':
447
  return array(
448
  '1' => $this->__('Yes'),
449
  '0' => $this->__('No')
450
  );
451
  }
452
- if(isset($column->gridOptions)) {
453
  return $column->gridOptions;
454
  }
455
  }
456
  return $this->getValueOptions();
457
  }
458
-
459
-
460
-
461
-
462
-
463
-
464
  /**
465
  * Retrieve input type
466
  *
@@ -468,20 +431,16 @@ abstract class Mzax_Emarketing_Model_Object_Filter_Table
468
  */
469
  public function getInputType()
470
  {
471
- if($column = $this->getTableColumn()) {
472
- switch($column->type) {
473
  case 'price':
474
  return 'numeric';
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 this Extension in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
  * http://opensource.org/licenses/osl-3.0.php
11
+ *
 
12
  * @category Mzax
13
  * @package Mzax_Emarketing
14
  * @author Jacob Siefer (jacob@mzax.de)
19
 
20
 
21
  /**
22
+ * Class Mzax_Emarketing_Model_Object_Filter_Table
23
+ *
24
+ * @method string getColumn()
25
+ * @method $this setColumn(string $name)
26
+ *
27
+ * @method boolean getRelative()
28
+ * @method $this setRelative(boolean $flag)
29
+ *
30
+ * @method mixed getValue()
31
+ * @method $this setValue(mixed $value)
32
+ *
33
+ * @method string getOperator()
34
+ * @method $this setOperator(string $value)
35
+ *
36
+ * @method string getDirection()
37
+ * @method $this setDirection(string $value)
38
+ *
39
+ * @method boolean getAnniversary()
40
+ * @method $this setAnniversary(boolean $value)
41
+ *
42
  */
43
  abstract class Mzax_Emarketing_Model_Object_Filter_Table
44
  extends Mzax_Emarketing_Model_Object_Filter_Abstract
45
  {
 
46
  const VALUE_KEY = 'value';
47
+
 
48
  /**
49
  * Name of table e.g. sales/order
50
+ *
51
  * @var string
52
  */
53
  protected $_table;
54
 
 
55
  /**
56
  * Query alias
57
+ *
58
  * @var string
59
  */
60
  protected $_tableAlias;
61
+
 
62
  /**
63
  * Id field/column name
64
+ *
65
  * @var string
66
  */
67
  protected $_tableIdFieldName = 'entity_id';
68
+
 
 
69
  /**
70
  * Form text
71
+ *
72
  * 1. Column Name
73
  * 2. Operator (is, is not, contains,...)
74
  * 3. Value
75
+ *
76
  * @var string
77
  */
78
  protected $_formText = '%s %s %s.';
79
+
 
 
80
  /**
81
  * Form text for boolean checks
82
  *
83
  * 1. Column Name
84
  * 2. Value (Yes, No)
85
+ *
86
+ * e.g
87
  * Quote %s %s. => Quote [is|is not] "Virtual".
88
  *
89
  * @var string
90
  */
91
  protected $_boolFormText = '%s %s.';
92
+
 
 
93
  /**
94
  * The binding that is required to show this filter.
95
  * Usally this is the table id field (order_id, quote_id, customer_id,...)
96
+ *
97
  * @var string
98
  */
99
  protected $_requireBinding;
100
+
 
 
101
  /**
102
  * Use _registerColumns() and addColumn()
103
+ *
104
  * @internal
105
  * @see Mzax_Emarketing_Model_Object_Filter_Table::_registerColumns()
106
  * @see Mzax_Emarketing_Model_Object_Filter_Table::addColumn()
107
  * @var array
108
  */
109
  protected $_columnOptions = array();
110
+
 
 
111
  /**
112
  * Reference to the selected table column
113
+ *
114
  * @internal
115
  * @see Mzax_Emarketing_Model_Object_Filter_Table::getTableColumn()
116
  * @var array
117
  */
118
  protected $_tableColumn;
119
+
 
 
120
  /**
121
  * Abstract method to register all columns
122
+ *
123
  * @return void
124
  */
125
  abstract protected function _registerColumns();
 
 
126
 
127
  /**
128
+ * @param Mzax_Emarketing_Model_Object_Filter_Component $parent
129
+ *
130
+ * @return bool
131
  */
132
  public function acceptParent(Mzax_Emarketing_Model_Object_Filter_Component $parent)
133
  {
134
  return $parent->hasBinding($this->_requireBinding);
135
  }
136
+
 
 
137
  /**
138
+ * @param Mage_Core_Model_Config_Element $config
 
 
139
  */
140
  protected function _prepareFilter(Mage_Core_Model_Config_Element $config)
141
  {
142
  parent::_prepareFilter($config);
143
  $this->_registerColumns();
144
+
145
+ Mage::dispatchEvent(
146
+ "mzax_emarketing_email_filter_prepare_table_" . $this->_tableAlias,
147
+ array('filter' => $this)
148
+ );
149
  }
150
+
 
 
 
151
  /**
152
+ * @param Mzax_Emarketing_Db_Select $query
153
+ *
154
+ * @return void
155
+ * @throws Exception
156
  */
157
  protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
158
  {
159
  /* @var $adapter Zend_Db_Adapter_Abstract */
160
  $column = $this->getTableColumn();
161
+
162
+ if (!$column) {
 
163
  throw new Exception("No valid table column defined");
164
  }
165
+
166
+ if ($this->_tableIdFieldName) {
167
  $bind = array($this->_tableIdFieldName => $this->_requireBinding);
168
+ } else {
 
169
  $bind = $this->_requireBinding;
170
  }
171
+
172
  $query->joinTable($bind, $this->_table, $this->_tableAlias);
173
  $query->addBinding('column_value', $column->name, $this->_tableAlias);
174
+
175
  $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
176
  $value = $this->getData(self::VALUE_KEY);
177
+
 
178
 
179
  // relative date
180
+ if ($this->getData('relative')) {
181
  $future = $this->getDirection() == 'future';
182
+
183
+ if ($this->getAnniversary()) {
184
  $query->where($this->getAnniversaryTimeExpr('{column_value}', self::VALUE_KEY, $future, $column->applyGmtOffset));
185
+ } else {
 
186
  $query->where($this->getTimeRangeExpr('{column_value}', self::VALUE_KEY, $future));
187
  }
188
  return;
189
  }
190
+
191
+ if ($column->type === 'boolean') {
192
  $value = '1';
193
  }
194
+
195
+ switch ($operator) {
196
  case '!=':
197
  case '>=':
198
  case '<=':
199
  case '>':
200
+ case '<':
201
+ $query->where("{column_value} {$operator} ?", $value);
202
+ break;
203
+ case '{}':
204
+ $query->where("{column_value} LIKE ?", "%$value%");
205
+ break;
206
+ case '!{}':
207
+ $query->where("{column_value} NOT LIKE ?", "%$value%");
208
+ break;
209
+ case '()':
210
+ $query->where("{column_value} IN (?)", $this->_explode($value));
211
+ break;
212
+ case '!()':
213
+ $query->where("{column_value} NOT IN (?)", $this->_explode($value));
214
+ break;
215
+ default:
216
+ $query->where("{column_value} = ?", $value);
217
+ break;
218
  }
219
  }
 
 
 
220
 
221
  /**
222
+ * @param Mzax_Emarketing_Model_Object_Collection $collection
223
+ *
224
+ * @return void
225
  */
226
  protected function _prepareCollection(Mzax_Emarketing_Model_Object_Collection $collection)
227
  {
228
  parent::_prepareCollection($collection);
229
  $collection->addField('column_value');
230
  }
231
+
 
 
232
  /**
233
+ * @param Mzax_Emarketing_Block_Filter_Object_Grid $grid
234
+ *
235
+ * @return void
236
  */
237
  public function prepareGridColumns(Mzax_Emarketing_Block_Filter_Object_Grid $grid)
238
  {
239
  parent::prepareGridColumns($grid);
240
+
241
+ if ($column = $this->getTableColumn()) {
 
242
  $grid->addColumn('column_value', array(
243
  'header' => ucfirst($column->label),
244
  'type' => $this->getColumnType(),
248
  'gmtoffset' => true
249
  ));
250
  }
 
251
  }
 
 
 
252
 
253
  /**
254
  * Retrieve table column name
255
  *
256
+ * @return stdClass
257
  */
258
  public function getTableColumn()
259
  {
260
+ if ($this->_tableColumn === null) {
261
  $column = $this->getData('column');
262
+ if (isset($this->_columnOptions[$column])) {
263
  $this->_tableColumn = $this->_columnOptions[$column];
264
+ } else {
 
265
  $this->_tableColumn = false;
266
  }
267
+
268
  }
269
+
270
  return $this->_tableColumn;
271
  }
 
 
 
 
272
 
273
  /**
274
  * html for settings in option form
278
  protected function prepareForm()
279
  {
280
  $column = $this->getTableColumn();
281
+ if (!$column) {
282
  return "**ERROR** NO COLUMN SELECTED.";
283
  }
284
+
285
  $html = $this->getHiddenField('column', $column->name)->toHtml();
286
+
287
  $operatorElement = $this->getOperatorElement();
288
  $valueElement = $this->getValueElement();
289
+
290
+
291
+ if ($this->getRelative()) {
 
 
 
292
  $html .= $this->getHiddenField('relative', 1)->toHtml();
293
  $html .= $this->getHiddenField('anniversary', $this->getAnniversary())->toHtml();
294
  $html .= $this->getHiddenField('direction', $this->getDirection())->toHtml();
295
+
296
  $timeRangeHtml = $this->getTimeRangeHtml(self::VALUE_KEY);
297
+
298
+ if ($this->getAnniversary()) {
 
299
  $text = $this->getDirection() == 'future'
300
  ? '%s anniversary is in %s.'
301
  : '%s anniversary was %s ago.';
302
+ } else {
 
303
  $text = $this->getDirection() == 'future'
304
  ? '%s is in %s.'
305
  : '%s was %s ago.';
306
  }
307
+
308
+ return $html . $this->__(
309
+ $text,
310
  $column->label,
311
  $timeRangeHtml
312
  );
313
  }
314
+
315
+ switch ($column->type) {
 
316
  case 'boolean':
317
+ return $html . $this->__(
318
+ $this->_boolFormText,
319
  $operatorElement->toHtml(),
320
  $column->label
321
  );
322
  }
323
+
324
+ return $html . $this->__(
325
+ $this->_formText,
326
  $column->label,
327
  $operatorElement->toHtml(),
328
  $valueElement->toHtml()
329
  );
330
  }
331
+
 
 
 
 
332
  /**
333
  * Retrieve operator select element
334
+ *
335
  * @return Varien_Data_Form_Element_Abstract
336
  */
337
  public function getOperatorElement()
338
  {
339
+ $type = $this->getInputType();
340
  $default = $this->helper()->getDefaultOperatorByType($type);
341
  $options = $this->helper()->getOperatorOptionsByType($type);
342
+
343
  return $this->getSelectElement('operator', $default, $options);
344
  }
345
+
 
 
346
  /**
347
+ * Retrieve value form element
348
+ *
349
  * @return Varien_Data_Form_Element_Abstract
350
  */
351
  public function getValueElement()
352
  {
353
  $type = $this->getInputType();
354
+
355
+ switch ($type) {
 
356
  case 'date':
357
  $element = $this->getDateElement(self::VALUE_KEY);
358
  break;
359
+
360
  case 'select':
361
  case 'boolean':
362
  $element = $this->getSelectElement(self::VALUE_KEY);
363
  break;
364
+
365
  case 'multiselect':
366
  $element = $this->getMultiSelectElement(self::VALUE_KEY);
367
  break;
368
+
369
  default:
370
  $element = $this->getInputElement(self::VALUE_KEY);
371
  break;
372
  }
373
+
374
+ if ($this->getChooserUrl()) {
375
  $element->setExplicitApply(true);
376
  $element->setAfterElementHtml($this->getChooserTriggerHtml());
377
  }
378
+
379
  return $element;
380
  }
381
+
 
 
 
 
 
382
  /**
383
  * Retrieve all value options as hash
384
+ *
385
  * array(value => label,...)
386
+ *
387
+ * @return string[]
388
  */
389
  public function getValueOptions()
390
  {
391
+ if ($column = $this->getTableColumn()) {
392
+ switch ($column->type) {
393
  case 'boolean':
394
  return array(
395
+ '1' => $this->__('is'),
396
  '0' => $this->__('is not')
397
  );
398
  }
399
  return $column->options;
400
+ }
401
+
402
  return array();
403
  }
404
+
 
 
405
  /**
406
  * Retrieve value options for the grid
407
  *
408
+ * @return string[]
409
  */
410
  public function getGridValueOptions()
411
  {
412
+ if ($column = $this->getTableColumn()) {
413
+ switch ($column->type) {
414
  case 'boolean':
415
  return array(
416
  '1' => $this->__('Yes'),
417
  '0' => $this->__('No')
418
  );
419
  }
420
+ if (isset($column->gridOptions)) {
421
  return $column->gridOptions;
422
  }
423
  }
424
  return $this->getValueOptions();
425
  }
426
+
 
 
 
 
 
427
  /**
428
  * Retrieve input type
429
  *
431
  */
432
  public function getInputType()
433
  {
434
+ if ($column = $this->getTableColumn()) {
435
+ switch ($column->type) {
436
  case 'price':
437
  return 'numeric';
438