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\MicrolearningTopicMapper;
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;

class TopicCapsuleForm extends Form
{

    /**
     * 
     * @param AdapterInterface $adapter
     * @param int $company_id
     * @param int $topic_id
     */
    public function __construct($adapter, $company_id, $topic_id) 
    {
        parent::__construct();
        $this->setInputFilter(new TopicCapsuleFilter($adapter));
        
        $this->add([
            'name' => 'topic_uuid',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' => 'topic_uuid',
            ],
            'options' => [
                'value_options' => $this->getSelectTopicOptions($adapter, $company_id)
            ]
        ]);
        
        
        
        $this->add([
            'name' => 'capsule_uuid',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' => 'capsule_uuid',
            ],
            'options' => [
                'value_options' => $this->getSelectCapsuleOptions($adapter, $company_id, $topic_id)
            ]
        ]);
    }
    
    /**
     *
     * @param AdapterInterface $adapter
     */
    private function getSelectTopicOptions($adapter, $company_id)
    {
        $options = [];
        
        $mapper = MicrolearningTopicMapper::getInstance($adapter);
        $records = $mapper->fetchAllByCompanyId($company_id); 
        
        foreach($records as $record)
        {
            $options[$record->uuid] = $record->name;    
        }
        return $options;
    }
    
    /**
     *
     * @param AdapterInterface $adapter
     */
    private function getSelectCapsuleOptions($adapter, $company_id, $topic_id)
    {
        $options = [];
        
        $mapper = MicrolearningCapsuleMapper::getInstance($adapter);
        $records = $mapper->fetchAllByCompanyIdAndTopicId($company_id, $topic_id);
        
        foreach($records as $record)
        {
            $options[$record->uuid] = $record->name;
        }
        return $options;
    }
}