Prado\Web\UI\WebControls\TDataGrid::applyItemStyles PHP 메소드

applyItemStyles() 보호된 메소드

Item styles are applied in a hierarchical way. Style in higher hierarchy will inherit from styles in lower hierarchy. Starting from the lowest hierarchy, the item styles include item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle}, {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}. Therefore, if background color is set as red in {@link getItemStyle ItemStyle}, {@link getEditItemStyle EditItemStyle} will also have red background color unless it is set to a different value explicitly.
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);
            }
        }
        $headerStyle = $this->getViewState('HeaderStyle', null);
        $footerStyle = $this->getViewState('FooterStyle', null);
        $pagerStyle = $this->getViewState('PagerStyle', null);
        $separatorStyle = $this->getViewState('SeparatorStyle', null);
        foreach ($this->getControls() as $index => $item) {
            if (!$item instanceof TDataGridItem && !$item instanceof TDataGridPager) {
                continue;
            }
            $itemType = $item->getItemType();
            switch ($itemType) {
                case TListItemType::Header:
                    if ($headerStyle) {
                        $item->getStyle()->mergeWith($headerStyle);
                    }
                    if (!$this->getShowHeader()) {
                        $item->setVisible(false);
                    }
                    break;
                case TListItemType::Footer:
                    if ($footerStyle) {
                        $item->getStyle()->mergeWith($footerStyle);
                    }
                    if (!$this->getShowFooter()) {
                        $item->setVisible(false);
                    }
                    break;
                case TListItemType::Separator:
                    if ($separatorStyle) {
                        $item->getStyle()->mergeWith($separatorStyle);
                    }
                    break;
                case TListItemType::Item:
                    if ($itemStyle) {
                        $item->getStyle()->mergeWith($itemStyle);
                    }
                    break;
                case TListItemType::AlternatingItem:
                    if ($alternatingItemStyle) {
                        $item->getStyle()->mergeWith($alternatingItemStyle);
                    }
                    break;
                case TListItemType::SelectedItem:
                    if ($selectedItemStyle) {
                        $item->getStyle()->mergeWith($selectedItemStyle);
                    }
                    if ($index % 2 == 1) {
                        if ($itemStyle) {
                            $item->getStyle()->mergeWith($itemStyle);
                        }
                    } else {
                        if ($alternatingItemStyle) {
                            $item->getStyle()->mergeWith($alternatingItemStyle);
                        }
                    }
                    break;
                case TListItemType::EditItem:
                    if ($editItemStyle) {
                        $item->getStyle()->mergeWith($editItemStyle);
                    }
                    if ($index % 2 == 1) {
                        if ($itemStyle) {
                            $item->getStyle()->mergeWith($itemStyle);
                        }
                    } else {
                        if ($alternatingItemStyle) {
                            $item->getStyle()->mergeWith($alternatingItemStyle);
                        }
                    }
                    break;
                case TListItemType::Pager:
                    if ($pagerStyle) {
                        $item->getStyle()->mergeWith($pagerStyle);
                        if ($index === 0) {
                            if ($pagerStyle->getPosition() === TDataGridPagerPosition::Bottom || !$pagerStyle->getVisible()) {
                                $item->setVisible(false);
                            }
                        } else {
                            if ($pagerStyle->getPosition() === TDataGridPagerPosition::Top || !$pagerStyle->getVisible()) {
                                $item->setVisible(false);
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
            if ($this->_columns && $itemType !== TListItemType::Pager) {
                $n = $this->_columns->getCount();
                $cells = $item->getCells();
                for ($i = 0; $i < $n; ++$i) {
                    $cell = $cells->itemAt($i);
                    $column = $this->_columns->itemAt($i);
                    if (!$column->getVisible()) {
                        $cell->setVisible(false);
                    } else {
                        if ($itemType === TListItemType::Header) {
                            $style = $column->getHeaderStyle(false);
                        } else {
                            if ($itemType === TListItemType::Footer) {
                                $style = $column->getFooterStyle(false);
                            } else {
                                $style = $column->getItemStyle(false);
                            }
                        }
                        if ($style !== null) {
                            $cell->getStyle()->mergeWith($style);
                        }
                    }
                }
            }
        }
    }