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


PHP DataObjectInterface::hasField方法代码示例

本文整理汇总了PHP中DataObjectInterface::hasField方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectInterface::hasField方法的具体用法?PHP DataObjectInterface::hasField怎么用?PHP DataObjectInterface::hasField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataObjectInterface的用法示例。


在下文中一共展示了DataObjectInterface::hasField方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
         throw new Exception('HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.');
     }
     $htmlValue = Injector::inst()->create('HTMLValue', $this->value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // Resample images and add default attributes
     if ($images = $htmlValue->getElementsByTagName('img')) {
         foreach ($images as $img) {
             // strip any ?r=n data from the src attribute
             $img->setAttribute('src', preg_replace('/([^\\?]*)\\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
             // Resample the images if the width & height have changed.
             if ($image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))))) {
                 $width = (int) $img->getAttribute('width');
                 $height = (int) $img->getAttribute('height');
                 if ($width && $height && ($width != $image->getWidth() || $height != $image->getHeight())) {
                     //Make sure that the resized image actually returns an image:
                     $resized = $image->ResizedImage($width, $height);
                     if ($resized) {
                         $img->setAttribute('src', $resized->getRelativePath());
                     }
                 }
             }
             // Add default empty title & alt attributes.
             if (!$img->getAttribute('alt')) {
                 $img->setAttribute('alt', '');
             }
             if (!$img->getAttribute('title')) {
                 $img->setAttribute('title', '');
             }
             // Use this extension point to manipulate images inserted using TinyMCE, e.g. add a CSS class, change default title
             // $image is the image, $img is the DOM model
             $this->extend('processImage', $image, $img);
         }
     }
     // optionally manipulate the HTML after a TinyMCE edit and prior to a save
     $this->extend('processHTML', $htmlValue);
     // Store into record
     $record->{$this->name} = $htmlValue->getContent();
 }
开发者ID:hpeide,项目名称:silverstripe-framework,代码行数:45,代码来源:HtmlEditorField.php

示例2: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
         throw new Exception('HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.');
     }
     // Resample images
     $value = Image::regenerate_html_links($this->value);
     $htmlValue = Injector::inst()->create('HTMLValue', $value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // optionally manipulate the HTML after a TinyMCE edit and prior to a save
     $this->extend('processHTML', $htmlValue);
     // Store into record
     $record->{$this->name} = $htmlValue->getContent();
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:18,代码来源:HtmlEditorField.php

示例3: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
         throw new Exception('HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.');
     }
     $htmlValue = Injector::inst()->create('HTMLValue', $this->value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // Resample images and add default attributes
     if ($images = $htmlValue->getElementsByTagName('img')) {
         foreach ($images as $img) {
             // strip any ?r=n data from the src attribute
             $img->setAttribute('src', preg_replace('/([^\\?]*)\\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
             // Resample the images if the width & height have changed.
             // TODO: look for -10x here?
             $filename = RetinaImage::removeFilenameAppender(urldecode(Director::makeRelative($img->getAttribute('src'))), '-10x');
             $image = File::find($filename);
             // try to find it using the legacy way
             if (!$image) {
                 $image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))));
             }
             if ($image) {
                 $imagemap = $image->toMap();
                 $retinaimage = RetinaImage::create();
                 foreach ($imagemap as $key => $value) {
                     $retinaimage->{$key} = $value;
                 }
                 $width = $img->getAttribute('width');
                 $height = $img->getAttribute('height');
                 if ($width && $height && ($width != $retinaimage->getWidth() || $height != $retinaimage->getHeight()) || !$img->hasAttribute('srcset') && RetinaImage::$forceretina) {
                     //Make sure that the resized image actually returns an image:
                     if (!is_numeric($width) || !is_numeric($height)) {
                         $width = (int) ($retinaimage->getWidth() / 2);
                         $height = (int) ($retinaimage->getHeight() / 2);
                     }
                     $resized = $retinaimage->ResizedImage($width, $height);
                     $url = $resized->getRelativePath();
                     $onex10 = $retinaimage->insertFilenameAppender($url, '-10x');
                     $onex15 = $retinaimage->insertFilenameAppender($url, '-15x');
                     $onex20 = $retinaimage->insertFilenameAppender($url, '-20x');
                     if ($resized) {
                         $img->setAttribute('src', $onex10);
                     }
                     // srcset=\"$onex10 1x, $onex15 1.5x, $onex20 2x\"
                     $img->setAttribute('srcset', "{$onex10} 1x, {$onex15} 1.5x, {$onex20} 2x");
                 }
             }
             // Add default empty title & alt attributes.
             if (!$img->getAttribute('alt')) {
                 $img->setAttribute('alt', '');
             }
             if (!$img->getAttribute('title')) {
                 $img->setAttribute('title', '');
             }
         }
     }
     // Store into record
     $record->{$this->name} = $htmlValue->getContent();
 }
开发者ID:chitosystems,项目名称:silverstripe-retina-images,代码行数:62,代码来源:RetinaImage.php

示例4: saveInto

 /**
  * Saves the field into a record
  * @param  DataObjectInterface $record
  * @return FileAttachmentField
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->getName();
     if (!$fieldname) {
         return $this;
     }
     // Handle deletions. This is a bit of a hack. A workaround for having a single form field
     // post two params.
     $deletions = Controller::curr()->getRequest()->postVar('__deletion__' . $this->getName());
     if ($deletions) {
         foreach ($deletions as $id) {
             $this->deleteFileByID($id);
         }
     }
     if ($relation = $this->getRelation()) {
         $relation->setByIDList($this->Value());
     } elseif ($record->has_one($fieldname)) {
         $record->{"{$fieldname}ID"} = $this->Value() ?: 0;
     } elseif ($record->hasField($fieldname)) {
         $record->{$fieldname} = is_array($this->Value()) ? implode(',', $this->Value()) : $this->Value();
     }
     return $this;
 }
开发者ID:rasstislav,项目名称:silverstripe-dropzone,代码行数:28,代码来源:FileAttachmentField.php

示例5: saveInto

 function saveInto(DataObjectInterface $record)
 {
     $relation = $this->getRelation();
     if ($relation) {
         $submittedTags = explode($this->getDelimiter(), $this->value);
         $tagClass = $this->getTagClass();
         $tagLabelField = $this->getTagLabelField();
         $tagObjects = DataList::create($tagClass)->filter($tagLabelField, $submittedTags);
         if ($tagObjects->Count() < count($submittedTags)) {
             // filter out the tags that exist already
             $tagsAsKeys = array_flip($submittedTags);
             foreach ($tagObjects as $tag) {
                 $label = $tag->{$tagLabelField};
                 unset($tagsAsKeys[$label]);
             }
             foreach ($tagsAsKeys as $label => $value) {
                 $tagObject = new $tagClass();
                 $tagObject->{$tagLabelField} = $label;
                 $tagObject->write();
                 $tagObjects->add($tagObject);
             }
         }
         $relationList = $this->form->record->{$this->name}();
         $oldTags = $relationList->map('ID', $tagLabelField)->toArray();
         $relationList->removeAll();
         $relationList->addMany($tagObjects->toArray());
         if ($this->deleteUnusedTags) {
             $deletedTags = array_diff($oldTags, $tagObjects->map('ID', $tagLabelField)->toArray());
             if (count($deletedTags) > 0) {
                 $relationTable = $relation[4];
                 foreach ($deletedTags as $id => $title) {
                     $query = new SQLQuery();
                     $query->select = array('ID', $tagLabelField);
                     $query->from = array($relationTable);
                     $query->where = array("ID = " . $id);
                     $count = $query->Count();
                     if ($count == 0) {
                         DataObject::delete_by_id($tagClass, $id);
                     }
                 }
             }
         }
     } else {
         if ($record->hasField($this->name)) {
             $record->setCastedField($this->name, $this->dataValue());
         } else {
             // @TODO: better error handling
         }
     }
 }
开发者ID:nathancox,项目名称:silverstripe-tagitfield,代码行数:50,代码来源:TagItField.php

示例6: saveInto

 /**
  * Save the current value of this MultiSelectField into a DataObject.
  * If the field it is saving to is a has_many or many_many relationship,
  * it is saved by setByIDList(), otherwise it creates a comma separated
  * list for a standard DB text/varchar field.
  *
  * @param DataObject $record The record to save into
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldName = $this->getName();
     if (empty($fieldName) || empty($record)) {
         return;
     }
     $relation = $record->hasMethod($fieldName) ? $record->{$fieldName}() : null;
     // Detect DB relation or field
     $items = $this->getValueArray();
     if ($relation instanceof Relation) {
         // Save ids into relation
         $relation->setByIDList($items);
     } elseif ($record->hasField($fieldName)) {
         // Save dataValue into field
         $record->{$fieldName} = $this->stringEncode($items);
     }
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:25,代码来源:MultiSelectField.php

示例7: getFieldsForObj

 /**
  * Returns all fields on the object which should be shown
  * in the output. Can be customised through {@link self::setCustomFields()}.
  *
  * @todo Allow for custom getters on the processed object (currently filtered through inheritedDatabaseFields)
  * @todo Field level permission checks
  *
  * @param DataObjectInterface|DataObject $obj
  * @return array
  */
 protected function getFieldsForObj($obj)
 {
     $dbFields = array();
     // if custom fields are specified, only select these
     if (is_array($this->customFields)) {
         foreach ($this->customFields as $fieldName) {
             // @todo Possible security risk by making methods accessible - implement field-level security
             if ($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) {
                 $dbFields[$fieldName] = $fieldName;
             }
         }
     } else {
         // by default, all database fields are selected
         $dbFields = $obj->db();
     }
     if (is_array($this->customAddFields)) {
         foreach ($this->customAddFields as $fieldName) {
             // @todo Possible security risk by making methods accessible - implement field-level security
             if ($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) {
                 $dbFields[$fieldName] = $fieldName;
             }
         }
     }
     // add default required fields
     $dbFields = array_merge($dbFields, array('ID' => 'Int'));
     if (is_array($this->removeFields)) {
         $dbFields = array_diff_key($dbFields, array_combine($this->removeFields, $this->removeFields));
     }
     return $dbFields;
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:40,代码来源:DataFormatter.php


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