library/Garp/Model/Behavior/Translatable.php
protected function _beforeSave($model, &$data, $where = null) {
        $localizedData = array();
        foreach ($this->_translatableFields as $field) {
            if (array_key_exists($field, $data)) {
                $localizedData[$field] = $data[$field];
                unset($data[$field]);
            }
        }
        // Can't use values that are not arrays
        $localizedData = array_filter($localizedData, 'is_array');

        // We now have an array containing all values that are provided in one or more languages
        $languages = Garp_I18n::getLocales();
        $existingRows = array_fill_keys($languages, array());
        if (!is_null($where)) {
            $pKeys = $this->_getPrimaryKeysOfAffectedRows($model, $where);
            if (!count($pKeys)) {
                // No primary keys found in update?
                // That means there aren't any affected rows and there's nothing for us to do.
                return;
            }
            $existingRows = $this->_fetchLocalizedRows($languages, $model, $pKeys);
        }

        $defaultLanguage = Garp_I18n::getDefaultLocale();
        $languages = array_diff($languages, array($defaultLanguage));
        foreach ($localizedData as $column => $val) {
            foreach ($languages as $language) {
                if (!empty($val[$language])) {
                    // If value provided in language: good!
                    continue;
                }
                if (empty($val[$defaultLanguage])) {
                    // No default? Nothing to fall back to
                    continue;
                }
                if (!$where) {
                    // If insert, just use default value
                    $localizedData[$column][$language] = $val[$defaultLanguage];
                    continue;
                }
                // Else if update, make sure existing row isn't different from default language row
                if (!$this->_translatedVersionHasBeenChanged(
                    $existingRows[$defaultLanguage],
                    $existingRows[$language], $column
                )
                ) {
                    $localizedData[$column][$language] = $val[$defaultLanguage];
                }
            }
        }
        $this->_queue = $localizedData;
    }
protected function _beforeSave($model, &$data, $where = null) {
        $localizedData = array();
        foreach ($this->_translatableFields as $field) {
            if (array_key_exists($field, $data)) {
                $localizedData[$field] = $data[$field];
                unset($data[$field]);
            }
        }
        // Can't use values that are not arrays
        $localizedData = array_filter($localizedData, 'is_array');

        // We now have an array containing all values that are provided in one or more languages
        $languages = Garp_I18n::getLocales();
        $existingRows = array_fill_keys($languages, array());
        if (!is_null($where)) {
            $pKeys = $this->_getPrimaryKeysOfAffectedRows($model, $where);
            if (!count($pKeys)) {
                // No primary keys found in update?
                // That means there aren't any affected rows and there's nothing for us to do.
                return;
            }
            $existingRows = $this->_fetchLocalizedRows($languages, $model, $pKeys);
        }

        $defaultLanguage = Garp_I18n::getDefaultLocale();
        $languages = array_diff($languages, array($defaultLanguage));
        foreach ($localizedData as $column => $val) {
            foreach ($languages as $language) {
                if (!empty($val[$language])) {
                    // If value provided in language: good!
                    continue;
                }
                if (empty($val[$defaultLanguage])) {
                    // No default? Nothing to fall back to
                    continue;
                }
                if (!$where) {
                    // If insert, just use default value
                    $localizedData[$column][$language] = $val[$defaultLanguage];
                    continue;
                }
                // Else if update, make sure existing row isn't different from default language row
                if (!$this->_translatedVersionHasBeenChanged(
                    $existingRows[$defaultLanguage],
                    $existingRows[$language], $column
                )
                ) {
                    $localizedData[$column][$language] = $val[$defaultLanguage];
                }
            }
        }
        $this->_queue = $localizedData;
    }
protected function _beforeSave ( $ model , & $ data , $ where = null ) { $ localizedData = array ( ) ; foreach ( $ this -> _translatableFields as $ field ) { if ( array_key_exists ( $ field , $ data ) ) { $ localizedData [ $ field ] = $ data [ $ field ] ; unset ( $ data [ $ field ] ) ; } } // Can't use values that are not arrays $ localizedData = array_filter ( $ localizedData , 'is_array' ) ; // We now have an array containing all values that are provided in one or more languages $ languages = Garp_I18n :: getLocales ( ) ; $ existingRows = array_fill_keys ( $ languages , array ( ) ) ; if ( ! is_null ( $ where ) ) { $ pKeys = $ this -> _getPrimaryKeysOfAffectedRows ( $ model , $ where ) ; if ( ! count ( $ pKeys ) ) { // No primary keys found in update? // That means there aren't any affected rows and there's nothing for us to do. return ; } $ existingRows = $ this -> _fetchLocalizedRows ( $ languages , $ model , $ pKeys ) ; } $ defaultLanguage = Garp_I18n :: getDefaultLocale ( ) ; $ languages = array_diff ( $ languages , array ( $ defaultLanguage ) ) ; foreach ( $ localizedData as $ column => $ val ) { foreach ( $ languages as $ language ) { if ( ! empty ( $ val [ $ language ] ) ) { // If value provided in language: good! continue ; } if ( empty ( $ val [ $ defaultLanguage ] ) ) { // No default? Nothing to fall back to continue ; } if ( ! $ where ) { // If insert, just use default value $ localizedData [ $ column ] [ $ language ] = $ val [ $ defaultLanguage ] ; continue ; } // Else if update, make sure existing row isn't different from default language row if ( ! $ this -> _translatedVersionHasBeenChanged ( $ existingRows [ $ defaultLanguage ] , $ existingRows [ $ language ] , $ column ) ) { $ localizedData [ $ column ] [ $ language ] = $ val [ $ defaultLanguage ] ; } } } $ this -> _queue = $ localizedData ; }
Callback before inserting or updating.
Extracts translatable fields.

@param Garp_Model_Db $model
@param Array $data The submitted data
@param String $where WHERE clause (in case of update)
@return Void
Callback before inserting or updating . Extracts translatable fields .