/**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  */
 public function execute($trackId = null, $fieldKey = null)
 {
     $batch = $this->getBatch();
     $engine = $this->loader->getTracker()->getTrackEngine($trackId);
     $fields = $engine->getFieldsDefinition();
     $model = $fields->getMaintenanceModel();
     $filter = FieldsDefinition::splitKey($fieldKey);
     $filter['gtf_id_track'] = $trackId;
     $data = $model->loadFirst($filter);
     // \MUtil_Echo::track($fieldKey, $data);
     if ($data) {
         unset($data['sub'], $data['gtf_id_field'], $data['gtf_id_track'], $data['gtf_filter_id'], $data['gtf_changed'], $data['gtf_changed_by'], $data['gtf_created'], $data['gtf_created_by'], $data['calculation'], $data['htmlUse'], $data['htmlCalc']);
         if (isset($data['gtf_calculate_using']) && $data['gtf_calculate_using']) {
             $calcs = explode(FieldAbstract::FIELD_SEP, $data['gtf_calculate_using']);
             foreach ($calcs as &$key) {
                 $key = $this->translateFieldCode($fields, $key);
             }
             $data['gtf_calculate_using'] = implode(FieldAbstract::FIELD_SEP, $calcs);
         }
         $count = $batch->addToCounter('fields_exported');
         if ($count == 1) {
             $this->exportTypeHeader('fields');
         }
         // The number and order of fields can change per field and installation
         $this->exportFieldHeaders($data);
         $this->exportFieldData($data);
         $this->exportFlush();
         $batch->setMessage('fields_export', sprintf($this->plural('%d field exported', '%d fields exported', $count), $count));
     }
 }
 /**
  * Overrule to implement snippet specific filtering and sorting.
  *
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
 {
     parent::processFilterAndSort($model);
     $appId = $this->request->getParam(\Gems_Model::APPOINTMENT_ID);
     if ($appId) {
         $appKeyPrefix = $this->db->quote(FieldsDefinition::makeKey(FieldMaintenanceModel::APPOINTMENTS_NAME, ''));
         $appSource = $this->db->quote(\Gems_Tracker_Engine_StepEngineAbstract::APPOINTMENT_TABLE);
         $or[] = $this->db->quoteInto("gro_valid_after_source = {$appSource} AND\n                        (gto_id_respondent_track, gro_valid_after_field) IN\n                            (SELECT gr2t2a_id_respondent_track, CONCAT({$appKeyPrefix}, gr2t2a_id_app_field)\n                                FROM gems__respondent2track2appointment\n                                WHERE gr2t2a_id_appointment = ?)", $appId);
         $or[] = $this->db->quoteInto("gro_valid_for_source = {$appSource} AND\n                        (gto_id_respondent_track, gro_valid_for_field) IN\n                            (SELECT gr2t2a_id_respondent_track, CONCAT({$appKeyPrefix}, gr2t2a_id_app_field)\n                                FROM gems__respondent2track2appointment\n                                WHERE gr2t2a_id_appointment = ?)", $appId);
     }
     $model->addFilter(array('(' . implode(') OR (', $or) . ')'));
 }
 /**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  *
  * @param array $trackData Nested array of trackdata
  */
 public function execute($lineNr = null, $fieldData = null)
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     if (!(isset($import['trackId']) && $import['trackId'])) {
         // Do nothing
         return;
     }
     $tracker = $this->loader->getTracker();
     $trackEngine = $tracker->getTrackEngine($import['trackId']);
     $fieldModel = $trackEngine->getFieldsMaintenanceModel(true, 'create');
     $fieldData['gtf_id_track'] = $import['trackId'];
     $fieldData = $fieldModel->save($fieldData);
     // Store the field reference
     $import['fieldCodes']['{f' . $fieldData['gtf_id_order'] . '}'] = FieldsDefinition::makeKey($fieldData['sub'], $fieldData['gtf_id_field']);
     if (isset($fieldData['gtf_calculate_using']) && $fieldData['gtf_calculate_using']) {
         $batch->addTask('Tracker\\Import\\UpdateFieldCalculationTask', $lineNr, $fieldData['gtf_id_field'], $fieldModel->getModelNameForRow($fieldData), $fieldData['gtf_calculate_using']);
     }
 }
 /**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  */
 public function execute($trackId = null, $roundId = null)
 {
     $batch = $this->getBatch();
     $select = $this->db->select();
     $select->from('gems__rounds', array('gro_id_order', 'gro_id_relationfield', 'gro_round_description', 'gro_icon_file', 'gro_changed_event', 'gro_display_event', 'gro_valid_after_source', 'gro_valid_after_field', 'gro_valid_after_unit', 'gro_valid_after_length', 'gro_valid_for_source', 'gro_valid_for_field', 'gro_valid_for_unit', 'gro_valid_for_length', 'gro_organizations', 'gro_code'))->joinInner('gems__surveys', 'gro_id_survey = gsu_id_survey', array('survey_export_code' => 'gsu_export_code'))->joinLeft('gems__rounds AS va', 'gems__rounds.gro_valid_after_id = va.gro_id_round', array('valid_after' => 'va.gro_id_order'))->joinLeft('gems__rounds AS vf', 'gems__rounds.gro_valid_for_id = vf.gro_id_round', array('valid_for' => 'vf.gro_id_order'))->where('gems__rounds.gro_id_round = ?', $roundId);
     // \MUtil_Echo::track($select->__toString(), $roundId);
     $data = $this->db->fetchRow($select);
     // \MUtil_Echo::track($data);
     if ($data) {
         $fields = $this->loader->getTracker()->getTrackEngine($trackId)->getFieldsDefinition();
         $tests = array(\Gems_Tracker_Engine_StepEngineAbstract::APPOINTMENT_TABLE, \Gems_Tracker_Engine_StepEngineAbstract::RESPONDENT_TRACK_TABLE);
         if (isset($data['gro_id_relationfield']) && $data['gro_id_relationfield']) {
             // -1 means the respondent itself, also gro_id_relationfield stores a "bare"
             // field id, not one with a table prefix
             if ($data['gro_id_relationfield'] >= 0) {
                 $data['gro_id_relationfield'] = $this->translateFieldCode($fields, FieldsDefinition::makeKey(FieldMaintenanceModel::FIELDS_NAME, $data['gro_id_relationfield']));
             }
         }
         if (isset($data['gro_valid_after_source'], $data['gro_valid_after_field']) && in_array($data['gro_valid_after_source'], $tests)) {
             // Translate field to {order}
             $data['gro_valid_after_field'] = $this->translateFieldCode($fields, $data['gro_valid_after_field']);
         }
         if (isset($data['gro_valid_for_source'], $data['gro_valid_for_field']) && in_array($data['gro_valid_for_source'], $tests)) {
             // Translate field to {order}
             $data['gro_valid_for_field'] = $this->translateFieldCode($fields, $data['gro_valid_for_field']);
         }
         $count = $batch->addToCounter('rounds_exported');
         if ($count == 1) {
             $this->exportTypeHeader('rounds');
             $this->exportFieldHeaders($data);
         }
         $this->exportFieldData($data);
         $this->exportFlush();
         $batch->setMessage('rounds_export', sprintf($this->plural('%d round exported', '%d rounds exported', $count), $count));
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns an array of all field id's for all tracks that have a code id
  *
  * @return array id => code
  */
 public function getAllCodeFields()
 {
     static $fields = false;
     // Using static so it will be refreshed once per request
     if ($fields === false) {
         $fields = array();
         $model = $this->createTrackClass('Model_FieldMaintenanceModel');
         $rows = $model->load(array('gtf_field_code IS NOT NULL'), array('gtf_field_code' => SORT_ASC));
         if ($rows) {
             foreach ($rows as $row) {
                 $key = FieldsDefinition::makeKey($row['sub'], $row['gtf_id_field']);
                 $fields[$key] = $row['gtf_field_code'];
             }
         }
     }
     return $fields;
 }
 /**
  * The field id as it is recognized be the track engine
  *
  * @return string
  */
 public function getFieldId()
 {
     if (isset($this->_data['gtap_id_app_field']) && $this->_data['gtap_id_app_field']) {
         return FieldsDefinition::makeKey(FieldMaintenanceModel::APPOINTMENTS_NAME, $this->_data['gtap_id_app_field']);
     }
 }
 /**
  * Get the calculate from options
  *
  * @param int $trackId
  * @return array
  */
 protected function getOptions($trackId = null)
 {
     if (null === $trackId) {
         $trackId = $this->_trackId;
     }
     $appFields = $this->db->fetchPairs("\n            SELECT gtap_id_app_field, gtap_field_name\n                FROM gems__track_appointments\n                WHERE gtap_id_track = ?\n                ORDER BY gtap_id_order", $trackId);
     $options = array();
     if ($appFields) {
         foreach ($appFields as $id => $label) {
             $key = FieldsDefinition::makeKey(FieldMaintenanceModel::APPOINTMENTS_NAME, $id);
             $options[$key] = $label;
         }
     }
     return $options;
 }
 /**
  * Translate a field code to the field order number
  *
  * @param FieldsDefinition $fields
  * @param string $fieldId
  * @return string {order} or original value
  */
 protected function translateFieldCode(FieldsDefinition $fields, $fieldId)
 {
     $field = $fields->getField($fieldId);
     if ($field instanceof FieldInterface) {
         return '{f' . $field->getOrder() . '}';
     }
     return $fieldId;
 }