Proyectos de Subversion LeadersLinked - Backend

Rev

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