根据开始时间格式化事件
仍在开发我的计划/日历应用程序。我快完成了,我已经完成了一些较难的部分,但我陷入了一个更困难的部分。我想根据事件的开始时间在网格中显示我的事件。
这张图片中没有显示,但假设 25 日左侧有一个时间栏(上午 8 点至晚上 11 点左右)。如果一个事件开始于……比如说,下午 1 点,我希望它显示在页面中间的某个位置。如果活动于上午 8:30 开始,则应在上午 8 点到 9 点之间显示。
我想我可以用表格来做到这一点,但我想知道是否还有其他方法。这可以用纯 html/css 或一些 Javascript 实现吗?关于实现这一目标的最佳方法有什么建议吗?如果我使用表格,我仍然不确定执行此操作的最佳方法是什么。每三十分钟一个单元?我可以从我的角度访问每个事件的开始和结束时间。事件数组(在本例中为第 25 个)如下所示:
Array
[1] => Array
(
[title] => Ethiek
[description] => Ethiek: Opdracht 1
[time_start] => 11:30:00
[time_end] => 12:00:00
)
[2] => Array
(
[title] => Project Management
[description] => Test: Project Management
[time_start] => 15:00:00
[time_end] => 16:00:00
)
[event_count] => 2
感谢您给我的任何建议。多谢!
编辑:开始对此进行赏金,因为我仍然陷入困境,我希望得到一些反馈。
更新:
我一直在为此绞尽脑汁,老实说我不知道最好的方法。首先,我认为我陷入困境的原因是我从数据库/数组读取事件的方式。这是我必须显示屏幕截图中所示事件的代码,不要介意我的复杂数组:
foreach($details[0] as $key => $detail)
{
echo "<div class='grid'>";
$header = "<p class='detail_header'>";
$header .= ucfirst($dates[0][$key]['name']) . ", " . $key . " " . $init['curr_month_name'];
$header .= "<img src='" . base_url() . "assets/images/create_event.png' alt='Plan iets'></p>";
echo $header;
for($i = 1; $i <= $details[0][$key]['event_count']; $i++)
{
echo "<div class='event " . $details[0][$key][$i]['type'] . "'>";
echo "<p class='event_title'>" . $details[0][$key][$i]['title'] . "</p>";
echo $details[0][$key][$i]['description'];
echo "</div>";
}
echo "</div>";
}
这有点混乱,更不用说我另一次有相同的代码来修复一些异常。但更重要的是..我觉得这些循环不允许我对其进行大量修改。我尝试为 AM 和 PM 添加两个 div,这样我就可以将事件分成中午之前和下午的块,然后只显示事件的时间(以避免必须处理 1000 个 15 分钟的块)。但是,是的.. 这并没有成功,因为如果下午有多个活动,它会放置几个“PM”div。
我很想暂时保留它,只在事件 div 中显示开始/结束时间......直到我找到一种更好的方法来从数组中读取它们并显示它们。
任何帮助/建议表示赞赏。谢谢。
Still working on my planner/calendar application. I'm nearly done, I got some of the harder parts working but I'm stuck at one more difficult part. I want to show my events in a grid according to their start time.
It doesn't show in this picture, but pretend there's a column with hours (8am - 11pm or so) at the left of the 25th. If an event starts at.. say, 1pm, I would like it to show somewhere in the middle of the page. If an event starts at 8:30 am, it should show between 8am and 9am.
I guess I could do this with tables, but I was wondering if there's another way. Is this doable with plain html/css, perhaps some Javascript? Any suggestions on what the best way would be to achieve this? If I use a table, I'm still not sure what would be the best way to do this. A cell for every thirty minutes? I have access to the start and end time of each event from my view. An event array (in this example, the 25th) looks like this:
Array
[1] => Array
(
[title] => Ethiek
[description] => Ethiek: Opdracht 1
[time_start] => 11:30:00
[time_end] => 12:00:00
)
[2] => Array
(
[title] => Project Management
[description] => Test: Project Management
[time_start] => 15:00:00
[time_end] => 16:00:00
)
[event_count] => 2
I appreciate any advice you can give me. Thanks a lot!
EDIT: Started a bounty on this because I'm still stuck and I would appreciate some feedback.
UPDATE:
I've been breaking my head over this and I honestly can't figure out the best way to do this. First of all, I think the reason I'm stuck is the way I read out my events from the db/array. This is the code I have to display the events as seen in my screenshot, don't mind my complex arrays:
foreach($details[0] as $key => $detail)
{
echo "<div class='grid'>";
$header = "<p class='detail_header'>";
$header .= ucfirst($dates[0][$key]['name']) . ", " . $key . " " . $init['curr_month_name'];
$header .= "<img src='" . base_url() . "assets/images/create_event.png' alt='Plan iets'></p>";
echo $header;
for($i = 1; $i <= $details[0][$key]['event_count']; $i++)
{
echo "<div class='event " . $details[0][$key][$i]['type'] . "'>";
echo "<p class='event_title'>" . $details[0][$key][$i]['title'] . "</p>";
echo $details[0][$key][$i]['description'];
echo "</div>";
}
echo "</div>";
}
It's a bit of a mess, not to mention that I have the same code another time to fix some exceptions. But more importantly.. I feel like those loops don't allow me to make a lot of modifications to it. I tried adding two divs for AM and PM so I could split up the events in before-noon and afternoon blocks, and then just display the time on the event (to avoid having to work with a thousand blocks of 15 minutes). But yeah.. That didn't work out since it would put a couple of 'PM' divs if there is more than one event in the afternoon.
I'm tempted to just leave it like it is for now and just display the start/end time in the event divs.. until I figure out a better way to read them from the array and display them.
Any help/suggestions appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
其实我现在也在做这个。我的解决方案是使用 960.gs 之类的 div。
首先,我定义了一系列常量:显示开始时间、显示结束时间、每小时列数、总列数。就我的应用程序而言,这些变量可由用户配置。
其次,我查询需要处理的一系列事件。其中包括开始时间和结束时间,以及我想要显示的详细信息。我将使用 jQuery QTip 弹出悬停的详细信息,因此填充这些信息的数据也包含在这个查询。
现在,960.gs 概念。网格的基础是知道您有 X 的空间来显示您的内容……如果是 960,则为 960 像素。我的是更定制的,但这提供了概念。您可以将其除以相当多的数字,这将成为如何分割网格的基础。使用这种方法,我可以轻松地定义从 grid_1 到 grid_4 的列,并且其宽度将占总宽度的相应百分比(即在 16 列布局上,执行 4 列 div 将覆盖 25%)。浏览器兼容,并且不需要大量的清晰 div。您只需将数字相加即可匹配您要使用的列数。
现在,我开始计算每列代表多少时间。我使用 foreach 循环来汇总每一天:我从显示开始时间的小时开始并递增。如果事件的 start_time 等于增量器,我会启动一个根据我的着色标准设置适当样式的 div。同样,如果我的结束时间 <= 增量器,我将停止 div 并在 id 中定义列的宽度。显然,在循环结束时,我执行了一个增量++。每天重复您显示的内容。
我的想法是在每周类型的日历的时间基础上执行此操作。但总体思路可以很容易地修改为月份式日历,甚至是日式日历。
表格肯定会让这一切变得更容易(版本 1 是表格),但如果你有耐心,这两种方法都可以完成。
I'm actually also doing this right now. My solution was to go with 960.gs-like divs.
First, I define a series of constants: Start time to display, end time to display, columns per hour, total columns. In my app's case, these variables are configurable by the user.
Second, I query an array of events that I need to deal with. These include a start time and end time, plus the details I want to display. I'll be using jQuery QTip to popup details that hover, so data to populate those is also included in this query.
Now, the 960.gs concept. The basis for a grid is knowing that you have X amount of space to display your content...with 960, it's 960 pixels. Mine is more custom, but this provides the concept. You can divide this by quite a few numbers, which becomes the basis for how to split the grid. Using this approach, I can easily define a column from grid_1 to grid_4, and it will take a width that is a commensurate percentage of the overall width (i.e. on a 16 column layout doing a 4 column div would cover 25%) It's cross-browser compatible, and doesn't require an overt amount of clear divs. You just need to make the numbers add up to match the amount of columns you want to work with.
Now, I begin by doing the math to figure out how much time each column represents. I assemble each day using a foreach loop: I start with the hour of the display start time and increment up. If the start_time of an event equals the incrementer, I start a div that's styled appropriately based on my coloring criteria. Likewise, if my end time <= the incrementer, I stop the div and define the column's width in the id. Obviously, at the end of the loop, I do an incrementer++. Repeat per day that you display.
My concept is doing this on an time basis for a weekly type calendar. But the overall idea could easily be modified for a month-style calendar or even for a day calendar.
Tables definitely make this easier (version 1 was tables) but it can be done either way if you have the patience.
你关于桌子的想法听起来是最好的选择。假设表格边框全部隐藏,您可以选择应用程序指定的任何时隙大小,而不会使其看起来太混乱。
如果他们只需要在正确的时间大致排队,我就会从代表 15 分钟的一行开始。您在每个块上的
:hover
效果可以显示准确的时间,然后表格就在那里,让您可以在大约 15 分钟的时间段内行跨度
您的事件,使其保持一致足够高以使其在视觉上具有代表性。Your idea about tables sounds like the best option. Assuming that the table borders are all hidden, you can go down to whatever time slot size your application dictates without making it look too messy.
I'd just start with a row representing 15 minutes if they just need to line up roughly at the correct times. Your
:hover
effect on each block could show the exact times, and the table is then just there to allow you torowspan
your events through rough 15 minute timeslots to make it line up enough that it's visually representative.您可以采用 CSS 方法和日历条目的绝对定位。然后,您需要为每个时间段提供一个 css 类。只是为了提供一些指导:
与 960grid 的想法相同
这 顶部位置的百分比,因此上午 8 点为 8%,下午 6 点为 100%。根据可用的大小和内容,这有点棘手,但可以解决。还没试过。只是让我想到了另一种可能性。
You could go with a css approach and absolute positioning of your calendar entries. You would then need a css class for each timeslot. Just to give some orientation:
It's the same idea as it is bedind 960grid
As an alternative you could maybe use a percentage for the position from the top so 8am would be 8% and 6pm 100%. It's a bit tricky depending on the available size and stuff but could work out. Haven't tried it yet. Just stuck my mind as another possibility.
我建议不要使用表格,而是使用 Javascript 和 CSS。
我建议实现此目的的最简单方法是使用 jQuery 的功能;
为此,您需要用 JSON(Javascript 对象表示法)表示事件。使用 php,使用 json_encode() 很容易做到这一点。
这种方法一开始可能有点难以理解,但它可以使您的标记 (HTML) 保持非常干净,并且适用于任何尺寸的屏幕。最重要的是,由于您的事件将表示为 Javascript 对象,因此它为您提供了一个创建真正丰富的 Ajax 应用程序的非常好的起点。
I would advise not to use tables, but instead Javascript and CSS.
I suggest the easiest way to implement this is by using the power of jQuery;
In order to do this, you would need to represent your events in JSON (Javascript Object Notation). Using php, this is easy with json_encode().
This method can be a little complicated to understand at first, but it keeps your markup (HTML) very clean and works really well with any size screen. Most importantly, as your events will be represented as Javascript Objects, it gives you a really great starting point to making a really rich Ajax application.
很高兴听到你正在取得进步。
在我看来,表格仍然是最好的解决方案。想一想:
- 您可以设置宽度、高度等样式,以类似网格的方式设置它们,这就是您想要的。
- 你确切地知道结构,所以运行表格是简单的循环代码
,对我来说最重要的是:
- 表格提供可访问性。由于屏幕阅读器可以为有视力障碍的观看者以有意义的方式解释表格,因此当内容通过行和列变得有意义时,表格特别有用,这正是您所拥有的。
顺便说一句,完成后请为我们输入正在运行的版本的 URL。
glad to hear you're making progress.
Tables still appear to me the best solution for this. Think about this:
- you can style width, height, etc, to set them in a grid like way, which is what you want.
- you know exactly the structure, so running through the table is simple loop code
And the clincher for me:
- tables provide accessibility. Because screenreaders have ways to interpret tables in meaningful ways for sight-impaired viewers, the tables a particularly helpful when the contents is made meaningful by the rows and columns, which is exactly what you've got.
By the way, put in the URL of a running version for us when you're done.
哟。我一直在寻找我必须构建的网站的日历模块的类似问题。我将其放在 C# 中,因此代码并不真正适合您的完整答案,但我查看数据的方式可能会有所帮助。
现在表格相当困难,所以请原谅它的粗糙性:P
如果你会看上面的内容。我有一天有开始时间或结束时间。这可以转换为您需要的任何时间格式 周月 无论如何。重点是,您可以查看所有项目并找到最早开始日期和最晚结束时间,计算 100% 的活动距离(对我来说是 810 分钟)。
从这里您可以计算个人甚至需要覆盖的%点
(单个事件运行时间/总事件运行时间 * 100)。这将是绘制单个项目的距离。
并给该项目一个起点(这也应该是一个百分比),但事件一的起点是 180 分钟(总事件开始时间 - 项目事件开始时间)
谢谢。
凯杰
Yo. I have been looking at a similar problem for a calendar module of a website I have to build. I am putting it together in c# so the code would not really suite your answer full but the way that i've looked at data may help.
Now tables are pretty hard so forgive the crudness of this :P
If you will look at the above. I have a day with start time or end time. This can be converted to what ever time format you need week month whatever. The point is that you can look at all your items and find the earliest start date and latest end time calculating 100% of your event distance(for me 810 mins).
From here you can calculate % points that an individual even needs to cover
(single event run time/total event runtime * 100). This would be the distance to draw that individual item.
And give that item a starting point(this should be a percentange as well) but starting point for event one is 180 mins(total event start time - item event start time )
Thanks.
KJ