Creates a new empty instance in DB and mark its status as INCOMPLETE

@param int $definitionid
@param int $raterid
@param int $itemid
@return int id of the created instance
766757
public static function create_new($definitionid, $raterid, $itemid) {
        global $DB;
        $instance = new stdClass();
        $instance->definitionid = $definitionid;
        $instance->raterid = $raterid;
        $instance->itemid = $itemid;
        $instance->status = self::INSTANCE_STATUS_INCOMPLETE;
        $instance->timemodified = time();
        $instance->feedbackformat = FORMAT_MOODLE;
        $instanceid = $DB->insert_record('grading_instances', $instance);
        return $instanceid;
    }
379686
public static function delete_data_for_instances(\context $context, array $itemids = []) {
        global $DB;
        $itemsql = '';
        $params = ['contextid' => $context->id];
        if (!empty($itemids)) {
            list($itemsql, $itemparams) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED);
            $params = array_merge($params, $itemparams);
            $itemsql = "AND itemid $itemsql";
        }
        $sql = "SELECT gi.id AS instanceid, gd.id, gd.method
                  FROM {grading_definitions} gd
                  JOIN {grading_instances} gi ON gi.definitionid = gd.id
                  JOIN {grading_areas} ga ON ga.id = gd.areaid
                 WHERE ga.contextid = :contextid $itemsql";
        $records = $DB->get_records_sql($sql, $params);
        if ($records) {
            $firstrecord = current($records);
            $method = $firstrecord->method;
            $instanceids = array_map(function($record) {
                return $record->instanceid;
            }, $records);
            manager::component_class_callback(
                "gradingform_{$method}",
                gradingform_provider_v2::class,
                'delete_gradingform_for_instances',
                [$instanceids]);
            // Delete grading_instances rows.
            $DB->delete_records_list('grading_instances', 'id', $instanceids);
        }
    }
454097
public function create($itemData, $rewriteIfExist = false)
    {
        $newData = $this->preCreate($itemData, $rewriteIfExist);
        $result = $this->dataStore->create($newData, $rewriteIfExist);

        return $this->postCreate($result, $newData, $rewriteIfExist);
    }
1061968
public static function create(int $itemid = 0) : \core_customfield\handler {
        if (static::$singleton === null) {
            self::$singleton = new static(0);
        }
        return self::$singleton;
    }
149347
public function getRankFromSiteId($siteId, $format = null)
    {
        $url = $this->sitesManager->getSiteUrlsFromId($siteId)[0];

        return $this->getRank($url, $format);
    }
892079
public function worker($serverId, $siteId, $workerId)
    {
        return new Worker(
            $this->get("servers/$serverId/sites/$siteId/workers/$workerId")['worker']
            + ['server_id' => $serverId, 'site_id' => $siteId], $this
        );
    }
773741
protected function _onChangeResetCounts($sOxid, $sVendorId = null, $sManufacturerId = null)
    {
        $myUtilsCount = \OxidEsales\Eshop\Core\Registry::getUtilsCount();

        if ($sVendorId) {
            $myUtilsCount->resetVendorArticleCount($sVendorId);
        }

        if ($sManufacturerId) {
            $myUtilsCount->resetManufacturerArticleCount($sManufacturerId);
        }

        $aCategoryIds = $this->getCategoryIds();
        //also reseting category counts
        foreach ($aCategoryIds as $sCatId) {
            $myUtilsCount->resetCatArticleCount($sCatId);
        }
    }
253932
protected function store_empty_document($contextid, $itemid) {
        // Store the file.
        $record = $this->get_stored_file_record($contextid, $itemid);
        $fs = get_file_storage();

        // Delete existing files first.
        $fs->delete_area_files($record->contextid, $record->component, $record->filearea, $record->itemid);

        $file = $fs->create_file_from_string($record, base64_decode(document_services::BLANK_PDF_BASE64));
        $this->pagecount = 1;

        $this->set_combined_file($file);

        return $this;
    }
227688
public function create($dataSetId, $columnId, $rowData)
    {
        $this->dataSetId = $dataSetId;
        $this->userId = $this->getEntityProvider()->getMe()->getId();
        $this->getLogger()->info('Creating row in dataSet ID ' . $dataSetId . ' Column ID ' . $columnId);
        $response = $this->doPost('/dataset/data/'. $dataSetId, [
            'dataSetColumnId_' . $columnId => $rowData
            ]);
        
        return $response;
    }
315425
public function reachedItemLimit( $storageId, $limit )
    {
        return (
            isset( $this->storageData[$storageId] )
            && count( $this->storageData[$storageId] ) >= $limit
        );
    }
1269066
public static function getItemIcon( int $item_id, array $attributes = [] ): Html
	{
		self::checkInit();

		$attrs = array_merge([ 'alt'   => $item_id ], self::getSetting(self::SET_CUSTOM_IMG_ATTRS, []), $attributes);
		$attrs['class'] = implode(' ', [
			self::getSetting(self::SET_DEFAULT_CLASS),
			self::getSetting(self::SET_ITEM_ICON_CLASS),
			@self::getSetting(self::SET_CUSTOM_IMG_ATTRS, [])['class'],
			@$attributes['class'],
		]);
		$attrs['src'] = self::getItemIconUrl($item_id);

		return Html::el('img', $attrs);
	}
1060515
public function create($data, $invoiceId, $invoiceItemId = null)
    {
        if (isset($invoiceItemId)) {
            return $this->client()->put(
                $data,
                'invoices/{invoiceId}/items/{invoiceItemId}',
                ['invoiceId' => $invoiceId, 'invoiceItemId' => $invoiceItemId]
            );
        }

        return $this->client()->post(
                $data,
                'invoices/{invoiceId}/items',
                ['invoiceId' => $invoiceId]
            );
    }
652812
private function generateFilenameByConsumerId($consumerId)
    {
        return rtrim($this->pidDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$consumerId.$this->pidFileExtension;
    }
921537
@Override
	@Transactional(enabled = false)
	public CPDefinition createCPDefinition(long CPDefinitionId) {
		return cpDefinitionPersistence.create(CPDefinitionId);
	}
709876
public function get_lineitem($courseid, $itemid, $typeid) {
        global $DB, $CFG;

        require_once($CFG->libdir . '/gradelib.php');
        $lineitem = \grade_item::fetch(array('id' => $itemid));
        if ($lineitem) {
            $gbs = $this->find_ltiservice_gradebookservice_for_lineitem($itemid);
            if (!$gbs) {
                // We will need to check if the activity related belongs to our tool proxy.
                $ltiactivity = $DB->get_record('lti', array('id' => $lineitem->iteminstance));
                if (($ltiactivity) && (isset($ltiactivity->typeid))) {
                    if ($ltiactivity->typeid != 0) {
                        $tool = $DB->get_record('lti_types', array('id' => $ltiactivity->typeid));
                    } else {
                        $tool = lti_get_tool_by_url_match($ltiactivity->toolurl, $courseid);
                        if (!$tool) {
                            $tool = lti_get_tool_by_url_match($ltiactivity->securetoolurl, $courseid);
                        }
                    }
                    if (is_null($typeid)) {
                        if (!(($tool) && ($this->get_tool_proxy()->id == $tool->toolproxyid))) {
                            return false;
                        }
                    } else {
                        if (!(($tool) && ($tool->id == $typeid))) {
                            return false;
                        }
                    }
                } else {
                    return false;
                }
            }
        }
        return $lineitem;
    }
1257155
public function isParentOf($itemId, $parentId)
    {
        $path = $this->getMelisKeyData($itemId);
        $paths = explode('/', $path);

        if (count($paths) > 0) {
            if (in_array($parentId, $paths)) {
                return true;
            }
        }

        return false;
    }
1363751
protected function getQueryBuilderForContainsMethods(string $itemType, int $itemUid) : QueryBuilder
    {
        $queryBuilder = $this->getQueryBuilder();
        return $queryBuilder->count('uid')->from($this->table)
            ->andWhere(
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter($itemType)),
                $queryBuilder->expr()->eq('item_uid', $itemUid)
            );
    }