protected function _extractContentTypeBindOptions($chapterType, $model) { if (is_string($chapterType)) { return array('modelClass' => 'Model_' . $chapterType); } $out = array(); if (isset($chapterType['i18n']) && $chapterType['i18n']) { if (!isset($chapterType['model'])) { throw new Exception('Required key "model" not found'); } if (Zend_Registry::isRegistered('CMS') && Zend_Registry::get('CMS')) { return array('modelClass' => 'Model_' . $chapterType['model']); } $out['modelClass'] = instance(new Garp_I18n_ModelFactory())->getModel($chapterType['model']); // Make sure the localised relation exists in the referenceMap $localiser = new Garp_Model_ReferenceMapLocalizer($model); $localiser->populate('Model_' . $chapterType['model']); } return $out; }
/** * 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); } }