Newscoop\Subscription\SectionFacade::save PHP Method

save() public method

Save section
public save ( array $values, Section $section = null ) : Newscoop\Subscription\Section
$values array
$section Section
return Newscoop\Subscription\Section
    public function save(array $values, Section $section = null)
    {
        if ($section === null) {
            if (!array_key_exists('subscription', $values)) {
                throw new \InvalidArgumentException("Subscription must be provided.");
            }
            if (!array_key_exists('section', $values)) {
                throw new \InvalidArgumentException("Section must be provided.");
            }
            $section = new Section($this->getSubscription($values), $this->getSectionNumber($values));
            $this->em->persist($section);
            if (!empty($values['language'])) {
                $section->setLanguage($this->getLanguage($values));
            }
        }
        $section->setStartDate(new \DateTime($values['startDate']));
        $section->setDays($values['days']);
        $section->setPaidDays($values['paidDays']);
        $this->em->flush();
        return $section;
    }