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:
Rodrigo Primo
2021-03-20 13:54:11 -03:00
committed by Veljko V
parent 298b8730fe
commit a18ae06f8a
6 changed files with 270 additions and 39 deletions

View File

@ -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;
}
}