/** * @param array $articleData * @param ArticleDatetime $dateData */ public function setValues($dateData, $article, $fieldName, $articleType = null, $otherInfo = null) { if (is_null($articleType) && !$article instanceof Article) { return false; } $this->articleId = $article instanceof Article ? $article->getId() : $article; $this->articleType = is_null($articleType) ? $article->getType() : $articleType; $this->fieldName = $fieldName; $this->startDate = $dateData->getStartDate(); $this->endDate = $dateData->getEndDate(); $this->startTime = $dateData->getStartTime(); $this->endTime = $dateData->getEndTime(); $this->recurring = $dateData->getRecurring(); $this->eventComment = null; if (is_array($otherInfo) && isset($otherInfo['eventComment'])) { $this->eventComment = $otherInfo['eventComment']; } }
/** * Update entry by id * @param int $id * @param array $timeSet * @param int $articleId * @param string $fieldName * @param string $recurring */ public function update($id, $timeSet, $articleId = null, $fieldName = null, $recurring = null, $otherInfo = null) { $em = $this->getEntityManager(); $entry = $this->find($id); if (!$entry) { return false; } if (is_null($articleId)) { $articleId = $entry->getArticleId(); } if (is_null($fieldName)) { $fieldName = $entry->getFieldName(); } $insertValues = $this->buildInsertValues($timeSet, $recurring); try { $em->getConnection()->beginTransaction(); $em->remove($entry); foreach ($insertValues as $dateValue) { foreach (array_merge(array($dateValue), $dateValue->getSpawns()) as $dateValue) { $articleDatetime = new ArticleDatetime(); $articleDatetime->setValues($dateValue, $articleId, $fieldName, $entry->getArticleType(), $otherInfo); $em->persist($articleDatetime); } } $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { $em->getConnection()->rollback(); $em->close(); return $e; } }
public function setId($id) { $this->__load(); return parent::setId($id); }