diff --git a/module/fid_bbi/src/fid_bbi/Db/Table/ResourceTagsTrait.php b/module/fid_bbi/src/fid_bbi/Db/Table/ResourceTagsTrait.php index 728740aad6c6760ca14b0aec68299370c52292a6..be84e7ea4c6f59d6e8e8d8b2b22350aacffbe60f 100644 --- a/module/fid_bbi/src/fid_bbi/Db/Table/ResourceTagsTrait.php +++ b/module/fid_bbi/src/fid_bbi/Db/Table/ResourceTagsTrait.php @@ -1,13 +1,11 @@ <?php - namespace fid_bbi\Db\Table; -use Zend\Db\Sql\Select, - Zend\Db\Sql\Expression; +use Zend\Db\Sql\Expression; +use Zend\Db\Sql\Select; trait ResourceTagsTrait { - /** * Get a subquery used for determining first post date of a tag. * @@ -26,19 +24,28 @@ trait ResourceTagsTrait return $sub; } - protected function addFirstPosted($select,$olderThan=true,$age = "7 days",$resourceTagsTableName = 'rt') { - + protected function addFirstPosted($select, $userId = null, $olderThan = true, $age = "7 days", $resourceTagsTableName = 'rt') + { $select->join( ['first' => $this->getFirstPostedSubquery()], - $resourceTagsTableName.'.tag_id = first.tag_id', + $resourceTagsTableName . '.tag_id = first.tag_id', [], Select::JOIN_INNER ); if ($olderThan) { - $select->where->lessThan( - 'first.first_posted', - date('Y-m-d H:i:s', strtotime("-" . $age)) - ); + if ($userId) { + // in case the current user is querying for their own tags + // we do not have to fulfil date constarints + $select->where->nest->lessThan( + 'first.first_posted', + date('Y-m-d H:i:s', strtotime("-" . $age)) + )->or->equalTo('user_id', $userId); + } else { + $select->where->lessThan( + 'first.first_posted', + date('Y-m-d H:i:s', strtotime("-" . $age)) + ); + } } else { // otherwise we look for younger entries $select->where->greaterThan( @@ -47,4 +54,4 @@ trait ResourceTagsTrait ); } } -} \ No newline at end of file +} diff --git a/module/fid_bbi/src/fid_bbi/Db/Table/Tags.php b/module/fid_bbi/src/fid_bbi/Db/Table/Tags.php index f08117adf55e2ef557a2f1c548fe0ac092e85c9a..1c5c3513ff0f266417dbef24b55002eb0589998d 100644 --- a/module/fid_bbi/src/fid_bbi/Db/Table/Tags.php +++ b/module/fid_bbi/src/fid_bbi/Db/Table/Tags.php @@ -249,7 +249,7 @@ class Tags extends BaseTags if (null !== $user) { $select->where->equalTo('rt.user_id', $user); } - $this->addFirstPosted($select); + $this->addFirstPosted($select, $userToCheck); } ); }