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


PHP DataObjectInterface类代码示例

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


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

示例1: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if ($this->name) {
         $value = $this->dataValue();
         $file = null;
         if ($value['id']) {
             $file = CloudinaryFile::get()->byID($value['id']);
         }
         if (!$file) {
             $file = new CloudinaryFile();
         }
         if ($value['resource_type'] == 'image') {
             $file->ClassName = 'CloudinaryImage';
         }
         if ($value['url']) {
             $file->update(array('CloudinaryURL' => $value['url'], 'Title' => $value['title'], 'Size' => $value['size'], 'FileName' => $value['filename'], 'ResourceType' => $value['resource_type'], 'Height' => (int) $value['height'], 'Width' => (int) $value['width'], 'Format' => $value['format']));
             $file->write();
             $record->setCastedField($this->name . 'ID', $file->ID);
         } else {
             if ($file->exists()) {
                 $file->delete();
             }
             $record->setCastedField($this->name . 'ID', 0);
         }
     }
 }
开发者ID:silverstripers,项目名称:cloudinary,代码行数:26,代码来源:CloudinaryUpload.php

示例2: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     $schemas = $record->getSchemas();
     $value = $this->Value();
     $metadata = array();
     foreach ($schemas as $schema) {
         $metadata[$schema->Name] = array();
         $fields = $schema->getFormFields();
         $namesMap = array();
         foreach ($fields as $field) {
             $brPos = strrpos($field->getName(), '[');
             $name = substr($field->getName(), $brPos + 1, -1);
             $namesMap[$field->getName()] = $name;
         }
         if (isset($value[$schema->Name])) {
             foreach ($fields as $field) {
                 $fName = $field->getName();
                 $sName = $namesMap[$fName];
                 if (array_key_exists($sName, $value[$schema->Name])) {
                     $field->setValue($value[$schema->Name][$sName], $value[$schema->Name]);
                 } else {
                     $field->setValue(null);
                 }
             }
         }
         foreach ($fields as $field) {
             $name = $namesMap[$field->getName()];
             $schemaField = $schema->Fields()->find('Name', $name);
             $toSave = $schemaField->processBeforeWrite($field->dataValue(), $record);
             $metadata[$schema->Name][$name] = $toSave;
         }
     }
     $record->{$this->name} = serialize($metadata);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-metadata,代码行数:34,代码来源:MetadataSetField.php

示例3: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     $isNew = !$record->exists();
     parent::saveInto($record);
     // if we're dealing with an unsaved record, we have to rebuild the relation list
     // with the proper meny_many_extraFields attributes (eg. the sort order)
     if ($isNew) {
         // we have to grab the raw post data as the data is in the right order there.
         // this is kind of a hack, but we simply lack the information about the client-side sorting otherwise
         if (isset($_POST[$this->name]) && isset($_POST[$this->name]['Files']) && is_array($_POST[$this->name]['Files'])) {
             $idList = $_POST[$this->name]['Files'];
         } else {
             // take the ItemIDs as a fallback
             $idList = $this->getItemIDs();
         }
         $sortColumn = $this->getSortColumn();
         $relationName = $this->getName();
         if ($relationName && $record->many_many($relationName) !== null && ($list = $record->{$relationName}())) {
             $arrayList = $list->toArray();
             foreach ($arrayList as $item) {
                 $list->remove($item);
                 $list->add($item, array($sortColumn => array_search($item->ID, $idList) + 1));
             }
         }
     }
 }
开发者ID:vinstah,项目名称:body,代码行数:26,代码来源:SortableUploadField.php

示例4: saveInto

 public function saveInto(\DataObjectInterface $record)
 {
     if (!$this->dataValue()) {
         return;
     }
     $record->setCastedField('AdministrativeArea', BelgianGeoUtils::getProvinceRegion($this->dataValue()));
     return parent::saveInto($record);
 }
开发者ID:helpfulrobot,项目名称:lekoala-silverstripe-geotools,代码行数:8,代码来源:BelgianProvinceField.php

示例5: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     $value = $this->value;
     $fieldName = $this->getName();
     if ($record->has_one($fieldName)) {
         $record->{$fieldName . 'ID'} = $value;
     }
     return $this;
 }
开发者ID:nathancox,项目名称:silverstripe-modifieduploadfield,代码行数:9,代码来源:ModifiedUploadField.php

示例6: saveInto

 /**
  * SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
  * initiates a new LinkField class object to pass through the values to the setter method.
  */
 function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create('AlternativeField', array("SelectedValue" => $this->fieldSelectedValue->Value(), "AlternativeValue" => $this->fieldAlternativeValue->Value()));
     } else {
         $dataObject->{$fieldName}->setSelectedValue($this->fieldSelectedValue->Value());
         $dataObject->{$fieldName}->setAlternativeValue($this->fieldAlternativeValue->Value());
     }
 }
开发者ID:helpfulrobot,项目名称:leapfrognz-alternative-field,代码行数:14,代码来源:AlternativeFormField.php

示例7: saveInto

 /**
  * SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
  * initiates a new LinkField class object to pass through the values to the setter method.
  */
 public function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create('LinkField', array("PageID" => $this->fieldPageID->Value(), "CustomURL" => $this->fieldCustomURL->Value()));
     } else {
         $dataObject->{$fieldName}->setPageID($this->fieldPageID->Value());
         $dataObject->{$fieldName}->setCustomURL($this->fieldCustomURL->Value());
     }
 }
开发者ID:helpfulrobot,项目名称:lrc-silverstripe-link-field,代码行数:14,代码来源:LinkFormField.php

示例8: saveInto

 public function saveInto(\DataObjectInterface $record)
 {
     if ($this->name) {
         $castingHelper = $record->castingHelper($this->name);
         if ($castingHelper == 'Boolean') {
             $record->setCastedField($this->name, $this->getBooleanValue());
         } else {
             $record->setCastedField($this->name, $this->dataValue());
         }
     }
 }
开发者ID:lekoala,项目名称:silverstripe-form-extras,代码行数:11,代码来源:YesNoOptionsetField.php

示例9: saveInto

 /**
  * Save value to dataobject
  *
  * @see forms/CheckboxSetField::saveInto()
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldName = $this->getName();
     $valueArray = is_array($this->value) && isset($this->value[0]) && strpos($this->value[0], ',') ? explode(',', $this->value[0]) : $this->value;
     if ($fieldName && ($record->has_many($fieldName) || $record->many_many($fieldName))) {
         // Set related records
         $record->{$fieldName}()->setByIDList($valueArray);
     } else {
         $record->{$fieldName} = is_array($this->value) ? implode(',', $this->value) : $this->value;
         $record->write();
     }
 }
开发者ID:swilsonalfa,项目名称:silverstripe-multiselectfield,代码行数:17,代码来源:MultiSelectField.php

示例10: saveInto

 function saveInto(DataObjectInterface $record)
 {
     $fieldName = $this->name;
     $fieldNameID = $fieldName . 'ID';
     $record->{$fieldNameID} = 0;
     if ($val = $this->value[$this->htmlListField]) {
         if ($val != 'undefined') {
             $record->{$fieldNameID} = $val;
         }
     }
     $record->write();
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:12,代码来源:HasOneComplexTableField.php

示例11: saveInto

 public function saveInto(\DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
     $value = $this->dataValue();
     if ($relation) {
         // TODO: Save to relation
     } else {
         if (is_array($value)) {
             $this->value = json_encode(array_values($value));
         }
     }
     parent::saveInto($record);
 }
开发者ID:lekoala,项目名称:silverstripe-form-extras,代码行数:14,代码来源:TableFieldCommon.php

示例12: __construct

 /**
  * @param string $name
  * @param string $title
  * @param DataObjectInterface $object
  * @param string $sort
  * @param SS_List $source
  * @param string $titleField
  */
 public function __construct($name, $title, DataObjectInterface $object, $sort = false, SS_List $source = null, $titleField = 'Title')
 {
     $this->setSort($sort);
     if ($object->many_many($name)) {
         $dataSource = $object->{$name}();
         // Check if we're dealing with an UnsavedRelationList
         $unsaved = $dataSource instanceof UnsavedRelationList;
         // Store the relation's class name
         $class = $dataSource->dataClass();
         $this->dataClass = $class;
         // Sort the items
         if ($this->getSort()) {
             $dataSource = $dataSource->sort($this->getSort());
         }
         // If we're dealing with an UnsavedRelationList, it'll be empty, so we
         // can skip this and just use an array of all available items
         if ($unsaved) {
             $dataSource = $class::get()->map()->toArray();
         } else {
             // If we've been given a list source, filter on those IDs only.
             if ($source) {
                 $dataSource = $dataSource->filter('ID', $source->column('ID'));
             }
             // Start building the data source from scratch. Currently selected items first,
             // in the correct sort order
             $dataSource = $dataSource->map('ID', $titleField)->toArray();
             // Get the other items
             $theRest = $class::get();
             // Exclude items that we've already found
             if (!empty($dataSource)) {
                 $theRest = $theRest->exclude('ID', array_keys($dataSource));
             }
             // If we've been given a list source, filter on those IDs only
             if ($source) {
                 $theRest = $theRest->filter('ID', $source->column('ID'));
             }
             $theRest = $theRest->map('ID', $titleField)->toArray();
             // ... we then add the remaining items in whatever order they come
             $dataSource = $dataSource + $theRest;
         }
     } elseif ($source instanceof SS_List) {
         $dataSource = $source->map('ID', $titleField)->toArray();
     } elseif (is_array($source) && ArrayLib::is_associative($source)) {
         $dataSource = $source;
     } else {
         user_error('MultiSelectField::__construct(): MultiSelectField only supports many-to-many relations');
     }
     parent::__construct($name, $title, $dataSource, '', null, true);
 }
开发者ID:helpfulrobot,项目名称:fullscreeninteractive-silverstripe-multiselectfield,代码行数:57,代码来源:MultiSelectField.php

示例13: saveInto

 /**
  * 30/06/2009 - Enhancement:
  * SaveInto checks if set-methods are available and use them
  * instead of setting the values in the money class directly. saveInto
  * initiates a new Money class object to pass through the values to the setter
  * method.
  *
  */
 function saveInto(DataObjectInterface $dataObject)
 {
     $fieldName = $this->name;
     if ($dataObject->hasMethod("set{$fieldName}")) {
         $dataObject->{$fieldName} = DBField::create_field('WTLink', array("Type" => $this->fieldType->Value(), "Internal" => $this->internalField->Value(), "External" => $this->externalField->Value(), "Email" => $this->emailField->Value(), "File" => $this->fileField->Value(), "TargetBlank" => $this->targetBlankField->Value()));
     } else {
         if (!empty($dataObject->{$fieldName})) {
             $dataObject->{$fieldName}->setType($this->fieldType->Value());
             $dataObject->{$fieldName}->setInternal($this->internalField->Value());
             $dataObject->{$fieldName}->setExternal($this->externalField->Value());
             $dataObject->{$fieldName}->setEmail($this->emailField->Value());
             $dataObject->{$fieldName}->setFile($this->fileField->Value());
             $dataObject->{$fieldName}->setTargetBlank($this->targetBlankField->Value());
         }
     }
 }
开发者ID:helpfulrobot,项目名称:webtorque7-link-field,代码行数:24,代码来源:WTLinkField.php

示例14: handleSave

 /**
  * Called when a grid field is saved, converts the StatefulGridFieldList to a RelationList
  * @param {GridField} $field
  * @param {DataObjectInterface} $record
  */
 public function handleSave(GridField $grid, DataObjectInterface $record)
 {
     $list = $grid->getList();
     if ($list instanceof StatefulGridFieldList) {
         $relationName = $list->getRelationName();
         if ($record->has_many($relationName)) {
             $list->changeToList($record->getComponents($list->getRelationName()));
         } else {
             if ($record->many_many($relationName)) {
                 $list->changeToList($record->getManyManyComponents($list->getRelationName()));
             } else {
                 throw new InvalidArgumentException('Record does not have a has_many or many_many relationship called "' . $relationName . '"', null, null);
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-statefulunsavedlist,代码行数:21,代码来源:StatefulGridFieldListSaveHandler.php

示例15: __construct

 public function __construct($controller, $name, DataObjectInterface $object)
 {
     $this->object = $object;
     $fields = $object->getFrontEndFields(array(get_class($object) => $object));
     $fields->push(new HiddenField("ID", "ID"));
     $actions = new FieldList(new FormAction("save", "Save " . $object->i18n_singular_name()));
     parent::__construct($controller, $name, $fields, $actions);
     $object->extend('updateEditComponentForm', $this);
     if ($this->object->isInDB()) {
         $this->loadDataFrom($this->object);
     }
     //all fields are required
     if (!$this->validator) {
         $this->setValidator(new RequiredFields(array_keys($fields->saveableFields())));
     }
 }
开发者ID:helpfulrobot,项目名称:burnbright-silverstripe-componenteditor,代码行数:16,代码来源:EditComponentForm.php


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