TemplateHydrator.php 1.7 KB
Newer Older
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
1
2
<?php

3
namespace UnicaenRenderer\Form\Template;
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
4

5
use UnicaenRenderer\Entity\Db\Template;
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
6
7
use Zend\Hydrator\HydratorInterface;

8
class TemplateHydrator implements HydratorInterface {
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
9
10

    /**
11
     * @param Template $object
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
12
13
14
15
16
17
18
19
     * @return array
     */
    public function extract($object)
    {
        $data = [
            'code' => ($object)?$object->getCode():null,
            'type' => ($object)?$object->getType():null,
            'description' => ($object)?$object->getDescription():null,
20
21
            'sujet' => ($object)?$object->getSujet():null,
            'corps' => ($object)?$object->getCorps():null,
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
22
23
24
25
26
27
28
            'css' => ($object)?$object->getCss():null,
        ];

        return $data;
    }

    /**
29
     * @param Template $object
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
30
     * @param array $data
31
     * @return Template
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
32
33
34
35
36
37
     */
    public function hydrate(array $data, $object)
    {
        $code = (isset($data['code']) AND trim($data['code']) !== "")?trim($data['code']):null;
        $type = (isset($data['type']) AND trim($data['type']) !== "")?trim($data['type']):null;
        $description = (isset($data['description']) AND trim($data['description']) !== "")?trim($data['description']):null;
38
39
        $sujet = (isset($data['sujet']) AND trim($data['sujet']) !== "")?strip_tags(trim($data['sujet'])):null;
        $corps = (isset($data['corps']) AND trim($data['corps']) !== "")?trim($data['corps']):null;
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
40
41
42
43
44
        $css = (isset($data['css']) AND trim($data['css']) !== "")?strip_tags(trim($data['css'])):null;

        $object->setCode($code);
        $object->setType($type);
        $object->setDescription($description);
45
46
        $object->setSujet($sujet);
        $object->setCorps($corps);
Jean-Philippe Metivier's avatar
Jean-Philippe Metivier committed
47
48
49
50
51
52
        $object->setCss($css);

        return $object;
    }

}