3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 class CRM_Core_BAO_MailSettings
extends CRM_Core_DAO_MailSettings
{
24 public function __construct() {
25 parent
::__construct();
29 * Return the DAO object containing to the default row of
30 * civicrm_mail_settings and cache it for further calls
34 * @return CRM_Core_BAO_MailSettings
35 * DAO with the default mail settings set
37 public static function defaultDAO($reset = FALSE) {
38 static $mailSettings = [];
39 $domainID = CRM_Core_Config
::domainID();
40 if (empty($mailSettings[$domainID]) ||
$reset) {
43 $dao->domain_id
= $domainID;
45 $mailSettings[$domainID] = $dao;
47 return $mailSettings[$domainID];
51 * Return the domain from the default set of settings.
56 public static function defaultDomain() {
57 return self
::defaultDAO()->domain
;
61 * Return the localpart from the default set of settings.
66 public static function defaultLocalpart() {
67 return self
::defaultDAO()->localpart
;
71 * Return the return path from the default set of settings.
76 public static function defaultReturnPath() {
77 return self
::defaultDAO()->return_path
;
81 * Return the "include message ID" flag from the default set of settings.
84 * default include message ID
86 public static function includeMessageId() {
87 return Civi
::settings()->get('include_message_id');
91 * Retrieve DB object based on input parameters.
93 * It also stores all the retrieved values in the default array.
95 * @param array $params
96 * (reference ) an assoc array of name/value pairs.
97 * @param array $defaults
98 * (reference ) an assoc array to hold the flattened values.
100 * @return CRM_Core_BAO_MailSettings
102 public static function retrieve(&$params, &$defaults) {
103 $mailSettings = new CRM_Core_DAO_MailSettings();
104 $mailSettings->copyValues($params);
107 if ($mailSettings->find(TRUE)) {
108 CRM_Core_DAO
::storeValues($mailSettings, $defaults);
109 $result = $mailSettings;
116 * Add new mail Settings.
118 * @param array $params
119 * Reference array contains the values submitted by the form.
124 public static function add(&$params) {
126 if (empty($params)) {
130 if (empty($params['id'])) {
131 $params['is_ssl'] = CRM_Utils_Array
::value('is_ssl', $params, FALSE);
132 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
136 if (!empty($params['is_default'])) {
137 $query = 'UPDATE civicrm_mail_settings SET is_default = 0 WHERE domain_id = %1';
138 $queryParams = [1 => [CRM_Core_Config
::domainID(), 'Integer']];
139 CRM_Core_DAO
::executeQuery($query, $queryParams);
142 $mailSettings = new CRM_Core_DAO_MailSettings();
143 $mailSettings->copyValues($params);
144 $result = $mailSettings->save();
150 * Takes an associative array and creates a mail settings object.
152 * @param array $params
153 * (reference ) an assoc array of name/value pairs.
155 * @return CRM_Core_BAO_MailSettings
157 public static function create(&$params) {
158 $transaction = new CRM_Core_Transaction();
160 $mailSettings = self
::add($params);
161 if (is_a($mailSettings, 'CRM_Core_Error')) {
162 $mailSettings->rollback();
163 return $mailSettings;
166 $transaction->commit();
167 CRM_Core_BAO_MailSettings
::defaultDAO(TRUE);
168 return $mailSettings;
172 * Delete the mail settings.
179 public static function deleteMailSettings($id) {
181 $transaction = new CRM_Core_Transaction();
183 $mailSettings = new CRM_Core_DAO_MailSettings();
184 $mailSettings->id
= $id;
185 $results = $mailSettings->delete();
187 $transaction->commit();