Commit 2158781b authored by Hendrik Rombach's avatar Hendrik Rombach
Browse files

Merge branch '29235' into '1.3'

#29235 - Convert cms attributes 'neti_tags' to array

See merge request shopware/labs/NetiTags!13
parents 956fb2f4 e9d7f22a
......@@ -45,6 +45,7 @@ class Setup
* @throws \Doctrine\ORM\ORMInvalidArgumentException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Shopware\Components\Api\Exception\ValidationException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function registerRelationTables(Plugin $plugin)
{
......
......@@ -17,6 +17,7 @@ class Shopware_Controllers_Backend_NetiTags extends AbstractBackendExtJsControll
* Load the backend-Main-Application
*
* @return void
* @throws Exception
*/
public function indexAction()
{
......@@ -30,6 +31,7 @@ class Shopware_Controllers_Backend_NetiTags extends AbstractBackendExtJsControll
/**
* @return PluginConfig
* @throws Exception
*/
protected function getPluginConfig()
{
......
......@@ -20,6 +20,7 @@
<argument type="service" id="shopware_attribute.table_mapping"/>
<argument type="service" id="dbal_connection"/>
<argument type="service" id="neti_tags.service.tag.relation_collector"/>
<argument type="service" id="models" />
</service>
<service decorates="shopware_attribute.data_persister"
......
......@@ -7,10 +7,12 @@
namespace NetiTags\Service\Decorations;
use NetiTags\Models\Tag;
use NetiTags\Service\Tag\RelationCollectorInterface;
use Shopware\Bundle\AttributeBundle\Service\DataLoader as CoreService;
use Shopware\Bundle\AttributeBundle\Service\TableMapping;
use Doctrine\DBAL\Connection;
use Shopware\Components\Model\ModelManager;
/**
* Class AttributeDataLoader
......@@ -39,25 +41,33 @@ class AttributeDataLoader extends CoreService
*/
protected $relationCollector;
/**
* @var ModelManager
*/
protected $em;
/**
* AttributeDataLoader constructor.
*
* @param CoreService $coreService
* @param TableMapping $mapping
* @param Connection $connection
* @param CoreService $coreService
* @param TableMapping $mapping
* @param Connection $connection
* @param RelationCollectorInterface $relationCollector
* @param ModelManager $em
*/
public function __construct(
CoreService $coreService,
TableMapping $mapping,
Connection $connection,
RelationCollectorInterface $relationCollector
RelationCollectorInterface $relationCollector,
ModelManager $em
) {
parent::__construct($connection, $mapping);
$this->coreService = $coreService;
$this->mapping = $mapping;
$this->connection = $connection;
$this->relationCollector = $relationCollector;
$this->em = $em;
}
/**
......@@ -65,6 +75,7 @@ class AttributeDataLoader extends CoreService
* @param string $foreignKey
*
* @return array
* @throws \Exception
*/
public function load($table, $foreignKey)
{
......@@ -93,11 +104,22 @@ class AttributeDataLoader extends CoreService
if (empty($relations)) {
$data['neti_tags'] = array();
$data['neti_tags_complete'] = array();
return;
}
$data['neti_tags'] = sprintf('|%s|', implode('|', $relations));
$data['neti_tags_complete'] = $this->loadRelationData($relations);
}
private function loadRelationData($tagIds)
{
$qb = $this->em->getRepository(Tag::class)->createQueryBuilder('t');
return $qb->select(['t.id', 't.title', 't.description'])
->where($qb->expr()->in('t.id', ':ids'))
->setParameter('ids', $tagIds)
->getQuery()->getArrayResult();
}
/**
......@@ -105,6 +127,7 @@ class AttributeDataLoader extends CoreService
* @param int $foreignKey
*
* @return array[]
* @throws \Exception
*/
public function loadTranslations($table, $foreignKey)
{
......
......@@ -57,6 +57,8 @@ class TableRegistry implements TableRegistryInterface
*
* @return bool
* @throws ValidationException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \Doctrine\ORM\OptimisticLockException
* @internal param string $name
*/
public function register($title, $tableName, $entityName, Plugin $plugin)
......
......@@ -300,7 +300,7 @@ class Cms implements RelationsInterface
/** @var QueryBuilder $qbr */
$qbr = $this->getTagsQuery($relationId);
$qbr->select([
't.id',
't.id'
]);
/** @var array $results */
......@@ -312,7 +312,8 @@ class Cms implements RelationsInterface
/**
* @param array $data
* @param int $relationId
* @throws \Doctrine\ORM\ORMInvalidArgumentException
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function persistRelations(array $data, $relationId)
......@@ -352,6 +353,8 @@ class Cms implements RelationsInterface
* @param int $relationId
*
* @return array|null
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getTags($relationId)
{
......
......@@ -109,6 +109,7 @@ class TagsSubscriber implements SubscriberInterface
/**
* @return PluginConfig
* @throws \Exception
*/
protected function getConfig()
{
......
......@@ -5,12 +5,21 @@
<label lang="de">Tags</label>
<label lang="en">Tags</label>
<version>1.3.1</version>
<version>1.3.2</version>
<link>http://www.netinventors.de</link>
<author>Net Inventors GmbH</author>
<compatibility minVersion="5.2.6"/>
<changelog version="1.3.1">
<changelog version="1.3.2">
<changes lang="de"><![CDATA[
[#29235] Übergabe der Tags an Smarty umwandeln
]]></changes>
<changes lang="en"><![CDATA[
[#29235] Convert handover of tags to smarty
]]></changes>
</changelog>
<changelog version="1.3.1">
<changes lang="de"><![CDATA[
[#29012] widget.neti_tags_field um allowBlank erweitern
]]></changes>
......
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