Unverified Commit cd915a6a authored by Sebastian Castro's avatar Sebastian Castro
Browse files

Fix element export admin

Export files, images, custom props, private props
parent 9cfd3bdc
......@@ -34,6 +34,5 @@ return [
Http\HttplugBundle\HttplugBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
App\Application\Sonata\UserBundle\ApplicationSonataUserBundle::class => ['all' => true],
App\Application\Sonata\Exporter\ApplicationSonataExporterBundle::class => ['all' => true],
App\Application\Sonata\UserBundle\ApplicationSonataUserBundle::class => ['all' => true]
];
......@@ -9,6 +9,8 @@
namespace App\Admin\Element;
// custom iterator
use Application\Sonata\Exporter\Source\DoctrineODMQuerySourceIterator;
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
// There is a chain of inherance to split ElementAdmin in different files
// ElementAdminShowEdit inherit from ElementAdminList wich inherit from ElementAdminFilters and so on..
......@@ -18,22 +20,58 @@ class ElementAdmin extends ElementAdminShowEdit
{
$dm = $this->getModelManager()->getDocumentManager('App\Document\Configuration');
$basicFields = [
'id' => 'id',
'name' => 'name',
'categories' => 'optionsString',
'latitude' => 'geo.latitude',
'longitude' => 'geo.longitude',
'streetAddress' => 'address.streetAddress',
'addressLocality' => 'address.addressLocality',
'postalCode' => 'address.postalCode',
'addressCountry' => 'address.addressCountry',
];
$publicProperties = $dm->getRepository('App\Document\Element')->findAllCustomProperties($onlypublic = true);
'id' => 'id',
'name' => 'name',
'categories' => 'optionsString',
'latitude' => 'geo.latitude',
'longitude' => 'geo.longitude',
'streetAddress' => 'address.streetAddress',
'addressLocality' => 'address.addressLocality',
'postalCode' => 'address.postalCode',
'addressCountry' => 'address.addressCountry',
'status' => 'status',
'moderationState' => 'moderationState',
'source' => 'sourceKey',
'images' => 'images',
'files' => 'files'
];
$props = $dm->getRepository('App\Document\Element')->findPublicCustomProperties();
$customFields = [];
foreach ($publicProperties as $key => $prop) {
$customFields[$prop] = 'data';
foreach ($props as $key => $prop) {
if (!isset($basicFields[$prop])) $customFields[$prop] = 'data';
}
$props = $dm->getRepository('App\Document\Element')->findPrivateCustomProperties();
foreach ($props as $key => $prop) {
if (!isset($basicFields[$prop])) $customFields[$prop] = 'privateData';
}
return array_merge($basicFields, $customFields);
}
public function getDataSourceIterator()
{
$datagrid = $this->getDatagrid();
$datagrid->buildPager();
$fields = [];
foreach ($this->getExportFields() as $key => $field) {
$label = $this->getTranslationLabel($field, 'export', 'label');
$transLabel = $this->trans($label);
// NEXT_MAJOR: Remove this hack, because all field labels will be translated with the major release
// No translation key exists
if ($transLabel == $label) {
$fields[$key] = $field;
} else {
$fields[$transLabel] = $field;
}
}
$datagrid->buildPager();
$query = $datagrid->getQuery();
return new ElementSourceIterator($query instanceof ProxyQuery ? $query->getQuery() : $query, $fields);
}
}
......@@ -15,15 +15,15 @@ class ElementAdminAbstract extends AbstractAdmin
protected $statusChoices = [
'' => 'Inconnu',
'-6' => 'Doublon supprimé',
'-4' => 'Supprimé',
'-3' => 'Refusé (votes) ',
'-2' => 'Refusé (admin)',
'-1' => 'En attente (modifs)',
'0' => 'En attente (ajout)',
'1' => 'Validé (admin)',
'2' => 'Validé (votes)',
'3' => 'Ajouté par admin',
'4' => 'Modifié par admin',
'-4' => 'Supprimé',
'-3' => 'Refusé (votes) ',
'-2' => 'Refusé (admin)',
'-1' => 'En attente (modifs)',
'0' => 'En attente (ajout)',
'1' => 'Validé (admin)',
'2' => 'Validé (votes)',
'3' => 'Ajouté par admin',
'4' => 'Modifié par admin',
'5' => 'Modifié par propriétaire',
'6' => 'Modifié avec lien direct',
'7' => 'Source externe',
......@@ -31,11 +31,11 @@ class ElementAdminAbstract extends AbstractAdmin
];
protected $moderationChoices = [
'-2' => 'Erreur geolocalisation',
'-1' => 'Aucune catégorie renseignée',
'0' => 'Pas de modération nécessaire',
'1' => 'Erreurs signalées',
'2' => 'Votes non consensuels',
'-2' => 'Erreur geolocalisation',
'-1' => 'Aucune catégorie renseignée',
'0' => 'Pas de modération nécessaire',
'1' => 'Erreurs signalées',
'2' => 'Votes non consensuels',
'3' => 'En attente depuis trop longtemps',
'4' => 'Doublon potentiel',
];
......
......@@ -15,7 +15,7 @@
to see ho it is used
*/
namespace App\Application\Sonata\Exporter\Source;
namespace App\Admin\Element;
use Doctrine\ODM\MongoDB\Query\Query;
use Doctrine\ORM\Internal\Hydration\IterableResult;
......@@ -24,7 +24,7 @@ use Exporter\Source\SourceIteratorInterface;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyPath;
class DoctrineODMQuerySourceIterator implements SourceIteratorInterface
class ElementSourceIterator implements SourceIteratorInterface
{
/**
* @var Query
......@@ -84,7 +84,7 @@ class DoctrineODMQuerySourceIterator implements SourceIteratorInterface
$data = [];
foreach ($this->propertyPaths as $name => $propertyPath) {
$data[$name] = $this->getValue($this->propertyAccessor->getValue($current, $propertyPath), $name);
$data[$name] = $this->getValue($this->propertyAccessor->getValue($current, $propertyPath), $name);
}
$this->query->getDocumentManager()->getUnitOfWork()->detach($current);
......@@ -153,13 +153,13 @@ class DoctrineODMQuerySourceIterator implements SourceIteratorInterface
protected function getValue($value, $name)
{
if (is_array($value)) {
$value = array_key_exists($name, $value) ? $value[$name] : null;
$value = array_key_exists($name, $value) ? $value[$name] : implode(',', $value);
} elseif ($value instanceof \Traversable) {
$value = null;
$value = implode(',', $value->toArray());
} elseif ($value instanceof \DateTimeInterface) {
$value = $value->format($this->dateTimeFormat);
} elseif (is_object($value)) {
$value = (string) $value;
$value = (string) $object;
}
return $value;
......
<?php
namespace App\Application\Sonata\Exporter;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* This file has been generated by the SonataEasyExtendsBundle.
*
* @see https://sonata-project.org/easy-extends
*
* References:
* @see http://symfony.com/doc/current/book/bundles.html
*/
class ApplicationSonataExporterBundle extends Bundle
{
}
......@@ -27,6 +27,7 @@ class ElementAdminBulkController extends Controller
$this->interactionService = $interactionService;
$this->asyncService = $asyncService;
$this->elementActionService = $elementActionService;
$this->jsonGenerator = $jsonGenerator;
$this->dm = $dm;
}
......
......@@ -43,6 +43,11 @@ class AbstractFile implements \Serializable
// $this->file = new UploadedFile($path, $fileName);
}
public function __toString()
{
return $this->getFileUrl();
}
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
......
......@@ -22,7 +22,7 @@ class EmbeddedImage extends AbstractFile
public function __toString()
{
return $this->fileName ?: $this->externalImageUrl;
return $this->getImageUrl();
}
public function toJson()
......
......@@ -91,23 +91,22 @@ class ElementJsonGenerator
// OPTIONS VALUES (= TAXONOMY)
$sortedOptionsValues = $element->getSortedOptionsValues();
$optValuesLength = count($sortedOptionsValues);
$optionsString = '';
$elementOptions = [];
$optionsFullJson = [];
if ($sortedOptionsValues) {
for ($i = 0; $i < $optValuesLength; ++$i) {
$optionValue = $sortedOptionsValues[$i];
if (isset($options[$optionValue->getOptionId()])) {
$optionName = json_encode($options[$optionValue->getOptionId()]['name']);
$optionsString .= $optionName.',';
$optionsFullJson[] = $sortedOptionsValues[$i]->toJson($optionName);
$optionName = $options[$optionValue->getOptionId()]['name'];
$elementOptions[] = $optionName;
$optionsFullJson[] = $sortedOptionsValues[$i]->toJson(json_encode($optionName));
} else {
$element->removeOptionValue($sortedOptionsValues[$i]);
}
}
}
$optionsString = rtrim($optionsString, ',');
$baseJson .= ',"categories": ['.$optionsString.'],';
$element->setOptionsString($optionsString); // we also update optionsString attribute which is used in exporting from element admin list
$baseJson .= ',"categories": ' . json_encode($elementOptions) . ',';
$element->setOptionsString(implode(',', $elementOptions)); // we also update optionsString attribute which is used in exporting from element admin list
// Options values with description
if (count($optionsFullJson)) {
$baseJson .= '"categoriesFull": ['.implode(',', $optionsFullJson).'],';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment