public function getSections()
 {
     $this->__load();
     return parent::getSections();
 }
 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;
 }
Esempio n. 3
0
 /**
  * Get json representation of subscription
  *
  * @param Newscoop\Entity\Subscription $subscription
  * @return array
  */
 public function SubscriptionJson(\Newscoop\Subscription\Subscription $subscription)
 {
     return array('id' => $subscription->getId(), 'publication' => array('id' => $subscription->getPublicationId(), 'name' => $subscription->getPublicationName()), 'link' => array('rel' => 'edit', 'href' => $this->view->url(array('module' => 'admin', 'controller' => 'subscription', 'action' => 'edit', 'subscription' => $subscription->getId(), 'user' => $subscription->getUser()->getId()), 'default')), 'toPay' => $subscription->getToPay(), 'type' => $subscription->getType(), 'active' => $subscription->isActive());
 }
 /**
  * Delete subscription
  *
  * @param Newscoop\Entity\Subscription $subscription
  * @return void
  */
 public function delete(Subscription $subscription)
 {
     $em = $this->getEntityManager();
     foreach ($subscription->getSections() as $section) {
         $em->remove($section);
     }
     $em->remove($subscription);
 }