private function generateShortname($instance, $text, $iteration = 0) { $shortname = SwatString::condenseToName($text); if ($iteration != 0) { $shortname = $shortname . (string) $iteration; } $sql = 'select id from BlorgAuthor where shortname = %s and instance = %s'; $sql = sprintf($sql, $this->table->process->dst_db->quote($shortname, 'text'), $this->table->process->dst_db->quote($instance, 'integer')); $rs = SwatDB::query($this->table->process->dst_db, $sql); if (count($rs) == 0) { return $shortname; } else { return $this->generateShortname($instance, $text, $iteration + 1); } }
private function generateShortname($text, $iteration = 0) { if ($iteration === 0 && preg_match('/^[a-z0-9_-]+$/', $text)) { return $text; } $shortname = SwatString::condenseToName($text); if ($iteration != 0) { $shortname = $shortname . (string) $iteration; } $sql = sprintf('select id from BlorgPost where shortname = %s and instance = %s', $this->table->process->dst_db->quote($shortname, 'text'), $this->table->process->dst_db->quote($this->table->process->instance, 'integer')); $rs = SwatDB::query($this->table->process->dst_db, $sql); if (count($rs) == 0) { return $shortname; } else { return $this->generateShortname($text, $iteration + 1); } }
/** * Generate a shortname * * @param string $text Text to generate the shortname from. * @return string A shortname. */ protected function generateShortname($text) { $shortname_base = SwatString::condenseToName($text); $count = 1; $shortname = $shortname_base; while ($this->validateShortname($shortname) === false) { $shortname = $shortname_base . $count++; } return $shortname; }
protected function getPostShortname(BlorgPost $post) { $title_value = $post->title == '' ? $post->bodytext : $post->title; $shortname_base = SwatString::condenseToName($title_value); $count = 1; $shortname = $shortname_base; while ($this->isShortnameValid($post, $shortname) === false) { $shortname = $shortname_base . $count++; } return $shortname; }