在日历上显示工作日

时间:2012-07-03 02:42:49

标签: php

我遇到了问题。我无法显示工作日。 因此,当我点击下一步时,它应显示周一到周五显示的下周的周。 当我点击之前它应该显示在周一到周五的最后一周

这是我的代码

控制器中的

    <?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>

在模型中

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 个答案:

没有答案