本文整理汇总了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();
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
}
}
}
示例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();
}
}
}
}
}
示例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);
}
}