/**
  * Save subscription
  *
  * @param Newscoop\Entity\Subscription $subscription
  * @param Newscoop\Entity\User\Subscriber $subscriber
  * @param array $values
  * @return void
  */
 public function save(Subscription $subscription, Subscriber $subscriber, array $values)
 {
     $em = $this->getEntityManager();
     $publication = $em->find('Newscoop\\Entity\\Publication', $values['publication']);
     $subscription->setType($values['type']);
     $subscription->setActive(!empty($values['active']));
     $subscription->setPublication($publication);
     $subscription->setSubscriber($subscriber);
     $em->persist($subscription);
     if (strtolower($values['sections']) == 'y') {
         // add sections
         $languages = array_map('intval', (array) $values['languages']);
         if ($values['language_set'] == 'select' && empty($languages)) {
             throw new \InvalidArgumentException('No languages specified');
         }
         foreach ($publication->getSections() as $section) {
             $subscriptionSection = new SubscriptionSection();
             if ($values['language_set'] == 'select' && !in_array($section->getLanguageId(), $languages)) {
                 continue;
                 // ignore by language if any
             } elseif ($values['language_set'] == 'select') {
                 $subscriptionSection->setLanguage($section->getLanguage());
             }
             $subscriptionSection->setSubscription($subscription)->setSectionNumber($section->getNumber())->setStartDate(new \DateTime($values['start_date']))->setDays((int) $values['days'])->setPaidDays(in_array($values['type'], array('PN', 'T')) ? (int) $values['days'] : 0);
             $em->persist($subscriptionSection);
         }
     }
 }