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


PHP ArrayLib::invert方法代码示例

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


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

示例1: testInvert

	function testInvert() {
		$arr = array(
			'row1' => array(
				'col1' =>'val1',
				'col2' => 'val2'
			),
			'row2' => array(
				'col1' => 'val3',
				'col2' => 'val4'
			)
		);
		
		$this->assertEquals(
			ArrayLib::invert($arr),
			array(
				'col1' => array(
					'row1' => 'val1',
					'row2' => 'val3',
				),
				'col2' => array(
					'row1' => 'val2',
					'row2' => 'val4',
				),
			)
		);
	}
开发者ID:redema,项目名称:sapphire,代码行数:26,代码来源:ArrayLibTest.php

示例2: saveInto

	/** 
	 * Saves the Dataobjects contained in the field
	 */
	function saveInto(DataObjectInterface $record) {
		// CMS sometimes tries to set the value to one.
		if(is_array($this->value)){
			$newFields = array();
			
			// Sort into proper array
			$value = ArrayLib::invert($this->value);
			$dataObjects = $this->sortData($value, $record->ID);
			
			// New fields are nested in their own sub-array, and need to be sorted separately
 			if(isset($dataObjects['new']) && $dataObjects['new']) {
 				$newFields = $this->sortData($dataObjects['new'], $record->ID);
 			}

			// Update existing fields
			// @todo Should this be in an else{} statement?
			$savedObjIds = $this->saveData($dataObjects, $this->editExisting);
			
			// Save newly added record
			if($savedObjIds || $newFields) {
				$savedObjIds = $this->saveData($newFields,false);
 			}

			// Add the new records to the DataList
			if($savedObjIds) foreach($savedObjIds as $id => $status) {
				$this->getDataList()->add($id);
			}	

			// Update the internal source items cache
			$this->value = null;
			$items = $this->sourceItems();
			
			// FormResponse::update_dom_id($this->id(), $this->FieldHolder());
		}
	}
开发者ID:redema,项目名称:sapphire,代码行数:38,代码来源:TableField.php

示例3: saveInto

 /** 
  * Saves the Dataobjects contained in the field
  */
 function saveInto(DataObject $record)
 {
     // CMS sometimes tries to set the value to one.
     if (is_array($this->value)) {
         $newFields = array();
         // Sort into proper array
         $value = ArrayLib::invert($this->value);
         $dataObjects = $this->sortData($value, $record->ID);
         // New fields are nested in their own sub-array, and need to be sorted separately
         if (isset($dataObjects['new']) && $dataObjects['new']) {
             $newFields = $this->sortData($dataObjects['new'], $record->ID);
         }
         // Update existing fields
         // @todo Should this be in an else{} statement?
         $savedObjIds = $this->saveData($dataObjects, $this->editExisting);
         // Save newly added record
         if ($savedObjIds || $newFields) {
             $savedObjIds = $this->saveData($newFields, false);
         }
         // Optionally save the newly created records into a relationship
         // on $record. This assumes the name of this formfield instance
         // is set to a relationship name on $record.
         if ($this->relationAutoSetting) {
             $relationName = $this->Name();
             if ($record->has_many($relationName) || $record->many_many($relationName)) {
                 if ($savedObjIds) {
                     foreach ($savedObjIds as $id => $status) {
                         $record->{$relationName}()->add($id);
                     }
                 }
             }
         }
         // Update the internal source items cache
         $this->value = null;
         $items = $this->sourceItems();
         FormResponse::update_dom_id($this->id(), $this->FieldHolder());
     }
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:41,代码来源:TableField.php

示例4: saveInto

	/** 
	 * Saves the Dataobjects contained in the field
	 */
	function saveInto(DataObject $record) {
		// CMS sometimes tries to set the value to one.
		if(is_array($this->value)){
			
			// Sort into proper array
			$this->value = ArrayLib::invert($this->value);
			$dataObjects = $this->sortData($this->value, $record->ID);
			if(isset($dataObjects['new']) && $dataObjects['new']) {
				$newFields = $this->sortData($dataObjects['new'], $record->ID);
			}

			$savedObj = $this->saveData($dataObjects, $this->editExisting);
			if($savedObj && isset($newFields)) {
				$savedObj = $this->saveData($newFields,false);
			} else if(isset($newFields)) {
				$savedObj = $this->saveData($newFields,false);
			}
			$items = $this->sourceItems();
			FormResponse::update_dom_id($this->id(), $this->FieldHolder());
		}
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:24,代码来源:TableField.php

示例5: saveInto

 function saveInto(DataObject $record)
 {
     $fieldname = $this->name;
     $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:nyeholt,项目名称:silverstripe-newsletter,代码行数:43,代码来源:CheckboxSetWithExtraField.php


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