Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17235 | Rev 17241 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17235 Rev 17236
Línea 165... Línea 165...
165
                $recordsPerPage, 
165
                $recordsPerPage, 
166
                $orderField, 
166
                $orderField, 
167
                $orderDirection
167
                $orderDirection
168
            );
168
            );
Línea 169... Línea 169...
169
 
169
 
Línea 170... Línea 170...
170
            $items = $this->prepareCapsuleItems($paginator->getCurrentItems(), $currentCompany, $permissions);
170
            $items = $this->prepareCapsuleItems($paginator->getCurrentItems(), $permissions);
171
 
171
 
172
            $response = [
172
            $response = [
173
                'success' => true,
173
                'success' => true,
Línea 195... Línea 195...
195
    private function getUserPermissions($acl, $currentUser)
195
    private function getUserPermissions($acl, $currentUser)
196
    {
196
    {
197
        return [
197
        return [
198
            'allowAdd' => $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/add'),
198
            'allowAdd' => $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/add'),
199
            'allowEdit' => $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/edit'),
199
            'allowEdit' => $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/edit'),
200
            'allowDelete' => $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/delete'),
200
            'allowDelete' => $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/delete')
201
            'allowUsers' => $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/users')
-
 
202
        ];
201
        ];
203
    }
202
    }
Línea 204... Línea 203...
204
 
203
 
205
    /**
204
    /**
206
     * Prepare capsule items for datatable
205
     * Prepare capsule items for datatable
207
     * @param array $records
-
 
208
     * @param \LeadersLinked\Model\Company $currentCompany
206
     * @param array $records
209
     * @param array $permissions
207
     * @param array $permissions
210
     * @return array
208
     * @return array
211
     */
209
     */
212
    private function prepareCapsuleItems($records, $currentCompany, $permissions)
210
    private function prepareCapsuleItems($records, $permissions)
213
    {
211
    {
214
        $items = [];
-
 
215
        $microlearningCapsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
212
        $items = [];
216
        $storage = Storage::getInstance($this->config, $this->adapter);
213
        $storage = Storage::getInstance($this->config, $this->adapter);
Línea 217... Línea 214...
217
        $path = $storage->getPathMicrolearningCapsule();
214
        $path = $storage->getPathMicrolearningCapsule();
218
 
-
 
219
        foreach ($records as $record) {
-
 
220
            $totalUsers = $microlearningCapsuleUserMapper->fetchCountUsersByCompanyIdAndCapsuleId($currentCompany->id, $record->id);
-
 
221
            $totalUsersActive = $microlearningCapsuleUserMapper->fetchCountUsersActiveByCompanyIdAndCapsuleId($currentCompany->id, $record->id);
-
 
222
 
-
 
223
            $status = $this->getCapsuleStatus($record->status);
-
 
224
            $privacy = $this->getCapsulePrivacy($record->privacy);
-
 
225
            $type = $this->getCapsuleType($record->type);
-
 
226
 
-
 
227
            $params = ['capsule_uuid' => $record->uuid];
215
 
228
 
216
        foreach ($records as $record) {
229
            $items[] = [
-
 
230
                'name' => $record->name,
-
 
231
                'details' => [
-
 
232
                    'status' => $status,
-
 
233
                    'privacy' => $privacy,
217
            $items[] = [
234
                    'type' => $type,
-
 
235
                    'cost' => $record->cost,
-
 
236
                    'total_users' => $totalUsers,
-
 
237
                    'total_users_active' => $totalUsersActive,
-
 
238
                ],
218
                'name' => $record->name,
239
                'images' => [
-
 
240
                    'image' => $storage->getGenericImage($path, $record->uuid, $record->image),
219
                'description' => $record->description,
241
                ],
220
                'image' => $storage->getGenericImage($path, $record->uuid, $record->image),
242
                'actions' => $this->prepareCapsuleActions($record, $permissions, $totalUsers, $totalUsersActive)
221
                'actions' => $this->prepareCapsuleActions($record, $permissions)
Línea 243... Línea 222...
243
            ];
222
            ];
244
        }
223
        }
Línea 245... Línea 224...
245
 
224
 
246
        return $items;
-
 
247
    }
-
 
248
 
-
 
249
    /**
-
 
250
     * Get capsule status label
-
 
251
     * @param int $status
-
 
252
     * @return string
-
 
253
     */
-
 
254
    private function getCapsuleStatus($status)
-
 
255
    {
-
 
256
        switch ($status) {
-
 
257
            case MicrolearningCapsule::STATUS_ACTIVE:
-
 
258
                return 'LABEL_ACTIVE';
-
 
259
            case MicrolearningCapsule::STATUS_INACTIVE:
-
 
260
                return 'LABEL_INACTIVE';
-
 
261
            default:
-
 
262
                return '';
-
 
263
        }
-
 
264
    }
-
 
265
 
-
 
266
    /**
-
 
267
     * Get capsule privacy label
-
 
268
     * @param int $privacy
-
 
269
     * @return string
-
 
270
     */
-
 
271
    private function getCapsulePrivacy($privacy)
-
 
272
    {
-
 
273
        switch ($privacy) {
-
 
274
            case MicrolearningCapsule::PRIVACY_PUBLIC:
-
 
275
                return 'LABEL_PUBLIC';
-
 
276
            case MicrolearningCapsule::PRIVACY_PRIVATE:
-
 
277
                return 'LABEL_PRIVATE';
-
 
278
            default:
-
 
279
                return '';
-
 
280
        }
-
 
281
    }
-
 
282
 
-
 
283
    /**
-
 
284
     * Get capsule type label
-
 
285
     * @param int $type
-
 
286
     * @return string
-
 
287
     */
-
 
288
    private function getCapsuleType($type)
-
 
289
    {
-
 
290
        switch ($type) {
-
 
291
            case MicrolearningCapsule::TYPE_FREE:
-
 
292
                return 'LABEL_FREE';
-
 
293
            case MicrolearningCapsule::TYPE_PRIVATE:
-
 
294
                return 'LABEL_PRIVATE';
-
 
295
            case MicrolearningCapsule::TYPE_SELLING:
-
 
296
                return 'LABEL_SELLING';
-
 
297
            default:
-
 
298
                return '';
-
 
299
        }
225
        return $items;
300
    }
226
    }
301
 
227
 
302
    /**
-
 
303
     * Prepare capsule actions
-
 
304
     * @param \LeadersLinked\Model\MicrolearningCapsule $record
228
    /**
305
     * @param array $permissions
229
     * Prepare capsule actions
306
     * @param int $totalUsers
230
     * @param \LeadersLinked\Model\MicrolearningCapsule $record
307
     * @param int $totalUsersActive
231
     * @param array $permissions
308
     * @return array
232
     * @return array
Línea 309... Línea 233...
309
     */
233
     */
310
    private function prepareCapsuleActions($record, $permissions, $totalUsers, $totalUsersActive)
234
    private function prepareCapsuleActions($record, $permissions)
311
    {
235
    {
312
        $params = ['capsule_uuid' => $record->uuid];
-
 
313
        
-
 
314
        return [
-
 
315
            'link_edit' => $permissions['allowEdit'] ? $this->url()->fromRoute('microlearning/content/capsules/edit', $params) : '',
-
 
316
            'link_delete' => $permissions['allowDelete'] ? $this->url()->fromRoute('microlearning/content/capsules/delete', $params) : '',
-
 
317
            'link_total_users' => $permissions['allowUsers'] && $totalUsers ? 
-
 
318
                $this->url()->fromRoute('microlearning/content/capsules/users', [
-
 
319
                    'capsule_uuid' => $record->uuid,
-
 
320
                    'type' => 'all'
-
 
321
                ]) : '',
-
 
322
            'link_total_users_actives' => $permissions['allowUsers'] && $totalUsersActive ? 
236
        $params = ['capsule_uuid' => $record->uuid];
323
                $this->url()->fromRoute('microlearning/content/capsules/users', [
237
        
Línea 324... Línea 238...
324
                    'capsule_uuid' => $record->uuid,
238
        return [
325
                    'type' => 'active'
239
            'link_edit' => $permissions['allowEdit'] ? $this->url()->fromRoute('microlearning/content/capsules/edit', $params) : '',
Línea 333... Línea 247...
333
     * @return \Laminas\View\Model\ViewModel
247
     * @return \Laminas\View\Model\ViewModel
334
     */
248
     */
335
    private function handleHtmlRequest($currentCompany)
249
    private function handleHtmlRequest($currentCompany)
336
    {
250
    {
337
        $imageSize = $this->config['leaderslinked.image_sizes.microlearning_image_upload'];
251
        $imageSize = $this->config['leaderslinked.image_sizes.microlearning_image_upload'];
338
        $marketplaceSize = $this->config['leaderslinked.image_sizes.marketplace'];
-
 
Línea 339... Línea 252...
339
        
252
        
340
        $formAdd = new CapsuleAddForm($currentCompany->internal);
253
        $formAdd = new CapsuleAddForm($currentCompany->internal);
Línea 341... Línea 254...
341
        $formEdit = new CapsuleEditForm($currentCompany->internal);
254
        $formEdit = new CapsuleEditForm($currentCompany->internal);
Línea 346... Línea 259...
346
        $viewModel->setVariables([
259
        $viewModel->setVariables([
347
            'formAdd' => $formAdd,
260
            'formAdd' => $formAdd,
348
            'formEdit' => $formEdit,
261
            'formEdit' => $formEdit,
349
            'company_uuid' => $currentCompany->uuid,
262
            'company_uuid' => $currentCompany->uuid,
350
            'image_size' => $imageSize,
263
            'image_size' => $imageSize,
351
            'marketplace_size' => $marketplaceSize,
-
 
352
        ]);
264
        ]);
Línea 353... Línea 265...
353
        
265
        
354
        return $viewModel;
266
        return $viewModel;