Move dynamic segments from Premium plugin
[MAILPOET-2382]
This commit is contained in:
committed by
Jack Kitterhing
parent
0af9f09f50
commit
70a89b7939
55
lib/Models/DynamicSegmentFilter.php
Normal file
55
lib/Models/DynamicSegmentFilter.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Premium\Models;
|
||||
|
||||
use MailPoet\Models\Model;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
/**
|
||||
* @property array|string|null $filter_data
|
||||
* @property string $segment_id
|
||||
*/
|
||||
class DynamicSegmentFilter extends Model {
|
||||
|
||||
public static $_table = MP_DYNAMIC_SEGMENTS_FILTERS_TABLE;
|
||||
|
||||
function save() {
|
||||
if (is_null($this->filter_data)) {
|
||||
$this->filter_data = [];
|
||||
}
|
||||
|
||||
if (!WPFunctions::get()->isSerialized($this->filter_data)) {
|
||||
$this->filter_data = serialize($this->filter_data);
|
||||
}
|
||||
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
static function getAllBySegmentIds($segmentIds) {
|
||||
if (empty($segmentIds)) return [];
|
||||
$query = self::tableAlias('filters')
|
||||
->whereIn('filters.segment_id', $segmentIds);
|
||||
|
||||
$query->findMany();
|
||||
return $query->findMany();
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
$value = parent::__get($name);
|
||||
if ($name === 'filter_data' && WPFunctions::get()->isSerialized($value)) {
|
||||
return unserialize($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function deleteAllBySegmentIds($segmentIds) {
|
||||
if (empty($segmentIds)) return;
|
||||
|
||||
$query = self::tableAlias('filters')
|
||||
->whereIn('segment_id', $segmentIds);
|
||||
|
||||
$query->deleteMany();
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user