diff --git a/.gitignore b/.gitignore index 7e8c9eac7c4416e172854f64fac4b58f50b3e87c..732736deb02e14576e195ad86d5a1186b46b1235 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,7 @@ node_modules/ # dotenv environment variables file .env + +# VS CODE +.vscode/ +workspace.code-workspace diff --git a/build/block.json b/build/block.json index e24a5b2365e4974db5fc13de75c09b69e3e97d15..c9057a942386683e4e19aa7c8698db310d844f7e 100644 --- a/build/block.json +++ b/build/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "acf/cpl-libcal-block", - "version": "1.0.9", + "version": "1.2.0", "title": "CPL Libcal Block", "category": "embed", "icon": "calendar-alt", diff --git a/build/index.asset.php b/build/index.asset.php index 12de3adfaf2e701c51754be148b0bef786f7bef7..f998c821ffd60e192fff54d1ecf12c5e43fa3691 100644 --- a/build/index.asset.php +++ b/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => '82982a152c4b55afc3ac'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'fffaf40064e605fc8f56'); diff --git a/build/index.js b/build/index.js index 09b0f9c9d1bd1bf89a4f21d31acea156e0de7c93..e86323bcbf86c12df0c24ff49f7277e819bbf8c9 100644 --- a/build/index.js +++ b/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,r={227:function(){var e=window.wp.blocks,r=window.wp.element,n=window.wp.i18n,o=window.wp.blockEditor,l=JSON.parse('{"u2":"acf/cpl-libcal-block"}');(0,e.registerBlockType)(l.u2,{edit:function(){return(0,r.createElement)("p",(0,o.useBlockProps)(),(0,n.__)("Cpl Libcal Block – hello from the editor!","cpl-libcal-block"))},save:function(){return(0,r.createElement)("p",o.useBlockProps.save(),(0,n.__)("Cpl Libcal Block – hello from the saved content!","cpl-libcal-block"))}})}},n={};function o(e){var l=n[e];if(void 0!==l)return l.exports;var t=n[e]={exports:{}};return r[e](t,t.exports,o),t.exports}o.m=r,e=[],o.O=function(r,n,l,t){if(!n){var c=1/0;for(p=0;p=t)&&Object.keys(o.O).every((function(e){return o.O[e](n[u])}))?n.splice(u--,1):(i=!1,t0&&e[p-1][2]>t;p--)e[p]=e[p-1];e[p]=[n,l,t]},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},function(){var e={826:0,431:0};o.O.j=function(r){return 0===e[r]};var r=function(r,n){var l,t,c=n[0],i=n[1],u=n[2],a=0;if(c.some((function(r){return 0!==e[r]}))){for(l in i)o.o(i,l)&&(o.m[l]=i[l]);if(u)var p=u(o)}for(r&&r(n);a{"use strict";var l,e={250:()=>{const l=window.wp.blocks,e=window.React,o=window.wp.i18n,r=window.wp.blockEditor,c=JSON.parse('{"u2":"acf/cpl-libcal-block"}');(0,l.registerBlockType)(c.u2,{edit:function(){return(0,e.createElement)("p",{...(0,r.useBlockProps)()},(0,o.__)("Cpl Libcal Block – hello from the editor!","cpl-libcal-block"))},save:function(){return(0,e.createElement)("p",{...r.useBlockProps.save()},(0,o.__)("Cpl Libcal Block – hello from the saved content!","cpl-libcal-block"))}})}},o={};function r(l){var c=o[l];if(void 0!==c)return c.exports;var t=o[l]={exports:{}};return e[l](t,t.exports,r),t.exports}r.m=e,l=[],r.O=(e,o,c,t)=>{if(!o){var i=1/0;for(s=0;s=t)&&Object.keys(r.O).every((l=>r.O[l](o[a])))?o.splice(a--,1):(n=!1,t0&&l[s-1][2]>t;s--)l[s]=l[s-1];l[s]=[o,c,t]},r.o=(l,e)=>Object.prototype.hasOwnProperty.call(l,e),(()=>{var l={826:0,431:0};r.O.j=e=>0===l[e];var e=(e,o)=>{var c,t,[i,n,a]=o,p=0;if(i.some((e=>0!==l[e]))){for(c in n)r.o(n,c)&&(r.m[c]=n[c]);if(a)var s=a(r)}for(e&&e(o);pr(250)));c=r.O(c)})(); \ No newline at end of file diff --git a/build/style-index.css b/build/style-index.css index e29b6be60c19b586b820edc756688e7baaadf627..451f2650c03f1316ca451f36ef73dca2fa08495d 100644 --- a/build/style-index.css +++ b/build/style-index.css @@ -1 +1 @@ -.entry-content .cpl-flex--mini{margin-left:0}.entry-content .cpl-flex--mini__item{border:solid #000;justify-content:center;list-style-type:none;margin-bottom:1rem;padding:.75rem}.cpl-flex--mini__item-name{font-size:1.25em;font-weight:650}.cpl-flex--mini__item-date{font-weight:500}.cpl-flex--mini__item>p{margin-top:1em} +.media-object__media{display:none}.media-object-container{border:3px solid #111;margin-bottom:15px;padding:20px 20px 0}@media screen and (min-width:500px){.media-object-container{grid-gap:20px;display:grid;grid-template-areas:"area-media area-object" "area-media area-footer";grid-template-columns:fit-content(200px) 1fr;grid-template-rows:1fr auto}.media-object-container--flipped{grid-template-areas:"area-object area-media" "area-footer area-media";grid-template-columns:1fr fit-content(250px)}.media-object__media{display:block;grid-area:area-media}.media-object__object{grid-area:area-object}.footer{grid-area:area-footer}.media-object__media{-ms-grid-row-span:3;-ms-grid-column:1;-ms-grid-row:1}.media-object-container--flipped>.media-object__media{-ms-grid-row-span:2;-ms-grid-column:2;-ms-grid-row:1}.media-object__object{-ms-grid-column:3;-ms-grid-row:1}.media-object-container--flipped>.media-object__object{-ms-grid-column:1;-ms-grid-row:1}.footer{-ms-grid-column:3;-ms-grid-row:3}.media-object-container--flipped>.footer{-ms-grid-column:1;-ms-grid-row:2}}.entry-content .cpl-flex--mini{margin-left:0}.entry-content .cpl-flex--mini__item{justify-content:center;list-style-type:none;margin-bottom:0;padding-bottom:0}@media screen and (max-width:979px){.entry-content .cpl-flex--mini__item{padding:.75rem}}h3.cpl-flex--mini__item-name{font-size:1.25em;font-weight:650;margin-top:0!important}.cpl-flex--mini__item-date{font-weight:500}.cpl-flex--mini__item>p{margin-top:1em} diff --git a/cpl-libcal-block.php b/cpl-libcal-block.php index 17d68594acaf14c1f60e4cbdfe2417461b3105cf..3dc40430b25b021080c4ab2def92fa8f543154e6 100644 --- a/cpl-libcal-block.php +++ b/cpl-libcal-block.php @@ -4,7 +4,7 @@ * Description: Gutenberg block that display CPL's events from Libcal calendar. Requires ACF Pro 6. * Requires at least: 6.0 * Requires PHP: 7.2+ - * Version: 1.0.9 + * Version: 1.2.0 * Author: Will Skora and the CPL Team * License: GPL-2.0-or-later * License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -84,6 +84,57 @@ function format_start_time( $input_date ) { return $formatted_date; } +/* +display_events_featured_image +display a fallback image based on the event's audience + +@param {array} $audience_array +typically consists of multiple audiences; each audience will consist of consists of 2 key=value pairs; + +e.g. Array +( [0] => stdClass Object ( [id] => 194 [name] => Adults Ages 19+ ) +[1] => stdClass Object ( [id] => 1741 [name] => Seniors ) +[2] => stdClass Object ( [id] => 1742 [name] => All Ages ) +[3] => stdClass Object ( [id] => 4989 [name] => Children Ages 6-11 ) )\ + +each image only represents 1 audience +per m.young; prioritize the youngest to oldest + +array_column pulls out all of the values for the key "id" in the array $audience_array, and returns them as an array + +array_search will first look to see if the audience ID (e.g. 1742) exists somewhere in the array +the !== FALSE is there; so that if there is only 1 audience in the audience_array; array_search will still find the audience ID + +*/ + +function display_events_featured_image( $audience_array ) { + if ( array_search( 1742, array_column( $audience_array, 'id' ) ) !== false ) { + echo 'Event For all ages'; + } elseif ( array_search( 195, array_column( $audience_array, 'id' ) ) !== false ) { + echo 'Event For young children under 6 years old'; + } elseif ( array_search( 4849, array_column( $audience_array, 'id' ) ) !== false ) { + echo 'Event For kids'; + } elseif ( array_search( 196, array_column( $audience_array, 'id' ) ) !== false ) { + echo 'Event For teens'; + } elseif ( array_search( 194, array_column( $audience_array, 'id' ) ) !== false ) { + echo 'Event For adults'; + } elseif ( array_search( 1741, array_column( $audience_array, 'id' ) ) !== false ) { + echo 'Event For seniors'; + } else { + echo ''; + } +} + + +// audience-> +// array( "1742" => "all ages", +// "195" => "Children 0-5", +// "4849" => "Kids 6011", +// "196" => "Teens", +// "194" => "adults", +// "1741" => "seniors" + + function block_render_callback( $block, $content = '', $is_preview = false, $post_id = 0 ) { $days_in_advance_to_show_var = sanitize_text_field( get_field( 'days_in_advance_to_show' ) ); @@ -92,9 +143,6 @@ function block_render_callback( $block, $content = '', $is_preview = false, $pos $initial_response = wp_remote_get( $my_api_base_url ); - // creates a variable for the fully constructured API URL; requires query-monitor plugin - // do_action( 'qm/debug', $my_api_base_url ); - if ( is_wp_error( $initial_response ) ) { return false; // can I return something else more verbose to the user? } @@ -112,7 +160,7 @@ function block_render_callback( $block, $content = '', $is_preview = false, $pos // detect if the response is empty; if so, return message if ( empty( $response_object->events ) ) { - ?>

No events currently scheduled at this location.

+ ?>

No events are currently scheduled at this location.

@@ -129,9 +177,22 @@ function block_render_callback( $block, $content = '', $is_preview = false, $pos format_start_time( $teh_date ); ?> -
  • - title; ?> -

    +
    +
    + featured_image ) ) { + echo ''; + } else { + display_events_featured_image( $event->audience ); + } + ?> +
    +
    +
  • +

    + title; ?> +

    campus->name ) ) { @@ -186,6 +247,9 @@ function block_render_callback( $block, $content = '', $is_preview = false, $pos ?>
  • + + +