コード例 #1
0
 /**
  * Called after the check that all required registry values
  * have been set correctly has run.
  *
  * @return void
  */
 public function afterRegistry()
 {
     parent::afterRegistry();
     if (!$this->user) {
         $this->user = $this->loader->getCurrentUser();
     }
 }
コード例 #2
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $dbLookup = $this->util->getDbLookup();
     $translated = $this->util->getTranslated();
     $noRound = array(self::NoRound => $this->_('No round description'));
     $empty = $translated->getEmptyDropdownArray();
     $rounds = $empty + $noRound + $dbLookup->getRoundsForExport();
     $surveys = $dbLookup->getSurveysForExport();
     $elements[] = $this->_createSelectElement('gto_id_survey', $surveys, $this->_('(select a survey)'));
     $elements[] = $this->_createSelectElement('gto_id_track', $this->util->getTrackData()->getAllTracks(), $this->_('(select a track)'));
     $elements[] = $this->_createSelectElement('gto_round_description', $rounds, $this->_('(select a round)'));
     $orgs = $this->loader->getCurrentUser()->getRespondentOrganizations();
     if (count($orgs) > 1) {
         $elements[] = $this->_createSelectElement('gto_id_organization', $orgs, $this->_('(all organizations)'));
     }
     $elements[] = null;
     $dates = array('gto_start_date' => $this->_('Track start'), 'gto_end_date' => $this->_('Track end'), 'gto_valid_from' => $this->_('Valid from'), 'gto_valid_until' => $this->_('Valid until'));
     // $dates = 'gto_valid_from';
     $this->_addPeriodSelectors($elements, $dates, 'gto_valid_from');
     $elements[] = null;
     $element = $this->form->createElement('checkbox', 'column_identifiers');
     $element->setLabel($this->_('Column Identifiers'));
     $element->setDescription($this->_('Prefix the column labels with an identifier. (A) Answers, (TF) Trackfields, (D) Description'));
     $elements[] = $element;
     $element = $this->form->createElement('checkbox', 'show_parent');
     $element->setLabel($this->_('Show parent'));
     $element->setDescription($this->_('Show the parent column even if it doesn\'t have answers'));
     $elements[] = $element;
     $element = $this->form->createElement('checkbox', 'prefix_child');
     $element->setLabel($this->_('Prefix child'));
     $element->setDescription($this->_('Prefix the child column labels with parent question label'));
     $elements[] = $element;
     $elements[] = null;
     return $elements;
 }
コード例 #3
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements = parent::getAutoSearchElements($data);
     $user = $this->loader->getCurrentUser();
     if ($user->hasPrivilege('pr.respondent.select-on-track')) {
         $tracks = $this->searchData['__active_tracks'];
         $masks['show_all'] = $this->_('(all)');
         $masks['show_without_track'] = $this->_('(no track)');
         if (count($tracks) > 1) {
             $masks['show_with_track'] = $this->_('(with track)');
         }
         if (count($tracks) > 1) {
             $elements[] = $this->_createSelectElement('gr2t_id_track', $masks + $tracks);
         } else {
             $element = $this->_createRadioElement('gr2t_id_track', $masks + $tracks);
             $element->setSeparator(' ');
             $elements[] = $element;
         }
         $lineBreak = true;
     } else {
         $lineBreak = false;
     }
     if ($user->hasPrivilege('pr.respondent.show-deleted')) {
         $elements[] = $this->_createCheckboxElement('grc_success', $this->_('Show active'));
     }
     if ($this->model->isMultiOrganization()) {
         $element = $this->_createSelectElement(\MUtil_Model::REQUEST_ID2, $user->getRespondentOrganizations(), $this->_('(all organizations)'));
         if ($lineBreak) {
             $element->setLabel($this->_('Organization'))->setAttrib('onchange', 'this.form.submit();');
             $elements[] = \MUtil_Html::create('br');
         }
         $elements[] = $element;
     }
     return $elements;
 }
コード例 #4
0
 /**
  * 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($sourceId = null, $userId = null)
 {
     $batch = $this->getBatch();
     $source = $this->loader->getTracker()->getSource($sourceId);
     if (is_null($userId)) {
         $userId = $this->loader->getCurrentUser()->getUserId();
     }
     $surveyCount = $batch->addToCounter('sourceSyncSources');
     $batch->setMessage('sourceSyncSources', sprintf($this->plural('Check %s source', 'Check %s sources', $surveyCount), $surveyCount));
     $source->synchronizeSurveyBatch($batch, $userId);
 }
コード例 #5
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements = parent::getAutoSearchElements($data);
     $this->_addPeriodSelectors($elements, 'gla_created');
     $elements[] = null;
     $elements[] = $this->_('Specific action');
     $sql = "SELECT gls_id_action, gls_name\n                    FROM gems__log_setup\n                    WHERE gls_when_no_user = 1 OR gls_on_action = 1 OR gls_on_change = 1 OR gls_on_post = 1\n                    ORDER BY gls_name";
     $elements[] = $this->_createSelectElement('gla_action', $sql, $this->_('(any action)'));
     $elements[] = $this->_createSelectElement('gla_organization', $this->loader->getCurrentUser()->getAllowedOrganizations(), $this->_('(all organizations)'));
     return $elements;
 }
コード例 #6
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     // Search text
     $elements = parent::getAutoSearchElements($data);
     $this->_addPeriodSelectors($elements, array('grco_created' => $this->_('Date sent')));
     $br = \MUtil_Html::create()->br();
     $elements[] = null;
     $dbLookup = $this->util->getDbLookup();
     $elements[] = $this->_createSelectElement('gto_id_track', $this->util->getTrackData()->getAllTracks(), $this->_('(select a track)'));
     $elements[] = $this->_createSelectElement('gto_id_survey', $this->util->getTrackData()->getAllSurveys(), $this->_('(all surveys)'));
     $elements[] = $this->_createSelectElement('grco_organization', $this->loader->getCurrentUser()->getRespondentOrganizations(), $this->_('(all organizations)'));
     return $elements;
 }
コード例 #7
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements[] = $this->_createSelectElement('gto_id_track', $this->util->getTrackData()->getAllTracks(), $this->_('(select a track)'));
     $orgs = $this->loader->getCurrentUser()->getRespondentOrganizations();
     if (count($orgs) > 1) {
         $elements[] = $this->_createSelectElement('gto_id_organization', $orgs, $this->_('(all organizations)'));
     }
     $elements[] = null;
     $dates = array('gr2t_start_date' => $this->_('Track start'), 'gr2t_end_date' => $this->_('Track end'), 'gto_valid_from' => $this->_('Valid from'), 'gto_valid_until' => $this->_('Valid until'));
     // $dates = 'gto_valid_from';
     $this->_addPeriodSelectors($elements, $dates, 'gto_valid_from');
     $elements[] = null;
     $sql = "SELECT DISTINCT ggp_id_group, ggp_name\n                    FROM gems__groups INNER JOIN gems__surveys ON ggp_id_group = gsu_id_primary_group\n                        INNER JOIN gems__rounds ON gsu_id_survey = gro_id_survey\n                        INNER JOIN gems__tracks ON gro_id_track = gtr_id_track\n                    WHERE ggp_group_active = 1 AND\n                        gro_active=1 AND\n                        gtr_active=1\n                    ORDER BY ggp_name";
     $elements[] = $this->_createSelectElement('gsu_id_primary_group', $sql, $this->_('(all fillers)'));
     return $elements;
 }
 /**
  * Hook containing the actual save code.
  *
  * Call's afterSave() for user interaction.
  *
  * @see afterSave()
  */
 protected function saveData()
 {
     $this->beforeSave();
     $changed = $this->setReceptionCode($this->formData[$this->receptionCodeItem], $this->loader->getCurrentUser()->getUserId());
     $this->afterSave($changed);
     $this->accesslog->logChange($this->request, null, $this->formData);
 }
コード例 #9
0
 /**
  * Function used to fill the tab bar
  *
  * @return array tabId => label
  */
 protected function getTabs()
 {
     $user = $this->loader->getCurrentUser();
     $sql = "SELECT gr2o_id_organization, gr2o_patient_nr FROM gems__respondent2org WHERE gr2o_id_user = ?";
     $this->defaultTab = $user->getCurrentOrganizationId();
     $this->currentTab = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
     $allowedOrgs = $user->getRespondentOrganizations();
     $existingOrgs = $this->db->fetchPairs($sql, $this->respondent->getId());
     $tabs = array();
     foreach ($allowedOrgs as $orgId => $name) {
         if (isset($existingOrgs[$orgId])) {
             $tabs[$orgId] = $name;
             $this->hrefs[$orgId] = array(\MUtil_Model::REQUEST_ID1 => $existingOrgs[$orgId], \MUtil_Model::REQUEST_ID2 => $orgId, 'RouteReset' => true);
         }
     }
     return $tabs;
 }
コード例 #10
0
 /**
  * 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($sourceId = null, $sourceSurveyId = null, $surveyId = null, $userId = null)
 {
     $batch = $this->getBatch();
     $source = $this->loader->getTracker()->getSource($sourceId);
     if (null === $userId) {
         $userId = $this->loader->getCurrentUser()->getUserId();
     }
     $messages = $source->checkSurvey($sourceSurveyId, $surveyId, $userId);
     $batch->addToCounter('checkedSurveys');
     $batch->addToCounter('changedSurveys', $messages ? 1 : 0);
     $batch->setMessage('changedSurveys', sprintf($this->_('%d of %d surveys changed.'), $batch->getCounter('changedSurveys'), $batch->getCounter('checkedSurveys')));
     if ($messages) {
         foreach ((array) $messages as $message) {
             $batch->addMessage($message);
         }
     }
 }
コード例 #11
0
 /**
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @param int $defaultOrgId The default organization id or null if current organization
  * @return \Gems_Model_StaffModel
  */
 public function applySettings($detailed, $action, $defaultOrgId)
 {
     $this->resetOrder();
     $dbLookup = $this->util->getDbLookup();
     $editing = $action == 'edit' || $action == 'create';
     $translated = $this->util->getTranslated();
     $user = $this->loader->getCurrentUser();
     $yesNo = $translated->getYesNo();
     if ($editing) {
         $ucfirst = new \Zend_Filter_Callback('ucfirst');
         if ($this->project->isLoginShared()) {
             $this->set('gsf_login', 'validator', $this->createUniqueValidator('gsf_login', array('gsf_id_user')));
         } else {
             // per organization
             $this->set('gsf_login', 'validator', $this->createUniqueValidator(array('gsf_login', 'gsf_id_organization'), array('gsf_id_user')));
         }
     } else {
         $ucfirst = null;
     }
     $this->set('gsf_login', 'label', $this->_('Username'), 'minlength', 4, 'required', true, 'size', 15);
     if ($user->hasPrivilege('pr.staff.see.all') || !$editing) {
         // Select organization
         $options = $dbLookup->getOrganizations();
     } else {
         $options = $user->getAllowedOrganizations();
     }
     $this->set('gsf_id_organization', 'label', $this->_('Organization'), 'multiOptions', $options, 'required', true);
     if ($detailed) {
         $this->set('gsf_first_name', 'label', $this->_('First name'), 'filters[ucfirst]', $ucfirst);
         $this->set('gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', $this->_('de, van der, \'t, etc...'));
         $this->set('gsf_last_name', 'label', $this->_('Last name'), 'required', true, 'filters[ucfirst]', $ucfirst);
     } else {
         $this->set('name', 'label', $this->_('Name'));
     }
     $this->set('gsf_gender', 'label', $this->_('Gender'), 'elementClass', 'Radio', 'multiOptions', $translated->getGenders(), 'separator', ' ');
     $this->set('gsf_email', 'label', $this->_('E-Mail'), 'itemDisplay', array('MUtil_Html_AElement', 'ifmail'), 'size', 30, 'validators[email]', 'SimpleEmail');
     $this->set('gsf_id_primary_group', 'label', $this->_('Primary function'), 'multiOptions', $editing ? $user->getAllowedStaffGroups() : $dbLookup->getStaffGroups());
     if ($detailed) {
         // Now try to load the current organization and find out if it has a default user definition
         // otherwise use the defaultStaffDefinition
         $organization = $this->loader->getOrganization($defaultOrgId ? $defaultOrgId : $user->getCurrentOrganizationId());
         $this->set('gsf_id_organization', 'default', $organization->getId());
         $this->set('gul_user_class', 'label', $this->_('User Definition'), 'default', $organization->get('gor_user_class', $this->defaultStaffDefinition), 'multiOptions', $this->loader->getUserLoader()->getAvailableStaffDefinitions());
         if ($editing) {
             $this->set('gul_user_class', 'order', 1, 'required', true);
         }
         $this->set('gsf_iso_lang', 'label', $this->_('Language'), 'default', $this->project->locale['default'], 'multiOptions', $this->util->getLocalized()->getLanguages());
         $this->set('gul_can_login', 'label', $this->_('Can login'), 'default', 1, 'description', $this->_('Users can only login when this box is checked.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo);
         $this->set('gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'description', $this->_('If checked the user will logoff when answering a survey.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo);
         $this->set('gsf_mail_watcher', 'label', $this->_('Check cron job mail'), 'description', $this->_('If checked the user will be mailed when the cron job does not run on time.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo);
     }
     $this->set('gsf_active', 'label', $this->_('Active'), 'elementClass', 'None', 'multiOptions', $yesNo);
     $this->setDeleteValues('gsf_active', 0, 'gul_can_login', 0);
     if (!$user->hasPrivilege('pr.staff.edit.all')) {
         $this->set('gsf_id_organization', 'elementClass', 'Exhibitor');
     }
     return $this;
 }
コード例 #12
0
 /**
  * Create the snippets content
  *
  * This is a stub function either override getHtmlOutput() or override render()
  *
  * @param \Zend_View_Abstract $view Just in case it is needed here
  * @return \MUtil_Html_HtmlInterface Something that can be rendered
  */
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $html = $this->getHtmlSequence();
     $html->h3($this->_('Choose an organization'));
     $user = $this->loader->getCurrentUser();
     $url[$this->request->getControllerKey()] = 'organization';
     $url[$this->request->getActionKey()] = 'change-ui';
     if ($orgs = $user->getRespondentOrganizations()) {
         $html->pInfo($this->_('This organization cannot have any respondents, please choose one that does:'));
         foreach ($orgs as $orgId => $name) {
             $url['org'] = $orgId;
             $html->pInfo()->actionLink($url, $name)->appendAttrib('class', 'larger');
         }
     } else {
         $html->pInfo($this->_('This organization cannot have any respondents.'));
     }
     return $html;
 }
コード例 #13
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements = parent::getAutoSearchElements($data);
     if ($elements) {
         $br = \MUtil_Html::create('br');
         $elements[] = $this->_createSelectElement('gtr_track_class', $this->model, $this->_('(all track engines)'));
         $elements[] = $br;
         $optionsA = $this->util->getTranslated()->getYesNo();
         $elementA = $this->_createSelectElement('gtr_active', $optionsA, $this->_('(both)'));
         $elementA->setLabel($this->model->get('gtr_active', 'label'));
         $elements[] = $elementA;
         $user = $this->loader->getCurrentUser();
         $optionsO = $user->getRespondentOrganizations();
         $elementO = $this->_createSelectElement('org', $optionsO, $this->_('(all organizations)'));
         $elements[] = $elementO;
     }
     return $elements;
 }
コード例 #14
0
 /**
  * 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();
 }
コード例 #15
0
 /**
  * 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($tokenData = null, $userId = null)
 {
     $batch = $this->getBatch();
     $tracker = $this->loader->getTracker();
     $token = $tracker->getToken($tokenData);
     if ($token->isCompleted()) {
         $respTrack = $token->getRespondentTrack();
         $userId = $userId ? $userId : $this->loader->getCurrentUser()->getUserId();
         if ($result = $respTrack->handleRoundCompletion($token, $userId)) {
             $a = $batch->addToCounter('roundCompletionCauses');
             $b = $batch->addToCounter('roundCompletionChanges', $result);
             $batch->setMessage('roundCompletionChanges', sprintf($this->_('%d token round completion events caused changed to %d tokens.'), $a, $b));
         }
         $trackId = $respTrack->getRespondentTrackId();
         $batch->setTask('Tracker_CheckTrackTokens', 'chktrck-' . $trackId, $trackId, $userId);
     }
     // Free memory
     $tracker->removeToken($token);
 }
コード例 #16
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements = parent::getAutoSearchElements($data);
     if ($elements) {
         $optionsG = $this->util->getDbLookup()->getGroups();
         $elementG = $this->_createSelectElement('gsf_id_primary_group', $optionsG, $this->_('(all functions)'));
         $elements[] = $elementG;
         $user = $this->loader->getCurrentUser();
         $optionsO = $user->getAllowedOrganizations();
         if (count($optionsO) > 1) {
             $elementO = $this->_createSelectElement('gsf_id_organization', $optionsO, $this->_('(all organizations)'));
             $elements[] = $elementO;
         }
         $optionsA = $this->util->getTranslated()->getYesNo();
         $elementA = $this->_createSelectElement('gsf_active', $optionsA, $this->_('(both)'));
         $elementA->setLabel($this->model->get('gsf_active', 'label'));
         $elements[] = $elementA;
     }
     return $elements;
 }
コード例 #17
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements[] = $this->_createSelectElement('gto_id_track', $this->util->getTrackData()->getAllTracks(), $this->_('(select a track)'));
     $orgs = $this->loader->getCurrentUser()->getRespondentOrganizations();
     if (count($orgs) > 1) {
         $elements[] = $this->_createSelectElement('gto_id_organization', $orgs, $this->_('(all organizations)'));
     }
     $elements[] = null;
     $dates = array('gr2t_start_date' => $this->_('Track start'), 'gr2t_end_date' => $this->_('Track end'), 'gto_valid_from' => $this->_('Valid from'), 'gto_valid_until' => $this->_('Valid until'));
     // $dates = 'gto_valid_from';
     $this->_addPeriodSelectors($elements, $dates, 'gto_valid_from');
     $elements[] = null;
     if (isset($data['gto_id_track']) && !empty($data['gto_id_track'])) {
         $trackId = $data['gto_id_track'];
     } else {
         $trackId = -1;
     }
     $sql = "SELECT ggp_name, ggp_name as label FROM (\n                    SELECT DISTINCT ggp_name\n                        FROM gems__groups INNER JOIN gems__surveys ON ggp_id_group = gsu_id_primary_group\n                            INNER JOIN gems__rounds ON gsu_id_survey = gro_id_survey\n                            INNER JOIN gems__tracks ON gro_id_track = gtr_id_track\n                        WHERE ggp_group_active = 1 AND\n                            gro_active=1 AND\n                            gtr_active=1 AND\n                            gtr_id_track = {$trackId}\n\n                UNION ALL\n\n                    SELECT DISTINCT gtf_field_name as ggp_name\n                        FROM gems__track_fields\n                        WHERE gtf_field_type = 'relation' AND\n                            gtf_id_track = {$trackId}\n                ) AS tmpTable\n                ORDER BY ggp_name";
     $elements[] = $this->_createSelectElement('ggp_name', $sql, $this->_('(all fillers)'));
     return $elements;
 }
コード例 #18
0
 /**
  * Create the options for the Select
  */
 protected function createFromSelect($elementName = 'from', $label = '')
 {
     $valid = array();
     $invalid = array();
     $organization = $this->mailer->getOrganization();
     // The organization
     $key = 'organization';
     if ($name = $organization->getContactName()) {
         $extra = $organization->getName();
     } else {
         $name = $organization->getName();
         $extra = null;
     }
     if ($email = $organization->getEmail()) {
         $title = false;
         $valid[] = $key;
     } else {
         $title = $this->_('Organization does not have an e-mail address.');
         $invalid[] = $key;
     }
     $options[$key] = $this->createMultiOption(array(\MUtil_Model::REQUEST_ID => $organization->getId()), $name, $email, $extra, $title, array('controller' => 'organization', 'action' => 'edit'));
     $this->fromOptions[$key] = $email;
     //$name . ' <' . $email . '>';
     // The user
     $key = 'user';
     $name = $this->currentUser->getFullName();
     $extra = null;
     if ($email = $this->currentUser->getEmailAddress()) {
         $title = false;
         $valid[] = $key;
     } else {
         $title = $this->_('You do not have an e-mail address.');
         $invalid[] = $key;
     }
     $options[$key] = $this->createMultiOption(array(), $name, $email, $extra, $title, array('controller' => 'option', 'action' => 'edit'));
     $this->fromOptions[$key] = $email;
     //$name . ' <' . $email . '>';
     // As "the" application
     $key = 'application';
     $user = $this->loader->getCurrentUser();
     if ($user->hasPrivilege('pr.plan.mail-as-application') && isset($this->project->email['site'])) {
         if ($email = $this->project->email['site']) {
             $options['application'] = $this->createMultiOption(array(), $this->project->name, $email);
             $valid[] = 'application';
             $this->fromOptions[$key] = $email;
             //$this->project->name . ' <' . $email . '>';
         }
     }
     $firstSelectable = reset($valid);
     $element = $this->form->createElement('radio', $elementName, array('disable' => $invalid, 'escape' => !$this->view, 'label' => $label, 'multiOptions' => $options, 'required' => true, 'value' => $firstSelectable));
     $element->addValidator('InArray', false, array('haystack' => $valid));
     return $element;
 }
コード例 #19
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements = parent::getAutoSearchElements($data);
     if ($this->organizationField) {
         $user = $this->loader->getCurrentUser();
         if ($this->respondentOrganizations) {
             $availableOrganizations = $this->util->getDbLookup()->getOrganizationsWithRespondents();
         } else {
             $availableOrganizations = $this->util->getDbLookup()->getActiveOrganizations();
         }
         if ($user->hasPrivilege('pr.staff.see.all')) {
             // Select organization
             $options = $availableOrganizations;
         } else {
             $options = array_intersect($availableOrganizations, $user->getAllowedOrganizations());
         }
         if ($options) {
             $elements[] = $this->_createSelectElement($this->organizationField, $options, $this->_('(all organizations)'));
         }
     }
     return $elements;
 }
 /**
  * Returns the caption for this table
  *
  * @param boolean $onlyNotCurrent Only return a string when the organization is different
  * @return string
  */
 protected function getCaption($onlyNotCurrent = false)
 {
     $orgId = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
     if ($orgId == $this->loader->getCurrentUser()->getCurrentOrganizationId()) {
         if ($onlyNotCurrent) {
             return;
         } else {
             return $this->_('Respondent information');
         }
     } else {
         return sprintf($this->_('%s respondent information'), $this->loader->getOrganization($orgId)->getName());
     }
 }
コード例 #21
0
 /**
  * Returns a text element for autosearch. Can be overruled.
  *
  * The form / html elements to search on. Elements can be grouped by inserting null's between them.
  * That creates a distinct group of elements
  *
  * @param array $data The $form field values (can be usefull, but no need to set them)
  * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
  */
 protected function getAutoSearchElements(array $data)
 {
     $elements = parent::getAutoSearchElements($data);
     $user = $this->loader->getCurrentUser();
     if ($user->hasPrivilege('pr.respondent.select-on-track')) {
         $elements[] = $this->_createCheckboxElement('show_with_track', $this->_('Has track'));
         $elements[] = $this->_createCheckboxElement('show_without_track', $this->_('No track'));
         $lineBreak = true;
     } else {
         $lineBreak = false;
     }
     if ($user->hasPrivilege('pr.respondent.show-deleted')) {
         $elements[] = $this->_createCheckboxElement('grc_success', $this->_('Show active'));
     }
     if ($this->model->isMultiOrganization()) {
         $element = $this->_createSelectElement(\MUtil_Model::REQUEST_ID2, $user->getRespondentOrganizations(), $this->_('(all organizations)'));
         if ($lineBreak) {
             $element->setLabel($this->_('Organization'));
             $elements[] = \MUtil_Html::create('br');
         }
         $elements[] = $element;
     }
     return $elements;
 }
コード例 #22
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());
 }
コード例 #23
0
 /**
  * Hook that allows actions when data was saved
  *
  * When not rerouted, the form will be populated afterwards
  *
  * @param int $changed The number of changed rows (0 or 1 usually, but can be more)
  */
 protected function afterSave($changed)
 {
     parent::afterSave($changed);
     // Make sure any changes in the allowed list are reflected.
     $this->loader->getCurrentUser()->refreshAllowedOrganizations();
 }
コード例 #24
0
 public function afterRegistry()
 {
     parent::afterRegistry();
     // The users current organization
     $this->_organization = $this->loader->getCurrentUser()->getCurrentOrganization();
 }
コード例 #25
0
 /**
  * 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 $row Row to save
  */
 public function execute($row = null, $noToken = \Gems_Model_Translator_AnswerTranslatorAbstract::TOKEN_ERROR, $tokenCompletion = \Gems_Model_Translator_AnswerTranslatorAbstract::TOKEN_ERROR)
 {
     // \MUtil_Echo::track($row);
     if ($row) {
         $answers = $row;
         $double = false;
         $token = null;
         $tracker = $this->loader->getTracker();
         $userId = $this->loader->getCurrentUser()->getUserId();
         // \Gems_Tracker::$verbose = true;
         $batch = $this->getBatch();
         $batch->addToCounter('imported');
         // Remove all "non-answer" fields
         unset($answers['token'], $answers['patient_id'], $answers['organization_id'], $answers['track_id'], $answers['survey_id'], $answers['completion_date'], $answers['gto_id_token']);
         if (isset($row['survey_id'])) {
             $model = $tracker->getSurvey($row['survey_id'])->getAnswerModel('en');
             foreach ($answers as $key => &$value) {
                 if ($value instanceof \Zend_Date) {
                     $value = $value->toString($model->getWithDefault($key, 'storageFormat', 'yyyy-MM-dd HH:mm:ss'));
                 }
             }
         }
         if (isset($row['token']) && $row['token']) {
             $token = $tracker->getToken($row['token']);
             if ($token->exists && $token->isCompleted() && $token->getReceptionCode()->isSuccess()) {
                 $currentAnswers = $token->getRawAnswers();
                 $usedAnswers = array_intersect_key($answers, $currentAnswers);
                 // \MUtil_Echo::track($currentAnswers, $answers, $usedAnswers);
                 if ($usedAnswers) {
                     foreach ($usedAnswers as $name => $value) {
                         if (null === $answers[$name] || $answers[$name] == $this->targetModel->get($name, 'default')) {
                             // There is no value to set, so do not set the value
                             unset($answers[$name]);
                         } elseif (!(null === $value || $value == $this->targetModel->get($name, 'default'))) {
                             // The value was already set
                             $double = true;
                             // But no break because of previous unsets
                             // break;
                         }
                     }
                 }
             }
         }
         if (!($token && $token->exists)) {
             if (!(isset($row['track_id']) && $row['track_id'])) {
             }
             // create token?
         }
         if ($answers) {
             if ($double) {
                 if (\Gems_Model_Translator_AnswerTranslatorAbstract::TOKEN_OVERWRITE == $tokenCompletion) {
                     $code = $this->util->getReceptionCode('redo');
                     $oldComment = "";
                     if ($token->getComment()) {
                         $oldComment .= "\n\n";
                         $oldComment .= $this->_('Previous comments:');
                         $oldComment .= "\n";
                         $oldComment .= $token->getComment();
                     }
                     $newComment = sprintf($this->_('Token %s overwritten by import.'), $token->getTokenId());
                     $replacementTokenId = $token->createReplacement($newComment . $oldComment, $userId);
                     $count = $batch->addToCounter('overwritten', 1);
                     $batch->setMessage('overwritten', sprintf($this->plural('%d token overwrote an existing token.', '%d tokens overwrote existing tokens.', $count), $count));
                     $oldToken = $token;
                     $token = $tracker->getToken($replacementTokenId);
                     // Add the old answers to the new answer set as the new answers OVERWRITE the old data
                     $answers = $answers + $currentAnswers;
                     // Make sure the Next token is set right
                     $oldToken->setNextToken($token);
                     $oldToken->setReceptionCode($code, sprintf($this->_('Token %s overwritten by import.'), $token->getTokenId()) . $oldComment, $userId);
                 } else {
                     $oldComment = "";
                     if ($token->getComment()) {
                         $oldComment .= "\n\n";
                         $oldComment .= $this->_('Previous comments:');
                         $oldComment .= "\n";
                         $oldComment .= $token->getComment();
                     }
                     $newComment = sprintf($this->_('More answers for token %s by import.'), $token->getTokenId());
                     $replacementTokenId = $token->createReplacement($newComment . $oldComment, $userId);
                     $count = $batch->addToCounter('addedAnswers', 1);
                     $batch->setMessage('addedAnswers', sprintf($this->plural('%d token was imported as a new extra token.', '%d tokens were imported as a new extra token.', $count), $count));
                     $oldToken = $token;
                     $token = $tracker->getToken($replacementTokenId);
                     // Make sure the Next token is set right
                     $oldToken->setNextToken($token);
                     $oldToken->setReceptionCode($oldToken->getReceptionCode(), sprintf($this->_('Additional answers in imported token %s.'), $token->getTokenId()) . $oldComment, $userId);
                 }
             }
             // There are still answers left to save
             // Make sure the token is known
             $token->getUrl($this->locale->getLanguage(), $userId);
             $token->setRawAnswers($answers);
             if (isset($row['completion_date']) && $row['completion_date']) {
                 $token->setCompletionTime($row['completion_date'], $userId);
             } elseif (!$token->isCompleted()) {
                 $token->setCompletionTime(new \MUtil_Date(), $userId);
             }
             $token->getRespondentTrack()->checkTrackTokens($userId, $token);
             $count = $batch->addToCounter('changed', 1);
             $batch->setMessage('changed', sprintf($this->plural('%d token imported.', '%d tokens imported.', $count), $count));
         }
     }
 }
コード例 #26
0
 /**
  *
  * @param \Zend_Controller_Request_Abstract $request
  * @param string $actionId
  * @param boolean $changed
  * @param mixed $message
  * @param mixed $data
  * @param int $respondentId
  * @return boolean True when a log entry was stored
  */
 public function _logEntry(\Zend_Controller_Request_Abstract $request, $actionId, $changed, $message, $data, $respondentId)
 {
     $action = $this->getAction($actionId);
     $currentUser = $this->_loader->getCurrentUser();
     if ($respondentId) {
         $this->_respondentId = $respondentId;
     }
     // Exit when the user is not logged in and we should only track for logged in users
     if (!$currentUser->isActive()) {
         if (!$action['gls_when_no_user']) {
             return false;
         }
     }
     if ($request instanceof \Zend_Controller_Request_Http) {
         $post = $request->isPost();
         $ip = $request->getClientIp();
         if ($post && null === $data) {
             $data = $request->getPost();
         }
     } else {
         $post = false;
         $ip = '';
     }
     if (null === $message) {
         $message = $this->getMessages();
     }
     if (!$respondentId) {
         // FallBack in case nothing is in $data
         $respondentId = $this->_respondentId;
         if (is_array($data)) {
             foreach ($this->_respondentIdFields as $field) {
                 if (isset($data[$field]) && $data[$field]) {
                     $respondentId = $data[$field];
                     break;
                 }
             }
         }
     }
     $orgId = $currentUser->getCurrentOrganizationId() ? $currentUser->getCurrentOrganizationId() : 0;
     if (is_array($data)) {
         foreach ($this->_organizationIdFields as $field) {
             if (isset($data[$field]) && $data[$field]) {
                 $orgId = $data[$field];
                 break;
             }
         }
     }
     // Get type for second exit check
     if ($changed) {
         $checkKey = 'gls_on_change';
     } elseif ($post) {
         $checkKey = 'gls_on_post';
     } else {
         $checkKey = 'gls_on_action';
     }
     if (!$action[$checkKey]) {
         return false;
     }
     $values['gla_action'] = $action['gls_id_action'];
     $values['gla_respondent_id'] = $respondentId;
     $values['gla_by'] = $currentUser->getUserId();
     $values['gla_organization'] = $orgId;
     $values['gla_role'] = $currentUser->getRole() ? $currentUser->getRole() : '--not set--';
     $values['gla_changed'] = $changed ? 1 : 0;
     $values['gla_message'] = $this->_toJson($message);
     $values['gla_data'] = $this->_toJson($data);
     $values['gla_method'] = $post ? 'POST' : 'GET';
     $values['gla_remote_ip'] = $ip;
     return $this->_storeLogEntry($request, $values, $changed);
 }
コード例 #27
0
 /**
  * Returns the full url Gems should forward to after survey completion.
  *
  * This fix allows multiple sites with multiple url's to share a single
  * installation.
  *
  * @return string
  */
 protected function calculateReturnUrl()
 {
     $currentUri = $this->util->getCurrentURI();
     /*
             // Referrer would be powerful when someone is usng multiple windows, but
             // the loop does not always provide a correct referrer.
             $referrer   = $_SERVER["HTTP_REFERER"];
     
             // If a referrer was specified and that referral is from the current site, then use it
             // as it is more dependable when the user has multiple windows open on the application.
             if ($referrer && (0 == strncasecmp($referrer, $currentUri, strlen($currentUri)))) {
                 return $referrer;
                 // \MUtil_Echo::track($referrer);
             } // */
     // Use the survey return if available.
     $surveyReturn = $this->loader->getCurrentUser()->getSurveyReturn();
     if ($surveyReturn) {
         // Do not show the base url as it is in $currentUri
         $surveyReturn['NoBase'] = true;
         // Add route reset to prevet the current parameters to be
         // added to the url.
         $surveyReturn['RouteReset'] = true;
         // \MUtil_Echo::track($currentUri, \MUtil_Html::urlString($surveyReturn));
         return $currentUri . \MUtil_Html::urlString($surveyReturn);
     }
     // Ultimate backup solution for return
     return $currentUri . '/ask/forward/' . \MUtil_Model::REQUEST_ID . '/' . urlencode($this->getTokenId());
 }
コード例 #28
0
 /**
  *
  * @param type $respId
  * @param type $orgId
  */
 public function getRespondentTokenFilter($respId, $orgId = null)
 {
     if (null === $orgId) {
         $orgId = $this->loader->getCurrentUser()->getCurrentOrganizationId();
     }
 }
コード例 #29
0
 /**
  * Retrieve an array of groups the user is allowed to assign: his own group and all groups
  * he inherits rights from
  *
  * @return array
  * @deprecated Since 1.7.2 Replaced by loader->getCurrentUser()->getAllowedStaffGroups()
  */
 public function getAllowedStaffGroups()
 {
     return $this->loader->getCurrentUser()->getAllowedStaffGroups();
 }
コード例 #30
0
 public function getChart()
 {
     $token = $this->token;
     $data = $this->data;
     $questions = $token->getSurvey()->getQuestionList($this->loader->getCurrentUser()->getLocale());
     $surveyName = $token->getSurveyName();
     // Convert questioncode to array if not already so
     $questionCodes = $this->question_code;
     if (!is_array($questionCodes)) {
         $questionCodes = (array) $questionCodes;
     }
     if (count($questionCodes) > 1) {
         $grouped = true;
     } else {
         $grouped = false;
     }
     if (empty($this->question_text)) {
         if ($grouped) {
             $question = join(', ', $questionCodes);
         } else {
             $question = isset($questions[$questionCodes[0]]) ? $questions[$questionCodes[0]] : $questionCodes[0];
         }
     } else {
         $question = $this->question_text;
     }
     $html = \MUtil_Html::create();
     $wrapper = $html->div(null, array('class' => 'barchart-wrapper'));
     $wrapper->div('', array('class' => 'header'))->append($surveyName)->append($html->br())->append($html->i($question));
     $chart = $wrapper->div(null, array('class' => 'barchart'));
     // the legend, only for printing since it is a hover for screen
     $legend = $html->div('', array('class' => 'legend'));
     $legendrow = $html->div('', array('class' => 'legendrow header'));
     $legendrow[] = $html->div($this->_('Date'), array('class' => 'date'));
     $legendrow[] = $html->div($this->_('Round'), array('class' => 'round', 'renderClosingTag' => true));
     if ($grouped) {
         $legendrow[] = $html->div($this->_('Code'), array('class' => 'code', 'renderClosingTag' => true));
     }
     $legendrow[] = $html->div($this->_('Value'), array('class' => 'value', 'renderClosingTag' => true));
     $legend[] = $legendrow;
     $range = $this->max - $this->min;
     $maxcols = 5;
     $chart[] = $html->div($this->max, array('class' => 'max'));
     $chart[] = $html->div($this->min, array('class' => 'min'));
     $this->doRulers($chart);
     foreach ($data as $row) {
         $token = $this->loader->getTracker()->getToken($row)->refresh();
         if ($token->getReceptionCode()->isSuccess() && $token->isCompleted()) {
             $answers = $token->getRawAnswers();
             foreach ($questionCodes as $idx => $questionCode) {
                 if (array_key_exists($questionCode, $answers)) {
                     $value = (double) $answers[$questionCode];
                     // Cast to number
                     $height = max(min($this->getPercentage($value), 100), 10);
                     // Add some limits
                     $valueBar = $html->div('', array('class' => 'bar col' . ($idx % $maxcols + 1), 'style' => sprintf('height: %s%%;', $height), 'onclick' => 'location.href=\'' . new \MUtil_Html_HrefArrayAttribute(array('controller' => 'track', 'action' => 'answer', \MUtil_Model::REQUEST_ID => $token->getTokenId())) . '\';'));
                     $date = $token->getCompletionTime()->get('dd-MM-yyyy HH:mm');
                     $info = $html->div($date, array('class' => 'info'));
                     $info[] = $html->br();
                     if ($grouped) {
                         $question = isset($questions[$questionCode]) ? $questions[$questionCode] : '';
                         $info[] = $questionCode;
                         $info[] = $html->br();
                         $info[] = $question;
                         $info[] = $html->br();
                     }
                     $info[] = $answers[$questionCode];
                     // The raw answer
                     $info[] = $html->br();
                     $info[] = $token->getRoundDescription();
                     $legendrow = $html->div('', array('class' => 'legendrow'));
                     $legendrow[] = $html->div($date, array('class' => 'date', 'renderClosingTag' => true));
                     $legendrow[] = $html->div($token->getRoundDescription(), array('class' => 'round', 'renderClosingTag' => true));
                     if ($grouped) {
                         $legendrow[] = $html->div($questionCode, array('class' => 'code', 'renderClosingTag' => true));
                     }
                     $legendrow[] = $html->div($answers[$questionCode], array('class' => 'value', 'renderClosingTag' => true));
                     $legend[] = $legendrow;
                     if (empty($value)) {
                         $value = 'N/A';
                     }
                     // Link the value to the answer view in a new window (not the bar to avoid usability issues on touch devices)
                     //$valueBar[] = $html->a(array('controller'=>'track', 'action'=>'answer', \MUtil_Model::REQUEST_ID => $token->getTokenId()), array('target'=>'_blank'), $html->div($value, array('class'=>'value')));
                     $valueBar[] = $info;
                     $chart[] = $valueBar;
                 }
             }
             // Add spacer between (groups of) bars
             if ($grouped) {
                 $class = 'spacer wide bar';
             } else {
                 $class = 'spacer bar';
             }
             $chart[] = $html->div(Mutil_Html::raw('&nbsp;'), array('class' => $class));
         }
     }
     $wrapper[] = $legend;
     return $wrapper;
 }