rep__employee_details_html()

This function, is designed to generate HTML for displaying employee details based on the provided employee post ID and content to display options.

Namespace

REP_Malcolm

Parameters

$post_id

int

Post ID of the listing.

$args

array

Key value pair of employee details.

Return

string

Employee details

Source

File: \includes\rep-helper-functions.php

function rep__employee_details_html( $post_id, $content_to_display = ['name','job_title','agency','rating'], $hero_profile = false ){

        ob_start();

        if( is_array( $content_to_display ) && ! empty( $content_to_display ) ) : ?>
            
            <div class="rep-employee-details"><?php

                foreach ($content_to_display as $content) {
                    
                    switch( $content ) {

                        case "name" :

                            $name = get_the_title( $post_id );
                            $permalink = get_the_permalink( $post_id );
                            $params = rep__agency_exp_url_params( $permalink, $post_id );

                            if( !empty( $params ) && $permalink ){
                                $permalink .= "?".implode("&",$params);
                            }

                            $hidden = lp__get_field_value( 'hide_post', $post_id );
                            $is_single_enabled = lp__get_field_value( REP__PREFIX.'_employee_single_page', 'option' );
                            $is_single_enabled = $is_single_enabled === false ? true : $is_single_enabled;

                            if( $name ) : ?>

                                <div class="rep-employee-name"><?php 
                                
                                    if( $hero_profile ) : ?>

                                        <h1><?php _e( $name, REP__TEXTDOMAIN ); ?></h1><?php

                                    elseif( $permalink && $is_single_enabled && ! $hidden ) :
                                    
                                        echo lp__link_html( $permalink, $name );

                                    else : 

                                        _e( $name );
                                    
                                    endif; ?>
                                        
                                </div><?php

                            endif;

                        break;

                        case "job_title" :

                            $job_title = lp__get_field_value( 'job_title', $post_id );

                            if( $job_title ) : ?>

                                <div class="rep-employee-title"><?=$job_title?></div><?php

                            endif; 

                        break;

                        case "agency" :

                            $agency_post_id = "";
                            $agency_id = lp__get_field_value( 'agency_id', $post_id );
                            $agency_lid = lp__get_field_value( 'agency_lid', $post_id );
                            $agency_mlids = lp__get_field_value( 'agency_mlids', $post_id );
                            $agency_location = lp__get_field_value('agency_location', $post_id);

                            if( ! $agency_lid && $agency_mlids ){
                                $agency_mlids = explode(",", $agency_mlids);
                                $agency_lid = $agency_mlids[0];
                            }

                            if( $agency_lid ){
                                $agency_post_id = rep__get_agency_post_id( $agency_lid, 'agency_lid' );
                            } elseif( $agency_location ){
                                $agency_location = explode(",", $agency_location);
                                $agency_post_id = rep__get_agency_post_id( $agency_location[0], 'agency_location' );
                            }

                            if( ! $agency_post_id ){
                                $agency_post_id = rep__get_agency_post_id( $agency_id );
                            }

                            if( $agency_post_id ) : 

                                $name = lp__get_field_value( 'display_name', $agency_post_id );
                                $permalink = get_the_permalink( $agency_post_id );
                                $hidden = lp__get_field_value( 'hide_post', $agency_post_id );
                                $is_single_enabled = lp__get_field_value( REP__PREFIX.'_agency_single_page', 'option' );
                                $is_single_enabled = $is_single_enabled === false ? true : $is_single_enabled; 

                                if( $is_single_enabled ) : ?>

                                    <div class="rep-agency-name"><?php
                                        
                                        if( ! $hidden && $permalink ) : 

                                            echo lp__link_html( $permalink, $name ); 

                                        else : 

                                            _e( $name );
                                        
                                        endif; ?>
                                            
                                    </div><?php

                                endif;

                            endif;

                        break;

                        case "rating" :

                            $reviews = lp__get_field_value( 'rea_total_reviews', $post_id );
                            $rating = lp__get_field_value( 'rea_avg_rating', $post_id );

                            if( $rating || $reviews ) : ?>

                                <div class="rep-rating-details rep-employee-rating-details"><?php

                                    if( $rating ) :

                                        ?><span class="rep-rating rep-employee-rating"><?= $rating; ?></span> <?php

                                    endif;
                                            
                                    if( $reviews ): 

                                        $url = lp__get_field_value( 'rea_agent_profile_url', $post_id );
                                        $s = (int)$reviews > 1 ? "s" : "";
                                        $reviews = "{$reviews} review{$s}";

                                        ?><span class="rep-review-count rep-employee-review-count"><?php 
                                            if( $url ) :
                                                echo lp__link_html( $url, $reviews, ["target"=>"_blank", "rel"=>"noopener"] ); 
                                            else:
                                                echo $reviews;
                                            endif;
                                        ?></span><?php 

                                    endif; ?>

                                </div><?php
                            
                            endif;

                        break;

                    };
                    
                } ?>

            </div><?php 

        endif;

        return ob_get_clean();

    }