Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16785 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
16785 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Form\Planning;
5
 
6
use Laminas\Form\Form;
7
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Mapper\PlanningPeriodMapper;
9
use LeadersLinked\Mapper\PlanningObjectiveMapper;
10
use LeadersLinked\Mapper\PlanningGoalMapper;
11
 
12
class PlanningTaskHeaderForm extends Form
13
{
14
    private int $first_period_id = 0;
15
    private int $first_objective_id = 0;
16
 
17
    /**
18
     *
19
     * @param AdapterInterface $dbAdapter
20
     * @param int $company_id
21
     */
22
    public function __construct($dbAdapter, $company_id)
23
    {
24
        parent::__construct();
25
 
26
        $this->setInputFilter(new PlanningGoalHeaderFilter());
27
 
28
        $this->add([
29
            'name' => 'period_id',
16802 efrain 30
            'type' => \Laminas\Form\Element\Select::class,
16785 efrain 31
            'attributes' => [
32
                'id' 			=> 'period_id',
33
            ],
34
            'options' => [
35
                'value_options' => $this->plannigPeriod($dbAdapter, $company_id)
36
            ]
37
        ]);
38
 
39
 
40
        $this->add([
41
            'name' => 'objective_id',
16802 efrain 42
            'type' => \Laminas\Form\Element\Select::class,
16785 efrain 43
            'attributes' => [
44
                'id' 			=> 'objective_id',
45
            ],
46
            'options' => [
47
                'value_options' => $this->plannigObjective($dbAdapter, $company_id)
48
            ]
49
        ]);
50
 
51
        $this->add([
52
            'name' => 'goal_id',
16802 efrain 53
            'type' => \Laminas\Form\Element\Select::class,
16785 efrain 54
            'attributes' => [
55
                'id' 			=> 'goal_id',
56
            ],
57
            'options' => [
58
                'value_options' => $this->plannigGoal($dbAdapter, $company_id)
59
            ]
60
        ]);
61
 
62
    }
63
 
64
    /**
65
     *
66
     * @param AdapterInterface $dbAdapter
67
     * @param int $company_id
68
     * return array
69
     */
70
    private function plannigPeriod($dbAdapter, $company_id)
71
    {
72
        $items = [];
73
 
74
        $planningPeriodMapper = PlanningPeriodMapper::getInstance($dbAdapter);
75
        $records = $planningPeriodMapper->fetchAllActiveByCompany($company_id);
76
        foreach($records as $record)
77
        {
78
 
79
            if(empty($this->first_period_id)) {
80
                $this->first_period_id = $record->id;
81
            }
82
 
83
            $items[ $record->uuid ] = $record->title;
84
        }
85
 
86
 
87
        return $items;
88
    }
89
 
90
    /**
91
     *
92
     * @param AdapterInterface $dbAdapter
93
     * @param int $company_id
94
     * return array
95
     */
96
    private function plannigObjective($dbAdapter, $company_id)
97
    {
98
        $items = [];
99
 
100
        $planningObjectiveMapper = PlanningObjectiveMapper::getInstance($dbAdapter);
101
        $records = $planningObjectiveMapper->fetchAllActiveByCompanyIdAndPeriodId($company_id, $this->first_period_id);
102
        foreach($records as $record)
103
        {
104
 
105
 
106
            if(empty($this->first_objective_id)) {
107
                $this->first_objective_id = $record->id;
108
            }
109
 
110
            $items[ $record->uuid ] = $record->title;
111
        }
112
 
113
        return $items;
114
    }
115
 
116
    /**
117
     *
118
     * @param AdapterInterface $dbAdapter
119
     * @param int $company_id
120
     * return array
121
     */
122
    private function plannigGoal($dbAdapter, $company_id)
123
    {
124
        $items = [];
125
 
126
        $planningGoalMapper = PlanningGoalMapper::getInstance($dbAdapter);
127
        $records = $planningGoalMapper->fetchAllActiveByCompanyIdAndObjectiveId($company_id, $this->first_objective_id);
128
        foreach($records as $record)
129
        {
130
            $items[ $record->uuid ] = $record->title;
131
        }
132
 
133
 
134
        return $items;
135
    }
136
 
137
}