Completed
Push — master ( 1d826a...bce6a5 )
by Alexey
05:15
created

File::relations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Exchange File
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 Exchange1c\Exchange;
13
14
class File extends \Model {
15
16
  public static $cols = [
17
      'name' => ['type' => 'text'],
18
      'exchange_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'exchange'],
19
      'size' => ['type' => 'number'],
20
      'status' => ['type' => 'text'],
21
      'deleted' => ['type' => 'bool'],
22
      'date_create' => ['type' => 'dateTime'],
23
  ];
24
  public static $dataManagers = [
25
      'manager' => [
26
          'cols' => [
27
              'name', 'size', 'status', 'deleted', 'date_create'
28
          ],
29
      ]
30
  ];
31
32
  public function deleteFile() {
33
    if ($this->exchange && file_exists($this->exchange->path . '/' . $this->name)) {
34
      unlink($this->exchange->path . '/' . $this->name);
35
    }
36
    $this->deleted = 1;
37
    $this->save();
38
  }
39
40
  public static function relations() {
41
    return [
42
        'exchange' => [
43
            'model' => 'Exchange1c\Exchange',
44
            'col' => 'exchange_id'
45
        ]
46
    ];
47
  }
48
49
}
50