Skip to content

Commit

Permalink
Added the ability to active/desactive a thesaurus. Only active thesau…
Browse files Browse the repository at this point in the history
…ri are indexed.
  • Loading branch information
romainruaud committed Sep 14, 2016
1 parent f78211e commit 2777bfd
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 10 deletions.
21 changes: 21 additions & 0 deletions src/module-elasticsuite-thesaurus/Api/Data/ThesaurusInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ interface ThesaurusInterface
*/
const TYPE = 'type';

/**
* Constant for field is_active
*/
const IS_ACTIVE = 'is_active';

/**
* Name of the link thesaurus/expansion terms TABLE
*/
Expand Down Expand Up @@ -99,6 +104,13 @@ public function getType();
*/
public function getStoreIds();

/**
* Get Thesaurus status
*
* @return bool
*/
public function isActive();

/**
* Set Thesaurus ID
*
Expand Down Expand Up @@ -134,4 +146,13 @@ public function setType($type);
* @return ThesaurusInterface
*/
public function setStoreIds($storeIds);

/**
* Set Thesaurus status
*
* @param bool $status The thesaurus status
*
* @return ThesaurusInterface
*/
public function setIsActive($status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,32 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic
*/
private $systemStore;

/**
* @var Yesno
*/
private $booleanSource;

/**
* Constructor
*
* @param Context $context Application context
* @param \Magento\Framework\Registry $registry The registry
* @param FormFactory $formFactory Form factory
* @param Store $systemStore Store Provider
* @param array $data Object data
* @param Context $context Application context
* @param \Magento\Framework\Registry $registry The registry
* @param FormFactory $formFactory Form factory
* @param Store $systemStore Store Provider
* @param Yesno $booleanSource Boolean Input Source Model
* @param array $data Object data
*/
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
Store $systemStore,
Yesno $booleanSource,
array $data = []
) {
$this->systemStore = $systemStore;
$this->booleanSource = $booleanSource;

parent::__construct($context, $registry, $formFactory, $data);
}

Expand Down Expand Up @@ -131,6 +139,17 @@ private function initBaseFields($fieldset, $model)
]
);

$fieldset->addField(
'is_active',
'select',
[
'name' => 'is_active',
'label' => __('Active'),
'title' => __('Active'),
'values' => $this->booleanSource->toOptionArray(),
]
);

if (!$this->_storeManager->isSingleStoreMode()) {
$field = $fieldset->addField(
'store_id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private function getBaseSelect($storeId, $type)
->join(['store' => $this->getTable(ThesaurusInterface::STORE_TABLE_NAME)], 'store.thesaurus_id = thesaurus.thesaurus_id', [])
->group(['thesaurus.thesaurus_id', 'terms.term_id'])
->where("thesaurus.type = ?", $type)
->where('thesaurus.is_active = 1')
->where('store.store_id IN (?)', [0, $storeId]);

return $select;
Expand Down
22 changes: 22 additions & 0 deletions src/module-elasticsuite-thesaurus/Model/Thesaurus.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,28 @@ public function getTermsData()
return $this->termsData;
}

/**
* Get Thesaurus status
*
* @return bool
*/
public function isActive()
{
return (bool) $this->getData(self::IS_ACTIVE);
}

/**
* Set Thesaurus status
*
* @param bool $status The thesaurus status
*
* @return ThesaurusInterface
*/
public function setIsActive($status)
{
return $this->setData(self::IS_ACTIVE, (bool) $status);
}

/**
* Internal Constructor
*
Expand Down
33 changes: 29 additions & 4 deletions src/module-elasticsuite-thesaurus/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
{
$setup->startSetup();

$this->createThesaurusTable($setup);
$this->createThesaurusStoreTable($setup);
$this->createExpandedTermsTable($setup);
$this->createExpansionReferenceTable($setup);
if (version_compare($context->getVersion(), '0.0.2', '<')) {
$this->createThesaurusTable($setup);
$this->createThesaurusStoreTable($setup);
$this->createExpandedTermsTable($setup);
$this->createExpansionReferenceTable($setup);
}

if (version_compare($context->getVersion(), '1.0.0', '<')) {
$this->appendIsActiveColumn($setup);
}

$setup->endSetup();
}
Expand Down Expand Up @@ -213,4 +219,23 @@ private function createExpandedTermsTable(SchemaSetupInterface $setup)

$setup->getConnection()->createTable($table);
}

/**
* Add an "is_active" column to the Thesaurus table.
*
* @param \Magento\Framework\Setup\SchemaSetupInterface $setup Setup instance
*/
private function appendIsActiveColumn(SchemaSetupInterface $setup)
{
$setup->getConnection()->addColumn(
$setup->getTable(ThesaurusInterface::TABLE_NAME),
ThesaurusInterface::IS_ACTIVE,
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
'nullable' => false,
'default' => 1,
'comment' => 'If the Thesaurus is active',
]
);
}
}
2 changes: 1 addition & 1 deletion src/module-elasticsuite-thesaurus/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Smile_ElasticsuiteThesaurus" setup_version="0.0.2">
<module name="Smile_ElasticsuiteThesaurus" setup_version="1.0.0">
<sequence>
<module name="Smile_ElasticsuiteCore"/>
</sequence>
Expand Down
2 changes: 2 additions & 0 deletions src/module-elasticsuite-thesaurus/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Expansions,Expansions
Terms,Terms
Action,Action
Edit,Edit
Active,Active
Inactive,Inactive
2 changes: 2 additions & 0 deletions src/module-elasticsuite-thesaurus/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Expansions,Expansions
Terms,Termes
Action,Action
Edit,Editer
Active,Activé
Inactive,Désactivé
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@
<argument name="sortable" xsi:type="string">0</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="thesaurus_is_active">
<arguments>
<argument name="header" xsi:type="string" translate="true">Status</argument>
<argument name="index" xsi:type="string">is_active</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="array">
<item name="expansion" xsi:type="array">
<item name="value" xsi:type="string">0</item>
<item name="label" xsi:type="string" translate="true">Inactive</item>
</item>
<item name="synonym" xsi:type="array">
<item name="value" xsi:type="string">1</item>
<item name="label" xsi:type="string" translate="true">Active</item>
</item>
</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="action">
<arguments>
<argument name="type" xsi:type="string">action</argument>
Expand Down

0 comments on commit 2777bfd

Please sign in to comment.