• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Date from RSEVENTS in RSFORM Pro

Date from RSEVENTS in RSFORM Pro 11 years 2 months ago #26411

Hi There,

I was wondering if this was possible:

I have a custom RSFORM PRO Registration Form for RSEVENTS PRO

What I would like is a dropdown in this form that takes the dates from the actual event.

Example:

I have an event with a range from the 1st of March till the 5th of March.

When I come to the registration part, I would like my Form to show a dropdown with:
Mar 1
Mar 2
Mar 3
Mar 4
Mar 5

Is this possible, or could you point me in the right direction for this?

Appreciate your help on this
The administrator has disabled public write access.

Date from RSEVENTS in RSFORM Pro 11 years 2 months ago #26449

Hi All,

I have seen some other posts asking for the same thing, so came up with a bit of code... I am not PHP master, and this is me fiddling around. Maybe if I start out here, we can hopefully optimize this and make it as efficient as possible!

This has been made by pickin up various codes from the internet and using some of the tutorials from rsjoomla as well.

This works perfectly for 1 day events, but for the multi day events, the dates are a bit off. Sometimes it ignores the first date, sometimes it adds an extra date before or after the event. I think this has to do with timezones, but am still working on this. Any help would be appreciated!

What I have done is the following:

Enter this is a dropdown in the item field:

//<code>
//get the URL of the form
$url = RSFormProHelper::getURL();
//strip the url to the ID + event name (e.g. /index.php/schedules/join/13-ma-newton -- strip this to 13-ma-newton)
$url= str_replace('XXXX.XXX/','',$url);
//Remove everyting after the firs "-" so you get the ID
$url = substr($url, 0, strpos($url, "-"));


// Query the rsevents DB to get the Start date
$db = JFactory::getDbo();
$db->setQuery("SELECT `start` FROM `xxx_rseventspro_events` where id='".(int) $url."'");
$startDate = $db->loadResult();


// Query the rsevents DB to get the end date date
$db = JFactory::getDbo();
$db->setQuery("SELECT `end` FROM `xxx_rseventspro_events` where id='".(int) $url."'");
$endDate = $db->loadResult();

$items = array();

$items[] = "|Please Select[c]";

// check if it is a one day or multi day event
If ($endDate == "0000-00-00 00:00:00") {

$items[] = '|'.gmdate("d-M-Y (D)", strtotime($startDate));
}

//perform the logic of getting all the days into the dropdown
else {
$startDate = gmdate("Y-m-d", strtotime($startDate));
$endDate = gmdate("Y-m-d", strtotime($endDate));

// Start the variable off with the start date
$items[] = '|'.gmdate("d-M-Y (D)", strtotime($startDate));

// Set a 'temp' variable, sCurrentDate, with
// the start date - before beginning the loop
$sCurrentDate = $startDate;

// While the current date is less than the end date
while($sCurrentDate < $endDate){
// Add a day to the current date
$sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));

// Add this new day to the aDays array
$items[] = '|'.gmdate("d-M-Y (D)", strtotime($sCurrentDate));
}

// Once the loop has finished, return the
// array of days.

}


$items = implode("\n", $items);

return $items;


//</code>
The administrator has disabled public write access.

Date from RSEVENTS in RSFORM Pro 11 years 2 months ago #26476

Okay, finally managed to get this script to work as I need. I think the main condition here is that the starting time and ending time is not taken into consideration, as this is not required for us.

You can see the dropdown in action on www.noblehouse.us/index.php/schedules/event/61-ca-los-angeles

//<code>
//get the form URL
$url = RSFormProHelper::getURL();
//Get rid of all junk and only strip out the Event ID (this only works if your URL has the event ID in it (e.g. 81-MA-Newton)
$url = trim(substr($url, strrpos($url, '/') + 1));
$url = substr($url, 0, strpos($url, "-"));

// connect to the database that holds the event information and store the start and end date
$db = JFactory::getDbo();
$db->setQuery("SELECT `start` FROM `XXX_rseventspro_events` where id='".(int) $url."'");
$startDate = $db->loadResult();


$db = JFactory::getDbo();
$db->setQuery("SELECT `end` FROM `XXX_rseventspro_events` where id='".(int) $url."'");
$endDate = $db->loadResult();

// build up the array that will hold the values for your dropdown and add the default value
$items = array();
$items[] = "|Please Select[c]";

//check if the event is an ALL day event
If ($endDate == "0000-00-00 00:00:00") {

//just add the start date to the array
$items[] = gmdate("d-M-Y (D)", strtotime($startDate));
}

//If it is a multi day event:
else {

//convert the start and end date to the format: 2014 - 02 - 01
$startDate = gmdate("Y-m-d", strtotime($startDate));
$endDate = gmdate("Y-m-d", strtotime($endDate));

//Add the start date to the array. By adding "(D)", we will also display the actual day (e.g. Mon)
//$items[] = gmdate("d-M-Y (D)", strtotime($startDate))."start Date";

// Set a 'temp' variable, sCurrentDate, with
// the start date - before beginning the loop
$sCurrentDate = $startDate;

// While the current date is less than the end date
while($sCurrentDate < $endDate){

// Add this new day to the array
$items[] = gmdate("d-M-Y (D)", strtotime($sCurrentDate));

// Add a day to the current date
$sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));
}
}
// Once the loop has finished, return the
// array of days.


// This will create separate lines for each array
$items = implode("\n", $items);

// This will return the days to the dropdown list
return $items;

//</code>

I also don't take in account the differences for dropdown labels and values.

Hope this is helpful to all

Thanks
Ash
Last Edit: 11 years 2 months ago by milan.noblehouse. Reason: fixed some code
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!