From fe4cb8da1da74b935f3a0e84a309759d9ea4bccd Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Fri, 6 May 2016 12:56:00 +0200 Subject: [PATCH] Removes no longer needed view helpers --- module/Application/Module.php | 25 ++- module/Application/autoload_classmap.php | 5 - module/Application/config/module.config.php | 10 +- .../src/Application/View/Helper/Bytes.php | 59 ------- .../src/Application/View/Helper/Date.php | 69 -------- .../Helper/{JobDuration.php => Example.php} | 21 ++- .../Application/View/Helper/Expiration.php | 80 ---------- .../View/Helper/HumanReadableTimeperiod.php | 133 --------------- .../src/Application/View/Helper/JobStatus.php | 151 ------------------ .../src/Application/View/Helper/JobType.php | 80 ---------- .../src/Application/View/Helper/Retention.php | 41 ----- .../View/Helper/StatusGlyphicons.php | 51 ------ 12 files changed, 36 insertions(+), 689 deletions(-) delete mode 100644 module/Application/src/Application/View/Helper/Bytes.php delete mode 100644 module/Application/src/Application/View/Helper/Date.php rename module/Application/src/Application/View/Helper/{JobDuration.php => Example.php} (78%) delete mode 100644 module/Application/src/Application/View/Helper/Expiration.php delete mode 100644 module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php delete mode 100644 module/Application/src/Application/View/Helper/JobStatus.php delete mode 100644 module/Application/src/Application/View/Helper/JobType.php delete mode 100644 module/Application/src/Application/View/Helper/Retention.php delete mode 100644 module/Application/src/Application/View/Helper/StatusGlyphicons.php diff --git a/module/Application/Module.php b/module/Application/Module.php index 3be7295c..4a306007 100644 --- a/module/Application/Module.php +++ b/module/Application/Module.php @@ -1,10 +1,27 @@ . + * */ namespace Application; diff --git a/module/Application/autoload_classmap.php b/module/Application/autoload_classmap.php index e1ecf1f1..38bb7e7a 100644 --- a/module/Application/autoload_classmap.php +++ b/module/Application/autoload_classmap.php @@ -2,10 +2,5 @@ return array( 'Application\Module' => __DIR__ . '/Module.php', - 'Application\View\Helper\Date' => __DIR__ . '/src/Application/View/Helper/Date.php', - 'Application\View\Helper\JobStatus' => __DIR__ . '/src/Application/View/Helper/JobStatus.php', - 'Application\View\Helper\JobLevel' => __DIR__ . '/src/Application/View/Helper/JobLevel.php', - 'Application\View\Helper\JobType' => __DIR__ . '/src/Application/View/Helper/JobType.php', - 'Application\View\Helper\JobDuration' => __DIR__ . '/src/Application/View/Helper/JobDuration.php', 'Application\Controller\IndexController' => __DIR__ . '/src/Application/Controller/IndexController.php', ); diff --git a/module/Application/config/module.config.php b/module/Application/config/module.config.php index 079dfde6..bf6d7073 100644 --- a/module/Application/config/module.config.php +++ b/module/Application/config/module.config.php @@ -88,15 +88,7 @@ ), 'view_helpers' => array( 'invokables' => array ( - 'printDate' => 'Application\View\Helper\Date', - 'printJobStatus' => 'Application\View\Helper\JobStatus', - 'printJobType' => 'Application\View\Helper\JobType', - 'printJobDuration' => 'Application\View\Helper\JobDuration', - 'printBytes' => 'Application\View\Helper\Bytes', - 'printRetention' => 'Application\View\Helper\Retention', - 'printHumanReadableTimeperiod' => 'Application\View\Helper\HumanReadableTimeperiod', - 'printExpiration' => 'Application\View\Helper\Expiration', - 'printStatusGlyphicons' => 'Application\View\Helper\StatusGlyphicons', + //'printExample' => 'Application\View\Helper\Example', // Example ViewHelper ), ), 'view_manager' => array( diff --git a/module/Application/src/Application/View/Helper/Bytes.php b/module/Application/src/Application/View/Helper/Bytes.php deleted file mode 100644 index d283615a..00000000 --- a/module/Application/src/Application/View/Helper/Bytes.php +++ /dev/null @@ -1,59 +0,0 @@ -. - * - */ -namespace Application\View\Helper; - -use Zend\View\Helper\AbstractHelper; - -/** - * - */ -class Bytes extends AbstractHelper -{ - - protected $bsize; - - /** - * @method - * @return string - */ - public function __invoke($bytes) - { - - $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); - $this->bsize = "0.00 B"; - - if($bytes > 0) - { - $result = log($bytes) / log(1000); - $this->bsize = round(pow(1000, $result - ($tmp = floor($result))), 2)." ".$units[$tmp]; - } - - return $this->bsize; - - } - -} - diff --git a/module/Application/src/Application/View/Helper/Date.php b/module/Application/src/Application/View/Helper/Date.php deleted file mode 100644 index 3c178d64..00000000 --- a/module/Application/src/Application/View/Helper/Date.php +++ /dev/null @@ -1,69 +0,0 @@ -. - * - */ - -namespace Application\View\Helper; - -use DateTime; -use IntlDateFormatter; -use Zend\View\Helper\AbstractHelper; - -class Date extends AbstractHelper -{ - - public function __invoke($dateString, $mode = 'iso8601') - { - if ($dateString == '0000-00-00 00:00:00' || $dateString == '') { - return '-'; - } - - switch ($mode) { - case 'full': - $dateType = IntlDateFormatter::FULL; - $timeType = IntlDateFormatter::FULL; - break; - case 'long': - $dateType = IntlDateFormatter::LONG; - $timeType = IntlDateFormatter::LONG; - break; - case 'short': - $dateType = IntlDateFormatter::SHORT; - $timeType = IntlDateFormatter::SHORT; - break; - case 'medium': - $dateType = IntlDateFormatter::MEDIUM; - $timeType = IntlDateFormatter::MEDIUM; - break; - default: - case 'iso8601': - return $dateString; - } - - $dateTime = new DateTime($dateString); - - return $this->getView()->dateFormat($dateTime, $dateType, $timeType); - } - -} diff --git a/module/Application/src/Application/View/Helper/JobDuration.php b/module/Application/src/Application/View/Helper/Example.php similarity index 78% rename from module/Application/src/Application/View/Helper/JobDuration.php rename to module/Application/src/Application/View/Helper/Example.php index 6faadea4..ef78041b 100644 --- a/module/Application/src/Application/View/Helper/JobDuration.php +++ b/module/Application/src/Application/View/Helper/Example.php @@ -5,8 +5,9 @@ * bareos-webui - Bareos Web-Frontend * * @link https://github.com/bareos/bareos-webui for the canonical source repository - * @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/) + * @copyright Copyright (c) 2013-2016 Bareos GmbH & Co. KG (http://www.bareos.org/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/) + * @author Frank Bergkemper * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -22,15 +23,21 @@ * along with this program. If not, see . * */ - namespace Application\View\Helper; use Zend\View\Helper\AbstractHelper; -class JobDuration extends AbstractHelper +class Example extends AbstractHelper { - public function __invoke($duration) - { - return $duration; - } + + protected $result; + + public function __invoke($var) + { + $this->result = $var; + + // DO SOMETHING + + return $this->result; + } } diff --git a/module/Application/src/Application/View/Helper/Expiration.php b/module/Application/src/Application/View/Helper/Expiration.php deleted file mode 100644 index 0964586e..00000000 --- a/module/Application/src/Application/View/Helper/Expiration.php +++ /dev/null @@ -1,80 +0,0 @@ -. - * - */ -namespace Application\View\Helper; - -use Zend\View\Helper\AbstractHelper; - -/** - * - */ -class Expiration extends AbstractHelper -{ - - protected $result; - - /** - * @method - * @return string - * @param - * @param - */ - public function __invoke($retention, $lastwritten, $volstatus) - { - - if($volstatus == "Used" || $volstatus == "Full") { - - if(empty($lastwritten)) { - return $this->result = "-"; - } - else { - - $this->result = "-"; - $lw = explode(" ", $lastwritten); - $t1 = explode("-", $lw[0]); - $t2 = explode("-", date("Y-m-d", time("NOW"))); - $d1 = mktime(0, 0, 0, (int)$t1[1],(int)$t1[2],(int)$t1[0]); - $d2 = mktime(0, 0, 0, (int)$t2[1],(int)$t2[2],(int)$t2[0]); - $interval = ($d2 - $d1) / (3600 * 24); - $retention = round(($retention / 60 / 60 / 24 ), 2, PHP_ROUND_HALF_EVEN); - $this->result = round(($retention - $interval), 2, PHP_ROUND_HALF_EVEN); - - if($this->result <= 0) { - return $this->result = "expired"; - } - elseif($this->result > 0) { - return "expires in " . $this->result . " days"; - } - - } - } - else { - return $this->result = round(($retention / 60 / 60 / 24 ), 2, PHP_ROUND_HALF_EVEN) . " days"; - } - - } - -} - diff --git a/module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php b/module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php deleted file mode 100644 index 00fdba8b..00000000 --- a/module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php +++ /dev/null @@ -1,133 +0,0 @@ -. - * - */ -namespace Application\View\Helper; - -use Zend\View\Helper\AbstractHelper; - -/** - * - */ -class HumanReadableTimeperiod extends AbstractHelper -{ - - protected $result; - - /** - * A function for making timeperiods human readable - * @method - * @return string - * @param - * @param - */ - public function __invoke($time, $format="short") - { - - if($time == "0000-00-00 00:00:00" || empty($time)) { - return $this->result = "never"; - } - else { - - $this->result = "-"; - $dateTime = date_create($time); - $timestamp = date_format($dateTime, 'U'); - $seconds = time() - $timestamp; - - if($format == "short") { - - $units = array( - 'y' => $seconds / 31556926 % 12, - 'w' => $seconds / 604800 % 52, - 'd' => $seconds / 86400 % 7, - 'h' => $seconds / 3600 % 24, - 'm' => $seconds / 60 % 60, - 's' => $seconds % 60 - ); - - foreach($units as $key => $value) { - if($value > 0) { - $res[] = $value . $key; - } - } - - $this->result = join(' ', $res) . " ago"; - - } - elseif($format == "long") { - - $units = array( - 'Year(s)' => $seconds / 31556926 % 12, - 'Week(s)' => $seconds / 604800 % 52, - 'Day(s)' => $seconds / 86400 % 7, - 'Hour(s)' => $seconds / 3600 % 24, - 'Minute(s)' => $seconds / 60 % 60, - 'Second(s)' => $seconds % 60 - ); - - foreach($units as $key => $value) { - if($value > 0) { - $res[] = $value . $key; - } - } - - $this->result = join(' ', $res) . " ago"; - - } - elseif($format == "fuzzy") { - - $t1 = explode("-", $time); - $t2 = explode("-", date("Y-m-d", time("NOW"))); - - $d1 = mktime(0, 0, 0, (int)$t1[1],(int)$t1[2],(int)$t1[0]); - $d2 = mktime(0, 0, 0, (int)$t2[1],(int)$t2[2],(int)$t2[0]); - - $interval = ($d2 - $d1) / (3600 * 24); - - if($interval < 1) { - return $this->result = "today"; - } - elseif($interval <= 31 && $interval >= 1) { - $interval = round($interval, 0, PHP_ROUND_HALF_UP); - $this->result = "about " . $interval . " day(s) ago"; - } - elseif($interval >= 31 && $interval <= 365) { - $interval = round($interval / 31, 0, PHP_ROUND_HALF_UP); - $this->result = "about " . $interval . " month ago"; - } - elseif($interval > 365) { - $interval = round($interval / 365, 1, PHP_ROUND_HALF_UP); - $this->result = "about " . $interval . " year(s) ago"; - } - - } - - return $this->result; - - } - - } - -} - diff --git a/module/Application/src/Application/View/Helper/JobStatus.php b/module/Application/src/Application/View/Helper/JobStatus.php deleted file mode 100644 index 57705bbc..00000000 --- a/module/Application/src/Application/View/Helper/JobStatus.php +++ /dev/null @@ -1,151 +0,0 @@ -. - * - */ - -namespace Application\View\Helper; - -use Zend\View\Helper\AbstractHelper; - -class JobStatus extends AbstractHelper -{ - public function __invoke($jobStatus) - { - - switch($jobStatus) - { - // Non-fatal error - case 'e': - $output = 'Failure'; - break; - // Terminated with errors - case 'E': - $output = 'Failure'; - break; - // Fatal error - case 'f': - $output = 'Failure'; - break; - // Terminated successful - case 'T': - $output = 'Success'; - break; - // Running - case 'R': - $output = 'Running'; - break; - // Created no yet running - case 'C': - $output = 'Queued'; - break; - // Blocked - case 'B': - $output = 'Blocked'; - break; - // Verify found differences - case 'D': - $output = 'Verify found differences'; - break; - // Canceled by user - case 'A': - $output = 'Canceled'; - break; - // Waiting for client - case 'F': - $output = 'Waiting'; - break; - // Waiting for storage daemon - case 'S': - $output = 'Waiting'; - break; - // Waiting for new media - case 'm': - $output = 'Waiting'; - break; - // Waiting for media mount - case 'M': - $output = 'Waiting'; - break; - // Waiting for storage resource - case 's': - $output = 'Waiting'; - break; - // Waiting for job resource - case 'j': - $output = 'Waiting'; - break; - // Waiting for client resource - case 'c': - $output = 'Waiting'; - break; - // Waiting on maximum jobs - case 'd': - $output = 'Waiting'; - break; - // Waiting on starttime - case 't': - $output = 'Waiting'; - break; - // Waiting on higher priority jobs - case 'p': - $output = 'Waiting'; - break; - // SD despooling attributes - case 'a': - $output = 'SD despooling attributes'; - break; - // Doing batch insert file records - case 'i': - $output = 'Doing batch insert file records'; - break; - // Incomplete - case 'I': - $output = 'Incomplete'; - break; - // Committing data - case 'L': - $output = 'Committing data'; - break; - // Terminated with warnings - case 'W': - $output = 'Warning'; - break; - // Doing data despooling - case 'l': - $output = 'Doing data despooling'; - break; - // Queued waiting for device - case 'q': - $output = 'Queued waiting for device'; - break; - // Default - default: - $output = '' . $jobStatus . ''; - break; - } - - return $output; - - } - -} diff --git a/module/Application/src/Application/View/Helper/JobType.php b/module/Application/src/Application/View/Helper/JobType.php deleted file mode 100644 index eab1ac82..00000000 --- a/module/Application/src/Application/View/Helper/JobType.php +++ /dev/null @@ -1,80 +0,0 @@ -. - * - */ - -namespace Application\View\Helper; - -use Zend\View\Helper\AbstractHelper; - -class JobType extends AbstractHelper -{ - public function __invoke($jobType) - { - switch($jobType) - { - case 'B': - $output = "Backup"; - break; - case 'M': - $output = "Migrated"; - break; - case 'V': - $output = "Verify"; - break; - case 'R': - $output = "Restore"; - break; - case 'U': - $output = "Console program"; - break; - case 'I': - $output = "Internal system job"; - break; - case 'D': - $output = "Admin"; - break; - case 'A': - $output = "Archive"; - break; - case 'C': - $output = "Copy of a Job"; - break; - case 'c': - $output = "Copy Job"; - break; - case 'g': - $output = "Migration Job"; - break; - case 'S': - $output = "Scan"; - break; - default: - $output = $jobType; - break; - } - - return $output; - - } -} diff --git a/module/Application/src/Application/View/Helper/Retention.php b/module/Application/src/Application/View/Helper/Retention.php deleted file mode 100644 index 89ad34a6..00000000 --- a/module/Application/src/Application/View/Helper/Retention.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * - */ - -namespace Application\View\Helper; - -use Zend\View\Helper\AbstractHelper; - -class Retention extends AbstractHelper -{ - protected $retention; - - public function __invoke($retention) - { - $this->retention = (int) $retention; - $this->retention = round(($this->retention / 60 / 60 / 24 ), 2, PHP_ROUND_HALF_EVEN); - return $this->retention; - } -} diff --git a/module/Application/src/Application/View/Helper/StatusGlyphicons.php b/module/Application/src/Application/View/Helper/StatusGlyphicons.php deleted file mode 100644 index 6563f19d..00000000 --- a/module/Application/src/Application/View/Helper/StatusGlyphicons.php +++ /dev/null @@ -1,51 +0,0 @@ -. - * - */ - -namespace Application\View\Helper; - -use Zend\View\Helper\AbstractHelper; - -class StatusGlyphicons extends AbstractHelper -{ - public function __invoke($status) - { - - switch($status) - { - case '0': - $output = '
'; - break; - case '-1': - $output = '
'; - break; - default: - $output = $status; - break; - } - - return $output; - - } -}