first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,183 @@
<?php
/**
* Class WPML_TF_Feedback_Collection_Filter
*
* @author OnTheGoSystems
*/
class WPML_TF_Feedback_Collection_Filter implements IWPML_TF_Collection_Filter {
/** @var bool $exclude_rating_only */
private $exclude_rating_only;
/** @var array $language_pairs */
private $language_pairs;
/** @var int $pending_tp_ratings */
private $pending_tp_ratings;
/** @var int tp_feedback_id */
private $tp_feedback_id;
/** @var int $post_id */
private $post_id;
/** @var int $reviewer_id */
private $reviewer_id;
/**
* WPML_TF_Feedback_Collection_Filter constructor.
*
* @param array $args
*/
public function __construct( array $args ) {
if ( isset( $args['exclude_rating_only'] ) ) {
$this->exclude_rating_only = $args['exclude_rating_only'];
}
if ( isset( $args['language_pairs'] ) ) {
$this->language_pairs = $args['language_pairs'];
}
if ( isset( $args['pending_tp_ratings'] ) ) {
$this->pending_tp_ratings = (int) $args['pending_tp_ratings'];
}
if ( isset( $args['tp_feedback_id'] ) ) {
$this->tp_feedback_id = (int) $args['tp_feedback_id'];
}
if ( isset( $args['post_id'] ) ) {
$this->post_id = (int) $args['post_id'];
}
if ( isset( $args['reviewer_id'] ) ) {
$this->reviewer_id = (int) $args['reviewer_id'];
}
}
/** @return null|bool */
private function get_exclude_rating_only() {
return $this->exclude_rating_only;
}
/** @return null|array */
private function get_language_pairs() {
return $this->language_pairs;
}
/** @return null|int */
private function get_pending_tp_ratings() {
return $this->pending_tp_ratings;
}
/** @return null|int */
private function get_tp_feedback_id() {
return $this->tp_feedback_id;
}
/** @return null|int */
private function get_reviewer_id() {
return $this->reviewer_id;
}
/** @return null|int */
private function get_post_id() {
return $this->post_id;
}
/** @return array */
public function get_posts_args() {
$args = array(
'posts_per_page' => -1,
'post_type' => WPML_TF_Feedback_Post_Convert::POST_TYPE,
'suppress_filters' => false,
'post_status' => array( 'any', 'trash' ),
);
if ( $this->get_exclude_rating_only() ) {
$args['exclude_tf_rating_only'] = true;
}
if ( is_array( $this->get_language_pairs() ) ) {
$meta_query = array(
'relation' => 'OR',
);
foreach ( $this->get_language_pairs() as $from => $targets ) {
foreach ( $targets as $to => $value ) {
$meta_query[] = array(
'relation' => 'AND',
array(
'key' => WPML_TF_Data_Object_Storage::META_PREFIX . 'language_from',
'value' => $from,
'compare' => '=',
),
array(
'key' => WPML_TF_Data_Object_Storage::META_PREFIX . 'language_to',
'value' => $to,
'compare' => '=',
),
);
}
}
$args['meta_query'] = $meta_query;
} elseif ( $this->get_pending_tp_ratings() ) {
$args['posts_per_page'] = $this->get_pending_tp_ratings();
$args['orderby'] = 'ID';
$args['order'] = 'ASC';
$args['meta_query'] = array(
array(
'key' => WPML_TF_Data_Object_Storage::META_PREFIX . 'tp_rating_id',
'value' => '',
'compare' => '=',
'type' => 'CHAR',
),
);
} elseif ( $this->get_tp_feedback_id() ) {
$args['posts_per_page'] = 1;
$args['meta_query'] = array(
array(
'key' => WPML_TF_Data_Object_Storage::META_PREFIX . 'tp_feedback_id',
'value' => $this->get_tp_feedback_id(),
'compare' => '=',
),
);
} elseif ( $this->get_post_id() ) {
$args['meta_query'] = array(
'relation' => 'AND',
array(
'key' => WPML_TF_Data_Object_Storage::META_PREFIX . 'document_id',
'value' => $this->get_post_id(),
'compare' => '=',
),
array(
'key' => WPML_TF_Data_Object_Storage::META_PREFIX . 'document_type',
'value' => 'post_' . get_post_type( $this->get_post_id() ),
'compare' => '=',
),
);
} elseif ( $this->get_reviewer_id() ) {
$args['meta_query'] = array(
array(
'key' => WPML_TF_Data_Object_Storage::META_PREFIX . 'reviewer_id',
'value' => $this->get_reviewer_id(),
'compare' => '=',
),
);
}
return $args;
}
/** @return WPML_TF_Feedback_Collection */
public function get_new_collection() {
return new WPML_TF_Feedback_Collection();
}
}

View File

@@ -0,0 +1,240 @@
<?php
/**
* Class WPML_TF_Feedback_Collection
*
* @author OnTheGoSystems
*/
class WPML_TF_Feedback_Collection extends WPML_TF_Collection {
private $order;
private $filter_value;
/**
* @param int $offset
* @param int $length
*/
public function reduce_collection( $offset, $length ) {
$this->collection = array_slice( $this->collection, $offset, $length, true );
}
/**
* @param string $property
* @param string $order
*/
public function sort_collection( $property, $order ) {
$this->order = $order;
$method = 'compare_by_' . $property;
if ( method_exists( $this, $method ) ) {
// Use @ to avoid warnings in unit tests => see bug https://bugs.php.net/bug.php?id=50688
@uasort( $this->collection, array( $this, $method ) );
}
}
/**
* @param WPML_TF_Feedback $a
* @param WPML_TF_Feedback $b
*
* @return mixed
*/
private function compare_by_pending( WPML_TF_Feedback $a, WPML_TF_Feedback $b ) {
if ( $a->is_pending() && ! $b->is_pending() ) {
$compare = -1;
} elseif ( ! $a->is_pending() && $b->is_pending() ) {
$compare = 1;
} else {
$compare = $this->compare_by_id( $a, $b );
}
return $compare;
}
/**
* @param WPML_TF_Feedback $a
* @param WPML_TF_Feedback $b
*
* @return mixed
*/
private function compare_by_feedback( WPML_TF_Feedback $a, WPML_TF_Feedback $b ) {
if ( 'asc' === $this->order ) {
$compare = strcasecmp( $a->get_content(), $b->get_content() );
} else {
$compare = strcasecmp( $b->get_content(), $a->get_content() );
}
if ( 0 === $compare ) {
$compare = $this->compare_by_id( $a, $b );
}
return $compare;
}
/**
* @param WPML_TF_Feedback $a
* @param WPML_TF_Feedback $b
*
* @return mixed
*/
private function compare_by_rating( WPML_TF_Feedback $a, WPML_TF_Feedback $b ) {
if ( 'asc' === $this->order ) {
$compare = $a->get_rating() - $b->get_rating();
} else {
$compare = $b->get_rating() - $a->get_rating();
}
if ( 0 === $compare ) {
$compare = $this->compare_by_id( $a, $b );
}
return $compare;
}
/**
* @param WPML_TF_Feedback $a
* @param WPML_TF_Feedback $b
*
* @return mixed
*/
private function compare_by_status( WPML_TF_Feedback $a, WPML_TF_Feedback $b ) {
if ( 'asc' === $this->order ) {
$compare = strcmp( $a->get_text_status(), $b->get_text_status() );
} else {
$compare = strcmp( $b->get_text_status(), $a->get_text_status() );
}
if ( 0 === $compare ) {
$compare = $this->compare_by_id( $a, $b );
}
return $compare;
}
/**
* @param WPML_TF_Feedback $a
* @param WPML_TF_Feedback $b
*
* @return mixed
*/
private function compare_by_document_title( WPML_TF_Feedback $a, WPML_TF_Feedback $b ) {
if ( 'asc' === $this->order ) {
$compare = strcasecmp( $a->get_document_information()->get_title(), $b->get_document_information()->get_title() );
} else {
$compare = strcasecmp( $b->get_document_information()->get_title(), $a->get_document_information()->get_title() );
}
if ( 0 === $compare ) {
$compare = $this->compare_by_id( $a, $b );
}
return $compare;
}
/**
* @param WPML_TF_Feedback $a
* @param WPML_TF_Feedback $b
*
* @return mixed
*/
private function compare_by_date( WPML_TF_Feedback $a, WPML_TF_Feedback $b ) {
if ( 'asc' === $this->order ) {
$compare = strtotime( $a->get_date_created() ) - strtotime( $b->get_date_created() );
} else {
$compare = strtotime( $b->get_date_created() ) - strtotime( $a->get_date_created() );
}
if ( 0 === $compare ) {
$compare = $this->compare_by_id( $a, $b );
}
return $compare;
}
/**
* @param WPML_TF_Feedback $a
* @param WPML_TF_Feedback $b
*
* @return int
*/
private function compare_by_id( WPML_TF_Feedback $a, WPML_TF_Feedback $b ) {
if ( 'asc' === $this->order ) {
return $a->get_id() - $b->get_id();
} else {
return $b->get_id() - $a->get_id();
}
}
/**
* @param WPML_TF_Message_Collection $message_collection
*/
public function link_messages_to_feedback( WPML_TF_Message_Collection $message_collection ) {
foreach ( $message_collection as $message ) {
if ( array_key_exists( $message->get_feedback_id(), $this->collection ) ) {
$this->collection[ $message->get_feedback_id() ]->add_message( $message );
}
}
}
/**
* @param string $property
* @param string $value
*/
public function filter_by( $property, $value ) {
$this->filter_value = $value;
$method = 'filter_by_' . $property;
if ( method_exists( $this, $method ) ) {
$this->collection = array_filter( $this->collection, array( $this, $method ) );
}
}
/**
* @param WPML_TF_Feedback $feedback
*
* @return bool
*/
private function filter_by_status( WPML_TF_Feedback $feedback ) {
if ( $feedback->get_status() === $this->filter_value ) {
return true;
}
return false;
}
/**
* @param WPML_TF_Feedback $feedback
*
* @return bool
*/
private function filter_by_language( WPML_TF_Feedback $feedback ) {
if ( $feedback->get_language_to() === $this->filter_value ) {
return true;
}
return false;
}
/**
* @param WPML_TF_Feedback $feedback
*
* @return bool
*/
private function filter_by_post_id( WPML_TF_Feedback $feedback ) {
if ( 0 === strpos( $feedback->get_document_type(), 'post_' )
&& $feedback->get_document_id() === (int) $this->filter_value
) {
return true;
}
return false;
}
public function remove_trashed() {
foreach ( $this->collection as $id => $feedback ) {
/** @var WPML_TF_Feedback $feedback */
if ( 'trash' === $feedback->get_status() ) {
unset( $this->collection[ $id ] );
}
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Class WPML_TF_Feedback_Factory
*
* @author OnTheGoSystems
*/
class WPML_TF_Feedback_Factory {
/**
* @param array $feedback_data
*
* @return WPML_TF_Feedback
*/
public function create( array $feedback_data ) {
global $sitepress;
$document_information = new WPML_TF_Backend_Document_Information(
$sitepress,
class_exists( 'WPML_TP_Client_Factory' ) ? new WPML_TP_Client_Factory() : null
);
return new WPML_TF_Feedback( $feedback_data, $document_information );
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Class WPML_TF_Feedback_Post_Convert
*
* @author OnTheGoSystems
*/
class WPML_TF_Feedback_Post_Convert extends WPML_TF_Data_Object_Post_Convert {
const POST_TYPE = 'wpml_tf_feedback';
/**
* @return array
*/
public function get_post_fields() {
return array(
'id' => 'ID',
'date_created' => 'post_date',
'content' => 'post_content',
'status' => 'post_status',
);
}
/**
* @return array
*/
public function get_meta_fields() {
return array(
'rating',
'document_id',
'document_type',
'language_from',
'language_to',
'job_id',
'reviewer_id',
'tp_rating_id',
'tp_feedback_id',
'feedback_forward_method'
);
}
/**
* @param IWPML_TF_Data_Object $feedback
*
* @return array
* @throws Exception
*/
public function to_post_data( IWPML_TF_Data_Object $feedback ) {
if( ! $feedback instanceof WPML_TF_Feedback ) {
throw new Exception( 'The $feedback argument must be an instance of WPML_TF_Feedback' );
}
/** @var WPML_TF_Feedback $feedback */
$post = new stdClass();
$post->ID = $feedback->get_id();
$post->post_date = $feedback->get_date_created();
$post->post_content = $feedback->get_content();
$post->post_status = $feedback->get_status();
$post->post_type = self::POST_TYPE;
return array(
'post' => $post,
'metadata' => array(
'rating' => $feedback->get_rating(),
'document_id' => $feedback->get_document_id(),
'document_type' => $feedback->get_document_type(),
'language_from' => $feedback->get_language_from(),
'language_to' => $feedback->get_language_to(),
'job_id' => $feedback->get_job_id(),
'reviewer_id' => $feedback->get_reviewer()->get_id(),
'tp_rating_id' => $feedback->get_tp_responses()->get_rating_id(),
'tp_feedback_id' => $feedback->get_tp_responses()->get_feedback_id(),
'feedback_forward_method' => $feedback->get_tp_responses()->get_feedback_forward_method(),
),
);
}
/**
* @param array $post_data
*
* @return WPML_TF_Feedback
*/
public function to_object( array $post_data ) {
$feedback_data = $this->build_object_data_for_constructor( $post_data );
$feedback_factory = new WPML_TF_Feedback_Factory();
return $feedback_factory->create( $feedback_data );
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* @author OnTheGoSystems
*/
class WPML_TF_Feedback_Reviewer {
/** @var int $id WP_User ID */
private $id;
/**
* WPML_TF_Feedback_Reviewer constructor.
*
* @param int $id
*/
public function __construct( $id ) {
$this->id = (int) $id;
}
/**
* @return int|null
*/
public function get_id() {
return $this->id;
}
/**
* @return string
*/
public function get_reviewer_display_name() {
$display_name = __( 'Unknown reviewer', 'sitepress' );
$reviewer = get_user_by( 'id', $this->get_id() );
if ( isset( $reviewer->display_name ) ) {
$display_name = $reviewer->display_name;
}
return $display_name;
}
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* Class WPML_TF_Feedback_Status
*
* @author OnTheGoSystems
*/
class WPML_TF_Feedback_Status {
/** @var string $status */
private $status = 'pending';
/**
* WPML_TF_Feedback_Status constructor.
*
* @param string $status
*/
public function __construct( $status = null ) {
if ( $status ) {
$this->set_value( $status );
}
}
/** @param string $status*/
public function set_value( $status ) {
$this->status = sanitize_text_field( $status );
}
/** @return string */
public function get_value() {
return $this->status;
}
/** @return null|string */
public function get_display_text() {
switch ( $this->get_value() ) {
case 'pending':
return __( 'New', 'sitepress' );
case 'sent_to_translator':
if ( $this->is_admin_user() ) {
return __( 'Sent to translator', 'sitepress' );
}
return __( 'New', 'sitepress' );
case 'translator_replied':
if ( $this->is_admin_user() ) {
return __( 'Translator replied', 'sitepress' );
}
return __( 'Replied', 'sitepress' );
case 'admin_replied':
if ( $this->is_admin_user() ) {
return __( 'Sent to translator', 'sitepress' );
}
return __( 'Admin replied', 'sitepress' );
case 'sent_to_ts_api':
case 'sent_to_ts_manual':
return __( 'Sent to translation service', 'sitepress' );
case 'sent_to_ts_email':
return __( 'E-mail sent to translation service', 'sitepress' );
case 'fixed':
return __( 'Translation fixed', 'sitepress' );
case 'publish':
return __( 'Approved', 'sitepress' );
}
return null;
}
/** @return bool */
private function is_admin_user() {
return current_user_can( 'manage_options' );
}
/**
* This is used by the blue button on the feedback list
*
* @return array|null
*/
public function get_next_status() {
if ( $this->is_admin_user() ) {
switch ( $this->get_value() ) {
case 'pending':
case 'sent_to_translator':
return array(
'value' => 'sent_to_translator',
'label' => __( 'Send to translator', 'sitepress' ),
);
case 'translator_replied':
return array(
'value' => 'admin_replied',
'label' => __( 'Reply to translator', 'sitepress' ),
);
case 'admin_replied':
return array(
'value' => 'admin_replied',
'label' => __( 'Send to translator', 'sitepress' ),
);
}
} else {
switch ( $this->get_value() ) {
case 'sent_to_translator':
case 'translator_replied':
case 'admin_replied':
return array(
'value' => 'translator_replied',
'label' => __( 'Reply to admin', 'sitepress' ),
);
}
}
return null;
}
/** @return bool */
public function is_pending() {
$pending_statuses = array( 'pending' );
if ( current_user_can( 'manage_options' ) ) {
$pending_statuses[] = 'translator_replied';
} else {
$pending_statuses[] = 'admin_replied';
$pending_statuses[] = 'sent_to_translator';
}
return in_array( $this->status, $pending_statuses, true );
}
}

View File

@@ -0,0 +1,297 @@
<?php
/**
* Class WPML_TF_Feedback
*
* @author OnTheGoSystems
*/
class WPML_TF_Feedback implements IWPML_TF_Data_Object {
/** @var int */
private $id;
/** @var string */
private $date_created;
/** @var WPML_TF_Feedback_Status */
private $status;
/** @var int */
private $rating;
/** @var string */
private $content;
/** @var int */
private $document_id;
/** @var string */
private $document_type;
/** @var string */
private $language_from;
/** @var string */
private $language_to;
/** @var int|null */
private $job_id;
/** @var WPML_TF_Feedback_Reviewer */
private $reviewer;
/** @var WPML_TF_Collection $messages */
private $messages;
/** @var WPML_TF_Backend_Document_Information $document_information */
private $document_information;
/** @var WPML_TF_TP_Responses $tp_rating_responses */
private $tp_responses;
/**
* WPML_Translation_Feedback constructor.
*
* @param array $data
* @param WPML_TF_Backend_Document_Information $document_information
*/
public function __construct(
$data = array(),
WPML_TF_Backend_Document_Information $document_information = null
) {
$this->id = array_key_exists( 'id', $data ) ? (int) $data['id'] : null;
$this->date_created = array_key_exists( 'date_created', $data )
? sanitize_text_field( $data['date_created'] ) : null;
$this->rating = array_key_exists( 'rating', $data ) ? (int) $data['rating'] : null;
$this->content = array_key_exists( 'content', $data )
? sanitize_text_field( $data['content'] ) : '';
$this->document_id = array_key_exists( 'document_id', $data ) ? (int) $data['document_id'] : null;
$this->document_type = array_key_exists( 'document_type', $data )
? sanitize_text_field( $data['document_type'] ) : null;
$this->language_from = array_key_exists( 'language_from', $data )
? sanitize_text_field( $data['language_from'] ) : null;
$this->language_to = array_key_exists( 'language_to', $data )
? sanitize_text_field( $data['language_to'] ) : null;
$this->job_id = array_key_exists( 'job_id', $data ) ? (int) $data['job_id'] : null;
$this->messages = array_key_exists( 'messages', $data ) && $data['messages'] instanceof WPML_TF_Collection
? $data['messages'] : new WPML_TF_Message_Collection();
if ( array_key_exists( 'reviewer_id', $data ) ) {
$this->set_reviewer( $data['reviewer_id'] );
}
$this->status = array_key_exists( 'status', $data )
? new WPML_TF_Feedback_Status( $data['status'] ) : new WPML_TF_Feedback_Status( 'pending' );
$this->set_tp_responses( new WPML_TF_TP_Responses( $data ) );
if ( $document_information ) {
$this->set_document_information( $document_information );
}
}
/**
* @return int|mixed|null
*/
public function get_id() {
return $this->id;
}
/**
* @return int|null
*/
public function get_feedback_id() {
return $this->id;
}
/**
* @param \WPML_TF_Message $message
*/
public function add_message( WPML_TF_Message $message ) {
$this->messages->add( $message );
}
/**
* @return mixed|null|string
*/
public function get_date_created() {
return $this->date_created;
}
/**
* @return string
*/
public function get_status() {
return $this->status->get_value();
}
/**
* @param string $status
*/
public function set_status( $status ) {
$this->status->set_value( $status );
}
/**
* @return int
*/
public function get_rating() {
return $this->rating;
}
/**
* @param int $rating
*/
public function set_rating( $rating ) {
$this->rating = (int) $rating;
}
/**
* @return mixed|null|string
*/
public function get_content() {
return $this->content;
}
/**
* @param string $content
*/
public function set_content( $content ) {
$this->content = sanitize_text_field( $content );
}
/**
* @return int|null
*/
public function get_document_id() {
return $this->document_id;
}
/**
* @return null|string
*/
public function get_document_type() {
return $this->document_type;
}
/**
* @return null|string
*/
public function get_language_from() {
return $this->language_from;
}
/**
* @return null|string
*/
public function get_language_to() {
return $this->language_to;
}
/**
* @return int|null
*/
public function get_job_id() {
return $this->job_id;
}
/**
* @return WPML_TF_Feedback_Reviewer
*/
public function get_reviewer() {
if ( ! isset( $this->reviewer ) ) {
$this->set_reviewer( 0 );
}
return $this->reviewer;
}
/**
* @param int $reviewer_id
*/
public function set_reviewer( $reviewer_id ) {
$this->reviewer = new WPML_TF_Feedback_Reviewer( $reviewer_id );
}
/**
* @return WPML_TF_Collection
*/
public function get_messages() {
return $this->messages;
}
/** @param WPML_TF_TP_Responses $tp_responses */
public function set_tp_responses( WPML_TF_TP_Responses $tp_responses ) {
$this->tp_responses = $tp_responses;
}
/** @return WPML_TF_TP_Responses */
public function get_tp_responses() {
return $this->tp_responses;
}
/**
* @return string|null
*/
public function get_text_status() {
return $this->status->get_display_text();
}
/** @return array */
public function get_next_status() {
return $this->status->get_next_status();
}
/** @return bool */
public function is_pending() {
return $this->status->is_pending();
}
/**
* @return string
*/
public function get_document_flag_url() {
return $this->document_information->get_flag_url( $this->get_language_to() );
}
/**
* @return string
*/
public function get_source_document_flag_url() {
return $this->document_information->get_flag_url( $this->get_language_from() );
}
/**
* @return bool
*/
public function is_local_translation() {
return $this->document_information->is_local_translation( $this->get_job_id() );
}
/**
* @return string
*/
public function get_translator_name() {
return $this->document_information->get_translator_name( $this->get_job_id() );
}
/**
* @return array
*/
public function get_available_translators() {
return $this->document_information->get_available_translators( $this->language_from, $this->language_to );
}
/**
* @param WPML_TF_Backend_Document_Information $document_information
*/
public function set_document_information( WPML_TF_Backend_Document_Information $document_information ) {
$this->document_information = $document_information;
$this->document_information->init( $this->get_document_id(), $this->get_document_type() );
}
/** @return WPML_TF_Backend_Document_Information */
public function get_document_information() {
return $this->document_information;
}
}

View File

@@ -0,0 +1,117 @@
<?php
use WPML\API\Sanitize;
/**
* Class WPML_TF_TP_Responses
*
* @author OnTheGoSystems
*/
class WPML_TF_TP_Responses {
const FEEDBACK_FORWARD_MANUAL = 'manual';
const FEEDBACK_FORWARD_EMAIL = 'email';
const FEEDBACK_FORWARD_API = 'api';
const FEEDBACK_TP_URL_ENDPOINT = '/feedbacks/{feedback_id}/external';
/**
* @var string|int $tp_rating_id
*
* - empty string for rating never sent (or problems occurred during TP transmission)
* - 0 for local jobs (which does not need to be sent)
* - positive integer for ratings already sent
*
* This will allow to have a shorter DB query to select feedback to be sent
*/
private $rating_id = '';
/** @var null|int $feedback_id */
private $feedback_id;
/** @var null|string $feedback_forward_method */
private $feedback_forward_method;
public function __construct( array $args = array() ) {
if( isset( $args['tp_rating_id'] ) ) {
$this->set_rating_id( $args['tp_rating_id'] );
}
if( isset( $args['tp_feedback_id'] ) ) {
$this->set_feedback_id( $args['tp_feedback_id'] );
}
if( isset( $args['feedback_forward_method'] ) ) {
$this->set_feedback_forward_method( $args['feedback_forward_method'] );
}
}
/** @param string|int $rating_id */
public function set_rating_id( $rating_id ) {
if ( is_numeric( $rating_id ) ) {
$rating_id = (int) $rating_id;
}
$this->rating_id = $rating_id;
}
/** @return string|int */
public function get_rating_id() {
return $this->rating_id;
}
/** @param int $feedback_id */
public function set_feedback_id( $feedback_id ) {
$this->feedback_id = (int) $feedback_id;
}
/** @return null|int */
public function get_feedback_id() {
return $this->feedback_id;
}
/** @param string $method */
public function set_feedback_forward_method( $method ) {
$this->feedback_forward_method = Sanitize::string( $method );
}
/** @return null|string */
public function get_feedback_forward_method() {
return $this->feedback_forward_method;
}
/** @return bool */
public function is_manual_feedback() {
return self::FEEDBACK_FORWARD_MANUAL === $this->feedback_forward_method;
}
/** @return bool */
public function is_email_feedback() {
return self::FEEDBACK_FORWARD_EMAIL === $this->feedback_forward_method;
}
/** @return bool */
public function is_api_feedback() {
return self::FEEDBACK_FORWARD_API === $this->feedback_forward_method;
}
/** @return null|string */
public function get_feedback_tp_url() {
$url = null;
if ( $this->is_api_feedback() && defined( 'OTG_TRANSLATION_PROXY_URL' ) ) {
$url = OTG_TRANSLATION_PROXY_URL . self::FEEDBACK_TP_URL_ENDPOINT;
$url = preg_replace( '/{feedback_id}/', $this->get_feedback_id(), $url );
}
return $url;
}
/** @return array */
public function get_strings() {
return array(
'display_for_manual' => __( '%1s cannot receive feedback about the translation automatically. Please log-in to %1s website and report these issues manually.', 'sitepress' ),
'display_for_email' => __( 'An email has been sent to %s to report the issue. Please check your email for a feedback from their part.', 'sitepress' ),
'display_for_api' => __( 'Issue tracking in %s', 'sitepress' ),
);
}
}