Proyectos de Subversion LeadersLinked - Services

Rev

Rev 295 | Rev 302 | 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
     *
298 www 278
     * @param string $path
279
     * @param string $code,
280
     * @param string $filename
281
     * @param boolean $checkExists
283 www 282
     * @return string
283
     */
298 www 284
    public function getGenericFile($path, $code, $filename, $checkExists = true)
283 www 285
    {
286
        $remoto = $path . '/' . $code. '/' .  $filename;
298 www 287
 
288
        if($checkExists) {
289
            if($this->s3Files->objectExist($remoto)) {
290
                return $this->s3Files->getPresignedUrl($remoto);
291
 
292
            } else {
293
                return;
294
            }
295
        }
296
        return $this->s3Files->getPresignedUrl($remoto);
283 www 297
    }
298
 
295 www 299
 
300
 
301
 
302
 
303
 
283 www 304
    /**
305
     *
306
     * @return string
307
     */
308
    public function getPathGroup()
309
    {
310
        return $this->config['leaderslinked.minio.fullpath_group'];
311
    }
312
 
313
    /**
314
     *
315
     * @return string
316
     */
317
    public function getPathUser()
318
    {
319
        return $this->config['leaderslinked.minio.fullpath_user'];
320
    }
321
 
322
    /**
323
     *
324
     * @return string
325
     */
326
    public function getPathImage()
327
    {
328
        return $this->config['leaderslinked.minio.fullpath_image'];
329
    }
330
 
331
    /**
332
     *
333
     * @return string
334
     */
335
    public function getPathJob()
336
    {
337
        return $this->config['leaderslinked.minio.fullpath_job'];
338
    }
339
 
340
    /**
341
     *
342
     * @return string
343
     */
344
    public function getPathCompany()
345
    {
346
        return $this->config['leaderslinked.minio.fullpath_company'];
347
    }
348
 
349
    /**
350
     *
351
     * @return string
352
     */
353
    public function getPathFeed()
354
    {
355
        return $this->config['leaderslinked.minio.fullpath_feed'];
356
    }
357
 
295 www 358
 
359
 
283 www 360
    /**
361
     *
362
     * @return string
363
     */
295 www 364
    public function getPathMessage()
365
    {
366
        return $this->config['leaderslinked.minio.fullpath_message'];
367
    }
368
 
369
    /**
370
     *
371
     * @return string
372
     */
283 www 373
    public function getPathPost()
374
    {
375
        return $this->config['leaderslinked.minio.fullpath_post'];
376
    }
377
 
378
    /**
379
     *
380
     * @return string
381
     */
382
    public function getPathMicrolearningTopic()
383
    {
384
        return $this->config['leaderslinked.minio.fullpath_microlearning_topic'];
385
    }
386
 
387
    /**
388
     *
389
     * @return string
390
     */
391
    public function getPathMicrolearningCapsule()
392
    {
393
        return $this->config['leaderslinked.minio.fullpath_microlearning_capsule'];
394
    }
395
 
396
    /**
397
     *
398
     * @return string
399
     */
400
    public function getPathMicrolearningSlide()
401
    {
402
        return $this->config['leaderslinked.minio.fullpath_microlearning_slide'];
403
    }
404
 
405
    /**
406
     *
407
     * @return string
408
     */
409
    public function getPathJobDescription()
410
    {
411
        return $this->config['leaderslinked.minio.fullpath_job_description'];
412
    }
413
 
414
    /**
415
     *
416
     * @return string
417
     */
295 www 418
    public function getPathSelfEvaluation()
283 www 419
    {
420
        return $this->config['leaderslinked.minio.fullpath_self_evaluation'];
421
    }
422
 
423
    /**
424
     *
425
     * @return string
426
     */
427
    public function getPathRecruitmentSelection()
428
    {
429
        return $this->config['leaderslinked.minio.fullpath_recruitment_selection'];
430
    }
431
 
432
    /**
433
     *
434
     * @return string
435
     */
436
    public function getPathPerformanceEvaluation()
437
    {
438
        return $this->config['leaderslinked.minio.fullpath_performance_evaluation'];
439
    }
440
 
441
    /**
442
     *
443
     * @return string
444
     */
445
    public function getPathPlanningObjectivesAnGoals()
446
    {
447
        return $this->config['leaderslinked.minio.fullpath_planning_objectives_and_goals'];
448
    }
449
 
450
    /**
451
     *
452
     * @return string
453
     */
454
    public function getPathSurvey()
455
    {
456
        return $this->config['leaderslinked.minio.fullpath_survey'];
457
    }
458
 
459
    /**
460
     *
461
     * @return string
462
     */
463
    public function getPathNetwork()
464
    {
465
        return $this->config['leaderslinked.minio.fullpath_network'];
466
    }
467
 
468
    /**
469
     *
470
     * @return string
471
     */
472
    public function getPathEngagementReward()
473
    {
474
        return $this->config['leaderslinked.minio.fullpath_engagement_reward'];
475
    }
476
 
477
    /**
478
     *
479
     * @return string
480
     */
481
    public function getPathDailyPulse()
482
    {
483
        return $this->config['leaderslinked.minio.fullpath_daily_pulse'];
484
    }
485
 
486
    /**
487
     *
488
     * @return string
489
     */
490
    public function getPathKnowledgeArea()
491
    {
492
        return $this->config['leaderslinked.minio.fullpath_knowledge_area'];
493
    }
494
 
495
    /**
496
     *
497
     * @return string
498
     */
499
    public function getPathMyCoach()
500
    {
501
        return $this->config['leaderslinked.minio.fullpath_my_coach'];
502
    }
503
 
504
    /**
505
     *
506
     * @param String $filename
507
     * return boolean
508
     */
509
    public function objectExist($filename)
510
    {
285 www 511
        return $this->s3Files->objectExist($filename);
283 www 512
    }
513
 
514
    /**
515
     *
516
     * @param string $filename
517
     * @param string $filepath
518
     * @return boolean
519
     */
520
    public function putObject($filename, $filepath)
521
    {
285 www 522
       return $this->s3Files->putObject($filename, $filepath);
283 www 523
    }
524
 
525
 
526
    /**
527
     *
528
     * @param string $filename
529
 
530
     * @return boolean
531
     */
532
    public function deleteObject($filename)
533
    {
285 www 534
        return $this->s3Files->deleteObject($filename);
283 www 535
    }
536
 
537
 
538
    /**
539
     *
540
     * @param string $path
541
     * @param string $code
542
     * @param string $filename
543
     * @return boolean
544
     */
545
    public function deleteFile($path, $code, $filename)
546
    {
547
        if($code) {
548
            $remoto = $path . '/' . $code. '/' .  $filename;
549
        } else {
550
            $remoto = $path . '/' .  $filename;
551
        }
552
        if($this->s3Files->objectExist($remoto)) {
553
            return $this->s3Files->deleteObject($remoto);
554
        } else {
555
            return true;
556
        }
557
    }
295 www 558
 
559
    /**
560
     *
561
     * @param string $path
562
     * @param string $code
563
     * @return boolean
564
     */
565
    public function deleteDirectory($path, $code)
566
    {
567
        $remoto = $path . '/' . $code;
568
        if($this->s3Files->objectExist($remoto)) {
569
            return $this->s3Files->deleteObject($remoto);
570
        } else {
571
            return true;
572
        }
573
    }
574
 
283 www 575
 
576
 
577
    /**
578
     *
579
     * @param string $path
580
     * @param string $code
290 www 581
     * @param string $local_filename
283 www 582
     * @return boolean
583
     */
290 www 584
    public function putFile($path, $code, $local_filename)
283 www 585
    {
586
        if($code) {
290 www 587
            $remote = $path . '/' . $code . '/' . basename($local_filename);
283 www 588
        } else {
290 www 589
            $remote = $path. '/' . basename($local_filename);
283 www 590
        }
591
 
290 www 592
 
593
        $result = $this->s3Files->putObject($remote, $local_filename);
594
        if(file_exists($local_filename)) {
595
            @unlink($local_filename);
596
        }
283 www 597
 
598
        return $result;
599
    }
600
 
601
 
602
    /**
603
     *
604
     * @param string $path
605
     * @param string $code
606
     * @param string $tempfile
607
     * @param string $filename
608
     * @return boolean
609
     */
610
    public function moveAndPutFile($path, $code, $tempfile, $filename)
611
    {
612
        if($code) {
613
            $filepath = $path . '/' . $code;
614
        } else {
615
            $filepath = $path;
616
        }
617
 
618
        $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
619
 
620
        move_uploaded_file($tempfile, $filename);
621
 
285 www 622
        $result = $this->s3Files->putObject($filename, $filepath);
283 www 623
        @unlink($filename);
624
 
625
        return $result;
626
    }
627
 
628
    /**
629
     *
630
     * @return string
631
     */
632
    public function getTempPath()
633
    {
634
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
635
    }
636
 
637
 
638
 
639
 
640
 
641
 
642
}