<?php
/*
*	---------------------------------------------------------------------
*	This file create and contains the team post_type meta elements
*	---------------------------------------------------------------------
*/
add_action('init', 'tzinteriart_create_team');
function tzinteriart_create_team()
{
    $labels = array(
        'name'               => esc_html_x('Team', 'Team General Name', 'tz-interiart'),
        'singular_name'      => esc_html_x('Team Item', 'Team Singular Name', 'tz-interiart'),
        'add_new'            => esc_html_x('Add New', 'Add New team Name', 'tz-interiart'),
        'add_new_item'       => esc_html__('Add New team', 'tz-interiart'),
        'edit_item'          => esc_html__('Edit team', 'tz-interiart'),
        'new_item'           => esc_html__('New team', 'tz-interiart'),
        'view_item'          => esc_html__('View team', 'tz-interiart'),
        'search_items'       => esc_html__('Search team', 'tz-interiart'),
        'not_found'          => esc_html__('Nothing found', 'tz-interiart'),
        'not_found_in_trash' => esc_html__('Nothing found in Trash', 'tz-interiart'),
        'parent_item_colon'  => ''
    );
    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'query_var'          => true,
        'rewrite'            => true,
//        'capability_type'    => 'post',
        'hierarchical'       => false,
        'menu_position'      => 5,
        'supports'           => array('title', 'editor','author','excerpt', 'thumbnail','comments'), //'editor', 'excerpt', 'comments',
        'rewrite'            => array('slug' => 'team', 'with_front' => false ),
        'has_archive'        => true,
    );
    register_post_type('team', $args);
    register_taxonomy(
        "team-category", array( "team" ), array(
        "hierarchical"   => true,
        "label"          => esc_html__("Team Categories","tz-interiart"),
        "singular_label" => esc_html__("Team Categories","tz-interiart"),
        "rewrite"        => true ));
    register_taxonomy_for_object_type('team-category', 'team');

    // function tags
    register_taxonomy(
        "team-tags",array("team"), array(
            "hierarchical"   => '',
            "label"          => esc_html__("Team Tags","tz-interiart"),
            "singular_label" => esc_html__("Team Tags","tz-interiart"),
            "rewrite"        => ''
        )
    );
    register_taxonomy_for_object_type('protfolio-tags','team');
}

// filter for team first page
add_filter("manage_edit-team_columns", "tzinteriart_show_team_column");
function tzinteriart_show_team_column($columns)
{
    $columns = array(
        "cb"                 => "<input type=\"checkbox\" />",
        "title"              => esc_html__("Title","tz-interiart"),
        "author"             => esc_html__("Author","tz-interiart"),
        "team-category" => esc_html__("Team Categories","tz-interiart"),
        "team-tags"     => esc_html__("Team Tags","tz-interiart"),
        "date"               => esc_html__("date","tz-interiart")
    );

    return $columns;
}

add_action("manage_posts_custom_column", "tzinteriart_team_custom_columns");
function tzinteriart_team_custom_columns($column)
{
    global $post;
    switch ($column) {
        case "team-category":
            echo get_the_term_list($post->ID, 'team-category', '', ', ', '');
            break;
        case "team-tags":
            echo get_the_term_list($post->ID, 'team-tags', '', ', ', '');
            break;
    }
}

function get_team_categories(){
    $taxonomy     = 'team-category';
    $orderby      = 'name';
    $show_count   = 0;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = '';
    $empty        = 0;

    $args = array(
        'taxonomy'     => $taxonomy,
        'orderby'      => $orderby,
        'show_count'   => $show_count,
        'pad_counts'   => $pad_counts,
        'hierarchical' => $hierarchical,
        'title_li'     => $title,
        'hide_empty'   => $empty
    );

    $categories = get_categories( $args );

    return $categories;
}

function get_cat_team_ID( $cat_name ) {
    $cat = get_term_by( 'name', $cat_name, 'team-category' );
    if ( $cat )
        return $cat->term_id;
    return 0;
}

function get_category_team_link( $category ) {
    if ( ! is_object( $category ) )
        $category = (int) $category;

    $category = get_term_link( $category, 'team-category' );

    if ( is_wp_error( $category ) )
        return '';

    return $category;
}

