1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Notes |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Bernhard Posselt <[email protected]> |
9
|
|
|
* @copyright Bernhard Posselt 2012, 2014 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Notes\Db; |
13
|
|
|
|
14
|
|
|
use OCP\Files\File; |
15
|
|
|
use OCP\AppFramework\Db\Entity; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Note |
19
|
|
|
* @method integer getId() |
20
|
|
|
* @method void setId(integer $value) |
21
|
|
|
* @method integer getModified() |
22
|
|
|
* @method void setModified(integer $value) |
23
|
|
|
* @method string getTitle() |
24
|
|
|
* @method void setTitle(string $value) |
25
|
|
|
* @method string getContent() |
26
|
|
|
* @method void setContent(string $value) |
27
|
|
|
* @method boolean getFavorite() |
28
|
|
|
* @method void setFavorite(boolean $value) |
29
|
|
|
* @package OCA\Notes\Db |
30
|
|
|
*/ |
31
|
|
|
class Note extends Entity { |
32
|
|
|
public $modified; |
33
|
|
|
public $title; |
34
|
|
|
public $content; |
35
|
|
|
public $favorite = false; |
36
|
|
|
|
37
|
|
|
public function __construct() { |
38
|
13 |
|
$this->addType('modified', 'integer'); |
39
|
13 |
|
$this->addType('favorite', 'boolean'); |
40
|
13 |
|
} |
41
|
13 |
|
|
42
|
|
|
/** |
43
|
|
|
* @param File $file |
44
|
|
|
* @return static |
45
|
|
|
*/ |
46
|
|
|
public static function fromFile(File $file, $tags=[]) { |
47
|
7 |
|
$note = new static(); |
48
|
7 |
|
$note->setId($file->getId()); |
49
|
7 |
|
$note->setContent($file->getContent()); |
50
|
7 |
|
$note->setModified($file->getMTime()); |
51
|
7 |
|
$note->setTitle(\pathinfo($file->getName(), PATHINFO_FILENAME)); // remove extension |
52
|
7 |
|
if (\is_array($tags) && \in_array(\OC\Tags::TAG_FAVORITE, $tags)) { |
53
|
7 |
|
$note->setFavorite(true); |
54
|
|
|
//unset($tags[array_search(\OC\Tags::TAG_FAVORITE, $tags)]); |
55
|
|
|
} |
56
|
|
|
$note->resetUpdatedFields(); |
57
|
7 |
|
return $note; |
58
|
7 |
|
} |
59
|
|
|
} |
60
|
|
|
|