-{include file='header' pageTitle='wcf.acp.paidSubscription.user.add'}
+{include file='header' pageTitle='wcf.acp.paidSubscription.user.'|concat:$action}
-<script data-relocate="true">
- $(function() {
- new WCF.Search.User('#username');
- });
-</script>
+{if $action == 'add'}
+ <script data-relocate="true">
+ $(function() {
+ new WCF.Search.User('#username');
+ });
+ </script>
+{/if}
<header class="contentHeader">
<div class="contentHeaderTitle">
- <h1 class="contentTitle">{lang}wcf.acp.paidSubscription.user.add{/lang}</h1>
- <p class="contentHeaderDescription">{$subscription->title|language}</p>
+ <h1 class="contentTitle">{lang}wcf.acp.paidSubscription.user.{$action}{/lang}</h1>
+ {if $action == 'add'}
+ <p class="contentHeaderDescription">{$subscription->title|language}</p>
+ {else}
+ <p class="contentHeaderDescription">{$subscriptionUser->getUser()->username}</p>
+ {/if}
</div>
<nav class="contentHeaderNavigation">
<ul>
- <li><a href="{link controller='PaidSubscriptionList'}{/link}" class="button"><span class="icon icon16 fa-list"></span> <span>{lang}wcf.acp.menu.link.paidSubscription.list{/lang}</span></a></li>
+ {if $action == 'add'}
+ <li><a href="{link controller='PaidSubscriptionList'}{/link}" class="button"><span class="icon icon16 fa-list"></span> <span>{lang}wcf.acp.menu.link.paidSubscription.list{/lang}</span></a></li>
+ {else}
+ <li><a href="{link controller='PaidSubscriptionUserList'}{/link}" class="button"><span class="icon icon16 fa-list"></span> <span>{lang}wcf.acp.menu.link.paidSubscription.user.list{/lang}</span></a></li>
+ {/if}
{event name='contentHeaderNavigation'}
</ul>
{include file='formError'}
{if $success|isset}
- <p class="success">{lang}wcf.global.success.add{/lang}</p>
+ <p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
{/if}
-<form method="post" action="{link controller='PaidSubscriptionUserAdd' id=$subscriptionID}{/link}">
+<form method="post" action="{if $action == 'add'}{link controller='PaidSubscriptionUserAdd' id=$subscriptionID}{/link}{else}{link controller='PaidSubscriptionUserEdit' id=$subscriptionUserID}{/link}{/if}">
<div class="section">
- <dl{if $errorField == 'username'} class="formError"{/if}>
- <dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
- <dd>
- <input type="text" id="username" name="username" value="{$username}" autofocus class="medium">
- {if $errorField == 'username'}
- <small class="innerError">
- {if $errorType == 'empty'}
- {lang}wcf.global.form.error.empty{/lang}
- {else}
- {lang}wcf.user.username.error.{@$errorType}{/lang}
- {/if}
- </small>
- {/if}
- </dd>
- </dl>
+ {if $action == 'add'}
+ <dl{if $errorField == 'username'} class="formError"{/if}>
+ <dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
+ <dd>
+ <input type="text" id="username" name="username" value="{$username}" autofocus class="medium">
+ {if $errorField == 'username'}
+ <small class="innerError">
+ {if $errorType == 'empty'}
+ {lang}wcf.global.form.error.empty{/lang}
+ {else}
+ {lang}wcf.user.username.error.{@$errorType}{/lang}
+ {/if}
+ </small>
+ {/if}
+ </dd>
+ </dl>
+ {/if}
{if $subscription->subscriptionLength}
<dl{if $errorField == 'endDate'} class="formError"{/if}>
<script data-relocate="true">
$(function() {
new WCF.Action.Delete('wcf\\data\\paid\\subscription\\user\\PaidSubscriptionUserAction', '.jsPaidSubscriptionUserRow');
+ new WCF.Search.User('#username');
});
</script>
{/hascontent}
</header>
+<form method="post" action="{link controller='PaidSubscriptionUserList'}{/link}">
+ <section class="section">
+ <h2 class="sectionTitle">{lang}wcf.global.filter{/lang}</h2>
+
+ <div class="row rowColGap formGrid">
+ <dl class="col-xs-12 col-md-4">
+ <dt></dt>
+ <dd>
+ <input type="text" id="username" name="username" value="{$username}" placeholder="{lang}wcf.user.username{/lang}" class="long">
+ </dd>
+ </dl>
+
+ {if $availableSubscriptions|count > 1}
+ <dl class="col-xs-12 col-md-4">
+ <dt></dt>
+ <dd>
+ <select name="subscriptionID" id="subscriptionID">
+ <option value="0">{lang}wcf.acp.paidSubscription.subscription{/lang}</option>
+ {foreach from=$availableSubscriptions item=availableSubscription}
+ <option value="{@$availableSubscription->subscriptionID}"{if $availableSubscription->subscriptionID == $subscriptionID} selected{/if}>{$availableSubscription->title|language}</option>
+ {/foreach}
+ </select>
+ </dd>
+ </dl>
+ {/if}
+
+ {event name='filterFields'}
+ </div>
+
+ <div class="formSubmit">
+ <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
+ {@SECURITY_TOKEN_INPUT_TAG}
+ </div>
+ </section>
+</form>
+
+{assign var='linkParameters' value=''}
+{if $username}{capture append=linkParameters}&username={@$username|rawurlencode}{/capture}{/if}
+{if $subscriptionID}{capture append=linkParameters}&subscriptionID={@$subscriptionID}{/capture}{/if}
+
{hascontent}
<div class="paginationTop">
- {content}{pages print=true assign=pagesLinks controller='PaidSubscriptionUserList' link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"}{/content}
+ {content}{pages print=true assign=pagesLinks controller='PaidSubscriptionUserList' link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder$linkParameters"}{/content}
</div>
{/hascontent}
<table class="table">
<thead>
<tr>
- <th class="columnID columnSubscriptionUserID{if $sortField == 'subscriptionUserID'} active {@$sortOrder}{/if}" colspan="2"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=subscriptionUserID&sortOrder={if $sortField == 'subscriptionUserID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.global.objectID{/lang}</a></th>
- <th class="columnText columnUsername{if $sortField == 'userID'} active {@$sortOrder}{/if}"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=userID&sortOrder={if $sortField == 'userID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.user.username{/lang}</a></th>
- <th class="columnText columnSubscriptionTitle{if $sortField == 'subscriptionID'} active {@$sortOrder}{/if}"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=subscriptionID&sortOrder={if $sortField == 'subscriptionID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.paidSubscription.subscription{/lang}</a></th>
- <th class="columnDate columnEndDate{if $sortField == 'endDate'} active {@$sortOrder}{/if}"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=endDate&sortOrder={if $sortField == 'endDate' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.paidSubscription.user.endDate{/lang}</a></th>
+ <th class="columnID columnSubscriptionUserID{if $sortField == 'subscriptionUserID'} active {@$sortOrder}{/if}" colspan="2"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=subscriptionUserID&sortOrder={if $sortField == 'subscriptionUserID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.global.objectID{/lang}</a></th>
+ <th class="columnText columnUsername{if $sortField == 'username'} active {@$sortOrder}{/if}"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=username&sortOrder={if $sortField == 'username' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.user.username{/lang}</a></th>
+ <th class="columnText columnSubscriptionTitle{if $sortField == 'subscriptionID'} active {@$sortOrder}{/if}"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=subscriptionID&sortOrder={if $sortField == 'subscriptionID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.acp.paidSubscription.subscription{/lang}</a></th>
+ <th class="columnDate columnEndDate{if $sortField == 'endDate'} active {@$sortOrder}{/if}"><a href="{link controller='PaidSubscriptionUserList'}pageNo={@$pageNo}&sortField=endDate&sortOrder={if $sortField == 'endDate' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{@$linkParameters}{/link}">{lang}wcf.acp.paidSubscription.user.endDate{/lang}</a></th>
{event name='columnHeads'}
</tr>
{foreach from=$objects item=subscriptionUser}
<tr class="jsPaidSubscriptionUserRow">
<td class="columnIcon">
+ {if $subscriptionUser->endDate}
+ <a href="{link controller='PaidSubscriptionUserEdit' id=$subscriptionUser->subscriptionUserID}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip"><span class="icon icon16 fa-pencil"></span></a>
+ {else}
+ <span class="icon icon16 fa-pencil disabled"></span>
+ {/if}
<span class="icon icon16 fa-times jsDeleteButton jsTooltip pointer" title="{lang}wcf.global.button.delete{/lang}" data-object-id="{@$subscriptionUser->subscriptionUserID}" data-confirm-message-html="{lang __encode=true}wcf.acp.paidSubscription.user.delete.confirmMessage{/lang}"></span>
{event name='itemButtons'}
use wcf\data\paid\subscription\PaidSubscription;
use wcf\data\user\User;
use wcf\form\AbstractForm;
-use wcf\system\exception\PermissionDeniedException;
+use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
use wcf\util\DateUtil;
if (isset($_REQUEST['id'])) $this->subscriptionID = intval($_REQUEST['id']);
$this->subscription = new PaidSubscription($this->subscriptionID);
if (!$this->subscription->subscriptionID) {
- throw new PermissionDeniedException();
+ throw new IllegalLinkException();
}
}
public function validate() {
parent::validate();
+ $this->validateUsername();
+ $this->validateEndDate();
+ }
+
+ /**
+ * Validates given username.
+ *
+ * @throws UserInputException
+ */
+ protected function validateUsername() {
if (empty($this->username)) {
throw new UserInputException('username');
}
if (!$this->user->userID) {
throw new UserInputException('username', 'notFound');
}
-
+ }
+
+ /**
+ * Validates given end date.
+ *
+ * @throws UserInputException
+ */
+ protected function validateEndDate() {
if ($this->subscription->subscriptionLength) {
$this->endDateTime = \DateTime::createFromFormat('Y-m-d', $this->endDate, new \DateTimeZone('UTC'));
if ($this->endDateTime === false || $this->endDateTime->getTimestamp() < TIME_NOW) {
}
if ($userSubscription === null) {
// create new subscription
- $action = new PaidSubscriptionUserAction([], 'create', [
+ $this->objectAction = new PaidSubscriptionUserAction([], 'create', [
'user' => $this->user,
'subscription' => $this->subscription,
'data' => $data
]);
- $action->executeAction();
+ $this->objectAction->executeAction();
}
else {
// extend existing subscription
- $action = new PaidSubscriptionUserAction([$userSubscription], 'extend', ['data' => $data]);
- $action->executeAction();
+ $this->objectAction = new PaidSubscriptionUserAction([$userSubscription], 'extend', ['data' => $data]);
+ $this->objectAction->executeAction();
}
$this->saved();
// reset values
- $this->username = $this->endDate = '';
+ $this->username = '';
+ $this->setDefaultEndDate();
// show success message
WCF::getTPL()->assign('success', true);
parent::readData();
if (empty($_POST)) {
- if ($this->subscription->subscriptionLength) {
- $d = DateUtil::getDateTimeByTimestamp(TIME_NOW);
- $d->add($this->subscription->getDateInterval());
- $this->endDate = $d->format('Y-m-d');
- }
+ $this->setDefaultEndDate();
+ }
+ }
+
+ /**
+ * Sets the default value for the end date.
+ */
+ protected function setDefaultEndDate() {
+ if ($this->subscription->subscriptionLength) {
+ $d = DateUtil::getDateTimeByTimestamp(TIME_NOW);
+ $d->add($this->subscription->getDateInterval());
+ $this->endDate = $d->format('Y-m-d');
}
}
'subscriptionID' => $this->subscriptionID,
'subscription' => $this->subscription,
'username' => $this->username,
- 'endDate' => $this->endDate
+ 'endDate' => $this->endDate,
+ 'action' => 'add'
]);
}
}
--- /dev/null
+<?php
+namespace wcf\acp\form;
+use wcf\data\paid\subscription\user\PaidSubscriptionUser;
+use wcf\data\paid\subscription\user\PaidSubscriptionUserAction;
+use wcf\form\AbstractForm;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\WCF;
+use wcf\util\DateUtil;
+
+/**
+ * Shows the user subscription edit form.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2017 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Acp\Form
+ * @since 3.1
+ */
+class PaidSubscriptionUserEditForm extends PaidSubscriptionUserAddForm {
+ /**
+ * subscription user id
+ * @var integer
+ */
+ public $subscriptionUserID = 0;
+
+ /**
+ * subscription user object
+ * @var PaidSubscriptionUser
+ */
+ public $subscriptionUser = null;
+
+ /**
+ * subscription end date
+ * @var string
+ */
+ public $endDate = '';
+
+ /**
+ * subscription end date
+ * @var \DateTime
+ */
+ public $endDateTime = null;
+
+ /**
+ * @inheritDoc
+ */
+ public function readParameters() {
+ AbstractForm::readParameters();
+
+ if (isset($_REQUEST['id'])) $this->subscriptionUserID = intval($_REQUEST['id']);
+ $this->subscriptionUser = new PaidSubscriptionUser($this->subscriptionUserID);
+ if (!$this->subscriptionUser->subscriptionUserID || !$this->subscriptionUser->endDate || !$this->subscriptionUser->isActive) {
+ throw new IllegalLinkException();
+ }
+ $this->subscription = $this->subscriptionUser->getSubscription();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected function validateUsername() {}
+
+ /**
+ * @inheritDoc
+ */
+ public function save() {
+ AbstractForm::save();
+
+ $data = [
+ 'endDate' => $this->endDateTime->getTimestamp()
+ ];
+ $this->objectAction = new PaidSubscriptionUserAction([$this->subscriptionUser], 'update', [
+ 'data' => $data
+ ]);
+ $this->objectAction->executeAction();
+ $this->saved();
+
+ // show success message
+ WCF::getTPL()->assign('success', true);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function readData() {
+ AbstractForm::readData();
+
+ if (empty($_POST)) {
+ $d = DateUtil::getDateTimeByTimestamp($this->subscriptionUser->endDate);
+ $this->endDate = $d->format('Y-m-d');
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign([
+ 'subscriptionUserID' => $this->subscriptionUserID,
+ 'subscriptionUser' => $this->subscriptionUser,
+ 'action' => 'edit'
+ ]);
+ }
+}
namespace wcf\acp\page;
use wcf\data\paid\subscription\user\PaidSubscriptionUserList;
use wcf\page\SortablePage;
+use wcf\system\cache\builder\PaidSubscriptionCacheBuilder;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
/**
* Shows the list of paid subscription users.
/**
* @inheritDoc
*/
- public $defaultSortField = 'userID';
+ public $defaultSortField = 'username';
/**
* @inheritDoc
*/
- public $validSortFields = ['subscriptionUserID', 'userID', 'subscriptionID', 'startDate', 'endDate'];
+ public $validSortFields = ['subscriptionUserID', 'username', 'subscriptionID', 'startDate', 'endDate'];
/**
* @inheritDoc
*/
public $objectListClassName = PaidSubscriptionUserList::class;
+ /**
+ * username
+ * @var string
+ */
+ public $username = '';
+
+ /**
+ * subscription id
+ * @var integer
+ */
+ public $subscriptionID = 0;
+
+ /**
+ * @inheritDoc
+ */
+ public function readParameters() {
+ parent::readParameters();
+
+ if (isset($_REQUEST['username'])) $this->username = StringUtil::trim($_REQUEST['username']);
+ if (isset($_REQUEST['subscriptionID'])) $this->subscriptionID = intval($_REQUEST['subscriptionID']);
+ }
+
/**
* Initializes DatabaseObjectList instance.
*/
protected function initObjectList() {
parent::initObjectList();
- $this->objectList->getConditionBuilder()->add('isActive = ?', [1]);
+ if ($this->username) {
+ $this->objectList->getConditionBuilder()->add('paid_subscription_user.userID IN (SELECT userID FROM wcf'.WCF_N.'_user WHERE username LIKE ?)', ['%' . $this->username . '%']);
+ }
+ if ($this->subscriptionID) {
+ $this->objectList->getConditionBuilder()->add('paid_subscription_user.subscriptionID = ?', [$this->subscriptionID]);
+ }
+
+ $this->objectList->getConditionBuilder()->add('paid_subscription_user.isActive = ?', [1]);
$this->objectList->sqlSelects = 'user_table.username, paid_subscription.title';
$this->objectList->sqlJoins = "LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = paid_subscription_user.userID)";
$this->objectList->sqlJoins .= " LEFT JOIN wcf".WCF_N."_paid_subscription paid_subscription ON (paid_subscription.subscriptionID = paid_subscription_user.subscriptionID)";
}
+
+ /**
+ * @inheritDoc
+ */
+ protected function readObjects() {
+ if ($this->sortField == 'username') {
+ $this->sqlOrderBy = 'user_table.username ' . $this->sortOrder . ', paid_subscription_user.subscriptionUserID ' . $this->sortOrder;
+ }
+
+ parent::readObjects();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign([
+ 'username' => $this->username,
+ 'subscriptionID' => $this->subscriptionID,
+ 'availableSubscriptions' => PaidSubscriptionCacheBuilder::getInstance()->getData()
+ ]);
+ }
}
namespace wcf\data\paid\subscription\user;
use wcf\data\paid\subscription\PaidSubscription;
use wcf\data\DatabaseObject;
+use wcf\data\user\User;
use wcf\system\WCF;
/**
*/
protected $subscription = null;
+ /**
+ * user object
+ * @var User
+ */
+ protected $user = null;
+
/**
* Returns the paid subscription object.
*
$this->subscription = $subscription;
}
+ /**
+ * Returns the user object.
+ *
+ * @return User
+ */
+ public function getUser() {
+ if ($this->user === null) {
+ $this->user = new User($this->userID);
+ }
+
+ return $this->user;
+ }
+
/**
* Returns a specific subscription user or `null` if such a user does not exist.
*
<item name="wcf.acp.paidSubscription.excludedSubscriptions.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} den Erwerb anderer bezahlter Mitgliedschaften für Käufer dieser Mitgliedschaft ausschließen.]]></item>
<item name="wcf.acp.paidSubscription.user.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} die Mitgliedschaft <span class="confirmationObject">{$subscriptionUser->title|language}</span> für den Benutzer <span class="confirmationObject">{$subscriptionUser->username}</span> wirklich entfernen?]]></item>
<item name="wcf.acp.paidSubscription.user.add"><![CDATA[Mitgliedschaft manuell zuweisen]]></item>
+ <item name="wcf.acp.paidSubscription.user.edit"><![CDATA[Aktive Mitgliedschaft bearbeiten]]></item>
<item name="wcf.acp.paidSubscription.error.noPaymentMethods"><![CDATA[Es muss mindestens ein Zahlungsanbieter in den Optionen unter „Zahlungsoptionen“ ausgewählt sein, um bezahlte Mitgliedschaften erstellen zu können.]]></item>
<item name="wcf.acp.paidSubscription.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} die bezahlte Mitgliedschaft <span class="confirmationObject">{$subscription->title|language}</span> wirklich löschen?]]></item>
</category>
<item name="wcf.acp.paidSubscription.excludedSubscriptions.description"><![CDATA[Prevents purchasing of other subscriptions for buyers of this subscription.]]></item>
<item name="wcf.acp.paidSubscription.user.delete.confirmMessage"><![CDATA[Do you really want to terminate the subscription <span class="confirmationObject">{$subscriptionUser->title|language}</span> for the user <span class="confirmationObject">{$subscriptionUser->username}</span>?]]></item>
<item name="wcf.acp.paidSubscription.user.add"><![CDATA[Manually Add Subscription]]></item>
+ <item name="wcf.acp.paidSubscription.user.edit"><![CDATA[Edit Active Subscription]]></item>
<item name="wcf.acp.paidSubscription.error.noPaymentMethods"><![CDATA[Adding subscriptions requires at least one active payment provider for the “Supported Payment Methods” option.]]></item>
<item name="wcf.acp.paidSubscription.delete.confirmMessage"><![CDATA[Do you really want to delete the paid subscription <span class="confirmationObject">{$subscription->title|language}</span>?]]></item>
</category>