Admin
7 years ago
Ajax
7 years ago
Autoloader
7 years ago
Check
7 years ago
Column
7 years ago
Deprecated
7 years ago
Exception
7 years ago
Form
7 years ago
Helper
7 years ago
Integration
7 years ago
ListScreen
7 years ago
Message
7 years ago
Meta
7 years ago
Plugin
7 years ago
Preferences
7 years ago
Relation
7 years ago
Request
7 years ago
Response
7 years ago
Screen
7 years ago
Settings
7 years ago
Storage
7 years ago
Table
7 years ago
ThirdParty
7 years ago
Transient
7 years ago
API.php
7 years ago
Addon.php
7 years ago
Admin.php
7 years ago
AdminColumns.php
7 years ago
ArrayIterator.php
7 years ago
Autoloader.php
7 years ago
Builder.php
7 years ago
Capabilities.php
7 years ago
Collection.php
7 years ago
Column.php
7 years ago
Config.php
7 years ago
Dependencies.php
7 years ago
Expirable.php
7 years ago
Groups.php
7 years ago
Helper.php
7 years ago
Integration.php
7 years ago
IntegrationFactory.php
7 years ago
Integrations.php
7 years ago
ListScreen.php
7 years ago
ListScreenFactory.php
7 years ago
ListScreenGroups.php
7 years ago
ListScreenPost.php
7 years ago
ListScreenWP.php
7 years ago
Message.php
7 years ago
MetaType.php
7 years ago
Middleware.php
7 years ago
Plugin.php
7 years ago
PluginInformation.php
7 years ago
Preferences.php
7 years ago
Registrable.php
7 years ago
Relation.php
7 years ago
Request.php
7 years ago
Screen.php
7 years ago
ScreenController.php
7 years ago
Settings.php
7 years ago
Transient.php
7 years ago
TypedArrayIterator.php
7 years ago
View.php
7 years ago
ScreenController.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC; |
| 4 | |
| 5 | class ScreenController { |
| 6 | |
| 7 | /** @var ListScreen */ |
| 8 | private $list_screen; |
| 9 | |
| 10 | /** @var array */ |
| 11 | private $headings = array(); |
| 12 | |
| 13 | /** |
| 14 | * @param ListScreen $list_screen |
| 15 | */ |
| 16 | public function __construct( ListScreen $list_screen ) { |
| 17 | $this->list_screen = $list_screen; |
| 18 | |
| 19 | // Headings |
| 20 | add_filter( $this->list_screen->get_heading_hookname(), array( $this, 'add_headings' ), 200 ); |
| 21 | |
| 22 | // Values |
| 23 | $this->list_screen->set_manage_value_callback(); |
| 24 | |
| 25 | do_action( 'ac/table/list_screen', $this->list_screen ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @since 2.0 |
| 30 | * |
| 31 | * @param $columns |
| 32 | * |
| 33 | * @return array |
| 34 | */ |
| 35 | public function add_headings( $columns ) { |
| 36 | if ( empty( $columns ) ) { |
| 37 | return $columns; |
| 38 | } |
| 39 | |
| 40 | // Store default headings |
| 41 | if ( ! AC()->is_doing_ajax() ) { |
| 42 | $this->list_screen->save_default_headings( $columns ); |
| 43 | } |
| 44 | |
| 45 | // Run once |
| 46 | if ( $this->headings ) { |
| 47 | return $this->headings; |
| 48 | } |
| 49 | |
| 50 | // Nothing stored. Show default columns on screen. |
| 51 | if ( ! $this->list_screen->get_settings() ) { |
| 52 | return $columns; |
| 53 | } |
| 54 | |
| 55 | // Add mandatory checkbox |
| 56 | if ( isset( $columns['cb'] ) ) { |
| 57 | $this->headings['cb'] = $columns['cb']; |
| 58 | } |
| 59 | |
| 60 | // On first visit 'columns' can be empty, because they were put in memory before 'default headings' |
| 61 | // were stored. We force get_columns() to be re-populated. |
| 62 | if ( ! $this->list_screen->get_columns() ) { |
| 63 | $this->list_screen->reset(); |
| 64 | $this->list_screen->reset_original_columns(); |
| 65 | } |
| 66 | |
| 67 | foreach ( $this->list_screen->get_columns() as $column ) { |
| 68 | $this->headings[ $column->get_name() ] = $column->get_custom_label(); |
| 69 | } |
| 70 | |
| 71 | return apply_filters( 'ac/headings', $this->headings, $this->list_screen ); |
| 72 | } |
| 73 | |
| 74 | } |