Completed
Push — develop ( 72a91d...14a321 )
by
unknown
04:09 queued 12s
created

Term_Matches_Widget   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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