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

Term_Matches_Widget::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
}