Plugin Directory

source: codepress-admin-columns/trunk/classes/Settings/Column/Post.php @ 2293580

Last change on this file since 2293580 was 2293580, checked in by tschutter, 5 years ago

trunk

File size: 2.0 KB
Line 
1<?php
2
3namespace AC\Settings\Column;
4
5use AC\Settings;
6use AC\View;
7
8class Post extends Settings\Column
9        implements Settings\FormatValue {
10
11        /**
12         * @var string
13         */
14        private $post_property;
15
16        protected function set_name() {
17                $this->name = 'post';
18        }
19
20        protected function define_options() {
21                return [
22                        'post_property_display' => 'title',
23                ];
24        }
25
26        public function get_dependent_settings() {
27                $setting = [];
28
29                switch ( $this->get_post_property_display() ) {
30                        case 'thumbnail' :
31                                $setting[] = new Settings\Column\Image( $this->column );
32                                break;
33                }
34
35                $setting[] = new Settings\Column\PostLink( $this->column );
36
37                return $setting;
38        }
39
40        /**
41         * @param int   $id
42         * @param mixed $original_value
43         *
44         * @return string|int
45         */
46        public function format( $id, $original_value ) {
47
48                switch ( $this->get_post_property_display() ) {
49
50                        case 'author' :
51                                $value = ac_helper()->user->get_display_name( ac_helper()->post->get_raw_field( 'post_author', $id ) );
52
53                                break;
54                        case 'thumbnail' :
55                                $value = get_post_thumbnail_id( $id );
56
57                                break;
58                        case 'title' :
59                                $value = ac_helper()->post->get_title( $id );
60
61                                break;
62                        default :
63                                $value = $id;
64                }
65
66                return $value;
67        }
68
69        public function create_view() {
70                $select = $this->create_element( 'select' )
71                               ->set_attribute( 'data-refresh', 'column' )
72                               ->set_options( $this->get_display_options() );
73
74                $view = new View( [
75                        'label'   => __( 'Display', 'codepress-admin-columns' ),
76                        'setting' => $select,
77                ] );
78
79                return $view;
80        }
81
82        protected function get_display_options() {
83                $options = [
84                        'title'     => __( 'Title' ),
85                        'id'        => __( 'ID' ),
86                        'author'    => __( 'Author' ),
87                        'thumbnail' => _x( 'Featured Image', 'post' ),
88                ];
89
90                asort( $options );
91
92                return $options;
93        }
94
95        /**
96         * @return string
97         */
98        public function get_post_property_display() {
99                return $this->post_property;
100        }
101
102        /**
103         * @param string $post_property
104         *
105         * @return bool
106         */
107        public function set_post_property_display( $post_property ) {
108                $this->post_property = $post_property;
109
110                return true;
111        }
112
113}
Note: See TracBrowser for help on using the repository browser.