doqp87012 2012-07-03 02:42
浏览 10

在日历上显示工作日

I am having a problem. I can't display the weekdays. So when I click next it should display the week for nextweek displaying Monday to Friday. And when I click previous it should display lastweek Monday to Friday

here's my code

in controller

    <?php
        public function calendar($dt) {
    //         = date("Y/m/d");
            $beginDate = $dt;
            $endDate = date("Y-m-d", strtotime($dt . "+6 days"));

            $posts = $this->Post->getWeekPosts($beginDate, $endDate);
            $members = $this->Post->PostgetUniqueMembers($posts);
    //        $week = $this->Post->weekNo($beginDate, $endDate);

            $this->set("posts", $posts);
            $this->set("members", $members);
            $this->set("begin", $beginDate);
    //        $this->set("week", $week);
        }


in view

<div id="content">
        <span id="calendar-week">
<!--            <h2> week  <?php echo $week; ?> <?php echo date("F Y", strtotime($begin)) ?> </h2>-->
            <h2> week <?php echo date("F Y", strtotime($begin)) ?> </h2>
            <a href="/cakemgmt/posts/calendar/<?php echo date("Y-m-d", strtotime($begin . "- 6 days")) ?>">Previous</a> | 
            <a href="/cakemgmt/posts/calendar/<?php echo date("Y-m-d", strtotime($begin . "+ 6 days")) ?>">Next</a>
        </span>

        <div id="calendar">
            <table>

                <tr id="calendar-names"><!-- member names -->

                    <td>&nbsp;</td>

                    <?php foreach ($members as $member) { ?>
                        <td><p><?php echo $member ?></p></td>
                    <?php } ?>

                </tr>

                <?php
                foreach ($posts as $key => $post) {
                    ?>
                    <tr>
                        <td class="calendar-background-days"><p class="calendar-days"><?php echo date("D", strtotime($key)) ?></p></td>
                        <?php foreach ($members as $memberKey => $member) { ?>

                            <td class="calendar-background-content">&nbsp;
                                <?php foreach ($post as $contentKey => $content) { ?>
                                    <?php if ($contentKey == $memberKey) { ?>
                                        <?php foreach ($content as $c) { ?>
                                            <p><?php echo $c['Post']['content'] ?></p>
                                        <?php } ?>
                                        <?php
                                    }
                                }
                                ?>
                            </td>
                        <?php } ?>
                    </tr>
                <?php } ?>

            </table>
        </div>

    </div>

in model

public function getWeekPosts($begin, $end) {

        $res = $this->find("all", array("order" => array('deadline', 'member_id'), "conditions" => "deadline BETWEEN '" . $begin . "' AND '" . $end . "'"));

        $res = $this->formatWeekPosts($begin, $res);

        return $res;
    }




public function formatWeekPosts($begin, $res) {
       $dt = array();

        for ($i = 0; $i < 6; $i++) {
            $dt[] = date("Y-m-d", strtotime($begin . "+ " . $i . " days"));
        }

        $members = array();
        $pastMember = "";

        foreach ($res as $r) {
            if ($pastMember != $r['Post']['member_id']) {
                $members[] = $r['Post']['member_id'];
                $pastMember = $r['Post']['member_id'];
            }
        }

       $posts = array();

        foreach ($dt as $d) {
            foreach ($res as $r) {
                if ($r['Post']['deadline'] == $d) {
                    $posts[$d][] = $r;
                }
            }
        }

       $sortedPosts = array();

        foreach ($members as $member) {
            foreach ($posts as $key => $postDate) {
                foreach ($postDate as $key2 => $p) {
                    if ($p["Post"]['member_id'] == $member) {
                        $sortedPosts[$key][$p["Post"]['member_id']][$key2] = $p;
                    }
                }
            }
        }
        ksort($sortedPosts);

        return $sortedPosts;
    }



public function PostgetUniqueMembers($posts) {
       $members = array();

        foreach ($posts as $post) {
            foreach ($post as $p) {
                $members[$p[key($p)]["Post"]["member_id"]] = $p[key($p)]["Member"]['username'];
            }
        }
        return $members;
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集