mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00

* PHRAS-3602 : migrate validations to baskets WIP [skip ci] * PHRAS-3602 : migrate validations code to baskets code (wip) WIP [skip ci] * PHRAS-3602 : migrate validations to baskets WIP [skip ci] * PHRAS-3602 : migrate validations to baskets WIP [skip ci] * PHRAS-3602 : fake commit to run tests * PHRAS-3602 : migrate validations to baskets fix typo * PHRAS-3602 : migrate validations to baskets fixed (some) tests * PHRAS-3602 : migrate validations to baskets fixed (some) tests * PHRAS-3602 : migrate validations to baskets fixed (some) tests. need to remove method():return_type signature because of old phpunit which does not mock it * PHRAS-3602 : migrate validations to baskets fix * PHRAS-3602 : migrate validations to baskets fix err 500 when a "vote" (feedback) is deployed in wz * PHRAS-3602 : migrate validations to baskets fix missing votes for element+participant fix update vote dates on basket * PHRAS-3602 : ux bump production-client to 34 WIP [skip ci] * PHRAS-3602 : rebase (bump production-client to 37) WIP [skip ci] * PHRAS-3602 : refacto css/twig/templates/... ; replace many png's by fonts WIP [skip ci] * PHRAS-3602 : fix icon / css WIP * PHRAS-3602 : better icon align ; back button color fix : save button after adding a user WIP [skip ci] * PHRAS-3602 : restore sharebasket controller todo : implement modification right ; owner is participant ? WIP [skip ci] * PHRAS-3602 : set "canModifiy" ; cleanup WIP [skip ci] * PHRAS-3602 : respect "can_modify" on shared basket WIP [skip ci] * PHRAS-3602 : fix badge icon bg ; fix button css WIP [skip ci] * PHRAS-3602 : fix css & cleanup WIP [skip ci] * PHRAS-3602 : fix 500 on preview/feedback tab WIP [skip ci] * PHRAS-3602 : fix allow to display dlg without selection * PHRAS-3602 : bump version to 4.1.6-rc1 ; prodclient=38 WIP [skip ci] * PHRAS-3602 : factorize baskets menu (wip) WIP [skip ci] * PHRAS-3602 : modify already shared or feedback basket (general menu) 4th icon on badges (vote != modify) quitshare option (todo back) allow fa-icons in toolbar WIP [skip ci] * PHRAS-3602 : add share end-date (todo:db write) add 4th general toggle button fix badge selection bug fix css badges zone (form position) WIP [skip ci] * PHRAS-3602 : big refacto to use "sharebasket" vocab. fusion "feedback/sharebasket" removed "feedback" adaptative ux: 1 "can_agree" ==> feedback display bump production-client to v50 todo: save shr/fbk end-dates todo: rename "pushXXX" to pushAndShare ? WIP [skip ci] * PHRAS-3602 : share / feedback expiration dates are saved in db date pickers with delta menu better adaptive ux todo: move select general togglers WIP [skip ci] * PHRAS-3602 : revert validation* tables (remove "dead" rename) drop all foreign keys from validation* WIP [skip ci] * PHRAS-3602 : restore deleted fields in validation, regenerate proxies WIP [skip ci] * PHRAS-3602 : fix initiator_id WIP [skip ci] * fix initiator_id-bis * PHRAS-3602 : css for input-text with glued button dynamic load of users-lists (left zone) = less duplicated code fix : users-lists works after refresh WIP [skip ci] * PHRAS-3602 : fix users-lists manager (orange) : go flex ! * PHRAS-3602 : empty dist to ease rebase WIP [skip ci] * PHRAS-3602 : rebase WIP [skip ci] * PHRAS-3602 : new ux for "owner" feedback mode is an independent toggle fix "missing mandatory parameter" WIP [skip ci] * PHRAS-3602 : fix css of owner badge WIP [skip ci] * PHRAS-3602 : fix handling of feedback initiator WIP [skip ci] * PHRAS-3602 : better wss to follow "skins" full roboto removed useless class "with-button" WIP [skip ci] * PHRAS-3602 : fix "a token require a validation" temporary fix 500 due to send email to (null) vote-initiator for simple share todo: send a specific email for simple share WIP [skip ci] * PHRAS-3602 : different emails depending if user can vote or not WIP [skip ci] * PHRAS-3602 : expired shared baskets removed from wz WIP [skip ci] * PHRAS-3602 : fix logic error on last sql WIP [skip ci] * PHRAS-3602 : fix missing shared baskets on wz WIP [skip ci] * PHRAS-3602 : fix blinking of wz/basket detail now only the title:hover displays detail WIP [skip ci] * PHRAS-3602 : rebase WIP [skip ci] * PHRAS-3602 : update basket proxy WIP [skip ci] * PHRAS-3602 : fix forever "unread" basket WIP [skip ci] * PHRAS-3602 : fix display of unread basket ; sync "eye" icon with css change WIP [skip ci] * PHRAS-3602 : "quitshare" action works WIP [skip ci] * PHRAS-3602 : missing dist files WIP [skip ci] * PHRAS-3602 : cleanup & run ci * PHRAS-3602 : disable failing unit test ; remove blue on onread basket * PHRAS-3602 : separate "vote" & "share" emails templates & u-tests * PHRAS-3602 : add 2 icons "stack" to icomoon set WIP [skip ci] * PHRAS-3602 : fix test * PHRAS-3602 : fix test ; add test for simple share email notification * PHRAS-3602 : changed proxy * PHRAS-3602 : colored basket icons WIP [skip ci] * PHRAS-3602 : circle basket icons WIP [skip ci] * PHRAS-3602 : fix wz filters, add "share" filter. todo: fix fr writing (new string) WIP [skip ci] * PHRAS-3602 : fix "share" dichotomy : use "shared" for wz filter WIP [skip ci] * PHRAS-3602 : fix PHRAS-3624 ; PHRAS-3623 ; now adding/removing a user from user list is immediate (no more save button) WIP [skip ci] * PHRAS-3602 : fix PHRAS-3647 ; shared basket are listed in api (for list and related record) * PHRAS-3602 : fix due to failing test * PHRAS-3602 : fix: can load a 1000 users list todo : move slow code to worker * PHRAS-3602 : fix due to failing test * PHRAS-3468 : (fixed in 3602) fix basket content still visible when baskets are hidden (wz-filter) * PHRAS-3602 : add "wip" baskets with notification & lock todo : move slow code from message to worker * PHRAS-3602 : fix tests due to accidental rename * PHRAS-3602 : fix : menu closes when mouse out : bump to 4.1.6-rc3 todo : fast move to another basket makes the menu appear on top ? * add shareBasket worker * fix test * PHRAS-3602 : fix : rights buttons on badges now works for users added from search (did work only from loading list) * PHRAS-3590 Co-authored-by: aynsix <asr@esokia-webagency.com> Co-authored-by: Nicolas Maillat <maillat@alchemy.fr>
421 lines
15 KiB
PHP
421 lines
15 KiB
PHP
<?php
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2016 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Controller\Prod;
|
|
|
|
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\Core\Event\Record\DeleteEvent;
|
|
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
|
use Alchemy\Phrasea\Core\Event\RecordEdit;
|
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
|
use Alchemy\Phrasea\Model\Entities\Basket;
|
|
use Alchemy\Phrasea\Model\Repositories\BasketElementRepository;
|
|
use Alchemy\Phrasea\Model\Repositories\StoryWZRepository;
|
|
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
|
use Alchemy\Phrasea\Twig\PhraseanetExtension;
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class RecordController extends Controller
|
|
{
|
|
use EntityManagerAware;
|
|
use SearchEngineAware;
|
|
/**
|
|
* Get record detailed view
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse
|
|
*/
|
|
public function getRecord(Request $request)
|
|
{
|
|
if (!$request->isXmlHttpRequest()) {
|
|
$this->app->abort(400);
|
|
}
|
|
|
|
$searchEngine = $options = null;
|
|
$train = '';
|
|
|
|
if ('' === $env = strtoupper($request->get('env', ''))) {
|
|
$this->app->abort(400, '`env` parameter is missing');
|
|
}
|
|
|
|
// Use $request->get as HTTP method can be POST or GET
|
|
if ('RESULT' == $env = strtoupper($request->get('env', ''))) {
|
|
try {
|
|
$options = SearchEngineOptions::hydrate($this->app, $request->get('options_serial'));
|
|
$searchEngine = $this->getSearchEngine();
|
|
} catch (\Exception $e) {
|
|
$this->app->abort(400, 'Search-engine options are not valid or missing');
|
|
}
|
|
}
|
|
|
|
$pos = (int) $request->get('pos', 0);
|
|
$query = $request->get('query', '');
|
|
$reloadTrain = !! $request->get('roll', false);
|
|
|
|
$record = new \record_preview(
|
|
$this->app,
|
|
$env,
|
|
$pos < 0 ? 0 : $pos,
|
|
$request->get('cont', ''),
|
|
$searchEngine,
|
|
$query,
|
|
$options
|
|
);
|
|
|
|
$currentRecord = $this->getContainerResult($record);
|
|
|
|
if ($record->is_from_reg()) {
|
|
$train = $this->render('prod/preview/reg_train.html.twig', ['record' => $record]);
|
|
} else if ($record->is_from_basket() && $reloadTrain) {
|
|
$train = $this->render('prod/preview/basket_train.html.twig', ['record' => $record]);
|
|
} else if ($record->is_from_feed()) {
|
|
$train = $this->render('prod/preview/feed_train.html.twig', ['record' => $record]);
|
|
}
|
|
|
|
$recordCaptions = [];
|
|
foreach ($record->get_caption()->get_fields(null, true) as $field) {
|
|
// get field's values
|
|
$recordCaptions[$field->get_name()] = $field->get_serialized_values();
|
|
}
|
|
$recordCaptions["technicalInfo"] = $record->getPositionFromTechnicalInfos();
|
|
|
|
// escape record title before rendering
|
|
$recordTitle = explode("</span>", $record->get_title());
|
|
if (count($recordTitle) >1) {
|
|
$recordTitle[1] = htmlspecialchars($recordTitle[1]);
|
|
$recordTitle = implode("</span>", $recordTitle);
|
|
} else {
|
|
$recordTitle = htmlspecialchars($record->get_title());
|
|
}
|
|
|
|
$containerType = null;
|
|
|
|
if ($env === 'BASK') {
|
|
/** @var Basket $basket */
|
|
$basket = $record->get_container();
|
|
if ($basket->isVoteBasket()) {
|
|
$containerType = 'feedback';
|
|
} elseif ($basket->getPusher()) {
|
|
$containerType = 'push';
|
|
} else {
|
|
$containerType = 'basket';
|
|
}
|
|
} elseif ($env === 'REG') {
|
|
$containerType = 'regroup';
|
|
}
|
|
|
|
$basketElementsRepository = $this->getBasketElementRepository();
|
|
$feedbackElementDatas = $basketElementsRepository->findElementsDatasByRecord($record);
|
|
|
|
return $this->app->json([
|
|
"desc" => $this->render('prod/preview/caption.html.twig', [
|
|
'record' => $record,
|
|
'highlight' => $query,
|
|
'searchEngine' => $searchEngine,
|
|
'searchOptions' => $options,
|
|
]),
|
|
"recordCaptions" => $recordCaptions,
|
|
"html_preview" => $this->render('common/preview.html.twig', [
|
|
'record' => $record
|
|
]),
|
|
"others" => $this->render('prod/preview/appears_in.html.twig', [
|
|
'parents' => $record->get_grouping_parents(),
|
|
'baskets' => $record->get_container_baskets($this->getEntityManager(), $this->getAuthenticatedUser()),
|
|
]),
|
|
"current" => $train,
|
|
"record" => $currentRecord,
|
|
"history" => $this->render('prod/preview/short_history.html.twig', [
|
|
'record' => $record,
|
|
]),
|
|
"popularity" => $this->render('prod/preview/popularity.html.twig', [
|
|
'record' => $record,
|
|
]),
|
|
"tools" => $this->render('prod/preview/tools.html.twig', [
|
|
'record' => $record,
|
|
]),
|
|
"votingNotice" => $this->render('prod/preview/voting_notice.html.twig', [
|
|
'feedbackElementDatas' => $feedbackElementDatas
|
|
]),
|
|
"pos" => $record->getNumber(),
|
|
"title" => $recordTitle,
|
|
"containerType" => $containerType,
|
|
"databox_name" => $record->getDatabox()->get_label($this->app['locale']),
|
|
"collection_name" => $record->getCollection()->get_name(),
|
|
"collection_logo" => $record->getCollection()->getLogo($record->getBaseId(), $this->app),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param \record_preview $recordContainer
|
|
* @return array
|
|
*/
|
|
private function getContainerResult(\record_preview $recordContainer)
|
|
{
|
|
/* @var $recordPreview \media_subdef */
|
|
$helpers = new PhraseanetExtension($this->app);
|
|
|
|
$recordData = [
|
|
'databoxId' => $recordContainer->getBaseId(),
|
|
'id' => $recordContainer->getId(),
|
|
'isGroup' => $recordContainer->isStory(),
|
|
'url' => (string)$helpers->getThumbnailUrl($recordContainer),
|
|
];
|
|
$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;
|
|
}
|
|
|
|
public function getRecordById($sbasId, $recordId)
|
|
{
|
|
$record = new \record_adapter($this->app, $sbasId, $recordId);
|
|
return $this->app->json([
|
|
"html_preview" => $this->render('common/preview.html.twig', [
|
|
'record' => $record
|
|
]),
|
|
"desc" => $this->render('common/caption.html.twig', [
|
|
'record' => $record,
|
|
'view' => 'preview'
|
|
])
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Delete a record or a list of records
|
|
*
|
|
* @param Request $request
|
|
* @return Response
|
|
*/
|
|
public function doDeleteRecords(Request $request)
|
|
{
|
|
$flatten = (bool)($request->request->get('del_children')) ? RecordsRequest::FLATTEN_YES_PRESERVE_STORIES : RecordsRequest::FLATTEN_NO;
|
|
$records = RecordsRequest::fromRequest(
|
|
$this->app,
|
|
$request,
|
|
$flatten,
|
|
[\ACL::CANDELETERECORD]
|
|
);
|
|
|
|
$basketElementsRepository = $this->getBasketElementRepository();
|
|
$StoryWZRepository = $this->getStoryWorkZoneRepository();
|
|
|
|
$deleted = [];
|
|
|
|
/** @var \collection[] $trashCollectionsBySbasId */
|
|
$trashCollectionsBySbasId = [];
|
|
|
|
$manager = $this->getEntityManager();
|
|
|
|
/** @var \record_adapter $record */
|
|
foreach ($records as $record) {
|
|
try {
|
|
$basketElements = $basketElementsRepository->findElementsByRecord($record);
|
|
|
|
foreach ($basketElements as $element) {
|
|
$manager->remove($element);
|
|
$deleted[] = $element->getRecord($this->app)->getId();
|
|
}
|
|
|
|
$attachedStories = $StoryWZRepository->findByRecord($this->app, $record);
|
|
|
|
foreach ($attachedStories as $attachedStory) {
|
|
$manager->remove($attachedStory);
|
|
}
|
|
|
|
foreach ($record->get_grouping_parents() as $story) {
|
|
$this->getEventDispatcher()->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($story));
|
|
}
|
|
|
|
$sbasId = $record->getDatabox()->get_sbas_id();
|
|
if (!array_key_exists($sbasId, $trashCollectionsBySbasId)) {
|
|
$trashCollectionsBySbasId[$sbasId] = $record->getDatabox()->getTrashCollection();
|
|
}
|
|
$deleted[] = $record->getId();
|
|
if ($trashCollectionsBySbasId[$sbasId] !== null) {
|
|
if($record->getCollection()->get_coll_id() == $trashCollectionsBySbasId[$sbasId]->get_coll_id()) {
|
|
// record is already in trash so delete it
|
|
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
|
|
} else {
|
|
// move to trash collection
|
|
$record->move_to_collection($trashCollectionsBySbasId[$sbasId]);
|
|
// disable permalinks
|
|
foreach($record->get_subdefs() as $subdef) {
|
|
if( ($pl = $subdef->get_permalink()) ) {
|
|
$pl->set_is_activated(false);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
// no trash collection, delete
|
|
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
|
|
}
|
|
} catch (\Exception $e) {
|
|
}
|
|
}
|
|
|
|
$manager->flush();
|
|
|
|
return $this->app->json($deleted);
|
|
}
|
|
|
|
/**
|
|
* @return BasketElementRepository
|
|
*/
|
|
private function getBasketElementRepository()
|
|
{
|
|
return $this->app['repo.basket-elements'];
|
|
}
|
|
|
|
/**
|
|
* @return StoryWZRepository
|
|
*/
|
|
private function getStoryWorkZoneRepository()
|
|
{
|
|
return $this->app['repo.story-wz'];
|
|
}
|
|
|
|
/**
|
|
* Delete a record or a list of records
|
|
*
|
|
* @param Request $request
|
|
* @return string html
|
|
*/
|
|
public function whatCanIDelete(Request $request)
|
|
{
|
|
$viewParms = [];
|
|
|
|
// pre-count records that would be trashed/deleted when the "deleted children" will be un-checked
|
|
|
|
$records = RecordsRequest::fromRequest(
|
|
$this->app,
|
|
$request,
|
|
RecordsRequest::FLATTEN_NO,
|
|
[\ACL::CANDELETERECORD]
|
|
);
|
|
|
|
$filteredRecords = $this->filterRecordToDelete($records);
|
|
|
|
$viewParms['parents_only'] = [
|
|
'records' => $records,
|
|
'trashableCount' => count($filteredRecords['trash']),
|
|
'deletableCount' => count($filteredRecords['delete'])
|
|
];
|
|
|
|
// pre-count records that would be trashed/deleted when the "deleted children" will be checked
|
|
//
|
|
$records = RecordsRequest::fromRequest(
|
|
$this->app,
|
|
$request,
|
|
RecordsRequest::FLATTEN_YES_PRESERVE_STORIES,
|
|
[\ACL::CANDELETERECORD]
|
|
);
|
|
$filteredRecords = $this->filterRecordToDelete($records);
|
|
$viewParms['with_children'] = [
|
|
'records' => $records,
|
|
'trashableCount' => count($filteredRecords['trash']),
|
|
'deletableCount' => count($filteredRecords['delete'])
|
|
];
|
|
|
|
return $this->render(
|
|
'prod/actions/delete_records_confirm.html.twig',
|
|
$viewParms
|
|
);
|
|
|
|
}
|
|
|
|
/**
|
|
* classifies records in two groups (does NOT delete anything)
|
|
* - 'trash' : the record can go to trash because the db has a "_TRASH_" coll, and the record is not already into it
|
|
* - 'delete' : the record would be deleted because the db has no trash, or the record is already trashed
|
|
*
|
|
* @param RecordsRequest $records
|
|
* @return array
|
|
*/
|
|
private function filterRecordToDelete(RecordsRequest $records)
|
|
{
|
|
$ret = [
|
|
'trash' => [],
|
|
'delete' => []
|
|
];
|
|
|
|
$trashCollectionsBySbasId = [];
|
|
foreach ($records as $record) {
|
|
/** @var \record_adapter $record */
|
|
$sbasId = $record->getDatabox()->get_sbas_id();
|
|
if (!array_key_exists($sbasId, $trashCollectionsBySbasId)) {
|
|
$trashCollectionsBySbasId[$sbasId] = $record->getDatabox()->getTrashCollection();
|
|
}
|
|
if ($trashCollectionsBySbasId[$sbasId] !== null) {
|
|
if ($record->getCollection()->get_coll_id() == $trashCollectionsBySbasId[$sbasId]->get_coll_id()) {
|
|
// record is already in trash
|
|
$ret['delete'][] = $record;
|
|
}
|
|
else {
|
|
// will be moved to trash
|
|
$ret['trash'][] = $record;
|
|
}
|
|
}
|
|
else {
|
|
// trash does not exist
|
|
$ret['delete'][] = $record;
|
|
}
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Renew url list of records
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse
|
|
* @throws \Alchemy\Phrasea\Cache\Exception
|
|
*/
|
|
public function renewUrl(Request $request)
|
|
{
|
|
$records = RecordsRequest::fromRequest($this->app, $request, !!$request->request->get('renew_children_url'));
|
|
|
|
$renewed = [];
|
|
foreach ($records as $record) {
|
|
$renewed[$record->getId()] = (string) $record->get_preview()->renew_url();
|
|
};
|
|
|
|
return $this->app->json($renewed);
|
|
}
|
|
|
|
/**
|
|
* @return EventDispatcherInterface
|
|
*/
|
|
private function getEventDispatcher()
|
|
{
|
|
return $this->app['dispatcher'];
|
|
}
|
|
}
|