Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17183 | Ir a la última revisión | | Comparar con el anterior | 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;
17178 stevensc 8
use Laminas\Form\Element\Select;
9
use Laminas\Form\Element\Textarea;
10
use Laminas\Form\Element\Text;
11
use Laminas\Form\Element\Hidden;
12
use LeadersLinked\Model\Company;
17002 efrain 13
use LeadersLinked\Model\MicrolearningTopic;
17178 stevensc 14
use LeadersLinked\Model\MicrolearningCapsule;
15
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
17002 efrain 16
 
17
class TopicEditForm extends Form
18
{
19
 
17178 stevensc 20
    public function __construct($adapter, $company_id, $internal = Company::INTERNAL_NO)
17002 efrain 21
    {
22
        parent::__construct();
17111 stevensc 23
        $this->setInputFilter(new TopicEditFilter($adapter));
17002 efrain 24
 
25
        $this->add([
26
            'name' => 'name',
17178 stevensc 27
            'type' => Textarea::class,
17002 efrain 28
            'attributes' => [
29
                'id'    => 'name',
30
            ]
31
        ]);
32
 
33
        $this->add([
34
            'name' => 'description',
17178 stevensc 35
            'type' => Textarea::class,
17002 efrain 36
            'attributes' => [
37
                'id'    => 'description',
38
            ]
39
        ]);
40
 
41
        $this->add([
42
            'name' => 'order',
17178 stevensc 43
            'type' => Text::class,
17002 efrain 44
            'attributes' => [
45
                'id'    => 'order',
46
            ],
47
        ]);
48
 
49
        $this->add([
50
            'name' => 'file',
17178 stevensc 51
            'type' => Hidden::class,
17002 efrain 52
            'attributes' => [
53
                'id' => 'file',
54
            ]
55
        ]);
56
 
17178 stevensc 57
        $this->add([
58
            'name' => 'marketplace',
59
            'type' => Hidden::class,
60
            'attributes' => [
61
                'id' => 'marketplace',
62
            ]
63
        ]);
17002 efrain 64
 
65
        $this->add([
66
            'name' => 'status',
17178 stevensc 67
            'type' => Select::class,
17002 efrain 68
            'options' => [
69
                'empty_option' => 'LABEL_STATUS',
70
                'value_options' => [
71
                    MicrolearningTopic::STATUS_ACTIVE => 'LABEL_ACTIVE',
72
                    MicrolearningTopic::STATUS_INACTIVE => 'LABEL_INACTIVE',
73
                ],
74
            ],
75
            'attributes' => [
76
                'id' => 'status',
77
            ]
78
        ]);
17178 stevensc 79
 
80
        if($internal == Company::INTERNAL_YES) {
81
            $value_options = [
82
                MicrolearningTopic::PRIVACY_PRIVATE => 'LABEL_PRIVATE',
83
                MicrolearningTopic::PRIVACY_PUBLIC => 'LABEL_PUBLIC',
84
            ];
85
        } else {
86
            $value_options = [
87
                MicrolearningTopic::PRIVACY_PRIVATE => 'LABEL_PRIVATE',
88
            ];
89
        }
90
 
91
        $this->add([
92
            'name' => 'privacy',
93
            'type' => Select::class,
94
            'options' => [
95
                'empty_option' => 'LABEL_PRIVACY',
96
                'value_options' => $value_options,
97
            ],
98
            'attributes' => [
99
                'id' => 'privacy',
100
            ]
101
        ]);
102
 
103
        if($internal == Company::INTERNAL_YES) {
104
            $value_options = [
105
                MicrolearningTopic::TYPE_FREE => 'LABEL_FREE',
106
                MicrolearningTopic::TYPE_SELLING => 'LABEL_SELLING',
107
                MicrolearningTopic::TYPE_PRIVATE => 'LABEL_PRIVATE',
108
            ];
109
        } else {
110
            $value_options = [
17183 stevensc 111
                MicrolearningTopic::TYPE_PRIVATE => 'LABEL_PRIVATE',
17178 stevensc 112
            ];
113
        }
114
 
115
        $this->add([
116
            'name' => 'type',
117
            'type' => Select::class,
118
            'options' => [
119
                'empty_option' => 'LABEL_TYPE',
120
                'value_options' => $value_options,
121
            ],
122
            'attributes' => [
123
                'id' => 'type',
124
            ]
125
        ]);
17002 efrain 126
 
17178 stevensc 127
        $this->add([
128
            'name' => 'cost',
129
            'type' => Text::class,
130
            'attributes' => [
131
                'id'    => 'cost',
132
            ],
133
        ]);
17109 stevensc 134
 
17178 stevensc 135
        $this->add([
136
            'name' => 'capsule_uuid',
137
            'type' => Select::class,
138
            'attributes' => [
139
                'multiple' 	=> 'yes',
140
                'id' =>  'capsule_uuid',
141
            ],
142
            'options' => [
143
                'disable_inarray_validator' => true,
144
                'value_options' => $this->getSelectOptions($adapter, $company_id)
145
            ]
146
        ]);
17002 efrain 147
    }
17178 stevensc 148
 
149
    private function getSelectOptions($adapter, $company_id)
150
    {
151
        $options = [];
152
 
153
        $mapper = MicrolearningCapsuleMapper::getInstance($adapter);
17183 stevensc 154
        $records = $mapper->fetchAllByCompanyId($company_id);
17178 stevensc 155
 
156
        foreach($records as $record)
157
        {
158
            $options[$record->uuid] = $record->name;
159
        }
160
        return $options;
161
    }
17002 efrain 162
}