3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Badge_BAO_Layout
extends CRM_Core_DAO_PrintLabel
{
20 * Retrieve DB object and copy to defaults array.
23 * @param array $params
24 * @param array $defaults
26 * @return CRM_Core_DAO_PrintLabel|NULL
28 public static function retrieve($params, &$defaults) {
29 return self
::commonRetrieve('CRM_Core_DAO_PrintLabel', $params, $defaults);
33 * Update the is_active flag in the db.
36 * Id of the database record.
37 * @param bool $is_active
38 * Value we want to set the is_active field.
41 * true if we found and updated the object, else false
43 public static function setIsActive($id, $is_active) {
44 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_PrintLabel', $id, 'is_active', $is_active);
50 * @param array $params
51 * Reference array contains the values submitted by the form.
56 public static function create(&$params) {
57 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
58 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
59 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
61 $params['label_type_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Core_DAO_PrintLabel', 'label_type_id', 'Event Badge');
63 // check if new layout is create, if so set the created_id (if not set)
64 if (empty($params['id'])) {
65 if (empty($params['created_id'])) {
66 $session = CRM_Core_Session
::singleton();
67 $params['created_id'] = $session->get('userID');
71 if (!isset($params['id']) && !isset($params['name'])) {
72 $params['name'] = CRM_Utils_String
::munge($params['title'], '_', 64);
75 // action is taken depending upon the mode
76 $printLabel = new CRM_Core_DAO_PrintLabel();
77 $printLabel->copyValues($params);
79 if ($params['is_default']) {
80 $query = "UPDATE civicrm_print_label SET is_default = 0";
81 CRM_Core_DAO
::executeQuery($query);
91 * @param int $printLabelId
94 public static function del($printLabelId) {
95 self
::deleteRecord(['id' => $printLabelId]);
99 * get the list of print labels.
104 public static function getList() {
105 $printLabel = new CRM_Core_DAO_PrintLabel();
109 while ($printLabel->fetch()) {
110 $labels[$printLabel->id
] = $printLabel->title
;
116 * Build layout structure.
118 * @param array $params
119 * Associated array of submitted values.
122 * array formatted array
124 public static function buildLayout(&$params) {
125 $layoutParams = ['id' => $params['badge_id']];
126 CRM_Badge_BAO_Layout
::retrieve($layoutParams, $layoutInfo);
128 $formatProperties = CRM_Core_PseudoConstant
::getKey('CRM_Core_DAO_PrintLabel', 'label_format_name', $layoutInfo['label_format_name']);
130 $layoutInfo['format'] = json_decode($formatProperties, TRUE);
131 $layoutInfo['data'] = CRM_Badge_BAO_Layout
::getDecodedData($layoutInfo['data']);
136 * Decode encoded data and return as an array.
138 * @param string $jsonData
142 * associated array of decoded elements
144 public static function getDecodedData($jsonData) {
145 return json_decode($jsonData, TRUE);