AdminBar.php
1 month ago
AdminBarEditColumns.php
1 month ago
Colors.php
1 month ago
CommonAssets.php
1 month ago
CurrentTable.php
1 month ago
ManageHeadings.php
1 month ago
ManageValue.php
1 month ago
NoticeChecks.php
1 month ago
PluginUpdate.php
1 month ago
PromoChecks.php
1 month ago
QuickEdit.php
1 month ago
SaveHeadings.php
1 month ago
Setup.php
1 month ago
TableRows.php
1 month ago
Tooltips.php
1 month ago
View.php
1 month ago
CurrentTable.php
114 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Service; |
| 4 | |
| 5 | use AC\AdminColumns; |
| 6 | use AC\ListScreen; |
| 7 | use AC\ListScreenRepository\Storage; |
| 8 | use AC\Registerable; |
| 9 | use AC\Request; |
| 10 | use AC\Settings\GeneralOption; |
| 11 | use AC\Table; |
| 12 | use AC\TableScreenFactory; |
| 13 | use WP_Screen; |
| 14 | |
| 15 | class CurrentTable implements Registerable |
| 16 | { |
| 17 | |
| 18 | private Storage $storage; |
| 19 | |
| 20 | private Table\TablePreference $preference; |
| 21 | |
| 22 | private Table\PrimaryColumnFactory $primary_column_factory; |
| 23 | |
| 24 | private TableScreenFactory $table_screen_factory; |
| 25 | |
| 26 | private Table\InlineStyle\ColumnSize $column_size; |
| 27 | |
| 28 | private AdminColumns $plugin; |
| 29 | |
| 30 | private GeneralOption $option_storage; |
| 31 | |
| 32 | public function __construct( |
| 33 | Storage $storage, |
| 34 | AdminColumns $plugin, |
| 35 | TableScreenFactory $table_screen_factory, |
| 36 | Table\TablePreference $preference, |
| 37 | Table\PrimaryColumnFactory $primary_column_factory, |
| 38 | Table\InlineStyle\ColumnSize $column_size, |
| 39 | GeneralOption $option_storage |
| 40 | ) { |
| 41 | $this->storage = $storage; |
| 42 | $this->preference = $preference; |
| 43 | $this->primary_column_factory = $primary_column_factory; |
| 44 | $this->table_screen_factory = $table_screen_factory; |
| 45 | $this->column_size = $column_size; |
| 46 | $this->plugin = $plugin; |
| 47 | $this->option_storage = $option_storage; |
| 48 | } |
| 49 | |
| 50 | public function register(): void |
| 51 | { |
| 52 | add_action('current_screen', [$this, 'handle']); |
| 53 | } |
| 54 | |
| 55 | public function handle(WP_Screen $wp_screen): void |
| 56 | { |
| 57 | $user = wp_get_current_user(); |
| 58 | |
| 59 | if ( ! $user) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if ( ! $this->table_screen_factory->can_create_from_wp_screen($wp_screen)) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | $table_screen = $this->table_screen_factory->create_from_wp_screen($wp_screen); |
| 68 | |
| 69 | $request = new Request(); |
| 70 | |
| 71 | $request->add_middleware( |
| 72 | new Request\Middleware\ListScreenTable( |
| 73 | $this->storage, |
| 74 | $table_screen->get_id(), |
| 75 | $this->preference, |
| 76 | $user |
| 77 | ) |
| 78 | ); |
| 79 | |
| 80 | do_action('ac/table/request', $request, $table_screen); |
| 81 | |
| 82 | $list_screen = $request->get('list_screen'); |
| 83 | |
| 84 | do_action('ac/table/screen', $table_screen, $list_screen); |
| 85 | |
| 86 | if ($list_screen instanceof ListScreen) { |
| 87 | $this->preference->save( |
| 88 | $table_screen->get_id(), |
| 89 | $list_screen->get_id() |
| 90 | ); |
| 91 | |
| 92 | $list = new Table\Service\ListScreen( |
| 93 | $list_screen, |
| 94 | $this->primary_column_factory, |
| 95 | $this->column_size |
| 96 | ); |
| 97 | $list->register(); |
| 98 | |
| 99 | do_action('ac/table/list_screen', $list_screen, $table_screen); |
| 100 | } |
| 101 | |
| 102 | $table = new Table\Screen( |
| 103 | $this->plugin, |
| 104 | $table_screen, |
| 105 | $this->option_storage, |
| 106 | $list_screen |
| 107 | ); |
| 108 | |
| 109 | do_action('ac/table', $table); |
| 110 | |
| 111 | $table->register(); |
| 112 | } |
| 113 | |
| 114 | } |