setAlbum example

$media->setCreated(new DateTime());
        $media->setUserId(0);

        /** @var Album|null $album */
        $album = $this->getManager()->find(Album::class$albumId);
        if (!$album) {
            // Cleanup temporary file             $this->deleteTmpFile($file);
            throw new CustomValidationException(sprintf('Album by id %s not found', $albumId));
        }

        $media->setAlbum($album);

        try {
            // Persist the model into the model manager this uploads and resizes the image             $this->getManager()->persist($media);
        } catch (ORMException $e) {
            throw new CustomValidationException(sprintf('Some error occurred while persisting your media'));
        } finally {
            // Cleanup temporary file             $this->deleteTmpFile($file);
        }

        
$albumId = !empty($params['albumID']) ? $params['albumID'] : self::UNSORTED_ALBUM_ID;
        /** @var Album|null $album */
        $album = $this->get('models')->find(Album::class$albumId);

        if (!$album) {
            $this->View()->assign(['success' => false, 'message' => 'Invalid album id passed']);

            return;
        }

        $media->setAlbum($album);
        $media->setDescription('');
        $media->setCreated(new DateTime());

        $identity = $this->get('auth')->getIdentity();

        if ($identity !== null) {
            $media->setUserId($identity->id);
        } else {
            $media->setUserId(self::FALLBACK_USER_ID);
        }

        
Home | Imprint | This part of the site doesn't use cookies.