本文整理汇总了PHP中UserRole::setRoleId方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRole::setRoleId方法的具体用法?PHP UserRole::setRoleId怎么用?PHP UserRole::setRoleId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRole
的用法示例。
在下文中一共展示了UserRole::setRoleId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeAddMember
public function executeAddMember()
{
$this->validAjaxRequest();
$ajax = new \AjaxResponse();
if (!$this->isAllowed(PERMISSION_ROLE_PERMISSION_MANAGE)) {
$ajax->type = \AjaxResponse::ERROR;
$ajax->message = t("You do not have permission fot this action");
return $this->renderText($ajax->toString());
}
$user_id = $this->post('user_id', 'INT', 0);
if (!$user_id || !($user = \Users::retrieveById($user_id))) {
$ajax->type = \AjaxResponse::ERROR;
$ajax->message = t("User not found");
return $this->renderText($ajax->toString());
}
$role_id = $this->post('role_id', 'INT', 0);
if (!$role_id || !($role = \Roles::retrieveById($role_id))) {
$ajax->type = \AjaxResponse::ERROR;
$ajax->message = t("Role not found");
return $this->renderText($ajax->toString());
}
if (\Users::SECTION_STAFF != $user->getSection()) {
$ajax->type = \AjaxResponse::ERROR;
$ajax->message = t("User %username% is not staff", array("%username%" => $user->getUsername()));
return $this->renderText($ajax->toString());
}
if (!($userRole = \UserRole::findOneByRoleIdAndUserId($role->getId(), $user->getId()))) {
$userRole = new \UserRole();
$userRole->setRoleId($role->getId());
$userRole->setUserId($user->getId());
if ($userRole->save()) {
$role->setMemberNo($role->getMemberNo() + 1);
$role->save(false);
}
}
$ajax->type = \AjaxResponse::SUCCESS;
$ajax->message = t("Add member successful!");
$ajax->user = $user->toArray();
$ajax->role = $role->toArray();
return $this->renderText($ajax->toString());
}