|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Gewaer\Models; |
|
5
|
|
|
|
|
6
|
|
|
use Gewaer\Exception\ServerErrorHttpException; |
|
7
|
|
|
use Gewaer\Exception\ModelException; |
|
8
|
|
|
use Phalcon\Di; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Classs for UserCompanyAppsActivities |
|
12
|
|
|
* @property Users $userData |
|
13
|
|
|
* @property Request $request |
|
14
|
|
|
* @property Config $config |
|
15
|
|
|
* @property Apps $app |
|
16
|
|
|
* @property \Phalcon\DI $di |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
class UserCompanyAppsActivities extends AbstractModel |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* |
|
23
|
|
|
* @var integer |
|
24
|
|
|
*/ |
|
25
|
|
|
public $companies_id; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* |
|
29
|
|
|
* @var integer |
|
30
|
|
|
*/ |
|
31
|
|
|
public $company_branches_id; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
* @var integer |
|
36
|
|
|
*/ |
|
37
|
|
|
public $apps_id; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
public $key; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
public $value; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
public $created_at; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
public $updated_at; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* |
|
65
|
|
|
* @var integer |
|
66
|
|
|
*/ |
|
67
|
|
|
public $is_deleted; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Initialize method for model. |
|
71
|
|
|
*/ |
|
72
|
6 |
|
public function initialize() |
|
73
|
|
|
{ |
|
74
|
6 |
|
$this->belongsTo( |
|
75
|
6 |
|
'companies_id', |
|
76
|
6 |
|
'Gewaer\Models\Companies', |
|
77
|
6 |
|
'id', |
|
78
|
6 |
|
['alias' => 'company'] |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
6 |
|
$this->belongsTo( |
|
82
|
6 |
|
'apps_id', |
|
83
|
6 |
|
'Gewaer\Models\Apps', |
|
84
|
6 |
|
'id', |
|
85
|
6 |
|
['alias' => 'app'] |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
6 |
|
$this->belongsTo( |
|
89
|
6 |
|
'company_branches_id', |
|
90
|
6 |
|
'Gewaer\Models\CompanyBranches', |
|
91
|
6 |
|
'id', |
|
92
|
6 |
|
['alias' => 'companyBranch'] |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
6 |
|
$this->setSource('user_company_apps_activities'); |
|
96
|
6 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Returns table name mapped in the model. |
|
100
|
|
|
* |
|
101
|
|
|
* @return string |
|
102
|
|
|
*/ |
|
103
|
6 |
|
public function getSource() : string |
|
104
|
|
|
{ |
|
105
|
6 |
|
return 'user_company_apps_activities'; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Get the value of the settins by it key |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $key |
|
112
|
|
|
* @param string $value |
|
113
|
|
|
*/ |
|
114
|
|
|
public static function get(string $key) : string |
|
115
|
|
|
{ |
|
116
|
|
|
$setting = self::findFirst([ |
|
117
|
|
|
'conditions' => 'companies_id = ?0 and apps_id = ?1 and key = ?2', |
|
118
|
|
|
'bind' => [Di::getDefault()->getUserData()->currentCompanyId(), Di::getDefault()->getApp()->getId(), $key] |
|
119
|
|
|
]); |
|
120
|
|
|
|
|
121
|
|
|
if (is_object($setting)) { |
|
122
|
|
|
return $setting->value; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
throw new ServerErrorHttpException(_('No settings found with this ' . $key)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Set a setting for the given app |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $key |
|
132
|
|
|
* @param string $value |
|
133
|
|
|
*/ |
|
134
|
1 |
|
public static function set(string $key, $value) : bool |
|
135
|
|
|
{ |
|
136
|
1 |
|
$activity = self::findFirst([ |
|
137
|
1 |
|
'conditions' => 'companies_id = ?0 and apps_id = ?1 and key = ?2', |
|
138
|
1 |
|
'bind' => [Di::getDefault()->getUserData()->currentCompanyId(), Di::getDefault()->getApp()->getId(), $key] |
|
139
|
|
|
]); |
|
140
|
|
|
|
|
141
|
1 |
|
if (!is_object($activity)) { |
|
142
|
1 |
|
$activity = new self(); |
|
143
|
1 |
|
$activity->companies_id = Di::getDefault()->getUserData()->currentCompanyId(); |
|
144
|
1 |
|
$activity->company_branches_id = Di::getDefault()->getUserData()->currentCompanyBranchId(); |
|
145
|
1 |
|
$activity->apps_id = Di::getDefault()->getApp()->getId(); |
|
146
|
1 |
|
$activity->key = $key; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
1 |
|
$activity->value = $value; |
|
150
|
|
|
|
|
151
|
1 |
|
if (!$activity->save()) { |
|
152
|
|
|
throw new ModelException((string)current($activity->getMessages())); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
1 |
|
return true; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|