From: Gustavo Martin Morcuende Date: Wed, 16 May 2012 22:43:33 +0000 (+0200) Subject: CompanyCategory and Ad table name field X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=3334b1a01c988da2bc46680c5c2155409ab9350a;p=mobi%2F.git 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. --- 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"; + } }