public function prepareWhere($aWhere, $oEntity, &$aWhereAttributes, $sOperator = 'AND') { $aResultOperations = array(); foreach ($aWhere as $sKey => $mValue) { if (strpos($sKey, '$') !== false) { list(, $sKey) = explode('$', $sKey); $aResultOperations[] = $this->prepareWhere($mValue, $oEntity, $aWhereAttributes, $sKey); } else { $mResultValue = null; $mResultOperator = '='; if (is_array($mValue)) { if (0 < count($mValue)) { $mResultValue = $mValue[0]; $mResultOperator = $mValue[1]; } } else { $mResultValue = $mValue; } if (isset($mResultValue)) { if (!in_array($sKey, $aWhereAttributes)) { $aWhereAttributes[] = $sKey; } if ($oEntity->isEncryptedAttribute($sKey)) { $mResultValue = \api_Utils::EncryptValue($mResultValue); } $bIsInOperator = false; if (strtolower($mResultOperator) === 'in' || strtolower($mResultOperator) === 'not in' && is_array($mResultValue)) { $bIsInOperator = true; $mResultValue = array_map(function ($mValue) use($oEntity, $sKey) { return $oEntity->isStringAttribute($sKey) ? $this->escapeString($mValue) : $mValue; }, $mResultValue); $mResultValue = '(' . implode(', ', $mResultValue) . ')'; } $sValueFormat = $oEntity->isStringAttribute($sKey) ? "%s" : "%d"; $aResultOperations[] = sprintf("`attrs_%s`.`value` %s " . $sValueFormat, $sKey, $mResultOperator, $oEntity->isStringAttribute($sKey) && !$bIsInOperator ? $this->escapeString($mResultValue) : $mResultValue); } } } return sprintf(count($aResultOperations) > 1 ? '(%s)' : '%s', implode(' ' . $sOperator . ' ', $aResultOperations)); }
/** * @param object $oObject * @param object $oHelper * @return array */ public static function DbInsertArrays($oObject, $oHelper) { $aResult = array(false, false); $sQueryParams = ''; $bUseLogQueryParams = (bool) CApi::GetConf('labs.db.log-query-params', false); $oObject->initBeforeChange(); $aStaticMap = $oObject->getMap(); $aMap = api_AContainer::DbWriteKeys($aStaticMap, true); $aDbKeys = array_keys($aMap); $aResult[0] = array_map(array(&$oHelper, 'EscapeColumn'), $aDbKeys); $aDbValues = array_values($aMap); foreach ($aDbValues as $iIndex => $sKey) { $mValue = $oObject->{$sKey}; if (isset($aStaticMap[$sKey][0])) { if ('password' === $aStaticMap[$sKey][0]) { $mValue = api_Utils::EncryptValue($mValue); } else { if ('datetime' === $aStaticMap[$sKey][0]) { $mValue = $oHelper->TimeStampToDateFormat($mValue); } else { if ('serialize' === $aStaticMap[$sKey][0]) { $mValue = '' === $mValue ? '' : serialize($mValue); } } } } $aDbValues[$iIndex] = is_string($mValue) ? $oHelper->EscapeString($mValue) : (int) $mValue; if ($bUseLogQueryParams) { $sDbKey = isset($aDbKeys[$iIndex]) ? $aDbKeys[$iIndex] : '!unknown!'; $sQueryParams .= API_CRLF . API_TAB . $sDbKey . ' = ' . $aDbValues[$iIndex]; } } $aResult[1] = $aDbValues; if ($bUseLogQueryParams) { CApi::Log($sQueryParams); } return $aResult; }
public function Encrypt() { $this->Value = \api_Utils::EncryptValue($this->Value); }