Proyectos de Subversion LeadersLinked - Services

Rev

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