Proyectos de Subversion LeadersLinked - Backend

Rev

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

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