Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | class CRM_Core_BAO_Persistent extends CRM_Core_DAO_Persistent { | |
36 | ||
37 | /** | |
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 | |
43 | * | |
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 | |
46 | * | |
47 | * @return object CRM_Core_BAO_Persistent object | |
48 | * @access public | |
49 | * @static | |
50 | */ | |
51 | static function retrieve(&$params, &$defaults) { | |
52 | $dao = new CRM_Core_DAO_Persistent(); | |
53 | $dao->copyValues($params); | |
54 | ||
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']); | |
59 | } | |
60 | return $dao; | |
61 | } | |
62 | return NULL; | |
63 | } | |
64 | ||
65 | /** | |
66 | * function to add the Persistent Record | |
67 | * | |
68 | * @param array $params reference array contains the values submitted by the form | |
69 | * @param array $ids reference array contains the id | |
70 | * | |
71 | * @access public | |
72 | * @static | |
73 | * | |
74 | * @return object | |
75 | */ | |
76 | static function add(&$params, &$ids) { | |
77 | if (CRM_Utils_Array::value('is_config', $params) == 1) { | |
78 | $params['data'] = serialize(explode(',', $params['data'])); | |
79 | } | |
80 | $persistentDAO = new CRM_Core_DAO_Persistent(); | |
81 | $persistentDAO->copyValues($params); | |
82 | ||
83 | $persistentDAO->id = CRM_Utils_Array::value('persistent', $ids); | |
84 | $persistentDAO->save(); | |
85 | return $persistentDAO; | |
86 | } | |
87 | ||
88 | static function getContext($context, $name = NULL) { | |
89 | static $contextNameData = array(); | |
90 | ||
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(); | |
96 | ||
97 | while ($persisntentDAO->fetch()) { | |
98 | $contextNameData[$context][$persisntentDAO->name] = $persisntentDAO->is_config == 1 ? unserialize($persisntentDAO->data) : $persisntentDAO->data; | |
99 | } | |
100 | } | |
101 | if (empty($name)) { | |
102 | return $contextNameData[$context]; | |
103 | } | |
104 | else { | |
105 | return CRM_Utils_Array::value($name, $contextNameData[$context]); | |
106 | } | |
107 | } | |
108 | } | |
109 |