1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Itil\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use App\Itil\Models\Common\Attachments; |
7
|
|
|
use Exception; |
8
|
|
|
use Auth; |
9
|
|
|
use App\Itil\Models\Common\GeneralInfo; |
10
|
|
|
|
11
|
|
|
class UtilityController extends Controller { |
12
|
|
|
|
13
|
|
View Code Duplication |
public static function assetSearch($query, $format = 'json') { |
|
|
|
|
14
|
|
|
$assets = new SdAssets(); |
15
|
|
|
$asset = $assets->where('name', 'LIKE', '%' . $query . '%')->select('name as label', 'id as value'); |
16
|
|
|
|
17
|
|
|
if ($format == 'json') { |
18
|
|
|
$asset = $asset->get()->toJson(); |
19
|
|
|
} |
20
|
|
|
return $asset; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public static function assetByTypeId($typeid) { |
24
|
|
|
$assets = new SdAssets(); |
25
|
|
|
$asset = $assets->where('asset_type_id', $typeid); |
26
|
|
|
return $asset; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
public static function getModelWithSelect($model, $select = []) { |
|
|
|
|
30
|
|
|
try { |
31
|
|
|
if (count($select) > 0) { |
32
|
|
|
$model = $model->select($select); |
33
|
|
|
} |
34
|
|
|
return $model; |
35
|
|
|
} catch (Exception $ex) { |
|
|
|
|
36
|
|
|
|
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public static function saveTicketRelation($ticketid, $table, $id) { |
|
|
|
|
41
|
|
|
|
42
|
|
|
$relation = new \App\Itil\Models\Common\TicketRelation(); |
43
|
|
|
$relations = $relation->where('ticket_id', $ticketid)->where('owner', 'LIKE', $table . "%")->get(); |
|
|
|
|
44
|
|
|
if ($relations->count() > 0) { |
45
|
|
|
foreach ($relations as $del) { |
46
|
|
|
$del->delete(); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
if (is_array($id)) { |
50
|
|
|
foreach ($id as $i) { |
51
|
|
|
$relation->create([ |
52
|
|
|
'ticket_id' => $ticketid, |
53
|
|
|
'owner' => "$table:$i", |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
} else { |
57
|
|
|
$owner = "$table:$id"; |
58
|
|
|
$relation->create([ |
59
|
|
|
'ticket_id' => $ticketid, |
60
|
|
|
'owner' => $owner, |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public static function saveAssetRelation($assetid, $table, $id) { |
|
|
|
|
66
|
|
|
if (is_array($assetid)) { |
67
|
|
|
$assetid = implode(',', $assetid); |
68
|
|
|
} |
69
|
|
|
$owner = "$table:$id"; |
70
|
|
|
$relation = new \App\Itil\Models\Common\AssetRelation(); |
71
|
|
|
$relations = $relation->where('owner', $owner)->get(); |
72
|
|
|
if ($relations->count() > 0) { |
73
|
|
|
foreach ($relations as $del) { |
74
|
|
|
$del->delete(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
$relation->create([ |
78
|
|
|
'asset_ids' => $assetid, |
79
|
|
|
'owner' => $owner, |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public static function getAssetByTicketid($ticketid) { |
|
|
|
|
84
|
|
|
$relation = new \App\Itil\Models\Common\AssetRelation(); |
85
|
|
|
$model = $relation->where('owner', "tickets:$ticketid")->first(); |
86
|
|
|
$asset = false; |
87
|
|
|
if ($model) { |
88
|
|
|
if ($model->asset_ids) { |
89
|
|
|
$assets = new SdAssets(); |
90
|
|
|
$asset = $assets->where('id', $model->asset_id)->first(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
return $asset; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public static function detachAsset($table,$id) { |
97
|
|
|
$relation = new \App\Itil\Models\Common\AssetRelation(); |
98
|
|
|
$model = $relation->where('owner', "$table:$id")->first(); |
99
|
|
|
if ($model) { |
100
|
|
|
$model->delete(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
public static function getRelationOfTicketByTable($ticketid, $table) { |
|
|
|
|
105
|
|
|
$realtions = new \App\Itil\Models\Common\TicketRelation(); |
106
|
|
|
$realtion = $realtions->where('ticket_id', $ticketid)->where('owner', 'LIKE', $table . "%")->first(); |
|
|
|
|
107
|
|
|
if ($realtion) { |
108
|
|
|
return $realtion; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
View Code Duplication |
public static function getTicketByThreadId($threadid) { |
|
|
|
|
113
|
|
|
$thread = \App\Model\helpdesk\Ticket\Ticket_Thread::where('id', $threadid)->first(); |
114
|
|
|
$tickets = new \App\Itil\Models\Common\Ticket(); |
115
|
|
|
$ticket = $tickets->where('id', $thread->ticket_id)->first(); |
|
|
|
|
116
|
|
|
return $ticket; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
public static function getUserByAssetId($assetid) { |
|
|
|
|
120
|
|
|
$assets = new SdAssets(); |
121
|
|
|
$asset = $assets->find($assetid); |
122
|
|
|
$userid = $asset->used_by; |
123
|
|
|
$users = new \App\User(); |
124
|
|
|
$user = $users->find($userid); |
|
|
|
|
125
|
|
|
return $user; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
public static function getManagedByAssetId($assetid) { |
|
|
|
|
129
|
|
|
$assets = new SdAssets(); |
130
|
|
|
$asset = $assets->find($assetid); |
131
|
|
|
$userid = $asset->managed_by; |
132
|
|
|
$users = new \App\User(); |
133
|
|
|
$user = $users->find($userid); |
|
|
|
|
134
|
|
|
return $user; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public static function getRelationOfTicket($id) { |
138
|
|
|
$relations = new \App\Itil\Models\Common\TicketRelation(); |
139
|
|
|
$relation = $relations->where('ticket_id', $id)->get(); |
|
|
|
|
140
|
|
|
return $relation; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
View Code Duplication |
public static function getRelationOfAsset($table, $id) { |
|
|
|
|
144
|
|
|
$relations = new \App\Itil\Models\Common\AssetRelation(); |
145
|
|
|
$owner = "$table:$id"; |
146
|
|
|
$relation = $relations->where('owner', $owner)->first(); |
147
|
|
|
return $relation; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
View Code Duplication |
public static function getSubjectByThreadId($threadid) { |
|
|
|
|
151
|
|
|
$threads = new \App\Model\helpdesk\Ticket\Ticket_Thread(); |
152
|
|
|
$thread = $threads->find($threadid); |
|
|
|
|
153
|
|
|
$ticketid = $thread->ticket_id; |
154
|
|
|
$thread_first = $threads->where('ticket_id', $ticketid)->first(); |
|
|
|
|
155
|
|
|
return $thread_first->title; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
View Code Duplication |
public static function getBodyByThreadId($threadid) { |
|
|
|
|
159
|
|
|
$threads = new \App\Model\helpdesk\Ticket\Ticket_Thread(); |
160
|
|
|
$thread = $threads->find($threadid); |
|
|
|
|
161
|
|
|
$ticketid = $thread->ticket_id; |
162
|
|
|
$thread_first = $threads->where('ticket_id', $ticketid)->first(); |
|
|
|
|
163
|
|
|
return $thread_first->body; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public static function getBodyByThreadMaxId($threadid) { |
167
|
|
|
$threads = new \App\Model\helpdesk\Ticket\Ticket_Thread(); |
168
|
|
|
$thread = $threads->find($threadid); |
|
|
|
|
169
|
|
|
return $thread->body; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
View Code Duplication |
public static function attachment($id, $table, $attachments, $saved = 2) { |
|
|
|
|
173
|
|
|
//dd($id); |
174
|
|
|
$owner = "$table:$id"; |
175
|
|
|
$value = ""; |
|
|
|
|
176
|
|
|
$type = ""; |
|
|
|
|
177
|
|
|
$size = ""; |
|
|
|
|
178
|
|
|
|
179
|
|
|
if (count($attachments) > 0) { |
180
|
|
|
foreach ($attachments as $attachment) { |
181
|
|
|
if ($attachment) { |
182
|
|
|
$name = $attachment->getClientOriginalName(); |
183
|
|
|
$destinationPath = public_path('uploads/service-desk/attachments'); |
184
|
|
|
$value = rand(0000, 9999) . '.' . $name; |
185
|
|
|
$type = $attachment->getClientOriginalExtension(); |
186
|
|
|
$size = $attachment->getSize(); |
187
|
|
|
if ($saved == 2) { |
188
|
|
|
$attachment->move($destinationPath, $value); |
189
|
|
|
} else { |
190
|
|
|
$value = file_get_contents($attachment->getRealPath()); |
191
|
|
|
} |
192
|
|
|
self::storeAttachment($saved, $owner, $value, $type, $size); |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
View Code Duplication |
public static function storeAttachment($saved, $owner, $value, $type, $size) { |
|
|
|
|
199
|
|
|
$attachments = new Attachments(); |
200
|
|
|
$attachments->create([ |
201
|
|
|
'saved' => $saved, |
202
|
|
|
'owner' => $owner, |
203
|
|
|
'value' => $value, |
204
|
|
|
'type' => $type, |
205
|
|
|
'size' => $size, |
206
|
|
|
]); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
View Code Duplication |
public static function deleteAttachments($id, $table) { |
|
|
|
|
210
|
|
|
$owner = "$table:$id"; |
211
|
|
|
$attachments = new Attachments(); |
212
|
|
|
$attachment = $attachments->where('owner', $owner)->first(); |
|
|
|
|
213
|
|
|
|
214
|
|
|
if ($attachment) { |
215
|
|
|
self::removeAttachment($attachment); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
219
|
|
View Code Duplication |
public static function removeAttachment($attachment) { |
|
|
|
|
220
|
|
|
$saved = $attachment->saved; |
221
|
|
|
if ($saved == 2) { |
222
|
|
|
$file = $attachment->value; |
223
|
|
|
$path = public_path('uploads' . DIRECTORY_SEPARATOR . 'service-desk' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $file); |
224
|
|
|
unlink($path); |
225
|
|
|
} |
226
|
|
|
$attachment->delete(); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
View Code Duplication |
public static function downloadAttachment($attachment) { |
|
|
|
|
230
|
|
|
$saved = $attachment->saved; |
231
|
|
|
if ($saved == 2) { |
232
|
|
|
$file = $attachment->value; |
233
|
|
|
$attach = public_path('uploads' . DIRECTORY_SEPARATOR . 'service-desk' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $file); |
234
|
|
|
} else { |
235
|
|
|
$attach = $attachment->value; |
236
|
|
|
} |
237
|
|
|
return $attach; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
View Code Duplication |
public static function storeAssetRelation($table, $id, $asset_ids = [], $update = false) { |
|
|
|
|
241
|
|
|
$relations = new AssetRelation(); |
242
|
|
|
$owner = "$table:$id"; |
243
|
|
|
$relationses = $relations->where('owner', $owner)->get(); |
244
|
|
|
if ($relationses->count() > 0) { |
245
|
|
|
foreach ($relationses as $relationse) { |
246
|
|
|
$relationse->delete(); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
if (count($asset_ids) > 0) { |
250
|
|
|
if (is_array($asset_ids)) { |
251
|
|
|
$asset_ids = implode(',', $asset_ids); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
$relations->asset_ids = $asset_ids; |
255
|
|
|
$relations->owner = $owner; |
256
|
|
|
$relations->save(); |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|
260
|
|
View Code Duplication |
public static function deleteAssetRelation($id) { |
|
|
|
|
261
|
|
|
$relations = new AssetRelation(); |
262
|
|
|
$relation = $relations->where('asset_ids', '!=', '')->get(); |
263
|
|
|
$asset_ids = ""; |
|
|
|
|
264
|
|
|
//dd($relation->asset_ids); |
|
|
|
|
265
|
|
|
foreach ($relation as $del) { |
266
|
|
|
$array = $del->asset_ids; |
267
|
|
|
$array = array_diff($array, [$id]); |
268
|
|
|
if (count($array) > 0) { |
269
|
|
|
$asset_ids = implode(',', $array); |
270
|
|
|
$del->asset_ids = $asset_ids; |
271
|
|
|
$del->save(); |
272
|
|
|
} else { |
273
|
|
|
$del->delete(); |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
|
View Code Duplication |
public static function xmlToArray($xml, $options = array()) { |
|
|
|
|
279
|
|
|
$defaults = array( |
280
|
|
|
'namespaceSeparator' => ':', //you may want this to be something other than a colon |
281
|
|
|
'attributePrefix' => '', //to distinguish between attributes and nodes with the same name |
282
|
|
|
'alwaysArray' => array(), //array of xml tag names which should always become arrays |
283
|
|
|
'autoArray' => true, //only create arrays for tags which appear more than once |
284
|
|
|
'textContent' => 'option-name', //key used for the text content of elements |
285
|
|
|
'autoText' => true, //skip textContent key if node has no attributes or child nodes |
286
|
|
|
'keySearch' => false, //optional search and replace on tag and attribute names |
287
|
|
|
'keyReplace' => false //replace values for above search values (as passed to str_replace()) |
288
|
|
|
); |
289
|
|
|
$options = array_merge($defaults, $options); |
290
|
|
|
$namespaces = $xml->getDocNamespaces(); |
291
|
|
|
$namespaces[''] = null; //add base (empty) namespace |
|
|
|
|
292
|
|
|
//get attributes from all namespaces |
293
|
|
|
$attributesArray = array(); |
294
|
|
|
foreach ($namespaces as $prefix => $namespace) { |
295
|
|
|
foreach ($xml->attributes($namespace) as $attributeName => $attribute) { |
296
|
|
|
//replace characters in attribute name |
297
|
|
|
if ($options['keySearch']) |
298
|
|
|
$attributeName = str_replace($options['keySearch'], $options['keyReplace'], $attributeName); |
299
|
|
|
$attributeKey = $options['attributePrefix'] |
300
|
|
|
. ($prefix ? $prefix . $options['namespaceSeparator'] : '') |
301
|
|
|
. $attributeName; |
302
|
|
|
$attributesArray[$attributeKey] = (string) $attribute; |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
//get child nodes from all namespaces |
307
|
|
|
$tagsArray = array(); |
308
|
|
|
foreach ($namespaces as $prefix => $namespace) { |
309
|
|
|
foreach ($xml->children($namespace) as $childXml) { |
310
|
|
|
//recurse into child nodes |
311
|
|
|
$childArray = self::xmlToArray($childXml, $options); |
312
|
|
|
list($childTagName, $childProperties) = each($childArray); |
313
|
|
|
|
314
|
|
|
//replace characters in tag name |
315
|
|
|
if ($options['keySearch']) |
316
|
|
|
$childTagName = str_replace($options['keySearch'], $options['keyReplace'], $childTagName); |
317
|
|
|
//add namespace prefix, if any |
318
|
|
|
if ($prefix) |
319
|
|
|
$childTagName = $prefix . $options['namespaceSeparator'] . $childTagName; |
320
|
|
|
|
321
|
|
|
if (!isset($tagsArray[$childTagName])) { |
322
|
|
|
//only entry with this key |
323
|
|
|
//test if tags of this type should always be arrays, no matter the element count |
324
|
|
|
$tagsArray[$childTagName] = in_array($childTagName, $options['alwaysArray']) || !$options['autoArray'] ? array($childProperties) : $childProperties; |
325
|
|
|
} elseif ( |
326
|
|
|
is_array($tagsArray[$childTagName]) && array_keys($tagsArray[$childTagName]) === range(0, count($tagsArray[$childTagName]) - 1) |
327
|
|
|
) { |
328
|
|
|
//key already exists and is integer indexed array |
329
|
|
|
$tagsArray[$childTagName][] = $childProperties; |
330
|
|
|
} else { |
331
|
|
|
//key exists so convert to integer indexed array with previous value in position 0 |
332
|
|
|
$tagsArray[$childTagName] = array($tagsArray[$childTagName], $childProperties); |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
//get text content of node |
338
|
|
|
$textContentArray = array(); |
339
|
|
|
$plainText = trim((string) $xml); |
340
|
|
|
if ($plainText !== '') |
341
|
|
|
$textContentArray[$options['textContent']] = $plainText; |
342
|
|
|
|
343
|
|
|
//stick it all together |
344
|
|
|
$propertiesArray = !$options['autoText'] || $attributesArray || $tagsArray || ($plainText === '') ? array_merge($attributesArray, $tagsArray, $textContentArray) : $plainText; |
|
|
|
|
345
|
|
|
|
346
|
|
|
//return node as array |
|
|
|
|
347
|
|
|
return array( |
348
|
|
|
$xml->getName() => $propertiesArray |
349
|
|
|
); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
View Code Duplication |
public static function arrayToXml($array, $key = '', $options = false) { |
|
|
|
|
353
|
|
|
$field = ""; |
354
|
|
|
$value = ""; |
355
|
|
|
//$options = false; |
|
|
|
|
356
|
|
|
if (is_integer($key)) { |
357
|
|
|
$field = "<field "; |
358
|
|
|
foreach ($array as $index => $item) { |
359
|
|
|
|
360
|
|
|
if (is_array($item)) { |
361
|
|
|
$value = self::value($item); |
362
|
|
|
$options = true; |
363
|
|
|
} elseif ($options == false) { |
|
|
|
|
364
|
|
|
$it = '=' . '"' . $item . '" '; |
365
|
|
|
$field .= $index . $it; |
366
|
|
|
} |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
$field .= ">$value</field>"; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
foreach ($array as $key => $value) { |
373
|
|
|
if (is_array($value)) { |
374
|
|
|
$field .= self::arrayToXml($value, $key, $options); |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
return $field; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
View Code Duplication |
public static function value($item) { |
|
|
|
|
382
|
|
|
$result = ""; |
383
|
|
|
foreach ($item as $k => $v) { |
384
|
|
|
$result .= '<option value=' . '"' . $k . '"' . '>' . $v . '</option>'; |
385
|
|
|
} |
386
|
|
|
return $result; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
View Code Duplication |
public static function deletePopUp($id, $url, $title = "Delete", $class = "btn btn-sm btn-danger", $btn_name = "Delete", $button_check = true) { |
|
|
|
|
390
|
|
|
$button = ""; |
391
|
|
|
if ($button_check == true) { |
|
|
|
|
392
|
|
|
$button = '<a href="#delete" class="' . $class . '" data-toggle="modal" data-target="#delete' . $id . '">' . $btn_name . '</a>'; |
393
|
|
|
} |
394
|
|
|
return $button . '<div class="modal fade" id="delete' . $id . '"> |
395
|
|
|
<div class="modal-dialog"> |
396
|
|
|
<div class="modal-content"> |
397
|
|
|
<div class="modal-header"> |
398
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
399
|
|
|
<h4 class="modal-title">' . $title . '</h4> |
400
|
|
|
</div> |
401
|
|
|
<div class="modal-body"> |
402
|
|
|
<div class="row"> |
403
|
|
|
<div class="col-md-12"> |
404
|
|
|
<p>Are you sure ?</p> |
405
|
|
|
</div> |
406
|
|
|
</div> |
407
|
|
|
</div> |
408
|
|
|
<div class="modal-footer"> |
409
|
|
|
<button type="button" id="close" class="btn btn-default pull-left" data-dismiss="modal">Close</button> |
410
|
|
|
<a href="' . $url . '" class="btn btn-danger">Delete</a> |
411
|
|
|
</div> |
412
|
|
|
</div> |
413
|
|
|
</div> |
414
|
|
|
</div>'; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
View Code Duplication |
public static function checkCabUser($cabid) { |
|
|
|
|
418
|
|
|
$authid = Auth::user()->id; |
419
|
|
|
$result = false; |
420
|
|
|
$cabs = new \App\Itil\Models\Cab(); |
421
|
|
|
$cab = $cabs->find($cabid); |
422
|
|
|
if ($cab) { |
423
|
|
|
$members = $cab->approvers; |
424
|
|
|
if (is_array($members)) { |
425
|
|
|
if (in_array($authid, $members)) { |
426
|
|
|
$result = true; |
427
|
|
|
} |
428
|
|
|
} elseif (is_integer($members)) { |
429
|
|
|
if ($authid == $members) { |
430
|
|
|
$result = true; |
431
|
|
|
} |
432
|
|
|
} elseif ($cab->head) { |
433
|
|
|
if ($authid == $cab->head) { |
434
|
|
|
$result = true; |
435
|
|
|
} |
436
|
|
|
} |
437
|
|
|
} |
438
|
|
|
return $result; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
View Code Duplication |
public static function cabMessage($cabid, $activity, $url) { |
|
|
|
|
442
|
|
|
$cabs = new \App\Itil\Models\Cab(); |
443
|
|
|
$cab = $cabs->find($cabid); |
444
|
|
|
if ($cab) { |
445
|
|
|
$members = $cab->approvers; |
446
|
|
|
$head = $cab->head; |
447
|
|
|
if (is_array($members)) { |
448
|
|
|
if (count($members) > 0) { |
449
|
|
|
foreach ($members as $userid) { |
450
|
|
|
self::sendCabMessage($userid, $head, $activity, $url); |
451
|
|
|
} |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
|
457
|
|
View Code Duplication |
public static function sendCabMessage($userid, $head, $activity, $url) { |
|
|
|
|
458
|
|
|
$users = new \App\User(); |
459
|
|
|
$user = $users->find($userid); |
|
|
|
|
460
|
|
|
$leader = $users->find($head); |
|
|
|
|
461
|
|
|
$heads = ""; |
462
|
|
|
//dd($url); |
463
|
|
|
if ($user) { |
464
|
|
|
$email = $user->email; |
465
|
|
|
$name = $user->first_name . " " . $user->last_name; |
466
|
|
|
if ($leader) { |
467
|
|
|
$heads = $leader->first_name . " " . $leader->last_name; |
468
|
|
|
} |
469
|
|
|
//dd([$email,$name,$heads,$url]); |
|
|
|
|
470
|
|
|
$php_mailer = new \App\Http\Controllers\Common\PhpMailController(); |
471
|
|
|
$php_mailer->sendmail( |
472
|
|
|
$from = $php_mailer->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = [ |
473
|
|
|
'subject' => 'Requesting For CAB Approval', |
474
|
|
|
'scenario' => 'sd-cab-vote', |
475
|
|
|
], $template_variables = [ |
476
|
|
|
'user' => $name, |
477
|
|
|
'system_link' => $url, |
478
|
|
|
'$system_from' => $heads, |
479
|
|
|
] |
480
|
|
|
); |
481
|
|
|
} |
482
|
|
|
} |
483
|
|
|
|
484
|
|
View Code Duplication |
public static function storeGeneralInfo($modelid, $table, $requests) { |
|
|
|
|
485
|
|
|
$owner = "$table:$modelid"; |
486
|
|
|
$request = $requests->except('_token', 'attachment', 'identifier'); |
487
|
|
|
// dd($request); |
|
|
|
|
488
|
|
|
$general = new GeneralInfo(); |
489
|
|
|
|
490
|
|
|
if (count($request) > 0) { |
491
|
|
|
foreach ($request as $key => $value) { |
492
|
|
|
$generals = $general->where('owner', $owner)->where('key', $key)->first(); |
|
|
|
|
493
|
|
|
if ($generals) { |
494
|
|
|
$generals->delete(); |
495
|
|
|
} |
496
|
|
|
if ($value !== "") { |
497
|
|
|
$general->create([ |
498
|
|
|
'owner' => $owner, |
499
|
|
|
'key' => $key, |
500
|
|
|
'value' => $value, |
501
|
|
|
]); |
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
$attachments = $requests->file('attachment'); |
507
|
|
|
$identifier = $requests->input('identifier'); |
508
|
|
|
$attach_table = "$table:$identifier"; |
509
|
|
|
self::attachment($modelid, $attach_table, $attachments); |
510
|
|
|
return "success"; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
View Code Duplication |
public static function getAttachmentSize($size) { |
|
|
|
|
514
|
|
|
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
515
|
|
|
$power = $size > 0 ? floor(log($size, 1024)) : 0; |
516
|
|
|
$value = number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power]; |
517
|
|
|
return $value; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
} |
521
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.