65 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
| <?php
 | |
| namespace Kai\Banner\Model;
 | |
| 
 | |
| use Kai\Banner\Model\KaiBannerCollection;
 | |
| use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
 | |
| use Magento\Framework\DB\Ddl\Table;
 | |
| 
 | |
| class KaiBannerValues extends AbstractSource
 | |
| {
 | |
|     protected $_optionFactory;
 | |
|     protected $collection;
 | |
| 
 | |
|     public function __construct(
 | |
|         KaiBannerCollection $collection
 | |
|     ) {
 | |
|         $this->collection = $collection;
 | |
|     }
 | |
| 
 | |
|     public function getAllOptions()
 | |
|     {
 | |
|         $data = $this->collection->getData();
 | |
|         $options = [
 | |
|             [
 | |
|                 'label' => 'Select option!',
 | |
|                 'value' => '',
 | |
|             ]
 | |
|         ];
 | |
| 
 | |
|         foreach ($data as $record) {
 | |
|             $options[] = [
 | |
|                 'label' => $record['id'],
 | |
|                 'value' => $record['title'],
 | |
|             ];
 | |
|         };
 | |
| 
 | |
|         $this->_options = $options;
 | |
|         return $options;
 | |
|     }
 | |
| 
 | |
|     public function getOptionText($value)
 | |
|     {
 | |
|         foreach ($this->getAllOptions() as $option) {
 | |
|             if ($option['value'] == $value) {
 | |
|                 return $option['label'];
 | |
|             }
 | |
|         }
 | |
|         return false;
 | |
|     }
 | |
| 
 | |
|     public function getFlatColumns()
 | |
|     {
 | |
|         $attributeCode = $this->getAttribute()->getAttributeCode();
 | |
|         return [
 | |
|             $attributeCode => [
 | |
|                 'unsigned' => false,
 | |
|                 'default' => null,
 | |
|                 'extra' => null,
 | |
|                 'type' => Table::TYPE_INTEGER,
 | |
|                 'nullable' => true,
 | |
|                 'comment' => 'Kai Banner ' . $attributeCode . ' column',
 | |
|             ],
 | |
|         ];
 | |
|     }
 | |
| }
 |