Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 从多个对象ID进行筛选_Sql_Performance_Query Optimization_Ezpublish - Fatal编程技术网

Sql 从多个对象ID进行筛选

Sql 从多个对象ID进行筛选,sql,performance,query-optimization,ezpublish,Sql,Performance,Query Optimization,Ezpublish,我正在尝试筛选一个文件 我有一个类,它有一个对象关系属性。My filter允许获取由object relations属性筛选的此类对象 我已经开始使用增强的对象关系过滤扩展(),但是这个扩展只适用于“AND”条件,而我希望使用“OR” 我能够编辑文件以添加“或”逻辑,这就是我得到的: <?php class EORExtendedFilter { function CreateSqlParts( $params ) { $db =& eZDB::

我正在尝试筛选一个文件

我有一个类,它有一个对象关系属性。My filter允许获取由object relations属性筛选的此类对象

我已经开始使用增强的对象关系过滤扩展(),但是这个扩展只适用于“AND”条件,而我希望使用“OR”

我能够编辑文件以添加“或”逻辑,这就是我得到的:

<?php
class EORExtendedFilter
{

    function CreateSqlParts( $params )
    {
        $db =& eZDB::instance();

        $tables = array();
        $joins  = array();

        // foreach filtered attribute, we add a join the relation table and filter
        // on the attribute ID + object ID
        foreach( $params as $param )
        {
            if ( !is_array( $param ) )
                continue;

            if ( !is_numeric( $param[0] ) )
            {
                $classAttributeId = eZContentObjectTreeNode::classAttributeIDByIdentifier( $param[0] );
            }
            else
            {
                $classAttributeId = $param[0];
            }

            // multiple objects ids
            if ( is_array($param[1]) )
            {
                foreach( $param[1] as $objectId )
                {
                    $join = array(); // 'OR' logic

                    if ( is_numeric( $objectId ) )
                    {
                        $tableName = 'eor_link_' . $objectId;
                        $tables[] = 'ezcontentobject_link ' . $tableName;

                        $join[]  = $tableName . '.from_contentobject_id = ezcontentobject.id';
                        $join[]  = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
                        $join[]  = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
                        $join[]  = $tableName . '.to_contentobject_id = ' . $objectId;
                    }

                    // 'OR' logic
                    $joins[] = $join;

                }
            }
            // single object id
            else
            {
                $objectId = $param[1];

                $tableName = 'eor_link_' . $objectId;
                $tables[] = 'ezcontentobject_link ' . $tableName;

                $joins[]  = $tableName . '.from_contentobject_id = ezcontentobject.id';
                $joins[]  = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
                $joins[]  = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
                $joins[]  = $tableName . '.to_contentobject_id = ' . $objectId;
            }
        }

        if ( !count( $tables ) or !count( $joins ) )
        {
            $tables = $joins = '';
        }
        else
        {
            $tables = "\n, "    . implode( "\n, ", $tables );

            // 'OR' logic
            if ( is_array($param[1]) )
            {
                $andClauses = array();
                foreach ($joins as $attr)
                {
                    $andClauses[] = implode( " AND\n ", $attr );
                }

                $joins =  implode( " OR\n ", $andClauses ) . " AND\n ";               
            }
            else
            {
                $joins =  implode( " AND\n ", $joins ) . " AND\n ";
            }

        }

        return array( 'tables' => $tables, 'joins' => $joins );
    }
}

我通过使用
eZPersistentObject::fetchObjectList()
重写所有内容解决了这个问题

SELECT DISTINCT
                       ezcontentobject.*,
                       ezcontentobject_tree.*,
                       ezcontentclass.serialized_name_list as class_serialized_name_list,
                       ezcontentclass.identifier as class_identifier,
                       ezcontentclass.is_container as is_container

                       , ezcontentobject_name.name as name,  ezcontentobject_name.real_translation 
                       , a0.sort_key_int

                   FROM
                      ezcontentobject_tree,
                      ezcontentobject,ezcontentclass
                      , ezcontentobject_name 
                      , ezcontentobject_attribute a0


, ezcontentobject_link eor_link_126
, ezcontentobject_link eor_link_127

                   WHERE
                      ezcontentobject_tree.parent_node_id = 1443 and
                      ((eor_link_126.from_contentobject_id = ezcontentobject.id AND
 eor_link_126.from_contentobject_version = ezcontentobject.current_version AND
 eor_link_126.contentclassattribute_id = 537 AND
 eor_link_126.to_contentobject_id = 126) OR
 (eor_link_127.from_contentobject_id = ezcontentobject.id AND
 eor_link_127.from_contentobject_version = ezcontentobject.current_version AND
 eor_link_127.contentclassattribute_id = 537 AND
 eor_link_127.to_contentobject_id = 127)) AND


                                   a0.contentobject_id = ezcontentobject.id AND
                                   a0.contentclassattribute_id = 191 AND
                                   a0.version = ezcontentobject_name.content_version AND
 ( a0.language_id & ezcontentobject.language_mask > 0 AND
     ( (   ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 2 ) )
   <
     ( a0.language_id & 1 )
   + ( ( a0.language_id & 2 ) )
 ) 
 AND 

                      ezcontentclass.version=0 AND

                      ezcontentobject_tree.contentobject_id = ezcontentobject.id  AND
                      ezcontentclass.id = ezcontentobject.contentclass_id AND

                         ezcontentobject.contentclass_id  IN  ( 17 ) AND
                       ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
                                   ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and 
 ( ezcontentobject_name.language_id & ezcontentobject.language_mask > 0 AND
     ( (   ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 2 ) )
   <
     ( ezcontentobject_name.language_id & 1 )
   + ( ( ezcontentobject_name.language_id & 2 ) )
 ) 

                      AND ezcontentobject_tree.is_invisible = 0


                       AND 
 ezcontentobject.language_mask & 3 > 0 

                 ORDER BY a0.sort_key_int DESC
LIMIT 0, 10