/[drupal]/contributions/modules/project_forecast/project_forecast.providers.inc
ViewVC logotype

Contents of /contributions/modules/project_forecast/project_forecast.providers.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Fri Jan 16 19:05:18 2009 UTC (10 months, 1 week ago) by jpetso
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Changes since 1.2: +4 -1 lines
File MIME type: text/x-php
The label customization got lost in the recent
"use value_provider template" commit, add it back.
1 <?php
2 // $Id: project_forecast.providers.inc,v 1.2 2009/01/16 17:00:23 jpetso Exp $
3 /**
4 * @file
5 * Project Forecast - Estimate completion dates for your project's tasks.
6 *
7 * This file contains an implementation of hook_value_provider_info(),
8 * providing an 'hours' value type.
9 *
10 * Copyright 2007 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
11 */
12
13 /**
14 * Implementation of hook_value_provider_info():
15 * Return information about which fields can represent time need values,
16 * and how to parse them into the number of hours required for this task.
17 */
18 function project_forecast_value_provider_info() {
19 $providers = array();
20
21 if (module_exists('content') && module_exists('duration')) {
22 foreach (content_fields() as $field) {
23 $field_db_info = content_database_info($field);
24
25 switch ($field['type']) {
26 case 'duration':
27 // Hours with standard 24/7 conversion factors.
28 $provider = value_provider_content_provider_base($field);
29 $provider['parse callback'] = 'project_forecast_parse_duration_hours';
30 $providers['hours'][$field['field_name']] = $provider;
31
32 // Hours with work week (8 hours a day, 5 days a week) conversion factors.
33 $provider['title'] = t('!label - work week conversions', array(
34 '!label' => value_provider_content_field_title($field)
35 ));
36 $provider['parse callback'] = 'project_forecast_parse_duration_hours_workweek';
37 $providers['hours'][$field['field_name'] . '_workweek'] = $provider;
38 break;
39 }
40 }
41 }
42 return $providers;
43 }
44
45 /**
46 * Implementation of hook_value_provider_info_alter():
47 * Duplicate all 'number' providers as 'hours' providers.
48 */
49 function project_forecast_value_provider_info_alter(&$providers) {
50 if (isset($providers['number'])) {
51 foreach ($providers['number'] as $provider_name => $provider) {
52 $providers['hours'][$provider_name] = $provider;
53 }
54 }
55 }
56
57 /**
58 * Transform a duration field into the corresponding number of hours,
59 * using standard 24/7 conversion factors.
60 */
61 function project_forecast_parse_duration_hours($value_properties) {
62 $seconds = isset($value_properties['approx_seconds'])
63 ? $value_properties['approx_seconds']
64 : 0;
65 return $seconds / 3600;
66 }
67
68 /**
69 * Transform a duration field into the corresponding number of hours,
70 * using work week conversion factors.
71 */
72 function project_forecast_parse_duration_hours_workweek($value_properties) {
73 $iso_string = $value_properties['iso8601'];
74 if (empty($iso_string)) {
75 return 0;
76 }
77 $duration = duration_create($iso_string);
78 if (isset($duration)) {
79 $duration->set_conversion_factors(array(
80 'days/months' => variable_get('project_forecast_days_per_month', 22),
81 'days/weeks' => variable_get('project_forecast_days_per_week', 5),
82 'hours/days' => variable_get('project_forecast_hours_per_day', 8),
83 ));
84 return $duration->to_single_metric('hours');
85 }
86 return 0;
87 }

  ViewVC Help
Powered by ViewVC 1.1.2