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.
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
</thead>
<tfoot>
<tr>
- <td colspan="5" class="rounded-foot-left"><em><?php echo __('Ads List') ?></em></td>
+ <td colspan="4" class="rounded-foot-left"><em><?php echo __('Ads List') ?></em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<?php foreach ($ads as $ad): ?>
<tr>
- <td><img src="<?php echo $ad->getAd()->getAdMobileImageLink() ?>" alt="<?php echo $ad->getAdName() ?>"/></td>
- <td><?php echo CompanyCategoryDescriptionTable::getInstance()->getCategGeneralFromIdDAOImpl($userLanguageId, $ad->getAd()->getCompanyCategId())->get(0)->company_categ_name?></td>
-
+ <td><img src="<?php echo $ad->getAd()->getAdMobileImageLink() ?>" width="80" height="80" alt="<?php echo $ad->getAdName() ?>"/></td>
+ <td><?php echo $ad->getAd()->getCompanyCategory() ?></td>
<td><?php echo $ad->getAdName() ?></td>
<td><a href="<?php echo url_for('ad/edit?id='.$ad->getAd()->getId()) ?>"><img src="/images/pencil_add.png" alt="" title="" border="0" /></a></td>
<td><?php echo link_to('<img src="/images/inadminpanel/images/trash.png" alt="" title="" border="0" />', 'ad/delete?id='.$ad->getAd()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?></td>
*
* @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";
+ }
}
*
* @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";
+ }
}