当前位置: 首页>>代码示例>>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;未经允许,请勿转载。