当前位置: 首页>>代码示例>>PHP>>正文


PHP UserGroup::exists方法代码示例

本文整理汇总了PHP中UserGroup::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP UserGroup::exists方法的具体用法?PHP UserGroup::exists怎么用?PHP UserGroup::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserGroup的用法示例。


在下文中一共展示了UserGroup::exists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate_groupname

 /**
  * A validation function that returns an error if the the passed group name is unavailable
  *
  * @param string $text A value to test as group name
  * @param FormControl $control The control that defines the value
  * @param FormContainer $form The container that holds the control
  * @param string $allowed_name An optional name which overrides the check and is always allowed
  * @param string $warning An optional error message
  * @return array An empty array if the value exists, or an array with strings describing the errors
  */
 public static function validate_groupname($value, $control, $form, $allowed_name = null, $warning = null)
 {
     if (isset($allowed_name) && $value == $allowed_name) {
         return array();
     }
     if (UserGroup::exists($value)) {
         $warning = empty($warning) ? _t('The group %s already exists.', array($value)) : $warning;
         return array($warning);
     }
     return array();
 }
开发者ID:habari,项目名称:system,代码行数:21,代码来源:formvalidators.php

示例2: update_groups

 /**
  * Add or delete groups.
  */
 public function update_groups($handler_vars, $ajax = TRUE)
 {
     $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
     if (isset($handler_vars['digest']) && $handler_vars['digest'] != $wsse['digest'] || isset($handler_vars['PasswordDigest']) && $handler_vars['PasswordDigest'] != $wsse['digest']) {
         Session::error(_t('WSSE authentication failed.'));
         return Session::messages_get(true, 'array');
     }
     if (isset($handler_vars['PasswordDigest']) || isset($handler_vars['digest'])) {
         if (isset($handler_vars['action']) && $handler_vars['action'] == 'add' || isset($handler_vars['newgroup'])) {
             if (isset($handler_vars['newgroup'])) {
                 $name = trim($handler_vars['new_groupname']);
             } else {
                 $name = trim($handler_vars['name']);
             }
             $settings = array('name' => $name);
             $this->theme->addform = $settings;
             if (UserGroup::exists($name)) {
                 Session::notice(sprintf(_t('The group %s already exists'), $name));
                 if ($ajax) {
                     return Session::messages_get(true, 'array');
                 } else {
                     return;
                 }
             } elseif (empty($name)) {
                 Session::notice(_t('The group must have a name'));
                 if ($ajax) {
                     return Session::message_get(true, 'array');
                 } else {
                     return;
                 }
             } else {
                 $groupdata = array('name' => $name);
                 $group = UserGroup::create($groupdata);
                 Session::notice(sprintf(_t('Added group %s'), $name));
                 // reload the groups
                 $this->theme->groups = UserGroups::get_all();
                 $this->theme->addform = array();
             }
             if ($ajax) {
                 return Session::messages_get(true, 'array');
             } else {
                 if (!$ajax) {
                     Utils::redirect(URL::get('admin', 'page=groups'));
                 }
             }
         }
         if (isset($handler_vars['action']) && $handler_vars['action'] == 'delete' && $ajax == true) {
             $ids = array();
             foreach ($_POST as $id => $delete) {
                 // skip POST elements which are not group ids
                 if (preg_match('/^p\\d+$/', $id) && $delete) {
                     $id = (int) substr($id, 1);
                     $ids[] = array('id' => $id);
                 }
             }
             $count = 0;
             if (!isset($ids)) {
                 Session::notice(_t('No groups deleted.'));
                 return Session::messages_get(true, 'array');
             }
             foreach ($ids as $id) {
                 $id = $id['id'];
                 $group = UserGroup::get_by_id($id);
                 $group->delete();
                 $count++;
             }
             if (!isset($msg_status)) {
                 $msg_status = sprintf(_t('Deleted %d groups.'), $count);
             }
             Session::notice($msg_status);
             return Session::messages_get(true, 'array');
         }
     }
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:77,代码来源:adminhandler.php

示例3: insert

 /**
  * Save a new user to the users table
  */
 public function insert()
 {
     $allow = true;
     $allow = Plugins::filter('user_insert_allow', $allow, $this);
     if (!$allow) {
         return;
     }
     Plugins::act('user_insert_before', $this);
     $this->exclude_fields('id');
     $result = parent::insertRecord(DB::table('users'));
     $this->fields['id'] = DB::last_insert_id();
     // Make sure the id is set in the user object to match the row id
     $this->info->set_key($this->id);
     /* If a new user is being created and inserted into the db, info is only safe to use _after_ this set_key call. */
     // $this->info->option_default = "saved";
     // Set the default timezone, date format, and time format
     $this->info->locale_tz = Options::get('timezone');
     $this->info->locale_date_format = Options::get('dateformat');
     $this->info->locale_time_format = Options::get('timeformat');
     $this->info->commit();
     if ($result) {
         // Add the user to the default authenticated group if it exists
         if (UserGroup::exists('authenticated')) {
             $this->add_to_group('authenticated');
         }
     }
     EventLog::log(sprintf(_t('New user created: %s'), $this->username), 'info', 'default', 'habari');
     Plugins::act('user_insert_after', $this);
     return $result;
 }
开发者ID:anupom,项目名称:my-blog,代码行数:33,代码来源:user.php

示例4: test_exists

 public function test_exists()
 {
     $this->assert_true(UserGroup::exists("new test group"), 'Cannot confirm existence of "new test group".');
     $group = UserGroup::get("new test group");
     $this->assert_true(UserGroup::exists($group->id), 'Cannot confirm existence of "new test group".');
     $this->assert_false(UserGroup::exists("nonexistent test group"), 'A nonexistent group should not exist.');
     $this->assert_false(UserGroup::exists(-1), 'A nonexistent group should not exist.');
 }
开发者ID:habari,项目名称:tests,代码行数:8,代码来源:test_usergroup.php


注:本文中的UserGroup::exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。