folders.class.php
7 years ago
form.class.php
7 years ago
plugin.updates.php
7 years ago
tree.class.php
7 years ago
tree.class.php
82 lines
| 1 | <?php |
| 2 | class WCP_Tree { |
| 3 | public function __construct() { |
| 4 | parent::__construct(); |
| 5 | } |
| 6 | |
| 7 | public function get_full_tree_data($post_type) { |
| 8 | $string = self::get_folder_category_data($post_type, 0, 0); |
| 9 | return $string['string']; |
| 10 | } |
| 11 | |
| 12 | public function get_folder_category_data($post_type, $parent = 0, $parentStatus = 0) { |
| 13 | // echo "<pre>"; print_r($post_type); die; |
| 14 | $terms = get_terms( $post_type, array( |
| 15 | 'hide_empty' => false, |
| 16 | 'parent' => $parent, |
| 17 | 'orderby' => 'meta_value_num', |
| 18 | 'order' => 'ASC', |
| 19 | 'hierarchical' => false, |
| 20 | 'update_count_callback' => '_update_generic_term_count', |
| 21 | 'meta_query' => [[ |
| 22 | 'key' => 'wcp_custom_order', |
| 23 | 'type' => 'NUMERIC', |
| 24 | ]] |
| 25 | )); |
| 26 | $string = ""; |
| 27 | $child = 0; |
| 28 | if(!empty($terms)) { |
| 29 | $child = count($terms); |
| 30 | foreach($terms as $term) { |
| 31 | $status = get_term_meta($term->term_id, "is_active", true); |
| 32 | $return = self::get_folder_category_data($post_type, $term->term_id, $status); |
| 33 | $class = ($status == 1 && $return['child']>0)?"active":""; |
| 34 | $class .= ($return['child'])>0?" has-sub-tree":""; |
| 35 | if($post_type == "attachment") { |
| 36 | $class .= (isset($_GET['term']) && $_GET['term'] == $term->slug)?" active-item active-term":""; |
| 37 | } else { |
| 38 | $class .= (isset($_GET[$post_type]) && $_GET[$post_type] == $term->slug)?" active-item active-term":""; |
| 39 | } |
| 40 | $status = get_term_meta($term->term_id, "is_highlighted", true); |
| 41 | $class .= ($status == 1)?" is-high":""; |
| 42 | $count = ($term->count != 0)?"<span class='total-count'>{$term->count}</span>":""; |
| 43 | $string .= "<li data-slug='{$term->slug}' class='ui-state-default route {$class}' id='wcp_folder_{$term->term_id}' data-folder-id='{$term->term_id}'><h3 class='title' title='{$term->name}' id='title_{$term->term_id}'><span class='title-text'>{$term->name}</span> <span class='update-inline-record'></span> {$count} <span class='star-icon'></span></h3><span class='nav-icon'><i class='wcp-icon folder-icon-arrow_right'></i></span><span class='ui-icon'><i class='wcp-icon folder-icon-folder'></i></span> <ul class='space' id='space_{$term->term_id}'>"; |
| 44 | $string .= $return['string']; |
| 45 | $string .= "</ul></li>"; |
| 46 | } |
| 47 | } |
| 48 | return array( |
| 49 | 'string' =>$string, |
| 50 | 'child' => $child |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | public function get_option_data_for_select($post_type) { |
| 55 | $string = "<option value='0'>Parent Folder</option>"; |
| 56 | $string .= self::get_folder_option_data($post_type, 0, ' '); |
| 57 | return $string; |
| 58 | } |
| 59 | |
| 60 | public function get_folder_option_data($post_type, $parent = 0, $space) { |
| 61 | $terms = get_terms( $post_type, array( |
| 62 | 'hide_empty' => false, |
| 63 | 'parent' => $parent, |
| 64 | 'orderby' => 'meta_value_num', |
| 65 | 'order' => 'ASC', |
| 66 | 'hierarchical' => false, |
| 67 | 'meta_query' => [[ |
| 68 | 'key' => 'wcp_custom_order', |
| 69 | 'type' => 'NUMERIC', |
| 70 | ]] |
| 71 | ) ); |
| 72 | |
| 73 | $string = ""; |
| 74 | if(!empty($terms)) { |
| 75 | foreach($terms as $term) { |
| 76 | $string .= "<option value='{$term->term_id}'>{$space}{$term->name}</option>"; |
| 77 | $string .= self::get_folder_option_data($post_type, $term->term_id, $space."  "); |
| 78 | } |
| 79 | } |
| 80 | return $string; |
| 81 | } |
| 82 | } |