1
1
<?php
2
-
3
2
/**
4
- * @version frontend/helpers/pizzabox.php 2014-07-23 09:36 :00 UTC zanardi
3
+ * @version frontend/helpers/pizzabox.php 2015-06-22 16:39 :00 UTC zanardi
5
4
* @package GiBi PizzaBox
6
5
* @author GiBiLogic <[email protected] >
7
6
* @authorUrl http://www.gibilogic.com
8
- * @copyright Copyright (C) 2011-2013 GiBiLogic. All rights reserved.
9
- * @license GNU/GPL v2 or later
7
+ * @copyright Copyright (C) 2011-2015 GiBiLogic. All rights reserved.
8
+ * @license GNU/GPL v3 or later
10
9
*/
11
10
defined ('_JEXEC ' ) or die ();
12
- require_once ( JPATH_COMPONENT_ADMINISTRATOR . '/models/orders.php ' ) ;
11
+ require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/orders.php ' ;
13
12
14
13
/**
15
14
* PizzaboxHelper
@@ -19,22 +18,18 @@ class PizzaboxHelper
19
18
20
19
public function __construct ()
21
20
{
22
- $ this ->params = & JComponentHelper::getParams ('com_pizzabox ' );
21
+ $ this ->params = JComponentHelper::getParams ('com_pizzabox ' );
23
22
}
24
23
25
24
public function formatPrice ($ price )
26
25
{
27
- if (!is_numeric ($ price ))
28
- {
26
+ if (!is_numeric ($ price )) {
29
27
return '' ;
30
28
}
31
29
32
- if ($ this ->params ->get ('currency_symbol_position ' , 'before ' ) == 'before ' )
33
- {
30
+ if ($ this ->params ->get ('currency_symbol_position ' , 'before ' ) == 'before ' ) {
34
31
return $ this ->params ->get ('currency_symbol ' ) . " " . sprintf ("%.2f " , $ price );
35
- }
36
- else
37
- {
32
+ } else {
38
33
return sprintf ("%.2f " , $ price ) . " " . $ this ->params ->get ('currency_symbol ' );
39
34
}
40
35
}
@@ -55,16 +50,17 @@ public function emailNotification($order_id)
55
50
$ mailer->
setSender (
$ config->
get (
'mailfrom ' ,
'[email protected] ' ));
56
51
57
52
// Recipient(s)
58
- foreach ($ this ->getAdminRecipients () as $ email => $ name )
59
- {
53
+ foreach ($ this ->getAdminRecipients () as $ email => $ name ) {
60
54
$ mailer ->addRecipient ($ email , $ name );
61
55
}
62
56
$ user = JFactory::getUser ();
63
57
$ mailer ->addRecipient ($ user ->email , $ user ->name );
64
58
65
59
// Subject and body
66
60
$ mailer ->setSubject (JText::_ ('PIZZABOX_EMAIL_NOTIFICATION_SUBJECT ' ));
67
- $ mailer ->setBody ('<html><body><p> ' . JText::_ ('PIZZABOX_EMAIL_NOTIFICATION_BODY ' ) . $ this ->buildOrderBody ($ order_id ) . "</p></body></html> " );
61
+ $ body = '<html><body><p> ' . JText::_ ('PIZZABOX_EMAIL_NOTIFICATION_BODY ' ) . $ this ->buildOrderBody ($ order_id ) . "</p></body></html> " ;
62
+ $ mailer ->setBody ($ body );
63
+ $ mailer ->AltBody = JMailHelper::cleanText (strip_tags ($ body ));
68
64
69
65
// Send message
70
66
$ mailer ->IsHTML (true );
@@ -79,8 +75,7 @@ public function emailNotification($order_id)
79
75
*/
80
76
private function buildOrderBody ($ order_id )
81
77
{
82
- if (!$ this ->params ->get ("email_includes_order " , 0 ))
83
- {
78
+ if (!$ this ->params ->get ("email_includes_order " , 0 )) {
84
79
$ link = JURI ::root () . JRoute::_ ("index.php?option=com_pizzabox&controller=orders&task=edit&id= $ order_id " );
85
80
return "<a href= \"$ link \"> " . JText::_ ('PIZZABOX_EMAIL_NOTIFICATION_BODY_ORDER_DETAIL ' ) . "</a> " ;
86
81
}
@@ -90,8 +85,7 @@ private function buildOrderBody($order_id)
90
85
$ this ->order = $ orderModel ->getItem ();
91
86
$ parts = $ orderModel ->getParts ();
92
87
93
- foreach ($ parts as &$ part )
94
- {
88
+ foreach ($ parts as &$ part ) {
95
89
$ part ->container_image = JURI ::root () . $ this ->getElementImage ('containers ' , $ part ->container_id );
96
90
$ part ->part_image = JURI ::root () . $ this ->getElementImage ('parts ' , $ part ->part_id );
97
91
$ part ->flavour_image = JURI ::root () . $ this ->getElementImage ('flavours ' , $ part ->flavour_id );
@@ -104,29 +98,24 @@ private function buildOrderBody($order_id)
104
98
$ this ->helper = new PizzaboxHelper ();
105
99
106
100
ob_start ();
107
- include JPATH_COMPONENT_SITE . '/layouts/_order_details .php ' ;
108
- return "<div> " . ob_get_clean (). "</div> " ;
101
+ include JPATH_COMPONENT_SITE . '/layouts/_mail_order_details .php ' ;
102
+ return "<div> " . ob_get_clean () . "</div> " ;
109
103
}
110
104
111
105
/**
112
106
* Get all admin recipients which should receive the notification
113
107
*/
114
108
private function getAdminRecipients ()
115
109
{
116
- if (!$ this ->params ->get ('email_notification ' , 0 ))
117
- {
110
+ if (!$ this ->params ->get ('email_notification ' , 0 )) {
118
111
return array ();
119
112
}
120
113
121
114
$ recipients = array ();
122
- if ($ this ->params ->get ('email_address ' , '' ))
123
- {
115
+ if ($ this ->params ->get ('email_address ' , '' )) {
124
116
$ recipients [$ this ->params ->get ('email_address ' )] = $ this ->params ->get ('email_address ' );
125
- }
126
- else
127
- {
128
- foreach ($ this ->_getSystemEmailAddresses () as $ recipient )
129
- {
117
+ } else {
118
+ foreach ($ this ->_getSystemEmailAddresses () as $ recipient ) {
130
119
$ recipients [$ recipient ->email ] = $ recipient ->name ;
131
120
}
132
121
}
@@ -138,10 +127,8 @@ public function convertOrderRows($rows)
138
127
{
139
128
$ results = array ();
140
129
141
- foreach ($ rows as $ row )
142
- {
143
- if (!array_key_exists ($ row ->container_number , $ results ))
144
- {
130
+ foreach ($ rows as $ row ) {
131
+ if (!array_key_exists ($ row ->container_number , $ results )) {
145
132
$ results [$ row ->container_number ] = array (
146
133
'id ' => $ row ->container_id ,
147
134
'name ' => $ row ->container_name ,
@@ -151,8 +138,7 @@ public function convertOrderRows($rows)
151
138
);
152
139
}
153
140
154
- if (!array_key_exists ($ row ->part_id , $ results [$ row ->container_number ]['parts ' ]))
155
- {
141
+ if (!array_key_exists ($ row ->part_id , $ results [$ row ->container_number ]['parts ' ])) {
156
142
$ results [$ row ->container_number ]['parts ' ][$ row ->part_id ] = array (
157
143
'id ' => $ row ->part_id ,
158
144
'name ' => $ row ->part_name ,
@@ -161,8 +147,7 @@ public function convertOrderRows($rows)
161
147
);
162
148
}
163
149
164
- if (!array_key_exists ($ row ->flavour_id , $ results [$ row ->container_number ]['parts ' ][$ row ->part_id ]['flavours ' ]))
165
- {
150
+ if (!array_key_exists ($ row ->flavour_id , $ results [$ row ->container_number ]['parts ' ][$ row ->part_id ]['flavours ' ])) {
166
151
$ results [$ row ->container_number ]['rowspan ' ] += 1 ;
167
152
$ results [$ row ->container_number ]['parts ' ][$ row ->part_id ]['flavours ' ][$ row ->flavour_id ] = array (
168
153
'id ' => $ row ->flavour_id ,
@@ -182,12 +167,11 @@ protected function _getSystemEmailAddresses()
182
167
{
183
168
$ recipients = array ();
184
169
$ query = "SELECT `name`, `email` " .
185
- "FROM `#__users` " .
186
- "WHERE `sendEmail` = '1' " ;
170
+ "FROM `#__users` " .
171
+ "WHERE `sendEmail` = '1' " ;
187
172
$ db = & JFactory::getDBO ();
188
173
$ db ->setQuery ($ query );
189
- if ($ result = $ db ->loadObjectList ())
190
- {
174
+ if ($ result = $ db ->loadObjectList ()) {
191
175
$ recipients = $ result ;
192
176
}
193
177
}
@@ -202,8 +186,7 @@ protected function _getSystemEmailAddresses()
202
186
private function getElementImage ($ elements_type , $ id )
203
187
{
204
188
$ class_name = "PizzaboxModel " . $ elements_type ;
205
- if (!class_exists ($ class_name ))
206
- {
189
+ if (!class_exists ($ class_name )) {
207
190
require_once ( JPATH_COMPONENT_ADMINISTRATOR . '/models/ ' . $ elements_type . '.php ' );
208
191
}
209
192
@@ -212,5 +195,4 @@ private function getElementImage($elements_type, $id)
212
195
$ element = $ model ->getItem ();
213
196
return ( $ element ['row ' ]->image );
214
197
}
215
-
216
198
}
0 commit comments