Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Poll.php « Db « lib - github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c25f79a8209747db0d52582c58b52a0be0c7fd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
 *
 * @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
 * @author Kai Schröer <git@schroeer.co>
 * @author René Gieling <github@dartcafe.de>
 *
 * @license GNU AGPL version 3 or any later version
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\Polls\Db;

use JsonSerializable;

use OCP\IUser;
use OCP\AppFramework\Db\Entity;

/**
 * @method string getType()
 * @method void setType(string $value)
 * @method string getTitle()
 * @method void setTitle(string $value)
 * @method string getDescription()
 * @method void setDescription(string $value)
 * @method string getOwner()
 * @method void setOwner(string $value)
 * @method int getCreated()
 * @method void setCreated(integer $value)
 * @method int getExpire()
 * @method void setExpire(integer $value)
 * @method int getDeleted()
 * @method void setDeleted(integer $value)
 * @method string getAccess()
 * @method void setAccess(string $value)
 * @method int getAnonymous()
 * @method void setAnonymous(integer $value)
 * @method int getFullAnonymous()
 * @method void setFullAnonymous(integer $value)
 * @method int getAllowMaybe()
 * @method void setAllowMaybe(integer $value)
 * @method string getOptions()
 * @method void setOptions(string $value)
 * @method string getSettings()
 * @method void setSettings(string $value)
 * @method int getVoteLimit()
 * @method void setVoteLimit(integer $value)
 * @method string getShowResults()
 * @method void setShowResults(string $value)
 * @method int getAdminAccess()
 * @method void setAdminAccess(integer $value)
 * @method int getImportant()
 * @method void setImportant(integer $value)
 */
class Poll extends Entity implements JsonSerializable {

	/** @var string $type */
	protected $type;

	/** @var string $title */
	protected $title;

	/** @var string $description */
	protected $description;

	/** @var string $owner */
	protected $owner;

	/** @var int $created */
	protected $created;

	/** @var int $expire */
	protected $expire;

	/** @var int $deleted */
	protected $deleted;

	/** @var string $access */
	protected $access;

	/** @var int $anonymous */
	protected $anonymous;

	/** @var int $fullAnonymous */
	protected $fullAnonymous;

	/** @var int $allowMaybe */
	protected $allowMaybe;

	/** @var string $options */
	protected $options;

	/** @var string $settings*/
	protected $settings;

	/** @var int $voteLimit*/
	protected $voteLimit;

	/** @var string $showResults */
	protected $showResults;

	/** @var int $adminAccess*/
	protected $adminAccess;

	/** @var int $important*/
	protected $important;

	public function jsonSerialize() {
		return [
			'id' => intval($this->id),
			'type' => $this->type,
			'title' => $this->title,
			'description' => $this->description,
			'owner' => $this->owner,
			'created' => intval($this->created),
			'expire' => intval($this->expire),
			'deleted' => intval($this->deleted),
			'access' => $this->access,
			'anonymous' => intval($this->anonymous),
			'allowMaybe' => intval($this->allowMaybe),
			'settings' => $this->settings,
			'voteLimit' => intval($this->voteLimit),
			'showResults' => $this->showResults,
			'adminAccess' => intVal($this->adminAccess),
			'ownerDisplayName' => $this->getDisplayName(),
			'important' => intVal($this->important)
		];
	}

	public function setAnonymous($value) {
		$this->anonymous = intval($value);
	}

	public function setAllowMaybe($value) {
		$this->allowMaybe = intval($value);
	}

	public function setAdminAccess($value) {
		$this->adminAccess = intval($value);
	}

	public function setImportant($value) {
		$this->important = intval($value);
	}

	public function deserializeArray($array) {
		$this->setTitle(isset($array['title']) ? $array['title'] : $this->getTitle());
		$this->setDescription(isset($array['description']) ? $array['description'] : $this->getDescription());
		$this->setAccess(isset($array['access']) ? $array['access'] : $this->getAccess());
		$this->setExpire(isset($array['expire']) ? $array['expire'] : $this->getExpire());
		$this->setAnonymous(isset($array['anonymous']) ? $array['anonymous'] : $this->getAnonymous());
		$this->setAllowMaybe(isset($array['allowMaybe']) ? $array['allowMaybe'] : $this->getAllowMaybe());
		$this->setVoteLimit(isset($array['voteLimit']) ? $array['voteLimit'] : $this->getVoteLimit());
		$this->setShowResults(isset($array['showResults']) ? $array['showResults'] : $this->getShowResults());
		$this->setDeleted(isset($array['deleted']) ? $array['deleted'] : $this->getDeleted());
		$this->setAdminAccess(isset($array['adminAccess']) ? $array['adminAccess'] : $this->getAdminAccess());
		$this->setImportant(isset($array['important']) ? $array['important'] : $this->getImportant());
		return $this;
	}

	private function getDisplayName() {
		if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) {
			return \OC::$server->getUserManager()->get($this->owner)->getDisplayName();
		} else {
			return $this->owner;
		}
	}
}