Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Some idea to replace ETC with TruncateAt character (sort of split) #339

Open
seansan opened this issue May 4, 2017 · 0 comments
Open

Some idea to replace ETC with TruncateAt character (sort of split) #339

seansan opened this issue May 4, 2017 · 0 comments

Comments

@seansan
Copy link

seansan commented May 4, 2017

in class BL_CustomGrid_Helper_String extends Mage_Core_Helper_Abstract

    public function truncateText($string, $truncateLength = 80, $truncateAt = '', &$remainder = '', $breakWords = true)
    {
        $remainder = '';

        /** @var $helper Mage_Core_Helper_String */
        $helper = Mage::helper('core/string');
		
		// Change etc to work as truncate At character
		if (!empty($truncateAt)) {
			$truncPos = strrpos($string, $truncateAt); 
			if ($truncPos != false) {
				$truncateLength = $truncPos;
			}
		}

        if ($truncateLength == 0) {
            return '';
        }

        $originalLength = $helper->strlen($string);
        
        if ($originalLength > $truncateLength) {
            // remove // $truncateLength -= $helper->strlen($etc);
            
            if ($truncateLength <= 0) {
                return '';
            }
            
            $preparedString = $string;
            $preparedLength = $truncateLength;
            
            if (!$breakWords) {
                $preparedString = preg_replace('/\s+?(\S+)?$/u', '', $this->substr($string, 0, $truncateLength + 1));
                $preparedLength = $this->strlen($preparedString);
            }
            
            $remainder = $helper->substr($string, $preparedLength, $originalLength);
			return $helper->substr($preparedString, 0, $truncateLength);
        }
        
        return $string;
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant