Completed
Push — master ( 8d89f8...682f30 )
by René
11:22 queued 07:33
created

Option   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 21
c 2
b 1
f 0
dl 0
loc 43
ccs 0
cts 15
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 15 3
A setOrder() 0 5 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author Vinzenz Rosenkranz <[email protected]>
6
 * @author Kai Schröer <[email protected]>
7
 * @author René Gieling <[email protected]>
8
*
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 *  This program is free software: you can redistribute it and/or modify
12
 *  it under the terms of the GNU Affero General Public License as
13
 *  published by the Free Software Foundation, either version 3 of the
14
 *  License, or (at your option) any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU Affero General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU Affero General Public License
22
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OCA\Polls\Db;
27
28
use JsonSerializable;
29
30
use OCP\AppFramework\Db\Entity;
31
32
/**
33
 * @method integer getId()
34
 * @method void setId(integer $value)
35
 * @method integer getPollId()
36
 * @method void setPollId(integer $value)
37
 * @method string getPollOptionText()
38
 * @method void setPollOptionText(string $value)
39
 * @method integer getTimestamp()
40
 * @method void setTimestamp(integer $value)
41
 * @method integer getOrder()
42
 * @method void setOrder(integer $value)
43
 */
44
class Option extends Entity implements JsonSerializable {
45
46
	/** @var int $pollId */
47
	protected $pollId;
48
49
	/** @var string $pollOptionText */
50
	protected $pollOptionText;
51
52
	/** @var int $timestamp */
53
	protected $timestamp;
54
55
	/** @var int $order */
56
	protected $order;
57
58
	public function jsonSerialize() {
59
		if (intval($this->timestamp) > 0) {
60
			$timestamp = $this->timestamp;
61
		} elseif (strtotime($this->pollOptionText)) {
62
			$timestamp = strtotime($this->pollOptionText);
63
		} else {
64
			$timestamp = 0;
65
		}
66
67
		return [
68
			'id' => intval($this->id),
69
			'pollId' => intval($this->pollId),
70
			'pollOptionText' => htmlspecialchars_decode($this->pollOptionText),
71
			'timestamp' => intval($timestamp),
72
			'order' => $this->setOrder(intval($this->timestamp), intval($this->order))
73
		];
74
75
	}
76
77
	/**
78
	 * Temporary fix
79
	 * Make sure, order is eqal to timestamp in date polls
80
	 */
81
	 // TODO: remove by time
82
	private function setOrder($timestamp, $order) {
83
		if ($timestamp === 0) {
84
			return $order;
85
		} else {
86
			return $timestamp;
87
		}
88
	}
89
}
90