Permalink
Browse files

removed unnessecary code from i18n

  • Loading branch information...
1 parent ccc7008 commit a08862c4ee27b389ed20fa13e58b358918ffeb6b @mpscholten committed Oct 5, 2013
@@ -44,14 +44,6 @@ public function postDelete($builder)
}
}
- public function objectAttributes($builder)
- {
- return $this->behavior->renderTemplate('objectAttributes', array(
- 'defaultLocale' => $this->behavior->getDefaultLocale(),
- 'objectClassName' => $builder->getClassNameFromBuilder($builder->getNewStubObjectBuilder($this->behavior->getI18nTable())),
- ));
- }
-
public function objectClearReferences($builder)
{
return $this->behavior->renderTemplate('objectClearReferences', array(
@@ -61,151 +53,6 @@ public function objectClearReferences($builder)
public function objectMethods($builder)
{
- $this->builder = $builder;
-
- $script = '';
- $script .= $this->addSetLocale();
- $script .= $this->addGetLocale();
-
- if ($alias = $this->behavior->getParameter('locale_alias')) {
- $script .= $this->addGetLocaleAlias($alias);
- $script .= $this->addSetLocaleAlias($alias);
- }
-
- $script .= $this->addGetTranslation();
- $script .= $this->addRemoveTranslation();
- $script .= $this->addGetCurrentTranslation();
-
- foreach ($this->behavior->getI18nColumns() as $column) {
- $script .= $this->addTranslatedColumnGetter($column);
- $script .= $this->addTranslatedColumnSetter($column);
- }
-
- return $script;
- }
-
- protected function addSetLocale()
- {
- return $this->behavior->renderTemplate('objectSetLocale', array(
- 'objectClassName' => $this->builder->getClassNameFromBuilder($this->builder->getStubObjectBuilder($this->table)),
- 'defaultLocale' => $this->behavior->getDefaultLocale(),
- 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName(),
- ));
- }
-
- protected function addGetLocale()
- {
- return $this->behavior->renderTemplate('objectGetLocale', array(
- 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName(),
- ));
- }
-
- protected function addSetLocaleAlias($alias)
- {
- return $this->behavior->renderTemplate('objectSetLocaleAlias', array(
- 'objectClassName' => $this->builder->getClassNameFromBuilder($this->builder->getStubObjectBuilder($this->table)),
- 'defaultLocale' => $this->behavior->getDefaultLocale(),
- 'alias' => ucfirst($alias),
- ));
- }
-
- protected function addGetLocaleAlias($alias)
- {
- return $this->behavior->renderTemplate('objectGetLocaleAlias', array(
- 'alias' => ucfirst($alias),
- ));
- }
-
- protected function addGetTranslation()
- {
- $plural = false;
- $i18nTable = $this->behavior->getI18nTable();
- $fk = $this->behavior->getI18nForeignKey();
-
- return $this->behavior->renderTemplate('objectGetTranslation', array(
- 'i18nTablePhpName' => $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($i18nTable)),
- 'defaultLocale' => $this->behavior->getDefaultLocale(),
- 'i18nListVariable' => $this->builder->getRefFKCollVarName($fk),
- 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName(),
- 'i18nQueryName' => $this->builder->getClassNameFromBuilder($this->builder->getNewStubQueryBuilder($i18nTable)),
- 'i18nSetterMethod' => $this->builder->getRefFKPhpNameAffix($fk, $plural),
- ));
- }
-
- protected function addRemoveTranslation()
- {
- $i18nTable = $this->behavior->getI18nTable();
- $fk = $this->behavior->getI18nForeignKey();
-
- return $this->behavior->renderTemplate('objectRemoveTranslation', array(
- 'objectClassName' => $this->builder->getClassNameFromBuilder($this->builder->getStubObjectBuilder($this->table)),
- 'defaultLocale' => $this->behavior->getDefaultLocale(),
- 'i18nQueryName' => $this->builder->getClassNameFromBuilder($this->builder->getNewStubQueryBuilder($i18nTable)),
- 'i18nCollection' => $this->builder->getRefFKCollVarName($fk),
- 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName(),
- ));
- }
-
- protected function addGetCurrentTranslation()
- {
- return $this->behavior->renderTemplate('objectGetCurrentTranslation', array(
- 'i18nTablePhpName' => $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable())),
- ));
- }
-
- // FIXME: the connection used by getCurrentTranslation in the generated code
- // cannot be specified by the user
- protected function addTranslatedColumnGetter(Column $column)
- {/*
- $objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
- $comment = '';
- $functionStatement = '';
- if ($this->isDateType($column->getType())) {
- $objectBuilder->addTemporalAccessorComment($comment, $column);
- $objectBuilder->addTemporalAccessorOpen($functionStatement, $column);
- } else {
- $objectBuilder->addDefaultAccessorComment($comment, $column);
- $objectBuilder->addDefaultAccessorOpen($functionStatement, $column);
- }
- $comment = preg_replace('/^\t/m', '', $comment);
- $functionStatement = preg_replace('/^\t/m', '', $functionStatement);
- preg_match_all('/\$[a-z]+/i', $functionStatement, $params);
-
- return $this->behavior->renderTemplate('objectTranslatedColumnGetter', array(
- 'comment' => $comment,
- 'functionStatement' => $functionStatement,
- 'columnPhpName' => $column->getPhpName(),
- 'params' => implode(', ', $params[0]),
- ));*/
- }
-
- // FIXME: the connection used by getCurrentTranslation in the generated code
- // cannot be specified by the user
- protected function addTranslatedColumnSetter(Column $column)
- {
- $i18nTablePhpName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable()));
- $tablePhpName = $this->builder->getObjectClassName();
- $objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
- $comment = '';
- $functionStatement = '';
- if ($this->isDateType($column->getType())) {
- $objectBuilder->addTemporalMutatorComment($comment, $column);
- $objectBuilder->addMutatorOpenOpen($functionStatement, $column);
- } else {
- $objectBuilder->addMutatorComment($comment, $column);
- $objectBuilder->addMutatorOpenOpen($functionStatement, $column);
- }
- $comment = preg_replace('/^\t/m', '', $comment);
- $comment = str_replace('@return ' . $i18nTablePhpName, '@return ' . $tablePhpName, $comment);
- $functionStatement = preg_replace('/^\t/m', '', $functionStatement);
- preg_match_all('/\$[a-z]+/i', $functionStatement, $params);
-
- return $this->behavior->renderTemplate('objectTranslatedColumnSetter', array(
- 'comment' => $comment,
- 'functionStatement' => $functionStatement,
- 'columnPhpName' => $column->getPhpName(),
- 'params' => implode(', ', $params[0]),
- ));
}
public function objectFilter(&$script, $builder)
@@ -1,12 +0,0 @@
-
-/**
- * Current locale
- * @var string
- */
-protected $currentLocale = '<?= $defaultLocale ?>';
-
-/**
- * Current translation objects
- * @var array[<?= $objectClassName ?>]
- */
-protected $currentTranslations;
@@ -1,12 +0,0 @@
-
-/**
- * Returns the current translation
- *
- * @param ConnectionInterface $con an optional connection object
- *
- * @return <?= $i18nTablePhpName ?>
- */
-public function getCurrentTranslation(ConnectionInterface $con = null)
-{
- return $this->getTranslation($this->getLocale(), $con);
-}
@@ -1,10 +0,0 @@
-
-/**
- * Gets the locale for translations
- *
- * @return string $locale Locale to use for the translation, e.g. 'fr_FR'
- */
-public function get<?= $localeColumnName ?>()
-{
- return $this->currentLocale;
-}
@@ -1,11 +0,0 @@
-
-/**
- * Gets the locale for translations.
- * Alias for getLocale(), for BC purpose.
- *
- * @return string $locale Locale to use for the translation, e.g. 'fr_FR'
- */
-public function get<?php echo $alias ?>()
-{
- return $this->getLocale();
-}
@@ -1,35 +0,0 @@
-
-/**
- * Returns the current translation for a given locale
- *
- * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
- * @param ConnectionInterface $con an optional connection object
- *
- * @return <?php echo $i18nTablePhpName ?>
- */
-public function getTranslation($locale = '<?php echo $defaultLocale ?>', ConnectionInterface $con = null)
-{
- if (!isset($this->currentTranslations[$locale])) {
- if (null !== $this-><?php echo $i18nListVariable ?>) {
- foreach ($this-><?php echo $i18nListVariable ?> as $translation) {
- if ($translation->get<?php echo $localeColumnName ?>() == $locale) {
- $this->currentTranslations[$locale] = $translation;
-
- return $translation;
- }
- }
- }
- if ($this->isNew()) {
- $translation = new <?php echo $i18nTablePhpName ?>();
- $translation->set<?php echo $localeColumnName ?>($locale);
- } else {
- $translation = <?php echo $i18nQueryName ?>::create()
- ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
- ->findOneOrCreate($con);
- $this->currentTranslations[$locale] = $translation;
- }
- $this->add<?php echo $i18nSetterMethod ?>($translation);
- }
-
- return $this->currentTranslations[$locale];
-}
@@ -1,28 +0,0 @@
-
-/**
- * Remove the translation for a given locale
- *
- * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
- * @param ConnectionInterface $con an optional connection object
- *
- * @return <?php echo $objectClassName ?> The current object (for fluent API support)
- */
-public function removeTranslation($locale = '<?php echo $defaultLocale ?>', ConnectionInterface $con = null)
-{
- if (!$this->isNew()) {
- <?php echo $i18nQueryName ?>::create()
- ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
- ->delete($con);
- }
- if (isset($this->currentTranslations[$locale])) {
- unset($this->currentTranslations[$locale]);
- }
- foreach ($this-><?php echo $i18nCollection ?> as $key => $translation) {
- if ($translation->get<?php echo $localeColumnName ?>() == $locale) {
- unset($this-><?php echo $i18nCollection ?>[$key]);
- break;
- }
- }
-
- return $this;
-}
@@ -1,14 +0,0 @@
-
-/**
- * Sets the locale for translations
- *
- * @param string $locale Locale 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 $localeColumnName ?>($locale = '<?php echo $defaultLocale ?>')
-{
- $this->currentLocale = $locale;
-
- return $this;
-}
@@ -1,13 +0,0 @@
-
-/**
- * Sets the locale for translations.
- * Alias for setLocale(), for BC purpose.
- *
- * @param string $locale Locale 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 ?>($locale = '<?php echo $defaultLocale ?>')
-{
- return $this->setLocale($locale);
-}
@@ -1,6 +0,0 @@
-
-<?php echo $comment ?>
-<?php echo $functionStatement ?>
-
- return $this->getCurrentTranslation()->get<?php echo $columnPhpName ?>(<?php echo $params ?>);
-}
@@ -1,7 +0,0 @@
-
-<?php echo $comment ?>
-<?php echo $functionStatement ?>
- $this->getCurrentTranslation()->set<?php echo $columnPhpName ?>(<?php echo $params ?>);
-
- return $this;
-}

0 comments on commit a08862c

Please sign in to comment.