Skip to content
Snippets Groups Projects
Commit 07f89ac0 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

feature(petition): added text petition

parent 8301c2a1
No related branches found
No related tags found
1 merge request!1feature(petition): added text petition
<?php
namespace WPDesk\RepositoryRating;
/**
* Petition text generator.
*/
interface PetitionText {
/**
* Returns petition text.
*
* @return string
*/
public function get_petition_text(): string;
}
\ No newline at end of file
<?php
namespace WPDesk\RepositoryRating;
class RepositoryRatingPetitionText implements PetitionText {
/**
* @var string
*/
private $plugin_author;
/**
* @var string
*/
private $plugin_title;
/**
* @var string
*/
private $rating_url;
/**
* @var string
*/
private $text_align;
/**
* @param string $plugin_author
* @param string $plugin_title
* @param string $rating_url
* @param string $text_align
*/
public function __construct( string $plugin_author, string $plugin_title, string $rating_url, string $text_align ) {
$this->plugin_author = $plugin_author;
$this->plugin_title = $plugin_title;
$this->rating_url = $rating_url;
$this->text_align = $text_align;
}
/**
* @inheritDoc
*/
public function get_petition_text(): string {
ob_start();
$plugin_author = $this->plugin_author;
$plugin_title = $this->plugin_title;
$rating_url = $this->rating_url;
$text_align = $this->text_align;
include __DIR__ . '/views/html-text-petition.php';
return ob_get_clean();
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ use WPDesk\RepositoryRating\DisplayStrategy\DisplayDecision;
/**
* Can display text petition.
*/
class TextPetition implements Hookable {
class TextPetitionDisplayer implements Hookable {
/**
* @var string
......@@ -20,56 +20,29 @@ class TextPetition implements Hookable {
*/
private $display_decision;
/**
* @var string
*/
private $text_align;
/**
* @var string
* @var PetitionText
*/
private $plugin_author;
/**
* @var string
*/
private $plugin_title;
/**
* @var string
*/
private $rating_url;
private $petition_text_generator;
/**
* @param string $display_on_action
* @param DisplayDecision $display_decision
* @param string $plugin_author
* @param string $plugin_title
* @param string $rating_url
* @param string $text_align
* @param PetitionText $petition_text_generator
*/
public function __construct( string $display_on_action, DisplayDecision $display_decision, string $plugin_author, string $plugin_title, string $rating_url, string $text_align = 'center' ) {
public function __construct( string $display_on_action, DisplayDecision $display_decision, PetitionText $petition_text_generator ) {
$this->display_on_action = $display_on_action;
$this->display_decision = $display_decision;
$this->text_align = $text_align;
$this->plugin_author = $plugin_author;
$this->plugin_title = $plugin_title;
$this->rating_url = $rating_url;
$this->petition_text_generator = $petition_text_generator;
}
public function hooks() {
add_action( $this->display_on_action, [ $this, 'display_petition_if_should' ] );
}
public function display_petition_if_should() {
if ( $this->display_decision->should_display() ) {
$text_align = $this->text_align;
$plugin_author = $this->plugin_author;
$plugin_title = $this->plugin_title;
$rating_url = $this->rating_url;
include __DIR__ . '/views/html-text-petition.php';
echo wp_kses_post( $this->petition_text_generator->get_petition_text() );
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment