Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
17002 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Form\Microlearning;
6
 
7
use Laminas\Form\Form;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Mapper\MicrolearningTopicMapper;
10
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
11
 
12
class TopicCapsuleForm extends Form
13
{
14
 
15
    /**
16
     *
17
     * @param AdapterInterface $adapter
18
     * @param int $company_id
19
     * @param int $topic_id
20
     */
21
    public function __construct($adapter, $company_id, $topic_id)
22
    {
23
        parent::__construct();
24
        $this->setInputFilter(new TopicCapsuleFilter($adapter));
25
 
26
        $this->add([
27
            'name' => 'topic_uuid',
28
            'type' => \Laminas\Form\Element\Select::class,
29
            'attributes' => [
30
                'id' => 'topic_uuid',
31
            ],
32
            'options' => [
33
                'value_options' => $this->getSelectTopicOptions($adapter, $company_id)
34
            ]
35
        ]);
36
 
37
 
38
 
39
        $this->add([
40
            'name' => 'capsule_uuid',
41
            'type' => \Laminas\Form\Element\Select::class,
42
            'attributes' => [
43
                'id' => 'capsule_uuid',
44
            ],
45
            'options' => [
46
                'value_options' => $this->getSelectCapsuleOptions($adapter, $company_id, $topic_id)
47
            ]
48
        ]);
49
    }
50
 
51
    /**
52
     *
53
     * @param AdapterInterface $adapter
54
     */
55
    private function getSelectTopicOptions($adapter, $company_id)
56
    {
57
        $options = [];
58
 
59
        $mapper = MicrolearningTopicMapper::getInstance($adapter);
60
        $records = $mapper->fetchAllByCompanyId($company_id);
61
 
62
        foreach($records as $record)
63
        {
64
            $options[$record->uuid] = $record->name;
65
        }
66
        return $options;
67
    }
68
 
69
    /**
70
     *
71
     * @param AdapterInterface $adapter
72
     */
73
    private function getSelectCapsuleOptions($adapter, $company_id, $topic_id)
74
    {
75
        $options = [];
76
 
77
        $mapper = MicrolearningCapsuleMapper::getInstance($adapter);
78
        $records = $mapper->fetchAllByCompanyIdAndTopicId($company_id, $topic_id);
79
 
80
        foreach($records as $record)
81
        {
82
            $options[$record->uuid] = $record->name;
83
        }
84
        return $options;
85
    }
86
}