本文整理汇总了PHP中Subscription::setUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscription::setUser方法的具体用法?PHP Subscription::setUser怎么用?PHP Subscription::setUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscription
的用法示例。
在下文中一共展示了Subscription::setUser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: body
protected function body()
{
if (!$this->userHasPrivileges(User::groupsJoinPrivate, User::groupsJoinPublic, User::groupsRequest)) {
return false;
}
if (!$this->isInputValid(array('id' => 'isIndex'))) {
return false;
}
$groupId = $this->getParams('id');
/**
* @var $group \Group
*/
$group = Repositories::findEntity(Repositories::Group, $groupId);
// Calculate privileges of the user
$user = User::instance();
$canJoinPrivate = User::instance()->hasPrivileges(User::groupsJoinPrivate);
$groupIsPrivate = $group->getType() == \Group::TYPE_PRIVATE;
$hasSufficientPrivileges = $groupIsPrivate && ($canJoinPrivate || $user->hasPrivileges(User::groupsRequest)) || !$groupIsPrivate && $user->hasPrivileges(User::groupsJoinPublic);
if (!$hasSufficientPrivileges) {
return $this->death(StringID::InsufficientPrivileges);
}
$status = $canJoinPrivate || !$groupIsPrivate ? \Subscription::STATUS_SUBSCRIBED : \Subscription::STATUS_REQUESTED;
// Put into database
$subscription = new \Subscription();
$subscription->setGroup($group);
$subscription->setUser(User::instance()->getEntity());
$subscription->setStatus($status);
Repositories::persistAndFlush($subscription);
return true;
}
示例2: onSuccess
public function onSuccess(Course $course)
{
$this->em->persist($course);
$subscription = new Subscription();
$user = $this->container->get('security.context')->getToken()->getUser();
$subscription->setUser($user);
$subscription->setCourse($course);
$this->em->persist($subscription);
$this->em->flush();
$this->get('session')->setFlash('notice', 'Your Course is created! & Subscription OK !');
}