summaryrefslogtreecommitdiff
path: root/app/Filter
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-04-10 08:15:10 -0400
committerFrederic Guillot <fred@kanboard.net>2016-04-10 08:15:10 -0400
commit38326c4ddf91ed54374775d7f7599136f3e38eea (patch)
tree7a037fe8f6c22d19622414d86b6db63d7fcdb6e5 /app/Filter
parent7705f4c533c3db726624e639be72fc9822904e96 (diff)
Added search by task creator
Diffstat (limited to 'app/Filter')
-rw-r--r--app/Filter/TaskCreatorFilter.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/app/Filter/TaskCreatorFilter.php b/app/Filter/TaskCreatorFilter.php
new file mode 100644
index 00000000..af35e6bc
--- /dev/null
+++ b/app/Filter/TaskCreatorFilter.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Kanboard\Filter;
+
+use Kanboard\Core\Filter\FilterInterface;
+use Kanboard\Model\Task;
+
+/**
+ * Filter tasks by creator
+ *
+ * @package filter
+ * @author Frederic Guillot
+ */
+class TaskCreatorFilter 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 (is_int($this->value) || ctype_digit($this->value)) {
+ $this->query->eq(Task::TABLE.'.creator_id', $this->value);
+ } else {
+ switch ($this->value) {
+ case 'me':
+ $this->query->eq(Task::TABLE.'.creator_id', $this->currentUserId);
+ break;
+ case 'nobody':
+ $this->query->eq(Task::TABLE.'.creator_id', 0);
+ break;
+ default:
+ $this->query->beginOr();
+ $this->query->ilike('uc.username', '%'.$this->value.'%');
+ $this->query->ilike('uc.name', '%'.$this->value.'%');
+ $this->query->closeOr();
+ }
+ }
+ }
+}