示例#1
0
 /**
  * Bind all the Chapters and ContentNodes to fetch the complete Article.
  * @param Garp_Model_Db $model
  * @return Void
  */
 public function bindWithChapters(Garp_Model_Db &$model)
 {
     $chapterModel = new Model_Chapter();
     $contentNodeModel = new Model_ContentNode();
     $chapterModel->bindModel('content', array('modelClass' => $contentNodeModel));
     foreach ($this->_config['contentTypes'] as $chapterType) {
         $chapterAlias = $this->_extractContentTypeAlias($chapterType);
         $options = $this->_extractContentTypeBindOptions($chapterType, $contentNodeModel);
         $contentNodeModel->bindModel($chapterAlias, $options);
     }
     $model->bindModel('chapters', array('modelClass' => $chapterModel));
 }
示例#2
0
 /**
  * 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);
     }
 }