1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use app\models\query\TagQuery; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This is the model class for table "tag". |
10
|
|
|
* |
11
|
|
|
* @property integer $id |
12
|
|
|
* @property string $user_id |
13
|
|
|
* @property string $title |
14
|
|
|
* @property integer $count |
15
|
|
|
*/ |
16
|
|
|
class Tag extends \yii\db\ActiveRecord |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @inheritdoc |
20
|
|
|
*/ |
21
|
|
|
public static function tableName() |
22
|
|
|
{ |
23
|
|
|
return 'tag'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritdoc |
28
|
|
|
*/ |
29
|
|
|
public function rules() |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
['title', 'trim'], |
33
|
|
|
['title', 'required'], |
34
|
|
|
['title', 'unique'], |
35
|
|
|
['title', 'string', 'max' => 255], |
36
|
|
|
|
37
|
|
|
['count', 'integer'], |
38
|
|
|
['count', 'default', 'value' => 0] |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
|
|
public function attributeLabels() |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
'id' => Yii::t('app', 'ID'), |
49
|
|
|
'title' => Yii::t('app', 'Title'), |
50
|
|
|
'count' => Yii::t('app', 'Amount'), |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
|
|
public function beforeSave($insert) |
58
|
|
|
{ |
59
|
|
|
if (parent::beforeSave($insert)) { |
60
|
|
|
if ($insert) { |
61
|
|
|
if (!Yii::$app instanceof \yii\console\Application) { |
62
|
|
|
$this->user_id = Yii::$app->user->id; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return false; // @codeCoverageIgnore |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
* @return TagQuery |
75
|
|
|
*/ |
76
|
|
|
public static function find() |
77
|
|
|
{ |
78
|
|
|
return new TagQuery(get_called_class()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Check access |
83
|
|
|
* |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
|
|
public function checkAccess() |
87
|
|
|
{ |
88
|
|
|
$isSuperUser = !Yii::$app->getUser()->getIsGuest() && Yii::$app->getUser()->getIdentity()->isSuperUser(); |
|
|
|
|
89
|
|
|
return $isSuperUser || Yii::$app->getUser()->id === $this->user_id; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: