Proyectos de Subversion LeadersLinked - Services

Rev

Rev 333 | Rev 345 | 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
 
334 www 38
    const BASE_PATH = 'data' . DIRECTORY_SEPARATOR . 'storage';
333 www 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) {
334 www 96
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $user->image;
333 www 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) {
334 www 116
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
333 www 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) {
334 www 137
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->image;
333 www 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) {
334 www 158
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->cover;
333 www 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) {
334 www 178
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->image;
333 www 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) {
334 www 199
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
333 www 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) {
334 www 219
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->cover;
333 www 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) {
334 www 239
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR . $group->image;
333 www 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) {
334 www 260
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
333 www 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) {
334 www 280
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR .  $group->cover;
333 www 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
    {
334 www 299
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $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
     */
334 www 320
    public function checkDirectory($path, $code)
321
    {
322
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code;
323
 
324
 
325
        if(file_exists( $directory)) {
326
            return true;
327
        } else {
328
            return @mkdir($directory, 0755, true);
329
        }
330
 
331
    }
332
 
333
 
334
    /**
335
     *
336
     * @param string $path
337
     * @param string $code,
338
     * @param string $filename
339
     * @return string
340
     */
341
    public function getFileFromDisk($path, $code, $filename)
342
    {
343
        $current_file = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
344
 
345
        if(file_exists($current_file)) {
346
            return $current_file;
347
        }
348
        return;
349
    }
350
 
351
    /**
352
     *
353
     * @param string $path
354
     * @param string $code,
355
     * @return string
356
     */
357
    public function getDirectoryFromDisk($path, $code)
358
    {
359
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code;
360
 
361
        if(file_exists($directory)) {
362
            return $directory;
363
        }
364
        return;
365
    }
366
 
367
 
368
 
369
 
370
    /**
371
     *
372
     * @param string $path
373
     * @param string $code,
374
     * @param string $filename
375
     * @param boolean $checkExists
376
     * @return string
377
     */
298 www 378
    public function getGenericFile($path, $code, $filename, $checkExists = true)
283 www 379
    {
334 www 380
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
298 www 381
 
333 www 382
 
298 www 383
        if($checkExists) {
333 www 384
            if(file_exists($remoto)) {
385
                return $this->getPresignedUrl($remoto);
298 www 386
 
387
            } else {
388
                return;
389
            }
390
        }
333 www 391
        return $this->getPresignedUrl($remoto);
283 www 392
    }
393
 
333 www 394
    public function getPathByType($type)
395
    {
396
        switch($type)
397
        {
398
            case TYPE_CHAT :
399
                return $this->getPathChat();
400
 
401
            case TYPE_GROUP :
402
                return $this->getPathGroup();
403
 
404
            case TYPE_USER :
405
                return $this->getPathUser();
406
 
407
            case TYPE_IMAGE :
408
                return $this->getPathImage();
409
 
410
            case TYPE_JOB :
411
                return $this->getPathJob();
412
 
413
            case TYPE_COMPANY :
414
                return $this->getPathCompany();
415
 
416
            case TYPE_FEED :
417
                return $this->getPathFeed();
418
 
419
            case TYPE_POST :
420
                return $this->getPathPost();
421
 
422
            case TYPE_MICROLEARNING_TOPIC  :
423
                return $this->getPathMicrolearningTopic();
424
 
425
            case TYPE_MICROLEARNING_CAPSULE :
426
                return $this->getPathMicrolearningCapsule();
427
 
428
            case TYPE_MICROLEARNING_SLIDE  :
429
                return $this->getPathMicrolearningSlide();
430
 
431
            case TYPE_JOB_DESCRIPTION :
432
                return $this->getPathJobDescription();
433
 
434
            case TYPE_SELF_EVALUATION  :
435
                return $this->getPathSelfEvaluation();
436
 
437
            case TYPE_PERFORMANCE_EVALUATION  :
438
                return $this->getPathPerformanceEvaluation();
439
 
440
            case TYPE_RECRUITMENT_SELECTION  :
441
                return $this->getPathRecruitmentSelection();
442
 
443
            case TYPE_PLANNING_OBJECTIVES_AND_GOALS :
444
                return $this->getPathPlanningObjectivesAnGoals();
445
 
446
 
447
            case TYPE_MESSAGE  :
448
                return $this->getPathMessage();
449
 
450
            case TYPE_SURVEY   :
451
                return $this->getPathSurvey();
452
 
453
            case TYPE_NETWORK   :
454
                return $this->getPathNetwork();
455
 
456
            case TYPE_DAILY_PULSE :
457
                return $this->getPathDailyPulse();
458
 
459
            case TYPE_ENGAGEMENT_REWARD  :
460
                return $this->getPathEngagementReward();
461
 
462
            case TYPE_KNOWLEDGE_AREA :
463
                return $this->getPathKnowledgeArea();
464
 
465
            case TYPE_MY_COACH :
466
                return $this->getPathMyCoach();
467
 
468
            case TYPE_HABIT_EMOJI  :
469
                return $this->getPathHabitEmoji();
470
 
471
            case TYPE_HABIT_CONTENT :
472
                return $this->getPathHabitContent();
473
 
474
            default :
334 www 475
                return DIRECTORY_SEPARATOR;
333 www 476
        }
477
 
478
 
479
    }
480
 
320 www 481
    /**
482
     *
333 www 483
     * @param Group $group
484
     * @return string
485
     */
486
    public function getGenericImageByType($type, $code, $filename)
487
    {
488
        $path = $this->getPathByType($type);
334 www 489
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
333 www 490
 
491
        if(file_exists($remoto)) {
492
            return $this->getPresignedUrl($remoto);
493
 
494
        } else {
495
            $remoto = $this->config['leaderslinked.images_default.no_image'];
496
            return $this->getPresignedUrl($remoto);
497
 
498
        }
499
    }
500
 
501
    /**
502
     *
503
     * @param string $type
504
     * @param string $code,
505
     * @param string $filename
506
     * @param boolean $checkExists
507
     * @return string
508
     */
509
    public function getGenericFileByType($type, $code, $filename, $checkExists = true)
510
    {
511
        $path = $this->getPathByType($type);
334 www 512
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
333 www 513
 
514
        if($checkExists) {
515
            if(file_exists($remoto)) {
516
                return $this->getPresignedUrl($remoto);
517
 
518
            } else {
519
                return;
520
            }
521
        }
522
        return $this->getPresignedUrl($remoto);
523
    }
524
 
525
    /**
526
     *
320 www 527
     * @param string $path
528
     * @param string $code
529
     * @param string $filename
530
     * @return string
531
     */
532
    public function delete($path, $code, $filename)
533
    {
334 www 534
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
333 www 535
        return @unlink($remoto);
536
 
320 www 537
 
538
    }
539
 
295 www 540
 
541
 
302 www 542
    /**
543
     *
544
     * @return string
545
     */
546
    public function getPathMedia()
547
    {
333 www 548
        return $this->config['leaderslinked.storage.fullpath_media'];
302 www 549
    }
295 www 550
 
551
 
283 www 552
    /**
324 www 553
     *
554
     * @return string
555
     */
556
    public function getPathHabitEmoji()
557
    {
333 www 558
        return $this->config['leaderslinked.storage.fullpath_habit_emoji'];
324 www 559
    }
560
 
561
    /**
562
     *
563
     * @return string
564
     */
565
    public function getPathHabitContent()
566
    {
333 www 567
        return $this->config['leaderslinked.storage.fullpath_habit_content'];
324 www 568
    }
569
 
570
 
571
    /**
283 www 572
     *
573
     * @return string
574
     */
575
    public function getPathGroup()
576
    {
333 www 577
        return $this->config['leaderslinked.storage.fullpath_group'];
283 www 578
    }
579
 
580
    /**
581
     *
582
     * @return string
583
     */
584
    public function getPathUser()
585
    {
333 www 586
        return $this->config['leaderslinked.storage.fullpath_user'];
283 www 587
    }
588
 
589
    /**
590
     *
591
     * @return string
592
     */
593
    public function getPathImage()
594
    {
333 www 595
        return $this->config['leaderslinked.storage.fullpath_image'];
283 www 596
    }
597
 
598
    /**
599
     *
600
     * @return string
601
     */
602
    public function getPathJob()
603
    {
333 www 604
        return $this->config['leaderslinked.storage.fullpath_job'];
283 www 605
    }
606
 
607
    /**
608
     *
609
     * @return string
610
     */
333 www 611
    public function getPathChat()
612
    {
613
        return $this->config['leaderslinked.storage.fullpath_chat'];
614
    }
615
 
616
    /**
617
     *
618
     * @return string
619
     */
283 www 620
    public function getPathCompany()
621
    {
333 www 622
        return $this->config['leaderslinked.storage.fullpath_company'];
283 www 623
    }
624
 
625
    /**
626
     *
627
     * @return string
628
     */
629
    public function getPathFeed()
630
    {
333 www 631
        return $this->config['leaderslinked.storage.fullpath_feed'];
283 www 632
    }
633
 
295 www 634
 
635
 
283 www 636
    /**
637
     *
638
     * @return string
639
     */
295 www 640
    public function getPathMessage()
641
    {
333 www 642
        return $this->config['leaderslinked.storage.fullpath_message'];
295 www 643
    }
644
 
645
    /**
646
     *
647
     * @return string
648
     */
283 www 649
    public function getPathPost()
650
    {
333 www 651
        return $this->config['leaderslinked.storage.fullpath_post'];
283 www 652
    }
653
 
654
    /**
655
     *
656
     * @return string
657
     */
658
    public function getPathMicrolearningTopic()
659
    {
333 www 660
        return $this->config['leaderslinked.storage.fullpath_microlearning_topic'];
283 www 661
    }
662
 
663
    /**
664
     *
665
     * @return string
666
     */
667
    public function getPathMicrolearningCapsule()
668
    {
333 www 669
        return $this->config['leaderslinked.storage.fullpath_microlearning_capsule'];
283 www 670
    }
671
 
672
    /**
673
     *
674
     * @return string
675
     */
676
    public function getPathMicrolearningSlide()
677
    {
333 www 678
        return $this->config['leaderslinked.storage.fullpath_microlearning_slide'];
283 www 679
    }
680
 
681
    /**
682
     *
683
     * @return string
684
     */
685
    public function getPathJobDescription()
686
    {
333 www 687
        return $this->config['leaderslinked.storage.fullpath_job_description'];
283 www 688
    }
689
 
690
    /**
691
     *
692
     * @return string
693
     */
295 www 694
    public function getPathSelfEvaluation()
283 www 695
    {
333 www 696
        return $this->config['leaderslinked.storage.fullpath_self_evaluation'];
283 www 697
    }
698
 
699
    /**
700
     *
701
     * @return string
702
     */
703
    public function getPathRecruitmentSelection()
704
    {
333 www 705
        return $this->config['leaderslinked.storage.fullpath_recruitment_selection'];
283 www 706
    }
707
 
708
    /**
709
     *
710
     * @return string
711
     */
712
    public function getPathPerformanceEvaluation()
713
    {
333 www 714
        return $this->config['leaderslinked.storage.fullpath_performance_evaluation'];
283 www 715
    }
716
 
717
    /**
718
     *
719
     * @return string
720
     */
721
    public function getPathPlanningObjectivesAnGoals()
722
    {
333 www 723
        return $this->config['leaderslinked.storage.fullpath_planning_objectives_and_goals'];
283 www 724
    }
725
 
726
    /**
727
     *
728
     * @return string
729
     */
730
    public function getPathSurvey()
731
    {
333 www 732
        return $this->config['leaderslinked.storage.fullpath_survey'];
283 www 733
    }
734
 
735
    /**
736
     *
737
     * @return string
738
     */
739
    public function getPathNetwork()
740
    {
333 www 741
        return $this->config['leaderslinked.storage.fullpath_network'];
283 www 742
    }
743
 
744
    /**
745
     *
746
     * @return string
747
     */
748
    public function getPathEngagementReward()
749
    {
333 www 750
        return $this->config['leaderslinked.storage.fullpath_engagement_reward'];
283 www 751
    }
752
 
753
    /**
754
     *
755
     * @return string
756
     */
757
    public function getPathDailyPulse()
758
    {
333 www 759
        return $this->config['leaderslinked.storage.fullpath_daily_pulse'];
283 www 760
    }
761
 
762
    /**
763
     *
764
     * @return string
765
     */
766
    public function getPathKnowledgeArea()
767
    {
333 www 768
        return $this->config['leaderslinked.storage.fullpath_knowledge_area'];
283 www 769
    }
770
 
771
    /**
772
     *
773
     * @return string
774
     */
775
    public function getPathMyCoach()
776
    {
333 www 777
        return $this->config['leaderslinked.storage.fullpath_my_coach'];
283 www 778
    }
779
 
780
    /**
781
     *
782
     * @param String $filename
783
     * return boolean
784
     */
785
    public function objectExist($filename)
786
    {
333 www 787
        return file_exists($filename);
283 www 788
    }
789
 
790
    /**
791
     *
302 www 792
     * @param string $remote
793
     * @param string $local
283 www 794
     * @return boolean
795
     */
302 www 796
    public function putObject($remote, $local)
283 www 797
    {
334 www 798
 
799
        $dir = dirname($remote);
800
        if(!file_exists($dir)) {
801
            @mkdir($dir, 0755, true);
802
        }
803
 
333 www 804
        return @rename($local, $remote);
283 www 805
    }
806
 
807
 
808
    /**
809
     *
810
     * @param string $filename
811
 
812
     * @return boolean
813
     */
814
    public function deleteObject($filename)
815
    {
333 www 816
        return @unlink($filename);
283 www 817
    }
818
 
819
 
820
    /**
821
     *
822
     * @param string $path
823
     * @param string $code
824
     * @param string $filename
825
     * @return boolean
826
     */
827
    public function deleteFile($path, $code, $filename)
828
    {
829
        if($code) {
334 www 830
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
283 www 831
        } else {
334 www 832
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $filename;
283 www 833
        }
333 www 834
        if(file_exists($remoto)) {
835
            return @unlink($remoto);
283 www 836
        } else {
837
            return true;
838
        }
839
    }
295 www 840
 
841
    /**
842
     *
843
     * @param string $path
844
     * @param string $code
845
     * @return boolean
846
     */
847
    public function deleteDirectory($path, $code)
848
    {
334 www 849
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .  $path . DIRECTORY_SEPARATOR . $code;
333 www 850
        if(file_exists($remoto)) {
334 www 851
            $this->deleteDirectoryRecursive($remoto);
852
            return true;
295 www 853
        } else {
854
            return true;
855
        }
856
    }
857
 
334 www 858
    /**
859
     *
860
     * @param string $dir
861
     */
862
    private function deleteDirectoryRecursive($dir) {
863
        if (is_dir($dir)) {
864
            $objects = scandir($dir);
865
            foreach ($objects as $object) {
866
                if ($object != ''.'' && $object != '..') {
867
                    if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir.'/'.$object)) {
868
                        @rmdir($dir. DIRECTORY_SEPARATOR .$object);
869
                    }  else {
870
                        @unlink($dir. DIRECTORY_SEPARATOR .$object);
871
                    }
872
                }
873
            }
874
            @rmdir($dir);
875
        }
876
    }
877
 
283 www 878
 
879
 
880
    /**
881
     *
882
     * @param string $path
883
     * @param string $code
290 www 884
     * @param string $local_filename
283 www 885
     * @return boolean
886
     */
290 www 887
    public function putFile($path, $code, $local_filename)
283 www 888
    {
889
        if($code) {
334 www 890
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $code . DIRECTORY_SEPARATOR . basename($local_filename);
283 www 891
        } else {
334 www 892
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path  . DIRECTORY_SEPARATOR .  basename($local_filename);
283 www 893
        }
334 www 894
 
895
        $dir = dirname($remote);
896
        if(!file_exists($dir)) {
897
            @mkdir($dir, 0755, true);
898
        }
283 www 899
 
290 www 900
 
333 www 901
        return @rename($local_filename, $remote);
902
 
283 www 903
    }
904
 
905
 
906
    /**
907
     *
334 www 908
     * @param string $tempfile
283 www 909
     * @param string $path
910
     * @param string $code
911
     * @param string $filename
912
     * @return boolean
913
     */
334 www 914
    public function moveAndPutFile($tempfile, $path, $code, $filename)
283 www 915
    {
916
        if($code) {
334 www 917
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
283 www 918
        } else {
334 www 919
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $filename;
283 www 920
        }
334 www 921
 
922
 
923
        $dir = dirname($target_file);
924
        if(!file_exists($dir)) {
925
            @mkdir($dir, 0755, true);
926
        }
333 www 927
 
334 www 928
        return move_uploaded_file($tempfile, $target_file);
283 www 929
    }
930
 
931
    /**
932
     *
933
     * @return string
934
     */
334 www 935
    public function getStoagePath()
283 www 936
    {
937
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
938
    }
939
 
333 www 940
    /**
941
     *
334 www 942
     * @return string
943
     */
944
    public function getTempPath() {
945
        $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
946
        if(!file_exists($interal_path)) {
947
            mkdir($interal_path, 0775);
948
        }
949
 
950
        return $interal_path;
951
 
952
    }
953
 
954
    /**
955
     *
333 www 956
     * @param string $url
957
     * @return string
958
     */
959
    public function getPresignedUrl($url)
960
    {
961
 
962
 
963
 
964
        $code = hash('sha256', $url);
965
 
966
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
967
        $storageFile = $storageFileMapper->fetchOneByCode($code);
968
        if(!$storageFile) {
969
            $storageFile = new \LeadersLinked\Model\StorageFile();
970
            $storageFile->code = $code;
971
            $storageFile->path = $url;
972
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
973
 
974
 
975
 
976
            $storageFileMapper->insert($storageFile);
977
 
978
        }
979
 
980
        /*
981
        $hostname = empty($_SERVER['HTTP_ORIGIN']) ? '' : $_SERVER['HTTP_ORIGIN'];
982
 
983
        if(empty($hostname)) {
984
 
985
            $hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
986
 
987
            if(empty($hostname)) {
988
                $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
989
 
990
            }
991
        }
992
 
993
        print_r($_SERVER);
994
 
995
 
996
        $hostname = trim(str_replace('http://', 'https://', $hostname));
997
        */
998
 
999
 
1000
 
1001
 
1002
 
1003
 
1004
 
1005
 
1006
        return 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
1007
 
1008
    }
283 www 1009
 
334 www 1010
 
283 www 1011
 
1012
 
1013
 
1014
 
333 www 1015
 
283 www 1016
}