Skip to content

Commit

Permalink
Export: comment count
Browse files Browse the repository at this point in the history
  • Loading branch information
andre2ar committed Dec 21, 2018
1 parent 9f1208e commit 7312339
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions public/wp-content/themes/rhs/inc/search/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ public static function export_search_xls($pagename, $content_file)
<tbody>";

foreach($content_file as $user) {
$comments_total = $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) AS total FROM $wpdb->comments WHERE comment_approved = 1 AND user_id = %s", $user->ID));
$sql = self::get_comments_query($wpdb->comments, $user->ID, 'user');
$comments_total = $wpdb->get_var($sql);
$name = $user->display_name;
$register_date = $user->user_registered;;

Expand Down Expand Up @@ -710,14 +711,14 @@ public static function export_search_xls($pagename, $content_file)
$get_link = $post->guid;
$get_views = $RHSNetwork->get_post_total_views($post->ID);
$get_shares = $RHSNetwork->get_post_total_shares($post->ID);
$post_comments = wp_count_comments($post->ID);
$get_votes = $RHSVote->get_total_votes($post->ID);

$views = return_value_or_zero($get_views);
$shares = return_value_or_zero($get_shares);
$votes = return_value_or_zero($get_votes);

$comments = (is_object($post_comments)) ? $post_comments->approved : 0;
$sql = self::get_comments_query($wpdb->comments, $post->ID, 'post');
$comments = $wpdb->get_var($sql);

$post_ufmun = get_post_ufmun($post->ID);
$uf = $post_ufmun['uf']['sigla'];
Expand Down Expand Up @@ -778,7 +779,8 @@ public static function export_search_csv($pagename, $content_file)
fputcsv($file, array('Nome do Usuário', 'Data de Cadastro', 'Total de Postagens', 'Total de Comentários Realizados', 'Total de Votos Recebidos', 'Estado', 'Cidade'));
foreach($content_file as $user) {

$comments_total = $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) AS total FROM $wpdb->comments WHERE comment_approved = 1 AND user_id = %s", $user->ID));
$sql = self::get_comments_query($wpdb->comments, $user->ID, 'user');
$comments_total = $wpdb->get_var($sql);
$name = $user->display_name;
$register_date = $user->user_registered;;

Expand Down Expand Up @@ -823,13 +825,14 @@ public static function export_search_csv($pagename, $content_file)
$get_link = $post->guid;
$get_views = $RHSNetwork->get_post_total_views($post->ID);
$get_shares = $RHSNetwork->get_post_total_shares($post->ID);
$get_comments = wp_count_comments($post->ID);
$get_votes = $RHSVote->get_total_votes($post->ID);

$views = return_value_or_zero($get_views);
$shares = return_value_or_zero($get_shares);
$votes = return_value_or_zero($get_votes);
$comments = return_value_or_zero($get_comments);

$sql = self::get_comments_query($wpdb->comments, $post->ID, 'post');
$comments = $wpdb->get_var($sql);

$post_ufmun = get_post_ufmun($post->ID);
$uf = $post_ufmun['uf']['sigla'];
Expand Down Expand Up @@ -862,6 +865,16 @@ public static function export_search_csv($pagename, $content_file)
fclose($file);
}

public static function get_comments_query($comments_db_name, $id, $type)
{
if($type == 'post')
$type = 'comment_post_id';
else if ($type == 'user')
$type = 'user_id';

return "SELECT COUNT(*) AS total FROM $comments_db_name WHERE comment_approved = 1 AND $type = $id";
}

public static function render_uf_city_select() {
UFMunicipio::form( array(
'content_before_field' => '<div class="form-group col-md-6">',
Expand Down

0 comments on commit 7312339

Please sign in to comment.