本文整理汇总了PHP中SQLQuery::filtersOnID方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLQuery::filtersOnID方法的具体用法?PHP SQLQuery::filtersOnID怎么用?PHP SQLQuery::filtersOnID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLQuery
的用法示例。
在下文中一共展示了SQLQuery::filtersOnID方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
if (Subsite::$disable_subsite_filter) {
return;
}
if ($dataQuery->getQueryParam('Subsite.filter') === false) {
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->filtersOnID()) {
return;
}
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->getFrom() as $tableName => $info) {
// The tableName should be custommenu...
if (strpos($tableName, 'CustomMenu') === false) {
break;
}
$query->addWhere("\"{$tableName}\".\"SubsiteID\" IN ({$subsiteID})");
break;
}
}
示例2: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
$ctrl = null;
if (Controller::has_curr()) {
$ctrl = Controller::curr();
}
if (Subsite::$disable_subsite_filter) {
return;
}
if ($dataQuery->getQueryParam('Subsite.filter') === false) {
return;
}
if ($ctrl && get_class(Controller::curr()) == 'Security') {
return;
}
// Don't run on delete queries, since they are always tied to
// a specific ID.
if ($query->getDelete()) {
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->filtersOnID()) {
if (Subsite::$force_subsite) {
$subsiteID = Subsite::$force_subsite;
} else {
$subsiteID = (int) Subsite::currentSubsiteID();
}
$froms = $query->getFrom();
$froms = array_keys($froms);
$tableName = array_shift($froms);
$query->addWhere("\"{$tableName}\".\"SubsiteID\" IN ({$subsiteID})");
}
}
示例3: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
// Filters are disabled globally
if (self::$disable) {
return;
}
// Filters are disabled for this query
if ($dataQuery->getQueryParam('SoftDeletable.filter') === false) {
return;
}
// Don't run on delete queries, since they are always tied to a specific ID.
if ($query->getDelete()) {
return;
}
// Don't run if querying by ID
if ($query->filtersOnID()) {
return;
}
$froms = $query->getFrom();
$froms = array_keys($froms);
$tableName = array_shift($froms);
$query->addWhere("\"{$tableName}\".\"Deleted\" IS NULL");
}
示例4: augmentSQL
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
if (!FluentOldPageRedirectFix::$disableSkipIDFilter) {
// Skip ID based filters
if ($query->filtersOnID()) {
return;
}
}
// Skip filter in the CMS, unless filtering is explicitly turned on
$filterAdmin = $dataQuery->getQueryParam('Fluent.FilterAdmin');
if (!$filterAdmin) {
$isFrontend = $dataQuery->getQueryParam('Fluent.IsFrontend');
if ($isFrontend === null) {
$isFrontend = Fluent::is_frontend();
}
if (!$isFrontend) {
return;
}
}
// Add filter for locale
$locale = $dataQuery->getQueryParam('Fluent.Locale') ?: Fluent::current_locale();
$query->addWhere("\"{$this->ownerBaseClass}\".\"LocaleFilter_{$locale}\" = 1");
}
示例5: testFiltersOnID
public function testFiltersOnID()
{
$query = new SQLQuery();
$query->setWhere("ID = 5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with simple unquoted column name");
$query = new SQLQuery();
$query->setWhere("ID=5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with simple unquoted column name and no spaces in equals sign");
$query = new SQLQuery();
$query->setWhere("Identifier = 5");
$this->assertFalse($query->filtersOnID(), "filtersOnID() is false with custom column name (starting with 'id')");
$query = new SQLQuery();
$query->setWhere("ParentID = 5");
$this->assertFalse($query->filtersOnID(), "filtersOnID() is false with column name ending in 'ID'");
$query = new SQLQuery();
$query->setWhere("MyTable.ID = 5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with table and column name");
$query = new SQLQuery();
$query->setWhere("MyTable.ID = 5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with table and quoted column name ");
}
示例6: testFiltersOnID
function testFiltersOnID() {
$query = new SQLQuery();
$query->where[] = "ID = 5";
$this->assertTrue(
$query->filtersOnID(),
"filtersOnID() is true with simple unquoted column name"
);
$query = new SQLQuery();
$query->where[] = "ID=5";
$this->assertTrue(
$query->filtersOnID(),
"filtersOnID() is true with simple unquoted column name and no spaces in equals sign"
);
/*
$query = new SQLQuery();
$query->where[] = "Foo='Bar' AND ID=5";
$this->assertTrue(
$query->filtersOnID(),
"filtersOnID() is true with combined SQL statements"
);
*/
$query = new SQLQuery();
$query->where[] = "Identifier = 5";
$this->assertFalse(
$query->filtersOnID(),
"filtersOnID() is false with custom column name (starting with 'id')"
);
$query = new SQLQuery();
$query->where[] = "ParentID = 5";
$this->assertFalse(
$query->filtersOnID(),
"filtersOnID() is false with column name ending in 'ID'"
);
$query = new SQLQuery();
$query->where[] = "MyTable.ID = 5";
$this->assertTrue(
$query->filtersOnID(),
"filtersOnID() is true with table and column name"
);
$query = new SQLQuery();
$query->where[] = "MyTable.`ID`= 5";
$this->assertTrue(
$query->filtersOnID(),
"filtersOnID() is true with table and quoted column name "
);
}
示例7: augmentSQL
/**
* Changes any SELECT query thats not filtering on an ID
* to limit by the current language defined in {@link get_current_locale()}.
* It falls back to "Locale='' OR Lang IS NULL" and assumes that
* this implies querying for the default language.
*
* Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering".
*/
function augmentSQL(SQLQuery &$query)
{
// If the record is saved (and not a singleton), and has a locale,
// limit the current call to its locale. This fixes a lot of problems
// with other extensions like Versioned
$locale = $this->owner->ID && $this->owner->Locale ? $this->owner->Locale : Translatable::get_current_locale();
$baseTable = ClassInfo::baseDataClass($this->owner->class);
$where = $query->where;
if ($locale && self::locale_filter_enabled() && !$query->filtersOnID() && array_search($baseTable, array_keys($query->from)) !== false && !preg_match('/("|\'|`)Locale("|\'|`)/', $query->getFilter())) {
$qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale));
$query->where[] = $qry;
}
}
示例8: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
public 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->getFrom() as $item) {
if (is_array($item) && strpos($item['table'], 'Group_Subsites') !== false || !is_array($item) && strpos($item, 'Group_Subsites') !== false) {
$hasGroupSubsites = true;
break;
}
}
if (!$hasGroupSubsites) {
if ($subsiteID) {
$query->addLeftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\"\n\t\t\t\t\t\t= \"Group\".\"ID\" AND \"Group_Subsites\".\"SubsiteID\" = {$subsiteID}");
$query->addWhere("(\"Group_Subsites\".\"SubsiteID\" IS NOT NULL OR\n\t\t\t\t\t\t\"Group\".\"AccessAllSubsites\" = 1)");
}
}
// WORKAROUND for databases that complain about an ORDER BY when the column wasn't selected (e.g. SQL Server)
$select = $query->getSelect();
if ($hasGroupSubsites && $subsiteID && isset($select[0]) && !$select[0] == 'COUNT(*)') {
$query->orderby = "\"AccessAllSubsites\" DESC" . ($query->orderby ? ', ' : '') . $query->orderby;
}
}
}
示例9: augmentSQL
/**
* Filter records on the current variant
*
* @param SQLQuery $query
* @param DataQuery $dataQuery
*/
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
$variant = SolrReindexTest_Variant::get_current();
if ($variant !== null && !$query->filtersOnID()) {
$sqlVariant = Convert::raw2sql($variant);
$query->addWhere("\"Variant\" = '{$sqlVariant}'");
}
}
示例10: augmentSQL
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
// Skip ID based filters
if ($query->filtersOnID()) {
return;
}
// Skip filter in the CMS
$isFrontend = $dataQuery->getQueryParam('Fluent.IsFrontend');
if ($isFrontend === null) {
$isFrontend = Fluent::is_frontend();
}
if (!$isFrontend) {
return;
}
// Add filter for locale
$locale = $dataQuery->getQueryParam('Fluent.Locale') ?: Fluent::current_locale();
$query->addWhere("\"{$this->ownerBaseClass}\".\"LocaleFilter_{$locale}\" = 1");
}
示例11: testFiltersOnID
public function testFiltersOnID()
{
$query = new SQLQuery();
$query->setWhere("ID = 5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with simple unquoted column name");
$query = new SQLQuery();
$query->setWhere('"ID" = 5');
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with simple quoted column name");
$query = new SQLQuery();
$query->setWhere(array('"ID"' => 4));
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with parameterised quoted column name");
$query = new SQLQuery();
$query->setWhere(array('"ID" = ?' => 4));
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with parameterised quoted column name");
$query = new SQLQuery();
$query->setWhere('"ID" IN (5,4)');
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with WHERE ID IN");
$query = new SQLQuery();
$query->setWhere(array('"ID" IN ?' => array(1, 2)));
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with parameterised WHERE ID IN");
$query = new SQLQuery();
$query->setWhere("ID=5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with simple unquoted column name and no spaces in equals sign");
$query = new SQLQuery();
$query->setWhere("Identifier = 5");
$this->assertFalse($query->filtersOnID(), "filtersOnID() is false with custom column name (starting with 'id')");
$query = new SQLQuery();
$query->setWhere("ParentID = 5");
$this->assertFalse($query->filtersOnID(), "filtersOnID() is false with column name ending in 'ID'");
$query = new SQLQuery();
$query->setWhere("MyTable.ID = 5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with table and column name");
$query = new SQLQuery();
$query->setWhere("MyTable.ID = 5");
$this->assertTrue($query->filtersOnID(), "filtersOnID() is true with table and quoted column name ");
}
示例12: augmentSQL
/**
* Changes any SELECT query thats not filtering on an ID
* to limit by the current language defined in {@link get_current_locale()}.
* It falls back to "Locale='' OR Lang IS NULL" and assumes that
* this implies querying for the default language.
*
* Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering".
*/
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
// If the record is saved (and not a singleton), and has a locale,
// limit the current call to its locale. This fixes a lot of problems
// with other extensions like Versioned
if ($this->owner->ID && !empty($this->owner->Locale)) {
$locale = $this->owner->Locale;
} else {
$locale = Translatable::get_current_locale();
}
$baseTable = ClassInfo::baseDataClass($this->owner->class);
if ($locale && self::locale_filter_enabled() && $dataQuery->getQueryParam(self::QUERY_LOCALE_FILTER_ENABLED) && !$query->filtersOnID() && array_search($baseTable, array_keys($query->getFrom())) !== false && !preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhere()))) {
$qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale));
$query->addWhere($qry);
}
}