* @since Version 1.1 */ class cModSettings { private $oDb; private $sName; const MOD_SETTINGS_PARTNER = 1425; const MOD_SETTINGS_DOCUMENTS = 1428; /** * Class constructor */ public function __construct() { $this->sName = get_class(); $this->oDb = cDb::getInstance(); } /** * Function to get module settings by types * * @author Mareks Keišs * @category cModSettings * @param int|array $iKeys - keys to select * @param bool $bReturnRaw - return RAW format JSON data * @param bool $bDevDb - use dev db * @return array - settings or array of settings if multiple requested */ public function getModuleSettingsByKey($iKeys, bool $bReturnRaw = false, bool $bDevDb = false): array { if (!!$iKeys) { $this->oDb->_querySelect(($bDevDb ? pubDocumentsModule::BILL_CP_DB . "." : "") . 'mod_settings', 'i_text', array('i_type' => (is_array($iKeys) ? $iKeys : array($iKeys))), false, false, false); $vData = $this->oDb->getFieldBasedArrayFieldsAdv('i_type', 'i_text'); if ($bReturnRaw) { return $vData; } if (!!$vData) { foreach ($vData as &$v) { $v = cJSON::decode($v, true); } unset($v); if (is_array($iKeys)) { return $vData; } elseif (isset($vData[$iKeys])) { return $vData[$iKeys]; } } } return []; } /** * Function to save module settings * * @author Mareks Keišs * @category cModSettings * @param mixed $vCFGData - raw data to convert to JSON & save in settings table * @param int $iKey - keys to save * @return bool - status */ public function saveModuleSettingsByKey($vCFGData, int $iKey): bool { if (!!$iKey && !!$vCFGData) { $vInsert = [ 'i_type' => $iKey, 'i_text' => cJSON::encode($vCFGData) ]; // Delete & insert data $this->oDb->_queryDelete('mod_settings', ['i_type' => $iKey]); $this->oDb->_queryInsert('mod_settings', $vInsert, false, true); return true; } return false; } }