本文整理汇总了PHP中UserRole::save方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRole::save方法的具体用法?PHP UserRole::save怎么用?PHP UserRole::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRole
的用法示例。
在下文中一共展示了UserRole::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setAdmin
/**
* @description Set the an user as administrator.
* @param mail Mail of the user.
*/
public function setAdmin($mail)
{
$this->output->writeln(sprintf('Set user <info>%s</info> as Administrator', $mail));
$admin_role = Role::get(1);
if (empty($admin_role)) {
$this->output->writeln('No Administrator role is in the database!');
return FALSE;
}
$user = new User();
$user->mail = $mail;
$user->fetch('mail');
if (empty($user->getId())) {
$this->output->writeln(sprintf('User with the mail address <info>%s</info> not found in in the database!', $mail));
return FALSE;
}
$ur = new UserRole();
$ur->user = $user;
$ur->role = $admin_role;
if (!$ur->save()) {
$this->output->writeln('Unable to associate the administrator role!');
$this->output->writeln(print_r($ur->getErrors(), TRUE));
return FALSE;
}
$this->output->writeln('User associated!');
return TRUE;
}
示例2: createOrFind
public function createOrFind(User $oUser, Role $oRole)
{
$oUserRole = $this->filterByUser($oUser)->filterByRole($oRole)->findOne();
if (!$oUserRole) {
$oUserRole = new UserRole();
$oUserRole->setRole($oRole);
$oUserRole->setUser($oUser);
$oUserRole->save();
}
return $oUserRole;
}
示例3: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->akuser !== null) {
if ($this->akuser->isModified() || $this->akuser->isNew()) {
$affectedRows += $this->akuser->save($con);
}
$this->setkuser($this->akuser);
}
if ($this->aUserRole !== null) {
if ($this->aUserRole->isModified() || $this->aUserRole->isNew()) {
$affectedRows += $this->aUserRole->save($con);
}
$this->setUserRole($this->aUserRole);
}
if ($this->isNew()) {
$this->modifiedColumns[] = KuserToUserRolePeer::ID;
}
// If this object has been modified, then save it to the database.
$this->objectSaved = false;
if ($this->isModified()) {
if ($this->isNew()) {
$pk = KuserToUserRolePeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
$this->objectSaved = true;
} else {
$affectedObjects = KuserToUserRolePeer::doUpdate($this, $con);
if ($affectedObjects) {
$this->objectSaved = true;
}
$affectedRows += $affectedObjects;
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例4: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new UserRole();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['UserRole'])) {
$model->attributes = $_POST['UserRole'];
//Ledger//
$ledger_create = 0;
$ledger_edit = 0;
$ledger_delete = 0;
$ledger_status_change = 0;
if (isset($_REQUEST["ledger_create"])) {
$ledger_create = $_REQUEST["ledger_create"];
}
if (isset($_REQUEST["ledger_edit"])) {
$ledger_edit = $_REQUEST["ledger_edit"];
}
if (isset($_REQUEST["ledger_delete"])) {
$ledger_delete = $_REQUEST["ledger_delete"];
}
if (isset($_REQUEST["ledger_status_change"])) {
$ledger_status_change = $_REQUEST["ledger_status_change"];
}
$ledgar_access = ['create' => $ledger_create, 'edit' => $ledger_edit, 'delete' => $ledger_delete, 'status_change' => $ledger_status_change];
$model->ledger_access_level = json_encode($ledgar_access);
//counterparties//
$counterpart_create = 0;
$counterpart_edit = 0;
$counterpart_delete = 0;
//$counterpart_status_change = 0;
if (isset($_REQUEST["counterpart_create"])) {
$counterpart_create = $_REQUEST["counterpart_create"];
}
if (isset($_REQUEST["counterpart_edit"])) {
$counterpart_edit = $_REQUEST["counterpart_edit"];
}
if (isset($_REQUEST["counterpart_delete"])) {
$counterpart_delete = $_REQUEST["counterpart_delete"];
}
if (isset($_REQUEST["counterpart_status_change"])) {
$counterpart_status_change = $_REQUEST["counterpart_status_change"];
}
$counterpart_access = ['create' => $counterpart_create, 'edit' => $counterpart_edit, 'delete' => $counterpart_delete];
$model->counterparties_access_level = json_encode($counterpart_access);
if ($model->save()) {
//$this->redirect(array('view','id'=>$model->id));
$this->redirect(['admin']);
}
}
$this->render('create', array('model' => $model));
}
示例5: postCheckadmin
public function postCheckadmin()
{
if (!Session::get('step4')) {
return Redirect::to('install/step4');
}
Session::put('step5', false);
$username = Input::get('username');
$email = Input::get('email');
$password = Input::get('password');
$password2 = Input::get('password2');
if ($password == $password2) {
$user = new User();
$user->username = $username;
$user->email = $email;
$user->password = Hash::make($password);
$user->save();
$roles = Role::where('on_install', 1)->get();
foreach ($roles as $role) {
$urole = new UserRole();
$urole->user_id = $user->id;
$urole->role_id = $role->id;
$urole->save();
}
Session::put('step5', true);
copy($_SERVER['DOCUMENT_ROOT'] . '/install/uninstalled', $_SERVER['DOCUMENT_ROOT'] . '/install/installed');
return $this->getFinal();
} else {
Session::put('step5', false);
return Illuminate\Support\Facades\Redirect::to('install/step5')->with('uerror', 'Parolele nu coincid');
}
}
示例6: assignRolesToUser
public function assignRolesToUser($user_id)
{
$successful = true;
foreach ($this->_selected_roles as $id_selected_role) {
$model = new UserRole();
$model->user_id = $user_id;
$model->role_id = $id_selected_role;
if (!$model->save()) {
return !$successful;
}
}
return $successful;
}
示例7: install
public function install()
{
$user = new self();
$user->login = self::ADMIN_LOGIN;
$user->displayname = Yii::app()->params['admin']['displayname'];
$user->email = Yii::app()->params['admin']['email'];
$user->password = Yii::app()->params['admin']['password'];
$user->active = true;
$user->show_email = Role::AUTHENTICATED;
$user->send_message = Role::AUTHENTICATED;
$user->timezone = Yii::app()->params['timezone'];
$user->save(false);
$role = Role::model()->findByAttributes(array('name' => Role::ADMINISTRATOR));
$userRole = new UserRole();
$userRole->user_id = $user->id;
$userRole->role_id = $role->id;
$userRole->save(false);
}
示例8: isset
<?php
/**
* @package deployment
*
* Create playback-only user role
*
* No need to re-run after server code deploy
*/
chdir(__DIR__);
require_once __DIR__ . '/../../bootstrap.php';
$realRun = isset($argv[1]) && $argv[1] == 'realrun';
KalturaStatement::setDryRun(!$realRun);
$userRole = new UserRole();
$userRole->setStrId('PLAYBACK_BASE_ROLE');
$userRole->setName('PLAYBACK BASE ROLE');
$userRole->setSystemName('PLAYBACK_BASE_ROLE');
$userRole->setDescription('Only playback');
$userRole->setPartnerId(0);
$userRole->setStatus(UserRoleStatus::ACTIVE);
$userRole->setPermissionNames('PLAYBACK_BASE_PERMISSION');
$userRole->save();
示例9: actionSaveuserrole
public function actionSaveuserrole()
{
$organid = $this->Getorganid();
$roleids = $_POST['roleids'];
$employeeID = $_POST['userid'];
$findmodel = UserRole::model()->findAll("EmployeeID=:userid", array(':userid' => $employeeID));
if (!empty($employeeID)) {
if (!empty($roleids)) {
$roleids = substr($roleids, 0, strlen($roleids) - 1);
$roleids = explode(',', $roleids);
if (count($findmodel) == 0) {
$i = 0;
foreach ($roleids as $roleid) {
$model = new UserRole();
$model->RoleID = $roleid;
$model->EmployeeID = $employeeID;
$model->OrganID = $organid['OrganID'];
$model->UserID = $organid['id'];
$model->CreateTime = time();
$result = $model->save();
if ($result) {
$i++;
}
}
if ($i == count($roleids)) {
$message = "保存成功";
} else {
$message = "保存失败";
}
} else {
foreach ($findmodel as $key => $val) {
if (!in_array($val->RoleID, $roleids)) {
$delcount = UserRole::model()->deleteByPk($val->ID);
}
}
foreach ($roleids as $roleid) {
$findmodel = UserRole::model()->findAll("RoleID=:roleid and EmployeeID=:urid", array(':roleid' => $roleid, ':urid' => $employeeID));
if (empty($findmodel)) {
$model = new UserRole();
$model->RoleID = $roleid;
$model->EmployeeID = $employeeID;
$model->OrganID = $organid['OrganID'];
$model->UserID = $organid['id'];
$model->CreateTime = time();
$result = $model->save();
}
}
$findmodel = UserRole::model()->findAll("EmployeeID=:userid", array(':userid' => $employeeID));
if (count($roleids) == count($findmodel)) {
$message = "保存成功";
} else {
$message = "保存失败";
}
}
} else {
$result = UserRole::model()->deleteAll("EmployeeID=:userid", array(":userid" => $employeeID));
if ($result > 0) {
$message = "保存成功";
} else {
$message = "保存失败";
}
}
} else {
$message = "保存失败";
}
echo json_encode($message);
}
示例10: role_store
public function role_store()
{
$data = Input::all();
$group = new UserRole();
$group->fill($data);
$group->save();
return Redirect::route('perm.role.list');
}
示例11: getOrCreateUserSessionRole
function getOrCreateUserSessionRole($partnerId)
{
PartnerPeer::clearInstancePool();
$partner = PartnerPeer::retrieveByPK($partnerId);
$role = null;
$id = $partner->getUserSessionRoleId();
if ($id) {
$role = UserRolePeer::retrieveByPK($id);
}
if (!$role) {
$role = new UserRole();
$role->setPartnerId($partnerId);
$role->setStatus(UserRoleStatus::ACTIVE);
$role->setName('Partner ' . $partnerId . ' user session permission');
$role->setDescription('Partner ' . $partnerId . ' user session permission');
$role->setPermissionNames(PermissionName::USER_SESSION_PERMISSION);
$role->save();
}
return $role;
}
示例12: postSaveroles
public function postSaveroles()
{
$uid = Input::get('id');
$uroles = User::extractRoles($uid);
if ((User::has('user-roles') && (!User::has('user-ptroles', $uroles) || $uid == Auth::user()->id)) == FALSE) {
throw new Exception("Access denied;");
}
$id = Input::get('id');
$roles = Input::get('roles');
Log::info('Change roles user#' . $id);
UserRole::where('user_id', $id)->delete();
if (is_array($roles)) {
foreach ($roles as $role_id) {
$item = new UserRole();
$item->role_id = $role_id;
$item->user_id = $id;
$item->save();
}
}
return [];
}
示例13: 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());
}
示例14: addRoleByUsers
public function addRoleByUsers($id, $roleId, $change)
{
if ($change == '1') {
$userRole = new UserRole();
$userRole->role_id = $roleId;
$userRole->user_id = $id;
$userRole->save();
} elseif ($change == '2') {
$criteria = new CDbCriteria();
$criteria->condition = 'user_id=:userId AND role_id=:roleId';
$criteria->params = array(':userId' => $id, ':roleId' => $roleId);
$userRole = UserRole::model()->find($criteria);
//error_log(print_r($userRole,1));
$userRole->delete();
}
}
示例15: actionCreaterole
public function actionCreaterole()
{
$model = new UserRole();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['UserRole'])) {
if (isset($_POST['UserRole']['name'])) {
$_POST['UserRole']['name'] = mb_strtolower($_POST['UserRole']['name']);
}
$model->attributes = $_POST['UserRole'];
if ($model->save()) {
if (isset($_POST['go_to_list'])) {
$this->redirect('/admin/user/list/role');
} else {
$this->redirect('/admin/user/list/updaterole/id/' . $model->id);
}
}
}
$this->render('createrole', array('model' => $model));
}