| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup DolphinStudio Dolphin Studio
- * @{
- */
- bx_import('BxDolLanguagesQuery');
- class BxDolStudioLanguagesUtilsQuery extends BxDolLanguagesQuery {
- function __construct() {
- parent::__construct();
- }
- function deleteLanguage($iId = 0) {
- $iId = (int)$iId;
- if($iId <= 0)
- return false;
- $sSql = $this->prepare("SELECT `ID`, `Name` FROM `sys_localization_languages` WHERE `ID`=?", $iId);
- $aLanguage = $this->getRow($sSql);
- if(empty($aLanguage))
- return false;
- $sSql = $this->prepare("SELECT COUNT(`IDKey`) FROM `sys_localization_strings` WHERE `IDLanguage`=?", $iId);
- $iStrings = (int)$this->getOne();
- $sSql = $this->prepare("DELETE FROM `sys_localization_strings` WHERE `IDLanguage`=?", $iId);
- if((int)$this->query($sSql) < $iStrings)
- return false;
- $sSql = $this->prepare("DELETE FROM `sys_localization_languages` WHERE `ID`=?", $iId);
- if((int)$this->query($sSql) <= 0)
- return false;
- @unlink( BX_DIRECTORY_PATH_ROOT . 'langs/lang-' . $aLanguage['Name'] . '.php');
- $sSql = $this->prepare("DELETE FROM `sys_email_templates` WHERE `LangID`=?", $iId);
- $this->query($sSql);
- return true;
- }
- function addKey($iCategoryId, $sKey) {
- $sSql = $this->prepare("SELECT `ID` FROM `sys_localization_keys` WHERE `Key`=? LIMIT 1", $sKey);
- if(($iId = (int)$this->getOne($sSql)) != 0)
- return $iId;
- $sSql = $this->prepare("INSERT INTO `sys_localization_keys` SET `IDCategory`=?, `Key`=?", $iCategoryId, $sKey);
- return (int)$this->query($sSql) > 0 ? $this->lastId() : false;
- }
- function addKeys($iLanguageId, $iCategoryId, &$aKeys) {
- foreach($aKeys as $sKey => $sValue) {
- $sQuery = $this->prepare("SELECT `ID` FROM `sys_localization_keys` WHERE `IDCategory`=? AND `Key`=? LIMIT 1", $iCategoryId, $sKey);
- $iKeyId = (int)$this->getOne($sQuery);
- if($iKeyId == 0) {
- $sQuery = $this->prepare("INSERT INTO `sys_localization_keys`(`IDCategory`, `Key`) VALUES(?, ?)", $iCategoryId, $sKey);
- if((int)$this->query($sQuery) <= 0)
- continue;
- $iKeyId = (int)$this->lastId();
- }
- $sQuery = $this->prepare("INSERT IGNORE INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES(?, ?, ?)", $iKeyId, $iLanguageId, $sValue);
- $this->query($sQuery);
- }
- }
- /**
- * Remove language key ONLY. Language strings should be already removed.
- * @param integer $iKeyId language key ID
- */
- function deleteKey($iKeyId) {
- $sQuery = $this->prepare("DELETE FROM `sys_localization_keys` WHERE `ID`=? LIMIT 1", $iKeyId);
- return (int)$this->query($sQuery) > 0;
- }
- function deleteKeys($aKeys) {
- foreach($aKeys as $sKey => $sValue) {
- $sQuery = $this->prepare("DELETE FROM `sys_localization_keys`, `sys_localization_strings` USING `sys_localization_keys`, `sys_localization_strings` WHERE `sys_localization_keys`.`ID`=`sys_localization_strings`.`IDKey` AND `sys_localization_keys`.`Key`=?", $sKey);
- $this->query($sQuery);
- }
- }
- function deleteKeysBy($aParams = array()) {
- $sWhereClause = "";
- switch($aParams['type']) {
- case 'by_key_id':
- $sWhereClause = $this->prepare(" AND `tk`.`ID`=?", $aParams['value']);
- break;
- case 'by_cat_id':
- $sWhereClause .= $this->prepare(" AND `tc`.`ID`=?", $aParams['value']);
- break;
- }
- $sSql = "DELETE FROM `tk`, `ts`
- USING
- `sys_localization_categories` AS `tc`,
- `sys_localization_keys` AS `tk`,
- `sys_localization_strings` AS `ts`
- WHERE `tk`.`ID`=`ts`.`IDKey` AND `tk`.`IDCategory`=`tc`.`ID`" . $sWhereClause;
- return (int)$this->query($sSql);
- }
- function addString($iKeyId, $iLanguageId, $sString) {
- $sSql = $this->prepare("INSERT INTO `sys_localization_strings` SET `IDKey`=?, `IDLanguage`=?, `String`=?", $iKeyId, $iLanguageId, $sString);
- return (int)$this->query($sSql) > 0;
- }
- function updateString($iKeyId, $iLanguageId, $sString) {
- $sSql = $this->prepare("SELECT `IDKey` FROM `sys_localization_strings` WHERE `IDKey`=? AND `IDLanguage`=?", $iKeyId, $iLanguageId);
- $iKeyIdDb = (int)$this->getOne($sSql);
-
- if($iKeyIdDb != 0)
- $sSql = $this->prepare("UPDATE `sys_localization_strings` SET `String`=? WHERE `IDKey`=? AND `IDLanguage`=?", $sString, $iKeyId, $iLanguageId);
- else
- $sSql = $this->prepare("INSERT INTO `sys_localization_strings` SET `IDKey`=?, `IDLanguage`=?, `String`=?", $iKeyId, $iLanguageId, $sString);
- return (int)$this->query($sSql) > 0;
- }
- function deleteString($iKeyId, $iLanguageId) {
- $sSql = $this->prepare("DELETE FROM `sys_localization_strings` WHERE `IDKey`=? AND `IDLanguage`=?", $iKeyId, $iLanguageId);
- return (int)$this->query($sSql) > 0;
- }
- function deleteStringsBy($aParams = array()) {
- $sWhereClause = "";
- switch($aParams['type']) {
- case 'by_lang':
- $sWhereClause .= $this->prepare(" AND `tl`.`ID`=?", $aParams['language_id']);
- break;
- case 'by_cat_and_lang':
- $sWhereClause .= $this->prepare(" AND `tc`.`ID`=? AND `tl`.`ID`=?", $aParams['category_id'], $aParams['language_id']);
- break;
- }
- $sSql = "DELETE FROM `ts`
- USING
- `sys_localization_categories` AS `tc`,
- `sys_localization_keys` AS `tk`,
- `sys_localization_languages` AS `tl`,
- `sys_localization_strings` AS `ts`
- WHERE `tk`.`ID`=`ts`.`IDKey` AND `tk`.`IDCategory`=`tc`.`ID` AND `ts`.`IDLanguage`=`tl`.`ID`" . $sWhereClause;
- return (int)$this->query($sSql);
- }
- function addCategory($sName) {
- $sQuery = $this->prepare("INSERT IGNORE INTO `sys_localization_categories` SET `Name`=?", $sName);
- $iResult = (int)$this->query($sQuery);
- if($iResult > 0)
- return (int)$this->lastId();
- $iCategoryId = 0;
- $this->getCategoriesBy(array('type' => 'id_by_name', 'value' => $sName), $iCategoryId);
- return $iCategoryId;
- }
- function deleteCategory($sName) {
- $sQuery = $this->prepare("DELETE FROM `sys_localization_categories` WHERE `Name`=?", $sName);
- $this->query($sQuery);
- }
- }
- /** @} */
|