Note::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Nextcloud - NextNote
4
 *
5
 *
6
 * @copyright Copyright (c) 2017, Sander Brand ([email protected])
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\NextNote\Db;
25
use \OCP\AppFramework\Db\Entity;
26
27
/**
28
 * @method integer getId()
29
 * @method void setId(int $value)
30
 * @method void setName(string $value)
31
 * @method void setGuid(string $value)
32
 * @method string getGuid()
33
 * @method string getName()
34
 * @method void setGrouping(string $value)
35
 * @method string getGrouping()
36
 * @method void setNotebook($value)
37
 * @method getNotebook()
38
 * @method void setUid(string $value)
39
 * @method string getNote()
40
 * @method void setNote(string $value)
41
 * @method string getUid()
42
 * @method void setMtime(integer $value)
43
 * @method integer getMtime()
44
 * @method void setDeleted(integer $value)
45
 * @method integer getDeleted()
46
 */
47
48
49
class Note extends Entity implements  \JsonSerializable{
50
51
	use EntityJSONSerializer;
52
53
	protected $name;
54
	protected $grouping;
55
	protected $notebook;
56
	protected $uid;
57
	protected $guid;
58
	protected $mtime;
59
	protected $deleted = 0;
60
	protected $note;
61
	protected $shared;
62
	public function __construct() {
63
		// add types in constructor
64
		$this->addType('mtime', 'integer');
65
		$this->addType('deleted', 'integer');
66
	}
67
	/**
68
	 * Turns entity attributes into an array
69
	 */
70
	public function jsonSerialize() {
71
		$now = new \DateTime();
72
		return [
73
			'id' => $this->getId(),
74
			'guid' => $this->getGuid(),
75
			'mtime' => $this->getMtime(),
76
			'timediff' =>  $now->getTimestamp() - $this->getMtime(),
77
			'title' => $this->getName(),
78
			'uid' => $this->getUid(),
79
			'notebook' => $this->getNotebook(),
80
			'content' => $this->getNote(),
81
			'content_plain' => strip_tags(html_entity_decode($this->getNote())),
82
			'deleted' => $this->getDeleted(),
83
			'permissions' => 31
84
		];
85
	}
86
}
87