| @@ -1,74 +1,74 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace FL\Assistant\Hooks; | |
| 4 | - | |
| 5 | -use FL\Assistant\Data\Transformers\NotationsTransformer; | |
| 6 | -use FL\Assistant\Data\Repository\NotationsRepository; | |
| 7 | -use FL\Assistant\Data\Repository\LabelsRepository; | |
| 8 | -use FL\Assistant\Data\Transformers\LabelsTransformer; | |
| 9 | -use FL\Assistant\Helpers\BeaverBuilderHelper; | |
| 10 | - | |
| 11 | -class AdminColumns { | |
| 12 | - | |
| 13 | - public function __construct() { | |
| 14 | - if ( BeaverBuilderHelper::is_assistant_extension() ) { | |
| 15 | - return; | |
| 16 | - } | |
| 17 | - | |
| 18 | - add_action( 'init', [ $this, 'enqueue_custom_admin_columns' ], PHP_INT_MAX ); | |
| 19 | - } | |
| 20 | - | |
| 21 | - public function enqueue_custom_admin_columns() { | |
| 22 | - $types = get_post_types( [ 'public' => true ], 'objects' ); | |
| 23 | - | |
| 24 | - foreach ( $types as $type => $info ) { | |
| 25 | - add_filter( "manage_{$type}_posts_columns", [ $this, 'add_columns' ] ); | |
| 26 | - add_action( "manage_{$type}_posts_custom_column", [ $this, 'render_column' ], 10, 2 ); | |
| 27 | - add_filter( "default_hidden_columns", [ $this, 'defualt_hidden_columns' ], 10, 2 ); | |
| 28 | - } | |
| 29 | - } | |
| 30 | - | |
| 31 | - public function add_columns( $columns ) { | |
| 32 | - $columns['fl_assistant'] = __( 'Labels', 'assistant' ); | |
| 33 | - return $columns; | |
| 34 | - } | |
| 35 | - | |
| 36 | - public function render_column( $column, $post_id ) { | |
| 37 | - $vars = '--fl-asst-red: #FF5335; --fl-asst-blue: #1BADF8; --fl-asst-green: #00D281; --fl-asst-yellow: #FFD000; --fl-asst-orange: #FF9500; --fl-asst-purple: #CC73E1; --fl-asst-pink: #FF2968;'; | |
| 38 | - $styles = "{$vars} padding: 2px 5px; display: inline-flex; flex: 0 0 auto; border-radius: 3px; border: 1px solid #d2d2d2; align-items: center; color: black; background: white; margin: 2px 5px 3px; margin-left:0; font-size: 12px;"; | |
| 39 | - $dot = 'width: 10px; height: 10px; flex: 0 0 10px; border-radius: 7px; background: blue; margin-right: 5px;'; | |
| 40 | - | |
| 41 | - if ( 'fl_assistant' === $column ) { | |
| 42 | - $transformer = new NotationsTransformer; | |
| 43 | - $repository = new NotationsRepository( $transformer ); | |
| 44 | - $labels = $repository->get_labels( 'post', $post_id ); | |
| 45 | - | |
| 46 | - $labels_repo = new LabelsRepository; | |
| 47 | - $labels_transformer = new LabelsTransformer( $labels_repo ); | |
| 48 | - $terms = $labels_repo->query( [ 'hide_empty' => false ] )->get_terms(); | |
| 49 | - | |
| 50 | - // Assemble term meta dataset | |
| 51 | - $term_meta = []; | |
| 52 | - foreach ( $terms as $key => $term ) { | |
| 53 | - $item = call_user_func( $labels_transformer, $term ); | |
| 54 | - $term_meta[ $item['id'] ] = $item; | |
| 55 | - } | |
| 56 | - | |
| 57 | - // Output labels | |
| 58 | - foreach ( $labels as $label ) { | |
| 59 | - $term = $term_meta[ $label['label_id'] ]; | |
| 60 | - if ( isset( $term ) ) { | |
| 61 | - print "<span style='{$styles}'><span style='{$dot}; background-color: {$term['color']}'></span>{$term['label']}</span>"; | |
| 62 | - } | |
| 63 | - } | |
| 64 | - } | |
| 65 | - } | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * Make our custom column hidden by default. | |
| 69 | - */ | |
| 70 | - public function defualt_hidden_columns( $hidden, $screen ) { | |
| 71 | - $hidden[] = 'fl_assistant'; | |
| 72 | - return $hidden; | |
| 73 | - } | |
| 74 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace FL\Assistant\Hooks; | |
| 4 | + | |
| 5 | +use FL\Assistant\Data\Transformers\NotationsTransformer; | |
| 6 | +use FL\Assistant\Data\Repository\NotationsRepository; | |
| 7 | +use FL\Assistant\Data\Repository\LabelsRepository; | |
| 8 | +use FL\Assistant\Data\Transformers\LabelsTransformer; | |
| 9 | +use FL\Assistant\Helpers\BeaverBuilderHelper; | |
| 10 | + | |
| 11 | +class AdminColumns { | |
| 12 | + | |
| 13 | + public function __construct() { | |
| 14 | + if ( BeaverBuilderHelper::is_assistant_extension() ) { | |
| 15 | + return; | |
| 16 | + } | |
| 17 | + | |
| 18 | + add_action( 'init', [ $this, 'enqueue_custom_admin_columns' ], PHP_INT_MAX ); | |
| 19 | + } | |
| 20 | + | |
| 21 | + public function enqueue_custom_admin_columns() { | |
| 22 | + $types = get_post_types( [ 'public' => true ], 'objects' ); | |
| 23 | + | |
| 24 | + foreach ( $types as $type => $info ) { | |
| 25 | + add_filter( "manage_{$type}_posts_columns", [ $this, 'add_columns' ] ); | |
| 26 | + add_action( "manage_{$type}_posts_custom_column", [ $this, 'render_column' ], 10, 2 ); | |
| 27 | + add_filter( "default_hidden_columns", [ $this, 'defualt_hidden_columns' ], 10, 2 ); | |
| 28 | + } | |
| 29 | + } | |
| 30 | + | |
| 31 | + public function add_columns( $columns ) { | |
| 32 | + $columns['fl_assistant'] = __( 'Labels', 'assistant' ); | |
| 33 | + return $columns; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function render_column( $column, $post_id ) { | |
| 37 | + $vars = '--fl-asst-red: #FF5335; --fl-asst-blue: #1BADF8; --fl-asst-green: #00D281; --fl-asst-yellow: #FFD000; --fl-asst-orange: #FF9500; --fl-asst-purple: #CC73E1; --fl-asst-pink: #FF2968;'; | |
| 38 | + $styles = "{$vars} padding: 2px 5px; display: inline-flex; flex: 0 0 auto; border-radius: 3px; border: 1px solid #d2d2d2; align-items: center; color: black; background: white; margin: 2px 5px 3px; margin-left:0; font-size: 12px;"; | |
| 39 | + $dot = 'width: 10px; height: 10px; flex: 0 0 10px; border-radius: 7px; background: blue; margin-right: 5px;'; | |
| 40 | + | |
| 41 | + if ( 'fl_assistant' === $column ) { | |
| 42 | + $transformer = new NotationsTransformer; | |
| 43 | + $repository = new NotationsRepository( $transformer ); | |
| 44 | + $labels = $repository->get_labels( 'post', $post_id ); | |
| 45 | + | |
| 46 | + $labels_repo = new LabelsRepository; | |
| 47 | + $labels_transformer = new LabelsTransformer( $labels_repo ); | |
| 48 | + $terms = $labels_repo->query( [ 'hide_empty' => false ] )->get_terms(); | |
| 49 | + | |
| 50 | + // Assemble term meta dataset | |
| 51 | + $term_meta = []; | |
| 52 | + foreach ( $terms as $key => $term ) { | |
| 53 | + $item = call_user_func( $labels_transformer, $term ); | |
| 54 | + $term_meta[ $item['id'] ] = $item; | |
| 55 | + } | |
| 56 | + | |
| 57 | + // Output labels | |
| 58 | + foreach ( $labels as $label ) { | |
| 59 | + $term = $term_meta[ $label['label_id'] ]; | |
| 60 | + if ( isset( $term ) ) { | |
| 61 | + print "<span style='{$styles}'><span style='{$dot}; background-color: {$term['color']}'></span>{$term['label']}</span>"; | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Make our custom column hidden by default. | |
| 69 | + */ | |
| 70 | + public function defualt_hidden_columns( $hidden, $screen ) { | |
| 71 | + $hidden[] = 'fl_assistant'; | |
| 72 | + return $hidden; | |
| 73 | + } | |
| 74 | +} | |