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

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

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


Revision 1.4 - (show annotations) (download) (as text)
Thu Oct 30 14:57:01 2008 UTC (12 months, 4 weeks ago) by jpetso
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC3, DRUPAL-6--1-0, HEAD
Changes since 1.3: +50 -12 lines
File MIME type: text/x-php
Yay for usability: Eliminate the "Task filters" page and instead
put the filters next to the view settings on the central admin page.
Less error prone, better overview, outright damn cool.

With this in place, I feel confident to release an 1.0.
(But first, sevi's improved Task Status add-on shall still be merged.)
1 <?php
2 // $Id: project_forecast.admin.inc,v 1.3 2008/09/24 16:06:16 jpetso Exp $
3 /**
4 * @file
5 * Project Forecast - Estimate completion dates for your project's tasks.
6 *
7 * This file contains the general parts of the administrative user interface.
8 * The "Task filters" page has been outsourced to the .admin.filters.inc file
9 * because of its complexity.
10 *
11 * Copyright 2007 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
12 */
13
14 /**
15 * Form callback for "admin/project/forecast[/relationships]":
16 * Let the admin select views of issues (plus arguments)
17 * and other node relationships.
18 */
19 function project_forecast_admin(&$form_state) {
20 $view_options = array();
21 $all_views = views_get_all_views();
22 foreach ($all_views as $view) {
23 $view_options[$view->name] = $view->name;
24 }
25 $tasks_view_name = variable_get('project_forecast_tasks_view', '');
26 $filters = variable_get('project_forecast_task_filters_open', array());
27
28 $form_state['original_tasks_view'] = $tasks_view_name;
29
30 // Notify the user about missing additional filters, as it's easy to miss.
31 if (empty($tasks_view_name)) {
32 $filter_options[] = l(t('Please select a view before adding filters here.'));
33 }
34 else {
35 include_once(drupal_get_path('module', 'project_forecast') . '/project_forecast.admin.filters.inc');
36
37 $view_settings = _project_forecast_tasks_view();
38 $tasks_view = $view_settings['view'];
39 $display_id = $view_settings['display_id'];
40 $tasks_view->set_display($display_id);
41 $display = &$tasks_view->display[$display_id];
42
43 // Get labels of the selected filters
44 $filter_options = array();
45 foreach ($filters as $key => $filter) {
46 $handler = views_get_handler($filter['table'], $filter['field'], 'filter');
47 if (empty($handler)) {
48 continue;
49 }
50 $handler->init($tasks_view, $filter['item']);
51 $filter_options[] = t('!filter-type @filter-summary (!delete)', array(
52 '!filter-type' => l($handler->ui_name(),
53 'admin/project/forecast/task-filters-open/edit/'. $key
54 ),
55 '@filter-summary' => $handler->admin_summary(),
56 '!delete' => l(t('delete'), 'admin/project/forecast/task-filters-open/delete/'. $key),
57 ));
58 }
59
60 if (empty($filters)) {
61 $filter_options = '<div class="messages warning"><ul><li><strong>' . l(t('Add filter...'), 'admin/project/forecast/task-filters-open/add') . '</strong><br/>' . t('You have not configured any additional filters for reducing this view to only open tasks. Please add one or more such filters, so that Project Forecast can restrict its queries to just the tasks that need to be considered for target date estimate calculations.') . '</li></ul></div>';
62 }
63 else {
64 $filter_options[] = l(t('Add filter...'), 'admin/project/forecast/task-filters-open/add');
65 $filter_options = '<ul><li>' . implode('</li><li>', $filter_options) . '</li></ul>';
66 }
67 }
68
69 $hours_providers = value_provider_options('hours');
70 $nid_providers = value_provider_options('nid');
71 $uid_providers = value_provider_options('uid');
72
73 $form = array();
74
75 $form['general'] = array(
76 '#type' => 'fieldset',
77 '#title' => t('Task retrieval'),
78 '#description' => t('Define how the list of tasks to be analyzed (...or issues, cases, bugs) is going be retrieved.'),
79 '#collapsible' => TRUE,
80 '#collapsed' => ($tasks_view_name != '' && !empty($filters) && empty($_GET['show-view-settings'])),
81 );
82 $form['general']['project_forecast_tasks_view'] = array(
83 '#type' => 'select',
84 '#title' => t('View of all tasks'),
85 '#options' => array_merge(array('' => t('please select a view')), $view_options),
86 '#required' => TRUE,
87 '#default_value' => $tasks_view_name,
88 '#description' => t('Choose the "Views module" view that selects all task nodes. The forecast will automatically filter this view according to its needs, using the other information that you provide here. For open tasks, the view\'s "sort criteria" section will be used to determine in which order the users are expected to complete these tasks.'),
89 );
90 $form['general']['project_forecast_tasks_view_args'] = array(
91 '#type' => 'textfield',
92 '#title' => t('View arguments'),
93 '#default_value' => variable_get('project_forecast_tasks_view_args', ''),
94 '#required' => FALSE,
95 '#description' => t('Provide a comma separated list of arguments to pass to the above view.'),
96 );
97 $form['general']['project_forecast_tasks_view_filters_open'] = array(
98 '#type' => 'item',
99 '#title' => t('Filter(s) for only including open tasks'),
100 '#value' => $filter_options,
101 );
102 $form['properties'] = array(
103 '#type' => 'fieldset',
104 '#title' => t('Task properties'),
105 '#description' => t('Define which data from the task nodes is going to be used by the forecast.'),
106 '#collapsible' => TRUE,
107 '#collapsed' => FALSE,
108 );
109 $form['properties']['project_forecast_timeneed_provider'] = array(
110 '#type' => 'select',
111 '#title' => t('Field for the task\'s time need'),
112 '#options' => empty($hours_providers)
113 ? array('' => t('Please create a duration field.'))
114 : $hours_providers,
115 '#required' => TRUE,
116 '#default_value' => variable_get('project_forecast_timeneed_provider', ''),
117 '#description' => t('The project forecast needs to know how many time is still required for a given task, and this information is extracted from the field that you need to specify here. Tasks without this field are assumed to have a zero-length time need.'),
118 );
119 $form['properties']['project_forecast_project_nid_provider'] = array(
120 '#type' => 'select',
121 '#title' => t('Field for the project node that contains the task'),
122 '#options' => empty($nid_providers)
123 ? array('' => t('Please create a node reference field.'))
124 : $nid_providers,
125 '#required' => TRUE,
126 '#default_value' => variable_get('project_forecast_project_nid_provider', ''),
127 '#description' => t('The project forecast needs to know which project contains the given task, and this information is extracted from the field that you need to specify here.'),
128 );
129 $form['properties']['project_forecast_assigned_uid_provider'] = array(
130 '#type' => 'select',
131 '#title' => t('Field for the user who is assigned to this task'),
132 '#options' => empty($uid_providers)
133 ? array('' => t('Please create a user reference field.'))
134 : $uid_providers,
135 '#required' => TRUE,
136 '#default_value' => variable_get('project_forecast_assigned_uid_provider', ''),
137 '#description' => t('The project forecast needs to know which user a task is assigned to, in order to process the tasks separately for each user. This field is required to provide this information.'),
138 );
139
140 $form = system_settings_form($form);
141 $form['#submit'][] = 'project_forecast_admin_submit';
142
143 return $form;
144 }
145
146 function project_forecast_admin_submit($form, &$form_state) {
147 if ($form_state['values']['project_forecast_tasks_view'] != $form_state['original_tasks_view']) {
148 // New view, new filters - the old ones most probably don't fit.
149 variable_del('project_forecast_task_filters_open');
150 }
151 project_forecast_recalculate_all();
152 }

  ViewVC Help
Powered by ViewVC 1.1.2