Skip to content
Code-Schnipsel Gruppen Projekte
Commit e610f468 erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

Merge branch 'dev' of https://dev.quiqqer.com/quiqqer/memberships into dev

Übergeordnete 6214c0cf 9425aa90
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -26,7 +26,7 @@ function ($searchParams) {
'title' => $Membership->getTitle(),
'description' => $Membership->getDescription(),
'duration' => $data['duration'],
'userCount' => 0,
'userCount' => count($Membership->getMembershipUserIds()),
'autoExtend' => boolval($data['autoExtend'])
);
}
......
......@@ -5,8 +5,6 @@
<event on="onQuiqqerOrderSuccessful" fire="\QUI\Memberships\Events::onQuiqqerOrderSuccessful" priority="5"/>
<event on="onQuiqqerProductsFieldDeleteBefore" fire="\QUI\Memberships\Events::onQuiqqerProductsFieldDeleteBefore"/>
<event on="onQuiqqerContractCreateFromOrder" fire="\QUI\Memberships\Events::onQuiqqerContractCreateFromOrder"/>
<event on="onQuiqqerContractCancel" fire="\QUI\Memberships\Events::onQuiqqerContractCancel"/>
<event on="onQuiqqerContractDelete" fire="\QUI\Memberships\Events::onQuiqqerContractDelete"/>
<event on="onQuiqqerContractsCreateFromOrder" fire="\QUI\Memberships\Events::onQuiqqerContractsCreateFromOrder"/>
<event on="onQuiqqerContractsDelete" fire="\QUI\Memberships\Events::onQuiqqerContractsDelete"/>
</events>
\ No newline at end of file
......@@ -43,11 +43,11 @@ public static function onPackageSetup(Package $Package)
case 'quiqqer/products':
self::createProductFields();
self::createProductCategory();
break;
continue 2;
case 'quiqqer/contracts':
// @todo setup routine for quiqqer/contracts
break;
continue 2;
}
}
} catch (\Exception $Exception) {
......@@ -282,10 +282,10 @@ public static function onQuiqqerOrderSuccessful($Order)
* If a contract is created from an order, check if the Order also contains a
*
* @param Contract $Contract
* @param Order $Order
* @param QUI\ERP\Order\OrderInProcess $Order
* @return void
*/
public static function onQuiqqerContractsCreateFromOrder(Contract $Contract, Order $Order)
public static function onQuiqqerContractsCreateFromOrder(Contract $Contract, $Order)
{
$MembershipField = Handler::getProductMembershipField();
......@@ -318,6 +318,7 @@ public static function onQuiqqerContractsCreateFromOrder(Contract $Contract, Ord
break;
} catch (\QUI\ERP\Products\Product\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
// nothing, this can happen if the $Product does not have a membership field assigned
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
......@@ -325,42 +326,43 @@ public static function onQuiqqerContractsCreateFromOrder(Contract $Contract, Ord
}
}
/**
* quiqqer/contracts: onQuiqqerContractsCancel
*
* Cancel a membership if a contract is cancelled
*
* @param Contract $Contract
* @return void
* @throws \QUI\Exception
* @throws \Exception
*/
public static function onQuiqqerContractsCancel(Contract $Contract)
{
$MembershipUsers = MembershipUsersHandler::getInstance();
$result = QUI::getDataBase()->fetch([
'select' => ['id'],
'from' => $MembershipUsers->getDataBaseTableName(),
'where' => [
'contractId' => $Contract->getCleanId()
]
]);
if (empty($result)) {
return;
}
/** @var QUI\Memberships\Users\MembershipUser $MembershipUser */
$MembershipUser = $MembershipUsers->getChild($result[0]['id']);
$MembershipUser->setAttributes([
'cancelStatus' => MembershipUsersHandler::CANCEL_STATUS_CANCELLED,
'cancelEndDate' => $Contract->getTerminationDate()->format('Y-m-d 23:59:59')
]);
$MembershipUser->sendConfirmCancelMail();
}
// /**
// * quiqqer/contracts: onQuiqqerContractsCancel
// *
// * Cancel a membership if a contract is cancelled
// *
// * @param Contract $Contract
// * @return void
// * @throws \QUI\Exception
// * @throws \Exception
// */
// public static function onQuiqqerContractsCancel(Contract $Contract)
// {
// $MembershipUsers = MembershipUsersHandler::getInstance();
//
// $result = QUI::getDataBase()->fetch([
// 'select' => ['id'],
// 'from' => $MembershipUsers->getDataBaseTableName(),
// 'where' => [
// 'contractId' => $Contract->getCleanId()
// ]
// ]);
//
// if (empty($result)) {
// return;
// }
//
// /** @var QUI\Memberships\Users\MembershipUser $MembershipUser */
// $MembershipUser = $MembershipUsers->getChild($result[0]['id']);
//
// $MembershipUser->setAttributes([
// 'cancelStatus' => MembershipUsersHandler::CANCEL_STATUS_CANCELLED,
// 'cancelEndDate' => $Contract->getTerminationDate()->format('Y-m-d 23:59:59')
// ]);
//
//
// $MembershipUser->sendConfirmCancelMail();
// }
/**
* quiqqer/contracts: onQuiqqerContractsDelete
......
......@@ -234,6 +234,43 @@ public function getMembershipUser($userId)
return MembershipUsersHandler::getInstance()->getChild($result[0]['id']);
}
/**
* Get all membership user IDs
*
* @param bool $includeArchived (optional) - Include archived MembershipUsers
* @return int[]
*/
public function getMembershipUserIds($includeArchived = false)
{
$membershipUserIds = [];
$where = [
'membershipId' => $this->id,
'archived' => 0
];
if ($includeArchived) {
unset($where['archived']);
}
try {
$result = QUI::getDataBase()->fetch([
'select' => 'id',
'from' => QUI\Memberships\Users\Handler::getInstance()->getDataBaseTableName(),
'where' => $where
]);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
return $membershipUserIds;
}
foreach ($result as $row) {
$membershipUserIds[] = $row['id'];
}
return $membershipUserIds;
}
/**
* Get IDs of all QUIQQER Groups that are UNIQUE to this membership
*
......
......@@ -330,6 +330,8 @@ public function confirmAbortCancel()
$this->addHistoryEntry(MembershipUsersHandler::HISTORY_TYPE_CANCEL_ABORT_CONFIRM);
$this->update(false);
QUI::getEvents()->fireEvent('quiqqerMembershipsCancelAbort', [$this]);
}
/**
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren