HomeHelpTrac

source: trunk/inc/prof.inc.php @ 15211

Revision 15211, 2.3 KB checked in by Alexander Trofimov, 12 months ago (diff)

Code cleaning:

  • converting new lines to \n
  • deleting spaces at the end of every line
  • converting all tabs to 4 spaces
  • automated script for future cleaning was added
Line 
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 */
7defined('BX_DOL') or die('hack attempt');
8
9define('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'));
14if (null === $GLOBALS['aPreValues'])
15    compilePreValues();
16
17
18function getPreKeys () {
19    return BxDolDb::getInstance()->fromCache('sys_prevalues_keys', 'getAll', "SELECT DISTINCT `Key` FROM `" . BX_SYS_PRE_VALUES_TABLE . "`");
20}
21
22function 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
37function 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
43function 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
Note: See TracBrowser for help on using the repository browser.