diff --git a/bower.json b/bower.json index 172a3bc945..afb39ca122 100644 --- a/bower.json +++ b/bower.json @@ -26,8 +26,7 @@ "fancytree": "~2.7", "bootstrap-sass": "v2.3.2.2", "jquery.lazyload": "~1.9.7", - "jquery-treeview": "~1.4.2", - "alchemy-embed-medias": "~0.3.2" + "jquery-treeview": "~1.4.2" }, "devDependencies": { "mocha": "latest", diff --git a/composer.json b/composer.json index 62c37a7134..a613ba34a7 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "php": ">=5.5.9", "ext-intl": "*", "alchemy-fr/tcpdf-clone": "~6.0", - "alchemy/embed-bundle": "^0.3.2", + "alchemy/embed-bundle": "^0.4.1", "alchemy/geonames-api-consumer": "~0.1.0", "alchemy/google-plus-api-client": "~0.6.2", "alchemy/mediavorus": "^0.4.4", diff --git a/composer.lock b/composer.lock index c762f1e5f6..51695bc8e5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2d3272f471d3cf0eb5c7d44c46bc7145", - "content-hash": "f3050bb8fb62cb6b00e3799a8e5c6936", + "hash": "19164414a7dd4683f8d99d828456fb19", + "content-hash": "b908509f786ac7437d41055fbd021bef", "packages": [ { "name": "alchemy-fr/tcpdf-clone", @@ -132,16 +132,16 @@ }, { "name": "alchemy/embed-bundle", - "version": "v0.3.3", + "version": "v0.4.1", "source": { "type": "git", "url": "https://github.com/alchemy-fr/embed-bundle.git", - "reference": "2eedc22e0030f6b4a166de2b93ffb108193c43dd" + "reference": "edbbb7f0b9de199d5a67ce19fbc41bb94168352d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alchemy-fr/embed-bundle/zipball/2eedc22e0030f6b4a166de2b93ffb108193c43dd", - "reference": "2eedc22e0030f6b4a166de2b93ffb108193c43dd", + "url": "https://api.github.com/repos/alchemy-fr/embed-bundle/zipball/edbbb7f0b9de199d5a67ce19fbc41bb94168352d", + "reference": "edbbb7f0b9de199d5a67ce19fbc41bb94168352d", "shasum": "" }, "require-dev": { @@ -179,10 +179,10 @@ ], "description": "Embed resources bundle", "support": { - "source": "https://github.com/alchemy-fr/embed-bundle/tree/v0.3.3", + "source": "https://github.com/alchemy-fr/embed-bundle/tree/v0.4.1", "issues": "https://github.com/alchemy-fr/embed-bundle/issues" }, - "time": "2016-06-14 13:51:50" + "time": "2016-06-16 09:35:17" }, { "name": "alchemy/geonames-api-consumer", diff --git a/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php b/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php index 9a48d92121..38975efb53 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php @@ -14,9 +14,12 @@ use Alchemy\Phrasea\Application\Helper\EntityManagerAware; use Alchemy\Phrasea\Application\Helper\SearchEngineAware; use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Controller\RecordsRequest; +use Alchemy\Phrasea\Model\Entities\BasketElement; use Alchemy\Phrasea\Model\Repositories\BasketElementRepository; use Alchemy\Phrasea\Model\Repositories\StoryWZRepository; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; +use Alchemy\Phrasea\Twig\Fit; +use Alchemy\Phrasea\Twig\PhraseanetExtension; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -69,15 +72,16 @@ class RecordController extends Controller ); if ($record->is_from_reg()) { + $currentRecord = $this->getContainerResult($record->get_container()); $train = $this->render('prod/preview/reg_train.html.twig', ['record' => $record]); - } - - if ($record->is_from_basket() && $reloadTrain) { + } else if ($record->is_from_basket() && $reloadTrain) { + $currentRecord = $this->getContainerResult($record); $train = $this->render('prod/preview/basket_train.html.twig', ['record' => $record]); - } - - if ($record->is_from_feed()) { + } else if ($record->is_from_feed()) { + $currentRecord = $this->getContainerResult($record->get_container()); $train = $this->render('prod/preview/feed_train.html.twig', ['record' => $record]); + } else { + $currentRecord = $this->getContainerResult($record); } $recordCaptions = []; @@ -86,6 +90,9 @@ class RecordController extends Controller $recordCaptions[$field->get_name()] = $field->get_serialized_values(); } + // add properties if record is embed in iframe: + + return $this->app->json([ "desc" => $this->render('prod/preview/caption.html.twig', [ 'record' => $record, @@ -102,6 +109,7 @@ class RecordController extends Controller 'baskets' => $record->get_container_baskets($this->getEntityManager(), $this->getAuthenticatedUser()), ]), "current" => $train, + "record" => $currentRecord, "history" => $this->render('prod/preview/short_history.html.twig', [ 'record' => $record, ]), @@ -216,4 +224,78 @@ class RecordController extends Controller { return $this->app['repo.story-wz']; } + + + private function getContainerResult($recordContainer) + { + /* @var $recordPreview \record_preview */ + $helpers = new PhraseanetExtension($this->app); + + $fit = $this->fitIn($recordContainer); + + $recordData = [ + 'databoxId' => $recordContainer->getBaseId(), + 'id' => $recordContainer->get_serialize_key(), + 'isGroup' => $recordContainer->isStory(), + //'type' => $recordObj->getType(), + 'url' => (string)$helpers->getThumbnailUrl($recordContainer), + 'width' => $fit['width'], + 'height' => $fit['height'], + 'fit' => [ + 'width' => $fit['width'], + 'height' => $fit['height'], + 'top' => $fit['top'], + ] + ]; + $userHaveAccess = $this->app->getAclForUser($this->getAuthenticatedUser())->has_access_to_subdef($recordContainer, 'preview'); + if ($userHaveAccess) { + $recordPreview = $recordContainer->get_preview(); + } else { + $recordPreview = $recordContainer->get_thumbnail(); + } + + $recordData['preview'] = [ + 'width' => $recordPreview->get_width(), + 'height' => $recordPreview->get_height(), + 'url' => $this->app->url('alchemy_embed_view', [ + 'url' => (string)($this->getAuthenticatedUser() ? $recordPreview->get_url() : $recordPreview->get_permalink()->get_url()), + 'autoplay' => false + ]) + ]; + + return $recordData; + } + + /** + * Resize record thumbnail - direct translation from twig macro + * @param $record + * @return array + */ + private function fitIn($record) + { + $thumb_w = 70; + $thumb_h = 70; + + $thumbnail = $record->get_thumbnail(); + + if ($thumbnail != null) { + + $thumb_w = $thumbnail->get_width(); + $thumb_h = $thumbnail->get_height(); + } + + $box_w = 70; + $box_h = 80; + + $original_h = $thumb_h > 0 ? $thumb_h : 70; + $original_w = $thumb_w > 0 ? $thumb_w : 70; + + $fitHelper = new Fit(); + $fit_size = $fitHelper->fitIn( + ["width" => $original_w, "height" => $original_h], + ["width" => $box_w, "height" => $box_h] + ); + + return $fit_size; + } } diff --git a/package.json b/package.json index 59d380a5d2..94353c138b 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "postinstall": "./node_modules/.bin/gulp install;" }, "dependencies": { - "phraseanet-production-client": "~0.19.0" + "alchemy-embed-medias": "^0.4.2", + "phraseanet-production-client": "~0.20.0" } } diff --git a/resources/gulp/build.js b/resources/gulp/build.js index 63dc8beba8..c8177a8d91 100644 --- a/resources/gulp/build.js +++ b/resources/gulp/build.js @@ -26,7 +26,7 @@ gulp.task('build', ['build-vendors'], function(){ // standalone vendors used across application gulp.task('build-vendors', [ - 'build-alchemy-embed', + 'build-alchemy-embed-medias', 'build-phraseanet-production-client', 'build-bootstrap', 'build-html5shiv', diff --git a/resources/gulp/components/vendors/alchemy-embed.js b/resources/gulp/components/vendors/alchemy-embed.js index 97a92126e1..5b3b7451b6 100644 --- a/resources/gulp/components/vendors/alchemy-embed.js +++ b/resources/gulp/components/vendors/alchemy-embed.js @@ -4,25 +4,22 @@ var utils = require('../../utils.js'); var debugMode = false; // for dev purposes -gulp.task('copy-alchemy-embed-debug', function(){ +gulp.task('copy-alchemy-embed-medias-debug', function(){ debugMode = true; - gulp.start('copy-alchemy-embed'); + gulp.start('copy-alchemy-embed-medias'); }); -gulp.task('copy-alchemy-embed', function(){ +gulp.task('copy-alchemy-embed-medias', function(){ // copy all dist folder: - if( debugMode === true) { - return gulp.src('vendor/alchemy/embed-bundle/dist/**/*') - .pipe(gulp.dest( config.paths.build + 'vendors/alchemy-embed-medias')); - } - return gulp.src(config.paths.vendors + 'alchemy-embed-medias/dist/**/*') + + return gulp.src('node_modules/alchemy-embed-medias/dist/**/*') .pipe(gulp.dest( config.paths.build + 'vendors/alchemy-embed-medias')); }); -gulp.task('watch-alchemy-embed-js', function() { +gulp.task('watch-alchemy-embed-medias-js', function() { debugMode = true; // in dev mode, watch composer's vendor path: - return gulp.watch('vendor/alchemy/embed-bundle/dist/**/*', ['copy-alchemy-embed']); + return gulp.watch('node_modules/alchemy-embed-medias/dist/**/*', ['copy-alchemy-embed-medias']); +}); +gulp.task('build-alchemy-embed-medias', function(){ + gulp.start('copy-alchemy-embed-medias'); }); -gulp.task('build-alchemy-embed', function(){ - gulp.start('copy-alchemy-embed'); -}); \ No newline at end of file diff --git a/resources/gulp/watch.js b/resources/gulp/watch.js index 4c087a56d5..e31e5d8457 100644 --- a/resources/gulp/watch.js +++ b/resources/gulp/watch.js @@ -29,7 +29,7 @@ gulp.task('watch-js', function(){ // gulp.start('watch-permaview'); gulp.start('watch-setup-js'); gulp.start('watch-authentication-js'); - gulp.start('watch-alchemy-embed-js'); + gulp.start('watch-alchemy-embed-medias-js'); gulp.start('watch-phraseanet-production-client-js'); }); diff --git a/templates/web/common/thumbnail.html.twig b/templates/web/common/thumbnail.html.twig index 07745d5d0e..742951f08b 100644 --- a/templates/web/common/thumbnail.html.twig +++ b/templates/web/common/thumbnail.html.twig @@ -10,24 +10,23 @@ {% endif %} {% if record_type == 'VIDEO_MP4' or record_type == 'VIDEO_FLV' %} -