listing modifications + added description to segments
This commit is contained in:
@@ -14,6 +14,13 @@ class Segment extends Model {
|
||||
));
|
||||
}
|
||||
|
||||
function delete() {
|
||||
// delete all relations to subscribers
|
||||
SubscriberSegment::where('segment_id', $this->id)->deleteMany();
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
function subscribers() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__.'\Subscriber',
|
||||
@@ -41,12 +48,22 @@ class Segment extends Model {
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Segment::count()
|
||||
'count' => Segment::whereNull('deleted_at')->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'trash',
|
||||
'label' => __('Trash'),
|
||||
'count' => Segment::whereNotNull('deleted_at')->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static function group($orm, $group = null) {
|
||||
static function groupBy($orm, $group = null) {
|
||||
if($group === 'trash') {
|
||||
return $orm->whereNotNull('deleted_at');
|
||||
} else {
|
||||
$orm = $orm->whereNull('deleted_at');
|
||||
}
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = array()) {
|
||||
@@ -77,7 +94,45 @@ class Segment extends Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function trash($listing) {
|
||||
return $listing->getSelection()->deleteMany();
|
||||
static function trash($listing, $data = array()) {
|
||||
$confirm_delete = filter_var($data['confirm'], FILTER_VALIDATE_BOOLEAN);
|
||||
if($confirm_delete) {
|
||||
// delete relations with all segments
|
||||
$segments = $listing->getSelection()->findResultSet();
|
||||
|
||||
if(!empty($segments)) {
|
||||
$segments_count = 0;
|
||||
foreach($segments as $segment) {
|
||||
if($segment->delete()) {
|
||||
$segments_count++;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'segments' => $segments_count
|
||||
);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
// soft delete
|
||||
$segments = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NOW()')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'segments' => $segments->count()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static function restore($listing, $data = array()) {
|
||||
$segments = $listing->getSelection()
|
||||
->findResultSet()
|
||||
->set_expr('deleted_at', 'NULL')
|
||||
->save();
|
||||
|
||||
return array(
|
||||
'segments' => $segments->count()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user