Skip Navigation

[Resolved] Appointment Booking

This thread is resolved. Here is a description of the problem and solution.

Problem:

Add two relationship filters into same post view.

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/appointment-booking/page/2/#post-2147421

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 3 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 14 replies, has 2 voices.

Last updated by bernhardK 3 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2143897

Hi Christian,

I have a school website where I want staff members to book appointments for students. Same Appointments can be booked by multiple students. For every booking a "participation" post type is being created, which is why a I need a form to do so.
As soon as there is a participation for the student for that appointment, the form should not be displayed.

Would be great to get some help here, as I've been struggling with this.

Post types:
Courses
Appointments
Participations
Students

Relations:
Courses [0 .. 1] << Appointments [*]
Appointments [0 .. 1] << Participations [*]
Students [0 .. 1] << Participations [*]

Detailed description:
Staff is selecting a student and a course, then all related appointments for this course are shown.
The student is available as a URL param "studentid".
Within the appointments loop I want to have a form that gets displayed, when there is *no* Participation to that particular appointment, *which belongs to the student*. If there *is* a participation to that appointment which belongs to the student, then some text should be displayed and no form.
On last two things I am struggling.

The form to create the particpiation itself includes the following relationship fields:
field='@appointment-participation.parent'
field='@student-participiation.parent'
All forms are automatically populated with data from course view, appointment view, from URL Params and from wpv-attributes.

Using Views latest version and no Blocks GUI for this.

Thanks and best regards
Bernhard

#2144415

Hello,

Within the "appointments loop" you mentioned above, you can display a child post view:
- Query "Participations" posts
- Filter by post type relationship between Appointments and Participations [*]
- If there is any result, display "some text"
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-items-found
- If no item found, display the "form "
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153285

For the question "from URL Params and from wpv-attributes"
You can get URL parameter value with shortcode [wpv-search-term], for example:
[wpv-search-term param="my-url-param"]
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term
And get view's shortcode attribute with shortcode [wpv-attribute]
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-309292

And pass them to Form field shortcode [cred_field] as parameter "value":
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field
value. Optional. Preset value

#2144993
wizard_appointments.png

Hi Luo,

thanks. The basics are working, but struggling with one scenario where there are more than 1 participations.

My setup:

Within the "appointments loop"
- Query "Participations" posts
- Filter by post type relationship between Appointments and Participations [*]
- If there is any result, display with the wpv-loop section:

In all scenarios below I want to check just for 1 student and if a participation form should be displayed or not. The ID of this student is available via URL param "studentid".

<!-- 1. when already booked -->

[wpv-conditional if="( '[wpv-search-term param="studentid"]' eq '[wpv-post-id item="@student-participation.parent"]' )"]Already booked[/wpv-conditional]

<!-- 2. participation existing but no student related -->

[wpv-conditional if="( '[wpv-post-id item="@student-participation.parent"]' eq '' )"][cred_form form="newparticipation" post='[wpv-attribute name="appointmendid"]'][/wpv-conditional]

<!-- 3. when found 1 participation and student from participiation is not equal to student ID from URL -->

[wpv-conditional if="( '[wpv-found-count]' eq '1' ) AND ( '[wpv-post-id item="@student-participation.parent"]' ne '[wpv-search-term param="studentid"]' )"][cred_form form="newparticipation" post='[wpv-attribute name="appointmentid"]'][/wpv-conditional]

<!-- 4. when found more than 1 participation and student from URL param studentid is not related to the participations -->
--> not working yet

[wpv-conditional if="( '[wpv-view name="countparticipations" appointmentid="[wpv-attribute name='appointmentid']"]' gte '2' ) AND ( '[wpv-post-id item="@student-participation.parent"]' ne '[wpv-search-term param="studentid"]' )"][cred_form form="newappointment" post='[wpv-attribute name="appointmentid"]'][/wpv-conditional]

Could you please help with scenario 4?

Uploaded a picture of my appointment booking wizard if it help somehow.

Many thanks
Bernhard

#2145321

For the new question:
4. when found more than 1 participation and student from URL param studentid is not related to the participations

1) found more than 1 participation
You can try below condition:
( '[wpv-found-count]' gt '1' )

2) student from URL param studentid is not related to the participations
( '[wpv-post-id item="@student-participation.parent"]' ne '[wpv-search-term param="studentid"]' )

All [wpv-conditional] shortcodes should be setup into the child post view

#2145461
wizard_appointments2.png

Hi Luo,

I tried wpv-found-count gt1 and gte2 together with AND conditon as you stated.
With this, I will get more than 1 participation form displayed per appointment when there are multiple participations where my student is not related to.
For every participation where my student is not part of, a form is being displayed.
The overall rule is still: Display a form, when there is no participation between my student (from URL param) and that appointment.


 [wpv-layout-start]

	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          
<!-- 1. when already booked -->          
[wpv-conditional if="( '[wpv-search-term param="studentid"]' eq '[wpv-post-id item="@student-participation.parent"]' )"]Already booked[/wpv-conditional]
          
<!-- 2. participation existing but no student related -->
[wpv-conditional if="( '[wpv-post-id item="@student-participation.parent"]' eq '' )"][cred_form form="new_participation_form" post='[wpv-attribute name="appointmentid"]'][/wpv-conditional]
          
<!-- 3. when found 1 participation and student from participiation is not equal to student ID from URL -->
[wpv-conditional if="( '[wpv-found-count]' eq '1' ) AND ( '[wpv-post-id item="@student-participation.parent"]' ne '[wpv-search-term param="studentid"]' )"][cred_form form="new_participation_form" post='[wpv-attribute name="appointmentid"]'][/wpv-conditional]
          
<!-- 4. when found more than 1 participation and student from URL param studentid is not related to the participations -->
     [wpv-conditional if="( '[wpv-found-count]' gt '1' ) AND ( '[wpv-post-id item="@student-participation.parent"]' ne '[wpv-search-term param="studentid"]' )"][cred_form form="new_participation_form" post='[wpv-attribute name="appointmentid"]'][/wpv-conditional]

          
</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]

[wpv-no-items-found]
[cred_form form="new_participation_form" post='[wpv-attribute name="appointmentid"]'] (no other participant)


  [/wpv-no-items-found]
[wpv-layout-end]


BR Bernhard

#2145523
relationship-filter3.JPG

For the question:

The overall rule is still: Display a form, when there is no participation between my student (from URL param) and that appointment.

It does not need [wpv-conditional] shortcode at all, you just need to setup a child post view as I mentioned above:
https://toolset.com/forums/topic/appointment-booking/#post-2144415

And you can also add another post type relationship filter between Students and Participations by the URL parameter "studentid", see my screenshot relationship-filter3.JPG

#2145587

I unfortunately cannot get it working and not sure if I fully understood.

Appointments View:
<wpv-loop>
[wpv-view name="view-participation"]
</wpv-loop>

Participation View: <-- this is the mentioned child post view, right?
Post type: participations
Filter by post type relationship between Appointments and Participations [*]
Filtered by "The current post in the loop"

When I change Filtered by "The current post in the loop" to post with ID set by URL param there will be a form displayed for all appointments.

Am I missing something here? Are you talking about a third view I have to setup?
I can provide details to my site.

#2145591

OK, please provide your website credentials in below private message box, also point out the problem page URLs and view URL, thanks

#2145617

The credentials you provided above redirect me to URL:
hidden link

Please check it, how can I login into your website? please check it, thanks

#2145619

Sorry, please go to hidden link enter the credentials and click on blue button "anmelden". Then you will be able to access hidden link

#2146415

Thanks for the details, I am checking it in in your website, will update here if find anything

#2146467

In your case, it needs to setup two relationship filters into post view "Quick_CheckforexistingRelation_Protokoll_Termin":
- Appointments [0 .. 1] << Participations [*] -> Termine [0 .. 1] << Protokolle [*]
- Students [0 .. 1] << Participations [*] -> Schuelerinnen [0 .. 1] << Protokolle [*]

But within Views UI, it can add only one relationship filter, you need to setup custom codes to add the another relationship filter, for example:
https://toolset.com/forums/topic/search-filter-with-two-post-relation-ships/

If you need more assistance for it, please provide your website FTP/SFTP access in below private message box, thanks

#2147349

Thanks for the details, I am checking it in your website, will update if find anything.

#2147407

I have done below modifications in your website:
Edit the custom code "second-relationshipfilter", add line 10:

add_filter( 'wpv_filter_query', 'filter_by_parent_schueler_func', 99, 3 );

Activate above custom code, test it in frontend, I get PHP error:
Out of memory (allocated 1642389504) (tried to allocate 1608519680 bytes) in /home/u803210759/domains/studi.fm/public_html/meinstudi/wp-content/plugins/wp-views/embedded/inc/wpv-filter-query.php on line 829

Since your website is using other plugins, and the problem page is using a nested post views, it needs to increase the PHP memory and output the view's results.

I am trying to find other workaround for this case, will update here if find anything

#2147421

Thanks Luo! My issue is resolved now.
It is working with the line you edited + I deactivated Query Monitor plugin which is activated for testing purposes. It needs a lot of RAM.

I am now quering to relations with this code:

add_filter( 'wpv_filter_query', 'filter_by_parent_student_func', 99, 3 );
function filter_by_parent_student_func( $query_args, $view_settings, $view_id ) {
    if ( $view_id == 16150 && isset($_GET['student'])) {
        if(!isset($query_args['toolset_relationships'])){
            $query_args['toolset_relationships'] = array();
        }
        $query_args['toolset_relationships'][] = array(
                'role' => 'child',
                'related_to' => $_GET['studentid'],
                'relationship' => 'student-participation'
        );
    }
    return $query_args;
}

Many thanks
Bernhard