Show deleted lists in newsletter listings [MAILPOET-489]
This commit is contained in:
@ -310,7 +310,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
|
|
||||||
if($newsletter->type === Newsletter::TYPE_STANDARD) {
|
if($newsletter->type === Newsletter::TYPE_STANDARD) {
|
||||||
$newsletter
|
$newsletter
|
||||||
->withSegments()
|
->withSegments(true)
|
||||||
->withSendingQueue()
|
->withSendingQueue()
|
||||||
->withStatistics();
|
->withStatistics();
|
||||||
} else if($newsletter->type === Newsletter::TYPE_WELCOME) {
|
} else if($newsletter->type === Newsletter::TYPE_WELCOME) {
|
||||||
@ -321,11 +321,11 @@ class Newsletters extends APIEndpoint {
|
|||||||
} else if($newsletter->type === Newsletter::TYPE_NOTIFICATION) {
|
} else if($newsletter->type === Newsletter::TYPE_NOTIFICATION) {
|
||||||
$newsletter
|
$newsletter
|
||||||
->withOptions()
|
->withOptions()
|
||||||
->withSegments()
|
->withSegments(true)
|
||||||
->withChildrenCount();
|
->withChildrenCount();
|
||||||
} else if($newsletter->type === Newsletter::TYPE_NOTIFICATION_HISTORY) {
|
} else if($newsletter->type === Newsletter::TYPE_NOTIFICATION_HISTORY) {
|
||||||
$newsletter
|
$newsletter
|
||||||
->withSegments()
|
->withSegments(true)
|
||||||
->withSendingQueue()
|
->withSendingQueue()
|
||||||
->withStatistics();
|
->withStatistics();
|
||||||
}
|
}
|
||||||
|
@ -182,8 +182,39 @@ class Newsletter extends Model {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function withSegments() {
|
function withSegments($inclDeleted = false) {
|
||||||
$this->segments = $this->segments()->findArray();
|
$this->segments = $this->segments()->findArray();
|
||||||
|
if($inclDeleted) {
|
||||||
|
$this->withDeletedSegments();
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intermediary table only
|
||||||
|
function segmentLinks() {
|
||||||
|
return $this->has_many(
|
||||||
|
__NAMESPACE__.'\NewsletterSegment',
|
||||||
|
'newsletter_id',
|
||||||
|
'id'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withDeletedSegments() {
|
||||||
|
if(!empty($this->segments)) {
|
||||||
|
$segmentIds = Helpers::arrayColumn($this->segments, 'id');
|
||||||
|
$links = $this->segmentLinks()
|
||||||
|
->whereNotIn('segment_id', $segmentIds)->findArray();
|
||||||
|
$deletedSegments = array();
|
||||||
|
|
||||||
|
foreach($links as $link) {
|
||||||
|
$deletedSegments[] = array(
|
||||||
|
'id' => $link['segment_id'],
|
||||||
|
'name' => __('Deleted list', 'mailpoet')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->segments = array_merge($this->segments, $deletedSegments);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +106,17 @@ class NewsletterTest extends MailPoetTest {
|
|||||||
expect($newsletter_segments[1]['name'])->equals('Segment 2');
|
expect($newsletter_segments[1]['name'])->equals('Segment 2');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCanHaveDeletedSegments() {
|
||||||
|
$this->segment_2->delete();
|
||||||
|
$this->newsletter->withSegments(true);
|
||||||
|
$newsletter_segments = $this->newsletter->segments;
|
||||||
|
expect($newsletter_segments)->count(2);
|
||||||
|
expect($newsletter_segments[0]['id'])->equals($this->segment_1->id);
|
||||||
|
expect($newsletter_segments[0]['name'])->equals('Segment 1');
|
||||||
|
expect($newsletter_segments[1]['id'])->equals($this->segment_2->id);
|
||||||
|
expect($newsletter_segments[1]['name'])->contains('Deleted');
|
||||||
|
}
|
||||||
|
|
||||||
function testItCanHaveStatistics() {
|
function testItCanHaveStatistics() {
|
||||||
$newsletter = $this->newsletter;
|
$newsletter = $this->newsletter;
|
||||||
$sending_queue = SendingQueue::create();
|
$sending_queue = SendingQueue::create();
|
||||||
|
Reference in New Issue
Block a user