n void */ public function set_listing_item_index( $index ) { $this->listing_item_index = $index; } /** * Reset repeater index * * @return [type] [description] */ public function reset_listing_item_index() { $this->listing_item_index = 1; } /** * Get repeater index * * @return int */ public function get_listing_item_index() { return $this->listing_item_index; } /** * Set repeater index * * @param int $index * @return void */ public function set_index( $index ) { $this->repeater_index = $index; } /** * Returns repeater value * * @return [type] [description] */ public function get_repeater_value( $field ) { $source_field = $this->current_listing->get_settings( 'repeater_field' ); $repeater_source = $this->current_listing->get_settings( 'repeater_source' ); $index = $this->repeater_index; $object = $this->get_current_object(); switch ( $repeater_source ) { case 'jet_engine': $meta_value = $this->get_meta( $source_field, $this->get_current_object(), 'object' ); if ( empty( $meta_value ) || ! is_array( $meta_value ) ) { return false; } $meta_value = array_values( $meta_value ); if ( empty( $meta_value[ $index ] ) ) { return false; } else { return isset( $meta_value[ $index ][ $field ] ) ? $meta_value[ $index ][ $field ] : false; } case 'jet_engine_options': $source_option = $this->current_listing->get_settings( 'repeater_option' ); if ( ! $source_option ) { return false; } $meta_value = $this->get_option( $source_option ); if ( empty( $meta_value ) || ! is_array( $meta_value ) ) { return false; } $meta_value = array_values( $meta_value ); if ( empty( $meta_value[ $index ] ) ) { return false; } else { return isset( $meta_value[ $index ][ $field ] ) ? $meta_value[ $index ][ $field ] : false; } case 'acf': return $this->get_acf_repeater_value( $object, $source_field, $field ); default: return apply_filters( 'jet-engine/listings/data/repeater-value/' . $repeater_source, false, $object, $source_field, $field, $index, $this ); } } /** * Returns value of ACF repeater field * * @param [type] $parent_field [description] * @param [type] $child_field [description] * @return [type] [description] */ public function get_acf_repeater_value( $object, $parent_field, $child_field ) { $field_key = $parent_field . '_' . $this->repeater_index . '_' . $child_field; return $this->get_meta( $field_key, $object, 'object' ); } /** * Get permalink to current post/term * * @return string */ public function get_current_object_permalink( $object = null ) { if ( ! $object ) { $object = $this->get_current_object(); } if ( ! $object || ! is_object( $object ) ) { return null; } $class = get_class( $object ); $result = ''; switch ( $class ) { case 'WP_Post': return get_permalink( $object->ID ); case 'WP_Term': $result = get_term_link( absint( $object->term_id ) ); if ( is_wp_error( $result ) ) { return ''; } return $result; case 'WP_User': return apply_filters( 'jet-engine/listings/data/user-permalink', false, $object ); } return null; } /** * Returns available list sources * * @return [type] [description] */ public function get_field_sources() { $sources = array( 'object' => __( 'Post/Term/User/Object Data', 'jet-engine' ), 'meta' => __( 'Meta Data', 'jet-engine' ), 'query_var' => __( 'Query Variable', 'jet-engine' ), ); if ( jet_engine()->options_pages ) { $sources['options_page'] = __( 'Options', 'jet-engine' ); } if ( jet_engine()->relations ) { $sources['relations_hierarchy'] = __( 'Relations Hierarchy', 'jet-engine' ); } $source = false; if ( $this->current_listing ) { $source = $this->current_listing->get_settings( 'listing_source' ); } $repeater_sources = apply_filters( 'jet-engine/listing/repeater-listing-sources', array( 'repeater' ) ); if ( in_array( $source, $repeater_sources ) ) { $sources['repeater_field'] = __( 'Repeater Field', 'jet-engine' ); } return apply_filters( 'jet-engine/listings/data/sources', $sources ); } /** * Set $current_object property by object id and class name. * * @param mixed $object_id Object ID * @param string $class Object class name * @param bool $clear_hook Clear or not the `the_post` hook */ public function set_current_object_by_id( $object_id = null, $class = null, $clear_hook = false ) { $object = $this->get_object_by_id( $object_id, $class ); $this->set_current_object( $object, $clear_hook ); } /** * Get object by object id and class name. * * @param mixed $object_id Object ID * @param string $class Object class name * * @return object|null */ public function get_object_by_id( $object_id = null, $class = null ) { $object = null; if ( ! $object_id || ! $class ) { return $object; } switch ( $class ) { case 'WP_Post': $object = get_post( $object_id ); break; case 'WP_Term': $object = get_term( $object_id ); break; case 'WP_User': $object = get_user_by( 'ID', $object_id ); break; case 'WP_Comment': $object = get_comment( $object_id ); break; default: $object = apply_filters( 'jet-engine/listings/data/object-by-id', null, $object_id, $class ); } return $object; } } }