Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17012 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17012 Rev 17018
Línea 6... Línea 6...
6
use LeadersLinked\Model\Company;
6
use LeadersLinked\Model\Company;
7
use LeadersLinked\Model\Group;
7
use LeadersLinked\Model\Group;
Línea 8... Línea 8...
8
 
8
 
9
class Storage 
9
class Storage 
-
 
10
{
-
 
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
    
10
{
40
    
11
    /**
41
    /**
12
     * 
42
     * 
13
     * @var\LeadersLinked\Library\Storage 
43
     * @var\LeadersLinked\Library\Storage 
14
     */
44
     */
Línea 18... Línea 48...
18
     * 
48
     * 
19
     * @var array
49
     * @var array
20
     */
50
     */
21
    private $config;
51
    private $config;
Línea 22... Línea -...
22
    
-
 
23
    
52
    
24
    /**
53
    /**
25
     * 
54
     * 
26
     * @var S3Files
55
     * @var \Laminas\Db\Adapter\AdapterInterface 
27
     */
56
     */
-
 
57
    private $adapter;
-
 
58
    
-
 
59
    
Línea 28... Línea 60...
28
    private $s3Files;
60
 
29
    
61
    
30
    /**
62
    /**
-
 
63
     * 
31
     * 
64
     * @param array $config
32
     * @param array $config
65
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
33
     */
66
     */
34
    private function __construct($config) 
67
    private function __construct($config, $adapter) 
35
    {
68
    {
36
        $this->config = $config;
69
        $this->config       = $config;
Línea 37... Línea 70...
37
        $this->s3Files = S3Files::getInstance($this->config);
70
        $this->adapter      = $adapter;
38
    }
71
    }
39
    
72
    
-
 
73
    /**
40
    /**
74
     * 
41
     * 
75
     * @param array $config
42
     * @param array $config
76
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
43
     * @return \LeadersLinked\Library\Storage
77
     * @return \LeadersLinked\Library\Storage
44
     */
78
     */
45
    public static function getInstance($config)
79
    public static function getInstance($config, $adapter)
46
    {
80
    {
Línea 47... Línea 81...
47
        if(self::$_instance == null) {
81
        if(self::$_instance == null) {
48
            self::$_instance = new Storage($config);
82
            self::$_instance = new Storage($config, $adapter);
Línea 57... Línea 91...
57
     * @return string
91
     * @return string
58
     */
92
     */
59
    public function getUserImage($user)
93
    public function getUserImage($user)
60
    {
94
    {
61
        if($user->image) {
95
        if($user->image) {
62
            $remoto = $this->getPathUser() . '/' . $user->uuid . '/' .  $user->image;
96
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $user->image;
63
            if($this->s3Files->objectExist($remoto)) {
97
            if(file_exists($remoto)) {
64
                return $this->s3Files->getPresignedUrl($remoto);
98
                return $this->getPresignedUrl($remoto);
-
 
99
                
65
            }
100
            }
66
        }
101
        }
Línea 67... Línea 102...
67
        
102
        
68
        $remoto = $this->config['leaderslinked.images_default.user_image'];
103
        $remoto = $this->config['leaderslinked.images_default.user_image'];
69
        return $this->s3Files->getPresignedUrl($remoto);
104
        return $this->getPresignedUrl($remoto);
Línea 70... Línea 105...
70
    }
105
    }
71
    
106
    
Línea 76... Línea 111...
76
     * @return string
111
     * @return string
77
     */
112
     */
78
    public function getUserImageForCodeAndFilename($code, $filename)
113
    public function getUserImageForCodeAndFilename($code, $filename)
79
    {
114
    {
80
        if($filename) {
115
        if($filename) {
81
            $remoto = $this->getPathUser() . '/' . $code . '/' .  $filename;
116
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
82
            if($this->s3Files->objectExist($remoto)) {
117
            if(file_exists($remoto)) {
83
                return $this->s3Files->getPresignedUrl($remoto);
118
                return $this->getPresignedUrl($remoto);
-
 
119
                
84
            }
120
            }
85
        }
121
        }
Línea 86... Línea 122...
86
        
122
        
87
        $remoto = $this->config['leaderslinked.images_default.user_image'];
123
        $remoto = $this->config['leaderslinked.images_default.user_image'];
-
 
124
        return $this->getPresignedUrl($remoto);
88
        return $this->s3Files->getPresignedUrl($remoto);
125
        
Línea 89... Línea 126...
89
    }
126
    }
90
    
127
    
91
    /**
128
    /**
Línea 95... Línea 132...
95
     * @return string
132
     * @return string
96
     */
133
     */
97
    public function getUserProfileImage($user, $userProfile)
134
    public function getUserProfileImage($user, $userProfile)
98
    {
135
    {
99
        if($userProfile->image) {
136
        if($userProfile->image) {
100
            $remoto = $this->getPathUser() . '/' . $user->uuid . '/' .  $userProfile->image;
137
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->image;
101
            if($this->s3Files->objectExist($remoto)) {
138
            if(file_exists($remoto)) {
102
                return $this->s3Files->getPresignedUrl($remoto);
139
                return $this->getPresignedUrl($remoto);
-
 
140
                
103
            }
141
            }
104
        }
142
        }
Línea 105... Línea 143...
105
        
143
        
106
        $remoto = $this->config['leaderslinked.images_default.user_profile'];
144
        $remoto = $this->config['leaderslinked.images_default.user_profile'];
-
 
145
        return $this->getPresignedUrl($remoto);
107
        return $this->s3Files->getPresignedUrl($remoto);
146
        
Línea 108... Línea 147...
108
    }
147
    }
109
    
148
    
110
    /**
149
    /**
Línea 114... Línea 153...
114
     * @return string
153
     * @return string
115
     */
154
     */
116
    public function getUserProfileCover($user, $userProfile)
155
    public function getUserProfileCover($user, $userProfile)
117
    {
156
    {
118
        if($userProfile->cover) {
157
        if($userProfile->cover) {
119
            $remoto = $this->getPathUser() . '/' . $user->uuid . '/' .  $userProfile->cover;
158
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->cover;
120
            if($this->s3Files->objectExist($remoto)) {
159
            if(file_exists($remoto)) {
121
                return $this->s3Files->getPresignedUrl($remoto);
160
                return $this->getPresignedUrl($remoto);
-
 
161
                
122
            }
162
            }
123
        }
163
        }
Línea 124... Línea 164...
124
        
164
        
125
        $remoto = $this->config['leaderslinked.images_default.user_cover'];
165
        $remoto = $this->config['leaderslinked.images_default.user_cover'];
-
 
166
        return $this->getPresignedUrl($remoto);
126
        return $this->s3Files->getPresignedUrl($remoto);
167
        
Línea 127... Línea 168...
127
    }
168
    }
128
    
169
    
129
    /**
170
    /**
130
     *
171
     *
131
     * @param Company $company
172
     * @param Company $company
132
     * @return string
173
     * @return string
133
     */
174
     */
134
    public function getCompanyImage($company)
175
    public function getCompanyImage($company)
135
    {
176
    {
136
        if($company->image) {
177
        if($company->image) {
137
            $remoto = $this->getPathCompany() . '/' . $company->uuid . '/' .  $company->image;
178
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->image;
-
 
179
            if(file_exists($remoto)) {
138
            if($this->s3Files->objectExist($remoto)) {
180
                return $this->getPresignedUrl($remoto);
139
                return $this->s3Files->getPresignedUrl($remoto);
181
                
Línea 140... Línea 182...
140
            }
182
            }
141
        }
183
        }
-
 
184
        
142
        
185
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
Línea 143... Línea 186...
143
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
186
        return $this->getPresignedUrl($remoto);
144
        return $this->s3Files->getPresignedUrl($remoto);
187
        
145
    }
188
    }
Línea 151... Línea 194...
151
     * @return string
194
     * @return string
152
     */
195
     */
153
    public function getCompanyImageForCodeAndFilename($code, $filename)
196
    public function getCompanyImageForCodeAndFilename($code, $filename)
154
    {
197
    {
155
        if($filename) {
198
        if($filename) {
156
            $remoto = $this->getPathCompany() . '/' . $code . '/' .  $filename;
199
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
157
            if($this->s3Files->objectExist($remoto)) {
200
            if(file_exists($remoto)) {
158
                return $this->s3Files->getPresignedUrl($remoto);
201
                return $this->getPresignedUrl($remoto);
-
 
202
                
159
            }
203
            }
160
        }
204
        }
Línea 161... Línea 205...
161
        
205
        
162
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
206
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
-
 
207
        return $this->getPresignedUrl($remoto);
163
        return $this->s3Files->getPresignedUrl($remoto);
208
        
Línea 164... Línea 209...
164
    }
209
    }
165
    
210
    
166
    /**
211
    /**
167
     *
212
     *
168
     * @param Company $company
213
     * @param Company $company
169
     * @return string
214
     * @return string
170
     */
215
     */
171
    public function getCompanyCover($company)
216
    public function getCompanyCover($company)
172
    {
217
    {
173
        if($company->cover) {
218
        if($company->cover) {
174
            $remoto = $this->getPathCompany() . '/' . $company->uuid . '/' .  $company->cover;
219
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->cover;
-
 
220
            if(file_exists($remoto)) {
175
            if($this->s3Files->objectExist($remoto)) {
221
                return $this->getPresignedUrl($remoto);
176
                return $this->s3Files->getPresignedUrl($remoto);
222
                
Línea 177... Línea 223...
177
            }
223
            }
178
        }
224
        }
-
 
225
        
179
        
226
        $remoto = $this->config['leaderslinked.images_default.company_cover'];
Línea 180... Línea 227...
180
        $remoto = $this->config['leaderslinked.images_default.company_cover'];
227
        return $this->getPresignedUrl($remoto);
181
        return $this->s3Files->getPresignedUrl($remoto);
228
        
182
    }
229
    }
183
    
230
    
184
    /**
231
    /**
185
     *
232
     *
186
     * @param Group $group
233
     * @param Group $group
187
     * @return string
234
     * @return string
188
     */
235
     */
189
    public function getGroupImage($group)
236
    public function getGroupImage($group)
190
    {
237
    {
-
 
238
        if($group->image) {
191
        if($group->image) {
239
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR . $group->image;
192
            $remoto = $this->getPathGroup() . '/' . $group->uuid . '/' .  $group->image;
240
            if(file_exists($remoto)) {
Línea 193... Línea 241...
193
            if($this->s3Files->objectExist($remoto)) {
241
                return $this->getPresignedUrl($remoto);
194
                return $this->s3Files->getPresignedUrl($remoto);
242
                
-
 
243
            }
195
            }
244
        }
Línea 196... Línea 245...
196
        }
245
        
197
        
246
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
198
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
247
        return $this->getPresignedUrl($remoto);
Línea 206... Línea 255...
206
     * @return string
255
     * @return string
207
     */
256
     */
208
    public function getGroupImageForCodeAndFilename($code, $filename)
257
    public function getGroupImageForCodeAndFilename($code, $filename)
209
    {
258
    {
210
        if($filename) {
259
        if($filename) {
211
            $remoto = $this->getPathGroup() . '/' . $code . '/' .  $filename;
260
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
212
            if($this->s3Files->objectExist($remoto)) {
261
            if(file_exists($remoto)) {
213
                return $this->s3Files->getPresignedUrl($remoto);
262
                return $this->getPresignedUrl($remoto);
-
 
263
                
214
            }
264
            }
215
        }
265
        }
Línea 216... Línea 266...
216
        
266
        
217
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
267
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
-
 
268
        return $this->getPresignedUrl($remoto);
218
        return $this->s3Files->getPresignedUrl($remoto);
269
        
Línea 219... Línea 270...
219
    }
270
    }
220
    
271
    
221
    /**
272
    /**
222
     *
273
     *
223
     * @param Group $group
274
     * @param Group $group
224
     * @return string
275
     * @return string
225
     */
276
     */
226
    public function getGroupCover($group)
277
    public function getGroupCover($group)
227
    {
278
    {
228
        if($group->cover) {
279
        if($group->cover) {
229
            $remoto = $this->getPathGroup() . '/' . $group->uuid . '/' .  $group->cover;
280
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR .  $group->cover;
-
 
281
            if(file_exists($remoto)) {
230
            if($this->s3Files->objectExist($remoto)) {
282
                return $this->getPresignedUrl($remoto);
231
                return $this->s3Files->getPresignedUrl($remoto);
283
                
Línea 232... Línea 284...
232
            }
284
            }
233
        }
285
        }
-
 
286
        
234
        
287
        $remoto = $this->config['leaderslinked.images_default.group_cover'];
Línea 235... Línea 288...
235
        $remoto = $this->config['leaderslinked.images_default.group_cover'];
288
        return $this->getPresignedUrl($remoto);
236
        return $this->s3Files->getPresignedUrl($remoto);
289
        
237
    }
290
    }
238
    
291
    
239
    /**
292
    /**
240
     *
293
     *
241
     * @param Group $group
294
     * @param Group $group
242
     * @return string
295
     * @return string
-
 
296
     */
-
 
297
    public function getGenericImage($path, $code, $filename)
243
     */
298
    {
244
    public function getGenericImage($path, $code, $filename)
299
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
-
 
300
        
245
    {
301
  
246
        $remoto = $path . '/' . $code. '/' .  $filename;
302
        if(file_exists($remoto)) {
247
        if($this->s3Files->objectExist($remoto)) {
303
            return $this->getPresignedUrl($remoto);
-
 
304
            
-
 
305
        } else {
-
 
306
            $remoto = $this->config['leaderslinked.images_default.no_image'];
-
 
307
            return $this->getPresignedUrl($remoto);
-
 
308
            
-
 
309
        }
-
 
310
    }
-
 
311
    
-
 
312
    
-
 
313
    
-
 
314
    
-
 
315
    /**
-
 
316
     *
-
 
317
     * @param string $path
-
 
318
     * @param string $code,
-
 
319
     * @param string $filename
-
 
320
     * @param boolean $checkExists
-
 
321
     * @return string
-
 
322
     */
-
 
323
    public function getFileFromDisk($path, $code, $filename)
-
 
324
    {
-
 
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
    {
248
            return $this->s3Files->getPresignedUrl($remoto);
342
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code;
-
 
343
        
249
        } else {
344
        if(file_exists($directory)) {
Línea 250... Línea 345...
250
            $remoto = $this->config['leaderslinked.images_default.no_image'];
345
            return $directory;
251
            return $this->s3Files->getPresignedUrl($remoto);
346
        }
252
        }
347
        return;
253
    }
348
    }
254
    
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
       
255
    /**
459
    }
256
     *
460
    
257
     * @param string $path
461
    /**
258
     * @param string $code 
462
     *
259
     * @param string $filename
463
     * @param Group $group
-
 
464
     * @return string
-
 
465
     */
260
     * @return string
466
    public function getGenericImageByType($type, $code, $filename)
261
     */
467
    {
-
 
468
        $path = $this->getPathByType($type);
262
    public function getGenericFile($path, $code, $filename)
469
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
-
 
470
 
263
    {
471
        if(file_exists($remoto)) {
-
 
472
            return $this->getPresignedUrl($remoto);
264
        $remoto = $path . '/' . $code. '/' .  $filename;
473
            
265
        if($this->s3Files->objectExist($remoto)) {
474
        } else {
Línea -... Línea 475...
-
 
475
            $remoto = $this->config['leaderslinked.images_default.no_image'];
-
 
476
            return $this->getPresignedUrl($remoto);
-
 
477
            
-
 
478
        }
-
 
479
    }
-
 
480
    
-
 
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
                
Línea 266... Línea 498...
266
            return $this->s3Files->getPresignedUrl($remoto);
498
            } else {
267
        } else {
499
                return;
268
            return;
500
            }
269
        }
501
        }
270
    }
502
        return $this->getPresignedUrl($remoto);
271
    
503
    }
272
    
504
    
273
    /**
505
    /**
274
     *
506
     *
275
     * @param string $path
507
     * @param string $path
276
     * @param string $code
-
 
277
     * @param string $filename
-
 
278
     * @return string
-
 
279
     */
-
 
280
    public function delete($path, $code, $filename)
-
 
281
    {
508
     * @param string $code
282
        $remoto = $path . '/' . $code. '/' .  $filename;
509
     * @param string $filename
Línea 283... Línea 510...
283
        try {
510
     * @return string
Línea -... Línea 511...
-
 
511
     */
-
 
512
    public function delete($path, $code, $filename)
284
            $this->s3Files->deleteObject($remoto);
513
    {
285
            return true;
514
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
286
        } catch (\Exception $exception) {
515
        return @unlink($remoto);
287
            //echo "No se pudo borrar el archivo : $remoto (" . $exception->getMessage() . ")";
516
 
288
            return false;
517
        
289
        }
518
    }
290
        
519
    
-
 
520
  
-
 
521
    
-
 
522
    /**
-
 
523
     *
-
 
524
     * @return string
-
 
525
     */
-
 
526
    public function getPathMedia()
-
 
527
    {
-
 
528
        return $this->config['leaderslinked.storage.fullpath_media'];
-
 
529
    }
291
    }
530
    
Línea -... Línea 531...
-
 
531
    
-
 
532
    /**
-
 
533
     *
-
 
534
     * @return string
-
 
535
     */
-
 
536
    public function getPathHabitEmoji()
-
 
537
    {
-
 
538
        return $this->config['leaderslinked.storage.fullpath_habit_emoji'];
-
 
539
    }
Línea 292... Línea 540...
292
    
540
    
293
    /**
541
    /**
294
     *
542
     *
295
     * @return string
543
     * @return string
296
     */
544
     */
297
    public function getPathMedia()
545
    public function getPathHabitContent()
298
    {
546
    {
299
        return $this->config['leaderslinked.minio.fullpath_media'];
547
        return $this->config['leaderslinked.storage.fullpath_habit_content'];
Línea 300... Línea 548...
300
    }
548
    }
301
    
549
 
302
    
550
    
303
    /**
551
    /**
304
     * 
552
     * 
305
     * @return string
553
     * @return string
306
     */
554
     */
307
    public function getPathGroup()
555
    public function getPathGroup()
Línea 308... Línea 556...
308
    {
556
    {
309
        return $this->config['leaderslinked.minio.fullpath_group'];
557
        return $this->config['leaderslinked.storage.fullpath_group'];
310
    }
558
    }
311
    
559
    
312
    /**
560
    /**
313
     *
561
     *
314
     * @return string
562
     * @return string
315
     */
563
     */
Línea 316... Línea 564...
316
    public function getPathUser()
564
    public function getPathUser()
317
    {
565
    {
318
        return $this->config['leaderslinked.minio.fullpath_user'];
566
        return $this->config['leaderslinked.storage.fullpath_user'];
319
    }
567
    }
320
    
568
    
321
    /**
569
    /**
322
     *
570
     *
323
     * @return string
571
     * @return string
Línea 324... Línea 572...
324
     */
572
     */
325
    public function getPathImage()
573
    public function getPathImage()
326
    {
574
    {
327
        return $this->config['leaderslinked.minio.fullpath_image'];
575
        return $this->config['leaderslinked.storage.fullpath_image'];
328
    }
576
    }
329
    
577
    
330
    /**
578
    /**
331
     *
579
     *
Línea 332... Línea 580...
332
     * @return string
580
     * @return string
333
     */
581
     */
334
    public function getPathJob()
582
    public function getPathJob()
335
    {
583
    {
336
        return $this->config['leaderslinked.minio.fullpath_job'];
584
        return $this->config['leaderslinked.storage.fullpath_job'];
337
    }
585
    }
338
    
586
    
339
    /**
587
    /**
Línea 340... Línea 588...
340
     *
588
     *
341
     * @return string
589
     * @return string
342
     */
590
     */
343
    public function getPathCompany()
591
    public function getPathChat()
344
    {
592
    {
345
        return $this->config['leaderslinked.minio.fullpath_company'];
593
        return $this->config['leaderslinked.storage.fullpath_chat'];
346
    }
594
    }
347
    
595
    
Línea -... Línea 596...
-
 
596
    /**
-
 
597
     *
348
    /**
598
     * @return string
349
     *
599
     */
350
     * @return string
600
    public function getPathCompany()
351
     */
601
    {
352
    public function getPathFeed()
602
        return $this->config['leaderslinked.storage.fullpath_company'];
353
    {
603
    }
354
        return $this->config['leaderslinked.minio.fullpath_feed'];
604
    
355
    }
605
    /**
Línea 356... Línea 606...
356
    
606
     *
357
    /**
607
     * @return string
358
     *
608
     */
359
     * @return string
609
    public function getPathFeed()
360
     */
610
    {
361
    public function getPathPost()
611
        return $this->config['leaderslinked.storage.fullpath_feed'];
362
    {
612
    }
363
        return $this->config['leaderslinked.minio.fullpath_post'];
613
    
Línea 364... Línea 614...
364
    }
614
    
365
    
615
    
366
    /**
616
    /**
367
     *
617
     *
368
     * @return string
618
     * @return string
369
     */
619
     */
370
    public function getPathMicrolearningTopic()
620
    public function getPathMessage()
371
    {
621
    {
Línea 372... Línea 622...
372
        return $this->config['leaderslinked.minio.fullpath_microlearning_topic'];
622
        return $this->config['leaderslinked.storage.fullpath_message'];
373
    }
623
    }
374
    
624
    
375
    /**
625
    /**
376
     *
626
     *
377
     * @return string
627
     * @return string
378
     */
628
     */
379
    public function getPathMicrolearningCapsule()
629
    public function getPathPost()
Línea 380... Línea 630...
380
    {
630
    {
381
        return $this->config['leaderslinked.minio.fullpath_microlearning_capsule'];
631
        return $this->config['leaderslinked.storage.fullpath_post'];
382
    }
632
    }
383
    
633
    
384
    /**
634
    /**
385
     *
635
     *
386
     * @return string
636
     * @return string
387
     */
637
     */
Línea 388... Línea 638...
388
    public function getPathMicrolearningSlide()
638
    public function getPathMicrolearningTopic()
389
    {
639
    {
390
        return $this->config['leaderslinked.minio.fullpath_microlearning_slide'];
640
        return $this->config['leaderslinked.storage.fullpath_microlearning_topic'];
391
    }
641
    }
392
    
642
    
393
    /**
643
    /**
394
     *
644
     *
395
     * @return string
645
     * @return string
Línea 396... Línea 646...
396
     */
646
     */
397
    public function getPathJobDescription()
647
    public function getPathMicrolearningCapsule()
398
    {
648
    {
399
        return $this->config['leaderslinked.minio.fullpath_job_description'];
649
        return $this->config['leaderslinked.storage.fullpath_microlearning_capsule'];
400
    }
650
    }
401
    
651
    
402
    /**
652
    /**
403
     *
653
     *
Línea 404... Línea 654...
404
     * @return string
654
     * @return string
405
     */
655
     */
406
    public function getPathJhSelfEvaluation()
656
    public function getPathMicrolearningSlide()
407
    {
657
    {
408
        return $this->config['leaderslinked.minio.fullpath_self_evaluation'];
658
        return $this->config['leaderslinked.storage.fullpath_microlearning_slide'];
409
    }
659
    }
410
    
660
    
411
    /**
661
    /**
Línea 412... Línea 662...
412
     *
662
     *
413
     * @return string
663
     * @return string
414
     */
664
     */
415
    public function getPathRecruitmentSelection()
665
    public function getPathJobDescription()
416
    {
666
    {
417
        return $this->config['leaderslinked.minio.fullpath_recruitment_selection'];
667
        return $this->config['leaderslinked.storage.fullpath_job_description'];
418
    }
668
    }
419
    
669
    
Línea 420... Línea 670...
420
    /**
670
    /**
421
     *
671
     *
422
     * @return string
672
     * @return string
423
     */
673
     */
424
    public function getPathPerformanceEvaluation()
674
    public function getPathSelfEvaluation()
425
    {
675
    {
426
        return $this->config['leaderslinked.minio.fullpath_performance_evaluation'];
676
        return $this->config['leaderslinked.storage.fullpath_self_evaluation'];
427
    }
677
    }
Línea 428... Línea 678...
428
    
678
    
429
    /**
679
    /**
430
     *
680
     *
431
     * @return string
681
     * @return string
432
     */
682
     */
433
    public function getPathPlanningObjectivesAnGoals()
683
    public function getPathRecruitmentSelection()
434
    {
684
    {
435
        return $this->config['leaderslinked.minio.fullpath_planning_objectives_and_goals'];
685
        return $this->config['leaderslinked.storage.fullpath_recruitment_selection'];
Línea 436... Línea 686...
436
    }
686
    }
437
    
687
    
438
    /**
688
    /**
439
     *
689
     *
440
     * @return string
690
     * @return string
441
     */
691
     */
442
    public function getPathSurvey()
692
    public function getPathPerformanceEvaluation()
443
    {
693
    {
Línea 444... Línea 694...
444
        return $this->config['leaderslinked.minio.fullpath_survey'];
694
        return $this->config['leaderslinked.storage.fullpath_performance_evaluation'];
445
    }
695
    }
446
    
696
    
447
    /**
697
    /**
448
     *
698
     *
449
     * @return string
699
     * @return string
450
     */
700
     */
451
    public function getPathNetwork()
701
    public function getPathPlanningObjectivesAnGoals()
Línea 452... Línea 702...
452
    {
702
    {
453
        return $this->config['leaderslinked.minio.fullpath_network'];
703
        return $this->config['leaderslinked.storage.fullpath_planning_objectives_and_goals'];
454
    }
704
    }
455
    
705
    
456
    /**
706
    /**
457
     *
707
     *
458
     * @return string
708
     * @return string
459
     */
709
     */
Línea 460... Línea -...
460
    public function getPathEngagementReward()
-
 
461
    {
710
    public function getPathSurvey()
462
        return $this->config['leaderslinked.minio.fullpath_engagement_reward'];
711
    {
463
    }
712
        return $this->config['leaderslinked.storage.fullpath_survey'];
464
    
713
    }
465
    /**
714
    
466
     *
715
    /**
467
     * @return string
716
     *
468
     */
717
     * @return string
Línea 469... Línea 718...
469
    public function getPathDailyPulse()
718
     */
470
    {
719
    public function getPathNetwork()
471
        return $this->config['leaderslinked.minio.fullpath_daily_pulse'];
720
    {
472
    }
721
        return $this->config['leaderslinked.storage.fullpath_network'];
473
    
722
    }
474
    /**
723
    
475
     *
724
    /**
476
     * @return string
725
     *
Línea 477... Línea 726...
477
     */
726
     * @return string
478
    public function getPathHabitEmoji()
727
     */
479
    {
728
    public function getPathEngagementReward()
480
        return $this->config['leaderslinked.minio.fullpath_habit_emoji'];
729
    {
481
    }
730
        return $this->config['leaderslinked.storage.fullpath_engagement_reward'];
482
    
731
    }
483
    /**
732
    
484
     *
733
    /**
485
     * @return string
734
     *
Línea 486... Línea 735...
486
     */
735
     * @return string
487
    public function getPathHabitContent()
736
     */
488
    {
737
    public function getPathDailyPulse()
489
        return $this->config['leaderslinked.minio.fullpath_habit_content'];
738
    {
490
    }
739
        return $this->config['leaderslinked.storage.fullpath_daily_pulse'];
491
    
740
    }
492
    
741
    
493
    /**
742
    /**
-
 
743
     *
-
 
744
     * @return string
-
 
745
     */
-
 
746
    public function getPathKnowledgeArea()
-
 
747
    {
-
 
748
        return $this->config['leaderslinked.storage.fullpath_knowledge_area'];
494
     *
749
    }
495
     * @return string
750
    
Línea 496... Línea 751...
496
     */
751
    /**
497
    public function getPathKnowledgeArea()
752
     *
Línea 536... Línea 791...
536
 
791
 
537
     * @return boolean
792
     * @return boolean
538
     */
793
     */
539
    public function deleteObject($filename)
794
    public function deleteObject($filename)
540
    {
795
    {
541
        return $this->s3Files->deleteObject($filename);
796
        return @unlink($filename);
Línea 542... Línea 797...
542
    }
797
    }
543
    
798
    
Línea 550... Línea 805...
550
     * @return boolean
805
     * @return boolean
551
     */
806
     */
552
    public function deleteFile($path, $code, $filename)
807
    public function deleteFile($path, $code, $filename)
553
    {
808
    {
554
        if($code) {
809
        if($code) {
555
            $remoto = $path . '/' . $code. '/' .  $filename;
810
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
556
        } else {
811
        } else {
557
            $remoto = $path . '/' .  $filename;
812
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $filename;
558
        }
813
        }
559
        if($this->s3Files->objectExist($remoto)) {
814
        if(file_exists($remoto)) {
560
            return $this->s3Files->deleteObject($remoto);
815
            return @unlink($remoto);
561
        } else {
816
        } else {
562
            return true;
817
            return true;
563
        }
818
        }
564
    }
819
    }
565
 
-
 
Línea 566... Línea 820...
566
    
820
    
567
    /**
821
    /**
568
     *
822
     *
569
     * @param string $path
823
     * @param string $path
570
     * @param string $code
-
 
571
     * @param string $full_localfilename
824
     * @param string $code
572
     * @return boolean
825
     * @return boolean
-
 
826
     */
-
 
827
    public function deleteDirectory($path, $code)
-
 
828
    {
-
 
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
573
     */
866
     */
574
    public function putFile($remotePath, $code, $full_localfilename)
867
    public function putFile($path, $code, $local_filename)
575
    {
868
    {
576
        if($code) {
869
        if($code) {
577
            $remotePath = $remotePath . '/' . $code;
870
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $code . DIRECTORY_SEPARATOR . basename($local_filename);
578
        } else {
871
        } else {
579
            $remotePath = $remotePath;
872
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path  . DIRECTORY_SEPARATOR .  basename($local_filename);
580
        }
-
 
581
        
-
 
582
        $full_remotefilename = $remotePath . '/' . basename($full_localfilename);
-
 
Línea 583... Línea 873...
583
        
873
        }
-
 
874
 
584
 
875
        $dir = dirname($remote);
-
 
876
        if(!file_exists($dir)) {
Línea 585... Línea -...
585
        $result = $this->s3Files->putObject($full_remotefilename, $full_localfilename);
-
 
586
        //@unlink($filename);
-
 
Línea -... Línea 877...
-
 
877
            @mkdir($dir, 0755, true);
-
 
878
        }
-
 
879
        
-
 
880
 
Línea 587... Línea 881...
587
        
881
        return @rename($local_filename, $remote);
588
        return $result;
882
 
-
 
883
    }
589
    }
884
    
590
 
885
    
591
    
-
 
592
    /**
886
    /**
593
     *
887
     *
594
     * @param string $path
888
     * @param string $tempfile
595
     * @param string $code
889
     * @param string $path
596
     * @param string $tempfile
890
     * @param string $code
597
     * @param string $filename
891
     * @param string $filename
598
     * @return boolean
892
     * @return boolean
599
     */
893
     */
600
    public function moveAndPutFile($path, $code, $tempfile, $filename)
894
    public function moveAndPutFile($tempfile, $path, $code, $filename)
601
    {
895
    {
Línea -... Línea 896...
-
 
896
        if($code) {
-
 
897
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
-
 
898
        } else {
-
 
899
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $filename;
-
 
900
        }
-
 
901
        
-
 
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
Línea -... Línea 923...
-
 
923
     */
Línea 602... Línea -...
602
        if($code) {
-
 
603
            $filepath = $path . '/' . $code;
-
 
604
        } else {
-
 
605
            $filepath = $path;
-
 
606
        }
-
 
607
        
-
 
608
        
-
 
609
        
-
 
610
        $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
924
    public function getTempPath() {
Línea 611... Línea 925...
611
        
925
        $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
612
        move_uploaded_file($tempfile, $filename);
926
        if(!file_exists($interal_path)) {
-
 
927
            mkdir($interal_path, 0775);
613
        
928
        }
614
        $result = $this->s3Files->putObject($filename, $filepath);
929
        
615
        @unlink($filename);
930
        return $interal_path;
616
        
931
        
-
 
932
    }
-
 
933
    
-
 
934
    /**
-
 
935
     * 
-
 
936
     * @param string $url
-
 
937
     * @return string
-
 
938
     */
-
 
939
    public function getPresignedUrl($url)
-
 
940
    {
-
 
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));
617
        return $result;
977
        */
-
 
978
        
618
    }
979
        
Línea -... Línea 980...
-
 
980