|
@@ -328,11 +328,46 @@ class Dashboard extends Component
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
// Try with status = 0 first (inactive), then status = 1 (active) as fallback
|
|
// Try with status = 0 first (inactive), then status = 1 (active) as fallback
|
|
|
- $activeCourses = \App\Models\MemberCourse::with(['course', 'member'])
|
|
|
|
|
|
|
+ $activeCourses = \App\Models\MemberCourse::with(['course.level', 'course.frequency', 'member'])
|
|
|
->whereIn('status', [0, 1]) // Include both statuses
|
|
->whereIn('status', [0, 1]) // Include both statuses
|
|
|
->whereRaw('JSON_EXTRACT(`when`, "$[*].day") LIKE ?', ['%"' . $todayName . '"%'])
|
|
->whereRaw('JSON_EXTRACT(`when`, "$[*].day") LIKE ?', ['%"' . $todayName . '"%'])
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
|
|
+ // Fallback: if JSON_EXTRACT doesn't work, get all and filter in PHP
|
|
|
|
|
+ if ($activeCourses->isEmpty()) {
|
|
|
|
|
+ Log::warning('JSON_EXTRACT query returned empty, trying PHP filtering');
|
|
|
|
|
+
|
|
|
|
|
+ $allCourses = \App\Models\MemberCourse::with(['course.level', 'course.frequency', 'member'])
|
|
|
|
|
+ ->whereIn('status', [0, 1])
|
|
|
|
|
+ ->whereNotNull('when')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ $activeCourses = $allCourses->filter(function($memberCourse) use ($todayName) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $whenData = json_decode($memberCourse->when, true);
|
|
|
|
|
+ if (is_array($whenData)) {
|
|
|
|
|
+ foreach($whenData as $schedule) {
|
|
|
|
|
+ if (isset($schedule['day']) && is_array($schedule['day']) && in_array($todayName, $schedule['day'])) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Log::debug('Error parsing when data', [
|
|
|
|
|
+ 'member_course_id' => $memberCourse->id,
|
|
|
|
|
+ 'when' => $memberCourse->when,
|
|
|
|
|
+ 'error' => $e->getMessage()
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ Log::info('PHP filtering results', [
|
|
|
|
|
+ 'total_courses_checked' => $allCourses->count(),
|
|
|
|
|
+ 'matching_courses' => $activeCourses->count()
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Log::info('Raw query for courses', [
|
|
Log::info('Raw query for courses', [
|
|
|
'today_name' => $todayName,
|
|
'today_name' => $todayName,
|
|
|
'query_like' => '%"' . $todayName . '"%',
|
|
'query_like' => '%"' . $todayName . '"%',
|
|
@@ -340,7 +375,7 @@ class Dashboard extends Component
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
// Debug: let's also try a direct query to see what we get
|
|
// Debug: let's also try a direct query to see what we get
|
|
|
- $allMemberCourses = \App\Models\MemberCourse::with(['course'])
|
|
|
|
|
|
|
+ $allMemberCourses = \App\Models\MemberCourse::with(['course.level', 'course.frequency'])
|
|
|
->limit(10)
|
|
->limit(10)
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
@@ -350,6 +385,8 @@ class Dashboard extends Component
|
|
|
'id' => $mc->id,
|
|
'id' => $mc->id,
|
|
|
'course_id' => $mc->course_id,
|
|
'course_id' => $mc->course_id,
|
|
|
'course_name' => $mc->course->name ?? 'No name',
|
|
'course_name' => $mc->course->name ?? 'No name',
|
|
|
|
|
+ 'level_name' => is_object($mc->course->level) ? $mc->course->level->name : 'No level',
|
|
|
|
|
+ 'frequency_name' => is_object($mc->course->frequency) ? $mc->course->frequency->name : 'No frequency',
|
|
|
'status' => $mc->status,
|
|
'status' => $mc->status,
|
|
|
'when' => $mc->when
|
|
'when' => $mc->when
|
|
|
];
|
|
];
|
|
@@ -388,11 +425,32 @@ class Dashboard extends Component
|
|
|
if ($todaySchedule) {
|
|
if ($todaySchedule) {
|
|
|
$days = implode('-', array_map('ucfirst', $todaySchedule['day']));
|
|
$days = implode('-', array_map('ucfirst', $todaySchedule['day']));
|
|
|
|
|
|
|
|
|
|
+ // Get course details
|
|
|
|
|
+ $course = $memberCourse->course;
|
|
|
|
|
+ $courseName = $course->name ?? 'Corso Sconosciuto';
|
|
|
|
|
+ $levelName = is_object($course->level) ? $course->level->name : '';
|
|
|
|
|
+ $frequencyName = is_object($course->frequency) ? $course->frequency->name : '';
|
|
|
|
|
+ $typeName = $course->getFormattedTypeField() ?? '';
|
|
|
|
|
+
|
|
|
|
|
+ // Build full course name similar to getCoursesForSelect
|
|
|
|
|
+ $courseNameParts = [$courseName];
|
|
|
|
|
+ if ($levelName) $courseNameParts[] = $levelName;
|
|
|
|
|
+ if ($typeName) $courseNameParts[] = $typeName;
|
|
|
|
|
+ if ($frequencyName) $courseNameParts[] = $frequencyName;
|
|
|
|
|
+
|
|
|
|
|
+ $fullCourseName = implode(' - ', $courseNameParts);
|
|
|
|
|
+
|
|
|
return [
|
|
return [
|
|
|
'time' => $todaySchedule['from'] . ' - ' . $todaySchedule['to'],
|
|
'time' => $todaySchedule['from'] . ' - ' . $todaySchedule['to'],
|
|
|
- 'course_name' => $memberCourse->course->name ?? 'Corso Sconosciuto',
|
|
|
|
|
|
|
+ 'course_name' => $courseName,
|
|
|
|
|
+ 'full_name' => $fullCourseName,
|
|
|
|
|
+ 'level_name' => $levelName,
|
|
|
|
|
+ 'type_name' => $typeName,
|
|
|
|
|
+ 'frequency_name' => $frequencyName,
|
|
|
'days' => $days,
|
|
'days' => $days,
|
|
|
- 'type' => $memberCourse->course->type ?? 'Standard'
|
|
|
|
|
|
|
+ 'type' => $course->type ?? 'Standard',
|
|
|
|
|
+ 'from_time' => $todaySchedule['from'], // Add for sorting
|
|
|
|
|
+ 'member_course_id' => $memberCourse->id
|
|
|
];
|
|
];
|
|
|
} else {
|
|
} else {
|
|
|
Log::debug('No matching schedule found for today', [
|
|
Log::debug('No matching schedule found for today', [
|
|
@@ -401,15 +459,37 @@ class Dashboard extends Component
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
- })->filter()->values()->toArray();
|
|
|
|
|
|
|
+ })->filter()->values();
|
|
|
|
|
|
|
|
- $this->courses = array_slice($this->courses, 0, 5);
|
|
|
|
|
|
|
+ // Sort by start time (from_time)
|
|
|
|
|
+ $sortedCourses = $this->courses->sortBy('from_time')->values();
|
|
|
|
|
+
|
|
|
|
|
+ // Log the sorted order before removing fields
|
|
|
|
|
+ Log::info('Courses sorted by time', [
|
|
|
|
|
+ 'sorted_courses' => $sortedCourses->map(function($course) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'time' => $course['time'],
|
|
|
|
|
+ 'from_time' => $course['from_time'],
|
|
|
|
|
+ 'course_name' => $course['course_name'],
|
|
|
|
|
+ 'member_course_id' => $course['member_course_id']
|
|
|
|
|
+ ];
|
|
|
|
|
+ })->toArray()
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ // Limit to 5 courses
|
|
|
|
|
+ $this->courses = $sortedCourses->take(5);
|
|
|
|
|
+
|
|
|
|
|
+ // Remove from_time field from final output and convert to array
|
|
|
|
|
+ $this->courses = $this->courses->map(function($course) {
|
|
|
|
|
+ unset($course['from_time'], $course['member_course_id']);
|
|
|
|
|
+ return $course;
|
|
|
|
|
+ })->toArray();
|
|
|
|
|
|
|
|
$endTime = microtime(true);
|
|
$endTime = microtime(true);
|
|
|
Log::info('Courses data loaded successfully', [
|
|
Log::info('Courses data loaded successfully', [
|
|
|
'final_courses_count' => count($this->courses),
|
|
'final_courses_count' => count($this->courses),
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2),
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2),
|
|
|
- 'courses' => $this->courses
|
|
|
|
|
|
|
+ 'final_courses_display' => $this->courses
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
@@ -429,7 +509,7 @@ class Dashboard extends Component
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
// Conta le partecipazioni per corso (include tutti gli status)
|
|
// Conta le partecipazioni per corso (include tutti gli status)
|
|
|
- $courseStats = \App\Models\MemberCourse::with('course')
|
|
|
|
|
|
|
+ $courseStats = \App\Models\MemberCourse::with(['course.level', 'course.frequency'])
|
|
|
->whereIn('status', [0, 1]) // Include both statuses
|
|
->whereIn('status', [0, 1]) // Include both statuses
|
|
|
->selectRaw('course_id, COUNT(*) as participants')
|
|
->selectRaw('course_id, COUNT(*) as participants')
|
|
|
->groupBy('course_id')
|
|
->groupBy('course_id')
|
|
@@ -440,9 +520,15 @@ class Dashboard extends Component
|
|
|
Log::info('Course participation stats', [
|
|
Log::info('Course participation stats', [
|
|
|
'courses_found' => $courseStats->count(),
|
|
'courses_found' => $courseStats->count(),
|
|
|
'stats' => $courseStats->map(function($stat) {
|
|
'stats' => $courseStats->map(function($stat) {
|
|
|
|
|
+ $course = $stat->course;
|
|
|
|
|
+ $levelName = is_object($course->level) ? $course->level->name : '';
|
|
|
|
|
+ $frequencyName = is_object($course->frequency) ? $course->frequency->name : '';
|
|
|
|
|
+
|
|
|
return [
|
|
return [
|
|
|
'course_id' => $stat->course_id,
|
|
'course_id' => $stat->course_id,
|
|
|
- 'course_name' => $stat->course->name ?? 'Unknown',
|
|
|
|
|
|
|
+ 'course_name' => $course->name ?? 'Unknown',
|
|
|
|
|
+ 'level_name' => $levelName,
|
|
|
|
|
+ 'frequency_name' => $frequencyName,
|
|
|
'participants' => $stat->participants
|
|
'participants' => $stat->participants
|
|
|
];
|
|
];
|
|
|
})->toArray()
|
|
})->toArray()
|
|
@@ -452,13 +538,29 @@ class Dashboard extends Component
|
|
|
|
|
|
|
|
$this->coursesParticipation = $courseStats->map(function($stat) use ($totalParticipants) {
|
|
$this->coursesParticipation = $courseStats->map(function($stat) use ($totalParticipants) {
|
|
|
$percentage = $totalParticipants > 0 ? ($stat->participants / $totalParticipants) * 100 : 0;
|
|
$percentage = $totalParticipants > 0 ? ($stat->participants / $totalParticipants) * 100 : 0;
|
|
|
- $courseName = $stat->course->name ?? 'Corso Sconosciuto';
|
|
|
|
|
|
|
+ $course = $stat->course;
|
|
|
|
|
+ $courseName = $course->name ?? 'Corso Sconosciuto';
|
|
|
|
|
+ $levelName = is_object($course->level) ? $course->level->name : '';
|
|
|
|
|
+ $frequencyName = is_object($course->frequency) ? $course->frequency->name : '';
|
|
|
|
|
+ $typeName = $course->getFormattedTypeField() ?? '';
|
|
|
|
|
+
|
|
|
|
|
+ // Build display name with level and frequency
|
|
|
|
|
+ $displayNameParts = [$courseName];
|
|
|
|
|
+ if ($levelName) $displayNameParts[] = $levelName;
|
|
|
|
|
+ if ($typeName) $displayNameParts[] = $typeName;
|
|
|
|
|
+ if ($frequencyName) $displayNameParts[] = $frequencyName;
|
|
|
|
|
+
|
|
|
|
|
+ $displayName = implode(' - ', $displayNameParts);
|
|
|
|
|
|
|
|
// Assegna colori basati sul nome del corso
|
|
// Assegna colori basati sul nome del corso
|
|
|
$color = $this->getCourseColor($courseName);
|
|
$color = $this->getCourseColor($courseName);
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
- 'course_name' => $courseName,
|
|
|
|
|
|
|
+ 'course_name' => $displayName,
|
|
|
|
|
+ 'base_course_name' => $courseName,
|
|
|
|
|
+ 'level_name' => $levelName,
|
|
|
|
|
+ 'type_name' => $typeName,
|
|
|
|
|
+ 'frequency_name' => $frequencyName,
|
|
|
'participants' => $stat->participants,
|
|
'participants' => $stat->participants,
|
|
|
'percentage' => round($percentage, 1),
|
|
'percentage' => round($percentage, 1),
|
|
|
'color' => $color
|
|
'color' => $color
|
|
@@ -484,25 +586,36 @@ class Dashboard extends Component
|
|
|
|
|
|
|
|
private function getCourseColor($courseName)
|
|
private function getCourseColor($courseName)
|
|
|
{
|
|
{
|
|
|
- $courseName = strtolower($courseName);
|
|
|
|
|
- $color = 'default';
|
|
|
|
|
-
|
|
|
|
|
- if (strpos($courseName, 'padel') !== false) {
|
|
|
|
|
- $color = 'padel'; // #FFD700
|
|
|
|
|
- } elseif (strpos($courseName, 'tennis') !== false) {
|
|
|
|
|
- $color = 'tennis'; // #8B4CF7
|
|
|
|
|
- } elseif (strpos($courseName, 'pallavolo') !== false || strpos($courseName, 'volley') !== false) {
|
|
|
|
|
- $color = 'pallavolo'; // #FF6B35
|
|
|
|
|
- } elseif (strpos($courseName, 'yoga') !== false) {
|
|
|
|
|
- $color = 'yoga'; // #339E8E
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Array of different colors for courses
|
|
|
|
|
+ $colors = [
|
|
|
|
|
+ 'padel', // #FFD700 - Gold
|
|
|
|
|
+ 'tennis', // #8B4CF7 - Purple
|
|
|
|
|
+ 'pallavolo', // #FF6B35 - Orange
|
|
|
|
|
+ 'yoga', // #339E8E - Teal
|
|
|
|
|
+ 'blue', // #0618BE - Blue
|
|
|
|
|
+ 'pink', // #E91E63 - Pink
|
|
|
|
|
+ 'green', // #4CAF50 - Green
|
|
|
|
|
+ 'red', // #F44336 - Red
|
|
|
|
|
+ 'indigo', // #3F51B5 - Indigo
|
|
|
|
|
+ 'amber', // #FF9800 - Amber
|
|
|
|
|
+ 'cyan', // #00BCD4 - Cyan
|
|
|
|
|
+ 'lime' // #CDDC39 - Lime
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ // Use course_id or course name hash to consistently assign colors
|
|
|
|
|
+ // This ensures the same course always gets the same color
|
|
|
|
|
+ $hash = crc32($courseName);
|
|
|
|
|
+ $colorIndex = abs($hash) % count($colors);
|
|
|
|
|
+ $assignedColor = $colors[$colorIndex];
|
|
|
|
|
|
|
|
Log::debug('Course color assigned', [
|
|
Log::debug('Course color assigned', [
|
|
|
'course_name' => $courseName,
|
|
'course_name' => $courseName,
|
|
|
- 'assigned_color' => $color
|
|
|
|
|
|
|
+ 'hash' => $hash,
|
|
|
|
|
+ 'color_index' => $colorIndex,
|
|
|
|
|
+ 'assigned_color' => $assignedColor
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
- return $color;
|
|
|
|
|
|
|
+ return $assignedColor;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function loadSavedNotes()
|
|
private function loadSavedNotes()
|
|
@@ -651,6 +764,59 @@ class Dashboard extends Component
|
|
|
return redirect()->to('/out?new=1');
|
|
return redirect()->to('/out?new=1');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Debug method - remove after testing
|
|
|
|
|
+ public function debugCourses()
|
|
|
|
|
+ {
|
|
|
|
|
+ Log::info('=== DEBUG COURSES CALLED ===');
|
|
|
|
|
+
|
|
|
|
|
+ $today = now()->format('N');
|
|
|
|
|
+ $dayNames = [
|
|
|
|
|
+ 1 => 'lun', 2 => 'mar', 3 => 'mer', 4 => 'gio',
|
|
|
|
|
+ 5 => 'ven', 6 => 'sab', 7 => 'dom'
|
|
|
|
|
+ ];
|
|
|
|
|
+ $todayName = $dayNames[$today];
|
|
|
|
|
+
|
|
|
|
|
+ // Get all member courses
|
|
|
|
|
+ $allCourses = \App\Models\MemberCourse::with('course')->get();
|
|
|
|
|
+
|
|
|
|
|
+ Log::info('All courses debug', [
|
|
|
|
|
+ 'total_courses' => $allCourses->count(),
|
|
|
|
|
+ 'today_name' => $todayName,
|
|
|
|
|
+ 'courses' => $allCourses->map(function($mc) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'id' => $mc->id,
|
|
|
|
|
+ 'status' => $mc->status,
|
|
|
|
|
+ 'when' => $mc->when,
|
|
|
|
|
+ 'course_name' => $mc->course->name ?? 'Unknown'
|
|
|
|
|
+ ];
|
|
|
|
|
+ })->toArray()
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $this->dispatchBrowserEvent('debug-completed');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Temporary method to activate courses for testing
|
|
|
|
|
+ public function activateTestCourses()
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $updated = \App\Models\MemberCourse::whereIn('id', [21, 22, 23, 24])
|
|
|
|
|
+ ->update(['status' => 1]);
|
|
|
|
|
+
|
|
|
|
|
+ Log::info('Activated test courses', ['updated_count' => $updated]);
|
|
|
|
|
+
|
|
|
|
|
+ // Reload the data
|
|
|
|
|
+ $this->loadCoursesData();
|
|
|
|
|
+ $this->loadCoursesParticipation();
|
|
|
|
|
+
|
|
|
|
|
+ $this->dispatchBrowserEvent('courses-activated', [
|
|
|
|
|
+ 'message' => "Attivati $updated corsi per test"
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Log::error('Error activating courses', ['error' => $e->getMessage()]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Existing methods (keeping original implementation)
|
|
// Existing methods (keeping original implementation)
|
|
|
private function getLabels()
|
|
private function getLabels()
|
|
|
{
|
|
{
|