Saves the field data for the respondent track id.

@param int $respTrackId Gems respondent track id
@param array $fieldData The values to save, only the key is used, not the code
@return int The number of changed fields
174781
public function saveFields($respTrackId, array $fieldData)
    {
        $saves = array();

        foreach ($this->_fields as $key => $field) {
            if ($field instanceof FieldInterface) {
                if (array_key_exists($key, $fieldData)) {
                    $inVal = $fieldData[$key];
                } else {
                    // There is no value do not save
                    continue;
                }

                $saveVal = $field->onFieldDataSave($inVal, $fieldData);

                $saves[] = array(
                    'sub'                        => $field->getFieldSub(),
                    'gr2t2f_id_respondent_track' => $respTrackId,
                    'gr2t2f_id_field'            => $field->getFieldId(),
                    'gr2t2f_value'               => $saveVal,
                );
            }
        }

        $model = $this->getDataStorageModel();
        $model->saveAll($saves);

        return $model->getChanged();
    }
751604
public function fillRawData(string $rawData): TelegramResponse
    {
        $this->rawData = $rawData;
        $this->decodedData = json_decode($this->rawData, true);

        if ($this->decodedData['ok'] === false) {
            $exception = new ClientException();
            $exception->setError(new UnsuccessfulRequest($this->decodedData));
            throw $exception;
        }

        return $this;
    }
690442
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));
    }
1137347
public function saveFields(array $fieldData)
    {
        $trackEngine = $this->getTrackEngine();

        if (! $trackEngine) {
            return 0;
        }

        //\MUtil_Echo::track($fieldData);
        $this->_fieldData = $this->_mergeFieldValues($fieldData, $this->getFieldData(), $trackEngine);

        $changed = $trackEngine->getFieldsDefinition()->saveFields($this->_respTrackId, $this->_fieldData);

        if ($changed) {
            $this->_ensureFieldData(true);
        }

        $this->handleFieldUpdate();

        return $changed;
    }
876965
public function recalculateFields(&$fieldsChanged = false)
    {
        $fieldDef  = $this->getTrackEngine()->getFieldsDefinition();

        $this->_ensureFieldData();
        $this->_fieldData = $this->processFieldsBeforeSave($this->_fieldData, $this->_respTrackData);
        $fieldsChanged    = $fieldDef->changed;

        $changes       = $fieldDef->saveFields($this->_respTrackId, $this->_fieldData);
        $fieldsChanged = (boolean) $changes;

        $this->handleFieldUpdate();

        $info = $fieldDef->calculateFieldsInfo($this->_fieldData);
        if ($info != $this->_respTrackData['gr2t_track_info']) {
            $this->_updateTrack(array('gr2t_track_info' => $info), $this->currentUser->getUserId());
        }

        // We always update the fields, but recalculate the token dates
        // only when this respondent track is still running.
        if ($this->hasSuccesCode() && $this->isOpen()) {
            return $this->checkTrackTokens($this->currentUser->getUserId());
        }
    }
959236
public function calculationStart(array $trackData)
    {
        if (isset($trackData['gr2t_id_respondent_track'])) {
            $this->_lastActiveKey = $trackData['gr2t_id_respondent_track'];
        } elseif (isset($trackData['gr2t_id_user'], $trackData['gr2t_id_organization'])) {
            $this->_lastActiveKey = $trackData['gr2t_id_user'] . '__' . $trackData['gr2t_id_organization'];
        } else {
            $this->_lastActiveKey = false;
        }
        if ($this->_lastActiveKey) {
            self::$_lastActiveAppointment[$this->_lastActiveKey]    = null;
            self::$_lastActiveAppointmentIds[$this->_lastActiveKey] = array();
        }

        return $this;
    }
1304729
private static function rle(&$stringData)
        {
            $outArray = array();
            $symbolArray = str_split($stringData);
            $last = '';
            $run = 1;
            
            while (count($symbolArray) > 0) {
                $symbol = array_shift($symbolArray);
                
                if ($symbol != $last) {
                    if ($run > 1) 
                        $outArray[] = $run;
                    
                    if ($last != '')
                        $outArray[] = $last;
                        
                    $run = 1;
                    $last = $symbol;
                } else {
                    $run++;
                }
            }
            
            if ($run > 1) 
                $outArray[] = $run;
                
            $outArray[] = $last;
            
            $stringData = $outArray;
        }
1112490
public function _hydrateTrackData(HpsTrackData $trackData, $xml)
    {
        $trackDataElement = $xml->createElement('hps:TrackData', $trackData->value);
        $trackDataElementMethod = $xml->createAttribute('method');
        $trackDataElementMethod->value = $trackData->method;
        $trackDataElement->appendChild($trackDataElementMethod);
        return $trackDataElement;
    }
1298778
public function submissionSaveData(array $formData)
    {
        // remove empty values
        $formData = array_filter($formData);

        // get array of files to upload
        $files = [];
        foreach ($formData as $field => $value) {
            if (Request::hasFile($field)) {
                $files[$field] = Request::file($field);
                unset($formData[$field]);
            }
        }

        // save form submission
        $form_submission = new FormSubmission;
        $form_submission->form_block_id = $this->_block->id;
        $form_submission->content = serialize($formData);
        $form_submission->sent = 0;
        $form_submission->from_page_id = PageBuilder::pageId();
        $form_submission->save();
        $form_submission->uploadFiles($files);
        return $form_submission;
    }
753855
public function setPayload($responseData) {

		try {
			$this->data = json_encode($responseData, $this->encodingOptions);
		}

		catch (\Exception $e) {

			// PHP 5.4 wrap exceptions thrown by JsonSerializable in a new exception that needs to be removed

			if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
				throw $e->getPrevious() ?: $e;
			}
			throw $e;
		}

		if (JSON_ERROR_NONE !== json_last_error()) {
			throw new \InvalidArgumentException(json_last_error_msg());
		}

		return $this->update();

	}
1302629
protected function dumpVarData(&$data, $levelLimit, $rootCall = true) {
		static $sizeLeft,
		$objectsHashes = array(),
		$origQueue = array(),
		$refQueue = array(),
		$levelsQueue = array();

		if($rootCall) {
			$sizeLeft = $this->dumpSizeLimit ? : 999999999;
		}

		if(is_object($data)) {
			if($data instanceof \Closure) {
				$data = '(callback function)';
				return;
			}
			if($rootCall) {
				$data = array('' => $data);
				return $this->dumpVarData($data, $levelLimit + 1);
			}
			$objectsHashes[] = spl_object_hash($data);
			$dataArray = array();
			foreach((array)$data as $key => $value) {
				$nullPos = strrpos($key, chr(0));
				if($nullPos) {
					$dataArray[substr($key, $nullPos + 1)] = $value;
				}
				else {
					$dataArray[$key] = $value;
				}
			}
			$data = $dataArray;
		}

		if(is_array($data)) {

			if($this->detectCallbacks && count($data) == 2 && is_callable($data)) {
				list($class, $method) = $data;
				$data = '(callback ' . (is_object($class) ? get_class($class) : $class) . '::' . $method . ')';
				$sizeLeft -= strlen($data) + 4;
				return;
			}

			$i = 0;
			$dataArray = array();
			foreach($data as $k => &$v) {
				if(($this->itemsCountLimit && $i >= $this->itemsCountLimit) || $sizeLeft <= 0) {
					break;
				}
				if(is_array($v) || is_object($v)) {
					if($levelLimit > 1) {
						$origQueue[] = $v;
						$refQueue[] =& $v;
						$levelsQueue[] = $levelLimit;
					}
					if(is_object($v) && !$v instanceof \Closure) {
						$k .= ':' . get_class($v);
						$hash = spl_object_hash($v);
						if(in_array($hash, $objectsHashes)) {
							$v = '*RECURSION*';
						}
						else {
							$v = '(object)';
							$objectsHashes[] = $hash;
						}
					}
					else {
						$v = '(array)';
					}
					$sizeLeft -= strlen($k) + strlen($v) + 8;
				}
				else {
					$sizeLeft -= strlen($k) + 4;
					$this->dumpVarData($v, $levelLimit - 1, false);
				}
				$dataArray[$k] =& $v;
				$i++;
			}

			if($i != count($data)) {
				$dataArray['...'] = '(displayed ' . $i . ' of ' . count($data) . ')';
			}
			$data = $dataArray;

			if(!$rootCall) {
				return;
			}

			do {
				$origData = array_shift($origQueue);
				$level = array_shift($levelsQueue);
				$refData =& $refQueue[0];
				array_shift($refQueue);
				$sizeLeft += strlen($refData);
				if($refData !== '*RECURSION*') {
					$this->dumpVarData($origData, $level - 1, false);
					$refData = $origData;
				}
			}
			while(count($origQueue) && $sizeLeft >= 0);

			if($rootCall) {
				$levelsQueue = $origQueue = $refQueue = $objectsHashes = array();
			}
		}
		// scalar or resource
		else {
			if(!is_scalar($data) && $data !== null) {
				if(is_resource($data)) {
					$data = '(' . strtolower((string)$data) . ' ' . get_resource_type($data) . ')';
					$sizeLeft -= strlen($data);
					return;
				}
				$data = var_export($data, true);
			}
			if(strlen($data) > $this->itemSizeLimit) {
				$data = substr($data, 0, $this->itemSizeLimit - 3) . '...';
			}
			if(strlen($data) > $sizeLeft) {
				$data = substr($data, 0, $sizeLeft - 3) . '...';
			}
			$sizeLeft -= strlen($data);
		}
	}
637087
public function update_form_data(stdClass $data) : stdClass {
        $answercount = count($this->get_answers());
        // Check for other answer entry.
        $lastanswer = $data->{'answer_editor[' . ($answercount - 1) . ']'};
        if (strpos($lastanswer, LESSON_OTHER_ANSWERS) !== false) {
            $data->{'answer_editor[' . ($this->lesson->maxanswers + 1) . ']'} =
                    $data->{'answer_editor[' . ($answercount - 1) . ']'};
            $data->{'response_editor[' . ($this->lesson->maxanswers + 1) . ']'} =
                    $data->{'response_editor[' . ($answercount - 1) . ']'};
            $data->{'jumpto[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'jumpto[' . ($answercount - 1) . ']'};
            $data->{'score[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'score[' . ($answercount - 1) . ']'};
            $data->enableotheranswers = true;
            // Unset the old values.
            unset($data->{'answer_editor[' . ($answercount - 1) . ']'});
            unset($data->{'response_editor[' . ($answercount - 1) . ']'});
            unset($data->{'jumpto[' . ($answercount - 1) . ']'});
            unset($data->{'score[' . ($answercount - 1) . ']'});
        }
        return $data;
    }
262458
public static Track2 from(final String rawTrackData)
  {
    final Matcher matcher = track2Pattern.matcher(trimToEmpty(rawTrackData));

    final String rawTrack2Data;
    final AccountNumber pan;
    final ExpirationDate expirationDate;
    final ServiceCode serviceCode;
    final String discretionaryData;

    if (matcher.matches())
    {
      rawTrack2Data = getGroup(matcher, 1);
      pan = new AccountNumber(getGroup(matcher, 2));
      expirationDate = new ExpirationDate(getGroup(matcher, 3));
      serviceCode = new ServiceCode(getGroup(matcher, 4));
      discretionaryData = getGroup(matcher, 5);
    }
    else
    {
      rawTrack2Data = null;
      pan = new AccountNumber();
      expirationDate = new ExpirationDate();
      serviceCode = new ServiceCode();
      discretionaryData = "";
    }

    return new Track2(rawTrack2Data,
                      pan,
                      expirationDate,
                      serviceCode,
                      discretionaryData);
  }
560624
public function getRespondentTrack()
    {
        static $respTrack;

        if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
            return $respTrack;
        }

        $respTrackId = $this->_getParam(\Gems_Model::RESPONDENT_TRACK);
        $tracker     = $this->loader->getTracker();

        if ($respTrackId) {
            $respTrack = $tracker->getRespondentTrack($respTrackId);
        } else {
            if ($this->isMultiTracks()) {
                throw new \Gems_Exception($this->_('No track specified for respondent!'));
            }

            $respondent = $this->getRespondent();
            $respTracks = $tracker->getRespondentTracks(
                    $respondent->getId(),
                    $respondent->getOrganizationId(),
                    array('grc_success DESC', 'gr2t_start_date')
                    );
            $trackId = $this->escort->getTrackId();
            if ($trackId) {
                foreach ($respTracks as $respTrack) {
                    if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
                        if ($trackId == $respTrack->getTrackId()) {
                            // Return the right track if it exists
                            break;
                        }
                    }
                }
            } else {
                $respTrack = reset($respTracks);
            }
        }
        if (! $respTrack instanceof \Gems_Tracker_RespondentTrack) {
            if ($this->isMultiTracks()) {
                throw new \Gems_Exception($this->_('No track found for respondent!'));
            } else {
                $this->menu->getParameterSource()->offsetSet('track_can_be_created', 1);
                return null;
            }
        }

        $respTrack->applyToMenuSource($this->menu->getParameterSource());

        // Otherwise return the last created track (yeah some implementations are not correct!)
        return $respTrack;
    }
292290
public function onFieldDataSave($currentValue, array $fieldData)
    {
        if (is_array($currentValue)) {
            return implode(parent::FIELD_SEP, $currentValue);
        }

        return $currentValue;
    }
465031
public static function allow_track() {
        $DoNotTrackHeader = "DNT";
        $DoNotTrackValue = "1";

        $phpHeader = "HTTP_" . strtoupper(str_replace("-", "_", $DoNotTrackHeader));

        $retval = ! ((array_key_exists($phpHeader, $_SERVER)) and ($_SERVER[$phpHeader] == $DoNotTrackValue));
        return $retval;
    }
1106136
protected function saveFields( array $submittedData, $task )
	{
		parent::saveFields( $submittedData, $task );

		$task->{$this->fieldSenderFrom} = $submittedData[$this->fieldSenderFrom];
		$task->{$this->fieldSenderEmail} = $submittedData[$this->fieldSenderEmail];
		$task->{$this->fieldReplyEmail} = $submittedData[$this->fieldReplyEmail];
		$task->{$this->fieldPageDetail} = $submittedData[$this->fieldPageDetail];
		$task->{$this->fieldPageDownload} = $submittedData[$this->fieldPageDownload];
		$task->{$this->fieldTemplateBaseurl} = $submittedData[$this->fieldTemplateBaseurl];
	}