List of events with a list of timestamps, grouped by hour in a tabular display, in PHP.

后端 未结 2 549
面向向阳花
面向向阳花 2021-01-15 06:13

While refactoring, I am looking for an optimised algorithm for a timetable (calendar) in PHP.

I have a list of events which have a list of timestamps. This must be p

相关标签:
2条回答
  • 2021-01-15 06:32

    I'm not familiar with Drupal at all, so I'm going to make a suggestion based on my own approach to your request to refactor the display of a list of movie titles in one column, and the start time in the appropriate time column.

    You are starting with an array of movies (or 'films') containing movie titles and start timestamps. I assume somewhere you can retrieve or create an array of hours for the column title.

    The example below ignores that you are dealing with an object, or that the object contains arrays, only to exhibit an alternate pattern approach. Rather than all the formatting and sorting you appear to be doing, this pattern iterates over each movie and uses a second foreach to iterate over the hour columns, and tests if the movie time matches the hour time.

    <?php foreach($movie_array as $movie){
        echo '<td>'.$movie['title'].'</td>';
        foreach($hours as $hour){
            if(date('H',$movie['starts_at']) == date('H',$hour)){
                echo '<td>'.date('H:i',$movie['starts_at']).'</td>';
            }//endif
            else{
                echo '<td></td>';
            }//endelse
        }//endforeach
     }//endforeach
    ?>
    

    I've skipped setting up the table, and of course, you could replace my html entities with however you prefer to set up the table.

    I think this is a viable pattern that seems to simplify the logic of your original pattern, and remains flexible. Hopefully I haven't misunderstood and omitted a critical part of your problem.

    0 讨论(0)
  • 2021-01-15 06:38

    Have you tried "Calendar" module. The Calendar module can be used to list the events as calendar. It is having views, taxonomy and cck support. The customization is also very easy.

    I am suggesting to find out contributed modules before thinking about our script. We can think about our script only if there is no contributed modules which satisfies our requirements.

    0 讨论(0)
提交回复
热议问题