Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AttemptService | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| getAttempts | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setStatesToExclude | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStatesToExclude | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| filterStates | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDelivery\model; |
| 23 | |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | use oat\oatbox\user\User; |
| 26 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 27 | use oat\taoDelivery\model\execution\DeliveryExecutionInterface; |
| 28 | |
| 29 | /** |
| 30 | * Service to count the attempts to pass the test. |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 34 | * @package taoDelivery |
| 35 | */ |
| 36 | class AttemptService extends ConfigurableService implements AttemptServiceInterface |
| 37 | { |
| 38 | public const OPTION_STATES_TO_EXCLUDE = 'states_to_exclude'; |
| 39 | |
| 40 | /** |
| 41 | * @inheritdoc |
| 42 | */ |
| 43 | public function getAttempts($deliveryId, User $user) |
| 44 | { |
| 45 | $executions = $this->getServiceLocator()->get(ServiceProxy::SERVICE_ID) |
| 46 | ->getUserExecutions(new \core_kernel_classes_Resource($deliveryId), $user->getIdentifier()); |
| 47 | return $this->filterStates($executions); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @inheritdoc |
| 52 | */ |
| 53 | public function setStatesToExclude(array $deliveryExecutionsStates) |
| 54 | { |
| 55 | $this->setOption(self::OPTION_STATES_TO_EXCLUDE, $deliveryExecutionsStates); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return array|mixed |
| 60 | */ |
| 61 | public function getStatesToExclude() |
| 62 | { |
| 63 | $statesToExclude = $this->getOption(self::OPTION_STATES_TO_EXCLUDE); |
| 64 | if (!is_array($statesToExclude)) { |
| 65 | $statesToExclude = []; |
| 66 | } |
| 67 | return $statesToExclude; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @param DeliveryExecutionInterface[] $executions |
| 72 | * @return DeliveryExecutionInterface[] |
| 73 | */ |
| 74 | protected function filterStates(array $executions = []) |
| 75 | { |
| 76 | $statesToExclude = $this->getStatesToExclude(); |
| 77 | if (!empty($statesToExclude)) { |
| 78 | $result = array_filter($executions, function ($execution) use ($statesToExclude) { |
| 79 | return !in_array($execution->getState()->getUri(), $statesToExclude); |
| 80 | }); |
| 81 | } else { |
| 82 | $result = $executions; |
| 83 | } |
| 84 | return $result; |
| 85 | } |
| 86 | } |