Proyectos de Subversion LeadersLinked - Services

Rev

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