Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
34cd78e1 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
34cd78e1 | 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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
34cd78e1 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | ||
37 | require_once 'CRM/Auction/DAO/Auction.php'; | |
38 | class CRM_Auction_BAO_Item extends CRM_Auction_DAO_Auction { | |
39 | ||
40 | /** | |
41 | * class constructor | |
42 | */ | |
43 | function __construct() { | |
44 | parent::__construct(); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Takes a bunch of params that are needed to match certain criteria and | |
49 | * retrieves the relevant objects. Typically the valid params are only | |
50 | * contact_id. We'll tweak this function to be more full featured over a period | |
51 | * of time. This is the inverse function of create. It also stores all the retrieved | |
52 | * values in the default array | |
53 | * | |
54 | * @param array $params (reference ) an assoc array of name/value pairs | |
55 | * @param array $defaults (reference ) an assoc array to hold the flattened values | |
56 | * | |
57 | * @return object CRM_Auction_BAO_Item object | |
58 | * @access public | |
59 | * @static | |
60 | */ | |
61 | static | |
62 | function retrieve(&$params, &$defaults) { | |
63 | $auction = new CRM_Auction_DAO_Item(); | |
64 | $auction->copyValues($params); | |
65 | if ($auction->find(TRUE)) { | |
66 | CRM_Core_DAO::storeValues($auction, $defaults); | |
67 | return $auction; | |
68 | } | |
69 | return NULL; | |
70 | } | |
71 | ||
72 | /** | |
73 | * update the is_active flag in the db | |
74 | * | |
75 | * @param int $id id of the database record | |
76 | * @param boolean $is_active value we want to set the is_active field | |
77 | * | |
78 | * @return Object DAO object on sucess, null otherwise | |
79 | * @static | |
80 | */ | |
81 | static | |
82 | function setIsActive($id, $is_active) { | |
83 | return CRM_Core_DAO::setFieldValue('CRM_Auction_DAO_Item', $id, 'is_active', $is_active); | |
84 | } | |
85 | ||
86 | /** | |
87 | * function to add the auction | |
88 | * | |
89 | * @param array $params reference array contains the values submitted by the form | |
90 | * | |
91 | * @access public | |
92 | * @static | |
93 | * | |
94 | * @return object | |
95 | */ | |
96 | static | |
97 | function add(&$params) { | |
98 | require_once 'CRM/Utils/Hook.php'; | |
99 | ||
a7488080 | 100 | if (!empty($params['id'])) { |
6a488035 TO |
101 | CRM_Utils_Hook::pre('edit', 'Auction_Item', $params['id'], $params); |
102 | } | |
103 | else { | |
104 | CRM_Utils_Hook::pre('create', 'Auction_Item', NULL, $params); | |
105 | } | |
106 | ||
107 | $auction = new CRM_Auction_DAO_Item(); | |
108 | ||
109 | $auction->copyValues($params); | |
110 | $auction->save(); | |
111 | ||
112 | // add attachments as needed | |
113 | CRM_Core_BAO_File::formatAttachment($params, | |
114 | $params, | |
115 | 'civicrm_auction_item', | |
116 | $auction->id | |
117 | ); | |
118 | // add attachments as needed | |
119 | CRM_Core_BAO_File::processAttachment($params, | |
120 | 'civicrm_auction_item', | |
121 | $auction->id | |
122 | ); | |
123 | ||
a7488080 | 124 | if (!empty($params['id'])) { |
6a488035 TO |
125 | CRM_Utils_Hook::post('edit', 'Auction_Item', $auction->id, $auction); |
126 | } | |
127 | else { | |
128 | CRM_Utils_Hook::post('create', 'Auction_Item', $auction->id, $auction); | |
129 | } | |
130 | ||
131 | return $result; | |
132 | } | |
133 | ||
134 | /** | |
135 | * function to create the auction | |
136 | * | |
137 | * @param array $params reference array contains the values submitted by the form | |
138 | * | |
139 | * @access public | |
140 | * @static | |
141 | * | |
142 | */ | |
143 | public static function create(&$params) { | |
144 | require_once 'CRM/Core/Transaction.php'; | |
145 | $transaction = new CRM_Core_Transaction(); | |
146 | ||
147 | $auction = self::add($params); | |
148 | ||
149 | if (is_a($auction, 'CRM_Core_Error')) { | |
150 | CRM_Core_DAO::transaction('ROLLBACK'); | |
151 | return $auction; | |
152 | } | |
153 | ||
154 | $transaction->commit(); | |
155 | ||
156 | return $auction; | |
157 | } | |
158 | ||
159 | /** | |
160 | * Function to delete the auction | |
161 | * | |
162 | * @param int $id auction id | |
163 | * | |
164 | * @access public | |
165 | * @static | |
166 | * | |
167 | */ | |
168 | static | |
169 | function del($id) { | |
170 | require_once 'CRM/Auction/DAO/Item.php'; | |
171 | $auction = new CRM_Auction_DAO_Item(); | |
172 | $auction->id = $id; | |
173 | $result = $auction->delete(); | |
174 | return $result; | |
175 | } | |
176 | ||
177 | /** | |
178 | * Function to check if email is enabled for a given profile | |
179 | * | |
180 | * @param int $id profile id | |
181 | * | |
182 | * @return boolean | |
183 | * @access public | |
184 | * @static | |
185 | * | |
186 | */ | |
187 | static | |
188 | function isEmailInProfile($profileId) { | |
189 | $query = " | |
190 | SELECT field_name | |
191 | FROM civicrm_uf_field | |
192 | WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1"; | |
193 | ||
194 | $params = array(1 => array($profileId, 'Integer')); | |
195 | $dao = CRM_Core_DAO::executeQuery($query, $params); | |
196 | if (!$dao->fetch()) { | |
197 | return TRUE; | |
198 | } | |
199 | return FALSE; | |
200 | } | |
201 | } | |
202 |