From 3334b1a01c988da2bc46680c5c2155409ab9350a Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Thu, 17 May 2012 00:43:33 +0200 Subject: [PATCH] CompanyCategory and Ad table name field We can retrieve the name field of these tables using the toString method. They are smart enough and try to return the name field depending on the user's language or rolling back to the default language. Otherwise it returns a nice error message. --- apps/companyfront/config/app.yml | 1 + apps/companyfront/modules/ad/templates/_list.php | 7 ++--- lib/model/doctrine/Ad.class.php | 39 ++++++++++++++++++++++-- lib/model/doctrine/CompanyCategory.class.php | 39 ++++++++++++++++++++++-- 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/apps/companyfront/config/app.yml b/apps/companyfront/config/app.yml index 0e41bc0..3c2b78e 100644 --- a/apps/companyfront/config/app.yml +++ b/apps/companyfront/config/app.yml @@ -5,6 +5,7 @@ all: max_offices_on_pager: 3 max_ads_on_pager: 2 + default_language: eng # Everything must exist at least with this language sf_guard_plugin: remember_key_expiration_age: 2592000 # 30 days in seconds diff --git a/apps/companyfront/modules/ad/templates/_list.php b/apps/companyfront/modules/ad/templates/_list.php index bad7921..5160b2f 100644 --- a/apps/companyfront/modules/ad/templates/_list.php +++ b/apps/companyfront/modules/ad/templates/_list.php @@ -10,16 +10,15 @@ - +   - <?php echo $ad->getAdName() ?> - getCategGeneralFromIdDAOImpl($userLanguageId, $ad->getAd()->getCompanyCategId())->get(0)->company_categ_name?> - + <?php echo $ad->getAdName() ?> + getAd()->getCompanyCategory() ?> getAdName() ?> ', 'ad/delete?id='.$ad->getAd()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?> diff --git a/lib/model/doctrine/Ad.class.php b/lib/model/doctrine/Ad.class.php index 88aa4d1..0b20ca5 100644 --- a/lib/model/doctrine/Ad.class.php +++ b/lib/model/doctrine/Ad.class.php @@ -7,9 +7,44 @@ * * @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 Ad extends BaseAd { + /** + * 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 + $adDescriptions = AdDescriptionTable::getInstance()->findByAdId($this->getId()); + foreach ($adDescriptions as $adDescription) + { + if ($adDescription->getLanguageId() == $languageId) + { + //We found it!!! + return (string) $adDescription->getAdName(); + } + } + + //Otherwise return with the default language + $languageCode = sfConfig::get('app_default_language'); + $languageId = LanguageTable::getInstance()->findByCode($languageCode); + foreach ($adDescriptions as $adDescription) + { + if ($adDescription->getLanguageId() == $languageId) + { + //We found the default language!!! + return (string) $adDescription->getAdName(); + } + } + + //Finally, if nothing was found, return nice error message. + return (string) "Ad without default language"; + } } diff --git a/lib/model/doctrine/CompanyCategory.class.php b/lib/model/doctrine/CompanyCategory.class.php index c165f3c..e64ac0d 100644 --- a/lib/model/doctrine/CompanyCategory.class.php +++ b/lib/model/doctrine/CompanyCategory.class.php @@ -7,9 +7,44 @@ * * @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 CompanyCategory extends BaseCompanyCategory { + /** + * 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 + $categoryDescriptions = CompanyCategoryDescriptionTable::getInstance()->findByCompanyCategId($this->getId()); + foreach ($categoryDescriptions as $categoryDescription) + { + if ($categoryDescription->getLanguageId() == $languageId) + { + //We found it!!! + return (string) $categoryDescription->getCompanyCategName(); + } + } + + //Otherwise return with the default language + $languageCode = sfConfig::get('app_default_language'); + $languageId = LanguageTable::getInstance()->findByCode($languageCode); + foreach ($categoryDescriptions as $categoryDescription) + { + if ($categoryDescription->getLanguageId() == $languageId) + { + //We found the default name description!!! + return (string) $categoryDescription->getCompanyCategName(); + } + } + + //Finally, if nothing was found, return nice error message. + return (string) "Company category without default language"; + } } -- 2.1.4