• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/comment.views.inc

Go to the documentation of this file.
00001 <?php
00018 function comment_views_data() {
00019   $data['comments']['moved to'] = 'comment';
00020   $data['comment']['comment']['moved to'] = array('field_data_comment_body', 'comment_body');
00021   $data['comment']['comment']['field']['moved to'] = array('field_data_comment_body', 'comment_body');
00022   // Define the base group of this table. Fields that don't
00023   // have a group defined will go into this field by default.
00024   $data['comment']['table']['group']  = t('Comment');
00025 
00026   $data['comment']['table']['base'] = array(
00027     'field' => 'cid',
00028     'title' => t('Comment'),
00029     'help' => t("Comments are responses to node content."),
00030     'access query tag' => 'comment_access',
00031   );
00032   $data['comment']['table']['entity type'] = 'comment';
00033 
00034   // Provide a "default relationship" to keep older views from choking.
00035   $data['comment']['table']['default_relationship'] = array(
00036     'node' => array(
00037       'table' => 'node',
00038       'field' => 'cid',
00039     ),
00040   );
00041 
00042   // ----------------------------------------------------------------
00043   // Fields
00044 
00045   // subject
00046   $data['comment']['subject'] = array(
00047     'title' => t('Title'),
00048     'help' => t('The title of the comment.'),
00049     'field' => array(
00050       'handler' => 'views_handler_field_comment',
00051       'click sortable' => TRUE,
00052     ),
00053     'filter' => array(
00054       'handler' => 'views_handler_filter_string',
00055     ),
00056     'sort' => array(
00057       'handler' => 'views_handler_sort',
00058     ),
00059     'argument' => array(
00060       'handler' => 'views_handler_argument_string',
00061     ),
00062   );
00063 
00064   // cid
00065   $data['comment']['cid'] = array(
00066     'title' => t('ID'),
00067     'help' => t('The comment ID of the field'),
00068     'field' => array(
00069       'handler' => 'views_handler_field_comment',
00070       'click sortable' => TRUE,
00071     ),
00072     'filter' => array(
00073       'handler' => 'views_handler_filter_numeric',
00074     ),
00075     'sort' => array(
00076       'handler' => 'views_handler_sort',
00077     ),
00078     'argument' => array(
00079       'handler' => 'views_handler_argument_numeric',
00080     ),
00081   );
00082 
00083   // name (of comment author)
00084   $data['comment']['name'] = array(
00085     'title' => t('Author'),
00086     'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
00087     'field' => array(
00088       'handler' => 'views_handler_field_comment_username',
00089       'click sortable' => TRUE,
00090     ),
00091     'filter' => array(
00092       'handler' => 'views_handler_filter_string',
00093     ),
00094     'sort' => array(
00095       'handler' => 'views_handler_sort',
00096     ),
00097     'argument' => array(
00098       'handler' => 'views_handler_argument_string',
00099     ),
00100   );
00101 
00102   // homepage
00103   $data['comment']['homepage'] = array(
00104     'title' => t("Author's website"),
00105     'help' => t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."),
00106     'field' => array(
00107       'handler' => 'views_handler_field_url',
00108       'click sortable' => TRUE,
00109     ),
00110     'filter' => array(
00111       'handler' => 'views_handler_filter_string',
00112     ),
00113     'sort' => array(
00114       'handler' => 'views_handler_sort',
00115     ),
00116     'argument' => array(
00117       'handler' => 'views_handler_argument_string',
00118     ),
00119   );
00120 
00121   // hostname
00122   $data['comment']['hostname'] = array(
00123     'title' => t('Hostname'),
00124     'help' => t('Hostname of user that posted the comment.'),
00125     'field' => array(
00126       'handler' => 'views_handler_field',
00127       'click sortable' => TRUE,
00128      ),
00129     'filter' => array(
00130       'handler' => 'views_handler_filter_string',
00131     ),
00132     'sort' => array(
00133       'handler' => 'views_handler_sort',
00134     ),
00135     'argument' => array(
00136       'handler' => 'views_handler_argument_string',
00137     ),
00138   );
00139 
00140   // mail
00141   $data['comment']['mail'] = array(
00142     'title' => t('Mail'),
00143     'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'),
00144     'field' => array(
00145       'handler' => 'views_handler_field',
00146       'click sortable' => TRUE,
00147      ),
00148     'filter' => array(
00149       'handler' => 'views_handler_filter_string',
00150     ),
00151     'sort' => array(
00152       'handler' => 'views_handler_sort',
00153     ),
00154     'argument' => array(
00155       'handler' => 'views_handler_argument_string',
00156     ),
00157   );
00158 
00159   // created (when comment was posted)
00160   $data['comment']['created'] = array(
00161     'title' => t('Post date'),
00162     'help' => t('Date and time of when the comment was created.'),
00163     'field' => array(
00164       'handler' => 'views_handler_field_date',
00165       'click sortable' => TRUE,
00166     ),
00167     'sort' => array(
00168       'handler' => 'views_handler_sort_date',
00169     ),
00170     'filter' => array(
00171       'handler' => 'views_handler_filter_date',
00172     ),
00173   );
00174 
00175   $data['comments']['timestamp']['moved to'] = array('comment', 'changed');
00176   // changed (when comment was last updated)
00177   $data['comment']['changed'] = array(
00178     'title' => t('Updated date'),
00179     'help' => t('Date and time of when the comment was last updated.'),
00180     'field' => array(
00181       'handler' => 'views_handler_field_date',
00182       'click sortable' => TRUE,
00183     ),
00184     'sort' => array(
00185       'handler' => 'views_handler_sort_date',
00186     ),
00187     'filter' => array(
00188       'handler' => 'views_handler_filter_date',
00189     ),
00190   );
00191 
00192   $data['comments']['timestamp_fulldate']['moved to'] = array('comment', 'changed_fulldata');
00193   $data['comment']['changed_fulldata'] = array(
00194     'title' => t('Created date'),
00195     'help' => t('Date in the form of CCYYMMDD.'),
00196     'argument' => array(
00197       'field' => 'changed',
00198       'handler' => 'views_handler_argument_node_created_fulldate',
00199     ),
00200   );
00201 
00202   $data['comments']['timestamp_year_month']['moved to'] = array('comment', 'changed_year_month');
00203   $data['comment']['changed_year_month'] = array(
00204     'title' => t('Created year + month'),
00205     'help' => t('Date in the form of YYYYMM.'),
00206     'argument' => array(
00207       'field' => 'changed',
00208       'handler' => 'views_handler_argument_node_created_year_month',
00209     ),
00210   );
00211 
00212   $data['comments']['timestamp_year']['moved to'] = array('comment', 'changed_year');
00213   $data['comment']['changed_year'] = array(
00214     'title' => t('Created year'),
00215     'help' => t('Date in the form of YYYY.'),
00216     'argument' => array(
00217       'field' => 'changed',
00218       'handler' => 'views_handler_argument_node_created_year',
00219     ),
00220   );
00221 
00222   $data['comments']['timestamp_month']['moved to'] = array('comment', 'changed_month');
00223   $data['comment']['changed_month'] = array(
00224     'title' => t('Created month'),
00225     'help' => t('Date in the form of MM (01 - 12).'),
00226     'argument' => array(
00227       'field' => 'changed',
00228       'handler' => 'views_handler_argument_node_created_month',
00229     ),
00230   );
00231 
00232   $data['comments']['timestamp_day']['moved to'] = array('comment', 'changed_day');
00233   $data['comment']['changed_day'] = array(
00234     'title' => t('Created day'),
00235     'help' => t('Date in the form of DD (01 - 31).'),
00236     'argument' => array(
00237       'field' => 'changed',
00238       'handler' => 'views_handler_argument_node_created_day',
00239     ),
00240   );
00241 
00242   $data['comments']['timestamp_week']['moved to'] = array('comment', 'changed_week');
00243   $data['comment']['changed_week'] = array(
00244     'title' => t('Created week'),
00245     'help' => t('Date in the form of WW (01 - 53).'),
00246     'argument' => array(
00247       'field' => 'changed',
00248       'handler' => 'views_handler_argument_node_created_week',
00249     ),
00250   );
00251 
00252   // status (approved or not)
00253   $data['comment']['status'] = array(
00254     'title' => t('Approved'),
00255     'help' => t('Whether the comment is approved (or still in the moderation queue).'),
00256     'field' => array(
00257       'handler' => 'views_handler_field_boolean',
00258       'click sortable' => TRUE,
00259       'output formats' => array(
00260         'approved-not-approved' => array(t('Approved'), t('Not Approved')),
00261       ),
00262     ),
00263     'filter' => array(
00264       'handler' => 'views_handler_filter_boolean_operator',
00265       'label' => t('Approved comment'),
00266       'type' => 'yes-no',
00267     ),
00268     'sort' => array(
00269       'handler' => 'views_handler_sort',
00270     ),
00271   );
00272 
00273   // link to view comment
00274   $data['comment']['view_comment'] = array(
00275     'field' => array(
00276       'title' => t('View link'),
00277       'help' => t('Provide a simple link to view the comment.'),
00278       'handler' => 'views_handler_field_comment_link',
00279     ),
00280   );
00281 
00282   // link to edit comment
00283   $data['comment']['edit_comment'] = array(
00284     'field' => array(
00285       'title' => t('Edit link'),
00286       'help' => t('Provide a simple link to edit the comment.'),
00287       'handler' => 'views_handler_field_comment_link_edit',
00288     ),
00289   );
00290 
00291   // link to delete comment
00292   $data['comment']['delete_comment'] = array(
00293     'field' => array(
00294       'title' => t('Delete link'),
00295       'help' => t('Provide a simple link to delete the comment.'),
00296       'handler' => 'views_handler_field_comment_link_delete',
00297     ),
00298   );
00299 
00300 
00301   // link to approve comment
00302   $data['comment']['approve_comment'] = array(
00303     'field' => array(
00304       'title' => t('Approve link'),
00305       'help' => t('Provide a simple link to approve the comment.'),
00306       'handler' => 'views_handler_field_comment_link_approve',
00307     ),
00308   );
00309 
00310   // link to reply to comment
00311   $data['comment']['replyto_comment'] = array(
00312     'field' => array(
00313       'title' => t('Reply-to link'),
00314       'help' => t('Provide a simple link to reply to the comment.'),
00315       'handler' => 'views_handler_field_comment_link_reply',
00316     ),
00317   );
00318 
00319   $data['comment']['thread'] = array(
00320     'field' => array(
00321       'title' => t('Depth'),
00322       'help' => t('Display the depth of the comment if it is threaded.'),
00323       'handler' => 'views_handler_field_comment_depth',
00324     ),
00325     'sort' => array(
00326       'title' => t('Thread'),
00327       'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
00328       'handler' => 'views_handler_sort_comment_thread',
00329     ),
00330   );
00331 
00332   $data['comment']['nid'] = array(
00333     'title' => t('Nid'),
00334     'help' => t('The node ID to which the comment is a reply to.'),
00335     'relationship' => array(
00336       'title' => t('Content'),
00337       'help' => t('The content to which the comment is a reply to.'),
00338       'base' => 'node',
00339       'base field' => 'nid',
00340       'handler' => 'views_handler_relationship',
00341       'label' => t('Content'),
00342     ),
00343     'filter' => array(
00344       'handler' => 'views_handler_filter_numeric',
00345     ),
00346     'argument' => array(
00347       'handler' => 'views_handler_argument_numeric',
00348     ),
00349     'field' => array(
00350       'handler' => 'views_handler_field_numeric',
00351     ),
00352   );
00353 
00354   $data['comment']['uid'] = array(
00355     'title' => t('Author uid'),
00356     'help' => t('If you need more fields than the uid add the comment: author relationship'),
00357     'relationship' => array(
00358       'title' => t('Author'),
00359       'help' => t("The User ID of the comment's author."),
00360       'base' => 'users',
00361       'base field' => 'uid',
00362       'handler' => 'views_handler_relationship',
00363       'label' => t('author'),
00364     ),
00365     'filter' => array(
00366       'handler' => 'views_handler_filter_numeric',
00367     ),
00368     'argument' => array(
00369       'handler' => 'views_handler_argument_numeric',
00370     ),
00371     'field' => array(
00372       'handler' => 'views_handler_field_user',
00373     ),
00374   );
00375 
00376   $data['comment']['pid'] = array(
00377     'title' => t('Parent CID'),
00378     'help' => t('The Comment ID of the parent comment.'),
00379     'field' => array(
00380       'handler' => 'views_handler_field',
00381     ),
00382     'relationship' => array(
00383       'title' => t('Parent comment'),
00384       'help' => t('The parent comment.'),
00385       'base' => 'comment',
00386       'base field' => 'cid',
00387       'handler' => 'views_handler_relationship',
00388       'label' => t('Parent comment'),
00389     ),
00390   );
00391 
00392   // ----------------------------------------------------------------------
00393   // node_comment_statistics table
00394 
00395   // define the group
00396   $data['node_comment_statistics']['table']['group']  = t('Content');
00397 
00398   // joins
00399   $data['node_comment_statistics']['table']['join'] = array(
00400     //...to the node table
00401     'node' => array(
00402       'type' => 'INNER',
00403       'left_field' => 'nid',
00404       'field' => 'nid',
00405      ),
00406   );
00407 
00408   // last_comment_timestamp
00409   $data['node_comment_statistics']['last_comment_timestamp'] = array(
00410     'title' => t('Last comment time'),
00411     'help' => t('Date and time of when the last comment was posted.'),
00412     'field' => array(
00413       'handler' => 'views_handler_field_last_comment_timestamp',
00414       'click sortable' => TRUE,
00415     ),
00416     'sort' => array(
00417       'handler' => 'views_handler_sort_date',
00418     ),
00419     'filter' => array(
00420       'handler' => 'views_handler_filter_date',
00421     ),
00422   );
00423 
00424   // last_comment_name (author's name)
00425   $data['node_comment_statistics']['last_comment_name'] = array(
00426     'title' => t("Last comment author"),
00427     'help' => t('The name of the author of the last posted comment.'),
00428     'field' => array(
00429       'handler' => 'views_handler_field_ncs_last_comment_name',
00430       'click sortable' => TRUE,
00431       'no group by' => TRUE,
00432     ),
00433     'sort' => array(
00434       'handler' => 'views_handler_sort_ncs_last_comment_name',
00435       'no group by' => TRUE,
00436     ),
00437   );
00438 
00439   // comment_count
00440   $data['node_comment_statistics']['comment_count'] = array(
00441     'title' => t('Comment count'),
00442     'help' => t('The number of comments a node has.'),
00443     'field' => array(
00444       'handler' => 'views_handler_field_numeric',
00445       'click sortable' => TRUE,
00446     ),
00447     'filter' => array(
00448       'handler' => 'views_handler_filter_numeric',
00449     ),
00450     'sort' => array(
00451       'handler' => 'views_handler_sort',
00452     ),
00453     'argument' => array(
00454       'handler' => 'views_handler_argument',
00455     ),
00456   );
00457 
00458   // last_comment_timestamp
00459   $data['node_comment_statistics']['last_updated'] = array(
00460     'title' => t('Updated/commented date'),
00461     'help' => t('The most recent of last comment posted or node updated time.'),
00462     'field' => array(
00463       'handler' => 'views_handler_field_ncs_last_updated',
00464       'click sortable' => TRUE,
00465       'no group by' => TRUE,
00466     ),
00467     'sort' => array(
00468       'handler' => 'views_handler_sort_ncs_last_updated',
00469       'no group by' => TRUE,
00470     ),
00471     'filter' => array(
00472       'handler' => 'views_handler_filter_ncs_last_updated',
00473     ),
00474   );
00475 
00476   $data['node_comment_statistics']['cid'] = array(
00477     'title' => t('Last comment CID'),
00478     'help' => t('Display the last comment of a node'),
00479     'relationship' => array(
00480       'title' => t('Last Comment'),
00481       'help' => t('The last comment of a node.'),
00482       'group' => t('Comment'),
00483       'base' => 'comment',
00484       'base field' => 'cid',
00485       'handler' => 'views_handler_relationship',
00486       'label' => t('Last Comment'),
00487     ),
00488   );
00489 
00490   // last_comment_uid
00491   $data['node_comment_statistics']['last_comment_uid'] = array(
00492     'title' => t('Last comment uid'),
00493     'help' => t('The User ID of the author of the last comment of a node.'),
00494     'relationship' => array(
00495       'title' => t('Last comment author'),
00496       'base' => 'users',
00497       'base field' => 'uid',
00498       'handler' => 'views_handler_relationship',
00499       'label' => t('Last comment author'),
00500     ),
00501     'filter' => array(
00502       'handler' => 'views_handler_filter_numeric',
00503     ),
00504     'argument' => array(
00505       'handler' => 'views_handler_argument_numeric',
00506     ),
00507     'field' => array(
00508       'handler' => 'views_handler_filter_user_name',
00509     ),
00510   );
00511 
00512   return $data;
00513 }
00514 
00519 function comment_views_data_alter(&$data) {
00520   // new comments
00521   $data['node']['new_comments'] = array(
00522     'title' => t('New comments'),
00523     'help' => t('The number of new comments on the node.'),
00524     'field' => array(
00525       'handler' => 'views_handler_field_node_new_comments',
00526       'no group by' => TRUE,
00527     ),
00528   );
00529 
00530   $data['node']['comments_link'] = array(
00531     'field' => array(
00532       'title' => t('Add comment link'),
00533       'help' => t('Display the standard add comment link used on regular nodes, which will only display if the viewing user has access to add a comment.'),
00534       'handler' => 'views_handler_field_comment_node_link',
00535     ),
00536   );
00537 
00538   // Comment status of the node
00539   $data['node']['comment'] = array(
00540     'title' => t('Comment status'),
00541     'help' => t('Whether comments are enabled or disabled on the node.'),
00542     'field' => array(
00543       'handler' => 'views_handler_field_node_comment',
00544       'click sortable' => TRUE,
00545     ),
00546     'sort' => array(
00547       'handler' => 'views_handler_sort',
00548     ),
00549     'filter' => array(
00550       'handler' => 'views_handler_filter_node_comment',
00551     ),
00552   );
00553 
00554   $data['node']['uid_touch'] = array(
00555     'title' => t('User posted or commented'),
00556     'help' => t('Display nodes only if a user posted the node or commented on the node.'),
00557     'argument' => array(
00558       'field' => 'uid',
00559       'name table' => 'users',
00560       'name field' => 'name',
00561       'handler' => 'views_handler_argument_comment_user_uid',
00562       'no group by' => TRUE,
00563     ),
00564     'filter' => array(
00565       'field' => 'uid',
00566       'name table' => 'users',
00567       'name field' => 'name',
00568       'handler' => 'views_handler_filter_comment_user_uid'
00569     ),
00570   );
00571 
00572   $data['node']['cid'] = array(
00573     'title' => t('Comments of the node'),
00574     'help' => t('Relate all comments on the node. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.'),
00575     'relationship' => array(
00576       'group' => t('Comment'),
00577       'label' => t('Comments'),
00578       'base' => 'comment',
00579       'base field' => 'nid',
00580       'relationship field' => 'nid',
00581       'handler' => 'views_handler_relationship',
00582     ),
00583   );
00584 
00585 }
00586 
00590 function comment_views_plugins() {
00591   return array(
00592     'module' => 'views',
00593     'row' => array(
00594       'comment' => array(
00595         'title' => t('Comment'),
00596         'help' => t('Display the comment with standard comment view.'),
00597         'handler' => 'views_plugin_row_comment_view',
00598         'theme' => 'views_view_row_comment',
00599         'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
00600         'base' => array('comment'), // only works with 'comment' as base.
00601         'uses options' => TRUE,
00602         'type' => 'normal',
00603         'help topic' => 'style-comment',
00604       ),
00605       'comment_rss' => array(
00606         'title' => t('Comment'),
00607         'help' => t('Display the comment as RSS.'),
00608         'handler' => 'views_plugin_row_comment_rss',
00609         'theme' => 'views_view_row_rss',
00610         'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules
00611         'base' => array('comment'), // only works with 'comment' as base.
00612         'uses options' => TRUE,
00613         'type' => 'feed',
00614         'help topic' => 'style-comment-rss',
00615       ),
00616     ),
00617   );
00618 }
00619 
00623 function template_preprocess_views_view_row_comment(&$vars) {
00624   $options = $vars['options'];
00625   $view = &$vars['view'];
00626   $plugin = &$view->style_plugin->row_plugin;
00627   $comment = $plugin->comments[$vars['row']->{$vars['field_alias']}];
00628   $node = $plugin->nodes[$comment->nid];
00629   // Put the view on the node so we can retrieve it in the preprocess.
00630   $node->view = &$view;
00631 
00632   $build = comment_view_multiple(array($comment->cid => $comment), $node, $plugin->options['view_mode']);
00633   // If we're displaying the comments without links, remove them from the
00634   // renderable array. There is no way to avoid building them in the first
00635   // place (see comment_build_content()).
00636   if (empty($options['links'])) {
00637     foreach ($build as $cid => &$comment_build) {
00638       if (isset($comment_build['links'])) {
00639         unset($comment_build['links']);
00640       }
00641     }
00642   }
00643   $vars['comment'] = drupal_render($build);
00644 }
00645 

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1