1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Core
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Translation resource model
30: *
31: * @category Mage
32: * @package Mage_Core
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Core_Model_Resource_Translate extends Mage_Core_Model_Resource_Db_Abstract
36: {
37: /**
38: * Define main table
39: *
40: */
41: protected function _construct()
42: {
43: $this->_init('core/translate', 'key_id');
44: }
45:
46: /**
47: * Retrieve translation array for store / locale code
48: *
49: * @param int $storeId
50: * @param string|Zend_Locale $locale
51: * @return array
52: */
53: public function getTranslationArray($storeId = null, $locale = null)
54: {
55: if (!Mage::isInstalled()) {
56: return array();
57: }
58:
59: if (is_null($storeId)) {
60: $storeId = Mage::app()->getStore()->getId();
61: }
62:
63: $adapter = $this->_getReadAdapter();
64: if (!$adapter) {
65: return array();
66: }
67:
68: $select = $adapter->select()
69: ->from($this->getMainTable(), array('string', 'translate'))
70: ->where('store_id IN (0 , :store_id)')
71: ->where('locale = :locale')
72: ->order('store_id');
73:
74: $bind = array(
75: ':locale' => (string)$locale,
76: ':store_id' => $storeId
77: );
78:
79: return $adapter->fetchPairs($select, $bind);
80:
81: }
82:
83: /**
84: * Retrieve translations array by strings
85: *
86: * @param array $strings
87: * @param int_type $storeId
88: * @return array
89: */
90: public function getTranslationArrayByStrings(array $strings, $storeId = null)
91: {
92: if (!Mage::isInstalled()) {
93: return array();
94: }
95:
96: if (is_null($storeId)) {
97: $storeId = Mage::app()->getStore()->getId();
98: }
99:
100: $adapter = $this->_getReadAdapter();
101: if (!$adapter) {
102: return array();
103: }
104:
105: if (empty($strings)) {
106: return array();
107: }
108:
109: $bind = array(
110: ':store_id' => $storeId
111: );
112: $select = $adapter->select()
113: ->from($this->getMainTable(), array('string', 'translate'))
114: ->where('string IN (?)', $strings)
115: ->where('store_id = :store_id');
116:
117: return $adapter->fetchPairs($select, $bind);
118: }
119:
120: /**
121: * Retrieve table checksum
122: *
123: * @return int
124: */
125: public function getMainChecksum()
126: {
127: return $this->getChecksum($this->getMainTable());
128: }
129: }
130: