Move dynamic segments from Premium plugin
[MAILPOET-2382]
This commit is contained in:
committed by
Jack Kitterhing
parent
0af9f09f50
commit
70a89b7939
35
lib/DynamicSegments/Persistence/Loading/Loader.php
Normal file
35
lib/DynamicSegments/Persistence/Loading/Loader.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Premium\DynamicSegments\Persistence\Loading;
|
||||
|
||||
use MailPoet\Premium\DynamicSegments\Mappers\DBMapper;
|
||||
use MailPoet\Premium\Models\DynamicSegment;
|
||||
use MailPoet\Premium\Models\DynamicSegmentFilter;
|
||||
|
||||
class Loader {
|
||||
|
||||
/** @var DBMapper */
|
||||
private $mapper;
|
||||
|
||||
public function __construct(DBMapper $mapper) {
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DynamicSegment[]
|
||||
*/
|
||||
function load() {
|
||||
$segments = DynamicSegment::findAll();
|
||||
return $this->loadFilters($segments);
|
||||
}
|
||||
|
||||
private function loadFilters(array $segments) {
|
||||
$ids = array_map(function($segment) {
|
||||
return $segment->id;
|
||||
}, $segments);
|
||||
$filters = DynamicSegmentFilter::getAllBySegmentIds($ids);
|
||||
|
||||
return $this->mapper->mapSegments($segments, $filters);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user