/**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     if (!$this->model instanceof FieldMaintenanceModel) {
         $this->model = $this->trackEngine->getFieldsMaintenanceModel(false, 'index');
     }
     return $this->model;
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $filter = $this->getSearchFilter($action !== 'export');
     // Return empty model when no track sel;ected
     if (!(isset($filter['gtf_id_track']) && $filter['gtf_id_track'])) {
         $model = new \Gems_Model_JoinModel('trackfields', 'gems__track_fields');
         $model->set('gtf_field_name', 'label', $this->_('Name'));
         $model->setFilter(array('1=0'));
         $this->autofilterParameters['onEmpty'] = $this->_('No track selected...');
         return $model;
     }
     $this->trackId = $filter['gtf_id_track'];
     $tracker = $this->loader->getTracker();
     $this->engine = $tracker->getTrackEngine($this->trackId);
     $orgs = $this->currentUser->getRespondentOrgFilter();
     $this->orgWhere = " AND gr2t_id_organization IN (" . implode(", ", $orgs) . ")";
     $sql = "SELECT COUNT(*)\n            FROM gems__respondent2track INNER JOIN gems__reception_codes ON gr2t_reception_code = grc_id_reception_code\n            WHERE gr2t_id_track = ? AND grc_success = 1" . $this->orgWhere;
     $this->trackCount = $this->db->fetchOne($sql, $this->trackId);
     $model = $this->engine->getFieldsMaintenanceModel();
     //$model->setFilter($filter);
     // $model->addColumn(new \Zend_Db_Expr($trackCount), 'trackcount');
     // $model->addColumn(new \Zend_Db_Expr("(SELECT COUNT())"), 'fillcount');
     $model->set('trackcount', 'label', $this->_('Tracks'));
     $model->setOnLoad('trackcount', $this->trackCount);
     $model->set('fillcount', 'label', $this->_('Filled'));
     $model->setOnLoad('fillcount', array($this, 'fillCount'));
     $model->set('emptycount', 'label', $this->_('Empty'));
     $model->setOnLoad('emptycount', array($this, 'emptyCount'));
     $model->set('valuecount', 'label', $this->_('Unique values'));
     $model->setOnLoad('valuecount', array($this, 'valueCount'));
     return $model;
 }