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


PHP DataObjectInterface::write方法代码示例

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


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

示例1: 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

示例2: 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

示例3: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if ($this->record) {
         // HACK: Use a fake Form object to save data into fields
         $form = new Form($this->record, $this->name . '-form', $this->FieldList(false), new FieldList());
         $form->loadDataFrom($this->value);
         $form->saveInto($this->record);
         // Save extra data into field
         if (count($this->extraData)) {
             $this->record->castedUpdate($this->extraData);
         }
         if (!$this->record->ID && count($this->defaultFromParent)) {
             foreach ($this->defaultFromParent as $pField => $rField) {
                 if (is_numeric($pField)) {
                     if ($this->record->{$rField}) {
                         continue;
                     }
                     $this->record->setCastedField($rField, $record->{$rField});
                 } else {
                     if ($this->record->{$pField}) {
                         continue;
                     }
                     $this->record->setCastedField($rField, $record->{$pField});
                 }
             }
         }
         if (count($this->overrideFromParent)) {
             foreach ($this->overrideFromParent as $pField => $rField) {
                 if (is_numeric($pField)) {
                     $this->record->setCastedField($rField, $record->{$rField});
                 } else {
                     $this->record->setCastedField($rField, $record->{$pField});
                 }
             }
         }
         $this->record->write();
         $fieldName = substr($this->name, -2) == 'ID' ? $this->name : $this->name . 'ID';
         $record->{$fieldName} = $this->record->ID;
         unset($form);
     }
 }
开发者ID:helpfulrobot,项目名称:milkyway-silverstripe-hasonecompositefield,代码行数:41,代码来源:HasOneCompositeField.php

示例4: saveInto

 /**
  * Save the current value of this field 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)
 {
     if ($this->multiple) {
         $fieldname = $this->name;
         $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
         if ($fieldname && $record && $relation && $relation instanceof RelationList) {
             $idList = is_array($this->value) ? array_values($this->value) : array();
             if (!$record->ID) {
                 $record->write();
                 // record needs to have an ID in order to set relationships
                 $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
             }
             $relation->setByIDList($idList);
         } elseif ($fieldname && $record) {
             if ($this->value) {
                 $this->value = str_replace(',', '{comma}', $this->value);
                 $record->{$fieldname} = implode(",", $this->value);
             } else {
                 $record->{$fieldname} = null;
             }
         }
     } else {
         parent::saveInto($record);
     }
 }
开发者ID:normann,项目名称:sapphire,代码行数:33,代码来源:ListboxField.php

示例5: saveInto

 /**
  * Update the permission set associated with $record DataObject
  *
  * @param DataObject $record
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $managedClass = $this->managedClass;
     // Remove all "privileged" permissions if the currently logged-in user is not an admin
     $privilegedPermissions = Permission::config()->privileged_permissions;
     if (!Permission::check('ADMIN')) {
         foreach ($this->value as $id => $bool) {
             if (in_array($id, $privilegedPermissions)) {
                 unset($this->value[$id]);
             }
         }
     }
     // remove all permissions and re-add them afterwards
     $permissions = $record->{$fieldname}();
     foreach ($permissions as $permission) {
         $permission->delete();
     }
     if ($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
         if (!$record->ID) {
             $record->write();
         }
         // We need a record ID to write permissions
         $idList = array();
         if ($this->value) {
             foreach ($this->value as $id => $bool) {
                 if ($bool) {
                     $perm = new $managedClass();
                     $perm->{$this->filterField} = $record->ID;
                     $perm->Code = $id;
                     $perm->write();
                 }
             }
         }
     }
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:41,代码来源:PermissionCheckboxSetField.php

示例6: saveInto

 /**
  * Update the permission set associated with $record DataObject
  *
  * @param DataObject $record
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $managedClass = $this->managedClass;
     // remove all permissions and re-add them afterwards
     $permissions = $record->{$fieldname}();
     foreach ($permissions as $permission) {
         $permission->delete();
     }
     if ($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
         if (!$record->ID) {
             $record->write();
         }
         // We need a record ID to write permissions
         $idList = array();
         if ($this->value) {
             foreach ($this->value as $id => $bool) {
                 if ($bool) {
                     $perm = new $managedClass();
                     $perm->{$this->filterField} = $record->ID;
                     $perm->Code = $id;
                     $perm->write();
                 }
             }
         }
     }
 }
开发者ID:normann,项目名称:sapphire,代码行数:32,代码来源:PermissionCheckboxSetField.php

示例7: saveInto

 function saveInto(\DataObjectInterface $record)
 {
     // If tags are enabled, saving into a relation will not work properly
     if ($this->tags) {
         $fieldname = str_replace('[]', '', $this->name);
         $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
         if ($fieldname && $record && $relation && ($relation instanceof RelationList || $relation instanceof UnsavedRelationList)) {
             $idList = is_array($this->value) ? array_values($this->value) : array();
             if (!$record->ID) {
                 $record->write();
                 // record needs to have an ID in order to set relationships
                 $relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
             }
             $newIdList = array();
             // Tags will be a list of comma separated tags by title
             $class = $relation->dataClass();
             $filterField = 'Title';
             $newList = $class::get()->filter($filterField, $idList);
             $newListMap = $newList->map($filterField, 'ID');
             // Tag will either already exist or need to be created
             foreach ($idList as $id) {
                 if (isset($newListMap[$id])) {
                     $newIdList[] = $newListMap[$id];
                 } else {
                     $obj = new $class();
                     $obj->Title = trim(str_replace(self::SEPARATOR, '', $id));
                     $obj->write();
                     $newIdList[] = $obj->ID;
                 }
             }
             $relation->setByIDList($newIdList);
         } elseif ($fieldname && $record) {
             if ($this->value) {
                 if (is_array($this->value)) {
                     $this->value = implode(self::SEPARATOR, $this->value);
                 }
                 $record->{$fieldname} = $this->value;
             } else {
                 $record->{$fieldname} = null;
             }
         }
     } else {
         return parent::saveInto($record);
     }
 }
开发者ID:helpfulrobot,项目名称:lekoala-silverstripe-form-extras,代码行数:45,代码来源:Select2Field.php


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