Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Core_BAO_MailSettings extends CRM_Core_DAO_MailSettings { | |
36 | ||
37 | /** | |
fe482240 | 38 | * Class constructor. |
6a488035 | 39 | */ |
00be9182 | 40 | public function __construct() { |
6a488035 TO |
41 | parent::__construct(); |
42 | } | |
43 | ||
44 | /** | |
45 | * Return the DAO object containing to the default row of | |
46 | * civicrm_mail_settings and cache it for further calls | |
47 | * | |
07b3c7ff EM |
48 | * @param bool $reset |
49 | * | |
16b10e64 CW |
50 | * @return CRM_Core_BAO_MailSettings |
51 | * DAO with the default mail settings set | |
6a488035 | 52 | */ |
00be9182 | 53 | public static function defaultDAO($reset = FALSE) { |
07b3c7ff EM |
54 | static $mailSettings = array(); |
55 | $domainID = CRM_Core_Config::domainID(); | |
56 | if (empty($mailSettings[$domainID]) || $reset) { | |
c301f76e | 57 | $dao = new self(); |
6a488035 | 58 | $dao->is_default = 1; |
353ffa53 | 59 | $dao->domain_id = $domainID; |
6a488035 | 60 | $dao->find(TRUE); |
07b3c7ff | 61 | $mailSettings[$domainID] = $dao; |
6a488035 | 62 | } |
07b3c7ff | 63 | return $mailSettings[$domainID]; |
6a488035 TO |
64 | } |
65 | ||
66 | /** | |
fe482240 | 67 | * Return the domain from the default set of settings. |
6a488035 | 68 | * |
a6c01b45 CW |
69 | * @return string |
70 | * default domain | |
6a488035 | 71 | */ |
00be9182 | 72 | public static function defaultDomain() { |
6a488035 TO |
73 | return self::defaultDAO()->domain; |
74 | } | |
75 | ||
76 | /** | |
fe482240 | 77 | * Return the localpart from the default set of settings. |
6a488035 | 78 | * |
a6c01b45 CW |
79 | * @return string |
80 | * default localpart | |
6a488035 | 81 | */ |
00be9182 | 82 | public static function defaultLocalpart() { |
6a488035 TO |
83 | return self::defaultDAO()->localpart; |
84 | } | |
85 | ||
86 | /** | |
fe482240 | 87 | * Return the return path from the default set of settings. |
6a488035 | 88 | * |
a6c01b45 CW |
89 | * @return string |
90 | * default return path | |
6a488035 | 91 | */ |
00be9182 | 92 | public static function defaultReturnPath() { |
6a488035 TO |
93 | return self::defaultDAO()->return_path; |
94 | } | |
95 | ||
96 | /** | |
97 | * Return the "include message ID" flag from the default set of settings. | |
98 | * | |
c301f76e | 99 | * @return bool |
a6c01b45 | 100 | * default include message ID |
6a488035 | 101 | */ |
00be9182 | 102 | public static function includeMessageId() { |
6a488035 TO |
103 | return CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, |
104 | 'include_message_id', | |
105 | NULL, | |
106 | FALSE | |
107 | ); | |
108 | } | |
109 | ||
110 | /** | |
fe482240 EM |
111 | * Retrieve DB object based on input parameters. |
112 | * | |
113 | * It also stores all the retrieved values in the default array. | |
6a488035 | 114 | * |
6a0b768e TO |
115 | * @param array $params |
116 | * (reference ) an assoc array of name/value pairs. | |
117 | * @param array $defaults | |
118 | * (reference ) an assoc array to hold the flattened values. | |
6a488035 | 119 | * |
16b10e64 | 120 | * @return CRM_Core_BAO_MailSettings |
6a488035 | 121 | */ |
00be9182 | 122 | public static function retrieve(&$params, &$defaults) { |
6a488035 TO |
123 | $mailSettings = new CRM_Core_DAO_MailSettings(); |
124 | $mailSettings->copyValues($params); | |
125 | ||
126 | $result = NULL; | |
127 | if ($mailSettings->find(TRUE)) { | |
128 | CRM_Core_DAO::storeValues($mailSettings, $defaults); | |
129 | $result = $mailSettings; | |
130 | } | |
131 | ||
132 | return $result; | |
133 | } | |
134 | ||
135 | /** | |
100fef9d | 136 | * Add new mail Settings. |
6a488035 | 137 | * |
6a0b768e TO |
138 | * @param array $params |
139 | * Reference array contains the values submitted by the form. | |
6a488035 | 140 | * |
6a488035 TO |
141 | * |
142 | * @return object | |
143 | */ | |
00be9182 | 144 | public static function add(&$params) { |
6a488035 TO |
145 | $result = NULL; |
146 | if (empty($params)) { | |
147 | return $result; | |
148 | } | |
149 | ||
22e263ad | 150 | if (empty($params['id'])) { |
e123fef4 EM |
151 | $params['is_ssl'] = CRM_Utils_Array::value('is_ssl', $params, FALSE); |
152 | $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); | |
153 | } | |
6a488035 TO |
154 | |
155 | //handle is_default. | |
e123fef4 | 156 | if (!empty($params['is_default'])) { |
6a488035 TO |
157 | $query = 'UPDATE civicrm_mail_settings SET is_default = 0 WHERE domain_id = %1'; |
158 | $queryParams = array(1 => array(CRM_Core_Config::domainID(), 'Integer')); | |
159 | CRM_Core_DAO::executeQuery($query, $queryParams); | |
160 | } | |
161 | ||
162 | $mailSettings = new CRM_Core_DAO_MailSettings(); | |
163 | $mailSettings->copyValues($params); | |
164 | $result = $mailSettings->save(); | |
165 | ||
166 | return $result; | |
167 | } | |
168 | ||
169 | /** | |
fe482240 | 170 | * Takes an associative array and creates a mail settings object. |
6a488035 | 171 | * |
6a0b768e TO |
172 | * @param array $params |
173 | * (reference ) an assoc array of name/value pairs. | |
6a488035 | 174 | * |
16b10e64 | 175 | * @return CRM_Core_BAO_MailSettings |
6a488035 | 176 | */ |
00be9182 | 177 | public static function create(&$params) { |
6a488035 TO |
178 | $transaction = new CRM_Core_Transaction(); |
179 | ||
180 | $mailSettings = self::add($params); | |
181 | if (is_a($mailSettings, 'CRM_Core_Error')) { | |
182 | $mailSettings->rollback(); | |
183 | return $mailSettings; | |
184 | } | |
185 | ||
186 | $transaction->commit(); | |
e123fef4 | 187 | CRM_Core_BAO_MailSettings::defaultDAO(TRUE); |
6a488035 TO |
188 | return $mailSettings; |
189 | } | |
190 | ||
191 | /** | |
100fef9d | 192 | * Delete the mail settings. |
6a488035 | 193 | * |
6a0b768e TO |
194 | * @param int $id |
195 | * Mail settings id. | |
6a488035 | 196 | * |
77b97be7 | 197 | * @return mixed|null |
6a488035 | 198 | */ |
00be9182 | 199 | public static function deleteMailSettings($id) { |
6a488035 TO |
200 | $results = NULL; |
201 | $transaction = new CRM_Core_Transaction(); | |
202 | ||
353ffa53 | 203 | $mailSettings = new CRM_Core_DAO_MailSettings(); |
6a488035 | 204 | $mailSettings->id = $id; |
353ffa53 | 205 | $results = $mailSettings->delete(); |
6a488035 TO |
206 | |
207 | $transaction->commit(); | |
208 | ||
209 | return $results; | |
210 | } | |
96025800 | 211 | |
6a488035 | 212 | } |