| 1 |
<?php
|
| 2 |
// $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()
|
| 57 |
*/
|
| 58 |
function timemap_sample_reports_timemap_report($op = 'list', $delta = 0, $stats = null) {
|
| 59 |
switch($op) {
|
| 60 |
|
| 61 |
case 'list':
|
| 62 |
$return[] = array(
|
| 63 |
'module' => 'timemap_sample_reports', // The module's name that is providing this report!!!
|
| 64 |
'title' => 'redfish',
|
| 65 |
'delta' => 0,
|
| 66 |
);
|
| 67 |
$return[] = array(
|
| 68 |
'module' => 'timemap_sample_reports', // The module's name that is providing this report!!!
|
| 69 |
'title' => 'bluefish',
|
| 70 |
'delta' => 1,
|
| 71 |
);
|
| 72 |
return $return;
|
| 73 |
|
| 74 |
case 'view':
|
| 75 |
switch($delta) {
|
| 76 |
case 0:
|
| 77 |
return timemap_sample_reports_get_report_0($stats);
|
| 78 |
case 1:
|
| 79 |
return timemap_sample_reports_get_report_1($stats);
|
| 80 |
}
|
| 81 |
break;
|
| 82 |
|
| 83 |
}
|
| 84 |
}
|
| 85 |
|
| 86 |
|
| 87 |
/**
|
| 88 |
* First Report : "Red Fish"
|
| 89 |
*/
|
| 90 |
function timemap_sample_reports_get_report_0($stats = null) {
|
| 91 |
$report = array();
|
| 92 |
$lastmidnight = strtotime(date("F j, Y") . " 12:00 am");
|
| 93 |
$days = $stats['info']['days'];
|
| 94 |
|
| 95 |
for ($i=$days; $i>0; $i--) {
|
| 96 |
$daybegin = $lastmidnight - (($i-1) * 86400);
|
| 97 |
$dayend = $daybegin + 86400 - 1;
|
| 98 |
$report[$i] = array();
|
| 99 |
$report[$i]['info'] = array(
|
| 100 |
'date' => date('D, j-M-Y',$daybegin),
|
| 101 |
'daybegin' => $daybegin,
|
| 102 |
);
|
| 103 |
|
| 104 |
$report[$i]['items'] = array();
|
| 105 |
while ($item = array_shift($stats['items'])) {
|
| 106 |
if ($item['time'] <= $dayend) {
|
| 107 |
//at what % into the day did this start?
|
| 108 |
$pcnt = round(($item['time'] - $daybegin) / 864) / 100;
|
| 109 |
//if negative, ie, carryover from previous day, reset to 0 for today.
|
| 110 |
if ($pcnt < 0) {
|
| 111 |
$pcnt = 0;
|
| 112 |
}
|
| 113 |
|
| 114 |
//peek ahead to see when this finished.
|
| 115 |
$finished = $stats['items'][0]['time'];
|
| 116 |
$length = $finsihed - $item['time'];
|
| 117 |
$length_pcnt = (round(($finished - $daybegin) / 864) / 100) - $pcnt;
|
| 118 |
//check to see if it goes past midnight and into tomorrow.
|
| 119 |
if (($pcnt + $length_pcnt) > 1) {
|
| 120 |
$length_pcnt = 1 - $pcnt;
|
| 121 |
// array_unshift($stats['items'], $item);
|
| 122 |
}
|
| 123 |
|
| 124 |
$report[$i]['items'][] = array(
|
| 125 |
'task' => $item['task'],
|
| 126 |
'cid' => $item['cid'],
|
| 127 |
'category' => $item['category'],
|
| 128 |
'day_pcnt' => $pcnt,
|
| 129 |
'length_pcnt' => $length_pcnt,
|
| 130 |
'time' => $item['time'],
|
| 131 |
);
|
| 132 |
}
|
| 133 |
else {
|
| 134 |
array_unshift($stats['items'], $item);
|
| 135 |
break;
|
| 136 |
}
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
| 140 |
return theme('timemap_sample_reports_get_report_0', $report);
|
| 141 |
}
|
| 142 |
|
| 143 |
/**
|
| 144 |
* Theme the First Report
|
| 145 |
*/
|
| 146 |
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');
|
| 148 |
$return = '<div class="timemap_report0">';
|
| 149 |
foreach ($report as $day) {
|
| 150 |
$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>';
|
| 152 |
|
| 153 |
foreach ($day['items'] as $item) {
|
| 154 |
$right = 1 - ($item['day_pcnt'] + $item['length_pcnt']);
|
| 155 |
$return .= '<div class="timemap_task">
|
| 156 |
<span class="timemap_task_bar" style="left:'.($item['day_pcnt']*100).'%; right:'.($right*100).'%;">
|
| 157 |
' . $item['task'] . '
|
| 158 |
</span>
|
| 159 |
</div>';
|
| 160 |
}
|
| 161 |
$return .= '</div>';
|
| 162 |
}
|
| 163 |
$return .= '</div>';
|
| 164 |
|
| 165 |
return $return;
|
| 166 |
}
|
| 167 |
|
| 168 |
|
| 169 |
/**
|
| 170 |
* Second Report : "Blue Fish"
|
| 171 |
*/
|
| 172 |
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>';
|
| 174 |
}
|