prof.inc.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. define('BX_SYS_PRE_VALUES_TABLE', 'sys_pre_values');
  9. $oCache = BxDolDb::getInstance()->getDbCacheObject();
  10. $GLOBALS['aPreValues'] = $oCache->getData(BxDolDb::getInstance()->genDbCacheKey('sys_pre_values'));
  11. if (null === $GLOBALS['aPreValues'])
  12. compilePreValues();
  13. function getPreKeys () {
  14. return BxDolDb::getInstance()->fromCache('sys_prevalues_keys', 'getAll', "SELECT DISTINCT `Key` FROM `" . BX_SYS_PRE_VALUES_TABLE . "`");
  15. }
  16. function getPreValues ($sKey, $aFields = array()) {
  17. $sFields = "*";
  18. if (is_array($aFields) && !empty($aFields)) {
  19. foreach ($aFields as $sValue)
  20. $sFields .= "`$sValue`, ";
  21. $sFields = trim($sFields, ', ');
  22. }
  23. $oDb = BxDolDb::getInstance();
  24. $sQuery = $oDb->prepare("SELECT $sFields FROM `" . BX_SYS_PRE_VALUES_TABLE ."`
  25. WHERE `Key` = ?
  26. ORDER BY `Order` ASC", $sKey);
  27. return $oDb->getAllWithKey($sQuery, 'Value');
  28. }
  29. function getPreValuesCount ($sKey, $aFields = array()) {
  30. $oDb = BxDolDb::getInstance();
  31. $sQuery = $oDb->prepare("SELECT COUNT(*) FROM `" . BX_SYS_PRE_VALUES_TABLE . "` WHERE `Key` = ?", $sKey);
  32. return $oDb->getOne($sQuery);
  33. }
  34. function compilePreValues() {
  35. BxDolDb::getInstance()->cleanCache('sys_prevalues_keys');
  36. $aPreValues = array ();
  37. $aKeys = getPreKeys();
  38. foreach ($aKeys as $aKey) {
  39. $sKey = $aKey['Key'];
  40. $aPreValues[$sKey] = array ();
  41. $aRows = getPreValues($sKey);
  42. foreach ($aRows as $aRow) {
  43. $aPreValues[$sKey][$aRow['Value']] = array ();
  44. foreach ($aRow as $sValKey => $sValue) {
  45. if ($sValKey == 'Key' or $sValKey == 'Value' or $sValKey == 'Order')
  46. continue; //skip key, value and order. they already used
  47. if (!strlen($sValue))
  48. continue; //skip empty values
  49. $aPreValues[$sKey][$aRow['Value']][$sValKey] = $sValue;
  50. }
  51. }
  52. }
  53. $oCache = BxDolDb::getInstance()->getDbCacheObject();
  54. $oCache->setData (BxDolDb::getInstance()->genDbCacheKey('sys_pre_values'), $aPreValues);
  55. $GLOBALS['aPreValues'] = $aPreValues;
  56. }