3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 class CRM_Core_BAO_MailSettings
extends CRM_Core_DAO_MailSettings
{
40 public function __construct() {
41 parent
::__construct();
45 * Return the DAO object containing to the default row of
46 * civicrm_mail_settings and cache it for further calls
50 * @return CRM_Core_BAO_MailSettings
51 * DAO with the default mail settings set
53 public static function defaultDAO($reset = FALSE) {
54 static $mailSettings = array();
55 $domainID = CRM_Core_Config
::domainID();
56 if (empty($mailSettings[$domainID]) ||
$reset) {
59 $dao->domain_id
= $domainID;
61 $mailSettings[$domainID] = $dao;
63 return $mailSettings[$domainID];
67 * Return the domain from the default set of settings.
72 public static function defaultDomain() {
73 return self
::defaultDAO()->domain
;
77 * Return the localpart from the default set of settings.
82 public static function defaultLocalpart() {
83 return self
::defaultDAO()->localpart
;
87 * Return the return path from the default set of settings.
92 public static function defaultReturnPath() {
93 return self
::defaultDAO()->return_path
;
97 * Return the "include message ID" flag from the default set of settings.
100 * default include message ID
102 public static function includeMessageId() {
103 return CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
,
104 'include_message_id',
111 * Retrieve DB object based on input parameters.
113 * It also stores all the retrieved values in the default array.
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.
120 * @return CRM_Core_BAO_MailSettings
122 public static function retrieve(&$params, &$defaults) {
123 $mailSettings = new CRM_Core_DAO_MailSettings();
124 $mailSettings->copyValues($params);
127 if ($mailSettings->find(TRUE)) {
128 CRM_Core_DAO
::storeValues($mailSettings, $defaults);
129 $result = $mailSettings;
136 * Add new mail Settings.
138 * @param array $params
139 * Reference array contains the values submitted by the form.
144 public static function add(&$params) {
146 if (empty($params)) {
150 if (empty($params['id'])) {
151 $params['is_ssl'] = CRM_Utils_Array
::value('is_ssl', $params, FALSE);
152 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
156 if (!empty($params['is_default'])) {
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);
162 $mailSettings = new CRM_Core_DAO_MailSettings();
163 $mailSettings->copyValues($params);
164 $result = $mailSettings->save();
170 * Takes an associative array and creates a mail settings object.
172 * @param array $params
173 * (reference ) an assoc array of name/value pairs.
175 * @return CRM_Core_BAO_MailSettings
177 public static function create(&$params) {
178 $transaction = new CRM_Core_Transaction();
180 $mailSettings = self
::add($params);
181 if (is_a($mailSettings, 'CRM_Core_Error')) {
182 $mailSettings->rollback();
183 return $mailSettings;
186 $transaction->commit();
187 CRM_Core_BAO_MailSettings
::defaultDAO(TRUE);
188 return $mailSettings;
192 * Delete the mail settings.
199 public static function deleteMailSettings($id) {
201 $transaction = new CRM_Core_Transaction();
203 $mailSettings = new CRM_Core_DAO_MailSettings();
204 $mailSettings->id
= $id;
205 $results = $mailSettings->delete();
207 $transaction->commit();