本文整理汇总了PHP中Hubzero\User\Group::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Group::exists方法的具体用法?PHP Group::exists怎么用?PHP Group::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hubzero\User\Group
的用法示例。
在下文中一共展示了Group::exists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sysGroup
/**
* Sync with system project group
*
* @param string $alias project alias
* @param string $prefix all project group names start with this
* @return void
*/
public function sysGroup($alias = NULL, $prefix = 'pr-')
{
if ($alias) {
$cn = $prefix . $alias;
$group = new \Hubzero\User\Group();
if (\Hubzero\User\Group::exists($cn)) {
$group = \Hubzero\User\Group::getInstance($cn);
} else {
// Create system group
$group->set('cn', $cn);
$group->set('gidNumber', 0);
$group->create();
$group = \Hubzero\User\Group::getInstance($cn);
}
$members = $this->getIds($alias, $role = '0', 1);
$authors = $this->getIds($alias, $role = '2', 1);
$managers = $this->getIds($alias, $role = '1', 1);
$all = array_merge($members, $managers, $authors);
$all = array_unique($all);
$group->set('members', $all);
$group->set('managers', $managers);
$group->set('type', 2);
$group->set('published', 1);
$group->set('discoverability', 1);
$group->update();
}
}
示例2: saveTask
/**
* Saves changes to a group or saves a new entry if creating
*
* @return void
*/
public function saveTask()
{
// Check for request forgeries
Request::checkToken();
// Incoming
$g = Request::getVar('group', array(), 'post', 'none', 2);
$g = $this->_multiArrayMap('trim', $g);
// Instantiate a Group object
$group = new Group();
// Is this a new entry or updating?
$isNew = false;
if (!$g['gidNumber']) {
$isNew = true;
// Set the task - if anything fails and we re-enter edit mode
// we need to know if we were creating new or editing existing
$this->_task = 'new';
$before = new Group();
} else {
$this->_task = 'edit';
// Load the group
$group->read($g['gidNumber']);
$before = clone $group;
}
$task = $this->_task == 'edit' ? 'edit' : 'create';
if (!$this->authorize($task, $group)) {
return;
}
// Check for any missing info
if (!$g['cn']) {
$this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_ID'));
}
if (!$g['description']) {
$this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_TITLE'));
}
// Push back into edit mode if any errors
if ($this->getError()) {
$this->view->setLayout('edit');
$this->view->group = $group;
// Set any errors
if ($this->getError()) {
$this->view->setError($this->getError());
}
// Output the HTML
$this->view->display();
return;
}
$g['cn'] = strtolower($g['cn']);
// Ensure the data passed is valid
if (!$this->_validCn($g['cn'], true)) {
$this->setError(Lang::txt('COM_GROUPS_ERROR_INVALID_ID'));
}
//only check if cn exists if we are creating or have changed the cn
if ($this->_task == 'new' || $group->get('cn') != $g['cn']) {
if (Group::exists($g['cn'], true)) {
$this->setError(Lang::txt('COM_GROUPS_ERROR_GROUP_ALREADY_EXIST'));
}
}
// Push back into edit mode if any errors
if ($this->getError()) {
$this->view->setLayout('edit');
$this->view->group = $group;
// Set any errors
if ($this->getError()) {
$this->view->setError($this->getError());
}
// Output the HTML
$this->view->display();
return;
}
// group params
$gparams = new Registry($group->get('params'));
$gparams->merge(new Registry($g['params']));
// set membership control param
$membership_control = isset($g['params']['membership_control']) ? 1 : 0;
$gparams->set('membership_control', $membership_control);
$params = $gparams->toString();
// Set the group changes and save
$group->set('cn', $g['cn']);
$group->set('type', $g['type']);
if ($isNew) {
$group->create();
$group->set('published', 1);
$group->set('approved', 1);
$group->set('created', Date::toSql());
$group->set('created_by', User::get('id'));
$group->add('managers', array(User::get('id')));
$group->add('members', array(User::get('id')));
}
$group->set('description', $g['description']);
$group->set('discoverability', $g['discoverability']);
$group->set('join_policy', $g['join_policy']);
$group->set('public_desc', $g['public_desc']);
$group->set('private_desc', $g['private_desc']);
$group->set('restrict_msg', $g['restrict_msg']);
$group->set('logo', $g['logo']);
//.........这里部分代码省略.........
示例3: groupavailabilityTask
/**
* Get a group's availability
*
* @param object $group Group
* @return string
*/
public function groupavailabilityTask($group = NULL)
{
//get the group
$group = !is_null($group) ? $group : Request::getVar('group', '');
$group = trim($group);
if ($group == '') {
return;
}
// Ensure the data passed is valid
if ($group == 'new' || $group == 'browse' || !$this->_validCn($group) || Group::exists($group, true)) {
$availability = false;
} else {
$availability = true;
}
if (Request::getVar('no_html', 0) == 1) {
echo json_encode(array('available' => $availability));
return;
} else {
return $availability;
}
}
示例4: createTask
/**
* Create a group
*
* @apiMethod POST
* @apiUri /groups
* @apiParameter {
* "name": "cn",
* "description": "Group alias that appears in the url for group. Only lowercase alphanumeric chars allowed.",
* "type": "string",
* "required": true,
* "default": null
* }
* @apiParameter {
* "name": "title",
* "description": "Group title",
* "type": "string",
* "required": true,
* "default": null
* }
* @apiParameter {
* "name": "tags",
* "description": "Group tags",
* "type": "string (comma separated)",
* "required": false,
* "default": null
* }
* @apiParameter {
* "name": "public_description",
* "description": "Group public description",
* "type": "string",
* "required": false,
* "default": null
* }
* @apiParameter {
* "name": "private_description",
* "description": "Group private description",
* "type": "string",
* "required": false,
* "default": null
* }
* @apiParameter {
* "name": "join_policy",
* "description": "Membership join policy",
* "type": "string",
* "required": true,
* "default": "open",
* "allowedValues": "open, restricted, invite_only, closed"
* }
* @apiParameter {
* "name": "discoverability",
* "description": "Is the group shown in hub searches/listings.",
* "type": "string",
* "required": true,
* "default": "visible",
* "allowedValues": "visible, hidden"
* }
* @return void
*/
public function createTask()
{
$this->requiresAuthentication();
$cn = Request::getWord('cn', '');
$title = Request::getVar('title', '');
$tags = Request::getVar('tags', '');
$publicDesc = Request::getVar('public_description', '');
$privateDesc = Request::getVar('private_description', '');
$joinPolicy = strtolower(Request::getWord('join_policy', 'open'));
$discoverability = Request::getWord('discoverability', 'visible');
// var to hold errors
$errors = array();
// check for required fields (cn & title)
if ($cn == '') {
$errors[] = array('field' => 'cn', 'message' => Lang::txt('Group cn cannot be empty.'));
}
if ($title == '') {
$errors[] = array('field' => 'title', 'message' => Lang::txt('Group title cannot be empty.'));
}
// check to make sure cn is valid & isnt taken
if (!\Hubzero\Utility\Validate::group($cn, false)) {
$errors[] = array('field' => 'cn', 'message' => Lang::txt('COM_GROUPS_SAVE_ERROR_INVALID_ID'));
}
if (\Hubzero\User\Group::exists($cn, false)) {
$errors[] = array('field' => 'cn', 'message' => Lang::txt('COM_GROUPS_SAVE_ERROR_ID_TAKEN'));
}
// valid join policy
$policies = array(0 => 'open', 1 => 'restricted', 2 => 'invite_only', 3 => 'closed');
// make sure we have a valid policy
if (!in_array($joinPolicy, $policies)) {
$errors[] = array('field' => 'join_policy', 'message' => Lang::txt('Group "join_policy" value must be one of the following: %s', implode(', ', $policies)));
}
// valid discoverabilities
$discoverabilities = array(0 => 'visible', 1 => 'hidden');
// make sure we have a valid discoverability
if (!in_array($discoverability, $discoverabilities)) {
$errors[] = array('field' => 'discoverability', 'message' => Lang::txt('Group "discoverability" value must be one of the following: %s', implode(', ', $discoverabilities)));
}
// check for errors at this point
if (!empty($errors)) {
throw new Exception(Lang::txt('Validation Failed') . ': ' . implode("\n", $errors), 422);
}
//.........这里部分代码省略.........
示例5: onGroup
/**
* Return data on a group view (this will be some form of HTML)
*
* @param object $group Current group
* @param string $option Name of the component
* @param string $authorized User's authorization level
* @param integer $limit Number of records to pull
* @param integer $limitstart Start of records to pull
* @param string $action Action to perform
* @param array $access What can be accessed
* @param array $areas Active area(s)
* @return array
*/
public function onGroup($group, $option, $authorized, $limit = 0, $limitstart = 0, $action = '', $access, $areas = null)
{
$return = 'html';
$active = 'wishlist';
// The output array we're returning
$arr = array('html' => '');
//get this area details
$this_area = $this->onGroupAreas();
// Check if our area is in the array of areas we want to return results for
if (is_array($areas) && $limit) {
if (!in_array($this_area['name'], $areas)) {
$return = 'metadata';
}
}
//get the group members
$members = $group->get('members');
//if we want to return content
if ($return == 'html') {
//set group members plugin access level
$group_plugin_acl = $access[$active];
//if set to nobody make sure cant access
if ($group_plugin_acl == 'nobody') {
$arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_OFF', ucfirst($active)) . '</p>';
return $arr;
}
//check if guest and force login if plugin access is registered or members
if (User::isGuest() && ($group_plugin_acl == 'registered' || $group_plugin_acl == 'members')) {
$url = Route::url('index.php?option=com_groups&cn=' . $group->get('cn') . '&active=' . $active, false, true);
App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url)), Lang::txt('GROUPS_PLUGIN_REGISTERED', ucfirst($active)), 'warning');
return;
}
//check to see if user is member and plugin access requires members
if (!in_array(User::get('id'), $members) && $group_plugin_acl == 'members' && $authorized != 'admin') {
$arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>';
return $arr;
}
}
//instantiate database
$database = App::get('db');
// Set some variables so other functions have access
$this->database = $database;
$this->authorized = $authorized;
$this->members = $members;
$this->group = $group;
$this->option = $option;
$this->action = $action;
//include com_wishlist files
require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php';
// Get the component parameters
$this->config = Component::params('com_wishlist');
Lang::load('com_wishlist') || Lang::load('com_wishlist', PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site');
//set some more vars
$gid = $this->group->get('gidNumber');
$cn = $this->group->get('cn');
$category = 'group';
$admin = 0;
// Configure controller
$controller = new \Components\Wishlist\Site\Controllers\Wishlists();
// Get filters
$filters = $controller->getFilters(0);
$filters['limit'] = $this->params->get('limit');
// Load some objects
$obj = new \Components\Wishlist\Tables\Wishlist($this->database);
$objWish = new \Components\Wishlist\Tables\Wish($this->database);
$objOwner = new \Components\Wishlist\Tables\Owner($this->database);
// Get wishlist id
$id = $obj->get_wishlistID($gid, $category);
// Create a new list if necessary
if (!$id) {
// create private list for group
if (\Hubzero\User\Group::exists($gid)) {
$group = \Hubzero\User\Group::getInstance($gid);
$id = $obj->createlist($category, $gid, 0, $cn . ' ' . Lang::txt('PLG_GROUPS_WISHLIST_NAME_GROUP'));
}
}
// get wishlist data
$wishlist = $obj->get_wishlist($id, $gid, $category);
//if we dont have a wishlist display error
if (!$wishlist) {
$arr['html'] = '<p class="error">' . Lang::txt('PLG_GROUPS_WISHLIST_ERROR_WISHLIST_NOT_FOUND') . '</p>';
return $arr;
}
// Get list owners
$owners = $objOwner->get_owners($id, $this->config->get('group'), $wishlist);
//if user is guest and wishlist isnt public
//if (!$wishlist->public && User::isGuest())
//.........这里部分代码省略.........
示例6: delete_owner_group
/**
* Remove a user as owner
*
* @param integer $listid List ID
* @param integer $groupid Group ID
* @param object $admingroup Admin group
* @return boolean False if errors, true on success
*/
public function delete_owner_group($listid, $groupid, $admingroup)
{
if ($listid === NULL or $groupid === NULL) {
return false;
}
$nativegroups = $this->get_owner_groups($listid, $admingroup, '', 1);
// cannot delete "native" owners (e.g. tool dev group)
if (Group::exists($groupid) && !in_array($groupid, $nativegroups, true)) {
$query = "DELETE FROM {$this->_tbl} WHERE wishlist=" . $this->_db->quote($listid) . " AND groupid=" . $this->_db->quote($groupid);
$this->_db->setQuery($query);
$this->_db->query();
return true;
}
}
示例7: writeMemberGroups
/**
* Write the list of group members
*
* @param array $new New members
* @param unknown $id Parameter description (if any) ...
* @param object $database JDatabase
* @param string &$err Error message
* @return array
*/
public function writeMemberGroups($new, $id, $database, &$err = '')
{
$toolhelper = new \Components\Tools\Helpers\Utils();
$groups = is_array($new) ? $new : $toolhelper->makeArray($new);
$grouplist = array();
$invalid = '';
$i = 0;
if (count($groups) > 0) {
foreach ($groups as $group) {
if (\Hubzero\User\Group::exists($group)) {
if ($id) {
$grouplist[$i]->cn = $group;
} else {
$grouplist[$i] = $group;
}
$i++;
} else {
$err = Lang::txt('CONTRIBTOOL_ERROR_GROUP_DOES_NOT_EXIST');
$invalid .= ' ' . $group . ';';
}
}
}
if ($err) {
$err .= $invalid;
}
return $grouplist;
}