adding non-working api structure and indentation fixes
[civicrm-core.git] / CRM / Mailing / BAO / MailingAB.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * Class CRM_Mailing_BAO_MailingAB
38 */
39 class CRM_Mailing_BAO_MailingAB extends CRM_Mailing_DAO_MailingAB {
40
41 /**
42 * class constructor
43 */
44 function __construct() {
45 parent::__construct();
46 }
47
48 /**
49 * Construct a new mailingab object
50 *
51 * @params array $params Form values
52 *
53 * @param $params
54 * @param array $ids
55 *
56 * @return object $mailingab The new mailingab object
57 * @access public
58 * @static
59 */
60 public static function create(&$params, $ids = array()) {
61 $transaction = new CRM_Core_Transaction();
62
63 $mailingab = self::add($params, $ids);
64
65 if (is_a($mailingab, 'CRM_Core_Error')) {
66 $transaction->rollback();
67 return $mailingab;
68 }
69 $transaction->commit();
70 }
71
72 /**
73 * function to add the mailings
74 *
75 * @param array $params reference array contains the values submitted by the form
76 * @param array $ids reference array contains the id
77 *
78 * @access public
79 * @static
80 *
81 * @return object
82 */
83 static function add(&$params, $ids = array()) {
84 $id = CRM_Utils_Array::value('mailingab_id', $ids, CRM_Utils_Array::value('id', $params));
85
86 if ($id) {
87 CRM_Utils_Hook::pre('edit', 'MailingAB', $id, $params);
88 }
89 else {
90 CRM_Utils_Hook::pre('create', 'MailingAB', NULL, $params);
91 }
92
93 $mailingab = new CRM_Mailing_DAO_MailingAB();
94 $mailingab->id = $id;
95 $mailingab->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
96
97 $mailingab->copyValues($params);
98
99 $result = $mailingab->save();
100
101 if ($id) {
102 CRM_Utils_Hook::post('edit', 'MailingAB', $mailingab->id, $mailingab);
103 }
104 else {
105 CRM_Utils_Hook::post('create', 'MailingAB', $mailingab->id, $mailingab);
106 }
107
108 return $result;
109 }
110
111
112 /**
113 * Delete MailingAB and all its associated records
114 *
115 * @param int $id id of the mail to delete
116 *
117 * @return void
118 * @access public
119 * @static
120 */
121 public static function del($id) {
122 if (empty($id)) {
123 CRM_Core_Error::fatal();
124 }
125
126 CRM_Utils_Hook::pre('delete', 'MailingAB', $id, CRM_Core_DAO::$_nullArray);
127
128 $dao = new CRM_Mailing_DAO_MailingAB();
129 $dao->id = $id;
130 $dao->delete();
131
132 CRM_Core_Session::setStatus(ts('Selected mailing has been deleted.'), ts('Deleted'), 'success');
133
134 CRM_Utils_Hook::post('delete', 'MailingAB', $id, $dao);
135 }
136
137 }