summaryrefslogtreecommitdiff
path: root/demos/blog/protected/Pages/SearchPost.php
blob: 437435f97a5e58aa1f78dbd6bf63e82c69f6e1ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

class SearchPost extends BlogPage
{
	private $_posts;

	public function onInit($param)
	{
		parent::onInit($param);
		$this->_posts=$this->DataAccess->queryPostsSearch(
				$this->getPostKeywords(),
				'ORDER BY create_time DESC',
				'LIMIT '.$this->getPageOffset().','.$this->getPageSize());
	}

	private function getPostKeywords()
	{
		return explode(' ',$this->Request['keyword']);
	}

	private function getPageOffset()
	{
		if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0)
			$offset=0;
		return $offset;
	}

	private function getPageSize()
	{
		if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0)
			$limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']);
		return $limit;
	}

	private function formUrl($newOffset)
	{
		$gets=array();
		$gets['offset']=$newOffset;
		if($this->Request['limit']!==null)
			$gets['limit']=$this->Request['limit'];
		if($this->Request['time']!==null)
			$gets['time']=$this->Request['time'];
		if($this->Request['cat']!==null)
			$gets['cat']=$this->Request['cat'];
		return $this->Service->constructUrl('Posts.ListPost',$gets);
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->PostList->DataSource=$this->_posts;
		$this->PostList->dataBind();
		if($this->getPageOffset()>0)
		{
			if(($offset=$this->getPageOffset()-$this->getPageSize())<0)
				$offset=0;
			$this->PrevPage->NavigateUrl=$this->formUrl($offset);
			$this->PrevPage->Visible=true;
		}
		if(count($this->_posts)===$this->getPageSize())
		{
			$this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize());
			$this->NextPage->Visible=true;
		}
	}
}

?>