Пример #1
0
 /**
  * @param string $params
  */
 public function readParams($params, $allow_trial = true)
 {
     // Old params only had trial and full
     if ($allow_trial) {
         $terms = array('trial_', 'full_');
     } else {
         $terms = array('full_');
     }
     $return = false;
     $this->pointer = 0;
     $this->terms = array();
     foreach ($terms as $t) {
         // Make sure this period is actually of substance
         if (!empty($params[$t . 'period']) || !empty($params['lifetime']) && $t == 'full_') {
             $term = new itemTerm();
             // If we have a trial, we need to mark this
             if ($t == 'trial_') {
                 $this->set('hasTrial', true);
                 $term->set('type', 'trial');
             } else {
                 $term->set('type', 'term');
             }
             if ($t != 'trial_' && !empty($params['lifetime'])) {
                 $duration['lifetime'] = true;
             } else {
                 $duration['period'] = $params[$t . 'period'];
                 $duration['unit'] = $params[$t . 'periodunit'];
             }
             $term->set('duration', $duration);
             if ($params[$t . 'free']) {
                 $term->addCost('0.00');
             } else {
                 $term->addCost($params[$t . 'amount']);
             }
             $this->addTerm($term);
             $return = true;
         }
     }
     $free = true;
     foreach ($this->terms as $term) {
         if (empty($term->free)) {
             $free = false;
         }
     }
     $this->free = $free;
     $this->nextterm =& $this->terms[$this->pointer];
     return $return;
 }