Skip to content

Commit

Permalink
iteration 1 feedback part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kasprzyk-sz committed Jul 26, 2023
1 parent 94a7773 commit 1d85a91
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 130 deletions.
40 changes: 13 additions & 27 deletions wp-content/themes/vf-wp-intranet/acf-json/training.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
"key": "field_649d474f51c90",
"label": "Alternative dates",
"name": "vf-wp-training-alternative",
"type": "repeater",
"type": "relationship",
"instructions": "",
"required": 0,
"conditional_logic": 0,
Expand All @@ -326,30 +326,17 @@
"class": "",
"id": ""
},
"collapsed": "",
"min": 0,
"max": 0,
"layout": "table",
"button_label": "Next date",
"sub_fields": [
{
"key": "field_649d477151c91",
"label": "Date",
"name": "vf-wp-training-alternative-date",
"type": "date_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"display_format": "j M Y",
"return_format": "j M Y",
"first_day": 1
}
]
"post_type": [
"training"
],
"taxonomy": "",
"filters": [
"search"
],
"elements": "",
"min": "",
"max": "",
"return_format": "object"
}
],
"location": [
Expand All @@ -368,6 +355,5 @@
"instruction_placement": "label",
"hide_on_screen": "",
"active": true,
"description": "",
"modified": 1690285448
"description": ""
}
139 changes: 89 additions & 50 deletions wp-content/themes/vf-wp-intranet/archive-training.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,64 @@
$today_date = date('Ymd');
?>

<section class="vf-intro | vf-u-margin__bottom--800">
<section class="vf-intro | vf-u-margin__bottom--400">
<div>
<!-- empty -->
</div>
<div class="vf-stack">
<h1 class="vf-intro__heading">
Training catalogue
<h1 class="vf-intro__heading | vf-u-margin__bottom--400">
Professional Development Training Catalogue
</h1>
<p class="vf-intro__text">Short description and invitation to browse
</p>
<p class="vf-intro__subheading">Improve your skills in communication, management and leadership; learn a language,
or find support for planning your career.
</p>
</div>
</section>

<div class="embl-grid embl-grid--has-centered-content vf-u-padding__bottom--500 | vf-content">
<div class="embl-grid embl-grid--has-centered-content | vf-u-margin__bottom--800">
<div></div>
<div>

<form action="#eventsFilter" onsubmit="return false;"
class="vf-form vf-form--search vf-form--search--responsive | vf-sidebar vf-sidebar--end">
<div class="vf-sidebar__inner">
<div class="vf-form__item">
<input id="search" class="vf-form__input vf-form__input--filter" data-jplist-control="textbox-filter"
data-group="data-group-1" data-name="my-filter-1" data-path=".search-data" type="text" value=""
placeholder="Enter your search term" data-clear-btn-id="name-clear-btn">
</div>
<button style="display: none;" type="button" id="name-clear-btn"
class="vf-search__button | vf-button vf-button--tertiary vf-button--sm">
<span class="vf-button__text">Reset</span>
</button>
</div>
</form>
<div class="vf-tabs">
<ul class="vf-tabs__list" data-vf-js-tabs>
<li class="vf-tabs__item">
<a class="vf-tabs__link" href="#vf-tabs__section--live-training">Live Training</a>
</li>
<li class="vf-tabs__item">
<a class="vf-tabs__link" href="#vf-tabs__section--on-demand-training">On-demand Training</a>
</li>
</ul>
</div>
</div>
</div>

<section class="embl-grid embl-grid--has-centered-content | vf-u-margin__bottom--800">
<div class="vf-stack vf-stack--400">
<?php include(locate_template('partials/training-filter.php', false, false)); ?>
</div>
<main>
<div class="vf-tabs-content" id="typeTraining" data-vf-js-tabs-content>
<section class="vf-tabs__section" id="vf-tabs__section--live-training">
<div class="embl-grid embl-grid--has-centered-content vf-u-padding__bottom--800 | vf-content">
<div></div>
<div>

<form action="#eventsFilter" onsubmit="return false;"
class="vf-form vf-form--search vf-form--search--responsive | vf-sidebar vf-sidebar--end">
<div class="vf-sidebar__inner">
<div class="vf-form__item">
<input id="search" class="vf-form__input vf-form__input--filter" data-jplist-control="textbox-filter"
data-group="data-group-1" data-name="my-filter-1" data-path=".search-data" type="text" value=""
placeholder="Enter your search term" data-clear-btn-id="name-clear-btn">
</div>
<button style="display: none;" type="button" id="name-clear-btn"
class="vf-search__button | vf-button vf-button--tertiary vf-button--sm">
<span class="vf-button__text">Reset</span>
</button>
</div>
</form>
</div>
</div>

<section class="embl-grid embl-grid--has-centered-content | vf-u-margin__bottom--800">
<div class="vf-stack vf-stack--400">
<?php include(locate_template('partials/training-filter.php', false, false)); ?>
</div>
<main>
<div id="upcoming-events" data-jplist-group="data-group-1">
<?php
$forthcomingLoop = new WP_Query (array(
Expand Down Expand Up @@ -72,33 +91,52 @@ class="vf-search__button | vf-button vf-button--tertiary vf-button--sm">
<?php
include(locate_template('partials/vf-summary--training.php', false, false)); ?>
<?php endwhile;?>
</div>
</main>
<div class="vf-stack vf-stack--400">
<article class="vf-card vf-card--brand vf-card--bordered">

<div class="vf-card__content | vf-stack vf-stack--400">
<h3 class="vf-card__heading"><a class="vf-card__link" href="JavaScript:Void(0);">Example link <svg
aria-hidden="true" class="vf-card__heading__icon | vf-icon vf-icon-arrow--inline-end" width="1em"
height="1em" xmlns="http://www.w3.org/2000/svg">
<path
d="M0 12c0 6.627 5.373 12 12 12s12-5.373 12-12S18.627 0 12 0C5.376.008.008 5.376 0 12zm13.707-5.209l4.5 4.5a1 1 0 010 1.414l-4.5 4.5a1 1 0 01-1.414-1.414l2.366-2.367a.25.25 0 00-.177-.424H6a1 1 0 010-2h8.482a.25.25 0 00.177-.427l-2.366-2.368a1 1 0 011.414-1.414z"
fill="currentColor" fill-rule="nonzero"></path>
</svg>
</a></h3>
<p class="vf-card__text">Sapiente harum, omnis provident</p>
</div>
</article>
<article class="vf-card vf-card--brand vf-card--bordered">
<div class="vf-card__content | vf-stack vf-stack--400">
<h3 class="vf-card__heading"><a class="vf-card__link" href="JavaScript:Void(0);">Example link <svg
aria-hidden="true" class="vf-card__heading__icon | vf-icon vf-icon-arrow--inline-end" width="1em"
height="1em" xmlns="http://www.w3.org/2000/svg">
<path
d="M0 12c0 6.627 5.373 12 12 12s12-5.373 12-12S18.627 0 12 0C5.376.008.008 5.376 0 12zm13.707-5.209l4.5 4.5a1 1 0 010 1.414l-4.5 4.5a1 1 0 01-1.414-1.414l2.366-2.367a.25.25 0 00-.177-.424H6a1 1 0 010-2h8.482a.25.25 0 00.177-.427l-2.366-2.368a1 1 0 011.414-1.414z"
fill="currentColor" fill-rule="nonzero"></path>
</svg>
</a></h3>
<p class="vf-card__text">Sapiente harum, omnis provident</p>
</div>
</article>
</div>
</section>
</section>

<section class="vf-tabs__section" id="vf-tabs__section--on-demand-training">
<div class="embl-grid embl-grid--has-centered-content | vf-u-margin__bottom--800">
<div></div>
<div class="vf-content">
<p>Content here</p>
</div>
</div>
</main>
<div class="vf-stack vf-stack--400">
<article class="vf-card vf-card--brand vf-card--bordered">

<div class="vf-card__content | vf-stack vf-stack--400"><h3 class="vf-card__heading"><a class="vf-card__link" href="JavaScript:Void(0);">Example link <svg aria-hidden="true" class="vf-card__heading__icon | vf-icon vf-icon-arrow--inline-end" width="1em" height="1em" xmlns="http://www.w3.org/2000/svg"><path d="M0 12c0 6.627 5.373 12 12 12s12-5.373 12-12S18.627 0 12 0C5.376.008.008 5.376 0 12zm13.707-5.209l4.5 4.5a1 1 0 010 1.414l-4.5 4.5a1 1 0 01-1.414-1.414l2.366-2.367a.25.25 0 00-.177-.424H6a1 1 0 010-2h8.482a.25.25 0 00.177-.427l-2.366-2.368a1 1 0 011.414-1.414z" fill="currentColor" fill-rule="nonzero"></path></svg>
</a></h3>
<p class="vf-card__text">Sapiente harum, omnis provident</p>
</section>
</div>
</article>
<article class="vf-card vf-card--brand vf-card--bordered">


<div class="vf-card__content | vf-stack vf-stack--400"><h3 class="vf-card__heading"><a class="vf-card__link" href="JavaScript:Void(0);">Example link <svg aria-hidden="true" class="vf-card__heading__icon | vf-icon vf-icon-arrow--inline-end" width="1em" height="1em" xmlns="http://www.w3.org/2000/svg"><path d="M0 12c0 6.627 5.373 12 12 12s12-5.373 12-12S18.627 0 12 0C5.376.008.008 5.376 0 12zm13.707-5.209l4.5 4.5a1 1 0 010 1.414l-4.5 4.5a1 1 0 01-1.414-1.414l2.366-2.367a.25.25 0 00-.177-.424H6a1 1 0 010-2h8.482a.25.25 0 00.177-.427l-2.366-2.368a1 1 0 011.414-1.414z" fill="currentColor" fill-rule="nonzero"></path></svg>
</a></h3>
<p class="vf-card__text">Sapiente harum, omnis provident</p>
</div>
</article>
</div>
</section>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>

<script type="text/javascript">
jplist.init({
});

jplist.init({});
</script>

<script>
Expand All @@ -109,7 +147,7 @@ class="vf-search__button | vf-button vf-button--tertiary vf-button--sm">
}
if ($('#upcoming-events').children().length <= 0) {
$('#upcoming-events').append(
'<p id="no-upcoming" class="vf-text-body vf-text-body--2">No results found.</p>');
'<p id="no-upcoming" class="vf-text-body vf-text-body--2">No results found.</p>');
}
});

Expand All @@ -121,6 +159,7 @@ class="vf-search__button | vf-button vf-button--tertiary vf-button--sm">
$('#past-events').append('<p id="no-past" class="vf-text-body vf-text-body--2">No results found.</p>');
}
});

</script>

<?php
Expand Down
1 change: 1 addition & 0 deletions wp-content/themes/vf-wp-intranet/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function add_scripts() {
require_once('functions/infoboard-news.php');
require_once('functions/people.php');
require_once('functions/relevanssi.php');
require_once('functions/training.php');


// CHILD THEME CSS FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ function training_init_register() {
'delete_with_user' => false,
'taxonomies' => array(
'training-organiser',
'embl-location',
'event-location',

),
));
Expand Down
82 changes: 82 additions & 0 deletions wp-content/themes/vf-wp-intranet/functions/training.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
// expire trainings on date field.
if (!wp_next_scheduled('expire_trainings')){
wp_schedule_event(time(), 'daily', 'expire_trainings'); // this can be hourly, twicedaily, or daily
}

add_action('expire_trainings', 'expire_trainings_function');

function expire_trainings_function() {
$today = date('Ymd');
$args = array(
'post_type' => array('training'), // post types you want to check
'posts_per_page' => -1
);
$posts = get_posts($args);
foreach($posts as $p){
$expiredate = get_field('vf-wp-training-start_date', $p->ID, false, false); // get the raw date from the db
if ($expiredate) {
if($expiredate <= $today){
$postdata = array(
'ID' => $p->ID,
'post_status' => 'draft'
);
wp_update_post($postdata);
}
}
}
}

// adds settings to run cron and unpublish trainings manually

add_action('admin_menu', 'unpublish_training_menu');

function unpublish_training_menu(){
add_submenu_page('edit.php?post_type=training', 'Training settings', 'Settings', 'manage_options', 'training-slug', 'unpublish_training_admin_page');
}

function unpublish_training_admin_page() {
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient pilchards to access this page.') );
}
// Start building the page
echo '<div class="wrap">';
echo '<h2>Unpublish past trainings manually</h2>';
// Check whether the button has been pressed AND also check the nonce
if (isset($_POST['unpublish_training']) && check_admin_referer('unpublish_training_clicked')) {
// the button has been pressed AND we've passed the security check
expire_trainings_function();
}
echo '<form action="edit.php?post_type=training&page=training-slug" method="post">';
// this is a WordPress security feature - see: https://codex.wordpress.org/WordPress_Nonces
wp_nonce_field('unpublish_training_clicked');
echo '<input type="hidden" value="true" name="unpublish_training" />';
submit_button('Unpublish');
echo '</form>';
echo '</div>';

}

// excludes drafts posts from the alternative dates selection
add_filter( 'acf/fields/relationship/query','relationship_options_filter', 10, 3);

function relationship_options_filter($options, $field, $the_post) {

$options['post_status'] = array('publish');
$options['meta_key'] = 'vf-wp-training-start_date';
$options['orderby'] = 'meta_value';
$options['order'] = 'ASC';

return $options;
}

add_filter('acf/fields/relationship/result', 'my_acf_fields_relationship_result', 10, 4);
function my_acf_fields_relationship_result( $text, $post, $field, $post_id ) {
$startDate = get_field( 'vf-wp-training-start_date', $post->ID );
if( $startDate ) {
$text .= ' ' . sprintf( '(%s)', $startDate );
}
return $text;
}

?>
Loading

0 comments on commit 1d85a91

Please sign in to comment.