Completed
Push — master ( 8717df...fdbe7f )
by Alexey
05:44
created

Event::relations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/**
4
 * Cart Event
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Ecommerce\Cart;
13
14
class Event extends \Model
15
{
16
    public static $cols = [
17
        //Основные параметры
18
        'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
19
        'cart_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'cart'],
20
        'cart_event_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'],
21
        'info' => ['type' => 'text'],
22
        //Системные
23
        'date_create' => ['type' => 'dateTime'],
24
    ];
25
26
    public static function indexes()
27
    {
28
        return [
29
            'ecommerce_cartEventCart' => [
30
                'type' => 'INDEX',
31
                'cols' => [
32
                    'cart_event_cart_id'
33
                ]
34
            ],
35
            'ecommerce_cartEventDate' => [
36
                'type' => 'INDEX',
37
                'cols' => [
38
                    'cart_event_date_create'
39
                ]
40
            ],
41
        ];
42
    }
43
44
    public static function relations()
45
    {
46
        return [
47
            'type' => [
48
                'model' => 'Ecommerce\Cart\Event\Type',
49
                'col' => 'cart_event_type_id',
50
            ],
51
            'cart' => [
52
                'model' => 'Ecommerce\Cart',
53
                'col' => 'cart_id',
54
            ],
55
            'user' => [
56
                'model' => 'Users\User',
57
                'col' => 'user_id',
58
            ],
59
        ];
60
    }
61
62
    public function afterSave()
63
    {
64
        $this->cart->date_last_activ = $this->date_create;
65
        $this->cart->save();
66
    }
67
68
}
69