/** * * @param string $patientId * @param int|\Gems_User_Organization $organization * @param int $respondentId * @return boolean True when something changed */ public function handleRespondentChanged($patientId, $organization, $respondentId = null) { if ($organization instanceof \Gems_User_Organization) { $org = $organization; $orgId = $organization->getId(); } else { $org = $this->loader->getOrganization($organization); $orgId = $organization; } $changeEventClass = $org->getRespondentChangeEventClass(); if ($changeEventClass) { $event = $this->loader->getEvents()->loadRespondentChangedEvent($changeEventClass); if ($event) { $respondent = $this->loader->getRespondent($patientId, $orgId, $respondentId); if ($event->processChangedRespondent($respondent)) { // If no change was registered yet, do so now if (!$this->getChanged()) { $this->addChanged(); } return true; } } } return false; }
/** * Sets the labels, format functions, etc... * * @param boolean $detailed True when shopwing detailed information * @param boolean $edit When true use edit settings * @return \Gems_Tracker_Model_TrackModel */ public function applyFormatting($detailed = false, $edit = false) { $translated = $this->util->getTranslated(); $translator = $this->getTranslateAdapter(); if ($edit) { $dateFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat'); } else { $dateFormat = $translated->dateFormatString; } $this->resetOrder(); $this->set('gtr_track_name', 'label', $translator->_('Name')); $this->set('gtr_track_class', 'label', $translator->_('Track Engine'), 'multiOptions', $this->tracker->getTrackEngineList($detailed)); $this->set('gtr_survey_rounds', 'label', $translator->_('Surveys')); $this->set('gtr_active', 'label', $translator->_('Active'), 'multiOptions', $translated->getYesNo()); $this->set('gtr_date_start', 'label', $translator->_('From'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDate); $this->set('gtr_date_until', 'label', $translator->_('Use until'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDateForever); $this->setIfExists('gtr_code', 'label', $translator->_('Track code'), 'size', 10, 'description', $translator->_('Optional code name to link the track to program code.')); if ($detailed) { $events = $this->loader->getEvents(); $caList = $events->listTrackCalculationEvents(); if (count($caList) > 1) { $this->setIfExists('gtr_calculation_event', 'label', $translator->_('Before (re)calculation'), 'multiOptions', $caList); } $coList = $events->listTrackCompletionEvents(); if (count($coList) > 1) { $this->setIfExists('gtr_completed_event', 'label', $translator->_('After completion'), 'multiOptions', $coList); } $bfuList = $events->listTrackBeforeFieldUpdateEvents(); if (count($bfuList) > 1) { $this->setIfExists('gtr_beforefieldupdate_event', 'label', $translator->_('Before field update'), 'multiOptions', $bfuList); } $fuList = $events->listTrackFieldUpdateEvents(); if (count($fuList) > 1) { $this->setIfExists('gtr_fieldupdate_event', 'label', $translator->_('After field update'), 'multiOptions', $fuList); } $this->setIfExists('gtr_organizations', 'label', $translator->_('Organizations'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizationsWithRespondents(), 'required', true); $ct = new \MUtil_Model_Type_ConcatenatedRow('|', $translator->_(', ')); $ct->apply($this, 'gtr_organizations'); } if ($edit) { $this->set('toggleOrg', 'elementClass', 'ToggleCheckboxes', 'selectorName', 'gtr_organizations'); $this->set('gtr_track_name', 'minlength', 4, 'size', 30, 'validators[unique]', $this->createUniqueValidator('gtr_track_name')); } return $this; }
/** * 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($lineNr = null, $roundData = null) { $batch = $this->getBatch(); $events = $this->loader->getEvents(); $import = $batch->getVariable('import'); if (isset($roundData['gro_id_order']) && $roundData['gro_id_order']) { $import['roundOrder'][$roundData['gro_id_order']] = false; } else { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('No gro_id_order specified for round at line %d.'), $lineNr)); } if (isset($roundData['survey_export_code']) && $roundData['survey_export_code']) { if (!(isset($import['surveyCodes']) && array_key_exists($roundData['survey_export_code'], $import['surveyCodes']))) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown survey export code "%s" specified for round on line %d.'), $roundData['survey_export_code'], $lineNr)); } } else { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('No survey export code specified for round on line %d.'), $lineNr)); } if (isset($roundData['gro_changed_event']) && $roundData['gro_changed_event']) { try { $events->loadRoundChangedEvent($roundData['gro_changed_event']); } catch (\Gems_Exception_Coding $ex) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown or invalid round changed event "%s" specified on line %d.'), $roundData['gro_changed_event'], $lineNr)); } } if (isset($roundData['gro_display_event']) && $roundData['gro_display_event']) { try { $events->loadSurveyDisplayEvent($roundData['gro_display_event']); } catch (\Gems_Exception_Coding $ex) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown or invalid round display event "%s" specified on line %d.'), $roundData['gro_display_event'], $lineNr)); } } }
/** * Set those settings needed for the browse display * * * @return \Gems_Model_OrganizationModel */ public function applyBrowseSettings() { $dbLookup = $this->util->getDbLookup(); $definitions = $this->loader->getUserLoader()->getAvailableStaffDefinitions(); $localized = $this->util->getLocalized(); $projectName = $this->project->getName(); $yesNo = $this->util->getTranslated()->getYesNo(); $this->resetOrder(); $this->set('gor_name', 'label', $this->_('Name'), 'tab', $this->_('General')); $this->set('gor_location', 'label', $this->_('Location')); $this->set('gor_task', 'label', $this->_('Task'), 'description', sprintf($this->_('Task in %s project'), $projectName)); $this->set('gor_url', 'label', $this->_('Url')); $this->setIfExists('gor_url_base', 'label', $this->_("Default url's"), 'description', sprintf($this->_("Always switch to this organization when %s is accessed from one of these space separated url's. The first is used for mails."), $projectName)); $this->setIfExists('gor_code', 'label', $this->_('Organization code'), 'description', $this->_('Optional code name to link the organization to program code.')); $this->set('gor_provider_id', 'label', $this->_('Healtcare provider id'), 'description', $this->_('An interorganizational id used for import and export.')); $this->setIfExists('gor_active', 'label', $this->_('Active'), 'description', $this->_('Can the organization be used?'), 'multiOptions', $yesNo); $this->set('gor_contact_name', 'label', $this->_('Contact name')); $this->set('gor_contact_email', 'label', $this->_('Contact email')); // Determine order for details, but do not show in browse $this->set('gor_welcome'); $this->set('gor_signature'); $this->set('gor_create_account_template'); $this->set('gor_reset_pass_template'); $this->set('gor_has_login', 'label', $this->_('Login'), 'description', $this->_('Can people login for this organization?'), 'multiOptions', $yesNo); $this->set('gor_add_respondents', 'label', $this->_('Accepting'), 'description', $this->_('Can new respondents be added to the organization?'), 'multiOptions', $yesNo); $this->set('gor_has_respondents', 'label', $this->_('Respondents'), 'description', $this->_('Does the organization have respondents?'), 'multiOptions', $yesNo); $this->set('gor_respondent_group', 'label', $this->_('Respondent group'), 'description', $this->_('Allows respondents to login.'), 'multiOptions', $dbLookup->getAllowedRespondentGroups()); $this->set('gor_accessible_by', 'label', $this->_('Accessible by'), 'description', $this->_('Checked organizations see this organizations respondents.'), 'multiOptions', $dbLookup->getOrganizations()); $tp = new \MUtil_Model_Type_ConcatenatedRow(':', ', '); $tp->apply($this, 'gor_accessible_by'); $this->setIfExists('gor_allowed_ip_ranges'); if ($definitions && count($definitions) > 1) { $this->setIfExists('gor_user_class', 'label', $this->_('User Definition'), 'multiOptions', $definitions); } $this->setIfExists('gor_resp_change_event', 'label', $this->_('Respondent change event'), 'multiOptions', $this->loader->getEvents()->listRespondentChangedEvents()); $this->setIfExists('gor_iso_lang', 'label', $this->_('Language'), 'multiOptions', $localized->getLanguages()); if ($this->_styles) { $this->setIfExists('gor_style', 'label', $this->_('Style'), 'multiOptions', $this->_styles); } return $this; }
/** * 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($tracksData = null) { $batch = $this->getBatch(); switch (count((array) $tracksData)) { case 0: $batch->addToCounter('import_errors'); $batch->addMessage($this->_('No "track" data found in import file.')); break; case 1: $trackData = reset($tracksData); $lineNr = key($tracksData); $defaults = array('gtr_track_name', 'gtr_track_info', 'gtr_code', 'gtr_date_start', 'gtr_date_until'); $events = $this->loader->getEvents(); $import = $batch->getVariable('import'); $tracker = $this->loader->getTracker(); $import['trackData'] = $trackData; foreach ($defaults as $name) { if (isset($trackData[$name])) { $import['formDefaults'][$name] = $trackData[$name]; $import['modelSettings'][$name]['respondentData'] = true; } } if ($batch->hasVariable('trackEngine') && isset($trackData['gtr_track_name'])) { $trackEngine = $batch->getVariable('trackEngine'); if ($trackEngine->getTrackName() == $trackData['gtr_track_name']) { $import['modelSettings']['gtr_track_name']['elementClass'] = 'Exhibitor'; } else { $import['modelSettings']['gtr_track_name']['description'] = sprintf($this->_('Current track name is "%s".'), $trackEngine->getTrackName()); } } if (isset($trackData['gtr_track_class']) && $trackData['gtr_track_class']) { $trackEngines = $tracker->getTrackEngineClasses(); if (!isset($trackEngines[$trackData['gtr_track_class']])) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown track engine "%s" specified on line %d.'), $trackData['gtr_track_class'], $lineNr)); } } else { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('No track engine specified on line %d.'), $lineNr)); } if (isset($trackData['gtr_beforefieldupdate_event']) && $trackData['gtr_beforefieldupdate_event']) { try { $events->loadTrackFieldUpdateEvent($trackData['gtr_beforefieldupdate_event']); } catch (\Gems_Exception_Coding $ex) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown or invalid track field before update event "%s" specified on line %d.'), $trackData['gtr_beforefieldupdate_event'], $lineNr)); } } if (isset($trackData['gtr_calculation_event']) && $trackData['gtr_calculation_event']) { try { $events->loadTrackCalculationEvent($trackData['gtr_calculation_event']); } catch (\Gems_Exception_Coding $ex) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown or invalid track calculation event "%s" specified on line %d.'), $trackData['gtr_calculation_event'], $lineNr)); } } if (isset($trackData['gtr_completed_event']) && $trackData['gtr_completed_event']) { try { $events->loadTrackCompletionEvent($trackData['gtr_completed_event']); } catch (\Gems_Exception_Coding $ex) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown or invalid track completion event "%s" specified on line %d.'), $trackData['gtr_completed_event'], $lineNr)); } } if (isset($trackData['gtr_fieldupdate_event']) && $trackData['gtr_fieldupdate_event']) { try { $events->loadTrackFieldUpdateEvent($trackData['gtr_fieldupdate_event']); } catch (\Gems_Exception_Coding $ex) { $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('Unknown or invalid track field update event "%s" specified on line %d.'), $trackData['gtr_fieldupdate_event'], $lineNr)); } } break; default: $batch->addToCounter('import_errors'); $batch->addMessage(sprintf($this->_('%d sets of "track" data found in import file.'), count($tracksData))); foreach ($tracksData as $lineNr => $trackData) { $batch->addMessage(sprintf($this->_('"track" data found on line %d.'), $lineNr)); } } }
/** * 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 */ protected function createModel($detailed, $action) { $dbLookup = $this->util->getDbLookup(); $survey = null; $translated = $this->util->getTranslated(); $yesNo = $translated->getYesNo(); if ($detailed) { $surveyId = $this->_getIdParam(); if ($surveyId) { $survey = $this->loader->getTracker()->getSurvey($surveyId); } } $model = new \Gems_Model_JoinModel('surveys', 'gems__surveys', 'gus'); $model->addTable('gems__sources', array('gsu_id_source' => 'gso_id_source')); $model->setCreate(false); $model->addColumn("CASE WHEN gsu_survey_pdf IS NULL OR CHAR_LENGTH(gsu_survey_pdf) = 0 THEN 0 ELSE 1 END", 'gsu_has_pdf'); $model->addColumn(sprintf("CASE WHEN (gsu_status IS NULL OR gsu_status = '') THEN '%s' ELSE gsu_status END", $this->_('OK')), 'gsu_status_show', 'gsu_status'); $model->addColumn("CASE WHEN gsu_surveyor_active THEN '' ELSE 'deleted' END", 'row_class'); $model->resetOrder(); $model->set('gsu_survey_name', 'label', $this->_('Name'), 'elementClass', 'Exhibitor'); $model->set('gsu_survey_description', 'label', $this->_('Description'), 'elementClass', 'Exhibitor', 'formatFunction', array(__CLASS__, 'formatDescription')); $model->set('gso_source_name', 'label', $this->_('Source'), 'elementClass', 'Exhibitor'); $model->set('gsu_surveyor_active', 'label', $this->_('Active in source'), 'elementClass', 'Exhibitor', 'multiOptions', $yesNo); $model->set('gsu_status_show', 'label', $this->_('Status in source'), 'elementClass', 'Exhibitor'); $model->set('gsu_active', 'label', sprintf($this->_('Active in %s'), $this->project->getName()), 'elementClass', 'Checkbox', 'multiOptions', $yesNo); $model->set('gsu_id_primary_group', 'label', $this->_('Group'), 'description', $this->_('If empty, survey will never show up!'), 'multiOptions', $dbLookup->getGroups()); if ($detailed) { $model->addDependency('CanEditDependency', 'gsu_surveyor_active', array('gsu_active')); $model->set('gsu_active', 'validators[group]', new \MUtil_Validate_Require($model->get('gsu_active', 'label'), 'gsu_id_primary_group', $model->get('gsu_id_primary_group', 'label'))); } $model->set('gsu_insertable', 'label', $this->_('Insertable'), 'description', $this->_('Can this survey be manually inserted into a track?'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo, 'onclick', 'this.form.submit()'); if ($detailed) { $model->set('gsu_valid_for_length', 'label', $this->_('Add to inserted end date'), 'description', $this->_('Add to the start date to calculate the end date when inserting.'), 'filter', 'Int'); $model->set('gsu_valid_for_unit', 'label', $this->_('Inserted end date unit'), 'description', $this->_('The unit used to calculate the end date when inserting the survey.'), 'multiOptions', $translated->getPeriodUnits()); $model->set('gsu_insert_organizations', 'label', $this->_('Insert organizations'), 'description', $this->_('The organizations where the survey may be inserted.'), 'elementClass', 'MultiCheckbox', 'multiOptions', $dbLookup->getOrganizations(), 'required', true); $ct = new \MUtil_Model_Type_ConcatenatedRow('|', $this->_(', ')); $ct->apply($model, 'gsu_insert_organizations'); // if ('edit' == $action) { // $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector'=>'input[name^=gtr_organizations]')); // $element->setLabel($this->_('Toggle')); // $model->set('toggleOrg', 'elementClass', $element); // } $switches = array(0 => array('gsu_valid_for_length' => array('elementClass' => 'Hidden', 'label' => null), 'gsu_valid_for_unit' => array('elementClass' => 'Hidden', 'label' => null), 'gsu_insert_organizations' => array('elementClass' => 'Hidden', 'label' => null))); $model->addDependency(array('ValueSwitchDependency', $switches), 'gsu_insertable'); } if ($detailed) { $model->set('track_usage', 'label', $this->_('Usage'), 'elementClass', 'Exhibitor', 'noSort', true, 'no_text_search', true); $model->setOnLoad('track_usage', array($this, 'calculateTrackUsage')); $model->set('calc_duration', 'label', $this->_('Duration calculated'), 'elementClass', 'Html'); $model->setOnLoad('calc_duration', array($this, 'calculateDuration')); $model->set('gsu_duration', 'label', $this->_('Duration description'), 'description', $this->_('Text to inform the respondent, e.g. "20 seconds" or "1 minute".')); if ($survey instanceof \Gems_Tracker_Survey) { $surveyFields = $this->util->getTranslated()->getEmptyDropdownArray() + $survey->getQuestionList($this->locale->getLanguage()); $model->set('gsu_result_field', 'label', $this->_('Result field'), 'multiOptions', $surveyFields); // $model->set('gsu_agenda_result', 'label', $this->_('Agenda field')); } } else { $model->set('track_count', 'label', ' ', 'elementClass', 'Exhibitor', 'noSort', true, 'no_text_search', true); $model->setOnLoad('track_count', array($this, 'calculateTrackCount')); } $model->set('gsu_code', 'label', $this->_('Survey code'), 'description', $this->_('Optional code name to link the survey to program code.'), 'size', 10); $model->set('gsu_export_code', 'label', $this->_('Survey export code'), 'description', $this->_('A unique code indentifying this survey during track import'), 'size', 20); if ($detailed) { $events = $this->loader->getEvents(); $beforeOptions = $events->listSurveyBeforeAnsweringEvents(); if (count($beforeOptions) > 1) { $model->set('gsu_beforeanswering_event', 'label', $this->_('Before answering'), 'multiOptions', $beforeOptions, 'elementClass', 'Select'); } $completedOptions = $events->listSurveyCompletionEvents(); if (count($completedOptions) > 1) { $model->set('gsu_completed_event', 'label', $this->_('After completion'), 'multiOptions', $completedOptions, 'elementClass', 'Select'); } $displayOptions = $events->listSurveyDisplayEvents(); if (count($displayOptions) > 1) { $model->set('gsu_display_event', 'label', $this->_('Answer display'), 'multiOptions', $displayOptions, 'elementClass', 'Select'); } if ('show' !== $action || $survey->hasPdf()) { // Only the action changes from the current page // and the right to see the pdf is the same as // the right to see this page. $pdfLink = \MUtil_Html::create('a', array($this->getRequest()->getActionKey() => 'pdf'), array('class' => 'pdf', 'target' => '_blank', 'type' => 'application/pdf', 'onclick' => 'event.cancelBubble = true;')); $model->set('gsu_survey_pdf', 'label', 'Pdf', 'accept', 'application/pdf', 'destination', $this->loader->getPdf()->getUploadDir('survey_pdfs'), 'elementClass', 'File', 'extension', 'pdf', 'filename', $surveyId, 'required', false, 'itemDisplay', $pdfLink, 'validators[pdf]', new \MUtil_Validate_Pdf()); } } return $model; }