<commit_before><?php
/**
 * Created by IntelliJ IDEA.
 * User: ioana
 * Date: 29/09/14
 * Time: 11:08
 */

class PlentymarketsTranslation 
{
	/**
	 *
	 * @var PlentymarketsTranslation
	 */
	protected static $Instance;


	/**
	 * I am the singleton method
	 *
	 * @return PlentymarketsTranslation
	 */
	public static function getInstance()
	{
		if (!self::$Instance instanceof self)
		{
			self::$Instance = new self();
		}
		return self::$Instance;
	}

	/**
	 * Check if the shop is the main shop
	 * @param int $shopId
	 * @return bool
	 */
	public static function isMainShop($shopId)
	{
		try
		{
			$sql = 'SELECT COUNT(*) AS "shopCount"
				FROM s_core_shops
				WHERE id ='. $shopId .
				' AND main_id IS NULL';

			$shopCount = Shopware()->Db()->query($sql)->fetchAll();

		}catch (Exception $e)
		{
			$shopCount[0]['shopCount'] = null;
		}

		if($shopCount[0]['shopCount'] > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * @description Get the current language of the shop with id = shopId
	 * @param int $shopId
	 * @return array
	 */
	public static function getShopMainLanguage($shopId)
	{
		/** @var $shopRepositoryList Shopware\Models\Shop\Repository */
		$shopRepositoryList = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');
		
		/** @var $shopRepository Shopware\Models\Shop\Shop */
		$shopRepository = $shopRepositoryList->getActiveById($shopId);
		
		$mainLang[$shopRepository->getLocale()->getId()] = array( 	'language' => $shopRepository->getLocale()->getLanguage(),
																	'locale' => $shopRepository->getLocale()->getLocale(),
																	'mainShopId' => NULL); // the main shop has no main shop Id => only language shops have a main shop ID !! TB: s_core_shops

		return $mainLang;
	}

	/**
	 * @description Convert the langugae format for plenty (e.g en_GB  = en)
	 * @param string $locale
	 * @return string
	 */
	public static function getPlentyLocaleFormat($locale)
	{
		$parts = explode('_',$locale);
		
		return $parts[0];
	}

	/**
	 * Return the total number of the shop languages (main languages + nr of shop languages)
	 * @param int $shopID
	 * @return int
	 */
	public static function getShopLanguageCount($shopID)
	{
		/** @var $shopRepositoryList Shopware\Models\Shop\Repository */
		$shopRepositoryList = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');

		$languageShops = $shopRepositoryList->findBy(array('mainId' => $shopID));
		
		$count = 1; // the main language
		
		// if language shops are found
		if(count($languageShops) > 0)
		{	
			// return the total number of shop languages (main language + nr of shop languages )
			return $count + count($languageShops);
		}
		else
		{	
			// the shop has only one language (main language)
			return $count;
		}	
	}
	
	/**
	 * @description Get all active languages (main language und all other activated languages) of the shop with id = shopId
	 * @param int $shopId
	 * @return array
	 */
	public static function getShopActiveLanguages($shopId)
	{

		// array for saving the languages of the shop
		$activeLanguages = array();
		
		
		// add the main language shop
		$mainLang = PlentymarketsTranslation::getInstance()->getShopMainLanguage($shopId);
		
		$activeLanguages[key($mainLang)] = array_pop($mainLang);
		
		/** @var $shopRepositoryList Shopware\Models\Shop\Repository */
		$shopRepositoryList = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');
		
		// get all language shops of the shop with id = $shopId =>  find all shops where mainId = shopId 
		$languageShops = $shopRepositoryList->findBy(array('mainId' => $shopId));

		/** @var $languageShop Shopware\Models\Shop\Shop */
		foreach($languageShops as $languageShop)
		{	
			// locale id = language id in shopware !! 
			$activeLanguages[$languageShop->getLocale()->getId()] = array(	'language' => $languageShop->getLocale()->getLanguage(), // e.g language = Englisch
																			'locale' => $languageShop->getLocale()->getLocale(), // e.g locale = en_GB 
																			'mainShopId' => $shopId);  
		}
		
		return $activeLanguages;
	}

	/**
	 * @description Get the language infos of the locale from shopware
	 * @param string locale
	 * @return array
	 */
	public static function getLanguageByLocale($locale)
	{<commit_msg>FIX Entity error<commit_after><?php
/**
 * Created by IntelliJ IDEA.
 * User: ioana
 * Date: 29/09/14
 * Time: 11:08
 */

class PlentymarketsTranslation 
{
	/**
	 *
	 * @var PlentymarketsTranslation
	 */
	protected static $Instance;


	/**
	 * I am the singleton method
	 *
	 * @return PlentymarketsTranslation
	 */
	public static function getInstance()
	{
		if (!self::$Instance instanceof self)
		{
			self::$Instance = new self();
		}
		return self::$Instance;
	}

	/**
	 * Check if the shop is the main shop
	 * @param int $shopId
	 * @return bool
	 */
	public static function isMainShop($shopId)
	{
		try
		{
			$sql = 'SELECT COUNT(*) AS "shopCount"
				FROM s_core_shops
				WHERE id ='. $shopId .
				' AND main_id IS NULL';

			$shopCount = Shopware()->Db()->query($sql)->fetchAll();

		}catch (Exception $e)
		{
			$shopCount[0]['shopCount'] = null;
		}

		if($shopCount[0]['shopCount'] > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * @description Get the current language of the shop with id = shopId
	 * @param int $shopId
	 * @return array
	 */
	public static function getShopMainLanguage($shopId)
	{
		/** @var $shopRepositoryList Shopware\Models\Shop\Repository */
		$shopRepositoryList = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');
		
		/** @var $shopRepository Shopware\Models\Shop\Shop */
		$shopRepository = $shopRepositoryList->getActiveById($shopId);
		
		$mainLang[$shopRepository->getLocale()->getId()] = array( 	'language' => $shopRepository->getLocale()->getLanguage(),
																	'locale' => $shopRepository->getLocale()->getLocale(),
																	'mainShopId' => NULL); // the main shop has no main shop Id => only language shops have a main shop ID !! TB: s_core_shops

		return $mainLang;
	}

	/**
	 * @description Convert the langugae format for plenty (e.g en_GB  = en)
	 * @param string $locale
	 * @return string
	 */
	public static function getPlentyLocaleFormat($locale)
	{
		$parts = explode('_',$locale);
		
		return $parts[0];
	}

	/**
	 * Return the total number of the shop languages (main languages + nr of shop languages)
	 * @param int $shopID
	 * @return int
	 */
	public static function getShopLanguageCount($shopID)
	{
		/** @var $shopRepositoryList Shopware\Models\Shop\Repository */
		$shopRepositoryList = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');

		$languageShops = $shopRepositoryList->findBy(array('mainId' => $shopID));
		
		$count = 1; // the main language
		
		// if language shops are found
		if(count($languageShops) > 0)
		{	
			// return the total number of shop languages (main language + nr of shop languages )
			return $count + count($languageShops);
		}
		else
		{	
			// the shop has only one language (main language)
			return $count;
		}	
	}
	
	/**
	 * @description Get all active languages (main language und all other activated languages) of the shop with id = shopId
	 * @param int $shopId
	 * @return array
	 */
	public static function getShopActiveLanguages($shopId)
	{

		// array for saving the languages of the shop
		$activeLanguages = array();
		
		
		// add the main language shop
		$mainLang = PlentymarketsTranslation::getInstance()->getShopMainLanguage($shopId);
		
		$activeLanguages[key($mainLang)] = array_pop($mainLang);
		
		/** @var $shopRepositoryList Shopware\Models\Shop\Repository */
		$shopRepositoryList = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');
		
		// get all language shops of the shop with id = $shopId =>  find all shops where mainId = shopId 
		$languageShops = $shopRepositoryList->findBy(array('mainId' => $shopId));

		/** @var $languageShop Shopware\Models\Shop\Shop */
		foreach($languageShops as $languageShop)
		{	
			// locale id = language id in shopware !! 
			$activeLanguages[$languageShop->getLocale()->getId()] = array(	'language' => $languageShop->getLocale()->getLanguage(), // e.g language = Englisch
																			'locale' => $languageShop->getLocale()->getLocale(), // e.g locale = en_GB 
																			'mainShopId' => $shopId);  
		}

		//
		Shopware()->Models()->clear();

		return $activeLanguages;
	}

	/**
	 * @description Get the language infos of the locale from shopware
	 * @param string locale
	 * @return array
	 */
	public static function getLanguageByLocale($locale)
	{
{'fraction_non_alphanumeric': 0.13988372093023255, 'fraction_numerical': 0.0037209302325581397, 'mean_word_length': 3.3837920489296636, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, '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': '4143476', 'n_tokens_mistral': 3046, 'n_tokens_neox': 2586, 'n_words': 707}