| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Llms_Txt\Application\Available_Posts; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Llms_Txt\Domain\Available_Posts\Data_Provider\Available_Posts_Data; |
| 7 |
use Yoast\WP\SEO\Llms_Txt\Domain\Available_Posts\Data_Provider\Available_Posts_Repository_Interface; |
| 8 |
use Yoast\WP\SEO\Llms_Txt\Domain\Available_Posts\Data_Provider\Data_Container; |
| 9 |
use Yoast\WP\SEO\Llms_Txt\Domain\Available_Posts\Data_Provider\Parameters; |
| 10 |
use Yoast\WP\SEO\Llms_Txt\Infrastructure\Content\Automatic_Post_Collection; |
| 11 |
|
| 12 |
/** |
| 13 |
* The data provider for available posts. |
| 14 |
*/ |
| 15 |
class Available_Posts_Repository implements Available_Posts_Repository_Interface { |
| 16 |
|
| 17 |
/** |
| 18 |
* The automatic post collection. |
| 19 |
* |
| 20 |
* @var Automatic_Post_Collection $automatic_post_collection |
| 21 |
*/ |
| 22 |
private $automatic_post_collection; |
| 23 |
|
| 24 |
/** |
| 25 |
* The constructor. |
| 26 |
* |
| 27 |
* @param Automatic_Post_Collection $automatic_post_collection The automatic post collection. |
| 28 |
*/ |
| 29 |
public function __construct( |
| 30 |
Automatic_Post_Collection $automatic_post_collection |
| 31 |
) { |
| 32 |
$this->automatic_post_collection = $automatic_post_collection; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Gets the available posts' data. |
| 37 |
* |
| 38 |
* @param Parameters $parameters The parameters to use for getting the available posts. |
| 39 |
* |
| 40 |
* @return Data_Container |
| 41 |
*/ |
| 42 |
public function get_posts( Parameters $parameters ): Data_Container { |
| 43 |
$available_posts = $this->automatic_post_collection->get_recent_posts( $parameters->get_post_type(), 100, $parameters->get_search_filter(), true ); |
| 44 |
|
| 45 |
$available_posts_data_container = new Data_Container(); |
| 46 |
|
| 47 |
foreach ( $available_posts as $available_post ) { |
| 48 |
$available_posts_data_container->add_data( new Available_Posts_Data( $available_post ) ); |
| 49 |
} |
| 50 |
|
| 51 |
return $available_posts_data_container; |
| 52 |
} |
| 53 |
} |
| 54 |
|