本文整理汇总了PHP中User_group::query方法的典型用法代码示例。如果您正苦于以下问题:PHP User_group::query方法的具体用法?PHP User_group::query怎么用?PHP User_group::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User_group
的用法示例。
在下文中一共展示了User_group::query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
static function register($fields)
{
// MAGICALLY put fields into current scope
extract($fields);
$group = new User_group();
$group->query('BEGIN');
if (empty($uri)) {
// fill in later...
$uri = null;
}
$group->nickname = $nickname;
$group->fullname = $fullname;
$group->homepage = $homepage;
$group->description = $description;
$group->location = $location;
$group->uri = $uri;
$group->mainpage = $mainpage;
$group->created = common_sql_now();
$result = $group->insert();
if (!$result) {
common_log_db_error($group, 'INSERT', __FILE__);
// TRANS: Server exception thrown when creating a group failed.
throw new ServerException(_('Could not create group.'));
}
if (!isset($uri) || empty($uri)) {
$orig = clone $group;
$group->uri = common_local_url('groupbyid', array('id' => $group->id));
$result = $group->update($orig);
if (!$result) {
common_log_db_error($group, 'UPDATE', __FILE__);
// TRANS: Server exception thrown when updating a group URI failed.
throw new ServerException(_('Could not set group URI.'));
}
}
$result = $group->setAliases($aliases);
if (!$result) {
// TRANS: Server exception thrown when creating group aliases failed.
throw new ServerException(_('Could not create aliases.'));
}
$member = new Group_member();
$member->group_id = $group->id;
$member->profile_id = $userid;
$member->is_admin = 1;
$member->created = $group->created;
$result = $member->insert();
if (!$result) {
common_log_db_error($member, 'INSERT', __FILE__);
// TRANS: Server exception thrown when setting group membership failed.
throw new ServerException(_('Could not set group membership.'));
}
if ($local) {
$local_group = new Local_group();
$local_group->group_id = $group->id;
$local_group->nickname = $nickname;
$local_group->created = common_sql_now();
$result = $local_group->insert();
if (!$result) {
common_log_db_error($local_group, 'INSERT', __FILE__);
// TRANS: Server exception thrown when saving local group information failed.
throw new ServerException(_('Could not save local group info.'));
}
}
$group->query('COMMIT');
return $group;
}
示例2: register
static function register($fields)
{
if (!empty($fields['userid'])) {
$profile = Profile::staticGet('id', $fields['userid']);
if ($profile && !$profile->hasRight(Right::CREATEGROUP)) {
common_log(LOG_WARNING, "Attempted group creation from banned user: " . $profile->nickname);
// TRANS: Client exception thrown when a user tries to create a group while banned.
throw new ClientException(_('You are not allowed to create groups on this site.'), 403);
}
}
// MAGICALLY put fields into current scope
// @fixme kill extract(); it makes debugging absurdly hard
$defaults = array('nickname' => null, 'fullname' => null, 'homepage' => null, 'description' => null, 'location' => null, 'uri' => null, 'mainpage' => null, 'aliases' => array(), 'userid' => null);
$fields = array_merge($defaults, $fields);
extract($fields);
$group = new User_group();
$group->query('BEGIN');
if (empty($uri)) {
// fill in later...
$uri = null;
}
if (empty($mainpage)) {
$mainpage = common_local_url('showgroup', array('nickname' => $nickname));
}
$group->nickname = $nickname;
$group->fullname = $fullname;
$group->homepage = $homepage;
$group->description = $description;
$group->location = $location;
$group->uri = $uri;
$group->mainpage = $mainpage;
$group->created = common_sql_now();
if (isset($fields['join_policy'])) {
$group->join_policy = intval($fields['join_policy']);
} else {
$group->join_policy = 0;
}
if (isset($fields['force_scope'])) {
$group->force_scope = intval($fields['force_scope']);
} else {
$group->force_scope = 0;
}
if (Event::handle('StartGroupSave', array(&$group))) {
$result = $group->insert();
if (!$result) {
common_log_db_error($group, 'INSERT', __FILE__);
// TRANS: Server exception thrown when creating a group failed.
throw new ServerException(_('Could not create group.'));
}
if (!isset($uri) || empty($uri)) {
$orig = clone $group;
$group->uri = common_local_url('groupbyid', array('id' => $group->id));
$result = $group->update($orig);
if (!$result) {
common_log_db_error($group, 'UPDATE', __FILE__);
// TRANS: Server exception thrown when updating a group URI failed.
throw new ServerException(_('Could not set group URI.'));
}
}
$result = $group->setAliases($aliases);
if (!$result) {
// TRANS: Server exception thrown when creating group aliases failed.
throw new ServerException(_('Could not create aliases.'));
}
$member = new Group_member();
$member->group_id = $group->id;
$member->profile_id = $userid;
$member->is_admin = 1;
$member->created = $group->created;
$result = $member->insert();
if (!$result) {
common_log_db_error($member, 'INSERT', __FILE__);
// TRANS: Server exception thrown when setting group membership failed.
throw new ServerException(_('Could not set group membership.'));
}
self::blow('profile:groups:%d', $userid);
if ($local) {
$local_group = new Local_group();
$local_group->group_id = $group->id;
$local_group->nickname = $nickname;
$local_group->created = common_sql_now();
$result = $local_group->insert();
if (!$result) {
common_log_db_error($local_group, 'INSERT', __FILE__);
// TRANS: Server exception thrown when saving local group information failed.
throw new ServerException(_('Could not save local group info.'));
}
}
$group->query('COMMIT');
Event::handle('EndGroupSave', array($group));
}
return $group;
}
示例3: showContent
function showContent()
{
if (common_logged_in()) {
$this->elementStart('p', array('id' => 'new_group'));
$this->element('a', array('href' => common_local_url('newgroup'), 'class' => 'more'), _('Create a new group'));
$this->elementEnd('p');
}
$offset = ($this->page - 1) * GROUPS_PER_PAGE;
$limit = GROUPS_PER_PAGE + 1;
$qry = 'SELECT user_group.* ' . 'from user_group join local_group on user_group.id = local_group.group_id ' . 'order by user_group.created desc ' . 'limit ' . $limit . ' offset ' . $offset;
$groups = new User_group();
$cnt = 0;
$groups->query($qry);
$gl = new GroupList($groups, null, $this);
$cnt = $gl->show();
$this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE, $this->page, 'groups');
}
示例4: getGroups
/**
* Get groups
*
* @return array groups
*/
function getGroups()
{
$qry = 'SELECT user_group.* ' . 'from user_group join local_group on user_group.id = local_group.group_id ' . 'order by created desc ';
$offset = intval($this->page - 1) * intval($this->count);
$limit = intval($this->count);
if (common_config('db', 'type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
$group = new User_group();
$group->query($qry);
$groups = array();
while ($group->fetch()) {
$groups[] = clone $group;
}
return $groups;
}
示例5: getGroups
function getGroups()
{
$group = new User_group();
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
$limit = PROFILES_PER_PAGE + 1;
if (isset($this->q)) {
$order = 'user_group.created ASC';
if ($this->sort == 'nickname') {
if ($this->reverse) {
$order = 'user_group.nickname DESC';
} else {
$order = 'user_group.nickname ASC';
}
} else {
if ($this->reverse) {
$order = 'user_group.created DESC';
}
}
$sql = <<<GROUP_QUERY_END
SELECT user_group.*
FROM user_group
JOIN local_group ON user_group.id = local_group.group_id
ORDER BY %s
LIMIT %d, %d
GROUP_QUERY_END;
$cnt = 0;
$group->query(sprintf($sql, $order, $limit, $offset));
$group->find();
} else {
// User is browsing via AlphaNav
$sort = $this->getSortKey();
$sql = <<<GROUP_QUERY_END
SELECT user_group.*
FROM user_group
JOIN local_group ON user_group.id = local_group.group_id
GROUP_QUERY_END;
switch ($this->filter) {
case 'all':
// NOOP
break;
case '0-9':
$sql .= ' AND LEFT(user_group.nickname, 1) BETWEEN \'0\' AND \'9\'';
break;
default:
$sql .= sprintf(' AND LEFT(LOWER(user_group.nickname), 1) = \'%s\'', $this->filter);
}
$sql .= sprintf(' ORDER BY user_group.%s %s, user_group.nickname ASC LIMIT %d, %d', $sort, $this->reverse ? 'DESC' : 'ASC', $offset, $limit);
$group->query($sql);
}
return $group;
}
示例6: getGroups
function getGroups($offset = 0, $limit = null)
{
$qry = 'SELECT user_group.* ' . 'FROM user_group JOIN group_member ' . 'ON user_group.id = group_member.group_id ' . 'WHERE group_member.profile_id = %d ' . 'ORDER BY group_member.created DESC ';
if ($offset > 0 && !is_null($limit)) {
if ($offset) {
if (common_config('db', 'type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
}
}
$groups = new User_group();
$cnt = $groups->query(sprintf($qry, $this->id));
return $groups;
}
示例7: initGroupProfileId
function initGroupProfileId()
{
printfnq("Ensuring all User_group entries have a Profile and profile_id...");
$group = new User_group();
$group->whereAdd('NOT EXISTS (SELECT id FROM profile WHERE id = user_group.profile_id)');
$group->find();
while ($group->fetch()) {
try {
// We must create a new, incrementally assigned profile_id
$profile = new Profile();
$profile->nickname = $group->nickname;
$profile->fullname = $group->fullname;
$profile->profileurl = $group->mainpage;
$profile->homepage = $group->homepage;
$profile->bio = $group->description;
$profile->location = $group->location;
$profile->created = $group->created;
$profile->modified = $group->modified;
$profile->query('BEGIN');
$id = $profile->insert();
if (empty($id)) {
$profile->query('ROLLBACK');
throw new Exception('Profile insertion failed, profileurl: ' . $profile->profileurl);
}
$group->query("UPDATE user_group SET profile_id={$id} WHERE id={$group->id}");
$profile->query('COMMIT');
$profile->free();
} catch (Exception $e) {
printfv("Error initializing Profile for group {$group->nickname}:" . $e->getMessage());
}
}
printfnq("DONE.\n");
}
示例8: trySave
function trySave()
{
$nickname = $this->trimmed('nickname');
$fullname = $this->trimmed('fullname');
$homepage = $this->trimmed('homepage');
$description = $this->trimmed('description');
$location = $this->trimmed('location');
if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
$this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
return;
} else {
if ($this->nicknameExists($nickname)) {
$this->showForm(_('Nickname already in use. Try another one.'));
return;
} else {
if (!User_group::allowedNickname($nickname)) {
$this->showForm(_('Not a valid nickname.'));
return;
} else {
if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
} else {
if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
} else {
if (!is_null($description) && mb_strlen($description) > 140) {
$this->showForm(_('description is too long (max 140 chars).'));
return;
} else {
if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
}
}
}
}
}
}
}
$cur = common_current_user();
// Checked in prepare() above
assert(!is_null($cur));
$group = new User_group();
$group->query('BEGIN');
$group->nickname = $nickname;
$group->fullname = $fullname;
$group->homepage = $homepage;
$group->description = $description;
$group->location = $location;
$group->created = common_sql_now();
$result = $group->insert();
if (!$result) {
common_log_db_error($group, 'INSERT', __FILE__);
$this->serverError(_('Could not create group.'));
}
$member = new Group_member();
$member->group_id = $group->id;
$member->profile_id = $cur->id;
$member->is_admin = 1;
$member->created = $group->created;
$result = $member->insert();
if (!$result) {
common_log_db_error($member, 'INSERT', __FILE__);
$this->serverError(_('Could not set group membership.'));
}
$group->query('COMMIT');
common_redirect($group->homeUrl(), 307);
}