ElementPedagogiqueSynchronisationForm.php 2.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

namespace Application\Form\OffreFormation;

use Application\Entity\Db\Traits\StructureAwareTrait;
use Application\Form\AbstractForm;
use Application\Service\Traits\ContextServiceAwareTrait;
use UnicaenApp\Service\EntityManagerAwareInterface;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Zend\Hydrator\ClassMethods;

/**
 * Description of ElementPedagogiqueSynchronisationForm
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
class ElementPedagogiqueSynchronisationForm extends AbstractForm implements EntityManagerAwareInterface
{
    use EntityManagerAwareTrait;
    use ContextServiceAwareTrait;
    use StructureAwareTrait;

    /**
     * This function is automatically called when creating element with factory. It
     * allows to perform various operations (add elements...)
     */
    public function init()
    {
        $this->setAttribute('class', 'element-pedagogique-synchronisation');
        $this->setAttribute('action', $this->getCurrentUrl());

        $this->add([
            'type'       => 'Select',
            'name'       => 'code',
            'options'    => [
                'label' => 'Code',
            ],
            'attributes' => [
                'class'            => 'selectpicker',
                'data-live-search' => 'true',
            ],
        ]);

        $this->add([
            'name'       => 'submit',
            'type'       => 'Submit',
            'attributes' => [
                'value' => 'Importer dans OSE',
                'class' => 'btn btn-primary importer',
            ],
        ]);
    }



    public function populate()
    {
        $elements = [];
59
        $sql      = "SELECT code, libelle FROM V_DIFF_ELEMENT_PEDAGOGIQUE WHERE IMPORT_ACTION IN ('insert','undelete') AND ANNEE_ID = :annee AND structure_id = :structure ORDER BY CODE";
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
        $params   = [
            'annee'     => $this->getServiceContext()->getAnnee()->getId(),
            'structure' => $this->getStructure()->getId(),
        ];
        $data     = $this->getEntityManager()->getConnection()->fetchAll($sql, $params);
        foreach ($data as $d) {
            $elements[$d['CODE']] = $d['CODE'] . ' : ' . $d['LIBELLE'];
        }
        $this->get('code')->setValueOptions($elements);
    }



    /**
     * Should return an array specification compatible with
     * {@link Zend\InputFilter\Factory::createInputFilter()}.
     *
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return [
            'code' => [
                'required' => true,
            ],
        ];
    }
}