| Total Complexity | 21 |
| Total Lines | 266 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class OperatorsController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'OperatorsController'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Default method to render the controller according to the action parameter. |
||
| 20 | */ |
||
| 21 | public function render() |
||
| 22 | { |
||
| 23 | $lang = $this->lang; |
||
| 24 | |||
| 25 | $action = $this->action; |
||
| 26 | if ('tree' == $action) { |
||
| 27 | return $this->doTree(); |
||
| 28 | } |
||
| 29 | |||
| 30 | $this->printHeader($lang['stroperators']); |
||
| 31 | $this->printBody(); |
||
| 32 | |||
| 33 | switch ($action) { |
||
| 34 | case 'save_create': |
||
| 35 | if (isset($_POST['cancel'])) { |
||
| 36 | $this->doDefault(); |
||
| 37 | } else { |
||
| 38 | $this->doSaveCreate(); |
||
| 39 | } |
||
| 40 | |||
| 41 | break; |
||
| 42 | case 'create': |
||
| 43 | doCreate(); |
||
| 44 | |||
| 45 | break; |
||
| 46 | case 'drop': |
||
| 47 | if (isset($_POST['cancel'])) { |
||
| 48 | $this->doDefault(); |
||
| 49 | } else { |
||
| 50 | $this->doDrop(false); |
||
| 51 | } |
||
| 52 | |||
| 53 | break; |
||
| 54 | case 'confirm_drop': |
||
| 55 | $this->doDrop(true); |
||
| 56 | |||
| 57 | break; |
||
| 58 | case 'properties': |
||
| 59 | $this->doProperties(); |
||
| 60 | |||
| 61 | break; |
||
| 62 | default: |
||
| 63 | $this->doDefault(); |
||
| 64 | |||
| 65 | break; |
||
| 66 | } |
||
| 67 | |||
| 68 | $this->printFooter(); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Generate XML for the browser tree. |
||
| 73 | */ |
||
| 74 | public function doTree() |
||
| 75 | { |
||
| 76 | $lang = $this->lang; |
||
| 77 | $data = $this->misc->getDatabaseAccessor(); |
||
| 78 | |||
| 79 | $operators = $data->getOperators(); |
||
| 80 | |||
| 81 | // Operator prototype: "type operator type" |
||
| 82 | $proto = Decorator::concat(Decorator::field('oprleftname'), ' ', Decorator::field('oprname'), ' ', Decorator::field('oprrightname')); |
||
| 83 | |||
| 84 | $reqvars = $this->misc->getRequestVars('operator'); |
||
| 85 | |||
| 86 | $attrs = [ |
||
| 87 | 'text' => $proto, |
||
| 88 | 'icon' => 'Operator', |
||
| 89 | 'toolTip' => Decorator::field('oprcomment'), |
||
| 90 | 'action' => Decorator::actionurl( |
||
| 91 | 'operators.php', |
||
| 92 | $reqvars, |
||
| 93 | [ |
||
| 94 | 'action' => 'properties', |
||
| 95 | 'operator' => $proto, |
||
| 96 | 'operator_oid' => Decorator::field('oid'), |
||
| 97 | ] |
||
| 98 | ), |
||
| 99 | ]; |
||
| 100 | |||
| 101 | return $this->printTree($operators, $attrs, 'operators'); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Show default list of operators in the database. |
||
| 106 | * |
||
| 107 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 108 | */ |
||
| 109 | public function doDefault($msg = '') |
||
| 110 | { |
||
| 111 | $lang = $this->lang; |
||
| 112 | $data = $this->misc->getDatabaseAccessor(); |
||
| 113 | |||
| 114 | $this->printTrail('schema'); |
||
| 115 | $this->printTabs('schema', 'operators'); |
||
| 116 | $this->printMsg($msg); |
||
| 117 | |||
| 118 | $operators = $data->getOperators(); |
||
| 119 | |||
| 120 | $columns = [ |
||
| 121 | 'operator' => [ |
||
| 122 | 'title' => $lang['stroperator'], |
||
| 123 | 'field' => Decorator::field('oprname'), |
||
| 124 | 'url' => "operators.php?action=properties&{$this->misc->href}&", |
||
| 125 | 'vars' => ['operator' => 'oprname', 'operator_oid' => 'oid'], |
||
| 126 | ], |
||
| 127 | 'leftarg' => [ |
||
| 128 | 'title' => $lang['strleftarg'], |
||
| 129 | 'field' => Decorator::field('oprleftname'), |
||
| 130 | ], |
||
| 131 | 'rightarg' => [ |
||
| 132 | 'title' => $lang['strrightarg'], |
||
| 133 | 'field' => Decorator::field('oprrightname'), |
||
| 134 | ], |
||
| 135 | 'returns' => [ |
||
| 136 | 'title' => $lang['strreturns'], |
||
| 137 | 'field' => Decorator::field('resultname'), |
||
| 138 | ], |
||
| 139 | 'actions' => [ |
||
| 140 | 'title' => $lang['stractions'], |
||
| 141 | ], |
||
| 142 | 'comment' => [ |
||
| 143 | 'title' => $lang['strcomment'], |
||
| 144 | 'field' => Decorator::field('oprcomment'), |
||
| 145 | ], |
||
| 146 | ]; |
||
| 147 | |||
| 148 | $actions = [ |
||
| 149 | 'drop' => [ |
||
| 150 | // 'title' => $lang['strdrop'], |
||
| 151 | // 'url' => "operators.php?action=confirm_drop&{$this->misc->href}&", |
||
| 152 | // 'vars' => array('operator' => 'oprname', 'operator_oid' => 'oid'), |
||
| 153 | 'content' => $lang['strdrop'], |
||
| 154 | 'attr' => [ |
||
| 155 | 'href' => [ |
||
| 156 | 'url' => 'operators.php', |
||
| 157 | 'urlvars' => [ |
||
| 158 | 'action' => 'confirm_drop', |
||
| 159 | 'operator' => Decorator::field('oprname'), |
||
| 160 | 'operator_oid' => Decorator::field('oid'), |
||
| 161 | ], |
||
| 162 | ], |
||
| 163 | ], |
||
| 164 | ], |
||
| 165 | ]; |
||
| 166 | |||
| 167 | echo $this->printTable($operators, $columns, $actions, 'operators-operators', $lang['strnooperators']); |
||
| 168 | |||
| 169 | // TODO operators.php action=create $lang['strcreateoperator'] |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Show read only properties for an operator. |
||
| 174 | * |
||
| 175 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 176 | */ |
||
| 177 | public function doProperties($msg = '') |
||
| 178 | { |
||
| 179 | $lang = $this->lang; |
||
| 180 | $data = $this->misc->getDatabaseAccessor(); |
||
| 181 | |||
| 182 | $this->printTrail('operator'); |
||
| 183 | $this->printTitle($lang['strproperties'], 'pg.operator'); |
||
| 184 | $this->printMsg($msg); |
||
| 185 | |||
| 186 | $oprdata = $data->getOperator($_REQUEST['operator_oid']); |
||
| 187 | $oprdata->fields['oprcanhash'] = $data->phpBool($oprdata->fields['oprcanhash']); |
||
| 188 | |||
| 189 | if ($oprdata->recordCount() > 0) { |
||
| 190 | echo "<table>\n"; |
||
| 191 | echo "<tr><th class=\"data left\">{$lang['strname']}</th>\n"; |
||
| 192 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprname']), "</td></tr>\n"; |
||
| 193 | echo "<tr><th class=\"data left\">{$lang['strleftarg']}</th>\n"; |
||
| 194 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprleftname']), "</td></tr>\n"; |
||
| 195 | echo "<tr><th class=\"data left\">{$lang['strrightarg']}</th>\n"; |
||
| 196 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrightname']), "</td></tr>\n"; |
||
| 197 | echo "<tr><th class=\"data left\">{$lang['strcommutator']}</th>\n"; |
||
| 198 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprcom']), "</td></tr>\n"; |
||
| 199 | echo "<tr><th class=\"data left\">{$lang['strnegator']}</th>\n"; |
||
| 200 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprnegate']), "</td></tr>\n"; |
||
| 201 | echo "<tr><th class=\"data left\">{$lang['strjoin']}</th>\n"; |
||
| 202 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprjoin']), "</td></tr>\n"; |
||
| 203 | echo "<tr><th class=\"data left\">{$lang['strhashes']}</th>\n"; |
||
| 204 | echo '<td class="data1">', ($oprdata->fields['oprcanhash']) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n"; |
||
| 205 | |||
| 206 | // these field only exists in 8.2 and before in pg_catalog |
||
| 207 | if (isset($oprdata->fields['oprlsortop'])) { |
||
| 208 | echo "<tr><th class=\"data left\">{$lang['strmerges']}</th>\n"; |
||
| 209 | echo '<td class="data1">', ('0' !== $oprdata->fields['oprlsortop'] && '0' !== $oprdata->fields['oprrsortop']) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n"; |
||
| 210 | echo "<tr><th class=\"data left\">{$lang['strrestrict']}</th>\n"; |
||
| 211 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrest']), "</td></tr>\n"; |
||
| 212 | echo "<tr><th class=\"data left\">{$lang['strleftsort']}</th>\n"; |
||
| 213 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprlsortop']), "</td></tr>\n"; |
||
| 214 | echo "<tr><th class=\"data left\">{$lang['strrightsort']}</th>\n"; |
||
| 215 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprrsortop']), "</td></tr>\n"; |
||
| 216 | echo "<tr><th class=\"data left\">{$lang['strlessthan']}</th>\n"; |
||
| 217 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprltcmpop']), "</td></tr>\n"; |
||
| 218 | echo "<tr><th class=\"data left\">{$lang['strgreaterthan']}</th>\n"; |
||
| 219 | echo '<td class="data1">', $this->misc->printVal($oprdata->fields['oprgtcmpop']), "</td></tr>\n"; |
||
| 220 | } else { |
||
| 221 | echo "<tr><th class=\"data left\">{$lang['strmerges']}</th>\n"; |
||
| 222 | echo '<td class="data1">', $data->phpBool($oprdata->fields['oprcanmerge']) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n"; |
||
| 223 | } |
||
| 224 | echo "</table>\n"; |
||
| 225 | |||
| 226 | $this->printNavLinks( |
||
| 227 | [ |
||
| 228 | 'showall' => [ |
||
| 229 | 'attr' => [ |
||
| 230 | 'href' => [ |
||
| 231 | 'url' => 'operators.php', |
||
| 232 | 'urlvars' => [ |
||
| 233 | 'server' => $_REQUEST['server'], |
||
| 234 | 'database' => $_REQUEST['database'], |
||
| 235 | 'schema' => $_REQUEST['schema'], |
||
| 236 | ], |
||
| 237 | ], |
||
| 238 | ], |
||
| 239 | 'content' => $lang['strshowalloperators'], |
||
| 240 | ]], |
||
| 241 | 'operators-properties', |
||
| 242 | get_defined_vars() |
||
| 243 | ); |
||
| 244 | } else { |
||
| 245 | $this->doDefault($lang['strinvalidparam']); |
||
| 246 | } |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Show confirmation of drop and perform actual drop. |
||
| 251 | * |
||
| 252 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 253 | */ |
||
| 254 | public function doDrop($confirm) |
||
| 280 | } |
||
| 281 | } |
||
| 282 | } |
||
| 283 | } |
||
| 284 |