/** * Execute a command and return a response. Does not render * @param IRequest $Request * @return IResponse the execution response */ function execute(IRequest $Request) { $walletOptions = array('Choose a Wallet' => null); /** @var AbstractWallet[] $WalletTypes */ $WalletTypes = array(); $WalletForms = array(); foreach (AbstractWallet::loadAllWalletTypes() as $WalletType) { $WalletTypes[$WalletType->getTypeName()] = $WalletType; $FieldSet = $WalletType->getFieldSet($Request); $FieldSet->setAttribute('data-' . self::PARAM_WALLET_TYPE, $WalletType->getTypeName()); $FieldSet->setAttribute('disabled', 'disabled'); $WalletForms[] = $FieldSet; $walletOptions[$WalletType->getDescription()] = $WalletType->getTypeName(); } $Form = new HTMLForm(self::FORM_METHOD, self::FORM_ACTION, self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '\\assets\\create-wallet.js'), new HTMLHeaderStyleSheet(__DIR__ . '\\assets\\create-wallet.css'), new HTMLElement('fieldset', new HTMLElement('legend', 'legend-wallet', 'Create a new Wallet'), new HTMLElement('label', null, "New Wallet type<br/>", new HTMLSelectField(self::PARAM_WALLET_TYPE, $walletOptions, new RequiredValidation())), "<br/><br/>", $WalletForms, "<br/><br/>", new HTMLButton('create', "Create New Wallet"))); $Form->setFormValues($Request); if (!$Request instanceof IFormRequest) { return $Form; } $walletType = $Form->validateField($Request, self::PARAM_WALLET_TYPE); $NewWallet = $WalletTypes[$walletType]; $NewWallet->validateRequest($Request, $Form); // $name = $Request[self::PARAM_WALLET_NAME]; // $email = $Request[self::PARAM_WALLET_EMAIL]; $id = WalletEntry::create($Request, $NewWallet); return new RedirectResponse(ManageWallet::getRequestURL($id), "Wallet created successfully. Redirecting...", 5); }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @return IResponse the execution response */ function execute(IRequest $Request) { $WalletEntry = WalletEntry::get($this->id); $Wallet = $WalletEntry->getWallet(); $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE . ': ' . $Wallet->getTitle()), new HTMLElement('fieldset', new HTMLElement('legend', 'legend-submit', self::TITLE . ': ' . $Wallet->getTitle()), new HTMLInputField(self::PARAM_ID, $this->id, 'hidden'), new HTMLElement('label', null, "Wallet Status<br/>", $Select = new HTMLSelectField(self::PARAM_WALLET_STATUS, WalletEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", $Wallet->getFieldSet($Request), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'update'), new HTMLButton(self::PARAM_SUBMIT, 'Delete', 'delete')), "<br/><br/>"); if (!$Request instanceof IFormRequest) { return $Form; } $Wallet->validateRequest($Request, $Form); $submit = $Request[self::PARAM_SUBMIT]; switch ($submit) { case 'update': $WalletEntry->update($Request, $Wallet); return new RedirectResponse(ManageWallet::getRequestURL($this->getWalletID()), "Wallet updated successfully. Redirecting...", 5); case 'delete': WalletEntry::delete($Request, $this->getWalletID()); return new RedirectResponse(SearchWallets::getRequestURL(), "Wallet deleted successfully. Redirecting...", 5); } throw new \InvalidArgumentException($submit); }
/** * @param $key * @param $value * @param null $arg1 * @return bool if true, the value has been rendered, otherwise false */ function renderNamedValue($key, $value, $arg1 = null) { switch ($key) { case 'created': if ($value) { echo DateUtil::ago($value) . ' ago'; } return true; case 'status': echo "<span class='status'>", $arg1 ?: $value, "</span>"; return true; case 'amount': if ($value) { echo "<span class='amount'>", $value, "</span>"; } return true; case 'payment-source': case 'payment-source-id': $href = $this->domain . ltrim(ManagePaymentSource::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'transaction': case 'transaction-id': $href = $this->domain . ltrim(ManageTransaction::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'product': case 'product-id': $href = $this->domain . ltrim(ManageProduct::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'test-url': $href = $this->domain . ltrim($value, '/'); echo "<a href='{$href}'>Test</a>"; return true; case 'order-page-url': $href = $this->domain . ltrim($value, '/'); echo "<a href='{$href}'>Order Page</a>"; return true; case 'account': case 'affiliate': case 'account-id': $href = $this->domain . ltrim(ManageAccount::getRequestURL($value), '/'); echo "<a href='{$href}'>", $arg1 ?: $value, "</a>"; return true; case 'wallet-id': $href = $this->domain . ltrim(ManageWallet::getRequestURL($value), '/'); echo "<a href='{$href}'>", $value, "</a>"; return true; } return false; }