Add public keyword to methods
[MAILPOET-2413]
This commit is contained in:
@ -19,7 +19,7 @@ class CustomField extends Model {
|
||||
const TYPE_CHECKBOX = 'checkbox';
|
||||
const TYPE_SELECT = 'select';
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->addValidations('name', [
|
||||
'required' => WPFunctions::get()->__('Please specify a name.', 'mailpoet'),
|
||||
@ -29,7 +29,7 @@ class CustomField extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
public function asArray() {
|
||||
$model = parent::asArray();
|
||||
|
||||
if (isset($model['params'])) {
|
||||
@ -40,7 +40,7 @@ class CustomField extends Model {
|
||||
return $model;
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
if (is_null($this->params)) {
|
||||
$this->params = [];
|
||||
}
|
||||
@ -52,7 +52,7 @@ class CustomField extends Model {
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
function formatValue($value = null) {
|
||||
public function formatValue($value = null) {
|
||||
// format custom field data depending on type
|
||||
if (is_array($value) && $this->type === self::TYPE_DATE) {
|
||||
$custom_field_data = $this->asArray();
|
||||
@ -122,7 +122,7 @@ class CustomField extends Model {
|
||||
return $value;
|
||||
}
|
||||
|
||||
function subscribers() {
|
||||
public function subscribers() {
|
||||
return $this->hasManyThrough(
|
||||
__NAMESPACE__ . '\Subscriber',
|
||||
__NAMESPACE__ . '\SubscriberCustomField',
|
||||
@ -131,7 +131,7 @@ class CustomField extends Model {
|
||||
)->selectExpr(MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value');
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
public static function createOrUpdate($data = []) {
|
||||
// set name as label by default
|
||||
if (empty($data['params']['label']) && isset($data['name'])) {
|
||||
$data['params']['label'] = $data['name'];
|
||||
|
@ -34,23 +34,23 @@ class DynamicSegment extends MailPoetSegment {
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
$this->set('type', DynamicSegment::TYPE_DYNAMIC);
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
function dynamicSegmentFilters() {
|
||||
public function dynamicSegmentFilters() {
|
||||
return $this->has_many(__NAMESPACE__ . '\DynamicSegmentFilter', 'segment_id');
|
||||
}
|
||||
|
||||
static function findAll() {
|
||||
public static function findAll() {
|
||||
$query = self::select('*');
|
||||
return $query->where('type', DynamicSegment::TYPE_DYNAMIC)
|
||||
->whereNull('deleted_at')
|
||||
->findMany();
|
||||
}
|
||||
|
||||
static function listingQuery(array $data = []) {
|
||||
public static function listingQuery(array $data = []) {
|
||||
$query = self::select('*');
|
||||
$query->where('type', DynamicSegment::TYPE_DYNAMIC);
|
||||
if (isset($data['group'])) {
|
||||
@ -62,7 +62,7 @@ class DynamicSegment extends MailPoetSegment {
|
||||
return $query;
|
||||
}
|
||||
|
||||
static function groups() {
|
||||
public static function groups() {
|
||||
return [
|
||||
[
|
||||
'name' => 'all',
|
||||
@ -77,12 +77,12 @@ class DynamicSegment extends MailPoetSegment {
|
||||
];
|
||||
}
|
||||
|
||||
function delete() {
|
||||
public function delete() {
|
||||
DynamicSegmentFilter::where('segment_id', $this->id)->deleteMany();
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
static function bulkTrash($orm) {
|
||||
public static function bulkTrash($orm) {
|
||||
$count = parent::bulkAction($orm, function($ids) {
|
||||
$placeholders = join(',', array_fill(0, count($ids), '?'));
|
||||
DynamicSegment::rawExecute(join(' ', [
|
||||
@ -95,7 +95,7 @@ class DynamicSegment extends MailPoetSegment {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
static function bulkDelete($orm) {
|
||||
public static function bulkDelete($orm) {
|
||||
$count = parent::bulkAction($orm, function($ids) {
|
||||
$placeholders = join(',', array_fill(0, count($ids), '?'));
|
||||
DynamicSegmentFilter::rawExecute(join(' ', [
|
||||
|
@ -13,7 +13,7 @@ class DynamicSegmentFilter extends Model {
|
||||
|
||||
public static $_table = MP_DYNAMIC_SEGMENTS_FILTERS_TABLE;
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
if (is_null($this->filter_data)) {
|
||||
$this->filter_data = [];
|
||||
}
|
||||
@ -25,7 +25,7 @@ class DynamicSegmentFilter extends Model {
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
static function getAllBySegmentIds($segmentIds) {
|
||||
public static function getAllBySegmentIds($segmentIds) {
|
||||
if (empty($segmentIds)) return [];
|
||||
$query = self::tableAlias('filters')
|
||||
->whereIn('filters.segment_id', $segmentIds);
|
||||
@ -42,7 +42,7 @@ class DynamicSegmentFilter extends Model {
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function deleteAllBySegmentIds($segmentIds) {
|
||||
public static function deleteAllBySegmentIds($segmentIds) {
|
||||
if (empty($segmentIds)) return;
|
||||
|
||||
$query = self::tableAlias('filters')
|
||||
|
@ -14,15 +14,15 @@ use MailPoet\WP\Functions as WPFunctions;
|
||||
class Form extends Model {
|
||||
public static $_table = MP_FORMS_TABLE;
|
||||
|
||||
function getSettings() {
|
||||
public function getSettings() {
|
||||
return WPFunctions::get()->isSerialized($this->settings) ? unserialize($this->settings) : $this->settings;
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
public function getBody() {
|
||||
return WPFunctions::get()->isSerialized($this->body) ? unserialize($this->body) : $this->body;
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
public function asArray() {
|
||||
$model = parent::asArray();
|
||||
|
||||
$model['body'] = $this->getBody();
|
||||
@ -31,7 +31,7 @@ class Form extends Model {
|
||||
return $model;
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
$this->set('body', (is_serialized($this->body))
|
||||
? $this->body
|
||||
: serialize($this->body)
|
||||
@ -43,7 +43,7 @@ class Form extends Model {
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
function getFieldList() {
|
||||
public function getFieldList() {
|
||||
$body = $this->getBody();
|
||||
if (empty($body)) {
|
||||
return false;
|
||||
@ -69,7 +69,7 @@ class Form extends Model {
|
||||
return $fields ?: false;
|
||||
}
|
||||
|
||||
function filterSegments(array $segment_ids = []) {
|
||||
public function filterSegments(array $segment_ids = []) {
|
||||
$settings = $this->getSettings();
|
||||
if (empty($settings['segments'])) {
|
||||
return [];
|
||||
@ -86,11 +86,11 @@ class Form extends Model {
|
||||
return $segment_ids;
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
public static function search($orm, $search = '') {
|
||||
return $orm->whereLike('name', '%' . $search . '%');
|
||||
}
|
||||
|
||||
static function groups() {
|
||||
public static function groups() {
|
||||
return [
|
||||
[
|
||||
'name' => 'all',
|
||||
@ -105,14 +105,14 @@ class Form extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function groupBy($orm, $group = null) {
|
||||
public static function groupBy($orm, $group = null) {
|
||||
if ($group === 'trash') {
|
||||
return $orm->whereNotNull('deleted_at');
|
||||
}
|
||||
return $orm->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
static function getDefaultSuccessMessage() {
|
||||
public static function getDefaultSuccessMessage() {
|
||||
$settings = SettingsController::getInstance();
|
||||
if ($settings->get('signup_confirmation.enabled')) {
|
||||
return __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet');
|
||||
@ -120,7 +120,7 @@ class Form extends Model {
|
||||
return __('You’ve been successfully subscribed to our newsletter!', 'mailpoet');
|
||||
}
|
||||
|
||||
static function updateSuccessMessages() {
|
||||
public static function updateSuccessMessages() {
|
||||
$right_message = self::getDefaultSuccessMessage();
|
||||
$wrong_message = (
|
||||
$right_message === __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet')
|
||||
|
@ -5,7 +5,7 @@ namespace MailPoet\Models;
|
||||
class MappingToExternalEntities extends Model {
|
||||
public static $_table = MP_MAPPING_TO_EXTERNAL_ENTITIES_TABLE;
|
||||
|
||||
static function create($data = []) {
|
||||
public static function create($data = []) {
|
||||
$relation = parent::create();
|
||||
$relation->hydrate($data);
|
||||
return $relation->save();
|
||||
|
@ -131,7 +131,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
protected $_errors;
|
||||
protected $_new_record;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
$this->_errors = [];
|
||||
$validator = new ModelValidator();
|
||||
parent::__construct($validator);
|
||||
@ -140,7 +140,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
static function create() {
|
||||
public static function create() {
|
||||
$created = parent::create();
|
||||
if (is_bool($created)) {
|
||||
throw new \Exception('ORM is not initialised');
|
||||
@ -194,7 +194,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
return self::_createOrUpdate($data);
|
||||
}
|
||||
|
||||
function getErrors() {
|
||||
public function getErrors() {
|
||||
if (empty($this->_errors)) {
|
||||
return false;
|
||||
} else {
|
||||
@ -202,7 +202,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
}
|
||||
}
|
||||
|
||||
function setError($error = '', $error_code = null) {
|
||||
public function setError($error = '', $error_code = null) {
|
||||
if (!$error_code) {
|
||||
$error_code = count($this->_errors);
|
||||
}
|
||||
@ -216,7 +216,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
}
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
$this->setTimestamp();
|
||||
$this->_new_record = $this->isNew();
|
||||
try {
|
||||
@ -247,17 +247,17 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function isNew() {
|
||||
public function isNew() {
|
||||
return (isset($this->_new_record)) ?
|
||||
$this->_new_record :
|
||||
parent::isNew();
|
||||
}
|
||||
|
||||
function trash() {
|
||||
public function trash() {
|
||||
return $this->set_expr('deleted_at', 'NOW()')->save();
|
||||
}
|
||||
|
||||
static function bulkTrash($orm) {
|
||||
public static function bulkTrash($orm) {
|
||||
$model = get_called_class();
|
||||
$count = self::bulkAction($orm, function($ids) use ($model) {
|
||||
$model::rawExecute(join(' ', [
|
||||
@ -270,7 +270,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
static function bulkDelete($orm) {
|
||||
public static function bulkDelete($orm) {
|
||||
$model = get_called_class();
|
||||
$count = self::bulkAction($orm, function($ids) use ($model) {
|
||||
$model::whereIn('id', $ids)->deleteMany();
|
||||
@ -279,11 +279,11 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
function restore() {
|
||||
public function restore() {
|
||||
return $this->set_expr('deleted_at', 'NULL')->save();
|
||||
}
|
||||
|
||||
static function bulkRestore($orm) {
|
||||
public static function bulkRestore($orm) {
|
||||
$model = get_called_class();
|
||||
$count = self::bulkAction($orm, function($ids) use ($model) {
|
||||
$model::rawExecute(join(' ', [
|
||||
@ -296,7 +296,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
static function bulkAction($orm, $callback = false) {
|
||||
public static function bulkAction($orm, $callback = false) {
|
||||
$total = $orm->count();
|
||||
|
||||
if ($total === 0) return false;
|
||||
@ -319,7 +319,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
->rowCount();
|
||||
}
|
||||
|
||||
function duplicate($data = []) {
|
||||
public function duplicate($data = []) {
|
||||
$model = get_called_class();
|
||||
$model_data = array_merge($this->asArray(), $data);
|
||||
unset($model_data['id']);
|
||||
@ -336,17 +336,17 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
|
||||
return $duplicate;
|
||||
}
|
||||
|
||||
function setTimestamp() {
|
||||
public function setTimestamp() {
|
||||
if ($this->created_at === null) {
|
||||
$this->set_expr('created_at', 'NOW()');
|
||||
}
|
||||
}
|
||||
|
||||
static function getPublished() {
|
||||
public static function getPublished() {
|
||||
return static::whereNull('deleted_at');
|
||||
}
|
||||
|
||||
static function getTrashed() {
|
||||
public static function getTrashed() {
|
||||
return static::whereNotNull('deleted_at');
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class ModelValidator extends \MailPoetVendor\Sudzy\Engine {
|
||||
'www',
|
||||
];
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->validators = [
|
||||
'validEmail' => 'validateEmail',
|
||||
@ -67,19 +67,19 @@ class ModelValidator extends \MailPoetVendor\Sudzy\Engine {
|
||||
}
|
||||
}
|
||||
|
||||
function validateEmail($email) {
|
||||
public function validateEmail($email) {
|
||||
$permitted_length = (strlen($email) >= self::EMAIL_MIN_LENGTH && strlen($email) <= self::EMAIL_MAX_LENGTH);
|
||||
$valid_email = WPFunctions::get()->isEmail($email) !== false && parent::_isEmail($email, null);
|
||||
return ($permitted_length && $valid_email);
|
||||
}
|
||||
|
||||
function validateNonRoleEmail($email) {
|
||||
public function validateNonRoleEmail($email) {
|
||||
if (!$this->validateEmail($email)) return false;
|
||||
$first_part = strtolower(substr($email, 0, strpos($email, '@')));
|
||||
return array_search($first_part, self::ROLE_EMAILS) === false;
|
||||
}
|
||||
|
||||
function validateRenderedNewsletterBody($newsletter_body) {
|
||||
public function validateRenderedNewsletterBody($newsletter_body) {
|
||||
if (is_serialized($newsletter_body)) {
|
||||
$newsletter_body = unserialize($newsletter_body);
|
||||
} else if (Helpers::isJson($newsletter_body)) {
|
||||
|
@ -57,18 +57,18 @@ class Newsletter extends Model {
|
||||
// automatic newsletters status
|
||||
const STATUS_ACTIVE = NewsletterEntity::STATUS_ACTIVE;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->addValidations('type', [
|
||||
'required' => WPFunctions::get()->__('Please specify a type.', 'mailpoet'),
|
||||
]);
|
||||
}
|
||||
|
||||
function queue() {
|
||||
public function queue() {
|
||||
return $this->hasOne(__NAMESPACE__ . '\SendingQueue', 'newsletter_id', 'id');
|
||||
}
|
||||
|
||||
function children() {
|
||||
public function children() {
|
||||
return $this->hasMany(
|
||||
__NAMESPACE__ . '\Newsletter',
|
||||
'parent_id',
|
||||
@ -76,7 +76,7 @@ class Newsletter extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function parent() {
|
||||
public function parent() {
|
||||
return $this->hasOne(
|
||||
__NAMESPACE__ . '\Newsletter',
|
||||
'id',
|
||||
@ -84,7 +84,7 @@ class Newsletter extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function segments() {
|
||||
public function segments() {
|
||||
return $this->hasManyThrough(
|
||||
__NAMESPACE__ . '\Segment',
|
||||
__NAMESPACE__ . '\NewsletterSegment',
|
||||
@ -93,7 +93,7 @@ class Newsletter extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function segmentRelations() {
|
||||
public function segmentRelations() {
|
||||
return $this->hasMany(
|
||||
__NAMESPACE__ . '\NewsletterSegment',
|
||||
'newsletter_id',
|
||||
@ -101,7 +101,7 @@ class Newsletter extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function options() {
|
||||
public function options() {
|
||||
return $this->hasManyThrough(
|
||||
__NAMESPACE__ . '\NewsletterOptionField',
|
||||
__NAMESPACE__ . '\NewsletterOption',
|
||||
@ -110,7 +110,7 @@ class Newsletter extends Model {
|
||||
)->select_expr(MP_NEWSLETTER_OPTION_TABLE . '.value');
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
if (is_string($this->deleted_at) && strlen(trim($this->deleted_at)) === 0) {
|
||||
$this->set_expr('deleted_at', 'NULL');
|
||||
}
|
||||
@ -133,7 +133,7 @@ class Newsletter extends Model {
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
function trash() {
|
||||
public function trash() {
|
||||
// trash queue associations
|
||||
$children = $this->children()->select('id')->findArray();
|
||||
if ($children) {
|
||||
@ -170,7 +170,7 @@ class Newsletter extends Model {
|
||||
return parent::trash();
|
||||
}
|
||||
|
||||
static function bulkTrash($orm) {
|
||||
public static function bulkTrash($orm) {
|
||||
// bulk trash queue and notification history associations
|
||||
parent::bulkAction($orm, function($ids) {
|
||||
$children = Newsletter::whereIn('parent_id', $ids)->select('id')->findArray();
|
||||
@ -209,7 +209,7 @@ class Newsletter extends Model {
|
||||
return parent::bulkTrash($orm);
|
||||
}
|
||||
|
||||
function delete() {
|
||||
public function delete() {
|
||||
// delete queue, notification history and segment associations
|
||||
$children = $this->children()->select('id')->findArray();
|
||||
if ($children) {
|
||||
@ -233,7 +233,7 @@ class Newsletter extends Model {
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
static function bulkDelete($orm) {
|
||||
public static function bulkDelete($orm) {
|
||||
// bulk delete queue, notification history and segment associations
|
||||
parent::bulkAction($orm, function($ids) {
|
||||
$children = Newsletter::whereIn('parent_id', $ids)->select('id')->findArray();
|
||||
@ -259,7 +259,7 @@ class Newsletter extends Model {
|
||||
return parent::bulkDelete($orm);
|
||||
}
|
||||
|
||||
function restore() {
|
||||
public function restore() {
|
||||
// restore trashed queue and notification history associations
|
||||
$children = $this->children()->select('id')->findArray();
|
||||
if ($children) {
|
||||
@ -300,7 +300,7 @@ class Newsletter extends Model {
|
||||
return parent::restore();
|
||||
}
|
||||
|
||||
static function bulkRestore($orm) {
|
||||
public static function bulkRestore($orm) {
|
||||
// bulk restore trashed queue and notification history associations
|
||||
parent::bulkAction($orm, function($ids) {
|
||||
$children = Newsletter::whereIn('parent_id', $ids)->select('id')->findArray();
|
||||
@ -347,7 +347,7 @@ class Newsletter extends Model {
|
||||
return parent::bulkRestore($orm);
|
||||
}
|
||||
|
||||
function setStatus($status = null) {
|
||||
public function setStatus($status = null) {
|
||||
if ($status === self::STATUS_ACTIVE) {
|
||||
if (!$this->body || empty(json_decode($this->body))) {
|
||||
$this->setError(
|
||||
@ -381,7 +381,7 @@ class Newsletter extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function duplicate($data = []) {
|
||||
public function duplicate($data = []) {
|
||||
$newsletter_data = $this->asArray();
|
||||
|
||||
// remove id so that it creates a new record
|
||||
@ -450,7 +450,7 @@ class Newsletter extends Model {
|
||||
return $duplicate;
|
||||
}
|
||||
|
||||
function createNotificationHistory() {
|
||||
public function createNotificationHistory() {
|
||||
$newsletter_data = $this->asArray();
|
||||
|
||||
// remove id so that it creates a new record
|
||||
@ -496,7 +496,7 @@ class Newsletter extends Model {
|
||||
return $notification_history;
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
public function asArray() {
|
||||
$model = parent::asArray();
|
||||
|
||||
if (isset($model['body'])) {
|
||||
@ -505,7 +505,7 @@ class Newsletter extends Model {
|
||||
return $model;
|
||||
}
|
||||
|
||||
function withSegments($incl_deleted = false) {
|
||||
public function withSegments($incl_deleted = false) {
|
||||
$this->segments = $this->segments()->findArray();
|
||||
if ($incl_deleted) {
|
||||
$this->withDeletedSegments();
|
||||
@ -513,7 +513,7 @@ class Newsletter extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withDeletedSegments() {
|
||||
public function withDeletedSegments() {
|
||||
if (!empty($this->segments)) {
|
||||
$segment_ids = array_column($this->segments, 'id');
|
||||
$links = $this->segmentRelations()
|
||||
@ -532,16 +532,16 @@ class Newsletter extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withChildrenCount() {
|
||||
public function withChildrenCount() {
|
||||
$this->children_count = $this->children()->count();
|
||||
return $this;
|
||||
}
|
||||
|
||||
function getQueue($columns = '*') {
|
||||
public function getQueue($columns = '*') {
|
||||
return SendingTask::getByNewsletterId($this->id);
|
||||
}
|
||||
|
||||
function withSendingQueue() {
|
||||
public function withSendingQueue() {
|
||||
$queue = $this->getQueue();
|
||||
if ($queue === false) {
|
||||
$this->queue = false;
|
||||
@ -551,7 +551,7 @@ class Newsletter extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withOptions() {
|
||||
public function withOptions() {
|
||||
$options = $this->options()->findArray();
|
||||
if (empty($options)) {
|
||||
$this->options = [];
|
||||
@ -561,7 +561,7 @@ class Newsletter extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withTotalSent() {
|
||||
public function withTotalSent() {
|
||||
// total of subscribers who received the email
|
||||
$this->total_sent = (int)SendingQueue::findTaskByNewsletterId($this->id)
|
||||
->where('tasks.status', SendingQueue::STATUS_COMPLETED)
|
||||
@ -569,25 +569,25 @@ class Newsletter extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withScheduledToBeSent() {
|
||||
public function withScheduledToBeSent() {
|
||||
$this->total_scheduled = (int)SendingQueue::findTaskByNewsletterId($this->id)
|
||||
->where('tasks.status', SendingQueue::STATUS_SCHEDULED)
|
||||
->count();
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withStatistics(WCHelper $woocommerce_helper) {
|
||||
public function withStatistics(WCHelper $woocommerce_helper) {
|
||||
$statistics = $this->getStatistics($woocommerce_helper);
|
||||
$this->statistics = $statistics;
|
||||
return $this;
|
||||
}
|
||||
|
||||
function render() {
|
||||
public function render() {
|
||||
$renderer = new Renderer($this);
|
||||
return $renderer->render();
|
||||
}
|
||||
|
||||
function getStatistics(WCHelper $woocommerce_helper) {
|
||||
public function getStatistics(WCHelper $woocommerce_helper) {
|
||||
if (($this->type !== self::TYPE_WELCOME) && ($this->queue === false)) {
|
||||
return false;
|
||||
}
|
||||
@ -630,7 +630,7 @@ class Newsletter extends Model {
|
||||
return $result;
|
||||
}
|
||||
|
||||
function wasScheduledForSubscriber($subscriber_id) {
|
||||
public function wasScheduledForSubscriber($subscriber_id) {
|
||||
/** @var \stdClass */
|
||||
$queue = SendingQueue::rawQuery(
|
||||
"SELECT COUNT(*) as count
|
||||
@ -645,7 +645,7 @@ class Newsletter extends Model {
|
||||
}
|
||||
|
||||
|
||||
static function getAnalytics() {
|
||||
public static function getAnalytics() {
|
||||
$welcome_newsletters_count = Newsletter::getPublished()
|
||||
->filter('filterType', self::TYPE_WELCOME)
|
||||
->filter('filterStatus', self::STATUS_ACTIVE)
|
||||
@ -703,7 +703,7 @@ class Newsletter extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function sentAfter($date) {
|
||||
public static function sentAfter($date) {
|
||||
return static::tableAlias('newsletters')
|
||||
->where('newsletters.type', self::TYPE_STANDARD)
|
||||
->where('newsletters.status', self::STATUS_SENT)
|
||||
@ -722,14 +722,14 @@ class Newsletter extends Model {
|
||||
->count();
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
public static function search($orm, $search = '') {
|
||||
if (strlen(trim($search)) > 0) {
|
||||
$orm->whereLike('subject', '%' . $search . '%');
|
||||
}
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filters($data = []) {
|
||||
public static function filters($data = []) {
|
||||
$type = isset($data['params']['type']) ? $data['params']['type'] : null;
|
||||
$group = (isset($data['params']['group'])) ? $data['params']['group'] : null;
|
||||
|
||||
@ -769,7 +769,7 @@ class Newsletter extends Model {
|
||||
return $filters;
|
||||
}
|
||||
|
||||
static function filterBy($orm, $data = []) {
|
||||
public static function filterBy($orm, $data = []) {
|
||||
// apply filters
|
||||
if (!empty($data['filter'])) {
|
||||
foreach ($data['filter'] as $key => $value) {
|
||||
@ -800,7 +800,7 @@ class Newsletter extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filterWithOptions($orm, $type) {
|
||||
public static function filterWithOptions($orm, $type) {
|
||||
$orm = $orm->select(MP_NEWSLETTERS_TABLE . '.*');
|
||||
$optionFields = NewsletterOptionField::findArray();
|
||||
foreach ($optionFields as $optionField) {
|
||||
@ -833,7 +833,7 @@ class Newsletter extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function groups($data = []) {
|
||||
public static function groups($data = []) {
|
||||
$type = isset($data['params']['type']) ? $data['params']['type'] : null;
|
||||
$group = (isset($data['params']['group'])) ? $data['params']['group'] : null;
|
||||
$parentId = (isset($data['params']['parent_id'])) ? $data['params']['parent_id'] : null;
|
||||
@ -952,7 +952,7 @@ class Newsletter extends Model {
|
||||
return $groups;
|
||||
}
|
||||
|
||||
static function groupBy($orm, $data = []) {
|
||||
public static function groupBy($orm, $data = []) {
|
||||
$group = (!empty($data['group'])) ? $data['group'] : 'all';
|
||||
|
||||
switch ($group) {
|
||||
@ -976,7 +976,7 @@ class Newsletter extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filterStatus($orm, $status = false) {
|
||||
public static function filterStatus($orm, $status = false) {
|
||||
if (in_array($status, [
|
||||
self::STATUS_DRAFT,
|
||||
self::STATUS_SCHEDULED,
|
||||
@ -989,7 +989,7 @@ class Newsletter extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filterType($orm, $type = false, $group = false) {
|
||||
public static function filterType($orm, $type = false, $group = false) {
|
||||
if (in_array($type, [
|
||||
self::TYPE_STANDARD,
|
||||
self::TYPE_WELCOME,
|
||||
@ -1020,7 +1020,7 @@ class Newsletter extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function listingQuery($data = []) {
|
||||
public static function listingQuery($data = []) {
|
||||
$query = self::select(
|
||||
[
|
||||
self::$_table . '.id',
|
||||
@ -1042,7 +1042,7 @@ class Newsletter extends Model {
|
||||
->filter('search', $data['search']);
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
public static function createOrUpdate($data = []) {
|
||||
$data['unsubscribe_token'] = Security::generateUnsubscribeToken(self::class);
|
||||
return parent::_createOrUpdate($data, false, function($data) {
|
||||
$settings = SettingsController::getInstance();
|
||||
@ -1080,7 +1080,7 @@ class Newsletter extends Model {
|
||||
});
|
||||
}
|
||||
|
||||
static function getWelcomeNotificationsForSegments($segments) {
|
||||
public static function getWelcomeNotificationsForSegments($segments) {
|
||||
return NewsletterOption::tableAlias('options')
|
||||
->select('options.newsletter_id')
|
||||
->select('options.value', 'segment_id')
|
||||
@ -1101,7 +1101,7 @@ class Newsletter extends Model {
|
||||
->findMany();
|
||||
}
|
||||
|
||||
static function getArchives($segment_ids = []) {
|
||||
public static function getArchives($segment_ids = []) {
|
||||
$orm = self::tableAlias('newsletters')
|
||||
->distinct()->select('newsletters.*')
|
||||
->select('newsletter_rendered_subject')
|
||||
@ -1136,18 +1136,18 @@ class Newsletter extends Model {
|
||||
return $orm->findMany();
|
||||
}
|
||||
|
||||
static function getByHash($hash) {
|
||||
public static function getByHash($hash) {
|
||||
return parent::where('hash', $hash)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
function getMeta() {
|
||||
public function getMeta() {
|
||||
if (!$this->meta) return;
|
||||
|
||||
return (Helpers::isJson($this->meta)) ? json_decode($this->meta, true) : $this->meta;
|
||||
}
|
||||
|
||||
static function findOneWithOptions($id) {
|
||||
public static function findOneWithOptions($id) {
|
||||
$newsletter = self::findOne($id);
|
||||
if (!$newsletter instanceof self) {
|
||||
return false;
|
||||
|
@ -11,7 +11,7 @@ namespace MailPoet\Models;
|
||||
class NewsletterOption extends Model {
|
||||
public static $_table = MP_NEWSLETTER_OPTION_TABLE;
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
public static function createOrUpdate($data = []) {
|
||||
if (!is_array($data) || empty($data['newsletter_id']) || empty($data['option_field_id'])) {
|
||||
return;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use MailPoet\WP\Functions as WPFunctions;
|
||||
class NewsletterOptionField extends Model {
|
||||
public static $_table = MP_NEWSLETTER_OPTION_FIELDS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->addValidations('name', [
|
||||
'required' => WPFunctions::get()->__('Please specify a name.', 'mailpoet'),
|
||||
@ -17,7 +17,7 @@ class NewsletterOptionField extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
function newsletters() {
|
||||
public function newsletters() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__ . '\Newsletter',
|
||||
__NAMESPACE__ . '\NewsletterOption',
|
||||
|
@ -10,7 +10,7 @@ namespace MailPoet\Models;
|
||||
class NewsletterPost extends Model {
|
||||
public static $_table = MP_NEWSLETTER_POSTS_TABLE;
|
||||
|
||||
static function getNewestNewsletterPost($newsletter_id) {
|
||||
public static function getNewestNewsletterPost($newsletter_id) {
|
||||
return self::where('newsletter_id', $newsletter_id)
|
||||
->orderByDesc('created_at')
|
||||
->findOne();
|
||||
|
@ -19,7 +19,7 @@ class NewsletterTemplate extends Model {
|
||||
const RECENTLY_SENT_CATEGORIES = '["recent"]';
|
||||
const RECENTLY_SENT_COUNT = 12;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('name', [
|
||||
@ -30,7 +30,7 @@ class NewsletterTemplate extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
static function cleanRecentlySent($data) {
|
||||
public static function cleanRecentlySent($data) {
|
||||
if (!empty($data['categories']) && $data['categories'] === self::RECENTLY_SENT_CATEGORIES) {
|
||||
$ids = parent::where('categories', self::RECENTLY_SENT_CATEGORIES)
|
||||
->select('id')
|
||||
@ -46,7 +46,7 @@ class NewsletterTemplate extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
public function asArray() {
|
||||
$template = parent::asArray();
|
||||
if (isset($template['body'])) {
|
||||
$template['body'] = json_decode($template['body'], true);
|
||||
|
@ -34,12 +34,12 @@ class ScheduledTask extends Model {
|
||||
|
||||
private $wp;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->wp = new WPFunctions();
|
||||
}
|
||||
|
||||
function subscribers() {
|
||||
public function subscribers() {
|
||||
return $this->hasManyThrough(
|
||||
__NAMESPACE__ . '\Subscriber',
|
||||
__NAMESPACE__ . '\ScheduledTaskSubscriber',
|
||||
@ -48,13 +48,13 @@ class ScheduledTask extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function pause() {
|
||||
public function pause() {
|
||||
$this->set('status', self::STATUS_PAUSED);
|
||||
$this->save();
|
||||
return ($this->getErrors() === false && $this->id() > 0);
|
||||
}
|
||||
|
||||
static function pauseAllByNewsletter(Newsletter $newsletter) {
|
||||
public static function pauseAllByNewsletter(Newsletter $newsletter) {
|
||||
ScheduledTask::rawExecute(
|
||||
'UPDATE `' . ScheduledTask::$_table . '` t ' .
|
||||
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
|
||||
@ -65,13 +65,13 @@ class ScheduledTask extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function resume() {
|
||||
public function resume() {
|
||||
$this->setExpr('status', 'NULL');
|
||||
$this->save();
|
||||
return ($this->getErrors() === false && $this->id() > 0);
|
||||
}
|
||||
|
||||
static function setScheduledAllByNewsletter(Newsletter $newsletter) {
|
||||
public static function setScheduledAllByNewsletter(Newsletter $newsletter) {
|
||||
ScheduledTask::rawExecute(
|
||||
'UPDATE `' . ScheduledTask::$_table . '` t ' .
|
||||
'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' .
|
||||
@ -83,14 +83,14 @@ class ScheduledTask extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function complete() {
|
||||
public function complete() {
|
||||
$this->processed_at = $this->wp->currentTime('mysql');
|
||||
$this->set('status', self::STATUS_COMPLETED);
|
||||
$this->save();
|
||||
return ($this->getErrors() === false && $this->id() > 0);
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
// set the default priority to medium
|
||||
if (!$this->priority) {
|
||||
$this->priority = self::PRIORITY_MEDIUM;
|
||||
@ -105,18 +105,18 @@ class ScheduledTask extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
public function asArray() {
|
||||
$model = parent::asArray();
|
||||
$model['meta'] = $this->getMeta();
|
||||
return $model;
|
||||
}
|
||||
|
||||
function getMeta() {
|
||||
public function getMeta() {
|
||||
$meta = (Helpers::isJson($this->meta)) ? json_decode($this->meta, true) : $this->meta;
|
||||
return !empty($meta) ? (array)$meta : [];
|
||||
}
|
||||
|
||||
function delete() {
|
||||
public function delete() {
|
||||
try {
|
||||
ORM::get_db()->beginTransaction();
|
||||
ScheduledTaskSubscriber::where('task_id', $this->id)->deleteMany();
|
||||
@ -129,7 +129,7 @@ class ScheduledTask extends Model {
|
||||
return null;
|
||||
}
|
||||
|
||||
function rescheduleProgressively() {
|
||||
public function rescheduleProgressively() {
|
||||
$scheduled_at = Carbon::createFromTimestamp($this->wp->currentTime('timestamp'));
|
||||
$timeout = (int)min(self::BASIC_RESCHEDULE_TIMEOUT * pow(2, $this->reschedule_count), self::MAX_RESCHEDULE_TIMEOUT);
|
||||
$this->scheduled_at = $scheduled_at->addMinutes($timeout);
|
||||
@ -139,7 +139,7 @@ class ScheduledTask extends Model {
|
||||
return $timeout;
|
||||
}
|
||||
|
||||
static function touchAllByIds(array $ids) {
|
||||
public static function touchAllByIds(array $ids) {
|
||||
ScheduledTask::rawExecute(
|
||||
'UPDATE `' . ScheduledTask::$_table . '`' .
|
||||
'SET `updated_at` = NOW() ' .
|
||||
@ -150,7 +150,7 @@ class ScheduledTask extends Model {
|
||||
/**
|
||||
* @return ScheduledTask|null
|
||||
*/
|
||||
static function findOneScheduledByNewsletterIdAndSubscriberId($newsletter_id, $subscriber_id) {
|
||||
public static function findOneScheduledByNewsletterIdAndSubscriberId($newsletter_id, $subscriber_id) {
|
||||
return ScheduledTask::tableAlias('tasks')
|
||||
->select('tasks.*')
|
||||
->innerJoin(SendingQueue::$_table, 'queues.task_id = tasks.id', 'queues')
|
||||
@ -163,19 +163,19 @@ class ScheduledTask extends Model {
|
||||
->findOne() ?: null;
|
||||
}
|
||||
|
||||
static function findDueByType($type, $limit = null) {
|
||||
public static function findDueByType($type, $limit = null) {
|
||||
return self::findByTypeAndStatus($type, ScheduledTask::STATUS_SCHEDULED, $limit);
|
||||
}
|
||||
|
||||
static function findRunningByType($type, $limit = null) {
|
||||
public static function findRunningByType($type, $limit = null) {
|
||||
return self::findByTypeAndStatus($type, null, $limit);
|
||||
}
|
||||
|
||||
static function findFutureScheduledByType($type, $limit = null) {
|
||||
public static function findFutureScheduledByType($type, $limit = null) {
|
||||
return self::findByTypeAndStatus($type, ScheduledTask::STATUS_SCHEDULED, $limit, true);
|
||||
}
|
||||
|
||||
static function findCompletedByType($type, $limit = null) {
|
||||
public static function findCompletedByType($type, $limit = null) {
|
||||
return self::findByTypeAndStatus($type, ScheduledTask::STATUS_COMPLETED, $limit);
|
||||
}
|
||||
|
||||
|
@ -25,11 +25,11 @@ class ScheduledTaskSubscriber extends Model {
|
||||
public static $_table = MP_SCHEDULED_TASK_SUBSCRIBERS_TABLE;
|
||||
public static $_id_column = ['task_id', 'subscriber_id'];
|
||||
|
||||
function task() {
|
||||
public function task() {
|
||||
return $this->hasOne(__NAMESPACE__ . '\ScheduledTask', 'id', 'task_id');
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
public static function createOrUpdate($data = []) {
|
||||
if (!is_array($data) || empty($data['task_id']) || empty($data['subscriber_id'])) {
|
||||
return;
|
||||
}
|
||||
@ -41,7 +41,7 @@ class ScheduledTaskSubscriber extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
static function setSubscribers($task_id, array $subscriber_ids) {
|
||||
public static function setSubscribers($task_id, array $subscriber_ids) {
|
||||
static::clearSubscribers($task_id);
|
||||
return static::addSubscribers($task_id, $subscriber_ids);
|
||||
}
|
||||
@ -49,7 +49,7 @@ class ScheduledTaskSubscriber extends Model {
|
||||
/**
|
||||
* For large batches use MailPoet\Segments\SubscribersFinder::addSubscribersToTaskFromSegments()
|
||||
*/
|
||||
static function addSubscribers($task_id, array $subscriber_ids) {
|
||||
public static function addSubscribers($task_id, array $subscriber_ids) {
|
||||
foreach ($subscriber_ids as $subscriber_id) {
|
||||
self::createOrUpdate([
|
||||
'task_id' => $task_id,
|
||||
@ -58,23 +58,23 @@ class ScheduledTaskSubscriber extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static function clearSubscribers($task_id) {
|
||||
public static function clearSubscribers($task_id) {
|
||||
return self::where('task_id', $task_id)->deleteMany();
|
||||
}
|
||||
|
||||
static function getUnprocessedCount($task_id) {
|
||||
public static function getUnprocessedCount($task_id) {
|
||||
return self::getCount($task_id, self::STATUS_UNPROCESSED);
|
||||
}
|
||||
|
||||
static function getProcessedCount($task_id) {
|
||||
public static function getProcessedCount($task_id) {
|
||||
return self::getCount($task_id, self::STATUS_PROCESSED);
|
||||
}
|
||||
|
||||
static function getTotalCount($task_id) {
|
||||
public static function getTotalCount($task_id) {
|
||||
return self::getCount($task_id);
|
||||
}
|
||||
|
||||
static function listingQuery($data) {
|
||||
public static function listingQuery($data) {
|
||||
$group = isset($data['group']) ? $data['group'] : 'all';
|
||||
return self::join(Subscriber::$_table, ["subscriber_id", "=", "subscribers.id"], "subscribers")
|
||||
->filter($group, $data['params'])
|
||||
@ -88,7 +88,7 @@ class ScheduledTaskSubscriber extends Model {
|
||||
->select('subscribers.first_name', 'firstName');
|
||||
}
|
||||
|
||||
static function groups($data) {
|
||||
public static function groups($data) {
|
||||
$params = $data['params'];
|
||||
return [
|
||||
[
|
||||
@ -114,23 +114,23 @@ class ScheduledTaskSubscriber extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function all($orm, $params) {
|
||||
public static function all($orm, $params) {
|
||||
return $orm->whereIn('task_id', $params['task_ids']);
|
||||
}
|
||||
|
||||
static function sent($orm, $params) {
|
||||
public static function sent($orm, $params) {
|
||||
return $orm->filter('all', $params)
|
||||
->where('processed', self::STATUS_PROCESSED)
|
||||
->where('failed', self::FAIL_STATUS_OK);
|
||||
}
|
||||
|
||||
static function failed($orm, $params) {
|
||||
public static function failed($orm, $params) {
|
||||
return $orm->filter('all', $params)
|
||||
->where('processed', self::STATUS_PROCESSED)
|
||||
->where('failed', self::FAIL_STATUS_FAILED);
|
||||
}
|
||||
|
||||
static function unprocessed($orm, $params) {
|
||||
public static function unprocessed($orm, $params) {
|
||||
return $orm->filter('all', $params)
|
||||
->where('processed', self::STATUS_UNPROCESSED);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class Segment extends Model {
|
||||
const TYPE_WC_USERS = SegmentEntity::TYPE_WC_USERS;
|
||||
const TYPE_DEFAULT = SegmentEntity::TYPE_DEFAULT;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('name', [
|
||||
@ -29,13 +29,13 @@ class Segment extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
function delete() {
|
||||
public function delete() {
|
||||
// delete all relations to subscribers
|
||||
SubscriberSegment::where('segment_id', $this->id)->deleteMany();
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
function newsletters() {
|
||||
public function newsletters() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__ . '\Newsletter',
|
||||
__NAMESPACE__ . '\NewsletterSegment',
|
||||
@ -44,7 +44,7 @@ class Segment extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function subscribers() {
|
||||
public function subscribers() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__ . '\Subscriber',
|
||||
__NAMESPACE__ . '\SubscriberSegment',
|
||||
@ -53,7 +53,7 @@ class Segment extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
function duplicate($data = []) {
|
||||
public function duplicate($data = []) {
|
||||
$duplicate = parent::duplicate($data);
|
||||
|
||||
if ($duplicate !== false) {
|
||||
@ -69,20 +69,20 @@ class Segment extends Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
function addSubscriber($subscriber_id) {
|
||||
public function addSubscriber($subscriber_id) {
|
||||
$relation = SubscriberSegment::create();
|
||||
$relation->set('subscriber_id', $subscriber_id);
|
||||
$relation->set('segment_id', $this->id);
|
||||
return $relation->save();
|
||||
}
|
||||
|
||||
function removeSubscriber($subscriber_id) {
|
||||
public function removeSubscriber($subscriber_id) {
|
||||
return SubscriberSegment::where('subscriber_id', $subscriber_id)
|
||||
->where('segment_id', $this->id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
function withSubscribersCount() {
|
||||
public function withSubscribersCount() {
|
||||
$this->subscribers_count = SubscriberSegment::tableAlias('relation')
|
||||
->where('relation.segment_id', $this->id)
|
||||
->join(
|
||||
@ -122,7 +122,7 @@ class Segment extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withAutomatedEmailsSubjects() {
|
||||
public function withAutomatedEmailsSubjects() {
|
||||
$automated_emails = NewsletterSegment::tableAlias('relation')
|
||||
->where('relation.segment_id', $this->id)
|
||||
->join(
|
||||
@ -145,7 +145,7 @@ class Segment extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
static function getWPSegment() {
|
||||
public static function getWPSegment() {
|
||||
$wp_segment = self::where('type', self::TYPE_WP_USERS)->findOne();
|
||||
|
||||
if ($wp_segment === false) {
|
||||
@ -163,7 +163,7 @@ class Segment extends Model {
|
||||
return $wp_segment;
|
||||
}
|
||||
|
||||
static function getWooCommerceSegment() {
|
||||
public static function getWooCommerceSegment() {
|
||||
$wc_segment = self::where('type', self::TYPE_WC_USERS)->findOne();
|
||||
|
||||
if ($wc_segment === false) {
|
||||
@ -181,7 +181,7 @@ class Segment extends Model {
|
||||
return $wc_segment;
|
||||
}
|
||||
|
||||
static function shouldShowWooCommerceSegment() {
|
||||
public static function shouldShowWooCommerceSegment() {
|
||||
$woocommerce_helper = new WCHelper();
|
||||
$is_woocommerce_active = $woocommerce_helper->isWooCommerceActive();
|
||||
$woocommerce_user_exists = Segment::tableAlias('segment')
|
||||
@ -200,7 +200,7 @@ class Segment extends Model {
|
||||
return true;
|
||||
}
|
||||
|
||||
static function getSegmentTypes() {
|
||||
public static function getSegmentTypes() {
|
||||
$types = [Segment::TYPE_DEFAULT, Segment::TYPE_WP_USERS];
|
||||
if (Segment::shouldShowWooCommerceSegment()) {
|
||||
$types[] = Segment::TYPE_WC_USERS;
|
||||
@ -208,11 +208,11 @@ class Segment extends Model {
|
||||
return $types;
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
public static function search($orm, $search = '') {
|
||||
return $orm->whereLike('name', '%' . $search . '%');
|
||||
}
|
||||
|
||||
static function groups() {
|
||||
public static function groups() {
|
||||
$all_query = Segment::getPublished();
|
||||
if (!Segment::shouldShowWooCommerceSegment()) {
|
||||
$all_query->whereNotEqual('type', self::TYPE_WC_USERS);
|
||||
@ -231,7 +231,7 @@ class Segment extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function groupBy($orm, $group = null) {
|
||||
public static function groupBy($orm, $group = null) {
|
||||
if ($group === 'trash') {
|
||||
$orm->whereNotNull('deleted_at');
|
||||
} else {
|
||||
@ -240,7 +240,7 @@ class Segment extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function getSegmentsWithSubscriberCount($type = self::TYPE_DEFAULT) {
|
||||
public static function getSegmentsWithSubscriberCount($type = self::TYPE_DEFAULT) {
|
||||
$query = self::selectMany([self::$_table . '.id', self::$_table . '.name'])
|
||||
->whereIn('type', Segment::getSegmentTypes())
|
||||
->selectExpr(
|
||||
@ -271,14 +271,14 @@ class Segment extends Model {
|
||||
return $query->findArray();
|
||||
}
|
||||
|
||||
static function getSegmentsForImport() {
|
||||
public static function getSegmentsForImport() {
|
||||
$segments = self::getSegmentsWithSubscriberCount($type = false);
|
||||
return array_values(array_filter($segments, function($segment) {
|
||||
return $segment['type'] !== Segment::TYPE_WC_USERS;
|
||||
}));
|
||||
}
|
||||
|
||||
static function getSegmentsForExport() {
|
||||
public static function getSegmentsForExport() {
|
||||
return self::rawQuery(
|
||||
'(SELECT segments.id, segments.name, COUNT(relation.subscriber_id) as subscribers ' .
|
||||
'FROM ' . MP_SUBSCRIBER_SEGMENT_TABLE . ' relation ' .
|
||||
@ -298,7 +298,7 @@ class Segment extends Model {
|
||||
)->findArray();
|
||||
}
|
||||
|
||||
static function listingQuery(array $data = []) {
|
||||
public static function listingQuery(array $data = []) {
|
||||
$query = self::select('*');
|
||||
$query->whereIn('type', Segment::getSegmentTypes());
|
||||
if (isset($data['group'])) {
|
||||
@ -307,11 +307,11 @@ class Segment extends Model {
|
||||
return $query;
|
||||
}
|
||||
|
||||
static function getPublic() {
|
||||
public static function getPublic() {
|
||||
return self::getPublished()->where('type', self::TYPE_DEFAULT)->orderByAsc('name');
|
||||
}
|
||||
|
||||
static function bulkTrash($orm) {
|
||||
public static function bulkTrash($orm) {
|
||||
$count = parent::bulkAction($orm, function($ids) {
|
||||
Segment::rawExecute(join(' ', [
|
||||
'UPDATE `' . Segment::$_table . '`',
|
||||
@ -324,7 +324,7 @@ class Segment extends Model {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
static function bulkDelete($orm) {
|
||||
public static function bulkDelete($orm) {
|
||||
$count = parent::bulkAction($orm, function($ids) {
|
||||
// delete segments (only default)
|
||||
$segments = Segment::whereIn('id', $ids)
|
||||
@ -341,7 +341,7 @@ class Segment extends Model {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
static function getAnalytics() {
|
||||
public static function getAnalytics() {
|
||||
$analytics = Segment::selectExpr('type, count(*) as count')
|
||||
->whereNull('deleted_at')
|
||||
->groupBy('type')
|
||||
|
@ -30,7 +30,7 @@ class SendingQueue extends Model {
|
||||
const PRIORITY_MEDIUM = SendingQueueEntity::PRIORITY_MEDIUM;
|
||||
const PRIORITY_LOW = SendingQueueEntity::PRIORITY_LOW;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('newsletter_rendered_body', [
|
||||
@ -38,15 +38,15 @@ class SendingQueue extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
function task() {
|
||||
public function task() {
|
||||
return $this->hasOne(__NAMESPACE__ . '\ScheduledTask', 'id', 'task_id');
|
||||
}
|
||||
|
||||
function newsletter() {
|
||||
public function newsletter() {
|
||||
return $this->has_one(__NAMESPACE__ . '\Newsletter', 'id', 'newsletter_id');
|
||||
}
|
||||
|
||||
function pause() {
|
||||
public function pause() {
|
||||
if ($this->count_processed === $this->count_total) {
|
||||
return false;
|
||||
} else {
|
||||
@ -54,7 +54,7 @@ class SendingQueue extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function resume() {
|
||||
public function resume() {
|
||||
if ($this->count_processed === $this->count_total) {
|
||||
return $this->complete();
|
||||
} else {
|
||||
@ -62,11 +62,11 @@ class SendingQueue extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function complete() {
|
||||
public function complete() {
|
||||
return $this->task()->findOne()->complete();
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
$this->newsletter_rendered_body = $this->getNewsletterRenderedBody();
|
||||
if (!Helpers::isJson($this->newsletter_rendered_body) && !is_null($this->newsletter_rendered_body)) {
|
||||
$this->set(
|
||||
@ -99,18 +99,18 @@ class SendingQueue extends Model {
|
||||
return $subscribers;
|
||||
}
|
||||
|
||||
function getNewsletterRenderedBody($type = false) {
|
||||
public function getNewsletterRenderedBody($type = false) {
|
||||
$rendered_newsletter = $this->decodeRenderedNewsletterBodyObject($this->newsletter_rendered_body);
|
||||
return ($type && !empty($rendered_newsletter[$type])) ?
|
||||
$rendered_newsletter[$type] :
|
||||
$rendered_newsletter;
|
||||
}
|
||||
|
||||
function getMeta() {
|
||||
public function getMeta() {
|
||||
return (Helpers::isJson($this->meta)) ? json_decode($this->meta, true) : $this->meta;
|
||||
}
|
||||
|
||||
function isSubscriberProcessed($subscriber_id) {
|
||||
public function isSubscriberProcessed($subscriber_id) {
|
||||
if (!empty($this->subscribers)
|
||||
&& ScheduledTaskSubscriber::getTotalCount($this->task_id) === 0
|
||||
) {
|
||||
@ -126,7 +126,7 @@ class SendingQueue extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
public function asArray() {
|
||||
$model = parent::asArray();
|
||||
$model['newsletter_rendered_body'] = $this->getNewsletterRenderedBody();
|
||||
$model['meta'] = $this->getMeta();
|
||||
@ -143,7 +143,7 @@ class SendingQueue extends Model {
|
||||
return $rendered_body;
|
||||
}
|
||||
|
||||
static function getTasks() {
|
||||
public static function getTasks() {
|
||||
return ScheduledTask::tableAlias('tasks')
|
||||
->selectExpr('tasks.*')
|
||||
->join(
|
||||
@ -153,7 +153,7 @@ class SendingQueue extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function joinWithTasks() {
|
||||
public static function joinWithTasks() {
|
||||
return static::tableAlias('queues')
|
||||
->join(
|
||||
MP_SCHEDULED_TASKS_TABLE,
|
||||
@ -162,7 +162,7 @@ class SendingQueue extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function joinWithSubscribers() {
|
||||
public static function joinWithSubscribers() {
|
||||
return static::joinWithTasks()
|
||||
->join(
|
||||
MP_SCHEDULED_TASK_SUBSCRIBERS_TABLE,
|
||||
@ -171,7 +171,7 @@ class SendingQueue extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function findTaskByNewsletterId($newsletter_id) {
|
||||
public static function findTaskByNewsletterId($newsletter_id) {
|
||||
return static::getTasks()
|
||||
->where('queues.newsletter_id', $newsletter_id);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use DateTimeInterface;
|
||||
class StatisticsClicks extends Model {
|
||||
public static $_table = MP_STATISTICS_CLICKS_TABLE;
|
||||
|
||||
static function createOrUpdateClickCount($link_id, $subscriber_id, $newsletter_id, $queue_id) {
|
||||
public static function createOrUpdateClickCount($link_id, $subscriber_id, $newsletter_id, $queue_id) {
|
||||
$statistics = self::where('link_id', $link_id)
|
||||
->where('subscriber_id', $subscriber_id)
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
@ -33,7 +33,7 @@ class StatisticsClicks extends Model {
|
||||
return $statistics->save();
|
||||
}
|
||||
|
||||
static function getAllForSubscriber(Subscriber $subscriber) {
|
||||
public static function getAllForSubscriber(Subscriber $subscriber) {
|
||||
return static::tableAlias('clicks')
|
||||
->select('clicks.id', 'id')
|
||||
->select('newsletter_rendered_subject')
|
||||
@ -53,7 +53,7 @@ class StatisticsClicks extends Model {
|
||||
->orderByAsc('url');
|
||||
}
|
||||
|
||||
static function findLatestPerNewsletterBySubscriber(Subscriber $subscriber, DateTimeInterface $from, DateTimeInterface $to) {
|
||||
public static function findLatestPerNewsletterBySubscriber(Subscriber $subscriber, DateTimeInterface $from, DateTimeInterface $to) {
|
||||
// subquery to find latest click IDs for each newsletter
|
||||
$table = self::$_table;
|
||||
$latest_click_ids_per_newsletter_query = "
|
||||
|
@ -8,7 +8,7 @@ namespace MailPoet\Models;
|
||||
class StatisticsNewsletters extends Model {
|
||||
public static $_table = MP_STATISTICS_NEWSLETTERS_TABLE;
|
||||
|
||||
static function createMultiple(array $data) {
|
||||
public static function createMultiple(array $data) {
|
||||
$values = [];
|
||||
foreach ($data as $value) {
|
||||
if (!empty($value['newsletter_id']) &&
|
||||
@ -32,7 +32,7 @@ class StatisticsNewsletters extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function getAllForSubscriber(Subscriber $subscriber) {
|
||||
public static function getAllForSubscriber(Subscriber $subscriber) {
|
||||
return static::tableAlias('statistics')
|
||||
->select('statistics.newsletter_id', 'newsletter_id')
|
||||
->select('newsletter_rendered_subject')
|
||||
|
@ -10,7 +10,7 @@ namespace MailPoet\Models;
|
||||
class StatisticsOpens extends Model {
|
||||
public static $_table = MP_STATISTICS_OPENS_TABLE;
|
||||
|
||||
static function getOrCreate($subscriber_id, $newsletter_id, $queue_id) {
|
||||
public static function getOrCreate($subscriber_id, $newsletter_id, $queue_id) {
|
||||
$statistics = self::where('subscriber_id', $subscriber_id)
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
->where('queue_id', $queue_id)
|
||||
|
@ -10,7 +10,7 @@ namespace MailPoet\Models;
|
||||
class StatisticsUnsubscribes extends Model {
|
||||
public static $_table = MP_STATISTICS_UNSUBSCRIBES_TABLE;
|
||||
|
||||
static function getOrCreate($subscriber_id, $newsletter_id, $queue_id) {
|
||||
public static function getOrCreate($subscriber_id, $newsletter_id, $queue_id) {
|
||||
$statistics = self::where('subscriber_id', $subscriber_id)
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
->where('queue_id', $queue_id)
|
||||
|
@ -16,7 +16,7 @@ use WC_Order;
|
||||
class StatisticsWooCommercePurchases extends Model {
|
||||
public static $_table = MP_STATISTICS_WOOCOMMERCE_PURCHASES_TABLE;
|
||||
|
||||
static function createOrUpdateByClickDataAndOrder(StatisticsClicks $click, WC_Order $order) {
|
||||
public static function createOrUpdateByClickDataAndOrder(StatisticsClicks $click, WC_Order $order) {
|
||||
// search by subscriber and newsletter IDs (instead of click itself) to avoid duplicities
|
||||
// when a new click from the subscriber appeared since last tracking for given newsletter
|
||||
// (this will keep the originally tracked click - likely the click that led to the order)
|
||||
|
@ -46,7 +46,7 @@ class Subscriber extends Model {
|
||||
/** @var string|bool */
|
||||
public $token;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('email', [
|
||||
@ -55,7 +55,7 @@ class Subscriber extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
static function findOne($id = false) {
|
||||
public static function findOne($id = false) {
|
||||
if (is_int($id) || (string)(int)$id === $id) {
|
||||
return parent::findOne($id);
|
||||
} else if (strlen(trim($id)) > 0) {
|
||||
@ -64,7 +64,7 @@ class Subscriber extends Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
function segments() {
|
||||
public function segments() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__ . '\Segment',
|
||||
__NAMESPACE__ . '\SubscriberSegment',
|
||||
@ -74,13 +74,13 @@ class Subscriber extends Model {
|
||||
->where(MP_SUBSCRIBER_SEGMENT_TABLE . '.status', self::STATUS_SUBSCRIBED);
|
||||
}
|
||||
|
||||
function save() {
|
||||
public function save() {
|
||||
// convert email to lowercase format
|
||||
$this->email = strtolower($this->email);
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
function delete() {
|
||||
public function delete() {
|
||||
// WP Users cannot be deleted
|
||||
if (!$this->isWPUser() && !$this->isWooCommerceUser()) {
|
||||
// delete all relations to segments
|
||||
@ -92,7 +92,7 @@ class Subscriber extends Model {
|
||||
return null;
|
||||
}
|
||||
|
||||
function trash() {
|
||||
public function trash() {
|
||||
// WP Users cannot be trashed
|
||||
if ($this->isWPUser() || $this->isWooCommerceUser()) {
|
||||
return false;
|
||||
@ -101,15 +101,15 @@ class Subscriber extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function isWPUser() {
|
||||
public function isWPUser() {
|
||||
return (bool)$this->wp_user_id;
|
||||
}
|
||||
|
||||
function isWooCommerceUser() {
|
||||
public function isWooCommerceUser() {
|
||||
return (bool)$this->is_woocommerce_user;
|
||||
}
|
||||
|
||||
static function getCurrentWPUser() {
|
||||
public static function getCurrentWPUser() {
|
||||
$wp_user = WPFunctions::get()->wpGetCurrentUser();
|
||||
if (empty($wp_user->ID)) {
|
||||
return false; // Don't look up a subscriber for guests
|
||||
@ -117,7 +117,7 @@ class Subscriber extends Model {
|
||||
return self::where('wp_user_id', $wp_user->ID)->findOne();
|
||||
}
|
||||
|
||||
static function filterOutReservedColumns(array $subscriber_data) {
|
||||
public static function filterOutReservedColumns(array $subscriber_data) {
|
||||
$reserved_columns = [
|
||||
'id',
|
||||
'wp_user_id',
|
||||
@ -138,7 +138,7 @@ class Subscriber extends Model {
|
||||
return $subscriber_data;
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
public static function search($orm, $search = '') {
|
||||
if (strlen(trim($search)) === 0) {
|
||||
return $orm;
|
||||
}
|
||||
@ -149,7 +149,7 @@ class Subscriber extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function filters($data = []) {
|
||||
public static function filters($data = []) {
|
||||
$group = (!empty($data['group'])) ? $data['group'] : 'all';
|
||||
|
||||
$segments = Segment::orderByAsc('name')
|
||||
@ -202,7 +202,7 @@ class Subscriber extends Model {
|
||||
return $filters;
|
||||
}
|
||||
|
||||
static function filterBy($orm, $filters = null) {
|
||||
public static function filterBy($orm, $filters = null) {
|
||||
if (empty($filters)) {
|
||||
return $orm;
|
||||
}
|
||||
@ -221,7 +221,7 @@ class Subscriber extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function groups() {
|
||||
public static function groups() {
|
||||
return [
|
||||
[
|
||||
'name' => 'all',
|
||||
@ -261,7 +261,7 @@ class Subscriber extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function groupBy($orm, $group = null) {
|
||||
public static function groupBy($orm, $group = null) {
|
||||
if ($group === 'trash') {
|
||||
return $orm->whereNotNull('deleted_at');
|
||||
} else if ($group === 'all') {
|
||||
@ -271,7 +271,7 @@ class Subscriber extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static function filterWithCustomFields($orm) {
|
||||
public static function filterWithCustomFields($orm) {
|
||||
$orm = $orm->select(MP_SUBSCRIBERS_TABLE . '.*');
|
||||
$customFields = CustomField::findArray();
|
||||
foreach ($customFields as $customField) {
|
||||
@ -301,7 +301,7 @@ class Subscriber extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filterWithCustomFieldsForExport($orm) {
|
||||
public static function filterWithCustomFieldsForExport($orm) {
|
||||
$orm = $orm->select(MP_SUBSCRIBERS_TABLE . '.*');
|
||||
$customFields = CustomField::findArray();
|
||||
foreach ($customFields as $customField) {
|
||||
@ -329,7 +329,7 @@ class Subscriber extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function getSubscribedInSegments($segment_ids) {
|
||||
public static function getSubscribedInSegments($segment_ids) {
|
||||
$subscribers = SubscriberSegment::tableAlias('relation')
|
||||
->whereIn('relation.segment_id', $segment_ids)
|
||||
->where('relation.status', 'subscribed')
|
||||
@ -349,7 +349,7 @@ class Subscriber extends Model {
|
||||
* @param string $customer_email
|
||||
* @return bool|Subscriber
|
||||
*/
|
||||
static function getWooCommerceSegmentSubscriber($customer_email) {
|
||||
public static function getWooCommerceSegmentSubscriber($customer_email) {
|
||||
$wc_segment = Segment::getWooCommerceSegment();
|
||||
return Subscriber::tableAlias('subscribers')
|
||||
->select('subscribers.*')
|
||||
@ -366,7 +366,7 @@ class Subscriber extends Model {
|
||||
->findOne();
|
||||
}
|
||||
|
||||
function customFields() {
|
||||
public function customFields() {
|
||||
return $this->hasManyThrough(
|
||||
__NAMESPACE__ . '\CustomField',
|
||||
__NAMESPACE__ . '\SubscriberCustomField',
|
||||
@ -375,7 +375,7 @@ class Subscriber extends Model {
|
||||
)->select_expr(MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value');
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
public static function createOrUpdate($data = []) {
|
||||
$subscriber = false;
|
||||
if (is_array($data) && !empty($data)) {
|
||||
$data = WPFunctions::get()->stripslashesDeep($data);
|
||||
@ -450,7 +450,7 @@ class Subscriber extends Model {
|
||||
return $subscriber;
|
||||
}
|
||||
|
||||
function withCustomFields() {
|
||||
public function withCustomFields() {
|
||||
$custom_fields = CustomField::select('id')->findArray();
|
||||
if (empty($custom_fields)) return $this;
|
||||
|
||||
@ -467,18 +467,18 @@ class Subscriber extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withSegments() {
|
||||
public function withSegments() {
|
||||
$this->segments = $this->segments()->findArray();
|
||||
return $this;
|
||||
}
|
||||
|
||||
function withSubscriptions() {
|
||||
public function withSubscriptions() {
|
||||
$this->subscriptions = SubscriberSegment::where('subscriber_id', $this->id())
|
||||
->findArray();
|
||||
return $this;
|
||||
}
|
||||
|
||||
function getCustomField($custom_field_id, $default = null) {
|
||||
public function getCustomField($custom_field_id, $default = null) {
|
||||
$custom_field = SubscriberCustomField::select('value')
|
||||
->where('custom_field_id', $custom_field_id)
|
||||
->where('subscriber_id', $this->id())
|
||||
@ -491,7 +491,7 @@ class Subscriber extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function saveCustomFields($custom_fields_data = []) {
|
||||
public function saveCustomFields($custom_fields_data = []) {
|
||||
// get custom field ids
|
||||
$custom_field_ids = array_keys($custom_fields_data);
|
||||
|
||||
@ -510,7 +510,7 @@ class Subscriber extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function setCustomField($custom_field_id, $value) {
|
||||
public function setCustomField($custom_field_id, $value) {
|
||||
return SubscriberCustomField::createOrUpdate([
|
||||
'subscriber_id' => $this->id(),
|
||||
'custom_field_id' => $custom_field_id,
|
||||
@ -518,7 +518,7 @@ class Subscriber extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
function setUnconfirmedData(array $subscriber_data) {
|
||||
public function setUnconfirmedData(array $subscriber_data) {
|
||||
$subscriber_data = self::filterOutReservedColumns($subscriber_data);
|
||||
$encoded = json_encode($subscriber_data);
|
||||
if (is_string($encoded)) {
|
||||
@ -526,7 +526,7 @@ class Subscriber extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
function getUnconfirmedData() {
|
||||
public function getUnconfirmedData() {
|
||||
if (!empty($this->unconfirmed_data)) {
|
||||
$subscriber_data = json_decode($this->unconfirmed_data, true);
|
||||
$subscriber_data = self::filterOutReservedColumns((array)$subscriber_data);
|
||||
@ -535,7 +535,7 @@ class Subscriber extends Model {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function bulkAddToList($orm, $data = []) {
|
||||
public static function bulkAddToList($orm, $data = []) {
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
|
||||
@ -555,7 +555,7 @@ class Subscriber extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function bulkMoveToList($orm, $data = []) {
|
||||
public static function bulkMoveToList($orm, $data = []) {
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
|
||||
@ -576,7 +576,7 @@ class Subscriber extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function bulkRemoveFromList($orm, $data = []) {
|
||||
public static function bulkRemoveFromList($orm, $data = []) {
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
|
||||
@ -596,7 +596,7 @@ class Subscriber extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function bulkRemoveFromAllLists($orm, $data = []) {
|
||||
public static function bulkRemoveFromAllLists($orm, $data = []) {
|
||||
$count = $orm->count();
|
||||
|
||||
parent::bulkAction($orm, function($subscriber_ids) {
|
||||
@ -608,7 +608,7 @@ class Subscriber extends Model {
|
||||
];
|
||||
}
|
||||
|
||||
static function getTotalSubscribers() {
|
||||
public static function getTotalSubscribers() {
|
||||
return self::whereIn('status', [
|
||||
self::STATUS_SUBSCRIBED,
|
||||
self::STATUS_UNCONFIRMED,
|
||||
@ -618,13 +618,13 @@ class Subscriber extends Model {
|
||||
->count();
|
||||
}
|
||||
|
||||
static function getInactiveSubscribersCount() {
|
||||
public static function getInactiveSubscribersCount() {
|
||||
return self::where('status', self::STATUS_INACTIVE)
|
||||
->whereNull('deleted_at')
|
||||
->count();
|
||||
}
|
||||
|
||||
static function bulkTrash($orm) {
|
||||
public static function bulkTrash($orm) {
|
||||
$count = parent::bulkAction($orm, function($subscriber_ids) {
|
||||
Subscriber::rawExecute(join(' ', [
|
||||
'UPDATE `' . Subscriber::$_table . '`',
|
||||
@ -642,7 +642,7 @@ class Subscriber extends Model {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
static function bulkDelete($orm) {
|
||||
public static function bulkDelete($orm) {
|
||||
$count = parent::bulkAction($orm, function($subscriber_ids) {
|
||||
// delete all subscriber/segment relationships
|
||||
SubscriberSegment::deleteManySubscriptions($subscriber_ids);
|
||||
@ -658,37 +658,37 @@ class Subscriber extends Model {
|
||||
return ['count' => $count];
|
||||
}
|
||||
|
||||
static function subscribed($orm) {
|
||||
public static function subscribed($orm) {
|
||||
return $orm
|
||||
->whereNull('deleted_at')
|
||||
->where('status', self::STATUS_SUBSCRIBED);
|
||||
}
|
||||
|
||||
static function unsubscribed($orm) {
|
||||
public static function unsubscribed($orm) {
|
||||
return $orm
|
||||
->whereNull('deleted_at')
|
||||
->where('status', self::STATUS_UNSUBSCRIBED);
|
||||
}
|
||||
|
||||
static function unconfirmed($orm) {
|
||||
public static function unconfirmed($orm) {
|
||||
return $orm
|
||||
->whereNull('deleted_at')
|
||||
->where('status', self::STATUS_UNCONFIRMED);
|
||||
}
|
||||
|
||||
static function bounced($orm) {
|
||||
public static function bounced($orm) {
|
||||
return $orm
|
||||
->whereNull('deleted_at')
|
||||
->where('status', self::STATUS_BOUNCED);
|
||||
}
|
||||
|
||||
static function inactive($orm) {
|
||||
public static function inactive($orm) {
|
||||
return $orm
|
||||
->whereNull('deleted_at')
|
||||
->where('status', self::STATUS_INACTIVE);
|
||||
}
|
||||
|
||||
static function withoutSegments($orm) {
|
||||
public static function withoutSegments($orm) {
|
||||
return $orm->select(MP_SUBSCRIBERS_TABLE . '.*')
|
||||
->whereRaw(
|
||||
MP_SUBSCRIBERS_TABLE . '.id NOT IN (
|
||||
@ -701,7 +701,7 @@ class Subscriber extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function createMultiple($columns, $values) {
|
||||
public static function createMultiple($columns, $values) {
|
||||
return self::rawExecute(
|
||||
'INSERT INTO `' . self::$_table . '` ' .
|
||||
'(' . implode(', ', $columns) . ') ' .
|
||||
@ -716,7 +716,7 @@ class Subscriber extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function updateMultiple($columns, $subscribers, $updated_at = false) {
|
||||
public static function updateMultiple($columns, $subscribers, $updated_at = false) {
|
||||
$ignore_columns_on_update = [
|
||||
'wp_user_id',
|
||||
'is_woocommerce_user',
|
||||
@ -773,13 +773,13 @@ class Subscriber extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function findSubscribersInSegments(array $subscribers_ids, array $segments_ids) {
|
||||
public static function findSubscribersInSegments(array $subscribers_ids, array $segments_ids) {
|
||||
return self::getSubscribedInSegments($segments_ids)
|
||||
->whereIn('subscribers.id', $subscribers_ids)
|
||||
->select('subscribers.*');
|
||||
}
|
||||
|
||||
static function extractSubscribersIds(array $subscribers) {
|
||||
public static function extractSubscribersIds(array $subscribers) {
|
||||
return array_filter(
|
||||
array_map(function($subscriber) {
|
||||
return (!empty($subscriber->id)) ? $subscriber->id : false;
|
||||
@ -787,7 +787,7 @@ class Subscriber extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function setRequiredFieldsDefaultValues($data) {
|
||||
public static function setRequiredFieldsDefaultValues($data) {
|
||||
$settings = SettingsController::getInstance();
|
||||
$required_field_default_values = [
|
||||
'first_name' => '',
|
||||
@ -804,7 +804,7 @@ class Subscriber extends Model {
|
||||
return $data;
|
||||
}
|
||||
|
||||
static function extractCustomFieldsFromFromObject($data) {
|
||||
public static function extractCustomFieldsFromFromObject($data) {
|
||||
$custom_fields = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if (strpos($key, 'cf_') === 0) {
|
||||
@ -836,7 +836,7 @@ class Subscriber extends Model {
|
||||
* @see https://kb.mailpoet.com/article/195-add-subscribers-through-your-own-form-or-plugin
|
||||
* @deprecated
|
||||
*/
|
||||
static function subscribe($subscriber_data = [], $segment_ids = []) {
|
||||
public static function subscribe($subscriber_data = [], $segment_ids = []) {
|
||||
trigger_error('Calling Subscriber::subscribe() is deprecated and will be removed. Use MailPoet\API\MP\v1\API instead. ', E_USER_DEPRECATED);
|
||||
$service = ContainerWrapper::getInstance()->get(\MailPoet\Subscribers\SubscriberActions::class);
|
||||
return $service->subscribe($subscriber_data, $segment_ids);
|
||||
|
@ -14,7 +14,7 @@ use function MailPoetVendor\array_column;
|
||||
class SubscriberCustomField extends Model {
|
||||
public static $_table = MP_SUBSCRIBER_CUSTOM_FIELD_TABLE;
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
public static function createOrUpdate($data = []) {
|
||||
$custom_field = CustomField::findOne($data['custom_field_id']);
|
||||
if ($custom_field instanceof CustomField) {
|
||||
$custom_field = $custom_field->asArray();
|
||||
@ -49,7 +49,7 @@ class SubscriberCustomField extends Model {
|
||||
]);
|
||||
}
|
||||
|
||||
static function createMultiple($values) {
|
||||
public static function createMultiple($values) {
|
||||
return self::rawExecute(
|
||||
'INSERT IGNORE INTO `' . self::$_table . '` ' .
|
||||
'(custom_field_id, subscriber_id, value) ' .
|
||||
@ -63,7 +63,7 @@ class SubscriberCustomField extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function updateMultiple($values) {
|
||||
public static function updateMultiple($values) {
|
||||
$subscriber_ids = array_unique(array_column($values, 1));
|
||||
$query = sprintf(
|
||||
"UPDATE `%s` SET value = (CASE %s ELSE value END) WHERE subscriber_id IN (%s)",
|
||||
@ -77,13 +77,13 @@ class SubscriberCustomField extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function deleteSubscriberRelations($subscriber) {
|
||||
public static function deleteSubscriberRelations($subscriber) {
|
||||
if ($subscriber === false) return false;
|
||||
$relations = self::where('subscriber_id', $subscriber->id);
|
||||
return $relations->deleteMany();
|
||||
}
|
||||
|
||||
static function deleteManySubscriberRelations(array $subscriber_ids) {
|
||||
public static function deleteManySubscriberRelations(array $subscriber_ids) {
|
||||
if (empty($subscriber_ids)) return false;
|
||||
$relations = self::whereIn('subscriber_id', $subscriber_ids);
|
||||
return $relations->deleteMany();
|
||||
|
@ -12,11 +12,11 @@ namespace MailPoet\Models;
|
||||
class SubscriberSegment extends Model {
|
||||
public static $_table = MP_SUBSCRIBER_SEGMENT_TABLE;
|
||||
|
||||
function subscriber() {
|
||||
public function subscriber() {
|
||||
return $this->has_one(__NAMESPACE__ . '\Subscriber', 'id', 'subscriber_id');
|
||||
}
|
||||
|
||||
static function unsubscribeFromSegments($subscriber, $segment_ids = []) {
|
||||
public static function unsubscribeFromSegments($subscriber, $segment_ids = []) {
|
||||
if ($subscriber === false) return false;
|
||||
|
||||
// Reset confirmation emails count, so user can resubscribe
|
||||
@ -59,7 +59,7 @@ class SubscriberSegment extends Model {
|
||||
return true;
|
||||
}
|
||||
|
||||
static function resubscribeToAllSegments($subscriber) {
|
||||
public static function resubscribeToAllSegments($subscriber) {
|
||||
if ($subscriber === false) return false;
|
||||
// (re)subscribe to all segments linked to the subscriber
|
||||
return self::where('subscriber_id', $subscriber->id)
|
||||
@ -68,7 +68,7 @@ class SubscriberSegment extends Model {
|
||||
->save();
|
||||
}
|
||||
|
||||
static function subscribeToSegments($subscriber, $segment_ids = []) {
|
||||
public static function subscribeToSegments($subscriber, $segment_ids = []) {
|
||||
if ($subscriber === false) return false;
|
||||
if (!empty($segment_ids)) {
|
||||
// subscribe to specified segments
|
||||
@ -85,12 +85,12 @@ class SubscriberSegment extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static function resetSubscriptions($subscriber, $segment_ids = []) {
|
||||
public static function resetSubscriptions($subscriber, $segment_ids = []) {
|
||||
self::unsubscribeFromSegments($subscriber);
|
||||
return self::subscribeToSegments($subscriber, $segment_ids);
|
||||
}
|
||||
|
||||
static function subscribeManyToSegments(
|
||||
public static function subscribeManyToSegments(
|
||||
$subscriber_ids = [],
|
||||
$segment_ids = []
|
||||
) {
|
||||
@ -119,7 +119,7 @@ class SubscriberSegment extends Model {
|
||||
return true;
|
||||
}
|
||||
|
||||
static function deleteManySubscriptions($subscriber_ids = [], $segment_ids = []) {
|
||||
public static function deleteManySubscriptions($subscriber_ids = [], $segment_ids = []) {
|
||||
if (empty($subscriber_ids)) return false;
|
||||
|
||||
// delete subscribers' relations to segments (except WP and WooCommerce segments)
|
||||
@ -147,7 +147,7 @@ class SubscriberSegment extends Model {
|
||||
return $subscriptions->deleteMany();
|
||||
}
|
||||
|
||||
static function deleteSubscriptions($subscriber, $segment_ids = []) {
|
||||
public static function deleteSubscriptions($subscriber, $segment_ids = []) {
|
||||
if ($subscriber === false) return false;
|
||||
|
||||
$wp_segment = Segment::getWPSegment();
|
||||
@ -162,11 +162,11 @@ class SubscriberSegment extends Model {
|
||||
return $subscriptions->deleteMany();
|
||||
}
|
||||
|
||||
static function subscribed($orm) {
|
||||
public static function subscribed($orm) {
|
||||
return $orm->where('status', Subscriber::STATUS_SUBSCRIBED);
|
||||
}
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
public static function createOrUpdate($data = []) {
|
||||
$keys = false;
|
||||
if (isset($data['subscriber_id']) && isset($data['segment_id'])) {
|
||||
$keys = [
|
||||
|
@ -9,7 +9,7 @@ use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
||||
|
||||
class SubscribersInDynamicSegment extends Subscriber {
|
||||
|
||||
static function listingQuery(array $data = []) {
|
||||
public static function listingQuery(array $data = []) {
|
||||
$query = self::select(self::$_table . '.*');
|
||||
$single_segment_loader = new SingleSegmentLoader(new DBMapper());
|
||||
$dynamic_segment = $single_segment_loader->load($data['filter']['segment']);
|
||||
|
Reference in New Issue
Block a user