diff --git a/lib/base/dao/dao.class.php b/lib/base/dao/dao.class.php index 1e6228293a..ccb61b5ff5 100644 --- a/lib/base/dao/dao.class.php +++ b/lib/base/dao/dao.class.php @@ -569,9 +569,10 @@ class baseDAO * Remove the part after order and limit. **/ $subLength = strlen($sql); - $groupPOS = strripos($sql, 'group by'); - $orderPOS = strripos($sql, 'order by'); - $limitPOS = strripos($sql, 'limit'); + $lastRight = strrpos($sql, ')') > 0 ? strrpos($sql, ')') : 0; + $groupPOS = strripos($sql, 'group by', $lastRight); + $orderPOS = strripos($sql, 'order by', $lastRight); + $limitPOS = strripos($sql, 'limit', $lastRight); if($limitPOS) $subLength = $limitPOS; if($orderPOS) $subLength = $orderPOS; if($groupPOS) $subLength = $groupPOS; diff --git a/module/doc/model.php b/module/doc/model.php index bb940baad3..9ed474d436 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -663,13 +663,18 @@ class docModel extends model $hasPrivDocIdList = $this->getPrivDocs($allLibIDList); if(in_array($type, array('view', 'collect'))) { - $docs = $this->dao->select('t1.*,t3.name as libName,t3.type as objectType,max(t2.`date`) as date')->from(TABLE_DOC)->alias('t1')->leftJoin(TABLE_DOCACTION)->alias('t2')->on("t1.id=t2.doc")->leftJoin(TABLE_DOCLIB)->alias('t3')->on("t1.lib=t3.id") + $docSQL = $this->dao->select('MAX(id)')->from(TABLE_DOCACTION) + ->where('action')->eq($type) + ->andWhere('actor')->eq($this->app->user->account) + ->groupBy('doc') + ->get(); + + $docs = $this->dao->select('t1.*,t2.date,t3.name as libName')->from(TABLE_DOC)->alias('t1') ->where('t1.deleted')->eq(0) ->andWhere('t1.lib')->ne('') ->andWhere('t1.type')->in($this->config->doc->docTypes) ->andWhere('t1.vision')->eq($this->config->vision) - ->andWhere('t2.action')->eq($type) - ->andWhere('t2.actor')->eq($this->app->user->account) + ->andWhere('t2.id')->subIn($docSQL) ->beginIF(!common::hasPriv('doc', 'productSpace'))->andWhere('t3.type')->ne('product')->fi() ->beginIF(!common::hasPriv('doc', 'projectSpace'))->andWhere('t3.type')->notIN('project,execution')->fi() ->beginIF(!common::hasPriv('doc', 'teamSpace'))->andWhere('t3.type')->ne('custom')->fi() @@ -677,7 +682,6 @@ class docModel extends model ->beginIF($browseType == 'draft')->andWhere('t1.status')->eq('draft')->andWhere('t1.addedBy')->eq($this->app->user->account)->fi() ->beginIF($browseType == 'bysearch')->andWhere($query)->fi() ->beginIF(!empty($hasPrivDocIdList))->andWhere('t1.id')->in($hasPrivDocIdList)->fi() - ->groupBy('t1.id') ->orderBy($orderBy) ->page($pager, 't1.id') ->fetchAll('id');