From d83a3991c7f830d4f44847907f163b11b66cf3c7 Mon Sep 17 00:00:00 2001 From: vivekarora Date: Mon, 26 Aug 2013 13:31:29 +0530 Subject: [PATCH] CRM-13187 - Word Replacement API,BAO and XML ---------------------------------------- * CRM-13187: hrui: Change breadcrumb from "CiviCRM" to "CiviHR" http://issues.civicrm.org/jira/browse/CRM-13187 --- CRM/Core/BAO/WordReplacement.php | 178 ++++++++++++++++++++++++++++ api/v3/WordReplacement.php | 91 ++++++++++++++ xml/schema/Core/WordReplacement.xml | 59 +++++++++ 3 files changed, 328 insertions(+) create mode 100644 CRM/Core/BAO/WordReplacement.php create mode 100644 api/v3/WordReplacement.php create mode 100644 xml/schema/Core/WordReplacement.xml diff --git a/CRM/Core/BAO/WordReplacement.php b/CRM/Core/BAO/WordReplacement.php new file mode 100644 index 0000000000..4968492a4e --- /dev/null +++ b/CRM/Core/BAO/WordReplacement.php @@ -0,0 +1,178 @@ +id = CRM_Core_Config::wordReplacementID(); + if (!$wordReplacement->find(TRUE)) { + CRM_Core_Error::fatal(); + } + } + return $wordReplacement; + } + + + /** + * Save the values of a WordReplacement + * + * @return WordReplacement array + * @access public + */ + static function edit(&$params, &$id) { + $wordReplacement = new CRM_Core_DAO_WordReplacement(); + $wordReplacement->id = $id; + $wordReplacement->copyValues($params); + $wordReplacement->save(); + self::rebuild(); + return $wordReplacement; + } + + /** + * Create a new WordReplacement + * + * @return WordReplacement array + * @access public + */ + static function create($params) { + if(array_key_exists("domain_id",$params) === false) { + $params["domain_id"] = CRM_Core_Config::domainID(); + } + $wordReplacement = new CRM_Core_DAO_WordReplacement(); + $wordReplacement->copyValues($params); + $wordReplacement->save(); + self::rebuild(); + return $wordReplacement; + } + + /** + * Delete website + * + * @param int $id WordReplacement id + * + * @return object + * @static + */ + static function del($id) { + $dao = new CRM_Core_DAO_WordReplacement(); + $dao->id = $id; + $dao->delete(); + self::rebuild(); + return $dao; + } + + /* + * Rebuild + */ + + static function rebuild() { + $id = CRM_Core_Config::domainID(); + $query = "SELECT find_word,replace_word FROM civicrm_word_replacement WHERE is_active = 1 AND domain_id = ".CRM_Utils_Type::escape($id, 'Integer'); + $dao = CRM_Core_DAO::executeQuery($query); + $wordReplacement = array(); + + while ($dao->fetch()) { + $wordReplacement[$dao->find_word] = $dao->replace_word; + } + + $overrides['enabled']['wildcardMatch'] = $wordReplacement; + + $config = CRM_Core_Config::singleton(); + $domain = new CRM_Core_DAO_Domain(); + $domain->find(TRUE); + + if ($domain->locales && $config->localeCustomStrings) { + // for multilingual + $addReplacements = $config->localeCustomStrings; + $addReplacements[$config->lcMessages] = $overrides; + $stringOverride = serialize($addReplacements); + } + else { + // for single language + $stringOverride = serialize(array($config->lcMessages => $overrides)); + } + + $params = array('locale_custom_strings' => $stringOverride); + + + $wordReplacementSettings = CRM_Core_BAO_Domain::edit($params, $id); + + if ($wordReplacementSettings) { + // Reset navigation + CRM_Core_BAO_Navigation::resetNavigation(); + // Clear js string cache + CRM_Core_Resources::singleton()->flushStrings(); + + return true; + } + + return false; + + } + +} + diff --git a/api/v3/WordReplacement.php b/api/v3/WordReplacement.php new file mode 100644 index 0000000000..7a1e2877c9 --- /dev/null +++ b/api/v3/WordReplacement.php @@ -0,0 +1,91 @@ + + + + CRM/Core + WordReplacement + civicrm_word_replacement + Top-level hierarchy to support word replacement. + 4.4 + + id + int unsigned + true + Word replacement ID + 4.4 + + + id + true + + + find_word + varchar + 255 + Word which need to be replaced + 4.4 + + + replace_word + varchar + 255 + Word which will replace the word in find + 4.4 + + + is_active + Word Replacement is Active + boolean + Is this entry active? + 4.4 + + + UI_find + find_word + true + 4.4 + + + domain_id + int unsigned + FK to Domain ID. This is for Domain specific word replacement + 1.1 + + + domain_id +
civicrm_domain
+ id + 1.1 + + -- 2.25.1