protected function _fetchRecordsInDefaultLanguage(Garp_Model_Db $model) { $i18nColumns = array_filter($model->getConfiguration('fields'), function ($col) { return $col['multilingual']; }); $i18nColumns = array_map(function ($col) { return $col['name']; }, $i18nColumns); $i18nModel = $model->getObserver('Translatable')->getI18nModel($model); $foreignKeyColumns = $this->_getForeignKeyColumns($i18nModel, $model); return $i18nModel->fetchAll($i18nModel->select()->from($i18nModel->getName(), array_merge($i18nColumns, $foreignKeyColumns))->where('lang = ?', Garp_I18n::getDefaultLocale())); }
/** * Bind all HABTM related models so they, too, get exported * * @param Garp_Model_Db $model * @return void */ protected function _bindModels(Garp_Model_Db $model) { // Add HABTM related records $relations = $model->getConfiguration('relations'); foreach ($relations as $key => $config) { if ($config['type'] !== 'hasAndBelongsToMany' && $config['type'] !== 'hasMany') { continue; } $otherModelName = 'Model_' . $config['model']; $otherModel = new $otherModelName(); $multilingual = false; $modelFactory = new Garp_I18n_ModelFactory(); if ($otherModel->getObserver('Translatable')) { $otherModel = $modelFactory->getModel($otherModel); $multilingual = true; } $otherModelAlias = $otherModel->getName(); $bindingModel = null; if ($config['type'] === 'hasAndBelongsToMany') { $bindingModelName = 'Model_' . $config['bindingModel']; $bindingModel = new $bindingModelName(); if ($multilingual) { $refmapLocaliser = new Garp_Model_ReferenceMapLocalizer($bindingModel); $refmapLocaliser->populate($otherModelName); } $otherModelAlias = 'm'; } $labelFields = $otherModel->getListFields(); $prefixedLabelFields = array(); foreach ($labelFields as $labelField) { $prefixedLabelFields[] = "{$otherModelAlias}.{$labelField}"; } $labelFields = 'CONCAT_WS(", ", ' . implode(', ', $prefixedLabelFields) . ')'; // If the Translatable behavior would be effective, // the output would be in a localized array, which is overkill for this // purpose. $otherModel->unregisterObserver('Translatable'); $options = array('bindingModel' => $bindingModel, 'modelClass' => $otherModel, 'conditions' => $otherModel->select()->from(array($otherModelAlias => $otherModel->getName()), array($config['label'] => $labelFields))->order("{$otherModelAlias}.id")); $model->bindModel($config['label'], $options); } }