Update copyright date in comments
[civicrm-core.git] / tools / CRM / Auction / BAO / Item.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
32 * $Id$
33 *
34 */
35
36
37 require_once 'CRM/Auction/DAO/Auction.php';
38
39 /**
40 * Class CRM_Auction_BAO_Item
41 */
42 class CRM_Auction_BAO_Item extends CRM_Auction_DAO_Auction {
43
44 /**
45 * class constructor
46 */
47 function __construct() {
48 parent::__construct();
49 }
50
51 /**
52 * Fetch object based on array of properties
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 CRM_Auction_BAO_Item object
58 */
59 static function retrieve(&$params, &$defaults) {
60 $auction = new CRM_Auction_DAO_Item();
61 $auction->copyValues($params);
62 if ($auction->find(TRUE)) {
63 CRM_Core_DAO::storeValues($auction, $defaults);
64 return $auction;
65 }
66 return NULL;
67 }
68
69 /**
70 * update the is_active flag in the db
71 *
72 * @param int $id id of the database record
73 * @param boolean $is_active value we want to set the is_active field
74 *
75 * @return Object DAO object on sucess, null otherwise
76 */
77 static function setIsActive($id, $is_active) {
78 return CRM_Core_DAO::setFieldValue('CRM_Auction_DAO_Item', $id, 'is_active', $is_active);
79 }
80
81 /**
82 * add the auction
83 *
84 * @param array $params reference array contains the values submitted by the form
85 * @return object
86 */
87 static function add(&$params) {
88 if (!empty($params['id'])) {
89 CRM_Utils_Hook::pre('edit', 'Auction_Item', $params['id'], $params);
90 }
91 else {
92 CRM_Utils_Hook::pre('create', 'Auction_Item', NULL, $params);
93 }
94
95 $auction = new CRM_Auction_DAO_Item();
96
97 $auction->copyValues($params);
98 $auction->save();
99
100 // add attachments as needed
101 CRM_Core_BAO_File::formatAttachment($params,
102 $params,
103 'civicrm_auction_item',
104 $auction->id
105 );
106 // add attachments as needed
107 CRM_Core_BAO_File::processAttachment($params,
108 'civicrm_auction_item',
109 $auction->id
110 );
111
112 if (!empty($params['id'])) {
113 CRM_Utils_Hook::post('edit', 'Auction_Item', $auction->id, $auction);
114 }
115 else {
116 CRM_Utils_Hook::post('create', 'Auction_Item', $auction->id, $auction);
117 }
118
119 return $result;
120 }
121
122 /**
123 * create the auction
124 *
125 * @param array $params reference array contains the values submitted by the form
126 *
127 * @return object
128 */
129 public static function create(&$params) {
130 $transaction = new CRM_Core_Transaction();
131
132 $auction = self::add($params);
133
134 if (is_a($auction, 'CRM_Core_Error')) {
135 CRM_Core_DAO::transaction('ROLLBACK');
136 return $auction;
137 }
138
139 $transaction->commit();
140
141 return $auction;
142 }
143
144 /**
145 * delete the auction
146 *
147 * @param int $id auction id
148 */
149 static function del($id) {
150 $auction = new CRM_Auction_DAO_Item();
151 $auction->id = $id;
152 $result = $auction->delete();
153 return $result;
154 }
155
156 /**
157 * Function to check if email is enabled for a given profile
158 *
159 * @param $profileId
160 *
161 * @internal param int $id profile id
162 *
163 * @return boolean
164 */
165 static function isEmailInProfile($profileId) {
166 $query = "
167 SELECT field_name
168 FROM civicrm_uf_field
169 WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1";
170
171 $params = array(1 => array($profileId, 'Integer'));
172 $dao = CRM_Core_DAO::executeQuery($query, $params);
173 if (!$dao->fetch()) {
174 return TRUE;
175 }
176 return FALSE;
177 }
178 }
179