/**
* Creates a datalist item instance based on the item type and index.
* @param integer zero-based item index
* @param TListItemType item type
* @return TControl created datalist item
*/
protected function createItem($itemIndex, $itemType)
{
$template = null;
$classPath = null;
switch ($itemType) {
case TListItemType::Item:
$classPath = $this->getItemRenderer();
$template = $this->_itemTemplate;
break;
case TListItemType::AlternatingItem:
list($classPath, $template) = $this->getAlternatingItemDisplay();
break;
case TListItemType::SelectedItem:
list($classPath, $template) = $this->getSelectedItemDisplay($itemIndex);
break;
case TListItemType::EditItem:
list($classPath, $template) = $this->getEditItemDisplay($itemIndex);
break;
case TListItemType::Header:
$classPath = $this->getHeaderRenderer();
$template = $this->_headerTemplate;
break;
case TListItemType::Footer:
$classPath = $this->getFooterRenderer();
$template = $this->_footerTemplate;
break;
case TListItemType::Separator:
$classPath = $this->getSeparatorRenderer();
$template = $this->_separatorTemplate;
break;
default:
throw new TInvalidDataValueException('datalist_itemtype_unknown', $itemType);
}
if ($classPath !== '') {
$item = Prado::createComponent($classPath);
if ($item instanceof IItemDataRenderer) {
$item->setItemIndex($itemIndex);
$item->setItemType($itemType);
}
} else {
if ($template !== null) {
$item = new TDataListItem();
$item->setItemIndex($itemIndex);
$item->setItemType($itemType);
$template->instantiateIn($item);
} else {
$item = null;
}
}
return $item;
}