0

我正在使用 php 函数来创建带有分页的条目的用户列表。我需要删除没有名称的条目,所以我尝试了这段代码,但它不起作用:没有名称的条目不会被删除。

$listing->entries( $order, $eLimit, $eLimStart, true, array('owner' => $userid, 'name' != null), false, $section);

相反的效果很好,使用此代码,我得到所有没有名称的条目:

$listing->entries( $order, $eLimit, $eLimStart, true, array('owner' => $userid, 'name' => null), false, $section);

名称在 DB 中是这样存储的:

- type: varchar(250)
- interclassement: utf8_general_ci
- Null: Yes
- Default: NULL

我正在使用 PHP 版本 5.3.16。

请问我做错了什么?非常感谢。

**编辑* * 上下文:Joomla 2.5.9 和 SobiPro 1.08。我使用 SobiPro API 创建列表:

$listing = SPFactory::Controller('listing');
$listing = new SPListingCtrl();

函数条目如下所示

public function entries( $eOrder, $eLimit = null, $eLimStart = null, $count = false, $conditions = array(), $entriesRecursive = false, $pid = -1 )
{
    return $this->getEntries( $eOrder, $eLimit, $eLimStart, $count, $conditions, $entriesRecursive, $pid );
}

函数 getEntries 如下所示:

/**
 * @param string $eOrder
 * @param int $eLimit
 * @param int $eLimStart
 * @return array
 */
public function getEntries( $eOrder, $eLimit = null, $eLimStart = null, $count = false, $conditions = array(), $entriesRecursive = false, $pid = 0 )
{
    /* var SPDb $db */
    $db =& SPFactory::db();
    $eClass = SPLoader::loadModel( 'entry' );
    $entries = array();
    $eDir = 'asc';
    $oPrefix = null;
    $conditions = is_array( $conditions ) ? $conditions : array();

    /* get the ordering and the direction */
    if ( strstr( $eOrder, '.' ) ) {
        $eOr = explode( '.', $eOrder );
        $eOrder = array_shift( $eOr );
        $eDir = implode( '.', $eOr );
    }
    $pid = $pid ? $pid : SPRequest::sid();
    /* if sort by name, then sort by the name field */
    if ( $eOrder == 'name' ) {
        $eOrder = SPFactory::config()->nameField()->get( 'fid' );
    }
    if ( $entriesRecursive ) {
        $pids = $this->_model->getChilds( 'category', true );
        if ( is_array( $pids ) ) {
            $pids = array_keys( $pids );
        }
        $pids[ ] = SPRequest::sid();
        $conditions[ 'sprl.pid' ] = $pids;
    }
    else {
        $conditions[ 'sprl.pid' ] = $pid;
    }
    if ( $pid == -1 ) {
        unset( $conditions[ 'sprl.pid' ] );
    }

    /* sort by field */
    if ( strstr( $eOrder, 'field_' ) ) {
        static $field = null;
        $specificMethod = false;
        if ( !$field ) {
            try {
                $db->select( 'fieldType', 'spdb_field', array( 'nid' => $eOrder, 'section' => Sobi::Section() ) );
                $fType = $db->loadResult();
            }
            catch ( SPException $x ) {
                Sobi::Error( $this->name(), SPLang::e( 'CANNOT_DETERMINE_FIELD_TYPE', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
            }
            if ( $fType ) {
                $field = SPLoader::loadClass( 'opt.fields.' . $fType );
            }
        }
        if ( $field && method_exists( $field, 'sortBy' ) ) {
            $table = null;
            $oPrefix = null;
            $specificMethod = call_user_func_array( array( $field, 'sortBy' ), array( &$table, &$conditions, &$oPrefix, &$eOrder, &$eDir ) );
        }
        if ( !$specificMethod ) {
            $table = $db->join(
                array(
                    array( 'table' => 'spdb_field', 'as' => 'fdef', 'key' => 'fid' ),
                    array( 'table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid' ),
                    array( 'table' => 'spdb_object', 'as' => 'spo', 'key' => array( 'fdata.sid', 'spo.id' ) ),
                    array( 'table' => 'spdb_relations', 'as' => 'sprl', 'key' => array( 'fdata.sid', 'sprl.id' ) ),
                )
            );
            $oPrefix = 'spo.';
            $conditions[ 'spo.oType' ] = 'entry';
            $conditions[ 'fdef.nid' ] = $eOrder;
         //   $eOrder = 'baseData.' . $eDir;
         $eOrder = 'baseData = "", CONVERT(baseData,UNSIGNED INTEGER).' . $eDir;
        }
    }

    else {
        $table = $db->join( array(
            array( 'table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id' ),
            array( 'table' => 'spdb_object', 'as' => 'spo', 'key' => 'id' )
        ) );
        $conditions[ 'spo.oType' ] = 'entry';
        $eOrder = $eOrder . '.' . $eDir;
        $oPrefix = 'spo.';
        if ( strstr( $eOrder, 'valid' ) ) {
            $eOrder = $oPrefix . $eOrder;
        }
    }

    /* check user permissions for the visibility */
    if ( Sobi::My( 'id' ) ) {
        $this->userPermissionsQuery( $conditions, $oPrefix );
        if( isset( $conditions[ $oPrefix . 'state' ] ) && $conditions[ $oPrefix . 'state' ] ) {
            $conditions[ 'sprl.copy' ] = 0;
        }
    }
    else {
        $conditions = array_merge( $conditions, array( $oPrefix . 'state' => '1', '@VALID' => $db->valid( $oPrefix . 'validUntil', $oPrefix . 'validSince' ) ) );
        $conditions[ 'sprl.copy' ] = '0';
    }
    try {
        $db->select( $oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true );
        $results = $db->loadResultArray();
    }
    catch ( SPException $x ) {
        Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
    }
    Sobi::Trigger( $this->name(), 'AfterGetEntries', array( &$results, $count ) );
    if ( count( $results ) && !$count ) {
        $memLimit = ( int )ini_get( 'memory_limit' ) * 2097152;
        foreach ( $results as $i => $sid ) {
            // it needs too much memory moving the object creation to the view
            //$entries[ $i ] = SPFactory::Entry( $sid );
            $entries[ $i ] = $sid;
        }
    }
    if ( $count ) {
        return $results;
    }
    return $entries;
}
4

2 回答 2

0

而不是寻找非空条目,也许您可​​以做相反的事情并寻找具有某些内容的条目,如下所示:

$listing->entries( $order, $eLimit, $eLimStart, true, array('owner' => $userid, 'name' => '%'), false, $section);

然而,这纯粹是一种猜测,因为我们需要查看entries函数以了解如何处理各种参数。

于 2013-04-15T19:00:47.477 回答
0

已解决 - 感谢大家的帮助!

$listing->entries($order, $eLimit, $eLimStart, true, array('owner' => $userid, '!name' => null), false, -1);

于 2013-04-16T09:58:47.210 回答