| 1: | <?php |
| 2: | |
| 3: | namespace Zippy\Html\DataList; |
| 4: | |
| 5: | use Zippy\Html\HtmlComponent; |
| 6: | use Zippy\Html\HtmlContainer; |
| 7: | use Zippy\Interfaces\DataItem; |
| 8: | use Zippy\Html\Form\RadioButton; |
| 9: | use Zippy\Exception as ZE; |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | class DataRow extends HtmlContainer |
| 15: | { |
| 16: | private $number; |
| 17: | private $dataitem = null; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | public function __construct($id, DataItem $dataitem, $number) { |
| 25: | |
| 26: | $this->number = $number; |
| 27: | HtmlComponent::__construct($id . "_" . $this->number); |
| 28: | $this->dataitem = $dataitem; |
| 29: | |
| 30: | |
| 31: | |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function setDataItem($dataitem) { |
| 39: | $this->dataitem = $dataitem; |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | public function getItemId() { |
| 47: | if ($this->dataitem instanceof DataItem) { |
| 48: | return $this->dataitem->getID(); |
| 49: | } else { |
| 50: | return null; |
| 51: | } |
| 52: | } |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | public function getDataItem() { |
| 59: | return $this->dataitem; |
| 60: | } |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | public function add(HtmlComponent $component) { |
| 68: | |
| 69: | if (isset($this->components[$component->id]) || isset($this->components[$component->id . ":" . $this->number])) { |
| 70: | |
| 71: | |
| 72: | throw new ZE(sprintf(ERROR_DATAROW_COMPONENT_EXISTS, $component->id)); |
| 73: | } |
| 74: | $this->components[$component->id] = $component; |
| 75: | $component->setOwner($this); |
| 76: | return $component; |
| 77: | } |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | public function updateChildId() { |
| 83: | $allchild = $this->getChildComponents(true); |
| 84: | foreach ($allchild as $component) { |
| 85: | $_id = $component->id; |
| 86: | $id = "_" . $this->number; |
| 87: | $component->id .= $id; |
| 88: | $attrid = $component->getAttribute("id"); |
| 89: | |
| 90: | if ($attrid != null) { |
| 91: | $component->setAttribute("id", $attrid . $id); |
| 92: | } |
| 93: | $attrid = $component->getAttribute("name"); |
| 94: | if ($attrid != null && $component instanceof RadioButton == false) { |
| 95: | $component->setAttribute("name", $attrid . $id); |
| 96: | } |
| 97: | unset($component->owner->components[$_id]); |
| 98: | $component->owner->components[$component->id] = $component; |
| 99: | |
| 100: | if ($component instanceof AbstractList) { |
| 101: | $component->Refresh(); |
| 102: | } |
| 103: | } |
| 104: | } |
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | public function getNumber() { |
| 112: | return $this->number; |
| 113: | } |
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | public function getChildElement($id) { |
| 122: | return $this->{$id . '_' . $this->getNumber()}; |
| 123: | } |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | public function getComponent($id, $desc = true) { |
| 132: | $c = parent::getComponent($id, $desc); |
| 133: | if ($c instanceof HtmlComponent) { |
| 134: | return $c; |
| 135: | } |
| 136: | $id = $id . '_' . $this->number; |
| 137: | return parent::getComponent($id, $desc); |
| 138: | } |
| 139: | |
| 140: | } |
| 141: | |