本文整理汇总了PHP中DataObjectInterface::hasMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectInterface::hasMethod方法的具体用法?PHP DataObjectInterface::hasMethod怎么用?PHP DataObjectInterface::hasMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataObjectInterface
的用法示例。
在下文中一共展示了DataObjectInterface::hasMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($name, $record, FieldList $fields = null)
{
$this->name = $name;
$this->record = $record;
if (!$fields) {
if ($this->record->hasMethod('getHasOneCMSFields')) {
$fields = $this->record->getHasOneCMSFields($name);
} else {
$fields = $this->record->getCMSFields();
}
if ($fields) {
$fields = $fields->dataFields();
}
}
parent::__construct($fields);
}
开发者ID:helpfulrobot,项目名称:milkyway-silverstripe-hasonecompositefield,代码行数:16,代码来源:HasOneCompositeField.php
示例2: 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());
}
}
示例3: 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());
}
}
示例4: 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);
}
示例5: 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());
}
}
}
示例6: saveInto
/**
* Save the contents of this form into the given data object.
* It will make use of setCastedField() to do this.
*
* @param $dataObject The object to save data into
* @param $fieldList An optional list of fields to process. This can be useful when you have a
* form that has some fields that save to one object, and some that save to another.
*/
function saveInto(DataObjectInterface $dataObject, $fieldList = null)
{
$dataFields = $this->fields->saveableFields();
$lastField = null;
$config = HTMLPurifier_Config::createDefault();
// Remove any CSS or inline styles
$config->set('CSS.AllowedProperties', array());
$purifier = new HTMLPurifier($config);
if ($dataFields) {
foreach ($dataFields as $field) {
// Skip fields that have been excluded
if ($fieldList && is_array($fieldList) && !in_array($field->Name(), $fieldList)) {
continue;
}
$saveMethod = "save{$field->getName()}";
//purify
$value = $field->dataValue();
$class = get_class($field);
if (is_string($value) && ($class == 'TextField' || $class == "TextareaField")) {
$field->setValue($purifier->purify($value));
}
if ($field->getName() == "ClassName") {
$lastField = $field;
} else {
if ($dataObject->hasMethod($saveMethod)) {
$dataObject->{$saveMethod}($field->dataValue());
} else {
if ($field->getName() != "ID") {
$field->saveInto($dataObject);
}
}
}
}
}
if ($lastField) {
$lastField->saveInto($dataObject);
}
}
示例7: 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.
*
* (see @link MoneyFieldTest_CustomSetter_Object for more information)
*/
public function saveInto(DataObjectInterface $dataObject)
{
$fieldName = $this->name;
if ($dataObject->hasMethod("set{$fieldName}")) {
$dataObject->{$fieldName} = DBField::create_field('Money', array("Currency" => $this->fieldCurrency->dataValue(), "Amount" => $this->fieldAmount->dataValue()));
} else {
$dataObject->{$fieldName}->setCurrency($this->fieldCurrency->dataValue());
$dataObject->{$fieldName}->setAmount($this->fieldAmount->dataValue());
}
}
示例8: 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.
*
* (see @link MoneyFieldTest_CustomSetter_Object for more information)
*/
public function saveInto(DataObjectInterface $dataObject)
{
$fieldName = $this->name;
if ($dataObject->hasMethod("set{$fieldName}")) {
$dataObject->{$fieldName} = DBField::create_field('PostCodeLocation', array("Postcode" => $this->fieldPostcode->Value(), "Country" => $this->fieldCountry->Value(), "Latitude" => $this->fieldLatitude->Value(), "Longditude" => $this->fieldLongditude->Value()));
} else {
$dataObject->{$fieldName}->setPostcode($this->fieldPostcode->Value());
$dataObject->{$fieldName}->setCountry($this->fieldCountry->Value());
$dataObject->{$fieldName}->setLatitude($this->fieldLatitude->Value());
$dataObject->{$fieldName}->setLongditude($this->fieldLongditude->Value());
}
}
示例9: saveInto
/**
* Save the contents of this form into the given data object.
* It will make use of setCastedField() to do this.
*
* @param $dataObject The object to save data into
* @param $fieldList An optional list of fields to process. This can be useful when you have a
* form that has some fields that save to one object, and some that save to another.
*/
public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
{
$dataFields = $this->fields->saveableFields();
$lastField = null;
if ($dataFields) {
foreach ($dataFields as $field) {
// Skip fields that have been exlcuded
if ($fieldList && is_array($fieldList) && !in_array($field->getName(), $fieldList)) {
continue;
}
$saveMethod = "save{$field->getName()}";
if ($field->getName() == "ClassName") {
$lastField = $field;
} else {
if ($dataObject->hasMethod($saveMethod)) {
$dataObject->{$saveMethod}($field->dataValue());
} else {
if ($field->getName() != "ID") {
$field->saveInto($dataObject);
}
}
}
}
}
if ($lastField) {
$lastField->saveInto($dataObject);
}
}
示例10: saveInto
/**
* Save the contents of this form into the given data object.
* It will make use of setCastedField() to do this.
*/
function saveInto(DataObjectInterface $dataObject)
{
$dataFields = $this->fields->dataFields();
$lastField = null;
if ($dataFields) {
foreach ($dataFields as $field) {
$saveMethod = "save{$field->Name()}";
if ($field->Name() == "ClassName") {
$lastField = $field;
} else {
if ($dataObject->hasMethod($saveMethod)) {
$dataObject->{$saveMethod}($field->dataValue());
} else {
if ($field->Name() != "ID") {
$field->saveInto($dataObject);
}
}
}
}
}
if ($lastField) {
$lastField->saveInto($dataObject);
}
}
示例11: saveInto
/**
* Save the results into the form
* Calls function $record->onChange($items) before saving to the assummed
* Component set.
*/
public function saveInto(DataObjectInterface $record)
{
// Detect whether this field has actually been updated
if ($this->value !== 'unchanged') {
$items = array();
$fieldName = $this->name;
$saveDest = $record->{$fieldName}();
if (!$saveDest) {
user_error("TreeMultiselectField::saveInto() Field '{$fieldName}' not found on" . " {$record->class}.{$record->ID}", E_USER_ERROR);
}
if ($this->value) {
$items = preg_split("/ *, */", trim($this->value));
}
// Allows you to modify the items on your object before save
$funcName = "onChange{$fieldName}";
if ($record->hasMethod($funcName)) {
$result = $record->{$funcName}($items);
if (!$result) {
return;
}
}
$saveDest->setByIDList($items);
}
}
示例12: 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.
*
* (see @link MoneyFieldTest_CustomSetter_Object for more information)
*/
public function saveInto(DataObjectInterface $dataObject)
{
$fieldName = $this->getName();
if ($dataObject->hasMethod("set{$fieldName}")) {
$dataObject->{$fieldName} = DBField::create_field('Money', array("Currency" => $this->fieldCurrency->dataValue(), "Amount" => $this->fieldAmount->dataValue()));
} else {
$currencyField = "{$fieldName}Currency";
$amountField = "{$fieldName}Amount";
$dataObject->{$currencyField} = $this->fieldCurrency->dataValue();
$dataObject->{$amountField} = $this->fieldAmount->dataValue();
}
}
示例13: saveInto
/**
* Save the current value of this MultiSelectField 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)
{
$fieldName = $this->getName();
if (empty($fieldName) || empty($record)) {
return;
}
$relation = $record->hasMethod($fieldName) ? $record->{$fieldName}() : null;
// Detect DB relation or field
$items = $this->getValueArray();
if ($relation instanceof Relation) {
// Save ids into relation
$relation->setByIDList($items);
} elseif ($record->hasField($fieldName)) {
// Save dataValue into field
$record->{$fieldName} = $this->stringEncode($items);
}
}
示例14: saveInto
/**
* Save the current value of this CheckboxSetField 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 DataObjectInterface $record The record to save into
*/
public function saveInto(DataObjectInterface $record)
{
$fieldname = $this->name;
$relation = $fieldname && $record && $record->hasMethod($fieldname) ? $record->{$fieldname}() : null;
if ($fieldname && $record && $relation && ($relation instanceof RelationList || $relation instanceof UnsavedRelationList)) {
// save the correct values
$idList = array();
if ($this->value) {
$idList = is_array($this->value) ? array_values($this->value) : explode(',', $this->value);
}
$relation->setByIDList($idList);
// put them in the right order
// This may be drastic overkill, this bit is pulled form
// GridFieldOrderable. I suspect we could simplify here?
$ids = $idList;
$items = $list = $relation;
$field = $this->getSortField();
// $items = $list->byIDs($ids)->sort($field);
//
// // Ensure that each provided ID corresponded to an actual object.
// if(count($items) != count($ids)) {
// $this->httpError(404);
// }
// Populate each object we are sorting with a sort value.
$this->populateSortValues($items);
// Generate the current sort values.
$current = $items->map('ID', $field)->toArray();
// Perform the actual re-ordering.
$this->reorderItems($list, $current, $ids);
} elseif ($fieldname && $record) {
$record->{$fieldname} = $this->getStringValue();
}
}
示例15: saveInto
public function saveInto(\DataObjectInterface $record)
{
if ($this->depth == 1) {
// Reset records to write for top-level MultiRecordField.
self::$_new_records_to_write = array();
self::$_existing_records_to_write = array();
self::$_records_to_delete = array();
}
$class_id_field = $this->Value();
if (!$class_id_field) {
return $this;
}
$list = $this->list;
// Workaround for #5775 - Fix bug where ListboxField writes to $record, making
// UnsavedRelationList redundant.
// https://github.com/silverstripe/silverstripe-framework/pull/5775
$relationName = $this->getName();
$relation = $record->hasMethod($relationName) ? $record->{$relationName}() : null;
if ($relation) {
// When ListboxField (or other) has saved a new record in its 'saveInto' function
if ($record->ID && $list instanceof UnsavedRelationList) {
if ($this->config()->enable_patch_5775 === false) {
throw new Exception("ListboxField or another FormField called DataObject::write() when it wasn't meant to on your unsaved record. https://github.com/silverstripe/silverstripe-framework/pull/5775 ---- Enable 'enable_patch_5775' in your config YML against " . __CLASS__ . " to enable a workaround.");
}
if ($relation instanceof ElementalArea) {
// Hack to support Elemental
$relation = $relation->Elements();
} else {
if ($relation instanceof DataObject) {
throw new Exception("Unable to use enable_patch_5775 workaround as \"" . $record->class . "\"::\"" . $relationName . "\"() does not return a DataList.");
}
}
$list = $relation;
}
}
$flatList = array();
if ($list instanceof DataList) {
$flatList = array();
foreach ($list as $r) {
$flatList[$r->ID] = $r;
}
} else {
if (!$list instanceof UnsavedRelationList) {
throw new Exception('Expected SS_List, but got "' . $list->class . '" in ' . __CLASS__);
}
}
$sortFieldName = $this->getSortFieldName();
foreach ($class_id_field as $class => $id_field) {
// Create and add records to list
foreach ($id_field as $idString => $subRecordData) {
if (strpos($idString, 'o-multirecordediting') !== FALSE) {
throw new Exception('Invalid template ID passed in ("' . $idString . '"). This should have been replaced by MultiRecordField.js. Is your JavaScript broken?');
}
$idParts = explode('_', $idString);
$id = 0;
$subRecord = null;
if ($idParts[0] === 'new') {
if (!isset($idParts[1])) {
throw new Exception('Missing ID part of "new_" identifier.');
}
$id = (int) $idParts[1];
if (!$id && $id > 0) {
throw new Exception('Invalid ID part of "new_" identifier. Positive Non-Zero Integers only are accepted.');
}
// New record
$subRecord = $class::create();
} else {
$id = $idParts[0];
// Find existing
$id = (int) $id;
if (!isset($flatList[$id])) {
throw new Exception('Record #' . $id . ' on "' . $class . '" does not exist in this DataList context. (From ID string: ' . $idString . ')');
}
$subRecord = $flatList[$id];
}
// Detect if record was deleted
if (isset($subRecordData['multirecordfield_delete']) && $subRecordData['multirecordfield_delete']) {
if ($subRecord && $subRecord->exists()) {
self::$_records_to_delete[] = $subRecord;
}
continue;
}
// maybetodo(Jake): To improve performance, maybe add 'dumb fields' config where it just gets the fields available
// on an unsaved record and just re-uses them for each instance. Of course
// this means conditional fields based on parent values/db values wont work.
$fields = $this->getRecordDataFields($subRecord);
$fields = $fields->dataFields();
if (!$fields) {
throw new Exception($class . ' is returning 0 fields.');
}
//
foreach ($subRecordData as $fieldName => $fieldData) {
if ($sortFieldName !== $fieldName && !isset($fields[$fieldName]) && strpos($fieldName, '_ClassName') == false) {
// todo(Jake): Say whether its missing the field from getCMSFields or getMultiRecordFields or etc.
throw new Exception('Missing field "' . $fieldName . '" from "' . $subRecord->class . '" fields based on data sent from client. (Could be a hack attempt)');
}
if (isset($fields[$fieldName])) {
$field = $fields[$fieldName];
if (!$field instanceof MultiRecordField) {
$value = $fieldData->value;
//.........这里部分代码省略.........