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
39 class CRM_Core_BAO_WordReplacement
extends CRM_Core_DAO_WordReplacement
{
41 function __construct() {
42 parent
::__construct();
45 * Takes a bunch of params that are needed to match certain criteria and
46 * retrieves the relevant objects.
48 * @param array $params (reference ) an assoc array of name/value pairs
49 * @param array $defaults (reference ) an assoc array to hold the flattened values
51 * @return object CRM_Core_DAO_WordRepalcement object
56 static function retrieve(&$params, &$defaults) {
57 return CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_WordRepalcement', $params, $defaults);
63 * @return null|object CRM_Core_BAO_WordRepalcement
67 static function getWordReplacement($reset = NULL) {
68 static $wordReplacement = NULL;
69 if (!$wordReplacement ||
$reset) {
70 $wordReplacement = new CRM_Core_BAO_WordRepalcement();
71 $wordReplacement->id
= CRM_Core_Config
::wordReplacementID();
72 if (!$wordReplacement->find(TRUE)) {
73 CRM_Core_Error
::fatal();
76 return $wordReplacement;
81 * Save the values of a WordReplacement
83 * @return WordReplacement array
86 static function edit(&$params, &$id) {
87 $wordReplacement = new CRM_Core_DAO_WordReplacement();
88 $wordReplacement->id
= $id;
89 $wordReplacement->copyValues($params);
90 $wordReplacement->save();
92 return $wordReplacement;
96 * Create a new WordReplacement
98 * @return WordReplacement array
101 static function create($params) {
102 if(array_key_exists("domain_id",$params) === FALSE) {
103 $params["domain_id"] = CRM_Core_Config
::domainID();
105 $wordReplacement = new CRM_Core_DAO_WordReplacement();
106 $wordReplacement->copyValues($params);
107 $wordReplacement->save();
109 return $wordReplacement;
115 * @param int $id WordReplacement id
120 static function del($id) {
121 $dao = new CRM_Core_DAO_WordReplacement();
129 * Get all word-replacements in the form of an array
131 * @param int $id domain ID
133 * @see civicrm_domain.locale_custom_strings
135 public static function getAllAsConfigArray($id) {
136 $query = "SELECT find_word,replace_word FROM civicrm_word_replacement WHERE is_active = 1 AND domain_id = ".CRM_Utils_Type
::escape($id, 'Integer');
137 $dao = CRM_Core_DAO
::executeQuery($query);
138 $wordReplacement = array();
140 while ($dao->fetch()) {
141 $wordReplacement[$dao->find_word
] = $dao->replace_word
;
144 $overrides['enabled']['wildcardMatch'] = $wordReplacement;
146 $config = CRM_Core_Config
::singleton();
147 $domain = new CRM_Core_DAO_Domain();
150 if ($domain->locales
&& $config->localeCustomStrings
) {
152 $addReplacements = $config->localeCustomStrings
;
153 $addReplacements[$config->lcMessages
] = $overrides;
154 $stringOverride = $addReplacements;
157 // for single language
158 $stringOverride = array($config->lcMessages
=> $overrides);
161 return $stringOverride;
167 static function rebuild() {
168 $id = CRM_Core_Config
::domainID();
169 $stringOverride = self
::getAllAsConfigArray($id);
170 $params = array('locale_custom_strings' => serialize($stringOverride));
171 $wordReplacementSettings = CRM_Core_BAO_Domain
::edit($params, $id);
173 if ($wordReplacementSettings) {
175 CRM_Core_BAO_Navigation
::resetNavigation();
176 // Clear js string cache
177 CRM_Core_Resources
::singleton()->flushStrings();