| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Dolphin Core |
|---|
| 4 | * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/ |
|---|
| 5 | * @license CC-BY - http://creativecommons.org/licenses/by/3.0/ |
|---|
| 6 | */ |
|---|
| 7 | defined('BX_DOL') or die('hack attempt'); |
|---|
| 8 | |
|---|
| 9 | define('BX_SYS_PRE_VALUES_TABLE', 'sys_pre_values'); |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | $oCache = BxDolDb::getInstance()->getDbCacheObject(); |
|---|
| 13 | $GLOBALS['aPreValues'] = $oCache->getData(BxDolDb::getInstance()->genDbCacheKey('sys_pre_values')); |
|---|
| 14 | if (null === $GLOBALS['aPreValues']) |
|---|
| 15 | compilePreValues(); |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | function getPreKeys () { |
|---|
| 19 | return BxDolDb::getInstance()->fromCache('sys_prevalues_keys', 'getAll', "SELECT DISTINCT `Key` FROM `" . BX_SYS_PRE_VALUES_TABLE . "`"); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | function getPreValues ($sKey, $aFields = array()) { |
|---|
| 23 | $sFields = "*"; |
|---|
| 24 | if (is_array($aFields) && !empty($aFields)) { |
|---|
| 25 | foreach ($aFields as $sValue) |
|---|
| 26 | $sFields .= "`$sValue`, "; |
|---|
| 27 | $sFields = trim($sFields, ', '); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | $oDb = BxDolDb::getInstance(); |
|---|
| 31 | $sQuery = $oDb->prepare("SELECT $sFields FROM `" . BX_SYS_PRE_VALUES_TABLE ."` |
|---|
| 32 | WHERE `Key` = ? |
|---|
| 33 | ORDER BY `Order` ASC", $sKey); |
|---|
| 34 | return $oDb->getAllWithKey($sQuery, 'Value'); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | function getPreValuesCount ($sKey, $aFields = array()) { |
|---|
| 38 | $oDb = BxDolDb::getInstance(); |
|---|
| 39 | $sQuery = $oDb->prepare("SELECT COUNT(*) FROM `" . BX_SYS_PRE_VALUES_TABLE . "` WHERE `Key` = ?", $sKey); |
|---|
| 40 | return $oDb->getOne($sQuery); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | function compilePreValues() { |
|---|
| 44 | |
|---|
| 45 | BxDolDb::getInstance()->cleanCache('sys_prevalues_keys'); |
|---|
| 46 | |
|---|
| 47 | $aPreValues = array (); |
|---|
| 48 | $aKeys = getPreKeys(); |
|---|
| 49 | |
|---|
| 50 | foreach ($aKeys as $aKey) { |
|---|
| 51 | |
|---|
| 52 | $sKey = $aKey['Key']; |
|---|
| 53 | $aPreValues[$sKey] = array (); |
|---|
| 54 | |
|---|
| 55 | $aRows = getPreValues($sKey); |
|---|
| 56 | foreach ($aRows as $aRow) { |
|---|
| 57 | |
|---|
| 58 | $aPreValues[$sKey][$aRow['Value']] = array (); |
|---|
| 59 | |
|---|
| 60 | foreach ($aRow as $sValKey => $sValue) { |
|---|
| 61 | if ($sValKey == 'Key' or $sValKey == 'Value' or $sValKey == 'Order') |
|---|
| 62 | continue; //skip key, value and order. they already used |
|---|
| 63 | |
|---|
| 64 | if (!strlen($sValue)) |
|---|
| 65 | continue; //skip empty values |
|---|
| 66 | |
|---|
| 67 | $aPreValues[$sKey][$aRow['Value']][$sValKey] = $sValue; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | $oCache = BxDolDb::getInstance()->getDbCacheObject(); |
|---|
| 75 | $oCache->setData (BxDolDb::getInstance()->genDbCacheKey('sys_pre_values'), $aPreValues); |
|---|
| 76 | |
|---|
| 77 | $GLOBALS['aPreValues'] = $aPreValues; |
|---|
| 78 | } |
|---|
| 79 | |
|---|