]>
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 if ( trim($member->email
) != '' && self
::isValidEmail($member->email
) ) {
118 if ( !in_array($member, $this->_mrecipients
) ) {
119 $this->_mrecipients
[] = $member;
121 $m[$member->email
] = $member->sname
;
123 if ( !in_array($member, $this->_unreachables
) ) {
124 $this->_unreachables
[] = $member;
128 parent
::setRecipients($m);
132 * Global getter method
134 * @param string $name name of the property we want to retrive
136 * @return false|object the called property
138 public function __get($name)
141 $forbidden = array('ordered');
142 if ( !in_array($name, $forbidden) ) {
145 return $this->cleanedHtml();
148 return $this->current_step
;
151 return $this->getSubject();
154 return $this->getMessage();
157 return $this->isHTML();
161 return $this->getPhpMailer();
164 return $this->getErrors();
167 return $this->_mrecipients
;
170 $rname = '_' . $name;
172 '[' . get_class($this) . 'Trying to get ' . $name .
173 ' renamed: ' . $rname,
176 return $this->$rname;
181 '[' . get_class($this) . 'Unable to get ' . $name .
182 ' renamed: ' . $rname,
190 * Global setter method
192 * @param string $name name of the property we want to assign a value to
193 * @param object $value a relevant value for the property
197 public function __set($name, $value)
200 $rname = '_' . $name;
204 $this->setSubject($value);
207 $this->setMessage($value);
210 if ( is_bool($value) ) {
211 $this->isHTML($value);
214 '[' . get_class($this) . '] Value for field `' . $name .
215 '` should be boolean - (' . gettype($value) . ')' .
221 /** FIXME: remove... should no longer exists with phpMailer */
223 $this->$rname = (get_magic_quotes_gpc())
224 ? stripslashes($value)
229 && ( $value == self
::STEP_START
230 ||
$value == self
::STEP_PREVIEW
231 ||
$value == self
::STEP_SEND
232 ||
$value == self
::STEP_SENT
)
234 $this->_current_step
= (int)$value;
237 '[' . get_class($this) . '] Value for field `' . $name .
238 '` should be integer and know - (' . gettype($value) . ')' .
246 '[' . get_class($this) . '] Unable to set proprety `' . $name . '`',