Completed
Pull Request — master (#249)
by
unknown
03:38
created

Note::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
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
33
    public $modified;
34
    public $title;
35
    public $content;
36
    public $favorite = false;
37
38 11
    public function __construct() {
39 11
        $this->addType('modified', 'integer');
40 11
        $this->addType('favorite', 'boolean');
41 11
    }
42
43
    /**
44
     * @param File $file
45
     * @return static
46
     */
47 5
    public static function fromFile(File $file, $tags=[]){
48 5
        $note = new static();
49 5
        $note->setId($file->getId());
50 5
        $note->setContent($file->getContent());
51 5
        $note->setModified($file->getMTime());
52 5
        $note->setTitle(pathinfo($file->getName(),PATHINFO_FILENAME)); // remove extension
53 5
        if(is_array($tags) && in_array(\OC\Tags::TAG_FAVORITE, $tags)) {
54
            $note->setFavorite(true);
55
            //unset($tags[array_search(\OC\Tags::TAG_FAVORITE, $tags)]);
56
        }
57 5
        $note->resetUpdatedFields();
58 5
        return $note;
59
    }
60
61
}
62