Development

/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/record/sfDoctrineRecordI18nFilter.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/record/sfDoctrineRecordI18nFilter.class.php

Revision 14472, 1.8 kB (checked in by Jonathan.Wage, 5 years ago)

[1.2] sfDoctrinePlugin: fixes issue where i18n doesn't fall back to default culture (fixes #5458)

Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Jonathan H. Wage <jonwage@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfDoctrineRecordI18nFilter implements access to the translated properties for
13  * the current culture from the internationalized model.
14  *
15  * @package    symfony
16  * @subpackage doctrine
17  * @author     Jonathan H. Wage <jonwage@gmail.com>
18  * @version    SVN: $Id: sfDoctrineRecordI18nFilter.class.php 11878 2008-09-30 20:14:40Z Jonathan.Wage $
19  */
20 class sfDoctrineRecordI18nFilter extends Doctrine_Record_Filter
21 {
22   public function init()
23   {
24   }
25
26   /**
27    * Implementation of filterSet() to call set on Translation relationship to allow
28    * access to I18n properties from the main object.
29    *
30    * @param Doctrine_Record $record
31    * @param string $name Name of the property
32    * @param string $value Value of the property
33    * @return void
34    */
35   public function filterSet(Doctrine_Record $record, $name, $value)
36   {
37     return $record['Translation'][sfDoctrineRecord::getDefaultCulture()][$name] = $value;
38   }
39
40   /**
41    * Implementation of filterGet() to call get on Translation relationship to allow
42    * access to I18n properties from the main object.
43    *
44    * @param Doctrine_Record $record
45    * @param string $name Name of the property
46    * @param string $value Value of the property
47    * @return void
48    */
49   public function filterGet(Doctrine_Record $record, $name)
50   {
51     $culture = sfDoctrineRecord::getDefaultCulture();
52     if (isset($record['Translation'][$culture]))
53     {
54       return $record['Translation'][$culture][$name];
55     } else {
56       $defaultCulture = sfConfig::get('sf_default_culture');
57       return $record['Translation'][$defaultCulture][$name];
58     }
59   }
60 }
Note: See TracBrowser for help on using the browser.