Skip to content
Snippets Groups Projects
Commit 2c2ca1a0 authored by Dorian Merz's avatar Dorian Merz Committed by Robert Lange
Browse files

refs #19719 [fid_bbi] show own tags without date restriction

parent ab52052a
Branches
Tags
No related merge requests found
<?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
}
......@@ -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);
}
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment