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]
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace MailPoet\API\JSON\ResponseBuilders;
|
|
|
|
use MailPoet\Entities\FormEntity;
|
|
use MailPoet\Models\StatisticsForms;
|
|
|
|
class FormsResponseBuilder {
|
|
const DATE_FORMAT = 'Y-m-d H:i:s';
|
|
|
|
public function build(FormEntity $form) {
|
|
return [
|
|
'id' => (string)$form->getId(), // (string) for BC
|
|
'name' => $form->getName(),
|
|
'status' => $form->getStatus(),
|
|
'body' => $form->getBody(),
|
|
'settings' => $form->getSettings(),
|
|
'styles' => $form->getStyles(),
|
|
'created_at' => $form->getCreatedAt()->format(self::DATE_FORMAT),
|
|
'updated_at' => $form->getUpdatedAt()->format(self::DATE_FORMAT),
|
|
'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;
|
|
}
|
|
}
|