Proyectos de Subversion LeadersLinked - Backend

Rev

Autoría | Ultima modificación | Ver Log |

<?php

declare(strict_types=1);

namespace LeadersLinked\Form\Microlearning;

use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Mapper\PushTemplateMapper;
use LeadersLinked\Model\PushTemplate;


class PushMicrolearningNotificationForm extends Form
{

    /**
     * 
     * 
     * @param AdapterInterface $adapter
     * @param int $company_id
     */
    public function __construct($adapter, $company_id) 
    {
        parent::__construct();
        $this->setInputFilter(new PushMicrolearningNotificationFilter($adapter));


        
        $this->add([
            'name' => 'push_template_id',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' => 'push_template_id',
            ],
            'options' => [
                'value_options' => $this->getSelectOptions($adapter, $company_id)
            ]
        ]);
        
    }
    
    /**
     *
     * @param AdapterInterface $adapter
     */
    private function getSelectOptions($adapter, $company_id)
    {
        $options = [];
        
        $mapper = PushTemplateMapper::getInstance($adapter);
        $records = $mapper->fetchAllActiveByTypeAndCompanyId(PushTemplate::TYPE_MICRO_LEARNING, $company_id);
        
        if(!$records) {
            $records = $mapper->fetchAllActiveByTypeDefault(PushTemplate::TYPE_MICRO_LEARNING);
        }
        
        foreach($records as $record)
        {
            $options[$record->uuid] = $record->title;
        }
        return $options;
    }
    


    
    
}