Proyectos de Subversion LeadersLinked - Services

Rev

Rev 290 | Rev 298 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
283 www 1
<?php
2
namespace LeadersLinked\Library;
3
 
4
use LeadersLinked\Model\User;
5
use LeadersLinked\Model\UserProfile;
6
use LeadersLinked\Model\Company;
7
use LeadersLinked\Model\Group;
8
 
9
class Storage
10
{
11
    /**
12
     *
13
     * @var\LeadersLinked\Library\Storage
14
     */
15
    private static $_instance;
16
 
17
    /**
18
     *
19
     * @var array
20
     */
21
    private $config;
22
 
23
 
24
    /**
25
     *
26
     * @var S3Files
27
     */
28
    private $s3Files;
29
 
30
    /**
31
     *
32
     * @param array $config
33
     */
34
    private function __construct($config)
35
    {
36
        $this->config = $config;
37
        $this->s3Files = S3Files::getInstance($this->config);
38
    }
39
 
40
    /**
41
     *
42
     * @param array $config
43
     * @return \LeadersLinked\Library\Storage
44
     */
45
    public static function getInstance($config)
46
    {
47
        if(self::$_instance == null) {
48
            self::$_instance = new Storage($config);
49
        }
50
 
51
        return self::$_instance;
52
    }
53
 
54
    /**
55
     *
56
     * @param User $user
57
     * @return string
58
     */
59
    public function getUserImage($user)
60
    {
61
        if($user->image) {
62
            $remoto = $this->getPathUser() . '/' . $user->uuid . '/' .  $user->image;
63
            if($this->s3Files->objectExist($remoto)) {
287 www 64
                return $this->s3Files->getPresignedUrl($remoto);
65
 
283 www 66
            }
67
        }
68
 
69
        $remoto = $this->config['leaderslinked.images_default.user_image'];
70
        return $this->s3Files->getPresignedUrl($remoto);
71
    }
72
 
73
 
74
    /**
75
     *
76
     * @param User $user
77
     * @return string
78
     */
79
    public function getUserImageForCodeAndFilename($code, $filename)
80
    {
81
        if($filename) {
82
            $remoto = $this->getPathUser() . '/' . $code . '/' .  $filename;
83
            if($this->s3Files->objectExist($remoto)) {
287 www 84
                return $this->s3Files->getPresignedUrl($remoto);
85
 
283 www 86
            }
87
        }
88
 
89
        $remoto = $this->config['leaderslinked.images_default.user_image'];
287 www 90
        return $this->s3Files->getPresignedUrl($remoto);
91
 
283 www 92
    }
93
 
94
    /**
95
     *
96
     * @param User $user
97
     * @param UserProfile $userProfile
98
     * @return string
99
     */
100
    public function getUserProfileImage($user, $userProfile)
101
    {
102
        if($userProfile->image) {
103
            $remoto = $this->getPathUser() . '/' . $user->uuid . '/' .  $userProfile->image;
104
            if($this->s3Files->objectExist($remoto)) {
287 www 105
                return $this->s3Files->getPresignedUrl($remoto);
106
 
283 www 107
            }
108
        }
109
 
110
        $remoto = $this->config['leaderslinked.images_default.user_profile'];
287 www 111
        return $this->s3Files->getPresignedUrl($remoto);
112
 
283 www 113
    }
114
 
115
    /**
116
     *
117
     * @param User $user
118
     * @param UserProfile $userProfile
119
     * @return string
120
     */
121
    public function getUserProfileCover($user, $userProfile)
122
    {
123
        if($userProfile->cover) {
124
            $remoto = $this->getPathUser() . '/' . $user->uuid . '/' .  $userProfile->cover;
125
            if($this->s3Files->objectExist($remoto)) {
287 www 126
                return $this->s3Files->getPresignedUrl($remoto);
127
 
283 www 128
            }
129
        }
130
 
131
        $remoto = $this->config['leaderslinked.images_default.user_cover'];
287 www 132
        return $this->s3Files->getPresignedUrl($remoto);
133
 
283 www 134
    }
135
 
136
    /**
137
     *
138
     * @param Company $company
139
     * @return string
140
     */
141
    public function getCompanyImage($company)
142
    {
143
        if($company->image) {
144
            $remoto = $this->getPathCompany() . '/' . $company->uuid . '/' .  $company->image;
145
            if($this->s3Files->objectExist($remoto)) {
287 www 146
                return $this->s3Files->getPresignedUrl($remoto);
147
 
283 www 148
            }
149
        }
150
 
151
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
287 www 152
        return $this->s3Files->getPresignedUrl($remoto);
153
 
283 www 154
    }
155
 
156
    /**
157
     *
158
     * @param string $code
159
     * @param string $filename
160
     * @return string
161
     */
162
    public function getCompanyImageForCodeAndFilename($code, $filename)
163
    {
164
        if($filename) {
165
            $remoto = $this->getPathCompany() . '/' . $code . '/' .  $filename;
166
            if($this->s3Files->objectExist($remoto)) {
287 www 167
                return $this->s3Files->getPresignedUrl($remoto);
168
 
283 www 169
            }
170
        }
171
 
172
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
287 www 173
        return $this->s3Files->getPresignedUrl($remoto);
174
 
283 www 175
    }
176
 
177
    /**
178
     *
179
     * @param Company $company
180
     * @return string
181
     */
182
    public function getCompanyCover($company)
183
    {
184
        if($company->cover) {
185
            $remoto = $this->getPathCompany() . '/' . $company->uuid . '/' .  $company->cover;
186
            if($this->s3Files->objectExist($remoto)) {
287 www 187
                return $this->s3Files->getPresignedUrl($remoto);
188
 
283 www 189
            }
190
        }
191
 
192
        $remoto = $this->config['leaderslinked.images_default.company_cover'];
287 www 193
        return $this->s3Files->getPresignedUrl($remoto);
194
 
283 www 195
    }
196
 
197
    /**
198
     *
199
     * @param Group $group
200
     * @return string
201
     */
202
    public function getGroupImage($group)
203
    {
204
        if($group->image) {
205
            $remoto = $this->getPathGroup() . '/' . $group->uuid . '/' .  $group->image;
206
            if($this->s3Files->objectExist($remoto)) {
287 www 207
                return $this->s3Files->getPresignedUrl($remoto);
208
 
283 www 209
            }
210
        }
211
 
212
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
287 www 213
        return $this->s3Files->getPresignedUrl($remoto);
214
 
283 www 215
    }
216
 
217
    /**
218
     *
219
     * @param string $code
220
     * @param string $filename
221
     * @return string
222
     */
223
    public function getGroupImageForCodeAndFilename($code, $filename)
224
    {
225
        if($filename) {
226
            $remoto = $this->getPathGroup() . '/' . $code . '/' .  $filename;
227
            if($this->s3Files->objectExist($remoto)) {
287 www 228
                return $this->s3Files->getPresignedUrl($remoto);
229
 
283 www 230
            }
231
        }
232
 
233
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
287 www 234
        return $this->s3Files->getPresignedUrl($remoto);
235
 
283 www 236
    }
237
 
238
    /**
239
     *
240
     * @param Group $group
241
     * @return string
242
     */
243
    public function getGroupCover($group)
244
    {
245
        if($group->cover) {
246
            $remoto = $this->getPathGroup() . '/' . $group->uuid . '/' .  $group->cover;
247
            if($this->s3Files->objectExist($remoto)) {
287 www 248
                return $this->s3Files->getPresignedUrl($remoto);
249
 
283 www 250
            }
251
        }
252
 
253
        $remoto = $this->config['leaderslinked.images_default.group_cover'];
287 www 254
        return $this->s3Files->getPresignedUrl($remoto);
255
 
283 www 256
    }
257
 
258
    /**
259
     *
260
     * @param Group $group
261
     * @return string
262
     */
263
    public function getGenericImage($path, $code, $filename)
264
    {
265
        $remoto = $path . '/' . $code. '/' .  $filename;
266
        if($this->s3Files->objectExist($remoto)) {
287 www 267
            return $this->s3Files->getPresignedUrl($remoto);
268
 
283 www 269
        } else {
270
            $remoto = $this->config['leaderslinked.images_default.no_image'];
287 www 271
            return $this->s3Files->getPresignedUrl($remoto);
272
 
283 www 273
        }
274
    }
275
 
276
    /**
277
     *
278
     * @param Group $group
279
     * @return string
280
     */
281
    public function getGenericFile($path, $code, $filename)
282
    {
283
        $remoto = $path . '/' . $code. '/' .  $filename;
284
        if($this->s3Files->objectExist($remoto)) {
287 www 285
            return $this->s3Files->getPresignedUrl($remoto);
286
 
283 www 287
        } else {
288
            return;
289
        }
290
    }
291
 
295 www 292
 
293
 
294
 
295
 
296
 
283 www 297
    /**
298
     *
299
     * @return string
300
     */
301
    public function getPathGroup()
302
    {
303
        return $this->config['leaderslinked.minio.fullpath_group'];
304
    }
305
 
306
    /**
307
     *
308
     * @return string
309
     */
310
    public function getPathUser()
311
    {
312
        return $this->config['leaderslinked.minio.fullpath_user'];
313
    }
314
 
315
    /**
316
     *
317
     * @return string
318
     */
319
    public function getPathImage()
320
    {
321
        return $this->config['leaderslinked.minio.fullpath_image'];
322
    }
323
 
324
    /**
325
     *
326
     * @return string
327
     */
328
    public function getPathJob()
329
    {
330
        return $this->config['leaderslinked.minio.fullpath_job'];
331
    }
332
 
333
    /**
334
     *
335
     * @return string
336
     */
337
    public function getPathCompany()
338
    {
339
        return $this->config['leaderslinked.minio.fullpath_company'];
340
    }
341
 
342
    /**
343
     *
344
     * @return string
345
     */
346
    public function getPathFeed()
347
    {
348
        return $this->config['leaderslinked.minio.fullpath_feed'];
349
    }
350
 
295 www 351
 
352
 
283 www 353
    /**
354
     *
355
     * @return string
356
     */
295 www 357
    public function getPathMessage()
358
    {
359
        return $this->config['leaderslinked.minio.fullpath_message'];
360
    }
361
 
362
    /**
363
     *
364
     * @return string
365
     */
283 www 366
    public function getPathPost()
367
    {
368
        return $this->config['leaderslinked.minio.fullpath_post'];
369
    }
370
 
371
    /**
372
     *
373
     * @return string
374
     */
375
    public function getPathMicrolearningTopic()
376
    {
377
        return $this->config['leaderslinked.minio.fullpath_microlearning_topic'];
378
    }
379
 
380
    /**
381
     *
382
     * @return string
383
     */
384
    public function getPathMicrolearningCapsule()
385
    {
386
        return $this->config['leaderslinked.minio.fullpath_microlearning_capsule'];
387
    }
388
 
389
    /**
390
     *
391
     * @return string
392
     */
393
    public function getPathMicrolearningSlide()
394
    {
395
        return $this->config['leaderslinked.minio.fullpath_microlearning_slide'];
396
    }
397
 
398
    /**
399
     *
400
     * @return string
401
     */
402
    public function getPathJobDescription()
403
    {
404
        return $this->config['leaderslinked.minio.fullpath_job_description'];
405
    }
406
 
407
    /**
408
     *
409
     * @return string
410
     */
295 www 411
    public function getPathSelfEvaluation()
283 www 412
    {
413
        return $this->config['leaderslinked.minio.fullpath_self_evaluation'];
414
    }
415
 
416
    /**
417
     *
418
     * @return string
419
     */
420
    public function getPathRecruitmentSelection()
421
    {
422
        return $this->config['leaderslinked.minio.fullpath_recruitment_selection'];
423
    }
424
 
425
    /**
426
     *
427
     * @return string
428
     */
429
    public function getPathPerformanceEvaluation()
430
    {
431
        return $this->config['leaderslinked.minio.fullpath_performance_evaluation'];
432
    }
433
 
434
    /**
435
     *
436
     * @return string
437
     */
438
    public function getPathPlanningObjectivesAnGoals()
439
    {
440
        return $this->config['leaderslinked.minio.fullpath_planning_objectives_and_goals'];
441
    }
442
 
443
    /**
444
     *
445
     * @return string
446
     */
447
    public function getPathSurvey()
448
    {
449
        return $this->config['leaderslinked.minio.fullpath_survey'];
450
    }
451
 
452
    /**
453
     *
454
     * @return string
455
     */
456
    public function getPathNetwork()
457
    {
458
        return $this->config['leaderslinked.minio.fullpath_network'];
459
    }
460
 
461
    /**
462
     *
463
     * @return string
464
     */
465
    public function getPathEngagementReward()
466
    {
467
        return $this->config['leaderslinked.minio.fullpath_engagement_reward'];
468
    }
469
 
470
    /**
471
     *
472
     * @return string
473
     */
474
    public function getPathDailyPulse()
475
    {
476
        return $this->config['leaderslinked.minio.fullpath_daily_pulse'];
477
    }
478
 
479
    /**
480
     *
481
     * @return string
482
     */
483
    public function getPathKnowledgeArea()
484
    {
485
        return $this->config['leaderslinked.minio.fullpath_knowledge_area'];
486
    }
487
 
488
    /**
489
     *
490
     * @return string
491
     */
492
    public function getPathMyCoach()
493
    {
494
        return $this->config['leaderslinked.minio.fullpath_my_coach'];
495
    }
496
 
497
    /**
498
     *
499
     * @param String $filename
500
     * return boolean
501
     */
502
    public function objectExist($filename)
503
    {
285 www 504
        return $this->s3Files->objectExist($filename);
283 www 505
    }
506
 
507
    /**
508
     *
509
     * @param string $filename
510
     * @param string $filepath
511
     * @return boolean
512
     */
513
    public function putObject($filename, $filepath)
514
    {
285 www 515
       return $this->s3Files->putObject($filename, $filepath);
283 www 516
    }
517
 
518
 
519
    /**
520
     *
521
     * @param string $filename
522
 
523
     * @return boolean
524
     */
525
    public function deleteObject($filename)
526
    {
285 www 527
        return $this->s3Files->deleteObject($filename);
283 www 528
    }
529
 
530
 
531
    /**
532
     *
533
     * @param string $path
534
     * @param string $code
535
     * @param string $filename
536
     * @return boolean
537
     */
538
    public function deleteFile($path, $code, $filename)
539
    {
540
        if($code) {
541
            $remoto = $path . '/' . $code. '/' .  $filename;
542
        } else {
543
            $remoto = $path . '/' .  $filename;
544
        }
545
        if($this->s3Files->objectExist($remoto)) {
546
            return $this->s3Files->deleteObject($remoto);
547
        } else {
548
            return true;
549
        }
550
    }
295 www 551
 
552
    /**
553
     *
554
     * @param string $path
555
     * @param string $code
556
     * @return boolean
557
     */
558
    public function deleteDirectory($path, $code)
559
    {
560
        $remoto = $path . '/' . $code;
561
        if($this->s3Files->objectExist($remoto)) {
562
            return $this->s3Files->deleteObject($remoto);
563
        } else {
564
            return true;
565
        }
566
    }
567
 
283 www 568
 
569
 
570
    /**
571
     *
572
     * @param string $path
573
     * @param string $code
290 www 574
     * @param string $local_filename
283 www 575
     * @return boolean
576
     */
290 www 577
    public function putFile($path, $code, $local_filename)
283 www 578
    {
579
        if($code) {
290 www 580
            $remote = $path . '/' . $code . '/' . basename($local_filename);
283 www 581
        } else {
290 www 582
            $remote = $path. '/' . basename($local_filename);
283 www 583
        }
584
 
290 www 585
 
586
        $result = $this->s3Files->putObject($remote, $local_filename);
587
        if(file_exists($local_filename)) {
588
            @unlink($local_filename);
589
        }
283 www 590
 
591
        return $result;
592
    }
593
 
594
 
595
    /**
596
     *
597
     * @param string $path
598
     * @param string $code
599
     * @param string $tempfile
600
     * @param string $filename
601
     * @return boolean
602
     */
603
    public function moveAndPutFile($path, $code, $tempfile, $filename)
604
    {
605
        if($code) {
606
            $filepath = $path . '/' . $code;
607
        } else {
608
            $filepath = $path;
609
        }
610
 
611
        $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
612
 
613
        move_uploaded_file($tempfile, $filename);
614
 
285 www 615
        $result = $this->s3Files->putObject($filename, $filepath);
283 www 616
        @unlink($filename);
617
 
618
        return $result;
619
    }
620
 
621
    /**
622
     *
623
     * @return string
624
     */
625
    public function getTempPath()
626
    {
627
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
628
    }
629
 
630
 
631
 
632
 
633
 
634
 
635
}