當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataObjectSet::insertFirst方法代碼示例

本文整理匯總了PHP中DataObjectSet::insertFirst方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataObjectSet::insertFirst方法的具體用法?PHP DataObjectSet::insertFirst怎麽用?PHP DataObjectSet::insertFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataObjectSet的用法示例。


在下文中一共展示了DataObjectSet::insertFirst方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: DataObjectSet

 /**
  * Return the subsites that the current user can access.
  * Look for one of the given permission codes on the site.
  *
  * Sites and Templates will only be included if they have a Title
  *
  * @param $permCode array|string Either a single permission code or an array of permission codes.
  * @param $includeMainSite If true, the main site will be included if appropriate.
  * @param $mainSiteTitle The label to give to the main site
  */
 function accessible_sites($permCode, $includeMainSite = false, $mainSiteTitle = "Main site", $member = null)
 {
     // Rationalise member arguments
     if (!$member) {
         $member = Member::currentUser();
     }
     if (!$member) {
         return new DataObjectSet();
     }
     if (!is_object($member)) {
         $member = DataObject::get_by_id('Member', $member);
     }
     if (is_array($permCode)) {
         $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
     } else {
         $SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
     }
     $templateClassList = "'" . implode("', '", ClassInfo::subclassesFor("Subsite_Template")) . "'";
     $subsites = DataObject::get('Subsite', "\"Subsite\".\"Title\" != ''", '', "LEFT JOIN \"Group_Subsites\" \n\t\t\t\tON \"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"\n\t\t\tINNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\"\n\t\t\t\tOR \"Group\".\"AccessAllSubsites\" = 1\n\t\t\tINNER JOIN \"Group_Members\" \n\t\t\t\tON \"Group_Members\".\"GroupID\"=\"Group\".\"ID\"\n\t\t\t\tAND \"Group_Members\".\"MemberID\" = {$member->ID}\n\t\t\tINNER JOIN \"Permission\" \n\t\t\t\tON \"Group\".\"ID\"=\"Permission\".\"GroupID\"\n\t\t\t\tAND \"Permission\".\"Code\" IN ({$SQL_codes}, 'ADMIN')");
     $rolesSubsites = DataObject::get('Subsite', "\"Subsite\".\"Title\" != ''", '', "LEFT JOIN \"Group_Subsites\" \n\t\t\t\tON \"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"\n\t\t\tINNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\"\n\t\t\t\tOR \"Group\".\"AccessAllSubsites\" = 1\n\t\t\tINNER JOIN \"Group_Members\" \n\t\t\t\tON \"Group_Members\".\"GroupID\"=\"Group\".\"ID\"\n\t\t\t\tAND \"Group_Members\".\"MemberID\" = {$member->ID}\n\t\t\tINNER JOIN \"Group_Roles\"\n\t\t\t\tON \"Group_Roles\".\"GroupID\"=\"Group\".\"ID\"\n\t\t\tINNER JOIN \"PermissionRole\"\n\t\t\t\tON \"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\"\n\t\t\tINNER JOIN \"PermissionRoleCode\"\n\t\t\t\tON \"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\"\n\t\t\t\tAND \"PermissionRoleCode\".\"Code\" IN ({$SQL_codes}, 'ADMIN')");
     if (!$subsites && $rolesSubsites) {
         return $rolesSubsites;
     }
     if ($rolesSubsites) {
         foreach ($rolesSubsites as $subsite) {
             if (!$subsites->containsIDs(array($subsite->ID))) {
                 $subsites->push($subsite);
             }
         }
     }
     // Include the main site
     if (!$subsites) {
         $subsites = new DataObjectSet();
     }
     if ($includeMainSite) {
         if (!is_array($permCode)) {
             $permCode = array($permCode);
         }
         if (self::hasMainSitePermission($member, $permCode)) {
             $mainSite = new Subsite();
             $mainSite->Title = $mainSiteTitle;
             $subsites->insertFirst($mainSite);
         }
     }
     return $subsites;
 }
開發者ID:hafriedlander,項目名稱:silverstripe-config-experiment,代碼行數:56,代碼來源:Subsite.php


注:本文中的DataObjectSet::insertFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。