当前位置: 首页>>代码示例>>PHP>>正文


PHP DataObject::dbObject方法代码示例

本文整理汇总了PHP中DataObject::dbObject方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::dbObject方法的具体用法?PHP DataObject::dbObject怎么用?PHP DataObject::dbObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataObject的用法示例。


在下文中一共展示了DataObject::dbObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getFieldList

 /**
  * Gets the form fields as defined through the metadata
  * on {@link $obj} and the custom parameters passed to FormScaffolder.
  * Depending on those parameters, the fields can be used in ajax-context,
  * contain {@link TabSet}s etc.
  * 
  * @return FieldList
  */
 public function getFieldList()
 {
     $fields = new FieldList();
     // tabbed or untabbed
     if ($this->tabbed) {
         $fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
         $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main"));
     }
     //var_dump($this->obj->db());exit();
     // add database fields
     foreach ($this->obj->db() as $fieldName => $fieldType) {
         if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) {
             continue;
         }
         // @todo Pass localized title
         if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
             $fieldClass = $this->fieldClasses[$fieldName];
             $fieldObject = new $fieldClass($fieldName);
         } else {
             $fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
         }
         $fieldObject->setTitle($this->obj->fieldLabel($fieldName));
         if ($this->tabbed) {
             $fields->addFieldToTab("Root.Main", $fieldObject);
         } else {
             $fields->push($fieldObject);
         }
     }
     return $fields;
 }
开发者ID:helpfulrobot,项目名称:axyr-silverstripe-externaldata,代码行数:38,代码来源:ExternalDataFormScaffolder.php

示例2: getColumnContent

 /**
  *
  * @param \GridField $gridField
  * @param \DataObject $record
  * @param string $columnName
  * @return string|null - the HTML for the column
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     if (!$record instanceof \Payment) {
         return null;
     }
     if (!$record->canRefund()) {
         return null;
     }
     \Requirements::css('omnipay-ui/css/omnipay-ui-cms.css');
     \Requirements::javascript('omnipay-ui/javascript/omnipay-ui-cms.js');
     \Requirements::add_i18n_javascript('omnipay-ui/javascript/lang');
     $infoText = '';
     switch (GatewayInfo::refundMode($record->Gateway)) {
         case GatewayInfo::MULTIPLE:
             $infoText = 'MultiRefundInfo';
             break;
         case GatewayInfo::PARTIAL:
             $infoText = 'SingleRefundInfo';
             break;
         case GatewayInfo::FULL:
             $infoText = 'FullRefundInfo';
             break;
     }
     /** @var \Money $money */
     $money = $record->dbObject('Money');
     /** @var \GridField_FormAction $field */
     $field = \GridField_FormAction::create($gridField, 'RefundPayment' . $record->ID, false, 'refundpayment', array('RecordID' => $record->ID))->addExtraClass('gridfield-button-refund payment-dialog-button')->setAttribute('title', _t('GridFieldRefundAction.Title', 'Refund Payment'))->setAttribute('data-icon', 'button-refund')->setAttribute('data-dialog', json_encode(array('maxAmount' => $money->Nice(), 'maxAmountNum' => $money->getAmount(), 'hasAmountField' => $record->canRefund(null, true), 'infoTextKey' => $infoText, 'buttonTextKey' => 'RefundAmount')))->setDescription(_t('GridFieldRefundAction.Description', 'Refund a captured payment'));
     return $field->Field();
 }
开发者ID:bummzack,项目名称:silverstripe-omnipay-ui,代码行数:36,代码来源:GridFieldRefundAction.php

示例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: getColumnContent

 /**
  *
  * @param \GridField $gridField
  * @param \DataObject $record
  * @param string $columnName
  * @return string|null - the HTML for the column
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     if (!$record instanceof \Payment) {
         return null;
     }
     if (!$record->canVoid()) {
         return null;
     }
     \Requirements::css('omnipay-ui/css/omnipay-ui-cms.css');
     \Requirements::javascript('omnipay-ui/javascript/omnipay-ui-cms.js');
     \Requirements::add_i18n_javascript('omnipay-ui/javascript/lang');
     /** @var \GridField_FormAction $field */
     $field = \GridField_FormAction::create($gridField, 'VoidPayment' . $record->ID, false, 'voidpayment', array('RecordID' => $record->ID))->addExtraClass('gridfield-button-void payment-dialog-button')->setAttribute('title', _t('GridFieldVoidAction.Title', 'Void Payment'))->setAttribute('data-icon', 'button-void')->setAttribute('data-dialog', json_encode(array('maxAmount' => $record->dbObject('Money')->Nice(), 'hasAmountField' => false, 'infoTextKey' => 'VoidInfo', 'buttonTextKey' => 'VoidPayment')))->setDescription(_t('GridFieldVoidAction.Description', 'Void an authorized payment'));
     return $field->Field();
 }
开发者ID:bummzack,项目名称:silverstripe-omnipay-ui,代码行数:22,代码来源:GridFieldVoidAction.php

示例5: getFieldSet

	/**
	 * Gets the form fields as defined through the metadata
	 * on {@link $obj} and the custom parameters passed to FormScaffolder.
	 * Depending on those parameters, the fields can be used in ajax-context,
	 * contain {@link TabSet}s etc.
	 * 
	 * @return FieldSet
	 */
	public function getFieldSet() {
		$fields = new FieldSet();
		
		// tabbed or untabbed
		if($this->tabbed) {
			$fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
			$mainTab->setTitle(_t('SiteTree.TABMAIN', "Main"));
		}
		
		// add database fields
		foreach($this->obj->db() as $fieldName => $fieldType) {
			if($this->restrictFields && !in_array($fieldName, $this->restrictFields)) continue;
			
			// @todo Pass localized title
			if($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
				$fieldClass = $this->fieldClasses[$fieldName];
				$fieldObject = new $fieldClass($fieldName);
			} else {
				$fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
			}
			$fieldObject->setTitle($this->obj->fieldLabel($fieldName));
			if($this->tabbed) {
				$fields->addFieldToTab("Root.Main", $fieldObject);
			} else {
				$fields->push($fieldObject);
			}
		}
		
		// add has_one relation fields
		if($this->obj->has_one()) {
			foreach($this->obj->has_one() as $relationship => $component) {
				if($this->restrictFields && !in_array($relationship, $this->restrictFields)) continue;
				$hasOneField = $this->obj->dbObject("{$relationship}ID")->scaffoldFormField(null, $this->getParamsArray());
				$hasOneField->setTitle($this->obj->fieldLabel($relationship));
				if($this->tabbed) {
					$fields->addFieldToTab("Root.Main", $hasOneField);
				} else {
					$fields->push($hasOneField);
				}
			}
		}
		
		// only add relational fields if an ID is present
		if($this->obj->ID) {
			// add has_many relation fields
			if($this->obj->has_many() && ($this->includeRelations === true || isset($this->includeRelations['has_many']))) {
				foreach($this->obj->has_many() as $relationship => $component) {
					if($this->tabbed) {
						$relationTab = $fields->findOrMakeTab(
							"Root.$relationship", 
							$this->obj->fieldLabel($relationship)
						);
					}
					$relationshipFields = singleton($component)->summaryFields();
					$foreignKey = $this->obj->getComponentJoinField($relationship);
					$ctf = new ComplexTableField(
						$this,
						$relationship,
						$component,
						$relationshipFields,
						"getCMSFields", 
						"$foreignKey = " . $this->obj->ID
					);
					$ctf->setPermissions(TableListField::permissions_for_object($component));
					if($this->tabbed) {
						$fields->addFieldToTab("Root.$relationship", $ctf);
					} else {
						$fields->push($ctf);
					}
				}
			}

			if($this->obj->many_many() && ($this->includeRelations === true || isset($this->includeRelations['many_many']))) {
				foreach($this->obj->many_many() as $relationship => $component) {
					if($this->tabbed) {
						$relationTab = $fields->findOrMakeTab(
							"Root.$relationship", 
							$this->obj->fieldLabel($relationship)
						);
					}

					$relationshipFields = singleton($component)->summaryFields();
					$filterWhere = $this->obj->getManyManyFilter($relationship, $component);
					$filterJoin = $this->obj->getManyManyJoin($relationship, $component);
					$ctf =  new ComplexTableField(
						$this,
						$relationship,
						$component,
						$relationshipFields,
						"getCMSFields", 
						$filterWhere,
						'', 
//.........这里部分代码省略.........
开发者ID:neopba,项目名称:silverstripe-book,代码行数:101,代码来源:FormScaffolder.php

示例6: getFieldList

 /**
  * Gets the form fields as defined through the metadata
  * on {@link $obj} and the custom parameters passed to FormScaffolder.
  * Depending on those parameters, the fields can be used in ajax-context,
  * contain {@link TabSet}s etc.
  *
  * @return FieldList
  */
 public function getFieldList()
 {
     $fields = new FieldList();
     // tabbed or untabbed
     if ($this->tabbed) {
         $fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
         $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main"));
     }
     // add database fields
     foreach ($this->obj->db() as $fieldName => $fieldType) {
         if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) {
             continue;
         }
         // @todo Pass localized title
         if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
             $fieldClass = $this->fieldClasses[$fieldName];
             $fieldObject = new $fieldClass($fieldName);
         } else {
             $fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
         }
         $fieldObject->setTitle($this->obj->fieldLabel($fieldName));
         if ($this->tabbed) {
             $fields->addFieldToTab("Root.Main", $fieldObject);
         } else {
             $fields->push($fieldObject);
         }
     }
     // add has_one relation fields
     if ($this->obj->hasOne()) {
         foreach ($this->obj->hasOne() as $relationship => $component) {
             if ($this->restrictFields && !in_array($relationship, $this->restrictFields)) {
                 continue;
             }
             $fieldName = $component === 'DataObject' ? $relationship : "{$relationship}ID";
             if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
                 $fieldClass = $this->fieldClasses[$fieldName];
                 $hasOneField = new $fieldClass($fieldName);
             } else {
                 $hasOneField = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
             }
             if (empty($hasOneField)) {
                 continue;
             }
             // Allow fields to opt out of scaffolding
             $hasOneField->setTitle($this->obj->fieldLabel($relationship));
             if ($this->tabbed) {
                 $fields->addFieldToTab("Root.Main", $hasOneField);
             } else {
                 $fields->push($hasOneField);
             }
         }
     }
     // only add relational fields if an ID is present
     if ($this->obj->ID) {
         // add has_many relation fields
         if ($this->obj->hasMany() && ($this->includeRelations === true || isset($this->includeRelations['has_many']))) {
             foreach ($this->obj->hasMany() as $relationship => $component) {
                 if ($this->tabbed) {
                     $relationTab = $fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship));
                 }
                 $fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'GridField';
                 $grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create());
                 if ($this->tabbed) {
                     $fields->addFieldToTab("Root.{$relationship}", $grid);
                 } else {
                     $fields->push($grid);
                 }
             }
         }
         if ($this->obj->manyMany() && ($this->includeRelations === true || isset($this->includeRelations['many_many']))) {
             foreach ($this->obj->manyMany() as $relationship => $component) {
                 if ($this->tabbed) {
                     $relationTab = $fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship));
                 }
                 $fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'GridField';
                 $grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create());
                 if ($this->tabbed) {
                     $fields->addFieldToTab("Root.{$relationship}", $grid);
                 } else {
                     $fields->push($grid);
                 }
             }
         }
     }
     return $fields;
 }
开发者ID:miamollie,项目名称:echoAerial,代码行数:94,代码来源:FormScaffolder.php

示例7: processFilterField

 /**
  * @param DataObject $rec           This would normally just be a singleton but we don't want to have to create it over and over
  * @param string     $filterField
  * @param mixed      $filterVal
  * @return array - returns the new filter added
  */
 public function processFilterField($rec, $filterField, $filterVal)
 {
     // First check for VFI fields
     if ($rec->hasExtension('VirtualFieldIndex') && ($spec = $rec->getVFISpec($filterField))) {
         if ($spec['Type'] == VirtualFieldIndex::TYPE_LIST) {
             // Lists have to be handled a little differently
             $f = $rec->getVFIFieldName($filterField) . ':PartialMatch';
             if (is_array($filterVal)) {
                 foreach ($filterVal as &$val) {
                     $val = '|' . $val . '|';
                 }
                 return array($f => $filterVal);
             } else {
                 return array($f => '|' . $filterVal . '|');
             }
         } else {
             // Simples are simple
             $filterField = $rec->getVFIFieldName($filterField);
         }
     }
     // Next check for regular db fields
     if ($rec->dbObject($filterField)) {
         // Is it a range value?
         if (preg_match('/^RANGE\\~(.+)\\~(.+)$/', $filterVal, $m)) {
             $filterField .= ':Between';
             $filterVal = array_slice($m, 1, 2);
         }
         return array($filterField => $filterVal);
     }
     return array();
 }
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-search,代码行数:37,代码来源:FacetHelper.php


注:本文中的DataObject::dbObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。