first commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TF_Message_Collection_Filter
|
||||
*
|
||||
* @author OnTheGoSystems
|
||||
*/
|
||||
class WPML_TF_Message_Collection_Filter implements IWPML_TF_Collection_Filter {
|
||||
|
||||
/** @var int $feedback_id */
|
||||
private $feedback_id;
|
||||
|
||||
/** @var array|null */
|
||||
private $feedback_ids;
|
||||
|
||||
/**
|
||||
* WPML_TF_Feedback_Collection_Filter constructor.
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
public function __construct( array $args = array() ) {
|
||||
if ( isset( $args['feedback_id'] ) ) {
|
||||
$this->feedback_id = (int) $args['feedback_id'];
|
||||
}
|
||||
|
||||
if ( isset( $args['feedback_ids'] ) && is_array( $args['feedback_ids'] ) ) {
|
||||
$this->feedback_ids = $args['feedback_ids'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
private function get_feedback_id() {
|
||||
return $this->feedback_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
private function get_feedback_ids() {
|
||||
return $this->feedback_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_posts_args() {
|
||||
$posts_args = array(
|
||||
'posts_per_page' => -1,
|
||||
'post_type' => WPML_TF_Message_Post_Convert::POST_TYPE,
|
||||
'suppress_filters' => false,
|
||||
'post_status' => 'any',
|
||||
);
|
||||
|
||||
if ( $this->get_feedback_id() ) {
|
||||
$posts_args['post_parent'] = $this->get_feedback_id();
|
||||
}
|
||||
|
||||
if ( $this->get_feedback_ids() ) {
|
||||
$posts_args['post_parent__in'] = $this->get_feedback_ids();
|
||||
}
|
||||
|
||||
return $posts_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WPML_TF_Message_Collection
|
||||
*/
|
||||
public function get_new_collection() {
|
||||
return new WPML_TF_Message_Collection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TF_Message_Collection
|
||||
*
|
||||
* @author OnTheGoSystems
|
||||
*/
|
||||
class WPML_TF_Message_Collection extends WPML_TF_Collection {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TF_Message_Post_Convert
|
||||
*
|
||||
* @author OnTheGoSystems
|
||||
*/
|
||||
class WPML_TF_Message_Post_Convert extends WPML_TF_Data_Object_Post_Convert {
|
||||
|
||||
const POST_TYPE = 'wpml_tf_message';
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_post_fields() {
|
||||
return array(
|
||||
'id' => 'ID',
|
||||
'date_created' => 'post_date',
|
||||
'content' => 'post_content',
|
||||
'feedback_id' => 'post_parent',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_meta_fields() {
|
||||
return array(
|
||||
'author_id',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IWPML_TF_Data_Object $message
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function to_post_data( IWPML_TF_Data_Object $message ) {
|
||||
if( ! $message instanceof WPML_TF_Message ) {
|
||||
throw new Exception( 'The $message argument must be an instance of WPML_TF_Message' );
|
||||
}
|
||||
|
||||
/** @var WPML_TF_Message $message */
|
||||
$post = new stdClass();
|
||||
$post->ID = $message->get_id();
|
||||
$post->post_date = $message->get_date_created();
|
||||
$post->post_content = $message->get_content();
|
||||
$post->post_parent = $message->get_feedback_id();
|
||||
$post->post_type = self::POST_TYPE;
|
||||
|
||||
return array(
|
||||
'post' => $post,
|
||||
'metadata' => array(
|
||||
'author_id' => $message->get_author_id(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $post_data
|
||||
*
|
||||
* @return WPML_TF_Message
|
||||
*/
|
||||
public function to_object( array $post_data ) {
|
||||
$message_data = $this->build_object_data_for_constructor( $post_data );
|
||||
return new WPML_TF_Message( $message_data );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TF_Message
|
||||
*
|
||||
* @author OnTheGoSystems
|
||||
*/
|
||||
class WPML_TF_Message implements IWPML_TF_Data_Object {
|
||||
|
||||
/** @var int $id */
|
||||
private $id;
|
||||
|
||||
/** @var int $feedback_id */
|
||||
private $feedback_id;
|
||||
|
||||
/** @var string $date_created */
|
||||
private $date_created;
|
||||
|
||||
/** @var string $content */
|
||||
private $content;
|
||||
|
||||
/** @var string $author_id */
|
||||
private $author_id;
|
||||
|
||||
/**
|
||||
* WPML_Translation_Feedback constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct( $data = array() ) {
|
||||
$this->id = array_key_exists( 'id', $data ) ? (int) $data['id'] : null;
|
||||
$this->feedback_id = array_key_exists( 'feedback_id', $data ) ? (int) $data['feedback_id'] : null;
|
||||
$this->date_created = array_key_exists( 'date_created', $data )
|
||||
? sanitize_text_field( $data['date_created'] ) : null;
|
||||
$this->content = array_key_exists( 'content', $data )
|
||||
? sanitize_text_field( $data['content'] ) : null;
|
||||
$this->author_id = array_key_exists( 'author_id', $data )
|
||||
? (int) $data['author_id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed|null
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_feedback_id() {
|
||||
return $this->feedback_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WPML_TF_Message $message
|
||||
*/
|
||||
public function add_message( WPML_TF_Message $message ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|null|string
|
||||
*/
|
||||
public function get_date_created() {
|
||||
return $this->date_created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|null|string
|
||||
*/
|
||||
public function get_content() {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_author_id() {
|
||||
return $this->author_id;
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
public function get_author_display_label() {
|
||||
$label = __( 'Translator', 'sitepress' );
|
||||
|
||||
if ( user_can( $this->get_author_id(), 'manage_options' ) ) {
|
||||
$label = __( 'Admin', 'sitepress' );
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
/** @return bool */
|
||||
public function author_is_current_user() {
|
||||
$current_user = wp_get_current_user();
|
||||
return $current_user->ID === $this->author_id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user