Your IP : 216.73.216.220


Current Path : /var/www/html/app/code/FlipsDigital/TextbookListStudent/Model/Options/
Upload File :
Current File : /var/www/html/app/code/FlipsDigital/TextbookListStudent/Model/Options/TextbookListStudent.php

<?php
namespace FlipsDigital\TextbookListStudent\Model\Options;

class TextbookListStudent implements \Magento\Framework\Option\ArrayInterface
{
    protected $_options;
    protected $_storeManager;
    protected $_objectManager;
    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManagerInterface,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookListFactory $customerTextbookListFactory,
        \FlipsDigital\TextbookListStudent\Model\TextbookListStudentFactory $textbookListStudentFactory
    ) {
        $this->_objectManager = $objectManagerInterface;
        $this->_storeManager = $storeManager;
        $this->_ctlFactory = $customerTextbookListFactory;
        $this->_tlsFactory = $textbookListStudentFactory;
    }

    public function toOptionArray()
    {
        $this->_options = [];
        array_unshift($this->_options, ['value' => '', 'label' => __('-- Please Select --')]);
        // $entityFactory = $this->_objectManager->create(\FlipsDigital\TextbookListStudent\Model\ResourceModel\TextbookListStudent\Collection::class);
        // $arrEnities = $entityFactory->addAttributeToSelect('*')
        //     ->setOrder('id','ASC')
        //     ->setStore($this->_storeManager->getStore());
        // if (count($arrEnities)){
        //     foreach ($arrEnities as $objEntity){
        //         $this->_options[] = [
        //             'label' => $objEntity->getData('mers_stock_source_g_gl_student_gl_classname') .' - '.$objEntity->getData('mers_stock_source_g_gl_student_student_class') .' - '.$objEntity->getData('mers_stock_source_g_gl_student_student_no') ,
        //             'value' => $objEntity->getId(),
        //         ];
        //     }
        // }
        $objCTL = $this->_ctlFactory->create();
        $collectionCTL = $objCTL->getCollection();
        $collectionCTL->addAttributeToSelect('*');
        $collectionCTL->setOrder('id','ASC');
        if ($collectionCTL->count()){
            $arrTLS = [];
            foreach ($collectionCTL->getItems() as $key => $value) {
                $arrTLS[] = $value->getData('booklist_student_id');
            }
            if(count(array_unique($arrTLS))){
                $objTLS = $this->_tlsFactory->create();
                $collectionTLS = $objTLS->getCollection();
                $collectionTLS->addAttributeToSelect('*');
                $collectionTLS->addAttributeToFilter('entity_id', array('in' => array_unique($arrTLS)));
                $collectionTLS->setOrder('mers_stock_source_g_gl_student_gl_classname','ASC');
                if ($collectionTLS->count()){
                    foreach ($collectionTLS->getItems() as $key => $objEntity) {
                        $this->_options[] = [
                            'label' => $objEntity->getData('mers_stock_source_g_gl_student_gl_classname') .' - '.$objEntity->getData('mers_stock_source_g_gl_student_student_class') .' - '.$objEntity->getData('mers_stock_source_g_gl_student_student_no') ,
                            'value' => $objEntity->getId(),
                        ];                    
                    }
                }
            }
        }

        return $this->_options;
    }
}