3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Core_BAO_Persistent
extends CRM_Core_DAO_Persistent
{
38 * Fetch object based on array of properties
40 * @param array $params (reference ) an assoc array of name/value pairs
41 * @param array $defaults (reference ) an assoc array to hold the flattened values
43 * @return CRM_Core_BAO_Persistent object
47 static function retrieve(&$params, &$defaults) {
48 $dao = new CRM_Core_DAO_Persistent();
49 $dao->copyValues($params);
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']);
62 * add the Persistent Record
64 * @param array $params reference array contains the values submitted by the form
65 * @param array $ids reference array contains the id
72 static function add(&$params, &$ids) {
73 if (CRM_Utils_Array
::value('is_config', $params) == 1) {
74 $params['data'] = serialize(explode(',', $params['data']));
76 $persistentDAO = new CRM_Core_DAO_Persistent();
77 $persistentDAO->copyValues($params);
79 $persistentDAO->id
= CRM_Utils_Array
::value('persistent', $ids);
80 $persistentDAO->save();
81 return $persistentDAO;
90 static function getContext($context, $name = NULL) {
91 static $contextNameData = array();
93 if (!array_key_exists($context, $contextNameData)) {
94 $contextNameData[$context] = array();
95 $persisntentDAO = new CRM_Core_DAO_Persistent();
96 $persisntentDAO->context
= $context;
97 $persisntentDAO->find();
99 while ($persisntentDAO->fetch()) {
100 $contextNameData[$context][$persisntentDAO->name
] = $persisntentDAO->is_config
== 1 ?
unserialize($persisntentDAO->data
) : $persisntentDAO->data
;
104 return $contextNameData[$context];
107 return CRM_Utils_Array
::value($name, $contextNameData[$context]);