8
0

345 Zeilen
9.0 KiB
PHP

2024-12-20 23:46:48 +01:00
<?php
2024-12-29 00:47:30 +01:00
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
2024-12-20 23:46:48 +01:00
namespace D3\KlicktippPhpClient\Entities;
2025-01-01 22:25:47 +01:00
use D3\KlicktippPhpClient\Exceptions\BaseException;
use D3\KlicktippPhpClient\Resources\Subscriber as SubscriberEndpoint;
2024-12-22 23:38:12 +01:00
use DateTime;
2024-12-20 23:46:48 +01:00
use Doctrine\Common\Collections\ArrayCollection;
2025-01-01 22:25:47 +01:00
use Exception;
2024-12-20 23:46:48 +01:00
class Subscriber extends ArrayCollection
{
2024-12-22 23:38:12 +01:00
public const STATUS_SUBSCRIBED = 'subscribed';
public const BOUNCE_NOTBOUNCED = 'Not Bounced';
2025-01-01 22:25:47 +01:00
private ?SubscriberEndpoint $endpoint;
public function __construct(array $elements = [], ?SubscriberEndpoint $endpoint = null)
2024-12-20 23:46:48 +01:00
{
2025-01-01 22:25:47 +01:00
$this->endpoint = $endpoint;
parent::__construct($elements);
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getId(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('id');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getListId(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('listid');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getOptinTime(): ?DateTime
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getDateTimeFromValue($this->get('optin'));
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function isOptedIn(): bool
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getOptinTime() !== null &&
$this->getOptinTime() > new DateTime('0000-00-00 00:00:00') &&
$this->getOptinTime() < new DateTime();
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getOptinIp(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('optin_ip');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getEmailAddress(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('email');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function changeEmailAddress(string $emailAddress): void
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
$this->set('email', $emailAddress);
// use persist method to send to Klicktipp
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getStatus(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('status');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function isSubscribed(): bool
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getStatus() === self::STATUS_SUBSCRIBED;
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getBounce(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('bounce');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function isBounced(): bool
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getBounce() !== self::BOUNCE_NOTBOUNCED;
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getDate(): ?DateTime
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getDateTimeFromValue($this->get('date'));
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getIp(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('ip');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getUnsubscription(): ?DateTime
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getDateTimeFromValue($this->get('unsubscription'));
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getUnsubscriptionIp(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('unsubscription_ip');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getReferrer(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('referrer');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getSmsPhone(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('sms_phone');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
/**
* @throws BaseException
*/
public function setSmsPhone(string $smsPhone): void
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
$this->set('sms_phone', $smsPhone);
// use persist method to send to Klicktipp
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getSmsStatus(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('sms_status');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getSmsBounce(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('sms_bounce');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getSmsDate(): ?DateTime
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getDateTimeFromValue($this->get('sms_date'));
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getSmsUnsubscription(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getDateTimeFromValue($this->get('sms_unsubscription'));
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getSmsReferrer(): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->get('sms_referrer');
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getFields(): ArrayCollection
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->filter(
function ($value, $key) {
return str_starts_with($key, 'field');
}
);
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getField(string $fieldId): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getFields()->get($this->getFieldLongName($fieldId));
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
/**
* @throws BaseException
*/
public function setField(string $fieldId, string $value): void
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
$this->set($this->getFieldLongName($fieldId), $value);
// use persist method to send to Klicktipp
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
protected function getFieldLongName(string $fieldId): ?string
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return str_starts_with($fieldId, 'field') ? trim($fieldId) : 'field'.trim($fieldId);
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getTags(): ArrayCollection
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return new ArrayCollection($this->get('tags') ?? []);
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function isTagSet(string $tagId): bool
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getTags()->contains($tagId);
2024-12-20 23:46:48 +01:00
}
2025-01-01 22:25:47 +01:00
/**
* manuelle Tags
*/
public function getManualTags(): ArrayCollection
2024-12-20 23:46:48 +01:00
{
2025-01-01 22:25:47 +01:00
return new ArrayCollection($this->get('manual_tags') ?? []);
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function isManualTagSet(string $tagId): bool
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getManualTags()->containsKey($tagId);
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getManualTagTime(string $tagId): ?DateTime
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return $this->getDateTimeFromValue($this->getManualTags()->get($tagId));
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function getSmartTags(): ArrayCollection
{
return new ArrayCollection($this->get('smart_tags') ?? []);
}
public function getSmartTagTime(string $tagId): ?DateTime
{
return $this->getDateTimeFromValue($this->getSmartTags()->get($tagId));
}
/**
* Kampagne gestartet
*/
public function getStartedCampaigns(): ArrayCollection
{
return new ArrayCollection($this->get('campaigns_started') ?? []);
}
public function getStartedCampaignTime(string $campaignId): ?DateTime
{
return $this->getDateTimeFromValue($this->getStartedCampaigns()->get($campaignId));
}
/**
* Kampagne beendet
*/
public function getFinishedCampaigns(): ArrayCollection
2024-12-22 23:38:12 +01:00
{
2025-01-01 22:25:47 +01:00
return new ArrayCollection($this->get('campaigns_finished') ?? []);
2024-12-20 23:46:48 +01:00
}
2025-01-01 22:25:47 +01:00
public function getFinishedCampaignTime(string $campaignId): ?DateTime
{
return $this->getDateTimeFromValue($this->getFinishedCampaigns()->get($campaignId));
}
/**
* Email (Marketing Cockpit) erhalten
*/
public function getSentNotificationEmails(): ArrayCollection
{
return new ArrayCollection($this->get('notification_emails_sent') ?? []);
}
/**
* Email (Marketing Cockpit) geoeffnet
*/
public function getOpenedNotificationEmails(): ArrayCollection
{
return new ArrayCollection($this->get('notification_emails_opened') ?? []);
}
/**
* Email (Marketing Cockpit) geklickt
*/
public function getClickedNotificationEmails(): ArrayCollection
{
return new ArrayCollection($this->get('notification_emails_clicked') ?? []);
}
/**
* Email (Marketing Cockpit) im Webbrowser angesehen
*/
public function getViewedNotificationEmails(): ArrayCollection
{
return new ArrayCollection($this->get('notification_emails_viewed') ?? []);
}
/**
* Outbound ausgeloest
*/
public function getOutbounds(): ArrayCollection
{
return new ArrayCollection($this->get('outbound') ?? []);
}
/**
* @return bool
* @throws BaseException
*/
public function persist(): bool
{
return $this->endpoint?->update(
$this->getId(),
$this->getFields()->toArray(),
$this->getEmailAddress(),
$this->getSmsPhone()
);
}
protected function getDateTimeFromValue($value): ?DateTime
{
try {
return $value ?
new DateTime((string)$value) :
null;
} catch (Exception) {
return null;
}
}
// missing getters (return is timestamp list)
// smart_links SmartLinks
// emails_sent Newsletter / Autoresponder erhalten
// emails_opened Newsletter / Autoresponder geoeffnet
// emails_clicked Newsletter / Autoresponder geklickt
// emails_viewed Newsletter / Autoresponder im Webbrowser angesehen
// conversions Newsletter / Autoresponder Conversion-Pixel geladen
// kajabi_activated Kajabi Membership aktiviert
// kajabi_deactivated Kajabi Membership deaktiviert
// taggingpixel_triggered Tagging-Pixel ausgeloest
// notification_sms_sent SMS (Marketing Cockpit) erhalten
// notification_sms_clicked SMS (Marketing Cockpit) geklickt
// api_subscriptions Via API-Key eingetragen
// email_subscriptions Via E-Mail eingetragen
// sms_subscriptions Via SMS eingetragen
// form_subscriptions Via Anmeldeformular
// facebook_subscriptions Via Facebook-Button eingetragen
// payments Zahlung eingegangen
// refunds Rueckzahlung ausgeloest
// chargebacks Chargeback ausgeloest
// rebills_canceled Abo gekuendigt
// rebills_resumed Abo wiederaufgenommen
// rebills_expired Letzten Tag des Abo erreicht
// digistore_affiliations Affiliate eines Digistore24-Produkts
2024-12-29 00:47:30 +01:00
}