Rewrite Forms::listing() API to use Doctrine
This commit replaces the usage of Paris with Doctrine inside MailPoet\API\JSON\v1\Forms::listing(). It also introduces a new class MailPoet\Form\Listing\FormListingRepository that is used by listing() to prepare the query that is executed by Doctrine and a new MailPoet\API\JSON\ResponseBuilders\FormsResponseBuilder::buildForListing() method to prepare the response that is returned by listing(). A few tests were adjusted and new tests were added for the new class. [MAILPOET-3036]
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace MailPoet\API\JSON\ResponseBuilders;
|
||||
|
||||
use MailPoet\Entities\FormEntity;
|
||||
use MailPoet\Models\StatisticsForms;
|
||||
|
||||
class FormsResponseBuilder {
|
||||
const DATE_FORMAT = 'Y-m-d H:i:s';
|
||||
@ -20,4 +21,22 @@ class FormsResponseBuilder {
|
||||
'deleted_at' => ($deletedAt = $form->getDeletedAt()) ? $deletedAt->format(self::DATE_FORMAT) : null,
|
||||
];
|
||||
}
|
||||
|
||||
public function buildForListing(array $forms) {
|
||||
$data = [];
|
||||
|
||||
foreach ($forms as $form) {
|
||||
$form = $this->build($form);
|
||||
$form['signups'] = StatisticsForms::getTotalSignups($form['id']);
|
||||
$form['segments'] = (
|
||||
!empty($form['settings']['segments'])
|
||||
? $form['settings']['segments']
|
||||
: []
|
||||
);
|
||||
|
||||
$data[] = $form;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user