Proyectos de Subversion LeadersLinked - Services

Rev

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