Пример #1
0
 protected function displayRenew()
 {
     // at this point, user is logged in
     $user_id = $this->getUser()->getId();
     $sub = WpSubscription::newActiveByUserId($user_id);
     if ($sub == null) {
         // "need an active subscription"
         $this->action = self::ACTION_LIST;
         $this->msgType = 'error';
         $this->msgKey = 'wp-no-active-sub';
         $this->display();
         return;
     }
     $renewal_plan_id = $sub->getRenewalPlanId();
     $formDescriptor = array('Plan' => array('type' => 'select', 'section' => 'sub-renew-section', 'label-message' => 'wp-planfield', 'help-message' => 'wp-planfield-help', 'validation-callback' => array($this, 'validateRenewPlanId'), 'options' => array(), 'default' => $renewal_plan_id), 'Check' => array('type' => 'check', 'section' => 'sub-renew-section', 'label-message' => 'wp-checkfield', 'validation-callback' => array($this, 'validateSubscribeCheck'), 'required' => 'true'));
     $nb_wikiplaces = WpWikiplace::countWikiplacesOwnedByUser($user_id);
     $nb_wikiplace_pages = WpPage::countPagesOwnedByUser($user_id);
     $diskspace = WpPage::countDiskspaceUsageByUser($user_id);
     $when = $sub->getEnd();
     $plans = WpPlan::factoryAvailableForRenewal($nb_wikiplaces, $nb_wikiplace_pages, $diskspace, $when);
     foreach ($plans as $plan) {
         $wpp_name = $plan->getName();
         $price = $plan->getPrice();
         $formDescriptor['Plan']['options'][wfMessage('wp-plan-desc-short', wfMessage('wpp-' . $wpp_name)->text(), $price['amount'])->text()] = $plan->getId();
     }
     // add "do not renew" at the end;
     $formDescriptor['Plan']['options'][wfMessage('wp-do-not-renew')->text()] = '0';
     $htmlForm = new HTMLFormS($formDescriptor);
     $htmlForm->setMessagePrefix('wp');
     $htmlForm->addHeaderText(wfMessage('wp-sub-renew-header')->parse());
     $htmlForm->setTitle($this->getTitleFor(self::TITLE_NAME, self::ACTION_RENEW));
     $htmlForm->setSubmitCallback(array($this, 'processRenew'));
     $htmlForm->setSubmitText(wfMessage('wp-plan-renew-go')->text());
     // validate and process the form is data sent
     if ($htmlForm->show()) {
         $this->action = self::ACTION_LIST;
         $this->msgKey = 'wp-renew-success';
         $this->msgType = 'success';
         $this->display();
     }
 }