From: Gustavo Martin Morcuende Date: Sun, 20 May 2012 19:40:01 +0000 (+0200) Subject: Fixing error in toString method Doctrine Record X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=548240442be41af163ad10d5f1ae7db328551e3a;p=mobi%2F.git Fixing error in toString method Doctrine Record I was not retrieving the right language id value in the Symfony Doctrine Record object. --- 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)