[Phphtmllib-devel] SF.net SVN: phphtmllib:[3342] trunk/open2300/lib/modules/wxdate
Status: Beta
Brought to you by:
hemna
From: <he...@us...> - 2010-02-22 04:12:28
|
Revision: 3342 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3342&view=rev Author: hemna Date: 2010-02-22 04:12:22 +0000 (Mon, 22 Feb 2010) Log Message: ----------- new dates Modified Paths: -------------- trunk/open2300/lib/modules/wxdate/page/WxDate.inc Added Paths: ----------- trunk/open2300/lib/modules/wxdate/widgets/ trunk/open2300/lib/modules/wxdate/widgets/WxDateCalendar.inc Modified: trunk/open2300/lib/modules/wxdate/page/WxDate.inc =================================================================== --- trunk/open2300/lib/modules/wxdate/page/WxDate.inc 2010-02-21 22:23:15 UTC (rev 3341) +++ trunk/open2300/lib/modules/wxdate/page/WxDate.inc 2010-02-22 04:12:22 UTC (rev 3342) @@ -30,21 +30,26 @@ * * @param TABLEtag object. */ - protected function main_block() { +// protected function main_block() { +// +// $main = new DIVtag(array("id" => "centercontent", +// "style" => "width: 510px; margin-left: auto; margin-right:auto;")); +// +// +// $table = TABLEtag::factory("100%", 0); +// +// $table->add_row( TDtag::factory("rightblock", "", $this->content_block() )); +// +// $table->add_row(new TDtag(array("colspan"=> 2), +// $this->footer_block())); +// $main->add( $table ); +// +// return $main; +// } - $main = new DIVtag(array("id" => "centercontent", - "style" => "width: 510px; margin-left: auto; margin-right:auto;")); - - - $table = TABLEtag::factory("100%", 0); - - $table->add_row( TDtag::factory("rightblock", "", $this->content_block() )); - - $table->add_row(new TDtag(array("colspan"=> 2), - $this->footer_block())); - $main->add( $table ); - - return $main; + protected function left_block() { + $div = new DIVtag(array("style" => "margin-top:20px"), new WxDateCalendar()); + return $div; } /** @@ -78,7 +83,8 @@ $this->add_css_link('/css/lightview/lightview.css'); $c = new Container(); - $c->add( H3tag::factory("Weather on ".date("l M d, Y", strtotime($this->wxdate))), + + $c->add( H3tag::factory("Weather on ".date("l M d, Y", strtotime($this->wxdate))), Brtag::factory(1), $right_div ); return $c; Added: trunk/open2300/lib/modules/wxdate/widgets/WxDateCalendar.inc =================================================================== --- trunk/open2300/lib/modules/wxdate/widgets/WxDateCalendar.inc (rev 0) +++ trunk/open2300/lib/modules/wxdate/widgets/WxDateCalendar.inc 2010-02-22 04:12:22 UTC (rev 3342) @@ -0,0 +1,118 @@ +<?php + +class WxDateCalendar extends AjaxableHTMLWidget { + + protected $date = null; + protected $year = null; + protected $month = null; + protected $day = null; + + protected $current_date; + + private $cur_month = null; + + public function __construct($date = null) { + $this->current_date = date("Y-m-d"); + if ($date == null) { + $this->date = Request::singleton()->get("date", date("Y-m-d")); + if (empty($this->date) || is_null($this->date)) { + $this->date = date("Y-m-d"); + } + } else { + $this->date = $date; + } + + $ts = strtotime($this->date); + $this->year = date("Y", $ts); + $this->month = date("n", $ts); + $this->day = date('j',$ts); + Log::Singleton()->debug("date=".$this->date." year = ".$this->year." month = ".$this->month." day = ".$this->day); + } + + + public function get_content() { + $div = new DIVtag(array('id'=>$this->get_ajax_replacement_divid().'contents')); + + $days = $this->get_days(); + + $pn = array('«'=>'/weblog/archive/2004/Jul', '»'=>'/weblog/archive/2004/Sep'); + $pn = $this->get_prev_next_urls(); + + $div->add(Calendar::factory($this->year, $this->month, $days, 3, null, 0, $pn)); + + return $div; + } + + + protected function get_prev_next_urls() { + + $next_month_ts = strtotime("+1 month", strtotime($this->date)); + $prev_month_ts = strtotime("-1 month", strtotime($this->date)); + + $prev = RequestBuilder::build_url("WxDate", array("date" => date("Y-m-d", $prev_month_ts))); + $next = RequestBuilder::build_url("WxDate", array("date" => date("Y-m-d", $next_month_ts))); + + Log::singleton()->debug("date = ".$this->date." prev = ".$prev." next=".$next); + + if (!$this->is_current_month()) { + return $pn = array("«" => $prev, "»" => $next ); + } else { + return $pn = array("«" => $prev); + } + } + + protected function get_days() { + $dt = new DateTime(); + $days = array(); + + $cur_ts = strtotime($this->current_date); + $ts = strtotime($this->date); + + $cur_month = $this->is_current_month(); + $cur_day = date("d"); + + $num_days = $this->get_days_in_month($this->month, $this->year); + + if ($cur_month) { + $num_days = $cur_day; + } + + for ($x=1; $x<=$num_days; $x++) { + + if ($x == $this->day) { + $days[$x] = array(null, "selected-day"); + } else { + $date = $this->year."-".$this->month."-".$x; + $url = RequestBuilder::build_url("WxDate", array("date" => $date)); + $days[$x] = array($url, "linked-day"); + } + } + return $days; + } + + private function is_current_month() { + if (!is_null($this->cur_month)) { + return $this->cur_month; + } + + $date = date("Y-m"); + $cur_ts = strtotime($date."-01"); + $ts = strtotime($this->year."-".$this->month."-01"); + + if ($cur_ts == $ts) { + $this->cur_month = true; + } else { + $this->cur_month = false; + } + + return $this->cur_month; + } + + private function get_days_in_month($month, $year) { + $ts = strtotime("-1 day", strtotime($year."-".$month."-01")); + return date("d", $ts); + } + + +} +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |