3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 class CRM_Core_BAO_Persistent
extends CRM_Core_DAO_Persistent
{
38 * Takes a bunch of params that are needed to match certain criteria and
39 * retrieves the relevant objects. Typically the valid params are only
40 * contact_id. We'll tweak this function to be more full featured over a period
41 * of time. This is the inverse function of create. It also stores all the retrieved
42 * values in the default array
44 * @param array $params (reference ) an assoc array of name/value pairs
45 * @param array $defaults (reference ) an assoc array to hold the flattened values
47 * @return object CRM_Core_BAO_Persistent object
51 static function retrieve(&$params, &$defaults) {
52 $dao = new CRM_Core_DAO_Persistent();
53 $dao->copyValues($params);
55 if ($dao->find(TRUE)) {
56 CRM_Core_DAO
::storeValues($dao, $defaults);
57 if (CRM_Utils_Array
::value('is_config', $defaults) == 1) {
58 $defaults['data'] = unserialize($defaults['data']);
66 * function to add the Persistent Record
68 * @param array $params reference array contains the values submitted by the form
69 * @param array $ids reference array contains the id
76 static function add(&$params, &$ids) {
77 if (CRM_Utils_Array
::value('is_config', $params) == 1) {
78 $params['data'] = serialize(explode(',', $params['data']));
80 $persistentDAO = new CRM_Core_DAO_Persistent();
81 $persistentDAO->copyValues($params);
83 $persistentDAO->id
= CRM_Utils_Array
::value('persistent', $ids);
84 $persistentDAO->save();
85 return $persistentDAO;
88 static function getContext($context, $name = NULL) {
89 static $contextNameData = array();
91 if (!array_key_exists($context, $contextNameData)) {
92 $contextNameData[$context] = array();
93 $persisntentDAO = new CRM_Core_DAO_Persistent();
94 $persisntentDAO->context
= $context;
95 $persisntentDAO->find();
97 while ($persisntentDAO->fetch()) {
98 $contextNameData[$context][$persisntentDAO->name
] = $persisntentDAO->is_config
== 1 ?
unserialize($persisntentDAO->data
) : $persisntentDAO->data
;
102 return $contextNameData[$context];
105 return CRM_Utils_Array
::value($name, $contextNameData[$context]);