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


PHP Permission::write方法代码示例

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


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

示例1: processRecord

 public function processRecord($record, $columnMap, &$results, $preview = false)
 {
     // We match by 'Code', the ID property is confusing the importer
     if (isset($record['ID'])) {
         unset($record['ID']);
     }
     $objID = parent::processRecord($record, $columnMap, $results, $preview);
     $group = DataObject::get_by_id($this->objectClass, $objID);
     // set group hierarchies - we need to do this after all records
     // are imported to avoid missing "early" references to parents
     // which are imported later on in the CSV file.
     if (isset($record['ParentCode']) && $record['ParentCode']) {
         $parentGroup = DataObject::get_one('Group', array('"Group"."Code"' => $record['ParentCode']));
         if ($parentGroup) {
             $group->ParentID = $parentGroup->ID;
             $group->write();
         }
     }
     // set permission codes - these are all additive, meaning
     // existing permissions arent cleared.
     if (isset($record['PermissionCodes']) && $record['PermissionCodes']) {
         foreach (explode(',', $record['PermissionCodes']) as $code) {
             $p = DataObject::get_one('Permission', array('"Permission"."Code"' => $code, '"Permission"."GroupID"' => $group->ID));
             if (!$p) {
                 $p = new Permission(array('Code' => $code));
                 $p->write();
             }
             $group->Permissions()->add($p);
         }
     }
     return $objID;
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:32,代码来源:GroupCsvBulkLoader.php

示例2: onAfterWrite

 public function onAfterWrite()
 {
     parent::onAfterWrite();
     // TODO: should test if this is needed or not
     if (!$this->owner->ID) {
         return;
     }
     // Apply the subsite title to config
     $siteconfig = $this->getSiteConfig();
     if ($siteconfig) {
         if ($siteconfig->Title == _t('Subsite.SiteConfigTitle', 'Your Site Name') && $this->owner->Title) {
             $siteconfig->Title = $this->owner->Title;
             $siteconfig->write();
         }
     }
     // Make sure we have groups for this subsite
     $groupName = $this->getAdministratorGroupName();
     $group = self::getGroupByName($groupName);
     if ($groupName && !$group) {
         $group = new Group();
         $group->Title = $groupName;
         $group->AccessAllSubsites = false;
         $group->write();
         $group->Subsites()->add($this->owner);
         // Apply default permissions to this group
         $codes = array_unique(array_keys(Permission::get_codes(false)));
         $default_permissions = Config::inst()->get('SubsiteExtension', 'admin_default_permissions');
         foreach ($default_permissions as $p) {
             if (in_array($p, $codes)) {
                 $po = new Permission(array('Code' => $p));
                 $po->write();
                 $group->Permissions()->add($po);
             }
         }
         $group->write();
     }
     $membersGroupName = $this->getMembersGroupName();
     $membersGroup = self::getGroupByName($membersGroupName);
     if ($membersGroupName && !$membersGroup) {
         $membersGroup = new Group();
         $membersGroup->Title = $membersGroupName;
         $membersGroup->AccessAllSubsites = true;
         $membersGroup->write();
         $membersGroup->Subsites()->add($this->owner);
         $membersGroup->write();
     }
 }
开发者ID:lekoala,项目名称:silverstripe-subsites-extras,代码行数:47,代码来源:SubsiteExtension.php

示例3: requireDefaultRecords

 /**
  * Create permissions, groups and member records if they don't exist.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $groups = array();
     // create or update groups, cache id by title
     foreach (self::$groups as $title => $description) {
         if (!($group = DataObject::get_one('Group', " Title = '{$title}'"))) {
             $group = new Group(array('Title' => $title));
         }
         // update description if exists, otherwise set
         $group->Description = $description;
         $group->write();
         $groups[$title] = $group->ID;
     }
     // create or update permissions and assign to associated group
     foreach (self::$permissions as $code => $groupTitle) {
         if (!($perm = DataObject::get_one('Permission', " Code = '{$code}' "))) {
             $perm = new Permission(array('Code' => $code));
         }
         $perm->GroupID = $groups[$groupTitle];
         $perm->write();
     }
     // if config option is true create or update members, then add Member to group
     if ($this->config()->get('create_members_and_assign_to_groups') === true) {
         foreach (self::$members as $memberInfo) {
             $email = $memberInfo['Email'];
             if (!($member = DataObject::get_one('Member', " Email = '{$email}' "))) {
                 $member = new Member();
             }
             // set or update data
             $member->update($memberInfo);
             $member->write();
             foreach (self::$member_groups[$email] as $groupTitle) {
                 // if not in the group already add it
                 $groupID = $groups[$groupTitle];
                 if (!$member->Groups()->filter('ID', $groupID)->first()) {
                     $member->Groups()->add($groupID);
                 }
                 $member->write();
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:govtnz-replicant,代码行数:46,代码来源:ReplicantPermissions.php

示例4: deny

 /**
  * Deny the given permission code/arg to the given group
  *
  * @param int $groupID The ID of the group
  * @param string $code The permission code
  * @param string Optional: The permission argument (e.g. a page ID).
  * @returns Permission Returns the new permission object.
  */
 public static function deny($groupID, $code, $arg = "any")
 {
     $perm = new Permission();
     $perm->GroupID = $groupID;
     $perm->Code = $code;
     $perm->Type = self::DENY_PERMISSION;
     // Arg component
     switch ($arg) {
         case "any":
             break;
         case "all":
             $perm->Arg = -1;
         default:
             if (is_numeric($arg)) {
                 $perm->Arg = $arg;
             } else {
                 user_error("Permission::checkMember: bad arg '{$arg}'", E_USER_ERROR);
             }
     }
     $perm->write();
     return $perm;
 }
开发者ID:Raiser,项目名称:Praktikum,代码行数:30,代码来源:Permission.php

示例5: logInWithPermission

 /**
  * Create a member and group with the given permission code, and log in with it.
  * Returns the member ID.
  */
 function logInWithPermission($permCode = "ADMIN")
 {
     if (!isset($this->cache_generatedMembers[$permCode])) {
         $group = new Group();
         $group->Title = "{$permCode} group";
         $group->write();
         $permission = new Permission();
         $permission->Code = $permCode;
         $permission->write();
         $group->Permissions()->add($permission);
         $member = DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "{$permCode}@example.org"));
         if (!$member) {
             $member = new Member();
         }
         $member->FirstName = $permCode;
         $member->Surname = "User";
         $member->Email = "{$permCode}@example.org";
         $member->write();
         $group->Members()->add($member);
         $this->cache_generatedMembers[$permCode] = $member;
     }
     $this->cache_generatedMembers[$permCode]->logIn();
 }
开发者ID:hamishcampbell,项目名称:silverstripe-sapphire,代码行数:27,代码来源:SapphireTest.php

示例6: requireDefaultRecords

 /**
  * Creates the default code bank config
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $codeVersion = singleton('CodeBank')->getVersion();
     if (!CodeBankConfig::get()->first()) {
         $conf = new CodeBankConfig();
         $conf->Version = $codeVersion;
         $conf->write();
         DB::alteration_message('Default Code Bank Config Created', 'created');
     }
     if (!Group::get()->filter('Code', 'code-bank-api')->first()) {
         $group = new Group();
         $group->Title = 'Code Bank Users';
         $group->Description = 'Code Bank Access Group';
         $group->Code = 'code-bank-api';
         $group->write();
         $permission = new Permission();
         $permission->Code = 'CODE_BANK_ACCESS';
         $permission->Type = 1;
         $permission->GroupID = $group->ID;
         $permission->write();
         DB::alteration_message('Code Bank Users Group Created', 'created');
     }
     //Check for and perform any needed updates
     $codeVersionTmp = explode(' ', $codeVersion);
     $dbVerTmp = explode(' ', CodeBankConfig::CurrentConfig()->Version);
     if ($codeVersionTmp[0] != '@@VERSION@@' && $codeVersionTmp[0] != $dbVerTmp[0]) {
         $updateXML = simplexml_load_string(file_get_contents('http://update.edchipman.ca/codeBank/airUpdate.xml'));
         $latestVersion = strip_tags($updateXML->version->asXML());
         $versionTmp = explode(' ', $latestVersion);
         //Sanity Check code version against latest
         if (version_compare($codeVersionTmp[0], $versionTmp[0], '>')) {
             DB::alteration_message('Unknown Code Bank server version ' . $codeVersion . ', current version available for download is ' . $latestVersion, 'error');
             return;
         }
         //Sanity Check make sure latest version is installed
         if ($codeVersionTmp[0] != $versionTmp[0]) {
             DB::alteration_message('A Code Bank Server update is available, please <a href="http://programs.edchipman.ca/applications/code-bank/">download</a> and install the update then run dev/build again.', 'error');
             return;
         }
         //Sanity Check database version against latest
         if (version_compare($dbVerTmp[0], $versionTmp[0], '<')) {
             $data = array('version' => CodeBankConfig::CurrentConfig()->Version, 'db_type' => 'SERVER');
             $data = http_build_query($data);
             $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($data) . "\r\n", 'content' => $data)));
             //Download and run queries needed
             $sql = simplexml_load_string(file_get_contents('http://update.edchipman.ca/codeBank/DatabaseUpgrade.php', false, $context));
             $sets = count($sql->query);
             foreach ($sql->query as $query) {
                 $queries = explode('$', $query);
                 $t = count($queries);
                 foreach ($queries as $query) {
                     if (empty($query)) {
                         continue;
                     }
                     DB::query($query);
                 }
             }
             //Update Database Version
             $codeBankConfig = CodeBankConfig::CurrentConfig();
             $codeBankConfig->Version = $latestVersion;
             $codeBankConfig->write();
             DB::alteration_message('Code Bank Server database upgraded', 'changed');
         }
     }
 }
开发者ID:helpfulrobot,项目名称:undefinedoffset-silverstripe-codebank,代码行数:69,代码来源:CodeBankConfig.php

示例7: logInWithPermssion

 /**
  * Create a member and group with the given permission code, and log in with it.
  * Returns the member ID.
  */
 function logInWithPermssion($permCode = "ADMIN")
 {
     if (!isset($this->cache_generatedMembers[$permCode])) {
         $group = new Group();
         $group->Title = "{$permCode} group";
         $group->write();
         $permission = new Permission();
         $permission->Code = $permCode;
         $permission->write();
         $group->Permissions()->add($permission);
         $member = new Member();
         $member->FirstName = $permCode;
         $member->Surname = "User";
         $member->Email = "{$permCode}@example.org";
         $member->write();
         $group->Members()->add($member);
         $this->cache_generatedMembers[$permCode] = $member;
     }
     $this->cache_generatedMembers[$permCode]->logIn();
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:24,代码来源:SapphireTest.php


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