criando classes filtros

This commit is contained in:
Eduardo humberto 2017-11-13 14:25:16 -02:00
parent 3612d37c81
commit 17611206b1
3 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Tainacan_Filter extends Entity {
use EntityCollectionRelation;
function __construct( $which = 0 ) {
$this->repository = 'Tainacan_Filters';
if ( is_numeric( $which ) && $which > 0) {
$post = get_post( $which );
if ( $post instanceof WP_Post) {
$this->WP_Post = get_post( $which );
}
} elseif ( $which instanceof WP_Post ) {
$this->WP_Post = $which;
} else {
$this->WP_Post = new StdClass();
}
}
// Getters
function get_id() {
return $this->get_mapped_property('ID');
}
function get_name() {
return $this->get_mapped_property('name');
}
function get_order() {
return $this->get_mapped_property('order');
}
function get_widget( $output = 'object' ){
if( $output === 'object'){
return unserialize( $this->get_mapped_property('option') );
}else{
return $this->get_mapped_property('widget');
}
}
//Setters
function set_widget($value){
if( is_object( $value ) && is_subclass_of( $value, 'Tainacan_Filter_Type' ) ){
$this->set_option( $value );
return $this->set_mapped_property('widget', get_class( $value ) ) ;
}
return null;
}
function set_option($value){
return $this->set_mapped_property('option', serialize($value) ) ;
}
}

View File

@ -0,0 +1,21 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
abstract class Tainacan_Filter_Type extends Entity {
abstract function render( $metadata );
function validate( $value ) {
return true;
}
function get_validation_errors() {
return [];
}
}

View File

@ -0,0 +1,84 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Tainacan_Filters {
const POST_TYPE = 'tainacan-filters';
var $map = [
'ID' => [
'map' => 'ID',
'validation' => ''
],
'name' => [
'map' => 'post_title',
'validation' => ''
],
'order' => [
'map' => 'menu_order',
'validation' => ''
],
'parent' => [
'map' => 'parent',
'validation' => ''
],
'description' => [
'map' => 'post_content',
'validation' => ''
],
'slug' => [
'map' => 'post_name',
'validation' => ''
],
'itens_per_page' => [
'map' => 'meta',
'validation' => ''
],
];
function __construct()
{
add_action('init', array(&$this, 'register_post_type'));
}
function register_post_type()
{
$labels = array(
'name' => 'Collections',
'singular_name' => 'Collections',
'add_new' => 'Adicionar Novo',
'add_new_item' => 'Adicionar Collections',
'edit_item' => 'Editar',
'new_item' => 'Novo Collections',
'view_item' => 'Visualizar',
'search_items' => 'Pesquisar',
'not_found' => 'Nenhum ticket encontrado',
'not_found_in_trash' => 'Nenhum Collections encontrado na lixeira',
'parent_item_colon' => 'Collections acima:',
'menu_name' => 'Collections'
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
//'supports' => array('title'),
//'taxonomies' => array(self::TAXONOMY),
'public' => true,
'show_ui' => tnc_enable_dev_wp_interface(),
'show_in_menu' => tnc_enable_dev_wp_interface(),
//'menu_position' => 5,
//'show_in_nav_menus' => false,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
);
register_post_type(self::POST_TYPE, $args);
}
}