Event Calendar - weekly view
81 posts by 2 authors in: Forums > CMS Builder
Last Post: Yesterday at 1:15am (RSS)
By MercerDesign - November 13
The error is because I'm not using the permalink but I don't want to keep having to edit the file at this stage, the event still disappears when I change the time
By Djulia - November 13
Can you provide the event in this format or with showme()? Thanks!
[
'title' => 'Annual Conference',
'start_date' => '2024-11-13 13:00:00',
'end_date' => '2024-11-13 13:10:00',
'permalink' => 'annual-conference',
'description' => 'Annual conference on technological innovations.',
'location' => 'Main Auditorium',
'category' => 'conference'
],
By Djulia - November 13
Thank you, I can reproduce the issue. In the meantime, could you use this file? Thanks!
By Djulia - November 13 - edited: November 13
Sorry for the delay, I had to finish a task. Could you please try this version? Thanks!
One final request, do you know how I can tell the calendar to open in the Day view when on a mobile instead of the Week view?
By Djulia - Wednesday at 8:00am - edited: Wednesday at 8:00am
Hi MercerDesign,
You can use user-agent analysis in the getCalendarParams() function :
/**
* Retrieves and validates calendar parameters from the GET request.
* Defaults to the current month, year, week, and day if parameters are not set.
*/
function getCalendarParams() {
// Define default parameters
$defaults = [
'view' => 'month',
'year' => date('Y'),
'month' => date('m'),
'week' => date('W'),
'day' => date('d')
];
// Retrieve GET parameter values, using default values if not set
$view = isset($_GET['view']) ? $_GET['view'] : null;
$year = isset($_GET['year']) ? intval($_GET['year']) : $defaults['year'];
$month = isset($_GET['month']) ? intval($_GET['month']) : $defaults['month'];
$week = isset($_GET['week']) ? intval($_GET['week']) : $defaults['week'];
$day = isset($_GET['day']) ? intval($_GET['day']) : $defaults['day'];
// List of allowed views
$allowed_views = ['month', 'week', 'day', 'year'];
// Device detection
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (is_null($view)) { // Only if the view is not specified in $_GET
if (preg_match('/Mobile|Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i', $user_agent)) {
$view = 'day'; // Default view for mobile
} else {
$view = 'week'; // Default view for desktop
}
}
// Validate parameters
$view = in_array($view, $allowed_views) ? $view : $defaults['view'];
$year = ($year >= 1970 && $year <= date('Y') + 25) ? $year : $defaults['year'];
$month = ($month >= 1 && $month <= 12) ? $month : $defaults['month'];
$week = ($week >= 1 && $week <= 53) ? $week : $defaults['week'];
$day = ($day >= 1 && $day <= 31) ? $day : $defaults['day'];
// Return validated parameters as an array
return [
'view' => $view,
'year' => $year,
'month' => $month,
'week' => $week,
'day' => $day
];
}
However, if you're looking for a more accurate solution, the Mobile Detect library is commonly used to determine whether the user is accessing the site from a mobile device or a desktop.
https://github.com/serbanghita/Mobile-Detect
Thanks,
Djulia