Merge pull request #15322 from alifrumin/removePrintIcon
[civicrm-core.git] / CRM / Core / BAO / Persistent.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 * $Id$
33 *
34 */
35class CRM_Core_BAO_Persistent extends CRM_Core_DAO_Persistent {
36
37 /**
0880a9d0 38 * Fetch object based on array of properties.
6a488035 39 *
6a0b768e
TO
40 * @param array $params
41 * (reference ) an assoc array of name/value pairs.
42 * @param array $defaults
43 * (reference ) an assoc array to hold the flattened values.
6a488035 44 *
16b10e64 45 * @return CRM_Core_BAO_Persistent
6a488035 46 */
00be9182 47 public static function retrieve(&$params, &$defaults) {
6a488035
TO
48 $dao = new CRM_Core_DAO_Persistent();
49 $dao->copyValues($params);
50
51 if ($dao->find(TRUE)) {
52 CRM_Core_DAO::storeValues($dao, $defaults);
53 if (CRM_Utils_Array::value('is_config', $defaults) == 1) {
54 $defaults['data'] = unserialize($defaults['data']);
55 }
56 return $dao;
57 }
58 return NULL;
59 }
60
61 /**
fe482240 62 * Add the Persistent Record.
6a488035 63 *
6a0b768e
TO
64 * @param array $params
65 * Reference array contains the values submitted by the form.
66 * @param array $ids
67 * Reference array contains the id.
6a488035 68 *
6a488035
TO
69 *
70 * @return object
71 */
00be9182 72 public static function add(&$params, &$ids) {
6a488035
TO
73 if (CRM_Utils_Array::value('is_config', $params) == 1) {
74 $params['data'] = serialize(explode(',', $params['data']));
75 }
76 $persistentDAO = new CRM_Core_DAO_Persistent();
77 $persistentDAO->copyValues($params);
78
79 $persistentDAO->id = CRM_Utils_Array::value('persistent', $ids);
80 $persistentDAO->save();
81 return $persistentDAO;
82 }
83
b5c2afd0
EM
84 /**
85 * @param $context
86 * @param null $name
87 *
88 * @return mixed
89 */
00be9182 90 public static function getContext($context, $name = NULL) {
be2fb01f 91 static $contextNameData = [];
6a488035
TO
92
93 if (!array_key_exists($context, $contextNameData)) {
be2fb01f 94 $contextNameData[$context] = [];
6a488035
TO
95 $persisntentDAO = new CRM_Core_DAO_Persistent();
96 $persisntentDAO->context = $context;
97 $persisntentDAO->find();
98
99 while ($persisntentDAO->fetch()) {
100 $contextNameData[$context][$persisntentDAO->name] = $persisntentDAO->is_config == 1 ? unserialize($persisntentDAO->data) : $persisntentDAO->data;
101 }
102 }
103 if (empty($name)) {
104 return $contextNameData[$context];
105 }
106 else {
107 return CRM_Utils_Array::value($name, $contextNameData[$context]);
108 }
109 }
96025800 110
6a488035 111}