Jump to content

Pobranie pierwszej litery kategorii produktu


Go to solution Solved by DawPi,

Recommended Posts

Posted

Cześć. Od kilku godzin próbuję zwrócić pierwszą literę nazwy kategorii produktów. Niestety próby użycia preg_match oraz substr nie działają, zamiast litery pierwszej pojawiają się liczby albo jakieś inne litery z frazy MD5 tylko w momencie użycia tych dwóch funkcji. Próbowałem również zrobić prowizorkę i zwrócić nazwę bezpośrednio przez pobranie ciągu języka.

 

{{foreach \IPS\nexus\Package\Group::rootsWithViewablePackages() as $group}}
  {{$llang = \IPS\Member::loggedIn()->language()->addToStack( \IPS\nexus\Package\Group::$titleLangPrefix . $group->id, TRUE, array( 'ucfirst' => TRUE ) );}}
  {{$xx = mb_ucfirst($group->_title);}}
  {$xx}
{{endforeach}}

 

żadne rozwiązania nie działają, próba pobrania {$llang} i {$xx} zwraca cały czas wartości z kodu MD5 soli języka. Jest na to jakiś inny sposób?

Posted
45 minut temu, DawPi napisał(a):
{{$groupName = \IPS\Member::loggedIn()->language()->get( 'core_group_' . $group->id );}}

 

lang_not_exists__core_group_38

 

Próbowałem nawet w taki sposób przetestować, lecz dalej zwraca string w MD5 po użyciu substr. Gdy normalnie zwracam pojawia się string(32) "tresc".

 

$db = \IPS\Db::i()->select( '*', 'nexus_package_groups' );
foreach ($db as $dx) {
	$title = \IPS\nexus\Package\Group::load( $dx['pg_id'] )->_title;
	echo $title .' / '.substr($title, 0, 1);
}

 

Ten kod zwraca: Call of Duty / 32b1ko4n1iosi12ed

  • Manager
Posted

Ajjj, kategorii produktu, a nie grupy! Sorry. Tak zrób wg Twojego kodu:

{{foreach \IPS\nexus\Package\Group::rootsWithViewablePackages() as $group}}
  {{$llang = \IPS\Member::loggedIn()->language()->get( 'nexus_pgroup_' . $group->id );}}
  {{$xx = mb_ucfirst($group->_title);}}
  {$xx}
{{endforeach}}

O ile to $group to jest to o co Ci chodzi.

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Posted
8 godzin temu, DawPi napisał(a):

Ajjj, kategorii produktu, a nie grupy! Sorry. Tak zrób wg Twojego kodu:

{{foreach \IPS\nexus\Package\Group::rootsWithViewablePackages() as $group}}
  {{$llang = \IPS\Member::loggedIn()->language()->get( 'nexus_pgroup_' . $group->id );}}
  {{$xx = mb_ucfirst($group->_title);}}
  {$xx}
{{endforeach}}

O ile to $group to jest to o co Ci chodzi.

 

image.thumb.png.d924594885f4182a407992a332027e8a.png

  • Manager
Posted
{{foreach \IPS\nexus\Package\Group::rootsWithViewablePackages() as $group}}
  {{$llang = \IPS\Member::loggedIn()->language()->get( 'nexus_pgroup_' . $group->id );}}
  {{$xx = mb_ucfirst($llang);}}
  {$xx}
{{endforeach}}

 

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Posted
2 godziny temu, DawPi napisał(a):
{{foreach \IPS\nexus\Package\Group::rootsWithViewablePackages() as $group}}
  {{$llang = \IPS\Member::loggedIn()->language()->get( 'nexus_pgroup_' . $group->id );}}
  {{$xx = mb_ucfirst($llang);}}
  {$xx}
{{endforeach}}

 

image.thumb.png.e6c96bc8e60bee1037b99eeb761c1645.png

 

 

Posted
6 minut temu, DawPi napisał(a):

image.png

 

image.png

 

image.png

 

Ja chcę aby zwracało pierwszą literę. Robię wyszukiwanie alfabetyczne i potrzebuję aby to działało 😕

  • Manager
  • Solution
Posted

Jak chcesz pierwszą to dlaczego dajesz kod na powiększenie pierwszego znaku?

{{$xx = mb_ucfirst($llang);}}

 

{{foreach \IPS\nexus\Package\Group::rootsWithViewablePackages() as $group}}
  {{$llang = \IPS\Member::loggedIn()->language()->get( 'nexus_pgroup_' . $group->id );}}
  {{$xx = mb_substr($llang, 0, 1);}}
  {$xx}
{{endforeach}}

 

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Posted
9 godzin temu, DawPi napisał(a):

Jak chcesz pierwszą to dlaczego dajesz kod na powiększenie pierwszego znaku?

{{$xx = mb_ucfirst($llang);}}

 

{{foreach \IPS\nexus\Package\Group::rootsWithViewablePackages() as $group}}
  {{$llang = \IPS\Member::loggedIn()->language()->get( 'nexus_pgroup_' . $group->id );}}
  {{$xx = mb_substr($llang, 0, 1);}}
  {$xx}
{{endforeach}}

 

Mój błąd. Ale to nic nie zmienia takie same są wartości co na screenie. Widzę że operacje na stringach nie działają na tłumaczeniowych frazach. Jest na to jakieś rozwiązanie?

  • Manager
Posted

Jak nie działają? Pokazałem na screenie, że działają. W dodatku właśnie to robi ta metoda (get):

	/**
	 * Get Language String
	 *
	 * @param	string|array	$key	Language key or array of keys
	 * @return	string|array			Language string or array of key => string pairs
	 */
	public function get( $key )
	{
		$return     = array();
		$keysToLoad = array();
		
		if ( \is_array( $key ) )
		{
			foreach( $key as $k )
			{
				if ( \in_array( $k, array_keys( $this->words ), true ) )
				{
					$return[ $k ] = $this->words[ $k ];
				}
				else
				{
					$keysToLoad[] = "'" . \IPS\Db::i()->real_escape_string( $k ) . "'";
				}
			}
			
			if ( !\count( $keysToLoad ) )
			{
				return $return;
			}
		}
		else
		{
			if ( isset( $this->words[ $key ] ) )
			{
				return $this->words[ $key ];
			}

			$keysToLoad = array( "'" . \IPS\Db::i()->real_escape_string( $key ) . "'" );
		}

		foreach( \IPS\Db::i()->select( 'word_key, word_default, word_custom', 'core_sys_lang_words', array( "lang_id=? AND word_key IN(" . implode( ",", $keysToLoad ) . ")", $this->id ) ) as $lang )
		{
			$value = $lang['word_custom'] ?: $lang['word_default'];
			
			$this->words[ $lang['word_key'] ] = $value;
			$return[ $lang['word_key' ] ]     = $value;
		}
		
		/* If we're using an array, fill any missings strings with NULL to prevent duplicate queries */
		if ( \is_array( $key ) )
		{
			foreach( $key as $k )
			{
				if ( !\in_array( $k, $return ) and ! array_key_exists( $k, $this->words ) )
				{
					$return[ $k ] = NULL;
					$this->words[ $k ] = NULL;
				}
			}
		}
		
		if ( !\count( $return ) )
		{
			throw new \UnderflowException( ( \is_string( $key ) ? 'lang_not_exists__' . $key : 'lang_not_exists__' . implode( ',', $key ) ) );
		}
		
		return \is_string( $key ) ? $this->words[ $key ] : $return;
	}

 

  • Thanks 1

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Posted
10 godzin temu, DawPi napisał(a):

Jak nie działają? Pokazałem na screenie, że działają. W dodatku właśnie to robi ta metoda (get):

	/**
	 * Get Language String
	 *
	 * @param	string|array	$key	Language key or array of keys
	 * @return	string|array			Language string or array of key => string pairs
	 */
	public function get( $key )
	{
		$return     = array();
		$keysToLoad = array();
		
		if ( \is_array( $key ) )
		{
			foreach( $key as $k )
			{
				if ( \in_array( $k, array_keys( $this->words ), true ) )
				{
					$return[ $k ] = $this->words[ $k ];
				}
				else
				{
					$keysToLoad[] = "'" . \IPS\Db::i()->real_escape_string( $k ) . "'";
				}
			}
			
			if ( !\count( $keysToLoad ) )
			{
				return $return;
			}
		}
		else
		{
			if ( isset( $this->words[ $key ] ) )
			{
				return $this->words[ $key ];
			}

			$keysToLoad = array( "'" . \IPS\Db::i()->real_escape_string( $key ) . "'" );
		}

		foreach( \IPS\Db::i()->select( 'word_key, word_default, word_custom', 'core_sys_lang_words', array( "lang_id=? AND word_key IN(" . implode( ",", $keysToLoad ) . ")", $this->id ) ) as $lang )
		{
			$value = $lang['word_custom'] ?: $lang['word_default'];
			
			$this->words[ $lang['word_key'] ] = $value;
			$return[ $lang['word_key' ] ]     = $value;
		}
		
		/* If we're using an array, fill any missings strings with NULL to prevent duplicate queries */
		if ( \is_array( $key ) )
		{
			foreach( $key as $k )
			{
				if ( !\in_array( $k, $return ) and ! array_key_exists( $k, $this->words ) )
				{
					$return[ $k ] = NULL;
					$this->words[ $k ] = NULL;
				}
			}
		}
		
		if ( !\count( $return ) )
		{
			throw new \UnderflowException( ( \is_string( $key ) ? 'lang_not_exists__' . $key : 'lang_not_exists__' . implode( ',', $key ) ) );
		}
		
		return \is_string( $key ) ? $this->words[ $key ] : $return;
	}

 

 

Moje niedopatrzenie. Działa. Dziękuję.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.