Projet

Général

Profil

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

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

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
      'exception' => array(
172
        'value' => '',
173
      ),
174
      'title' => '%1\'s bookmarks',
175
      'default_argument_type' => 'fixed',
176
      'default_argument' => '',
177
      'validate_type' => 'flag_bookmark_plugin_owner_perm',
178
      'validate_fail' => 'not found',
179
      'break_phrase' => 0,
180
      'not' => 0,
181
      'id' => 'uid',
182
      'table' => 'users',
183
      'field' => 'uid',
184
      'override' => array(
185
        'button' => 'Override',
186
      ),
187
      'relationship' => 'uid',
188
      'default_options_div_prefix' => '',
189
      'default_argument_user' => 0,
190
      'default_argument_fixed' => '',
191
      'default_argument_php' => '',
192
    ),
193
  );
194

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

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

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

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

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

    
248
  $view = new view;
249
  $view->name = 'flag_' . $flag->name;
250
  $view->description = "A page listing the current user's bookmarks at /bookmarks.";
251
  $view->tag = 'flag';
252
  $view->view_php = '';
253
  $view->base_table = 'node';
254
  $view->is_cacheable = '0';
255
  $view->api_version = 2;
256
  $view->disabled = FALSE;
257
  $handler = $view->new_display('default', 'Defaults', 'default');
258
  $handler->override_option('relationships', $relationships);
259
  $handler->override_option('fields', $fields);
260
  $handler->override_option('filters', $filters);
261
  $handler->override_option('access', $access);
262
  $handler->override_option('title', t('My bookmarks'));
263
  $handler->override_option('items_per_page', '25');
264
  $handler->override_option('use_pager', TRUE);
265
  $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.');
266
  $handler->override_option('empty_format', filter_fallback_format());
267
  $handler->override_option('style_plugin', 'table');
268
  $handler->override_option('style_options', $style_options);
269
  $handler = $view->new_display('page', 'Page', 'page');
270
  $handler->override_option('path', 'bookmarks');
271
  $handler->override_option('menu', array(
272
    'type' => 'normal',
273
    'title' => t('My bookmarks'),
274
    'weight' => '0',
275
  ));
276
  $handler->override_option('tab_options', array(
277
    'type' => 'none',
278
    'title' => NULL,
279
    'weight' => NULL,
280
  ));
281

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

    
284
  return $views;
285
}