Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17018 Rev 17288
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
declare(strict_types=1);
3
declare(strict_types=1);
Línea 3... Línea 4...
3
 
4
 
Línea 4... Línea 5...
4
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
Línea 26... Línea 27...
26
    /**
27
    /**
27
     *
28
     *
28
     * @var \Laminas\Db\Adapter\AdapterInterface
29
     * @var \Laminas\Db\Adapter\AdapterInterface
29
     */
30
     */
30
    private $adapter;
31
    private $adapter;
31
    
32
 
32
    /**
33
    /**
33
     *
34
     *
34
     * @var \LeadersLinked\Cache\CacheInterface
35
     * @var \LeadersLinked\Cache\CacheInterface
35
     */
36
     */
36
    private $cache;
37
    private $cache;
37
    
38
 
38
    
39
 
39
    /**
40
    /**
40
     *
41
     *
41
     * @var \Laminas\Log\LoggerInterface
42
     * @var \Laminas\Log\LoggerInterface
42
     */
43
     */
43
    private $logger;
44
    private $logger;
44
    
45
 
45
    /**
46
    /**
46
     *
47
     *
47
     * @var array
48
     * @var array
48
     */
49
     */
49
    private $config;
50
    private $config;
50
    
51
 
51
    
52
 
52
    /**
53
    /**
53
     *
54
     *
54
     * @var \Laminas\Mvc\I18n\Translator
55
     * @var \Laminas\Mvc\I18n\Translator
55
     */
56
     */
56
    private $translator;
57
    private $translator;
57
    
58
 
58
    
59
 
59
    /**
60
    /**
60
     *
61
     *
61
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
62
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
62
     * @param \LeadersLinked\Cache\CacheInterface $cache
63
     * @param \LeadersLinked\Cache\CacheInterface $cache
63
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
64
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
Línea 70... Línea 71...
70
        $this->cache        = $cache;
71
        $this->cache        = $cache;
71
        $this->logger       = $logger;
72
        $this->logger       = $logger;
72
        $this->config       = $config;
73
        $this->config       = $config;
73
        $this->translator   = $translator;
74
        $this->translator   = $translator;
74
    }
75
    }
75
    
76
 
76
    /**
77
    /**
77
     * 
78
     * 
78
     * Generación del listado de perfiles
79
     * Generación del listado de perfiles
79
     * {@inheritDoc}
80
     * {@inheritDoc}
80
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
81
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
Línea 83... Línea 84...
83
    {
84
    {
84
        $request = $this->getRequest();
85
        $request = $this->getRequest();
85
        $currentUserPlugin = $this->plugin('currentUserPlugin');
86
        $currentUserPlugin = $this->plugin('currentUserPlugin');
86
        $currentCompany = $currentUserPlugin->getCompany();
87
        $currentCompany = $currentUserPlugin->getCompany();
87
        $currentUser    = $currentUserPlugin->getUser();
88
        $currentUser    = $currentUserPlugin->getUser();
88
        
89
 
89
        
90
 
90
        $request = $this->getRequest();
91
        $request = $this->getRequest();
91
        if($request->isGet()) {
92
        if ($request->isGet()) {
92
            
93
 
93
            
94
 
94
            $headers  = $request->getHeaders();
95
            $headers  = $request->getHeaders();
95
            
96
 
96
            $isJson = false;
97
            $isJson = false;
97
            if($headers->has('Accept')) {
98
            if ($headers->has('Accept')) {
98
                $accept = $headers->get('Accept');
99
                $accept = $headers->get('Accept');
99
                
100
 
100
                $prioritized = $accept->getPrioritized();
101
                $prioritized = $accept->getPrioritized();
101
                
102
 
102
                foreach($prioritized as $key => $value) {
103
                foreach ($prioritized as $key => $value) {
103
                    $raw = trim($value->getRaw());
104
                    $raw = trim($value->getRaw());
104
                    
105
 
105
                    if(!$isJson) {
106
                    if (!$isJson) {
106
                        $isJson = strpos($raw, 'json');
107
                        $isJson = strpos($raw, 'json');
107
                    }
108
                    }
108
                    
-
 
109
                }
109
                }
110
            }
110
            }
111
            
111
 
112
           // $isJson = true;
112
            // $isJson = true;
113
            if($isJson) {
113
            if ($isJson) {
114
                $category = null;
114
                $category = null;
115
                $uuid = \LeadersLinked\Library\Functions::sanitizeFilterString($this->params()->fromQuery('category'));
115
                $uuid = \LeadersLinked\Library\Functions::sanitizeFilterString($this->params()->fromQuery('category'));
116
                if($uuid) {
116
                if ($uuid) {
117
                    $categoryMapper = \LeadersLinked\Mapper\MediaCategoryMapper::getInstance($this->adapter);
117
                    $categoryMapper = \LeadersLinked\Mapper\MediaCategoryMapper::getInstance($this->adapter);
118
                    $category = $categoryMapper->fetchOneByUuid($uuid);
118
                    $category = $categoryMapper->fetchOneByUuid($uuid);
119
                    if(!$category) {
119
                    if (!$category) {
120
                        
120
 
121
                        if(!$category) {
121
                        if (!$category) {
122
                            return new JsonModel([
122
                            return new JsonModel([
123
                                'success'   => false,
123
                                'success'   => false,
124
                                'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
124
                                'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
125
                            ]);
125
                            ]);
126
                        }
126
                        }
127
                        
127
 
128
                        if($category->company_id != $currentCompany->id) {
128
                        if ($category->company_id != $currentCompany->id) {
129
                            return new JsonModel([
129
                            return new JsonModel([
130
                                'success'   => false,
130
                                'success'   => false,
131
                                'data'   => 'ERROR_UNAUTHORIZED'
131
                                'data'   => 'ERROR_UNAUTHORIZED'
132
                            ]);
132
                            ]);
133
                        }
133
                        }
134
                        
-
 
135
                        
-
 
136
                    }
134
                    }
137
                    
-
 
138
                    
-
 
139
                }
135
                }
140
                
136
 
141
                if(!$category) {
137
                if (!$category) {
142
                    return new JsonModel([
138
                    return new JsonModel([
143
                        'success' => true,
139
                        'success' => true,
144
                        'data' => [
140
                        'data' => [
145
                            'items' => [],
141
                            'items' => [],
146
                            'total' => 0,
142
                            'total' => 0,
147
                        ]
143
                        ]
148
                    ]);
144
                    ]);
149
                }
145
                }
150
                
146
 
151
                $search = $this->params()->fromQuery('search', []);
147
                $search = $this->params()->fromQuery('search', []);
152
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
148
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
153
                
149
 
154
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
150
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
155
                $page               = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
151
                $page               = (intval($this->params()->fromQuery('start', 1), 10) / $records_x_page) + 1;
156
                $order =  $this->params()->fromQuery('order', []);
152
                $order =  $this->params()->fromQuery('order', []);
157
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
153
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
158
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
154
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
159
                
155
 
160
                $fields =  ['name'];
156
                $fields =  ['name'];
161
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
157
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
162
                
158
 
163
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
159
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
164
                    $order_direction = 'ASC';
160
                    $order_direction = 'ASC';
165
                }
161
                }
166
                
162
 
167
     
163
 
168
                $storage = Storage::getInstance($this->config, $this->adapter);
164
                $storage = Storage::getInstance($this->config, $this->adapter);
169
                $target_path = $storage->getPathMedia();
165
                $target_path = $storage->getPathMedia();
170
                
166
 
171
                
167
 
172
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
168
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
173
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'media/files/delete');
169
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'media/files/delete');
Línea 174... Línea 170...
174
 
170
 
175
                
171
 
Línea 176... Línea 172...
176
                $mediaFileMapper = MediaFileMapper::getInstance($this->adapter);
172
                $mediaFileMapper = MediaFileMapper::getInstance($this->adapter);
Línea 177... Línea 173...
177
 
173
 
178
                $paginator = $mediaFileMapper->fetchAllDataTableByCategoryId($category->id, $search, $page, $records_x_page, $order_field, $order_direction);
174
                $paginator = $mediaFileMapper->fetchAllDataTableByCategoryId($category->id, $search, $page, $records_x_page, $order_field, $order_direction);
179
 
175
 
Línea 180... Línea 176...
180
                
176
 
181
         
177
 
-
 
178
                $records = $paginator->getCurrentItems();
-
 
179
 
182
                $records = $paginator->getCurrentItems();
180
                $items = [];
Línea 183... Línea -...
183
 
-
 
184
                $items = [];
-
 
185
                foreach($records as $record)
-
 
186
                {
181
                foreach ($records as $record) {
187
 
182
 
188
                    
183
 
189
                    if($record->type == MediaFile::TYPE_IMAGE) {
184
                    if ($record->type == MediaFile::TYPE_IMAGE) {
190
                    
185
 
191
                        $urlFile = $storage->getGenericImage($target_path, $record->uuid, $record->file);
186
                        $urlFile = $storage->getGenericImage($target_path, $record->uuid, $record->file);
192
                    } else {
187
                    } else {
193
                        $urlFile = $storage->getGenericFile($target_path, $record->uuid, $record->file);
188
                        $urlFile = $storage->getGenericFile($target_path, $record->uuid, $record->file);
194
                    }
189
                    }
195
                    
190
 
196
                    if($record->preview) {
191
                    if ($record->preview) {
Línea 197... Línea 192...
197
                        $urlPreview = $storage->getGenericImage($target_path, $record->uuid, $record->preview);
192
                        $urlPreview = $storage->getGenericImage($target_path, $record->uuid, $record->preview);
198
                    } else {
193
                    } else {
199
                        $urlPreview = '';
194
                        $urlPreview = '';
200
                    }
195
                    }
201
                    
196
 
202
 
197
 
203
                    $item = [
198
                    $item = [
204
               
199
 
205
                        'name' => $record->name,
200
                        'name' => $record->name,
206
                        'file' => [
201
                        'file' => [
207
                           'filename'   => $record->file,
202
                            'filename'   => $record->file,
208
                           'url'        => $urlFile, 
203
                            'url'        => $urlFile,
209
                            'type'      => $record->type,
204
                            'type'      => $record->type,
210
                        ],    
205
                        ],
211
                        'preview'       => [
206
                        'preview'       => [
212
                            'filename'   => $record->preview,
207
                            'filename'   => $record->preview,
213
                            'url'        => $urlPreview,
208
                            'url'        => $urlPreview,
214
                        ],    
209
                        ],
215
                        'actions' => [
210
                        'actions' => [
Línea 216... Línea 211...
216
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('media/files/delete', ['id' => $record->uuid ]) : '',
211
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('media/files/delete', ['id' => $record->uuid]) : '',
217
                        ]
212
                        ]
Línea 218... Línea 213...
218
                        
213
 
219
                        
214
 
220
                    ];
215
                    ];
221
                    
216
 
222
 
217
 
223
                    array_push($items, $item);
218
                    array_push($items, $item);
224
                }
219
                }
225
 
220
 
226
                
221
 
227
                
-
 
228
                return new JsonModel([
-
 
229
                    'success' => true,
-
 
230
                    'data' => [
222
 
231
                        'items' => $items,
223
                return new JsonModel([
232
                        'total' => $paginator->getTotalItemCount(),
224
                    'success' => true,
233
                    ]
225
                    'data' => [
234
                ]);
226
                        'items' => $items,
235
                
227
                        'total' => $paginator->getTotalItemCount(),
236
                
228
                    ]
237
                
-
 
238
            } else {
229
                ]);
239
                
230
            } else {
240
                $categories = [];
231
 
241
                
232
                $categories = [];
242
                $categoryMapper = MediaCategoryMapper::getInstance($this->adapter);
233
 
243
                $records = $categoryMapper->fetchAllByCompanyId($currentCompany->id);
234
                $categoryMapper = MediaCategoryMapper::getInstance($this->adapter);
244
                foreach($records as $record)
235
                $records = $categoryMapper->fetchAllByCompanyId($currentCompany->id);
245
                {
236
                foreach ($records as $record) {
246
                    $categories[  $record->uuid ] = $record->name;
237
                    $categories[$record->uuid] = $record->name;
247
                }
238
                }
248
                
239
 
249
           
240
 
Línea 250... Línea 241...
250
                $form = new FileForm();
241
                $form = new FileForm();
251
                $this->layout()->setTemplate('layout/layout-backend.phtml');
242
                $this->layout()->setTemplate('layout/layout-backend.phtml');
252
                $viewModel = new ViewModel();
243
                $viewModel = new ViewModel();
253
                $viewModel->setTemplate('leaders-linked/media/files.phtml');
-
 
254
                $viewModel->setVariables([
244
                $viewModel->setTemplate('leaders-linked/media/files.phtml');
255
                   'categories' => $categories,
245
                $viewModel->setVariables([
256
                   'form' => $form,
246
                    'categories' => $categories,
257
                   
247
                    'form' => $form,
258
 
248
 
Línea 269... Línea 259...
269
    }
259
    }
Línea 270... Línea 260...
270
 
260
 
271
    public function uploadAction()
261
    public function uploadAction()
272
    {
262
    {
273
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
263
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
274
        $currentCompany     = $currentUserPlugin->getCompany(); 
264
        $currentCompany     = $currentUserPlugin->getCompany();
275
        $currentUser        = $currentUserPlugin->getUser();
265
        $currentUser        = $currentUserPlugin->getUser();
276
        
266
 
Línea 277... Línea 267...
277
        $request    = $this->getRequest();
267
        $request    = $this->getRequest();
278
 
268
 
279
        if($request->isPost()) {
269
        if ($request->isPost()) {
280
            
270
 
281
            $category = null;
271
            $category = null;
282
            $uuid = \LeadersLinked\Library\Functions::sanitizeFilterString($this->params()->fromPost('category'));
272
            $uuid = \LeadersLinked\Library\Functions::sanitizeFilterString($this->params()->fromPost('category'));
283
            if($uuid) {
273
            if ($uuid) {
284
                $categoryMapper = \LeadersLinked\Mapper\MediaCategoryMapper::getInstance($this->adapter);
274
                $categoryMapper = \LeadersLinked\Mapper\MediaCategoryMapper::getInstance($this->adapter);
285
                $category = $categoryMapper->fetchOneByUuid($uuid);
275
                $category = $categoryMapper->fetchOneByUuid($uuid);
286
                if(!$category) {
276
                if (!$category) {
287
                    
277
 
288
                    if(!$category) {
278
                    if (!$category) {
289
                        return new JsonModel([
279
                        return new JsonModel([
290
                            'success'   => false,
280
                            'success'   => false,
291
                            'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
281
                            'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
292
                        ]);
282
                        ]);
293
                    }
283
                    }
294
                    
284
 
295
                    if($category->company_id != $currentCompany->id) {
285
                    if ($category->company_id != $currentCompany->id) {
296
                        return new JsonModel([
286
                        return new JsonModel([
297
                            'success'   => false,
287
                            'success'   => false,
298
                            'data'   => 'ERROR_UNAUTHORIZED'
288
                            'data'   => 'ERROR_UNAUTHORIZED'
299
                        ]);
-
 
300
                    }
-
 
301
                    
289
                        ]);
302
                    
-
 
303
                }
-
 
304
                
290
                    }
305
                
291
                }
306
            }
292
            }
307
            
293
 
308
            if(!$category) {
294
            if (!$category) {
309
                return new JsonModel([
295
                return new JsonModel([
310
                    'success'   => false,
296
                    'success'   => false,
311
                    'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
297
                    'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
312
                ]);
298
                ]);
313
            }
299
            }
314
            
300
 
315
            
301
 
316
            $form = new FileForm();
302
            $form = new FileForm();
317
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
303
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
318
            
304
 
319
            $form->setData($dataPost);
305
            $form->setData($dataPost);
320
            
306
 
321
            if($form->isValid()) {
307
            if ($form->isValid()) {
322
                $dataPost = (array) $form->getData();
308
                $dataPost = (array) $form->getData();
323
                
309
 
324
                $hydrator = new ObjectPropertyHydrator();
310
                $hydrator = new ObjectPropertyHydrator();
325
                $mediaFile = new MediaFile();
311
                $mediaFile = new MediaFile();
326
                $hydrator->hydrate($dataPost, $mediaFile);
312
                $hydrator->hydrate($dataPost, $mediaFile);
327
                
313
 
328
                $mediaFile->category_id = $category->id;
314
                $mediaFile->category_id = $category->id;
329
                $mediaFile->company_id  = $category->company_id;
315
                $mediaFile->company_id  = $category->company_id;
330
                $mediaFile->file        = 'tmp';
316
                $mediaFile->file        = 'tmp';
331
                $mediaFile->type        = 'tmp';
317
                $mediaFile->type        = 'tmp';
332
                
318
 
333
                $files = $this->getRequest()->getFiles()->toArray();
319
                $files = $this->getRequest()->getFiles()->toArray();
334
                $media_type = '';
320
                $media_type = '';
335
                $media_tmp_filename = '';
321
                $media_tmp_filename = '';
336
                $media_filename = '';
322
                $media_filename = '';
337
                
323
 
338
                if (isset($files['file']) && empty($files['file']['error'])) {
324
                if (isset($files['file']) && empty($files['file']['error'])) {
339
                    $media_tmp_filename  = $files['file']['tmp_name'];
325
                    $media_tmp_filename  = $files['file']['tmp_name'];
340
                    $media_filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
326
                    $media_filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
341
                    
327
 
342
                    $mime_type = mime_content_type($media_tmp_filename);
328
                    $mime_type = mime_content_type($media_tmp_filename);
343
                    
329
 
344
                    
330
 
345
                    if ($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
331
                    if ($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
346
                        $media_type = MediaFile::TYPE_IMAGE;
332
                        $media_type = MediaFile::TYPE_IMAGE;
347
                    } else if ($mime_type ==  'video/quicktime' ||  $mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
333
                    } else if ($mime_type ==  'video/quicktime' ||  $mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
348
                        $media_type = MediaFile::TYPE_VIDEO;
334
                        $media_type = MediaFile::TYPE_VIDEO;
349
                    } else if ($mime_type == 'audio/wav' || $mime_type == 'audio/mpeg') {
335
                    } else if ($mime_type == 'audio/wav' || $mime_type == 'audio/mpeg') {
350
                        $media_type =  MediaFile::TYPE_AUDIO;
336
                        $media_type =  MediaFile::TYPE_AUDIO;
351
                    }
337
                    }
352
                }
338
                }
353
                
339
 
354
                
340
 
355
                
341
 
356
                
342
 
357
                if(empty($media_type)) {
343
                if (empty($media_type)) {
358
                   return new JsonModel([
344
                    return new JsonModel([
359
                        'success'   => false,
345
                        'success'   => false,
360
                        'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
-
 
361
                    ]);
346
                        'data'   => 'ERROR_MEDIA_CATEGORY_NOT_FOUND'
Línea 362... Línea 347...
362
             
347
                    ]);
363
                }
348
                }
364
 
349
 
365
               
350
 
366
                
351
 
367
                $fileMapper = MediaFileMapper::getInstance($this->adapter);
352
                $fileMapper = MediaFileMapper::getInstance($this->adapter);
368
                if($fileMapper->insert($mediaFile)) {
353
                if ($fileMapper->insert($mediaFile)) {
369
                    $mediaFile = $fileMapper->fetchOne($mediaFile->id);
354
                    $mediaFile = $fileMapper->fetchOne($mediaFile->id);
370
                    
355
 
371
                    $storage = Storage::getInstance($this->config, $this->adapter);
356
                    $storage = Storage::getInstance($this->config, $this->adapter);
372
                    $target_path = $storage->getPathMedia();
357
                    $target_path = $storage->getPathMedia();
373
                    $interal_path = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
358
                    $interal_path = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
374
                    if(!file_exists($interal_path)) {
359
                    if (!file_exists($interal_path)) {
375
                        mkdir($interal_path, 0775);
360
                        mkdir($interal_path, 0775);
376
                    }
361
                    }
377
                    
362
 
378
                    if ($media_type == MediaFile::TYPE_AUDIO) {
363
                    if ($media_type == MediaFile::TYPE_AUDIO) {
379
                        if($storage->moveAndPutFile($target_path, $mediaFile->uuid, $media_tmp_filename, $media_filename)) {
364
                        if ($storage->moveAndPutFile($target_path, $mediaFile->uuid, $media_tmp_filename, $media_filename)) {
380
                 
365
 
381
                            $mediaFile->type    = $media_type;
366
                            $mediaFile->type    = $media_type;
382
                            $mediaFile->file    = $media_filename;
367
                            $mediaFile->file    = $media_filename;
383
                            
-
 
384
                            $fileMapper->update($mediaFile);
368
 
385
                        }
-
 
Línea -... Línea 369...
-
 
369
                            $fileMapper->update($mediaFile);
386
                        
370
                        }
387
                    } else if ($media_type == MediaFile::TYPE_IMAGE) {
371
                    } else if ($media_type == MediaFile::TYPE_IMAGE) {
388
                       
372
 
389
 
373
 
390
                        $filename = substr($media_filename, 0, strrpos($media_filename, '.')).  '.png';
374
                        $filename = substr($media_filename, 0, strrpos($media_filename, '.')) .  '.png';
391
                        
375
 
392
                        $image = Image::getInstance($this->config);
376
                        $image = Image::getInstance($this->config);
393
                        $full_tmp_filename = $image->uploadProcessWithOutChangeSize($media_tmp_filename, $filename);
377
                        $full_tmp_filename = $image->uploadProcessWithOutChangeSize($media_tmp_filename, $filename);
394
                        
378
 
395
                        if($full_tmp_filename) {
379
                        if ($full_tmp_filename) {
396
                            if($storage->putFile($target_path, $mediaFile->uuid,  $full_tmp_filename)) {
380
                            if ($storage->putFile($target_path, $mediaFile->uuid,  $full_tmp_filename)) {
397
                                $mediaFile->type    = $media_type;
381
                                $mediaFile->type    = $media_type;
398
                                $mediaFile->file    = $media_filename;
382
                                $mediaFile->file    = $media_filename;
399
                                
383
 
400
                                
-
 
401
                                $fileMapper->update($mediaFile);
-
 
402
                            }
384
 
403
                        }
385
                                $fileMapper->update($mediaFile);
404
                        
386
                            }
405
                   
387
                        }
406
                    } else if ($media_type == MediaFile::TYPE_VIDEO) {
388
                    } else if ($media_type == MediaFile::TYPE_VIDEO) {
407
                        try {
389
                        try {
408
                            $full_filename          = $interal_path . DIRECTORY_SEPARATOR. $media_filename;
390
                            $full_filename          = $interal_path . DIRECTORY_SEPARATOR . $media_filename;
409
                            $poster_filename        = substr($media_filename, 0, strrpos($media_filename, '.')).  '.jpg';
391
                            $poster_filename        = substr($media_filename, 0, strrpos($media_filename, '.')) .  '.jpg';
410
                            $poster_full_filename   = $interal_path . DIRECTORY_SEPARATOR . $poster_filename;
392
                            $poster_full_filename   = $interal_path . DIRECTORY_SEPARATOR . $poster_filename;
411
                            
393
 
412
                            move_uploaded_file($media_tmp_filename, $full_filename);
394
                            move_uploaded_file($media_tmp_filename, $full_filename);
413
   
395
 
414
                            $cmd        = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration  $full_filename";
396
                            $cmd        = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration  $full_filename";
415
                            $response   = trim(shell_exec($cmd));
397
                            $response   = trim(shell_exec($cmd));
416
                            
398
 
417
                            $source_duration = 0;
399
                            $source_duration = 0;
418
                            $lines = explode("\n", $response);
400
                            $lines = explode("\n", $response);
419
                            foreach ($lines as $line) {
401
                            foreach ($lines as $line) {
420
                                $line = trim(strtolower($line));
402
                                $line = trim(strtolower($line));
421
                                if (strpos($line, 'duration') !== false) {
403
                                if (strpos($line, 'duration') !== false) {
422
                                    $values = explode('=', $line);
404
                                    $values = explode('=', $line);
423
                                    $source_duration = intval(str_replace($values[1], '#', ''), 10);
405
                                    $source_duration = intval(str_replace($values[1], '#', ''), 10);
424
                                }
406
                                }
425
                            }
407
                            }
426
                            
408
 
427
                            
409
 
428
                            if ($source_duration == 0) {
410
                            if ($source_duration == 0) {
429
                                $second_extract = '00:00:02';
411
                                $second_extract = '00:00:02';
430
                            } else {
412
                            } else {
431
                                if ($source_duration > 10) {
413
                                if ($source_duration > 10) {
432
                                    $second_extract = '00:00:10';
414
                                    $second_extract = '00:00:10';
433
                                } else {
415
                                } else {
434
                                    $second_extract = '00:00:02';
416
                                    $second_extract = '00:00:02';
435
                                }
417
                                }
436
                            }
418
                            }
437
                            
419
 
438
                            //$imageSize = $this->config['leaderslinked.image_sizes.feed_image_size'];
420
                            //$imageSize = $this->config['leaderslinked.image_sizes.feed_image_size'];
439
                            
421
 
440
                            //$cmd = "/usr/bin/ffmpeg -y -i $full_filename  -pix_fmt yuvj422p -deinterlace -an -ss $second_extract -f mjpeg -t 1 -r 1 -y -s $imageSize $generateFile";
422
                            //$cmd = "/usr/bin/ffmpeg -y -i $full_filename  -pix_fmt yuvj422p -deinterlace -an -ss $second_extract -f mjpeg -t 1 -r 1 -y -s $imageSize $generateFile";
441
                            // $cmd = "/usr/bin/ffmpeg -y -i $full_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y -s $imageSize $generateFile";
423
                            // $cmd = "/usr/bin/ffmpeg -y -i $full_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y -s $imageSize $generateFile";
442
                            $cmd = "/usr/bin/ffmpeg -y -i $full_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y  $poster_full_filename";
424
                            $cmd = "/usr/bin/ffmpeg -y -i $full_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y  $poster_full_filename";
443
                            exec($cmd);
425
                            exec($cmd);
444
        
426
 
445
                            
427
 
446
                            $ok = $storage->putFile($target_path, $mediaFile->uuid, $poster_full_filename);
428
                            $ok = $storage->putFile($target_path, $mediaFile->uuid, $poster_full_filename);
447
                            $ok = $ok && $storage->putFile($target_path, $mediaFile->uuid, $full_filename);
429
                            $ok = $ok && $storage->putFile($target_path, $mediaFile->uuid, $full_filename);
448
                            
430
 
449
                            if( $ok ) {
431
                            if ($ok) {
450
                                
432
 
451
                                
433
 
452
                                $mediaFile->type    = $media_type;
434
                                $mediaFile->type    = $media_type;
453
                                $mediaFile->file    = basename($media_filename);
435
                                $mediaFile->file    = basename($media_filename);
454
                                $mediaFile->preview = basename($poster_filename);
436
                                $mediaFile->preview = basename($poster_filename);
455
                          
437
 
456
                                if($fileMapper->update($mediaFile)) {
438
                                if ($fileMapper->update($mediaFile)) {
457
                                
439
 
458
                                    $videoConvert = new VideoConvert();
440
                                    $videoConvert = new VideoConvert();
459
                                    $videoConvert->uuid     = $mediaFile->uuid;
441
                                    $videoConvert->uuid     = $mediaFile->uuid;
460
                                    $videoConvert->filename = basename($media_filename);
442
                                    $videoConvert->filename = basename($media_filename);
461
                                    $videoConvert->type     = VideoConvert::TYPE_MEDIA;
443
                                    $videoConvert->type     = VideoConvert::TYPE_MEDIA;
462
                                    
444
 
463
                                    $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
445
                                    $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
464
                                    $videoConvertMapper->insert($videoConvert);
446
                                    $videoConvertMapper->insert($videoConvert);
465
                                }
447
                                }
466
                            }
448
                            }
467
                            
449
 
468
                           // @unlink($full_filename);
450
                            // @unlink($full_filename);
469
                            //@unlink($generate_full_filename);
451
                            //@unlink($generate_full_filename);
470
                            
452
 
471
                 
453
 
472
                            
454
 
473
                        } catch (\Throwable $e) {
455
                        } catch (\Throwable $e) {
474
            
456
 
475
                            $fileMapper->delete($mediaFile);
457
                            $fileMapper->delete($mediaFile);
476
                            
458
 
477
                            
459
 
478
                            return new JsonModel([
-
 
479
                                'success'   => false,
460
                            return new JsonModel([
480
                                'data'   => 'ERROR_UPLOAD_FILE'
461
                                'success'   => false,
481
                            ]);
462
                                'data'   => 'ERROR_UPLOAD_FILE'
482
                            
463
                            ]);
483
                        }
464
                        }
484
                    } 
465
                    }
485
         
466
 
486
                    $this->logger->info('Se agrego el archivo a la media library ' . $mediaFile->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
467
                    $this->logger->info('Se agrego el archivo a la media library ' . $mediaFile->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
487
                    
468
 
488
                    return new JsonModel([
-
 
489
                        'success'   => true,
-
 
490
                        'data'   => 'LABEL_RECORD_ADDED'
-
 
491
                    ]);
469
                    return new JsonModel([
492
     
470
                        'success'   => true,
493
                   
471
                        'data'   => 'LABEL_RECORD_ADDED'
494
                   
472
                    ]);
495
                } else {
473
                } else {
496
                    $data = [
-
 
497
                        'success'   => false,
474
                    $data = [
498
                        'data'      => $fileMapper->getError()
475
                        'success'   => false,
499
                    ];
476
                        'data'      => $fileMapper->getError()
500
                    
-
 
501
                }
477
                    ];
502
                
478
                }
503
                return new JsonModel($data);
479
 
504
                
480
                return new JsonModel($data);
505
            } else {
-
 
506
                $messages = [];
481
            } else {
507
                $form_messages = (array) $form->getMessages();
482
                $messages = [];
508
                foreach($form_messages  as $fieldname => $field_messages)
483
                $form_messages = (array) $form->getMessages();
509
                {
484
                foreach ($form_messages  as $fieldname => $field_messages) {
510
                    
485
 
511
                    $messages[$fieldname] = array_values($field_messages);
486
                    $messages[$fieldname] = array_values($field_messages);
512
                }
487
                }
513
                
488
 
514
                return new JsonModel([
489
                return new JsonModel([
515
                    'success'   => false,
-
 
516
                    'data'   => $messages
490
                    'success'   => false,
517
                ]);
491
                    'data'   => $messages
518
            }
492
                ]);
519
            
493
            }
520
        } else {
494
        } else {
521
            $data = [
495
            $data = [
522
                'success' => false,
496
                'success' => false,
523
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
497
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
524
            ];
498
            ];
525
            
499
 
526
            return new JsonModel($data);
500
            return new JsonModel($data);
527
        }
501
        }
528
        
502
 
529
        return new JsonModel($data);
503
        return new JsonModel($data);
530
    }
504
    }
531
    
505
 
532
    /**
506
    /**
533
     * 
507
     * 
534
     * Borrar un perfil excepto el público
508
     * Borrar un perfil excepto el público
535
     * @return \Laminas\View\Model\JsonModel
509
     * @return \Laminas\View\Model\JsonModel
536
     */
510
     */
537
    public function deleteAction()
511
    public function deleteAction()
538
    {
512
    {
539
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
513
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
540
        $currentCompany     = $currentUserPlugin->getCompany();
514
        $currentCompany     = $currentUserPlugin->getCompany();
541
        $currentUser        = $currentUserPlugin->getUser();
515
        $currentUser        = $currentUserPlugin->getUser();
542
        
516
 
543
        $request    = $this->getRequest();
517
        $request    = $this->getRequest();
544
        $id   = $this->params()->fromRoute('id');
518
        $id   = $this->params()->fromRoute('id');
545
        
519
 
546
        
520
 
547
        $fileMapper = MediaFileMapper::getInstance($this->adapter);
521
        $fileMapper = MediaFileMapper::getInstance($this->adapter);
548
        $file = $fileMapper->fetchOneByUuid($id);
522
        $file = $fileMapper->fetchOneByUuid($id);
549
        if(!$file) {
523
        if (!$file) {
550
            return new JsonModel([
524
            return new JsonModel([
551
                'success'   => false,
525
                'success'   => false,
552
                'data'   => 'ERROR_MEDIA_FILE_NOT_FOUND'
526
                'data'   => 'ERROR_MEDIA_FILE_NOT_FOUND'
553
            ]);
527
            ]);
554
        }
528
        }
555
        
529
 
556
        if($file->company_id != $currentCompany->id) {
530
        if ($file->company_id != $currentCompany->id) {
557
            return new JsonModel([
531
            return new JsonModel([
558
                'success'   => false,
-
 
Línea -... Línea 532...
-
 
532
                'success'   => false,
559
                'data'   => 'ERROR_UNAUTHORIZED'
533
                'data'   => 'ERROR_UNAUTHORIZED'
560
            ]);
534
            ]);
561
        }
535
        }
562
        
536
 
563
 
537
 
564
        
538
 
565
        if($request->isPost()) {
539
        if ($request->isPost()) {
566
            
540
 
567
            
541
 
568
            
542
 
569
            $result = $fileMapper->delete($file);
543
            $result = $fileMapper->delete($file);
570
            if($result) {
544
            if ($result) {
571
                $this->logger->info('Se borro el el archivo de la media query : ' .  $file->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
545
                $this->logger->info('Se borro el el archivo de la media query : ' .  $file->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
Línea 572... Línea 546...
572
                
546
 
573
                $storage = Storage::getInstance($this->config, $this->adapter);
547
                $storage = Storage::getInstance($this->config, $this->adapter);
574
                $target_path = $storage->getPathMedia();
548
                $target_path = $storage->getPathMedia();
575
                
549
 
576
                $storage->deleteFile($target_path, $file->uuid, $file->file);
550
                $storage->deleteFile($target_path, $file->uuid, $file->file);
577
 
551
 
578
                
552
 
579
                if($file->type == MediaFile::TYPE_VIDEO) {
553
                if ($file->type == MediaFile::TYPE_VIDEO) {
580
                    $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
554
                    $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
581
                    $videoConvertMapper->deleteByUuidAndType($file->uuid, $file->type);
555
                    $videoConvertMapper->deleteByUuidAndType($file->uuid, $file->type);
582
                }
556
                }
583
                
557
 
584
                
558
 
585
                $data = [
559
                $data = [
586
                    'success' => true,
560
                    'success' => true,
587
                    'data' => 'LABEL_RECORD_DELETED'
561
                    'data' => 'LABEL_RECORD_DELETED'
588
                ];
562
                ];
589
            } else {
563
            } else {
590
                
564
 
591
                $data = [
565
                $data = [
592
                    'success'   => false,
-
 
593
                    'data'      => $fileMapper->getError()
566
                    'success'   => false,
594
                ];
567
                    'data'      => $fileMapper->getError()
595
                
568
                ];
596
                return new JsonModel($data);
569
 
597
            }
570
                return new JsonModel($data);
598
            
571
            }
599
        } else {
572
        } else {
600
            $data = [
573
            $data = [
601
                'success' => false,
574
                'success' => false,
602
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
575
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
603
            ];
576
            ];
604
            
-
 
605
            return new JsonModel($data);
-
 
606
        }
-
 
607
        
-
 
608
        return new JsonModel($data);
577