src/ORM/FieldType/DBText.php
public function Summary($maxWords = 50, $add = '...')
    {
        // Get plain-text version
        $value = $this->Plain();
        if (!$value) {
            return '';
        }

        // Split on sentences (don't remove period)
        $sentences = array_filter(array_map(function ($str) {
            return trim($str);
        }, preg_split('@(?<=\.)@', $value)));
        $wordCount = count(preg_split('#\s+#u', $sentences[0]));

        // if the first sentence is too long, show only the first $maxWords words
        if ($wordCount > $maxWords) {
            return implode(' ', array_slice(explode(' ', $sentences[0]), 0, $maxWords)) . $add;
        }

        // add each sentence while there are enough words to do so
        $result = '';
        do {
            // Add next sentence
            $result .= ' ' . array_shift($sentences);

            // If more sentences to process, count number of words
            if ($sentences) {
                $wordCount += count(preg_split('#\s+#u', $sentences[0]));
            }
        } while ($wordCount < $maxWords && $sentences && trim($sentences[0]));

        return trim($result);
    }
public function Summary($maxWords = 50, $add = '...')
    {
        // Get plain-text version
        $value = $this->Plain();
        if (!$value) {
            return '';
        }

        // Split on sentences (don't remove period)
        $sentences = array_filter(array_map(function ($str) {
            return trim($str);
        }, preg_split('@(?<=\.)@', $value)));
        $wordCount = count(preg_split('#\s+#u', $sentences[0]));

        // if the first sentence is too long, show only the first $maxWords words
        if ($wordCount > $maxWords) {
            return implode(' ', array_slice(explode(' ', $sentences[0]), 0, $maxWords)) . $add;
        }

        // add each sentence while there are enough words to do so
        $result = '';
        do {
            // Add next sentence
            $result .= ' ' . array_shift($sentences);

            // If more sentences to process, count number of words
            if ($sentences) {
                $wordCount += count(preg_split('#\s+#u', $sentences[0]));
            }
        } while ($wordCount < $maxWords && $sentences && trim($sentences[0]));

        return trim($result);
    }
public function Summary ( $ maxWords = 50 , $ add = '...' ) { // Get plain-text version $ value = $ this -> Plain ( ) ; if ( ! $ value ) { return '' ; } // Split on sentences (don't remove period) $ sentences = array_filter ( array_map ( function ( $ str ) { return trim ( $ str ) ; } , preg_split ( '@(?<=\.)@' , $ value ) ) ) ; $ wordCount = count ( preg_split ( '#\s+#u' , $ sentences [ 0 ] ) ) ; // if the first sentence is too long, show only the first $maxWords words if ( $ wordCount > $ maxWords ) { return implode ( ' ' , array_slice ( explode ( ' ' , $ sentences [ 0 ] ) , 0 , $ maxWords ) ) . $ add ; } // add each sentence while there are enough words to do so $ result = '' ; do { // Add next sentence $ result .= ' ' . array_shift ( $ sentences ) ; // If more sentences to process, count number of words if ( $ sentences ) { $ wordCount += count ( preg_split ( '#\s+#u' , $ sentences [ 0 ] ) ) ; } } while ( $ wordCount < $ maxWords && $ sentences && trim ( $ sentences [ 0 ] ) ) ; return trim ( $ result ) ; }
Builds a basic summary, up to a maximum number of words

@param int $maxWords
@param string $add
@return string
Builds a basic summary up to a maximum number of words