本文整理汇总了PHP中UploadField::saveInto方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadField::saveInto方法的具体用法?PHP UploadField::saveInto怎么用?PHP UploadField::saveInto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadField
的用法示例。
在下文中一共展示了UploadField::saveInto方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
}
}
}
示例2: 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 many_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();
}
// Get general info about this relation (if possible)
$sortColumn = $this->getSortColumn();
$relationName = $this->getName();
if ($relationName) {
// Get relation type.
$isManyMany = $record->many_many($relationName) !== null;
// Using "null" here since we know it will properly return null if there is no many_many component by this name.
$isHasMany = (bool) $record->has_many($relationName);
// TODO: Return to more strict check of === null here when SS framework issue is mainstream: https://github.com/silverstripe/silverstripe-framework/pull/4130
if ($isManyMany || $isHasMany) {
// Get list from that relation and begin to manipulate it.
$list = $record->{$relationName}();
$arrayList = $list->toArray();
foreach ($arrayList as $item) {
// Get the specified sort order for this item (offset from posted 0 index).
$sortOrder = array_search($item->ID, $idList) + 1;
// The method by which we update this relation varies depending on the relationship type...
if ($isManyMany) {
// Alter data in the pivot table.
$list->remove($item);
$list->add($item, array($sortColumn => $sortOrder));
} elseif ($isHasMany) {
// Just update information in the sort field directly on the item itself.
$item->{$sortColumn} = $sortOrder;
$item->write();
}
}
}
}
}
}
示例3: saveInto
/**
* Called before the dataobject record is saved.
* @param DataObjectInterface $record The record.
* @return [type] [description]
*/
public function saveInto(DataObjectInterface $record)
{
// On the dataobject record set the lat, long, zoom fields (names specified by the dev at
// time of construction) to the values of the lat long and zoom child fields of this class.
$record->setCastedField($this->latFieldName, $this->latField->dataValue());
$record->setCastedField($this->lngFieldName, $this->lngField->dataValue());
$record->setCastedField($this->zoomFieldName, $this->zoomField->dataValue());
// Do parent stuff as normal.
return parent::saveInto($record);
}