/**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  *
  * @param array $trackData Nested array of trackdata
  */
 public function execute($lineNr = null, $fieldData = null)
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     if (isset($fieldData['gtf_id_order']) && $fieldData['gtf_id_order']) {
         $import['fieldOrder'][$fieldData['gtf_id_order']] = false;
         if ($batch->hasVariable('trackEngine') && isset($fieldData['gtf_field_type']) && $fieldData['gtf_field_type']) {
             $trackEngine = $batch->getVariable('trackEngine');
             if ($trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
                 $fieldDef = $trackEngine->getFieldsDefinition();
                 $field = $fieldDef->getFieldByOrder($fieldData['gtf_id_order']);
                 if ($field instanceof FieldInterface) {
                     if ($field->getFieldType() != $fieldData['gtf_field_type']) {
                         $batch->addToCounter('import_errors');
                         $batch->addMessage(sprintf($this->_('Conflicting field types "%s" and "%s" for field orders %d specified on line %d.'), $field->getFieldType(), $fieldData['gtf_field_type'], $fieldData['gtf_id_order'], $lineNr));
                     }
                 }
             }
         }
     } else {
         $batch->addToCounter('import_errors');
         $batch->addMessage(sprintf($this->_('No gtf_id_order specified for field at line %d.'), $lineNr));
     }
     if (isset($fieldData['gtf_field_type']) && $fieldData['gtf_field_type']) {
         $model = $this->loader->getTracker()->createTrackClass('Model\\FieldMaintenanceModel');
         $fields = $model->getFieldTypes();
         if (!isset($fields[$fieldData['gtf_field_type']])) {
             $batch->addToCounter('import_errors');
             $batch->addMessage(sprintf($this->_('Unknown field type "%s" specified on line %d.'), $fieldData['gtf_field_type'], $lineNr));
         }
     } else {
         $batch->addToCounter('import_errors');
         $batch->addMessage(sprintf($this->_('No field type specified on line %d.'), $lineNr));
     }
 }
 /**
  * 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($formData = null)
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     $tracker = $this->loader->getTracker();
     $model = $tracker->getTrackModel();
     $model->applyFormatting(true, true);
     $trackData = $import['trackData'];
     $trackData['gtr_track_name'] = $formData['gtr_track_name'];
     $trackData['gtr_organizations'] = $formData['gtr_organizations'];
     if ($batch->hasVariable('trackEngine')) {
         $trackEngine = $batch->getVariable('trackEngine');
         if ($trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
             $trackData['gtr_id_track'] = $trackEngine->getTrackId();
         }
     }
     // \MUtil_Echo::track($trackData);
     if ($trackData['gtr_date_start'] && !$trackData['gtr_date_start'] instanceof \Zend_Date) {
         $trackData['gtr_date_start'] = new \MUtil_Date($trackData['gtr_date_start'], 'yyyy-MM-dd');
     }
     $output = $model->save($trackData);
     $import['trackId'] = $output['gtr_id_track'];
     $import['trackData']['gtr_id_track'] = $output['gtr_id_track'];
     $batch->addMessage($this->_('Merged track data'));
 }
 /**
  * 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();
     $import = $batch->getVariable('import');
     if (!(isset($import['trackId']) && $import['trackId'])) {
         // Do nothing
         return;
     }
     // Only save when export code is known and set
     if (!isset($roundData['survey_export_code'], $import['surveyCodes'][$roundData['survey_export_code']])) {
         // Do nothing, no survey export code or no known export code
         return;
     }
     if (!$import['surveyCodes'][$roundData['survey_export_code']]) {
         // Export code not set to skip import of round
         return;
     }
     $fieldCodes = $import['fieldCodes'];
     $roundOrders = isset($import['roundOrders']) ? $import['roundOrders'] : array();
     $tracker = $this->loader->getTracker();
     $trackEngine = $tracker->getTrackEngine($import['trackId']);
     $model = $trackEngine->getRoundModel(true, 'create');
     $roundData['gro_id_track'] = $import['trackId'];
     $roundData['gro_id_survey'] = $import['surveyCodes'][$roundData['survey_export_code']];
     if (isset($roundData['valid_after']) && $roundData['valid_after']) {
         if (isset($roundOrders[$roundData['valid_after']]) && $roundOrders[$roundData['valid_after']]) {
             $roundData['gro_valid_after_id'] = $roundOrders[$roundData['valid_after']];
         } else {
             $batch->addTask('Tracker\\Import\\UpdateRoundValidTask', $lineNr, $roundData['gro_id_order'], $roundData['valid_after'], 'gro_valid_after_id');
         }
     }
     if (isset($roundData['gro_valid_after_source'], $fieldData['gro_valid_after_field'])) {
         switch ($roundData['gro_valid_after_source']) {
             case self::APPOINTMENT_TABLE:
             case self::RESPONDENT_TRACK_TABLE:
                 if (isset($fieldCodes[$fieldData['gro_valid_after_field']])) {
                     $fieldData['gro_valid_after_field'] = $fieldCodes[$fieldData['gro_valid_after_field']];
                 }
         }
     }
     if (isset($roundData['valid_for']) && $roundData['valid_for']) {
         if (isset($roundOrders[$roundData['valid_for']]) && $roundOrders[$roundData['valid_for']]) {
             $roundData['gro_valid_for_id'] = $roundOrders[$roundData['valid_for']];
         } else {
             $batch->addTask('Tracker\\Import\\UpdateRoundValidTask', $lineNr, $roundData['gro_id_order'], $roundData['valid_for'], 'gro_valid_for_id');
         }
     }
     if (isset($roundData['gro_valid_for_source'], $fieldData['gro_valid_for_field'])) {
         switch ($roundData['gro_valid_for_source']) {
             case self::APPOINTMENT_TABLE:
             case self::RESPONDENT_TRACK_TABLE:
                 if (isset($fieldCodes[$fieldData['gro_valid_for_field']])) {
                     $fieldData['gro_valid_for_field'] = $fieldCodes[$fieldData['gro_valid_for_field']];
                 }
         }
     }
     $roundData = $model->save($roundData);
     $import['rounds'][$lineNr]['gro_id_round'] = $roundData['gro_id_round'];
     $import['roundOrders'][$roundData['gro_id_order']] = $roundData['gro_id_round'];
 }
 /**
  * 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();
     $batch->addToCounter('checkedTokens');
     $token = $tracker->getToken($tokenData);
     $wasAnswered = $token->isCompleted();
     if ($result = $token->checkTokenCompletion($userId)) {
         if ($result & \Gems_Tracker_Token::COMPLETION_DATACHANGE) {
             $i = $batch->addToCounter('resultDataChanges');
             $batch->setMessage('resultDataChanges', sprintf($this->_('Results and timing changed for %d tokens.'), $i));
             if ($wasAnswered) {
                 $action = 'token.data-changed';
                 $message = sprintf($this->_("Token '%s' data has changed."), $token->getTokenId());
             } else {
                 $action = 'token.answered';
                 $message = sprintf($this->_("Token '%s' was answered."), $token->getTokenId());
             }
             if (!$this->request instanceof \Zend_Controller_Request_Abstract) {
                 $this->request = \Zend_Controller_Front::getInstance()->getRequest();
             }
             $this->accesslog->logEntry($this->request, $action, true, $message, $token->getArrayCopy(), $token->getRespondentId());
         }
         if ($result & \Gems_Tracker_Token::COMPLETION_EVENTCHANGE) {
             $i = $batch->addToCounter('surveyCompletionChanges');
             $batch->setMessage('surveyCompletionChanges', sprintf($this->_('Answers changed by survey completion event for %d tokens.'), $i));
         }
     }
     if ($token->isCompleted()) {
         $batch->setTask('Tracker_ProcessTokenCompletion', 'tokproc-' . $token->getTokenId(), $tokenData, $userId);
     }
     $batch->setMessage('checkedTokens', sprintf($this->_('Checked %d tokens.'), $batch->getCounter('checkedTokens')));
     // Free memory
     $tracker->removeToken($token);
 }
 /**
  * Get information on the field translations
  *
  * @return array of fields sourceName => targetName
  * @throws \MUtil_Model_ModelException
  */
 public function getFieldsTranslations()
 {
     if (!$this->_targetModel instanceof \MUtil_Model_ModelAbstract) {
         throw new \MUtil_Model_ModelTranslateException(sprintf('Called %s without a set target model.', __FUNCTION__));
     }
     $this->_targetModel->set('gto_id_token', 'label', $this->_('Token'), 'import_descr', $this->loader->getTracker()->getTokenLibrary()->getFormat(), 'required', true, 'order', 2);
     return array('token' => 'gto_id_token') + parent::getFieldsTranslations();
 }
 /**
  * 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($respTrackData = null, $userId = null)
 {
     $batch = $this->getBatch();
     $tracker = $this->loader->getTracker();
     $respTrack = $tracker->getRespondentTrack($respTrackData);
     $engine = $respTrack->getTrackEngine();
     $engine->checkRoundsFor($respTrack, $userId, $batch);
 }
 /**
  * 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($surveyId = null, $questionId = null, $order = null)
 {
     $batch = $this->getBatch();
     $survey = $this->loader->getTracker()->getSurvey($surveyId);
     // Now save the questions
     $answerModel = $survey->getAnswerModel('en');
     $questionModel = new \MUtil_Model_TableModel('gems__survey_questions');
     \Gems_Model::setChangeFieldsByPrefix($questionModel, 'gsq');
     $label = $answerModel->get($questionId, 'label');
     /*
             if ($label instanceof \MUtil_Html_HtmlInterface) {
                 $label = $label->render($this->view);
             }
             // */
     $question['gsq_id_survey'] = $surveyId;
     $question['gsq_name'] = $questionId;
     $question['gsq_name_parent'] = $answerModel->get($questionId, 'parent_question');
     $question['gsq_order'] = $order;
     $question['gsq_type'] = $answerModel->getWithDefault($questionId, 'type', \MUtil_Model::TYPE_STRING);
     $question['gsq_class'] = $answerModel->get($questionId, 'thClass');
     $question['gsq_group'] = $answerModel->get($questionId, 'group');
     $question['gsq_label'] = $label;
     $question['gsq_description'] = $answerModel->get($questionId, 'description');
     // \MUtil_Echo::track($question);
     try {
         $questionModel->save($question);
     } catch (\Exception $e) {
         $batch->addMessage(sprintf($this->_('Save failed for survey %s, question %s: %s'), $survey->getName(), $questionId, $e->getMessage()));
     }
     $batch->addToCounter('checkedQuestions');
     if ($questionModel->getChanged()) {
         $batch->addToCounter('changedQuestions');
     }
     $batch->setMessage('questionschanged', sprintf($this->_('%d of %d questions changed.'), $batch->getCounter('changedQuestions'), $batch->getCounter('checkedQuestions')));
     $options = $answerModel->get($questionId, 'multiOptions');
     if ($options) {
         $optionModel = new \MUtil_Model_TableModel('gems__survey_question_options');
         \Gems_Model::setChangeFieldsByPrefix($optionModel, 'gsqo');
         $option['gsqo_id_survey'] = $surveyId;
         $option['gsqo_name'] = $questionId;
         $i = 0;
         // \MUtil_Echo::track($options);
         foreach ($options as $key => $label) {
             $option['gsqo_order'] = $i;
             $option['gsqo_key'] = $key;
             $option['gsqo_label'] = $label;
             try {
                 $optionModel->save($option);
             } catch (\Exception $e) {
                 $batch->addMessage(sprintf($this->_('Save failed for survey %s, question %s, option "%s" => "%s": %s'), $survey->getName(), $questionId, $key, $label, $e->getMessage()));
             }
             $i++;
         }
         $batch->addToCounter('checkedOptions', count($options));
         $batch->addToCounter('changedOptions', $optionModel->getChanged());
         $batch->setMessage('optionschanged', sprintf($this->_('%d of %d options changed.'), $batch->getCounter('changedOptions'), $batch->getCounter('checkedOptions')));
     }
 }
 /**
  * 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)
 {
     $messages = false;
     if ($this->wasAnswered) {
         $this->currentToken = $this->token->getNextUnansweredToken();
     } else {
         $validator = $this->loader->getTracker()->getTokenValidator();
         if ($validator->isValid($this->token->getTokenId())) {
             $this->currentToken = $this->token;
         } else {
             $messages = $validator->getMessages();
             $this->currentToken = $this->token->getNextUnansweredToken();
         }
     }
     if ($this->currentToken instanceof \Gems_Tracker_Token) {
         $href = $this->getTokenHref($this->currentToken);
         $url = $href->render($this->view);
         // Redirect at once
         header('Location: ' . $url);
         exit;
     }
     // After the header() so that the patient does not see the messages after answering surveys
     if ($messages) {
         $this->addMessage($messages);
     }
     $org = $this->token->getOrganization();
     $html = $this->getHtmlSequence();
     $html->h3($this->_('Token'));
     $html->pInfo(sprintf($this->_('Thank you %s,'), $this->token->getRespondentName()));
     if ($welcome = $org->getWelcome()) {
         $html->pInfo()->raw(\MUtil_Markup::render($this->_($welcome), 'Bbcode', 'Html'));
     }
     $p = $html->pInfo()->spaced();
     if ($this->wasAnswered) {
         $p->append($this->_('Thanks for answering our questions.'));
     } elseif (!$this->isValid) {
         if ($this->token->isExpired()) {
             $this->addMessage($this->_('This survey has expired. You can no longer answer it.'));
         } else {
             $this->addMessage($this->_('This survey is no longer valid.'));
         }
     }
     $p->append($this->_('We have no further questions for you at the moment.'));
     $p->append($this->_('We appreciate your cooperation very much.'));
     if ($sig = $org->getSignature()) {
         $html->pInfo()->raw(\MUtil_Markup::render($this->_($sig), 'Bbcode', 'Html'));
     }
     /*
             $html->br();
     
             $href = array($this->request->getActionKey() => 'index', \MUtil_Model::REQUEST_ID => null);
             $buttonDiv = $html->buttonDiv(array('class' => 'centerAlign'));
             $buttonDiv->actionLink($href, $this->_('OK'));
             // */
     return $html;
 }
 /**
  * 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, $command = null)
 {
     $batch = $this->getBatch();
     $params = array_slice(func_get_args(), 2);
     $source = $this->loader->getTracker()->getSource($sourceId);
     if ($messages = call_user_func_array(array($source, $command), $params)) {
         foreach ($messages as $message) {
             $batch->addMessage($command . ': ' . $message);
         }
     }
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->db = \Zend_Db::factory('pdo_sqlite', array('dbname' => ':memory:'));
     \Zend_Registry::set('db', $this->db);
     $settings = new \Zend_Config_Ini(GEMS_ROOT_DIR . '/configs/application.example.ini', APPLICATION_ENV);
     $sa = $settings->toArray();
     $this->loader = new \Gems_Loader(\Zend_Registry::getInstance(), $sa['loaderDirs']);
     \Zend_Registry::set('loader', $this->loader);
     $this->tracker = $this->loader->getTracker();
     \Zend_Registry::set('tracker', $this->tracker);
 }
 /**
  * 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);
 }
 /**
  * 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()
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     if (!(isset($import['trackId']) && $import['trackId'])) {
         // Do nothing
         return;
     }
     $tracker = $this->loader->getTracker();
     $trackEngine = $tracker->getTrackEngine($import['trackId']);
     $trackEngine->updateRoundCount($this->currentUser->getUserLoginId());
 }
 /**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     if ($this->model instanceof \Gems_Tracker_Model_StandardTokenModel) {
         $model = $this->model;
     } else {
         $model = $this->loader->getTracker()->getTokenModel();
     }
     $model->addColumn('CASE WHEN gto_completion_time IS NULL THEN gto_valid_from ELSE gto_completion_time END', 'calc_used_date', 'gto_valid_from');
     $model->addColumn('CASE WHEN gto_completion_time IS NULL THEN gto_valid_from ELSE NULL END', 'calc_valid_from', 'gto_valid_from');
     $model->addColumn('CASE WHEN gto_completion_time IS NULL AND grc_success = 1 AND gto_valid_from <= CURRENT_TIMESTAMP AND gto_completion_time IS NULL AND (gto_valid_until IS NULL OR gto_valid_until >= CURRENT_TIMESTAMP) THEN gto_id_token ELSE NULL END', 'calc_id_token', 'gto_id_token');
     $model->addColumn('CASE WHEN gto_completion_time IS NULL AND grc_success = 1 AND gto_valid_from <= CURRENT_TIMESTAMP AND gto_completion_time IS NULL AND gto_valid_until < CURRENT_TIMESTAMP THEN 1 ELSE 0 END', 'was_missed');
     return $model;
 }
 /**
  * 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($respTrackData = null, $userId = null)
 {
     $batch = $this->getBatch();
     $tracker = $this->loader->getTracker();
     $respTrack = $tracker->getRespondentTrack($respTrackData);
     $i = $batch->addToCounter('checkedRespondentTracks');
     if ($result = $respTrack->checkTrackTokens($userId)) {
         $a = $batch->addToCounter('tokenDateCauses');
         $b = $batch->addToCounter('tokenDateChanges', $result);
         $batch->setMessage('tokenDateChanges', sprintf($this->_('%2$d token date changes in %1$d tracks.'), $a, $b));
     }
     $batch->setMessage('checkedRespondentTracks', sprintf($this->_('Checked %d tracks.'), $i));
 }
 /**
  * Process the respondent and return true when data has changed.
  *
  * The event has to handle the actual storage of the changes.
  *
  * @param \Gems_Tracker_Respondent $respondent
  * @param int $userId The current user
  * @return boolean True when something changed
  */
 public function processChangedRespondent(\Gems_Tracker_Respondent $respondent)
 {
     $changes = 0;
     $tracker = $this->loader->getTracker();
     $respTracks = $tracker->getRespondentTracks($respondent->getId(), $respondent->getOrganizationId());
     $userId = $this->currentUser->getUserId();
     foreach ($respTracks as $respondentTrack) {
         if ($respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
             $changes += $respondentTrack->checkTrackTokens($userId);
         }
     }
     // \MUtil_Echo::track('Hi there! ' . $changes);
     return (bool) $changes;
 }
 /**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     $model = $this->loader->getTracker()->getRespondentTrackModel();
     $model->addColumn('CONCAT(gr2t_completed, \'' . $this->_(' of ') . '\', gr2t_count)', 'progress');
     $model->resetOrder();
     $model->set('gtr_track_name', 'label', $this->_('Track'));
     $model->set('gr2t_track_info', 'label', $this->_('Description'));
     $model->set('gr2t_start_date', 'label', $this->_('Start'), 'formatFunction', $this->util->getTranslated()->formatDate, 'default', \MUtil_Date::format(new \Zend_Date(), 'dd-MM-yyyy'));
     $model->set('gr2t_reception_code');
     $model->set('progress', 'label', $this->_('Progress'));
     // , 'tdClass', 'rightAlign', 'thClass', 'rightAlign');
     $model->set('assigned_by', 'label', $this->_('Assigned by'));
     return $model;
 }
 /**
  * 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($tokenId = null)
 {
     $batch = $this->getBatch();
     $tracker = $this->loader->getTracker();
     $token = $tracker->getToken($tokenId);
     $checked = $batch->addToCounter('ta-checkedTokens');
     if ($token->inSource()) {
         $survey = $token->getSurvey();
         if ($survey->copyTokenToSource($token, '')) {
             $batch->addToCounter('ta-changedTokens');
         }
     }
     $cTokens = $batch->getCounter('ta-changedTokens');
     $batch->setMessage('ta-check', sprintf($this->plural('%d token out of %d tokens changed.', '%d tokens out of %d tokens changed.', $cTokens), $cTokens, $checked));
 }
 /**
  * Default overview action
  */
 public function indexAction()
 {
     if ($this->checkForAnswersOnLoad) {
         $this->loader->getTracker()->processCompletedTokens(null, $this->currentUser->getUserId(), $this->currentUser->getCurrentOrganizationId(), true);
     }
     parent::indexAction();
 }
 public function save(array $newValues, array $filter = null)
 {
     // Allow to add default fields to any new track
     if ($defaultFields = $this->getDefaultFields()) {
         $keys = $this->getKeys();
         $keys = array_flip($keys);
         $missing = array_diff_key($keys, $newValues);
         // On copy track the key exists but is null
         $newValues = parent::save($newValues, $filter);
         if (!empty($missing)) {
             // We have an insert!
             $foundKeys = array_intersect_key($newValues, $missing);
             // Now get the fieldmodel
             $engine = $this->loader->getTracker()->getTrackEngine($foundKeys['gtr_id_track']);
             $fieldmodel = $engine->getFieldsMaintenanceModel(true, 'create');
             $lastOrder = 0;
             foreach ($defaultFields as $field) {
                 // Load defaults
                 $record = $fieldmodel->loadNew();
                 $record['gtf_id_order'] = $lastOrder + 10;
                 $record = $field + $record;
                 // Add defaults to the new field
                 $record = $fieldmodel->save($record);
                 $lastOrder = $record['gtf_id_order'];
                 // Save order for next record
             }
         }
     } else {
         $newValues = parent::save($newValues, $filter);
     }
     return $newValues;
 }
 /**
  * Perform automatic job mail
  */
 public function commJob()
 {
     $batch = $this->loader->getTaskRunnerBatch('cron');
     $batch->minimalStepDurationMs = 3000;
     // 3 seconds max before sending feedback
     $batch->autoStart = true;
     if (!$batch->isLoaded()) {
         // Check for unprocessed tokens
         $tracker = $this->loader->getTracker();
         $tracker->processCompletedTokens(null, $this->currentUser->getUserId());
         $batch->addTask('Mail\\AddAllMailJobsTask');
     }
     $title = $this->_('Executing cron jobs');
     $this->_helper->BatchRunner($batch, $title, $this->accesslog);
     $this->html->br();
 }
 /**
  * Return the survey id (and set a menu var)
  *
  * @return int
  */
 public function getSurveyId()
 {
     $id = $this->_getIdParam();
     $survey = $this->loader->getTracker()->getSurvey($id);
     $this->menu->getParameterSource()->offsetSet('gsu_active', $survey->isActive() ? 1 : 0);
     return $id;
 }
 /**
  * Validate the data against the target form
  *
  * @param array $row
  * @param scalar $key
  * @return mixed Row array or false when errors occurred
  */
 public function validateRowValues(array $row, $key)
 {
     $row = parent::validateRowValues($row, $key);
     $token = $this->loader->getTracker()->getToken($row['token'] ? $row['token'] : 'emptytoken');
     if ($token->exists) {
         // If token is not completed we can use it, otherwise it depends on the settings
         if ($token->isCompleted()) {
             switch ($this->getTokenCompleted()) {
                 case self::TOKEN_SKIP:
                     return false;
                 case self::TOKEN_ERROR:
                     $this->_addErrors(sprintf($this->_('Token %s is completed.'), $token->getTokenId()), $key);
                     break;
                     // Intentional fall-through,
                     // other case are handled in SaveAnswerTask
             }
         }
     } else {
         switch ($this->getNoToken()) {
             case self::TOKEN_SKIP:
                 return false;
             case self::TOKEN_ERROR:
                 $this->_addErrors($this->getNoTokenError($row, $key), $key);
                 break;
             default:
                 $respTrack = $this->findRespondentTrackFor($row);
                 if ($respTrack) {
                     $row['resp_track_id'] == $respTrack;
                 } else {
                     $this->_addErrors(sprintf($this->_('No track for inserting found for %s.'), implode(" / ", $row)), $key);
                 }
         }
     }
     return $row;
 }
 /**
  * Hook that loads the form data from $_POST or the model
  *
  * Or from whatever other source you specify here.
  */
 protected function loadFormData()
 {
     parent::loadFormData();
     $surveyId = $this->request->getParam(\MUtil_Model::REQUEST_ID);
     if (isset($this->formData['survey']) && $this->formData['survey'] && !$this->_survey instanceof \Gems_Tracker_Survey) {
         $this->_survey = $this->loader->getTracker()->getSurvey($this->formData['survey']);
     }
     if ($this->_survey instanceof \Gems_Tracker_Survey) {
         // Add (optional) survey specific translators
         $extraTrans = $this->importLoader->getAnswerImporters($this->_survey);
         if ($extraTrans) {
             $this->importTranslators = $extraTrans + $this->importTranslators;
             $this->_translatorDescriptions = false;
             $this->importModel->set('trans', 'multiOptions', $this->getTranslatorDescriptions());
         }
     }
     if ($this->_survey instanceof \Gems_Tracker_Survey) {
         $this->targetModel = $this->_survey->getAnswerModel($this->locale->toString());
         $this->importer->setTargetModel($this->targetModel);
         $source = $this->menu->getParameterSource();
         $source->offsetSet('gsu_has_pdf', $this->_survey->hasPdf() ? 1 : 0);
         $source->offsetSet('gsu_active', $this->_survey->isActive() ? 1 : 0);
     }
     // \MUtil_Echo::track($this->formData);
 }
 /**
  * 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);
         }
     }
 }
 private function getRepeater($trackId)
 {
     if (!$this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
         $this->trackEngine = $this->loader->getTracker()->getTrackEngine($trackId);
     }
     $roundModel = $this->trackEngine->getRoundModel(true, null);
     return $roundModel->loadRepeatable(array('gro_id_track' => $trackId, 'gro_active' => 1));
 }
 /**
  * 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();
 }
 /**
  * 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)
 {
     $tracker = $this->loader->getTracker();
     $token = $tracker->getToken($tokenData[0]);
     $survey = $token->getSurvey();
     $source = $survey->getSource();
     if (method_exists($source, 'getCompletedTokens')) {
         $completed = $source->getCompletedTokens($tokenData, $survey->getSourceSurveyId());
     } else {
         // No bulk method, check all individually
         $completed = $tokenData;
     }
     if ($completed) {
         $batch = $this->getBatch();
         foreach ($completed as $tokenId) {
             $batch->setTask('Tracker_CheckTokenCompletion', 'tokchk-' . $tokenId, $tokenId, $userId);
         }
     }
 }
 /**
  * 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);
 }
 /**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  *
  * @param array $trackData Nested array of trackdata
  */
 public function execute($lineNr = null, $fieldData = null)
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     if (!(isset($import['trackId']) && $import['trackId'])) {
         // Do nothing
         return;
     }
     $tracker = $this->loader->getTracker();
     $trackEngine = $tracker->getTrackEngine($import['trackId']);
     $fieldModel = $trackEngine->getFieldsMaintenanceModel(true, 'create');
     $fieldData['gtf_id_track'] = $import['trackId'];
     $fieldData = $fieldModel->save($fieldData);
     // Store the field reference
     $import['fieldCodes']['{f' . $fieldData['gtf_id_order'] . '}'] = FieldsDefinition::makeKey($fieldData['sub'], $fieldData['gtf_id_field']);
     if (isset($fieldData['gtf_calculate_using']) && $fieldData['gtf_calculate_using']) {
         $batch->addTask('Tracker\\Import\\UpdateFieldCalculationTask', $lineNr, $fieldData['gtf_id_field'], $fieldModel->getModelNameForRow($fieldData), $fieldData['gtf_calculate_using']);
     }
 }
 /**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  *
  * @param array $trackData Nested array of trackdata
  */
 public function execute($formData = null)
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     $tracker = $this->loader->getTracker();
     $model = $tracker->getTrackModel();
     $model->applyFormatting(true, true);
     $trackData = $import['trackData'];
     $trackData['gtr_track_name'] = $formData['gtr_track_name'];
     $trackData['gtr_organizations'] = $formData['gtr_organizations'];
     // \MUtil_Echo::track($trackData);
     if ($trackData['gtr_date_start'] && !$trackData['gtr_date_start'] instanceof \Zend_Date) {
         $trackData['gtr_date_start'] = new \MUtil_Date($trackData['gtr_date_start'], 'yyyy-MM-dd');
     }
     $output = $model->save($trackData);
     $import['trackId'] = $output['gtr_id_track'];
     $import['trackData']['gtr_id_track'] = $output['gtr_id_track'];
     $batch->addMessage(sprintf($this->_('Created track with id %d'), $output['gtr_id_track']));
 }