Exemplo n.º 1
0
 static function getTotalAllowedChildItems($gids, $metaUser, $list = array())
 {
     $groups = ItemGroupHandler::getChildren($gids, 'group');
     if (!empty($groups)) {
         foreach ($groups as $groupid) {
             $group = new ItemGroup();
             $group->load($groupid);
             if (!$group->checkVisibility($metaUser)) {
                 continue;
             }
             if (!empty($group->params['reveal_child_items']) && empty($group->params['symlink'])) {
                 $list = ItemGroupHandler::getTotalAllowedChildItems($groupid, $metaUser, $list);
             } else {
                 if (ItemGroupHandler::hasVisibleChildren($group, $metaUser)) {
                     $list[] = ItemGroupHandler::getGroupListItem($group);
                 }
             }
         }
     }
     $items = ItemGroupHandler::getChildren($gids, 'item');
     if (!empty($items)) {
         foreach ($items as $itemid) {
             $plan = new SubscriptionPlan();
             $plan->load($itemid);
             if (!$plan->checkVisibility($metaUser)) {
                 continue;
             }
             $list[] = ItemGroupHandler::getItemListItem($plan);
         }
     }
     return $list;
 }
Exemplo n.º 2
0
 public function create($intro = 0, $usage = 0, $group = 0, $processor = null, $invoice = 0, $autoselect = false)
 {
     global $aecConfig;
     $register = !$this->loadMetaUser(true);
     $this->getPassthrough();
     // Reset $register if we seem to have all data
     if ($register && !empty($this->passthrough['username']) || !empty($aecConfig->cfg['skip_registration'])) {
         $register = 0;
     }
     if ($intro && $this->metaUser->hasSubscription && !$aecConfig->cfg['customintro_always']) {
         $intro = false;
     }
     if (empty($this->usage) && empty($group) && !$intro && !empty($aecConfig->cfg['customintro'])) {
         if (!empty($aecConfig->cfg['customintro_userid'])) {
             aecRedirect($aecConfig->cfg['customintro'], $this->userid, "aechidden");
         } else {
             aecRedirect($aecConfig->cfg['customintro']);
         }
     }
     $this->recurring = aecGetParam('recurring', null);
     $planlist = new SubscriptionPlanList($usage, $group, $this->metaUser, $this->recurring);
     $nochoice = false;
     // There is no choice if we have only one group or only one item with one payment option
     if (count($planlist->list) === 1) {
         if ($planlist->list[0]['type'] == 'item') {
             if (count($planlist->list[0]['gw']) === 1) {
                 $nochoice = true;
             } elseif (!empty($processor)) {
                 foreach ($planlist->list[0]['gw'] as $gw) {
                     if ($gw->processor_name == $processor) {
                         $nochoice = true;
                     }
                 }
                 if ($nochoice) {
                     $first = 0;
                     foreach ($planlist->list[0]['gw'] as $gwid => $gw) {
                         if ($gw->processor_name != $processor) {
                             unset($planlist->list[0]['gw'][$gwid]);
                         } else {
                             $first = $gwid;
                         }
                     }
                     if (!empty($first)) {
                         $planlist->list[0]['gw'][0] = $planlist->list[0]['gw'][$first];
                         unset($planlist->list[0]['gw'][$first]);
                     }
                 }
             }
         } else {
             // Jump back and use the only group we've found
             return $this->create($intro, 0, $planlist->list[0]['id'], null, 0, true);
         }
     }
     // If we have only one processor on one plan, there is no need for a decision
     if ($nochoice && !($aecConfig->cfg['show_fixeddecision'] && empty($processor))) {
         // If the user also needs to register, we need to guide him there after the selection has now been made
         if ($register && empty($aecConfig->cfg['skip_registration'])) {
             aecRegistration::registerRedirect($intro, $planlist->list[0]);
         } else {
             // Existing user account - so we need to move on to the confirmation page with the details
             $this->usage = $planlist->list[0]['id'];
             if (isset($planlist->list[0]['gw'][0]->recurring)) {
                 $this->recurring = $planlist->list[0]['gw'][0]->recurring;
             } else {
                 $this->recurring = 0;
             }
             $this->processor = $planlist->list[0]['gw'][0]->processor_name;
             if ($invoice != 0 && !is_null($invoice)) {
                 $this->invoice_number = $invoice;
             }
             return $this->confirm();
         }
     }
     if ($group) {
         $g = new ItemGroup();
         $g->load($group);
         $planlist->list['group'] = ItemGroupHandler::getGroupListItem($g);
     }
     $cart = $this->userid ? aecCartHelper::getCartidbyUserid($this->userid) : false;
     $selected = (!empty($group) || !empty($usage)) && !$autoselect;
     if (!$selected && !empty($planlist->list['group'])) {
         unset($planlist->list['group']);
     }
     $passthrough = $this->getPassthrough();
     $csslist = $planlist->addButtons($register, $passthrough);
     return getView('plans', array('userid' => $this->userid, 'list' => $planlist->list, 'passthrough' => $passthrough, 'register' => $register, 'cart' => $cart, 'selected' => $selected, 'group' => $group, 'csslist' => $csslist));
 }