Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17110 | Rev 17178 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php

declare(strict_types=1);

namespace LeadersLinked\Form\Microlearning;

use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Log\LoggerInterface;
use LeadersLinked\Mapper\CompanySizeMapper;
use LeadersLinked\Mapper\IndustryMapper;
use LeadersLinked\Model\Feed;
use LeadersLinked\Model\MicrolearningTopic;
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
use Laminas\Form\Element\Select;

class TopicAddForm extends Form
{
    public function __construct($adapter, $company_id) 
    {
        parent::__construct();
        $this->setInputFilter(new TopicAddFilter($adapter));

        $this->add([
            'name' => 'name',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'name',
            ]
        ]);
        
        $this->add([
            'name' => 'description',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'description',
            ]
        ]);
        
        $this->add([
            'name' => 'order',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'id'    => 'order',
            ],
        ]);
        
        $this->add([
            'name' => 'file',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id' => 'file',
            ]
        ]); 
        
        $this->add([
            'name' => 'status',
            'type' => \Laminas\Form\Element\Select::class,
            'options' => [
                'empty_option' => 'LABEL_STATUS',
                'value_options' => [
                    MicrolearningTopic::STATUS_ACTIVE => 'LABEL_ACTIVE',
                    MicrolearningTopic::STATUS_INACTIVE => 'LABEL_INACTIVE',
                ],
            ],
            'attributes' => [
                'id' => 'status',
            ]
        ]);
        
        $this->add([
            'name' => 'capsule_uuid',
            'type' => Select::class,
            'attributes' => [
                'multiple'      => 'yes',
                'id' =>  'capsule_uuid',
            ],
            'options' => [
                'disable_inarray_validator' => true,
                'value_options' => $this->getSelectOptions($adapter, $company_id)
            ]
        ]);
    }

    private function getSelectOptions($adapter, $company_id)
    {
        $options = [];
    
        $mapper = MicrolearningCapsuleMapper::getInstance($adapter);
        $records = $mapper->fetchAllActiveByCompanyId($company_id);
    
        foreach($records as $record)
        {
            $options[$record->uuid] = $record->name;
        }
        return $options;
    }
}