/** * Removes a tag or a set of tags from the object. As usual, the second * parameter might be an array of tags or a comma-separated string. * * @param BaseObject $object * @param mixed $tagname */ public function removeTagForIndex($tagname) { $tagname = deppPropelActAsTaggableToolkit::explodeTagString($tagname); if (is_array($tagname)) { foreach ($tagname as $tag) { $this->removeTagForIndex($tag); } } else { $tagname = deppPropelActAsTaggableToolkit::cleanTagName($tagname); sfContext::getInstance()->getLogger()->info('{opp_debug}' . $tagname); $tag_object = TagPeer::retrieveByTagname($tagname); $tagging = TaggingForIndexPeer::retrieveByTagAndAtto($tag_object->getId(), $this->getId()); $tagging->delete(); } }
/** * Removes a tag or a set of tags from the object. As usual, the second * parameter might be an array of tags or a comma-separated string. * * @param BaseObject $object * @param mixed $tagname */ public function removeTag(BaseObject $object, $tagname) { $tagname = deppPropelActAsTaggableToolkit::explodeTagString($tagname); if (is_array($tagname)) { foreach ($tagname as $tag) { $this->removeTag($object, $tag); } } else { $tagname = deppPropelActAsTaggableToolkit::cleanTagName($tagname); $tags = self::get_tags($object); $saved_tags = $this->getSavedTags($object); if (isset($tags[$tagname])) { unset($tags[$tagname]); self::set_tags($object, $tags); } if (isset($saved_tags[$tagname])) { unset($saved_tags[$tagname]); self::set_saved_tags($object, $saved_tags); self::add_removed_tag($object, $tagname); } } }
/** * Returns the taggings associated to one tag or a set of tags. * * The second optionnal parameter permits to restrict the results with * different criterias * * @param mixed $tags Array of tag strings or string * @param array $options Array of options parameters * @return array */ protected static function getTaggings($tags = array(), $options = array()) { $tags = deppPropelActAsTaggableToolkit::explodeTagString($tags); if (is_string($tags)) { $tags = array($tags); } $c = new Criteria(); $c->addJoin(TagPeer::ID, TaggingPeer::TAG_ID); if (count($tags) > 0) { $c->add(TagPeer::NAME, $tags, Criteria::IN); $having = $c->getNewCriterion('COUNT(' . TaggingPeer::TAGGABLE_MODEL . ') ', count($tags), Criteria::GREATER_EQUAL); $c->addHaving($having); } $c->addGroupByColumn(TaggingPeer::TAGGABLE_ID); $c->clearSelectColumns(); $c->addSelectColumn(TaggingPeer::TAGGABLE_MODEL); $c->addSelectColumn(TaggingPeer::TAGGABLE_ID); // Taggable model class option if (isset($options['model'])) { if (!class_exists($options['model']) || !is_callable(array(new $options['model'](), 'getPeer'))) { throw new PropelException(sprintf('The class "%s" does not exist, or it is not a model class.', $options['model'])); } $c->add(TaggingPeer::TAGGABLE_MODEL, $options['model']); } else { $c->addGroupByColumn(TaggingPeer::TAGGABLE_MODEL); } if (isset($options['triple'])) { $c->add(TagPeer::IS_TRIPLE, $options['triple']); } if (isset($options['namespace'])) { $c->add(TagPeer::TRIPLE_NAMESPACE, $options['namespace']); } if (isset($options['key'])) { $c->add(TagPeer::TRIPLE_KEY, $options['key']); } if (isset($options['value'])) { $c->add(TagPeer::TRIPLE_VALUE, $options['value']); } $param = array(); $sql = BasePeer::createSelectSql($c, $param); $con = Propel::getConnection(); if (Propel::VERSION < '1.3') { $stmt = $con->prepareStatement($sql); $position = 1; foreach ($tags as $tag) { $stmt->setString($position, $tag); $position++; } if (isset($options['model'])) { $stmt->setString($position, $options['model']); $position++; } if (isset($options['triple'])) { $stmt->setBoolean($position, $options['triple']); $position++; } if (isset($options['namespace'])) { $stmt->setString($position, $options['namespace']); $position++; } if (isset($options['key'])) { $stmt->setString($position, $options['key']); $position++; } if (isset($options['value'])) { $stmt->setString($position, $options['value']); $position++; } } else { $stmt = $con->prepare($sql); $position = 1; foreach ($tags as $tag) { $stmt->bindValue(':p' . $position, $tag, PDO::PARAM_STR); $position++; } if (isset($options['model'])) { $stmt->bindValue(':p' . $position, $options['model'], PDO::PARAM_STR); $position++; } if (isset($options['triple'])) { $stmt->bindValue(':p' . $position, $options['triple']); $position++; } if (isset($options['namespace'])) { $stmt->bindValue(':p' . $position, $options['namespace'], PDO::PARAM_STR); $position++; } if (isset($options['key'])) { $stmt->bindValue(':p' . $position, $options['key'], PDO::PARAM_STR); $position++; } if (isset($options['value'])) { $stmt->bindValue(':p' . $position, $options['value'], PDO::PARAM_STR); $position++; } } if (!isset($options['nb_common_tags']) || $options['nb_common_tags'] > count($tags)) { $options['nb_common_tags'] = count($tags); } if ($options['nb_common_tags'] > 0) { if (Propel::VERSION >= '1.3') { $stmt->bindValue(':p' . $position, $options['nb_common_tags'], PDO::PARAM_STR); } else { $stmt->setString($position, $options['nb_common_tags']); } } $taggings = array(); if (Propel::VERSION >= '1.3') { $rs = $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $model = $row[0]; if (!isset($taggings[$model])) { $taggings[$model] = array(); } $taggings[$model][] = $row[1]; } } else { $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); while ($rs->next()) { $model = $rs->getString(1); if (!isset($taggings[$model])) { $taggings[$model] = array(); } $taggings[$model][] = $rs->getInt(2); } } return $taggings; }