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
17 class CRM_Core_BAO_MailSettings
extends CRM_Core_DAO_MailSettings
{
20 * Get a list of setup-actions.
23 * List of available actions. See description in the hook-docs.
24 * @see CRM_Utils_Hook::mailSetupActions()
26 public static function getSetupActions() {
28 $setupActions['standard'] = [
29 'title' => ts('Standard Mail Account'),
30 'callback' => ['CRM_Core_BAO_MailSettings', 'setupStandardAccount'],
33 CRM_Utils_Hook
::mailSetupActions($setupActions);
37 public static function setupStandardAccount($setupAction) {
39 'url' => CRM_Utils_System
::url('civicrm/admin/mailSettings', 'action=add&reset=1', TRUE, NULL, FALSE),
44 * Return the DAO object containing to the default row of
45 * civicrm_mail_settings and cache it for further calls
49 * @return CRM_Core_BAO_MailSettings
50 * DAO with the default mail settings set
52 public static function defaultDAO($reset = FALSE) {
53 static $mailSettings = [];
54 $domainID = CRM_Core_Config
::domainID();
55 if (empty($mailSettings[$domainID]) ||
$reset) {
58 $dao->domain_id
= $domainID;
60 $mailSettings[$domainID] = $dao;
62 return $mailSettings[$domainID];
66 * Return the domain from the default set of settings.
71 public static function defaultDomain() {
72 return self
::defaultDAO()->domain
;
76 * Return the localpart from the default set of settings.
81 public static function defaultLocalpart() {
82 return self
::defaultDAO()->localpart
;
86 * Return the return path from the default set of settings.
91 public static function defaultReturnPath() {
92 return self
::defaultDAO()->return_path
;
96 * Return the "include message ID" flag from the default set of settings.
99 * default include message ID
101 public static function includeMessageId() {
102 return Civi
::settings()->get('include_message_id');
106 * Retrieve DB object based on input parameters.
108 * It also stores all the retrieved values in the default array.
110 * @param array $params
111 * (reference ) an assoc array of name/value pairs.
112 * @param array $defaults
113 * (reference ) an assoc array to hold the flattened values.
115 * @return CRM_Core_BAO_MailSettings
117 public static function retrieve(&$params, &$defaults) {
118 $mailSettings = new CRM_Core_DAO_MailSettings();
119 $mailSettings->copyValues($params);
122 if ($mailSettings->find(TRUE)) {
123 CRM_Core_DAO
::storeValues($mailSettings, $defaults);
124 $result = $mailSettings;
131 * Add new mail Settings.
133 * @param array $params
134 * Reference array contains the values submitted by the form.
137 * @return CRM_Core_DAO_MailSettings
139 public static function add(&$params) {
141 if (empty($params)) {
145 if (empty($params['id'])) {
146 $params['is_ssl'] = CRM_Utils_Array
::value('is_ssl', $params, FALSE);
147 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
151 if (!empty($params['is_default'])) {
152 $query = 'UPDATE civicrm_mail_settings SET is_default = 0 WHERE domain_id = %1';
153 $queryParams = [1 => [CRM_Core_Config
::domainID(), 'Integer']];
154 CRM_Core_DAO
::executeQuery($query, $queryParams);
157 $mailSettings = new CRM_Core_DAO_MailSettings();
158 $mailSettings->copyValues($params);
159 $result = $mailSettings->save();
165 * Takes an associative array and creates a mail settings object.
167 * @param array $params
168 * (reference ) an assoc array of name/value pairs.
170 * @return CRM_Core_DAO_MailSettings|CRM_Core_Error
172 public static function create(&$params) {
173 $transaction = new CRM_Core_Transaction();
175 $mailSettings = self
::add($params);
176 if (is_a($mailSettings, 'CRM_Core_Error')) {
177 $mailSettings->rollback();
178 return $mailSettings;
181 $transaction->commit();
182 CRM_Core_BAO_MailSettings
::defaultDAO(TRUE);
183 return $mailSettings;
187 * Delete the mail settings.
194 public static function deleteMailSettings($id) {
196 $transaction = new CRM_Core_Transaction();
198 $mailSettings = new CRM_Core_DAO_MailSettings();
199 $mailSettings->id
= $id;
200 $results = $mailSettings->delete();
202 $transaction->commit();