setActive() public method

Set active
public setActive ( boolean $active ) : Newscoop\Entity\Subscription
$active boolean
return Newscoop\Entity\Subscription
 /**
  * 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);
         }
     }
 }
 public function setActive($active)
 {
     $this->__load();
     return parent::setActive($active);
 }
Exemplo n.º 3
0
 private function apply(Subscription $subscription, SubscriptionData $data)
 {
     if ($data->userId) {
         $user = $this->em->getRepository('Newscoop\\Entity\\User')->getOneActiveUser($data->userId, false)->getOneOrNullResult();
         if ($user) {
             $subscription->setUser($user);
         }
     }
     if ($data->publicationId) {
         $publication = $this->em->getRepository('Newscoop\\Entity\\Publication')->findOneBy(array('id' => $data->publicationId));
         if ($publication) {
             $subscription->setPublication($publication);
         }
     }
     if ($data->toPay) {
         $subscription->setToPay($data->toPay);
     }
     if ($data->currency) {
         $subscription->setCurrency($data->currency);
     }
     if ($data->active) {
         $subscription->setActive($data->active);
     }
     if ($data->type) {
         $subscription->setType($data->type);
     }
     if ($data->sections) {
         $sectionsIds = array();
         foreach ($data->sections as $key => $section) {
             $subscription->addSection($section);
             $sectionsIds[] = $section->getId();
         }
         //Clean conncted sections list
         $subscription->setSections($sectionsIds);
     }
     if ($data->articles) {
         $articlesIds = array();
         foreach ($data->articles as $key => $article) {
             $subscription->addArticle($article);
             $articlesIds[] = $article->getId();
         }
         //Clean conncted sections list
         $subscription->setArticles($articlesIds);
     }
     if ($data->issues) {
         $issuesIds = array();
         foreach ($data->issues as $key => $issue) {
             $subscription->addIssue($issue);
             $issuesIds[] = $issue->getId();
         }
         //Clean conncted sections list
         $subscription->setIssues($issuesIds);
     }
     return $subscription;
 }