| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: timemap_sample_reports.module,v 1.1 2008/06/03 02:34:15 sethfreach Exp $ |
| 3 |
|
|
| 4 |
|
/* TODO FormAPI image buttons are now supported. |
| 5 |
|
FormAPI now offers the 'image_button' element type, allowing developers to |
| 6 |
|
use icons or other custom images in place of traditional HTML submit buttons. |
| 7 |
|
|
| 8 |
|
$form['my_image_button'] = array( |
| 9 |
|
'#type' => 'image_button', |
| 10 |
|
'#title' => t('My button'), |
| 11 |
|
'#return_value' => 'my_data', |
| 12 |
|
'#src' => 'my/image/path.jpg', |
| 13 |
|
); */ |
| 14 |
|
|
| 15 |
|
/* TODO New user_mail_tokens() method may be useful. |
| 16 |
|
user.module now provides a user_mail_tokens() function to return an array |
| 17 |
|
of the tokens available for the email notification messages it sends when |
| 18 |
|
accounts are created, activated, blocked, etc. Contributed modules that |
| 19 |
|
wish to make use of the same tokens for their own needs are encouraged |
| 20 |
|
to use this function. */ |
| 21 |
|
|
| 22 |
|
/* TODO |
| 23 |
|
There is a new hook_watchdog in core. This means that contributed modules |
| 24 |
|
can implement hook_watchdog to log Drupal events to custom destinations. |
| 25 |
|
Two core modules are included, dblog.module (formerly known as watchdog.module), |
| 26 |
|
and syslog.module. Other modules in contrib include an emaillog.module, |
| 27 |
|
included in the logging_alerts module. See syslog or emaillog for an |
| 28 |
|
example on how to implement hook_watchdog. |
| 29 |
|
function example_watchdog($log = array()) { |
| 30 |
|
if ($log['severity'] == WATCHDOG_ALERT) { |
| 31 |
|
mysms_send($log['user']->uid, |
| 32 |
|
$log['type'], |
| 33 |
|
$log['message'], |
| 34 |
|
$log['variables'], |
| 35 |
|
$log['severity'], |
| 36 |
|
$log['referer'], |
| 37 |
|
$log['ip'], |
| 38 |
|
format_date($log['timestamp'])); |
| 39 |
|
} |
| 40 |
|
} */ |
| 41 |
|
|
| 42 |
|
/* TODO Implement the hook_theme registry. Combine all theme registry entries |
| 43 |
|
into one hook_theme function in each corresponding module file. |
| 44 |
|
function timemap_sample_reports_theme() { |
| 45 |
|
return array( |
| 46 |
|
'timemap_sample_reports_get_report_0' => array( |
| 47 |
|
'file' => 'timemap_sample_reports.module', |
| 48 |
|
'arguments' => array( |
| 49 |
|
'report' => NULL, |
| 50 |
|
), |
| 51 |
|
), |
| 52 |
|
); |
| 53 |
|
} */ |
| 54 |
|
|
| 55 |
/** |
/** |
| 56 |
* Implementation of hook_timemap_report() |
* Implementation of hook_timemap_report() |
| 57 |
*/ |
*/ |
| 58 |
function timemap_sample_reports_timemap_report($op = 'list', $delta = 0, $stats = null) { |
function timemap_sample_reports_timemap_report($op = 'list', $delta = 0, $stats = null) { |
| 59 |
switch($op) { |
switch($op) { |
| 60 |
|
|
| 86 |
|
|
| 87 |
/** |
/** |
| 88 |
* First Report : "Red Fish" |
* First Report : "Red Fish" |
| 89 |
*/ |
*/ |
| 90 |
function timemap_sample_reports_get_report_0($stats = null) { |
function timemap_sample_reports_get_report_0($stats = null) { |
| 91 |
$report = array(); |
$report = array(); |
| 92 |
$lastmidnight = strtotime(date("F j, Y") . " 12:00 am"); |
$lastmidnight = strtotime(date("F j, Y") . " 12:00 am"); |
| 93 |
$days = $stats['info']['days']; |
$days = $stats['info']['days']; |
| 94 |
|
|
| 95 |
for ($i=$days; $i>0; $i--) { |
for ($i=$days; $i>0; $i--) { |
| 96 |
$daybegin = $lastmidnight - (($i-1) * 86400); |
$daybegin = $lastmidnight - (($i-1) * 86400); |
| 97 |
$dayend = $daybegin + 86400 - 1; |
$dayend = $daybegin + 86400 - 1; |
| 99 |
$report[$i]['info'] = array( |
$report[$i]['info'] = array( |
| 100 |
'date' => date('D, j-M-Y',$daybegin), |
'date' => date('D, j-M-Y',$daybegin), |
| 101 |
'daybegin' => $daybegin, |
'daybegin' => $daybegin, |
| 102 |
); |
); |
| 103 |
|
|
| 104 |
$report[$i]['items'] = array(); |
$report[$i]['items'] = array(); |
| 105 |
while ($item = array_shift($stats['items'])) { |
while ($item = array_shift($stats['items'])) { |
| 106 |
if ($item['time'] <= $dayend) { |
if ($item['time'] <= $dayend) { |
| 107 |
//at what % into the day did this start? |
//at what % into the day did this start? |
| 108 |
$pcnt = round(($item['time'] - $daybegin) / 864) / 100; |
$pcnt = round(($item['time'] - $daybegin) / 864) / 100; |
| 109 |
//if negative, ie, carryover from previous day, reset to 0 for today. |
//if negative, ie, carryover from previous day, reset to 0 for today. |
| 110 |
if ($pcnt < 0) { |
if ($pcnt < 0) { |
| 111 |
$pcnt = 0; |
$pcnt = 0; |
| 112 |
} |
} |
| 113 |
|
|
| 114 |
//peek ahead to see when this finished. |
//peek ahead to see when this finished. |
| 115 |
$finished = $stats['items'][0]['time']; |
$finished = $stats['items'][0]['time']; |
| 116 |
$length = $finsihed - $item['time']; |
$length = $finsihed - $item['time']; |
| 120 |
$length_pcnt = 1 - $pcnt; |
$length_pcnt = 1 - $pcnt; |
| 121 |
// array_unshift($stats['items'], $item); |
// array_unshift($stats['items'], $item); |
| 122 |
} |
} |
| 123 |
|
|
| 124 |
$report[$i]['items'][] = array( |
$report[$i]['items'][] = array( |
| 125 |
'task' => $item['task'], |
'task' => $item['task'], |
| 126 |
'cid' => $item['cid'], |
'cid' => $item['cid'], |
| 128 |
'day_pcnt' => $pcnt, |
'day_pcnt' => $pcnt, |
| 129 |
'length_pcnt' => $length_pcnt, |
'length_pcnt' => $length_pcnt, |
| 130 |
'time' => $item['time'], |
'time' => $item['time'], |
| 131 |
); |
); |
| 132 |
} |
} |
| 133 |
else { |
else { |
| 134 |
array_unshift($stats['items'], $item); |
array_unshift($stats['items'], $item); |
| 135 |
break; |
break; |
| 142 |
|
|
| 143 |
/** |
/** |
| 144 |
* Theme the First Report |
* Theme the First Report |
| 145 |
*/ |
*/ |
| 146 |
function theme_timemap_sample_reports_get_report_0($report) { |
function theme_timemap_sample_reports_get_report_0($report) { |
| 147 |
drupal_add_css(drupal_get_path('module', 'timemap_sample_reports') .'/timemap_sample_reports_0.css'); |
drupal_add_css(drupal_get_path('module', 'timemap_sample_reports') .'/timemap_sample_reports_0.css'); |
| 148 |
$return = '<div class="timemap_report0">'; |
$return = '<div class="timemap_report0">'; |
| 149 |
foreach ($report as $day) { |
foreach ($report as $day) { |
| 150 |
$return .= '<div class="timemap_day">'. $day['info']['date'] .'<br />'; |
$return .= '<div class="timemap_day">'. $day['info']['date'] .'<br />'; |
| 151 |
$return .= '<span class="timemap_timeline">0 . 01 . 02 . 03 . 04 . 05 . 06 . 07 . 08 . 09 . 10 . 11 . 12 . 13 . 14 . 15 . 16 . 17 . 18 . 19 . 20 . 21 . 22 . 23 . 24</span>'; |
$return .= '<span class="timemap_timeline">0 . 01 . 02 . 03 . 04 . 05 . 06 . 07 . 08 . 09 . 10 . 11 . 12 . 13 . 14 . 15 . 16 . 17 . 18 . 19 . 20 . 21 . 22 . 23 . 24</span>'; |
| 152 |
|
|
| 153 |
foreach ($day['items'] as $item) { |
foreach ($day['items'] as $item) { |
| 154 |
$right = 1 - ($item['day_pcnt'] + $item['length_pcnt']); |
$right = 1 - ($item['day_pcnt'] + $item['length_pcnt']); |
| 155 |
$return .= '<div class="timemap_task"> |
$return .= '<div class="timemap_task"> |
| 161 |
$return .= '</div>'; |
$return .= '</div>'; |
| 162 |
} |
} |
| 163 |
$return .= '</div>'; |
$return .= '</div>'; |
| 164 |
|
|
| 165 |
return $return; |
return $return; |
| 166 |
} |
} |
| 167 |
|
|
| 168 |
|
|
| 169 |
/** |
/** |
| 170 |
* Second Report : "Blue Fish" |
* Second Report : "Blue Fish" |
| 171 |
*/ |
*/ |
| 172 |
function timemap_sample_reports_get_report_1($stats = null) { |
function timemap_sample_reports_get_report_1($stats = null) { |
| 173 |
return '<p> This is the <span style="color:blue">Blue Fish</span> report. It dosen\'t really contain any useful info.</p>'; |
return '<p> This is the <span style="color:blue">Blue Fish</span> report. It dosen\'t really contain any useful info.</p>'; |
| 174 |
} |
} |