Completed
Pull Request — develop (#1328)
by Naveen
03:04
created

Term_Matches_Widget   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A connect_hook() 0 3 1
A render_widget() 0 21 2
1
<?php
2
3
namespace Wordlift\Vocabulary\Dashboard;
4
use Wordlift\Vocabulary\Data\Term_Count\Term_Count;
5
6
/**
7
 * This class adds the term matches widget to the admin dashboard
8
 * @since 3.30.0
9
 * @author Naveen Muthusamy <[email protected]>
10
 */
11
class Term_Matches_Widget {
12
	/**
13
	 * @var Term_Count
14
	 */
15
	private $term_count;
16
17
	/**
18
	 * Term_Matches_Widget constructor.
19
	 *
20
	 * @param $term_count Term_Count
21
	 */
22
	public function __construct( $term_count ) {
23
		$this->term_count = $term_count;
24
	}
25
26
	public function connect_hook() {
27
		add_action( 'wl_admin_dashboard_widgets', array( $this, 'render_widget' ) );
28
	}
29
30
	public function render_widget() {
31
		$term_count  = $this->term_count->get_term_count();
32
		if ( $term_count <= 0 ) {
33
			return;
34
		}
35
36
		$match_terms_url = menu_page_url('wl-vocabulary-match-terms', false);
37
		$term_count_link = "<a href='$match_terms_url'>" . $term_count . " term(s)</a>";
38
		$match_terms = __('Match terms', 'wordlift');
39
		$additional_text = __(' waiting to be matched with entities.', 'wordlift');
40
		echo <<<EOF
41
        <div id="wl-match-terms" class="wl-dashboard__block wl-dashboard__block--match-terms">
42
            <header>
43
                <h3>$match_terms</h3>
44
            </header>
45
                <p>
46
                	<strong>$term_count_link</strong> $additional_text	
47
                </p>
48
        </div>
49
EOF;
50
	}
51
52
}