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


PHP DataObject::context_obj方法代碼示例

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


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

示例1: augmentSQL

 /**
  * Update any requests to limit the results to the current site
  */
 function augmentSQL(SQLQuery &$query)
 {
     if (Subsite::$disable_subsite_filter) {
         return;
     }
     // Don't run on delete queries, since they are always tied to
     // a specific ID.
     if ($query->delete) {
         return;
     }
     // If you're querying by ID, ignore the sub-site - this is a bit ugly...
     // if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) {
     if (!$query->where || !preg_match('/\\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0])) {
         if (Subsite::$force_subsite) {
             $subsiteID = Subsite::$force_subsite;
         } else {
             if ($context = DataObject::context_obj()) {
                 $subsiteID = (int) $context->SubsiteID;
             } else {
                 $subsiteID = (int) Subsite::currentSubsiteID();
             }
         }
         // The foreach is an ugly way of getting the first key :-)
         foreach ($query->from as $tableName => $info) {
             // The tableName should be SiteTree or SiteTree_Live...
             if (strpos($tableName, 'SiteTree') === false) {
                 break;
             }
             $query->where[] = "\"{$tableName}\".\"SubsiteID\" IN ({$subsiteID})";
             break;
         }
     }
 }
開發者ID:hafriedlander,項目名稱:silverstripe-config-experiment,代碼行數:36,代碼來源:SiteTreeSubsites.php

示例2: augmentSQL

 /**
  * Update any requests to limit the results to the current site
  */
 function augmentSQL(SQLQuery &$query)
 {
     if (Subsite::$disable_subsite_filter) {
         return;
     }
     // If you're querying by ID, ignore the sub-site - this is a bit ugly...
     if (!$query->where || !preg_match('/\\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]) && !preg_match('/\\.?(\'|"|`|)SubsiteID(\'|"|`|)( ?)=/', $query->where[0])) {
         if ($context = DataObject::context_obj()) {
             $subsiteID = (int) $context->SubsiteID;
         } else {
             $subsiteID = (int) Subsite::currentSubsiteID();
         }
         $tableName = array_shift(array_keys($query->from));
         if ($tableName != 'SiteConfig') {
             return;
         }
         $query->where[] = "\"{$tableName}\".\"SubsiteID\" IN ({$subsiteID})";
     }
 }
開發者ID:hafriedlander,項目名稱:silverstripe-config-experiment,代碼行數:22,代碼來源:SiteConfigSubsites.php

示例3: augmentSQL

 /**
  * Update any requests to limit the results to the current site
  */
 function augmentSQL(SQLQuery &$query)
 {
     // If you're querying by ID, ignore the sub-site - this is a bit ugly... (but it was WAYYYYYYYYY worse)
     if (!$query->where || !preg_match('/\\.(\'|"|`|)ID(\'|"|`|)/', $query->where[0])) {
         if ($context = DataObject::context_obj()) {
             $subsiteID = (int) $context->SubsiteID;
         } else {
             $subsiteID = (int) Subsite::currentSubsiteID();
         }
         // The foreach is an ugly way of getting the first key :-)
         foreach ($query->from as $tableName => $info) {
             $where = "\"{$tableName}\".\"SubsiteID\" IN (0, {$subsiteID})";
             $query->where[] = $where;
             break;
         }
         $isCounting = strpos($query->select[0], 'COUNT') !== false;
         // Ordering when deleting or counting doesn't apply
         if (!$query->delete && !$isCounting) {
             $query->orderby = "\"SubsiteID\"" . ($query->orderby ? ', ' : '') . $query->orderby;
         }
     }
 }
開發者ID:hafriedlander,項目名稱:silverstripe-config-experiment,代碼行數:25,代碼來源:FileSubsites.php

示例4: set_context_obj

	/**
	 * Sets a 'context object' that can be used to provide hints about how to process a particular get / get_one request.
	 * In particular, DataObjectDecorators can use this to amend queries more effectively.
	 * Care must be taken to unset the context object after you're done with it, otherwise you will have a stale context,
	 * which could cause horrible bugs.
	 */
	public static function set_context_obj($obj) {
		if($obj && self::$context_obj) user_error("Dataobject::set_context_obj passed " . $obj->class . "." . $obj->ID . " when there is already a context: " . self::$context_obj->class . '.' . self::$context_obj->ID, E_USER_WARNING);
		self::$context_obj = $obj;
	}
開發者ID:neopba,項目名稱:silverstripe-book,代碼行數:10,代碼來源:DataObject.php

示例5: set_context_obj

 /**
  * Sets a 'context object' that can be used to provide hints about how to process a particular get / get_one request.  
  * In particular, DataObjectDecorators can use this to amend queries more effectively.
  * Care must be taken to unset the context object after you're done with it, otherwise you will have a stale context,
  * which could cause horrible bugs.
  */
 public static function set_context_obj($obj)
 {
     if ($obj && self::$context_obj) {
         user_error("Dataobject::set_context_obj called when there is already a context.", E_USER_WARNING);
     }
     self::$context_obj = $obj;
 }
開發者ID:ramziammar,項目名稱:websites,代碼行數:13,代碼來源:DataObject.php

示例6: augmentSQL

 /**
  * Update any requests to limit the results to the current site
  */
 function augmentSQL(SQLQuery &$query)
 {
     if (Subsite::$disable_subsite_filter) {
         return;
     }
     if (Cookie::get('noSubsiteFilter') == 'true') {
         return;
     }
     // If you're querying by ID, ignore the sub-site - this is a bit ugly...
     if (!$query->filtersOnID()) {
         if ($context = DataObject::context_obj()) {
             $subsiteID = (int) $context->SubsiteID;
         } else {
             $subsiteID = (int) Subsite::currentSubsiteID();
         }
         // Don't filter by Group_Subsites if we've already done that
         $hasGroupSubsites = false;
         foreach ($query->from as $item) {
             if (strpos($item, 'Group_Subsites') !== false) {
                 $hasGroupSubsites = true;
                 break;
             }
         }
         if (!$hasGroupSubsites) {
             if ($subsiteID) {
                 $query->leftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\" \n\t\t\t\t\t\t= \"Group\".\"ID\" AND \"Group_Subsites\".\"SubsiteID\" = {$subsiteID}");
                 $query->where[] = "(\"Group_Subsites\".\"SubsiteID\" IS NOT NULL OR\n\t\t\t\t\t\t\"Group\".\"AccessAllSubsites\" = 1)";
             } else {
                 $query->where[] = "\"Group\".\"AccessAllSubsites\" = 1";
             }
         }
         // WORKAROUND for databases that complain about an ORDER BY when the column wasn't selected (e.g. SQL Server)
         if (!$query->select[0] == 'COUNT(*)') {
             $query->orderby = "\"AccessAllSubsites\" DESC" . ($query->orderby ? ', ' : '') . $query->orderby;
         }
     }
 }
開發者ID:hafriedlander,項目名稱:silverstripe-config-experiment,代碼行數:40,代碼來源:GroupSubsites.php


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