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


PHP DataObject::db方法代码示例

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


在下文中一共展示了DataObject::db方法的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: 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

示例3: getHTMLImageUrls

 /**
  * Get an array of all image urls in an object's HTML fields
  *
  * @param DataObject $localObject
  * @return array
  */
 protected function getHTMLImageUrls(DataObject $localObject)
 {
     $imageURLs = array();
     // Extract all html images
     foreach ($localObject->db() as $field => $type) {
         if ($type !== 'HTMLText') {
             continue;
         }
         // Find all images
         $htmlValue = Injector::inst()->create('HTMLValue', $localObject->{$field});
         $images = $htmlValue->getElementsByTagName('img');
         if (empty($images)) {
             continue;
         }
         // Extract urls of each image
         foreach ($images as $img) {
             $url = Director::makeRelative($img->getAttribute('src'));
             if (stripos($url, ASSETS_DIR) === 0) {
                 $imageURLs[] = $url;
             }
         }
     }
     return $imageURLs;
 }
开发者ID:tractorcow,项目名称:silverstripe-legacyimport,代码行数:30,代码来源:AssetLinker.php

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

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

示例6: getFieldsForObj

 /**
  * Returns all fields on the object which should be shown
  * in the output. Can be customised through {@link self::setCustomFields()}.
  *
  * @todo Allow for custom getters on the processed object (currently filtered through inheritedDatabaseFields)
  * @todo Field level permission checks
  *
  * @param DataObjectInterface|DataObject $obj
  * @return array
  */
 protected function getFieldsForObj($obj)
 {
     $dbFields = array();
     // if custom fields are specified, only select these
     if (is_array($this->customFields)) {
         foreach ($this->customFields as $fieldName) {
             // @todo Possible security risk by making methods accessible - implement field-level security
             if ($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) {
                 $dbFields[$fieldName] = $fieldName;
             }
         }
     } else {
         // by default, all database fields are selected
         $dbFields = $obj->db();
     }
     if (is_array($this->customAddFields)) {
         foreach ($this->customAddFields as $fieldName) {
             // @todo Possible security risk by making methods accessible - implement field-level security
             if ($obj->hasField($fieldName) || $obj->hasMethod("get{$fieldName}")) {
                 $dbFields[$fieldName] = $fieldName;
             }
         }
     }
     // add default required fields
     $dbFields = array_merge($dbFields, array('ID' => 'Int'));
     if (is_array($this->removeFields)) {
         $dbFields = array_diff_key($dbFields, array_combine($this->removeFields, $this->removeFields));
     }
     return $dbFields;
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:40,代码来源:DataFormatter.php

示例7: writeLanguageObject

 /**
  * Writes the given language object
  *
  * @param DataObject $languageObj Language object to write
  * @param array      $mainRecord  Main record data of the multilingual DataObject
  *
  * @return void 
  * 
  * @author Roland Lehmann <rlehmann@pixeltricks.de>
  * @since 04.01.2012
  */
 public static function writeLanguageObject($languageObj, $mainRecord)
 {
     $record = array();
     foreach ($languageObj->db() as $dbFieldName => $dbFieldType) {
         if (array_key_exists($dbFieldName, $mainRecord)) {
             $record[$dbFieldName] = $mainRecord[$dbFieldName];
         }
     }
     $languageObj->update($record);
     $languageObj->write();
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:22,代码来源:SilvercartLanguageHelper.php


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