Changeset 1988370
- Timestamp:
- 12/07/2018 10:44:18 PM (7 years ago)
- Location:
- support-hours
- Files:
-
- 40 added
- 6 edited
-
tags/1.5.4 (added)
-
tags/1.5.4/LICENSE.txt (added)
-
tags/1.5.4/README.txt (added)
-
tags/1.5.4/admin (added)
-
tags/1.5.4/admin/class-support-hours-admin.php (added)
-
tags/1.5.4/admin/index.php (added)
-
tags/1.5.4/admin/partials (added)
-
tags/1.5.4/admin/partials/common (added)
-
tags/1.5.4/admin/partials/common/bottom-message.php (added)
-
tags/1.5.4/admin/partials/common/notice-configure.php (added)
-
tags/1.5.4/admin/partials/common/notice-no-hours.php (added)
-
tags/1.5.4/admin/partials/common/worktable.php (added)
-
tags/1.5.4/admin/partials/settings (added)
-
tags/1.5.4/admin/partials/settings/general-settings-form.php (added)
-
tags/1.5.4/admin/partials/settings/work-table-fields.php (added)
-
tags/1.5.4/admin/partials/settings/work-table-form.php (added)
-
tags/1.5.4/admin/partials/widgets (added)
-
tags/1.5.4/admin/partials/widgets/widget-clock.php (added)
-
tags/1.5.4/admin/support-hours-admin-functions.php (added)
-
tags/1.5.4/admin/support-hours-admin-overview.php (added)
-
tags/1.5.4/admin/support-hours-admin-settings.php (added)
-
tags/1.5.4/admin/support-hours-admin-widget.php (added)
-
tags/1.5.4/dist (added)
-
tags/1.5.4/dist/scripts (added)
-
tags/1.5.4/dist/scripts/support-hours-admin.js (added)
-
tags/1.5.4/dist/styles (added)
-
tags/1.5.4/dist/styles/support-hours-admin.css (added)
-
tags/1.5.4/includes (added)
-
tags/1.5.4/includes/class-support-hours-activator.php (added)
-
tags/1.5.4/includes/class-support-hours-deactivator.php (added)
-
tags/1.5.4/includes/class-support-hours-i18n.php (added)
-
tags/1.5.4/includes/class-support-hours-loader.php (added)
-
tags/1.5.4/includes/class-support-hours.php (added)
-
tags/1.5.4/includes/index.php (added)
-
tags/1.5.4/languages (added)
-
tags/1.5.4/languages/support-hours-nl_NL.mo (added)
-
tags/1.5.4/languages/support-hours-nl_NL.po (added)
-
tags/1.5.4/languages/support-hours.pot (added)
-
tags/1.5.4/support-hours.php (added)
-
tags/1.5.4/uninstall.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/partials/common/bottom-message.php (modified) (1 diff)
-
trunk/admin/partials/common/worktable.php (modified) (1 diff)
-
trunk/admin/partials/widgets/widget-clock.php (modified) (1 diff)
-
trunk/admin/support-hours-admin-functions.php (modified) (5 diffs)
-
trunk/support-hours.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
support-hours/trunk/README.txt
r1975615 r1988370 4 4 Requires at least: 4.6 5 5 Tested up to: 5.0 6 Stable tag: 1.5. 36 Stable tag: 1.5.4 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later … … 46 46 47 47 == Changelog == 48 49 = 1.5.4 = 50 * Fixed widget circle percentage when multiple times hours were added 51 * Fixed total time issue in the widget output. 48 52 49 53 = 1.5.3 = -
support-hours/trunk/admin/partials/common/bottom-message.php
r1960674 r1988370 18 18 endif; 19 19 if ($pagenow == 'index.php'): 20 $percentage = percentage($ used_minutes, $bought_minutes);20 $percentage = percentage($workFields, $used_minutes, $bought_minutes); 21 21 ?> 22 22 <p> -
support-hours/trunk/admin/partials/common/worktable.php
r1975615 r1988370 21 21 <tbody> 22 22 <?php 23 $widget_fields = $workFields; 23 24 if ($pagenow == 'index.php'): 24 $w orkFields = array_slice($workFields, -5);25 $widget_fields = array_slice($workFields, -5); 25 26 endif; 26 foreach ( $w orkFields as $field ) { ?>27 foreach ( $widget_fields as $field ) { ?> 27 28 <tr> 28 29 <td><?php if(!empty($field['used'])) echo $field['date'] ?></td> -
support-hours/trunk/admin/partials/widgets/widget-clock.php
r1975615 r1988370 1 <div class="progress-bar position <?php echo $current_color;?>" data-percent="<?php echo percentage($ used_minutes, $bought_minutes); ?>">1 <div class="progress-bar position <?php echo $current_color;?>" data-percent="<?php echo percentage($workFields, $used_minutes, $bought_minutes); ?>"> 2 2 <div class="progress-bar__background"> 3 3 <div class="progress-bar__rotate"></div> -
support-hours/trunk/admin/support-hours-admin-functions.php
r1968512 r1988370 15 15 // NOTE: temp function to transform first set of hours to new hour system. 16 16 function transform_fixed_time($static_time, $workFields, $name, $options){ 17 if($options['bought_hours'] != '00:00'){18 echo "<h3>". __('Update of Support Hours complete, please refresh page', $name)."</h3>";19 $newdata = array (20 'date' => date('d-m-Y'),21 'description' => __('First bought time - added by Support Hours', $name),22 'used' => $static_time,23 'type' => 'time-added'24 );25 array_unshift($options['workFields'], $newdata);26 //$options = array_diff_key($options, ['bought_hours' => "xy"]);27 28 $options['workFields'] = array_map(function($arr){29 return $arr + ['type' =>'time-used'];30 }, $options['workFields']);31 32 update_option($name, $options);33 }17 if($options['bought_hours'] != '00:00'){ 18 echo "<h3>". __('Update of Support Hours complete, please refresh page', $name)."</h3>"; 19 $newdata = array ( 20 'date' => date('d-m-Y'), 21 'description' => __('First bought time - added by Support Hours', $name), 22 'used' => $static_time, 23 'type' => 'time-added' 24 ); 25 array_unshift($options['workFields'], $newdata); 26 //$options = array_diff_key($options, ['bought_hours' => "xy"]); 27 28 $options['workFields'] = array_map(function($arr){ 29 return $arr + ['type' =>'time-used']; 30 }, $options['workFields']); 31 32 update_option($name, $options); 33 } 34 34 } 35 35 echo transform_fixed_time($static_time, $workFields, $name, $options); 36 36 */ 37 37 38 /** 39 * Transforms $minutes to HH:MM 40 * @since 41 * @param int $minutes minutes, can be bought or used 42 * @return string HH:MM 43 */ 38 44 function minutestoTime($minutes){ 39 45 return sprintf("%02d:%02d", floor($minutes/60), $minutes%60); // 01:37 40 46 } 41 // function to strip the hours displayed in the clock of minutes if the hour is round. 47 48 /** 49 * function to strip the hours displayed in the clock of minutes if the hour is round. 50 * @since 51 * @param [type] $minutes minutes, can be bought or used 52 * @return string Retunrs full hour without zeros 53 */ 42 54 function minutestoTimeRound($minutes) { 43 if($minutes % 60 == 0):55 if($minutes % 60 == 0): 44 56 $time = $minutes/60; 45 57 else: … … 49 61 } 50 62 51 /* 52 Checks the workfields for the time fields. Adds all timefields and returns them. 53 If no workfields and therefore no time fields are filled, returns 00:00 54 */ 55 63 64 65 /** 66 * Checks the workfields array for the time fields. Adds all timefields and returns them. 67 * If no workfields and therefore no time fields are filled, returns 00:00 68 * @since 1.4 69 * @param array $workFields The workfields from this plugin, contains bought and used hours 70 * @param string $type can be used or bought 71 * @param string $returns if minutes returns total minutes 72 * @return string Returns full hours format or total minutes of used or bought hours 73 */ 56 74 function AddTime($workFields, $type, $returns = null) { 75 $output = 0; 76 $minutes = 0; 57 77 if($workFields != null){ 58 $minutes = 0;59 78 if(isset($workFields[0]['type'])): 60 79 $workFields = array_filter($workFields, function ($var) use ($type) { 61 80 return ($var['type'] == $type); 62 81 }); 63 foreach ($workFields as $time) {82 foreach ($workFields as $time) { 64 83 // Check if the field is not empty. Else stay with 0. 65 84 if($time['type'] !== ""){ … … 70 89 } 71 90 if($returns == 'minutes'): 72 return$minutes;91 $output = $minutes; 73 92 else: 74 93 $hours = floor($minutes / 60); 75 94 $minutes -= $hours * 60; 76 95 $time = sprintf('%02d:%02d', $hours, $minutes); 77 return$time;96 $output = $time; 78 97 endif; 79 98 endif; 80 } else{ 81 return "0"; 82 } 83 } 84 99 } 100 return $output; 101 } 102 103 104 105 /** 106 * Searches our $workFields array for the last bought hours. 107 * @since 108 * @param array $workFields The workfields from this plugin, contains bought and used hours 109 * @return int Last bought hours in minute format 110 */ 85 111 function last_bought($workFields){ 86 112 $minutes = 0; 87 113 if($workFields != null){ 88 $workFields = array_reverse($workFields); 89 $key = array_search('time-added', array_column($workFields, 'type')); 90 91 if($key !== false): 92 $time = $workFields[$key]['used']; 93 list($hour, $minute) = explode(':', $time); 94 $minutes += $hour * 60; 95 $minutes += $minute; 96 return $minutes; 97 else: 98 return 0; 114 $workFields = array_reverse($workFields); // invert array so we can search DESC 115 $key = array_search('time-added', array_column($workFields, 'type')); // searching for the last time-added value in key 'type' 116 117 if($key !== false): // if there is a key! 118 $time = $workFields[$key]['used']; // take our time in HH:MM format from the field 119 list($hour, $minute) = explode(':', $time); // explode the time 120 $minutes += $hour * 60; // hours to minutes, add them to minutes 121 $minutes += $minute; // add minutes to total as well. 99 122 endif; 100 } 101 return 0; 102 } 123 124 } 125 return $minutes; 126 } 127 128 129 130 /** 131 * To not overcluther the interface we only show the time you actually care about in the widget. 132 * If multiple time hours are bought, and most of it was spent, we only want to see the 133 * last bought hours and the hours left calculated against that. 134 * This function is used to return all used minutes minus all the minutes prior to the last bought hours 135 * so we can display the used hours correctly. Used in percentage() and widget_output() 136 * @since 137 * @param array $workFields The workfields from this plugin, contains bought and used hours 138 * @param int $bought_minutes Total bought minutes 139 * @return int minutes 140 */ 103 141 function bought_minus_last($workFields, $bought_minutes){ 142 $output = 0; 143 104 144 if($workFields != null){ 105 return $bought_minutes - last_bought($workFields); 106 } else{ 107 return 0; 108 } 109 } 110 145 $output = $bought_minutes - last_bought($workFields); 146 } 147 148 return $output; 149 } 150 151 152 153 154 /** 155 * This function is being used to display the hours in the widget. 156 * Output depends on time spent, time bought and time bought the last time. 157 * @since 1.4 158 * @param array $workFields The workfields from this plugin, contains bought and used hours 159 * @param int $used_minutes Total used minutes 160 * @param int $bought_minutes Total bought minutes 161 * @return string Returns hours in HH:MM format or HH format where the first is used time, the second the bought time. 162 */ 111 163 function widget_output($workFields, $used_minutes, $bought_minutes){ 112 164 $bought_minus_last = bought_minus_last($workFields, $bought_minutes); 113 165 $minutes_to_spent = $bought_minutes - $used_minutes; 114 166 $last_bought_minutes = last_bought($workFields); 115 // NOTE: calculates spent hours 167 168 // NOTE: calculates used hours 116 169 if($used_minutes > $bought_minus_last){ 117 170 $used_minutes = $used_minutes - $bought_minus_last; … … 119 172 $used_minutes = $used_minutes; 120 173 } 121 // NOTE: returns hours left 174 175 // NOTE: calculates bought hours 122 176 if($minutes_to_spent < $last_bought_minutes){ 123 177 $bought_minutes = $last_bought_minutes; … … 125 179 $bought_minutes = $bought_minutes; 126 180 } 181 127 182 $widget_hours = minutestoTimeRound($used_minutes).' / '.minutestoTimeRound($bought_minutes); 128 183 return $widget_hours; 129 184 } 130 185 131 function percentage($used_minutes, $bought_minutes){ 132 133 if($used_minutes > $bought_minutes){ 134 $used_minutes = $bought_minutes; 135 } 136 if(!empty($bought_minutes)){ 137 $percentage = $used_minutes * 100 / $bought_minutes; 138 if($percentage > 100){ 139 $percentage = 100; 140 } 141 $percentage = round($percentage); 142 return $percentage; 143 } 144 } 145 146 147 // function to control the font size 186 187 188 189 /** 190 * used for calculating the hours left in the notices 191 * and in the widget to animate the circle. 192 * @since 193 * @param array $workFields The workfields from this plugin, contains bought and used hours 194 * @param int $used_minutes Total used minutes 195 * @param int $bought_minutes Total bought minutes 196 * @return int Calculated percentage 197 */ 198 function percentage($workFields, $used_minutes, $bought_minutes){ 199 200 $bought_minus_last = bought_minus_last($workFields, $bought_minutes); 201 $minutes_to_spent = $bought_minutes - $used_minutes; 202 $last_bought_minutes = last_bought($workFields); 203 204 // NOTE: calculates used hours 205 if($used_minutes > $bought_minus_last){ 206 $used_minutes = $used_minutes - $bought_minus_last; 207 } else{ 208 $used_minutes = $used_minutes; 209 } 210 211 // NOTE: calculates bought hours 212 if($minutes_to_spent < $last_bought_minutes){ 213 $bought_minutes = $last_bought_minutes; 214 } else{ 215 $bought_minutes = $bought_minutes; 216 } 217 218 $percentage = $used_minutes * 100 / $bought_minutes; 219 if($percentage > 100){ 220 $percentage = 100; 221 } 222 $percentage = round($percentage); 223 return $percentage; 224 225 } 226 227 228 229 /** 230 * Control the font size of the time in the widget 231 * big font size if time doesn't include :00 (minutes) 232 * and bought hours are less then 99 hours. Otherwise UI will be too cluttered. 233 * @since 234 * @param int $used_minutes Total used minutes 235 * @param int $bought_minutes Total bought minutes 236 * @return string small or big, this is used in our css to display the correct font size 237 */ 148 238 function font_size($used_minutes, $bought_minutes){ 149 // big font size if time doesn't include :00 (minutes) and bought hours are less then 99 hours. Otherwise UI will be too cluttered. 239 $size = 'small'; 240 150 241 if($used_minutes %60 == 0 && $bought_minutes < 5940): 151 242 $size = 'big'; 152 else:153 $size = 'small';154 243 endif; 244 155 245 return $size; 156 246 } -
support-hours/trunk/support-hours.php
r1975615 r1988370 17 17 * Plugin URI: http://basedonline.nl 18 18 * Description: Use Support hours to give yourself and your clients insights on the status of pre-paid work. 19 * Version: 1.5. 319 * Version: 1.5.4 20 20 * Author: Erik van der Bas 21 21 * Author URI: https://basedonline.nl
Note: See TracChangeset
for help on using the changeset viewer.