-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommtoolFactory.php
More file actions
99 lines (80 loc) · 2.85 KB
/
CommtoolFactory.php
File metadata and controls
99 lines (80 loc) · 2.85 KB
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
59
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
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Optime\Bundle\CommtoolBundle;
use Optime\Bundle\CommtoolBundle\ControlFactory;
use Optime\Bundle\CommtoolBundle\Builder\Builder;
use Optime\Bundle\CommtoolBundle\CommtoolBuilderInterface;
use Optime\Commtool\TemplateBundle\Model\TemplateInterface;
use Optime\Commtool\TemplateBundle\Twig\Extension\SectionExtension;
/**
*
* Clase que crea los controles para un commtool
*
* @author Manuel Aguirre <programador.manuel@gmail.com>
*/
class CommtoolFactory
{
/**
* clase que crea los controles
* @var ControlFactory
*/
protected $controlFactory;
/**
*
* @var \Twig_Environment
*/
protected $twig;
/**
* Extensión twig que crea los atributos en las etiquetas html
* @var SectionExtension
*/
protected $sectionExtension;
function __construct(ControlFactory $controlFactory, \Twig_Environment $twig
, SectionExtension $sectionExtension)
{
$this->controlFactory = $controlFactory;
$this->twig = $twig;
$this->sectionExtension = $sectionExtension;
}
/**
* Crea los controles en el commtool, a partir de un TemplateInterface
* @param \Optime\Bundle\CommtoolBundle\CommtoolBuilderInterface $commtoolBuilder
* @param \Optime\Commtool\TemplateBundle\Model\TemplateInterface $template
* @param array $options
*/
public function create(CommtoolBuilderInterface $commtoolBuilder
, TemplateInterface $template, array $options = array())
{
$manipulator = $this->controlFactory->getManipulator();
$manipulator->setContent($this->twig->render($template->getView()));
$builder = new Builder($this->controlFactory, null);
$options['template'] = $template;
$commtoolBuilder->build($builder, $options);
if (isset($options['data'])) {
$values = $options['data'];
} else {
$values = array();
}
if ($builder->hasControls() and count($template->getSections())) {
$controls = $builder->createControls($template->getSections());
}else{
$controls = array();
}
$commtoolBuilder->setControls($controls);
$commtoolBuilder->setContent($this->getContent($commtoolBuilder, $template));
$commtoolBuilder->setValues($values);
}
/**
* Devuelve el contenido html del template
*
* @param \Optime\Bundle\CommtoolBundle\CommtoolBuilderInterface $commtool
* @param \Optime\Commtool\TemplateBundle\Model\TemplateInterface $template
* @return string
*/
protected function getContent(CommtoolBuilderInterface $commtool, TemplateInterface $template)
{
$this->sectionExtension->setCommtool($commtool);
$content = $this->twig->render($template->getView());
$this->sectionExtension->setCommtool(null);
return $content;
}
}