CRM-12965 more cleanup and fixes
[civicrm-core.git] / CRM / Badge / BAO / Layout.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id$
33 *
34 */
35 class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel {
36
37 /**
38 * class constructor
39 */
40 function __construct() {
41 parent::__construct();
42 }
43
44 /**
45 * Takes a bunch of params that are needed to match certain criteria and
46 * retrieves the relevant objects. It also stores all the retrieved
47 * values in the default array
48 *
49 * @param array $params (reference ) an assoc array of name/value pairs
50 * @param array $defaults (reference ) an assoc array to hold the flattened values
51 *
52 * @return object CRM_Core_DAO_PrintLabel object on success, null otherwise
53 * @access public
54 * @static
55 */
56 static function retrieve(&$params, &$defaults) {
57 $printLabel = new CRM_Core_DAO_PrintLabel();
58 $printLabel->copyValues($params);
59 if ($printLabel->find(TRUE)) {
60 CRM_Core_DAO::storeValues($printLabel, $defaults);
61 return $printLabel;
62 }
63 return NULL;
64 }
65
66 /**
67 * update the is_active flag in the db
68 *
69 * @param int $id id of the database record
70 * @param boolean $is_active value we want to set the is_active field
71 *
72 * @return Object DAO object on success, null otherwise
73 *
74 * @access public
75 * @static
76 */
77 static function setIsActive($id, $is_active) {
78 return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_PrintLabel', $id, 'is_active', $is_active);
79 }
80
81 /**
82 * Function to add a name label
83 *
84 * @param array $params reference array contains the values submitted by the form
85 * @param array $ids reference array contains the id
86 *
87 * @access public
88 * @static
89 *
90 * @return object
91 */
92 static function create(&$params) {
93 $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
94 $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
95 $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
96
97 // action is taken depending upon the mode
98 $printLabel = new CRM_Core_DAO_PrintLabel();
99 $printLabel->copyValues($params);
100
101 if ($params['is_default']) {
102 $query = "UPDATE civicrm_print_label SET is_default = 0";
103 CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
104 }
105
106 $printLabel->save();
107 return $printLabel;
108 }
109
110 /**
111 * Function to delete name labels
112 *
113 * @param int $printLabelId ID of the name label to be deleted.
114 *
115 * @access public
116 * @static
117 */
118 static function del($printLabelId) {
119 $printLabel = new CRM_Core_DAO_PrintLabel();
120 $printLabel->id = $printLabelId;
121 $printLabel->delete();
122 }
123 }
124