3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Business objects for managing price fields values.
40 class CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue
extends CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue
{
43 * Insert/update a new entry in the database.
45 * @param array $params
46 * (reference), array $ids.
50 * @return CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue object
53 public static function &add(&$params, $ids) {
55 $fieldValueBAO = new CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue();
56 $fieldValueBAO->copyValues($params);
58 if ($id = CRM_Utils_Array
::value('id', $ids)) {
59 $fieldValueBAO->id
= $id;
61 if (!empty($params['is_default'])) {
62 $query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE price_field_id = %1';
63 $p = array(1 => array($params['price_field_id'], 'Integer'));
64 CRM_Core_DAO
::executeQuery($query, $p);
67 $fieldValueBAO->save();
68 return $fieldValueBAO;
72 * Creates a new entry in the database.
74 * @param array $params
75 * (reference), array $ids.
79 * @return CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue object
82 public static function create(&$params, $ids) {
84 if (!is_array($params) ||
empty($params)) {
88 if ($id = CRM_Utils_Array
::value('id', $ids)) {
89 if (isset($params['name'])) {
90 unset($params['name']);
95 $oldWeight = CRM_Core_DAO
::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', $id, 'weight', 'id');
98 $fieldValues = array('price_field_id' => CRM_Utils_Array
::value('price_field_id', $params, 0));
99 $params['weight'] = CRM_Utils_Weight
::updateOtherWeights('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', $oldWeight, $params['weight'], $fieldValues);
102 if (empty($params['name'])) {
103 $params['name'] = CRM_Utils_String
::munge(CRM_Utils_Array
::value('label', $params), '_', 64);
105 if (empty($params['weight'])) {
106 $params['weight'] = 1;
109 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, 0);
111 return self
::add($params, $ids);
115 * Takes a bunch of params that are needed to match certain criteria and
116 * retrieves the relevant objects.
118 * @param array $params
119 * (reference ) an assoc array.
120 * @param array $defaults
121 * (reference ) an assoc array to hold the flattened values.
123 * @return CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue object
126 public static function retrieve(&$params, &$defaults) {
127 return CRM_Core_DAO
::commonRetrieve('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', $params, $defaults);
131 * Retrive the all values for given field id
133 * @param int $fieldId
135 * @param array $values
136 * (reference ) to hold the values.
137 * @param string $orderBy
138 * For order by, default weight.
139 * @param bool|int $isActive is_active, default false
141 * @return array $values
145 public static function getValues($fieldId, &$values, $orderBy = 'weight', $isActive = FALSE) {
146 $fieldValueDAO = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue();
147 $fieldValueDAO->price_field_id
= $fieldId;
148 $fieldValueDAO->orderBy($orderBy, 'label');
150 $fieldValueDAO->is_active
= 1;
152 $fieldValueDAO->find();
154 while ($fieldValueDAO->fetch()) {
155 CRM_Core_DAO
::storeValues($fieldValueDAO, $values[$fieldValueDAO->id
]);
162 * Get the price field option label.
165 * Id of field option.
167 * @return string name
172 public static function getOptionLabel($id) {
173 return CRM_Core_DAO
::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', $id, 'label');
177 * Update the is_active flag in the db
180 * Id of the database record.
181 * @param bool $is_active
182 * Value we want to set the is_active field.
184 * @return Object DAO object on sucess, null otherwise
188 public static function setIsActive($id, $is_active) {
189 return CRM_Core_DAO
::setFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', $id, 'is_active', $is_active);
193 * Delete all values of the given field id
195 * @param int $fieldId
202 public static function deleteValues($fieldId) {
207 $fieldValueDAO = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue();
208 $fieldValueDAO->price_field_id
= $fieldId;
209 $fieldValueDAO->delete();
222 public static function del($id) {
227 $fieldValueDAO = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue();
228 $fieldValueDAO->id
= $id;
229 return $fieldValueDAO->delete();