Newscoop\Entity\Repository\ArticleDatetimeRepository::add PHP Метод

add() публичный Метод

Adds time intervals
public add ( array | ArticleDatetime $timeSet, integer | Article $articleId, string $fieldName = null, string $recurring = null, boolean $overwrite = false, $otherInfo = null )
$timeSet array | Newscoop\Entity\ArticleDatetime Complex set of intervals { "2011-11-02" = { "12:00" => "18:00", "20:00" => "22:00", [ "recurring" => true|false ] } - between these hours on 11-02 "2011-11-03" = "11:00 - recurring:weekly" - at 11:00 this day, and recurring weekly "2011-11-03 14:00" = "18:00" - from 3rd nov 14:00 until 18:00 "2011-11-04" = "2011-11-07" - from 4th till 7th nov "2011-11-08" = "2011-11-09 12:00" - from 8th till 12:00 9th "2011-11-10 10:30" = "2011-11-11" - from 10th 10:40 until the end of the day "2011-11-12 12:30" = "2011-11-13 13:00" - self explanatory "2011-11-14 14:30" = "2011-11-15 15:00" - self explanatory "2011-11-15 15:30" = "2011-11-17" - self explanatory "2011-11-30" = true - on the 30th full day }
$articleId integer | Newscoop\Entity\Article
$fieldName string
$recurring string
$overwrite boolean
    public function add($timeSet, $articleId, $fieldName = null, $recurring = null, $overwrite = false, $otherInfo = null)
    {
        $insertValues = $this->buildInsertValues($timeSet, $recurring);
        $article = null;
        $em = $this->getEntityManager();
        // check article
        if (is_numeric($articleId)) {
            $article = $em->getRepository('Newscoop\\Entity\\Article')->findOneBy(array('number' => $articleId));
            /* @var $article Newscoop\Entity\Article */
        } elseif ($articleId instanceof \Article) {
            $article = $articleId;
        }
        if (is_null($article)) {
            return false;
        }
        $em->getConnection()->beginTransaction();
        try {
            if ($overwrite) {
                $this->deleteByArticle($articleId);
            }
            foreach ($insertValues as $dateValue) {
                foreach (array_merge(array($dateValue), $dateValue->getSpawns()) as $dateValue) {
                    $articleDatetime = new ArticleDatetime();
                    $articleDatetime->setValues($dateValue, $article, $fieldName, null, $otherInfo);
                    $em->persist($articleDatetime);
                }
            }
            $em->flush();
            $em->getConnection()->commit();
        } catch (\Exception $e) {
            $em->getConnection()->rollback();
            $em->close();
            return $e;
        }
    }