本文整理汇总了PHP中DbHelper::getTextualColumnStorageCapacity方法的典型用法代码示例。如果您正苦于以下问题:PHP DbHelper::getTextualColumnStorageCapacity方法的具体用法?PHP DbHelper::getTextualColumnStorageCapacity怎么用?PHP DbHelper::getTextualColumnStorageCapacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbHelper
的用法示例。
在下文中一共展示了DbHelper::getTextualColumnStorageCapacity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* @inheritDoc BaseFieldType::validate()
*
* @param mixed $value
*
* @return true|string|array
*/
public function validate($value)
{
$settings = $this->getSettings();
// This wasn't always a setting.
$columnType = !$settings->getAttribute('columnType') ? ColumnType::Text : $settings->getAttribute('columnType');
$postContentSize = strlen($value);
$maxDbColumnSize = DbHelper::getTextualColumnStorageCapacity($columnType);
// Give ourselves 10% wiggle room.
$maxDbColumnSize = ceil($maxDbColumnSize * 0.9);
if ($postContentSize > $maxDbColumnSize) {
// Give ourselves 10% wiggle room.
$maxDbColumnSize = ceil($maxDbColumnSize * 0.9);
if ($postContentSize > $maxDbColumnSize) {
return Craft::t('{attribute} is too long.', array('attribute' => Craft::t($this->model->name)));
}
}
return true;
}
示例2: _indexElementKeywords
/**
* Indexes keywords for a specific element attribute/field.
*
* @param int $elementId
* @param string $attribute
* @param string $fieldId
* @param string|null $localeId
* @param string $dirtyKeywords
*
* @return null
*/
private function _indexElementKeywords($elementId, $attribute, $fieldId, $localeId, $dirtyKeywords)
{
$attribute = StringHelper::toLowerCase($attribute);
if (!$localeId) {
$localeId = craft()->i18n->getPrimarySiteLocaleId();
}
// Clean 'em up
$cleanKeywords = StringHelper::normalizeKeywords($dirtyKeywords);
// Save 'em
$keyColumns = array('elementId' => $elementId, 'attribute' => $attribute, 'fieldId' => $fieldId, 'locale' => $localeId);
if ($cleanKeywords !== null && $cleanKeywords !== false && $cleanKeywords !== '') {
// Add padding around keywords
$cleanKeywords = ' ' . $cleanKeywords . ' ';
}
$cleanKeywordsLength = strlen($cleanKeywords);
$maxDbColumnSize = DbHelper::getTextualColumnStorageCapacity(ColumnType::Text);
// Give ourselves 10% wiggle room.
$maxDbColumnSize = ceil($maxDbColumnSize * 0.9);
if ($cleanKeywordsLength > $maxDbColumnSize) {
// Time to truncate.
$cleanKeywords = mb_strcut($cleanKeywords, 0, $maxDbColumnSize);
// Make sure we don't cut off a word in the middle.
if ($cleanKeywords[mb_strlen($cleanKeywords) - 1] !== ' ') {
$position = mb_strrpos($cleanKeywords, ' ');
if ($position) {
$cleanKeywords = mb_substr($cleanKeywords, 0, $position + 1);
}
}
}
// Insert/update the row in searchindex
craft()->db->createCommand()->insertOrUpdate('searchindex', $keyColumns, array('keywords' => $cleanKeywords), false);
}