Ejemplo n.º 1
0
 /**
  * Save subscription
  *
  * @param array $values
  * @param Newscoop\Entity\Subscription|null $subscription
  * @return Newscoop\Entity\Subscription
  */
 public function save(array $values, Subscription $subscription = null)
 {
     if ($subscription === null) {
         $subscription = new Subscription();
         $this->em->persist($subscription);
     }
     if (array_key_exists('user', $values)) {
         $subscription->setUser(is_numeric($values['user']) ? $this->em->getReference('Newscoop\\Entity\\User', $values['user']) : $values['user']);
     }
     if (array_key_exists('publication', $values)) {
         $subscription->setPublication(is_numeric($values['publication']) ? $this->em->getReference('Newscoop\\Entity\\Publication', $values['publication']) : $values['publication']);
     }
     if (array_key_exists('type', $values)) {
         $subscription->setType($values['type']);
     }
     if (array_key_exists('active', $values)) {
         $subscription->setActive($values['active']);
     }
     if (array_key_exists('currency', $values)) {
         $subscription->setCurrency($values['currency']);
     }
     if (array_key_exists('toPay', $values)) {
         $subscription->setToPay($values['toPay']);
     }
     if (array_key_exists('add_sections', $values) && $values['add_sections']) {
         if (!array_key_exists('publication', $values)) {
             throw new \InvalidArgumentException("No publication provided for adding sections");
         }
         $publication = is_numeric($values['publication']) ? $this->em->getRepository('Newscoop\\Entity\\Publication')->find($values['publication']) : $values['publication'];
         $subscription->addSections($values, $publication);
     }
     $this->em->flush();
     return $subscription;
 }
Ejemplo n.º 2
0
 /**
  * Save ip
  *
  * @param array $values
  * @return Newscoop\Entity\User\Ip
  */
 public function save(array $values)
 {
     $ip = new Ip($values['ip'], $values['number']);
     if (array_key_exists('user', $values)) {
         $ip->setUser(is_numeric($values['user']) ? $this->em->getReference('Newscoop\\Entity\\User', $values['user']) : $values['user']);
     }
     $this->em->persist($ip);
     $this->em->flush($ip);
     return $ip;
 }
Ejemplo n.º 3
0
 /**
  * Save article image
  *
  * @param Newscoop\Image\ArticleImage $articleImage
  * @param array $values
  * @return void
  */
 public function saveArticleImage(ArticleImage $articleImage, array $values)
 {
     $language = $this->orm->getReference('Newscoop\\Entity\\Language', $values['language']);
     $articleImage->setNumber($values['number']);
     $articleImage->setCaption($values['caption'], $language);
     $this->orm->flush();
 }
Ejemplo n.º 4
0
 /**
  * Delete section
  *
  * @param int $id
  * @return void
  */
 public function delete($id)
 {
     $this->em->remove($this->em->getReference('Newscoop\\Subscription\\Section', $id));
     $this->em->flush();
 }