public loadPostData ( $key, $values ) : boolean | ||
Résultat | boolean | whether the data of the component has been changed |
public function loadPostData($key, $values)
{
if (!$this->getEnabled(true)) {
return false;
}
$this->ensureDataBound();
$selections = isset($values[$key]) ? $values[$key] : null;
if ($selections !== null) {
$items = $this->getItems();
if ($this->getSelectionMode() === TListSelectionMode::Single) {
$selection = is_array($selections) ? $selections[0] : $selections;
$index = $items->findIndexByValue($selection, false);
if ($this->getSelectedIndex() !== $index) {
$this->setSelectedIndex($index);
return $this->_dataChanged = true;
} else {
return false;
}
}
if (!is_array($selections)) {
$selections = array($selections);
}
$list = array();
foreach ($selections as $selection) {
$list[] = $items->findIndexByValue($selection, false);
}
$list2 = $this->getSelectedIndices();
$n = count($list);
$flag = false;
if ($n === count($list2)) {
sort($list, SORT_NUMERIC);
for ($i = 0; $i < $n; ++$i) {
if ($list[$i] !== $list2[$i]) {
$flag = true;
break;
}
}
} else {
$flag = true;
}
if ($flag) {
$this->setSelectedIndices($list);
$this->_dataChanged = true;
}
return $flag;
} else {
if ($this->getSelectedIndex() !== -1) {
$this->clearSelection();
return $this->_dataChanged = true;
} else {
return false;
}
}
}