From 548240442be41af163ad10d5f1ae7db328551e3a Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 20 May 2012 21:40:01 +0200 Subject: [PATCH] Fixing error in toString method Doctrine Record I was not retrieving the right language id value in the Symfony Doctrine Record object. --- lib/model/doctrine/Ad.class.php | 2 +- lib/model/doctrine/Company.class.php | 40 ++++++++++++++++++++++++++-- lib/model/doctrine/GeneralCategory.class.php | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/model/doctrine/Ad.class.php b/lib/model/doctrine/Ad.class.php index 0b20ca5..8a9351e 100644 --- a/lib/model/doctrine/Ad.class.php +++ b/lib/model/doctrine/Ad.class.php @@ -34,7 +34,7 @@ class Ad extends BaseAd //Otherwise return with the default language $languageCode = sfConfig::get('app_default_language'); - $languageId = LanguageTable::getInstance()->findByCode($languageCode); + $languageId = LanguageTable::getInstance()->findOneByCode($languageCode)->getId(); foreach ($adDescriptions as $adDescription) { if ($adDescription->getLanguageId() == $languageId) diff --git a/lib/model/doctrine/Company.class.php b/lib/model/doctrine/Company.class.php index 21bf5a9..b4a1b27 100644 --- a/lib/model/doctrine/Company.class.php +++ b/lib/model/doctrine/Company.class.php @@ -7,9 +7,45 @@ * * @package mobiads * @subpackage model - * @author Your name here - * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ + * @author Gustavo Martin Morcuende + * @version */ class Company extends BaseCompany { + + /** + * Returns the string representation of this object. + * + * @return string + */ + public function __toString() + { + $languageId = sfContext::getInstance()->getUser()->getGuardUser()->getLanguage()->getId(); + + //Check if there is description with the user's language + $companyDescriptions = CompanyDescriptionTable::getInstance()->findByCompanyId($this->getId()); + foreach ($companyDescriptions as $companyDescription) + { + if ($companyDescription->getLanguageId() == $languageId) + { + //We found it!!! + return (string) $companyDescription->getCompanyName(); + } + } + + //Otherwise return with the default language + $languageCode = sfConfig::get('app_default_language'); + $languageId = LanguageTable::getInstance()->findOneByCode($languageCode)->getId(); + foreach ($companyDescriptions as $companyDescription) + { + if ($companyDescription->getLanguageId() == $languageId) + { + //We found the default name description!!! + return (string) $companyDescription->getCompanyName(); + } + } + + //Finally, if nothing was found, return nice error message. + return (string) "Company without default language"; + } } diff --git a/lib/model/doctrine/GeneralCategory.class.php b/lib/model/doctrine/GeneralCategory.class.php index a96f051..5419fb6 100644 --- a/lib/model/doctrine/GeneralCategory.class.php +++ b/lib/model/doctrine/GeneralCategory.class.php @@ -34,7 +34,7 @@ class GeneralCategory extends BaseGeneralCategory //Otherwise return with the default language $languageCode = sfConfig::get('app_default_language'); - $languageId = LanguageTable::getInstance()->findByCode($languageCode); + $languageId = LanguageTable::getInstance()->findOneByCode($languageCode)->getId(); foreach ($generalCategoryDescriptions as $generalCategoryDescription) { if ($generalCategoryDescription->getLanguageId() == $languageId) -- 2.1.4