Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
InMemoryQueuePersistence
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 8
240
0.00% covered (danger)
0.00%
0 / 1
 get
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 add
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 search
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
30
 has
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 update
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 setReport
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 count
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAll
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22namespace oat\oatbox\task\implementation;
23
24use oat\oatbox\task\Task;
25use oat\oatbox\task\TaskInterface\TaskPersistenceInterface;
26use Zend\ServiceManager\ServiceLocatorAwareTrait;
27
28/**
29 * @deprecated since version 7.10.0, to be removed in 8.0. Use \oat\tao\model\taskQueue\Queue\Broker\InMemoryQueueBroker
30 *             instead.
31 */
32class InMemoryQueuePersistence implements TaskPersistenceInterface
33{
34    use ServiceLocatorAwareTrait;
35
36    /**
37     * @var array
38     */
39    protected $taskList = [];
40
41    public function get($taskId)
42    {
43        if (array_key_exists($taskId, $this->taskList)) {
44            return $this->taskList[$taskId];
45        }
46        return null;
47    }
48
49    public function add(Task $task)
50    {
51        $taskId = (microtime(true) * 10000) . rand(100000, 999999);
52        $task->setId($taskId);
53        $this->taskList[$taskId] = $task;
54        return $task;
55    }
56
57    public function search(array $filterTask, $rows = null, $page = null, $sortBy = null, $sortOrder = null)
58    {
59
60        $taskList = array_filter($this->taskList, function ($elem) use ($filterTask) {
61            /**
62             * @var $elem Task
63             */
64
65            if (isset($filterTask['status'])) {
66                $result = ($elem->getStatus() === $filterTask['status']);
67            } else {
68                $result = ($elem->getStatus() !== Task::STATUS_ARCHIVED);
69            }
70
71            if (isset($filterTask['type'])) {
72                $result = ($elem->getType() === $filterTask['type']);
73            }
74
75            if (isset($filterTask['owner'])) {
76                $result = ($elem->getOwner() === $filterTask['owner']);
77            }
78
79            if (isset($filterTask['label'])) {
80                $result = (strpos(strtolower($filterTask['label']), strtotime($elem->getLabel())) !== false);
81            }
82
83            return $result;
84        });
85
86        return new TaskList($taskList);
87    }
88
89    public function has($taskId)
90    {
91        return !is_null($this->get($taskId));
92    }
93
94    public function update($taskId, $status)
95    {
96        $task = $this->get($taskId);
97        if (!is_null($task)) {
98            $task->setStatus($status);
99            return true;
100        }
101        return false;
102    }
103
104    public function setReport($taskId, \common_report_Report $report)
105    {
106        $task = $this->get($taskId);
107        if (!is_null($task)) {
108            $task->setReport($report);
109            return true;
110        }
111        return false;
112    }
113
114    public function count(array $params)
115    {
116        return count($this->search($params));
117    }
118
119
120    public function getAll()
121    {
122        return $this->taskList;
123    }
124}