Mage_Core_Model_Mysql4_Translate_String Class Reference

Inheritance diagram for Mage_Core_Model_Mysql4_Translate_String:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 load (Mage_Core_Model_Abstract $object, $value, $field=null)
 _afterLoad (Mage_Core_Model_Abstract $object)
 deleteTranslate ($string, $locale=null, $storeId=null)
 saveTranslate ($string, $translate, $locale=null, $storeId=null)

Protected Member Functions

 _construct ()
 _getLoadSelect ($field, $value, $object)
 _beforeSave (Mage_Core_Model_Abstract $object)
 _afterSave (Mage_Core_Model_Abstract $object)


Detailed Description

Definition at line 34 of file String.php.


Member Function Documentation

_afterLoad ( Mage_Core_Model_Abstract object  ) 

Perform actions after object load

Parameters:
Varien_Object $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 65 of file String.php.

00066     {
00067         $connection = $this->_getReadAdapter();
00068         $select = $connection->select()
00069             ->from($this->getMainTable(), array('store_id', 'translate'))
00070             ->where('string=:translate_string');
00071         $translations = $connection->fetchPairs($select, array('translate_string' => $object->getString()));
00072         $object->setStoreTranslations($translations);
00073         return parent::_afterLoad($object);
00074     }

_afterSave ( Mage_Core_Model_Abstract object  )  [protected]

Perform actions after object save

Parameters:
Varien_Object $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 88 of file String.php.

00089     {
00090         $connection = $this->_getWriteAdapter();
00091         $select = $connection->select()
00092             ->from($this->getMainTable(), array('store_id', 'key_id'))
00093             ->where('string=?', $object->getString());
00094         $stors = $connection->fetchPairs($select);
00095 
00096         $translations = $object->getStoreTranslations();
00097 
00098         if (is_array($translations)) {
00099             foreach ($translations as $storeId => $translate) {
00100                 $condition = $connection->quoteInto('store_id=? AND ', $storeId) .
00101                     $connection->quoteInto('string=?', $object->getString());
00102 
00103                 if (is_null($translate) || $translate=='') {
00104                     $connection->delete($this->getMainTable(), $condition);
00105                 }
00106                 else {
00107                     $data = array(
00108                        'store_id'  => $storeId,
00109                        'string'    => $object->getString(),
00110                        'translate' =>$translate,
00111                     );
00112 
00113                     if (isset($stors[$storeId])) {
00114                         $connection->update(
00115                            $this->getMainTable(),
00116                            $data,
00117                            $connection->quoteInto('key_id=?', $stors[$storeId]));
00118                     }
00119                     else {
00120                         $connection->insert($this->getMainTable(), $data);
00121                     }
00122                 }
00123             }
00124         }
00125         return parent::_afterSave($object);
00126     }

_beforeSave ( Mage_Core_Model_Abstract object  )  [protected]

Perform actions before object save

Parameters:
Varien_Object $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 76 of file String.php.

00077     {
00078         $connection = $this->_getWriteAdapter();
00079         $select = $connection->select()
00080             ->from($this->getMainTable(), 'key_id')
00081             ->where('string=?', $object->getString())
00082             ->where('store_id=?', 0);
00083 
00084         $object->setId($connection->fetchOne($select));
00085         return parent::_beforeSave($object);
00086     }

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 36 of file String.php.

00037     {
00038         $this->_init('core/translate', 'key_id');
00039     }

_getLoadSelect ( field,
value,
object 
) [protected]

Retrieve select object for load object data

Parameters:
string $field
mixed $value
Returns:
Zend_Db_Select

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 57 of file String.php.

00058     {
00059         $select = parent::_getLoadSelect($field, $value, $object);
00060         $select->where('store_id', 0);
00061         return $select;
00062     }

deleteTranslate ( string,
locale = null,
storeId = null 
)

Delete translates

Parameters:
string $string
string $locale
int|null $storeId
Returns:
Mage_Core_Model_Mysql4_Translate_String

Definition at line 137 of file String.php.

00138     {
00139         if (is_null($locale)) {
00140             $locale = Mage::app()->getLocale()->getLocaleCode();
00141         }
00142 
00143         $where = array(
00144             $this->_getWriteAdapter()->quoteInto('locale=?', $locale),
00145             $this->_getWriteAdapter()->quoteInto('string=?', $string),
00146         );
00147 
00148         if ($storeId === false) {
00149             $where[] = $this->_getWriteAdapter()->quoteInto('store_id>?', 0);
00150         }
00151         elseif (!is_null($storeId)) {
00152             $where[] = $this->_getWriteAdapter()->quoteInto('store_id=?', $storeId);
00153         }
00154 
00155         $this->_getWriteAdapter()->delete($this->getMainTable(), $where);
00156 
00157         return $this;
00158     }

load ( Mage_Core_Model_Abstract object,
value,
field = null 
)

Load an object

Parameters:
Mage_Core_Model_Abstract $object
mixed $value
string $field field to load by (defaults to model id)
Returns:
Mage_Core_Model_Mysql4_Abstract

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 41 of file String.php.

00042     {
00043         if (is_string($value)) {
00044             $select = $this->_getReadAdapter()->select()
00045                 ->from($this->getMainTable())
00046                 ->where($this->getMainTable().'.string=:tr_string');
00047             $result = $this->_getReadAdapter()->fetchRow($select, array('tr_string'=>$value));
00048             $object->setData($result);
00049             $this->_afterLoad($object);
00050             return $result;
00051         }
00052         else {
00053             return parent::load($object, $value, $field);
00054         }
00055     }

saveTranslate ( string,
translate,
locale = null,
storeId = null 
)

Definition at line 160 of file String.php.

00161     {
00162         $write = $this->_getWriteAdapter();
00163         $table = $this->getMainTable();
00164 
00165         if (is_null($locale)) {
00166             $locale = Mage::app()->getLocale()->getLocaleCode();
00167         }
00168 
00169         if (is_null($storeId)) {
00170             $storeId = Mage::app()->getStore()->getId();
00171         }
00172 
00173         $select = $write->select()
00174             ->from($table, array('key_id', 'translate'))
00175             ->where('store_id=?', $storeId)
00176             ->where('locale=?', $locale)
00177             ->where('string=?', $string)
00178         ;
00179         if ($row = $write->fetchRow($select)) {
00180             $original = $string;
00181             if (strpos($original, '::')!==false) {
00182                 list($scope, $original) = explode('::', $original);
00183             }
00184             if ($original == $translate) {
00185                 $write->delete($table, 'key_id='.(int)$row['key_id']);
00186             } elseif ($row['translate']!=$translate) {
00187                 $write->update($table, array('translate'=>$translate), 'key_id='.(int)$row['key_id']);
00188             }
00189         } else {
00190             $write->insert($table, array(
00191                 'store_id'=>$storeId,
00192                 'locale'=>$locale,
00193                 'string'=>$string,
00194                 'translate'=>$translate,
00195             ));
00196         }
00197 
00198         return $this;
00199     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:59 2009 for Magento by  doxygen 1.5.8