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
 
11
class PlanningGoalHeaderForm extends Form
12
{
13
    private int $first_period_id = 0;
14
 
15
    /**
16
     *
17
     * @param AdapterInterface $dbAdapter
18
     * @param int $company_id
19
     */
20
    public function __construct($dbAdapter, $company_id)
21
    {
22
        parent::__construct();
23
 
24
        $this->setInputFilter(new PlanningGoalHeaderFilter());
25
 
26
        $this->add([
27
            'name' => 'period_id',
16802 efrain 28
            'type' => \Laminas\Form\Element\Select::class,
16785 efrain 29
            'attributes' => [
30
                'id' 			=> 'period_id',
31
            ],
32
            'options' => [
33
                'value_options' => $this->plannigPeriod($dbAdapter, $company_id)
34
            ]
35
        ]);
36
 
37
 
38
        $this->add([
39
            'name' => 'objective_id',
16802 efrain 40
            'type' => \Laminas\Form\Element\Select::class,
16785 efrain 41
            'attributes' => [
42
                'id' 			=> 'objective_id',
43
            ],
44
            'options' => [
45
                'value_options' => $this->plannigObjective($dbAdapter, $company_id)
46
            ]
47
        ]);
48
 
49
 
50
 
51
    }
52
 
53
    /**
54
     *
55
     * @param AdapterInterface $dbAdapter
56
     * @param int $company_id
57
     * return array
58
     */
59
    private function plannigPeriod($dbAdapter, $company_id)
60
    {
61
        $items = [];
62
 
63
        $planningPeriodMapper = PlanningPeriodMapper::getInstance($dbAdapter);
64
        $records = $planningPeriodMapper->fetchAllActiveByCompany($company_id);
65
        foreach($records as $record)
66
        {
67
 
68
            if(empty($this->first_period_id)) {
69
                $this->first_period_id = $record->id;
70
            }
71
 
72
            $items[ $record->uuid ] = $record->title;
73
        }
74
 
75
 
76
        return $items;
77
    }
78
 
79
    /**
80
     *
81
     * @param AdapterInterface $dbAdapter
82
     * @param int $company_id
83
     * return array
84
     */
85
    private function plannigObjective($dbAdapter, $company_id)
86
    {
87
        $items = [];
88
 
89
        $planningObjectiveMapper = PlanningObjectiveMapper::getInstance($dbAdapter);
90
        $records = $planningObjectiveMapper->fetchAllActiveByCompanyIdAndPeriodId($company_id, $this->first_period_id);
91
        foreach($records as $record)
92
        {
93
            $items[ $record->uuid ] = $record->title;
94
        }
95
 
96
 
97
        return $items;
98
    }
99
 
100
}