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
{
22 public function __construct() {
23 parent
::__construct();
27 * Retrieve DB object based on input parameters.
29 * It also stores all the retrieved values in the default array.
31 * @param array $params
32 * (reference ) an assoc array of name/value pairs.
33 * @param array $defaults
34 * (reference ) an assoc array to hold the flattened values.
36 * @return CRM_Core_DAO_PrintLabel|null
37 * object on success, null otherwise
39 public static function retrieve(&$params, &$defaults) {
40 $printLabel = new CRM_Core_DAO_PrintLabel();
41 $printLabel->copyValues($params);
42 if ($printLabel->find(TRUE)) {
43 CRM_Core_DAO
::storeValues($printLabel, $defaults);
50 * Update the is_active flag in the db.
53 * Id of the database record.
54 * @param bool $is_active
55 * Value we want to set the is_active field.
58 * true if we found and updated the object, else false
60 public static function setIsActive($id, $is_active) {
61 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_PrintLabel', $id, 'is_active', $is_active);
67 * @param array $params
68 * Reference array contains the values submitted by the form.
73 public static function create(&$params) {
74 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
75 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
76 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
78 $params['label_type_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Core_DAO_PrintLabel', 'label_type_id', 'Event Badge');
80 // check if new layout is create, if so set the created_id (if not set)
81 if (empty($params['id'])) {
82 if (empty($params['created_id'])) {
83 $session = CRM_Core_Session
::singleton();
84 $params['created_id'] = $session->get('userID');
88 if (!isset($params['id']) && !isset($params['name'])) {
89 $params['name'] = CRM_Utils_String
::munge($params['title'], '_', 64);
92 // action is taken depending upon the mode
93 $printLabel = new CRM_Core_DAO_PrintLabel();
94 $printLabel->copyValues($params);
96 if ($params['is_default']) {
97 $query = "UPDATE civicrm_print_label SET is_default = 0";
98 CRM_Core_DAO
::executeQuery($query);
106 * Delete name labels.
108 * @param int $printLabelId
111 public static function del($printLabelId) {
112 self
::deleteRecord(['id' => $printLabelId]);
116 * get the list of print labels.
121 public static function getList() {
122 $printLabel = new CRM_Core_DAO_PrintLabel();
126 while ($printLabel->fetch()) {
127 $labels[$printLabel->id
] = $printLabel->title
;
133 * Build layout structure.
135 * @param array $params
136 * Associated array of submitted values.
139 * array formatted array
141 public static function buildLayout(&$params) {
142 $layoutParams = ['id' => $params['badge_id']];
143 CRM_Badge_BAO_Layout
::retrieve($layoutParams, $layoutInfo);
145 $formatProperties = CRM_Core_PseudoConstant
::getKey('CRM_Core_DAO_PrintLabel', 'label_format_name', $layoutInfo['label_format_name']);
147 $layoutInfo['format'] = json_decode($formatProperties, TRUE);
148 $layoutInfo['data'] = CRM_Badge_BAO_Layout
::getDecodedData($layoutInfo['data']);
153 * Decode encoded data and return as an array.
155 * @param json $jsonData
159 * associated array of decoded elements
161 public static function getDecodedData($jsonData) {
162 return json_decode($jsonData, TRUE);