Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
67 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Form;
6
 
7
use Laminas\Form\Form;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Mapper\JobDescriptionMapper;
10
use LeadersLinked\Mapper\UserMapper;
11
use LeadersLinked\Mapper\CompanyUserMapper;
12
use LeadersLinked\Model\CompanyUser;
13
 
14
 
15
class PositionForm extends Form
16
{
17
 
18
    /**
19
     *
20
     * @param AdapterInterface $adapter
21
     */
22
    public function __construct($adapter, $company_id)
23
    {
24
        parent::__construct();
25
        $this->setInputFilter(new PositionFilter($adapter, $company_id));
26
 
27
        $this->add([
28
            'name' => 'user_id',
29
            'type' => \Laminas\Form\Element\Select::class,
30
            'attributes' => [
31
                'id' => 'user_id',
32
            ],
33
            'options' => [
34
                'value_options' => $this->getSelectUserOptions($adapter, $company_id)
35
            ]
36
        ]);
37
 
38
        $this->add([
39
            'name' => 'job_description_id',
40
            'type' => \Laminas\Form\Element\Select::class,
41
            'attributes' => [
42
                'id' => 'job_description_id',
43
            ],
44
            'options' => [
45
                'value_options' => $this->getSelectJobsDescriptionOptions($adapter, $company_id)
46
            ]
47
        ]);
48
 
49
 
1320 efrain 50
 
51
        $this->add([
52
            'name' => 'subordinates',
53
            'type' => \Laminas\Form\Element\Select::class,
54
            'attributes' => [
55
                'multiple' 	=> 'yes',
56
                'id' =>  'subordinates',
57
            ],
58
            'options' => [
59
                'disable_inarray_validator' => true,
60
                //'value_options' => $this->getSelectSubordinateOptions($adapter)
61
            ]
62
        ]);
63
 
64
 
67 efrain 65
 
66
 
67
        $this->add([
68
            'name' => 'status',
69
            'type' => \Laminas\Form\Element\Checkbox::class,
70
            'attributes' => [
71
                'id' 			=> 'status',
72
            ],
73
            'options' => [
74
                'use_hidden_element' => 0,
75
                'unchecked_value' => \LeadersLinked\Model\Position::STATUS_INACTIVE,
76
                'checked_value'=> \LeadersLinked\Model\Position::STATUS_ACTIVE,
77
            ]
78
        ]);
79
 
80
    }
81
 
82
    /**
83
     *
84
     * @param AdapterInterface $adapter
85
     */
86
    private function getSelectUserOptions($adapter, $company_id)
87
    {
88
        $options = [];
89
 
90
 
91
        $userMapper = UserMapper::getInstance($adapter);
92
        $mapper = CompanyUserMapper::getInstance($adapter);
93
        $records = $mapper->fetchAllByCompanyId($company_id);
94
 
95
        foreach($records as $record)
96
        {
97
            if($record->status == CompanyUser::STATUS_ACCEPTED && $record->owner != CompanyUser::OWNER_YES) {
98
                $user = $userMapper->fetchOne($record->user_id);
99
 
100
                if($user) {
101
                    $options[$user->uuid] = trim($user->first_name . ' ' . $user->last_name) . ' (' . $user->email . ')';
102
                }
103
            }
104
        }
105
 
106
        natcasesort($options);
107
        return $options;
108
    }
109
 
110
    /**
111
     *
112
     * @param AdapterInterface $adapter
113
     */
114
    private function getSelectJobsDescriptionOptions($adapter, $company_id)
115
    {
116
        $options = [];
117
 
118
        $mapper = JobDescriptionMapper::getInstance($adapter);
119
        $records = $mapper->fetchAllActiveByCompanyId($company_id);
120
 
121
 
122
        foreach($records as $record)
123
        {
124
            $options[$record->uuid] = $record->name;
125
        }
126
        return $options;
127
    }
128
}