]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Core/Mailing.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2009-2012 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2009-2012 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.7dev - 2009-03-07
38 namespace Galette\Core
;
40 use Galette\Common\KLogger
as KLogger
;
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2009-2012 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
52 * @since Available since 0.7dev - 2009-03-07
54 class Mailing
extends GaletteMail
57 const STEP_PREVIEW
= 1;
61 const MIME_HTML
= 'text/html';
62 const MIME_TEXT
= 'text/plain';
63 const MIME_DEFAULT
= self
::MIME_TEXT
;
65 private $_unreachables;
66 private $_mrecipients;
67 private $_current_step;
74 * @param array $members An array of members
76 public function __construct($members)
78 $this->_current_step
= self
::STEP_START
;
79 $this->_mime_type
= self
::MIME_DEFAULT
;
80 /** TODO: add a preference that propose default mime-type to use,
82 if ( $members !== null) {
83 //Check which members have a valid email adress and which have not
84 $this->setRecipients($members);
89 * Apply final header to mail and send it :-)
91 * @return GaletteMail::MAIL_ERROR|GaletteMail::MAIL_SENT
93 public function send()
96 foreach ( $this->_mrecipients
as $member ) {
97 $m[$member->email
] = $member->sname
;
99 parent
::setRecipients($m);
100 return parent
::send();
104 * Set mailing recipients
106 * @param <type> $members Array of Adherent objects
110 public function setRecipients($members)
113 $this->_mrecipients
= array();
114 $this->_unreachables
= array();
116 foreach ($members as $member) {
117 $email = $member->email
;
118 if ( trim($email) != '' && self
::isValidEmail($email) ) {
119 if ( !in_array($member, $this->_mrecipients
) ) {
120 $this->_mrecipients
[] = $member;
122 $m[$email] = $member->sname
;
124 if ( !in_array($member, $this->_unreachables
) ) {
125 $this->_unreachables
[] = $member;
129 parent
::setRecipients($m);
133 * Global getter method
135 * @param string $name name of the property we want to retrive
137 * @return false|object the called property
139 public function __get($name)
142 $forbidden = array('ordered');
143 if ( !in_array($name, $forbidden) ) {
146 return $this->cleanedHtml();
149 return $this->current_step
;
152 return $this->getSubject();
155 return $this->getMessage();
158 return $this->isHTML();
162 return $this->getPhpMailer();
165 return $this->getErrors();
168 return $this->_mrecipients
;
171 $rname = '_' . $name;
173 '[' . get_class($this) . 'Trying to get ' . $name .
174 ' renamed: ' . $rname,
177 return $this->$rname;
182 '[' . get_class($this) . 'Unable to get ' . $name .
183 ' renamed: ' . $rname,
191 * Global setter method
193 * @param string $name name of the property we want to assign a value to
194 * @param object $value a relevant value for the property
198 public function __set($name, $value)
201 $rname = '_' . $name;
205 $this->setSubject($value);
208 $this->setMessage($value);
211 if ( is_bool($value) ) {
212 $this->isHTML($value);
215 '[' . get_class($this) . '] Value for field `' . $name .
216 '` should be boolean - (' . gettype($value) . ')' .
222 /** FIXME: remove... should no longer exists with phpMailer */
224 $this->$rname = (get_magic_quotes_gpc())
225 ? stripslashes($value)
230 && ( $value == self
::STEP_START
231 ||
$value == self
::STEP_PREVIEW
232 ||
$value == self
::STEP_SEND
233 ||
$value == self
::STEP_SENT
)
235 $this->_current_step
= (int)$value;
238 '[' . get_class($this) . '] Value for field `' . $name .
239 '` should be integer and know - (' . gettype($value) . ')' .
247 '[' . get_class($this) . '] Unable to set proprety `' . $name . '`',