INFRA-132 - Comment grammar cleanup
[civicrm-core.git] / CRM / Core / BAO / Persistent.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35 class CRM_Core_BAO_Persistent extends CRM_Core_DAO_Persistent {
36
37 /**
38 * Fetch object based on array of properties
39 *
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.
44 *
45 * @return CRM_Core_BAO_Persistent object
46 * @static
47 */
48 public static function retrieve(&$params, &$defaults) {
49 $dao = new CRM_Core_DAO_Persistent();
50 $dao->copyValues($params);
51
52 if ($dao->find(TRUE)) {
53 CRM_Core_DAO::storeValues($dao, $defaults);
54 if (CRM_Utils_Array::value('is_config', $defaults) == 1) {
55 $defaults['data'] = unserialize($defaults['data']);
56 }
57 return $dao;
58 }
59 return NULL;
60 }
61
62 /**
63 * Add the Persistent Record
64 *
65 * @param array $params
66 * Reference array contains the values submitted by the form.
67 * @param array $ids
68 * Reference array contains the id.
69 *
70 * @static
71 *
72 * @return object
73 */
74 public static function add(&$params, &$ids) {
75 if (CRM_Utils_Array::value('is_config', $params) == 1) {
76 $params['data'] = serialize(explode(',', $params['data']));
77 }
78 $persistentDAO = new CRM_Core_DAO_Persistent();
79 $persistentDAO->copyValues($params);
80
81 $persistentDAO->id = CRM_Utils_Array::value('persistent', $ids);
82 $persistentDAO->save();
83 return $persistentDAO;
84 }
85
86 /**
87 * @param $context
88 * @param null $name
89 *
90 * @return mixed
91 */
92 public static function getContext($context, $name = NULL) {
93 static $contextNameData = array();
94
95 if (!array_key_exists($context, $contextNameData)) {
96 $contextNameData[$context] = array();
97 $persisntentDAO = new CRM_Core_DAO_Persistent();
98 $persisntentDAO->context = $context;
99 $persisntentDAO->find();
100
101 while ($persisntentDAO->fetch()) {
102 $contextNameData[$context][$persisntentDAO->name] = $persisntentDAO->is_config == 1 ? unserialize($persisntentDAO->data) : $persisntentDAO->data;
103 }
104 }
105 if (empty($name)) {
106 return $contextNameData[$context];
107 }
108 else {
109 return CRM_Utils_Array::value($name, $contextNameData[$context]);
110 }
111 }
112 }