/[drupal]/contributions/modules/draggableviews/draggableviews.module
ViewVC logotype

Contents of /contributions/modules/draggableviews/draggableviews.module

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


Revision 1.7 - (show annotations) (download) (as text)
Thu Jan 8 22:38:36 2009 UTC (10 months, 2 weeks ago) by sevi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +110 -27 lines
File MIME type: text/x-php
Fundamental changes:
*) Introduction of handlers (handle saving and outputting)
1 <?php
2 // $Id: draggableviews.module,v 1.6 2008/09/21 20:36:49 sevi Exp $
3
4 /**
5 * @file
6 * Draggableviews module provides a style plugin for views.
7 * With this plugin rows become draggable and can be subordinated.
8 */
9
10 include_once('draggableviews.inc');
11
12 /**
13 * Display help and module information
14 * @param path which path of the site we're displaying help
15 * @param arg array that holds the current path as would be returned from arg() function
16 * @return help text for the path
17 */
18 function draggableviews_help($path, $arg) {
19 $output = '';
20 switch ($path) {
21 case "admin/help#draggableviews":
22 $output = '<p>'. t("Makes views draggable") .'</p>';
23 break;
24 }
25 return $output;
26 }
27
28 /**
29 * Implementing hook_admin
30 */
31 function draggableviews_admin() {
32 module_load_include('inc', 'views', 'includes/admin');
33
34 $options = views_fetch_fields(array('node', '#global'), 'sort');
35 $implementations = array(1 => "oasch");
36 $form = array();
37
38 if (!empty($options)) {
39 $form['implementations'] = array(
40 '#type' => 'fieldset',
41 '#title' => t('Specific implementations'),
42 '#description' => t('Define how the list of tasks to be analyzed (...or issues, cases, bugs) is going be retrieved.'),
43 '#collapsible' => TRUE,
44 '#collapsed' => (variable_get('project_forecast_tasks_view', '') != ''),
45 );
46 foreach ($options as $key => $option) {
47 $group = preg_replace('/[^a-z0-9]/', '-', strtolower($option['group']));
48 $groups[$group] = $option['group'];
49 $title = t('!group: !field', array('!group' => $option['group'], '!field' => $option['title']));
50
51 $form['implementations']['field_' .$key] = array(
52 '#prefix' => '<div class="draggableviews-admin"><div class="draggableviews-admin-field">'. $title .'</div>',
53 '#suffix' => '</div>',
54 '#type' => 'select',
55 '#options' => array_merge(array(0 => "None"), $implementations),
56 '#required' => FALSE,
57 '#default_value' => variable_get("draggableviews_implementation_" .str_replace('.', '_', $key), 0),
58 '#description' => t('Choose an inplementation.'),
59 );
60 }
61 }
62
63
64 return system_settings_form($form);
65 }
66
67 /**
68 * Implementing hook_menu
69 */
70 function draggableviews_menu() {
71
72 $items = array();
73 $items['admin/settings/draggableviews'] = array(
74 'title' => 'Draggable views settings',
75 'description' => 'Configure settings',
76 'file' => 'draggableviews.admin.inc',
77 'page callback' => 'drupal_get_form',
78 'page arguments' => array('draggableviews_admin'),
79 'access arguments' => array('access administration pages'),
80 'type' => MENU_NORMAL_ITEM,
81 );
82
83 return $items;
84 }
85
86 /**
87 * Implementing hook_validate
88 */
89 function draggableviews_admin_validate($form, &$form_state) {
90 $some_settings = $form_state['values']['draggableviews_some_settings'];
91 foreach($form_state['clicked_button']['#post'] AS $key => $implementation) {
92 if (!ereg('field_', $key)) continue;
93 $field = substr($key, 6);
94 variable_set("draggableviews_implementation_". $field, $implementation);
95 }
96 }
97
98 /**
99 * Discover all Implementations for draggableviews
100 *
101 */
102 function draggableviews_discover_handlers($filter_handler = FALSE) {
103 $cache = array();
104 // Get implementation definitions from all modules.
105 foreach (module_implements('draggableviews_handlers') as $module) {
106 $function = $module . '_draggableviews_handlers';
107 $result = $function();
108 if (!is_array($result)) {
109 continue;
110 }
111
112 $path = drupal_get_path('module', $module);
113
114 foreach ($result as $handler => $def) {
115 if (!isset($def['path'])) {
116 $def['path'] = $path;
117 }
118 if (!isset($def['file'])) {
119 $def['file'] = "$handler.inc";
120 }
121 if (!isset($def['handler'])) {
122 $def['handler'] = $implementation;
123 }
124 // merge the new data in
125 $cache[$handler] = $def;
126 }
127 }
128
129 if ($filter_handler) {
130 return $cache[$filter_handler];
131 }
132 return $cache;
133 }
134
135 /**
136 * Return a list of all draggableviews handlers
137 */
138 function draggableviews_get_handlers_list() {
139 $handlers = draggableviews_discover_handlers();
140 foreach($handlers as $handler => $def) {
141 $list[$handler] = $def['title'];
142 }
143
144 return $list;
145 }
146
147 /**
148 * Implementing hook_draggableviews_handlers
149 */
150 function draggableviews_draggableviews_handlers() {
151 return array(
152 'auto' => array(
153 'file' => 'implementations/draggableviews_handler_auto.inc',
154 'title' => t('Auto'),
155 'description' => 'Storage of structure done by draggableviews',
156 'handler' => 'draggableviews_handler_auto',
157 ),
158 );
159 }
160
161 /**
162 * Implementing hook_perm
163 */
164 function draggableviews_perm() {
165 return array('Allow Reordering');
166 }
167
168 /**
169 * Implement hook_theme
170 */
171 function draggableviews_theme() {
172 return array(
173 'draggableviews_ui_style_plugin_draggabletable' => array(
174 'arguments' => array('form' => NULL),
175 ),
176 'draggableviews_view_draggabletable_form' => array(
177 'template' => 'draggableviews-view-draggabletable-form',
178 'arguments' => array('form' => NULL),
179 ),
180 );
181 }
182
183 /**
184 * Impleneting hook_views_api
185 */
186 function draggableviews_views_api() {
187 return array(
188 'api' => 2.0,
189 'path' => drupal_get_path('module', 'draggableviews') . '/views',
190 );
191 }

  ViewVC Help
Powered by ViewVC 1.1.2