Línea 515... |
Línea 515... |
515 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByUuid($id);
|
515 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByUuid($id);
|
Línea 516... |
Línea 516... |
516 |
|
516 |
|
Línea -... |
Línea 517... |
- |
|
517 |
|
517 |
|
518 |
if ($request->isPost()) {
|
518 |
if ($request->isPost()) {
|
519 |
|
Línea -... |
Línea 520... |
- |
|
520 |
// Capturar datos de la pregunta ANTES de eliminarla para formato consistente
|
- |
|
521 |
$userMapper = UserMapper::getInstance($this->adapter);
|
519 |
|
522 |
$user = $userMapper->fetchOne($myCoachQuestion->user_id);
|
- |
|
523 |
|
- |
|
524 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
- |
|
525 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
- |
|
526 |
$myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
|
- |
|
527 |
$myCoachQuestionViewMapper = MyCoachQuestionViewMapper::getInstance($this->adapter);
|
- |
|
528 |
$myCoachCategoryMapper = MyCoachCategoryMapper::getInstance($this->adapter);
|
- |
|
529 |
|
- |
|
530 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
- |
|
531 |
|
- |
|
532 |
// Obtener categorías de la pregunta antes de eliminar
|
- |
|
533 |
$myCoachQuestionCategoryMapper = MyCoachQuestionCategoryMapper::getInstance($this->adapter);
|
- |
|
534 |
$questionCategories = $myCoachQuestionCategoryMapper->fetchAllByQuestionId($myCoachQuestion->id);
|
- |
|
535 |
|
- |
|
536 |
$bags_categories = [];
|
- |
|
537 |
foreach($questionCategories as $questionCategory) {
|
- |
|
538 |
$category = $myCoachCategoryMapper->fetchOne($questionCategory->category_id);
|
- |
|
539 |
if($category) {
|
- |
|
540 |
array_push($bags_categories, $category->name);
|
- |
|
541 |
}
|
- |
|
542 |
}
|
- |
|
543 |
|
- |
|
544 |
// Formatear descripción (limitar a 250 caracteres)
|
- |
|
545 |
$description = strip_tags($myCoachQuestion->description);
|
- |
|
546 |
if (strlen($description) > 250) {
|
- |
|
547 |
$description = substr($description, 0, 250) . '...';
|
- |
|
548 |
}
|
- |
|
549 |
|
- |
|
550 |
// Formatear fechas
|
- |
|
551 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $myCoachQuestion->added_on);
|
- |
|
552 |
$added_on = $dt->format('d/m/Y H:i a');
|
- |
|
553 |
|
- |
|
554 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $myCoachQuestion->updated_on);
|
- |
|
555 |
$updated_on = $dt->format('d/m/Y H:i a');
|
- |
|
556 |
|
- |
|
557 |
// Capturar datos completos antes de eliminar
|
- |
|
558 |
$questionData = [
|
- |
|
559 |
'uuid' => $myCoachQuestion->uuid,
|
- |
|
560 |
'user_name' => trim($user->first_name . ' ' . $user->last_name),
|
- |
|
561 |
'user_image' => $storage->getUserImage($user),
|
- |
|
562 |
'title' => $myCoachQuestion->title,
|
- |
|
563 |
'description' => $description,
|
- |
|
564 |
'categories' => $bags_categories,
|
- |
|
565 |
'views' => intval($myCoachQuestionViewMapper->fetchCountByQuestionId($myCoachQuestion->id), 10),
|
- |
|
566 |
'answers' => intval($myCoachAnswerMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
|
- |
|
567 |
'reactions' => intval($contentReactionMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
|
- |
|
568 |
'comments' => intval($commentMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
|
- |
|
569 |
'added_on' => $added_on,
|
- |
|
570 |
'updated_on' => $updated_on,
|
- |
|
571 |
'link_add_comment' => $this->url()->fromRoute('my-coach/questions/comments/add', ['id' => $myCoachQuestion->uuid],['force_canonical' => true]),
|
- |
|
572 |
'link_view' => $this->url()->fromRoute('my-coach/questions/view', ['id' => $myCoachQuestion->uuid]),
|
- |
|
573 |
'link_edit' => $this->url()->fromRoute('my-coach/questions/edit', ['id' => $myCoachQuestion->uuid],['force_canonical' => true]),
|
- |
|
574 |
'link_delete' => $this->url()->fromRoute('my-coach/questions/delete', ['id' => $myCoachQuestion->uuid],['force_canonical' => true]),
|
- |
|
575 |
'link_reactions' => $this->url()->fromRoute('my-coach/questions/reactions', ['id' => $myCoachQuestion->uuid],['force_canonical' => true])
|
520 |
$myCoachQuestionCategoryMapper = MyCoachQuestionCategoryMapper::getInstance($this->adapter);
|
576 |
];
|
Línea 521... |
Línea 577... |
521 |
$myCoachQuestionCategoryMapper->deleteAllByQuestionId($myCoachQuestion->id);
|
577 |
|
522 |
|
578 |
// Proceder con la eliminación
|
- |
|
579 |
$myCoachQuestionCategoryMapper->deleteAllByQuestionId($myCoachQuestion->id);
|
- |
|
580 |
$myCoachAnswerMapper->deleteAllByQuestionId($myCoachQuestion->id);
|
523 |
$myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
|
581 |
|
524 |
$myCoachAnswerMapper->deleteAllByQuestionId($myCoachQuestion->id);
|
582 |
$result = $myCoachQuestionMapper->delete($myCoachQuestion);
|
- |
|
583 |
if ($result) {
|
- |
|
584 |
$this->logger->info('Se elimino la pregunta ' . $myCoachQuestion->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
525 |
|
585 |
|
- |
|
586 |
$data = [
|
526 |
$result = $myCoachQuestionMapper->delete($myCoachQuestion);
|
587 |
'success' => true,
|
527 |
if ($result) {
|
588 |
'data' => [
|
528 |
$data = [
|
- |
|
529 |
'success' => true,
|
589 |
'question' => $questionData,
|
530 |
'data' => 'LABEL_RECORD_DELETED'
|
590 |
'message' => 'LABEL_RECORD_DELETED'
|
531 |
];
|
591 |
]
|
532 |
} else {
|
592 |
];
|