| Conditions | 13 |
| Paths | 36 |
| Total Lines | 167 |
| Code Lines | 133 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 declare(strict_types=1); |
||
| 285 | function xhelp_default() |
||
| 286 | { |
||
| 287 | $helper = Xhelp\Helper::getInstance(); |
||
| 288 | |||
| 289 | xoops_cp_header(); |
||
| 290 | //echo $oAdminButton->renderButtons('index'); |
||
| 291 | $adminObject = Admin::getInstance(); |
||
| 292 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 293 | |||
| 294 | $displayName = $helper->getConfig('xhelp_displayName'); // Determines if username or real name is displayed |
||
| 295 | |||
| 296 | $stylePath = XHELP_BASE_URL . '/assets/css/xhelp.css'; |
||
| 297 | echo '<link rel="stylesheet" type="text/css" media="all" href="' . $stylePath . '"><!--[if if lt IE 7]><script src="iepngfix.js" language="JavaScript" type="text/javascript"></script><![endif]-->'; |
||
| 298 | |||
| 299 | global $xoopsUser, $xoopsDB; |
||
| 300 | /** @var \XoopsModules\Xhelp\TicketHandler $ticketHandler */ |
||
| 301 | $ticketHandler = $helper->getHandler('Ticket'); |
||
| 302 | /** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
||
| 303 | $statusHandler = $helper->getHandler('Status'); |
||
| 304 | |||
| 305 | $criteria = new \Criteria('', ''); |
||
| 306 | $criteria->setSort('description'); |
||
| 307 | $criteria->setOrder('ASC'); |
||
| 308 | $statuses = $statusHandler->getObjects($criteria); |
||
| 309 | $table_class = ['odd', 'even']; |
||
| 310 | echo "<table border='0' width='100%'>"; |
||
| 311 | echo "<tr><td width='50%' valign='top'>"; |
||
| 312 | echo "<div id='ticketInfo'>"; |
||
| 313 | echo "<table border='0' width='95%' cellspacing='1' class='outer'> |
||
| 314 | <tr><th colspan='2'>" . _AM_XHELP_TEXT_TICKET_INFO . '</th></tr>'; |
||
| 315 | $class = 'odd'; |
||
| 316 | $totalTickets = 0; |
||
| 317 | foreach ($statuses as $status) { |
||
| 318 | $criteria = new \Criteria('status', $status->getVar('id')); |
||
| 319 | $numTickets = $ticketHandler->getCount($criteria); |
||
| 320 | $totalTickets += $numTickets; |
||
| 321 | |||
| 322 | echo "<tr class='" . $class . "'><td>" . $status->getVar('description') . '</td><td>' . $numTickets . '</td></tr>'; |
||
| 323 | if ('odd' === $class) { |
||
| 324 | $class = 'even'; |
||
| 325 | } else { |
||
| 326 | $class = 'odd'; |
||
| 327 | } |
||
| 328 | } |
||
| 329 | echo "<tr class='foot'><td>" . _AM_XHELP_TEXT_TOTAL_TICKETS . '</td><td>' . $totalTickets . '</td></tr>'; |
||
| 330 | echo '</table></div><br>'; |
||
| 331 | |||
| 332 | /** @var \XoopsModules\Xhelp\StaffHandler $staffHandler */ |
||
| 333 | $staffHandler = $helper->getHandler('Staff'); |
||
| 334 | /** @var \XoopsModules\Xhelp\ResponseHandler $responseHandler */ |
||
| 335 | $responseHandler = $helper->getHandler('Response'); |
||
| 336 | echo "</td><td valign='top'>"; // Outer table |
||
| 337 | echo "<div id='timeSpent'>"; // Start inner top-left cell |
||
| 338 | echo "<table border='0' width='100%' cellspacing='1' class='outer'> |
||
| 339 | <tr><th colspan='2'>" . _AM_XHELP_TEXT_RESPONSE_TIME . '</th></tr>'; |
||
| 340 | |||
| 341 | $sql = sprintf('SELECT u.uid, u.uname, u.name, (s.responseTime / s.ticketsResponded) AS AvgResponseTime FROM `%s` u INNER JOIN %s s ON u.uid = s.uid WHERE ticketsResponded > 0 ORDER BY AvgResponseTime', $xoopsDB->prefix('users'), $xoopsDB->prefix('xhelp_staff')); |
||
| 342 | $ret = $xoopsDB->query($sql, MAX_STAFF_RESPONSETIME); |
||
| 343 | $i = 0; |
||
| 344 | while ([$uid, $uname, $name, $avgResponseTime] = $xoopsDB->fetchRow($ret)) { |
||
| 345 | $class = $table_class[$i % 2]; |
||
| 346 | echo "<tr class='$class'><td>" . Xhelp\Utility::getDisplayName($displayName, $name, $uname) . "</td><td align='right'>" . Xhelp\Utility::formatTime((int)$avgResponseTime) . '</td></tr>'; |
||
| 347 | ++$i; |
||
| 348 | } |
||
| 349 | echo '</table></div><br>'; // End inner top-left cell |
||
| 350 | echo "</td></tr><tr><td valign='top'>"; // End first, start second cell |
||
| 351 | |||
| 352 | //Get Calls Closed block |
||
| 353 | $sql = sprintf('SELECT SUM(callsClosed) FROM `%s`', $xoopsDB->prefix('xhelp_staff')); |
||
| 354 | $ret = $xoopsDB->query($sql); |
||
| 355 | if ([$totalStaffClosed] = $xoopsDB->fetchRow($ret)) { |
||
| 356 | if ($totalStaffClosed) { |
||
| 357 | $sql = sprintf('SELECT u.uid, u.uname, u.name, s.callsClosed FROM `%s` u INNER JOIN %s s ON u.uid = s.uid WHERE s.callsClosed > 0 ORDER BY s.callsClosed DESC', $xoopsDB->prefix('users'), $xoopsDB->prefix('xhelp_staff')); |
||
| 358 | $ret = $xoopsDB->query($sql, MAX_STAFF_CALLSCLOSED); |
||
| 359 | echo "<div id='callsClosed'>"; |
||
| 360 | echo "<table border='0' width='95%' cellspacing='1' class='outer'> |
||
| 361 | <tr><th colspan='2'>" . _AM_XHELP_TEXT_TOP_CLOSERS . '</th></tr>'; |
||
| 362 | $i = 0; |
||
| 363 | while ([$uid, $uname, $name, $callsClosed] = $xoopsDB->fetchRow($ret)) { |
||
| 364 | $class = $table_class[$i % 2]; |
||
| 365 | echo "<tr class='$class'><td>" . Xhelp\Utility::getDisplayName($displayName, $name, $uname) . "</td><td align='right'>" . $callsClosed . ' (' . round(($callsClosed / $totalStaffClosed) * 100, 2) . '%)</td></tr>'; |
||
| 366 | ++$i; |
||
| 367 | } |
||
| 368 | echo '</table></div><br>'; // End inner table top row |
||
| 369 | echo "</td><td valign='top'>"; // End top row of outer table |
||
| 370 | |||
| 371 | $sql = sprintf('SELECT u.uid, u.uname, u.name, (s.responseTime / s.ticketsResponded) AS AvgResponseTime FROM `%s` u INNER JOIN %s s ON u.uid = s.uid WHERE ticketsResponded > 0 ORDER BY AvgResponseTime DESC', $xoopsDB->prefix('users'), $xoopsDB->prefix('xhelp_staff')); |
||
| 372 | $ret = $xoopsDB->query($sql, MAX_STAFF_RESPONSETIME); |
||
| 373 | echo "<div id='leastCallsClosed'>"; |
||
| 374 | echo "<table border='0' width='100%' cellspacing='1' class='outer'> |
||
| 375 | <tr><th colspan='2'>" . _AM_XHELP_TEXT_RESPONSE_TIME_SLOW . '</th></tr>'; |
||
| 376 | $i = 0; |
||
| 377 | while ([$uid, $uname, $name, $avgResponseTime] = $xoopsDB->fetchRow($ret)) { |
||
| 378 | $class = $table_class[$i % 2]; |
||
| 379 | echo "<tr class='$class'><td>" . Xhelp\Utility::getDisplayName($displayName, $name, $uname) . "</td><td align='right'>" . Xhelp\Utility::formatTime($avgResponseTime) . '</td></tr>'; |
||
| 380 | ++$i; |
||
| 381 | } |
||
| 382 | echo '</table></div>'; // End first cell, second row of inner table |
||
| 383 | } |
||
| 384 | } |
||
| 385 | echo '</td></tr></table><br>'; // End second cell, second row of inner table |
||
| 386 | |||
| 387 | $criteria = new \Criteria('state', '2', '<>', 's'); |
||
| 388 | $criteria->setSort('priority'); |
||
| 389 | $criteria->setOrder('ASC'); |
||
| 390 | $criteria->setLimit(10); |
||
| 391 | $highPriority = $ticketHandler->getObjects($criteria); |
||
| 392 | $has_highPriority = (count($highPriority) > 0); |
||
| 393 | if ($has_highPriority) { |
||
| 394 | echo "<div id='highPriority'>"; |
||
| 395 | echo "<table border='0' width='100%' cellspacing='1' class='outer'> |
||
| 396 | <tr><th colspan='8'>" . _AM_XHELP_TEXT_HIGH_PRIORITY . '</th></tr>'; |
||
| 397 | echo "<tr class='head'><td>" |
||
| 398 | . _AM_XHELP_TEXT_PRIORITY |
||
| 399 | . '</td><td>' |
||
| 400 | . _AM_XHELP_TEXT_ELAPSED |
||
| 401 | . '</td><td>' |
||
| 402 | . _AM_XHELP_TEXT_STATUS |
||
| 403 | . '</td><td>' |
||
| 404 | . _AM_XHELP_TEXT_SUBJECT |
||
| 405 | . '</td><td>' |
||
| 406 | . _AM_XHELP_TEXT_DEPARTMENT |
||
| 407 | . '</td><td>' |
||
| 408 | . _AM_XHELP_TEXT_OWNER |
||
| 409 | . '</td><td>' |
||
| 410 | . _AM_XHELP_TEXT_LAST_UPDATED |
||
| 411 | . '</td><td>' |
||
| 412 | . _AM_XHELP_TEXT_LOGGED_BY |
||
| 413 | . '</td></tr>'; |
||
| 414 | $i = 0; |
||
| 415 | foreach ($highPriority as $ticket) { |
||
| 416 | if ($ticket->isOverdue()) { |
||
| 417 | $class = $table_class[$i % 2] . ' overdue'; |
||
| 418 | } else { |
||
| 419 | $class = $table_class[$i % 2]; |
||
| 420 | } |
||
| 421 | $priority_url = "<img src='" . XHELP_IMAGE_URL . '/priority' . $ticket->getVar('priority') . ".png' alt='" . $ticket->getVar('priority') . "'>"; |
||
| 422 | $subject_url = sprintf("<a href='" . XHELP_BASE_URL . '/ticket.php?id=' . $ticket->getVar('id') . "' target='_BLANK'>%s</a>", $ticket->getVar('subject')); |
||
| 423 | $dept = $ticket->getDepartment(); |
||
| 424 | if ($dept) { |
||
| 425 | $dept_url = sprintf("<a href='" . XHELP_BASE_URL . '/index.php?op=staffViewAll&dept=' . $dept->getVar('id') . "' target='_BLANK'>%s</a>", $dept->getVar('department')); |
||
| 426 | } else { |
||
| 427 | $dept_url = _AM_XHELP_TEXT_NO_DEPT; |
||
| 428 | } |
||
| 429 | if (0 != $ticket->getVar('ownership')) { |
||
| 430 | $owner_url = sprintf("<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $ticket->getVar('uid') . "' target='_BLANK'>%s</a>", Xhelp\Utility::getUsername($ticket->getVar('ownership'), $displayName)); |
||
| 431 | } else { |
||
| 432 | $owner_url = _AM_XHELP_TEXT_NO_OWNER; |
||
| 433 | } |
||
| 434 | $user_url = sprintf("<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $ticket->getVar('uid') . "' target='_BLANK'>%s</a>", Xhelp\Utility::getUsername($ticket->getVar('uid'), $displayName)); |
||
| 435 | echo "<tr class='$class'><td>" . $priority_url . '</td> |
||
| 436 | <td>' . $ticket->elapsed() . '</td> |
||
| 437 | <td>' . Xhelp\Utility::getStatus($ticket->getVar('status')) . '</td> |
||
| 438 | <td>' . $subject_url . '</td> |
||
| 439 | <td>' . $dept_url . '</td> |
||
| 440 | <td>' . $owner_url . ' </td> |
||
| 441 | <td>' . $ticket->lastUpdated() . '</td> |
||
| 442 | <td>' . $user_url . '</td> |
||
| 443 | </tr>'; |
||
| 444 | ++$i; |
||
| 445 | } |
||
| 446 | echo '</table></div>'; |
||
| 447 | } |
||
| 448 | |||
| 449 | pathConfiguration(); |
||
| 450 | |||
| 451 | require_once __DIR__ . '/admin_footer.php'; |
||
| 452 | } |
||
| 510 |