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 based on input parameters.
22 * It also stores all the retrieved values in the default array.
24 * @param array $params
25 * (reference ) an assoc array of name/value pairs.
26 * @param array $defaults
27 * (reference ) an assoc array to hold the flattened values.
29 * @return CRM_Core_DAO_PrintLabel|null
30 * object on success, null otherwise
32 public static function retrieve(&$params, &$defaults) {
33 $printLabel = new CRM_Core_DAO_PrintLabel();
34 $printLabel->copyValues($params);
35 if ($printLabel->find(TRUE)) {
36 CRM_Core_DAO
::storeValues($printLabel, $defaults);
43 * Update the is_active flag in the db.
46 * Id of the database record.
47 * @param bool $is_active
48 * Value we want to set the is_active field.
51 * true if we found and updated the object, else false
53 public static function setIsActive($id, $is_active) {
54 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_PrintLabel', $id, 'is_active', $is_active);
60 * @param array $params
61 * Reference array contains the values submitted by the form.
66 public static function create(&$params) {
67 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
68 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
69 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
71 $params['label_type_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Core_DAO_PrintLabel', 'label_type_id', 'Event Badge');
73 // check if new layout is create, if so set the created_id (if not set)
74 if (empty($params['id'])) {
75 if (empty($params['created_id'])) {
76 $session = CRM_Core_Session
::singleton();
77 $params['created_id'] = $session->get('userID');
81 if (!isset($params['id']) && !isset($params['name'])) {
82 $params['name'] = CRM_Utils_String
::munge($params['title'], '_', 64);
85 // action is taken depending upon the mode
86 $printLabel = new CRM_Core_DAO_PrintLabel();
87 $printLabel->copyValues($params);
89 if ($params['is_default']) {
90 $query = "UPDATE civicrm_print_label SET is_default = 0";
91 CRM_Core_DAO
::executeQuery($query);
101 * @param int $printLabelId
104 public static function del($printLabelId) {
105 self
::deleteRecord(['id' => $printLabelId]);
109 * get the list of print labels.
114 public static function getList() {
115 $printLabel = new CRM_Core_DAO_PrintLabel();
119 while ($printLabel->fetch()) {
120 $labels[$printLabel->id
] = $printLabel->title
;
126 * Build layout structure.
128 * @param array $params
129 * Associated array of submitted values.
132 * array formatted array
134 public static function buildLayout(&$params) {
135 $layoutParams = ['id' => $params['badge_id']];
136 CRM_Badge_BAO_Layout
::retrieve($layoutParams, $layoutInfo);
138 $formatProperties = CRM_Core_PseudoConstant
::getKey('CRM_Core_DAO_PrintLabel', 'label_format_name', $layoutInfo['label_format_name']);
140 $layoutInfo['format'] = json_decode($formatProperties, TRUE);
141 $layoutInfo['data'] = CRM_Badge_BAO_Layout
::getDecodedData($layoutInfo['data']);
146 * Decode encoded data and return as an array.
148 * @param json $jsonData
152 * associated array of decoded elements
154 public static function getDecodedData($jsonData) {
155 return json_decode($jsonData, TRUE);