summaryrefslogtreecommitdiff
path: root/app/php/model/Calendar.php
blob: 23a08189f6bdc30e362d5cbc332e5a505594be43 (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
<?php

Prado::using('Application.db.ActiveRecord');
Prado::using('Application.model.Entry');
Prado::using('Application.model.Category');

class Calendar extends ActiveRecord {

    const TABLE = 'calendars';

    public $UID;
    public $Url;
    public $Name;
    public $Website;
    public $Visible;
    public $CustomName;
    public $CustomImage;
    public $CustomUrl;
    public $LastUpdated;

    public $CategoryID;

    public static $COLUMN_MAPPING = [
        'uid' => 'UID',
        'url' => 'Url',
        'name' => 'Name',
        'website' => 'Website',
        'visible' => 'Visible',
        'last_updated' => 'LastUpdated',
        'custom_name' => 'CustomName',
        'custom_image' => 'CustomImage',
        'custom_url' => 'CustomUrl',
        '_category' => 'CategoryID'
    ];

    public static $RELATIONS = [
        'Entries' => [self::HAS_MANY, 'Entry', '_calendar'],
        'Category' => [self::BELONGS_TO, 'Category', '_category']
    ];

    public static function finder($className=__CLASS__) {
        return parent::finder($className);
    }

    const CUSTOM_IMAGE_PATH = '../../resources/images/calendars/';

    public function getCustomImageUrl() {
        if ($this->CustomImage) {
            if (!preg_match('#^//#', $this->CustomImage)) {
                return Prado::getApplication()->getAssetManager()->publishFilePath(
                    implode(
                        DIRECTORY_SEPARATOR,
                        [
                            Prado::getApplication()->getBasePath(),
                            self::CUSTOM_IMAGE_PATH,
                            $this->CustomImage
                        ]
                    ),
                    TRUE
                );
            }
            return $this->CustomImage;
        }
    }

}

?>