Newer
Older
'cancelUntilDate' => $this->formatDate($CancelUntilDate),
'cycleEndDate' => $cycleEndDate,
'nextCycleEndDate' => $nextCycleEndDate
]
);
} else {
$cancelInfoText = QUI::getLocale()->get(
'quiqqer/memberships',
'MembershipUser.cancel.info_text.period_of_notice_expired',
[
'addedDate' => $addedDate,
'cancelUntilDate' => $this->formatDate($CancelUntilDate),
'cycleBeginDate' => $cycleBeginDate,
'cycleEndDate' => $cycleEndDate,
'nextCycleEndDate' => $nextCycleEndDate
]
);
}
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
} else {
$cancelInfoText = QUI::getLocale()->get(
'quiqqer/memberships',
'MembershipUser.cancel.info_text.cycle_cancel_anytime',
[
'addedDate' => $addedDate,
'cycleEndDate' => $cycleEndDate,
'nextCycleEndDate' => $nextCycleEndDate
]
);
}
} elseif ($this->getMembership()->isInfinite()) {
$cancelInfoText = QUI::getLocale()->get(
'quiqqer/memberships',
'MembershipUser.cancel.info_text.cancel_anytime'
);
} else {
$cancelInfoText = QUI::getLocale()->get(
'quiqqer/memberships',
'MembershipUser.cancel.info_text.cycle_cancel_anytime',
[
'addedDate' => $addedDate,
'cycleEndDate' => $cycleEndDate,
'nextCycleEndDate' => $nextCycleEndDate
]
);
}
return [
'id' => $this->getId(),
'userId' => $QuiqqerUser->getId(),
'membershipId' => $Membership->getId(),
'membershipTitle' => $title,
'membershipShort' => $description,
'membershipContent' => $content,
'username' => $QuiqqerUser->getUsername(),
'fullName' => $QuiqqerUser->getName(),
'beginDate' => $cycleBeginDate,
'endDate' => $cycleEndDate,
'cancelEndDate' => $this->formatDate($CurrentCancelEndDate),
'cancelDate' => $this->formatDate($this->getAttribute('cancelDate')),
// 'cancelUntilDate' => $CancelUntilDate ? $this->formatDate($CancelUntilDate) : false,
'cancelStatus' => $this->getAttribute('cancelStatus'),
'cancelAllowed' => $cancelAllowed,
'cancelInfoText' => $cancelInfoText,
// 'archived' => $this->isArchived(),
// 'archiveReason' => $this->getAttribute('archiveReason'),
'cancelled' => $this->isCancelled(),
'autoExtend' => $Membership->isAutoExtend(),
'infinite' => $Membership->isInfinite()

Patrick Müller
committed
}
/**
* Get membership data for backend view/edit purposes
*
* @return array
*/
public function getBackendViewData()
{
$QuiqqerUser = $this->getUser();
$Membership = $this->getMembership();
return [
'id' => $this->getId(),
'userId' => $this->getUserId(),
'membershipId' => $Membership->getId(),
'membershipTitle' => $Membership->getTitle(),
'username' => $QuiqqerUser ? $QuiqqerUser->getUsername() : '-',
'firstname' => $QuiqqerUser ? $QuiqqerUser->getAttribute('firstname') : '-',
'lastname' => $QuiqqerUser ? $QuiqqerUser->getAttribute('lastname') : '-',
'fullName' => $QuiqqerUser ? $QuiqqerUser->getName() : '-',
'addedDate' => $this->getAttribute('addedDate'),
'beginDate' => $this->getAttribute('beginDate'),
'endDate' => $this->getAttribute('endDate'),
'archived' => $this->isArchived(),
'archiveReason' => $this->getAttribute('archiveReason'),
'archiveDate' => $this->getAttribute('archiveDate'),
'cancelled' => $this->isCancelled(),

Patrick Müller
committed
'infinite' => $Membership->isInfinite(),
'contractId' => $this->getContractId()
/**
* Get Verification object for MembershipUser cancellation
*
* @return CancelVerification
*/
protected function getCancelVerification()
{
return new CancelVerification($this->id);
}
/**
* Get Verification object for MembershipUser cancel abort
*
* @return AbortCancelVerification
*/
protected function getAbortCancelVerification()
{
return new AbortCancelVerification($this->id);
}
/**
* Send an email to the membership user
*
* @param string $subject - mail subject
* @param string $templateFile
* @param array $templateVars (optional) - additional template variables (besides $this)
* @return void
* @throws \QUI\Exception
public function sendMail($subject, $templateFile, $templateVars = [])
$User = $this->getUser();
$email = $User->getAttribute('email');
if (empty($email)) {
QUI\System\Log::addError(
'Could not send mail to user #'.$User->getId().' because the user has'
.' no email address!'
);
$Engine = QUI::getTemplateManager()->getEngine();
$Engine->assign(array_merge(

Patrick Müller
committed
'Locale' => $this->getUser()->getLocale(),
'data' => $this->getFrontendViewData()
$templateVars
));
$template = $Engine->fetch($templateFile);
$Mailer = new Mailer();
$Mailer->addRecipient($email, $User->getName());
$Mailer->setSubject($subject);
$Mailer->setBody($template);
$Mailer->send();
}
/**
* Set any extra text data to the MembershipUser
*
* This is meant for extra information that is not already covered by the history.
*
* @param string $key
* @param string $value
*/
public function setExtraData($key, $value)
{
$extraData = $this->getExtraData();
$User = QUI::getUserBySession();
$userString = $User->getName().' ('.$User->getId().')';
$editString = Utils::getFormattedTimestamp().' - '.$userString;
if (isset($extraData[$key])) {
$extraData[$key]['edit'] = $editString;
$extraData[$key]['value'] = $value;
} else {
$extraData[$key] = [
'value' => $value,
'add' => $editString,
'edit' => '-'
}
$this->setAttribute('extraData', json_encode($extraData));
}
/**
* Get extra data of this MembershipUser
*
* @param string $key (optional) - If omitted return all extra data
* @return array|string|false
*/
public function getExtraData($key = null)
{
$extraData = $this->getAttribute('extraData');
if (empty($extraData)) {
$extraData = [];
} else {
$extraData = json_decode($extraData, true);
}
if (is_null($key)) {
return $extraData;
}
if (!array_key_exists($key, $extraData)) {
return false;
}
return $extraData[$key]['value'];
}

Patrick Müller
committed
/**
* Get begin Date of the current cycle

Patrick Müller
committed
*
* @return \DateTime
*/
public function getCycleBeginDate()

Patrick Müller
committed
{
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
return \date_create($this->getAttribute('beginDate'));
}
/**
* Get end Date of the current cycle
*
* @return \DateTime|false - DateTime of the cycle end or false if Membership has no cycle end (i.e. is infinite)
*/
public function getCycleEndDate()
{
$Contract = $this->getContract();
if ($Contract) {
return $Contract->getCycleEndDate();
}
if ($this->getMembership()->isInfinite()) {
return false;
}
return \date_create($this->getAttribute('endDate'));
}
/**
* Get begin date of the (hypothetical) next cycle
*
* @return \DateTime|false - DateTime of the cycle end or false if Membership has no next cycle (i.e. is infinite)
*/
public function getNextCycleBeginDate()
{
$Contract = $this->getContract();
if ($Contract) {
$EndDate = $Contract->getCycleEndDate();
$NextBeginDate = clone $EndDate;
$NextBeginDate->add(\date_interval_create_from_date_string('1 day'));
$NextBeginDate->setTime(0, 0, 0);
return $NextBeginDate;
}
if ($this->getMembership()->isInfinite()) {
return false;
}
$EndDate = $this->getCycleEndDate();
if (!$EndDate) {
}
if (MembershipUsersHandler::getExtendMode() === MembershipUsersHandler::EXTEND_MODE_PROLONG) {
return $this->getCycleBeginDate();
}

Patrick Müller
committed
$NextBeginDate = clone $EndDate;
switch (MembershipUsersHandler::getDurationMode()) {
case MembershipUsersHandler::DURATION_MODE_EXACT:
$NextBeginDate->add(\date_interval_create_from_date_string('1 second'));
break;
default:
$NextBeginDate->add(\date_interval_create_from_date_string('1 day'));
$NextBeginDate->setTime(0, 0, 0);

Patrick Müller
committed
}
return $NextBeginDate;
}
/**
* Get the end Date of the (hypothetical) next cycle
*
* @return \DateTime|false - DateTime of the next cycle end or false if Membership has no next cycle end (i.e. is infinite)
*/
public function getNextCycleEndDate()
{
$Contract = $this->getContract();
if ($Contract) {
return $Contract->getNextCycleEndDate();
}

Patrick Müller
committed
$Membership = $this->getMembership();
if ($Membership->isInfinite()) {
return false;

Patrick Müller
committed
}
$NextCycleBeginDate = $this->getNextCycleBeginDate();
if (!$NextCycleBeginDate) {
return false;
}
$start = $NextCycleBeginDate->format('Y-m-d');
$duration = explode('-', $Membership->getAttribute('duration'));
$durationCount = $duration[0];
$durationScope = $duration[1];
switch (MembershipUsersHandler::getDurationMode()) {
case MembershipUsersHandler::DURATION_MODE_DAY:
$endTime = strtotime($start.' +'.$durationCount.' '.$durationScope);
$beginOfDay = strtotime("midnight", $endTime);
$end = strtotime("tomorrow", $beginOfDay) - 1;
break;
default:
$end = strtotime($start.' +'.$durationCount.' '.$durationScope);
}
return \date_create('@'.$end);
}
/**
* Calculates the date the membership for this user would end
* if it was cancelled NOW
*
* @return \DateTime
*/
public function getCurrentCancelEndDate()
{
/**
* If a contract is connected to this MembershipUser
* the contract cancel termination date has priority!
*/
$Contract = $this->getContract();
if ($Contract) {
try {
return $Contract->getCurrentCancelTerminationDate();
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
return $this->getCycleEndDate();

Patrick Müller
committed
}