本文整理汇总了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',
),
)
);
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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} = '';
}
}
}