本文整理汇总了PHP中DataObject::hasMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::hasMethod方法的具体用法?PHP DataObject::hasMethod怎么用?PHP DataObject::hasMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataObject
的用法示例。
在下文中一共展示了DataObject::hasMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
public function convert(DataObject $object)
{
if ($object->hasMethod('toFilteredMap')) {
return Convert::raw2json($object->toFilteredMap());
}
return Convert::raw2json($object->toMap());
}
示例2: walkRelationshipChain
protected function walkRelationshipChain(DataObject $from, ArrayList $list, array $parts, $lastPart, $lastItem)
{
$part = array_shift($parts);
if (!$from->hasMethod($part)) {
// error, no such part of relationship chain
return false;
}
if (count($parts)) {
foreach ($from->{$part}() as $item) {
$this->walkRelationshipChain($item, $list, $parts, $part, $item);
}
} else {
$images = $from->{$part}()->toNestedArray();
// mark the images with a source from relationship and ID
/** @var Image $image */
foreach ($images as &$image) {
if ($lastItem instanceof Variation) {
$options = $lastItem->Options();
foreach ($options as $option) {
$image['ProductID'] = $lastItem->Product()->ID;
$image['VariationID'] = $lastItem->ID;
$image['OptionID'] = $option->ID;
$image['AttributeID'] = $option->AttributeID;
}
}
}
$list->merge(new ArrayList($images));
}
return true;
}
示例3: convertDataObjectToArray
/**
* @param DataObject $obj
* @param array $config
* @return array|bool
*/
public function convertDataObjectToArray(DataObject $obj, $config = array())
{
$content = array();
$allowedFields = $obj instanceof FlexibleDataFormatterInterface ? $obj->getAllowedFields($config) : array_keys($obj->db());
foreach ($allowedFields as $fieldName) {
if ($obj->hasMethod($fieldName)) {
$fieldValue = $obj->{$fieldName}();
} else {
$fieldValue = $obj->dbObject($fieldName);
if (is_null($fieldValue)) {
$fieldValue = $obj->{$fieldName};
}
}
if ($fieldValue instanceof Object) {
switch (get_class($fieldValue)) {
case 'Boolean':
$content[$fieldName] = (bool) $fieldValue->getValue();
break;
case 'PrimaryKey':
$content[$fieldName] = $obj->{$fieldName};
break;
case 'HTMLText':
$content[$fieldName] = $fieldValue->forTemplate();
break;
default:
$content[$fieldName] = $fieldValue->getValue();
break;
}
} else {
$content[$fieldName] = $fieldValue;
}
}
if ($obj instanceof FlexibleDataFormatterInterface) {
foreach ($obj->getAllowedHasOneRelations($config) as $relName) {
if ($obj->{$relName . 'ID'}) {
$content[$relName] = $this->convertDataObjectToArray($obj->{$relName}(), $config);
}
}
foreach ($obj->getAllowedHasManyRelations($config) as $relName) {
$items = $obj->{$relName}();
if ($items instanceof SS_List && count($items) > 0) {
$content[$relName] = array();
foreach ($items as $item) {
$content[$relName][] = $this->convertDataObjectToArray($item, $config);
}
}
}
foreach ($obj->getAllowedManyManyRelations($config) as $relName) {
$items = $obj->{$relName}();
if ($items instanceof SS_List && count($items) > 0) {
$content[$relName] = array();
foreach ($items as $item) {
$content[$relName][] = $this->convertDataObjectToArray($item, $config);
}
}
}
}
return $content;
}
开发者ID:helpfulrobot,项目名称:heyday-silverstripe-flexibledataformatters,代码行数:64,代码来源:FlexibleDataFormatter.php
示例4: convert
public function convert(DataObject $object)
{
if ($object->hasMethod('toFilteredMap')) {
$data = $object->toFilteredMap();
} else {
$data = $object->toMap();
}
$converter = new ArrayToXml('item');
return $converter->convertArray($data);
}
示例5: getColumnContent
/**
* @param GridField $gridField
* @param DataObject $record
* @param string $columnName
*
* @return string - the HTML for the column
*/
public function getColumnContent($gridField, $record, $columnName)
{
// No permission checks, handled through GridFieldDetailForm,
// which can make the form readonly if no edit permissions are available.
if ($record->hasMethod("CMSEditLink")) {
$data = new ArrayData(array('Link' => Controller::join_links($record->CMSEditLink())));
return $data->renderWith('GridFieldEditButtonInSiteTree');
} else {
return parent::getColumnContent($gridField, $record, $columnName);
}
}
示例6: getPlaceholderImageRecursive
/**
* Recursivly search for a PlaceholderImage.
*
* @param DataObject $object
* @return Image | null
*/
protected function getPlaceholderImageRecursive(DataObject $object)
{
if ($object->has_one('PlaceholderImage')) {
$image = $object->getComponent('PlaceholderImage');
if ($image->exists()) {
return $image;
}
}
$parentObject = $object->hasMethod('Parent') ? $object->Parent() : null;
return isset($parentObject) && $parentObject->exists() ? $this->getPlaceholderImageRecursive($parentObject) : null;
}
开发者ID:helpfulrobot,项目名称:studiobonito-silverstripe-imagefunctions,代码行数:17,代码来源:PlaceholderImagePageExtension.php
示例7: trackInteraction
public function trackInteraction($interactionType, DataObject $item = null, Member $user = null)
{
if ($user == null) {
$user = Member::currentUserID();
}
// Create a new user interaction object to track the page count.
$link = '#';
if ($item->hasMethod('RelativeLink')) {
$link = $item->RelativeLink();
}
$interaction = UserInteraction::create(array('Title' => $item->Title, 'Type' => $interactionType, 'ItemClass' => get_class($item), 'ItemID' => $item->ID, 'URL' => $link, 'MemberID' => $user));
$interaction->write();
}
示例8: setValue
/**
* Sets the value of the form field.
*
* @param mixed $value If numeric, get the file by ID, otherwise, introspect the $data object
* @param DataObject $data The record associated with the parent form
*/
public function setValue($value = null, $data = null)
{
if (!is_numeric($value)) {
if ($id = Controller::curr()->getRequest()->requestVar($this->Name() . "ID")) {
$value = $id;
} elseif (!$value && $data && $data instanceof DataObject && $data->hasMethod($this->name)) {
$funcName = $this->name;
if ($obj = $data->{$funcName}()) {
if ($obj instanceof File || $obj instanceof S3File) {
$value = $obj->ID;
}
}
}
}
parent::setValue($value, $data);
}
示例9: getDefinitionFor
/**
* Gets the workflow definition for a given dataobject, if there is one
*
* Will recursively query parent elements until it finds one, if available
*
* @param DataObject $dataObject
*/
public function getDefinitionFor(DataObject $dataObject)
{
if ($dataObject->hasExtension('WorkflowApplicable') || $dataObject->hasExtension('FileWorkflowApplicable')) {
if ($dataObject->WorkflowDefinitionID) {
return DataObject::get_by_id('WorkflowDefinition', $dataObject->WorkflowDefinitionID);
}
if ($dataObject->ParentID) {
return $this->getDefinitionFor($dataObject->Parent());
}
if ($dataObject->hasMethod('workflowParent')) {
$obj = $dataObject->workflowParent();
if ($obj) {
return $this->getDefinitionFor($obj);
}
}
}
return null;
}
示例10: model2cacheable
/**
*
* Dynamically augments any $cacheableClass object with
* methods and properties of $model.
*
* Warning: Uses PHP magic methods __get() and __set().
*
* @param DataObject $model
* @param string $cacheableClass
* @return ViewableData $cacheable
*/
public static function model2cacheable(DataObject $model, $cacheableClass = null)
{
if (!$cacheableClass) {
$cacheableClass = "Cacheable" . $model->ClassName;
}
$cacheable = $cacheableClass::create();
$cacheable_fields = $cacheable->get_cacheable_fields();
foreach ($cacheable_fields as $field) {
$cacheable->__set($field, $model->__get($field));
}
$cacheable_functions = $cacheable->get_cacheable_functions();
foreach ($cacheable_functions as $function) {
/*
* Running tests inside a project with its own YML config for
* cacheable_fields and cacheable_functions will fail if we don't check first
*/
if ($model->hasMethod($function)) {
$cacheable->__set($function, $model->{$function}());
}
}
return $cacheable;
}
示例11: saveInto
/**
* Save the results into the form
* Calls function $record->onChange($items) before saving to the assummed
* Component set.
*/
function saveInto(DataObject $record)
{
// Detect whether this field has actually been updated
if ($this->value !== 'unchanged') {
$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 = 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: getWriterFor
/**
* Gets a writer for a DataObject
*
* If the field already has a value, a writer is created matching that
* identifier. Otherwise, a new writer is created based on either
*
* - The $type passed in
* - whether the $object class specifies a prefered storage type via
* getEffectiveContentStore
* - what the `defaultStore` is set to for the content service
*
*
* @param DataObject $object
* The object to get a writer for
* @param String $field
* The field being written to
* @param String $type
* Explicitly state what the content store type will be
* @return ContentWriter
*/
public function getWriterFor(DataObject $object = null, $field = 'FilePointer', $type = null)
{
if ($object && $field && $object->hasField($field)) {
$val = $object->{$field};
if (strlen($val)) {
$reader = $this->getReader($val);
if ($reader && $reader->isReadable()) {
return $reader->getWriter();
}
}
}
if (!$type) {
// specifically expecting to be handling File objects, but allows other
// objects to play too
if ($object && $object->hasMethod('getEffectiveContentStore')) {
$type = $object->getEffectiveContentStore();
} else {
$type = $this->defaultStore;
}
}
// looks like we're getting a writer with no underlying file (as yet)
return $this->getWriter($type);
}
示例13: getFileEditValidator
/**
* Determines the validator to use for the edit form
* @example 'getCMSValidator'
*
* @param DataObject $file File context to generate validator from
* @return Validator Validator object
*/
public function getFileEditValidator(DataObject $file)
{
// Empty validator
if (empty($this->fileEditValidator)) {
return null;
}
// Validator instance
if ($this->fileEditValidator instanceof Validator) {
return $this->fileEditValidator;
}
// Method to call on the given file
if ($file->hasMethod($this->fileEditValidator)) {
return $file->{$this->fileEditValidator}();
}
user_error("Invalid value for UploadField::fileEditValidator", E_USER_ERROR);
}
示例14: markChildren
/**
* Mark all children of the given node that match the marking filter.
*
* @param DataObject $node Parent node
* @param mixed $context
* @param string $childrenMethod The name of the instance method to call to get the object's list of children
* @param string $numChildrenMethod The name of the instance method to call to count the object's children
* @return DataList
*/
public function markChildren($node, $context = null, $childrenMethod = "AllChildrenIncludingDeleted", $numChildrenMethod = "numChildren")
{
if ($node->hasMethod($childrenMethod)) {
$children = $node->{$childrenMethod}($context);
} else {
user_error(sprintf("Can't find the method '%s' on class '%s' for getting tree children", $childrenMethod, get_class($node)), E_USER_ERROR);
}
$node->markExpanded();
if ($children) {
foreach ($children as $child) {
$markingMatches = $this->markingFilterMatches($child);
if ($markingMatches) {
// Mark a child node as unexpanded if it has children and has not already been expanded
if ($child->{$numChildrenMethod}() && !$child->isExpanded()) {
$child->markUnexpanded();
} else {
$child->markExpanded();
}
$this->markedNodes[$child->ID] = $child;
}
}
}
return $children;
}
示例15: getObjectRelationQuery
/**
* @param DataObject $obj
* @param array $params
* @param int|array $sort
* @param int|array $limit
* @param string $relationName
* @return SQLQuery|boolean
*/
protected function getObjectRelationQuery($obj, $params, $sort, $limit, $relationName)
{
if ($obj->hasMethod("{$relationName}Query")) {
// @todo HACK Switch to ComponentSet->getQuery() once we implement it (and lazy loading)
$query = $obj->{"{$relationName}Query"}(null, $sort, null, $limit);
$relationClass = $obj->{"{$relationName}Class"}();
} elseif ($relationClass = $obj->many_many($relationName)) {
// many_many() returns different notation
$relationClass = $relationClass[1];
$query = $obj->getManyManyComponentsQuery($relationName);
} elseif ($relationClass = $obj->has_many($relationName)) {
$query = $obj->getComponentsQuery($relationName);
} elseif ($relationClass = $obj->has_one($relationName)) {
$query = null;
} else {
return false;
}
// get all results
return $this->getSearchQuery($relationClass, $params, $sort, $limit, $query);
}