<?php namespace MailPoet\Models; if (!defined('ABSPATH')) exit; use MailPoet\Util\Helpers; /** * @property int $subscriberId * @property int $customFieldId * @property string $value */ class SubscriberCustomField extends Model { public static $_table = MP_SUBSCRIBER_CUSTOM_FIELD_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration public static function createOrUpdate($data = []) { $customField = CustomField::findOne($data['custom_field_id']); if ($customField instanceof CustomField) { $customField = $customField->asArray(); } else { return false; } if ($customField['type'] === 'date') { if (is_array($data['value'])) { $day = ( isset($data['value']['day']) ? (int)$data['value']['day'] : 1 ); $month = ( isset($data['value']['month']) ? (int)$data['value']['month'] : 1 ); $year = ( isset($data['value']['year']) ? (int)$data['value']['year'] : 1970 ); $data['value'] = mktime(0, 0, 0, $month, $day, $year); } } return parent::_createOrUpdate($data, [ 'custom_field_id' => $data['custom_field_id'], 'subscriber_id' => $data['subscriber_id'], ]); } public static function createMultiple($values) { return self::rawExecute( 'INSERT IGNORE INTO `' . self::$_table . '` ' . '(custom_field_id, subscriber_id, value) ' . 'VALUES ' . rtrim( str_repeat( '(?, ?, ?)' . ', ', count($values) ), ', ' ), Helpers::flattenArray($values) ); } public static function updateMultiple($values) { $subscriberIds = array_unique(array_column($values, 1)); $query = sprintf( "UPDATE `%s` SET value = (CASE %s ELSE value END) WHERE subscriber_id IN (%s)", self::$_table, str_repeat('WHEN custom_field_id = ? AND subscriber_id = ? THEN ? ', count($values)), implode(',', $subscriberIds) ); self::rawExecute( $query, Helpers::flattenArray($values) ); } public static function deleteSubscriberRelations($subscriber) { if ($subscriber === false) return false; $relations = self::where('subscriber_id', $subscriber->id); return $relations->deleteMany(); } public static function deleteManySubscriberRelations(array $subscriberIds) { if (empty($subscriberIds)) return false; $relations = self::whereIn('subscriber_id', $subscriberIds); return $relations->deleteMany(); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
CustomField.php | File | 3.79 KB | 0644 |
|
DynamicSegment.php | File | 4.05 KB | 0644 |
|
DynamicSegmentFilter.php | File | 1.35 KB | 0644 |
|
Form.php | File | 4.02 KB | 0644 |
|
MappingToExternalEntities.php | File | 378 B | 0644 |
|
Model.php | File | 13.58 KB | 0644 |
|
ModelValidator.php | File | 2.44 KB | 0644 |
|
Newsletter.php | File | 15.14 KB | 0644 |
|
NewsletterLink.php | File | 530 B | 0644 |
|
NewsletterOption.php | File | 670 B | 0644 |
|
NewsletterOptionField.php | File | 939 B | 0644 |
|
NewsletterSegment.php | File | 312 B | 0644 |
|
ScheduledTask.php | File | 6.58 KB | 0644 |
|
ScheduledTaskSubscriber.php | File | 5.31 KB | 0644 |
|
Segment.php | File | 10.89 KB | 0644 |
|
SendingQueue.php | File | 4.31 KB | 0644 |
|
StatisticsClicks.php | File | 1.08 KB | 0644 |
|
StatisticsForms.php | File | 1.85 KB | 0644 |
|
StatisticsNewsletters.php | File | 1.61 KB | 0644 |
|
StatisticsOpens.php | File | 807 B | 0644 |
|
StatisticsUnsubscribes.php | File | 821 B | 0644 |
|
StatisticsWooCommercePurchases.php | File | 1.5 KB | 0644 |
|
Subscriber.php | File | 20.83 KB | 0644 |
|
SubscriberCustomField.php | File | 2.5 KB | 0644 |
|
SubscriberIP.php | File | 1.12 KB | 0644 |
|
SubscriberSegment.php | File | 5.2 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|