Files
Phraseanet/lib/Alchemy/Phrasea/Controller/Prod/Edit.php
Nicolas Le Goff 949bf06cac Merge branch '3.8'
Conflicts:
	CHANGELOG.md
	bin/console
	bin/developer
	bin/setup
	bower.json
	composer.json
	composer.lock
	features/bootstrap/FeatureContext.php
	features/bootstrap/GuiContext.php
	lib/Alchemy/Phrasea/Authentication/Token/TokenValidator.php
	lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php
	lib/Alchemy/Phrasea/Command/CreateCollection.php
	lib/Alchemy/Phrasea/Command/Developer/JavascriptBuilder.php
	lib/Alchemy/Phrasea/Controller/Admin/Collection.php
	lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php
	lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php
	lib/Alchemy/Phrasea/Controller/Api/V1.php
	lib/Alchemy/Phrasea/Controller/Client/Baskets.php
	lib/Alchemy/Phrasea/Controller/Client/Root.php
	lib/Alchemy/Phrasea/Controller/Prod/Basket.php
	lib/Alchemy/Phrasea/Controller/Prod/Export.php
	lib/Alchemy/Phrasea/Controller/Prod/Property.php
	lib/Alchemy/Phrasea/Controller/Prod/Records.php
	lib/Alchemy/Phrasea/Controller/Prod/Tools.php
	lib/Alchemy/Phrasea/Controller/Prod/Upload.php
	lib/Alchemy/Phrasea/Controller/Root/Login.php
	lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php
	lib/Alchemy/Phrasea/Core/Event/ApiLoadEndEvent.php
	lib/Alchemy/Phrasea/Core/Event/ApiLoadStartEvent.php
	lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php
	lib/Alchemy/Phrasea/Core/Version.php
	lib/Alchemy/Phrasea/Exception/XMLParseErrorException.php
	lib/Alchemy/Phrasea/Helper/DatabaseHelper.php
	lib/Alchemy/Phrasea/Helper/User/Edit.php
	lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php
	lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php
	lib/Doctrine/Entities/AuthFailure.php
	lib/Doctrine/Entities/Basket.php
	lib/Doctrine/Entities/BasketElement.php
	lib/Doctrine/Entities/LazaretAttribute.php
	lib/Doctrine/Entities/LazaretCheck.php
	lib/Doctrine/Entities/LazaretFile.php
	lib/Doctrine/Entities/LazaretSession.php
	lib/Doctrine/Entities/Session.php
	lib/Doctrine/Entities/SessionModule.php
	lib/Doctrine/Entities/StoryWZ.php
	lib/Doctrine/Entities/UsrList.php
	lib/Doctrine/Entities/UsrListEntry.php
	lib/Doctrine/Entities/UsrListOwner.php
	lib/Doctrine/Entities/ValidationData.php
	lib/Doctrine/Entities/ValidationParticipant.php
	lib/Doctrine/Entities/ValidationSession.php
	lib/Doctrine/Logger/MonologSQLLogger.php
	lib/Doctrine/Repositories/BasketRepository.php
	lib/Doctrine/Repositories/ValidationParticipantRepository.php
	lib/Doctrine/Types/Binary.php
	lib/Doctrine/Types/Blob.php
	lib/Doctrine/Types/Enum.php
	lib/Doctrine/Types/LongBlob.php
	lib/Doctrine/Types/VarBinary.php
	lib/classes/API/OAuth2/Account.php
	lib/classes/API/OAuth2/Application.php
	lib/classes/API/OAuth2/Application/OfficePlugin.php
	lib/classes/API/OAuth2/AuthCode.php
	lib/classes/API/OAuth2/RefreshToken.php
	lib/classes/API/OAuth2/Token.php
	lib/classes/API/V1/Abstract.php
	lib/classes/API/V1/Interface.php
	lib/classes/API/V1/adapter.php
	lib/classes/API/V1/exception/abstract.php
	lib/classes/API/V1/exception/badrequest.php
	lib/classes/API/V1/exception/forbidden.php
	lib/classes/API/V1/exception/internalservererror.php
	lib/classes/API/V1/exception/maintenance.php
	lib/classes/API/V1/exception/methodnotallowed.php
	lib/classes/API/V1/exception/notfound.php
	lib/classes/API/V1/exception/unauthorized.php
	lib/classes/API/V1/result.php
	lib/classes/Exception/Feed/EntryNotFound.php
	lib/classes/Exception/Feed/ItemNotFound.php
	lib/classes/Exception/Feed/PublisherNotFound.php
	lib/classes/Feed/Abstract.php
	lib/classes/Feed/Adapter.php
	lib/classes/Feed/Aggregate.php
	lib/classes/Feed/Collection.php
	lib/classes/Feed/CollectionInterface.php
	lib/classes/Feed/Entry/Adapter.php
	lib/classes/Feed/Entry/Collection.php
	lib/classes/Feed/Entry/CollectionInterface.php
	lib/classes/Feed/Entry/Interface.php
	lib/classes/Feed/Entry/Item.php
	lib/classes/Feed/Entry/ItemInterface.php
	lib/classes/Feed/Interface.php
	lib/classes/Feed/Link.php
	lib/classes/Feed/LinkInterface.php
	lib/classes/Feed/Publisher/Adapter.php
	lib/classes/Feed/Publisher/Interface.php
	lib/classes/Feed/Token.php
	lib/classes/Feed/TokenAggregate.php
	lib/classes/Feed/XML/Abstract.php
	lib/classes/Feed/XML/Atom.php
	lib/classes/Feed/XML/Cooliris.php
	lib/classes/Feed/XML/Interface.php
	lib/classes/Feed/XML/RSS.php
	lib/classes/Feed/XML/RSS/Image.php
	lib/classes/Feed/XML/RSS/ImageInterface.php
	lib/classes/User/Adapter.php
	lib/classes/User/Interface.php
	lib/classes/appbox/register.php
	lib/classes/connection.php
	lib/classes/connection/abstract.php
	lib/classes/connection/interface.php
	lib/classes/connection/pdo.php
	lib/classes/connection/pdoStatementDebugger.php
	lib/classes/deprecated/countries.php
	lib/classes/deprecated/inscript.api.php
	lib/classes/eventsmanager/event/test.php
	lib/classes/ftpclient.php
	lib/classes/http/request.php
	lib/classes/media/subdef.php
	lib/classes/module/console/schedulerStart.php
	lib/classes/module/console/schedulerState.php
	lib/classes/module/console/schedulerStop.php
	lib/classes/module/console/taskState.php
	lib/classes/module/console/tasklist.php
	lib/classes/module/console/taskrun.php
	lib/classes/patch/320alpha4b.php
	lib/classes/patch/3715alpha1a.php
	lib/classes/patch/379alpha1a.php
	lib/classes/patch/380alpha10a.php
	lib/classes/patch/380alpha11a.php
	lib/classes/patch/380alpha13a.php
	lib/classes/patch/380alpha14a.php
	lib/classes/patch/380alpha15a.php
	lib/classes/patch/380alpha16a.php
	lib/classes/patch/380alpha17a.php
	lib/classes/patch/380alpha18a.php
	lib/classes/patch/380alpha3a.php
	lib/classes/patch/380alpha4a.php
	lib/classes/patch/380alpha6a.php
	lib/classes/patch/380alpha8a.php
	lib/classes/patch/380alpha9a.php
	lib/classes/patch/381alpha1b.php
	lib/classes/patch/381alpha2a.php
	lib/classes/patch/381alpha3a.php
	lib/classes/patch/381alpha4a.php
	lib/classes/patch/383alpha1a.php
	lib/classes/patch/383alpha2a.php
	lib/classes/patch/383alpha3a.php
	lib/classes/patch/383alpha4a.php
	lib/classes/record/adapter.php
	lib/classes/record/preview.php
	lib/classes/recordutils.php
	lib/classes/recordutils/audio.php
	lib/classes/recordutils/document.php
	lib/classes/recordutils/map.php
	lib/classes/recordutils/video.php
	lib/classes/registry.php
	lib/classes/registryInterface.php
	lib/classes/set/order.php
	lib/classes/system/url.php
	lib/classes/task/Scheduler.php
	lib/classes/task/appboxAbstract.php
	lib/classes/task/databoxAbstract.php
	lib/classes/task/manager.php
	lib/classes/task/period/RecordMover.php
	lib/classes/task/period/apibridge.php
	lib/classes/task/period/apiwebhooks.php
	lib/classes/task/period/archive.php
	lib/classes/task/period/cindexer.php
	lib/classes/task/period/emptyColl.php
	lib/classes/task/period/ftp.php
	lib/classes/task/period/ftpPull.php
	lib/classes/task/period/subdef.php
	lib/classes/task/period/test.php
	lib/classes/task/period/writemeta.php
	lib/conf.d/PhraseaFixture/AbstractWZ.php
	lib/conf.d/PhraseaFixture/Basket/LoadFiveBaskets.php
	lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php
	lib/conf.d/PhraseaFixture/Basket/LoadOneBasketEnv.php
	lib/conf.d/PhraseaFixture/Lazaret/LoadOneFile.php
	lib/conf.d/PhraseaFixture/Story/LoadOneStory.php
	lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php
	lib/conf.d/PhraseaFixture/UsrLists/UsrList.php
	lib/conf.d/PhraseaFixture/UsrLists/UsrListEntry.php
	lib/conf.d/PhraseaFixture/UsrLists/UsrListOwner.php
	lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php
	lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php
	lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php
	templates/web/admin/collection/collection.html.twig
	templates/web/common/dialog_export.html.twig
	templates/web/common/menubar.html.twig
	templates/web/prod/actions/Tools/index.html.twig
	templates/web/prod/index.html.twig
	templates/web/prod/upload/upload-flash.html.twig
	templates/web/prod/upload/upload.html.twig
	templates/web/report/report_layout_child.html.twig
	templates/web/setup/step2.html.twig
	templates/web/thesaurus/new-synonym-dialog.html.twig
	templates/web/thesaurus/properties.html.twig
	templates/web/thesaurus/search.html.twig
	tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php
	tests/Alchemy/Tests/Phrasea/Cache/FactoryTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php
2015-02-05 18:38:49 +01:00

385 lines
15 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 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\Core\Event\RecordEdit;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController;
use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Metadata\Tag\TfEditdate;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
class Edit implements ControllerProviderInterface
{
public function connect(Application $app)
{
$app['controller.prod.edit'] = $this;
$controllers = $app['controllers_factory'];
$app['firewall']->addMandatoryAuthentication($controllers);
$controllers->before(function (Request $request) use ($app) {
$app['firewall']
->requireNotGuest()
->requireRight('modifyrecord');
});
$controllers->post('/', function (Application $app, Request $request) {
$records = RecordsRequest::fromRequest($app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, ['canmodifrecord']);
$thesaurus = false;
$status = $ids = $elements = $suggValues =
$fields = $JSFields = [];
$databox = null;
$multipleDataboxes = count($records->databoxes()) > 1;
if (1 === count($records->databoxes())) {
$databoxes = $records->databoxes();
$databox = array_pop($databoxes);
/**
* generate javascript fields
*/
foreach ($databox->get_meta_structure() as $meta) {
$fields[] = $meta;
$separator = $meta->get_separator();
/** @Ignore */
$JSFields[$meta->get_id()] = [
'meta_struct_id' => $meta->get_id(),
'name' => $meta->get_name(),
'_status' => 0,
'_value' => '',
'_sgval' => [],
'required' => $meta->is_required(),
/** @Ignore */
'label' => $meta->get_label($app['locale']),
'readonly' => $meta->is_readonly(),
'type' => $meta->get_type(),
'format' => '',
'explain' => '',
'tbranch' => $meta->get_tbranch(),
'maxLength' => $meta->get_tag()->getMaxLength(),
'minLength' => $meta->get_tag()->getMinLength(),
'multi' => $meta->is_multi(),
'separator' => $separator,
'vocabularyControl' => $meta->getVocabularyControl() ? $meta->getVocabularyControl()->getType() : null,
'vocabularyRestricted' => $meta->getVocabularyControl() ? $meta->isVocabularyRestricted() : false,
];
if (trim($meta->get_tbranch()) !== '') {
$thesaurus = true;
}
}
/**
* generate javascript sugg values
*/
foreach ($records->collections() as $collection) {
/* @var $record record_adapter */
$suggValues['b' . $collection->get_base_id()] = [];
if ($sxe = simplexml_load_string($collection->get_prefs())) {
$z = $sxe->xpath('/baseprefs/sugestedValues');
if (!$z || !is_array($z)) {
continue;
}
foreach ($z[0] as $ki => $vi) { // les champs
$field = $databox->get_meta_structure()->get_element_by_name($ki);
if (!$field || !$vi) {
continue;
}
$suggValues['b' . $collection->get_base_id()][$field->get_id()] = [];
foreach ($vi->value as $oneValue) {
$suggValues['b' . $collection->get_base_id()][$field->get_id()][] = (string) $oneValue;
}
}
}
unset($collection);
}
/**
* generate javascript status
*/
if ($app['acl']->get($app['authentication']->getUser())->has_right('changestatus')) {
$dbstatus = \databox_status::getDisplayStatus($app);
if (isset($dbstatus[$databox->get_sbas_id()])) {
foreach ($dbstatus[$databox->get_sbas_id()] as $n => $statbit) {
$status[$n] = [];
$status[$n]['label0'] = $statbit['labels_off_i18n'][$app['locale']];
$status[$n]['label1'] = $statbit['labels_on_i18n'][$app['locale']];
$status[$n]['img_off'] = $statbit['img_off'];
$status[$n]['img_on'] = $statbit['img_on'];
$status[$n]['_value'] = 0;
}
}
}
/**
* generate javascript elements
*/
foreach ($databox->get_meta_structure() as $field) {
$databox_fields[$field->get_id()] = [
'dirty' => false,
'meta_struct_id' => $field->get_id(),
'values' => []
];
}
foreach ($records as $record) {
$indice = $record->get_number();
$elements[$indice] = [
'bid' => $record->get_base_id(),
'rid' => $record->get_record_id(),
'sselcont_id' => null,
'_selected' => false,
'fields' => $databox_fields
];
$elements[$indice]['statbits'] = [];
if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'chgstatus')) {
foreach ($status as $n => $s) {
$tmp_val = substr(strrev($record->get_status()), $n, 1);
$elements[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0';
$elements[$indice]['statbits'][$n]['dirty'] = false;
}
}
$elements[$indice]['originalname'] = $record->get_original_name();
foreach ($record->get_caption()->get_fields(null, true) as $field) {
$meta_struct_id = $field->get_meta_struct_id();
if (!isset($JSFields[$meta_struct_id])) {
continue;
}
$values = [];
foreach ($field->get_values() as $value) {
$type = $id = null;
if ($value->getVocabularyType()) {
$type = $value->getVocabularyType()->getType();
$id = $value->getVocabularyId();
}
$values[$value->getId()] = [
'meta_id' => $value->getId(),
'value' => $value->getValue(),
'vocabularyId' => $id,
'vocabularyType' => $type
];
}
$elements[$indice]['fields'][$meta_struct_id] = [
'dirty' => false,
'meta_struct_id' => $meta_struct_id,
'values' => $values
];
}
$elements[$indice]['subdefs'] = [];
$thumbnail = $record->get_thumbnail();
$elements[$indice]['subdefs']['thumbnail'] = [
'url' => (string) $thumbnail->get_url()
, 'w' => $thumbnail->get_width()
, 'h' => $thumbnail->get_height()
];
$elements[$indice]['preview'] = $app['twig']->render('common/preview.html.twig', ['record' => $record]);
$elements[$indice]['type'] = $record->get_type();
}
}
$params = [
'multipleDataboxes' => $multipleDataboxes,
'recordsRequest' => $records,
'databox' => $databox,
'JSonStatus' => json_encode($status),
'JSonRecords' => json_encode($elements),
'JSonFields' => json_encode($JSFields),
'JSonIds' => json_encode(array_keys($elements)),
'status' => $status,
'fields' => $fields,
'JSonSuggValues' => json_encode($suggValues),
'thesaurus' => $thesaurus,
];
return $app['twig']->render('prod/actions/edit_default.html.twig', $params);
});
$controllers->get('/vocabulary/{vocabulary}/', function (Application $app, Request $request, $vocabulary) {
$datas = ['success' => false, 'message' => '', 'results' => []];
$sbas_id = (int) $request->query->get('sbas_id');
try {
if ($sbas_id === 0) {
throw new \Exception('Invalid sbas_id');
}
$VC = VocabularyController::get($app, $vocabulary);
$databox = $app['phraseanet.appbox']->get_databox($sbas_id);
} catch (\Exception $e) {
$datas['message'] = $app->trans('Vocabulary not found');
return $app->json($datas);
}
$query = $request->query->get('query');
$results = $VC->find($query, $app['authentication']->getUser(), $databox);
$list = [];
foreach ($results as $Term) {
/* @var $Term \Alchemy\Phrasea\Vocabulary\Term */
$list[] = [
'id' => $Term->getId(),
'context' => $Term->getContext(),
'value' => $Term->getValue(),
];
}
$datas['success'] = true;
$datas['results'] = $list;
return $app->json($datas);
});
$controllers->post('/apply/', function (Application $app, Request $request) {
$records = RecordsRequest::fromRequest($app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, ['canmodifrecord']);
if (count($records->databoxes()) !== 1) {
throw new \Exception('Unable to edit on multiple databoxes');
}
if ($request->request->get('act_option') == 'SAVEGRP'
&& $request->request->get('newrepresent')
&& $records->isSingleStory()) {
try {
$reg_record = $records->singleStory();
$newsubdef_reg = new \record_adapter($app, $reg_record->get_sbas_id(), $request->request->get('newrepresent'));
foreach ($newsubdef_reg->get_subdefs() as $name => $value) {
if (!in_array($name, ['thumbnail', 'preview'])) {
continue;
}
if ($value->get_type() !== \media_subdef::TYPE_IMAGE) {
continue;
}
$media = $app['mediavorus']->guess($value->get_pathfile());
$app['subdef.substituer']->substitute($reg_record, $name, $media);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($reg_record));
$app['phraseanet.logger']($reg_record->get_databox())->log(
$reg_record,
\Session_Logger::EVENT_SUBSTITUTE,
$name == 'document' ? 'HD' : $name,
''
);
}
} catch (\Exception $e) {
}
}
if (!is_array($request->request->get('mds'))) {
return $app->json(['message' => '', 'error' => false]);
}
$databoxes = $records->databoxes();
$databox = array_pop($databoxes);
$elements = $records->toArray();
foreach ($request->request->get('mds') as $rec) {
try {
$record = $databox->get_record($rec['record_id']);
} catch (\Exception $e) {
continue;
}
$key = $record->get_serialize_key();
if (!array_key_exists($key, $elements)) {
continue;
}
$statbits = $rec['status'];
$editDirty = $rec['edit'];
if ($editDirty == '0') {
$editDirty = false;
} else {
$editDirty = true;
}
if (isset($rec['metadatas']) && is_array($rec['metadatas'])) {
$record->set_metadatas($rec['metadatas']);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($record));
}
$newstat = $record->get_status();
$statbits = ltrim($statbits, 'x');
if (!in_array($statbits, ['', 'null'])) {
$mask_and = ltrim(str_replace(['x', '0', '1', 'z'], ['1', 'z', '0', '1'], $statbits), '0');
if ($mask_and != '') {
$newstat = \databox_status::operation_and_not($app, $newstat, $mask_and);
}
$mask_or = ltrim(str_replace('x', '0', $statbits), '0');
if ($mask_or != '') {
$newstat = \databox_status::operation_or($app, $newstat, $mask_or);
}
$record->set_binary_status($newstat);
}
$record
->write_metas()
->get_collection()
->reset_stamp($record->get_record_id());
if ($statbits != '') {
$app['phraseanet.logger']($record->get_databox())
->log($record, \Session_Logger::EVENT_STATUS, '', '');
}
if ($editDirty) {
$app['phraseanet.logger']($record->get_databox())
->log($record, \Session_Logger::EVENT_EDIT, '', '');
}
}
return $app->json(['success' => true]);
});
return $controllers;
}
}