Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15831 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15451 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Form\MyCoach;
6
 
7
use Laminas\Form\Form;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Model\Topic;
11
use Laminas\Form\Element;
12
 
13
use LeadersLinked\Mapper\UserMapper;
14
 
15
 
16
class MyCoachCategoryForm extends Form
17
{
18
 
19
    /**
20
     *
21
     * @param AdapterInterface $adapter
22
     * @param int $company_id
23
     * @param int $allowPrivacyPublic
24
     */
25
    public function __construct($adapter, $company_id, $allowPrivacyPublic) {
26
        parent::__construct();
27
        $this->setInputFilter(new MyCoachCategoryFilter($adapter));
28
 
29
         $this->add([
30
            'name' => 'name',
31
            'type' => \Laminas\Form\Element\Text::class,
32
            'attributes' => [
33
                'maxlength' 	=> 128,
34
                'id' 			=> 'name',
35
            ]
36
        ]);
37
 
38
       $this->add([
39
            'name' => 'description',
40
            'type' => \Laminas\Form\Element\Textarea::class,
41
            'attributes' => [
42
                'id'    => 'description',
43
            ]
44
        ]);
45
 
46
        $this->add([
47
            'name' => 'status',
48
            'type' => \Laminas\Form\Element\Checkbox::class,
49
            'attributes' => [
50
                'id' 			=> 'status',
51
            ],
52
            'options' => [
53
                'use_hidden_element' => 0,
54
                'unchecked_value' => \LeadersLinked\Model\MyCoachCategory::STATUS_INACTIVE,
55
                'checked_value'=> \LeadersLinked\Model\MyCoachCategory::STATUS_ACTIVE
56
            ]
57
        ]);
58
 
59
        $options = [];
60
        if($allowPrivacyPublic) {
61
            $options = [
62
                \LeadersLinked\Model\MyCoachCategory::PRIVATY_PUBLIC => 'LABEL_PUBLIC',
63
                \LeadersLinked\Model\MyCoachCategory::PRIVACY_COMPANY => 'LABEL_COMPANY',
64
            ];
65
        } else {
66
            $options = [
67
                \LeadersLinked\Model\MyCoachCategory::PRIVACY_COMPANY => 'LABEL_COMPANY',
68
            ];
69
        }
70
 
71
 
72
        $this->add([
73
            'name' => 'privacy',
74
            'type' => \Laminas\Form\Element\Select::class,
75
            'attributes' => [
76
                'id' =>  'privacy',
77
            ],
78
            'options' => [
79
                //'disable_inarray_validator' => true,
80
                'value_options' =>  $options
81
            ]
82
        ]);
83
 
84
        $this->add([
85
            'name' => 'editors',
86
            'type' => \Laminas\Form\Element\Select::class,
87
            'attributes' => [
88
                'multiple' => true,
89
                'id' =>  'editors',
90
            ],
91
            'options' => [
92
                'disable_inarray_validator' => true,
93
                'value_options' =>  $this->editorOptions($adapter, $company_id),
94
            ]
95
        ]);
96
 
97
    }
98
 
99
    private function editorOptions($adapter, $company_id)
100
    {
101
        $options = [];
102
        $userMapper = UserMapper::getInstance($adapter);
103
        $records = $userMapper->fetchAllByCompanyId($company_id);
104
 
105
        foreach($records as $record)
106
        {
107
            $options[ $record->uuid ] = trim($record->first_name . ' ' . $record->last_name .  '(' . $record->email . ')');
108
        }
109
 
110
        return $options;
111
 
112
    }
113
 
114
}
115