Acf
1 month ago
Admin
1 month ago
Ajax
1 month ago
ApplyFilter
1 month ago
Asset
1 month ago
Capabilities
1 month ago
Check
1 month ago
Collection
1 month ago
Column
1 month ago
ColumnFactories
1 month ago
ColumnFactory
1 month ago
ColumnIterator
1 month ago
ColumnRepository
1 month ago
ColumnSize
1 month ago
DI
1 month ago
Deprecated
1 month ago
Entity
1 month ago
Exception
1 month ago
Expression
1 month ago
Form
1 month ago
Formatter
1 month ago
Helper
1 month ago
Integration
1 month ago
ListScreenRepository
1 month ago
ListTable
1 month ago
Message
1 month ago
Meta
1 month ago
Nonce
1 month ago
Notice
1 month ago
Plugin
1 month ago
Preferences
1 month ago
Promo
1 month ago
Request
1 month ago
RequestHandler
1 month ago
Response
1 month ago
Sanitize
1 month ago
Service
1 month ago
Setting
1 month ago
Settings
1 month ago
Storage
1 month ago
Table
1 month ago
TableIdsFactory
1 month ago
TableScreen
1 month ago
TableScreenFactory
1 month ago
ThirdParty
1 month ago
Type
1 month ago
Value
1 month ago
View
1 month ago
Acf.php
1 month ago
AdminColumns.php
1 month ago
ArrayIterator.php
1 month ago
Capabilities.php
1 month ago
Collection.php
1 month ago
CollectionFormatter.php
1 month ago
Column.php
1 month ago
ColumnCollection.php
1 month ago
ColumnFactoryCollectionFactory.php
1 month ago
ColumnFactoryDefinitionCollection.php
1 month ago
ColumnGroups.php
1 month ago
ColumnIterator.php
1 month ago
ColumnNamesTrait.php
1 month ago
ColumnRepository.php
1 month ago
ColumnTypeRepository.php
1 month ago
Config.php
1 month ago
Container.php
1 month ago
DateFormats.php
1 month ago
Expirable.php
1 month ago
Formatter.php
1 month ago
FormatterCollection.php
1 month ago
Helper.php
1 month ago
ListScreen.php
1 month ago
ListScreenCollection.php
1 month ago
ListScreenRepository.php
1 month ago
ListScreenRepositoryWritable.php
1 month ago
ListTable.php
1 month ago
ListTableFactory.php
1 month ago
Loader.php
1 month ago
Message.php
1 month ago
MetaType.php
1 month ago
Middleware.php
1 month ago
OpCacheInvalidateTrait.php
1 month ago
PluginActionLinks.php
1 month ago
PluginActionUpgrade.php
1 month ago
PostType.php
1 month ago
PostTypeRepository.php
1 month ago
Registerable.php
1 month ago
Registry.php
1 month ago
Renderable.php
1 month ago
Request.php
1 month ago
RequestAjaxHandler.php
1 month ago
RequestAjaxHandlers.php
1 month ago
RequestAjaxParser.php
1 month ago
RequestHandler.php
1 month ago
RequestHandlerFactory.php
1 month ago
Screen.php
1 month ago
Services.php
1 month ago
TableIdsFactory.php
1 month ago
TableScreen.php
1 month ago
TableScreenFactory.php
1 month ago
Taxonomy.php
1 month ago
Transient.php
1 month ago
TypedArrayIterator.php
1 month ago
View.php
1 month ago
WooCommerce.php
1 month ago
WpListTableFactory.php
1 month ago
ColumnTypeRepository.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC; |
| 6 | |
| 7 | use AC\Collection\ColumnFactories; |
| 8 | use AC\Column\ColumnFactory; |
| 9 | use AC\ColumnFactories\Aggregate; |
| 10 | use AC\Storage\Repository\OriginalColumnsRepository; |
| 11 | use AC\Type\TableId; |
| 12 | |
| 13 | class ColumnTypeRepository |
| 14 | { |
| 15 | |
| 16 | private Aggregate $aggregate; |
| 17 | |
| 18 | private OriginalColumnsRepository $original_columns_repository; |
| 19 | |
| 20 | public function __construct(Aggregate $aggregate, OriginalColumnsRepository $original_columns_repository) |
| 21 | { |
| 22 | $this->aggregate = $aggregate; |
| 23 | $this->original_columns_repository = $original_columns_repository; |
| 24 | } |
| 25 | |
| 26 | private function find_column_factory(ColumnFactories $factories, string $type): ?ColumnFactory |
| 27 | { |
| 28 | foreach ($factories as $column_factory) { |
| 29 | if ($type === $column_factory->get_column_type()) { |
| 30 | return $column_factory; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return null; |
| 35 | } |
| 36 | |
| 37 | public function find(TableScreen $table_screen, string $type): ?Column |
| 38 | { |
| 39 | $factory = $this->find_column_factory($this->aggregate->create($table_screen), $type); |
| 40 | |
| 41 | if ( ! $factory) { |
| 42 | return null; |
| 43 | } |
| 44 | |
| 45 | return $factory->create( |
| 46 | new Setting\Config([ |
| 47 | 'label' => $factory->get_label(), |
| 48 | ]) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | public function find_all(TableScreen $table_screen): ColumnCollection |
| 53 | { |
| 54 | $columns = new ColumnCollection(); |
| 55 | |
| 56 | foreach ($this->aggregate->create($table_screen) as $factory) { |
| 57 | $columns->add($factory->create(new Setting\Config())); |
| 58 | } |
| 59 | |
| 60 | return $columns; |
| 61 | } |
| 62 | |
| 63 | private function get_originals(TableId $id): array |
| 64 | { |
| 65 | $column_names = []; |
| 66 | |
| 67 | foreach ($this->original_columns_repository->find_all_cached($id) as $column) { |
| 68 | $column_names[$column->get_name()] = $column->get_label(); |
| 69 | } |
| 70 | |
| 71 | return $column_names; |
| 72 | } |
| 73 | |
| 74 | public function find_all_by_original(TableScreen $table_screen): ColumnCollection |
| 75 | { |
| 76 | $columns = new ColumnCollection(); |
| 77 | |
| 78 | $originals = $this->get_originals($table_screen->get_id()); |
| 79 | |
| 80 | foreach ($this->aggregate->create($table_screen) as $factory) { |
| 81 | $type = $factory->get_column_type(); |
| 82 | $label = $originals[$type] ?? null; |
| 83 | |
| 84 | if (null === $label) { |
| 85 | continue; |
| 86 | } |
| 87 | |
| 88 | $columns->add( |
| 89 | $factory->create( |
| 90 | new Setting\Config([ |
| 91 | 'name' => $type, |
| 92 | 'label' => (string)$label, |
| 93 | ]) |
| 94 | ) |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | return $columns; |
| 99 | } |
| 100 | |
| 101 | } |