Prepare a draft file are for the files belonging the a response variable
of this step.

@param string $name the variable name the files belong to.
@param int $contextid the id of the context the quba belongs to.
@return int the draft itemid.
160553
public function prepare_response_files_draft_itemid($name, $contextid) {
        list($draftid, $notused) = $this->prepare_response_files_draft_itemid_with_text(
                $name, $contextid, null);
        return $draftid;
    }
230887
public function execute($name, AnCommandContext $context)
    {
        $parts = explode('.', $name);
        $result = $context->result;

        //after an action save
        if ($parts[0] === 'after' && $parts[1] != 'cancel') {

            //skip if there are not any commitable
            if (count($this->getRepository()->getSpace()->getCommitables()) == 0) {
                return;
            }

            $result = $this->commit();

            $type = $result === false ? 'error' : 'success';
            $message = $this->_makeStatusMessage($context->action, $type);

            if ($message) {
                $this->setMessage($message, $type);
            }

            if ($result === false) {
                if ($this->isIdentifiable() && $this->getItem()) {
                    if ($this->getItem()->getErrors()->count()) {
                        throw new AnErrorException($this->getItem()->getErrors(), AnHttpResponse::BAD_REQUEST);
                        return;
                    }
                } else {
                    $errors = AnHelperArray::getValues($this->getCommitErrors());
                    throw new AnErrorException($errors, AnHttpResponse::BAD_REQUEST);
                    return;
                }
            }
        }
    }
1293490
function update_content($recordid, $value, $name='') {
        global $CFG, $DB, $USER;
        $fs = get_file_storage();

        // Should always be available since it is set by display_add_field before initializing the draft area.
        $content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid));
        if (!$content) {
            $content = (object)array('fieldid' => $this->field->id, 'recordid' => $recordid);
            $content->id = $DB->insert_record('data_content', $content);
        }

        file_save_draft_area_files($value, $this->context->id, 'mod_data', 'content', $content->id);

        $usercontext = context_user::instance($USER->id);
        $files = $fs->get_area_files($this->context->id, 'mod_data', 'content', $content->id, 'itemid, filepath, filename', false);

        // We expect no or just one file (maxfiles = 1 option is set for the form_filemanager).
        if (count($files) == 0) {
            $content->content = null;
        } else {
            $content->content = array_values($files)[0]->get_filename();
            if (count($files) > 1) {
                // This should not happen with a consistent database. Inform admins/developers about the inconsistency.
                debugging('more then one file found in mod_data instance {$this->data->id} file field (field id: {$this->field->id}) area during update data record {$recordid} (content id: {$content->id})', DEBUG_NORMAL);
            }
        }
        $DB->update_record('data_content', $content);
    }
151435
protected function createConfigFile(string $name): void
    {
        $file = base_path($this->moduleName().'/'.$name.'/Config/config.php');
        if (! $this->files->exists($file)) {
            $this->files->put($file, $this->files->get(__DIR__.'/stubs/config.stub'));
        }
    }
818747
public function getVar($name = null)
    {
        $context = $this->_context;

        if ($name === null) {
            return $context->vars;
        } else {
            return isset($context->vars[$name]) ? $context->vars[$name] : null;
        }
    }
27305
public function makeDir($name, $parentID = 0)
    {
        $data = [
            'name'      => $name,
            'parent_id' => $parentID
        ];

        return $this->post('files/create-folder', $data, \false, 'file');
    }
1206984
protected function runScript($name, array $context)
    {
        // Prevent $name and $context being available in the view script
        $___ = $this->getFilePath($name); 
        $_context_ = $context;
        unset($name, $context);
        
        /** @see http://php.net/extract */
        extract($_context_);
        unset($_context_);
        
        include $___;
    }
636583
public function build_property( $name, $context = null, $default = null, $comment = null, $export_default = true )
	{	
		if ( is_null( $context ) )
		{
			$context = 'public';
		}
		
		if ( is_null( $comment ) )
		{
			$comment = ucfirst( $name );
		}
		
		if ( $default !== null )
		{
			$type = gettype( $default );
			
			// integer to int
			if ( $type === 'integer' )
			{
				$type = 'int';
			} 
			
			// boolean to bool
			if ( $type === 'boolean' )
			{
				$type = 'bool';
			} 
			
			$comment .= "\n\n@var ".$type;
		}
		
		$forge = new \CCForge_Php;
		
		return $forge->property( $context.' $'.$name, $default, $comment, $export_default );
	}
1101983
public static function fromContext($context, $ltiResourceLinkId, $tempId = null)
    {

        $resourceLink = new ResourceLink();
        $resourceLink->setContextId($context->getRecordId());
        $resourceLink->context = $context;
        $resourceLink->dataConnector = $context->getDataConnector();
        $resourceLink->ltiResourceLinkId = $ltiResourceLinkId;
        if (!empty($ltiResourceLinkId)) {
            $resourceLink->load();
            if (is_null($resourceLink->id) && !empty($tempId)) {
                $resourceLink->ltiResourceLinkId = $tempId;
                $resourceLink->load();
                $resourceLink->ltiResourceLinkId = $ltiResourceLinkId;
            }
        }

        return $resourceLink;

    }
1308185
public function generateNextUniqueReproducibleIdForContext($contextId)
    {
        if (!array_key_exists($contextId, $this->registeredNamesPerContext)) {
            $this->registeredNamesPerContext[$contextId] = [];
        }

        $index = count($this->registeredNamesPerContext[$contextId]);

        $id = 'v'.$this->currentLoadingVersion.'.'.sha1($contextId.'_'.$index);
        $this->registeredNamesPerContext[$contextId][] = $id;

        return $id;
    }
85881
public static function compileDynamic(&$context, $name) {
        if (!$context['flags']['runpart']) {
            return;
        }

        $func = static::compile($context, $context['usedPartial'][$name], $name);

        if (!isset($context['partialCode'][$name]) && $func) {
            $context['partialCode'][$name] = "'$name' => $func";
        }

        return $func;
    }
606693
public function build_function( $name, $context = null, $content = null, $comment = null )
	{	
		if ( is_null( $context ) )
		{
			$context = 'public';
		}
		
		if ( strpos( $name, '(' ) === false && strpos( $name, '(' ) === false )
		{
			$name .= '()';
		}
		
		if ( is_null( $comment ) )
		{
			$comment = ucfirst( $name )." function\n\nreturn void";
		}
		
		$forge = new \CCForge_Php;
		return $forge->closure( $context.' function '.$name, $content, $comment );
	}
1085308
public function getMemoEntryId($name) {
        return isset($this->memoEntries[$name]) ? $this->memoEntries[$name] : null;
    }
1057384
public function offsetGet($contextId)
    {
        $ctxkey = $this->makeParameterId($contextId);
        if (array_key_exists($ctxkey, $this->pagers)) {
            return $this->pagers[$ctxkey];
        }

        return false;
    }
728666
public function PushVar( $name )
	{
		$id = $this->NewReference();
		$this->_slots[] = new NameSlot( $id, $name );
		return $id;
	}
921255
public function execute($name, AnCommandContext $context)
    {
        $type = '';

        if ($context->caller) {
            $identifier = clone $context->caller->getIdentifier();

            if ($identifier->path) {
                $type = array_shift($identifier->path);
            } else {
                $type = $identifier->name;
            }
        }

        $parts = explode('.', $name);
        $method = !empty($type) ? '_'.$type.ucfirst(AnInflector::implode($parts)) : '_'.lcfirst(AnInflector::implode($parts));

        if (in_array($method, $this->getMethods())) {
            return $this->$method($context);
        }

        return true;
    }
1121947
public static function preload_contexts_by_id(array $contextids) {
        global $DB;

        // Determine which contexts are not already cached.
        $tofetch = [];
        foreach ($contextids as $contextid) {
            if (!self::cache_get_by_id($contextid)) {
                $tofetch[] = $contextid;
            }
        }

        if (count($tofetch) > 1) {
            // There are at least two to fetch.
            // There is no point only fetching a single context as this would be no more efficient than calling the existing code.
            list($insql, $inparams) = $DB->get_in_or_equal($tofetch, SQL_PARAMS_NAMED);
            $ctxs = $DB->get_records_select('context', "id {$insql}", $inparams, '',
                    \context_helper::get_preload_record_columns_sql('{context}'));
            foreach ($ctxs as $ctx) {
                self::preload_from_record($ctx);
            }
        }
    }