/** * Adds an image to album * * @param Tx_Yag_Domain_Model_Item $item Item to be added to album */ public function addItem(Tx_Yag_Domain_Model_Item $item) { $this->album->addItem($item); if ($this->album->getThumb() == NULL) { $this->album->setThumb($item); } }
/** * @return Tx_Yag_Domain_Model_Item */ protected function getTestItemObject() { $item = new Tx_Yag_Domain_Model_Item(); $album = new Tx_Yag_Domain_Model_Album(); $gallery = new Tx_Yag_Domain_Model_Gallery(); $album->setGallery($gallery); $item->setAlbum($album); $item->setSourceuri(substr(ExtensionManagementUtility::extPath($this->extensionName) . 'Tests/Unit/TestImages/', strlen(PATH_site)) . 'testImage.jpg'); return $item; }
/** * Renders link for an album * * @param Tx_Yag_Domain_Model_Album $album Album object to render link for * @param Tx_Yag_Domain_Model_Gallery $gallery Gallery object to render link for * @param integer $pageUid * @param integer $pageType type of the target page. See typolink.parameter * @param integer $pageType type of the target page. See typolink.parameter * @param boolean $noCache set this to disable caching for the target page. You should not need this. * @param boolean $noCacheHash set this to supress the cHash query parameter created by TypoLink. You should not need this. * @param string $section the anchor to be added to the URI * @param string $format The requested format, e.g. ".html" * @return string Rendered link for album * @throws Exception */ public function render(Tx_Yag_Domain_Model_Album $album = null, Tx_Yag_Domain_Model_Gallery $gallery = null, $pageUid = null, $pageType = 0, $noCache = false, $noCacheHash = false, $section = '', $format = '') { // TODO implement gallery download if ($album instanceof Tx_Yag_Domain_Model_Album) { $namespace = Tx_Yag_Domain_Context_YagContextFactory::getInstance()->getObjectNamespace() . '.albumUid'; $arguments = Tx_PtExtbase_Utility_NameSpace::saveDataInNamespaceTree($namespace, array(), $album->getUid()); } Tx_PtExtbase_State_Session_SessionPersistenceManagerFactory::getInstance()->addSessionRelatedArguments($arguments); return parent::render('downloadAsZip', $arguments, 'ItemList', null, null, $pageUid, $pageType, $noCache, $noCacheHash, $section, $format); }
/** * Creates path for original files on server. * If path does not exist, it will be created if given parameter is true. * * @param Tx_Yag_Domain_Model_Album $album * @param bool $createIfNotExists If set to true, directory will be created if it does not exist * @return string Path for original images (absolute) * @throws Exception */ public function getOrigFileDirectoryPathForAlbum(Tx_Yag_Domain_Model_Album $album, $createIfNotExists = true) { $path = Tx_Yag_Domain_Configuration_ConfigurationBuilderFactory::getInstance()->buildExtensionConfiguration()->getOrigFilesRootAbsolute() . '/' . $album->getUid() . '/'; if ($createIfNotExists) { $success = Tx_Yag_Domain_FileSystem_Div::checkDirAndCreateIfMissing($path); if (!$success) { throw new Exception(sprintf('The original file path %s for album %s could not be created!', $path, $album->getUid()), 1404452464); } } return $path; }
/** * Renders link for an album * * @param integer $albumUid UID of album to render link for * @param Tx_Yag_Domain_Model_Album $album Album object to render link for * @param Tx_Yag_Domain_Model_Gallery $gallery Gallery object to render link for * @param integer pageUid (Optional) ID of page to render link for. If null, current page is used * @param integer $pageType type of the target page. See typolink.parameter * @param integer $pageType type of the target page. See typolink.parameter * @param boolean $noCache set this to disable caching for the target page. You should not need this. * @param boolean $noCacheHash set this to supress the cHash query parameter created by TypoLink. You should not need this. * @param string $section the anchor to be added to the URI * @param string $format The requested format, e.g. ".html" * @return string Rendered link for album * @throws Exception */ public function render($albumUid = 0, Tx_Yag_Domain_Model_Album $album = NULL, Tx_Yag_Domain_Model_Gallery $gallery = NULL, $pageUid = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '') { if ($albumUid == 0 && $album === NULL) { throw new Exception('You have to set "albumUid" or "album" as parameter. Both parameters can not be empty when using albumLinkViewHelper', 1295575454); } if ($albumUid == 0) { $albumUid = $album->getUid(); } $baseNamespace = Tx_Yag_Domain_Context_YagContextFactory::getInstance()->getObjectNamespace(); $arguments = Tx_PtExtbase_Utility_NameSpace::saveDataInNamespaceTree($baseNamespace . '.albumUid', array(), $albumUid); if ($gallery !== NULL) { $arguments = Tx_PtExtbase_Utility_NameSpace::saveDataInNamespaceTree($baseNamespace . '.galleryUid', $arguments, $gallery->getUid()); } return parent::render('submitFilter', $arguments, 'ItemList', NULL, NULL, $pageUid, $pageType, $noCache, $noCacheHash, $section, $format); }
protected function createAlbums(Tx_Yag_Domain_Model_Gallery $gallery) { $albumRepository = $this->objectManager->get('Tx_Yag_Domain_Repository_AlbumRepository'); /* @var $albumRepository Tx_Yag_Domain_Repository_AlbumRepository */ $first = true; for ($i = 1; $i <= $this->albumsPerGalleryCount; $i++) { $album = new Tx_Yag_Domain_Model_Album(); $album->setName('TestAlbum ' . $i); $album->setDescription('Created on ' . date('d.m.Y H:i:s')); $album->setGallery($gallery); $albumRepository->add($album); if ($first) { $gallery->setThumbAlbum($album); $first = FALSE; } $this->createItems($album); } }
/** * @return Tx_Yag_Domain_Model_Album */ public function getAlbum() { if (!$this->selectedAlbumUid) { return NULL; } if ($this->selectedAlbum instanceof Tx_Yag_Domain_Model_Album && $this->selectedAlbum->getUid() == $this->selectedAlbumUid) { return $this->selectedAlbum; } else { return $this->objectManager->get('Tx_Yag_Domain_Repository_AlbumRepository')->findByUid($this->selectedAlbumUid); } }
/** * Adds a new album to repository * * @param Tx_Yag_Domain_Model_Album $album */ public function add($album) { if (!$album->getSorting()) { $sorting = 0; if ($album->getGallery()->getAlbums()->count() > 0) { $sorting = $album->getGallery()->getAlbums()->current()->getSorting(); } $album->setSorting($sorting + 1); } parent::add($album); }
/** * Imports a file given by its filepath. If an item object * is given, this one is used. Otherwise a new one is created. * * @param string $filePath Absolute file path to file on server * @param Tx_Yag_Domain_Model_Item $item Item to attach file to * @return Tx_Yag_Domain_Model_Item Item created or used for import */ protected function importFileByFilename($filePath, $item = null) { // Create new item if none is given if ($item === null) { $item = $this->objectManager->get('Tx_Yag_Domain_Model_Item'); $item->setFeUserUid($this->feUser->getUid()); } // Set sorting of item, if not yet given if (!$item->getSorting() > 0) { $item->setSorting($this->album->getMaxSorting() + 1); } $fileSizes = getimagesize($filePath); $relativeFilePath = $this->getRelativeFilePath($filePath); $item->setSourceuri($relativeFilePath); $item->setFilename(Tx_Yag_Domain_FileSystem_Div::getFilenameFromFilePath($relativeFilePath)); $item->setWidth($fileSizes[0]); $item->setHeight($fileSizes[1]); $item->setItemType($fileSizes['mime']); // Metadata if ($this->importerConfiguration->getParseItemMeta()) { try { $item->setItemMeta($this->itemMetaDataFactory->createItemMetaForFile($filePath)); } catch (Exception $e) { GeneralUtility::sysLog('Error while extracting MetaData from "' . $filePath . '". Error was: ' . $e->getMessage(), 'yag', 2); } if ($this->importerConfiguration->getGenerateTagsFromMetaData() && is_a($item->getItemMeta(), 'Tx_Yag_Domain_Model_ItemMeta')) { try { $item->addTagsFromCSV($item->getItemMeta()->getKeywords()); } catch (Exception $e) { GeneralUtility::sysLog('Error while saving KeyWords from"' . $filePath . '". Error was: ' . $e->getMessage(), 'yag', 2); } } $item->setTitle($this->processStringFromMetaData($item, $this->importerConfiguration->getTitleFormat())); $item->setDescription($this->processStringFromMetaData($item, $this->importerConfiguration->getDescriptionFormat())); } $item->setAlbum($this->album); $item->setFilesize(filesize($filePath)); $item->setItemAsAlbumThumbIfNotExisting(); $item->setFilehash(md5_file($filePath)); $this->albumContentManager->addItem($item); $this->itemRepository->add($item); return $item; }
/** * @param PathInfo $pathInfo * @param \Tx_Yag_Domain_Model_Album $album * @return array */ protected function buildAlbumObjectInfo(PathInfo $pathInfo, \Tx_Yag_Domain_Model_Album $album) { return array('name' => $album->getName() . ' |' . $album->getUid(), 'identifier' => \Tx_Yag_Domain_FileSystem_Div::concatenatePaths(array($pathInfo->getGalleryPath(), $album->getName() . ' |' . $album->getUid())) . '/', 'storage' => $this->storage->getUid()); }
/** * Deletes given album * * @param Tx_Yag_Domain_Model_Album $album * @rbacNeedsAccess * @rbacObject Album * @rbacAction delete */ public function deleteAlbumAction(Tx_Yag_Domain_Model_Album $album) { $album->delete(); $this->albumRepository->syncTranslatedAlbums(); $this->returnDataAndShutDown(); }
/** * Creates a new album and imports images from zip into that album * * TODO this method is not yet used and hence not tested! * * @param Tx_Yag_Domain_Model_Gallery $gallery Gallery to add album to * @param string $albumName Name of album to be created * @throws Exception */ public function createNewAlbumAndImportFromZipAction(Tx_Yag_Domain_Model_Gallery $gallery, $albumName) { $album = new Tx_Yag_Domain_Model_Album(); $album->setName($albumName); $album->addGallery($gallery); $gallery->addAlbum($album); $this->albumRepository->add($album); $persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'); $persistenceManager->persistAll(); if (!$album->getUid() > 0) { throw new Exception('Album hat keine UID!'); } $importer = Tx_Yag_Domain_Import_ZipImporter_ImporterBuilder::getInstance()->getZipImporterInstanceForAlbum($album); $importer->runImport(); $this->view->assign('album', $album); }
/** * Set this item as album thumb, if no thumbnail for album is existing * */ public function setItemAsAlbumThumbIfNotExisting() { if ($this->album->getThumb() == null) { $this->album->setThumb($this); } }
/** * Sets sorting of whole album to given sorting parameter with given sorting direction * * @param Tx_Yag_Domain_Model_Album $album * @param string $sortingField * @param int $sortingDirection (1 = ASC, -1 = DESC) * @rbacNeedsAccess * @rbacObject album * @rbacAction update * @return void */ public function updateSortingAction(Tx_Yag_Domain_Model_Album $album, $sortingField, $sortingDirection) { $direction = $sortingDirection == 1 ? \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING : \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING; $album->updateSorting($sortingField, $direction); $this->albumRepository->update($album); $this->addFlashMessage(LocalizationUtility::translate('tx_yag_controller_album.sortingChanged', $this->extensionName), '', FlashMessage::OK); $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll(); $this->forward('list', 'ItemList'); }
/** * Deletes given album * * @param Tx_Yag_Domain_Model_Album $album * @rbacNeedsAccess * @rbacObject Album * @rbacAction delete */ public function deleteAlbumAction(Tx_Yag_Domain_Model_Album $album) { $album->delete(); $this->returnDataAndShutDown(); }