<commit_before><?php
class Tags
{
	public static function getAll($cnx)
	{
		$tags = array();
		if($cnx)
		{
			$result = pg_query($cnx, "SELECT label FROM tag_labels ORDER BY label");

			if($result !== false)
			{
				while(($row = pg_fetch_assoc($result)) !== false)
				{
					$tags[] = $row['label'];
				}
			}
		}
		return $tags;
	}

	public static function getTagIdByLabel($user_id, $label, $cnx)
	{
		$result = pg_query($cnx, "SELECT id FROM tag_labels WHERE owner = " . pg_escape_string($user_id) . " AND label = '" . pg_escape_string($label) . "' LIMIT 1");
		if($result && pg_num_rows($result) > 0)
		{
			$row = pg_fetch_assoc($result, 0);
			return $row['id'];
		}

		return false;
	}
}
?><commit_msg>Renamed getTagIdByLabel() to getIdByLabel(). Added addLabel() and removeLabel(). Added support for owner.<commit_after><?php
class Tags
{
	public static function getAll($user_id, $cnx)
	{
		$tags = array();
		if($cnx)
		{
			$result = pg_query($cnx, "SELECT label FROM tag_labels WHERE owner = " . $user_id . " ORDER BY label");

			if($result !== false)
			{
				while(($row = pg_fetch_assoc($result)) !== false)
				{
					$tags[] = $row['label'];
				}
			}
		}
		return $tags;
	}

	public static function addLabel($user_id, $label, $cnx)
	{
		$result = pg_query($cnx, "INSERT INTO tag_labels (label, owner) VALUES ('" . pg_escape_string($label) . "', " . $user_id . ") RETURNING id");
		if(pg_num_rows($result) == 1)
		{
			$row = pg_fetch_assoc($result, 0);
			return $row['id'];
		}

		return false;
	}

	public static function getIdByLabel($user_id, $label, $cnx)
	{
		$result = pg_query($cnx, "SELECT id FROM tag_labels WHERE label = '" . pg_escape_string($label) . "' AND owner = " . $user_id . " LIMIT 1");

		if(pg_num_rows($result) == 1)
		{
			$row = pg_fetch_assoc($result, 0);

			return $row['id'];
		}

		//Label doesn't exist
		return false;
	}

	public static function removeLabel($owner, $label, $cnx)
	{
		$result = pg_query($cnx, "DELETE FROM tag_labels WHERE label = '" . pg_escape_string($label) . "' AND owner = " . $owner);

		if($result)
		{
			return true;
		}
		return false;
	}
}
?>
{'fraction_non_alphanumeric': 0.17544684854186265, 'fraction_numerical': 0.0037629350893697085, 'mean_word_length': 3.4684873949579833, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '3045187', 'n_tokens_mistral': 905, 'n_tokens_neox': 793, 'n_words': 182}