-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTicketFile.php
executable file
·106 lines (98 loc) · 2.91 KB
/
TicketFile.php
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/************************************************************************************
*
* Copyright (c) 2018 Thanasis Vergoulis & Konstantinos Zagganas & Loukas Kavouras
* for the Information Management Systems Institute, "Athena" Research Center.
*
* This file is part of SCHeMa.
*
* SCHeMa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SCHeMa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <https://www.gnu.org/licenses/>.
*
************************************************************************************/
namespace app\models;
use Yii;
/**
* This is the model class for table "ticket_file".
*
* @property integer $id
* @property integer $id_body
* @property string $fileName
* @property string $document_name
*
* @property TicketBody $idBody
*/
class TicketFile extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%ticket_file}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_body'], 'integer'],
[['fileName','document_name'], 'string', 'max' => 255],
[
['id_body'],
'exist',
'skipOnError' => true,
'targetClass' => TicketBody::className(),
'targetAttribute' => ['id_body' => 'id'],
],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'id_body' => Yii::t('app', 'Id Body'),
'fileName' => Yii::t('app', 'File Name'),
'document_name' => Yii::t('app', 'Document name'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdBody()
{
return $this->hasOne(TicketBody::className(), ['id' => 'id_body']);
}
/**
* @param $ticket
* @param $uploadForm
* @return bool
*/
public static function saveImage($ticket, $uploadForm)
{
if ($uploadForm->getName() == null) {
return false;
}
foreach ($uploadForm->getName() as $file) {
$ticketFile = new TicketFile();
$ticketFile->id_body = $ticket->primaryKey;
$ticketFile->fileName = $file['real'];
$ticketFile->document_name = $file['document'];
$ticketFile->save();
}
}
}