本文整理汇总了PHP中NewsletterSubscription::addRelationship方法的典型用法代码示例。如果您正苦于以下问题:PHP NewsletterSubscription::addRelationship方法的具体用法?PHP NewsletterSubscription::addRelationship怎么用?PHP NewsletterSubscription::addRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NewsletterSubscription
的用法示例。
在下文中一共展示了NewsletterSubscription::addRelationship方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newsletter_unsubscribe_email
/**
* Remove a subscription for an email address to a container
*
* @param string $email The email address to remove from the subscriptions
* @param ElggEntity $entity The container entity to unsubscribe from
*
* @return boolean true on success else false
*/
function newsletter_unsubscribe_email($email, ElggEntity $entity)
{
$result = false;
if (!empty($email) && !empty($entity)) {
if (newsletter_is_email_address($email) && (elgg_instanceof($entity, "site") || elgg_instanceof($entity, "group"))) {
// check if not existing user
$users = get_user_by_email($email);
if (!empty($users)) {
// existing user
$result = newsletter_unsubscribe_user($users[0], $entity);
} else {
// email address
$subscription = newsletter_get_subscription($email);
if (empty($subscription)) {
$subscription = new NewsletterSubscription();
$subscription->title = $email;
if (!$subscription->save()) {
return false;
}
}
// remove existing subscription (if any)
$subscription->removeRelationship($entity->getGUID(), NewsletterSubscription::SUBSCRIPTION);
// add to blocked list
$result = $subscription->addRelationship($entity->getGUID(), NewsletterSubscription::BLACKLIST);
}
}
}
return $result;
}