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


PHP Local_group::insert方法代码示例

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


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

示例1: 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;
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:93,代码来源:User_group.php

示例2: 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;
 }
开发者ID:stevertiqo,项目名称:StatusNet,代码行数:65,代码来源:User_group.php

示例3: initLocalGroup

function initLocalGroup()
{
    printfnq("Ensuring all local user groups have a local_group...");
    $group = new User_group();
    $group->whereAdd('NOT EXISTS (select group_id from local_group where group_id = user_group.id)');
    $group->find();
    while ($group->fetch()) {
        try {
            // Hack to check for local groups
            if ($group->getUri() == common_local_url('groupbyid', array('id' => $group->id))) {
                $lg = new Local_group();
                $lg->group_id = $group->id;
                $lg->nickname = $group->nickname;
                $lg->created = $group->created;
                // XXX: common_sql_now() ?
                $lg->modified = $group->modified;
                $lg->insert();
            }
        } catch (Exception $e) {
            printfv("Error initializing local group for {$group->nickname}:" . $e->getMessage());
        }
    }
    printfnq("DONE.\n");
}
开发者ID:Grasia,项目名称:bolotweet,代码行数:24,代码来源:upgrade.php


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