Completed
Pull Request — develop (#1444)
by Zack
14:05 queued 04:01
created

GravityView_Widget_Pagination_Info   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 70.83%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 17
cts 24
cp 0.7083
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
B render_frontend() 0 39 5
1
<?php
2
3
4
/**
5
 * Widget to display pagination info
6
 *
7
 * @extends GravityView_Widget
8
 */
9
class GravityView_Widget_Pagination_Info extends \GV\Widget {
10
11
	/**
12
	 * Does this get displayed on a single entry?
13
	 * @var boolean
14
	 */
15
	protected $show_on_single = false;
16
17 3
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18
19 3
		$this->widget_description = __('Summary of the number of visible entries out of the total results.', 'gravityview' );
20
21
		$default_values = array(
22 3
			'header' => 1,
23
			'footer' => 1,
24
		);
25
26 3
		$settings = array();
27
28 3
		parent::__construct( __( 'Show Pagination Info', 'gravityview' ) , 'page_info', $default_values, $settings );
29 3
	}
30
31 2
	public function render_frontend( $widget_args, $content = '', $context = '') {
32 2
		$gravityview_view = GravityView_View::getInstance();
33
34 2
		if( !$this->pre_render_frontend() ) {
35 1
			return;
36
		}
37
38 1
		if( !empty( $widget_args['title'] ) ) {
39
			echo $widget_args['title'];
40
		}
41
42 1
		$pagination_counts = $gravityview_view->getPaginationCounts();
43
44 1
		$total = $first = $last = null;
45
46 1
		$output = '';
47
48 1
		if( ! empty( $pagination_counts ) ) {
49
50
			$first = $pagination_counts['first'];
51
			$last = $pagination_counts['last'];
52
			$total = $pagination_counts['total'];
53
54
			$class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
55
			$class = gravityview_sanitize_html_class( $class );
56
57
			$output = '<div class="gv-widget-pagination '.$class.'"><p>'. sprintf(__( 'Displaying %1$s - %2$s of %3$s', 'gravityview' ), number_format_i18n( $first ), number_format_i18n( $last ), number_format_i18n( $total ) ) . '</p></div>';
58
		}
59
60
		/**
61
		 * @filter `gravityview_pagination_output` Modify the pagination widget output
62
		 * @param string $output HTML output
63
		 * @param int $first First entry #
64
		 * @param int $last Last entry #
65
		 * @param int $total Total entries #
66
		 */
67 1
		echo apply_filters( 'gravityview_pagination_output', $output, $first, $last, $total );
68
69 1
	}
70
71
}
72
73
new GravityView_Widget_Pagination_Info;