Support

Home Forums Event Espresso Premium Active status for multiple datetimes

Active status for multiple datetimes

Posted: March 15, 2018 at 8:39 am

Viewing 19 reply threads


motio

March 15, 2018 at 8:39 am

We sell courses (e.g. Yoga, Pilates) with multiple datetimes, mostly 8 times, per event. I understand that the upcoming status is if the current date is before the event datetime. This makes sense for long events. With multiple datetimes an event last for at least 8 weeks. So the status upcoming is misleading for some customers because the course has already begun after the first datetime.
Is it possible to define the active status as the time between the start of the first datetime and the end of the last datetime?


Josh

  • Support Staff

March 16, 2018 at 1:20 pm

No I’m afraid it’s not possible to define the active status that way.


motio

March 16, 2018 at 1:45 pm

Okay!? Is it possible than just change somehow the sign „upcoming“ on the event page, table list template and calendar on the frontend to „in progress“ between the first and last datetime? The official status doesn’t have to be change. It’s just have to be clear everywhere for the customers that the course has startet and is in progress.


Josh

  • Support Staff

March 16, 2018 at 1:51 pm

I don’t believe the table list template or calendar shows the Datetime status. For the event page, you can set “Display Status Banner?” to “No” on the Event Espresso > Events > Templates settings page and the banner will no longer display.


motio

March 16, 2018 at 1:58 pm

I would like to communicate somehow that the course has started and is in progress.

On the eventpage like described or add an additional banner in the text that show automatically if the course is in progress.

On the table list and calendar change the text from „register“ to „in progress“.


Josh

  • Support Staff

March 19, 2018 at 9:34 am

Hi there,

This isn’t a supported feature and would require custom PHP programming to add these. I’m afraid we do not have any code examples that are remotely related to defining active statuses.


motio

March 19, 2018 at 10:25 am

Hey Josh,
thank you for your reply. If I may, I would like to describe again, what I am trying to do, because I don’t want to define an active status.

I would like to add an automated text on the event page via php for the the following cases:
– if the current date is bevor the start date than the text in the description says “open for registration”
– if the current date is after the start date and before the enddate than the text in the description says “course pending”
– if the current date is after the end date than the text in the description says “course ended”
– if the current status is canceled than the text in the description says “course is canceled”

With a bit of styling it would look like banner and would show in a glance what status the course is in.

I’ve found the template tags on https://eventespresso.com/wiki/ee4-themes-templates/. I guess I need the espresso_event_date() for the start date and espresso_event_status() for the status. I am just started with php and still figuring out how to achieve this. Maybe you could give me a direction or maybe an example how a similar case is what exist already.


Josh

  • Support Staff

March 19, 2018 at 2:53 pm

Hi there,

The espresso_event_date() tag will only return the first Datetime of the event, and espresso_event_status() will return these statuses:

One thing to keep in mind is there are two classes that handle the active status logic, one for events and one for datetimes. Here are links to the source PHP for those:

https://github.com/eventespresso/event-espresso-core/blob/master/core/db_classes/EE_Datetime.class.php#L1070

https://github.com/eventespresso/event-espresso-core/blob/master/core/db_classes/EE_Event.class.php#L1022


motio

March 20, 2018 at 2:31 am

Hey Josh,
thank you for the information. I am new to php and I am still struggling with the object and methods. Maybe you could assist me a little.

My current action looks like this:

 
add_action('AHEE_event_details_after_the_content', 'my_custom_event_status_banner');
function my_custom_event_status_banner() {

		$today = time();
		
		$event_start = strtotime(espresso_event_date());
		// get the end date of current event
		$event_end = strtotime(espresso_event_end_date());

		// check if the current event status is not canceled
		$event_status_is_not_canceled = $post->EE_Event->is_cancelled() == false;
		// check if the current event status is canceled
		$event_status_is_canceled =	!$post->EE_Event->is_cancelled() == false ;

		if ( $event_status_is_not_canceled && $today < $event_start) {
	    echo "open for sale";
	} elseif ($event_status_is_not_canceled && $today > $event_start && $today < $event_end) {
	    echo "course pending";
	} elseif ($event_status_is_not_canceled && $today > $event_end) {
	    echo "course ended";
	} elseif ($event_status_is_canceled) {
		    echo "course is canceled";
	}
}

How can I check if the event is canceled or not in the if statement? I understand that it is the is_cancelled function but I can’t figure out how to use it.
public function is_cancelled()
{
return $this->status() === EEM_Event::cancelled;
}

The second part is that espresso_event_date() echoing the result if want to use it as a variable. I have to return the value of that and than edit it by the strtotime function to be able to compare it in the if statement.

I would appreciate if you give me maybe an existing example how to do those two things.


motio

March 20, 2018 at 2:51 am

Okay, I figured out how to check the status

 $event_status_is_not_canceled = !$public_event_stati->EE_Event->is_cancelled(); 

and adding $public_event_stati to the function.


motio

March 20, 2018 at 3:30 am

I can’t figuring out how to pull the information from

    /**
     * Set event start date
     * set the start date for an event
     *
     * @param string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
     * @throws ReflectionException
     * @throws InvalidArgumentException
     * @throws InvalidInterfaceException
     * @throws InvalidDataTypeException
     * @throws EE_Error
     */
    public function set_start_date($date)
    {
        $this->_set_date_for($date, 'DTT_EVT_start');
    }


motio

March 20, 2018 at 3:31 am

Sorry I mean:

    /**
     * get event start date.  Provide either the date format, or NULL to re-use the
     * last-used format, or '' to use the default date format
     *
     * @param string $dt_frmt   string representation of date format defaults to 'F j, Y'
     * @return mixed            string on success, FALSE on fail
     * @throws ReflectionException
     * @throws InvalidArgumentException
     * @throws InvalidInterfaceException
     * @throws InvalidDataTypeException
     * @throws EE_Error
     */
    public function start_date($dt_frmt = '')
    {
        return $this->_show_datetime('D', 'start', $dt_frmt);
    }


Tony

  • Support Staff

March 20, 2018 at 6:22 am

$event_status_is_not_canceled = !$public_event_stati->EE_Event->is_cancelled();

$public_event_stati doesn’t look correct there, I have no idea where thats from, but I don’t think it would be an object that would have the EE_Event property unless its a poorly named variable.

I can’t figuring out how to pull the information from start_date()

What do you mean by pulling info?

$start_date = $datetime->start_date();

Would assign to the start to dat to the $start_date variable.


motio

March 21, 2018 at 10:37 am

Hey Tony,
pulling info is probably the wrong term. What I meant is that I don’t know how to call/initiate a method and properties? The explanation that I found are for beginners that I understand the concept of classes or others that are way over my head.

I appreciate the example from you a lot but I also understand that the purpose of the support is not to write everything for me. It would help me a lot, if you give the info how to fill the variables, e.g. in this case the info $event_status_is_not_canceled and $start_date. I would love to learn to write myself and use this as a project to learn it.

For the variable that doesn’t look right: I am always searching the forum for cases that I could use. In this case I found not that code but similar in different post and tried it to apply it here. By trial and error this worked and showed my the test echo on the page.

I know that I’ve posted a lot of topics so far. So I thank you guys for your work and hope that your answers don’t only help me but others how also are beginners.
Thomas


Josh

  • Support Staff

March 23, 2018 at 12:42 pm

Hi Thomas,

One way to learn is from looking at similar code from within the project. One similar example is the espresso_event_reg_button() template tag which does something similar:

https://github.com/eventespresso/event-espresso-core/blob/master/public/template_tags.php#L251


motio

March 23, 2018 at 2:25 pm

Hey Josh, thank you for the link. I found a lot of information by searching examples and infos here but it is a lot to process.

I am trying to make sense of the structure of EE. I understand that a method is calling another method to have a flexibel system. But it is hard to follow where to find the other class and method.
e.g. Where do I find the EEH_Event_View class?
And do you have somewhere an explanation what the EED, EEM, EEH… at the beginning stands for? Maybe that helps me to understand the structure.

The guide from the other post was very helpful but I am stuck how to call method.
I’ve tried to call the method start() from the class EE_Datetime. If I call it statically, the error comes that I can’t call a non-statical statically.
I probably have to define a variable as an instance of that class first. I don’t know what I have to learn/read first to be able to start.

I found also the model https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md
Do you have a link to a good guide/tutorial how a model system works?

Let me know if I am starting to annoy you with my question.
I wish you guys a great weekend.


motio

March 25, 2018 at 12:48 pm

So I went through the classes and I guess I kinda get it. Here is my code for the custom banner and is working.

// Add custom banner after the content
add_action('AHEE_event_details_after_the_content', 'my_test_function');
function my_test_function() {

    $today = time();

  	$first_date_object = EEH_Event_View::get_primary_date_obj( );
		$first_date_timestamp = $first_date_object instanceof EE_Datetime ? $first_date_object->get_raw( 'DTT_EVT_start' ) :  '';

    $last_date_object = EEH_Event_View::get_last_date_obj( );
		$last_date_timestamp = $last_date_object instanceof EE_Datetime ? $last_date_object->get_raw( 'DTT_EVT_end' ) :  '';

    $get_event = EEH_Event_View::get_event();
    $event_is_canceled = $get_event instanceof EE_Event ? $get_event->is_cancelled() :  '';
    $event_is_soldout = $get_event instanceof EE_Event ? $get_event->is_sold_out() :  '';

    if ($event_is_canceled==true) {
    echo "<span class=\"banner banner_canceled\">canceled</span>";
  }   elseif ($event_is_soldout==true){
    echo "<span class=\"banner banner_sold_out\">event is sold out</span>";
  }   elseif ($today < $first_date_timestamp){
    echo "<span class=\"banner banner_open\">open for registration</span>";
  }   elseif ($first_date_timestamp < $today && $today < $last_date_timestamp){
    echo "<span class=\"banner banner_pending\">pending</span>";
  }   elseif ($last_date_timestamp < $today){
    echo "<span class=\"banner banner_expired\">expired</span>";
  }
}

And the CSS to that belongs to that banner.

add_action( 'wp_head', 'css_for_custom_plugin_functions_ee' );
function css_for_custom_plugin_functions_ee() {
        ?>
    <style type="text/css">

.banner{
display: inline-block;
position: relative;
float: right;
z-index: 1;
padding: 0.5em 1.5em 0.5em;
margin: 0 0 0 1em;
border-bottom: 1px solid rgba(0,0,0,0.1);
font-weight: bold;
color: #fff !important;
text-decoration: none;
text-align: center;
text-shadow: 0 -1px 0 rgba(0,0,0,0.25);
font-size: 1.5em;
line-height: 1;
border-radius: 0;
box-shadow: none;
}

.banner_canceled{
background-color: red;
}
.banner_sold_out{
background-color: orange;
}
.banner_open{
background-color: #00B1CA;
}
.banner_pending{
background-color: green;
}
.banner_expired{
background-color: grey;
}

    </style>
        <?php
}

Even though the code works, I am not sure exactly what is stored in the variables. Becomes the variable an object of the class?

If it’s possible it would be great to get some infos to my questions from my previous post to understand the ee system better.


Josh

  • Support Staff

March 26, 2018 at 3:43 pm

You can get a better insight of what’s stored in each variable by installing the Kint Debugger plugin, then as you’re coding, and wondering about a variable, you add a line of temporary debug code like this:
d( $mystery_variable_name );

Then view the browser/refresh and Kint will display all kinds of information about the variable.

Side note: If you’re using the non-release-tag version of Event Espresso from Github then Kint is already included from within the plugin.


motio

March 27, 2018 at 1:46 am

Thank you Josh, I will try it.

I would like to add an additional condition. We have a custom message template for the group “registration approved” that we send out to confirm the start of the course and new registration will receive the same info.

Which method would you recommend to check if this message group is set to “global” or check if this uses the custom template name “course confirmed”?


Josh

  • Support Staff

March 27, 2018 at 7:48 am

It’s not my place to recommend, but I can point you to the EE_Messages_Generator class that has similar logic:

https://github.com/eventespresso/event-espresso-core/blob/master/core/libraries/messages/EE_Messages_Generator.lib.php

Viewing 19 reply threads

The support post ‘Active status for multiple datetimes’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso