1: <?php
2:
3: namespace Alpha\View;
4:
5: use Alpha\Controller\Front\FrontController;
6: use Alpha\Util\Logging\Logger;
7: use Alpha\Util\Config\ConfigProvider;
8: use Alpha\Model\Type\String;
9: use Alpha\View\Widget\Button;
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
53: class SequenceView extends View
54: {
55: 56: 57: 58: 59: 60: 61:
62: private static $logger = null;
63:
64: 65: 66: 67: 68: 69: 70: 71: 72:
73: protected function __construct($BO)
74: {
75: self::$logger = new Logger('SequenceView');
76: self::$logger->debug('>>__construct(BO=['.var_export($BO, true).'])');
77:
78: parent::__construct($BO);
79:
80: self::$logger->debug('<<__construct');
81: }
82:
83: 84: 85: 86: 87: 88: 89:
90: public function listView($fields = array())
91: {
92: self::$logger->debug('>>listView(fields=['.var_export($fields, true).'])');
93:
94: if (method_exists($this, 'before_listView_callback')) {
95: $this->before_listView_callback();
96: }
97:
98: $config = ConfigProvider::getInstance();
99:
100:
101: $fields['formAction'] = $fields['URI'];
102:
103:
104: $reflection = new \ReflectionClass(get_class($this->BO));
105: $properties = array_keys($reflection->getDefaultProperties());
106: $fields['colCount'] = 1 + count(array_diff($properties, $this->BO->getDefaultAttributes(), $this->BO->getTransientAttributes()));
107:
108:
109: $properties = $reflection->getProperties();
110:
111: $html = '';
112:
113: $html .= '<tr>';
114: foreach ($properties as $propObj) {
115: $propName = $propObj->name;
116:
117:
118: $property = $this->BO->getPropObject($propName);
119: if (!($property instanceof String && $property->checkIsPassword())) {
120: if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
121: $html .= ' <th>'.$this->BO->getDataLabel($propName).'</th>';
122: }
123: if ($propName == 'OID') {
124: $html .= ' <th>'.$this->BO->getDataLabel($propName).'</th>';
125: }
126: } else {
127: $fields['colCount'] = $fields['colCount'] - 1;
128: }
129: }
130: $html .= '</tr><tr>';
131:
132: $fields['formHeadings'] = $html;
133:
134: $html = '';
135:
136:
137: foreach ($properties as $propObj) {
138: $propName = $propObj->name;
139:
140: $property = $this->BO->getPropObject($propName);
141: if (!($property instanceof String && $property->checkIsPassword())) {
142: if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
143: $propClass = get_class($this->BO->getPropObject($propName));
144:
145: if ($propClass == 'Alpha\Model\Type\Text') {
146: $text = htmlentities($this->BO->get($propName), ENT_COMPAT, 'utf-8');
147: if (mb_strlen($text) > 70) {
148: $html .= ' <td> '.mb_substr($text, 0, 70).'...</td>';
149: } else {
150: $html .= ' <td> '.$text.'</td>';
151: }
152: } elseif ($propClass == 'Alpha\Model\Type\DEnum') {
153: $html .= ' <td> '.$this->BO->getPropObject($propName)->getDisplayValue().'</td>';
154: } else {
155: $html .= ' <td> '.$this->BO->get($propName).'</td>';
156: }
157: }
158: if ($propName == 'OID') {
159: $html .= ' <td> '.$this->BO->getOID().'</td>';
160: }
161: }
162: }
163: $html .= '</tr>';
164:
165: $fields['formFields'] = $html;
166:
167: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'viewBut');
168: $fields['viewButton'] = $button->render();
169:
170:
171: $fields['adminButtons'] = '';
172:
173:
174: $fields['formSecurityFields'] = $this->renderSecurityFields();
175:
176: $html = $this->loadTemplate($this->BO, 'list', $fields);
177:
178: if (method_exists($this, 'after_listView_callback')) {
179: $this->after_listView_callback();
180: }
181:
182: self::$logger->debug('<<listView');
183:
184: return $html;
185: }
186:
187: 188: 189: 190: 191: 192: 193:
194: public function detailedView($fields = array())
195: {
196: self::$logger->debug('>>detailedView(fields=['.var_export($fields, true).'])');
197:
198: if (method_exists($this, 'before_detailedView_callback')) {
199: $this->before_detailedView_callback();
200: }
201:
202: $config = ConfigProvider::getInstance();
203:
204:
205: $fields['OIDLabel'] = $this->BO->getDataLabel('OID');
206: $fields['OID'] = $this->BO->getOID();
207:
208:
209: $fields['formFields'] = $this->renderAllFields('view');
210:
211:
212: $button = new Button('history.back()', 'Back', 'backBut');
213: $fields['backButton'] = $button->render();
214:
215: $fields['adminButtons'] = '';
216:
217: $html = $this->loadTemplate($this->BO, 'detail', $fields);
218:
219: if (method_exists($this, 'after_detailedView_callback')) {
220: $this->after_detailedView_callback();
221: }
222:
223: self::$logger->debug('<<detailedView');
224:
225: return $html;
226: }
227: }
228: