1: <?php
2: /**
3: * PHP version 5
4: * @package generalDriver
5: * @author Christian Schiffler <c.schiffler@cyberspectrum.de>
6: * @author Stefan Heimes <stefan_heimes@hotmail.com>
7: * @author Tristan Lins <tristan.lins@bit3.de>
8: * @copyright The MetaModels team.
9: * @license LGPL.
10: * @filesource
11: */
12:
13: namespace DcGeneral\Data;
14:
15: /**
16: * Class MultiLanguageDataProvider.
17: * Implementation of a multi language Contao database data provider.
18: *
19: * The default language will be initialized to "en".
20: *
21: * @package DcGeneral\Data
22: */
23: class MultiLanguageDataProvider extends DefaultDataProvider implements MultiLanguageDataProviderInterface
24: {
25: /**
26: * Buffer to keep the current active working language.
27: *
28: * @var string
29: */
30: protected $strCurrentLanguage;
31:
32: /**
33: * Constructor - initializes the object with English as working language.
34: */
35: public function __construct()
36: {
37: $this->setCurrentLanguage('en');
38:
39: parent::__construct();
40: }
41:
42: /**
43: * Get all available languages of a certain record.
44: *
45: * @param mixed $mixID The ID of the record to retrieve.
46: *
47: * @return LanguageInformationCollectionInterface
48: */
49: public function getLanguages($mixID)
50: {
51: $collection = new DefaultLanguageInformationCollection();
52:
53: // FIXME: hardcoded languages "German" and "English".
54: $collection
55: ->add(new DefaultLanguageInformation('de', null))
56: ->add(new DefaultLanguageInformation('en', null));
57:
58: return $collection;
59: }
60:
61: /**
62: * Get the fallback language of a certain record.
63: *
64: * @param mixed $mixID The ID of the record to retrieve.
65: *
66: * @return LanguageInformationInterface
67: */
68: public function getFallbackLanguage($mixID)
69: {
70: // FIXME: hardcoded fallback language "English".
71: return new DefaultLanguageInformation('en', null);
72: }
73:
74: /**
75: * Set the current working language for the whole data provider.
76: *
77: * @param string $strLanguage The new language, use short tag "2 chars like de, fr etc.".
78: *
79: * @return DataProviderInterface
80: */
81: public function setCurrentLanguage($strLanguage)
82: {
83: $this->strCurrentLanguage = $strLanguage;
84:
85: return $this;
86: }
87:
88: /**
89: * Get the current working language.
90: *
91: * @return string Short tag for the current working language like de or fr etc.
92: */
93: public function getCurrentLanguage()
94: {
95: return $this->strCurrentLanguage;
96: }
97: }
98: