当前位置: 首页>>代码示例>>PHP>>正文


PHP DbHelper::getTextualColumnStorageCapacity方法代码示例

本文整理汇总了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;
 }
开发者ID:scisahaha,项目名称:generator-craft,代码行数:25,代码来源:RichTextFieldType.php

示例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);
 }
开发者ID:paulcarvill,项目名称:Convergence-craft,代码行数:43,代码来源:SearchService.php


注:本文中的DbHelper::getTextualColumnStorageCapacity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。