/** * 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 the model * * @return \MUtil_Model_ModelAbstract */ protected function createModel() { if (!$this->model instanceof RoundModel) { $this->model = $this->trackEngine->getRoundModel(false, 'index'); } // Now add the joins so we can sort on the real name // $this->model->addTable('gems__surveys', array('gro_id_survey' => 'gsu_id_survey')); // $this->model->set('gsu_survey_name', $this->model->get('gro_id_survey')); return $this->model; }
/** * * @return \Gems_Task_TaskRunnerBatch */ protected function getImportMergeBatch() { $batch = $this->loader->getTaskRunnerBatch('track_import_create_' . $this->formData['importId']); $import = $this->loadImportData(); $batch->setVariable('import', $import); $batch->setVariable('trackEngine', $this->trackEngine); if ($batch->isFinished()) { return $batch; } if (!$batch->isLoaded()) { $batch->addTask('Tracker\\Merge\\MergeTrackImportTask', $this->formData); $fieldDef = $this->trackEngine->getFieldsDefinition(); foreach ($import['fields'] as $lineNr => &$fieldData) { $field = $fieldDef->getFieldByOrder($fieldData['gtf_id_order']); if ($field instanceof FieldInterface) { $fieldData['gtf_id_field'] = $field->getFieldId(); } $batch->addTask('Tracker\\Import\\CreateTrackFieldImportTask', $lineNr, $fieldData); } foreach ($import['rounds'] as $lineNr => $roundData) { $batch->addTask('Tracker\\Import\\CreateTrackRoundImportTask', $lineNr, $roundData); } if (isset($import['deactivateRounds'])) { foreach ($import['deactivateRounds'] as $roundId => $roundDescription) { $batch->addTask('Tracker\\Merge\\DeactivateTrackFieldTask', $roundId, $roundDescription); } } $batch->addTask('AddTask', 'Tracker\\Import\\FinishTrackImport'); } return $batch; }
/** * * @return \Gems_Tracker_Engine_TrackEngineInterface * @throws \Gems_Exception */ protected function getTrackEngine() { if ($this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) { return $this->trackEngine; } $trackId = $this->_getIdParam(); if (!$trackId) { throw new \Gems_Exception($this->_('Missing track identifier.')); } $menuSource = $this->menu->getParameterSource(); $this->trackEngine = $this->loader->getTracker()->getTrackEngine($trackId); $this->trackEngine->applyToMenuSource($menuSource); $menuSource->setRequestId($trackId); // Tell the menu we're using track id as request id return $this->trackEngine; }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { if ($this->respondent instanceof \Gems_Tracker_Respondent) { if (!$this->patientId) { $this->patientId = $this->respondent->getPatientNumber(); } if (!$this->organizationId) { $this->organizationId = $this->respondent->getOrganizationId(); } } // Try to get $this->respondentTrackId filled if (!$this->respondentTrackId) { if ($this->respondentTrack) { $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId(); } else { $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK); } } // Try to get $this->respondentTrack filled if ($this->respondentTrackId && !$this->respondentTrack) { $this->respondentTrack = $this->loader->getTracker()->getRespondentTrack($this->respondentTrackId); } // Set the user id if (!$this->userId) { $this->userId = $this->loader->getCurrentUser()->getUserId(); } if ($this->respondentTrack) { // We are updating $this->createData = false; // Try to get $this->trackEngine filled if (!$this->trackEngine) { // Set the engine used $this->trackEngine = $this->respondentTrack->getTrackEngine(); } } else { // We are inserting $this->createData = true; $this->saveLabel = $this->_($this->_('Add track')); // Try to get $this->trackId filled if (!$this->trackId) { if ($this->trackEngine) { $this->trackId = $this->trackEngine->getTrackId(); } else { $this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID); } } // Try to get $this->trackEngine filled if ($this->trackId && !$this->trackEngine) { $this->trackEngine = $this->loader->getTracker()->getTrackEngine($this->trackId); } if (!($this->trackEngine && $this->patientId && $this->organizationId && $this->userId)) { throw new \Gems_Exception_Coding('Missing parameter for ' . __CLASS__ . ': could not find data for editing a respondent track nor the track engine, patientId and organizationId needed for creating one.'); } } return parent::hasHtmlOutput(); }
/** * A ModelAbstract->setOnLoad() function that takes care of transforming a * dateformat read from the database to a \Zend_Date format * * If empty or \Zend_Db_Expression (after save) it will return just the value * currently there are no checks for a valid date format. * * @see \MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved * @param string $name The name of the current field * @param array $context Optional, the other values being saved * @param boolean $isPost True when passing on post data * @return \MUtil_Date|\Zend_Db_Expr|string */ public function valueCount($value, $isNew = false, $name = null, array $context = array(), $isPost = false) { $model = $this->engine->getFieldsDataStorageModel(); if (!$model instanceof FieldDataModel) { return null; } $subName = $model->getModelNameForRow($context); $sql = sprintf("SELECT COUNT(DISTINCT %s)\n FROM %s INNER JOIN gems__respondent2track ON %s = gr2t_id_respondent_track\n INNER JOIN gems__reception_codes ON gr2t_reception_code = grc_id_reception_code\n WHERE %s = %s AND %s IS NOT NULL AND gr2t_id_track = %d AND grc_success = 1" . $this->orgWhere, $model->getFieldName('gr2t2f_value', $subName), $model->getTableName($subName), $model->getFieldName('gr2t2f_id_respondent_track', $subName), $model->getFieldName('gr2t2f_id_field', $subName), $context['gtf_id_field'], $model->getFieldName('gr2t2f_value', $subName), $this->trackId); // \MUtil_Echo::track($sql); $value = $this->db->fetchOne($sql); return sprintf($this->_('%d (uses per value: %01.2f)'), $value, $value ? $this->trackFilled / $value : 0); }
/** * Hook containing the actual save code. * * Call's afterSave() for user interaction. * * @see afterSave() */ protected function saveData() { parent::saveData(); if ($this->createData && !$this->roundId) { $this->roundId = $this->formData['gro_id_round']; } if ($this->formData['gro_valid_for_source'] == 'tok' && $this->formData['gro_valid_for_field'] == 'gto_valid_from' && empty($this->formData['gro_valid_for_id'])) { // Special case we should insert the current roundID here $this->formData['gro_valid_for_id'] = $this->roundId; // Now save, don't call saveData again to keep changed message as is $model = $this->getModel(); $this->formData = $model->save($this->formData); } $this->trackEngine->updateRoundCount($this->loader->getCurrentUser()->getUserId()); }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { if (!$this->trackId) { if (isset($this->trackData['gtr_id_track'])) { $this->trackId = $this->trackData['gtr_id_track']; } elseif ($this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) { $this->trackId = $this->trackEngine->getTrackId(); } } if (!$this->trackName) { if (isset($this->trackData['gtr_track_name'])) { $this->trackName = $this->trackData['gtr_track_name']; } elseif ($this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) { $this->trackName = $this->trackEngine->getTrackName(); } } return (bool) $this->trackName && parent::hasHtmlOutput(); }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { if ($this->trackEngine && !$this->trackId) { $this->trackId = $this->trackEngine->getTrackId(); } if ($this->trackId) { // Try to get $this->trackEngine filled if (!$this->trackEngine) { // Set the engine used $this->trackEngine = $this->loader->getTracker()->getTrackEngine($this->trackId); } } else { return false; } if (!$this->roundId) { $this->roundId = $this->request->getParam(\Gems_Model::ROUND_ID); } return $this->roundId && parent::hasHtmlOutput(); }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { if (!$this->multiTracks) { return false; } if (!$this->trackData) { if (!$this->trackId) { if ($this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) { $this->trackId = $this->trackEngine->getTrackId(); } else { return false; } } $trackModel = new \MUtil_Model_TableModel('gems__tracks'); $this->trackData = $trackModel->loadFirst(array('gtr_id_track' => $this->trackId)); } elseif (!$this->trackId) { $this->trackId = $this->trackData['gtr_id_track']; } return parent::hasHtmlOutput(); }
/** * Hook containing the actual save code. * * Call's afterSave() for user interaction. * * @see afterSave() */ protected function saveData() { // feature request #200 if (isset($this->formData['gtr_organizations']) && is_array($this->formData['gtr_organizations'])) { $this->formData['gtr_organizations'] = '|' . implode('|', $this->formData['gtr_organizations']) . '|'; } if ($this->trackEngine) { $this->formData['gtr_survey_rounds'] = $this->trackEngine->calculateRoundCount(); } else { $this->formData['gtr_survey_rounds'] = 0; } parent::saveData(); // Check for creation if ($this->createData) { if (isset($this->formData['gtr_id_track'])) { $this->trackId = $this->formData['gtr_id_track']; } } elseif ($this->trackEngine && isset($this->formData[$this->_oldClassName], $this->formData['gtr_track_class']) && $this->formData[$this->_oldClassName] != $this->formData['gtr_track_class']) { // Track conversion $this->trackEngine->convertTo($this->formData['gtr_track_class']); } }
/** * * @return \Gems_Task_TaskRunnerBatch */ protected function getExportBatch($load = true) { if ($this->_batch) { return $this->_batch; } $this->_batch = $this->loader->getTaskRunnerBatch('track_export_' . $this->trackEngine->getTrackId()); if (!$load || $this->_batch->isFinished()) { return $this->_batch; } if (!$this->_batch->isLoaded()) { $filename = \MUtil_File::createTemporaryIn(GEMS_ROOT_DIR . '/var/tmp/export/track'); $trackId = $this->trackEngine->getTrackId(); $this->_batch->setSessionVariable('filename', $filename); $this->_batch->addTask('Tracker\\Export\\ProjectVersionExportTask'); $this->_batch->addTask('Tracker\\Export\\MainTrackExportTask', $this->trackEngine->getTrackId(), $this->formData['orgs']); if (isset($this->formData['fields']) && is_array($this->formData['fields'])) { // \MUtil_Echo::track($this->formData['fields']); foreach ($this->formData['fields'] as $fieldId) { $this->_batch->addTask('Tracker\\Export\\TrackFieldExportTask', $trackId, $fieldId); } } $model = $this->getModel(); foreach ($model->getCol('surveyId') as $surveyId) { $this->_batch->addTask('Tracker\\Export\\TrackSurveyExportTask', $trackId, $surveyId); } if (isset($this->formData['rounds']) && is_array($this->formData['rounds'])) { foreach ($this->formData['rounds'] as $roundId) { $this->_batch->addTask('Tracker\\Export\\TrackRoundExportTask', $trackId, $roundId); } } } else { $filename = $this->_batch->getSessionVariable('filename'); } $this->_batch->setVariable('file', fopen($filename, 'a')); return $this->_batch; }
/** * Set those settings needed for the detailed display * * @param \Gems_Tracker_Engine_TrackEngineInterface $trackEngine * @param boolean $edit When true the fields are added in edit mode * @return \Gems_Model_RespondentTrackModel */ public function applyDetailSettings(\Gems_Tracker_Engine_TrackEngineInterface $trackEngine, $edit = false) { $this->resetOrder(); $translated = $this->util->getTranslated(); $formatDate = $this->util->getTranslated()->formatDate; $this->set('gr2o_patient_nr', 'label', $this->_('Respondent number')); $this->set('respondent_name', 'label', $this->_('Respondent name')); $this->set('gtr_track_name', 'label', $this->_('Track')); $this->set('gr2t_mailable', 'label', $this->_('May be mailed'), 'elementClass', 'radio', 'separator', ' ', 'multiOptions', array('1' => $this->_('Yes'), '0' => $this->_('No'))); $this->set('assigned_by', 'label', $this->_('Assigned by')); $this->set('gr2t_start_date', 'label', $this->_('Start'), 'dateFormat', 'dd-MM-yyyy', 'formatFunction', $formatDate); // Integrate fields $trackEngine->addFieldsToModel($this, $edit); $this->set('gr2t_end_date_manual', 'label', $this->_('Set ending on'), 'description', $this->_('Manually set dates are fixed an will never be (re)calculated.'), 'elementClass', 'Radio', 'multiOptions', $translated->getDateCalculationOptions(), 'separator', ' '); $this->set('gr2t_end_date', 'label', $this->_('Ending on'), 'dateFormat', 'dd-MM-yyyy', 'formatFunction', $formatDate); $this->set('gr2t_track_info', 'label', $this->_('Description')); $this->set('gr2t_comment', 'label', $this->_('Comment')); return $this; }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { // Try to set $this->respondentTrackId, it can be ok when not set if (!$this->respondentTrackId) { if ($this->respondentTrack) { $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId(); } else { $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK); } } // First attempt at trackId if (!$this->trackId && $this->trackEngine) { $this->trackId = $this->trackEngine->getTrackId(); } // Check if a sufficient set of data is there if (!($this->trackId || $this->patientId || $this->organizationId)) { // Now we really need $this->respondentTrack if (!$this->respondentTrack) { if ($this->respondentTrackId) { $this->respondentTrack = $this->loader->getTracker()->getRespondentTrack($this->respondentTrackId); } else { // Parameters not valid return false; } } } if (!$this->trackId) { $this->trackId = $this->respondentTrack->getTrackId(); } if (!$this->patientId) { $this->patientId = $this->respondentTrack->getPatientNumber(); } if (!$this->organizationId) { $this->organizationId = $this->respondentTrack->getOrganizationId(); } // \MUtil_Echo::track($this->trackId, $this->patientId, $this->organizationId, $this->respondentTrackId); return $this->getModel()->loadFirst() && parent::hasHtmlOutput(); }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { if (!$this->multiTracks) { return false; } $this->tracker = $this->loader->getTracker(); if (!$this->respondentTrackId) { $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK); } if ($this->respondentTrackId) { if (!$this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) { $this->respondentTrack = $this->tracker->getRespondentTrack($this->respondentTrackId); } } if ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) { if (!$this->respondentTrackId) { $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId(); } $this->trackId = $this->respondentTrack->getTrackId(); if (!$this->respondentId) { $this->respondentId = $this->respondentTrack->getRespondentId(); } if (!$this->organizationId) { $this->organizationId = $this->respondentTrack->getOrganizationId(); } $this->caption = $this->_('Other assignments of this track to this respondent.'); $this->onEmpty = $this->_('This track is assigned only once to this respondent.'); } else { if ($this->respondent instanceof \Gems_Tracker_Respondent) { if (!$this->respondentId) { $this->respondentId = $this->respondent->getId(); } if (!$this->organizationId) { $this->organizationId = $this->respondent->getOrganizationId(); } } $this->caption = $this->_('Existing assignments of this track to this respondent.'); $this->onEmpty = $this->_('This track is not assigned to this respondent.'); } if (!$this->trackId) { $this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID); } if (!$this->trackId && $this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) { $this->trackId = $this->trackEngine->getTrackId(); } return $this->trackId && $this->respondentId && $this->organizationId && parent::hasHtmlOutput(); }
/** * Processes the field values and returns the new complete field data * * @param array $newFieldData The new field values, may be partial, field set by code overwrite field set by key * @param array $oldFieldData The old field values * @param \Gems_Tracker_Engine_TrackEngineInterface $trackEngine * @return array The processed data in the format key1 => val1, code1 => val1, key2 => val2 */ protected function _mergeFieldValues(array $newFieldData, array $oldFieldData, \Gems_Tracker_Engine_TrackEngineInterface $trackEngine) { $fieldMap = $trackEngine->getFieldsDefinition()->getFieldCodes(); $output = array(); foreach ($fieldMap as $key => $code) { if ($code) { if (isset($newFieldData[$code])) { $output[$key] = $newFieldData[$code]; $output[$code] = $newFieldData[$code]; } elseif (isset($newFieldData[$key])) { $output[$key] = $newFieldData[$key]; $output[$code] = $newFieldData[$key]; } elseif (isset($oldFieldData[$code])) { $output[$key] = $oldFieldData[$code]; $output[$code] = $oldFieldData[$code]; } elseif (isset($oldFieldData[$key])) { $output[$key] = $oldFieldData[$key]; $output[$code] = $oldFieldData[$key]; } else { $output[$key] = null; $output[$code] = null; } } else { if (isset($newFieldData[$key])) { $output[$key] = $newFieldData[$key]; } elseif (isset($oldFieldData[$key])) { $output[$key] = $oldFieldData[$key]; } else { $output[$key] = null; } } } return $output; }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { // Apply translations if (!$this->showAnswersTranslated) { // Here, not in e.g. __construct as these vars may be set during initiation $this->showAnswersNone = $this->_($this->showAnswersNone); $this->showAnswersRemoved = $this->_($this->showAnswersRemoved); $this->showAnswersSeparator = $this->_($this->showAnswersSeparator); $this->showAnswersTranslated = true; } // Overrule any setting of these values from source $this->data = null; $this->repeater = null; if (!$this->surveyId) { if ($this->token instanceof \Gems_Tracker_Token && $this->token->exists) { $this->surveyId = $this->token->getSurveyId(); } elseif ($this->trackData && !$this->trackId) { // Look up key values from trackData if (isset($this->trackData['gsu_id_survey'])) { $this->surveyId = $this->trackData['gsu_id_survey']; } elseif (isset($this->trackData['gro_id_survey'])) { $this->surveyId = $this->trackData['gro_id_survey']; } elseif (!$this->trackId) { if (isset($this->trackData['gtr_id_track'])) { $this->trackId = $this->trackData['gtr_id_track']; } elseif (isset($this->trackData['gro_id_track'])) { $this->trackId = $this->trackData['gro_id_track']; } } } if (!$this->trackId && $this->trackEngine) { $this->trackId = $this->trackEngine->getTrackId(); } if ($this->trackId && !$this->surveyId) { // Use the track ID to get the id of the first active survey $this->surveyId = $this->db->fetchOne('SELECT gro_id_survey FROM gems__rounds WHERE gro_active = 1 AND gro_id_track = ? ORDER BY gro_id_order', $this->trackId); } } // \MUtil_Echo::track($this->surveyId, $this->trackId); // Get the survey if ($this->surveyId && !$this->survey instanceof \Gems_Tracker_Survey) { $this->survey = $this->loader->getTracker()->getSurvey($this->surveyId); } // Load the data if ($this->survey instanceof \Gems_Tracker_Survey && $this->survey->exists) { $this->data = \MUtil_Ra::addKey($this->survey->getQuestionInformation($this->locale->getLanguage()), 'key'); //\MUtil_Echo::track($this->data); } return parent::hasHtmlOutput(); }
/** * Called after the check that all required registry values * have been set correctly has run. * * @return void */ public function afterRegistry() { parent::afterRegistry(); $this->contentTitle = sprintf($this->_('Rounds in %s track'), $this->trackEngine->getTrackName()); }