Sorting by date and weekday

Hello,
I have a calendar with a date-field and weekday field(text)
there are events with date or weekly repetitions

how can I sort the pages by date and weekday,
when the date is not set but the weekday ?

like this:

  • Donnerstag 27.0.2017
  • Freitag 28.07.2017
  • Jeden Samstag
  • Sonntag 30.07.2017

blueprint


title: message

pages: false


fields:

  title:
    label: title
    type: text

  date:
    label: Datum
    type:  date
    width: 1/3

  start_time:
    label: Startzeit
    type: time
    width: 1/3

  end_time:
    label: Endzeit
    type: time
    width: 1/3


  fix_date:
    label: Wiederholende Veranstaltung - Wochentag
    type: text

  text:
    label: Text
    type: markdown

  image:
    label: Image
    type: image

template

<?php foreach($site->find('kalender')->children()->visible() as $article): ?>
         <article class="grid-24-8">
         <?php $day_arr = array("null", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag",  "Samstag",  "Sonntag"); ?>
         <time class="flex">
          <?php if($article->date() != ""){ ?>
          <span><?php echo $day_arr[strftime($article->date('w'))] ?></span>
          <div>
          <?php echo strftime($article->date('d'))."." ?>
          <?php echo strftime($article->date('m'))."." ?>
          <?php echo strftime($article->date('Y')) ?>
          </div>
          <?php } else { echo "<span>".$article->fix_date()."</span>"; }?>
          </time>

           <h3><?php echo $article->title() ?></h3>
           <div><?php echo $article->text()->kirbytext() ?></div>
        </article>
        <?php endforeach ?>

First, looks like you want to make your life complicated, why not simply get the date like this

<div>
<?php echo $page->date('d.m.Y') ?>
</div>

instead of using strftime and outputting every date element separately?

I actually had a similar task, but I use a startdate and an enddate in the events rather than just the day of week. Then you can get all dates in between those two dates, and take it from there. The DateTime PHP class is your friend, it gives you methods to create intervals etc.

yes, simpler

      <section class="grid-24-18 flex calendar justify-content-spacebetween">
          <h2><?php echo $site->children()->visible()->find('kalender')->title()  ?></h2>

        <?php foreach($site->find('kalender')->children()->visible() as $article): ?>
         <article class="grid-24-8">
         <?php $day_arr = array("null", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag",  "Samstag",  "Sonntag"); ?>
          <time class="flex">
            <?php if($article->date() != ""){ ?>
            <span><?php echo $day_arr[$article->date('w')] ?></span>
            <div>
              <?php echo $article->date('d.m.Y') ?>
            </div>
            <?php } else { echo "<span>".$article->fix_date()."</span>"; }?>
          </time>

          <h3><?php echo $article->title() ?></h3>
          <div><?php echo $article->text()->kirbytext() ?></div>
        </article>
        <?php endforeach ?>
      </section>

Is there no possibility to sort the pages in the panel?

title: message-overview

pages: 
  template: message
  num: date


fields:
  title:
    label: Title
    type:  text
    readonly: true



files: false


The num option is only relevant for the sorting number when the page is visible. There is no manual sorting like with files. It wouldn’t help you at all, by the way, because your event is a repeating event, how do you want to sort that manually?

For what sort of time period do you want to output the events? If you want an easy way, you could loop through the days of a week or month, check for each day if an event fits that date or - if the date is empty - if the weekday fits, and then output that event.

However, are you sure an event always takes place on a certain weekday, without any exceptions? What about public holidays etc.?

This is part of my event blueprint:

  start_date:
    icon: calendar
    label: Startdatum
    type: date
    width: 1/4
    required: true
  end_date:
    icon: calendar
    label: Enddatum
    type: date
    width: 1/4
    required: true
  start_time:
    label: Anfang
    type: time
    interval: 15
    width: 1/4
  end_time:
    label: Ende
    type: time
    interval: 15
    width: 1/4
  event_location:
    label: Veranstaltungsort
    type: select
    width: 1/3
    options: query
    query:
      page: veranstaltungsorte
      fetch: children
      value: '{{location_name}}'
      text: '{{location_name}}'
  event_repeat:
    label: Wiederkehrendes Ereignis?
    type: select
    width: 1/3
    default: no
    required: true
    options:
      no: nein
      "1 day": Täglich
      "1 week": Wöchentlich
      "2 weeks": Zweiwöchentlich
      "1 month": Monatlich
  exceptions:
    label: Ausnahmen
    type: structure
    style: table
    fields:
      date:
        label: Datum
        type: date
    width: 1/3

@texnixe i found a solution to sort the events by date

php

      <section id="calendar">
        <h2><?php echo $site->children()->visible()->find('kalender')->title()  ?></h2>
        <div class="grid-24-18 flex calendar justify-content-spacebetween">

            

          <?php foreach($site->find('kalender')->children()->visible() as $article): ?>
          
          
          <!--Veranstaltung einmalig -->
          <?php if($article->date_event() != ""){ ?>
          <!-- Wochentag -->
          <?php $weekday = $day_arr[date("w",strtotime($article->date_event()))]; ?>
          <!-- Datum -->
          <?php $event_date = date("d.m.Y",strtotime($article->date_event())); ?>


          <article class="grid-24-8" data-date = "<?php echo $article->date_event() ?>">

            <time class="flex">
             
              <span>
                <?php echo $weekday ?>
              </span>
              
              <div>
                 <?php echo $event_date ?>
              </div>
            </time>

            <h3><?php echo $article->title() ?></h3>
            <div><?php echo $article->text()->kirbytext() ?></div>
          </article>
          <?php } ?>


            
          <!--Veranstaltung wiederkehrend -->
          <?php if($article->periode_date_start() != ""){ ?>
            
            
               
          <?php if($article->periode_date_end() > date("Y-m-d")){ ?>
          <!-- Wochentag -->
          <?php $weekday = $day_arr[date("w",strtotime($article->periode_date_end()))]; ?>
          <!-- Datum - Nächster Wochentag-->
          <?php
            $get_weekday = date("l",strtotime($article->periode_date_end()));
            $event_date = date("d.m.Y", strtotime("next ".$get_weekday));
            $event_date_js = date("Y-m-d", strtotime("next ".$get_weekday));
          ?>

          <article class="grid-24-8" data-date = "<?php echo $event_date_js ?>">

            <time class="flex">
              <span>
               <?php echo $weekday ?>
              </span>
             
              <div>
                <?php echo $event_date ?>
              </div>
            </time>

            <h3><?php echo $article->title() ?></h3>
            <div><?php echo $article->text()->kirbytext() ?></div>
          </article>

          <?php } ?>
          <?php } ?>

        <?php endforeach ?>
        <div>
      </section>

sort with js

	$(function() {


  var $list = $("section#calendar div");
  $list.children().detach().sort(function(a,b){
    return new Date($(a).attr("data-date")) > new Date($(b).attr("data-date"));
    }).appendTo($list);



});	

Thank you for helping