Skip to content

Commit

Permalink
Merge branch 'dev-hiresuit' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinjohn22 committed Feb 4, 2025
2 parents 260ce2c + 17d3395 commit 5cd0e18
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 174 deletions.
51 changes: 46 additions & 5 deletions admin/class-awsm-job-openings-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public static function get_default_settings( $option_name = '' ) {
),
),
'awsm_enable_job_filter_listing' => 'enabled',
'awsm_enable_job_search' => 'enabled',
'awsm_enable_job_search' => 'enabled',
'awsm_jobs_listing_available_filters' => array( 'job-category', 'job-type', 'job-location' ),
'awsm_jobs_listing_specs' => array( 'job-category', 'job-location' ),
'awsm_jobs_admin_upload_file_ext' => array( 'pdf', 'doc', 'docx' ),
Expand Down Expand Up @@ -660,6 +660,8 @@ public function template_handler( $option_name, $template ) {

public function awsm_jobs_filter_handle( $filters ) {
$old_value = get_option( 'awsm_jobs_filter' );
error_log('filter: ' . print_r($filters, true));
error_log('old value: ' . print_r($old_value, true));
if ( ! empty( $filters ) ) {
foreach ( $filters as $index => $filter ) {
$spec_name = isset( $filter['filter'] ) ? sanitize_text_field( $filter['filter'] ) : '';
Expand Down Expand Up @@ -714,7 +716,8 @@ public function awsm_jobs_filter_handle( $filters ) {
}
return $filters;
}



public function update_awsm_jobs_filter( $old_value, $new_value ) {
$awsm_job_openings = AWSM_Job_Openings::init();
$awsm_job_openings->awsm_jobs_taxonomies( $new_value );
Expand Down Expand Up @@ -1214,33 +1217,70 @@ public function spec_template( $index, $tax_details = array(), $filters = array(
return;
}
$spec_title = $row_data = $del_btn_data = $icon_option = $tag_options = ''; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found

$spec_key_html = sprintf( '<input type="text" class="widefat awsm-jobs-spec-key" name="awsm_jobs_filter[%1$s][taxonomy]" value="" maxlength="32" placeholder="%2$s" title="%3$s" required /><input type="hidden" name="awsm_jobs_filter[%1$s][register]" value="true" />', esc_attr( $index ), esc_attr__( 'Specification key', 'wp-job-openings' ), esc_attr__( 'The job specification key should only contain alphanumeric, latin characters separated by hyphen/underscore, and cannot begin or end with a hyphen/underscore.', 'wp-job-openings' ) );

if ( ! empty( $tax_details ) && isset( $tax_details['key'] ) && isset( $tax_details['options'] ) ) {
$spec_key = $tax_details['key'];
$spec_options = $tax_details['options'];
$row_data = sprintf( ' data-index="%s"', esc_attr( $index ) );
$del_btn_data = sprintf( ' data-taxonomy="%s"', esc_attr( $spec_key ) );
$spec_title = $spec_options->label;
$spec_key_html = sprintf( '<input type="text" class="widefat" value="%2$s" disabled /><input type="hidden" name="awsm_jobs_filter[%1$s][taxonomy]" value="%2$s" />', esc_attr( $index ), esc_attr( $spec_key ) );

// Get icon option if exists in filters
foreach ( $filters as $filter ) {
if ( $spec_key === $filter['taxonomy'] ) {
if ( ! empty( $filter['icon'] ) ) {
$icon_option = sprintf( '<option value="%1$s" selected><i class="awsm-job-icon-%1$s"></i> %1$s</option>', esc_attr( $filter['icon'] ) );
}
break;
}
}

// Get all terms
$terms = get_terms(
array(
'taxonomy' => $spec_key,
'orderby' => 'name',
'hide_empty' => false,
)
);

if ( ! empty( $terms ) ) {
// Create an associative array of terms for easy lookup
$terms_map = array();
foreach ( $terms as $term ) {
$tag_options .= sprintf( '<option value="%1$s" data-termid="%2$s" selected>%1$s (%3$s)</option>', esc_attr( $term->name ), esc_attr( $term->term_id ), esc_attr( $term->count ) );
$terms_map[$term->name] = $term;
}

// First add terms that exist in filters' tags array
foreach ( $filters as $filter ) {
if ( $spec_key === $filter['taxonomy'] && isset( $filter['tags'] ) && is_array( $filter['tags'] ) ) {
foreach ( $filter['tags'] as $tag ) {
if ( isset( $terms_map[$tag] ) ) {
$term = $terms_map[$tag];
$tag_options .= sprintf(
'<option value="%1$s" data-termid="%2$s" selected>%1$s (%3$s)</option>',
esc_attr( $term->name ),
esc_attr( $term->term_id ),
esc_attr( $term->count )
);
// Remove from map to track which terms have been added
unset( $terms_map[$tag] );
}
}
}
}

// Add remaining terms that weren't in the filters
foreach ( $terms_map as $term ) {
$tag_options .= sprintf(
'<option value="%1$s" data-termid="%2$s" selected>%1$s (%3$s)</option>',
esc_attr( $term->name ),
esc_attr( $term->term_id ),
esc_attr( $term->count )
);
}
}
}
Expand All @@ -1266,6 +1306,7 @@ public function spec_template( $index, $tax_details = array(), $filters = array(
</tr>
<?php
}


public function get_template_tags() {
$template_tags = apply_filters(
Expand Down
2 changes: 1 addition & 1 deletion admin/templates/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
),
),
),

'value' => $listing_view,
),
array(
Expand Down
11 changes: 2 additions & 9 deletions admin/templates/meta/applicant-single.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,8 @@
?>
<div class="awsm-applicant-info">
<h3><?php echo esc_html( $applicant_details['name'] ); ?></h3>
<?php $title = esc_html( sprintf( get_post_meta( $post->ID, 'awsm_apply_for', true ) ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ?>
<p>
<?php
// phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.NoEmptyStrings
printf( esc_html__( '%s', 'wp-job-openings' ), esc_html( $title ) );
?>
</p>

</div><!-- .awsm-applicant-info -->
<p><?php echo esc_html( get_post_meta( $post->ID, 'awsm_apply_for', true ) ); ?></p>
</div><!-- .awsm-applicant-info -->
<?php
/**
* Fires after applicant photo content.
Expand Down
181 changes: 107 additions & 74 deletions admin/templates/meta/job-specifications.php
Original file line number Diff line number Diff line change
@@ -1,86 +1,119 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
exit;
}
$awsm_filters = get_option( 'awsm_jobs_filter' );
$taxonomy_objects = get_object_taxonomies( 'awsm_job_openings', 'objects' );
$awsm_filters = get_option( 'awsm_jobs_filter' );
$taxonomy_objects = get_object_taxonomies( 'awsm_job_openings', 'objects' );

/**
* Initialize job specifications meta box.
*
* @since 1.6.0
*/
do_action( 'awsm_job_specs_mb_init', $post->ID );
/**
* Initialize job specifications meta box.
*
* @since 1.6.0
*/
do_action( 'awsm_job_specs_mb_init', $post->ID );
?>

<div class="awsm-job-specifications-section" id="awsm_job_specifications">
<?php
/**
* Fires before job specifications meta box content.
*
* @since 1.6.0
*/
do_action( 'before_awsm_job_specs_mb_content', $post->ID );
<?php
/**
* Fires before job specifications meta box content.
*
* @since 1.6.0
*/
do_action( 'before_awsm_job_specs_mb_content', $post->ID );

if ( ! empty( $taxonomy_objects ) && ! empty( $awsm_filters ) ) :
$spec_keys = wp_list_pluck( $awsm_filters, 'taxonomy' );
if ( ! empty( $taxonomy_objects ) && ! empty( $awsm_filters ) ) :
$spec_keys = wp_list_pluck( $awsm_filters, 'taxonomy' );

echo '<ul class="awsm-job-specification-wrapper">';
foreach ( $taxonomy_objects as $spec => $spec_options ) :
if ( ! in_array( $spec, $spec_keys, true ) ) {
continue;
}
echo '<ul class="awsm-job-specification-wrapper">';
foreach ( $taxonomy_objects as $spec => $spec_options ) :
if ( ! in_array( $spec, $spec_keys, true ) ) {
continue;
}

/**
* Filter the arguments for specification terms.
*
* @since 3.3.0
*
* @param array $terms_args Array of arguments.
*/
$terms_args = apply_filters(
'awsm_jobs_spec_terms_args',
array(
'taxonomy' => $spec,
'orderby' => 'name',
'hide_empty' => false,
)
);
$spec_terms = get_terms( $terms_args );
// Find the corresponding filter array to get the tags order
$current_filter = array_filter($awsm_filters, function($filter) use ($spec) {
return $filter['taxonomy'] === $spec;
});
$current_filter = reset($current_filter);

$post_terms = get_the_terms( $post->ID, $spec );
$post_terms_ids = array();
if ( ! empty( $post_terms ) ) {
foreach ( $post_terms as $post_term ) {
$post_terms_ids[] = $post_term->term_id;
}
}
?>
<li>
<input type="hidden" name="awsm_job_spec_terms[<?php echo esc_attr( $spec ); ?>][]" value="" />
<label for="awsm_job_<?php echo esc_attr( $spec ); ?>_specification"><?php echo esc_html( $spec_options->label ); ?></label>
<select class="awsm_job_specification_terms" id="awsm_job_<?php echo esc_attr( $spec ); ?>_specification" name="awsm_job_spec_terms[<?php echo esc_attr( $spec ); ?>][]" multiple="multiple" style="width: 100%;">
<?php
if ( ! empty( $spec_terms ) ) :
foreach ( $spec_terms as $spec_term ) :
?>
<option value="<?php echo esc_attr( $spec_term->term_id ); ?>"<?php echo ( ! empty( $post_terms_ids ) ) ? ( in_array( $spec_term->term_id, $post_terms_ids ) ? ' selected' : '' ) : ''; ?>><?php echo esc_html( $spec_term->name ); ?></option>
<?php
endforeach;
endif;
?>
</select>
</li>
<?php
endforeach;
echo '</ul><!-- .awsm-job-specification-wrapper -->';
endif;
/**
* Filter the arguments for specification terms.
*
* @since 3.3.0
*
* @param array $terms_args Array of arguments.
*/
$terms_args = apply_filters(
'awsm_jobs_spec_terms_args',
array(
'taxonomy' => $spec,
'orderby' => 'name',
'hide_empty' => false,
)
);
$spec_terms = get_terms( $terms_args );

/**
* Fires after job specifications meta box content.
*
* @since 1.6.0
*/
do_action( 'after_awsm_job_specs_mb_content', $post->ID );
?>
</div><!-- #awsm_job_specifications -->
// Create an ordered array of terms based on the tags order
$ordered_terms = array();
if (!empty($current_filter['tags']) && !empty($spec_terms)) {
// First, create a name => term object mapping for quick lookup
$term_map = array();
foreach ($spec_terms as $term) {
$term_map[$term->name] = $term;
$term_map[$term->term_id] = $term;
}

// Add terms in the order specified in tags
foreach ($current_filter['tags'] as $tag) {
if (isset($term_map[$tag])) {
$ordered_terms[] = $term_map[$tag];
}
}

// Add any remaining terms that weren't in the tags array
foreach ($spec_terms as $term) {
if (!in_array($term, $ordered_terms)) {
$ordered_terms[] = $term;
}
}
} else {
$ordered_terms = $spec_terms;
}

$post_terms = get_the_terms( $post->ID, $spec );
$post_terms_ids = array();
if ( ! empty( $post_terms ) ) {
foreach ( $post_terms as $post_term ) {
$post_terms_ids[] = $post_term->term_id;
}
}
?>
<li>
<input type="hidden" name="awsm_job_spec_terms[<?php echo esc_attr( $spec ); ?>][]" value="" />
<label for="awsm_job_<?php echo esc_attr( $spec ); ?>_specification"><?php echo esc_html( $spec_options->label ); ?></label>
<select class="awsm_job_specification_terms" id="awsm_job_<?php echo esc_attr( $spec ); ?>_specification" name="awsm_job_spec_terms[<?php echo esc_attr( $spec ); ?>][]" multiple="multiple" style="width: 100%;">
<?php
if ( ! empty( $ordered_terms ) ) :
foreach ( $ordered_terms as $spec_term ) :
?>
<option value="<?php echo esc_attr( $spec_term->term_id ); ?>"<?php echo ( ! empty( $post_terms_ids ) ) ? ( in_array( $spec_term->term_id, $post_terms_ids ) ? ' selected' : '' ) : ''; ?>><?php echo esc_html( $spec_term->name ); ?></option>
<?php
endforeach;
endif;
?>
</select>
</li>
<?php
endforeach;
echo '</ul><!-- .awsm-job-specification-wrapper -->';
endif;

/**
* Fires after job specifications meta box content.
*
* @since 1.6.0
*/
do_action( 'after_awsm_job_specs_mb_content', $post->ID );
?>
</div><!-- #awsm_job_specifications -->
2 changes: 2 additions & 0 deletions admin/templates/specifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
}
$awsm_filters = get_option( 'awsm_jobs_filter' );
$taxonomy_objects = get_object_taxonomies( 'awsm_job_openings', 'objects' );
// echo '<pre>';
// var_dump($awsm_filters );
$spec_label_placeholder = 'placeholder="' . esc_html__( 'Enter a specification', 'wp-job-openings' ) . '"';
$spec_tags_placeholder = 'data-placeholder="' . esc_html__( 'Enter options', 'wp-job-openings' ) . '"';
$icon_placeholder = 'data-placeholder="' . esc_html__( 'Select icon', 'wp-job-openings' ) . '"';
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-overview.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5cd0e18

Please sign in to comment.