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); } } }
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()); } } }
public function saveInto(\DataObjectInterface $record) { if (!$this->dataValue()) { return; } $record->setCastedField('AdministrativeArea', BelgianGeoUtils::getProvinceRegion($this->dataValue())); return parent::saveInto($record); }
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); } }
/** * Method to save this form field into the given data object. * By default, makes use of $this->dataValue() * * @param DataObjectInterface $record DataObject to save data into */ public function saveInto(DataObjectInterface $record) { if ($this->name) { $record->setCastedField($this->name, $this->dataValue()); } }
/** * Take the latitude/longitude fields and save them to the DataObject. * {@inheritdoc} */ public function saveInto(DataObjectInterface $record) { $record->setCastedField($this->childFieldName('Latitude'), $this->latField->dataValue()); $record->setCastedField($this->childFieldName('Longitude'), $this->lngField->dataValue()); $record->setCastedField($this->childFieldName('Zoom'), $this->zoomField->dataValue()); return $this; }
/** * Save * * @param DataObjectInterface $record */ public function saveInto(DataObjectInterface $record) { $value = $this->value; /** * If the $this->value has multiple values. */ if (is_array($value)) { $combinedArray = array('selector' => $this->selector); if (is_array($this->fields)) { foreach ($this->fields as $key => $item) { $combinedArray = array_merge($combinedArray, array($key => $value[$key])); } } $return = json_encode($combinedArray); } else { $return = $value; } /** * If name exists: * Save content from a form into a field on this data object. */ if ($this->name) { $record->setCastedField($this->name, $return); } }
function saveInto(DataObjectInterface $record) { $relation = $this->getRelation(); if ($relation) { $submittedTags = explode($this->getDelimiter(), $this->value); $tagClass = $this->getTagClass(); $tagLabelField = $this->getTagLabelField(); $tagObjects = DataList::create($tagClass)->filter($tagLabelField, $submittedTags); if ($tagObjects->Count() < count($submittedTags)) { // filter out the tags that exist already $tagsAsKeys = array_flip($submittedTags); foreach ($tagObjects as $tag) { $label = $tag->{$tagLabelField}; unset($tagsAsKeys[$label]); } foreach ($tagsAsKeys as $label => $value) { $tagObject = new $tagClass(); $tagObject->{$tagLabelField} = $label; $tagObject->write(); $tagObjects->add($tagObject); } } $relationList = $this->form->record->{$this->name}(); $oldTags = $relationList->map('ID', $tagLabelField)->toArray(); $relationList->removeAll(); $relationList->addMany($tagObjects->toArray()); if ($this->deleteUnusedTags) { $deletedTags = array_diff($oldTags, $tagObjects->map('ID', $tagLabelField)->toArray()); if (count($deletedTags) > 0) { $relationTable = $relation[4]; foreach ($deletedTags as $id => $title) { $query = new SQLQuery(); $query->select = array('ID', $tagLabelField); $query->from = array($relationTable); $query->where = array("ID = " . $id); $count = $query->Count(); if ($count == 0) { DataObject::delete_by_id($tagClass, $id); } } } } } else { if ($record->hasField($this->name)) { $record->setCastedField($this->name, $this->dataValue()); } else { // @TODO: better error handling } } }
/** * Allow spam flag to be saved to the underlying data record * * @param \DataObjectInterface $record */ public function saveInto(\DataObjectInterface $record) { if (Config::inst()->get('AkismetSpamProtector', 'save_spam')) { $dataValue = $this->getIsSpam() ? 1 : 0; $record->setCastedField($this->name, $dataValue); } }
/** * 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); }