Skip to content

Commit e77a72b

Browse files
committed
Moved models to Model model
1 parent d58e3f8 commit e77a72b

File tree

11 files changed

+413
-278
lines changed

11 files changed

+413
-278
lines changed

CmfSimpleCmsBundle.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66
use Symfony\Component\HttpKernel\Bundle\Bundle;
7+
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
78

89
class CmfSimpleCmsBundle extends Bundle
910
{
@@ -14,5 +15,17 @@ public function build(ContainerBuilder $container)
1415
if ($container->hasExtension('jms_di_extra')) {
1516
$container->getExtension('jms_di_extra')->blackListControllerFile(__DIR__ . '/Controller/PageAdminController.php');
1617
}
18+
19+
if (class_exists('Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass')) {
20+
$container->addCompilerPass(
21+
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
22+
array(
23+
realpath(__DIR__ . '/Resources/config/doctrine-model') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Model',
24+
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr',
25+
),
26+
array('cmf_simple_cms.manager_name')
27+
)
28+
);
29+
}
1730
}
1831
}

Doctrine/Phpcr/Page.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr;
4+
5+
use Symfony\Cmf\Bundle\SimpleCmsBundle\Model\Page as ModelPage;
6+
7+
/**
8+
* {@inheritDoc}
9+
*/
10+
class Page extends ModelPage
11+
{
12+
}

Document/MultilangRedirectRoute.php renamed to Doctrine/Phpcr/PageRedirectRoute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* provides multi language support when using MultilangRouteProvider
1313
*/
14-
class MultilangRedirectRoute extends RedirectRoute
14+
class PageRedirectRoute extends RedirectRoute
1515
{
1616
/**
1717
* {@inheritDoc}

Document/MultilangRoute.php renamed to Doctrine/Phpcr/PageRoute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* provides multi language support when using MultilangRouteProvider
1313
*/
14-
class MultilangRoute extends Route
14+
class PageRoute extends Route
1515
{
1616
/**
1717
* {@inheritDoc}

Document/MultilangRouteProvider.php renamed to Doctrine/Phpcr/PageRouteProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
1212
*/
13-
class MultilangRouteProvider extends RouteProvider
13+
class PageRouteProvider extends RouteProvider
1414
{
1515
/**
1616
* Locales

Document/MultilangPage.php

Lines changed: 0 additions & 83 deletions
This file was deleted.

Model/Page.php

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Model;
4+
5+
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
6+
use Symfony\Component\Validator\Constraints as Assert;
7+
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableInterface;
8+
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodInterface;
9+
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
10+
11+
/**
12+
* This is the standard Page document.
13+
*
14+
* It adds the following to the base document
15+
*
16+
* - Translatable
17+
* - Publish Workflow
18+
* - Tags
19+
*
20+
* Additionally you can store "extra" string values in it for application
21+
* specific purposes.
22+
*
23+
* @PHPCRODM\Document(translator="attribute")
24+
*/
25+
class Page extends PageBase implements
26+
PublishTimePeriodInterface,
27+
PublishableInterface,
28+
TranslatableInterface
29+
{
30+
/**
31+
* @var \DateTime
32+
*/
33+
protected $publishStartDate;
34+
35+
/**
36+
* @var \DateTime
37+
*/
38+
protected $publishEndDate;
39+
40+
/**
41+
* @var boolean
42+
*/
43+
protected $publishable = true;
44+
45+
/**
46+
* @var boolean
47+
*/
48+
protected $addLocalePattern;
49+
50+
/**
51+
* @var string
52+
*/
53+
protected $locale;
54+
55+
/**
56+
* @var array
57+
*/
58+
protected $tags = array();
59+
60+
/**
61+
* Extra values an application can store along with a page
62+
*/
63+
protected $extras;
64+
65+
/**
66+
* Overwrite to be able to create route without pattern
67+
*
68+
* @param Boolean $addFormatPattern whether to add ".{_format}" to the route pattern
69+
* also implicitly sets a default/require on "_format" to "html"
70+
* @param Boolean $addLocalePattern whether to add "/{_locale}" to the route pattern
71+
*/
72+
public function __construct($addFormatPattern = false, $addLocalePattern = true)
73+
{
74+
parent::__construct($addFormatPattern);
75+
$this->addLocalePattern = $addLocalePattern;
76+
}
77+
78+
79+
public function getLocale()
80+
{
81+
return $this->locale;
82+
}
83+
84+
public function setLocale($locale)
85+
{
86+
$this->locale = $locale;
87+
}
88+
89+
/**
90+
* {@inheritDoc}
91+
*
92+
* automatically prepend the _locale to the pattern
93+
*
94+
* @see MultilangRouteProvider::getCandidates()
95+
*/
96+
public function getStaticPrefix()
97+
{
98+
if (!$this->addLocalePattern) {
99+
return parent::getStaticPrefix();
100+
}
101+
102+
$prefix = $this->getPrefix();
103+
$path = substr(parent::getId(), strlen($prefix));
104+
$path = $prefix.'/{_locale}'.$path;
105+
106+
return $this->generateStaticPrefix($path, $this->idPrefix);
107+
}
108+
109+
/**
110+
* {@inheritDoc}
111+
*/
112+
public function getDate()
113+
{
114+
return $this->publishStartDate ? $this->publishStartDate : $this->createDate;
115+
}
116+
117+
/**
118+
* {@inheritDoc}
119+
*/
120+
public function getPublishStartDate()
121+
{
122+
return $this->publishStartDate;
123+
}
124+
125+
/**
126+
* {@inheritDoc}
127+
*/
128+
public function setPublishStartDate(\DateTime $publishStartDate = null)
129+
{
130+
$this->publishStartDate = $publishStartDate;
131+
}
132+
133+
/**
134+
* {@inheritDoc}
135+
*/
136+
public function getPublishEndDate()
137+
{
138+
return $this->publishEndDate;
139+
}
140+
141+
/**
142+
* {@inheritDoc}
143+
*/
144+
public function setPublishEndDate(\DateTime $publishEndDate = null)
145+
{
146+
$this->publishEndDate = $publishEndDate;
147+
}
148+
149+
/**
150+
* {@inheritDoc}
151+
*/
152+
public function isPublishable()
153+
{
154+
return $this->publishable;
155+
}
156+
157+
/**
158+
* {@inheritDoc}
159+
*/
160+
public function setPublishable($publishable)
161+
{
162+
$this->publishable = $publishable;
163+
}
164+
165+
/**
166+
* Content method: Get tags of this page
167+
*
168+
* @return \Traversable list of tag strings
169+
*/
170+
public function getTags()
171+
{
172+
return $this->tags;
173+
}
174+
175+
/**
176+
* Content method: Set tags of this page
177+
*
178+
* @param $tags \Traversable list of tag strings
179+
*/
180+
public function setTags($tags)
181+
{
182+
$this->tags = $tags;
183+
}
184+
185+
/**
186+
* Get extras - a flat key-value hashmap
187+
*
188+
* @return array with only string values
189+
*/
190+
public function getExtras()
191+
{
192+
return $this->extras;
193+
}
194+
195+
/**
196+
* Set extras - applications can store additional information on a page
197+
* without needing to extend the document class.
198+
*
199+
* @param array $extras a flat key-value hashmap. The values are cast to
200+
* string as PHPCR stores multivalue data with only one data type for
201+
* all values.
202+
*/
203+
public function setExtras($extras)
204+
{
205+
foreach ($extras as $key => $value) {
206+
$extras[$key] = (string) $value;
207+
}
208+
209+
$this->extras = $extras;
210+
}
211+
212+
/**
213+
* Add a single key - value pair to extras
214+
*
215+
* @param string $key
216+
* @param string $value - if this is not a string it is cast to one
217+
*/
218+
public function addExtra($key, $value)
219+
{
220+
$this->extras[$key] = (string) $value;
221+
}
222+
223+
/**
224+
* Remove a single key - value pair from extras, if it was set.
225+
*
226+
* @param string $key
227+
*/
228+
public function removeExtra($key)
229+
{
230+
if (array_key_exists($key, $this->extras)) {
231+
unset($this->extras[$key]);
232+
}
233+
}
234+
235+
/**
236+
* Return a single extras value for the provided key or the $default if
237+
* the key is not defined.
238+
*
239+
* @param string $key
240+
* @param string|null $default
241+
*
242+
* @return string|null The value at $key or if not existing $default
243+
*/
244+
public function getExtra($key, $default = null)
245+
{
246+
return array_key_exists($key, $this->extras) ? $this->extras[$key] : $default;
247+
}
248+
}

0 commit comments

Comments
 (0)