Línea 657... |
Línea 657... |
657 |
|
657 |
|
Línea -... |
Línea 658... |
- |
|
658 |
|
- |
|
659 |
|
- |
|
660 |
$this->logger->info('Se edito la pregunta ' . $myCoachQuestion->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
- |
|
661 |
|
- |
|
662 |
// Recargar la pregunta actualizada con todos sus datos
|
- |
|
663 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOne($myCoachQuestion->id);
|
- |
|
664 |
|
- |
|
665 |
// Obtener datos adicionales para formato consistente con questionsAction
|
- |
|
666 |
$userMapper = UserMapper::getInstance($this->adapter);
|
- |
|
667 |
$user = $userMapper->fetchOne($currentUser->id);
|
- |
|
668 |
|
- |
|
669 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
- |
|
670 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
- |
|
671 |
$myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
|
- |
|
672 |
$myCoachQuestionViewMapper = MyCoachQuestionViewMapper::getInstance($this->adapter);
|
- |
|
673 |
|
- |
|
674 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
- |
|
675 |
|
- |
|
676 |
// Obtener categorías de la pregunta
|
- |
|
677 |
$bags_categories = [];
|
- |
|
678 |
if(is_array($category_ids)) {
|
- |
|
679 |
foreach($category_ids as $category_id) {
|
- |
|
680 |
$category = $myCoachCategoryMapper->fetchOneByUuid($category_id);
|
- |
|
681 |
if($category) {
|
- |
|
682 |
array_push($bags_categories, $category->name);
|
- |
|
683 |
}
|
- |
|
684 |
}
|
- |
|
685 |
} else {
|
- |
|
686 |
$category = $myCoachCategoryMapper->fetchOneByUuid($category_ids);
|
- |
|
687 |
if($category) {
|
- |
|
688 |
array_push($bags_categories, $category->name);
|
- |
|
689 |
}
|
- |
|
690 |
}
|
- |
|
691 |
|
- |
|
692 |
// Formatear descripción (limitar a 250 caracteres)
|
- |
|
693 |
$description = strip_tags($myCoachQuestion->description);
|
- |
|
694 |
if (strlen($description) > 250) {
|
- |
|
695 |
$description = substr($description, 0, 250) . '...';
|
- |
|
696 |
}
|
- |
|
697 |
|
- |
|
698 |
// Formatear fechas
|
- |
|
699 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $myCoachQuestion->added_on);
|
- |
|
700 |
$added_on = $dt->format('d/m/Y H:i a');
|
- |
|
701 |
|
- |
|
702 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $myCoachQuestion->updated_on);
|
- |
|
703 |
$updated_on = $dt->format('d/m/Y H:i a');
|
- |
|
704 |
|
- |
|
705 |
// Verificar permisos
|
- |
|
706 |
$message_error = '';
|
- |
|
707 |
$allowEdit = $myCoachAccessControl->hasAccessEditQuestion($currentUser->id, $myCoachQuestion->id, $currentNetwork->id, $message_error);
|
- |
|
708 |
$allowDelete = $myCoachAccessControl->hasAccessDeleteQuestion($currentUser->id, $myCoachQuestion->id, $currentNetwork->id, $message_error);
|
- |
|
709 |
|
- |
|
710 |
$questionData = [
|
- |
|
711 |
'uuid' => $myCoachQuestion->uuid,
|
- |
|
712 |
'user_name' => trim($user->first_name . ' ' . $user->last_name),
|
- |
|
713 |
'user_image' => $storage->getUserImage($user),
|
- |
|
714 |
'title' => $myCoachQuestion->title,
|
- |
|
715 |
'description' => $description,
|
- |
|
716 |
'categories' => $bags_categories,
|
- |
|
717 |
'views' => intval($myCoachQuestionViewMapper->fetchCountByQuestionId($myCoachQuestion->id), 10),
|
- |
|
718 |
'answers' => intval($myCoachAnswerMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
|
- |
|
719 |
'reactions' => intval($contentReactionMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
|
- |
|
720 |
'comments' => intval($commentMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id), 10),
|
- |
|
721 |
'added_on' => $added_on,
|
- |
|
722 |
'updated_on' => $updated_on,
|
- |
|
723 |
'link_add_comment' => $this->url()->fromRoute('my-coach/questions/comments/add', ['id' => $myCoachQuestion->uuid],['force_canonical' => true]),
|
- |
|
724 |
'link_view' => $this->url()->fromRoute('my-coach/questions/view', ['id' => $myCoachQuestion->uuid]),
|
- |
|
725 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('my-coach/questions/edit', ['id' => $myCoachQuestion->uuid],['force_canonical' => true]) : '',
|
658 |
|
726 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('my-coach/questions/delete', ['id' => $myCoachQuestion->uuid],['force_canonical' => true]) : '',
|
659 |
|
727 |
'link_reactions' => $this->url()->fromRoute('my-coach/questions/reactions', ['id' => $myCoachQuestion->uuid],['force_canonical' => true])
|
- |
|
728 |
];
|
- |
|
729 |
|
660 |
$this->logger->info('Se edito la pregunta ' . $myCoachQuestion->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
730 |
$data = [
|
- |
|
731 |
'success' => true,
|
661 |
|
732 |
'data' => [
|
662 |
$data = [
|
733 |
'question' => $questionData,
|
663 |
'success' => true,
|
734 |
'message' => 'LABEL_RECORD_UPDATED'
|
664 |
'data' => 'LABEL_RECORD_UPDATED'
|
735 |
]
|
665 |
];
|
736 |
];
|