Skip to content

Commit

Permalink
Merge pull request #18 from TobiasPrt/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
TobiasPrt authored Apr 5, 2021
2 parents 9b4af0e + f29cd1a commit e956b21
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 34 deletions.
2 changes: 2 additions & 0 deletions includes/custom-blocks/block-block-2.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
'value' => true,
),
) ),
Field::make( 'text', 'button_extern', __( 'Externer Link' ) )
->set_help_text( 'Feld leer lassen, wenn interner Link verwendet werden soll.' ),
Field::make( 'select', 'button_link', __( 'Button Link' ) )
->set_options( call_user_func( 'get_all_posts', array( 'page', 'job', 'service', 'store' ) ) )
->set_help_text( 'Seite zu dem der Button führen soll' )
Expand Down
24 changes: 24 additions & 0 deletions includes/custom-blocks/block-employees.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,41 @@
* @since 1.0.0
*/
(function() {
$employees = call_user_func( 'get_all_posts', 'employee' );

Block::make( __( 'Employees' ) )
->set_description( __( 'Ein 4-spaltiges Layout, dass alle Mitarbeiter:innen sortiert nach Gruppen und Alphabetisch mit Foto, Name und Rolle darstellt.') )
->set_category( 'widgets', __( 'Vorausgefüllte Blocks' ) )
->set_parent( 'carbon-fields/section' )
->set_icon( 'businessperson' )
->add_fields( array(
Field::make( 'separator', 'separator', __( 'Employees' ) ),
Field::make( 'set', 'employees', __( 'Mitarbeiter:innen auswählen' ))
->set_options( $employees ),
Field::make( 'checkbox', 'show_application_link', __( 'Call-To-Action: Jetzt bewerben anzeigen' ) )
->set_help_text( 'Dieser Block stellt ein 4-spaltiges Grid aus allen Mitarbeiter:innen von Smartphoniker dar.' )
) )
->set_render_callback( function ( array $fields, array $attributes, string $inner_blocks ) {
$employees = array();

foreach ( $fields['employees'] as $employee => $employee_id ) {
$employees[$employee_id] = get_post_meta( $employee_id );
$employees[$employee_id]['id'] = $employee_id;
$employees[$employee_id]['name'] = get_the_title( $employee_id );
}

// sort by group and then by name
uasort( $employees, function($a, $b) {
if( $a['_group'][0] === $b['_group'][0] ) {
if ( $a['name'] > $b['name'] ) {
return 1;
}
}
return $a['_group'][0] > $b['_group'][0] ? 1 : -1;
});

$fields['employees'] = $employees;

get_template_part( 'template-parts/component', 'employees', $fields );
} );
})();
5 changes: 5 additions & 0 deletions includes/custom-blocks/block-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
) )
->set_render_callback( function ( array $fields, array $attributes, string $inner_blocks ) {

$fields['stores'] = array_filter($fields['stores']);
$fields['stores'] = array_filter($fields['stores'], function ( $key ) {
return get_post_status( $key );
});

$locations = array();
foreach( $fields['stores'] as $store => $store_id ) {
array_push( $locations, array(
Expand Down
3 changes: 3 additions & 0 deletions includes/custom-blocks/block-stores.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
) )
->set_render_callback( function ( array $fields, array $attributes, string $inner_blocks ) {
$fields['stores'] = array_filter($fields['stores']);
$fields['stores'] = array_filter($fields['stores'], function ( $key ) {
return get_post_status( $key );
});
get_template_part( 'template-parts/component', 'stores', $fields );
} );
})();
2 changes: 1 addition & 1 deletion style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion style.css.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion stylesheets/components/_grid-5.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@

&__img {
padding: 3rem 2rem;
border-bottom: 1px solid #a6a6a6;
object-fit: scale-down;
max-width: 100%;
max-height: 15rem;
height: 15rem;
}

&__subtitle {
@include fg(orange);
@extend .text-sm;
border-top: 1px solid #a6a6a6;
font-weight: 400;
padding: 1rem 0;
display: block;
Expand Down
8 changes: 6 additions & 2 deletions template-parts/component-block-2.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@
<!-- Button -->
<?php if ( $content['button_is_enabled'] ): ?>
<a
class="block-2__button button button--<?php echo esc_html( $args['color'] ); ?>"
href="<?php echo get_permalink( $content['button_link'] ); ?>"
class="block-2__button button button--<?php echo esc_html( $args['color'] ); ?>"
<?php if ( isset( $content['button_extern']) && $content['button_extern'] != '' ):?>
href="<?php echo $content['button_extern']; ?>"
<?php else: ?>
href="<?php echo get_permalink( $content['button_link'] ); ?>"
<?php endif; ?>
target="<?php echo esc_html( $content['button_target'] ); ?>"
>
<?php echo esc_html( $content['button_text'] ); ?>
Expand Down
37 changes: 8 additions & 29 deletions template-parts/component-employees.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,20 @@
* @package Smartphoniker
* @since 1.0.0
*/


$employees = new WP_Query( array(
'posts_per_page' => -1,
'post_type' => 'employee',
'orderby' => array(
'group' => 'ASC',
'title' => 'ASC',
),
'meta_query' => array(
'group' => array(
'key' => 'group',
'compare' => 'EXISTS'
),
),
) );
?>

<div class="section__content grid-4">

<!-- Grid of employees -->
<?php if ($employees->have_posts() ) : ?>

<?php while ( $employees->have_posts() ) : $employees->the_post(); ?>

<div class="grid-4__element person">
<?php echo wp_get_attachment_image( get_post_meta( get_the_ID(), '_image' )[0], 'medium', false, array( 'class' => 'person__img' ) ); ?>
<p class="person__name"> <?php the_title(); ?></p>
<p class="person__title"><?php echo get_post_meta( get_the_ID(), '_role' )[0]; ?></p>
</div>

<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php foreach ( (array) $args['employees'] as $employee_id => $employee ): ?>
<div class="grid-4__element person">
<?php echo wp_get_attachment_image( $employee['_image'][0], 'medium', false, array( 'class' => 'person__img' ) ); ?>
<p class="person__name"> <?php echo $employee['name'] ?></p>
<p class="person__title"><?php echo $employee['_role'][0]; ?></p>
</div>

<?php endforeach; ?>

<?php endif; ?>

<!-- Link for application -->
<?php if ( in_array( 'show_application_link', $args ) ): ?>
Expand Down

0 comments on commit e956b21

Please sign in to comment.