1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\System\Db;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2019, Afterlogic Corp.
14: *
15: * @package Api
16: * @subpackage Db
17: */
18: abstract class AbstractCommandCreator
19: {
20: /**
21: * @var IDbHelper
22: */
23: protected $oHelper;
24:
25: /**
26: * @var string
27: */
28: protected $sPrefix;
29:
30: /**
31: * @param IHelper $oHelper
32: * @param string $sPrefix
33: */
34: public function __construct($oHelper = '', $sPrefix = '')
35: {
36: $oSettings =& \Aurora\System\Api::GetSettings();
37:
38: $oCommandCreatorHelper =& $this->GetHelper();
39:
40: if ($oSettings) {
41: $this->oHelper = $oCommandCreatorHelper;
42: $this->sPrefix = (string) $oSettings->DBPrefix;
43: }
44: }
45:
46: /**
47: * @return CDbStorage
48: */
49: public function &GetHelper()
50: {
51: if (null === $this->oHelper) {
52: $oSettings =& \Aurora\System\Api::GetSettings();
53: if ($oSettings) {
54: $this->oHelper = \Aurora\System\Db\Creator::CreateCommandCreatorHelper($oSettings);
55: } else {
56: $this->oHelper = false;
57: }
58: }
59: return $this->oHelper;
60: }
61:
62: public function prefix()
63: {
64: return $this->sPrefix;
65: }
66:
67: /**
68: * @param string $sValue
69: * @param bool $bWithOutQuote = false
70: * @param bool $bSearch = false
71: * @return string
72: */
73: protected function escapeString($sValue, $bWithOutQuote = false, $bSearch = false)
74: {
75: return $this->oHelper->EscapeString($sValue, $bWithOutQuote, $bSearch);
76: }
77:
78: /**
79: * @param array $aValue
80: * @return array
81: */
82: protected function escapeArray($aValue)
83: {
84: return array_map(array(&$this->oHelper, 'EscapeString'), $aValue);
85: }
86:
87: /**
88: * @param string $str
89: * @return string
90: */
91: protected function escapeColumn($str)
92: {
93: return $this->oHelper->EscapeColumn($str);
94: }
95:
96: /**
97: * @param string $sFieldName
98: * @return string
99: */
100: protected function GetDateFormat($sFieldName)
101: {
102: return $this->oHelper->GetDateFormat($sFieldName);
103: }
104:
105: /**
106: * @param string $sFieldName
107: * @return string
108: */
109: protected function UpdateDateFormat($sFieldName)
110: {
111: return $this->oHelper->UpdateDateFormat($sFieldName);
112: }
113: }
114: