daniel-rose / magento2-gallery

Gallery module for Magento 2
15 stars 5 forks source link

Bug: Image Filter function in Gallerires Admin page #2

Closed letunhatkong closed 8 years ago

letunhatkong commented 8 years ago

Hi Daniel Rose, When user create a new gallery and select a image that was selected on another gallery. The image filter function will not load. I think SQL statement is wrong. My first solution: With other Gallery, i will only show images that never were selected.

In file DR/Gallery/Block/Adminhtml/Gallery/Edit/Tab/Image.php

protected function _prepareCollection()
    {
        /** @var Collection $collection */
        $collection = $this->collectionFactory->create();
        $collection->getSelect()->joinLeft(
            ['link_table' => $collection->getTable('dr_gallery_gallery_image')],
            'main_table.image_id = link_table.image_id',
            ['gallery_id', 'position']);

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

I edited this function to solved this issue.

protected function _prepareCollection()
    {
        /** @var Collection $collection */
        $collection = $this->collectionFactory->create();
        $collection->getSelect()->joinLeft(
            ['link_table' => $collection->getTable('dr_gallery_gallery_image')],
            'main_table.image_id = link_table.image_id',
            ['gallery_id', 'position'])
            ->where("link_table.image_id is null");

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

My second solution: Filter all images, and allow select duplicated images.

letunhatkong commented 8 years ago

Fix protected function _prepareCollection()

$collection->getSelect()->joinLeft(
            ['link_table' => $collection->getTable('dr_gallery_gallery_image')],
            'main_table.image_id = link_table.image_id',
            ['gallery_id', 'position'])
        ->group('main_table.image_id');