/** * @param string $websiteId * @param array $columnValues * @param boolean $useColumnsValuesId * @return \Orm\Entity\Media * @throws \Cms\Exception */ public function create($websiteId, array $columnValues, $useColumnsValuesId = false) { if (!$useColumnsValuesId) { $website = $this->getEntityManager()->getRepository('Orm\\Entity\\Website')->findOneById($websiteId); if ($website === null) { throw new CmsException('268', __METHOD__, __LINE__); } $albumId = isset($columnValues['albumid']) ? $columnValues['albumid'] : null; $album = $this->getEntityManager()->getRepository('Orm\\Entity\\Album')->findOneBy(array('id' => $albumId, 'websiteid' => $websiteId)); if ($album === null) { throw new CmsException('267', __METHOD__, __LINE__); } } $media = new Media(); if ($useColumnsValuesId && isset($columnValues['id'])) { $media->setId($columnValues['id']); } else { $media->setNewGeneratedId(); } if (isset($columnValues['dateuploaded'])) { $media->setDateUploaded($columnValues['dateuploaded']); } else { $media->setDateUploaded(time()); } if (isset($columnValues['albumid'])) { /** @var \Orm\Entity\Album $album */ $album = $this->getEntitymanager()->getRepository('Orm\\Entity\\Album')->findOneBy(array('id' => $columnValues['albumid'], 'websiteid' => $websiteId)); $media->setAlbumId($album->getId()); } $media->setWebsiteId($websiteId); $media->setName($columnValues['name']); if (isset($columnValues['filename'])) { $media->setFilename($columnValues['filename']); } if (isset($columnValues['file'])) { $media->setFile($columnValues['file']); } $media->setExtension($columnValues['extension']); $media->setSize($columnValues['size']); if (isset($columnValues['lastmod'])) { $media->setLastmod($columnValues['lastmod']); } else { $media->setLastmod(time()); } $media->setType($columnValues['type']); if (isset($columnValues['mimetype'])) { $media->setMimetype($columnValues['mimetype']); } try { $entityManager = $this->getEntityManager(); $entityManager->persist($media); $entityManager->flush(); $entityManager->refresh($media); $this->clearEntityManager(); } catch (Exception $e) { throw new CmsException(104, __METHOD__, __LINE__, null, $e); } return $media; }