Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added getter/setter for slug (getSlug/setSlug) in the translation mod…

…el in case 'slug' column name is different from 'slug'

removed extra empty lines
  • Loading branch information...
commit 246b87201a42e75333557b4500821db8f28af038 1 parent 7b6117d
@ElvenPath authored
View
23 I18nWithSlugBehavior.php
@@ -59,6 +59,17 @@ public function modifyTable()
$this->addCultureColumnToI18n();
$this->addSlugColumnToI18n();
$this->moveI18nColumns();
+
+
+ // tell the parent table that it has a descendant
+ $parentBehavior = new I18nWithSlugChildBehavior();
+ $parentBehavior->setName('i18n_with_slug_child');
+ $parentBehavior->setParameters(array('slug_column' => $this->getParameter('slug_column')));
+ $this->i18nTable->addBehavior($parentBehavior);
+ $parentBehavior->getTableModifier()->modifyTable();
+ $parentBehavior->setTableModified(true);
+
+
}
protected function addI18nTable()
@@ -173,11 +184,10 @@ protected function moveI18nColumns()
protected function addSlugColumnToI18n()
{
- $slugColumnName = $this->getSlugColumnName();
- if (!$this->i18nTable->hasColumn($slugColumnName))
+ if (!$this->i18nTable->hasColumn($this->getParameter('slug_column')))
{
$this->i18nTable->addColumn(array(
- 'name' => $slugColumnName,
+ 'name' => $this->getParameter('slug_column'),
'type' => 'VARCHAR',
'size' => 255
));
@@ -206,10 +216,6 @@ protected function getCultureColumnName()
{
return $this->replaceTokens($this->getParameter('culture_column'));
}
- protected function getSlugColumnName()
- {
- return $this->replaceTokens($this->getParameter('slug_column'));
- }
protected function getI18nColumnNamesFromConfig()
{
@@ -259,9 +265,10 @@ public function getCultureColumn()
{
return $this->getI18nTable()->getColumn($this->getCultureColumnName());
}
+
public function getSlugColumn()
{
- return $this->getI18nTable()->getColumn($this->getSlugColumnName());
+ return $this->getI18nTable()->getColumn($this->getParameter('slug_column'));
}
public function getI18nColumns()
View
1  I18nWithSlugBehaviorObjectBuilderModifier.php
@@ -222,6 +222,7 @@ protected function addSlugSetter()
{
return $this->behavior->renderTemplate('objectSlugSetter', array(
'slugColumnName' => $this->behavior->getSlugColumn()->getPhpName(),
+ 'objectClassname' => $this->builder->getNewStubObjectBuilder($this->behavior->getTable())->getClassname(),
));
}
View
26 I18nWithSlugChildBehavior.php
@@ -0,0 +1,26 @@
+<?php
+require_once dirname(__FILE__) . '/I18nWithSlugChildBehaviorObjectBuilderModifier.php';
+
+class I18nWithSlugChildBehavior extends Behavior
+{
+ protected $tableModificationOrder = 71;
+
+ protected
+ $objectBuilderModifier,
+ $queryBuilderModifier;
+
+
+ public function getObjectBuilderModifier()
+ {
+ if (is_null($this->objectBuilderModifier))
+ {
+ $this->objectBuilderModifier = new I18nWithSlugChildBehaviorObjectBuilderModifier($this);
+ }
+ return $this->objectBuilderModifier;
+ }
+
+ public function getSlugColumn()
+ {
+ return $this->table->getColumn($this->getParameter('slug_column'));
+ }
+}
View
40 I18nWithSlugChildBehaviorObjectBuilderModifier.php
@@ -0,0 +1,40 @@
+<?php
+class I18nWithSlugChildBehaviorObjectBuilderModifier
+{
+ protected $behavior, $table, $builder;
+
+ public function __construct(I18nWithSlugChildBehavior $behavior)
+ {
+ $this->behavior = $behavior;
+ $this->table = $behavior->getTable();
+ }
+
+ public function objectMethods($builder)
+ {
+ $this->builder = $builder;
+ $script = '';
+
+ if ($this->behavior->getParameter('slug_column') <> 'slug')
+ {
+ $script .= $this->addSlugSetter();
+ $script .= $this->addSlugGetter();
+ }
+
+ return $script;
+ }
+
+ protected function addSlugSetter()
+ {
+ return $this->behavior->renderTemplate('objectChildSlugSetter', array(
+ 'slugColumnName' => $this->behavior->getSlugColumn()->getPhpName(),
+ 'objectClassname' => $this->builder->getNewStubObjectBuilder($this->behavior->getTable())->getClassname(),
+ ));
+ }
+
+ protected function addSlugGetter()
+ {
+ return $this->behavior->renderTemplate('objectChildSlugGetter', array(
+ 'slugColumnName' => $this->behavior->getSlugColumn()->getPhpName(),
+ ));
+ }
+}
View
9 templates/objectChildSlugGetter.php
@@ -0,0 +1,9 @@
+/**
+* Wrap the getter for slug
+*
+* @return string
+*/
+public function getSlug()
+{
+ return $this->get<?php echo $slugColumnName?>();
+}
View
10 templates/objectChildSlugSetter.php
@@ -0,0 +1,10 @@
+/**
+* Wrap the setter for slug value
+*
+* @param string
+* @return <?php echo $objectClassname ?> The current object (for fluent API support)
+*/
+public function setSlug($slug)
+{
+ return $this->set<?php echo $slugColumnName?>($slug);
+}
View
5 templates/objectCreateSlug.php
@@ -3,7 +3,6 @@
*
* @return string The object slug
*/
-
protected function createSlug($culture = '<?php $defaultCulture ?>')
{
$slug = $this->createRawSlug();
@@ -18,7 +17,6 @@ protected function createSlug($culture = '<?php $defaultCulture ?>')
*
* @return string
*/
-
protected function createRawSlug()
{
<?php if ($pattern):?>
@@ -36,7 +34,6 @@ protected function createRawSlug()
* @param string $separator the separator used by slug
* @return string the slugified text
*/
-
protected static function cleanupSlugPart($slug, $replacement = '<?php echo $replacement?>')
{
// transliterate
@@ -76,7 +73,6 @@ protected static function cleanupSlugPart($slug, $replacement = '<?php echo $rep
* Make sure the slug is short enough to accomodate the column size
*
* @param string $slug the slug to check
-*
* @return string the truncated slug
*/
protected static function limitSlugSize($slug, $incrementReservedSpace = 3)
@@ -97,7 +93,6 @@ protected static function limitSlugSize($slug, $incrementReservedSpace = 3)
* @param string $separator the separator used by slug
* @return string the unique slug
*/
-
protected function makeSlugUnique($slug, $culture = '<?php echo $defaultCulture ?>', $separator = '<?php echo $separator?>', $increment = 0)
{
$slug2 = empty($increment) ? $slug : $slug . $separator . $increment;
View
1  templates/objectGetCurrentTranslation.php
@@ -3,7 +3,6 @@
* Returns the current translation
*
* @param PropelPDO $con an optional connection object
- *
* @return <?php echo $i18nTablePhpName ?>
*/
public function getCurrentTranslation(PropelPDO $con = null)
View
1  templates/objectRemoveTranslation.php
@@ -4,7 +4,6 @@
*
* @param string $culture Culture to use for the translation, e.g. 'fr_FR'
* @param PropelPDO $con an optional connection object
- *
* @return <?php echo $objectClassname ?> The current object (for fluent API support)
*/
public function removeTranslation($culture = '<?php echo $defaultCulture ?>', PropelPDO $con = null)
View
1  templates/objectSetCulture.php
@@ -3,7 +3,6 @@
* Sets the culture for translations
*
* @param string $culture Culture to use for the translation, e.g. 'fr_FR'
- *
* @return <?php echo $objectClassname ?> The current object (for fluent API support)
*/
public function setCulture($culture = '<?php echo $defaultCulture ?>')
View
1  templates/objectSetCultureAlias.php
@@ -4,7 +4,6 @@
* Alias for setCulture(), for BC purpose.
*
* @param string $culture Culture to use for the translation, e.g. 'fr_FR'
- *
* @return <?php echo $objectClassname ?> The current object (for fluent API support)
*/
public function set<?php echo $alias ?>($culture = '<?php echo $defaultCulture ?>')
View
1  templates/objectSetTranslation.php
@@ -4,7 +4,6 @@
*
* @param <?php echo $i18nTablePhpName ?> $translation The translation object
* @param string $culture Culture to use for the translation, e.g. 'fr_FR'
- *
* @return <?php echo $objectClassname ?> The current object (for fluent API support)
*/
public function setTranslation($translation, $culture = '<?php echo $defaultCulture ?>')
View
1  templates/objectSlugGetter.php
@@ -3,7 +3,6 @@
*
* @return string
*/
-
public function getSlug()
{
return $this->getCurrentTranslation()->get<?php echo $slugColumnName?>();
View
2  templates/objectSlugSetter.php
@@ -4,8 +4,6 @@
* @param string
* @return <?php echo $objectClassname ?> The current object (for fluent API support)
*/
-
-
public function setSlug($slug)
{
return $this->getCurrentTranslation()->set<?php echo $slugColumnName?>($slug);
View
2  templates/queryFilterBySlug.php
@@ -4,10 +4,8 @@
* @see filterBy()
*
* @param string $slug The value to use as filter.
-*
* @return <?php echo $queryClass ?> The current query, for fluid interface
*/
-
public function filterBySlug($slug, $culture = '<?php echo $defaultCulture ?>')
{
return $this
View
1  templates/queryFindOneBySlug.php
@@ -7,7 +7,6 @@
*
* @return <?php echo $objectClassname?> the result, formatted by the current formatter
*/
-
public function findOneBySlug($slug, $culture = '<?php echo $defaultCulture ?>', $con = null)
{
return $this
Please sign in to comment.
Something went wrong with that request. Please try again.