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