Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17012 | | 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
{
17018 efrain 11
 
12
    const TYPE_CHAT                             = 'chat';
13
    const TYPE_GROUP                            = 'group';
14
    const TYPE_USER                             = 'user';
15
    const TYPE_IMAGE                            = 'image';
16
    const TYPE_JOB                              = 'job';
17
    const TYPE_COMPANY                          = 'company';
18
    const TYPE_FEED                             = 'feed';
19
    CONST TYPE_POST                             = 'post';
20
    const TYPE_MICROLEARNING_TOPIC              = 'topic';
21
    const TYPE_MICROLEARNING_CAPSULE            = 'capsule';
22
    const TYPE_MICROLEARNING_SLIDE              = 'slide';
23
    const TYPE_JOB_DESCRIPTION                  = 'jobdesc';
24
    const TYPE_SELF_EVALUATION                  = 'selfval';
25
    const TYPE_PERFORMANCE_EVALUATION           = 'perfeva';
26
    const TYPE_RECRUITMENT_SELECTION            = 'recrsel';
27
    const TYPE_PLANNING_OBJECTIVES_AND_GOALS    = 'plannig';
28
    const TYPE_MESSAGE                          = 'message';
29
    const TYPE_SURVEY                           = 'survey';
30
    const TYPE_NETWORK                          = 'network';
31
    const TYPE_DAILY_PULSE                      = 'dailpuls';
32
    const TYPE_ENGAGEMENT_REWARD                = 'engarewr';
33
    const TYPE_KNOWLEDGE_AREA                   = 'knowarea';
34
    const TYPE_MY_COACH                         = 'mycoach';
35
    const TYPE_HABIT_EMOJI                      = 'habit-emoji';
36
    const TYPE_HABIT_CONTENT                    = 'habit-content';
37
 
38
    const BASE_PATH = 'data' . DIRECTORY_SEPARATOR . 'storage';
39
 
40
 
17002 efrain 41
    /**
42
     *
43
     * @var\LeadersLinked\Library\Storage
44
     */
45
    private static $_instance;
46
 
47
    /**
48
     *
49
     * @var array
50
     */
51
    private $config;
52
 
53
    /**
54
     *
17018 efrain 55
     * @var \Laminas\Db\Adapter\AdapterInterface
17002 efrain 56
     */
17018 efrain 57
    private $adapter;
17002 efrain 58
 
17018 efrain 59
 
60
 
61
 
17002 efrain 62
    /**
63
     *
64
     * @param array $config
17018 efrain 65
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
17002 efrain 66
     */
17018 efrain 67
    private function __construct($config, $adapter)
17002 efrain 68
    {
17018 efrain 69
        $this->config       = $config;
70
        $this->adapter      = $adapter;
17002 efrain 71
    }
72
 
73
    /**
74
     *
75
     * @param array $config
17018 efrain 76
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
17002 efrain 77
     * @return \LeadersLinked\Library\Storage
78
     */
17018 efrain 79
    public static function getInstance($config, $adapter)
17002 efrain 80
    {
81
        if(self::$_instance == null) {
17018 efrain 82
            self::$_instance = new Storage($config, $adapter);
17002 efrain 83
        }
84
 
85
        return self::$_instance;
86
    }
87
 
88
    /**
89
     *
90
     * @param User $user
91
     * @return string
92
     */
93
    public function getUserImage($user)
94
    {
95
        if($user->image) {
17018 efrain 96
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $user->image;
97
            if(file_exists($remoto)) {
98
                return $this->getPresignedUrl($remoto);
99
 
17002 efrain 100
            }
101
        }
102
 
103
        $remoto = $this->config['leaderslinked.images_default.user_image'];
17018 efrain 104
        return $this->getPresignedUrl($remoto);
17002 efrain 105
    }
106
 
107
 
108
    /**
109
     *
110
     * @param User $user
111
     * @return string
112
     */
113
    public function getUserImageForCodeAndFilename($code, $filename)
114
    {
115
        if($filename) {
17018 efrain 116
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
117
            if(file_exists($remoto)) {
118
                return $this->getPresignedUrl($remoto);
119
 
17002 efrain 120
            }
121
        }
122
 
123
        $remoto = $this->config['leaderslinked.images_default.user_image'];
17018 efrain 124
        return $this->getPresignedUrl($remoto);
125
 
17002 efrain 126
    }
127
 
128
    /**
129
     *
130
     * @param User $user
131
     * @param UserProfile $userProfile
132
     * @return string
133
     */
134
    public function getUserProfileImage($user, $userProfile)
135
    {
136
        if($userProfile->image) {
17018 efrain 137
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->image;
138
            if(file_exists($remoto)) {
139
                return $this->getPresignedUrl($remoto);
140
 
17002 efrain 141
            }
142
        }
143
 
144
        $remoto = $this->config['leaderslinked.images_default.user_profile'];
17018 efrain 145
        return $this->getPresignedUrl($remoto);
146
 
17002 efrain 147
    }
148
 
149
    /**
150
     *
151
     * @param User $user
152
     * @param UserProfile $userProfile
153
     * @return string
154
     */
155
    public function getUserProfileCover($user, $userProfile)
156
    {
157
        if($userProfile->cover) {
17018 efrain 158
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->cover;
159
            if(file_exists($remoto)) {
160
                return $this->getPresignedUrl($remoto);
161
 
17002 efrain 162
            }
163
        }
164
 
165
        $remoto = $this->config['leaderslinked.images_default.user_cover'];
17018 efrain 166
        return $this->getPresignedUrl($remoto);
167
 
17002 efrain 168
    }
169
 
170
    /**
171
     *
172
     * @param Company $company
173
     * @return string
174
     */
175
    public function getCompanyImage($company)
176
    {
177
        if($company->image) {
17018 efrain 178
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->image;
179
            if(file_exists($remoto)) {
180
                return $this->getPresignedUrl($remoto);
181
 
17002 efrain 182
            }
183
        }
184
 
185
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
17018 efrain 186
        return $this->getPresignedUrl($remoto);
187
 
17002 efrain 188
    }
189
 
190
    /**
191
     *
192
     * @param string $code
193
     * @param string $filename
194
     * @return string
195
     */
196
    public function getCompanyImageForCodeAndFilename($code, $filename)
197
    {
198
        if($filename) {
17018 efrain 199
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
200
            if(file_exists($remoto)) {
201
                return $this->getPresignedUrl($remoto);
202
 
17002 efrain 203
            }
204
        }
205
 
206
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
17018 efrain 207
        return $this->getPresignedUrl($remoto);
208
 
17002 efrain 209
    }
210
 
211
    /**
212
     *
213
     * @param Company $company
214
     * @return string
215
     */
216
    public function getCompanyCover($company)
217
    {
218
        if($company->cover) {
17018 efrain 219
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->cover;
220
            if(file_exists($remoto)) {
221
                return $this->getPresignedUrl($remoto);
222
 
17002 efrain 223
            }
224
        }
225
 
226
        $remoto = $this->config['leaderslinked.images_default.company_cover'];
17018 efrain 227
        return $this->getPresignedUrl($remoto);
228
 
17002 efrain 229
    }
230
 
231
    /**
232
     *
233
     * @param Group $group
234
     * @return string
235
     */
236
    public function getGroupImage($group)
237
    {
238
        if($group->image) {
17018 efrain 239
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR . $group->image;
240
            if(file_exists($remoto)) {
241
                return $this->getPresignedUrl($remoto);
242
 
17002 efrain 243
            }
244
        }
245
 
246
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
17018 efrain 247
        return $this->getPresignedUrl($remoto);
248
 
17002 efrain 249
    }
250
 
251
    /**
252
     *
253
     * @param string $code
254
     * @param string $filename
255
     * @return string
256
     */
257
    public function getGroupImageForCodeAndFilename($code, $filename)
258
    {
259
        if($filename) {
17018 efrain 260
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
261
            if(file_exists($remoto)) {
262
                return $this->getPresignedUrl($remoto);
263
 
17002 efrain 264
            }
265
        }
266
 
267
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
17018 efrain 268
        return $this->getPresignedUrl($remoto);
269
 
17002 efrain 270
    }
271
 
272
    /**
273
     *
274
     * @param Group $group
275
     * @return string
276
     */
277
    public function getGroupCover($group)
278
    {
279
        if($group->cover) {
17018 efrain 280
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR .  $group->cover;
281
            if(file_exists($remoto)) {
282
                return $this->getPresignedUrl($remoto);
283
 
17002 efrain 284
            }
285
        }
286
 
287
        $remoto = $this->config['leaderslinked.images_default.group_cover'];
17018 efrain 288
        return $this->getPresignedUrl($remoto);
289
 
17002 efrain 290
    }
291
 
292
    /**
293
     *
294
     * @param Group $group
295
     * @return string
296
     */
297
    public function getGenericImage($path, $code, $filename)
298
    {
17018 efrain 299
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
300
 
301
 
302
        if(file_exists($remoto)) {
303
            return $this->getPresignedUrl($remoto);
304
 
17002 efrain 305
        } else {
306
            $remoto = $this->config['leaderslinked.images_default.no_image'];
17018 efrain 307
            return $this->getPresignedUrl($remoto);
308
 
17002 efrain 309
        }
310
    }
311
 
17018 efrain 312
 
313
 
314
 
17002 efrain 315
    /**
316
     *
17008 efrain 317
     * @param string $path
17018 efrain 318
     * @param string $code,
17008 efrain 319
     * @param string $filename
17018 efrain 320
     * @param boolean $checkExists
17002 efrain 321
     * @return string
322
     */
17018 efrain 323
    public function getFileFromDisk($path, $code, $filename)
17002 efrain 324
    {
17018 efrain 325
        $current_file = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
326
 
327
        if(file_exists($current_file)) {
328
            return $current_file;
329
        }
330
        return;
331
    }
332
 
333
 
334
    /**
335
     *
336
     * @param string $path
337
     * @param string $code,
338
     * @return string
339
     */
340
    public function getDirectoryFromDisk($path, $code)
341
    {
342
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code;
343
 
344
        if(file_exists($directory)) {
345
            return $directory;
346
        }
347
        return;
348
    }
349
 
350
    /**
351
     *
352
     * @param string $path
353
     * @param string $code,
354
     * @param string $filename
355
     * @param boolean $checkExists
356
     * @return string
357
     */
358
    public function getGenericFile($path, $code, $filename, $checkExists = true)
359
    {
360
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
361
 
362
 
363
        if($checkExists) {
364
            if(file_exists($remoto)) {
365
                return $this->getPresignedUrl($remoto);
366
 
367
            } else {
368
                return;
369
            }
370
        }
371
        return $this->getPresignedUrl($remoto);
372
    }
373
 
374
    public function getPathByType($type)
375
    {
376
        switch($type)
377
        {
378
            case TYPE_CHAT :
379
                return $this->getPathChat();
380
 
381
            case TYPE_GROUP :
382
                return $this->getPathGroup();
383
 
384
            case TYPE_USER :
385
                return $this->getPathUser();
386
 
387
            case TYPE_IMAGE :
388
                return $this->getPathImage();
389
 
390
            case TYPE_JOB :
391
                return $this->getPathJob();
392
 
393
            case TYPE_COMPANY :
394
                return $this->getPathCompany();
395
 
396
            case TYPE_FEED :
397
                return $this->getPathFeed();
398
 
399
            case TYPE_POST :
400
                return $this->getPathPost();
401
 
402
            case TYPE_MICROLEARNING_TOPIC  :
403
                return $this->getPathMicrolearningTopic();
404
 
405
            case TYPE_MICROLEARNING_CAPSULE :
406
                return $this->getPathMicrolearningCapsule();
407
 
408
            case TYPE_MICROLEARNING_SLIDE  :
409
                return $this->getPathMicrolearningSlide();
410
 
411
            case TYPE_JOB_DESCRIPTION :
412
                return $this->getPathJobDescription();
413
 
414
            case TYPE_SELF_EVALUATION  :
415
                return $this->getPathSelfEvaluation();
416
 
417
            case TYPE_PERFORMANCE_EVALUATION  :
418
                return $this->getPathPerformanceEvaluation();
419
 
420
            case TYPE_RECRUITMENT_SELECTION  :
421
                return $this->getPathRecruitmentSelection();
422
 
423
            case TYPE_PLANNING_OBJECTIVES_AND_GOALS :
424
                return $this->getPathPlanningObjectivesAnGoals();
425
 
426
 
427
            case TYPE_MESSAGE  :
428
                return $this->getPathMessage();
429
 
430
            case TYPE_SURVEY   :
431
                return $this->getPathSurvey();
432
 
433
            case TYPE_NETWORK   :
434
                return $this->getPathNetwork();
435
 
436
            case TYPE_DAILY_PULSE :
437
                return $this->getPathDailyPulse();
438
 
439
            case TYPE_ENGAGEMENT_REWARD  :
440
                return $this->getPathEngagementReward();
441
 
442
            case TYPE_KNOWLEDGE_AREA :
443
                return $this->getPathKnowledgeArea();
444
 
445
            case TYPE_MY_COACH :
446
                return $this->getPathMyCoach();
447
 
448
            case TYPE_HABIT_EMOJI  :
449
                return $this->getPathHabitEmoji();
450
 
451
            case TYPE_HABIT_CONTENT :
452
                return $this->getPathHabitContent();
453
 
454
            default :
455
                return DIRECTORY_SEPARATOR;
456
        }
457
 
458
 
459
    }
460
 
461
    /**
462
     *
463
     * @param Group $group
464
     * @return string
465
     */
466
    public function getGenericImageByType($type, $code, $filename)
467
    {
468
        $path = $this->getPathByType($type);
469
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
470
 
471
        if(file_exists($remoto)) {
472
            return $this->getPresignedUrl($remoto);
473
 
17002 efrain 474
        } else {
17018 efrain 475
            $remoto = $this->config['leaderslinked.images_default.no_image'];
476
            return $this->getPresignedUrl($remoto);
477
 
17002 efrain 478
        }
479
    }
480
 
17018 efrain 481
    /**
482
     *
483
     * @param string $type
484
     * @param string $code,
485
     * @param string $filename
486
     * @param boolean $checkExists
487
     * @return string
488
     */
489
    public function getGenericFileByType($type, $code, $filename, $checkExists = true)
490
    {
491
        $path = $this->getPathByType($type);
492
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
493
 
494
        if($checkExists) {
495
            if(file_exists($remoto)) {
496
                return $this->getPresignedUrl($remoto);
497
 
498
            } else {
499
                return;
500
            }
501
        }
502
        return $this->getPresignedUrl($remoto);
503
    }
17008 efrain 504
 
17002 efrain 505
    /**
506
     *
17008 efrain 507
     * @param string $path
508
     * @param string $code
509
     * @param string $filename
17002 efrain 510
     * @return string
511
     */
17008 efrain 512
    public function delete($path, $code, $filename)
513
    {
17018 efrain 514
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
515
        return @unlink($remoto);
516
 
17008 efrain 517
 
518
    }
519
 
17018 efrain 520
 
521
 
17008 efrain 522
    /**
523
     *
524
     * @return string
525
     */
17002 efrain 526
    public function getPathMedia()
527
    {
17018 efrain 528
        return $this->config['leaderslinked.storage.fullpath_media'];
17002 efrain 529
    }
530
 
531
 
532
    /**
17018 efrain 533
     *
534
     * @return string
535
     */
536
    public function getPathHabitEmoji()
537
    {
538
        return $this->config['leaderslinked.storage.fullpath_habit_emoji'];
539
    }
540
 
541
    /**
542
     *
543
     * @return string
544
     */
545
    public function getPathHabitContent()
546
    {
547
        return $this->config['leaderslinked.storage.fullpath_habit_content'];
548
    }
549
 
550
 
551
    /**
17002 efrain 552
     *
553
     * @return string
554
     */
555
    public function getPathGroup()
556
    {
17018 efrain 557
        return $this->config['leaderslinked.storage.fullpath_group'];
17002 efrain 558
    }
559
 
560
    /**
561
     *
562
     * @return string
563
     */
564
    public function getPathUser()
565
    {
17018 efrain 566
        return $this->config['leaderslinked.storage.fullpath_user'];
17002 efrain 567
    }
568
 
569
    /**
570
     *
571
     * @return string
572
     */
573
    public function getPathImage()
574
    {
17018 efrain 575
        return $this->config['leaderslinked.storage.fullpath_image'];
17002 efrain 576
    }
577
 
578
    /**
579
     *
580
     * @return string
581
     */
582
    public function getPathJob()
583
    {
17018 efrain 584
        return $this->config['leaderslinked.storage.fullpath_job'];
17002 efrain 585
    }
586
 
587
    /**
588
     *
589
     * @return string
590
     */
17018 efrain 591
    public function getPathChat()
592
    {
593
        return $this->config['leaderslinked.storage.fullpath_chat'];
594
    }
595
 
596
    /**
597
     *
598
     * @return string
599
     */
17002 efrain 600
    public function getPathCompany()
601
    {
17018 efrain 602
        return $this->config['leaderslinked.storage.fullpath_company'];
17002 efrain 603
    }
604
 
605
    /**
606
     *
607
     * @return string
608
     */
609
    public function getPathFeed()
610
    {
17018 efrain 611
        return $this->config['leaderslinked.storage.fullpath_feed'];
17002 efrain 612
    }
613
 
17018 efrain 614
 
615
 
17002 efrain 616
    /**
617
     *
618
     * @return string
619
     */
17018 efrain 620
    public function getPathMessage()
621
    {
622
        return $this->config['leaderslinked.storage.fullpath_message'];
623
    }
624
 
625
    /**
626
     *
627
     * @return string
628
     */
17002 efrain 629
    public function getPathPost()
630
    {
17018 efrain 631
        return $this->config['leaderslinked.storage.fullpath_post'];
17002 efrain 632
    }
633
 
634
    /**
635
     *
636
     * @return string
637
     */
638
    public function getPathMicrolearningTopic()
639
    {
17018 efrain 640
        return $this->config['leaderslinked.storage.fullpath_microlearning_topic'];
17002 efrain 641
    }
642
 
643
    /**
644
     *
645
     * @return string
646
     */
647
    public function getPathMicrolearningCapsule()
648
    {
17018 efrain 649
        return $this->config['leaderslinked.storage.fullpath_microlearning_capsule'];
17002 efrain 650
    }
651
 
652
    /**
653
     *
654
     * @return string
655
     */
656
    public function getPathMicrolearningSlide()
657
    {
17018 efrain 658
        return $this->config['leaderslinked.storage.fullpath_microlearning_slide'];
17002 efrain 659
    }
660
 
661
    /**
662
     *
663
     * @return string
664
     */
665
    public function getPathJobDescription()
666
    {
17018 efrain 667
        return $this->config['leaderslinked.storage.fullpath_job_description'];
17002 efrain 668
    }
669
 
670
    /**
671
     *
672
     * @return string
673
     */
17018 efrain 674
    public function getPathSelfEvaluation()
17002 efrain 675
    {
17018 efrain 676
        return $this->config['leaderslinked.storage.fullpath_self_evaluation'];
17002 efrain 677
    }
678
 
679
    /**
680
     *
681
     * @return string
682
     */
683
    public function getPathRecruitmentSelection()
684
    {
17018 efrain 685
        return $this->config['leaderslinked.storage.fullpath_recruitment_selection'];
17002 efrain 686
    }
687
 
688
    /**
689
     *
690
     * @return string
691
     */
692
    public function getPathPerformanceEvaluation()
693
    {
17018 efrain 694
        return $this->config['leaderslinked.storage.fullpath_performance_evaluation'];
17002 efrain 695
    }
696
 
697
    /**
698
     *
699
     * @return string
700
     */
701
    public function getPathPlanningObjectivesAnGoals()
702
    {
17018 efrain 703
        return $this->config['leaderslinked.storage.fullpath_planning_objectives_and_goals'];
17002 efrain 704
    }
705
 
706
    /**
707
     *
708
     * @return string
709
     */
710
    public function getPathSurvey()
711
    {
17018 efrain 712
        return $this->config['leaderslinked.storage.fullpath_survey'];
17002 efrain 713
    }
714
 
715
    /**
716
     *
717
     * @return string
718
     */
719
    public function getPathNetwork()
720
    {
17018 efrain 721
        return $this->config['leaderslinked.storage.fullpath_network'];
17002 efrain 722
    }
723
 
724
    /**
725
     *
726
     * @return string
727
     */
728
    public function getPathEngagementReward()
729
    {
17018 efrain 730
        return $this->config['leaderslinked.storage.fullpath_engagement_reward'];
17002 efrain 731
    }
732
 
733
    /**
734
     *
735
     * @return string
736
     */
737
    public function getPathDailyPulse()
738
    {
17018 efrain 739
        return $this->config['leaderslinked.storage.fullpath_daily_pulse'];
17002 efrain 740
    }
741
 
742
    /**
743
     *
744
     * @return string
745
     */
746
    public function getPathKnowledgeArea()
747
    {
17018 efrain 748
        return $this->config['leaderslinked.storage.fullpath_knowledge_area'];
17002 efrain 749
    }
750
 
751
    /**
752
     *
753
     * @return string
754
     */
755
    public function getPathMyCoach()
756
    {
17018 efrain 757
        return $this->config['leaderslinked.storage.fullpath_my_coach'];
17002 efrain 758
    }
759
 
760
    /**
761
     *
762
     * @param String $filename
763
     * return boolean
764
     */
765
    public function objectExist($filename)
766
    {
17018 efrain 767
        return file_exists($filename);
17002 efrain 768
    }
769
 
770
    /**
771
     *
17018 efrain 772
     * @param string $remote
17002 efrain 773
     * @param string $local
774
     * @return boolean
775
     */
776
    public function putObject($remote, $local)
777
    {
17018 efrain 778
 
779
        $dir = dirname($remote);
780
        if(!file_exists($dir)) {
781
            @mkdir($dir, 0755, true);
782
        }
783
 
784
        return @rename($local, $remote);
17002 efrain 785
    }
786
 
787
 
788
    /**
789
     *
790
     * @param string $filename
791
 
792
     * @return boolean
793
     */
794
    public function deleteObject($filename)
795
    {
17018 efrain 796
        return @unlink($filename);
17002 efrain 797
    }
798
 
799
 
800
    /**
801
     *
802
     * @param string $path
803
     * @param string $code
804
     * @param string $filename
805
     * @return boolean
806
     */
807
    public function deleteFile($path, $code, $filename)
808
    {
809
        if($code) {
17018 efrain 810
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
17002 efrain 811
        } else {
17018 efrain 812
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $filename;
17002 efrain 813
        }
17018 efrain 814
        if(file_exists($remoto)) {
815
            return @unlink($remoto);
17002 efrain 816
        } else {
817
            return true;
818
        }
819
    }
820
 
821
    /**
822
     *
823
     * @param string $path
824
     * @param string $code
825
     * @return boolean
826
     */
17018 efrain 827
    public function deleteDirectory($path, $code)
17002 efrain 828
    {
17018 efrain 829
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .  $path . DIRECTORY_SEPARATOR . $code;
830
        if(file_exists($remoto)) {
831
            $this->deleteDirectoryRecursive($remoto);
832
            return true;
833
        } else {
834
            return true;
835
        }
836
    }
837
 
838
    /**
839
     *
840
     * @param string $dir
841
     */
842
    private function deleteDirectoryRecursive($dir) {
843
        if (is_dir($dir)) {
844
            $objects = scandir($dir);
845
            foreach ($objects as $object) {
846
                if ($object != ''.'' && $object != '..') {
847
                    if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir.'/'.$object)) {
848
                        @rmdir($dir. DIRECTORY_SEPARATOR .$object);
849
                    }  else {
850
                        @unlink($dir. DIRECTORY_SEPARATOR .$object);
851
                    }
852
                }
853
            }
854
            @rmdir($dir);
855
        }
856
    }
857
 
858
 
859
 
860
    /**
861
     *
862
     * @param string $path
863
     * @param string $code
864
     * @param string $local_filename
865
     * @return boolean
866
     */
867
    public function putFile($path, $code, $local_filename)
868
    {
17002 efrain 869
        if($code) {
17018 efrain 870
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $code . DIRECTORY_SEPARATOR . basename($local_filename);
17002 efrain 871
        } else {
17018 efrain 872
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path  . DIRECTORY_SEPARATOR .  basename($local_filename);
17002 efrain 873
        }
17018 efrain 874
 
875
        $dir = dirname($remote);
876
        if(!file_exists($dir)) {
877
            @mkdir($dir, 0755, true);
878
        }
17002 efrain 879
 
880
 
17018 efrain 881
        return @rename($local_filename, $remote);
882
 
17002 efrain 883
    }
884
 
17018 efrain 885
 
17002 efrain 886
    /**
887
     *
17018 efrain 888
     * @param string $tempfile
17002 efrain 889
     * @param string $path
890
     * @param string $code
891
     * @param string $filename
892
     * @return boolean
893
     */
17018 efrain 894
    public function moveAndPutFile($tempfile, $path, $code, $filename)
17002 efrain 895
    {
896
        if($code) {
17018 efrain 897
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
17002 efrain 898
        } else {
17018 efrain 899
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $filename;
17002 efrain 900
        }
901
 
17018 efrain 902
 
903
        $dir = dirname($target_file);
904
        if(!file_exists($dir)) {
905
            @mkdir($dir, 0755, true);
906
        }
907
 
908
        return move_uploaded_file($tempfile, $target_file);
909
    }
910
 
911
    /**
912
     *
913
     * @return string
914
     */
915
    public function getStoagePath()
916
    {
917
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
918
    }
919
 
920
    /**
921
     *
922
     * @return string
923
     */
924
    public function getTempPath() {
925
        $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
926
        if(!file_exists($interal_path)) {
927
            mkdir($interal_path, 0775);
928
        }
17002 efrain 929
 
17018 efrain 930
        return $interal_path;
17002 efrain 931
 
932
    }
933
 
934
    /**
935
     *
17018 efrain 936
     * @param string $url
17002 efrain 937
     * @return string
938
     */
17018 efrain 939
    public function getPresignedUrl($url)
17002 efrain 940
    {
17018 efrain 941
 
942
 
943
 
944
        $code = hash('sha256', $url);
945
 
946
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
947
        $storageFile = $storageFileMapper->fetchOneByCode($code);
948
        if(!$storageFile) {
949
            $storageFile = new \LeadersLinked\Model\StorageFile();
950
            $storageFile->code = $code;
951
            $storageFile->path = $url;
952
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
953
 
954
 
955
 
956
            $storageFileMapper->insert($storageFile);
957
 
958
        }
959
 
960
        /*
961
        $hostname = empty($_SERVER['HTTP_ORIGIN']) ? '' : $_SERVER['HTTP_ORIGIN'];
962
 
963
        if(empty($hostname)) {
964
 
965
            $hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
966
 
967
            if(empty($hostname)) {
968
                $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
969
 
970
            }
971
        }
972
 
973
        print_r($_SERVER);
974
 
975
 
976
        $hostname = trim(str_replace('http://', 'https://', $hostname));
977
        */
978
 
979
 
980
 
981
 
982
 
983
 
984
 
985
 
986
        return 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
987
 
17002 efrain 988
    }
989
 
17018 efrain 990
 
17002 efrain 991
 
992
 
993
 
994
 
995
 
996
}