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


PHP DataObjectInterface::many_many方法代码示例

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


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

示例1: saveInto

 /**
  * Save value to dataobject
  *
  * @see forms/CheckboxSetField::saveInto()
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldName = $this->getName();
     $valueArray = is_array($this->value) && isset($this->value[0]) && strpos($this->value[0], ',') ? explode(',', $this->value[0]) : $this->value;
     if ($fieldName && ($record->has_many($fieldName) || $record->many_many($fieldName))) {
         // Set related records
         $record->{$fieldName}()->setByIDList($valueArray);
     } else {
         $record->{$fieldName} = is_array($this->value) ? implode(',', $this->value) : $this->value;
         $record->write();
     }
 }
开发者ID:swilsonalfa,项目名称:silverstripe-multiselectfield,代码行数:17,代码来源:MultiSelectField.php

示例2: __construct

 /**
  * @param string $name
  * @param string $title
  * @param DataObjectInterface $object
  * @param string $sort
  * @param SS_List $source
  * @param string $titleField
  */
 public function __construct($name, $title, DataObjectInterface $object, $sort = false, SS_List $source = null, $titleField = 'Title')
 {
     $this->setSort($sort);
     if ($object->many_many($name)) {
         $dataSource = $object->{$name}();
         // Check if we're dealing with an UnsavedRelationList
         $unsaved = $dataSource instanceof UnsavedRelationList;
         // Store the relation's class name
         $class = $dataSource->dataClass();
         $this->dataClass = $class;
         // Sort the items
         if ($this->getSort()) {
             $dataSource = $dataSource->sort($this->getSort());
         }
         // If we're dealing with an UnsavedRelationList, it'll be empty, so we
         // can skip this and just use an array of all available items
         if ($unsaved) {
             $dataSource = $class::get()->map()->toArray();
         } else {
             // If we've been given a list source, filter on those IDs only.
             if ($source) {
                 $dataSource = $dataSource->filter('ID', $source->column('ID'));
             }
             // Start building the data source from scratch. Currently selected items first,
             // in the correct sort order
             $dataSource = $dataSource->map('ID', $titleField)->toArray();
             // Get the other items
             $theRest = $class::get();
             // Exclude items that we've already found
             if (!empty($dataSource)) {
                 $theRest = $theRest->exclude('ID', array_keys($dataSource));
             }
             // If we've been given a list source, filter on those IDs only
             if ($source) {
                 $theRest = $theRest->filter('ID', $source->column('ID'));
             }
             $theRest = $theRest->map('ID', $titleField)->toArray();
             // ... we then add the remaining items in whatever order they come
             $dataSource = $dataSource + $theRest;
         }
     } elseif ($source instanceof SS_List) {
         $dataSource = $source->map('ID', $titleField)->toArray();
     } elseif (is_array($source) && ArrayLib::is_associative($source)) {
         $dataSource = $source;
     } else {
         user_error('MultiSelectField::__construct(): MultiSelectField only supports many-to-many relations');
     }
     parent::__construct($name, $title, $dataSource, '', null, true);
 }
开发者ID:helpfulrobot,项目名称:fullscreeninteractive-silverstripe-multiselectfield,代码行数:57,代码来源:MultiSelectField.php

示例3: handleSave

 /**
  * Called when a grid field is saved, converts the StatefulGridFieldList to a RelationList
  * @param {GridField} $field
  * @param {DataObjectInterface} $record
  */
 public function handleSave(GridField $grid, DataObjectInterface $record)
 {
     $list = $grid->getList();
     if ($list instanceof StatefulGridFieldList) {
         $relationName = $list->getRelationName();
         if ($record->has_many($relationName)) {
             $list->changeToList($record->getComponents($list->getRelationName()));
         } else {
             if ($record->many_many($relationName)) {
                 $list->changeToList($record->getManyManyComponents($list->getRelationName()));
             } else {
                 throw new InvalidArgumentException('Record does not have a has_many or many_many relationship called "' . $relationName . '"', null, null);
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-statefulunsavedlist,代码行数:21,代码来源:StatefulGridFieldListSaveHandler.php

示例4: saveInto

 /**
  * Update the permission set associated with $record DataObject
  *
  * @param DataObject $record
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $managedClass = $this->managedClass;
     // Remove all "privileged" permissions if the currently logged-in user is not an admin
     $privilegedPermissions = Permission::config()->privileged_permissions;
     if (!Permission::check('ADMIN')) {
         foreach ($this->value as $id => $bool) {
             if (in_array($id, $privilegedPermissions)) {
                 unset($this->value[$id]);
             }
         }
     }
     // remove all permissions and re-add them afterwards
     $permissions = $record->{$fieldname}();
     foreach ($permissions as $permission) {
         $permission->delete();
     }
     if ($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
         if (!$record->ID) {
             $record->write();
         }
         // We need a record ID to write permissions
         $idList = array();
         if ($this->value) {
             foreach ($this->value as $id => $bool) {
                 if ($bool) {
                     $perm = new $managedClass();
                     $perm->{$this->filterField} = $record->ID;
                     $perm->Code = $id;
                     $perm->write();
                 }
             }
         }
     }
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:41,代码来源:PermissionCheckboxSetField.php

示例5: saveInto

 /**
  * Update the permission set associated with $record DataObject
  *
  * @param DataObject $record
  */
 public function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $managedClass = $this->managedClass;
     // remove all permissions and re-add them afterwards
     $permissions = $record->{$fieldname}();
     foreach ($permissions as $permission) {
         $permission->delete();
     }
     if ($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
         if (!$record->ID) {
             $record->write();
         }
         // We need a record ID to write permissions
         $idList = array();
         if ($this->value) {
             foreach ($this->value as $id => $bool) {
                 if ($bool) {
                     $perm = new $managedClass();
                     $perm->{$this->filterField} = $record->ID;
                     $perm->Code = $id;
                     $perm->write();
                 }
             }
         }
     }
 }
开发者ID:normann,项目名称:sapphire,代码行数:32,代码来源:PermissionCheckboxSetField.php

示例6: saveInto

	public function saveInto(DataObjectInterface $record) {
		if($record->escapeTypeForField($this->name) != 'xml') {
			throw new Exception (
				'HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.'
			);
		}
		
		$linkedPages = array();
		$linkedFiles = array();
		
		$htmlValue = new SS_HTMLValue($this->value);
		
		if(class_exists('SiteTree')) {
			// Populate link tracking for internal links & links to asset files.
			if($links = $htmlValue->getElementsByTagName('a')) foreach($links as $link) {
				$href = Director::makeRelative($link->getAttribute('href'));

				if($href) {
					if(preg_match('/\[sitetree_link id=([0-9]+)\]/i', $href, $matches)) {
						$ID = $matches[1];

						// clear out any broken link classes
						if($class = $link->getAttribute('class')) {
							$link->setAttribute('class', preg_replace('/(^ss-broken|ss-broken$| ss-broken )/', null, $class));
						}

						$linkedPages[] = $ID;
						if(!DataObject::get_by_id('SiteTree', $ID))  $record->HasBrokenLink = true;

					} else if(substr($href, 0, strlen(ASSETS_DIR) + 1) == ASSETS_DIR.'/') {
						$candidateFile = File::find(Convert::raw2sql(urldecode($href)));
						if($candidateFile) {
							$linkedFiles[] = $candidateFile->ID;
						} else {
							$record->HasBrokenFile = true;
						}
					} else if($href == '' || $href[0] == '/') {
						$record->HasBrokenLink = true;
					}
				}
			}
		}
		
		// Resample images, add default attributes and add to assets tracking.
		if($images = $htmlValue->getElementsByTagName('img')) foreach($images as $img) {
			// strip any ?r=n data from the src attribute
			$img->setAttribute('src', preg_replace('/([^\?]*)\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
			if(!$image = File::find($path = urldecode(Director::makeRelative($img->getAttribute('src'))))) {
				if(substr($path, 0, strlen(ASSETS_DIR) + 1) == ASSETS_DIR . '/') {
					$record->HasBrokenFile = true;
				}
				
				continue;
			}
			
			// Resample the images if the width & height have changed.
			$width  = $img->getAttribute('width');
			$height = $img->getAttribute('height');
			
			if($image){
				if($width && $height && ($width != $image->getWidth() || $height != $image->getHeight())) {
					//Make sure that the resized image actually returns an image:
					$resized=$image->ResizedImage($width, $height);
					if($resized)
						$img->setAttribute('src', $resized->getRelativePath());
				}
			}
			
			// Add default empty title & alt attributes.
			if(!$img->getAttribute('alt')) $img->setAttribute('alt', '');
			if(!$img->getAttribute('title')) $img->setAttribute('title', '');
			
			//If the src attribute is not set, then we won't add this to the list:
			if($img->getAttribute('src')){
				// Add to the tracked files.
				$linkedFiles[] = $image->ID;
			}
		}
		
		// Save file & link tracking data.
		if(class_exists('SiteTree')) {
			if($record->ID && $record->many_many('LinkTracking') && $tracker = $record->LinkTracking()) {
			    $tracker->removeByFilter(sprintf('"FieldName" = \'%s\' AND "SiteTreeID" = %d', $this->name, $record->ID));

				if($linkedPages) foreach($linkedPages as $item) {
					$SQL_fieldName = Convert::raw2sql($this->name);
					DB::query("INSERT INTO \"SiteTree_LinkTracking\" (\"SiteTreeID\",\"ChildID\", \"FieldName\")
						VALUES ($record->ID, $item, '$SQL_fieldName')");
				}
			}
		
			if($record->ID && $record->many_many('ImageTracking') && $tracker = $record->ImageTracking()) {
			    $tracker->where(sprintf('"FieldName" = \'%s\' AND "SiteTreeID" = %d', $this->name, $record->ID))->removeAll();

				$fieldName = $this->name;
				if($linkedFiles) foreach($linkedFiles as $item) {
					$tracker->add($item, array('FieldName' => $this->name));
				}
			}
		}
//.........这里部分代码省略.........
开发者ID:redema,项目名称:sapphire,代码行数:101,代码来源:HtmlEditorField.php

示例7: 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 DataObject $record The record to save into
  */
 function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     //check if dataobject has a field name the same as this->name
     if ($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
         $idList = array();
         if ($this->value) {
             foreach ($this->value as $id => $bool) {
                 if ($bool) {
                     $idList[] = $id;
                 }
                 //TODO: include support for setting $record->has_many($this->childsorce) and many_many($this->childsource) values
             }
         }
         $record->{$fieldname}()->setByIDList($idList);
     } elseif ($fieldname && $record) {
         if ($this->value) {
             $record->{$fieldname} = $this->dataValue();
         } else {
             $record->{$fieldname} = '';
         }
     }
 }
开发者ID:helpfulrobot,项目名称:joshkosmala-silverstripe-hierarchicalcheckboxsetfield,代码行数:31,代码来源:HierarchicalCheckboxSetField.php

示例8: saveInto

 /**
  *
  * TO DO: explain how this works or what it does.
  */
 public function saveInto(DataObjectInterface $record)
 {
     if ($this->value !== 'unchanged') {
         $items = array();
         $fieldName = $this->name;
         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;
             }
         }
         if ($fieldName && ($record->has_many($fieldName) || $record->many_many($fieldName))) {
             // Set related records
             $record->{$fieldName}()->setByIDList($items);
         } else {
             $record->{$fieldName} = implode(',', $items);
         }
     }
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce-discount-coupon,代码行数:28,代码来源:DiscountCouponSiteTreeDOD.php

示例9: saveInto

 function saveInto(DataObjectInterface $record)
 {
     $fieldname = $this->name;
     $this->value['Email']['Value'] = 'Email';
     $this->value['Email']['Required'] = 1;
     $value = ArrayLib::invert($this->value);
     if ($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
         $idList = array();
         if ($value) {
             foreach ($value['Value'] as $id => $bool) {
                 if ($bool) {
                     $idList[] = $id;
                 }
             }
         }
         $record->{$fieldname}()->setByIDList($idList);
     } elseif ($fieldname && $record) {
         if ($value) {
             if (is_array($value)) {
                 foreach ($value as $k => $items) {
                     if (is_array($items)) {
                         foreach ($items as $key => $val) {
                             if (!$val) {
                                 unset($value[$k][$key]);
                             } else {
                                 if ($k == 'Value') {
                                     $value[$k][$key] = str_replace(", ", "{comma}", $val);
                                 }
                             }
                         }
                     }
                 }
             }
             foreach ($value as $k => $v) {
                 if ($k == 'Value') {
                     $record->{$fieldname} = implode(",", $v);
                 } else {
                     $record->{$k} = Convert::array2json($v);
                 }
             }
         } else {
             $record->{$fieldname} = '';
         }
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-newsletter,代码行数:45,代码来源:CheckboxSetWithExtraField.php


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