394 lignes
11 KiB
PHP
Brut Vue normale Historique

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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->getDateTimeFromValue($this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
$this->set(SubscriberEndpoint::EMAIL, $emailAddress);
2025-01-01 22:25:47 +01:00
// 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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->getDateTimeFromValue($this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->getDateTimeFromValue($this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::SMS_PHONE);
2024-12-22 23:38:12 +01:00
}
2025-01-01 22:25:47 +01:00
public function setSmsPhone(string $smsPhone): void
2024-12-22 23:38:12 +01:00
{
2025-01-03 00:05:00 +01:00
$this->set(SubscriberEndpoint::SMS_PHONE, $smsPhone);
2025-01-01 22:25:47 +01:00
// 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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->getDateTimeFromValue($this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->getDateTimeFromValue($this->get(SubscriberEndpoint::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-03 00:05:00 +01:00
return $this->get(SubscriberEndpoint::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
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-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::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
}
public function clearTags(): void
{
$tags = $this->getTags();
$tags->clear();
2025-01-03 00:05:00 +01:00
$this->set(SubscriberEndpoint::TAGS, $tags->toArray());
// use persist method to send to Klicktipp
}
public function addTag(string $tagId): void
{
$tags = $this->getTags();
$tags->add($tagId);
2025-01-03 00:05:00 +01:00
$this->set(SubscriberEndpoint::TAGS, $tags->toArray());
// use persist method to send to Klicktipp
}
public function removeTag(string $tagId): void
{
$tags = $this->getTags();
$tags->removeElement($tagId);
2025-01-03 00:05:00 +01:00
$this->set(SubscriberEndpoint::TAGS, $tags->toArray());
// use persist method to send to Klicktipp
}
2025-01-01 22:25:47 +01:00
/**
* manuelle Tags
*/
public function getManualTags(): ArrayCollection
2024-12-20 23:46:48 +01:00
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::MANUALTAGS) ?? []);
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
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::SMARTTAGS) ?? []);
2025-01-01 22:25:47 +01:00
}
public function getSmartTagTime(string $tagId): ?DateTime
{
return $this->getDateTimeFromValue($this->getSmartTags()->get($tagId));
}
/**
* Kampagne gestartet
*/
public function getStartedCampaigns(): ArrayCollection
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::CAMPAIGNSSTARTED) ?? []);
2025-01-01 22:25:47 +01:00
}
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-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::CAMPAIGNSFINISHED) ?? []);
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
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::NOTIFICATIONEMAILSSENT) ?? []);
2025-01-01 22:25:47 +01:00
}
/**
* Email (Marketing Cockpit) geoeffnet
*/
public function getOpenedNotificationEmails(): ArrayCollection
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::NOTIFICATIONEMAILSOPENED) ?? []);
2025-01-01 22:25:47 +01:00
}
/**
* Email (Marketing Cockpit) geklickt
*/
public function getClickedNotificationEmails(): ArrayCollection
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::NOTIFICATIONEMAILSCLICKED) ?? []);
2025-01-01 22:25:47 +01:00
}
/**
* Email (Marketing Cockpit) im Webbrowser angesehen
*/
public function getViewedNotificationEmails(): ArrayCollection
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::NOTIFICATIONEMAILSVIEWED) ?? []);
2025-01-01 22:25:47 +01:00
}
/**
* Outbound ausgeloest
*/
public function getOutbounds(): ArrayCollection
{
2025-01-03 00:05:00 +01:00
return new ArrayCollection($this->get(SubscriberEndpoint::OUTBOUND) ?? []);
2025-01-01 22:25:47 +01:00
}
/**
2025-01-02 23:52:24 +01:00
* @return null|bool
2025-01-01 22:25:47 +01:00
* @throws BaseException
*/
public function persist(): ?bool
2025-01-01 22:25:47 +01:00
{
$return = $this->endpoint?->update(
2025-01-01 22:25:47 +01:00
$this->getId(),
$this->getFields()->toArray(),
$this->getEmailAddress(),
$this->getSmsPhone()
);
$this->persistTags();
return $return;
}
/**
* @throws BaseException
*/
protected function persistTags(): void
{
if (!$this->endpoint instanceof SubscriberEndpoint) {
return;
}
$currentTags = $this->endpoint->getEntity($this->getId())->getTags();
2025-01-02 23:52:24 +01:00
$removeTags = array_diff($currentTags->toArray(), $this->getTags()->toArray());
if (count($removeTags)) {
foreach ($removeTags as $removeTag) {
$this->endpoint->untag($this->getEmailAddress(), $removeTag);
}
}
2025-01-02 23:52:24 +01:00
$addTags = array_diff($this->getTags()->toArray(), $currentTags->toArray());
if (count($addTags)) {
$this->endpoint->tag($this->getEmailAddress(), $addTags);
}
2025-01-01 22:25:47 +01:00
}
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
}