1: <?php
2:
3: namespace Alpha\View;
4:
5: use Alpha\Util\Config\ConfigProvider;
6: use Alpha\Util\Security\SecurityUtils;
7: use Alpha\Util\Http\Session\SessionProviderFactory;
8: use Alpha\Controller\Front\FrontController;
9: use Alpha\View\Widget\StringBox;
10: use Alpha\View\Widget\Button;
11: use Alpha\Model\Type\DEnumItem;
12: use Alpha\Model\Type\String;
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: 54: 55:
56: class DEnumView extends View
57: {
58: 59: 60: 61: 62: 63: 64:
65: public function listView($fields = array())
66: {
67: $config = ConfigProvider::getInstance();
68: $sessionProvider = $config->get('session.provider.name');
69: $session = SessionProviderFactory::getInstance($sessionProvider);
70:
71: $reflection = new \ReflectionClass(get_class($this->BO));
72: $properties = $reflection->getProperties();
73: $labels = $this->BO->getDataLabels();
74: $colCount = 1;
75:
76: $html = '<form action="'.$fields['URI'].'" method="POST">';
77: $html .= '<table class="table">';
78:
79: $html .= '<tr>';
80: foreach ($properties as $propObj) {
81: $prop = $propObj->name;
82: if (!in_array($prop, $this->BO->getDefaultAttributes()) && !in_array($prop, $this->BO->getTransientAttributes())) {
83: if (get_class($this->BO->getPropObject($prop)) != 'Alpha\Model\Type\Text') {
84: ++$colCount;
85: $html .= ' <th>'.$labels[$prop].'</th>';
86: }
87: }
88: if ($prop == 'OID') {
89: $html .= ' <th>'.$labels[$prop].'</th>';
90: }
91: }
92:
93: $html .= ' <th>Item count</th>';
94:
95: $html .= '</tr><tr>';
96:
97:
98: foreach ($properties as $propObj) {
99: $prop = $propObj->name;
100: if (!in_array($prop, $this->BO->getDefaultAttributes()) && !in_array($prop, $this->BO->getTransientAttributes())) {
101: if (get_class($this->BO->getPropObject($prop)) != 'Alpha\Model\Type\Text') {
102: $html .= ' <td> '.$this->BO->get($prop).'</td>';
103: }
104: }
105: if ($prop == 'OID') {
106: $html .= ' <td> '.$this->BO->getID().'</td>';
107: }
108: }
109:
110: $html .= ' <td> '.$this->BO->getItemCount().'</td>';
111:
112: $html .= '</tr>';
113:
114: $html .= '<tr><td colspan="'.($colCount + 1).'" style="text-align:center;">';
115:
116: if ($session->get('currentUser') != null && $session->get('currentUser')->inGroup('Admin')) {
117: $html .= ' ';
118: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\DEnumController&denumOID='.$this->BO->getOID())."'", 'Edit', 'edit'.$this->BO->getOID().'But');
119: $html .= $button->render();
120: }
121: $html .= '</td></tr>';
122:
123: $html .= '</table>';
124:
125: $html .= '</form>';
126:
127: return $html;
128: }
129:
130: 131: 132: 133: 134: 135: 136:
137: public function editView($fields = array())
138: {
139: $config = ConfigProvider::getInstance();
140:
141: $labels = $this->BO->getDataLabels();
142: $obj_type = '';
143:
144: $html = '<form action="'.$fields['URI'].'" method="POST" accept-charset="UTF-8">';
145:
146: $temp = new StringBox($this->BO->getPropObject('name'), $labels['name'], 'name', '', 0, true, true);
147: $html .= $temp->render();
148:
149: $html .= '<h3>DEnum display values:</h3>';
150:
151:
152: $denum = $this->BO;
153: $tmp = new DEnumItem();
154: $denumItems = $tmp->loadItems($denum->getID());
155:
156: foreach ($denumItems as $item) {
157: $labels = $item->getDataLabels();
158: $temp = new StringBox($item->getPropObject('value'), $labels['value'], 'value_'.$item->getID(), '');
159: $html .= $temp->render();
160: }
161:
162: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num');
163:
164: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getVersion().'"/>';
165:
166: $html .= '<h3>Add a new value to the DEnum dropdown list:</h3>';
167:
168: $temp = new StringBox(new String(), 'Dropdown value', 'new_value', '');
169: $html .= $temp->render();
170:
171: $temp = new Button('submit', 'Save', 'saveBut');
172: $html .= $temp->render();
173: $html .= ' ';
174: $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\DEnumController')."'", 'Back to List', 'cancelBut');
175: $html .= $temp->render();
176: $html .= '';
177:
178: $html .= View::renderSecurityFields();
179:
180: $html .= '</form>';
181:
182: return $html;
183: }
184: }
185: