Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @throws RequestException
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $SessionRequest = $Request;
     if (!$SessionRequest instanceof ISessionRequest) {
         throw new RequestException("Session required");
     }
     $ProductEntry = ProductEntry::get($this->id);
     $setRates = false;
     $Account = AbstractAccountType::loadFromSession($SessionRequest);
     if ($Account instanceof MerchantAccount) {
         if ($Account->getID() !== $ProductEntry->getAccountID()) {
             throw new RequestException("Product does not belong to merchant");
         }
     } else {
         if ($Account instanceof AdministratorAccount) {
             $setRates = true;
         } else {
             throw new RequestException("Only merchants may create a new Product");
         }
     }
     $Product = $ProductEntry->getProduct();
     $sourceOptions = array("Choose a Payment Product" => null);
     $PaymentSourceTable = new PaymentSourceTable();
     foreach ($PaymentSourceTable->fetchAll(1) as $PaymentSourceEntry) {
         $PaymentSource = $PaymentSourceEntry->getPaymentSource();
         $sourceOptions[$PaymentSource->getTitle()] = $PaymentSourceEntry->getID();
     }
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/product.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/product.css'), new HTMLInputField(self::PARAM_ID, $this->id, 'hidden'), new HTMLInputField(self::PARAM_PRODUCT_TYPE, $Product->getTypeName(), 'hidden'), new HTMLElement('fieldset', new HTMLElement('legend', 'legend-order-page', "Try Order Page"), new HTMLAnchor(OrderForm::getRequestURL($this->getProductID()), "Order Page")), new HTMLElement('fieldset', 'fieldset-info inline', new HTMLElement('legend', 'legend-info', "Product Info"), new MapRenderer($ProductEntry)), new HTMLElement('fieldset', 'fieldset-config inline', new HTMLElement('legend', 'legend-config', self::TITLE), $Product->getConfigFieldSet($Request), $FeesFieldSet = $Product->getFeesFieldSet($Request), new HTMLElement('fieldset', 'fieldset-status inline', new HTMLElement('legend', 'legend-status', "Status"), $SelectStatus = new HTMLSelectField(self::PARAM_PRODUCT_STATUS, ProductEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'update')), new HTMLElement('fieldset', 'inline', new HTMLElement('legend', 'legend-submit', "Delete Product"), new HTMLButton(self::PARAM_SUBMIT, 'Delete', 'delete')), "<br/>");
     if (!$setRates) {
         $FeesFieldSet->setAttribute('disabled', 'disabled');
     }
     $SelectStatus->setInputValue($ProductEntry->getStatus());
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $submit = $Request[self::PARAM_SUBMIT];
     switch ($submit) {
         case 'update':
             $status = $Request[self::PARAM_PRODUCT_STATUS];
             $Product->validateConfigRequest($Request, $Form);
             $Product->validateFeesRequest($Request, $Form);
             $ProductEntry->update($Request, $Product, $status);
             return new RedirectResponse(ManageProduct::getRequestURL($this->getProductID()), "Product updated successfully. Redirecting...", 2);
         case 'delete':
             ProductEntry::delete($Request, $this->getProductID());
             return new RedirectResponse(SearchProducts::getRequestURL(), "Product deleted successfully. Redirecting...", 8);
     }
     throw new \InvalidArgumentException($submit);
 }
Пример #3
0
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @throws \Exception
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $SessionRequest = $Request;
     if (!$SessionRequest instanceof ISessionRequest) {
         throw new \Exception("Session required");
     }
     $Account = AbstractAccountType::loadFromSession($SessionRequest);
     if (!$Account instanceof MerchantAccount) {
         throw new RequestException("Only merchants may create a new Product");
     }
     $productOptions = array("Choose a Product Type" => null);
     /** @var AbstractProductType[] $ProductTypes */
     $ProductTypes = array();
     $ProductForms = array();
     foreach (Types\AbstractProductType::loadAllProductTypes() as $ProductType) {
         $ProductTypes[$ProductType->getTypeName()] = $ProductType;
         $FieldSet = $ProductType->getConfigFieldSet($Request);
         $FieldSet->setAttribute('disabled', 'disabled');
         $ProductForms[] = $FieldSet;
         //			$FieldSet = $ProductType->getRatesFieldSet($Request);
         //			$FieldSet->setAttribute('disabled', 'disabled');
         //			$ProductForms[] = $FieldSet;
         $productOptions[$ProductType->getTypeDescription()] = $ProductType->getTypeName();
     }
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/product.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/product.css'), new HTMLElement('fieldset', 'fieldset-create-product', new HTMLElement('legend', 'legend-product', self::TITLE), new HTMLElement('label', null, "Status<br/>", new HTMLSelectField(self::PARAM_PRODUCT_STATUS, ProductEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Choose a Product Type<br/>", new HTMLSelectField(self::PARAM_PRODUCT_TYPE, $productOptions, new RequiredValidation())), "<br/><br/>", $ProductForms, "<br/><br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>");
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $status = $Form->validateField($Request, self::PARAM_PRODUCT_STATUS);
     $productType = $Form->validateField($Request, self::PARAM_PRODUCT_TYPE);
     //		$sourceID = $Form->validateField($Request, self::PARAM_PAYMENT_SOURCE_TYPE);
     $ChosenProduct = $ProductTypes[$productType];
     $ChosenProduct->validateConfigRequest($Request, $Form);
     $accountID = 'default';
     if ($Account) {
         $accountID = $Account->getID();
     }
     $id = ProductEntry::create($Request, $ChosenProduct, $accountID, $status);
     return new RedirectResponse(ManageProduct::getRequestURL($id), "Product created successfully. Redirecting...", 5);
 }