Projet

Général

Profil

Paste
Télécharger (7,77 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / flag / flag_bookmark / includes / flag_bookmark.views_default.inc @ a6e869e4

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides support for the Views module.
6
 */
7

    
8
/**
9
 * Implements hook_views_default_views().
10
 */
11
function flag_bookmark_views_default_views() {
12
  // Only setup views for the "bookmarks" flag.
13
  // If it's been deleted, don't create any views.
14
  $flag = flag_get_flag('bookmarks');
15
  if (!$flag) {
16
    return array();
17
  }
18

    
19
  // Set up properties that are used for both views.
20
  $fields = array(
21
    'type' => array(
22
      'id' => 'type',
23
      'table' => 'node',
24
      'field' => 'type',
25
      'label' => 'Type',
26
    ),
27
    'title' => array(
28
      'id' => 'title',
29
      'table' => 'node',
30
      'field' => 'title',
31
      'label' => 'Title',
32
      'link_to_node' => 1,
33
    ),
34
    'name' => array(
35
      'label' => 'Author',
36
      'link_to_user' => 1,
37
      'id' => 'name',
38
      'table' => 'users',
39
      'field' => 'name',
40
      'relationship' => 'uid_1',
41
    ),
42
  );
43

    
44
  $style_options = array(
45
    'grouping' => '',
46
    'override' => 0,
47
    'sticky' => 1,
48
    'columns' => array(),
49
    'default' => 'title',
50
    'order' => 'asc',
51
    'columns' => array(
52
      'type' => 'type',
53
      'title' => 'title',
54
      'name' => 'name',
55
    ),
56
    'info' => array(
57
      'type' => array(
58
        'sortable' => TRUE,
59
      ),
60
      'title' => array(
61
        'sortable' => TRUE,
62
      ),
63
      'name' => array(
64
        'sortable' => TRUE,
65
      ),
66
    ),
67
    'override' => FALSE,
68
    'order' => 'asc',
69
  );
70

    
71
  $filters = array(
72
    'status' => array(
73
      'operator' => '=',
74
      'value' => 1,
75
      'group' => '0',
76
      'exposed' => FALSE,
77
      'expose' => array(
78
        'operator' => FALSE,
79
        'label' => '',
80
      ),
81
      'id' => 'status',
82
      'table' => 'node',
83
      'field' => 'status',
84
      'relationship' => 'none',
85
    ),
86
  );
87

    
88
  $relationships = array(
89
    'flag_content_rel' => array(
90
      'label' => 'bookmarks',
91
      'required' => 1,
92
      'flag' => 'bookmarks',
93
      'user_scope' => 'current',
94
      'id' => 'flag_content_rel',
95
      'table' => 'node',
96
      'field' => 'flag_content_rel',
97
      'relationship' => 'none',
98
      'override' => array(
99
        'button' => 'Override',
100
      ),
101
    ),
102
    'uid_1' => array(
103
      'label' => 'author',
104
      'required' => 0,
105
      'id' => 'uid_1',
106
      'table' => 'node',
107
      'field' => 'uid',
108
    ),
109
  );
110

    
111
  $access = array(
112
    'type' => 'perm',
113
    'perm' => 'flag bookmarks',
114
  );
115

    
116
  // Additional fields and style options if comment exists.
117
  if (module_exists('comment')) {
118
    $fields += array(
119
      'comment_count' => array(
120
        'id' => 'comment_count',
121
        'table' => 'node_comment_statistics',
122
        'field' => 'comment_count',
123
        'label' => 'Replies',
124
      ),
125
      'last_comment_timestamp' => array(
126
        'id' => 'last_comment_timestamp',
127
        'table' => 'node_comment_statistics',
128
        'field' => 'last_comment_timestamp',
129
        'label' => 'Last Post',
130
      ),
131
    );
132

    
133
    $style_options['default'] = 'last_comment_timestamp';
134
    $style_options['order'] = 'desc';
135
    $style_options['info'] += array(
136
      'comment_count' => array(
137
        'sortable' => TRUE,
138
      ),
139
      'last_comment_timestamp' => array(
140
        'sortable' => TRUE,
141
      ),
142
    );
143
    $style_options['columns'] += array(
144
      'comment_count' => 'comment_count',
145
      'last_comment_timestamp' => 'last_comment_timestamp',
146
    );
147
  }
148

    
149
  /* Individual users user/%/bookmarks tab. */
150

    
151
  // Additional relationship for this view.
152
  $relationships_tab = $relationships;
153
  $relationships_tab['flag_content_rel']['user_scope'] = 'any';
154
  $relationships_tab += array(
155
    'uid' => array(
156
      'label' => 'bookmarks_user',
157
      'required' => 1,
158
      'id' => 'uid',
159
      'table' => 'flagging',
160
      'field' => 'uid',
161
      'relationship' => 'flag_content_rel',
162
    ),
163
  );
164

    
165
  // Additional argument for this view.
166
  $arguments_tab = array(
167
    'uid' => array(
168
      'default_action' => 'empty',
169
      'style_plugin' => 'default_summary',
170
      'style_options' => array(),
171
      'wildcard' => 'all',
172
      'wildcard_substitution' => 'All',
173
      'title' => '%1\'s bookmarks',
174
      'default_argument_type' => 'fixed',
175
      'default_argument' => '',
176
      'validate_type' => 'none',
177
      'validate_fail' => 'not found',
178
      'break_phrase' => 0,
179
      'not' => 0,
180
      'id' => 'uid',
181
      'table' => 'users',
182
      'field' => 'uid',
183
      'override' => array(
184
        'button' => 'Override',
185
      ),
186
      'relationship' => 'uid',
187
      'default_options_div_prefix' => '',
188
      'default_argument_user' => 0,
189
      'default_argument_fixed' => '',
190
      'default_argument_php' => '',
191
    ),
192
  );
193

    
194
  $view = new view;
195
  $view->name = 'flag_bookmarks_tab';
196
  $view->description = "Provides a tab on all users' profile pages containing bookmarks for that user.";
197
  $view->tag = 'flag';
198
  $view->view_php = '';
199
  $view->base_table = 'node';
200
  $view->is_cacheable = FALSE;
201
  $view->api_version = 2;
202
  $view->disabled = FALSE;
203
  $handler = $view->new_display('default', 'Defaults', 'default');
204
  $handler->override_option('relationships', $relationships_tab);
205
  $handler->override_option('fields', $fields);
206
  $handler->override_option('arguments', $arguments_tab);
207
  $handler->override_option('filters', $filters);
208
  $handler->override_option('access', $access);
209
  $handler->override_option('title', 'User bookmarks');
210
  $handler->override_option('empty', 'This user has not yet bookmarked any content.');
211
  $handler->override_option('empty_format', filter_fallback_format());
212
  $handler->override_option('items_per_page', '25');
213
  $handler->override_option('use_pager', TRUE);
214
  $handler->override_option('style_plugin', 'table');
215
  $handler->override_option('style_options', $style_options);
216

    
217
  $handler = $view->new_display('page', 'Page', 'page');
218
  $handler->override_option('path', 'user/%/bookmarks');
219
  $handler->override_option('menu', array(
220
    'type' => 'tab',
221
    'title' => 'Bookmarks',
222
    'weight' => '0',
223
    'name' => 'navigation',
224
  ));
225
  $handler->override_option('tab_options', array(
226
    'type' => 'none',
227
    'title' => NULL,
228
    'weight' => NULL,
229
  ));
230

    
231
  $views[$view->name] = $view;
232

    
233
  /* User bookmarks page with Ops. */
234

    
235
  // Add some unique options for this view.
236
  $style_options['columns'] += array('ops' => 'ops');
237
  $fields += array(
238
    'ops' => array(
239
      'label' => 'Ops',
240
      'id' => 'ops',
241
      'table' => 'flagging',
242
      'field' => 'ops',
243
      'relationship' => 'flag_content_rel',
244
    ),
245
  );
246

    
247
  $view = new view;
248
  $view->name = 'flag_' . $flag->name;
249
  $view->description = "A page listing the current user's bookmarks at /bookmarks.";
250
  $view->tag = 'flag';
251
  $view->view_php = '';
252
  $view->base_table = 'node';
253
  $view->is_cacheable = '0';
254
  $view->api_version = 2;
255
  $view->disabled = FALSE;
256
  $handler = $view->new_display('default', 'Defaults', 'default');
257
  $handler->override_option('relationships', $relationships);
258
  $handler->override_option('fields', $fields);
259
  $handler->override_option('filters', $filters);
260
  $handler->override_option('access', $access);
261
  $handler->override_option('title', t('My bookmarks'));
262
  $handler->override_option('items_per_page', '25');
263
  $handler->override_option('use_pager', TRUE);
264
  $handler->override_option('empty', 'You have not yet bookmarked any content. Click the "' . $flag->flag_short . '" link when viewing a piece of content to add it to this list.');
265
  $handler->override_option('empty_format', filter_fallback_format());
266
  $handler->override_option('style_plugin', 'table');
267
  $handler->override_option('style_options', $style_options);
268
  $handler = $view->new_display('page', 'Page', 'page');
269
  $handler->override_option('path', 'bookmarks');
270
  $handler->override_option('menu', array(
271
    'type' => 'normal',
272
    'title' => t('My bookmarks'),
273
    'weight' => '0',
274
  ));
275
  $handler->override_option('tab_options', array(
276
    'type' => 'none',
277
    'title' => NULL,
278
    'weight' => NULL,
279
  ));
280

    
281
  $views[$view->name] = $view;
282

    
283
  return $views;
284
}