01.18 php saved
ruxkor
Tags add more
i18n  
Note
modified aftersave function in order to save fields like 'localizedfilename' => 'locale' => 'value'
  1.     function afterSave(&$model, $created) {
  2.         if (!isset($this->runtime[$model->alias]['beforeSave'])) {
  3.             return true;
  4.         }
  5.         $locale = $this->_getLocale($model);
  6.         $tempData = $this->runtime[$model->alias]['beforeSave'];
  7.         unset($this->runtime[$model->alias]['beforeSave']);
  8.         $conditions = array('locale' => $locale, 'model' => $model->alias, 'foreign_key' => $model->id);
  9.         $RuntimeModel =& $this->translateModel($model);
  10.         if (empty($created)) {
  11.             $translations = $RuntimeModel->find('list', array('conditions' => array_merge($conditions, array($RuntimeModel->displayField => array_keys($tempData)))));
  12.             if ($translations) {
  13.                 foreach ($translations as $id => $field) {
  14.                     $RuntimeModel->create();
  15.                     $RuntimeModel->save(array($RuntimeModel->alias => array('id' => $id, 'content' => $tempData[$field])));
  16.                     unset($tempData[$field]);
  17.                 }
  18.             }
  19.         }
  20.        
  21.         if (!empty($tempData)) {
  22.             foreach ($tempData as $field => $value) {
  23.                 if (is_array($value)) {
  24.                     foreach ($value as $loc=>$val) {
  25.                         $tmploc = array('locale'=>$loc);
  26.                         $RuntimeModel->create(array_unique(array_merge($conditions,$tmploc, array($RuntimeModel->displayField => $field, 'content' => $val))));
  27.                         $RuntimeModel->save();
  28.                     }
  29.                 }
  30.                 else {
  31.                     $RuntimeModel->create(array_merge($conditions, array($RuntimeModel->displayField => $field, 'content' => $value)));
  32.                     $RuntimeModel->save();
  33.                 }
  34.             }
  35.         }
  36.     }
Parsed in 0.099 seconds, using GeSHi 1.0.7.14

Modify this Paste