Added search in activity stream
This commit is contained in:
103
app/Filter/BaseDateFilter.php
Normal file
103
app/Filter/BaseDateFilter.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Filter;
|
||||
|
||||
use Kanboard\Core\DateParser;
|
||||
|
||||
/**
|
||||
* Base date filter class
|
||||
*
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
abstract class BaseDateFilter extends BaseFilter
|
||||
{
|
||||
/**
|
||||
* DateParser object
|
||||
*
|
||||
* @access protected
|
||||
* @var DateParser
|
||||
*/
|
||||
protected $dateParser;
|
||||
|
||||
/**
|
||||
* Set DateParser object
|
||||
*
|
||||
* @access public
|
||||
* @param DateParser $dateParser
|
||||
* @return $this
|
||||
*/
|
||||
public function setDateParser(DateParser $dateParser)
|
||||
{
|
||||
$this->dateParser = $dateParser;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse operator in the input string
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function parseOperator()
|
||||
{
|
||||
$operators = array(
|
||||
'<=' => 'lte',
|
||||
'>=' => 'gte',
|
||||
'<' => 'lt',
|
||||
'>' => 'gt',
|
||||
);
|
||||
|
||||
foreach ($operators as $operator => $method) {
|
||||
if (strpos($this->value, $operator) === 0) {
|
||||
$this->value = substr($this->value, strlen($operator));
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a date filter
|
||||
*
|
||||
* @access protected
|
||||
* @param string $field
|
||||
*/
|
||||
protected function applyDateFilter($field)
|
||||
{
|
||||
$method = $this->parseOperator();
|
||||
$timestamp = $this->dateParser->getTimestampFromIsoFormat($this->value);
|
||||
|
||||
if ($method !== '') {
|
||||
$this->query->$method($field, $this->getTimestampFromOperator($method, $timestamp));
|
||||
} else {
|
||||
$this->query->gte($field, $timestamp);
|
||||
$this->query->lte($field, $timestamp + 86399);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timestamp from the operator
|
||||
*
|
||||
* @access public
|
||||
* @param string $method
|
||||
* @param integer $timestamp
|
||||
* @return integer
|
||||
*/
|
||||
protected function getTimestampFromOperator($method, $timestamp)
|
||||
{
|
||||
switch ($method) {
|
||||
case 'lte':
|
||||
return $timestamp + 86399;
|
||||
case 'lt':
|
||||
return $timestamp;
|
||||
case 'gte':
|
||||
return $timestamp;
|
||||
case 'gt':
|
||||
return $timestamp + 86400;
|
||||
}
|
||||
|
||||
return $timestamp;
|
||||
}
|
||||
}
|
||||
@@ -72,48 +72,4 @@ abstract class BaseFilter
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse operator in the input string
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function parseOperator()
|
||||
{
|
||||
$operators = array(
|
||||
'<=' => 'lte',
|
||||
'>=' => 'gte',
|
||||
'<' => 'lt',
|
||||
'>' => 'gt',
|
||||
);
|
||||
|
||||
foreach ($operators as $operator => $method) {
|
||||
if (strpos($this->value, $operator) === 0) {
|
||||
$this->value = substr($this->value, strlen($operator));
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a date filter
|
||||
*
|
||||
* @access protected
|
||||
* @param string $field
|
||||
*/
|
||||
protected function applyDateFilter($field)
|
||||
{
|
||||
$timestamp = strtotime($this->value);
|
||||
$method = $this->parseOperator();
|
||||
|
||||
if ($method !== '') {
|
||||
$this->query->$method($field, $timestamp);
|
||||
} else {
|
||||
$this->query->gte($field, $timestamp);
|
||||
$this->query->lte($field, $timestamp + 86399);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
app/Filter/ProjectActivityCreationDateFilter.php
Normal file
38
app/Filter/ProjectActivityCreationDateFilter.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Filter;
|
||||
|
||||
use Kanboard\Core\Filter\FilterInterface;
|
||||
use Kanboard\Model\ProjectActivity;
|
||||
|
||||
/**
|
||||
* Filter activity events by creation date
|
||||
*
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectActivityCreationDateFilter extends BaseDateFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array('created');
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filter
|
||||
*
|
||||
* @access public
|
||||
* @return FilterInterface
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->applyDateFilter(ProjectActivity::TABLE.'.date_creation');
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
65
app/Filter/ProjectActivityCreatorFilter.php
Normal file
65
app/Filter/ProjectActivityCreatorFilter.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Filter;
|
||||
|
||||
use Kanboard\Core\Filter\FilterInterface;
|
||||
use Kanboard\Model\ProjectActivity;
|
||||
|
||||
/**
|
||||
* Filter activity events by creator
|
||||
*
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectActivityCreatorFilter extends BaseFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Current user id
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
private $currentUserId = 0;
|
||||
|
||||
/**
|
||||
* Set current user id
|
||||
*
|
||||
* @access public
|
||||
* @param integer $userId
|
||||
* @return TaskAssigneeFilter
|
||||
*/
|
||||
public function setCurrentUserId($userId)
|
||||
{
|
||||
$this->currentUserId = $userId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get search attribute
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array('creator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filter
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
if ($this->value === 'me') {
|
||||
$this->query->eq(ProjectActivity::TABLE . '.creator_id', $this->currentUserId);
|
||||
} else {
|
||||
$this->query->beginOr();
|
||||
$this->query->ilike('uc.username', '%'.$this->value.'%');
|
||||
$this->query->ilike('uc.name', '%'.$this->value.'%');
|
||||
$this->query->closeOr();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class ProjectActivityProjectIdsFilter extends BaseFilter implements FilterInterf
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array('project_ids');
|
||||
return array('projects');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
38
app/Filter/ProjectActivityProjectNameFilter.php
Normal file
38
app/Filter/ProjectActivityProjectNameFilter.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Filter;
|
||||
|
||||
use Kanboard\Core\Filter\FilterInterface;
|
||||
use Kanboard\Model\Project;
|
||||
|
||||
/**
|
||||
* Filter activity events by project name
|
||||
*
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectActivityProjectNameFilter extends BaseFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array('project');
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filter
|
||||
*
|
||||
* @access public
|
||||
* @return FilterInterface
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->query->ilike(Project::TABLE.'.name', '%'.$this->value.'%');
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
43
app/Filter/ProjectActivityTaskStatusFilter.php
Normal file
43
app/Filter/ProjectActivityTaskStatusFilter.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Filter;
|
||||
|
||||
use Kanboard\Core\Filter\FilterInterface;
|
||||
use Kanboard\Model\Task;
|
||||
|
||||
/**
|
||||
* Filter activity events by task status
|
||||
*
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectActivityTaskStatusFilter extends BaseFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filter
|
||||
*
|
||||
* @access public
|
||||
* @return FilterInterface
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
if ($this->value === 'open') {
|
||||
$this->query->eq(Task::TABLE.'.is_active', Task::STATUS_OPEN);
|
||||
} elseif ($this->value === 'closed') {
|
||||
$this->query->eq(Task::TABLE.'.is_active', Task::STATUS_CLOSED);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Kanboard\Filter;
|
||||
|
||||
use Kanboard\Core\Filter\FilterInterface;
|
||||
use Kanboard\Model\Task;
|
||||
|
||||
/**
|
||||
* Filter activity events by task title
|
||||
@@ -11,7 +10,7 @@ use Kanboard\Model\Task;
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectActivityTaskTitleFilter extends BaseFilter implements FilterInterface
|
||||
class ProjectActivityTaskTitleFilter extends TaskTitleFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
@@ -23,16 +22,4 @@ class ProjectActivityTaskTitleFilter extends BaseFilter implements FilterInterfa
|
||||
{
|
||||
return array('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filter
|
||||
*
|
||||
* @access public
|
||||
* @return FilterInterface
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->query->ilike(Task::TABLE.'.title', '%'.$this->value.'%');
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use Kanboard\Model\Task;
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskCompletionDateFilter extends BaseFilter implements FilterInterface
|
||||
class TaskCompletionDateFilter extends BaseDateFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
|
||||
@@ -11,7 +11,7 @@ use Kanboard\Model\Task;
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskCreationDateFilter extends BaseFilter implements FilterInterface
|
||||
class TaskCreationDateFilter extends BaseDateFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
|
||||
@@ -11,7 +11,7 @@ use Kanboard\Model\Task;
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskDueDateFilter extends BaseFilter implements FilterInterface
|
||||
class TaskDueDateFilter extends BaseDateFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
|
||||
@@ -11,7 +11,7 @@ use Kanboard\Model\Task;
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskModificationDateFilter extends BaseFilter implements FilterInterface
|
||||
class TaskModificationDateFilter extends BaseDateFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
|
||||
@@ -32,7 +32,12 @@ class TaskProjectsFilter extends BaseFilter implements FilterInterface
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->query->in(Task::TABLE.'.project_id', $this->value);
|
||||
if (empty($this->value)) {
|
||||
$this->query->eq(Task::TABLE.'.project_id', 0);
|
||||
} else {
|
||||
$this->query->in(Task::TABLE.'.project_id', $this->value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use Kanboard\Model\Task;
|
||||
* @package filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskStartDateFilter extends BaseFilter implements FilterInterface
|
||||
class TaskStartDateFilter extends BaseDateFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Get search attribute
|
||||
|
||||
Reference in New Issue
Block a user