Add the survey source attributes to the export model that have not yet been set.

@param MUtil_Model_ModelAbstract $model
@param Gems_Tracker_Survey $survey
@param array $data
@param array $prefixes
@throws Gems_Exception
541633
protected function _addSurveySourceAttributesToExportModel(\MUtil_Model_ModelAbstract $model, \Gems_Tracker_Survey $survey, array $data, array &$prefixes)
    {
        $source = $survey->getSource();
        $attributes = $source->getAttributes();
        $preExistingFields = $model->getColNames('label');
        $attributes = array_diff($attributes, $preExistingFields);

        foreach($attributes as $attribute) {
            $model->set($attribute, 'label', $attribute);
        }
    }
924080
private function _checkRelationExists(Model $model, string $relationName)
    {
        if (!method_exists($model, $relationName) || !$model->{$relationName}() instanceof Relation) {
            if (Lang::has('resource-controller.data2relationinexistent')) {
                $message = trans('resource-controller.data2relationinexistent', ['relationName' => $relationName]);
            } else {
                $message = "Array type request data '{$relationName}' must be named after an existent relation.";
            }

            throw new MassAssignmentException($message);
        }
    }
579629
public function updateModel(array $data, Model $model)
    {
        $model = $model->fill($data);

        return $model->isDirty() && $model->update($data);
    }
215108
protected function doUpdateSkills(Reference $model, $data) {
		// remove all relationships before
		SkillReferenceQuery::create()->filterByReference($model)->delete();

		// add them
		$errors = [];
		foreach ($data as $entry) {
			if (!isset($entry['id'])) {
				$errors[] = 'Missing id for Skill';
			} else {
				$related = SkillQuery::create()->findOneById($entry['id']);
				$model->addSkill($related);
			}
		}

		if (count($errors) > 0) {
			throw new ErrorsException($errors);
		}
	}
1366068
public function setSource(array $data, $fields = null)
    {
        $this->setModel(new \atk4\data\Model(new \atk4\data\Persistence_Static($data)), $fields);
    }
1353165
public function create($model, $data)
	{
		$params = $this->buildParams(array(
			$model,
			'create',
			$data
		));

		$response = $this->getClient('object')->call('execute', $params);

		return $response;
	}
1228769
protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
    {
        parent::processFilterAndSort($model);

        $eid = $this->request->getParam(\Gems_Model::EPISODE_ID);
        if ($eid) {
            $model->addFilter(['gap_id_episode' => $eid]);
        }
    }
544485
protected function doAddChildren(Skill $model, $data) {
		$errors = [];
		foreach ($data as $entry) {
			if (!isset($entry['id'])) {
				$errors[] = 'Missing id for Skill';
			} else {
				$related = SkillQuery::create()->findOneById($entry['id']);
				$model->addSkillRelatedByDependencyId($related);
			}
		}

		if (count($errors) > 0) {
			return new ErrorsException($errors);
		}
	}
1242773
public function beforeInsert($model, &$data)
    {
        if ($this->weak) {
            return;
        }

        if ($model->hasField($this->master_field)
            && $model[$this->master_field]
        ) {
            // The value for the master_field is set,
            // we are going to use existing record.
            return;
        }

        // Figure out where are we going to save data
        $persistence = $this->persistence ?:
            $this->owner->persistence;

        $this->id = $persistence->insert(
            $model,
            $this->save_buffer,
            $this->foreign_table
        );

        $data[$this->master_field] = $this->id;

        //$this->owner->set($this->master_field, $this->id);
    }
386500
protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
    {
        $filter['gto_id_respondent']   = $this->respondent->getId();
        if (is_array($this->forOtherOrgs)) {
            $filter['gto_id_organization'] = $this->forOtherOrgs;
        } elseif (true !== $this->forOtherOrgs) {
            $filter['gto_id_organization'] = $this->respondent->getOrganizationId();
        }

        // Filter for valid track reception codes
        $filter[] = 'gr2t_reception_code IN (SELECT grc_id_reception_code FROM gems__reception_codes WHERE grc_success = 1)';
        $filter['grc_success'] = 1;
        // Active round
        // or
        // no round
        // or
        // token is success and completed
        $filter[] = 'gro_active = 1 OR gro_active IS NULL OR (grc_success=1 AND gto_completion_time IS NOT NULL)';
        $filter['gsu_active']  = 1;

        // NOTE! $this->model does not need to be the token model, but $model is a token model
        $tabFilter = $this->model->getMeta('tab_filter');
        if ($tabFilter) {
            $model->addFilter($tabFilter);
        }

        $model->addFilter($filter);

        // \MUtil_Echo::track($model->getFilter());

        $this->processSortOnly($model);
    }
292231
protected function intermediateRelation(Model $model, array $intermediateTable, $prefix)
    {
        $attributes = $this->intermediateAttributes($model, $prefix);

        $class = $intermediateTable['class'];

        if ($class === Pivot::class) {
            return $class::fromAttributes($model, $attributes, $intermediateTable['table'], true);
        }

        if (is_subclass_of($class, Pivot::class)) {
            return $class::fromRawAttributes($model, $attributes, $intermediateTable['table'], true);
        }

        /** @var \Illuminate\Database\Eloquent\Model $instance */
        $instance = new $class;

        return $instance->newFromBuilder($attributes);
    }
78242
protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
    {
        parent::processFilterAndSort($model);

        $filter = $model->getFilter();

        if (isset($filter['gr2o_id_organization'])) {
            $otherOrgs = $this->util->getOtherOrgsFor($filter['gr2o_id_organization']);
            if (is_array($otherOrgs)) {
                // If more than one org, do not use patient number but resp id
                if (isset($filter['gr2o_patient_nr'])) {
                    $filter['gr2o_id_user'] = $this->respondent->getId();
                    unset($filter['gr2o_patient_nr']);
                }

                $filter['gr2o_id_organization'] = $otherOrgs;

                // Second filter, should be changed as well
                if (isset($this->extraFilter['gr2t_id_organization'])) {
                    $this->extraFilter['gr2t_id_organization'] = $otherOrgs;
                }
                $model->setFilter($filter);
            }
        }
    }
314105
public function requireModel($model, &$data, $prefix = null)
    {
        $class = null;
        $name = (null !== $prefix) ? $prefix : substr($model, strlen(explode('_', $model)[0]) + 7);
        
        foreach ($this->array_prefix as $k => $ap) {
            if (strrpos($ap, $name) === (strlen($ap) - strlen($name))) {
                unset($this->array_prefix[$k]);
                $class = clone $this->container->get($model);
                $class->setPrefix($prefix);
                $class->setArrayPrefix($this->array_prefix);
                $class->setParentModel($this);
                $class->exchangeArray($data);
                if (! $class->Keep()) {
                    return new IsNull();
                }
                break;
            }
        }
        
        return $class;
    }
1107932
public function beforeInsert($model, &$data)
    {
        if ($this->weak) {
            return;
        }

        // The value for the master_field is set, so we are going to use existing record anyway
        if ($model->hasField($this->master_field) && $model[$this->master_field]) {
            return;
        }

        $insert = $this->dsql();
        $insert->mode('insert');
        $insert->set($model->persistence->typecastSaveRow($model, $this->save_buffer));
        $this->save_buffer = [];
        $insert->set($this->foreign_field, null);
        $insert->insert();
        $this->id = $this->owner->lastInsertID();

        if ($this->join) {
            $this->join->set($this->master_field, $this->id);
        } else {
            $data[$this->master_field] = $this->id;
        }
    }
846870
protected function _addSlugFromSingle(Garp_Model_Db $model, array &$targetData, array $referenceData) {
        $baseFields = $this->_config['baseField'];
        $slugFields = $this->_config['slugField'];
        $lang = null;
        if (isset($referenceData[Garp_Model_Behavior_Translatable::LANG_COLUMN])) {
            $lang = $referenceData[Garp_Model_Behavior_Translatable::LANG_COLUMN];
        }
        foreach ($baseFields as $i => $baseField) {
            $baseData = $this->_getBaseString($baseField, $referenceData);
            $slugField = $slugFields[$i];
            if (!empty($targetData[$slugField])) {
                continue;
            }
            $targetData[$slugField] = $this->generateUniqueSlug($baseData, $model, $slugField, $lang);
        }
    }
293272
protected function addStepElementsForStep1(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model) {
        $model->set('source_survey', 'elementClass', 'Select');
        $this->addItems($bridge, 'source_survey', 'target_survey');
        $this->addItems($bridge, 'track_replace', 'token_update', 'copy_answers');
    }
855219
private function cacheModelByKeys(\Tx_Oelib_Model $model, array $data)
    {
        foreach ($this->additionalKeys as $key) {
            if (isset($data[$key])) {
                $value = $data[$key];
                if ($value !== '') {
                    $this->cacheByKey[$key][$value] = $model;
                }
            }
        }

        $this->cacheModelByCombinedKeys($model, $data);
        if (!empty($this->compoundKeyParts)) {
            $this->cacheModelByCompoundKey($model, $data);
        }
    }