Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 531 Rev 532
Línea 354... Línea 354...
354
 
354
 
355
            // 🔹 Crear nueva competencia si nro == 0
355
            // 🔹 Crear nueva competencia si nro == 0
356
            if ((int) ($hasIdData['nro'] ?? 0) === 0) {
356
            if ((int) ($hasIdData['nro'] ?? 0) === 0) {
Línea 357... Línea 357...
357
                $uuid = $this->generateUuid();
357
                $uuid = $this->generateUuid();
358
 
358
 
359
                $insert = $sql->insert('tbl_competencies')
359
                $insert = $sql->insert(CompetencyMapper::_TABLE)
360
                    ->values([
360
                    ->values([
361
                        'uuid' => $uuid,
361
                        'uuid' => $uuid,
362
                        'name' => $name,
362
                        'name' => $name,
363
                        'description' => $description,
363
                        'description' => $description,
364
                        'competency_type_id' => $competencyTypeId,
364
                        'competency_type_id' => $competencyTypeId,
365
                        'status' => 'a',
365
                        'status' => CompetencyMapper::STATUS_ACTIVE,
366
                        'added_on' => date('Y-m-d H:i:s'),
366
                        'added_on' => date('Y-m-d H:i:s'),
367
                        'updated_on' => date('Y-m-d H:i:s')
367
                        'updated_on' => date('Y-m-d H:i:s')
-
 
368
                    ]);
-
 
369
                $stmt = $sql->prepareStatementForSqlObject($insert)->execute();
-
 
370
 
-
 
371
                if ($stmt->getAffectedRows() === 0) {
-
 
372
                    return [
-
 
373
                        'success' => false,
-
 
374
                        'message' => "Error al insertar la competencia '{$name}'",
-
 
375
                        'data' => []
-
 
376
                    ];
368
                    ]);
377
                }
369
                $sql->prepareStatementForSqlObject($insert)->execute();
378
 
370
                $competencyId = $adapter->getDriver()->getLastGeneratedValue();
379
                $competencyId = $adapter->getDriver()->getLastGeneratedValue();
371
                $status = 'created';
380
                $status = 'created';
372
            }
381
            }
373
            // 🔹 Actualizar competencia existente si nro > 0
382
            // 🔹 Actualizar competencia existente si nro > 0
Línea 374... Línea 383...
374
            else {
383
            else {
375
                $competencyId = (int) $hasIdData['nro'];
384
                $competencyId = (int) $hasIdData['nro'];
376
 
385
 
Línea 377... Línea 386...
377
                $select = $sql->select('tbl_competencies')
386
                $select = $sql->select(CompetencyMapper::_TABLE)
378
                    ->where(['id' => $competencyId]);
387
                    ->where(['id' => $competencyId]);
Línea 386... Línea 395...
386
                    ];
395
                    ];
387
                }
396
                }
Línea 388... Línea 397...
388
 
397
 
389
                // Solo actualizamos si realmente cambia el nombre o la descripción
398
                // Solo actualizamos si realmente cambia el nombre o la descripción
390
                if ($existing['name'] !== $name || $existing['description'] !== $description) {
399
                if ($existing['name'] !== $name || $existing['description'] !== $description) {
391
                    $update = $sql->update('tbl_competencies')
400
                    $update = $sql->update(CompetencyMapper::_TABLE)
392
                        ->set([
401
                        ->set([
393
                            'name' => $name,
402
                            'name' => $name,
394
                            'description' => $description,
403
                            'description' => $description,
395
                            'updated_on' => date('Y-m-d H:i:s')
404
                            'updated_on' => date('Y-m-d H:i:s')
396
                        ])
405
                        ])
397
                        ->where(['id' => $competencyId]);
406
                        ->where(['id' => $competencyId]);
-
 
407
                    $stmt = $sql->prepareStatementForSqlObject($update)->execute();
-
 
408
 
-
 
409
                    if ($stmt->getAffectedRows() === 0) {
-
 
410
                        return [
-
 
411
                            'success' => false,
-
 
412
                            'message' => "Error al actualizar la competencia '{$name}' (ID {$competencyId})",
-
 
413
                            'data' => []
-
 
414
                        ];
398
                    $sql->prepareStatementForSqlObject($update)->execute();
415
                    }
Línea 399... Línea 416...
399
                }
416
                }
400
 
417
 
Línea -... Línea 418...
-
 
418
                $status = 'updated';
-
 
419
            }
-
 
420
 
-
 
421
            // 🔹 Vincular competencia con job description si no está vinculada
-
 
422
            $linkCheck = $sql->select(JobDescriptionCompetencyMapper::_TABLE)
-
 
423
                ->where([
-
 
424
                    'job_description_id' => $jobDescriptionId,
-
 
425
                    'competency_id' => $competencyId
-
 
426
                ]);
-
 
427
            $existsLink = $sql->prepareStatementForSqlObject($linkCheck)->execute()->current();
-
 
428
 
-
 
429
            if (!$existsLink) {
-
 
430
                $linkInsert = $sql->insert(JobDescriptionCompetencyMapper::_TABLE)
-
 
431
                    ->values([
-
 
432
                        'job_description_id' => $jobDescriptionId,
-
 
433
                        'competency_id' => $competencyId
-
 
434
                    ]);
-
 
435
                $stmt = $sql->prepareStatementForSqlObject($linkInsert)->execute();
-
 
436
 
-
 
437
                if ($stmt->getAffectedRows() === 0) {
-
 
438
                    return [
-
 
439
                        'success' => false,
-
 
440
                        'message' => "Error al vincular competencia '{$name}' con la descripción {$jobDescriptionId}",
-
 
441
                        'data' => []
-
 
442
                    ];
401
                $status = 'updated';
443
                }
402
            }
444
            }
403
 
445
 
404
            // 🔹 Guardar resultado
446
            // 🔹 Guardar resultado exitoso
405
            $results[] = [
447
            $results[] = [
406
                'name' => $name,
448
                'name' => $name,
407
                'competency_id' => $competencyId,
449
                'competency_id' => $competencyId,
Línea 408... Línea 450...
408
                'status' => $status
450
                'status' => $status
409
            ];
451
            ];
410
        }
452
        }
411
 
453
 
412
        return [
454
        return [
413
            'success' => true,
455
            'success' => true,
Línea 414... Línea -...
414
            'message' => 'Procesamiento completado',
-
 
415
            'data' => $results
-
 
416
        ];
456
            'message' => 'Procesamiento completado exitosamente.',
417
    }
457
            'data' => $results
418
 
458
        ];
419
 
459
    }
420
 
460