本文整理汇总了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);
}
}
}
示例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);
}
示例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));
}
}
}
}
示例4: saveInto
public function saveInto(\DataObjectInterface $record)
{
if (!$this->dataValue()) {
return;
}
$record->setCastedField('AdministrativeArea', BelgianGeoUtils::getProvinceRegion($this->dataValue()));
return parent::saveInto($record);
}
示例5: saveInto
public function saveInto(DataObjectInterface $record)
{
$value = $this->value;
$fieldName = $this->getName();
if ($record->has_one($fieldName)) {
$record->{$fieldName . 'ID'} = $value;
}
return $this;
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
}
示例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();
}
}
示例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();
}
示例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);
}
示例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());
}
}
}
示例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())));
}
}