| 1 |
<?php |
| 2 |
/** |
| 3 |
* User Earnings template |
| 4 |
* |
| 5 |
* This template can be overridden by copying it to yourtheme/gamipress/earnings.php |
| 6 |
*/ |
| 7 |
global $gamipress_template_args; |
| 8 |
|
| 9 |
// Shorthand |
| 10 |
$a = $gamipress_template_args; |
| 11 |
|
| 12 |
// Execute the query |
| 13 |
$user_earnings = $a['query']->get_results(); |
| 14 |
?> |
| 15 |
|
| 16 |
<div class="gamipress-earnings"> |
| 17 |
|
| 18 |
<div class="gamipress-earnings-atts"> |
| 19 |
|
| 20 |
<?php |
| 21 |
/** |
| 22 |
* Before render earnings atts |
| 23 |
* |
| 24 |
* @since 1.4.9 |
| 25 |
* |
| 26 |
* @param array $template_args Template received arguments |
| 27 |
*/ |
| 28 |
do_action( 'gamipress_before_render_earnings_atts', $a ); ?> |
| 29 |
|
| 30 |
<?php // Hidden fields for ajax request |
| 31 |
echo gamipress_array_as_hidden_inputs( $a, array( 'query' ) ); ?> |
| 32 |
|
| 33 |
<?php |
| 34 |
/** |
| 35 |
* After render earnings atts |
| 36 |
* |
| 37 |
* @since 1.4.9 |
| 38 |
* |
| 39 |
* @param array $template_args Template received arguments |
| 40 |
*/ |
| 41 |
do_action( 'gamipress_after_render_earnings_atts', $a ); ?> |
| 42 |
|
| 43 |
</div> |
| 44 |
|
| 45 |
<?php |
| 46 |
/** |
| 47 |
* Before render earnings |
| 48 |
* |
| 49 |
* @since 1.0.0 |
| 50 |
* |
| 51 |
* @param array $template_args Template received arguments |
| 52 |
*/ |
| 53 |
do_action( 'gamipress_before_render_earnings', $a ); ?> |
| 54 |
|
| 55 |
<?php if( $a['query']->found_results > 0 ) : ?> |
| 56 |
|
| 57 |
<?php |
| 58 |
/** |
| 59 |
* Earnings columns |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* |
| 63 |
* @param array $columns Earnings table columns to be rendered |
| 64 |
* @param array $template_args Template received arguments |
| 65 |
*/ |
| 66 |
$columns = apply_filters( 'gamipress_earnings_columns', $a['columns'], $a ); |
| 67 |
?> |
| 68 |
|
| 69 |
<table id="gamipress-earnings-table" class="gamipress-earnings-table <?php if( $a['force_responsive'] === 'yes' ) : ?>gamipress-earnings-force-responsive<?php endif;?>"> |
| 70 |
|
| 71 |
<thead> |
| 72 |
|
| 73 |
<tr> |
| 74 |
|
| 75 |
<?php foreach( $columns as $column_name => $column_label ) : ?> |
| 76 |
<th class="gamipress-earnings-col gamipress-earnings-col-<?php echo esc_attr( $column_name ); ?>"><?php echo $column_label; ?></th> |
| 77 |
<?php endforeach ?> |
| 78 |
|
| 79 |
</tr> |
| 80 |
|
| 81 |
</thead> |
| 82 |
|
| 83 |
<tbody> |
| 84 |
|
| 85 |
<?php foreach( $user_earnings as $user_earning ) : ?> |
| 86 |
|
| 87 |
<?php // Skip earnings that post assigned has been deleted |
| 88 |
if( ! gamipress_post_exists( $user_earning->post_id ) ) { continue; } ?> |
| 89 |
|
| 90 |
<tr> |
| 91 |
|
| 92 |
<?php foreach( $columns as $column_name => $column_label ) : ?> |
| 93 |
|
| 94 |
<?php |
| 95 |
/** |
| 96 |
* Render earnings column |
| 97 |
* |
| 98 |
* @since 1.0.0 |
| 99 |
* |
| 100 |
* @see gamipress_earnings_render_column() |
| 101 |
* |
| 102 |
* @param string $column_output Default column output |
| 103 |
* @param string $column_name The column name |
| 104 |
* @param stdClass $user_earning The column name |
| 105 |
* @param array $template_args Template received arguments |
| 106 |
* |
| 107 |
* @return string |
| 108 |
*/ |
| 109 |
$column_output = apply_filters( 'gamipress_earnings_render_column', '', $column_name, $user_earning, $a ); |
| 110 |
|
| 111 |
$css_class = 'gamipress-earnings-col gamipress-earnings-col-' . $column_name; |
| 112 |
|
| 113 |
if( empty( $column_output ) ) { |
| 114 |
$column_output = ' '; |
| 115 |
$css_class .= ' gamipress-earnings-col-empty'; |
| 116 |
} |
| 117 |
?> |
| 118 |
|
| 119 |
<td class="<?php echo esc_attr( $css_class ); ?>" data-label="<?php echo esc_attr( $column_label ); ?>"><?php echo $column_output; ?></td> |
| 120 |
<?php endforeach ?> |
| 121 |
|
| 122 |
</tr> |
| 123 |
|
| 124 |
<?php endforeach; ?> |
| 125 |
|
| 126 |
</tbody> |
| 127 |
|
| 128 |
</table><!-- .gamipress-earnings-table --> |
| 129 |
|
| 130 |
<?php // Pagination |
| 131 |
if( $a['pagination'] === 'yes' ) : ?> |
| 132 |
|
| 133 |
<?php |
| 134 |
/** |
| 135 |
* Before render earnings list pagination |
| 136 |
* |
| 137 |
* @since 1.4.9 |
| 138 |
* |
| 139 |
* @param array $template_args Template received arguments |
| 140 |
*/ |
| 141 |
do_action( 'gamipress_before_render_earnings_list_pagination', $a ); ?> |
| 142 |
|
| 143 |
<div id="gamipress-earnings-pagination" class="gamipress-earnings-pagination navigation"> |
| 144 |
<?php echo paginate_links( array( |
| 145 |
'base' => str_replace( 999999, '%#%', esc_url( get_pagenum_link( 999999 ) ) ), |
| 146 |
'format' => '?paged=%#%', |
| 147 |
'current' => max( 1, get_query_var( 'paged' ) ), |
| 148 |
'total' => ceil( $a['query']->found_results / $a['limit'] ) |
| 149 |
) ); ?> |
| 150 |
</div> |
| 151 |
|
| 152 |
<?php |
| 153 |
/** |
| 154 |
* After render earnings list pagination |
| 155 |
* |
| 156 |
* @since 1.4.9 |
| 157 |
* |
| 158 |
* @param array $template_args Template received arguments |
| 159 |
*/ |
| 160 |
do_action( 'gamipress_after_render_earnings_list_pagination', $a ); ?> |
| 161 |
|
| 162 |
<?php // Loading spinner ?> |
| 163 |
<div id="gamipress-earnings-spinner" class="gamipress-spinner" style="display: none;"></div> |
| 164 |
|
| 165 |
<?php endif; ?> |
| 166 |
|
| 167 |
<?php else : ?> |
| 168 |
|
| 169 |
<p id="gamipress-earnings-no-results"><?php echo __( 'You have not earned anything yet.', 'gamipress' ); ?></p> |
| 170 |
|
| 171 |
<?php endif; ?> |
| 172 |
|
| 173 |
<?php |
| 174 |
/** |
| 175 |
* After render earnings |
| 176 |
* |
| 177 |
* @since 1.0.0 |
| 178 |
* |
| 179 |
* @param array $template_args Template received arguments |
| 180 |
*/ |
| 181 |
do_action( 'gamipress_after_render_earnings', $a ); ?> |
| 182 |
|
| 183 |
</div> |
| 184 |
|