protected applyItemStyles ( ) |
protected function applyItemStyles()
{
$itemStyle = $this->getViewState('ItemStyle', null);
$alternatingItemStyle = $this->getViewState('AlternatingItemStyle', null);
if ($itemStyle !== null) {
if ($alternatingItemStyle === null) {
$alternatingItemStyle = $itemStyle;
} else {
$alternatingItemStyle->mergeWith($itemStyle);
}
}
$selectedItemStyle = $this->getViewState('SelectedItemStyle', null);
$editItemStyle = $this->getViewState('EditItemStyle', null);
if ($selectedItemStyle !== null) {
if ($editItemStyle === null) {
$editItemStyle = $selectedItemStyle;
} else {
$editItemStyle->mergeWith($selectedItemStyle);
}
}
// apply header style if any
if ($this->_header !== null && $this->_header instanceof IStyleable) {
if ($headerStyle = $this->getViewState('HeaderStyle', null)) {
$this->_header->getStyle()->mergeWith($headerStyle);
}
}
// apply footer style if any
if ($this->_footer !== null && $this->_footer instanceof IStyleable) {
if ($footerStyle = $this->getViewState('FooterStyle', null)) {
$this->_footer->getStyle()->mergeWith($footerStyle);
}
}
$selectedIndex = $this->getSelectedItemIndex();
$editIndex = $this->getEditItemIndex();
// apply item styles if any
foreach ($this->getItems() as $index => $item) {
if ($index === $editIndex) {
$style = $editItemStyle;
} else {
if ($index === $selectedIndex) {
$style = $selectedItemStyle;
} else {
if ($index % 2 === 0) {
$style = $itemStyle;
} else {
$style = $alternatingItemStyle;
}
}
}
if ($style && $item instanceof IStyleable) {
$item->getStyle()->mergeWith($style);
}
}
// apply separator style if any
if (($separatorStyle = $this->getViewState('SeparatorStyle', null)) !== null && $this->getHasSeparators()) {
$controls = $this->getControls();
$count = $controls->getCount();
for ($i = $this->_header ? 2 : 1; $i < $count; $i += 2) {
if (($separator = $controls->itemAt($i)) instanceof IStyleable) {
$separator->getStyle()->mergeWith($separatorStyle);
}
}
}
}