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