| Conditions | 9 |
| Paths | 48 |
| Total Lines | 128 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 314 | public function index() { |
||
| 315 | |||
| 316 | global $access_level_names; |
||
| 317 | |||
| 318 | print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>"; |
||
| 319 | print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>"; |
||
| 320 | print "<div dojoType='fox.Toolbar'>"; |
||
| 321 | |||
| 322 | $user_search = trim(clean($_REQUEST["search"])); |
||
| 323 | |||
| 324 | if (array_key_exists("search", $_REQUEST)) { |
||
| 325 | $_SESSION["prefs_user_search"] = $user_search; |
||
| 326 | } else { |
||
| 327 | $user_search = $_SESSION["prefs_user_search"]; |
||
| 328 | } |
||
| 329 | |||
| 330 | print "<div style='float : right; padding-right : 4px;'> |
||
| 331 | <input dojoType='dijit.form.TextBox' id='user_search' size='20' type='search' |
||
| 332 | value=\"$user_search\"> |
||
| 333 | <button dojoType='dijit.form.Button' onclick='Users.reload()'>". |
||
| 334 | __('Search')."</button> |
||
| 335 | </div>"; |
||
| 336 | |||
| 337 | $sort = clean($_REQUEST["sort"]); |
||
| 338 | |||
| 339 | if (!$sort || $sort == "undefined") { |
||
| 340 | $sort = "login"; |
||
| 341 | } |
||
| 342 | |||
| 343 | print "<div dojoType='fox.form.DropDownButton'>". |
||
| 344 | "<span>".__('Select')."</span>"; |
||
| 345 | print "<div dojoType='dijit.Menu' style='display: none'>"; |
||
| 346 | print "<div onclick=\"Tables.select('prefUserList', true)\" |
||
| 347 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
||
| 348 | print "<div onclick=\"Tables.select('prefUserList', false)\" |
||
| 349 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
||
| 350 | print "</div></div>"; |
||
| 351 | |||
| 352 | print "<button dojoType='dijit.form.Button' onclick='Users.add()'>".__('Create user')."</button>"; |
||
| 353 | |||
| 354 | print " |
||
| 355 | <button dojoType='dijit.form.Button' onclick='Users.editSelected()'>". |
||
| 356 | __('Edit')."</button dojoType=\"dijit.form.Button\"> |
||
| 357 | <button dojoType='dijit.form.Button' onclick='Users.removeSelected()'>". |
||
| 358 | __('Remove')."</button dojoType=\"dijit.form.Button\"> |
||
| 359 | <button dojoType='dijit.form.Button' onclick='Users.resetSelected()'>". |
||
| 360 | __('Reset password')."</button dojoType=\"dijit.form.Button\">"; |
||
| 361 | |||
| 362 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
||
| 363 | "hook_prefs_tab_section", "prefUsersToolbar"); |
||
| 364 | |||
| 365 | print "</div>"; #toolbar |
||
| 366 | print "</div>"; #pane |
||
| 367 | print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>"; |
||
| 368 | |||
| 369 | $sort = $this->validate_field($sort, |
||
| 370 | ["login", "access_level", "created", "num_feeds", "created", "last_login"], "login"); |
||
| 371 | |||
| 372 | if ($sort != "login") { |
||
| 373 | $sort = "$sort DESC"; |
||
| 374 | } |
||
| 375 | |||
| 376 | $sth = $this->pdo->prepare("SELECT |
||
| 377 | tu.id, |
||
| 378 | login,access_level,email, |
||
| 379 | ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, |
||
| 380 | ".SUBSTRING_FOR_DATE."(created,1,16) as created, |
||
| 381 | (SELECT COUNT(id) FROM ttrss_feeds WHERE owner_uid = tu.id) AS num_feeds |
||
| 382 | FROM |
||
| 383 | ttrss_users tu |
||
| 384 | WHERE |
||
| 385 | (:search = '' OR login LIKE :search) AND tu.id > 0 |
||
| 386 | ORDER BY $sort"); |
||
| 387 | $sth->execute([":search" => $user_search ? "%$user_search%" : ""]); |
||
| 388 | |||
| 389 | print "<p><table width='100%' cellspacing='0' class='prefUserList' id='prefUserList'>"; |
||
| 390 | |||
| 391 | print "<tr class='title'> |
||
| 392 | <td align='center' width='5%'> </td> |
||
| 393 | <td width='20%'><a href='#' onclick=\"Users.reload('login')\">".__('Login')."</a></td> |
||
| 394 | <td width='20%'><a href='#' onclick=\"Users.reload('access_level')\">".__('Access Level')."</a></td> |
||
| 395 | <td width='10%'><a href='#' onclick=\"Users.reload('num_feeds')\">".__('Subscribed feeds')."</a></td> |
||
| 396 | <td width='20%'><a href='#' onclick=\"Users.reload('created')\">".__('Registered')."</a></td> |
||
| 397 | <td width='20%'><a href='#' onclick=\"Users.reload('last_login')\">".__('Last login')."</a></td></tr>"; |
||
| 398 | |||
| 399 | $lnum = 0; |
||
| 400 | |||
| 401 | while ($line = $sth->fetch()) { |
||
| 402 | |||
| 403 | $uid = $line["id"]; |
||
| 404 | |||
| 405 | print "<tr data-row-id='$uid' onclick='Users.edit($uid)'>"; |
||
| 406 | |||
| 407 | $line["login"] = htmlspecialchars($line["login"]); |
||
| 408 | $line["created"] = make_local_datetime($line["created"], false); |
||
| 409 | $line["last_login"] = make_local_datetime($line["last_login"], false); |
||
| 410 | |||
| 411 | print "<td align='center'><input onclick='Tables.onRowChecked(this); event.stopPropagation();' |
||
| 412 | dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
||
| 413 | |||
| 414 | print "<td title='".__('Click to edit')."'><i class='material-icons'>person</i> ".$line["login"]."</td>"; |
||
| 415 | |||
| 416 | print "<td>".$access_level_names[$line["access_level"]]."</td>"; |
||
| 417 | print "<td>".$line["num_feeds"]."</td>"; |
||
| 418 | print "<td>".$line["created"]."</td>"; |
||
| 419 | print "<td>".$line["last_login"]."</td>"; |
||
| 420 | |||
| 421 | print "</tr>"; |
||
| 422 | |||
| 423 | ++$lnum; |
||
| 424 | } |
||
| 425 | |||
| 426 | print "</table>"; |
||
| 427 | |||
| 428 | if ($lnum == 0) { |
||
| 429 | if (!$user_search) { |
||
| 430 | print_warning(__('No users defined.')); |
||
| 431 | } else { |
||
| 432 | print_warning(__('No matching users found.')); |
||
| 433 | } |
||
| 434 | } |
||
| 435 | |||
| 436 | print "</div>"; #pane |
||
| 437 | |||
| 438 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
||
| 439 | "hook_prefs_tab", "prefUsers"); |
||
| 440 | |||
| 441 | print "</div>"; #container |
||
| 442 | |||
| 454 |