/**
  * Returns the appropiate slug to save
  *
  * @param   BaseObject  $node
  * @param   string      $from     Column from which slug is generated
  */
 public function createSlug(BaseObject $node)
 {
     $peer_name = get_class($node->getPeer());
     $node_class = get_class($node);
     $getter = self::forgeMethodName($node, 'get', 'from');
     $column = self::getColumnConstant($node_class, 'to');
     $conf_separator = sprintf('propel_behavior_sfPropelActAsSluggableBehavior_%s_separator', $node_class);
     $separator = sfConfig::has($conf_separator) ? sfConfig::get($conf_separator) : $this->default_separator;
     $slug = sfPropelActAsSluggableBehaviorUtils::stripText($node->{$getter}(), $separator);
     $ret = $slug;
     $i = 0;
     $conf_scope = sprintf('propel_behavior_sfPropelActAsSluggableBehavior_%s_scope', $node_class);
     $scope = sfConfig::has($conf_scope) ? sfConfig::get($conf_scope) : array();
     $scope_criteria = new Criteria();
     foreach ($scope as $my_col) {
         $getter = 'get' . call_user_func(array($peer_name, 'translateFieldName'), $column, BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
         $scope_criteria->add($column, $node->{$getter}());
     }
     while (1) {
         $c = clone $scope_criteria;
         $c->add($column, $ret);
         $entry = call_user_func(array($peer_name, 'doSelectOne'), $c);
         if ($entry && !$entry->equals($node)) {
             $i++;
             $ret = $slug . $separator . $i;
         } else {
             return $ret;
         }
     }
 }
Beispiel #2
0
 public function addTerm($term_name, $category = false)
 {
     if (is_numeric($term_name)) {
         $term = TermPeer::retrieveByPk($term_name);
     } else {
         $slug = sfPropelActAsSluggableBehaviorUtils::stripText(ForgeToolkit::normalizeTag($term_name), '_');
         $term = TermPeer::retrieveBySlug($slug);
     }
     if (!$term) {
         $term = new Term();
         $term->setTitle(ForgeToolkit::normalizeTag($term_name));
         $term->setCategory(false);
         $term->save();
     }
     try {
         $rel = new TermRelationship();
         $rel->setTerm($term);
         $rel->setPlugin($this);
         $rel->save();
     } catch (PropelException $e) {
         // avoid duplicates
     }
 }