本文整理汇总了PHP中TagPeer::retrieveOrCreateByTagName方法的典型用法代码示例。如果您正苦于以下问题:PHP TagPeer::retrieveOrCreateByTagName方法的具体用法?PHP TagPeer::retrieveOrCreateByTagName怎么用?PHP TagPeer::retrieveOrCreateByTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagPeer
的用法示例。
在下文中一共展示了TagPeer::retrieveOrCreateByTagName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postSave
/**
* Tags saving logic, runned after the object himself has been saved
*
* @param BaseObject $object
*/
public function postSave(BaseObject $object)
{
$tags = self::get_tags($object);
$removed_tags = self::get_removed_tags($object);
// save new tags
foreach ($tags as $tagname) {
$tag = TagPeer::retrieveOrCreateByTagName($tagname);
$tag->save();
$tagging = new Tagging();
$tagging->setTagId($tag->getId());
$tagging->setTaggableId($object->getPrimaryKey());
$tagging->setTaggableModel(get_class($object));
$tagging->save();
}
// remove removed tags
$c = new Criteria();
$c->add(TagPeer::NAME, $removed_tags, Criteria::IN);
$rs = TagPeer::doSelectRS($c);
$removed_tag_ids = array();
while ($rs->next()) {
$removed_tag_ids[] = $rs->getInt(1);
}
$c = new Criteria();
$c->add(TaggingPeer::TAG_ID, $removed_tag_ids, Criteria::IN);
$c->add(TaggingPeer::TAGGABLE_ID, $object->getPrimaryKey());
$c->add(TaggingPeer::TAGGABLE_MODEL, get_class($object));
TaggingPeer::doDelete($c);
$tags = array_merge(self::get_tags($object), $this->getSavedTags($object));
self::set_saved_tags($object, $tags);
self::clear_tags($object);
self::clear_removed_tags($object);
}
示例2: postSave
/**
* Tags saving logic, runned after the object himself has been saved
*
* @param BaseObject $object
*/
public function postSave(BaseObject $object)
{
$tags = self::get_tags($object);
$removed_tags = self::get_removed_tags($object);
// read some config parameters and defaults
$anonymous_tagging = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_anonymous_tagging', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_anonymous_tagging', true));
$allows_tagging_removal = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_allows_tagging_removal', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_allows_tagging_removal', 'all'));
$tagging_removal_credentials = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_tagging_removal_credentials', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_tagging_removal_credentials', array()));
$use_unique_triple_values = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_use_unique_triple_values', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_use_unique_triple_values', false));
$user = @sfContext::getInstance()->getUser();
// save new tags
foreach ($tags as $tagname) {
if ($use_unique_triple_values) {
$tag = TagPeer::retrieveOrCreateByTripleValue($tagname);
} else {
$tag = TagPeer::retrieveOrCreateByTagName($tagname);
}
$tag->save();
$tagging = TaggingPeer::retrieveOrCreateByTagAndTaggable($tag->getId(), $object->getPrimaryKey(), get_class($object));
$user_id = deppPropelActAsTaggableToolkit::getUserId();
if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id != '') {
if ($tagging->isNew()) {
$tagging->setUserId($user_id);
}
}
$tagging->save();
}
// remove removed tags
$removed_tag_ids = array();
$c = new Criteria();
$c->add(TagPeer::NAME, $removed_tags, Criteria::IN);
if (Propel::VERSION >= '1.3') {
$rs = TagPeer::doSelectStmt($c);
while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
$removed_tag_ids[] = intval($row['ID']);
}
} else {
$rs = TagPeer::doSelectRS($c);
while ($rs->next()) {
$removed_tag_ids[] = $rs->getInt(1);
}
}
$c = new Criteria();
$c->add(TaggingPeer::TAG_ID, $removed_tag_ids, Criteria::IN);
$c->add(TaggingPeer::TAGGABLE_ID, $object->getPrimaryKey());
$c->add(TaggingPeer::TAGGABLE_MODEL, get_class($object));
$user_id = deppPropelActAsTaggableToolkit::getUserId();
// for authenticated users that do not have tagging_removal_credentials
// if the only tags they're allowed to remove are their own
// then, remove only those tags
// this only works, if anonymnous_tagging is set to false
if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id != '' && $allows_tagging_removal == 'self' && !$user->hasCredential($tagging_removal_credentials, false)) {
$c->add(TaggingPeer::USER_ID, $user_id);
}
// delete e non doDelete, in modo che anche sul tagging si possano attivare i behavior (per le news)
// TaggingPeer::doDelete($c);
$tags_to_delete = TaggingPeer::doSelect($c);
foreach ($tags_to_delete as $tag_to_delete) {
$tag_to_delete->delete();
}
$tags = array_merge(self::get_tags($object), $this->getSavedTags($object));
self::set_saved_tags($object, $tags);
self::clear_tags($object);
self::clear_removed_tags($object);
}