Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Boolean Class Reference
Inheritance diagram for Boolean:
AbstractSource SourceInterface ArrayInterface OptionSourceInterface Boolean

Public Member Functions

 __construct (\Magento\Eav\Model\ResourceModel\Entity\AttributeFactory $eavAttrEntity)
 
 getAllOptions ()
 
 getOptionArray ()
 
 getOptionText ($value)
 
 getFlatColumns ()
 
 getFlatIndexes ()
 
 getFlatUpdateSelect ($store)
 
 getIndexOptionText ($value)
 
 addValueSortToCollection ($collection, $dir=\Magento\Framework\DB\Select::SQL_ASC)
 
- Public Member Functions inherited from AbstractSource
 setAttribute ($attribute)
 
 getAttribute ()
 
 getOptionText ($value)
 
 getOptionId ($value)
 
 addValueSortToCollection ($collection, $dir=\Magento\Framework\Data\Collection::SORT_ORDER_DESC)
 
 getFlatColumns ()
 
 getFlatIndexes ()
 
 getFlatUpdateSelect ($store)
 
 getIndexOptionText ($value)
 
 toOptionArray ()
 

Data Fields

const VALUE_YES = 1
 
const VALUE_NO = 0
 

Protected Attributes

 $_eavAttrEntity
 
- Protected Attributes inherited from AbstractSource
 $_attribute
 
 $_options = null
 

Detailed Description

@api

Since
100.0.2

Definition at line 12 of file Boolean.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Eav\Model\ResourceModel\Entity\AttributeFactory  $eavAttrEntity)
Parameters
\Magento\Eav\Model\ResourceModel\Entity\AttributeFactory$eavAttrEntity@codeCoverageIgnore

Definition at line 30 of file Boolean.php.

32  {
33  $this->_eavAttrEntity = $eavAttrEntity;
34  }

Member Function Documentation

◆ addValueSortToCollection()

addValueSortToCollection (   $collection,
  $dir = \Magento\Framework\DB\Select::SQL_ASC 
)

Add Value Sort To Collection Select

Parameters
\Magento\Eav\Model\Entity\Collection\AbstractCollection$collection
string$dir
Returns
\Magento\Eav\Model\Entity\Attribute\Source\Boolean

Definition at line 157 of file Boolean.php.

158  {
159  $attributeCode = $this->getAttribute()->getAttributeCode();
160  $attributeId = $this->getAttribute()->getId();
161  $attributeTable = $this->getAttribute()->getBackend()->getTable();
162  $linkField = $this->getAttribute()->getEntity()->getLinkField();
163 
164  if ($this->getAttribute()->isScopeGlobal()) {
165  $tableName = $attributeCode . '_t';
166  $collection->getSelect()
167  ->joinLeft(
168  [$tableName => $attributeTable],
169  "e.{$linkField}={$tableName}.{$linkField}"
170  . " AND {$tableName}.attribute_id='{$attributeId}'"
171  . " AND {$tableName}.store_id='0'",
172  []
173  );
174  $valueExpr = $tableName . '.value';
175  } else {
176  $valueTable1 = $attributeCode . '_t1';
177  $valueTable2 = $attributeCode . '_t2';
178  $collection->getSelect()
179  ->joinLeft(
180  [$valueTable1 => $attributeTable],
181  "e.{$linkField}={$valueTable1}.{$linkField}"
182  . " AND {$valueTable1}.attribute_id='{$attributeId}'"
183  . " AND {$valueTable1}.store_id='0'",
184  []
185  )
186  ->joinLeft(
187  [$valueTable2 => $attributeTable],
188  "e.{$linkField}={$valueTable2}.{$linkField}"
189  . " AND {$valueTable2}.attribute_id='{$attributeId}'"
190  . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
191  []
192  );
193  $valueExpr = $collection->getConnection()->getCheckSql(
194  $valueTable2 . '.value_id > 0',
195  $valueTable2 . '.value',
196  $valueTable1 . '.value'
197  );
198  }
199 
200  $collection->getSelect()->order($valueExpr . ' ' . $dir);
201  return $this;
202  }
$tableName
Definition: trigger.php:13
$attributeCode
Definition: extend.phtml:12

◆ getAllOptions()

getAllOptions ( )

Retrieve all options array

Returns
array

Implements SourceInterface.

Definition at line 41 of file Boolean.php.

42  {
43  if ($this->_options === null) {
44  $this->_options = [
45  ['label' => __('Yes'), 'value' => self::VALUE_YES],
46  ['label' => __('No'), 'value' => self::VALUE_NO],
47  ];
48  }
49  return $this->_options;
50  }
__()
Definition: __.php:13

◆ getFlatColumns()

getFlatColumns ( )

Retrieve flat column definition

Returns
array

Definition at line 88 of file Boolean.php.

89  {
90  $attributeCode = $this->getAttribute()->getAttributeCode();
91 
92  return [
93  $attributeCode => [
94  'unsigned' => false,
95  'default' => null,
96  'extra' => null,
98  'length' => 1,
99  'nullable' => true,
100  'comment' => $attributeCode . ' column',
101  ],
102  ];
103  }
$attributeCode
Definition: extend.phtml:12

◆ getFlatIndexes()

getFlatIndexes ( )

Retrieve Indexes(s) for Flat

Returns
array

Definition at line 110 of file Boolean.php.

111  {
112  $indexes = [];
113 
114  $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode());
115  $indexes[$index] = ['type' => 'index', 'fields' => [$this->getAttribute()->getAttributeCode()]];
116 
117  return $indexes;
118  }
$index
Definition: list.phtml:44

◆ getFlatUpdateSelect()

getFlatUpdateSelect (   $store)

Retrieve Select For Flat Attribute update

Parameters
int$store
Returns
\Magento\Framework\DB\Select|null

Definition at line 126 of file Boolean.php.

127  {
128  return $this->_eavAttrEntity->create()->getFlatUpdateSelect($this->getAttribute(), $store);
129  }

◆ getIndexOptionText()

getIndexOptionText (   $value)

Get a text for index option value

Parameters
string | int$value
Returns
string|bool

Definition at line 137 of file Boolean.php.

138  {
139  switch ($value) {
140  case self::VALUE_YES:
141  return 'Yes';
142  case self::VALUE_NO:
143  return 'No';
144  }
145 
146  return parent::getIndexOptionText($value);
147  }
$value
Definition: gender.phtml:16

◆ getOptionArray()

getOptionArray ( )

Retrieve option array

Returns
array

Definition at line 57 of file Boolean.php.

◆ getOptionText()

getOptionText (   $value)

Get a text for option value

Parameters
string | int$value
Returns
string|false

Implements SourceInterface.

Definition at line 72 of file Boolean.php.

73  {
74  $options = $this->getAllOptions();
75  foreach ($options as $option) {
76  if ($option['value'] == $value) {
77  return $option['label'];
78  }
79  }
80  return false;
81  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_eavAttrEntity

$_eavAttrEntity
protected

Definition at line 24 of file Boolean.php.

◆ VALUE_NO

const VALUE_NO = 0

Definition at line 19 of file Boolean.php.

◆ VALUE_YES

const VALUE_YES = 1

Option values

Definition at line 17 of file Boolean.php.


The documentation for this class was generated from the following file: