Proyectos de Subversion LeadersLinked - Backend

Rev

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

<?php

declare(strict_types=1);

namespace LeadersLinked\Form;

use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Log\LoggerInterface;
use LeadersLinked\Mapper\TopicMapper;

class MyTrainerQuestionForm extends Form
{

    public function __construct($adapter) 
    {
        parent::__construct();
        $this->setInputFilter(new MyTrainerQuestionFilter($adapter));

        $this->add([
            'name' => 'title',
            'type' => \Laminas\Form\Element\Text::class,
             'attributes' => [
                'id'                    => 'title',
            ]
        ]);
         
        $this->add([
            'name' => 'text',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'text',
            ]
        ]);

        $this->add([
            'name' => 'category_id',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' => 'category_id',
                'multiple' => 'yes',
            ],
            'options' => [
                'disable_inarray_validator' => true,
                'value_options' => $this->getSelectFormOptions($adapter)
            ]
        ]);
        
    }

     /**
     *
     * @param AdapterInterface $adapter
     */
    private function getSelectFormOptions($adapter)
    {
        $options = [];
        
        $mapper = TopicMapper::getInstance($adapter);
        $records = $mapper->fetchAllMyTrainer(); 
        
        foreach($records as $record)
        {
            $options[$record->uuid] = $record->title;    
        }
        return $options;
    }
}