Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
6 / 12
42.86% covered (danger)
42.86%
3 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ContextTypePropertyColumn
50.00% covered (danger)
50.00%
6 / 12
42.86% covered (danger)
42.86%
3 / 7
16.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 fromArray
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setContextType
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 getContextType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isTestTakerType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isDeliveryType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 3
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\taoOutcomeUi\model\table;
23
24/**
25 * ContextTypePropertyColumn
26 *
27 * @author Gyula Szucs <gyula@taotesting.com>
28 */
29class ContextTypePropertyColumn extends \tao_models_classes_table_PropertyColumn
30{
31    public const CONTEXT_TYPE_TEST_TAKER = 'test_taker';
32    public const CONTEXT_TYPE_DELIVERY = 'delivery';
33
34    public $contextType;
35
36    /**
37     * ContextAwarePropertyColumn constructor.
38     *
39     * @param string                        $contextType
40     * @param \core_kernel_classes_Property $property
41     */
42    public function __construct($contextType, \core_kernel_classes_Property $property)
43    {
44        parent::__construct($property);
45
46        $this->setContextType($contextType);
47    }
48
49    /**
50     * @param array $data
51     * @return ContextTypePropertyColumn
52     */
53    protected static function fromArray($data)
54    {
55        return new self($data['contextType'], new \core_kernel_classes_Property($data['prop']));
56    }
57
58    /**
59     * @param string $contextType
60     * @throws \common_exception_InvalidArgumentType
61     */
62    public function setContextType($contextType)
63    {
64        if (!in_array($contextType, [self::CONTEXT_TYPE_TEST_TAKER, self::CONTEXT_TYPE_DELIVERY])) {
65            throw new \common_exception_InvalidArgumentType('Not valid context type "' . $contextType . '"');
66        }
67
68        $this->contextType = $contextType;
69    }
70
71    /**
72     * @return string
73     */
74    public function getContextType()
75    {
76        return $this->contextType;
77    }
78
79    /**
80     * @return bool
81     */
82    public function isTestTakerType()
83    {
84        return $this->getContextType() == self::CONTEXT_TYPE_TEST_TAKER;
85    }
86
87    /**
88     * @return bool
89     */
90    public function isDeliveryType()
91    {
92        return $this->getContextType() == self::CONTEXT_TYPE_DELIVERY;
93    }
94
95    /**
96     * @return array
97     */
98    public function toArray()
99    {
100        $result = parent::toArray();
101
102        $result['contextType'] = $this->getContextType();
103
104        return $result;
105    }
106}