Habari\Term::setslug PHP Method

setslug() protected method

Generate a new slug for the post.
protected setslug ( ) : string
return string The slug
    protected function setslug()
    {
        $value = '';
        // determine the base value from:
        // - the new slug
        if (isset($this->newfields['term']) && $this->newfields['term'] != '') {
            $value = $this->newfields['term'];
        } elseif ($this->fields['term'] != '') {
            $value = $this->fields['term'];
        } elseif (isset($this->newfields['term_display']) && $this->newfields['term_display'] != '') {
            $value = $this->newfields['term_display'];
        } elseif ($this->fields['term_display'] != '') {
            $value = $this->fields['term_display'];
        }
        // make sure our slug is unique
        $slug = Plugins::filter('term_setslug', $value);
        $slug = Utils::slugify($slug);
        $postfix = '';
        $postfixcount = 0;
        do {
            if (!($slugcount = DB::get_row('SELECT COUNT(term) AS ct FROM {terms} WHERE term = ? AND vocabulary_id = ?;', array($slug . $postfix, $this->fields['vocabulary_id'])))) {
                Utils::debug(DB::get_errors());
                exit;
            }
            if ($slugcount->ct != 0) {
                $postfix = "-" . ++$postfixcount;
            }
        } while ($slugcount->ct != 0);
        return $this->newfields['term'] = $slug . $postfix;
    }