本文整理汇总了PHP中UserGroup::save方法的典型用法代码示例。如果您正苦于以下问题:PHP UserGroup::save方法的具体用法?PHP UserGroup::save怎么用?PHP UserGroup::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserGroup
的用法示例。
在下文中一共展示了UserGroup::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
$this->role = Role::getNewInstance('__testrole__');
$this->role->save();
$this->userGroup = UserGroup::getNewInstance('Any random group name');
$this->userGroup->save();
}
示例2: addAction
public function addAction()
{
$ans = [];
try {
if (!$this->request->isPost()) {
throw new Exception('请用正确的方式访问我们的API', 99);
}
$validation = new Phalcon\Validation();
$validation->add('name', new PresenceOf(['message' => 'name is needed']));
$validation->add('name', new StringLength(['max' => 30, 'messageMaximum' => 'The name is too long.']));
$messages = $validation->validate($_POST);
foreach ($messages as $message) {
throw new Exception($message, 102);
}
//获取Post中的内容,然后将name存入到数据库中
$name = $this->request->getPost('name');
$userGroup = new UserGroup();
$userGroup->name = $name;
$success = $userGroup->save();
if ($success) {
$ans['id'] = $userGroup->id;
} else {
foreach ($userGroup->getMessages() as $message) {
throw new Exception($message, 100);
}
}
} catch (Exception $e) {
$ans['id'] = -1;
Utils::makeError($e, $ans);
} finally {
echo json_encode($ans);
}
}
示例3: save_data
/**
* Save imported class data to database
*
* @param $classes
*
* @return int
*/
function save_data($classes)
{
$count = 0;
$usergroup = new UserGroup();
foreach ($classes as $index => $class) {
$usersToAdd = isset($class['users']) ? $class['users'] : null;
unset($class['users']);
$id = $usergroup->save($class);
if ($id) {
if (!empty($usersToAdd)) {
$usersToAddList = explode(',', $usersToAdd);
$userIdList = array();
foreach ($usersToAddList as $username) {
$userInfo = api_get_user_info_from_username($username);
$userIdList[] = $userInfo['user_id'];
}
if (!empty($userIdList)) {
$usergroup->subscribe_users_to_usergroup($id, $userIdList, false);
}
}
$count++;
}
}
return $count;
}
示例4: testCreateNewGroup
public function testCreateNewGroup()
{
// Create new UserGroup model
$model = new UserGroup();
$model->name = 'Admin';
$model->description = 'Test Group';
$model->gperm_access_admin_panel = 1;
$model->pperm_browse_crash_reports = 1;
$model->pperm_browse_bugs = 1;
$model->pperm_browse_debug_info = 1;
$model->pperm_manage_crash_reports = 1;
$model->pperm_manage_bugs = 1;
$model->pperm_manage_debug_info = 1;
$model->default_sidebar_tab = 'Digest';
$model->default_bug_status_filter = 'open';
// Validate model - assume failure (group name already exist)
$this->assertFalse($model->validate());
// Correct name
$model->name = 'NewGroup';
// Validate model - assume success
$this->assertTrue($model->validate());
// Apply changes to database - assume success
$this->assertTrue($model->save());
// Ensure group's status is Active
$this->assertTrue($model->status == UserGroup::STATUS_ACTIVE);
// Check the new group is not standard
$this->assertFalse($model->isStandard());
// Check the new group can be updated
$this->assertTrue($model->canUpdate());
// Delete new group - should succeed
$this->assertTrue($model->delete());
}
示例5: groups
public function groups($nickname = null)
{
$user = $this->load_user($nickname);
$this->assign("user", $user);
if ($this->post && isset($_POST['group_id'])) {
$group = Group::find_by_iD($_POST['group_id']);
if ($group) {
$userGroup = new UserGroup();
$userGroup->group_id = $group->id;
$userGroup->user_id = $user->id;
if ($userGroup->save()) {
Site::Flash('notice', 'The user has been added to the group');
Redirect("admin/users/" . $user->permalink() . '/groups');
}
}
}
$userGroups = array();
foreach ($user->groups() as $ug) {
$userGroups[] = $ug->id;
}
$allGroups = Group::find_all();
$groups = array();
foreach ($allGroups as $group) {
if (in_array($group->id, $userGroups)) {
continue;
}
$groups[$group->id] = $group->name;
}
$this->assign('groups', $groups);
$this->title = "{$user->nickname} :: Groups";
$this->render("user/groups.tpl");
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
if ($this->user_role == 'top_admin') {
$model = new UserGroup();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
$criteria = new CDbCriteria();
$criteria->condition = 'status=:status';
$criteria->params = array(':status' => 1);
$criteria->order = 'sort_order';
$menu_list = UserMenu::model()->findAll($criteria);
if (isset($_POST['UserGroup'])) {
$sep = "";
$user_menu = "";
if (isset($_POST['user_menu'])) {
// echo "<pre>".print_r($_POST['user_menu'])."</pre>";
$count_menu = count($_POST['user_menu']);
$menu_list = array();
$menu_list = $_POST['user_menu'];
foreach ($menu_list as $key => $value) {
$user_menu .= $sep . $value;
$sep = ",";
}
}
$_POST['UserGroup']['user_menu'] = $user_menu;
$model->attributes = $_POST['UserGroup'];
if ($model->save()) {
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model, 'menu_list' => $menu_list));
} else {
$this->redirect(array('site/index'));
}
}
示例7: group_store
public function group_store()
{
$data = Input::all();
$group = new UserGroup();
$group->fill($data);
$group->save();
return Redirect::route('perm.group.list');
}
示例8: addUserGroupSubmit
function addUserGroupSubmit($p)
{
$grp = new UserGroup();
$grp->setName($p['name']);
$grp->setInfo($p['info']);
$grp->setLevel($p['level']);
$grp->save();
redir('a/usergroups');
}
示例9: saveUserGroupSubmit
function saveUserGroupSubmit($p)
{
$grp = new UserGroup($p['g_id']);
$grp->setName($p['name']);
$grp->setInfo($p['info']);
$grp->setLevel($p['level']);
$grp->save();
return true;
}
示例10: addToGroups
/**
* add user to groups
*
* @param array $group_name
*/
public function addToGroups($group_name)
{
$group_ids = Group::findGroupIdByNames($group_name);
foreach ($group_ids as $group_id) {
$user_group = new UserGroup();
$user_group->user_id = $this->getId();
$user_group->group_id = $group_id;
$user_group->save();
}
}
示例11: _mainModelAfterSave
/**
* We're going to create a UserGroup when a new Model record is created
*
* @param Model $Model
* @param boolean $created
*/
private function _mainModelAfterSave(Model $Model, $created)
{
if ($created) {
$UserGroup = new UserGroup();
// create a UserGroup for this Course
$data = $UserGroup->create(array('title' => $Model->data[$Model->alias][$Model->displayField], 'model' => $Model->alias, 'foreign_key' => $Model->id, 'owner_id' => $Model->userId));
$UserGroup->save($data);
// make the current Auth.User a member, and the moderator, for this group
$UserGroup->UsersUserGroup->add(array('UsersUserGroup' => array('user_id' => $Model->userId, 'user_group_id' => $UserGroup->id, 'is_moderator' => 1, 'is_approved' => 1)));
}
}
示例12: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new UserGroup();
if (isset($_POST['UserGroup'])) {
$model->attributes = $_POST['UserGroup'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例13: save_data
/**
* Save imported class data to database
*/
function save_data($classes)
{
$number_of_added_classes = 0;
$usergroup = new UserGroup();
foreach ($classes as $index => $class) {
$id = $usergroup->save($class);
if ($id) {
$number_of_added_classes++;
}
}
return $number_of_added_classes;
}
示例14: run
public function run()
{
$model = new UserGroup();
if (isset($_POST['UserGroup'])) {
$model->attributes = $_POST['UserGroup'];
$model->acl = isset($_POST['acls']) ? $_POST['acls'] : array();
if ($model->save()) {
$this->controller->message('success', Yii::t('admin', 'Add Success'), $this->controller->createUrl('index'));
}
}
$this->controller->render('create', array('model' => $model, 'acls' => $this->controller->acl()));
}
示例15: UserGroupSave
/**
* 保存用户到用户组
*/
static function UserGroupSave($user_id, $group)
{
\Yii::app()->db->createCommand()->update('users', array('yourself' => $_POST['self'] ? 1 : 0), 'id=:id', array('id' => $user_id));
if ($group) {
UserGroup::model()->deleteAllByAttributes(array('user_id' => $user_id));
foreach ($group as $group_id) {
$model = new UserGroup();
$model->group_id = $group_id;
$model->user_id = $user_id;
$model->save();
}
}
}