<commit_before><?php

/**
 * @module Assets
 */
/**
 * Methods for manipulating "Assets/NFT/Series" streams
 * @class Assets_NFT_Series
 */
class Assets_NFT_Series
{
	static $categoryStreamName = "Assets/NFT/series";
	static $relationType = "Assets/NFT/series";
	static $streamType = "Assets/NFT/series";

	/**
	 * Get or create new NFT empty stream for composer
	 * @method getComposerStream
	 * @param {string} [$userId=null] If null loggedin user id used
	 * @return {Streams_Stream}
	 */
	static function getComposerStream ($userId=null) {
		$userId = $userId ?: Users::loggedInUser(true)->id;

		$relations = Streams_RelatedTo::select()->where(array(
			"toPublisherId" => $userId,
			"toStreamName" => self::$categoryStreamName,
			"type" => "new"
		))->ignoreCache()->fetchDbRows();

		if (empty($relations)) {
			$data = Q::event("Users/external/response/data", array("userId"));
			$stream = Streams::create($userId, $userId, "Assets/NFT/series", array(
				"attributes" => array(
					"author" => $data["wallet"]
				)
			), array(
				"publisherId" => $userId,
				"streamName" => self::$categoryStreamName,
				"type" => "new"
			));
			$maxWeight = Streams_RelatedTo::select()->where(array(
				"toPublisherId" => $userId,
				"toStreamName" => self::$categoryStreamName,
				"type" => self::$relationType
			))->orderBy("weight", false)->limit(1)->fetchDbRow();
			$maxWeight = $maxWeight ? (int)$maxWeight->weight : 0;
			$lastPart = explode("/", $stream->name);
			$lastPart = end($lastPart);
			$tokenId = Streams::toHexString($userId, "$maxWeight/$lastPart");
			$tokenId = preg_replace("/0+$/", "", $tokenId);
			$seriesId = substr($tokenId, 0, 16);
			$stream->setAttribute("tokenId", $tokenId)->save();
			$stream->setAttribute("seriesId", $seriesId)->save();

			$stream->join(compact("userId"));
			return $stream;
		} else {
			$relation = reset($relations);
			$stream = Streams::fetchOne($relation->fromPublisherId, $relation->fromPublisherId, $relation->fromStreamName);
			return $stream;
		}
	}

	/**
	 * Updated NFT stream with new data
	 * @method update
	 * @param {Streams_Stream} $stream - NFT stream
	 * @param {array} $fields - Array of data to update stream
	 * @return {Streams_Stream}
	 */
	static function update ($stream, $fields) {
		$userId = Users::loggedInUser(true)->id;
		$fieldsUpdated = false;
		foreach (array("title", "content") as $field) {
			if (!Q::ifset($fields, $field)) {
				continue;<commit_msg>Fixed Assets_NFT_series::getComposerStream method. Need to substr 18 chars when parse tokenId to seriesId, because 0x<commit_after><?php

/**
 * @module Assets
 */
/**
 * Methods for manipulating "Assets/NFT/Series" streams
 * @class Assets_NFT_Series
 */
class Assets_NFT_Series
{
	static $categoryStreamName = "Assets/NFT/series";
	static $relationType = "Assets/NFT/series";
	static $streamType = "Assets/NFT/series";

	/**
	 * Get or create new NFT empty stream for composer
	 * @method getComposerStream
	 * @param {string} [$userId=null] If null loggedin user id used
	 * @return {Streams_Stream}
	 */
	static function getComposerStream ($userId=null) {
		$userId = $userId ?: Users::loggedInUser(true)->id;

		$relations = Streams_RelatedTo::select()->where(array(
			"toPublisherId" => $userId,
			"toStreamName" => self::$categoryStreamName,
			"type" => "new"
		))->ignoreCache()->fetchDbRows();

		if (empty($relations)) {
			$data = Q::event("Users/external/response/data", array("userId"));
			$stream = Streams::create($userId, $userId, "Assets/NFT/series", array(
				"attributes" => array(
					"author" => $data["wallet"]
				)
			), array(
				"publisherId" => $userId,
				"streamName" => self::$categoryStreamName,
				"type" => "new"
			));
			$maxWeight = Streams_RelatedTo::select()->where(array(
				"toPublisherId" => $userId,
				"toStreamName" => self::$categoryStreamName,
				"type" => self::$relationType
			))->orderBy("weight", false)->limit(1)->fetchDbRow();
			$maxWeight = $maxWeight ? (int)$maxWeight->weight : 0;
			$lastPart = explode("/", $stream->name);
			$lastPart = end($lastPart);
			$tokenId = Streams::toHexString($userId, "$maxWeight/$lastPart");
			$tokenId = preg_replace("/0+$/", "", $tokenId);
			$seriesId = substr($tokenId, 0, 18);
			$stream->setAttribute("tokenId", $tokenId)->save();
			$stream->setAttribute("seriesId", $seriesId)->save();

			$stream->join(compact("userId"));
			return $stream;
		} else {
			$relation = reset($relations);
			$stream = Streams::fetchOne($relation->fromPublisherId, $relation->fromPublisherId, $relation->fromStreamName);
			return $stream;
		}
	}

	/**
	 * Updated NFT stream with new data
	 * @method update
	 * @param {Streams_Stream} $stream - NFT stream
	 * @param {array} $fields - Array of data to update stream
	 * @return {Streams_Stream}
	 */
	static function update ($stream, $fields) {
		$userId = Users::loggedInUser(true)->id;
		$fieldsUpdated = false;
		foreach (array("title", "content") as $field) {
			if (!Q::ifset($fields, $field)) {
				continue;
{'fraction_non_alphanumeric': 0.18189070602313523, 'fraction_numerical': 0.002991623454327882, 'mean_word_length': 4.486870897155361, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6956056', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1651, 'n_words': 347}