This commit is contained in:
parent
3c7fa1b8a4
commit
a8409f2bbe
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Controller\QA;
|
namespace App\Controller\QA;
|
||||||
|
|
||||||
use App\Entity\Answer;
|
use App\Entity\Answer;
|
||||||
|
use App\Entity\Attachment;
|
||||||
use App\Entity\Question;
|
use App\Entity\Question;
|
||||||
use App\Entity\QuestionTag;
|
use App\Entity\QuestionTag;
|
||||||
use App\Entity\QuestionTagRelation;
|
use App\Entity\QuestionTagRelation;
|
||||||
|
|
@ -136,9 +137,24 @@ class QAController extends AbstractController
|
||||||
$form = $this->createForm(QuestionFormType::class, $question);
|
$form = $this->createForm(QuestionFormType::class, $question);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
error_log('=== FORM DEBUG ===');
|
||||||
|
error_log('Form isSubmitted: ' . ($form->isSubmitted() ? 'true' : 'false'));
|
||||||
|
error_log('Form isValid: ' . ($form->isSubmitted() ? ($form->isValid() ? 'true' : 'false') : 'not checked'));
|
||||||
|
error_log('Request method: ' . $request->getMethod());
|
||||||
|
error_log('Request files count: ' . count($request->files->all()));
|
||||||
|
error_log('Form name: ' . $form->getName());
|
||||||
|
error_log('Form block prefix: ' . $form->getConfig()->getType()->getBlockPrefix());
|
||||||
|
error_log('Request data keys: ' . implode(', ', array_keys($request->request->all())));
|
||||||
|
error_log('=== END FORM DEBUG ===');
|
||||||
|
|
||||||
if ($form->isSubmitted()) {
|
if ($form->isSubmitted()) {
|
||||||
|
error_log('=== FORM SUBMITTED ===');
|
||||||
|
error_log('Request method: ' . $request->getMethod());
|
||||||
|
error_log('Content type: ' . $request->headers->get('Content-Type'));
|
||||||
|
error_log('Request files count: ' . count($request->files->all()));
|
||||||
|
error_log('Request data: ' . print_r($request->request->all(), true));
|
||||||
|
error_log('Request files: ' . print_r($request->files->all(), true));
|
||||||
|
|
||||||
// بررسی CSRF token - حذف شده چون Symfony خودش بررسی میکند
|
// بررسی CSRF token - حذف شده چون Symfony خودش بررسی میکند
|
||||||
// if (!$this->isCsrfTokenValid('question', $request->request->get('_token'))) {
|
// if (!$this->isCsrfTokenValid('question', $request->request->get('_token'))) {
|
||||||
// $this->addFlash('error', 'CSRF token نامعتبر است.');
|
// $this->addFlash('error', 'CSRF token نامعتبر است.');
|
||||||
|
|
@ -165,7 +181,13 @@ class QAController extends AbstractController
|
||||||
|
|
||||||
// اگر form valid نیست، خطاها را نمایش بده
|
// اگر form valid نیست، خطاها را نمایش بده
|
||||||
if (!$form->isValid()) {
|
if (!$form->isValid()) {
|
||||||
$this->addFlash('error', 'لطفاً تمام فیلدهای الزامی را پر کنید');
|
$errors = [];
|
||||||
|
foreach ($form->getErrors(true) as $error) {
|
||||||
|
$errors[] = $error->getMessage();
|
||||||
|
}
|
||||||
|
error_log('Form validation errors: ' . implode(', ', $errors));
|
||||||
|
|
||||||
|
$this->addFlash('error', 'لطفاً خطاهای فرم را برطرف کنید: ' . implode(', ', $errors));
|
||||||
$availableTags = $this->tagRepository->findActiveTags();
|
$availableTags = $this->tagRepository->findActiveTags();
|
||||||
return $this->render('qa/ask_question.html.twig', [
|
return $this->render('qa/ask_question.html.twig', [
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
|
|
@ -174,33 +196,223 @@ class QAController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
// مدیریت پیوست فایلها
|
// مدیریت پیوست فایلها
|
||||||
|
error_log('=== STARTING FILE PROCESSING ===');
|
||||||
$attachments = $form->get('attachments')->getData();
|
$attachments = $form->get('attachments')->getData();
|
||||||
error_log('Attachments from form: ' . print_r($attachments, true));
|
error_log('Attachments from form: ' . print_r($attachments, true));
|
||||||
|
error_log('Form attachments type: ' . gettype($attachments));
|
||||||
|
error_log('Form attachments count: ' . (is_array($attachments) ? count($attachments) : 'not array'));
|
||||||
|
|
||||||
// بررسی فایلهای ارسال شده در request
|
// بررسی فایلهای ارسال شده در request
|
||||||
$uploadedFiles = $request->files->get('question_form')['attachments'] ?? [];
|
$uploadedFiles = $request->files->get('question_form')['attachments'] ?? [];
|
||||||
error_log('Uploaded files from request: ' . print_r($uploadedFiles, true));
|
error_log('Uploaded files from request: ' . print_r($uploadedFiles, true));
|
||||||
|
error_log('Uploaded files type: ' . gettype($uploadedFiles));
|
||||||
|
error_log('Uploaded files count: ' . (is_array($uploadedFiles) ? count($uploadedFiles) : 'not array'));
|
||||||
|
|
||||||
if ($attachments && count($attachments) > 0) {
|
// بررسی فایلهای ارسال شده در request به صورت مستقیم
|
||||||
error_log('Processing ' . count($attachments) . ' attachments from form');
|
$uploadedFilesDirect = $request->files->get('question_form');
|
||||||
$uploadedAttachments = $this->attachmentService->uploadAttachments($attachments, $this->getUser(), $question);
|
error_log('Question form files structure: ' . print_r($uploadedFilesDirect, true));
|
||||||
error_log('Uploaded attachments: ' . print_r($uploadedAttachments, true));
|
if (isset($uploadedFilesDirect['attachments'])) {
|
||||||
|
$uploadedFiles = $uploadedFilesDirect['attachments'];
|
||||||
foreach ($uploadedAttachments as $attachment) {
|
error_log('Uploaded files from request (direct): ' . print_r($uploadedFiles, true));
|
||||||
$question->addAttachment($attachment);
|
error_log('Direct uploaded files type: ' . gettype($uploadedFiles));
|
||||||
error_log('Added attachment to question: ' . $attachment->getOriginalFilename());
|
error_log('Direct uploaded files count: ' . (is_array($uploadedFiles) ? count($uploadedFiles) : 'not array'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// بررسی مستقیم فایلهای attachments
|
||||||
|
$directFiles = $request->files->get('attachments') ?? [];
|
||||||
|
error_log('Direct files from request: ' . print_r($directFiles, true));
|
||||||
|
error_log('Direct files type: ' . gettype($directFiles));
|
||||||
|
error_log('Direct files count: ' . (is_array($directFiles) ? count($directFiles) : 'not array'));
|
||||||
|
|
||||||
|
// بررسی فایلهای درون question_form
|
||||||
|
$questionFormFiles = $request->files->get('question_form') ?? [];
|
||||||
|
error_log('Question form files: ' . print_r($questionFormFiles, true));
|
||||||
|
error_log('Question form files type: ' . gettype($questionFormFiles));
|
||||||
|
error_log('Question form files count: ' . (is_array($questionFormFiles) ? count($questionFormFiles) : 'not array'));
|
||||||
|
|
||||||
|
// بررسی تمام فایلهای ارسال شده در request
|
||||||
|
$allFiles = $request->files->all();
|
||||||
|
error_log('All files in request: ' . print_r($allFiles, true));
|
||||||
|
error_log('All files type: ' . gettype($allFiles));
|
||||||
|
error_log('All files count: ' . (is_array($allFiles) ? count($allFiles) : 'not array'));
|
||||||
|
|
||||||
|
// بررسی دقیقتر ساختار فایلها
|
||||||
|
foreach ($allFiles as $key => $value) {
|
||||||
|
error_log("File key: $key, type: " . gettype($value));
|
||||||
|
if (is_array($value)) {
|
||||||
|
foreach ($value as $subKey => $subValue) {
|
||||||
|
error_log(" Sub key: $subKey, type: " . gettype($subValue));
|
||||||
|
if (is_array($subValue)) {
|
||||||
|
foreach ($subValue as $subSubKey => $subSubValue) {
|
||||||
|
error_log(" Sub sub key: $subSubKey, type: " . gettype($subSubValue));
|
||||||
|
if ($subSubValue instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||||
|
error_log(" Found UploadedFile: " . $subSubValue->getClientOriginalName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($subValue instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||||
|
error_log(" Found UploadedFile: " . $subValue->getClientOriginalName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($value instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||||
|
error_log(" Found UploadedFile: " . $value->getClientOriginalName());
|
||||||
}
|
}
|
||||||
} elseif ($uploadedFiles && count($uploadedFiles) > 0) {
|
}
|
||||||
error_log('Processing ' . count($uploadedFiles) . ' files from request');
|
|
||||||
$uploadedAttachments = $this->attachmentService->uploadAttachments($uploadedFiles, $this->getUser(), $question);
|
$filesToProcess = [];
|
||||||
error_log('Uploaded attachments from request: ' . print_r($uploadedAttachments, true));
|
error_log('=== DETERMINING FILES TO PROCESS ===');
|
||||||
|
|
||||||
|
// اولویت با فایلهای form
|
||||||
|
if ($attachments && count($attachments) > 0) {
|
||||||
|
$filesToProcess = $attachments;
|
||||||
|
error_log('Using attachments from form: ' . count($attachments));
|
||||||
|
}
|
||||||
|
// سپس فایلهای request
|
||||||
|
elseif ($uploadedFiles && count($uploadedFiles) > 0) {
|
||||||
|
$filesToProcess = $uploadedFiles;
|
||||||
|
error_log('Using files from request: ' . count($uploadedFiles));
|
||||||
|
}
|
||||||
|
// سپس فایلهای مستقیم
|
||||||
|
elseif ($directFiles && count($directFiles) > 0) {
|
||||||
|
$filesToProcess = $directFiles;
|
||||||
|
error_log('Using direct files: ' . count($directFiles));
|
||||||
|
}
|
||||||
|
// سپس فایلهای درون question_form
|
||||||
|
elseif (!empty($questionFormFiles) && isset($questionFormFiles['attachments'])) {
|
||||||
|
$filesToProcess = $questionFormFiles['attachments'];
|
||||||
|
error_log('Using files from question_form: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
// در نهایت بررسی تمام فایلهای ارسال شده
|
||||||
|
elseif (!empty($allFiles)) {
|
||||||
|
foreach ($allFiles as $fieldName => $fieldFiles) {
|
||||||
|
error_log("Processing field: $fieldName");
|
||||||
|
if (is_array($fieldFiles)) {
|
||||||
|
foreach ($fieldFiles as $file) {
|
||||||
|
if ($file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||||
|
$filesToProcess[] = $file;
|
||||||
|
error_log("Added file from allFiles: " . $file->getClientOriginalName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($fieldFiles instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||||
|
$filesToProcess[] = $fieldFiles;
|
||||||
|
error_log("Added file from allFiles: " . $fieldFiles->getClientOriginalName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
error_log('Using files from all request: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log('Final files to process count: ' . count($filesToProcess));
|
||||||
|
error_log('Files to process: ' . print_r($filesToProcess, true));
|
||||||
|
|
||||||
|
// اگر هنوز فایلی پیدا نشده، بررسی دقیقتر
|
||||||
|
if (empty($filesToProcess)) {
|
||||||
|
error_log('=== NO FILES FOUND, CHECKING REQUEST STRUCTURE ===');
|
||||||
|
$requestData = $request->request->all();
|
||||||
|
$filesData = $request->files->all();
|
||||||
|
error_log('Request data: ' . print_r($requestData, true));
|
||||||
|
error_log('Files data: ' . print_r($filesData, true));
|
||||||
|
|
||||||
foreach ($uploadedAttachments as $attachment) {
|
// بررسی فایلهای درون question_form
|
||||||
$question->addAttachment($attachment);
|
if (isset($filesData['question_form']['attachments'])) {
|
||||||
error_log('Added attachment to question: ' . $attachment->getOriginalFilename());
|
$filesToProcess = $filesData['question_form']['attachments'];
|
||||||
|
error_log('Found files in question_form[attachments]: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
|
||||||
|
// بررسی فایلهای درون question_form به صورت مستقیم
|
||||||
|
if (empty($filesToProcess) && isset($filesData['question_form'])) {
|
||||||
|
$questionFormData = $filesData['question_form'];
|
||||||
|
if (isset($questionFormData['attachments'])) {
|
||||||
|
$filesToProcess = $questionFormData['attachments'];
|
||||||
|
error_log('Found files in question_form directly: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// بررسی فایلهای درون attachments
|
||||||
|
if (empty($filesToProcess) && isset($filesData['attachments'])) {
|
||||||
|
$filesToProcess = $filesData['attachments'];
|
||||||
|
error_log('Found files in attachments directly: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log('Final files to process after detailed check: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
|
||||||
|
// اگر هنوز فایلی پیدا نشده، بررسی دقیقتر
|
||||||
|
if (empty($filesToProcess)) {
|
||||||
|
error_log('=== NO FILES FOUND, CHECKING REQUEST STRUCTURE ===');
|
||||||
|
$requestData = $request->request->all();
|
||||||
|
$filesData = $request->files->all();
|
||||||
|
error_log('Request data: ' . print_r($requestData, true));
|
||||||
|
error_log('Files data: ' . print_r($filesData, true));
|
||||||
|
|
||||||
|
// بررسی فایلهای درون question_form
|
||||||
|
if (isset($filesData['question_form']['attachments'])) {
|
||||||
|
$filesToProcess = $filesData['question_form']['attachments'];
|
||||||
|
error_log('Found files in question_form[attachments]: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
|
||||||
|
// بررسی فایلهای درون question_form به صورت مستقیم
|
||||||
|
if (empty($filesToProcess) && isset($filesData['question_form'])) {
|
||||||
|
$questionFormData = $filesData['question_form'];
|
||||||
|
if (isset($questionFormData['attachments'])) {
|
||||||
|
$filesToProcess = $questionFormData['attachments'];
|
||||||
|
error_log('Found files in question_form directly: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// بررسی فایلهای درون attachments
|
||||||
|
if (empty($filesToProcess) && isset($filesData['attachments'])) {
|
||||||
|
$filesToProcess = $filesData['attachments'];
|
||||||
|
error_log('Found files in attachments directly: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log('Final files to process after detailed check: ' . count($filesToProcess));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($filesToProcess)) {
|
||||||
|
error_log('=== PROCESSING FILES ===');
|
||||||
|
error_log('Processing ' . count($filesToProcess) . ' files');
|
||||||
|
|
||||||
|
// فیلتر کردن فایلهای معتبر
|
||||||
|
$validFiles = [];
|
||||||
|
foreach ($filesToProcess as $index => $file) {
|
||||||
|
error_log("Processing file $index: " . gettype($file));
|
||||||
|
if ($file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||||
|
error_log("File $index is UploadedFile: " . $file->getClientOriginalName());
|
||||||
|
error_log("File $index error code: " . $file->getError());
|
||||||
|
error_log("File $index size: " . $file->getSize());
|
||||||
|
error_log("File $index MIME type: " . $file->getMimeType());
|
||||||
|
|
||||||
|
if ($file->getError() === UPLOAD_ERR_OK) {
|
||||||
|
$validFiles[] = $file;
|
||||||
|
error_log('Valid file found: ' . $file->getClientOriginalName() . ' (size: ' . $file->getSize() . ')');
|
||||||
|
} else {
|
||||||
|
error_log('Invalid file: ' . $file->getClientOriginalName() . ' (error: ' . $file->getError() . ')');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error_log('Invalid file type: ' . gettype($file) . ' (error: ' . ($file->getError() ?? 'unknown') . ')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log('Valid files count: ' . count($validFiles));
|
||||||
|
|
||||||
|
if (!empty($validFiles)) {
|
||||||
|
error_log('=== UPLOADING ATTACHMENTS ===');
|
||||||
|
$uploadedAttachments = $this->attachmentService->uploadAttachments($validFiles, $this->getUser(), $question);
|
||||||
|
error_log('Uploaded attachments count: ' . count($uploadedAttachments));
|
||||||
|
error_log('Uploaded attachments: ' . print_r($uploadedAttachments, true));
|
||||||
|
|
||||||
|
foreach ($uploadedAttachments as $attachment) {
|
||||||
|
$question->addAttachment($attachment);
|
||||||
|
error_log('Added attachment to question: ' . $attachment->getOriginalFilename());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ذخیره تغییرات در دیتابیس
|
||||||
|
$this->entityManager->flush();
|
||||||
|
error_log('Question attachments saved to database');
|
||||||
|
} else {
|
||||||
|
error_log('No valid files found to process');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error_log('No attachments found in form data or request');
|
error_log('No attachments found in any source');
|
||||||
}
|
}
|
||||||
|
|
||||||
// حذف تمام تگهای قبلی برای این سوال
|
// حذف تمام تگهای قبلی برای این سوال
|
||||||
|
|
@ -232,6 +444,16 @@ class QAController extends AbstractController
|
||||||
$this->entityManager->persist($question);
|
$this->entityManager->persist($question);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
error_log('Question saved with ID: ' . $question->getId());
|
||||||
|
error_log('Question attachments count after save: ' . $question->getAttachments()->count());
|
||||||
|
|
||||||
|
// بررسی فایلهای ضمیمه در دیتابیس
|
||||||
|
$attachmentsInDb = $this->entityManager->getRepository(\App\Entity\Attachment::class)->findBy(['question' => $question]);
|
||||||
|
error_log('Attachments found in database for question ' . $question->getId() . ': ' . count($attachmentsInDb));
|
||||||
|
foreach ($attachmentsInDb as $attachment) {
|
||||||
|
error_log('Database attachment: ' . $attachment->getOriginalFilename() . ' (ID: ' . $attachment->getId() . ')');
|
||||||
|
}
|
||||||
|
|
||||||
$this->addFlash('success', 'سوال شما با موفقیت ثبت شد.');
|
$this->addFlash('success', 'سوال شما با موفقیت ثبت شد.');
|
||||||
return $this->redirectToRoute('qa_question_show', ['id' => $question->getId()]);
|
return $this->redirectToRoute('qa_question_show', ['id' => $question->getId()]);
|
||||||
}
|
}
|
||||||
|
|
@ -261,7 +483,23 @@ class QAController extends AbstractController
|
||||||
$form = $this->createForm(AnswerFormType::class, $answer);
|
$form = $this->createForm(AnswerFormType::class, $answer);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted()) {
|
||||||
|
// بررسی اعتبارسنجی
|
||||||
|
if (!$form->isValid()) {
|
||||||
|
$errors = [];
|
||||||
|
foreach ($form->getErrors(true) as $error) {
|
||||||
|
$errors[] = $error->getMessage();
|
||||||
|
}
|
||||||
|
error_log('Form validation errors: ' . implode(', ', $errors));
|
||||||
|
|
||||||
|
// نمایش خطاها به کاربر
|
||||||
|
$this->addFlash('error', 'لطفاً خطاهای فرم را برطرف کنید: ' . implode(', ', $errors));
|
||||||
|
|
||||||
|
return $this->render('qa/ask_question.html.twig', [
|
||||||
|
'form' => $form->createView(),
|
||||||
|
'tags' => $this->entityManager->getRepository(QuestionTag::class)->findBy(['isActive' => true])
|
||||||
|
]);
|
||||||
|
}
|
||||||
// مدیریت پیوست فایلها
|
// مدیریت پیوست فایلها
|
||||||
$attachments = $form->get('attachments')->getData();
|
$attachments = $form->get('attachments')->getData();
|
||||||
if ($attachments) {
|
if ($attachments) {
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,8 @@ class QuestionFormType extends AbstractType
|
||||||
'attr' => [
|
'attr' => [
|
||||||
'class' => 'form-control',
|
'class' => 'form-control',
|
||||||
'accept' => '.jpg,.jpeg,.png,.gif,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt',
|
'accept' => '.jpg,.jpeg,.png,.gif,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt',
|
||||||
'multiple' => true
|
'multiple' => true,
|
||||||
|
'name' => 'question_form[attachments][]'
|
||||||
],
|
],
|
||||||
'constraints' => [
|
'constraints' => [
|
||||||
new Assert\Count([
|
new Assert\Count([
|
||||||
|
|
@ -129,4 +130,9 @@ class QuestionFormType extends AbstractType
|
||||||
'data_class' => Question::class,
|
'data_class' => Question::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBlockPrefix(): string
|
||||||
|
{
|
||||||
|
return 'question_form';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,36 @@ class AttachmentService
|
||||||
{
|
{
|
||||||
$attachments = [];
|
$attachments = [];
|
||||||
|
|
||||||
foreach ($uploadedFiles as $uploadedFile) {
|
error_log('=== ATTACHMENT SERVICE START ===');
|
||||||
|
error_log('AttachmentService: Processing ' . count($uploadedFiles) . ' files');
|
||||||
|
error_log('AttachmentService: User ID: ' . $user->getId());
|
||||||
|
error_log('AttachmentService: Question ID: ' . ($question ? $question->getId() : 'null'));
|
||||||
|
error_log('AttachmentService: Answer ID: ' . ($answer ? $answer->getId() : 'null'));
|
||||||
|
|
||||||
|
foreach ($uploadedFiles as $index => $uploadedFile) {
|
||||||
|
error_log("AttachmentService: Processing file $index");
|
||||||
|
error_log("AttachmentService: File type: " . gettype($uploadedFile));
|
||||||
|
|
||||||
if ($uploadedFile instanceof UploadedFile) {
|
if ($uploadedFile instanceof UploadedFile) {
|
||||||
|
error_log("AttachmentService: File $index is UploadedFile: " . $uploadedFile->getClientOriginalName());
|
||||||
|
error_log("AttachmentService: File $index error code: " . $uploadedFile->getError());
|
||||||
|
error_log("AttachmentService: File $index size: " . $uploadedFile->getSize());
|
||||||
|
error_log("AttachmentService: File $index MIME type: " . $uploadedFile->getMimeType());
|
||||||
|
|
||||||
$attachment = $this->uploadSingleFile($uploadedFile, $user, $question, $answer);
|
$attachment = $this->uploadSingleFile($uploadedFile, $user, $question, $answer);
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
$attachments[] = $attachment;
|
$attachments[] = $attachment;
|
||||||
|
error_log("AttachmentService: Successfully created attachment for file $index: " . $attachment->getOriginalFilename());
|
||||||
|
} else {
|
||||||
|
error_log("AttachmentService: Failed to create attachment for file $index: " . $uploadedFile->getClientOriginalName());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
error_log("AttachmentService: File $index is not UploadedFile: " . gettype($uploadedFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log('AttachmentService: Total attachments created: ' . count($attachments));
|
||||||
|
error_log('=== ATTACHMENT SERVICE END ===');
|
||||||
return $attachments;
|
return $attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,13 +72,36 @@ class AttachmentService
|
||||||
*/
|
*/
|
||||||
public function uploadSingleFile(UploadedFile $file, User $user, ?Question $question = null, ?Answer $answer = null): ?Attachment
|
public function uploadSingleFile(UploadedFile $file, User $user, ?Question $question = null, ?Answer $answer = null): ?Attachment
|
||||||
{
|
{
|
||||||
|
error_log('=== UPLOAD SINGLE FILE START ===');
|
||||||
|
error_log('AttachmentService: Starting upload for: ' . $file->getClientOriginalName());
|
||||||
|
error_log('AttachmentService: File size: ' . $file->getSize());
|
||||||
|
error_log('AttachmentService: File MIME type: ' . $file->getMimeType());
|
||||||
|
error_log('AttachmentService: File error code: ' . $file->getError());
|
||||||
|
|
||||||
|
// بررسی خطای آپلود
|
||||||
|
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||||
|
error_log('AttachmentService: Upload error: ' . $file->getError());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
|
$originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
|
||||||
$safeFilename = $this->slugger->slug($originalFilename);
|
$safeFilename = $this->slugger->slug($originalFilename);
|
||||||
$fileName = $safeFilename . '-' . uniqid() . '.' . $file->guessExtension();
|
$fileName = $safeFilename . '-' . uniqid() . '.' . $file->guessExtension();
|
||||||
|
|
||||||
|
error_log('AttachmentService: Target directory: ' . $this->targetDirectory);
|
||||||
|
error_log('AttachmentService: Generated filename: ' . $fileName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// اطمینان از وجود دایرکتوری
|
||||||
|
if (!is_dir($this->targetDirectory)) {
|
||||||
|
mkdir($this->targetDirectory, 0755, true);
|
||||||
|
error_log('AttachmentService: Created directory: ' . $this->targetDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
$file->move($this->targetDirectory, $fileName);
|
$file->move($this->targetDirectory, $fileName);
|
||||||
|
error_log('AttachmentService: File moved successfully');
|
||||||
} catch (FileException $e) {
|
} catch (FileException $e) {
|
||||||
|
error_log('AttachmentService: File move failed: ' . $e->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,14 +115,18 @@ class AttachmentService
|
||||||
|
|
||||||
if ($question) {
|
if ($question) {
|
||||||
$attachment->setQuestion($question);
|
$attachment->setQuestion($question);
|
||||||
|
error_log('AttachmentService: Set question ID: ' . $question->getId());
|
||||||
}
|
}
|
||||||
if ($answer) {
|
if ($answer) {
|
||||||
$attachment->setAnswer($answer);
|
$attachment->setAnswer($answer);
|
||||||
|
error_log('AttachmentService: Set answer ID: ' . $answer->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->entityManager->persist($attachment);
|
$this->entityManager->persist($attachment);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
error_log('AttachmentService: Attachment entity created and saved with ID: ' . $attachment->getId());
|
||||||
|
error_log('=== UPLOAD SINGLE FILE END ===');
|
||||||
return $attachment;
|
return $attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center lg:text-right">
|
<div class="text-center lg:text-right">
|
||||||
<div class="text-3xl md:text-4xl font-bold text-red-600 mb-1 counter" data-target="43">0</div>
|
<div class="text-3xl md:text-4xl font-bold text-red-600 mb-1 counter" data-target="43">0</div>
|
||||||
<div class="text-gray-600">کسب و کار فعال</div>
|
<div class="text-gray-600">هزار کسبوکار</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -625,13 +625,20 @@
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
const target = parseInt(entry.target.dataset.target);
|
const target = parseInt(entry.target.dataset.target);
|
||||||
animateCounter(entry.target, target);
|
// بررسی اینکه آیا شمارنده قبلاً انیمیشن شده یا نه
|
||||||
|
if (!entry.target.classList.contains('animated')) {
|
||||||
|
entry.target.classList.add('animated');
|
||||||
|
animateCounter(entry.target, target);
|
||||||
|
}
|
||||||
observer.unobserve(entry.target);
|
observer.unobserve(entry.target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, { threshold: 0.5 });
|
}, { threshold: 0.5 });
|
||||||
|
|
||||||
counters.forEach(counter => {
|
counters.forEach(counter => {
|
||||||
|
// ریست کردن شمارنده به صفر
|
||||||
|
counter.textContent = '0';
|
||||||
|
counter.classList.remove('animated');
|
||||||
observer.observe(counter);
|
observer.observe(counter);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -683,12 +690,21 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// اجرا پس از بارگذاری صفحه
|
// تابع اصلی برای اجرای انیمیشنها
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
function initHomeAnimations() {
|
||||||
handleScrollAnimation();
|
handleScrollAnimation();
|
||||||
animateSteps();
|
animateSteps();
|
||||||
animateFloatingElements();
|
animateFloatingElements();
|
||||||
initHoverEffects();
|
initHoverEffects();
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// اجرا پس از بارگذاری صفحه
|
||||||
|
document.addEventListener('DOMContentLoaded', initHomeAnimations);
|
||||||
|
|
||||||
|
// اجرا پس از تغییر صفحه با Turbo
|
||||||
|
document.addEventListener('turbo:load', initHomeAnimations);
|
||||||
|
|
||||||
|
// اجرا پس از بازگشت به صفحه با Turbo
|
||||||
|
document.addEventListener('turbo:render', initHomeAnimations);
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -1020,21 +1020,80 @@ window.QuestionFormClasses.FileManager = class FileManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('=== UPDATING FILE INPUT ===');
|
||||||
|
console.log('Selected files count:', this.selectedFiles.length);
|
||||||
|
console.log('Selected files:', this.selectedFiles);
|
||||||
|
|
||||||
// تنظیم فایلها در input اصلی
|
// تنظیم فایلها در input اصلی
|
||||||
try {
|
try {
|
||||||
const dt = new DataTransfer();
|
// ایجاد یک input جدید برای هر فایل
|
||||||
this.selectedFiles.forEach(fileData => {
|
const form = this.fileInput.closest('form');
|
||||||
dt.items.add(fileData.file);
|
if (form) {
|
||||||
});
|
console.log('Form found:', form);
|
||||||
this.fileInput.files = dt.files;
|
|
||||||
|
// حذف input های قبلی
|
||||||
|
const existingInputs = form.querySelectorAll('input[type="file"][name*="attachments"]');
|
||||||
|
console.log('Existing inputs count:', existingInputs.length);
|
||||||
|
existingInputs.forEach(input => {
|
||||||
|
if (input !== this.fileInput) {
|
||||||
|
input.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// اضافه کردن فایلها به input اصلی
|
||||||
|
if (this.selectedFiles.length > 0) {
|
||||||
|
console.log('Adding files to input...');
|
||||||
|
|
||||||
|
// استفاده از DataTransfer اگر پشتیبانی شود
|
||||||
|
if (typeof DataTransfer !== 'undefined') {
|
||||||
|
console.log('Using DataTransfer API');
|
||||||
|
const dt = new DataTransfer();
|
||||||
|
this.selectedFiles.forEach((fileData, index) => {
|
||||||
|
console.log(`Adding file ${index}:`, fileData.file.name);
|
||||||
|
dt.items.add(fileData.file);
|
||||||
|
});
|
||||||
|
this.fileInput.files = dt.files;
|
||||||
|
console.log('DataTransfer files count:', this.fileInput.files.length);
|
||||||
|
} else {
|
||||||
|
console.log('Using alternative method');
|
||||||
|
// روش جایگزین: ایجاد input های جداگانه
|
||||||
|
this.selectedFiles.forEach((fileData, index) => {
|
||||||
|
console.log(`Creating input for file ${index}:`, fileData.file.name);
|
||||||
|
const newInput = document.createElement('input');
|
||||||
|
newInput.type = 'file';
|
||||||
|
newInput.name = 'question_form[attachments][]';
|
||||||
|
newInput.style.display = 'none';
|
||||||
|
|
||||||
|
// ایجاد FileList جدید
|
||||||
|
const fileList = new DataTransfer();
|
||||||
|
fileList.items.add(fileData.file);
|
||||||
|
newInput.files = fileList.files;
|
||||||
|
|
||||||
|
form.appendChild(newInput);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('No files to add');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('Form not found');
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Updated file input with', this.selectedFiles.length, 'files');
|
console.log('Updated file input with', this.selectedFiles.length, 'files');
|
||||||
console.log('File input files:', this.fileInput.files.length);
|
console.log('File input files:', this.fileInput.files.length);
|
||||||
|
|
||||||
|
// بررسی نهایی فایلها
|
||||||
|
for (let i = 0; i < this.fileInput.files.length; i++) {
|
||||||
|
console.log(`Final file ${i}:`, this.fileInput.files[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('DataTransfer not supported:', e);
|
console.error('Error updating file input:', e);
|
||||||
// در صورت عدم پشتیبانی، فایلها را در متغیر سراسری ذخیره میکنیم
|
// در صورت خطا، فایلها را در متغیر سراسری ذخیره میکنیم
|
||||||
window.selectedFiles = this.selectedFiles;
|
window.selectedFiles = this.selectedFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('=== FILE INPUT UPDATE COMPLETE ===');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1100,13 +1159,17 @@ function initializeQuestionForm() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFormSubmit(e) {
|
function handleFormSubmit(e) {
|
||||||
|
console.log('=== FORM SUBMIT START ===');
|
||||||
|
|
||||||
// اطمینان از اینکه تگها به فرم اضافه شدهاند
|
// اطمینان از اینکه تگها به فرم اضافه شدهاند
|
||||||
if (window.questionFormManager.tagManager) {
|
if (window.questionFormManager.tagManager) {
|
||||||
|
console.log('Updating tag manager...');
|
||||||
// ابتدا تگها را به فرم اضافه کن
|
// ابتدا تگها را به فرم اضافه کن
|
||||||
window.questionFormManager.tagManager.updateHiddenInput();
|
window.questionFormManager.tagManager.updateHiddenInput();
|
||||||
|
|
||||||
// اعتبارسنجی تگها
|
// اعتبارسنجی تگها
|
||||||
if (!window.questionFormManager.tagManager.validateTags()) {
|
if (!window.questionFormManager.tagManager.validateTags()) {
|
||||||
|
console.log('Tag validation failed');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1115,7 +1178,17 @@ function handleFormSubmit(e) {
|
||||||
|
|
||||||
// اطمینان از اینکه فایلها به فرم اضافه شدهاند
|
// اطمینان از اینکه فایلها به فرم اضافه شدهاند
|
||||||
if (window.questionFormManager.fileManager) {
|
if (window.questionFormManager.fileManager) {
|
||||||
|
console.log('Updating file manager...');
|
||||||
window.questionFormManager.fileManager.updateFileInput();
|
window.questionFormManager.fileManager.updateFileInput();
|
||||||
|
|
||||||
|
// بررسی نهایی فایلها
|
||||||
|
const fileInput = e.target.querySelector('input[type="file"]');
|
||||||
|
if (fileInput) {
|
||||||
|
console.log('Final file input files:', fileInput.files.length);
|
||||||
|
for (let i = 0; i < fileInput.files.length; i++) {
|
||||||
|
console.log('File', i, ':', fileInput.files[i].name, fileInput.files[i].size);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// غیرفعال کردن Turbo برای این فرم
|
// غیرفعال کردن Turbo برای این فرم
|
||||||
|
|
@ -1131,6 +1204,18 @@ function handleFormSubmit(e) {
|
||||||
if (window.questionFormManager.fileManager) {
|
if (window.questionFormManager.fileManager) {
|
||||||
console.log('Selected files in JavaScript:', window.questionFormManager.fileManager.selectedFiles.length);
|
console.log('Selected files in JavaScript:', window.questionFormManager.fileManager.selectedFiles.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// بررسی تمام فایلهای موجود در فرم
|
||||||
|
const allFileInputs = form.querySelectorAll('input[type="file"]');
|
||||||
|
console.log('All file inputs in form:', allFileInputs.length);
|
||||||
|
allFileInputs.forEach((input, index) => {
|
||||||
|
console.log(`File input ${index}:`, input.name, input.files.length);
|
||||||
|
for (let i = 0; i < input.files.length; i++) {
|
||||||
|
console.log(` File ${i}:`, input.files[i].name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('=== FORM SUBMIT END ===');
|
||||||
}
|
}
|
||||||
|
|
||||||
// اجرا در بارگذاری صفحه
|
// اجرا در بارگذاری صفحه
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue