Fills a cache containing the first time each analysable in the provided model was analysed.

@param int $modelid
@param int|null $analysableid
@return null
429058
public static function fill_firstanalyses_cache(int $modelid, ?int $analysableid = null) {
        global $DB;

        // Using composed keys instead of cache $identifiers because of MDL-65358.
        $primarykey = $DB->sql_concat($modelid, "'_'", 'analysableid');
        $sql = "SELECT $primarykey AS id, MIN(firstanalysis) AS firstanalysis
                  FROM {analytics_used_analysables} aua
                 WHERE modelid = :modelid";
        $params = ['modelid' => $modelid];

        if ($analysableid) {
            $sql .= " AND analysableid = :analysableid";
            $params['analysableid'] = $analysableid;
        }

        $sql .= " GROUP BY modelid, analysableid ORDER BY analysableid";

        $firstanalyses = $DB->get_records_sql($sql, $params);
        if ($firstanalyses) {
            $cache = \cache::make('core', 'modelfirstanalyses');

            $firstanalyses = array_map(function($record) {
                return $record->firstanalysis;
            }, $firstanalyses);

            $cache->set_many($firstanalyses);
        }

        return $firstanalyses;
    }
190533
public function getNamespace($modelid)
    {
        $returnValue = null;
    
        if(count($this->namespaces) == 0){
        	$this->getAllNamespaces();	//load the namespaces attribute 
       	}
        
        //get modelId from modelUri
        if(is_string($modelid)){
        	$modelid = array_search($modelid, $this->namespaces);
        }
        
    	//get namespace from modelId
    	if(is_int($modelid)){
        	if(isset($this->namespaces[$modelid])){
        		$returnValue = new common_ext_Namespace($modelid, $this->namespaces[$modelid]);
        	}
        }

        return $returnValue;
    }
850433
public function archive($userId, $callId)
    {

        /** @var StateStorage $stateStorage */
        $stateStorage = $this->getServiceManager()->get(StateStorage::SERVICE_ID);

        $state = $stateStorage->get($userId, $callId);

        return (!is_null($state)) ? $this->getFileSystem()->write($this->generateSerial($userId, $callId), $state) : false;
    }
419244
public static function findByParentModelId( $parentId, $parentType, $modelId ) {

		return self::queryByParentModelId( $parentId, $parentType, $modelId )->all();
	}
930126
public function getModelVersionById($modelId, $versionId)
    {
        $modelResult = $this->getRequest()->request(
            'GET',
            $this->getRequestUrl(sprintf('models/%s/versions/%s', $modelId, $versionId))
        );

        if (isset($modelResult['model_version'])) {
            $modelVersion = new ModelVersion($modelResult['model_version']);
        } else {
            throw new \Exception('Model Versions Not Found');
        }

        return $modelVersion;
    }
859403
public static function queryByParentModelId( $parentId, $parentType, $modelId ) {

		$tableName = static::tableName();

		return self::queryWithModel()->where( "$tableName.parentId=:pid AND $tableName.parentType=:ptype AND $tableName.modelId=:mid", [ ':pid' => $parentId, ':ptype' => $parentType, ':mid' => $modelId ] );
	}
338756
public function findCacheById(int $id, int $siteId = null)
    {

        // Resolve siteId
        $siteId = SiteHelper::resolveSiteId($siteId);

        // Check if already in addToCache
        if ($this->isCachedById($id, $siteId)) {
            return $this->cacheById[$siteId][$id];
        }

        return null;
    }
1013358
public function loadById($productId)
    {
        return $this->productRepository->getById($productId, false, $this->storeManager->getStore()->getId(), true);
    }
1142754
public static function delete_previous_evaluation_file($modelid, $timesplittingid) {
        if ($file = self::get_previous_evaluation_file($modelid, $timesplittingid)) {
            $file->delete();
            return true;
        }

        return false;
    }
1134315
protected function flushForModel($index, $modelId)
    {
        $query = [
            'index' => $index,
            'body' => [
                'query' => [
                    'bool' => [
                        'filter' => [
                            'bool' => [
                                'must' => [
                                    'term' => ['model_id' => $modelId]
                                ]
                            ]
                        ],
                    ]
                ]
            ]
        ];
        $pks = IndexHelper::primaryKeysByCondition($this->client, $query);
        if (count($pks) > 0) {
            $params = ['body' => []];
            foreach ($pks as $id => $types) {
                foreach ($types as $type) {
                    $params['body'][] = [
                        'delete' => [
                            '_index' => $index,
                            '_type' => $type,
                            '_id' => $id
                        ]
                    ];
                }
            }
            $this->client->bulk($params);
        }
    }
341296
private function _first(callable $callback = null)
    {
        $values = $this->getValues();
        if ($callback){
            foreach($values as $key => $value){
                if ($callback($value, $key)){
                    return $value;
                }
            }
        }
        else{
            return empty($values) ? null : $values[0];
        }
        return null;
    }
1055526
public function addFooter($filename, $modelId = null)
    {   
        $tempFilename = str_replace($this->fileExtension, '', $filename);
        $this->model = $this->getModel();
        $this->modelId = $modelId;

        if ($this->batch) {
            $iteration = $this->batch->getSessionVariable('iteration');
        } else {
            $this->_session = new \Zend_Session_Namespace(__CLASS__);
            $iteration = $this->_session->iteration;
        }

        $writer = new XMLWriter();
        $writer->openURI($filename);
        $writer->setIndent(true);
        $writer->startDocument('1.0', 'UTF-8');
        //Added padding comparable to xml output;
        $writer->startElement('dta');

            $this->createHeaderFile($writer, $filename);

            $writer->startElement('data');

            for($i=0;$i<$iteration;$i++) {
                $partFilename = $tempFilename . '_' . $i . $this->fileExtension;

                $data = file_get_contents($partFilename);
                $writer->writeRaw($data);
                unlink($partFilename);
            }

            $writer->endElement();

        $writer->endElement();

        // reset rowNumber
        if ($this->batch) {
            $this->batch->setSessionVariable('rowNumber', 0);
            $this->batch->setSessionVariable('iteration', 0);
            $this->batch->setSessionVariable('stringSizes', array());
        } else {
            $this->_session->rowNumber = 0;
            $this->_session->iteration = 0;
            $this->_session->stringSizes = array();
        }
    }
222451
protected function guardNotEditOnly(ModelIdInterface $modelId)
    {
        if ($this->getEnvironment()->getDataDefinition()->getBasicDefinition()->isEditOnlyMode()) {
            throw new EditOnlyModeException($modelId->getDataProviderName());
        }
    }
797335
protected function getModelFromSerializedId($serializedId)
    {
        $modelId      = ModelId::fromSerialized($serializedId);
        $dataProvider = $this->getEnvironment()->getDataProvider($modelId->getDataProviderName());
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        if (null === $model) {
            $event = new LogEvent(
                'A record with the ID "' . $serializedId . '" does not exist in "' .
                $this->getEnvironment()->getDataDefinition()->getName() . '"',
                'Ajax executePostActions()',
                TL_ERROR
            );
            $this->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::SYSTEM_LOG, $event);

            throw new ResponseException(new Response(Response::$statusTexts[400], 400));
        }

        return $model;
    }
1016268
private function getCachedData($locationId) {
    if (!self::DEBUG_MODE) {
      return NULL;
    }

    $cachedData = $this->cacheBackend->get(get_class($this) . '_embed_' . $locationId);
    if ($cachedData) {
      return $cachedData->data;
    }

    return NULL;
  }
282500
protected function load($modelId, $file) {
        
        $easyRdf = new EasyRdf_Graph();
        $easyRdf->parseFile($file);
        
        foreach ($easyRdf->toRdfPhp() as $subject => $propertiesValues){
            foreach ($propertiesValues as $predicate => $values){
                foreach ($values as $k => $v) {
                    $triple = new core_kernel_classes_Triple();
                    $triple->modelid = $modelId;
                    $triple->subject = $subject;
                    $triple->predicate = $predicate;
                    $triple->object = $v['value'];
                    $triple->lg = isset($v['lang']) ? $v['lang'] : null;
                    $this->triples[] = $triple;
                }
            }
        }
    }
1281160
public function parse($modelId, $rawConfig, $allowEmpty = false) {
        if (!is_null($rawConfig)) {
            $this->_validate($rawConfig, $allowEmpty);
            return $rawConfig;
        } else throw new Exception("The {$modelId} configuration is NULL.");
    }